@core-ai/anthropic 0.3.0 → 0.4.0
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/dist/index.js +40 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -257,15 +257,23 @@ function mapGenerateResponse(response) {
|
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
const cacheReadTokens = response.usage.cache_read_input_tokens ?? 0;
|
|
261
|
+
const cacheWriteTokens = response.usage.cache_creation_input_tokens ?? 0;
|
|
262
|
+
const inputTokens = response.usage.input_tokens + cacheReadTokens + cacheWriteTokens;
|
|
260
263
|
return {
|
|
261
264
|
content: content.length > 0 ? content : null,
|
|
262
265
|
toolCalls,
|
|
263
266
|
finishReason: mapStopReason(response.stop_reason),
|
|
264
267
|
usage: {
|
|
265
|
-
inputTokens
|
|
268
|
+
inputTokens,
|
|
266
269
|
outputTokens: response.usage.output_tokens,
|
|
267
|
-
|
|
268
|
-
|
|
270
|
+
inputTokenDetails: {
|
|
271
|
+
cacheReadTokens,
|
|
272
|
+
cacheWriteTokens
|
|
273
|
+
},
|
|
274
|
+
outputTokenDetails: {
|
|
275
|
+
reasoningTokens: 0
|
|
276
|
+
}
|
|
269
277
|
}
|
|
270
278
|
};
|
|
271
279
|
}
|
|
@@ -274,18 +282,31 @@ async function* transformStream(stream) {
|
|
|
274
282
|
let usage = {
|
|
275
283
|
inputTokens: 0,
|
|
276
284
|
outputTokens: 0,
|
|
277
|
-
|
|
278
|
-
|
|
285
|
+
inputTokenDetails: {
|
|
286
|
+
cacheReadTokens: 0,
|
|
287
|
+
cacheWriteTokens: 0
|
|
288
|
+
},
|
|
289
|
+
outputTokenDetails: {
|
|
290
|
+
reasoningTokens: 0
|
|
291
|
+
}
|
|
279
292
|
};
|
|
280
293
|
const toolBuffers = /* @__PURE__ */ new Map();
|
|
281
294
|
const emittedToolCalls = /* @__PURE__ */ new Set();
|
|
282
295
|
for await (const event of stream) {
|
|
283
296
|
if (event.type === "message_start") {
|
|
297
|
+
const cacheReadTokens = event.message.usage.cache_read_input_tokens ?? 0;
|
|
298
|
+
const cacheWriteTokens = event.message.usage.cache_creation_input_tokens ?? 0;
|
|
299
|
+
const inputTokens = event.message.usage.input_tokens + cacheReadTokens + cacheWriteTokens;
|
|
284
300
|
usage = {
|
|
285
|
-
inputTokens
|
|
301
|
+
inputTokens,
|
|
286
302
|
outputTokens: event.message.usage.output_tokens,
|
|
287
|
-
|
|
288
|
-
|
|
303
|
+
inputTokenDetails: {
|
|
304
|
+
cacheReadTokens,
|
|
305
|
+
cacheWriteTokens
|
|
306
|
+
},
|
|
307
|
+
outputTokenDetails: {
|
|
308
|
+
reasoningTokens: 0
|
|
309
|
+
}
|
|
289
310
|
};
|
|
290
311
|
continue;
|
|
291
312
|
}
|
|
@@ -346,11 +367,19 @@ async function* transformStream(stream) {
|
|
|
346
367
|
}
|
|
347
368
|
if (event.type === "message_delta") {
|
|
348
369
|
finishReason = mapStopReason(event.delta.stop_reason);
|
|
370
|
+
const nonCachedInputTokens = event.usage.input_tokens ?? usage.inputTokens - usage.inputTokenDetails.cacheReadTokens - usage.inputTokenDetails.cacheWriteTokens;
|
|
371
|
+
const cacheReadTokens = event.usage.cache_read_input_tokens ?? usage.inputTokenDetails.cacheReadTokens;
|
|
372
|
+
const cacheWriteTokens = event.usage.cache_creation_input_tokens ?? usage.inputTokenDetails.cacheWriteTokens;
|
|
349
373
|
usage = {
|
|
350
|
-
inputTokens:
|
|
374
|
+
inputTokens: nonCachedInputTokens + cacheReadTokens + cacheWriteTokens,
|
|
351
375
|
outputTokens: event.usage.output_tokens,
|
|
352
|
-
|
|
353
|
-
|
|
376
|
+
inputTokenDetails: {
|
|
377
|
+
cacheReadTokens,
|
|
378
|
+
cacheWriteTokens
|
|
379
|
+
},
|
|
380
|
+
outputTokenDetails: {
|
|
381
|
+
reasoningTokens: 0
|
|
382
|
+
}
|
|
354
383
|
};
|
|
355
384
|
continue;
|
|
356
385
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@core-ai/anthropic",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Anthropic provider package for @core-ai/core-ai",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Omnifact (https://omnifact.ai)",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:watch": "vitest"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@core-ai/core-ai": "^0.
|
|
46
|
+
"@core-ai/core-ai": "^0.4.0",
|
|
47
47
|
"@anthropic-ai/sdk": "^0.78.0",
|
|
48
48
|
"zod-to-json-schema": "^3.25.1"
|
|
49
49
|
},
|