@browserbasehq/stagehand 3.0.7-alpha-30b0e12357f23070415422e7e50325986ba474f6 → 3.0.7-alpha-cadd192066c8aa5d19bb4d5daa630ed5981b5d7e
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/dist/index.d.ts +6 -0
- package/dist/index.js +711 -505
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -179,7 +179,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
179
179
|
var STAGEHAND_VERSION;
|
|
180
180
|
var init_version = __esm({
|
|
181
181
|
"lib/version.ts"() {
|
|
182
|
-
STAGEHAND_VERSION = "3.0.7-alpha-
|
|
182
|
+
STAGEHAND_VERSION = "3.0.7-alpha-cadd192066c8aa5d19bb4d5daa630ed5981b5d7e";
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
185
|
|
|
@@ -26873,6 +26873,7 @@ module.exports = __toCommonJS(v3_exports);
|
|
|
26873
26873
|
|
|
26874
26874
|
// lib/v3/v3.ts
|
|
26875
26875
|
var import_dotenv = __toESM(require("dotenv"));
|
|
26876
|
+
var import_events2 = require("events");
|
|
26876
26877
|
var import_fs8 = __toESM(require("fs"));
|
|
26877
26878
|
var import_os2 = __toESM(require("os"));
|
|
26878
26879
|
var import_path6 = __toESM(require("path"));
|
|
@@ -26900,6 +26901,7 @@ init_sdkErrors();
|
|
|
26900
26901
|
var import_genai = require("@google/genai");
|
|
26901
26902
|
var import_zod2 = require("zod");
|
|
26902
26903
|
var import_v3 = __toESM(require("zod/v3"));
|
|
26904
|
+
var import_sharp = __toESM(require("sharp"));
|
|
26903
26905
|
var ID_PATTERN = /^\d+-\d+$/;
|
|
26904
26906
|
var zFactories = {
|
|
26905
26907
|
v4: import_zod2.z,
|
|
@@ -31232,6 +31234,15 @@ var V3AgentHandler = class {
|
|
|
31232
31234
|
}
|
|
31233
31235
|
}
|
|
31234
31236
|
state.currentPageUrl = (yield this.v3.context.awaitActivePage()).url();
|
|
31237
|
+
try {
|
|
31238
|
+
yield this.captureAndEmitScreenshot();
|
|
31239
|
+
} catch (e2) {
|
|
31240
|
+
this.logger({
|
|
31241
|
+
category: "agent",
|
|
31242
|
+
message: `Warning: Failed to capture screenshot: ${getErrorMessage(e2)}`,
|
|
31243
|
+
level: 1
|
|
31244
|
+
});
|
|
31245
|
+
}
|
|
31235
31246
|
}
|
|
31236
31247
|
if (userCallback) {
|
|
31237
31248
|
yield userCallback(event);
|
|
@@ -31481,6 +31492,24 @@ STRATEGY:
|
|
|
31481
31492
|
}
|
|
31482
31493
|
return (0, import_ai11.stepCountIs)(maxSteps)(result);
|
|
31483
31494
|
}
|
|
31495
|
+
/**
|
|
31496
|
+
* Capture a screenshot and emit it via the event bus
|
|
31497
|
+
*/
|
|
31498
|
+
captureAndEmitScreenshot() {
|
|
31499
|
+
return __async(this, null, function* () {
|
|
31500
|
+
try {
|
|
31501
|
+
const page = yield this.v3.context.awaitActivePage();
|
|
31502
|
+
const screenshot = yield page.screenshot({ fullPage: false });
|
|
31503
|
+
this.v3.bus.emit("agent_screensot_taken_event", screenshot);
|
|
31504
|
+
} catch (error) {
|
|
31505
|
+
this.logger({
|
|
31506
|
+
category: "agent",
|
|
31507
|
+
message: `Error capturing screenshot: ${getErrorMessage(error)}`,
|
|
31508
|
+
level: 0
|
|
31509
|
+
});
|
|
31510
|
+
}
|
|
31511
|
+
});
|
|
31512
|
+
}
|
|
31484
31513
|
};
|
|
31485
31514
|
|
|
31486
31515
|
// lib/v3/handlers/v3CuaAgentHandler.ts
|
|
@@ -34897,9 +34926,7 @@ var V3CuaAgentHandler = class {
|
|
|
34897
34926
|
try {
|
|
34898
34927
|
const page = yield this.v3.context.awaitActivePage();
|
|
34899
34928
|
const base64Image = yield page.screenshot({ fullPage: false });
|
|
34900
|
-
|
|
34901
|
-
this.screenshotCollector.addScreenshot(base64Image);
|
|
34902
|
-
}
|
|
34929
|
+
this.v3.bus.emit("agent_screensot_taken_event", base64Image);
|
|
34903
34930
|
const currentUrl = page.url();
|
|
34904
34931
|
return yield this.agentClient.captureScreenshot({
|
|
34905
34932
|
base64Image,
|
|
@@ -34924,20 +34951,6 @@ var V3CuaAgentHandler = class {
|
|
|
34924
34951
|
}
|
|
34925
34952
|
});
|
|
34926
34953
|
}
|
|
34927
|
-
/**
|
|
34928
|
-
* Set the screenshot collector for this agent handler
|
|
34929
|
-
*/
|
|
34930
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34931
|
-
setScreenshotCollector(collector) {
|
|
34932
|
-
this.screenshotCollector = collector;
|
|
34933
|
-
}
|
|
34934
|
-
/**
|
|
34935
|
-
* Get the screenshot collector
|
|
34936
|
-
*/
|
|
34937
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34938
|
-
getScreenshotCollector() {
|
|
34939
|
-
return this.screenshotCollector;
|
|
34940
|
-
}
|
|
34941
34954
|
};
|
|
34942
34955
|
|
|
34943
34956
|
// lib/v3/launch/browserbase.ts
|
|
@@ -44387,6 +44400,54 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
44387
44400
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
44388
44401
|
}
|
|
44389
44402
|
var VERSION3 = true ? "3.0.18" : "0.0.0-test";
|
|
44403
|
+
function loadApiKey2({
|
|
44404
|
+
apiKey,
|
|
44405
|
+
environmentVariableName,
|
|
44406
|
+
apiKeyParameterName = "apiKey",
|
|
44407
|
+
description
|
|
44408
|
+
}) {
|
|
44409
|
+
if (typeof apiKey === "string") {
|
|
44410
|
+
return apiKey;
|
|
44411
|
+
}
|
|
44412
|
+
if (apiKey != null) {
|
|
44413
|
+
throw new import_provider23.LoadAPIKeyError({
|
|
44414
|
+
message: `${description} API key must be a string.`
|
|
44415
|
+
});
|
|
44416
|
+
}
|
|
44417
|
+
if (typeof process === "undefined") {
|
|
44418
|
+
throw new import_provider23.LoadAPIKeyError({
|
|
44419
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
44420
|
+
});
|
|
44421
|
+
}
|
|
44422
|
+
apiKey = process.env[environmentVariableName];
|
|
44423
|
+
if (apiKey == null) {
|
|
44424
|
+
throw new import_provider23.LoadAPIKeyError({
|
|
44425
|
+
message: `${description} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
44426
|
+
});
|
|
44427
|
+
}
|
|
44428
|
+
if (typeof apiKey !== "string") {
|
|
44429
|
+
throw new import_provider23.LoadAPIKeyError({
|
|
44430
|
+
message: `${description} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
44431
|
+
});
|
|
44432
|
+
}
|
|
44433
|
+
return apiKey;
|
|
44434
|
+
}
|
|
44435
|
+
function loadOptionalSetting2({
|
|
44436
|
+
settingValue,
|
|
44437
|
+
environmentVariableName
|
|
44438
|
+
}) {
|
|
44439
|
+
if (typeof settingValue === "string") {
|
|
44440
|
+
return settingValue;
|
|
44441
|
+
}
|
|
44442
|
+
if (settingValue != null || typeof process === "undefined") {
|
|
44443
|
+
return void 0;
|
|
44444
|
+
}
|
|
44445
|
+
settingValue = process.env[environmentVariableName];
|
|
44446
|
+
if (settingValue == null || typeof settingValue !== "string") {
|
|
44447
|
+
return void 0;
|
|
44448
|
+
}
|
|
44449
|
+
return settingValue;
|
|
44450
|
+
}
|
|
44390
44451
|
function loadSetting2({
|
|
44391
44452
|
settingValue,
|
|
44392
44453
|
environmentVariableName,
|
|
@@ -47768,7 +47829,7 @@ function createVertex2(options = {}) {
|
|
|
47768
47829
|
}
|
|
47769
47830
|
var vertex = createVertex2();
|
|
47770
47831
|
|
|
47771
|
-
// ../../node_modules/.pnpm/@ai-sdk+anthropic@2.0.
|
|
47832
|
+
// ../../node_modules/.pnpm/@ai-sdk+anthropic@2.0.53_zod@4.1.12/node_modules/@ai-sdk/anthropic/dist/index.mjs
|
|
47772
47833
|
var import_provider34 = require("@ai-sdk/provider");
|
|
47773
47834
|
var import_provider35 = require("@ai-sdk/provider");
|
|
47774
47835
|
var import_v433 = require("zod/v4");
|
|
@@ -47789,9 +47850,9 @@ var import_v445 = require("zod/v4");
|
|
|
47789
47850
|
var import_v446 = require("zod/v4");
|
|
47790
47851
|
var import_v447 = require("zod/v4");
|
|
47791
47852
|
var import_v448 = require("zod/v4");
|
|
47792
|
-
var VERSION5 = true ? "2.0.
|
|
47793
|
-
var anthropicErrorDataSchema =
|
|
47794
|
-
() =>
|
|
47853
|
+
var VERSION5 = true ? "2.0.53" : "0.0.0-test";
|
|
47854
|
+
var anthropicErrorDataSchema = lazySchema2(
|
|
47855
|
+
() => zodSchema2(
|
|
47795
47856
|
import_v433.z.object({
|
|
47796
47857
|
type: import_v433.z.literal("error"),
|
|
47797
47858
|
error: import_v433.z.object({
|
|
@@ -47801,12 +47862,12 @@ var anthropicErrorDataSchema = lazySchema(
|
|
|
47801
47862
|
})
|
|
47802
47863
|
)
|
|
47803
47864
|
);
|
|
47804
|
-
var anthropicFailedResponseHandler =
|
|
47865
|
+
var anthropicFailedResponseHandler = createJsonErrorResponseHandler2({
|
|
47805
47866
|
errorSchema: anthropicErrorDataSchema,
|
|
47806
47867
|
errorToMessage: (data) => data.error.message
|
|
47807
47868
|
});
|
|
47808
|
-
var anthropicMessagesResponseSchema =
|
|
47809
|
-
() =>
|
|
47869
|
+
var anthropicMessagesResponseSchema = lazySchema2(
|
|
47870
|
+
() => zodSchema2(
|
|
47810
47871
|
import_v434.z.object({
|
|
47811
47872
|
type: import_v434.z.literal("message"),
|
|
47812
47873
|
id: import_v434.z.string().nullish(),
|
|
@@ -48006,8 +48067,8 @@ var anthropicMessagesResponseSchema = lazySchema(
|
|
|
48006
48067
|
})
|
|
48007
48068
|
)
|
|
48008
48069
|
);
|
|
48009
|
-
var anthropicMessagesChunkSchema =
|
|
48010
|
-
() =>
|
|
48070
|
+
var anthropicMessagesChunkSchema = lazySchema2(
|
|
48071
|
+
() => zodSchema2(
|
|
48011
48072
|
import_v434.z.discriminatedUnion("type", [
|
|
48012
48073
|
import_v434.z.object({
|
|
48013
48074
|
type: import_v434.z.literal("message_start"),
|
|
@@ -48262,8 +48323,8 @@ var anthropicMessagesChunkSchema = lazySchema(
|
|
|
48262
48323
|
])
|
|
48263
48324
|
)
|
|
48264
48325
|
);
|
|
48265
|
-
var anthropicReasoningMetadataSchema =
|
|
48266
|
-
() =>
|
|
48326
|
+
var anthropicReasoningMetadataSchema = lazySchema2(
|
|
48327
|
+
() => zodSchema2(
|
|
48267
48328
|
import_v434.z.object({
|
|
48268
48329
|
signature: import_v434.z.string().optional(),
|
|
48269
48330
|
redactedData: import_v434.z.string().optional()
|
|
@@ -48295,6 +48356,20 @@ var anthropicFilePartProviderOptions = import_v435.z.object({
|
|
|
48295
48356
|
});
|
|
48296
48357
|
var anthropicProviderOptions = import_v435.z.object({
|
|
48297
48358
|
sendReasoning: import_v435.z.boolean().optional(),
|
|
48359
|
+
/**
|
|
48360
|
+
* Determines how structured outputs are generated.
|
|
48361
|
+
*
|
|
48362
|
+
* - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
|
|
48363
|
+
* - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
|
|
48364
|
+
* - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
|
|
48365
|
+
*/
|
|
48366
|
+
structuredOutputMode: import_v435.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
|
|
48367
|
+
/**
|
|
48368
|
+
* Configuration for enabling Claude's extended thinking.
|
|
48369
|
+
*
|
|
48370
|
+
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
48371
|
+
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
48372
|
+
*/
|
|
48298
48373
|
thinking: import_v435.z.object({
|
|
48299
48374
|
type: import_v435.z.union([import_v435.z.literal("enabled"), import_v435.z.literal("disabled")]),
|
|
48300
48375
|
budgetTokens: import_v435.z.number().optional()
|
|
@@ -48326,7 +48401,11 @@ var anthropicProviderOptions = import_v435.z.object({
|
|
|
48326
48401
|
version: import_v435.z.string().optional()
|
|
48327
48402
|
})
|
|
48328
48403
|
).optional()
|
|
48329
|
-
}).optional()
|
|
48404
|
+
}).optional(),
|
|
48405
|
+
/**
|
|
48406
|
+
* @default 'high'
|
|
48407
|
+
*/
|
|
48408
|
+
effort: import_v435.z.enum(["low", "medium", "high"]).optional()
|
|
48330
48409
|
});
|
|
48331
48410
|
var MAX_CACHE_BREAKPOINTS = 4;
|
|
48332
48411
|
function getCacheControl(providerMetadata) {
|
|
@@ -48368,15 +48447,15 @@ var CacheControlValidator = class {
|
|
|
48368
48447
|
return this.warnings;
|
|
48369
48448
|
}
|
|
48370
48449
|
};
|
|
48371
|
-
var textEditor_20250728ArgsSchema =
|
|
48372
|
-
() =>
|
|
48450
|
+
var textEditor_20250728ArgsSchema = lazySchema2(
|
|
48451
|
+
() => zodSchema2(
|
|
48373
48452
|
import_v436.z.object({
|
|
48374
48453
|
maxCharacters: import_v436.z.number().optional()
|
|
48375
48454
|
})
|
|
48376
48455
|
)
|
|
48377
48456
|
);
|
|
48378
|
-
var textEditor_20250728InputSchema =
|
|
48379
|
-
() =>
|
|
48457
|
+
var textEditor_20250728InputSchema = lazySchema2(
|
|
48458
|
+
() => zodSchema2(
|
|
48380
48459
|
import_v436.z.object({
|
|
48381
48460
|
command: import_v436.z.enum(["view", "create", "str_replace", "insert"]),
|
|
48382
48461
|
path: import_v436.z.string(),
|
|
@@ -48388,7 +48467,7 @@ var textEditor_20250728InputSchema = lazySchema(
|
|
|
48388
48467
|
})
|
|
48389
48468
|
)
|
|
48390
48469
|
);
|
|
48391
|
-
var factory =
|
|
48470
|
+
var factory = createProviderDefinedToolFactory2({
|
|
48392
48471
|
id: "anthropic.text_editor_20250728",
|
|
48393
48472
|
name: "str_replace_based_edit_tool",
|
|
48394
48473
|
inputSchema: textEditor_20250728InputSchema
|
|
@@ -48396,8 +48475,8 @@ var factory = createProviderDefinedToolFactory({
|
|
|
48396
48475
|
var textEditor_20250728 = (args = {}) => {
|
|
48397
48476
|
return factory(args);
|
|
48398
48477
|
};
|
|
48399
|
-
var webSearch_20250305ArgsSchema =
|
|
48400
|
-
() =>
|
|
48478
|
+
var webSearch_20250305ArgsSchema = lazySchema2(
|
|
48479
|
+
() => zodSchema2(
|
|
48401
48480
|
import_v437.z.object({
|
|
48402
48481
|
maxUses: import_v437.z.number().optional(),
|
|
48403
48482
|
allowedDomains: import_v437.z.array(import_v437.z.string()).optional(),
|
|
@@ -48412,8 +48491,8 @@ var webSearch_20250305ArgsSchema = lazySchema(
|
|
|
48412
48491
|
})
|
|
48413
48492
|
)
|
|
48414
48493
|
);
|
|
48415
|
-
var webSearch_20250305OutputSchema =
|
|
48416
|
-
() =>
|
|
48494
|
+
var webSearch_20250305OutputSchema = lazySchema2(
|
|
48495
|
+
() => zodSchema2(
|
|
48417
48496
|
import_v437.z.array(
|
|
48418
48497
|
import_v437.z.object({
|
|
48419
48498
|
url: import_v437.z.string(),
|
|
@@ -48425,14 +48504,14 @@ var webSearch_20250305OutputSchema = lazySchema(
|
|
|
48425
48504
|
)
|
|
48426
48505
|
)
|
|
48427
48506
|
);
|
|
48428
|
-
var webSearch_20250305InputSchema =
|
|
48429
|
-
() =>
|
|
48507
|
+
var webSearch_20250305InputSchema = lazySchema2(
|
|
48508
|
+
() => zodSchema2(
|
|
48430
48509
|
import_v437.z.object({
|
|
48431
48510
|
query: import_v437.z.string()
|
|
48432
48511
|
})
|
|
48433
48512
|
)
|
|
48434
48513
|
);
|
|
48435
|
-
var factory2 =
|
|
48514
|
+
var factory2 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
48436
48515
|
id: "anthropic.web_search_20250305",
|
|
48437
48516
|
name: "web_search",
|
|
48438
48517
|
inputSchema: webSearch_20250305InputSchema,
|
|
@@ -48441,8 +48520,8 @@ var factory2 = createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
48441
48520
|
var webSearch_20250305 = (args = {}) => {
|
|
48442
48521
|
return factory2(args);
|
|
48443
48522
|
};
|
|
48444
|
-
var webFetch_20250910ArgsSchema =
|
|
48445
|
-
() =>
|
|
48523
|
+
var webFetch_20250910ArgsSchema = lazySchema2(
|
|
48524
|
+
() => zodSchema2(
|
|
48446
48525
|
import_v438.z.object({
|
|
48447
48526
|
maxUses: import_v438.z.number().optional(),
|
|
48448
48527
|
allowedDomains: import_v438.z.array(import_v438.z.string()).optional(),
|
|
@@ -48452,8 +48531,8 @@ var webFetch_20250910ArgsSchema = lazySchema(
|
|
|
48452
48531
|
})
|
|
48453
48532
|
)
|
|
48454
48533
|
);
|
|
48455
|
-
var webFetch_20250910OutputSchema =
|
|
48456
|
-
() =>
|
|
48534
|
+
var webFetch_20250910OutputSchema = lazySchema2(
|
|
48535
|
+
() => zodSchema2(
|
|
48457
48536
|
import_v438.z.object({
|
|
48458
48537
|
type: import_v438.z.literal("web_fetch_result"),
|
|
48459
48538
|
url: import_v438.z.string(),
|
|
@@ -48478,14 +48557,14 @@ var webFetch_20250910OutputSchema = lazySchema(
|
|
|
48478
48557
|
})
|
|
48479
48558
|
)
|
|
48480
48559
|
);
|
|
48481
|
-
var webFetch_20250910InputSchema =
|
|
48482
|
-
() =>
|
|
48560
|
+
var webFetch_20250910InputSchema = lazySchema2(
|
|
48561
|
+
() => zodSchema2(
|
|
48483
48562
|
import_v438.z.object({
|
|
48484
48563
|
url: import_v438.z.string()
|
|
48485
48564
|
})
|
|
48486
48565
|
)
|
|
48487
48566
|
);
|
|
48488
|
-
var factory3 =
|
|
48567
|
+
var factory3 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
48489
48568
|
id: "anthropic.web_fetch_20250910",
|
|
48490
48569
|
name: "web_fetch",
|
|
48491
48570
|
inputSchema: webFetch_20250910InputSchema,
|
|
@@ -48595,7 +48674,7 @@ function prepareTools2(_0) {
|
|
|
48595
48674
|
break;
|
|
48596
48675
|
}
|
|
48597
48676
|
case "anthropic.text_editor_20250728": {
|
|
48598
|
-
const args = yield
|
|
48677
|
+
const args = yield validateTypes2({
|
|
48599
48678
|
value: tool13.args,
|
|
48600
48679
|
schema: textEditor_20250728ArgsSchema
|
|
48601
48680
|
});
|
|
@@ -48635,7 +48714,7 @@ function prepareTools2(_0) {
|
|
|
48635
48714
|
}
|
|
48636
48715
|
case "anthropic.web_fetch_20250910": {
|
|
48637
48716
|
betas.add("web-fetch-2025-09-10");
|
|
48638
|
-
const args = yield
|
|
48717
|
+
const args = yield validateTypes2({
|
|
48639
48718
|
value: tool13.args,
|
|
48640
48719
|
schema: webFetch_20250910ArgsSchema
|
|
48641
48720
|
});
|
|
@@ -48652,7 +48731,7 @@ function prepareTools2(_0) {
|
|
|
48652
48731
|
break;
|
|
48653
48732
|
}
|
|
48654
48733
|
case "anthropic.web_search_20250305": {
|
|
48655
|
-
const args = yield
|
|
48734
|
+
const args = yield validateTypes2({
|
|
48656
48735
|
value: tool13.args,
|
|
48657
48736
|
schema: webSearch_20250305ArgsSchema
|
|
48658
48737
|
});
|
|
@@ -48732,8 +48811,8 @@ function prepareTools2(_0) {
|
|
|
48732
48811
|
}
|
|
48733
48812
|
});
|
|
48734
48813
|
}
|
|
48735
|
-
var codeExecution_20250522OutputSchema =
|
|
48736
|
-
() =>
|
|
48814
|
+
var codeExecution_20250522OutputSchema = lazySchema2(
|
|
48815
|
+
() => zodSchema2(
|
|
48737
48816
|
import_v439.z.object({
|
|
48738
48817
|
type: import_v439.z.literal("code_execution_result"),
|
|
48739
48818
|
stdout: import_v439.z.string(),
|
|
@@ -48742,14 +48821,14 @@ var codeExecution_20250522OutputSchema = lazySchema(
|
|
|
48742
48821
|
})
|
|
48743
48822
|
)
|
|
48744
48823
|
);
|
|
48745
|
-
var codeExecution_20250522InputSchema =
|
|
48746
|
-
() =>
|
|
48824
|
+
var codeExecution_20250522InputSchema = lazySchema2(
|
|
48825
|
+
() => zodSchema2(
|
|
48747
48826
|
import_v439.z.object({
|
|
48748
48827
|
code: import_v439.z.string()
|
|
48749
48828
|
})
|
|
48750
48829
|
)
|
|
48751
48830
|
);
|
|
48752
|
-
var factory4 =
|
|
48831
|
+
var factory4 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
48753
48832
|
id: "anthropic.code_execution_20250522",
|
|
48754
48833
|
name: "code_execution",
|
|
48755
48834
|
inputSchema: codeExecution_20250522InputSchema,
|
|
@@ -48758,8 +48837,8 @@ var factory4 = createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
48758
48837
|
var codeExecution_20250522 = (args = {}) => {
|
|
48759
48838
|
return factory4(args);
|
|
48760
48839
|
};
|
|
48761
|
-
var codeExecution_20250825OutputSchema =
|
|
48762
|
-
() =>
|
|
48840
|
+
var codeExecution_20250825OutputSchema = lazySchema2(
|
|
48841
|
+
() => zodSchema2(
|
|
48763
48842
|
import_v440.z.discriminatedUnion("type", [
|
|
48764
48843
|
import_v440.z.object({
|
|
48765
48844
|
type: import_v440.z.literal("bash_code_execution_result"),
|
|
@@ -48804,8 +48883,8 @@ var codeExecution_20250825OutputSchema = lazySchema(
|
|
|
48804
48883
|
])
|
|
48805
48884
|
)
|
|
48806
48885
|
);
|
|
48807
|
-
var codeExecution_20250825InputSchema =
|
|
48808
|
-
() =>
|
|
48886
|
+
var codeExecution_20250825InputSchema = lazySchema2(
|
|
48887
|
+
() => zodSchema2(
|
|
48809
48888
|
import_v440.z.discriminatedUnion("type", [
|
|
48810
48889
|
import_v440.z.object({
|
|
48811
48890
|
type: import_v440.z.literal("bash_code_execution"),
|
|
@@ -48834,7 +48913,7 @@ var codeExecution_20250825InputSchema = lazySchema(
|
|
|
48834
48913
|
])
|
|
48835
48914
|
)
|
|
48836
48915
|
);
|
|
48837
|
-
var factory5 =
|
|
48916
|
+
var factory5 = createProviderDefinedToolFactoryWithOutputSchema2({
|
|
48838
48917
|
id: "anthropic.code_execution_20250825",
|
|
48839
48918
|
name: "code_execution",
|
|
48840
48919
|
inputSchema: codeExecution_20250825InputSchema,
|
|
@@ -48875,7 +48954,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
48875
48954
|
function shouldEnableCitations(providerMetadata) {
|
|
48876
48955
|
return __async(this, null, function* () {
|
|
48877
48956
|
var _a22, _b2;
|
|
48878
|
-
const anthropicOptions = yield
|
|
48957
|
+
const anthropicOptions = yield parseProviderOptions2({
|
|
48879
48958
|
provider: "anthropic",
|
|
48880
48959
|
providerOptions: providerMetadata,
|
|
48881
48960
|
schema: anthropicFilePartProviderOptions
|
|
@@ -48885,7 +48964,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
48885
48964
|
}
|
|
48886
48965
|
function getDocumentMetadata(providerMetadata) {
|
|
48887
48966
|
return __async(this, null, function* () {
|
|
48888
|
-
const anthropicOptions = yield
|
|
48967
|
+
const anthropicOptions = yield parseProviderOptions2({
|
|
48889
48968
|
provider: "anthropic",
|
|
48890
48969
|
providerOptions: providerMetadata,
|
|
48891
48970
|
schema: anthropicFilePartProviderOptions
|
|
@@ -48952,7 +49031,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
48952
49031
|
} : {
|
|
48953
49032
|
type: "base64",
|
|
48954
49033
|
media_type: part.mediaType === "image/*" ? "image/jpeg" : part.mediaType,
|
|
48955
|
-
data:
|
|
49034
|
+
data: convertToBase642(part.data)
|
|
48956
49035
|
},
|
|
48957
49036
|
cache_control: cacheControl
|
|
48958
49037
|
});
|
|
@@ -48972,7 +49051,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
48972
49051
|
} : {
|
|
48973
49052
|
type: "base64",
|
|
48974
49053
|
media_type: "application/pdf",
|
|
48975
|
-
data:
|
|
49054
|
+
data: convertToBase642(part.data)
|
|
48976
49055
|
},
|
|
48977
49056
|
title: (_b = metadata.title) != null ? _b : part.filename
|
|
48978
49057
|
}, metadata.context && { context: metadata.context }), enableCitations && {
|
|
@@ -49126,7 +49205,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
49126
49205
|
}
|
|
49127
49206
|
case "reasoning": {
|
|
49128
49207
|
if (sendReasoning) {
|
|
49129
|
-
const reasoningMetadata = yield
|
|
49208
|
+
const reasoningMetadata = yield parseProviderOptions2({
|
|
49130
49209
|
provider: "anthropic",
|
|
49131
49210
|
providerOptions: part.providerOptions,
|
|
49132
49211
|
schema: anthropicReasoningMetadataSchema
|
|
@@ -49226,7 +49305,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
49226
49305
|
break;
|
|
49227
49306
|
}
|
|
49228
49307
|
if (output.value.type === "code_execution_result") {
|
|
49229
|
-
const codeExecutionOutput = yield
|
|
49308
|
+
const codeExecutionOutput = yield validateTypes2({
|
|
49230
49309
|
value: output.value,
|
|
49231
49310
|
schema: codeExecution_20250522OutputSchema
|
|
49232
49311
|
});
|
|
@@ -49242,7 +49321,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
49242
49321
|
cache_control: cacheControl
|
|
49243
49322
|
});
|
|
49244
49323
|
} else {
|
|
49245
|
-
const codeExecutionOutput = yield
|
|
49324
|
+
const codeExecutionOutput = yield validateTypes2({
|
|
49246
49325
|
value: output.value,
|
|
49247
49326
|
schema: codeExecution_20250825OutputSchema
|
|
49248
49327
|
});
|
|
@@ -49271,7 +49350,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
49271
49350
|
});
|
|
49272
49351
|
break;
|
|
49273
49352
|
}
|
|
49274
|
-
const webFetchOutput = yield
|
|
49353
|
+
const webFetchOutput = yield validateTypes2({
|
|
49275
49354
|
value: output.value,
|
|
49276
49355
|
schema: webFetch_20250910OutputSchema
|
|
49277
49356
|
});
|
|
@@ -49306,7 +49385,7 @@ function convertToAnthropicMessagesPrompt(_0) {
|
|
|
49306
49385
|
});
|
|
49307
49386
|
break;
|
|
49308
49387
|
}
|
|
49309
|
-
const webSearchOutput = yield
|
|
49388
|
+
const webSearchOutput = yield validateTypes2({
|
|
49310
49389
|
value: output.value,
|
|
49311
49390
|
schema: webSearch_20250305OutputSchema
|
|
49312
49391
|
});
|
|
@@ -49448,7 +49527,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49448
49527
|
var _a4;
|
|
49449
49528
|
this.modelId = modelId;
|
|
49450
49529
|
this.config = config;
|
|
49451
|
-
this.generateId = (_a4 = config.generateId) != null ? _a4 :
|
|
49530
|
+
this.generateId = (_a4 = config.generateId) != null ? _a4 : generateId2;
|
|
49452
49531
|
}
|
|
49453
49532
|
supportsUrl(url) {
|
|
49454
49533
|
return url.protocol === "https:";
|
|
@@ -49462,6 +49541,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49462
49541
|
}
|
|
49463
49542
|
getArgs(_0) {
|
|
49464
49543
|
return __async(this, arguments, function* ({
|
|
49544
|
+
userSuppliedBetas,
|
|
49465
49545
|
prompt,
|
|
49466
49546
|
maxOutputTokens,
|
|
49467
49547
|
temperature,
|
|
@@ -49476,7 +49556,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49476
49556
|
toolChoice,
|
|
49477
49557
|
providerOptions
|
|
49478
49558
|
}) {
|
|
49479
|
-
var _a4, _b, _c, _d2;
|
|
49559
|
+
var _a4, _b, _c, _d2, _e;
|
|
49480
49560
|
const warnings = [];
|
|
49481
49561
|
if (frequencyPenalty != null) {
|
|
49482
49562
|
warnings.push({
|
|
@@ -49496,6 +49576,21 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49496
49576
|
setting: "seed"
|
|
49497
49577
|
});
|
|
49498
49578
|
}
|
|
49579
|
+
if (temperature != null && temperature > 1) {
|
|
49580
|
+
warnings.push({
|
|
49581
|
+
type: "unsupported-setting",
|
|
49582
|
+
setting: "temperature",
|
|
49583
|
+
details: `${temperature} exceeds anthropic maximum of 1.0. clamped to 1.0`
|
|
49584
|
+
});
|
|
49585
|
+
temperature = 1;
|
|
49586
|
+
} else if (temperature != null && temperature < 0) {
|
|
49587
|
+
warnings.push({
|
|
49588
|
+
type: "unsupported-setting",
|
|
49589
|
+
setting: "temperature",
|
|
49590
|
+
details: `${temperature} is below anthropic minimum of 0. clamped to 0`
|
|
49591
|
+
});
|
|
49592
|
+
temperature = 0;
|
|
49593
|
+
}
|
|
49499
49594
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
49500
49595
|
if (responseFormat.schema == null) {
|
|
49501
49596
|
warnings.push({
|
|
@@ -49511,29 +49606,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49511
49606
|
});
|
|
49512
49607
|
}
|
|
49513
49608
|
}
|
|
49514
|
-
const
|
|
49609
|
+
const anthropicOptions = yield parseProviderOptions2({
|
|
49610
|
+
provider: "anthropic",
|
|
49611
|
+
providerOptions,
|
|
49612
|
+
schema: anthropicProviderOptions
|
|
49613
|
+
});
|
|
49614
|
+
const {
|
|
49615
|
+
maxOutputTokens: maxOutputTokensForModel,
|
|
49616
|
+
supportsStructuredOutput,
|
|
49617
|
+
isKnownModel
|
|
49618
|
+
} = getModelCapabilities(this.modelId);
|
|
49619
|
+
const structureOutputMode = (_a4 = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a4 : "jsonTool";
|
|
49620
|
+
const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
|
|
49621
|
+
const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
|
|
49515
49622
|
type: "function",
|
|
49516
49623
|
name: "json",
|
|
49517
49624
|
description: "Respond with a JSON object.",
|
|
49518
49625
|
inputSchema: responseFormat.schema
|
|
49519
49626
|
} : void 0;
|
|
49520
|
-
const anthropicOptions = yield parseProviderOptions({
|
|
49521
|
-
provider: "anthropic",
|
|
49522
|
-
providerOptions,
|
|
49523
|
-
schema: anthropicProviderOptions
|
|
49524
|
-
});
|
|
49525
49627
|
const cacheControlValidator = new CacheControlValidator();
|
|
49526
49628
|
const { prompt: messagesPrompt, betas } = yield convertToAnthropicMessagesPrompt({
|
|
49527
49629
|
prompt,
|
|
49528
|
-
sendReasoning: (
|
|
49630
|
+
sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
|
|
49529
49631
|
warnings,
|
|
49530
49632
|
cacheControlValidator
|
|
49531
49633
|
});
|
|
49532
|
-
const isThinking = ((
|
|
49533
|
-
const thinkingBudget = (
|
|
49534
|
-
const maxOutputTokensForModel = getMaxOutputTokensForModel(this.modelId);
|
|
49634
|
+
const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
|
|
49635
|
+
const thinkingBudget = (_d2 = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d2.budgetTokens;
|
|
49535
49636
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
49536
|
-
const baseArgs = __spreadProps(__spreadValues(__spreadValues({
|
|
49637
|
+
const baseArgs = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
49537
49638
|
// model id:
|
|
49538
49639
|
model: this.modelId,
|
|
49539
49640
|
// standardized settings:
|
|
@@ -49544,10 +49645,17 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49544
49645
|
stop_sequences: stopSequences
|
|
49545
49646
|
}, isThinking && {
|
|
49546
49647
|
thinking: { type: "enabled", budget_tokens: thinkingBudget }
|
|
49648
|
+
}), (anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
49649
|
+
output_config: { effort: anthropicOptions.effort }
|
|
49650
|
+
}), useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
49651
|
+
output_format: {
|
|
49652
|
+
type: "json_schema",
|
|
49653
|
+
schema: responseFormat.schema
|
|
49654
|
+
}
|
|
49547
49655
|
}), (anthropicOptions == null ? void 0 : anthropicOptions.container) && {
|
|
49548
49656
|
container: {
|
|
49549
49657
|
id: anthropicOptions.container.id,
|
|
49550
|
-
skills: (
|
|
49658
|
+
skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
|
|
49551
49659
|
type: skill.type,
|
|
49552
49660
|
skill_id: skill.skillId,
|
|
49553
49661
|
version: skill.version
|
|
@@ -49590,7 +49698,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49590
49698
|
}
|
|
49591
49699
|
baseArgs.max_tokens = maxTokens + thinkingBudget;
|
|
49592
49700
|
}
|
|
49593
|
-
if (baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
49701
|
+
if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
|
|
49594
49702
|
if (maxOutputTokens != null) {
|
|
49595
49703
|
warnings.push({
|
|
49596
49704
|
type: "unsupported-setting",
|
|
@@ -49613,6 +49721,12 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49613
49721
|
});
|
|
49614
49722
|
}
|
|
49615
49723
|
}
|
|
49724
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
49725
|
+
betas.add("effort-2025-11-24");
|
|
49726
|
+
}
|
|
49727
|
+
if (useStructuredOutput) {
|
|
49728
|
+
betas.add("structured-outputs-2025-11-13");
|
|
49729
|
+
}
|
|
49616
49730
|
const {
|
|
49617
49731
|
tools: anthropicTools2,
|
|
49618
49732
|
toolChoice: anthropicToolChoice,
|
|
@@ -49638,7 +49752,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49638
49752
|
tool_choice: anthropicToolChoice
|
|
49639
49753
|
}),
|
|
49640
49754
|
warnings: [...warnings, ...toolWarnings, ...cacheWarnings],
|
|
49641
|
-
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas]),
|
|
49755
|
+
betas: /* @__PURE__ */ new Set([...betas, ...toolsBetas, ...userSuppliedBetas]),
|
|
49642
49756
|
usesJsonResponseTool: jsonResponseTool != null
|
|
49643
49757
|
};
|
|
49644
49758
|
});
|
|
@@ -49648,10 +49762,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49648
49762
|
betas,
|
|
49649
49763
|
headers
|
|
49650
49764
|
}) {
|
|
49651
|
-
return
|
|
49652
|
-
yield
|
|
49653
|
-
|
|
49654
|
-
|
|
49765
|
+
return combineHeaders2(
|
|
49766
|
+
yield resolve2(this.config.headers),
|
|
49767
|
+
headers,
|
|
49768
|
+
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
|
|
49769
|
+
);
|
|
49770
|
+
});
|
|
49771
|
+
}
|
|
49772
|
+
getBetasFromHeaders(requestHeaders) {
|
|
49773
|
+
return __async(this, null, function* () {
|
|
49774
|
+
var _a4, _b;
|
|
49775
|
+
const configHeaders = yield resolve2(this.config.headers);
|
|
49776
|
+
const configBetaHeader = (_a4 = configHeaders["anthropic-beta"]) != null ? _a4 : "";
|
|
49777
|
+
const requestBetaHeader = (_b = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b : "";
|
|
49778
|
+
return new Set(
|
|
49779
|
+
[
|
|
49780
|
+
...configBetaHeader.toLowerCase().split(","),
|
|
49781
|
+
...requestBetaHeader.toLowerCase().split(",")
|
|
49782
|
+
].map((beta) => beta.trim()).filter((beta) => beta !== "")
|
|
49655
49783
|
);
|
|
49656
49784
|
});
|
|
49657
49785
|
}
|
|
@@ -49689,18 +49817,20 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49689
49817
|
doGenerate(options) {
|
|
49690
49818
|
return __async(this, null, function* () {
|
|
49691
49819
|
var _a4, _b, _c, _d2, _e, _f, _g, _h;
|
|
49692
|
-
const { args, warnings, betas, usesJsonResponseTool } = yield this.getArgs(options)
|
|
49820
|
+
const { args, warnings, betas, usesJsonResponseTool } = yield this.getArgs(__spreadProps(__spreadValues({}, options), {
|
|
49821
|
+
userSuppliedBetas: yield this.getBetasFromHeaders(options.headers)
|
|
49822
|
+
}));
|
|
49693
49823
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
49694
49824
|
const {
|
|
49695
49825
|
responseHeaders,
|
|
49696
49826
|
value: response,
|
|
49697
49827
|
rawValue: rawResponse
|
|
49698
|
-
} = yield
|
|
49828
|
+
} = yield postJsonToApi2({
|
|
49699
49829
|
url: this.buildRequestUrl(false),
|
|
49700
49830
|
headers: yield this.getHeaders({ betas, headers: options.headers }),
|
|
49701
49831
|
body: this.transformRequestBody(args),
|
|
49702
49832
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
49703
|
-
successfulResponseHandler:
|
|
49833
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
49704
49834
|
anthropicMessagesResponseSchema
|
|
49705
49835
|
),
|
|
49706
49836
|
abortSignal: options.abortSignal,
|
|
@@ -49956,15 +50086,19 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49956
50086
|
}
|
|
49957
50087
|
doStream(options) {
|
|
49958
50088
|
return __async(this, null, function* () {
|
|
49959
|
-
|
|
50089
|
+
var _a4, _b;
|
|
50090
|
+
const { args, warnings, betas, usesJsonResponseTool } = yield this.getArgs(__spreadProps(__spreadValues({}, options), {
|
|
50091
|
+
userSuppliedBetas: yield this.getBetasFromHeaders(options.headers)
|
|
50092
|
+
}));
|
|
49960
50093
|
const citationDocuments = this.extractCitationDocuments(options.prompt);
|
|
49961
50094
|
const body = __spreadProps(__spreadValues({}, args), { stream: true });
|
|
49962
|
-
const
|
|
49963
|
-
|
|
50095
|
+
const url = this.buildRequestUrl(true);
|
|
50096
|
+
const { responseHeaders, value: response } = yield postJsonToApi2({
|
|
50097
|
+
url,
|
|
49964
50098
|
headers: yield this.getHeaders({ betas, headers: options.headers }),
|
|
49965
50099
|
body: this.transformRequestBody(body),
|
|
49966
50100
|
failedResponseHandler: anthropicFailedResponseHandler,
|
|
49967
|
-
successfulResponseHandler:
|
|
50101
|
+
successfulResponseHandler: createEventSourceResponseHandler2(
|
|
49968
50102
|
anthropicMessagesChunkSchema
|
|
49969
50103
|
),
|
|
49970
50104
|
abortSignal: options.abortSignal,
|
|
@@ -49983,477 +50117,538 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
49983
50117
|
let container = null;
|
|
49984
50118
|
let blockType = void 0;
|
|
49985
50119
|
const generateId3 = this.generateId;
|
|
49986
|
-
|
|
49987
|
-
|
|
49988
|
-
|
|
49989
|
-
start
|
|
49990
|
-
|
|
49991
|
-
|
|
49992
|
-
|
|
49993
|
-
|
|
49994
|
-
|
|
49995
|
-
|
|
49996
|
-
|
|
49997
|
-
|
|
49998
|
-
|
|
50120
|
+
const transformedStream = response.pipeThrough(
|
|
50121
|
+
new TransformStream({
|
|
50122
|
+
start(controller) {
|
|
50123
|
+
controller.enqueue({ type: "stream-start", warnings });
|
|
50124
|
+
},
|
|
50125
|
+
transform(chunk, controller) {
|
|
50126
|
+
var _a22, _b2, _c, _d2, _e, _f, _g, _h, _i, _j;
|
|
50127
|
+
if (options.includeRawChunks) {
|
|
50128
|
+
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
50129
|
+
}
|
|
50130
|
+
if (!chunk.success) {
|
|
50131
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
50132
|
+
return;
|
|
50133
|
+
}
|
|
50134
|
+
const value = chunk.value;
|
|
50135
|
+
switch (value.type) {
|
|
50136
|
+
case "ping": {
|
|
49999
50137
|
return;
|
|
50000
50138
|
}
|
|
50001
|
-
|
|
50002
|
-
|
|
50003
|
-
|
|
50004
|
-
|
|
50005
|
-
|
|
50006
|
-
|
|
50007
|
-
|
|
50008
|
-
|
|
50009
|
-
|
|
50010
|
-
|
|
50011
|
-
|
|
50012
|
-
|
|
50013
|
-
|
|
50014
|
-
|
|
50015
|
-
|
|
50016
|
-
|
|
50017
|
-
|
|
50018
|
-
|
|
50019
|
-
|
|
50020
|
-
|
|
50021
|
-
|
|
50022
|
-
|
|
50023
|
-
|
|
50024
|
-
|
|
50025
|
-
|
|
50026
|
-
|
|
50027
|
-
|
|
50028
|
-
|
|
50029
|
-
type: "reasoning-start",
|
|
50030
|
-
id: String(value.index),
|
|
50031
|
-
providerMetadata: {
|
|
50032
|
-
anthropic: {
|
|
50033
|
-
redactedData: value.content_block.data
|
|
50034
|
-
}
|
|
50139
|
+
case "content_block_start": {
|
|
50140
|
+
const contentBlockType = value.content_block.type;
|
|
50141
|
+
blockType = contentBlockType;
|
|
50142
|
+
switch (contentBlockType) {
|
|
50143
|
+
case "text": {
|
|
50144
|
+
contentBlocks[value.index] = { type: "text" };
|
|
50145
|
+
controller.enqueue({
|
|
50146
|
+
type: "text-start",
|
|
50147
|
+
id: String(value.index)
|
|
50148
|
+
});
|
|
50149
|
+
return;
|
|
50150
|
+
}
|
|
50151
|
+
case "thinking": {
|
|
50152
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
50153
|
+
controller.enqueue({
|
|
50154
|
+
type: "reasoning-start",
|
|
50155
|
+
id: String(value.index)
|
|
50156
|
+
});
|
|
50157
|
+
return;
|
|
50158
|
+
}
|
|
50159
|
+
case "redacted_thinking": {
|
|
50160
|
+
contentBlocks[value.index] = { type: "reasoning" };
|
|
50161
|
+
controller.enqueue({
|
|
50162
|
+
type: "reasoning-start",
|
|
50163
|
+
id: String(value.index),
|
|
50164
|
+
providerMetadata: {
|
|
50165
|
+
anthropic: {
|
|
50166
|
+
redactedData: value.content_block.data
|
|
50035
50167
|
}
|
|
50036
|
-
}
|
|
50037
|
-
|
|
50038
|
-
|
|
50039
|
-
|
|
50040
|
-
|
|
50168
|
+
}
|
|
50169
|
+
});
|
|
50170
|
+
return;
|
|
50171
|
+
}
|
|
50172
|
+
case "tool_use": {
|
|
50173
|
+
contentBlocks[value.index] = usesJsonResponseTool ? { type: "text" } : {
|
|
50174
|
+
type: "tool-call",
|
|
50175
|
+
toolCallId: value.content_block.id,
|
|
50176
|
+
toolName: value.content_block.name,
|
|
50177
|
+
input: "",
|
|
50178
|
+
firstDelta: true
|
|
50179
|
+
};
|
|
50180
|
+
controller.enqueue(
|
|
50181
|
+
usesJsonResponseTool ? { type: "text-start", id: String(value.index) } : {
|
|
50182
|
+
type: "tool-input-start",
|
|
50183
|
+
id: value.content_block.id,
|
|
50184
|
+
toolName: value.content_block.name
|
|
50185
|
+
}
|
|
50186
|
+
);
|
|
50187
|
+
return;
|
|
50188
|
+
}
|
|
50189
|
+
case "server_tool_use": {
|
|
50190
|
+
if ([
|
|
50191
|
+
"web_fetch",
|
|
50192
|
+
"web_search",
|
|
50193
|
+
// code execution 20250825:
|
|
50194
|
+
"code_execution",
|
|
50195
|
+
// code execution 20250825 text editor:
|
|
50196
|
+
"text_editor_code_execution",
|
|
50197
|
+
// code execution 20250825 bash:
|
|
50198
|
+
"bash_code_execution"
|
|
50199
|
+
].includes(value.content_block.name)) {
|
|
50200
|
+
contentBlocks[value.index] = {
|
|
50041
50201
|
type: "tool-call",
|
|
50042
50202
|
toolCallId: value.content_block.id,
|
|
50043
50203
|
toolName: value.content_block.name,
|
|
50044
50204
|
input: "",
|
|
50205
|
+
providerExecuted: true,
|
|
50045
50206
|
firstDelta: true
|
|
50046
50207
|
};
|
|
50047
|
-
|
|
50048
|
-
|
|
50049
|
-
|
|
50050
|
-
|
|
50051
|
-
|
|
50052
|
-
|
|
50053
|
-
);
|
|
50054
|
-
return;
|
|
50055
|
-
}
|
|
50056
|
-
case "server_tool_use": {
|
|
50057
|
-
if ([
|
|
50058
|
-
"web_fetch",
|
|
50059
|
-
"web_search",
|
|
50060
|
-
// code execution 20250825:
|
|
50061
|
-
"code_execution",
|
|
50062
|
-
// code execution 20250825 text editor:
|
|
50063
|
-
"text_editor_code_execution",
|
|
50064
|
-
// code execution 20250825 bash:
|
|
50065
|
-
"bash_code_execution"
|
|
50066
|
-
].includes(value.content_block.name)) {
|
|
50067
|
-
contentBlocks[value.index] = {
|
|
50068
|
-
type: "tool-call",
|
|
50069
|
-
toolCallId: value.content_block.id,
|
|
50070
|
-
toolName: value.content_block.name,
|
|
50071
|
-
input: "",
|
|
50072
|
-
providerExecuted: true,
|
|
50073
|
-
firstDelta: true
|
|
50074
|
-
};
|
|
50075
|
-
const mappedToolName = value.content_block.name === "text_editor_code_execution" || value.content_block.name === "bash_code_execution" ? "code_execution" : value.content_block.name;
|
|
50076
|
-
controller.enqueue({
|
|
50077
|
-
type: "tool-input-start",
|
|
50078
|
-
id: value.content_block.id,
|
|
50079
|
-
toolName: mappedToolName,
|
|
50080
|
-
providerExecuted: true
|
|
50081
|
-
});
|
|
50082
|
-
}
|
|
50083
|
-
return;
|
|
50208
|
+
const mappedToolName = value.content_block.name === "text_editor_code_execution" || value.content_block.name === "bash_code_execution" ? "code_execution" : value.content_block.name;
|
|
50209
|
+
controller.enqueue({
|
|
50210
|
+
type: "tool-input-start",
|
|
50211
|
+
id: value.content_block.id,
|
|
50212
|
+
toolName: mappedToolName,
|
|
50213
|
+
providerExecuted: true
|
|
50214
|
+
});
|
|
50084
50215
|
}
|
|
50085
|
-
|
|
50086
|
-
|
|
50087
|
-
|
|
50088
|
-
|
|
50089
|
-
|
|
50090
|
-
|
|
50091
|
-
|
|
50092
|
-
|
|
50093
|
-
|
|
50094
|
-
|
|
50095
|
-
|
|
50096
|
-
|
|
50097
|
-
|
|
50098
|
-
|
|
50099
|
-
|
|
50100
|
-
|
|
50101
|
-
|
|
50102
|
-
|
|
50103
|
-
|
|
50104
|
-
|
|
50216
|
+
return;
|
|
50217
|
+
}
|
|
50218
|
+
case "web_fetch_tool_result": {
|
|
50219
|
+
const part = value.content_block;
|
|
50220
|
+
if (part.content.type === "web_fetch_result") {
|
|
50221
|
+
controller.enqueue({
|
|
50222
|
+
type: "tool-result",
|
|
50223
|
+
toolCallId: part.tool_use_id,
|
|
50224
|
+
toolName: "web_fetch",
|
|
50225
|
+
result: {
|
|
50226
|
+
type: "web_fetch_result",
|
|
50227
|
+
url: part.content.url,
|
|
50228
|
+
retrievedAt: part.content.retrieved_at,
|
|
50229
|
+
content: {
|
|
50230
|
+
type: part.content.content.type,
|
|
50231
|
+
title: part.content.content.title,
|
|
50232
|
+
citations: part.content.content.citations,
|
|
50233
|
+
source: {
|
|
50234
|
+
type: part.content.content.source.type,
|
|
50235
|
+
mediaType: part.content.content.source.media_type,
|
|
50236
|
+
data: part.content.content.source.data
|
|
50105
50237
|
}
|
|
50106
50238
|
}
|
|
50107
|
-
}
|
|
50108
|
-
|
|
50109
|
-
|
|
50110
|
-
|
|
50111
|
-
|
|
50112
|
-
|
|
50113
|
-
|
|
50114
|
-
|
|
50115
|
-
|
|
50116
|
-
|
|
50117
|
-
|
|
50118
|
-
|
|
50119
|
-
}
|
|
50120
|
-
|
|
50121
|
-
|
|
50239
|
+
},
|
|
50240
|
+
providerExecuted: true
|
|
50241
|
+
});
|
|
50242
|
+
} else if (part.content.type === "web_fetch_tool_result_error") {
|
|
50243
|
+
controller.enqueue({
|
|
50244
|
+
type: "tool-result",
|
|
50245
|
+
toolCallId: part.tool_use_id,
|
|
50246
|
+
toolName: "web_fetch",
|
|
50247
|
+
isError: true,
|
|
50248
|
+
result: {
|
|
50249
|
+
type: "web_fetch_tool_result_error",
|
|
50250
|
+
errorCode: part.content.error_code
|
|
50251
|
+
},
|
|
50252
|
+
providerExecuted: true
|
|
50253
|
+
});
|
|
50122
50254
|
}
|
|
50123
|
-
|
|
50124
|
-
|
|
50125
|
-
|
|
50126
|
-
|
|
50127
|
-
|
|
50128
|
-
|
|
50129
|
-
|
|
50130
|
-
|
|
50131
|
-
|
|
50132
|
-
|
|
50133
|
-
|
|
50134
|
-
|
|
50135
|
-
pageAge: (_a22 = result.page_age) != null ? _a22 : null,
|
|
50136
|
-
encryptedContent: result.encrypted_content,
|
|
50137
|
-
type: result.type
|
|
50138
|
-
};
|
|
50139
|
-
}),
|
|
50140
|
-
providerExecuted: true
|
|
50141
|
-
});
|
|
50142
|
-
for (const result of part.content) {
|
|
50143
|
-
controller.enqueue({
|
|
50144
|
-
type: "source",
|
|
50145
|
-
sourceType: "url",
|
|
50146
|
-
id: generateId3(),
|
|
50255
|
+
return;
|
|
50256
|
+
}
|
|
50257
|
+
case "web_search_tool_result": {
|
|
50258
|
+
const part = value.content_block;
|
|
50259
|
+
if (Array.isArray(part.content)) {
|
|
50260
|
+
controller.enqueue({
|
|
50261
|
+
type: "tool-result",
|
|
50262
|
+
toolCallId: part.tool_use_id,
|
|
50263
|
+
toolName: "web_search",
|
|
50264
|
+
result: part.content.map((result) => {
|
|
50265
|
+
var _a32;
|
|
50266
|
+
return {
|
|
50147
50267
|
url: result.url,
|
|
50148
50268
|
title: result.title,
|
|
50149
|
-
|
|
50150
|
-
|
|
50151
|
-
|
|
50152
|
-
|
|
50153
|
-
|
|
50154
|
-
|
|
50155
|
-
|
|
50156
|
-
|
|
50157
|
-
controller.enqueue({
|
|
50158
|
-
type: "tool-result",
|
|
50159
|
-
toolCallId: part.tool_use_id,
|
|
50160
|
-
toolName: "web_search",
|
|
50161
|
-
isError: true,
|
|
50162
|
-
result: {
|
|
50163
|
-
type: "web_search_tool_result_error",
|
|
50164
|
-
errorCode: part.content.error_code
|
|
50165
|
-
},
|
|
50166
|
-
providerExecuted: true
|
|
50167
|
-
});
|
|
50168
|
-
}
|
|
50169
|
-
return;
|
|
50170
|
-
}
|
|
50171
|
-
// code execution 20250522:
|
|
50172
|
-
case "code_execution_tool_result": {
|
|
50173
|
-
const part = value.content_block;
|
|
50174
|
-
if (part.content.type === "code_execution_result") {
|
|
50175
|
-
controller.enqueue({
|
|
50176
|
-
type: "tool-result",
|
|
50177
|
-
toolCallId: part.tool_use_id,
|
|
50178
|
-
toolName: "code_execution",
|
|
50179
|
-
result: {
|
|
50180
|
-
type: part.content.type,
|
|
50181
|
-
stdout: part.content.stdout,
|
|
50182
|
-
stderr: part.content.stderr,
|
|
50183
|
-
return_code: part.content.return_code
|
|
50184
|
-
},
|
|
50185
|
-
providerExecuted: true
|
|
50186
|
-
});
|
|
50187
|
-
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
50269
|
+
pageAge: (_a32 = result.page_age) != null ? _a32 : null,
|
|
50270
|
+
encryptedContent: result.encrypted_content,
|
|
50271
|
+
type: result.type
|
|
50272
|
+
};
|
|
50273
|
+
}),
|
|
50274
|
+
providerExecuted: true
|
|
50275
|
+
});
|
|
50276
|
+
for (const result of part.content) {
|
|
50188
50277
|
controller.enqueue({
|
|
50189
|
-
type: "
|
|
50190
|
-
|
|
50191
|
-
|
|
50192
|
-
|
|
50193
|
-
|
|
50194
|
-
|
|
50195
|
-
|
|
50196
|
-
|
|
50197
|
-
|
|
50278
|
+
type: "source",
|
|
50279
|
+
sourceType: "url",
|
|
50280
|
+
id: generateId3(),
|
|
50281
|
+
url: result.url,
|
|
50282
|
+
title: result.title,
|
|
50283
|
+
providerMetadata: {
|
|
50284
|
+
anthropic: {
|
|
50285
|
+
pageAge: (_a22 = result.page_age) != null ? _a22 : null
|
|
50286
|
+
}
|
|
50287
|
+
}
|
|
50198
50288
|
});
|
|
50199
50289
|
}
|
|
50200
|
-
|
|
50290
|
+
} else {
|
|
50291
|
+
controller.enqueue({
|
|
50292
|
+
type: "tool-result",
|
|
50293
|
+
toolCallId: part.tool_use_id,
|
|
50294
|
+
toolName: "web_search",
|
|
50295
|
+
isError: true,
|
|
50296
|
+
result: {
|
|
50297
|
+
type: "web_search_tool_result_error",
|
|
50298
|
+
errorCode: part.content.error_code
|
|
50299
|
+
},
|
|
50300
|
+
providerExecuted: true
|
|
50301
|
+
});
|
|
50201
50302
|
}
|
|
50202
|
-
|
|
50203
|
-
|
|
50204
|
-
|
|
50205
|
-
|
|
50303
|
+
return;
|
|
50304
|
+
}
|
|
50305
|
+
// code execution 20250522:
|
|
50306
|
+
case "code_execution_tool_result": {
|
|
50307
|
+
const part = value.content_block;
|
|
50308
|
+
if (part.content.type === "code_execution_result") {
|
|
50206
50309
|
controller.enqueue({
|
|
50207
50310
|
type: "tool-result",
|
|
50208
50311
|
toolCallId: part.tool_use_id,
|
|
50209
50312
|
toolName: "code_execution",
|
|
50210
|
-
result:
|
|
50313
|
+
result: {
|
|
50314
|
+
type: part.content.type,
|
|
50315
|
+
stdout: part.content.stdout,
|
|
50316
|
+
stderr: part.content.stderr,
|
|
50317
|
+
return_code: part.content.return_code
|
|
50318
|
+
},
|
|
50319
|
+
providerExecuted: true
|
|
50320
|
+
});
|
|
50321
|
+
} else if (part.content.type === "code_execution_tool_result_error") {
|
|
50322
|
+
controller.enqueue({
|
|
50323
|
+
type: "tool-result",
|
|
50324
|
+
toolCallId: part.tool_use_id,
|
|
50325
|
+
toolName: "code_execution",
|
|
50326
|
+
isError: true,
|
|
50327
|
+
result: {
|
|
50328
|
+
type: "code_execution_tool_result_error",
|
|
50329
|
+
errorCode: part.content.error_code
|
|
50330
|
+
},
|
|
50211
50331
|
providerExecuted: true
|
|
50212
50332
|
});
|
|
50213
|
-
return;
|
|
50214
|
-
}
|
|
50215
|
-
default: {
|
|
50216
|
-
const _exhaustiveCheck = contentBlockType;
|
|
50217
|
-
throw new Error(
|
|
50218
|
-
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
50219
|
-
);
|
|
50220
50333
|
}
|
|
50334
|
+
return;
|
|
50335
|
+
}
|
|
50336
|
+
// code execution 20250825:
|
|
50337
|
+
case "bash_code_execution_tool_result":
|
|
50338
|
+
case "text_editor_code_execution_tool_result": {
|
|
50339
|
+
const part = value.content_block;
|
|
50340
|
+
controller.enqueue({
|
|
50341
|
+
type: "tool-result",
|
|
50342
|
+
toolCallId: part.tool_use_id,
|
|
50343
|
+
toolName: "code_execution",
|
|
50344
|
+
result: part.content,
|
|
50345
|
+
providerExecuted: true
|
|
50346
|
+
});
|
|
50347
|
+
return;
|
|
50348
|
+
}
|
|
50349
|
+
default: {
|
|
50350
|
+
const _exhaustiveCheck = contentBlockType;
|
|
50351
|
+
throw new Error(
|
|
50352
|
+
`Unsupported content block type: ${_exhaustiveCheck}`
|
|
50353
|
+
);
|
|
50221
50354
|
}
|
|
50222
50355
|
}
|
|
50223
|
-
|
|
50224
|
-
|
|
50225
|
-
|
|
50226
|
-
|
|
50227
|
-
|
|
50356
|
+
}
|
|
50357
|
+
case "content_block_stop": {
|
|
50358
|
+
if (contentBlocks[value.index] != null) {
|
|
50359
|
+
const contentBlock = contentBlocks[value.index];
|
|
50360
|
+
switch (contentBlock.type) {
|
|
50361
|
+
case "text": {
|
|
50362
|
+
controller.enqueue({
|
|
50363
|
+
type: "text-end",
|
|
50364
|
+
id: String(value.index)
|
|
50365
|
+
});
|
|
50366
|
+
break;
|
|
50367
|
+
}
|
|
50368
|
+
case "reasoning": {
|
|
50369
|
+
controller.enqueue({
|
|
50370
|
+
type: "reasoning-end",
|
|
50371
|
+
id: String(value.index)
|
|
50372
|
+
});
|
|
50373
|
+
break;
|
|
50374
|
+
}
|
|
50375
|
+
case "tool-call":
|
|
50376
|
+
if (!usesJsonResponseTool) {
|
|
50228
50377
|
controller.enqueue({
|
|
50229
|
-
type: "
|
|
50230
|
-
id:
|
|
50378
|
+
type: "tool-input-end",
|
|
50379
|
+
id: contentBlock.toolCallId
|
|
50231
50380
|
});
|
|
50232
|
-
|
|
50233
|
-
}
|
|
50234
|
-
case "reasoning": {
|
|
50381
|
+
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
50235
50382
|
controller.enqueue({
|
|
50236
|
-
type: "
|
|
50237
|
-
|
|
50383
|
+
type: "tool-call",
|
|
50384
|
+
toolCallId: contentBlock.toolCallId,
|
|
50385
|
+
toolName,
|
|
50386
|
+
input: contentBlock.input === "" ? "{}" : contentBlock.input,
|
|
50387
|
+
providerExecuted: contentBlock.providerExecuted
|
|
50238
50388
|
});
|
|
50239
|
-
break;
|
|
50240
50389
|
}
|
|
50241
|
-
|
|
50242
|
-
if (!usesJsonResponseTool) {
|
|
50243
|
-
controller.enqueue({
|
|
50244
|
-
type: "tool-input-end",
|
|
50245
|
-
id: contentBlock.toolCallId
|
|
50246
|
-
});
|
|
50247
|
-
const toolName = contentBlock.toolName === "text_editor_code_execution" || contentBlock.toolName === "bash_code_execution" ? "code_execution" : contentBlock.toolName;
|
|
50248
|
-
controller.enqueue({
|
|
50249
|
-
type: "tool-call",
|
|
50250
|
-
toolCallId: contentBlock.toolCallId,
|
|
50251
|
-
toolName,
|
|
50252
|
-
input: contentBlock.input,
|
|
50253
|
-
providerExecuted: contentBlock.providerExecuted
|
|
50254
|
-
});
|
|
50255
|
-
}
|
|
50256
|
-
break;
|
|
50257
|
-
}
|
|
50258
|
-
delete contentBlocks[value.index];
|
|
50390
|
+
break;
|
|
50259
50391
|
}
|
|
50260
|
-
|
|
50261
|
-
return;
|
|
50392
|
+
delete contentBlocks[value.index];
|
|
50262
50393
|
}
|
|
50263
|
-
|
|
50264
|
-
|
|
50265
|
-
|
|
50266
|
-
|
|
50267
|
-
|
|
50268
|
-
|
|
50269
|
-
|
|
50270
|
-
|
|
50271
|
-
type: "text-delta",
|
|
50272
|
-
id: String(value.index),
|
|
50273
|
-
delta: value.delta.text
|
|
50274
|
-
});
|
|
50394
|
+
blockType = void 0;
|
|
50395
|
+
return;
|
|
50396
|
+
}
|
|
50397
|
+
case "content_block_delta": {
|
|
50398
|
+
const deltaType = value.delta.type;
|
|
50399
|
+
switch (deltaType) {
|
|
50400
|
+
case "text_delta": {
|
|
50401
|
+
if (usesJsonResponseTool) {
|
|
50275
50402
|
return;
|
|
50276
50403
|
}
|
|
50277
|
-
|
|
50404
|
+
controller.enqueue({
|
|
50405
|
+
type: "text-delta",
|
|
50406
|
+
id: String(value.index),
|
|
50407
|
+
delta: value.delta.text
|
|
50408
|
+
});
|
|
50409
|
+
return;
|
|
50410
|
+
}
|
|
50411
|
+
case "thinking_delta": {
|
|
50412
|
+
controller.enqueue({
|
|
50413
|
+
type: "reasoning-delta",
|
|
50414
|
+
id: String(value.index),
|
|
50415
|
+
delta: value.delta.thinking
|
|
50416
|
+
});
|
|
50417
|
+
return;
|
|
50418
|
+
}
|
|
50419
|
+
case "signature_delta": {
|
|
50420
|
+
if (blockType === "thinking") {
|
|
50278
50421
|
controller.enqueue({
|
|
50279
50422
|
type: "reasoning-delta",
|
|
50280
50423
|
id: String(value.index),
|
|
50281
|
-
delta:
|
|
50424
|
+
delta: "",
|
|
50425
|
+
providerMetadata: {
|
|
50426
|
+
anthropic: {
|
|
50427
|
+
signature: value.delta.signature
|
|
50428
|
+
}
|
|
50429
|
+
}
|
|
50282
50430
|
});
|
|
50283
|
-
return;
|
|
50284
50431
|
}
|
|
50285
|
-
|
|
50286
|
-
|
|
50287
|
-
|
|
50288
|
-
|
|
50289
|
-
|
|
50290
|
-
|
|
50291
|
-
providerMetadata: {
|
|
50292
|
-
anthropic: {
|
|
50293
|
-
signature: value.delta.signature
|
|
50294
|
-
}
|
|
50295
|
-
}
|
|
50296
|
-
});
|
|
50297
|
-
}
|
|
50432
|
+
return;
|
|
50433
|
+
}
|
|
50434
|
+
case "input_json_delta": {
|
|
50435
|
+
const contentBlock = contentBlocks[value.index];
|
|
50436
|
+
let delta = value.delta.partial_json;
|
|
50437
|
+
if (delta.length === 0) {
|
|
50298
50438
|
return;
|
|
50299
50439
|
}
|
|
50300
|
-
|
|
50301
|
-
|
|
50302
|
-
let delta = value.delta.partial_json;
|
|
50303
|
-
if (delta.length === 0) {
|
|
50440
|
+
if (usesJsonResponseTool) {
|
|
50441
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "text") {
|
|
50304
50442
|
return;
|
|
50305
50443
|
}
|
|
50306
|
-
|
|
50307
|
-
|
|
50308
|
-
|
|
50309
|
-
|
|
50310
|
-
|
|
50311
|
-
|
|
50312
|
-
|
|
50313
|
-
|
|
50314
|
-
});
|
|
50315
|
-
} else {
|
|
50316
|
-
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
50317
|
-
return;
|
|
50318
|
-
}
|
|
50319
|
-
if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
|
|
50320
|
-
delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
|
|
50321
|
-
}
|
|
50322
|
-
controller.enqueue({
|
|
50323
|
-
type: "tool-input-delta",
|
|
50324
|
-
id: contentBlock.toolCallId,
|
|
50325
|
-
delta
|
|
50326
|
-
});
|
|
50327
|
-
contentBlock.input += delta;
|
|
50328
|
-
contentBlock.firstDelta = false;
|
|
50444
|
+
controller.enqueue({
|
|
50445
|
+
type: "text-delta",
|
|
50446
|
+
id: String(value.index),
|
|
50447
|
+
delta
|
|
50448
|
+
});
|
|
50449
|
+
} else {
|
|
50450
|
+
if ((contentBlock == null ? void 0 : contentBlock.type) !== "tool-call") {
|
|
50451
|
+
return;
|
|
50329
50452
|
}
|
|
50330
|
-
|
|
50331
|
-
|
|
50332
|
-
case "citations_delta": {
|
|
50333
|
-
const citation = value.delta.citation;
|
|
50334
|
-
const source = createCitationSource(
|
|
50335
|
-
citation,
|
|
50336
|
-
citationDocuments,
|
|
50337
|
-
generateId3
|
|
50338
|
-
);
|
|
50339
|
-
if (source) {
|
|
50340
|
-
controller.enqueue(source);
|
|
50453
|
+
if (contentBlock.firstDelta && (contentBlock.toolName === "bash_code_execution" || contentBlock.toolName === "text_editor_code_execution")) {
|
|
50454
|
+
delta = `{"type": "${contentBlock.toolName}",${delta.substring(1)}`;
|
|
50341
50455
|
}
|
|
50342
|
-
|
|
50456
|
+
controller.enqueue({
|
|
50457
|
+
type: "tool-input-delta",
|
|
50458
|
+
id: contentBlock.toolCallId,
|
|
50459
|
+
delta
|
|
50460
|
+
});
|
|
50461
|
+
contentBlock.input += delta;
|
|
50462
|
+
contentBlock.firstDelta = false;
|
|
50343
50463
|
}
|
|
50344
|
-
|
|
50345
|
-
|
|
50346
|
-
|
|
50347
|
-
|
|
50348
|
-
|
|
50464
|
+
return;
|
|
50465
|
+
}
|
|
50466
|
+
case "citations_delta": {
|
|
50467
|
+
const citation = value.delta.citation;
|
|
50468
|
+
const source = createCitationSource(
|
|
50469
|
+
citation,
|
|
50470
|
+
citationDocuments,
|
|
50471
|
+
generateId3
|
|
50472
|
+
);
|
|
50473
|
+
if (source) {
|
|
50474
|
+
controller.enqueue(source);
|
|
50349
50475
|
}
|
|
50476
|
+
return;
|
|
50477
|
+
}
|
|
50478
|
+
default: {
|
|
50479
|
+
const _exhaustiveCheck = deltaType;
|
|
50480
|
+
throw new Error(
|
|
50481
|
+
`Unsupported delta type: ${_exhaustiveCheck}`
|
|
50482
|
+
);
|
|
50350
50483
|
}
|
|
50351
50484
|
}
|
|
50352
|
-
|
|
50353
|
-
|
|
50354
|
-
|
|
50355
|
-
|
|
50356
|
-
|
|
50357
|
-
|
|
50358
|
-
|
|
50359
|
-
|
|
50360
|
-
|
|
50361
|
-
|
|
50362
|
-
|
|
50363
|
-
|
|
50364
|
-
|
|
50365
|
-
|
|
50366
|
-
|
|
50367
|
-
|
|
50368
|
-
|
|
50369
|
-
|
|
50370
|
-
|
|
50371
|
-
|
|
50372
|
-
|
|
50373
|
-
|
|
50374
|
-
|
|
50375
|
-
|
|
50376
|
-
|
|
50377
|
-
|
|
50378
|
-
|
|
50379
|
-
|
|
50380
|
-
} : null
|
|
50381
|
-
|
|
50382
|
-
|
|
50383
|
-
|
|
50384
|
-
|
|
50385
|
-
|
|
50386
|
-
|
|
50387
|
-
|
|
50388
|
-
|
|
50389
|
-
|
|
50390
|
-
|
|
50391
|
-
|
|
50392
|
-
|
|
50393
|
-
|
|
50394
|
-
|
|
50395
|
-
|
|
50485
|
+
}
|
|
50486
|
+
case "message_start": {
|
|
50487
|
+
usage.inputTokens = value.message.usage.input_tokens;
|
|
50488
|
+
usage.cachedInputTokens = (_b2 = value.message.usage.cache_read_input_tokens) != null ? _b2 : void 0;
|
|
50489
|
+
rawUsage = __spreadValues({}, value.message.usage);
|
|
50490
|
+
cacheCreationInputTokens = (_c = value.message.usage.cache_creation_input_tokens) != null ? _c : null;
|
|
50491
|
+
controller.enqueue({
|
|
50492
|
+
type: "response-metadata",
|
|
50493
|
+
id: (_d2 = value.message.id) != null ? _d2 : void 0,
|
|
50494
|
+
modelId: (_e = value.message.model) != null ? _e : void 0
|
|
50495
|
+
});
|
|
50496
|
+
return;
|
|
50497
|
+
}
|
|
50498
|
+
case "message_delta": {
|
|
50499
|
+
usage.outputTokens = value.usage.output_tokens;
|
|
50500
|
+
usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
|
|
50501
|
+
finishReason = mapAnthropicStopReason({
|
|
50502
|
+
finishReason: value.delta.stop_reason,
|
|
50503
|
+
isJsonResponseFromTool: usesJsonResponseTool
|
|
50504
|
+
});
|
|
50505
|
+
stopSequence = (_h = value.delta.stop_sequence) != null ? _h : null;
|
|
50506
|
+
container = value.delta.container != null ? {
|
|
50507
|
+
expiresAt: value.delta.container.expires_at,
|
|
50508
|
+
id: value.delta.container.id,
|
|
50509
|
+
skills: (_j = (_i = value.delta.container.skills) == null ? void 0 : _i.map((skill) => ({
|
|
50510
|
+
type: skill.type,
|
|
50511
|
+
skillId: skill.skill_id,
|
|
50512
|
+
version: skill.version
|
|
50513
|
+
}))) != null ? _j : null
|
|
50514
|
+
} : null;
|
|
50515
|
+
rawUsage = __spreadValues(__spreadValues({}, rawUsage), value.usage);
|
|
50516
|
+
return;
|
|
50517
|
+
}
|
|
50518
|
+
case "message_stop": {
|
|
50519
|
+
controller.enqueue({
|
|
50520
|
+
type: "finish",
|
|
50521
|
+
finishReason,
|
|
50522
|
+
usage,
|
|
50523
|
+
providerMetadata: {
|
|
50524
|
+
anthropic: {
|
|
50525
|
+
usage: rawUsage != null ? rawUsage : null,
|
|
50526
|
+
cacheCreationInputTokens,
|
|
50527
|
+
stopSequence,
|
|
50528
|
+
container
|
|
50396
50529
|
}
|
|
50397
|
-
}
|
|
50398
|
-
|
|
50399
|
-
|
|
50400
|
-
|
|
50401
|
-
|
|
50402
|
-
|
|
50403
|
-
|
|
50404
|
-
|
|
50405
|
-
|
|
50406
|
-
|
|
50407
|
-
}
|
|
50530
|
+
}
|
|
50531
|
+
});
|
|
50532
|
+
return;
|
|
50533
|
+
}
|
|
50534
|
+
case "error": {
|
|
50535
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
50536
|
+
return;
|
|
50537
|
+
}
|
|
50538
|
+
default: {
|
|
50539
|
+
const _exhaustiveCheck = value;
|
|
50540
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
50408
50541
|
}
|
|
50409
50542
|
}
|
|
50410
|
-
}
|
|
50411
|
-
)
|
|
50543
|
+
}
|
|
50544
|
+
})
|
|
50545
|
+
);
|
|
50546
|
+
const [streamForFirstChunk, streamForConsumer] = transformedStream.tee();
|
|
50547
|
+
const firstChunkReader = streamForFirstChunk.getReader();
|
|
50548
|
+
try {
|
|
50549
|
+
yield firstChunkReader.read();
|
|
50550
|
+
let result = yield firstChunkReader.read();
|
|
50551
|
+
if (((_a4 = result.value) == null ? void 0 : _a4.type) === "raw") {
|
|
50552
|
+
result = yield firstChunkReader.read();
|
|
50553
|
+
}
|
|
50554
|
+
if (((_b = result.value) == null ? void 0 : _b.type) === "error") {
|
|
50555
|
+
const error = result.value.error;
|
|
50556
|
+
throw new import_provider35.APICallError({
|
|
50557
|
+
message: error.message,
|
|
50558
|
+
url,
|
|
50559
|
+
requestBodyValues: body,
|
|
50560
|
+
statusCode: error.type === "overloaded_error" ? 529 : 500,
|
|
50561
|
+
responseHeaders,
|
|
50562
|
+
responseBody: JSON.stringify(error),
|
|
50563
|
+
isRetryable: error.type === "overloaded_error"
|
|
50564
|
+
});
|
|
50565
|
+
}
|
|
50566
|
+
} finally {
|
|
50567
|
+
firstChunkReader.cancel().catch(() => {
|
|
50568
|
+
});
|
|
50569
|
+
firstChunkReader.releaseLock();
|
|
50570
|
+
}
|
|
50571
|
+
return {
|
|
50572
|
+
stream: streamForConsumer,
|
|
50412
50573
|
request: { body },
|
|
50413
50574
|
response: { headers: responseHeaders }
|
|
50414
50575
|
};
|
|
50415
50576
|
});
|
|
50416
50577
|
}
|
|
50417
50578
|
};
|
|
50418
|
-
function
|
|
50419
|
-
if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-
|
|
50420
|
-
return
|
|
50579
|
+
function getModelCapabilities(modelId) {
|
|
50580
|
+
if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
|
|
50581
|
+
return {
|
|
50582
|
+
maxOutputTokens: 64e3,
|
|
50583
|
+
supportsStructuredOutput: true,
|
|
50584
|
+
isKnownModel: true
|
|
50585
|
+
};
|
|
50586
|
+
} else if (modelId.includes("claude-opus-4-1")) {
|
|
50587
|
+
return {
|
|
50588
|
+
maxOutputTokens: 32e3,
|
|
50589
|
+
supportsStructuredOutput: true,
|
|
50590
|
+
isKnownModel: true
|
|
50591
|
+
};
|
|
50592
|
+
} else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
|
|
50593
|
+
return {
|
|
50594
|
+
maxOutputTokens: 64e3,
|
|
50595
|
+
supportsStructuredOutput: false,
|
|
50596
|
+
isKnownModel: true
|
|
50597
|
+
};
|
|
50421
50598
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
50422
|
-
return
|
|
50599
|
+
return {
|
|
50600
|
+
maxOutputTokens: 32e3,
|
|
50601
|
+
supportsStructuredOutput: false,
|
|
50602
|
+
isKnownModel: true
|
|
50603
|
+
};
|
|
50423
50604
|
} else if (modelId.includes("claude-3-5-haiku")) {
|
|
50424
|
-
return
|
|
50605
|
+
return {
|
|
50606
|
+
maxOutputTokens: 8192,
|
|
50607
|
+
supportsStructuredOutput: false,
|
|
50608
|
+
isKnownModel: true
|
|
50609
|
+
};
|
|
50610
|
+
} else if (modelId.includes("claude-3-haiku")) {
|
|
50611
|
+
return {
|
|
50612
|
+
maxOutputTokens: 4096,
|
|
50613
|
+
supportsStructuredOutput: false,
|
|
50614
|
+
isKnownModel: true
|
|
50615
|
+
};
|
|
50425
50616
|
} else {
|
|
50426
|
-
return
|
|
50617
|
+
return {
|
|
50618
|
+
maxOutputTokens: 4096,
|
|
50619
|
+
supportsStructuredOutput: false,
|
|
50620
|
+
isKnownModel: false
|
|
50621
|
+
};
|
|
50427
50622
|
}
|
|
50428
50623
|
}
|
|
50429
|
-
var bash_20241022InputSchema =
|
|
50430
|
-
() =>
|
|
50624
|
+
var bash_20241022InputSchema = lazySchema2(
|
|
50625
|
+
() => zodSchema2(
|
|
50431
50626
|
import_v441.z.object({
|
|
50432
50627
|
command: import_v441.z.string(),
|
|
50433
50628
|
restart: import_v441.z.boolean().optional()
|
|
50434
50629
|
})
|
|
50435
50630
|
)
|
|
50436
50631
|
);
|
|
50437
|
-
var bash_20241022 =
|
|
50632
|
+
var bash_20241022 = createProviderDefinedToolFactory2({
|
|
50438
50633
|
id: "anthropic.bash_20241022",
|
|
50439
50634
|
name: "bash",
|
|
50440
50635
|
inputSchema: bash_20241022InputSchema
|
|
50441
50636
|
});
|
|
50442
|
-
var bash_20250124InputSchema =
|
|
50443
|
-
() =>
|
|
50637
|
+
var bash_20250124InputSchema = lazySchema2(
|
|
50638
|
+
() => zodSchema2(
|
|
50444
50639
|
import_v442.z.object({
|
|
50445
50640
|
command: import_v442.z.string(),
|
|
50446
50641
|
restart: import_v442.z.boolean().optional()
|
|
50447
50642
|
})
|
|
50448
50643
|
)
|
|
50449
50644
|
);
|
|
50450
|
-
var bash_20250124 =
|
|
50645
|
+
var bash_20250124 = createProviderDefinedToolFactory2({
|
|
50451
50646
|
id: "anthropic.bash_20250124",
|
|
50452
50647
|
name: "bash",
|
|
50453
50648
|
inputSchema: bash_20250124InputSchema
|
|
50454
50649
|
});
|
|
50455
|
-
var computer_20241022InputSchema =
|
|
50456
|
-
() =>
|
|
50650
|
+
var computer_20241022InputSchema = lazySchema2(
|
|
50651
|
+
() => zodSchema2(
|
|
50457
50652
|
import_v443.z.object({
|
|
50458
50653
|
action: import_v443.z.enum([
|
|
50459
50654
|
"key",
|
|
@@ -50472,13 +50667,13 @@ var computer_20241022InputSchema = lazySchema(
|
|
|
50472
50667
|
})
|
|
50473
50668
|
)
|
|
50474
50669
|
);
|
|
50475
|
-
var computer_20241022 =
|
|
50670
|
+
var computer_20241022 = createProviderDefinedToolFactory2({
|
|
50476
50671
|
id: "anthropic.computer_20241022",
|
|
50477
50672
|
name: "computer",
|
|
50478
50673
|
inputSchema: computer_20241022InputSchema
|
|
50479
50674
|
});
|
|
50480
|
-
var computer_20250124InputSchema =
|
|
50481
|
-
() =>
|
|
50675
|
+
var computer_20250124InputSchema = lazySchema2(
|
|
50676
|
+
() => zodSchema2(
|
|
50482
50677
|
import_v444.z.object({
|
|
50483
50678
|
action: import_v444.z.enum([
|
|
50484
50679
|
"key",
|
|
@@ -50507,13 +50702,13 @@ var computer_20250124InputSchema = lazySchema(
|
|
|
50507
50702
|
})
|
|
50508
50703
|
)
|
|
50509
50704
|
);
|
|
50510
|
-
var computer_20250124 =
|
|
50705
|
+
var computer_20250124 = createProviderDefinedToolFactory2({
|
|
50511
50706
|
id: "anthropic.computer_20250124",
|
|
50512
50707
|
name: "computer",
|
|
50513
50708
|
inputSchema: computer_20250124InputSchema
|
|
50514
50709
|
});
|
|
50515
|
-
var memory_20250818InputSchema =
|
|
50516
|
-
() =>
|
|
50710
|
+
var memory_20250818InputSchema = lazySchema2(
|
|
50711
|
+
() => zodSchema2(
|
|
50517
50712
|
import_v445.z.discriminatedUnion("command", [
|
|
50518
50713
|
import_v445.z.object({
|
|
50519
50714
|
command: import_v445.z.literal("view"),
|
|
@@ -50549,13 +50744,13 @@ var memory_20250818InputSchema = lazySchema(
|
|
|
50549
50744
|
])
|
|
50550
50745
|
)
|
|
50551
50746
|
);
|
|
50552
|
-
var memory_20250818 =
|
|
50747
|
+
var memory_20250818 = createProviderDefinedToolFactory2({
|
|
50553
50748
|
id: "anthropic.memory_20250818",
|
|
50554
50749
|
name: "memory",
|
|
50555
50750
|
inputSchema: memory_20250818InputSchema
|
|
50556
50751
|
});
|
|
50557
|
-
var textEditor_20241022InputSchema =
|
|
50558
|
-
() =>
|
|
50752
|
+
var textEditor_20241022InputSchema = lazySchema2(
|
|
50753
|
+
() => zodSchema2(
|
|
50559
50754
|
import_v446.z.object({
|
|
50560
50755
|
command: import_v446.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
50561
50756
|
path: import_v446.z.string(),
|
|
@@ -50567,13 +50762,13 @@ var textEditor_20241022InputSchema = lazySchema(
|
|
|
50567
50762
|
})
|
|
50568
50763
|
)
|
|
50569
50764
|
);
|
|
50570
|
-
var textEditor_20241022 =
|
|
50765
|
+
var textEditor_20241022 = createProviderDefinedToolFactory2({
|
|
50571
50766
|
id: "anthropic.text_editor_20241022",
|
|
50572
50767
|
name: "str_replace_editor",
|
|
50573
50768
|
inputSchema: textEditor_20241022InputSchema
|
|
50574
50769
|
});
|
|
50575
|
-
var textEditor_20250124InputSchema =
|
|
50576
|
-
() =>
|
|
50770
|
+
var textEditor_20250124InputSchema = lazySchema2(
|
|
50771
|
+
() => zodSchema2(
|
|
50577
50772
|
import_v447.z.object({
|
|
50578
50773
|
command: import_v447.z.enum(["view", "create", "str_replace", "insert", "undo_edit"]),
|
|
50579
50774
|
path: import_v447.z.string(),
|
|
@@ -50585,13 +50780,13 @@ var textEditor_20250124InputSchema = lazySchema(
|
|
|
50585
50780
|
})
|
|
50586
50781
|
)
|
|
50587
50782
|
);
|
|
50588
|
-
var textEditor_20250124 =
|
|
50783
|
+
var textEditor_20250124 = createProviderDefinedToolFactory2({
|
|
50589
50784
|
id: "anthropic.text_editor_20250124",
|
|
50590
50785
|
name: "str_replace_editor",
|
|
50591
50786
|
inputSchema: textEditor_20250124InputSchema
|
|
50592
50787
|
});
|
|
50593
|
-
var textEditor_20250429InputSchema =
|
|
50594
|
-
() =>
|
|
50788
|
+
var textEditor_20250429InputSchema = lazySchema2(
|
|
50789
|
+
() => zodSchema2(
|
|
50595
50790
|
import_v448.z.object({
|
|
50596
50791
|
command: import_v448.z.enum(["view", "create", "str_replace", "insert"]),
|
|
50597
50792
|
path: import_v448.z.string(),
|
|
@@ -50603,7 +50798,7 @@ var textEditor_20250429InputSchema = lazySchema(
|
|
|
50603
50798
|
})
|
|
50604
50799
|
)
|
|
50605
50800
|
);
|
|
50606
|
-
var textEditor_20250429 =
|
|
50801
|
+
var textEditor_20250429 = createProviderDefinedToolFactory2({
|
|
50607
50802
|
id: "anthropic.text_editor_20250429",
|
|
50608
50803
|
name: "str_replace_based_edit_tool",
|
|
50609
50804
|
inputSchema: textEditor_20250429InputSchema
|
|
@@ -50759,12 +50954,18 @@ var anthropicTools = {
|
|
|
50759
50954
|
webSearch_20250305
|
|
50760
50955
|
};
|
|
50761
50956
|
function createAnthropic(options = {}) {
|
|
50762
|
-
var _a4;
|
|
50763
|
-
const baseURL = (_a4 =
|
|
50764
|
-
|
|
50957
|
+
var _a4, _b;
|
|
50958
|
+
const baseURL = (_a4 = withoutTrailingSlash2(
|
|
50959
|
+
loadOptionalSetting2({
|
|
50960
|
+
settingValue: options.baseURL,
|
|
50961
|
+
environmentVariableName: "ANTHROPIC_BASE_URL"
|
|
50962
|
+
})
|
|
50963
|
+
)) != null ? _a4 : "https://api.anthropic.com/v1";
|
|
50964
|
+
const providerName = (_b = options.name) != null ? _b : "anthropic.messages";
|
|
50965
|
+
const getHeaders = () => withUserAgentSuffix2(
|
|
50765
50966
|
__spreadValues({
|
|
50766
50967
|
"anthropic-version": "2023-06-01",
|
|
50767
|
-
"x-api-key":
|
|
50968
|
+
"x-api-key": loadApiKey2({
|
|
50768
50969
|
apiKey: options.apiKey,
|
|
50769
50970
|
environmentVariableName: "ANTHROPIC_API_KEY",
|
|
50770
50971
|
description: "Anthropic"
|
|
@@ -50775,11 +50976,11 @@ function createAnthropic(options = {}) {
|
|
|
50775
50976
|
const createChatModel = (modelId) => {
|
|
50776
50977
|
var _a22;
|
|
50777
50978
|
return new AnthropicMessagesLanguageModel(modelId, {
|
|
50778
|
-
provider:
|
|
50979
|
+
provider: providerName,
|
|
50779
50980
|
baseURL,
|
|
50780
50981
|
headers: getHeaders,
|
|
50781
50982
|
fetch: options.fetch,
|
|
50782
|
-
generateId: (_a22 = options.generateId) != null ? _a22 :
|
|
50983
|
+
generateId: (_a22 = options.generateId) != null ? _a22 : generateId2,
|
|
50783
50984
|
supportedUrls: () => ({
|
|
50784
50985
|
"image/*": [/^https?:\/\/.*$/]
|
|
50785
50986
|
})
|
|
@@ -64190,6 +64391,11 @@ var _V3 = class _V3 {
|
|
|
64190
64391
|
this.observeHandler = null;
|
|
64191
64392
|
this.ctx = null;
|
|
64192
64393
|
this.llmClient = void 0;
|
|
64394
|
+
/**
|
|
64395
|
+
* Event bus for internal communication.
|
|
64396
|
+
* Emits events like 'screenshot' when screenshots are captured during agent execution.
|
|
64397
|
+
*/
|
|
64398
|
+
this.bus = new import_events2.EventEmitter();
|
|
64193
64399
|
this.modelName = void 0;
|
|
64194
64400
|
this.modelClientOptions = void 0;
|
|
64195
64401
|
this.llmProvider = void 0;
|