Skip to content

Commit 8aa0256

Browse files
authored
Merge pull request #28 from trypear/pay-as-you-go-notif
Pay as you go notif
2 parents 823ec11 + bd0002b commit 8aa0256

4 files changed

Lines changed: 55 additions & 3 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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@ export class DeepSeekHandler implements ApiHandler, SingleCompletionHandler {
8181

8282
try {
8383
const chunk = JSON.parse(data)
84+
// Handle regular delta format
8485
const delta = chunk.choices[0]?.delta ?? {}
85-
86-
if (delta.content) {
86+
if (delta.type === "ui") {
87+
yield {
88+
type: "text",
89+
text: delta.metadata?.content || "",
90+
metadata: delta.metadata,
91+
}
92+
} else if (delta.content) {
8793
yield {
8894
type: "text",
8995
text: delta.content,

src/api/providers/pearai.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,28 @@ 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+
warningMsg += chunk.metadata?.content
132+
continue
133+
}
134+
yield chunk
135+
}
136+
137+
if (warningMsg) {
138+
if (warningMsg.includes("pay-as-you-go")) {
139+
vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => {
140+
if (selection === "View Pay-As-You-Go") {
141+
vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go"))
142+
}
143+
})
144+
} else {
145+
vscode.window.showInformationMessage(warningMsg)
146+
}
147+
}
127148
}
128149

129150
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)