pi-codebuddy-sdk 0.4.28 → 0.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.ts +11 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-codebuddy-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.30",
|
|
4
4
|
"description": "Pi extension that uses CodeBuddy (via Agent SDK) as a model provider and adds an AskCodebuddy tool.",
|
|
5
5
|
"author": "RealAlexandreAI",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tencent-ai/agent-sdk": "^0.3.
|
|
36
|
+
"@tencent-ai/agent-sdk": "^0.3.279",
|
|
37
37
|
"change-case": "^5.4.4"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -853,10 +853,18 @@ function buildMcpServers(tools: Tool[], queryCtx: QueryContext): Record<string,
|
|
|
853
853
|
// --- Usage helpers ---
|
|
854
854
|
|
|
855
855
|
function updateUsage(output: AssistantMessage, usage: Record<string, number | undefined>, model: Model<any>): void {
|
|
856
|
-
|
|
856
|
+
// CodeBuddy reports OpenAI/DeepSeek-style usage: input_tokens covers the whole prompt and
|
|
857
|
+
// cache_read_input_tokens is the cached slice of that same prompt. pi's Usage type is
|
|
858
|
+
// Anthropic-style, where input holds only the uncached remainder, because pi derives
|
|
859
|
+
// promptTokens = input + cacheRead + cacheWrite (core/cache-stats). Storing the total in
|
|
860
|
+
// the input field therefore counts the cached prompt twice and makes pi report bogus
|
|
861
|
+
// 'Cache miss: <n> tokens re-billed' notices. Mirrors pi-ai's openai-completions adapter.
|
|
862
|
+
const cacheReadTokens = usage.cache_read_input_tokens ?? 0;
|
|
863
|
+
const cacheWriteTokens = usage.cache_creation_input_tokens ?? 0;
|
|
864
|
+
if (usage.input_tokens != null) output.usage.input = Math.max(0, usage.input_tokens - cacheReadTokens - cacheWriteTokens);
|
|
857
865
|
if (usage.output_tokens != null) output.usage.output = usage.output_tokens;
|
|
858
|
-
if (usage.cache_read_input_tokens != null) output.usage.cacheRead =
|
|
859
|
-
if (usage.cache_creation_input_tokens != null) output.usage.cacheWrite =
|
|
866
|
+
if (usage.cache_read_input_tokens != null) output.usage.cacheRead = cacheReadTokens;
|
|
867
|
+
if (usage.cache_creation_input_tokens != null) output.usage.cacheWrite = cacheWriteTokens;
|
|
860
868
|
// CodeBuddy may report reasoning/thinking tokens separately, while pi's Usage type does not model that field.
|
|
861
869
|
const reasoning = usage.reasoning_tokens ?? usage.thinking_tokens;
|
|
862
870
|
if (reasoning != null) (output.usage as typeof output.usage & { reasoning?: number }).reasoning = reasoning;
|