@@ -13,6 +13,17 @@ import type {
1313
1414const textDecoder = new TextDecoder ( ) ;
1515
16+ const SUPPORTED_EVENT_TYPES = [
17+ 'token' ,
18+ 'tool_start' ,
19+ 'tool_end' ,
20+ 'heartbeat' ,
21+ 'agent_start' ,
22+ 'agent_finish' ,
23+ 'tool_selection_start' ,
24+ 'tool_selection_end' ,
25+ ] as const ;
26+
1627export class PatternModel implements LanguageModelV1 {
1728 readonly modelId = 'pattern-model' ;
1829 readonly provider = 'pattern' ;
@@ -61,7 +72,7 @@ export class PatternModel implements LanguageModelV1 {
6172 * @returns Reasoning text for a tool start event
6273 */
6374 private getToolStartReasoningText ( event : ToolStartEvent ) {
64- return `#### Tool call - ${ event . tool } \n${ Object . entries ( event . tool_input ?? { } ) . map ( ( entry ) => `* **${ entry [ 0 ] } **: ${ entry [ 1 ] } \n` ) } ` ;
75+ return `#### Tool call - ${ event . tool_name } \n${ Object . entries ( JSON . parse ( event . params ) ) . map ( ( entry ) => `* **${ entry [ 0 ] } **: ${ entry [ 1 ] } \n` ) } ` ;
6576 }
6677
6778 /**
@@ -89,20 +100,11 @@ export class PatternModel implements LanguageModelV1 {
89100 type : 'text-delta' ,
90101 textDelta : event . data ,
91102 } ) ;
92- } else if ( event . type === 'tool_start' ) {
103+ } else if ( SUPPORTED_EVENT_TYPES . includes ( event . type ) ) {
93104 /**
94105 * TODO: Re-enable reasoning when backend supports it
95106 * https://github.com/pattern-tech/pattern-app/issues/27
96107 */
97- } else if (
98- event . type === 'completion' ||
99- event . type === 'heartbeat'
100- ) {
101- /**
102- * Ignore heartbeat and completion events. Completion event is
103- * identified automatically when the stream is ended, and the
104- * heartbeat event is only for keeping the connection alive
105- */
106108 } else {
107109 controller . enqueue ( {
108110 type : 'error' ,
0 commit comments