diff --git a/src/api/providers/anthropic.ts b/src/api/providers/anthropic.ts index 8354950136b..42db0c82f35 100644 --- a/src/api/providers/anthropic.ts +++ b/src/api/providers/anthropic.ts @@ -178,6 +178,27 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler { yield { type: "text", text: chunk.content_block.text } break + default: { + const block = chunk.content_block as { + type: string + text?: string + metadata?: { ui_only?: boolean; content?: string } + } + + if (block.type === "ui") { + yield { + type: "text", + text: block.text || "", + metadata: block.metadata, + } + } else { + yield { + type: "text", + text: block.text || "", + } + } + break + } } break case "content_block_delta": diff --git a/src/api/providers/deepseek.ts b/src/api/providers/deepseek.ts index 148bf31310e..1ed0b410506 100644 --- a/src/api/providers/deepseek.ts +++ b/src/api/providers/deepseek.ts @@ -81,9 +81,15 @@ export class DeepSeekHandler implements ApiHandler, SingleCompletionHandler { try { const chunk = JSON.parse(data) + // Handle regular delta format const delta = chunk.choices[0]?.delta ?? {} - - if (delta.content) { + if (delta.type === "ui") { + yield { + type: "text", + text: delta.metadata?.content || "", + metadata: delta.metadata, + } + } else if (delta.content) { yield { type: "text", text: delta.content, diff --git a/src/api/providers/pearai.ts b/src/api/providers/pearai.ts index ca825243c08..bff95db4880 100644 --- a/src/api/providers/pearai.ts +++ b/src/api/providers/pearai.ts @@ -123,7 +123,28 @@ export class PearAiHandler { async *createMessage(systemPrompt: string, messages: any[]): AsyncGenerator { const generator = this.handler.createMessage(systemPrompt, messages) - yield* generator + let warningMsg = "" + + for await (const chunk of generator) { + console.dir(chunk) + if (chunk.type === "text" && chunk.metadata?.ui_only) { + warningMsg += chunk.metadata?.content + continue + } + yield chunk + } + + if (warningMsg) { + if (warningMsg.includes("pay-as-you-go")) { + vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => { + if (selection === "View Pay-As-You-Go") { + vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go")) + } + }) + } else { + vscode.window.showInformationMessage(warningMsg) + } + } } async completePrompt(prompt: string): Promise { diff --git a/src/api/transform/stream.ts b/src/api/transform/stream.ts index 97751edd90d..a0f27bb32c6 100644 --- a/src/api/transform/stream.ts +++ b/src/api/transform/stream.ts @@ -4,6 +4,10 @@ export type ApiStreamChunk = ApiStreamTextChunk | ApiStreamUsageChunk | ApiStrea export interface ApiStreamTextChunk { type: "text" text: string + metadata?: { + ui_only?: boolean + content?: string + } } export interface ApiStreamReasoningChunk {