Skip to content

Commit de5b2ff

Browse files
committed
Added working for anthropic
1 parent ecc9643 commit de5b2ff

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

src/api/providers/anthropic.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ export class AnthropicHandler implements ApiHandler, SingleCompletionHandler {
178178

179179
yield { type: "text", text: chunk.content_block.text }
180180
break
181+
default: {
182+
const block = chunk.content_block as {
183+
type: string
184+
text?: string
185+
metadata?: { ui_only?: boolean; content?: string }
186+
}
187+
188+
if (block.type === "ui") {
189+
yield {
190+
type: "text",
191+
text: block.text || "",
192+
metadata: block.metadata,
193+
}
194+
} else {
195+
yield {
196+
type: "text",
197+
text: block.text || "",
198+
}
199+
}
200+
break
201+
}
181202
}
182203
break
183204
case "content_block_delta":

src/api/providers/deepseek.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ export class DeepSeekHandler implements ApiHandler, SingleCompletionHandler {
8383
const chunk = JSON.parse(data)
8484
const delta = chunk.choices[0]?.delta ?? {}
8585

86-
if (delta.content) {
86+
if (delta.type === "ui") {
87+
yield {
88+
type: "text",
89+
text: delta.metadata?.content || "",
90+
metadata: { ui_only: delta.metadata?.ui_only },
91+
}
92+
} else if (delta.content) {
8793
yield {
8894
type: "text",
8995
text: delta.content,

src/api/providers/pearai.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,31 @@ export class PearAiHandler {
123123

124124
async *createMessage(systemPrompt: string, messages: any[]): AsyncGenerator<any> {
125125
const generator = this.handler.createMessage(systemPrompt, messages)
126-
yield* generator
126+
let warningMsg = ""
127+
128+
for await (const chunk of generator) {
129+
console.dir(chunk)
130+
if (chunk.type === "text" && chunk.metadata?.ui_only) {
131+
console.dir("HOLY SHIT IM HERE")
132+
warningMsg += chunk.metadata?.content
133+
console.dir("WARING MESSAGE")
134+
console.dir(warningMsg)
135+
continue
136+
}
137+
yield chunk
138+
}
139+
140+
if (warningMsg) {
141+
if (warningMsg.includes("pay-as-you-go") || true) {
142+
vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => {
143+
if (selection === "View Pay-As-You-Go") {
144+
vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go"))
145+
}
146+
})
147+
} else {
148+
vscode.window.showInformationMessage(warningMsg)
149+
}
150+
}
127151
}
128152

129153
async completePrompt(prompt: string): Promise<string> {

src/api/transform/stream.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export type ApiStreamChunk = ApiStreamTextChunk | ApiStreamUsageChunk | ApiStrea
44
export interface ApiStreamTextChunk {
55
type: "text"
66
text: string
7+
metadata?: {
8+
ui_only?: boolean
9+
content?: string
10+
}
711
}
812

913
export interface ApiStreamReasoningChunk {

0 commit comments

Comments
 (0)