Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions components/message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { DocumentToolCall, DocumentToolResult } from './document';
import { DocumentPreview } from './document-preview';
import { Markdown } from './markdown';
import { MessageEditor } from './message-editor';
import { MessageReasoning } from './message-reasoning';
import { PreviewAttachment } from './preview-attachment';
import { Weather } from './weather';

Expand All @@ -42,6 +41,13 @@ const PurePreviewMessage = ({
}) => {
const [mode, setMode] = useState<'view' | 'edit'>('view');

/**
* For now, only streaming reasoning to console is supported
*/
if (message.reasoning) {
console.log('Pattern event: ', message.reasoning);
}

return (
<AnimatePresence>
<motion.div
Expand Down Expand Up @@ -86,13 +92,6 @@ const PurePreviewMessage = ({
</div>
)}

{message.reasoning && (
<MessageReasoning
isLoading={isLoading}
reasoning={message.reasoning}
/>
)}

{(message.content || message.reasoning) && mode === 'view' && (
<div className="flex flex-row gap-2 items-start">
<div
Expand Down
16 changes: 11 additions & 5 deletions lib/ai/pattern-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ToolStartEvent,
} from '@/lib/ai/types';

import { showToolCalls as showToolCallsFlag } from '../flags';
import { extractErrorMessageOrDefault } from '../utils';

const textDecoder = new TextDecoder();
Expand Down Expand Up @@ -85,7 +86,10 @@ export class PatternModel implements LanguageModelV1 {
let incompleteJsonFragment = '';

return new TransformStream<string, LanguageModelV1StreamPart>({
transform: (chunk, controller) => {
transform: async (chunk, controller) => {
const showToolCalls = await showToolCallsFlag();
const shouldStreamToolCalls = showToolCalls === 'console';

if (ArrayBuffer.isView(chunk)) {
try {
const chunkBuffer = new Uint8Array(
Expand Down Expand Up @@ -160,10 +164,12 @@ export class PatternModel implements LanguageModelV1 {
textDelta: event.data,
});
} else if (SUPPORTED_EVENT_TYPES.includes(event.type)) {
/**
* TODO: Re-enable reasoning when backend supports it
* https://github.com/pattern-tech/pattern-app/issues/27
*/
if (shouldStreamToolCalls) {
controller.enqueue({
type: 'reasoning',
textDelta: JSON.stringify(event),
});
}
} else {
controller.enqueue({
type: 'error',
Expand Down
11 changes: 11 additions & 0 deletions lib/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ import { flag } from 'flags/next';
* key: 'some-flag',
* });
*/

/**
* Feature flag to control whether to show tool calls in the chat UI
*/
type ShowToolCalls = 'console' | undefined;
export const showToolCalls = flag<ShowToolCalls>({
adapter: edgeConfigAdapter(),
key: 'show-tool-calls',
options: ['console'],
defaultValue: undefined,
});