@ai-sdk/anthropic 2.0.51 → 2.0.53
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/CHANGELOG.md +12 -0
- package/dist/index.js +30 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +29 -50
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +29 -51
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/anthropic
|
|
2
2
|
|
|
3
|
+
## 2.0.53
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 65dee10: fix(anthropic): simplify pulling first chunk
|
|
8
|
+
|
|
9
|
+
## 2.0.52
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 518e786: fix(anthropic): send {} as tool input when streaming tool calls without arguments
|
|
14
|
+
|
|
3
15
|
## 2.0.51
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
|
|
|
31
31
|
var import_provider_utils20 = require("@ai-sdk/provider-utils");
|
|
32
32
|
|
|
33
33
|
// src/version.ts
|
|
34
|
-
var VERSION = true ? "2.0.
|
|
34
|
+
var VERSION = true ? "2.0.53" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2314,6 +2314,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2314
2314
|
};
|
|
2315
2315
|
}
|
|
2316
2316
|
async doStream(options) {
|
|
2317
|
+
var _a, _b;
|
|
2317
2318
|
const { args, warnings, betas, usesJsonResponseTool } = await this.getArgs({
|
|
2318
2319
|
...options,
|
|
2319
2320
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
@@ -2345,25 +2346,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2345
2346
|
let container = null;
|
|
2346
2347
|
let blockType = void 0;
|
|
2347
2348
|
const generateId3 = this.generateId;
|
|
2348
|
-
let isFirstChunk = true;
|
|
2349
|
-
let stream = void 0;
|
|
2350
|
-
const returnPromise = new import_provider_utils11.DelayedPromise();
|
|
2351
2349
|
const transformedStream = response.pipeThrough(
|
|
2352
2350
|
new TransformStream({
|
|
2353
2351
|
start(controller) {
|
|
2354
2352
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2355
2353
|
},
|
|
2356
|
-
async flush() {
|
|
2357
|
-
if (returnPromise.isPending()) {
|
|
2358
|
-
returnPromise.resolve({
|
|
2359
|
-
stream,
|
|
2360
|
-
request: { body },
|
|
2361
|
-
response: { headers: responseHeaders }
|
|
2362
|
-
});
|
|
2363
|
-
}
|
|
2364
|
-
},
|
|
2365
2354
|
transform(chunk, controller) {
|
|
2366
|
-
var
|
|
2355
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2367
2356
|
if (options.includeRawChunks) {
|
|
2368
2357
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2369
2358
|
}
|
|
@@ -2371,29 +2360,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2371
2360
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2372
2361
|
return;
|
|
2373
2362
|
}
|
|
2374
|
-
if (isFirstChunk) {
|
|
2375
|
-
if (chunk.value.type === "error") {
|
|
2376
|
-
returnPromise.reject(
|
|
2377
|
-
new import_provider3.APICallError({
|
|
2378
|
-
message: chunk.value.error.message,
|
|
2379
|
-
url,
|
|
2380
|
-
requestBodyValues: body,
|
|
2381
|
-
statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
|
|
2382
|
-
responseHeaders,
|
|
2383
|
-
responseBody: JSON.stringify(chunk.value.error),
|
|
2384
|
-
isRetryable: chunk.value.error.type === "overloaded_error"
|
|
2385
|
-
})
|
|
2386
|
-
);
|
|
2387
|
-
controller.terminate();
|
|
2388
|
-
return;
|
|
2389
|
-
}
|
|
2390
|
-
isFirstChunk = false;
|
|
2391
|
-
returnPromise.resolve({
|
|
2392
|
-
stream,
|
|
2393
|
-
request: { body },
|
|
2394
|
-
response: { headers: responseHeaders }
|
|
2395
|
-
});
|
|
2396
|
-
}
|
|
2397
2363
|
const value = chunk.value;
|
|
2398
2364
|
switch (value.type) {
|
|
2399
2365
|
case "ping": {
|
|
@@ -2525,11 +2491,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2525
2491
|
toolCallId: part.tool_use_id,
|
|
2526
2492
|
toolName: "web_search",
|
|
2527
2493
|
result: part.content.map((result) => {
|
|
2528
|
-
var
|
|
2494
|
+
var _a3;
|
|
2529
2495
|
return {
|
|
2530
2496
|
url: result.url,
|
|
2531
2497
|
title: result.title,
|
|
2532
|
-
pageAge: (
|
|
2498
|
+
pageAge: (_a3 = result.page_age) != null ? _a3 : null,
|
|
2533
2499
|
encryptedContent: result.encrypted_content,
|
|
2534
2500
|
type: result.type
|
|
2535
2501
|
};
|
|
@@ -2545,7 +2511,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2545
2511
|
title: result.title,
|
|
2546
2512
|
providerMetadata: {
|
|
2547
2513
|
anthropic: {
|
|
2548
|
-
pageAge: (
|
|
2514
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null
|
|
2549
2515
|
}
|
|
2550
2516
|
}
|
|
2551
2517
|
});
|
|
@@ -2646,7 +2612,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2646
2612
|
type: "tool-call",
|
|
2647
2613
|
toolCallId: contentBlock.toolCallId,
|
|
2648
2614
|
toolName,
|
|
2649
|
-
input: contentBlock.input,
|
|
2615
|
+
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
2650
2616
|
providerExecuted: contentBlock.providerExecuted
|
|
2651
2617
|
});
|
|
2652
2618
|
}
|
|
@@ -2748,7 +2714,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2748
2714
|
}
|
|
2749
2715
|
case "message_start": {
|
|
2750
2716
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
2751
|
-
usage.cachedInputTokens = (
|
|
2717
|
+
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
2752
2718
|
rawUsage = {
|
|
2753
2719
|
...value.message.usage
|
|
2754
2720
|
};
|
|
@@ -2812,22 +2778,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2812
2778
|
})
|
|
2813
2779
|
);
|
|
2814
2780
|
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
2815
|
-
stream = streamForConsumer;
|
|
2816
2781
|
const firstChunkReader = streamForFirstChunk.getReader();
|
|
2817
2782
|
try {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2783
|
+
await firstChunkReader.read();
|
|
2784
|
+
let result = await firstChunkReader.read();
|
|
2785
|
+
if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
|
|
2786
|
+
result = await firstChunkReader.read();
|
|
2821
2787
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2788
|
+
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
2789
|
+
const error = result.value.error;
|
|
2790
|
+
throw new import_provider3.APICallError({
|
|
2791
|
+
message: error.message,
|
|
2792
|
+
url,
|
|
2793
|
+
requestBodyValues: body,
|
|
2794
|
+
statusCode: error.type === "overloaded_error" ? 529 : 500,
|
|
2795
|
+
responseHeaders,
|
|
2796
|
+
responseBody: JSON.stringify(error),
|
|
2797
|
+
isRetryable: error.type === "overloaded_error"
|
|
2798
|
+
});
|
|
2826
2799
|
}
|
|
2827
2800
|
} finally {
|
|
2801
|
+
firstChunkReader.cancel().catch(() => {
|
|
2802
|
+
});
|
|
2828
2803
|
firstChunkReader.releaseLock();
|
|
2829
2804
|
}
|
|
2830
|
-
return
|
|
2805
|
+
return {
|
|
2806
|
+
stream: streamForConsumer,
|
|
2807
|
+
request: { body },
|
|
2808
|
+
response: { headers: responseHeaders }
|
|
2809
|
+
};
|
|
2831
2810
|
}
|
|
2832
2811
|
};
|
|
2833
2812
|
function getModelCapabilities(modelId) {
|