Skip to content

Commit 59fcd0e

Browse files
author
Zoo (VP)
committed
fix(vscode-e2e): emit attempt_completion in provider-cost stub and fix partial check
1 parent 712bb66 commit 59fcd0e

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

‎apps/vscode-e2e/src/suite/provider-cost.test.ts‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,39 @@ function readRequestBody(req: IncomingMessage): Promise<string> {
4343
}
4444

4545
function buildSsePayload(modelId: string): string {
46-
const textChunk = {
46+
const toolChunk = {
4747
id: "chatcmpl-stub",
4848
object: "chat.completion.chunk",
49-
created: 0,
49+
created: Math.floor(Date.now() / 1000),
5050
model: modelId,
51-
choices: [{ index: 0, delta: { role: "assistant", content: "4" }, finish_reason: null }],
52-
}
53-
54-
const finalChunk = {
55-
id: "chatcmpl-stub",
56-
object: "chat.completion.chunk",
57-
created: 0,
58-
model: modelId,
59-
choices: [{ index: 0, delta: {}, finish_reason: "stop" }],
51+
choices: [
52+
{
53+
index: 0,
54+
delta: {
55+
role: "assistant",
56+
tool_calls: [
57+
{
58+
index: 0,
59+
id: "call_stub_001",
60+
type: "function",
61+
function: {
62+
name: "attempt_completion",
63+
arguments: JSON.stringify({ result: "4" }),
64+
},
65+
},
66+
],
67+
},
68+
finish_reason: "tool_calls",
69+
},
70+
],
6071
usage: {
6172
prompt_tokens: STUB_INPUT_TOKENS,
6273
completion_tokens: STUB_OUTPUT_TOKENS,
6374
total_tokens: STUB_INPUT_TOKENS + STUB_OUTPUT_TOKENS,
6475
},
6576
}
6677

67-
return `data: ${JSON.stringify(textChunk)}\n\ndata: ${JSON.stringify(finalChunk)}\n\ndata: [DONE]\n\n`
78+
return `data: ${JSON.stringify(toolChunk)}\n\ndata: [DONE]\n\n`
6879
}
6980

7081
function isChatCompletionsUrl(rawUrl: string): boolean {
@@ -177,7 +188,7 @@ suite("Provider Cost Metrics (B17)", function () {
177188

178189
const apiReqMessages: ClineMessage[] = []
179190
const onMessage = ({ message }: { message: ClineMessage }) => {
180-
if (message.type === "say" && message.say === "api_req_started" && message.partial === false) {
191+
if (message.type === "say" && message.say === "api_req_started" && message.partial !== true) {
181192
apiReqMessages.push(message)
182193
}
183194
}

0 commit comments

Comments
 (0)