@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/dist/internal/index.js
CHANGED
|
@@ -2478,6 +2478,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2478
2478
|
};
|
|
2479
2479
|
}
|
|
2480
2480
|
async doStream(options) {
|
|
2481
|
+
var _a, _b;
|
|
2481
2482
|
const {
|
|
2482
2483
|
args: body,
|
|
2483
2484
|
warnings,
|
|
@@ -2516,25 +2517,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2516
2517
|
let isJsonResponseFromTool = false;
|
|
2517
2518
|
let blockType = void 0;
|
|
2518
2519
|
const generateId2 = this.generateId;
|
|
2519
|
-
let isFirstChunk = true;
|
|
2520
|
-
let stream = void 0;
|
|
2521
|
-
const returnPromise = new import_provider_utils11.DelayedPromise();
|
|
2522
2520
|
const transformedStream = response.pipeThrough(
|
|
2523
2521
|
new TransformStream({
|
|
2524
2522
|
start(controller) {
|
|
2525
2523
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2526
2524
|
},
|
|
2527
|
-
async flush() {
|
|
2528
|
-
if (returnPromise.isPending()) {
|
|
2529
|
-
returnPromise.resolve({
|
|
2530
|
-
stream,
|
|
2531
|
-
request: { body },
|
|
2532
|
-
response: { headers: responseHeaders }
|
|
2533
|
-
});
|
|
2534
|
-
}
|
|
2535
|
-
},
|
|
2536
2525
|
transform(chunk, controller) {
|
|
2537
|
-
var
|
|
2526
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2538
2527
|
if (options.includeRawChunks) {
|
|
2539
2528
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2540
2529
|
}
|
|
@@ -2542,29 +2531,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2542
2531
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2543
2532
|
return;
|
|
2544
2533
|
}
|
|
2545
|
-
if (isFirstChunk) {
|
|
2546
|
-
if (chunk.value.type === "error") {
|
|
2547
|
-
returnPromise.reject(
|
|
2548
|
-
new import_provider3.APICallError({
|
|
2549
|
-
message: chunk.value.error.message,
|
|
2550
|
-
url,
|
|
2551
|
-
requestBodyValues: body,
|
|
2552
|
-
statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
|
|
2553
|
-
responseHeaders,
|
|
2554
|
-
responseBody: JSON.stringify(chunk.value.error),
|
|
2555
|
-
isRetryable: chunk.value.error.type === "overloaded_error"
|
|
2556
|
-
})
|
|
2557
|
-
);
|
|
2558
|
-
controller.terminate();
|
|
2559
|
-
return;
|
|
2560
|
-
}
|
|
2561
|
-
isFirstChunk = false;
|
|
2562
|
-
returnPromise.resolve({
|
|
2563
|
-
stream,
|
|
2564
|
-
request: { body },
|
|
2565
|
-
response: { headers: responseHeaders }
|
|
2566
|
-
});
|
|
2567
|
-
}
|
|
2568
2534
|
const value = chunk.value;
|
|
2569
2535
|
switch (value.type) {
|
|
2570
2536
|
case "ping": {
|
|
@@ -2704,11 +2670,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2704
2670
|
toolCallId: part.tool_use_id,
|
|
2705
2671
|
toolName: "web_search",
|
|
2706
2672
|
result: part.content.map((result) => {
|
|
2707
|
-
var
|
|
2673
|
+
var _a3;
|
|
2708
2674
|
return {
|
|
2709
2675
|
url: result.url,
|
|
2710
2676
|
title: result.title,
|
|
2711
|
-
pageAge: (
|
|
2677
|
+
pageAge: (_a3 = result.page_age) != null ? _a3 : null,
|
|
2712
2678
|
encryptedContent: result.encrypted_content,
|
|
2713
2679
|
type: result.type
|
|
2714
2680
|
};
|
|
@@ -2723,7 +2689,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2723
2689
|
title: result.title,
|
|
2724
2690
|
providerMetadata: {
|
|
2725
2691
|
anthropic: {
|
|
2726
|
-
pageAge: (
|
|
2692
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null
|
|
2727
2693
|
}
|
|
2728
2694
|
}
|
|
2729
2695
|
});
|
|
@@ -2951,7 +2917,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2951
2917
|
}
|
|
2952
2918
|
case "message_start": {
|
|
2953
2919
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
2954
|
-
usage.cachedInputTokens = (
|
|
2920
|
+
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
2955
2921
|
rawUsage = {
|
|
2956
2922
|
...value.message.usage
|
|
2957
2923
|
};
|
|
@@ -3015,22 +2981,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3015
2981
|
})
|
|
3016
2982
|
);
|
|
3017
2983
|
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
3018
|
-
stream = streamForConsumer;
|
|
3019
2984
|
const firstChunkReader = streamForFirstChunk.getReader();
|
|
3020
2985
|
try {
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
2986
|
+
await firstChunkReader.read();
|
|
2987
|
+
let result = await firstChunkReader.read();
|
|
2988
|
+
if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
|
|
2989
|
+
result = await firstChunkReader.read();
|
|
3024
2990
|
}
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
2991
|
+
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
2992
|
+
const error = result.value.error;
|
|
2993
|
+
throw new import_provider3.APICallError({
|
|
2994
|
+
message: error.message,
|
|
2995
|
+
url,
|
|
2996
|
+
requestBodyValues: body,
|
|
2997
|
+
statusCode: error.type === "overloaded_error" ? 529 : 500,
|
|
2998
|
+
responseHeaders,
|
|
2999
|
+
responseBody: JSON.stringify(error),
|
|
3000
|
+
isRetryable: error.type === "overloaded_error"
|
|
3001
|
+
});
|
|
3029
3002
|
}
|
|
3030
3003
|
} finally {
|
|
3004
|
+
firstChunkReader.cancel().catch(() => {
|
|
3005
|
+
});
|
|
3031
3006
|
firstChunkReader.releaseLock();
|
|
3032
3007
|
}
|
|
3033
|
-
return
|
|
3008
|
+
return {
|
|
3009
|
+
stream: streamForConsumer,
|
|
3010
|
+
request: { body },
|
|
3011
|
+
response: { headers: responseHeaders }
|
|
3012
|
+
};
|
|
3034
3013
|
}
|
|
3035
3014
|
};
|
|
3036
3015
|
function getModelCapabilities(modelId) {
|