File tree Expand file tree Collapse file tree 3 files changed +29
-13
lines changed
Expand file tree Collapse file tree 3 files changed +29
-13
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ import { DocumentToolCall, DocumentToolResult } from './document';
1515import { DocumentPreview } from './document-preview' ;
1616import { Markdown } from './markdown' ;
1717import { MessageEditor } from './message-editor' ;
18- import { MessageReasoning } from './message-reasoning' ;
1918import { PreviewAttachment } from './preview-attachment' ;
2019import { Weather } from './weather' ;
2120
@@ -42,6 +41,13 @@ const PurePreviewMessage = ({
4241} ) => {
4342 const [ mode , setMode ] = useState < 'view' | 'edit' > ( 'view' ) ;
4443
44+ /**
45+ * For now, only streaming reasoning to console is supported
46+ */
47+ if ( message . reasoning ) {
48+ console . log ( 'Pattern event: ' , message . reasoning ) ;
49+ }
50+
4551 return (
4652 < AnimatePresence >
4753 < motion . div
@@ -86,13 +92,6 @@ const PurePreviewMessage = ({
8692 </ div >
8793 ) }
8894
89- { message . reasoning && (
90- < MessageReasoning
91- isLoading = { isLoading }
92- reasoning = { message . reasoning }
93- />
94- ) }
95-
9695 { ( message . content || message . reasoning ) && mode === 'view' && (
9796 < div className = "flex flex-row gap-2 items-start" >
9897 < div
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import type {
1111 ToolStartEvent ,
1212} from '@/lib/ai/types' ;
1313
14+ import { showToolCalls as showToolCallsFlag } from '../flags' ;
1415import { extractErrorMessageOrDefault } from '../utils' ;
1516
1617const textDecoder = new TextDecoder ( ) ;
@@ -85,7 +86,10 @@ export class PatternModel implements LanguageModelV1 {
8586 let incompleteJsonFragment = '' ;
8687
8788 return new TransformStream < string , LanguageModelV1StreamPart > ( {
88- transform : ( chunk , controller ) => {
89+ transform : async ( chunk , controller ) => {
90+ const showToolCalls = await showToolCallsFlag ( ) ;
91+ const shouldStreamToolCalls = showToolCalls === 'console' ;
92+
8993 if ( ArrayBuffer . isView ( chunk ) ) {
9094 try {
9195 const chunkBuffer = new Uint8Array (
@@ -160,10 +164,12 @@ export class PatternModel implements LanguageModelV1 {
160164 textDelta : event . data ,
161165 } ) ;
162166 } else if ( SUPPORTED_EVENT_TYPES . includes ( event . type ) ) {
163- /**
164- * TODO: Re-enable reasoning when backend supports it
165- * https://github.com/pattern-tech/pattern-app/issues/27
166- */
167+ if ( shouldStreamToolCalls ) {
168+ controller . enqueue ( {
169+ type : 'reasoning' ,
170+ textDelta : JSON . stringify ( event ) ,
171+ } ) ;
172+ }
167173 } else {
168174 controller . enqueue ( {
169175 type : 'error' ,
Original file line number Diff line number Diff line change @@ -8,3 +8,14 @@ import { flag } from 'flags/next';
88 * key: 'some-flag',
99 * });
1010 */
11+
12+ /**
13+ * Feature flag to control whether to show tool calls in the chat UI
14+ */
15+ type ShowToolCalls = 'console' | undefined ;
16+ export const showToolCalls = flag < ShowToolCalls > ( {
17+ adapter : edgeConfigAdapter ( ) ,
18+ key : 'show-tool-calls' ,
19+ options : [ 'console' ] ,
20+ defaultValue : undefined ,
21+ } ) ;
You can’t perform that action at this time.
0 commit comments