@ai-sdk/anthropic 3.0.0-beta.67 → 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 +12 -0
- package/dist/index.js +30 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -54
- 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 +31 -53
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -11,18 +11,17 @@ import {
|
|
|
11
11
|
} from "@ai-sdk/provider-utils";
|
|
12
12
|
|
|
13
13
|
// src/version.ts
|
|
14
|
-
var VERSION = true ? "3.0.0-beta.
|
|
14
|
+
var VERSION = true ? "3.0.0-beta.69" : "0.0.0-test";
|
|
15
15
|
|
|
16
16
|
// src/anthropic-messages-language-model.ts
|
|
17
17
|
import {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
APICallError,
|
|
19
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
20
20
|
} from "@ai-sdk/provider";
|
|
21
21
|
import {
|
|
22
22
|
combineHeaders,
|
|
23
23
|
createEventSourceResponseHandler,
|
|
24
24
|
createJsonResponseHandler,
|
|
25
|
-
DelayedPromise,
|
|
26
25
|
generateId,
|
|
27
26
|
parseProviderOptions as parseProviderOptions2,
|
|
28
27
|
postJsonToApi,
|
|
@@ -2506,6 +2505,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2506
2505
|
};
|
|
2507
2506
|
}
|
|
2508
2507
|
async doStream(options) {
|
|
2508
|
+
var _a, _b;
|
|
2509
2509
|
const {
|
|
2510
2510
|
args: body,
|
|
2511
2511
|
warnings,
|
|
@@ -2544,25 +2544,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2544
2544
|
let isJsonResponseFromTool = false;
|
|
2545
2545
|
let blockType = void 0;
|
|
2546
2546
|
const generateId3 = this.generateId;
|
|
2547
|
-
let isFirstChunk = true;
|
|
2548
|
-
let stream = void 0;
|
|
2549
|
-
const returnPromise = new DelayedPromise();
|
|
2550
2547
|
const transformedStream = response.pipeThrough(
|
|
2551
2548
|
new TransformStream({
|
|
2552
2549
|
start(controller) {
|
|
2553
2550
|
controller.enqueue({ type: "stream-start", warnings });
|
|
2554
2551
|
},
|
|
2555
|
-
async flush() {
|
|
2556
|
-
if (returnPromise.isPending()) {
|
|
2557
|
-
returnPromise.resolve({
|
|
2558
|
-
stream,
|
|
2559
|
-
request: { body },
|
|
2560
|
-
response: { headers: responseHeaders }
|
|
2561
|
-
});
|
|
2562
|
-
}
|
|
2563
|
-
},
|
|
2564
2552
|
transform(chunk, controller) {
|
|
2565
|
-
var
|
|
2553
|
+
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2566
2554
|
if (options.includeRawChunks) {
|
|
2567
2555
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2568
2556
|
}
|
|
@@ -2570,29 +2558,6 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2570
2558
|
controller.enqueue({ type: "error", error: chunk.error });
|
|
2571
2559
|
return;
|
|
2572
2560
|
}
|
|
2573
|
-
if (isFirstChunk) {
|
|
2574
|
-
if (chunk.value.type === "error") {
|
|
2575
|
-
returnPromise.reject(
|
|
2576
|
-
new APICallError({
|
|
2577
|
-
message: chunk.value.error.message,
|
|
2578
|
-
url,
|
|
2579
|
-
requestBodyValues: body,
|
|
2580
|
-
statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
|
|
2581
|
-
responseHeaders,
|
|
2582
|
-
responseBody: JSON.stringify(chunk.value.error),
|
|
2583
|
-
isRetryable: chunk.value.error.type === "overloaded_error"
|
|
2584
|
-
})
|
|
2585
|
-
);
|
|
2586
|
-
controller.terminate();
|
|
2587
|
-
return;
|
|
2588
|
-
}
|
|
2589
|
-
isFirstChunk = false;
|
|
2590
|
-
returnPromise.resolve({
|
|
2591
|
-
stream,
|
|
2592
|
-
request: { body },
|
|
2593
|
-
response: { headers: responseHeaders }
|
|
2594
|
-
});
|
|
2595
|
-
}
|
|
2596
2561
|
const value = chunk.value;
|
|
2597
2562
|
switch (value.type) {
|
|
2598
2563
|
case "ping": {
|
|
@@ -2732,11 +2697,11 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2732
2697
|
toolCallId: part.tool_use_id,
|
|
2733
2698
|
toolName: "web_search",
|
|
2734
2699
|
result: part.content.map((result) => {
|
|
2735
|
-
var
|
|
2700
|
+
var _a3;
|
|
2736
2701
|
return {
|
|
2737
2702
|
url: result.url,
|
|
2738
2703
|
title: result.title,
|
|
2739
|
-
pageAge: (
|
|
2704
|
+
pageAge: (_a3 = result.page_age) != null ? _a3 : null,
|
|
2740
2705
|
encryptedContent: result.encrypted_content,
|
|
2741
2706
|
type: result.type
|
|
2742
2707
|
};
|
|
@@ -2751,7 +2716,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2751
2716
|
title: result.title,
|
|
2752
2717
|
providerMetadata: {
|
|
2753
2718
|
anthropic: {
|
|
2754
|
-
pageAge: (
|
|
2719
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null
|
|
2755
2720
|
}
|
|
2756
2721
|
}
|
|
2757
2722
|
});
|
|
@@ -2877,7 +2842,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2877
2842
|
type: "tool-call",
|
|
2878
2843
|
toolCallId: contentBlock.toolCallId,
|
|
2879
2844
|
toolName,
|
|
2880
|
-
input: contentBlock.input,
|
|
2845
|
+
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
2881
2846
|
providerExecuted: contentBlock.providerExecuted
|
|
2882
2847
|
});
|
|
2883
2848
|
}
|
|
@@ -2979,7 +2944,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2979
2944
|
}
|
|
2980
2945
|
case "message_start": {
|
|
2981
2946
|
usage.inputTokens = value.message.usage.input_tokens;
|
|
2982
|
-
usage.cachedInputTokens = (
|
|
2947
|
+
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
2983
2948
|
rawUsage = {
|
|
2984
2949
|
...value.message.usage
|
|
2985
2950
|
};
|
|
@@ -3043,22 +3008,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3043
3008
|
})
|
|
3044
3009
|
);
|
|
3045
3010
|
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
3046
|
-
stream = streamForConsumer;
|
|
3047
3011
|
const firstChunkReader = streamForFirstChunk.getReader();
|
|
3048
3012
|
try {
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3013
|
+
await firstChunkReader.read();
|
|
3014
|
+
let result = await firstChunkReader.read();
|
|
3015
|
+
if (((_a = result.value) == null ? void 0 : _a.type) === "raw") {
|
|
3016
|
+
result = await firstChunkReader.read();
|
|
3052
3017
|
}
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3018
|
+
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
3019
|
+
const error = result.value.error;
|
|
3020
|
+
throw new APICallError({
|
|
3021
|
+
message: error.message,
|
|
3022
|
+
url,
|
|
3023
|
+
requestBodyValues: body,
|
|
3024
|
+
statusCode: error.type === "overloaded_error" ? 529 : 500,
|
|
3025
|
+
responseHeaders,
|
|
3026
|
+
responseBody: JSON.stringify(error),
|
|
3027
|
+
isRetryable: error.type === "overloaded_error"
|
|
3028
|
+
});
|
|
3057
3029
|
}
|
|
3058
3030
|
} finally {
|
|
3031
|
+
firstChunkReader.cancel().catch(() => {
|
|
3032
|
+
});
|
|
3059
3033
|
firstChunkReader.releaseLock();
|
|
3060
3034
|
}
|
|
3061
|
-
return
|
|
3035
|
+
return {
|
|
3036
|
+
stream: streamForConsumer,
|
|
3037
|
+
request: { body },
|
|
3038
|
+
response: { headers: responseHeaders }
|
|
3039
|
+
};
|
|
3062
3040
|
}
|
|
3063
3041
|
};
|
|
3064
3042
|
function getModelCapabilities(modelId) {
|