@ai-sdk/anthropic 3.0.0-beta.68 → 3.0.0-beta.69
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 +6 -0
- package/dist/index.js +29 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -53
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +28 -49
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +30 -52
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
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 ? "3.0.0-beta.
|
|
34
|
+
var VERSION = true ? "3.0.0-beta.69" : "0.0.0-test";
|
|
35
35
|
|
|
36
36
|
// src/anthropic-messages-language-model.ts
|
|
37
37
|
var import_provider3 = require("@ai-sdk/provider");
|
|
@@ -2485,6 +2485,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2485
2485
|
};
|
|
2486
2486
|
}
|
|
2487
2487
|
async doStream(options) {
|
|
2488
|
+
var _a, _b;
|
|
2488
2489
|
const {
|
|
2489
2490
|
args: body,
|
|
2490
2491
|
warnings,
|
|
@@ -2523,25 +2524,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2523
2524
|
let isJsonResponseFromTool = false;
|
|
2524
2525
|
let blockType = void 0;
|
|
2525
2526
|
const generateId3 = this.generateId;
|
|
2526
|
-
let isFirstChunk = true;
|
|
2527
|
-
let stream = void 0;
|
|
2528
|
-
const returnPromise = new import_provider_utils11.DelayedPromise();
|
|
2529
2527
|
const transformedStream = response.pipeThrough(
|
|
2530
2528
|
new TransformStream({
|
|
2531
2529
|
start(controller) {
|
|
2532
2530
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2533
2531
|
},
|
|
2534
|
-
async flush() {
|
|
2535
|
-
if (returnPromise.isPending()) {
|
|
2536
|
-
returnPromise.resolve({
|
|
2537
|
-
stream,
|
|
2538
|
-
request: { body },
|
|
2539
|
-
response: { headers: responseHeaders }
|
|
2540
|
-
});
|
|
2541
|
-
}
|
|
2542
|
-
},
|
|
2543
2532
|
transform(chunk, controller) {
|
|
2544
|
-
var
|
|
2533
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2545
2534
|
if (options.includeRawChunks) {
|
|
2546
2535
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2547
2536
|
}
|
|
@@ -2549,29 +2538,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2549
2538
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2550
2539
|
return;
|
|
2551
2540
|
}
|
|
2552
|
-
if (isFirstChunk) {
|
|
2553
|
-
if (chunk.value.type === "error") {
|
|
2554
|
-
returnPromise.reject(
|
|
2555
|
-
new import_provider3.APICallError({
|
|
2556
|
-
message: chunk.value.error.message,
|
|
2557
|
-
url,
|
|
2558
|
-
requestBodyValues: body,
|
|
2559
|
-
statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
|
|
2560
|
-
responseHeaders,
|
|
2561
|
-
responseBody: JSON.stringify(chunk.value.error),
|
|
2562
|
-
isRetryable: chunk.value.error.type === "overloaded_error"
|
|
2563
|
-
})
|
|
2564
|
-
);
|
|
2565
|
-
controller.terminate();
|
|
2566
|
-
return;
|
|
2567
|
-
}
|
|
2568
|
-
isFirstChunk = false;
|
|
2569
|
-
returnPromise.resolve({
|
|
2570
|
-
stream,
|
|
2571
|
-
request: { body },
|
|
2572
|
-
response: { headers: responseHeaders }
|
|
2573
|
-
});
|
|
2574
|
-
}
|
|
2575
2541
|
const value = chunk.value;
|
|
2576
2542
|
switch (value.type) {
|
|
2577
2543
|
case "ping": {
|
|
@@ -2711,11 +2677,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2711
2677
|
toolCallId: part.tool_use_id,
|
|
2712
2678
|
toolName: "web_search",
|
|
2713
2679
|
result: part.content.map((result) => {
|
|
2714
|
-
var
|
|
2680
|
+
var _a3;
|
|
2715
2681
|
return {
|
|
2716
2682
|
url: result.url,
|
|
2717
2683
|
title: result.title,
|
|
2718
|
-
pageAge: (
|
|
2684
|
+
pageAge: (_a3 = result.page_age) != null ? _a3 : null,
|
|
2719
2685
|
encryptedContent: result.encrypted_content,
|
|
2720
2686
|
type: result.type
|
|
2721
2687
|
};
|
|
@@ -2730,7 +2696,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2730
2696
|
title: result.title,
|
|
2731
2697
|
providerMetadata: {
|
|
2732
2698
|
anthropic: {
|
|
2733
|
-
pageAge: (
|
|
2699
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null
|
|
2734
2700
|
}
|
|
2735
2701
|
}
|
|
2736
2702
|
});
|
|
@@ -2958,7 +2924,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2958
2924
|
}
|
|
2959
2925
|
case "message_start": {
|
|
2960
2926
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
2961
|
-
usage.cachedInputTokens = (
|
|
2927
|
+
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
2962
2928
|
rawUsage = {
|
|
2963
2929
|
...value.message.usage
|
|
2964
2930
|
};
|
|
@@ -3022,22 +2988,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3022
2988
|
})
|
|
3023
2989
|
);
|
|
3024
2990
|
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
3025
|
-
stream = streamForConsumer;
|
|
3026
2991
|
const firstChunkReader = streamForFirstChunk.getReader();
|
|
3027
2992
|
try {
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
2993
|
+
await firstChunkReader.read();
|
|
2994
|
+
let result = await firstChunkReader.read();
|
|
2995
|
+
if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
|
|
2996
|
+
result = await firstChunkReader.read();
|
|
3031
2997
|
}
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
2998
|
+
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
2999
|
+
const error = result.value.error;
|
|
3000
|
+
throw new import_provider3.APICallError({
|
|
3001
|
+
message: error.message,
|
|
3002
|
+
url,
|
|
3003
|
+
requestBodyValues: body,
|
|
3004
|
+
statusCode: error.type === "overloaded_error" ? 529 : 500,
|
|
3005
|
+
responseHeaders,
|
|
3006
|
+
responseBody: JSON.stringify(error),
|
|
3007
|
+
isRetryable: error.type === "overloaded_error"
|
|
3008
|
+
});
|
|
3036
3009
|
}
|
|
3037
3010
|
} finally {
|
|
3011
|
+
firstChunkReader.cancel().catch(() => {
|
|
3012
|
+
});
|
|
3038
3013
|
firstChunkReader.releaseLock();
|
|
3039
3014
|
}
|
|
3040
|
-
return
|
|
3015
|
+
return {
|
|
3016
|
+
stream: streamForConsumer,
|
|
3017
|
+
request: { body },
|
|
3018
|
+
response: { headers: responseHeaders }
|
|
3019
|
+
};
|
|
3041
3020
|
}
|
|
3042
3021
|
};
|
|
3043
3022
|
function getModelCapabilities(modelId) {
|