@molecule/api-ai-anthropic 1.2.0 → 1.3.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/provider.d.ts.map +1 -1
- package/dist/provider.js +22 -0
- package/package.json +2 -2
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EACV,UAAU,EAQX,MAAM,kBAAkB,CAAA;AASzB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAosBjD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,UAAU,CAEnE"}
|
package/dist/provider.js
CHANGED
|
@@ -31,8 +31,19 @@ function snapshotUsage(state) {
|
|
|
31
31
|
: {}),
|
|
32
32
|
...(state.cacheReadInputTokens ? { cacheReadInputTokens: state.cacheReadInputTokens } : {}),
|
|
33
33
|
...(state.speed ? { speed: state.speed } : {}),
|
|
34
|
+
...webSearchUsage(state.webSearchRequests ?? state.webSearchBlocks),
|
|
34
35
|
};
|
|
35
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The `webSearchRequests` part of a `TokenUsage`: the count when searches ran,
|
|
39
|
+
* nothing otherwise.
|
|
40
|
+
*
|
|
41
|
+
* @param count - Web searches billed for the request.
|
|
42
|
+
* @returns A spreadable partial.
|
|
43
|
+
*/
|
|
44
|
+
function webSearchUsage(count) {
|
|
45
|
+
return count ? { webSearchRequests: count } : {};
|
|
46
|
+
}
|
|
36
47
|
/**
|
|
37
48
|
* Narrows the provider-reported speed tier to the TokenUsage union.
|
|
38
49
|
*
|
|
@@ -410,6 +421,7 @@ class AnthropicAIProvider {
|
|
|
410
421
|
? { cacheReadInputTokens: usage.cache_read_input_tokens }
|
|
411
422
|
: {}),
|
|
412
423
|
...(servedSpeed ? { speed: servedSpeed } : {}),
|
|
424
|
+
...webSearchUsage(usage?.server_tool_use?.web_search_requests),
|
|
413
425
|
},
|
|
414
426
|
};
|
|
415
427
|
}
|
|
@@ -437,6 +449,8 @@ class AnthropicAIProvider {
|
|
|
437
449
|
cacheCreationInputTokens: 0,
|
|
438
450
|
cacheReadInputTokens: 0,
|
|
439
451
|
speed: null,
|
|
452
|
+
webSearchRequests: null,
|
|
453
|
+
webSearchBlocks: 0,
|
|
440
454
|
pendingTool: null,
|
|
441
455
|
pendingThinking: null,
|
|
442
456
|
};
|
|
@@ -564,6 +578,11 @@ class AnthropicAIProvider {
|
|
|
564
578
|
else if (block.type === 'thinking') {
|
|
565
579
|
state.pendingThinking = '';
|
|
566
580
|
}
|
|
581
|
+
else if (block.type === 'server_tool_use' && block.name === 'web_search') {
|
|
582
|
+
// Billed per search. Counted here so a stream cut before
|
|
583
|
+
// message_delta (which carries the reported count) still meters it.
|
|
584
|
+
state.webSearchBlocks++;
|
|
585
|
+
}
|
|
567
586
|
}
|
|
568
587
|
else if (eventType === 'content_block_stop') {
|
|
569
588
|
// Emit completed tool_use with accumulated input
|
|
@@ -590,6 +609,9 @@ class AnthropicAIProvider {
|
|
|
590
609
|
}
|
|
591
610
|
else if (eventType === 'message_delta') {
|
|
592
611
|
const usage = event.usage;
|
|
612
|
+
const reportedSearches = usage?.server_tool_use?.web_search_requests;
|
|
613
|
+
if (typeof reportedSearches === 'number')
|
|
614
|
+
state.webSearchRequests = reportedSearches;
|
|
593
615
|
if (usage?.output_tokens) {
|
|
594
616
|
state.outputTokens = usage.output_tokens;
|
|
595
617
|
// Metering snapshot (latest wins): if the stream is cut after this
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/api-ai-anthropic",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Anthropic Claude AI provider for molecule.dev",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/api-ai-anthropic",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"directory": "packages/api/bonds/ai/anthropic"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@molecule/api-ai": "1.
|
|
36
|
+
"@molecule/api-ai": "1.3.0",
|
|
37
37
|
"@molecule/api-bond": "1.0.2",
|
|
38
38
|
"@types/node": "26.1.2",
|
|
39
39
|
"typescript": "6.0.3",
|