@ai-sdk/anthropic 3.0.0-beta.62 → 3.0.0-beta.64
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 +17 -0
- package/dist/index.js +485 -437
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +488 -438
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +3 -3
- package/dist/internal/index.d.ts +3 -3
- package/dist/internal/index.js +484 -436
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +487 -437
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/internal/index.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// src/anthropic-messages-language-model.ts
|
|
2
2
|
import {
|
|
3
|
-
UnsupportedFunctionalityError as UnsupportedFunctionalityError3
|
|
3
|
+
UnsupportedFunctionalityError as UnsupportedFunctionalityError3,
|
|
4
|
+
APICallError
|
|
4
5
|
} from "@ai-sdk/provider";
|
|
5
6
|
import {
|
|
6
7
|
combineHeaders,
|
|
7
8
|
createEventSourceResponseHandler,
|
|
8
9
|
createJsonResponseHandler,
|
|
10
|
+
DelayedPromise,
|
|
9
11
|
generateId,
|
|
10
12
|
parseProviderOptions as parseProviderOptions2,
|
|
11
13
|
postJsonToApi,
|
|
@@ -673,8 +675,8 @@ var CacheControlValidator = class {
|
|
|
673
675
|
}
|
|
674
676
|
if (!context.canCache) {
|
|
675
677
|
this.warnings.push({
|
|
676
|
-
type: "unsupported
|
|
677
|
-
|
|
678
|
+
type: "unsupported",
|
|
679
|
+
feature: "cache_control on non-cacheable context",
|
|
678
680
|
details: `cache_control cannot be set on ${context.type}. It will be ignored.`
|
|
679
681
|
});
|
|
680
682
|
return void 0;
|
|
@@ -682,8 +684,8 @@ var CacheControlValidator = class {
|
|
|
682
684
|
this.breakpointCount++;
|
|
683
685
|
if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
|
|
684
686
|
this.warnings.push({
|
|
685
|
-
type: "unsupported
|
|
686
|
-
|
|
687
|
+
type: "unsupported",
|
|
688
|
+
feature: "cacheControl breakpoint limit",
|
|
687
689
|
details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
|
|
688
690
|
});
|
|
689
691
|
return void 0;
|
|
@@ -1017,14 +1019,20 @@ async function prepareTools({
|
|
|
1017
1019
|
break;
|
|
1018
1020
|
}
|
|
1019
1021
|
default: {
|
|
1020
|
-
toolWarnings.push({
|
|
1022
|
+
toolWarnings.push({
|
|
1023
|
+
type: "unsupported",
|
|
1024
|
+
feature: `provider-defined tool ${tool.id}`
|
|
1025
|
+
});
|
|
1021
1026
|
break;
|
|
1022
1027
|
}
|
|
1023
1028
|
}
|
|
1024
1029
|
break;
|
|
1025
1030
|
}
|
|
1026
1031
|
default: {
|
|
1027
|
-
toolWarnings.push({
|
|
1032
|
+
toolWarnings.push({
|
|
1033
|
+
type: "unsupported",
|
|
1034
|
+
feature: `tool ${tool}`
|
|
1035
|
+
});
|
|
1028
1036
|
break;
|
|
1029
1037
|
}
|
|
1030
1038
|
}
|
|
@@ -1926,34 +1934,25 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1926
1934
|
var _a, _b, _c, _d, _e, _f;
|
|
1927
1935
|
const warnings = [];
|
|
1928
1936
|
if (frequencyPenalty != null) {
|
|
1929
|
-
warnings.push({
|
|
1930
|
-
type: "unsupported-setting",
|
|
1931
|
-
setting: "frequencyPenalty"
|
|
1932
|
-
});
|
|
1937
|
+
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
1933
1938
|
}
|
|
1934
1939
|
if (presencePenalty != null) {
|
|
1935
|
-
warnings.push({
|
|
1936
|
-
type: "unsupported-setting",
|
|
1937
|
-
setting: "presencePenalty"
|
|
1938
|
-
});
|
|
1940
|
+
warnings.push({ type: "unsupported", feature: "presencePenalty" });
|
|
1939
1941
|
}
|
|
1940
1942
|
if (seed != null) {
|
|
1941
|
-
warnings.push({
|
|
1942
|
-
type: "unsupported-setting",
|
|
1943
|
-
setting: "seed"
|
|
1944
|
-
});
|
|
1943
|
+
warnings.push({ type: "unsupported", feature: "seed" });
|
|
1945
1944
|
}
|
|
1946
1945
|
if (temperature != null && temperature > 1) {
|
|
1947
1946
|
warnings.push({
|
|
1948
|
-
type: "unsupported
|
|
1949
|
-
|
|
1947
|
+
type: "unsupported",
|
|
1948
|
+
feature: "temperature",
|
|
1950
1949
|
details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
|
|
1951
1950
|
});
|
|
1952
1951
|
temperature = 1;
|
|
1953
1952
|
} else if (temperature != null && temperature < 0) {
|
|
1954
1953
|
warnings.push({
|
|
1955
|
-
type: "unsupported
|
|
1956
|
-
|
|
1954
|
+
type: "unsupported",
|
|
1955
|
+
feature: "temperature",
|
|
1957
1956
|
details: `${temperature} is below anthropic minimum of 0. clamped to 0`
|
|
1958
1957
|
});
|
|
1959
1958
|
temperature = 0;
|
|
@@ -1961,8 +1960,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
1961
1960
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
1962
1961
|
if (responseFormat.schema == null) {
|
|
1963
1962
|
warnings.push({
|
|
1964
|
-
type: "unsupported
|
|
1965
|
-
|
|
1963
|
+
type: "unsupported",
|
|
1964
|
+
feature: "responseFormat",
|
|
1966
1965
|
details: "JSON response format requires a schema. The response format is ignored."
|
|
1967
1966
|
});
|
|
1968
1967
|
}
|
|
@@ -2055,24 +2054,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2055
2054
|
if (baseArgs.temperature != null) {
|
|
2056
2055
|
baseArgs.temperature = void 0;
|
|
2057
2056
|
warnings.push({
|
|
2058
|
-
type: "unsupported
|
|
2059
|
-
|
|
2057
|
+
type: "unsupported",
|
|
2058
|
+
feature: "temperature",
|
|
2060
2059
|
details: "temperature is not supported when thinking is enabled"
|
|
2061
2060
|
});
|
|
2062
2061
|
}
|
|
2063
2062
|
if (topK != null) {
|
|
2064
2063
|
baseArgs.top_k = void 0;
|
|
2065
2064
|
warnings.push({
|
|
2066
|
-
type: "unsupported
|
|
2067
|
-
|
|
2065
|
+
type: "unsupported",
|
|
2066
|
+
feature: "topK",
|
|
2068
2067
|
details: "topK is not supported when thinking is enabled"
|
|
2069
2068
|
});
|
|
2070
2069
|
}
|
|
2071
2070
|
if (topP != null) {
|
|
2072
2071
|
baseArgs.top_p = void 0;
|
|
2073
2072
|
warnings.push({
|
|
2074
|
-
type: "unsupported
|
|
2075
|
-
|
|
2073
|
+
type: "unsupported",
|
|
2074
|
+
feature: "topP",
|
|
2076
2075
|
details: "topP is not supported when thinking is enabled"
|
|
2077
2076
|
});
|
|
2078
2077
|
}
|
|
@@ -2081,8 +2080,8 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2081
2080
|
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
2082
2081
|
if (maxOutputTokens != null) {
|
|
2083
2082
|
warnings.push({
|
|
2084
|
-
type: "unsupported
|
|
2085
|
-
|
|
2083
|
+
type: "unsupported",
|
|
2084
|
+
feature: "maxOutputTokens",
|
|
2086
2085
|
details: `${baseArgs.max_tokens} (maxOutputTokens + thinkingBudget) is greater than ${this.modelId} ${maxOutputTokensForModel} max output tokens. The max output tokens have been limited to ${maxOutputTokensForModel}.`
|
|
2087
2086
|
});
|
|
2088
2087
|
}
|
|
@@ -2508,8 +2507,9 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2508
2507
|
userSuppliedBetas: await this.getBetasFromHeaders(options.headers)
|
|
2509
2508
|
});
|
|
2510
2509
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
2510
|
+
const url = this.buildRequestUrl(true);
|
|
2511
2511
|
const { responseHeaders, value: response } = await postJsonToApi({
|
|
2512
|
-
url
|
|
2512
|
+
url,
|
|
2513
2513
|
headers: await this.getHeaders({ betas, headers: options.headers }),
|
|
2514
2514
|
body: this.transformRequestBody(body),
|
|
2515
2515
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
@@ -2534,473 +2534,523 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2534
2534
|
let isJsonResponseFromTool = false;
|
|
2535
2535
|
let blockType = void 0;
|
|
2536
2536
|
const generateId2 = this.generateId;
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2537
|
+
let isFirstChunk = true;
|
|
2538
|
+
let stream = void 0;
|
|
2539
|
+
const returnPromise = new DelayedPromise();
|
|
2540
|
+
const transformedStream = response.pipeThrough(
|
|
2541
|
+
new TransformStream({
|
|
2542
|
+
start(controller) {
|
|
2543
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
2544
|
+
},
|
|
2545
|
+
async flush() {
|
|
2546
|
+
if (returnPromise.isPending()) {
|
|
2547
|
+
returnPromise.resolve({
|
|
2548
|
+
stream,
|
|
2549
|
+
request: { body },
|
|
2550
|
+
response: { headers: responseHeaders }
|
|
2551
|
+
});
|
|
2552
|
+
}
|
|
2553
|
+
},
|
|
2554
|
+
transform(chunk, controller) {
|
|
2555
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2556
|
+
if (options.includeRawChunks) {
|
|
2557
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
2558
|
+
}
|
|
2559
|
+
if (!chunk.success) {
|
|
2560
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
2561
|
+
return;
|
|
2562
|
+
}
|
|
2563
|
+
if (isFirstChunk) {
|
|
2564
|
+
if (chunk.value.type === "error") {
|
|
2565
|
+
returnPromise.reject(
|
|
2566
|
+
new APICallError({
|
|
2567
|
+
message: chunk.value.error.message,
|
|
2568
|
+
url,
|
|
2569
|
+
requestBodyValues: body,
|
|
2570
|
+
statusCode: chunk.value.error.type === "overloaded_error" ? 529 : 500,
|
|
2571
|
+
responseHeaders,
|
|
2572
|
+
responseBody: JSON.stringify(chunk.value.error),
|
|
2573
|
+
isRetryable: chunk.value.error.type === "overloaded_error"
|
|
2574
|
+
})
|
|
2575
|
+
);
|
|
2576
|
+
controller.terminate();
|
|
2577
|
+
return;
|
|
2547
2578
|
}
|
|
2548
|
-
|
|
2549
|
-
|
|
2579
|
+
isFirstChunk = false;
|
|
2580
|
+
returnPromise.resolve({
|
|
2581
|
+
stream,
|
|
2582
|
+
request: { body },
|
|
2583
|
+
response: { headers: responseHeaders }
|
|
2584
|
+
});
|
|
2585
|
+
}
|
|
2586
|
+
const value = chunk.value;
|
|
2587
|
+
switch (value.type) {
|
|
2588
|
+
case "ping": {
|
|
2550
2589
|
return;
|
|
2551
2590
|
}
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2591
|
+
case "content_block_start": {
|
|
2592
|
+
const part = value.content_block;
|
|
2593
|
+
const contentBlockType = part.type;
|
|
2594
|
+
blockType = contentBlockType;
|
|
2595
|
+
switch (contentBlockType) {
|
|
2596
|
+
case "text": {
|
|
2597
|
+
if (usesJsonResponseTool) {
|
|
2598
|
+
return;
|
|
2599
|
+
}
|
|
2600
|
+
contentBlocks[value.index] = { type: "text" };
|
|
2601
|
+
controller.enqueue({
|
|
2602
|
+
type: "text-start",
|
|
2603
|
+
id: String(value.index)
|
|
2604
|
+
});
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
case "thinking": {
|
|
2608
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
2609
|
+
controller.enqueue({
|
|
2610
|
+
type: "reasoning-start",
|
|
2611
|
+
id: String(value.index)
|
|
2612
|
+
});
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
case "redacted_thinking": {
|
|
2616
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
2617
|
+
controller.enqueue({
|
|
2618
|
+
type: "reasoning-start",
|
|
2619
|
+
id: String(value.index),
|
|
2620
|
+
providerMetadata: {
|
|
2621
|
+
anthropic: {
|
|
2622
|
+
redactedData: part.data
|
|
2623
|
+
}
|
|
2565
2624
|
}
|
|
2625
|
+
});
|
|
2626
|
+
return;
|
|
2627
|
+
}
|
|
2628
|
+
case "tool_use": {
|
|
2629
|
+
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2630
|
+
if (isJsonResponseTool) {
|
|
2631
|
+
isJsonResponseFromTool = true;
|
|
2566
2632
|
contentBlocks[value.index] = { type: "text" };
|
|
2567
2633
|
controller.enqueue({
|
|
2568
2634
|
type: "text-start",
|
|
2569
2635
|
id: String(value.index)
|
|
2570
2636
|
});
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2637
|
+
} else {
|
|
2638
|
+
contentBlocks[value.index] = {
|
|
2639
|
+
type: "tool-call",
|
|
2640
|
+
toolCallId: part.id,
|
|
2641
|
+
toolName: part.name,
|
|
2642
|
+
input: "",
|
|
2643
|
+
firstDelta: true
|
|
2644
|
+
};
|
|
2575
2645
|
controller.enqueue({
|
|
2576
|
-
type: "
|
|
2577
|
-
id:
|
|
2646
|
+
type: "tool-input-start",
|
|
2647
|
+
id: part.id,
|
|
2648
|
+
toolName: part.name
|
|
2578
2649
|
});
|
|
2579
|
-
return;
|
|
2580
2650
|
}
|
|
2581
|
-
|
|
2582
|
-
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
case "server_tool_use": {
|
|
2654
|
+
if ([
|
|
2655
|
+
"web_fetch",
|
|
2656
|
+
"web_search",
|
|
2657
|
+
// code execution 20250825:
|
|
2658
|
+
"code_execution",
|
|
2659
|
+
// code execution 20250825 text editor:
|
|
2660
|
+
"text_editor_code_execution",
|
|
2661
|
+
// code execution 20250825 bash:
|
|
2662
|
+
"bash_code_execution"
|
|
2663
|
+
].includes(part.name)) {
|
|
2664
|
+
contentBlocks[value.index] = {
|
|
2665
|
+
type: "tool-call",
|
|
2666
|
+
toolCallId: part.id,
|
|
2667
|
+
toolName: part.name,
|
|
2668
|
+
input: "",
|
|
2669
|
+
providerExecuted: true,
|
|
2670
|
+
firstDelta: true
|
|
2671
|
+
};
|
|
2672
|
+
const mappedToolName = part.name === "text_editor_code_execution" || part.name === "bash_code_execution" ? "code_execution" : part.name;
|
|
2583
2673
|
controller.enqueue({
|
|
2584
|
-
type: "
|
|
2585
|
-
id:
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
redactedData: part.data
|
|
2589
|
-
}
|
|
2590
|
-
}
|
|
2674
|
+
type: "tool-input-start",
|
|
2675
|
+
id: part.id,
|
|
2676
|
+
toolName: mappedToolName,
|
|
2677
|
+
providerExecuted: true
|
|
2591
2678
|
});
|
|
2592
|
-
return;
|
|
2593
|
-
}
|
|
2594
|
-
case "tool_use": {
|
|
2595
|
-
const isJsonResponseTool = usesJsonResponseTool && part.name === "json";
|
|
2596
|
-
if (isJsonResponseTool) {
|
|
2597
|
-
isJsonResponseFromTool = true;
|
|
2598
|
-
contentBlocks[value.index] = { type: "text" };
|
|
2599
|
-
controller.enqueue({
|
|
2600
|
-
type: "text-start",
|
|
2601
|
-
id: String(value.index)
|
|
2602
|
-
});
|
|
2603
|
-
} else {
|
|
2604
|
-
contentBlocks[value.index] = {
|
|
2605
|
-
type: "tool-call",
|
|
2606
|
-
toolCallId: part.id,
|
|
2607
|
-
toolName: part.name,
|
|
2608
|
-
input: "",
|
|
2609
|
-
firstDelta: true
|
|
2610
|
-
};
|
|
2611
|
-
controller.enqueue({
|
|
2612
|
-
type: "tool-input-start",
|
|
2613
|
-
id: part.id,
|
|
2614
|
-
toolName: part.name
|
|
2615
|
-
});
|
|
2616
|
-
}
|
|
2617
|
-
return;
|
|
2618
2679
|
}
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
"
|
|
2625
|
-
|
|
2626
|
-
"
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
controller.enqueue({
|
|
2640
|
-
type: "tool-input-start",
|
|
2641
|
-
id: part.id,
|
|
2642
|
-
toolName: mappedToolName,
|
|
2643
|
-
providerExecuted: true
|
|
2644
|
-
});
|
|
2645
|
-
}
|
|
2646
|
-
return;
|
|
2647
|
-
}
|
|
2648
|
-
case "web_fetch_tool_result": {
|
|
2649
|
-
if (part.content.type === "web_fetch_result") {
|
|
2650
|
-
controller.enqueue({
|
|
2651
|
-
type: "tool-result",
|
|
2652
|
-
toolCallId: part.tool_use_id,
|
|
2653
|
-
toolName: "web_fetch",
|
|
2654
|
-
result: {
|
|
2655
|
-
type: "web_fetch_result",
|
|
2656
|
-
url: part.content.url,
|
|
2657
|
-
retrievedAt: part.content.retrieved_at,
|
|
2658
|
-
content: {
|
|
2659
|
-
type: part.content.content.type,
|
|
2660
|
-
title: part.content.content.title,
|
|
2661
|
-
citations: part.content.content.citations,
|
|
2662
|
-
source: {
|
|
2663
|
-
type: part.content.content.source.type,
|
|
2664
|
-
mediaType: part.content.content.source.media_type,
|
|
2665
|
-
data: part.content.content.source.data
|
|
2666
|
-
}
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2682
|
+
case "web_fetch_tool_result": {
|
|
2683
|
+
if (part.content.type === "web_fetch_result") {
|
|
2684
|
+
controller.enqueue({
|
|
2685
|
+
type: "tool-result",
|
|
2686
|
+
toolCallId: part.tool_use_id,
|
|
2687
|
+
toolName: "web_fetch",
|
|
2688
|
+
result: {
|
|
2689
|
+
type: "web_fetch_result",
|
|
2690
|
+
url: part.content.url,
|
|
2691
|
+
retrievedAt: part.content.retrieved_at,
|
|
2692
|
+
content: {
|
|
2693
|
+
type: part.content.content.type,
|
|
2694
|
+
title: part.content.content.title,
|
|
2695
|
+
citations: part.content.content.citations,
|
|
2696
|
+
source: {
|
|
2697
|
+
type: part.content.content.source.type,
|
|
2698
|
+
mediaType: part.content.content.source.media_type,
|
|
2699
|
+
data: part.content.content.source.data
|
|
2667
2700
|
}
|
|
2668
2701
|
}
|
|
2669
|
-
}
|
|
2670
|
-
}
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
}
|
|
2681
|
-
}
|
|
2682
|
-
return;
|
|
2702
|
+
}
|
|
2703
|
+
});
|
|
2704
|
+
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
2705
|
+
controller.enqueue({
|
|
2706
|
+
type: "tool-result",
|
|
2707
|
+
toolCallId: part.tool_use_id,
|
|
2708
|
+
toolName: "web_fetch",
|
|
2709
|
+
isError: true,
|
|
2710
|
+
result: {
|
|
2711
|
+
type: "web_fetch_tool_result_error",
|
|
2712
|
+
errorCode: part.content.error_code
|
|
2713
|
+
}
|
|
2714
|
+
});
|
|
2683
2715
|
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
2696
|
-
encryptedContent: result.encrypted_content,
|
|
2697
|
-
type: result.type
|
|
2698
|
-
};
|
|
2699
|
-
})
|
|
2700
|
-
});
|
|
2701
|
-
for (const result of part.content) {
|
|
2702
|
-
controller.enqueue({
|
|
2703
|
-
type: "source",
|
|
2704
|
-
sourceType: "url",
|
|
2705
|
-
id: generateId2(),
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
case "web_search_tool_result": {
|
|
2719
|
+
if (Array.isArray(part.content)) {
|
|
2720
|
+
controller.enqueue({
|
|
2721
|
+
type: "tool-result",
|
|
2722
|
+
toolCallId: part.tool_use_id,
|
|
2723
|
+
toolName: "web_search",
|
|
2724
|
+
result: part.content.map((result) => {
|
|
2725
|
+
var _a2;
|
|
2726
|
+
return {
|
|
2706
2727
|
url: result.url,
|
|
2707
2728
|
title: result.title,
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
} else {
|
|
2716
|
-
controller.enqueue({
|
|
2717
|
-
type: "tool-result",
|
|
2718
|
-
toolCallId: part.tool_use_id,
|
|
2719
|
-
toolName: "web_search",
|
|
2720
|
-
isError: true,
|
|
2721
|
-
result: {
|
|
2722
|
-
type: "web_search_tool_result_error",
|
|
2723
|
-
errorCode: part.content.error_code
|
|
2724
|
-
}
|
|
2725
|
-
});
|
|
2726
|
-
}
|
|
2727
|
-
return;
|
|
2728
|
-
}
|
|
2729
|
-
// code execution 20250522:
|
|
2730
|
-
case "code_execution_tool_result": {
|
|
2731
|
-
if (part.content.type === "code_execution_result") {
|
|
2732
|
-
controller.enqueue({
|
|
2733
|
-
type: "tool-result",
|
|
2734
|
-
toolCallId: part.tool_use_id,
|
|
2735
|
-
toolName: "code_execution",
|
|
2736
|
-
result: {
|
|
2737
|
-
type: part.content.type,
|
|
2738
|
-
stdout: part.content.stdout,
|
|
2739
|
-
stderr: part.content.stderr,
|
|
2740
|
-
return_code: part.content.return_code
|
|
2741
|
-
}
|
|
2742
|
-
});
|
|
2743
|
-
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
2729
|
+
pageAge: (_a2 = result.page_age) != null ? _a2 : null,
|
|
2730
|
+
encryptedContent: result.encrypted_content,
|
|
2731
|
+
type: result.type
|
|
2732
|
+
};
|
|
2733
|
+
})
|
|
2734
|
+
});
|
|
2735
|
+
for (const result of part.content) {
|
|
2744
2736
|
controller.enqueue({
|
|
2745
|
-
type: "
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2737
|
+
type: "source",
|
|
2738
|
+
sourceType: "url",
|
|
2739
|
+
id: generateId2(),
|
|
2740
|
+
url: result.url,
|
|
2741
|
+
title: result.title,
|
|
2742
|
+
providerMetadata: {
|
|
2743
|
+
anthropic: {
|
|
2744
|
+
pageAge: (_a = result.page_age) != null ? _a : null
|
|
2745
|
+
}
|
|
2752
2746
|
}
|
|
2753
2747
|
});
|
|
2754
2748
|
}
|
|
2755
|
-
|
|
2756
|
-
}
|
|
2757
|
-
// code execution 20250825:
|
|
2758
|
-
case "bash_code_execution_tool_result":
|
|
2759
|
-
case "text_editor_code_execution_tool_result": {
|
|
2749
|
+
} else {
|
|
2760
2750
|
controller.enqueue({
|
|
2761
2751
|
type: "tool-result",
|
|
2762
2752
|
toolCallId: part.tool_use_id,
|
|
2763
|
-
toolName: "
|
|
2764
|
-
|
|
2753
|
+
toolName: "web_search",
|
|
2754
|
+
isError: true,
|
|
2755
|
+
result: {
|
|
2756
|
+
type: "web_search_tool_result_error",
|
|
2757
|
+
errorCode: part.content.error_code
|
|
2758
|
+
}
|
|
2765
2759
|
});
|
|
2766
|
-
return;
|
|
2767
2760
|
}
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2761
|
+
return;
|
|
2762
|
+
}
|
|
2763
|
+
// code execution 20250522:
|
|
2764
|
+
case "code_execution_tool_result": {
|
|
2765
|
+
if (part.content.type === "code_execution_result") {
|
|
2766
|
+
controller.enqueue({
|
|
2767
|
+
type: "tool-result",
|
|
2768
|
+
toolCallId: part.tool_use_id,
|
|
2769
|
+
toolName: "code_execution",
|
|
2770
|
+
result: {
|
|
2771
|
+
type: part.content.type,
|
|
2772
|
+
stdout: part.content.stdout,
|
|
2773
|
+
stderr: part.content.stderr,
|
|
2774
|
+
return_code: part.content.return_code
|
|
2781
2775
|
}
|
|
2782
|
-
};
|
|
2783
|
-
|
|
2784
|
-
return;
|
|
2785
|
-
}
|
|
2786
|
-
case "mcp_tool_result": {
|
|
2776
|
+
});
|
|
2777
|
+
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
2787
2778
|
controller.enqueue({
|
|
2788
2779
|
type: "tool-result",
|
|
2789
2780
|
toolCallId: part.tool_use_id,
|
|
2790
|
-
toolName:
|
|
2791
|
-
isError:
|
|
2792
|
-
result:
|
|
2793
|
-
|
|
2794
|
-
|
|
2781
|
+
toolName: "code_execution",
|
|
2782
|
+
isError: true,
|
|
2783
|
+
result: {
|
|
2784
|
+
type: "code_execution_tool_result_error",
|
|
2785
|
+
errorCode: part.content.error_code
|
|
2786
|
+
}
|
|
2795
2787
|
});
|
|
2796
|
-
return;
|
|
2797
|
-
}
|
|
2798
|
-
default: {
|
|
2799
|
-
const _exhaustiveCheck = contentBlockType;
|
|
2800
|
-
throw new Error(
|
|
2801
|
-
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
2802
|
-
);
|
|
2803
2788
|
}
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
// code execution 20250825:
|
|
2792
|
+
case "bash_code_execution_tool_result":
|
|
2793
|
+
case "text_editor_code_execution_tool_result": {
|
|
2794
|
+
controller.enqueue({
|
|
2795
|
+
type: "tool-result",
|
|
2796
|
+
toolCallId: part.tool_use_id,
|
|
2797
|
+
toolName: "code_execution",
|
|
2798
|
+
result: part.content
|
|
2799
|
+
});
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
case "mcp_tool_use": {
|
|
2803
|
+
mcpToolCalls[part.id] = {
|
|
2804
|
+
type: "tool-call",
|
|
2805
|
+
toolCallId: part.id,
|
|
2806
|
+
toolName: part.name,
|
|
2807
|
+
input: JSON.stringify(part.input),
|
|
2808
|
+
providerExecuted: true,
|
|
2809
|
+
dynamic: true,
|
|
2810
|
+
providerMetadata: {
|
|
2811
|
+
anthropic: {
|
|
2812
|
+
type: "mcp-tool-use",
|
|
2813
|
+
serverName: part.server_name
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
};
|
|
2817
|
+
controller.enqueue(mcpToolCalls[part.id]);
|
|
2818
|
+
return;
|
|
2819
|
+
}
|
|
2820
|
+
case "mcp_tool_result": {
|
|
2821
|
+
controller.enqueue({
|
|
2822
|
+
type: "tool-result",
|
|
2823
|
+
toolCallId: part.tool_use_id,
|
|
2824
|
+
toolName: mcpToolCalls[part.tool_use_id].toolName,
|
|
2825
|
+
isError: part.is_error,
|
|
2826
|
+
result: part.content,
|
|
2827
|
+
dynamic: true,
|
|
2828
|
+
providerMetadata: mcpToolCalls[part.tool_use_id].providerMetadata
|
|
2829
|
+
});
|
|
2830
|
+
return;
|
|
2831
|
+
}
|
|
2832
|
+
default: {
|
|
2833
|
+
const _exhaustiveCheck = contentBlockType;
|
|
2834
|
+
throw new Error(
|
|
2835
|
+
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
2836
|
+
);
|
|
2804
2837
|
}
|
|
2805
2838
|
}
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2839
|
+
}
|
|
2840
|
+
case "content_block_stop": {
|
|
2841
|
+
if (contentBlocks[value.index] != null) {
|
|
2842
|
+
const contentBlock = contentBlocks[value.index];
|
|
2843
|
+
switch (contentBlock.type) {
|
|
2844
|
+
case "text": {
|
|
2845
|
+
controller.enqueue({
|
|
2846
|
+
type: "text-end",
|
|
2847
|
+
id: String(value.index)
|
|
2848
|
+
});
|
|
2849
|
+
break;
|
|
2850
|
+
}
|
|
2851
|
+
case "reasoning": {
|
|
2852
|
+
controller.enqueue({
|
|
2853
|
+
type: "reasoning-end",
|
|
2854
|
+
id: String(value.index)
|
|
2855
|
+
});
|
|
2856
|
+
break;
|
|
2857
|
+
}
|
|
2858
|
+
case "tool-call":
|
|
2859
|
+
const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
|
|
2860
|
+
if (!isJsonResponseTool) {
|
|
2811
2861
|
controller.enqueue({
|
|
2812
|
-
type: "
|
|
2813
|
-
id:
|
|
2862
|
+
type: "tool-input-end",
|
|
2863
|
+
id: contentBlock.toolCallId
|
|
2814
2864
|
});
|
|
2815
|
-
|
|
2816
|
-
}
|
|
2817
|
-
case "reasoning": {
|
|
2865
|
+
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
2818
2866
|
controller.enqueue({
|
|
2819
|
-
type: "
|
|
2820
|
-
|
|
2867
|
+
type: "tool-call",
|
|
2868
|
+
toolCallId: contentBlock.toolCallId,
|
|
2869
|
+
toolName,
|
|
2870
|
+
input: contentBlock.input,
|
|
2871
|
+
providerExecuted: contentBlock.providerExecuted
|
|
2821
2872
|
});
|
|
2822
|
-
break;
|
|
2823
2873
|
}
|
|
2824
|
-
|
|
2825
|
-
const isJsonResponseTool = usesJsonResponseTool && contentBlock.toolName === "json";
|
|
2826
|
-
if (!isJsonResponseTool) {
|
|
2827
|
-
controller.enqueue({
|
|
2828
|
-
type: "tool-input-end",
|
|
2829
|
-
id: contentBlock.toolCallId
|
|
2830
|
-
});
|
|
2831
|
-
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
2832
|
-
controller.enqueue({
|
|
2833
|
-
type: "tool-call",
|
|
2834
|
-
toolCallId: contentBlock.toolCallId,
|
|
2835
|
-
toolName,
|
|
2836
|
-
input: contentBlock.input,
|
|
2837
|
-
providerExecuted: contentBlock.providerExecuted
|
|
2838
|
-
});
|
|
2839
|
-
}
|
|
2840
|
-
break;
|
|
2841
|
-
}
|
|
2842
|
-
delete contentBlocks[value.index];
|
|
2874
|
+
break;
|
|
2843
2875
|
}
|
|
2844
|
-
|
|
2845
|
-
return;
|
|
2876
|
+
delete contentBlocks[value.index];
|
|
2846
2877
|
}
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
type: "text-delta",
|
|
2856
|
-
id: String(value.index),
|
|
2857
|
-
delta: value.delta.text
|
|
2858
|
-
});
|
|
2878
|
+
blockType = void 0;
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
case "content_block_delta": {
|
|
2882
|
+
const deltaType = value.delta.type;
|
|
2883
|
+
switch (deltaType) {
|
|
2884
|
+
case "text_delta": {
|
|
2885
|
+
if (usesJsonResponseTool) {
|
|
2859
2886
|
return;
|
|
2860
2887
|
}
|
|
2861
|
-
|
|
2888
|
+
controller.enqueue({
|
|
2889
|
+
type: "text-delta",
|
|
2890
|
+
id: String(value.index),
|
|
2891
|
+
delta: value.delta.text
|
|
2892
|
+
});
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
case "thinking_delta": {
|
|
2896
|
+
controller.enqueue({
|
|
2897
|
+
type: "reasoning-delta",
|
|
2898
|
+
id: String(value.index),
|
|
2899
|
+
delta: value.delta.thinking
|
|
2900
|
+
});
|
|
2901
|
+
return;
|
|
2902
|
+
}
|
|
2903
|
+
case "signature_delta": {
|
|
2904
|
+
if (blockType === "thinking") {
|
|
2862
2905
|
controller.enqueue({
|
|
2863
2906
|
type: "reasoning-delta",
|
|
2864
2907
|
id: String(value.index),
|
|
2865
|
-
delta:
|
|
2908
|
+
delta: "",
|
|
2909
|
+
providerMetadata: {
|
|
2910
|
+
anthropic: {
|
|
2911
|
+
signature: value.delta.signature
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2866
2914
|
});
|
|
2867
|
-
return;
|
|
2868
2915
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
providerMetadata: {
|
|
2876
|
-
anthropic: {
|
|
2877
|
-
signature: value.delta.signature
|
|
2878
|
-
}
|
|
2879
|
-
}
|
|
2880
|
-
});
|
|
2881
|
-
}
|
|
2916
|
+
return;
|
|
2917
|
+
}
|
|
2918
|
+
case "input_json_delta": {
|
|
2919
|
+
const contentBlock = contentBlocks[value.index];
|
|
2920
|
+
let delta = value.delta.partial_json;
|
|
2921
|
+
if (delta.length === 0) {
|
|
2882
2922
|
return;
|
|
2883
2923
|
}
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
let delta = value.delta.partial_json;
|
|
2887
|
-
if (delta.length === 0) {
|
|
2924
|
+
if (isJsonResponseFromTool) {
|
|
2925
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
2888
2926
|
return;
|
|
2889
2927
|
}
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
});
|
|
2899
|
-
} else {
|
|
2900
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
2901
|
-
return;
|
|
2902
|
-
}
|
|
2903
|
-
if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
|
|
2904
|
-
delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
|
|
2905
|
-
}
|
|
2906
|
-
controller.enqueue({
|
|
2907
|
-
type: "tool-input-delta",
|
|
2908
|
-
id: contentBlock.toolCallId,
|
|
2909
|
-
delta
|
|
2910
|
-
});
|
|
2911
|
-
contentBlock.input += delta;
|
|
2912
|
-
contentBlock.firstDelta = false;
|
|
2928
|
+
controller.enqueue({
|
|
2929
|
+
type: "text-delta",
|
|
2930
|
+
id: String(value.index),
|
|
2931
|
+
delta
|
|
2932
|
+
});
|
|
2933
|
+
} else {
|
|
2934
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
2935
|
+
return;
|
|
2913
2936
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
case "citations_delta": {
|
|
2917
|
-
const citation = value.delta.citation;
|
|
2918
|
-
const source = createCitationSource(
|
|
2919
|
-
citation,
|
|
2920
|
-
citationDocuments,
|
|
2921
|
-
generateId2
|
|
2922
|
-
);
|
|
2923
|
-
if (source) {
|
|
2924
|
-
controller.enqueue(source);
|
|
2937
|
+
if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
|
|
2938
|
+
delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
|
|
2925
2939
|
}
|
|
2926
|
-
|
|
2940
|
+
controller.enqueue({
|
|
2941
|
+
type: "tool-input-delta",
|
|
2942
|
+
id: contentBlock.toolCallId,
|
|
2943
|
+
delta
|
|
2944
|
+
});
|
|
2945
|
+
contentBlock.input += delta;
|
|
2946
|
+
contentBlock.firstDelta = false;
|
|
2927
2947
|
}
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2950
|
+
case "citations_delta": {
|
|
2951
|
+
const citation = value.delta.citation;
|
|
2952
|
+
const source = createCitationSource(
|
|
2953
|
+
citation,
|
|
2954
|
+
citationDocuments,
|
|
2955
|
+
generateId2
|
|
2956
|
+
);
|
|
2957
|
+
if (source) {
|
|
2958
|
+
controller.enqueue(source);
|
|
2933
2959
|
}
|
|
2960
|
+
return;
|
|
2961
|
+
}
|
|
2962
|
+
default: {
|
|
2963
|
+
const _exhaustiveCheck = deltaType;
|
|
2964
|
+
throw new Error(
|
|
2965
|
+
`Unsupported delta type: ${_exhaustiveCheck}`
|
|
2966
|
+
);
|
|
2934
2967
|
}
|
|
2935
2968
|
}
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
} : null
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2969
|
+
}
|
|
2970
|
+
case "message_start": {
|
|
2971
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
2972
|
+
usage.cachedInputTokens = (_b = value.message.usage.cache_read_input_tokens) != null ? _b : void 0;
|
|
2973
|
+
rawUsage = {
|
|
2974
|
+
...value.message.usage
|
|
2975
|
+
};
|
|
2976
|
+
cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
|
|
2977
|
+
controller.enqueue({
|
|
2978
|
+
type: "response-metadata",
|
|
2979
|
+
id: (_d = value.message.id) != null ? _d : void 0,
|
|
2980
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
2981
|
+
});
|
|
2982
|
+
return;
|
|
2983
|
+
}
|
|
2984
|
+
case "message_delta": {
|
|
2985
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
2986
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
2987
|
+
finishReason = mapAnthropicStopReason({
|
|
2988
|
+
finishReason: value.delta.stop_reason,
|
|
2989
|
+
isJsonResponseFromTool
|
|
2990
|
+
});
|
|
2991
|
+
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
2992
|
+
container = value.delta.container != null ? {
|
|
2993
|
+
expiresAt: value.delta.container.expires_at,
|
|
2994
|
+
id: value.delta.container.id,
|
|
2995
|
+
skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
2996
|
+
type: skill.type,
|
|
2997
|
+
skillId: skill.skill_id,
|
|
2998
|
+
version: skill.version
|
|
2999
|
+
}))) != null ? _j : null
|
|
3000
|
+
} : null;
|
|
3001
|
+
rawUsage = {
|
|
3002
|
+
...rawUsage,
|
|
3003
|
+
...value.usage
|
|
3004
|
+
};
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
case "message_stop": {
|
|
3008
|
+
controller.enqueue({
|
|
3009
|
+
type: "finish",
|
|
3010
|
+
finishReason,
|
|
3011
|
+
usage,
|
|
3012
|
+
providerMetadata: {
|
|
3013
|
+
anthropic: {
|
|
3014
|
+
usage: rawUsage != null ? rawUsage : null,
|
|
3015
|
+
cacheCreationInputTokens,
|
|
3016
|
+
stopSequence,
|
|
3017
|
+
container
|
|
2985
3018
|
}
|
|
2986
|
-
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
}
|
|
3019
|
+
}
|
|
3020
|
+
});
|
|
3021
|
+
return;
|
|
3022
|
+
}
|
|
3023
|
+
case "error": {
|
|
3024
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
3025
|
+
return;
|
|
3026
|
+
}
|
|
3027
|
+
default: {
|
|
3028
|
+
const _exhaustiveCheck = value;
|
|
3029
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
2997
3030
|
}
|
|
2998
3031
|
}
|
|
2999
|
-
}
|
|
3000
|
-
)
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3032
|
+
}
|
|
3033
|
+
})
|
|
3034
|
+
);
|
|
3035
|
+
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
3036
|
+
stream = streamForConsumer;
|
|
3037
|
+
const reader = streamForFirstChunk.getReader();
|
|
3038
|
+
(async () => {
|
|
3039
|
+
try {
|
|
3040
|
+
const { done } = await reader.read();
|
|
3041
|
+
if (!done) {
|
|
3042
|
+
await reader.cancel();
|
|
3043
|
+
}
|
|
3044
|
+
} catch (error) {
|
|
3045
|
+
try {
|
|
3046
|
+
await reader.cancel();
|
|
3047
|
+
} catch (e) {
|
|
3048
|
+
}
|
|
3049
|
+
} finally {
|
|
3050
|
+
reader.releaseLock();
|
|
3051
|
+
}
|
|
3052
|
+
})();
|
|
3053
|
+
return returnPromise.promise;
|
|
3004
3054
|
}
|
|
3005
3055
|
};
|
|
3006
3056
|
function getModelCapabilities(modelId) {
|