@browserbasehq/stagehand 3.0.8-alpha-0149ad50074dd78904613508baf67cbbe19d66e5 → 3.0.8-alpha-72ac775a831d6f0f376ceda4426525f93cc21452
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 +1 -1
- package/dist/index.js +243 -209
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { ClientOptions as ClientOptions$1 } from 'openai';
|
|
|
8
8
|
import { Client, ClientOptions as ClientOptions$3 } from '@modelcontextprotocol/sdk/client/index.js';
|
|
9
9
|
import * as ai from 'ai';
|
|
10
10
|
import { ToolSet, ModelMessage, PrepareStepFunction, GenerateTextOnStepFinishCallback, StreamTextOnStepFinishCallback, StreamTextOnErrorCallback, StreamTextOnChunkCallback, StreamTextOnFinishCallback, StepResult, StreamTextResult, wrapLanguageModel, generateObject, generateText, streamText, streamObject, experimental_generateImage, embed, embedMany, experimental_transcribe, experimental_generateSpeech, InferUITools } from 'ai';
|
|
11
|
-
export { ModelMessage } from 'ai';
|
|
11
|
+
export { ModelMessage, Tool, tool } from 'ai';
|
|
12
12
|
import { Page as Page$1 } from 'playwright-core';
|
|
13
13
|
export { Page as PlaywrightPage } from 'playwright-core';
|
|
14
14
|
import { Page as Page$2 } from 'puppeteer-core';
|
package/dist/index.js
CHANGED
|
@@ -27155,6 +27155,7 @@ __export(v3_exports, {
|
|
|
27155
27155
|
providerEnvVarMap: () => providerEnvVarMap,
|
|
27156
27156
|
toGeminiSchema: () => toGeminiSchema,
|
|
27157
27157
|
toJsonSchema: () => toJsonSchema,
|
|
27158
|
+
tool: () => import_ai23.tool,
|
|
27158
27159
|
transformSchema: () => transformSchema,
|
|
27159
27160
|
trimTrailingTextNode: () => trimTrailingTextNode,
|
|
27160
27161
|
validateZodSchema: () => validateZodSchema
|
|
@@ -28127,7 +28128,7 @@ var ActCache = class {
|
|
|
28127
28128
|
};
|
|
28128
28129
|
});
|
|
28129
28130
|
}
|
|
28130
|
-
tryReplay(context, page, timeout) {
|
|
28131
|
+
tryReplay(context, page, timeout, llmClientOverride) {
|
|
28131
28132
|
return __async(this, null, function* () {
|
|
28132
28133
|
var _a4;
|
|
28133
28134
|
if (!this.enabled) return null;
|
|
@@ -28180,7 +28181,13 @@ var ActCache = class {
|
|
|
28180
28181
|
}
|
|
28181
28182
|
}
|
|
28182
28183
|
});
|
|
28183
|
-
return yield this.replayCachedActions(
|
|
28184
|
+
return yield this.replayCachedActions(
|
|
28185
|
+
context,
|
|
28186
|
+
entry,
|
|
28187
|
+
page,
|
|
28188
|
+
timeout,
|
|
28189
|
+
llmClientOverride
|
|
28190
|
+
);
|
|
28184
28191
|
});
|
|
28185
28192
|
}
|
|
28186
28193
|
store(context, result) {
|
|
@@ -28230,12 +28237,13 @@ var ActCache = class {
|
|
|
28230
28237
|
});
|
|
28231
28238
|
return (0, import_crypto.createHash)("sha256").update(payload).digest("hex");
|
|
28232
28239
|
}
|
|
28233
|
-
replayCachedActions(context, entry, page, timeout) {
|
|
28240
|
+
replayCachedActions(context, entry, page, timeout, llmClientOverride) {
|
|
28234
28241
|
return __async(this, null, function* () {
|
|
28235
28242
|
const handler = this.getActHandler();
|
|
28236
28243
|
if (!handler) {
|
|
28237
28244
|
throw new StagehandNotInitializedError("act()");
|
|
28238
28245
|
}
|
|
28246
|
+
const effectiveClient = llmClientOverride != null ? llmClientOverride : this.getDefaultLlmClient();
|
|
28239
28247
|
const execute = () => __async(this, null, function* () {
|
|
28240
28248
|
var _a4, _b, _c;
|
|
28241
28249
|
const actionResults = [];
|
|
@@ -28244,7 +28252,7 @@ var ActCache = class {
|
|
|
28244
28252
|
action,
|
|
28245
28253
|
page,
|
|
28246
28254
|
this.domSettleTimeoutMs,
|
|
28247
|
-
|
|
28255
|
+
effectiveClient,
|
|
28248
28256
|
void 0,
|
|
28249
28257
|
context.variables
|
|
28250
28258
|
);
|
|
@@ -28482,7 +28490,7 @@ var AgentCache = class {
|
|
|
28482
28490
|
};
|
|
28483
28491
|
});
|
|
28484
28492
|
}
|
|
28485
|
-
tryReplay(context) {
|
|
28493
|
+
tryReplay(context, llmClientOverride) {
|
|
28486
28494
|
return __async(this, null, function* () {
|
|
28487
28495
|
if (!this.enabled) return null;
|
|
28488
28496
|
const {
|
|
@@ -28515,7 +28523,7 @@ var AgentCache = class {
|
|
|
28515
28523
|
url: { value: context.startUrl, type: "string" }
|
|
28516
28524
|
}
|
|
28517
28525
|
});
|
|
28518
|
-
return yield this.replayAgentCacheEntry(context, entry);
|
|
28526
|
+
return yield this.replayAgentCacheEntry(context, entry, llmClientOverride);
|
|
28519
28527
|
});
|
|
28520
28528
|
}
|
|
28521
28529
|
/**
|
|
@@ -28534,9 +28542,9 @@ var AgentCache = class {
|
|
|
28534
28542
|
* and await `result` even when the response comes from cache, maintaining
|
|
28535
28543
|
* API consistency regardless of whether the result was cached or live.
|
|
28536
28544
|
*/
|
|
28537
|
-
tryReplayAsStream(context) {
|
|
28545
|
+
tryReplayAsStream(context, llmClientOverride) {
|
|
28538
28546
|
return __async(this, null, function* () {
|
|
28539
|
-
const result = yield this.tryReplay(context);
|
|
28547
|
+
const result = yield this.tryReplay(context, llmClientOverride);
|
|
28540
28548
|
if (!result) return null;
|
|
28541
28549
|
return this.createCachedStreamResult(result);
|
|
28542
28550
|
});
|
|
@@ -28762,17 +28770,23 @@ var AgentCache = class {
|
|
|
28762
28770
|
}
|
|
28763
28771
|
return value;
|
|
28764
28772
|
}
|
|
28765
|
-
replayAgentCacheEntry(context, entry) {
|
|
28773
|
+
replayAgentCacheEntry(context, entry, llmClientOverride) {
|
|
28766
28774
|
return __async(this, null, function* () {
|
|
28767
28775
|
var _a4, _b, _c;
|
|
28768
28776
|
const ctx = this.getContext();
|
|
28769
28777
|
const handler = this.getActHandler();
|
|
28770
28778
|
if (!ctx || !handler) return null;
|
|
28779
|
+
const effectiveClient = llmClientOverride != null ? llmClientOverride : this.getDefaultLlmClient();
|
|
28771
28780
|
try {
|
|
28772
28781
|
const updatedSteps = [];
|
|
28773
28782
|
let stepsChanged = false;
|
|
28774
28783
|
for (const step of (_a4 = entry.steps) != null ? _a4 : []) {
|
|
28775
|
-
const replayedStep = (_b = yield this.executeAgentReplayStep(
|
|
28784
|
+
const replayedStep = (_b = yield this.executeAgentReplayStep(
|
|
28785
|
+
step,
|
|
28786
|
+
ctx,
|
|
28787
|
+
handler,
|
|
28788
|
+
effectiveClient
|
|
28789
|
+
)) != null ? _b : step;
|
|
28776
28790
|
stepsChanged || (stepsChanged = replayedStep !== step);
|
|
28777
28791
|
updatedSteps.push(replayedStep);
|
|
28778
28792
|
}
|
|
@@ -28805,20 +28819,22 @@ var AgentCache = class {
|
|
|
28805
28819
|
}
|
|
28806
28820
|
});
|
|
28807
28821
|
}
|
|
28808
|
-
executeAgentReplayStep(step, ctx, handler) {
|
|
28822
|
+
executeAgentReplayStep(step, ctx, handler, llmClient) {
|
|
28809
28823
|
return __async(this, null, function* () {
|
|
28810
28824
|
switch (step.type) {
|
|
28811
28825
|
case "act":
|
|
28812
28826
|
return yield this.replayAgentActStep(
|
|
28813
28827
|
step,
|
|
28814
28828
|
ctx,
|
|
28815
|
-
handler
|
|
28829
|
+
handler,
|
|
28830
|
+
llmClient
|
|
28816
28831
|
);
|
|
28817
28832
|
case "fillForm":
|
|
28818
28833
|
return yield this.replayAgentFillFormStep(
|
|
28819
28834
|
step,
|
|
28820
28835
|
ctx,
|
|
28821
|
-
handler
|
|
28836
|
+
handler,
|
|
28837
|
+
llmClient
|
|
28822
28838
|
);
|
|
28823
28839
|
case "goto":
|
|
28824
28840
|
yield this.replayAgentGotoStep(step, ctx);
|
|
@@ -28850,7 +28866,7 @@ var AgentCache = class {
|
|
|
28850
28866
|
}
|
|
28851
28867
|
});
|
|
28852
28868
|
}
|
|
28853
|
-
replayAgentActStep(step, ctx, handler) {
|
|
28869
|
+
replayAgentActStep(step, ctx, handler, llmClient) {
|
|
28854
28870
|
return __async(this, null, function* () {
|
|
28855
28871
|
const actions = Array.isArray(step.actions) ? step.actions : [];
|
|
28856
28872
|
if (actions.length > 0) {
|
|
@@ -28861,7 +28877,7 @@ var AgentCache = class {
|
|
|
28861
28877
|
action,
|
|
28862
28878
|
page,
|
|
28863
28879
|
this.domSettleTimeoutMs,
|
|
28864
|
-
|
|
28880
|
+
llmClient
|
|
28865
28881
|
);
|
|
28866
28882
|
if (result.success && Array.isArray(result.actions)) {
|
|
28867
28883
|
updatedActions.push(...cloneForCache(result.actions));
|
|
@@ -28878,7 +28894,7 @@ var AgentCache = class {
|
|
|
28878
28894
|
return step;
|
|
28879
28895
|
});
|
|
28880
28896
|
}
|
|
28881
|
-
replayAgentFillFormStep(step, ctx, handler) {
|
|
28897
|
+
replayAgentFillFormStep(step, ctx, handler, llmClient) {
|
|
28882
28898
|
return __async(this, null, function* () {
|
|
28883
28899
|
var _a4;
|
|
28884
28900
|
const actions = Array.isArray(step.actions) && step.actions.length > 0 ? step.actions : (_a4 = step.observeResults) != null ? _a4 : [];
|
|
@@ -28892,7 +28908,7 @@ var AgentCache = class {
|
|
|
28892
28908
|
action,
|
|
28893
28909
|
page,
|
|
28894
28910
|
this.domSettleTimeoutMs,
|
|
28895
|
-
|
|
28911
|
+
llmClient
|
|
28896
28912
|
);
|
|
28897
28913
|
if (result.success && Array.isArray(result.actions)) {
|
|
28898
28914
|
updatedActions.push(...cloneForCache(result.actions));
|
|
@@ -32340,8 +32356,8 @@ function buildToolsSection(isHybridMode, hasSearch, excludeTools) {
|
|
|
32340
32356
|
description: "Perform a web search and return results. Prefer this over navigating to Google and searching within the page for reliability and efficiency."
|
|
32341
32357
|
});
|
|
32342
32358
|
}
|
|
32343
|
-
const filteredTools = baseTools.filter((
|
|
32344
|
-
const toolLines = filteredTools.map((
|
|
32359
|
+
const filteredTools = baseTools.filter((tool22) => !excludeSet.has(tool22.name));
|
|
32360
|
+
const toolLines = filteredTools.map((tool22) => ` <tool name="${tool22.name}">${tool22.description}</tool>`).join("\n");
|
|
32345
32361
|
return `<tools>
|
|
32346
32362
|
${toolLines}
|
|
32347
32363
|
</tools>`;
|
|
@@ -33534,8 +33550,8 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
33534
33550
|
betas: ["computer-use-2025-01-24"]
|
|
33535
33551
|
};
|
|
33536
33552
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
33537
|
-
const customTools = Object.entries(this.tools).map(([name,
|
|
33538
|
-
const schema =
|
|
33553
|
+
const customTools = Object.entries(this.tools).map(([name, tool22]) => {
|
|
33554
|
+
const schema = tool22.inputSchema;
|
|
33539
33555
|
const jsonSchema3 = toJsonSchema(schema);
|
|
33540
33556
|
const inputSchema = {
|
|
33541
33557
|
type: "object",
|
|
@@ -33544,7 +33560,7 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
33544
33560
|
};
|
|
33545
33561
|
return {
|
|
33546
33562
|
name,
|
|
33547
|
-
description:
|
|
33563
|
+
description: tool22.description,
|
|
33548
33564
|
input_schema: inputSchema
|
|
33549
33565
|
};
|
|
33550
33566
|
});
|
|
@@ -33662,13 +33678,13 @@ var AnthropicCUAClient = class extends AgentClient {
|
|
|
33662
33678
|
let toolResult = "Tool executed successfully";
|
|
33663
33679
|
if (this.tools && item.name in this.tools) {
|
|
33664
33680
|
try {
|
|
33665
|
-
const
|
|
33681
|
+
const tool22 = this.tools[item.name];
|
|
33666
33682
|
logger({
|
|
33667
33683
|
category: "agent",
|
|
33668
33684
|
message: `Executing tool call: ${item.name} with args: ${JSON.stringify(item.input)}`,
|
|
33669
33685
|
level: 1
|
|
33670
33686
|
});
|
|
33671
|
-
const result = yield
|
|
33687
|
+
const result = yield tool22.execute(item.input, {
|
|
33672
33688
|
toolCallId: item.id,
|
|
33673
33689
|
messages: []
|
|
33674
33690
|
});
|
|
@@ -34230,13 +34246,13 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
34230
34246
|
truncation: "auto"
|
|
34231
34247
|
};
|
|
34232
34248
|
if (this.tools && Object.keys(this.tools).length > 0) {
|
|
34233
|
-
const customTools = Object.entries(this.tools).map(([name,
|
|
34249
|
+
const customTools = Object.entries(this.tools).map(([name, tool22]) => ({
|
|
34234
34250
|
type: "function",
|
|
34235
34251
|
name,
|
|
34236
34252
|
function: {
|
|
34237
34253
|
name,
|
|
34238
|
-
description:
|
|
34239
|
-
parameters:
|
|
34254
|
+
description: tool22.description,
|
|
34255
|
+
parameters: tool22.inputSchema
|
|
34240
34256
|
}
|
|
34241
34257
|
}));
|
|
34242
34258
|
requestParams.tools = [
|
|
@@ -34388,14 +34404,14 @@ var OpenAICUAClient = class extends AgentClient {
|
|
|
34388
34404
|
let toolResult = "Tool executed successfully";
|
|
34389
34405
|
if (this.tools && item.name in this.tools) {
|
|
34390
34406
|
try {
|
|
34391
|
-
const
|
|
34407
|
+
const tool22 = this.tools[item.name];
|
|
34392
34408
|
const args = JSON.parse(item.arguments);
|
|
34393
34409
|
logger({
|
|
34394
34410
|
category: "agent",
|
|
34395
34411
|
message: `Executing tool call: ${item.name} with args: ${item.arguments}`,
|
|
34396
34412
|
level: 1
|
|
34397
34413
|
});
|
|
34398
|
-
const result = yield
|
|
34414
|
+
const result = yield tool22.execute(args, {
|
|
34399
34415
|
toolCallId: item.call_id,
|
|
34400
34416
|
messages: []
|
|
34401
34417
|
});
|
|
@@ -34558,8 +34574,8 @@ function executeGoogleCustomTool(toolName, toolArgs, tools, functionCall, logger
|
|
|
34558
34574
|
message: `Executing custom tool: ${toolName} with args: ${JSON.stringify(toolArgs)}`,
|
|
34559
34575
|
level: 1
|
|
34560
34576
|
});
|
|
34561
|
-
const
|
|
34562
|
-
const toolResult = yield
|
|
34577
|
+
const tool22 = tools[toolName];
|
|
34578
|
+
const toolResult = yield tool22.execute(toolArgs, {
|
|
34563
34579
|
toolCallId: `tool_${Date.now()}`,
|
|
34564
34580
|
messages: []
|
|
34565
34581
|
});
|
|
@@ -34607,22 +34623,22 @@ function isCustomTool(functionCall, tools) {
|
|
|
34607
34623
|
}
|
|
34608
34624
|
function convertToolSetToFunctionDeclarations(tools) {
|
|
34609
34625
|
const functionDeclarations = [];
|
|
34610
|
-
for (const [name,
|
|
34611
|
-
const functionDeclaration = convertToolToFunctionDeclaration(name,
|
|
34626
|
+
for (const [name, tool22] of Object.entries(tools)) {
|
|
34627
|
+
const functionDeclaration = convertToolToFunctionDeclaration(name, tool22);
|
|
34612
34628
|
if (functionDeclaration) {
|
|
34613
34629
|
functionDeclarations.push(functionDeclaration);
|
|
34614
34630
|
}
|
|
34615
34631
|
}
|
|
34616
34632
|
return functionDeclarations;
|
|
34617
34633
|
}
|
|
34618
|
-
function convertToolToFunctionDeclaration(name,
|
|
34634
|
+
function convertToolToFunctionDeclaration(name, tool22) {
|
|
34619
34635
|
try {
|
|
34620
|
-
const schema =
|
|
34636
|
+
const schema = tool22.inputSchema;
|
|
34621
34637
|
const jsonSchema3 = toJsonSchema(schema);
|
|
34622
34638
|
const parameters = convertJsonSchemaToGoogleParameters(jsonSchema3);
|
|
34623
34639
|
return {
|
|
34624
34640
|
name,
|
|
34625
|
-
description:
|
|
34641
|
+
description: tool22.description || `Execute ${name}`,
|
|
34626
34642
|
parameters
|
|
34627
34643
|
};
|
|
34628
34644
|
} catch (error) {
|
|
@@ -38113,10 +38129,10 @@ You must respond in JSON format. respond WITH JSON. Do not include any other tex
|
|
|
38113
38129
|
}
|
|
38114
38130
|
const tools = {};
|
|
38115
38131
|
if (options.tools && options.tools.length > 0) {
|
|
38116
|
-
for (const
|
|
38117
|
-
tools[
|
|
38118
|
-
description:
|
|
38119
|
-
inputSchema:
|
|
38132
|
+
for (const tool22 of options.tools) {
|
|
38133
|
+
tools[tool22.name] = {
|
|
38134
|
+
description: tool22.description,
|
|
38135
|
+
inputSchema: tool22.parameters
|
|
38120
38136
|
};
|
|
38121
38137
|
}
|
|
38122
38138
|
}
|
|
@@ -38315,14 +38331,14 @@ var AnthropicClient = class extends LLMClient {
|
|
|
38315
38331
|
}
|
|
38316
38332
|
formattedMessages.push(screenshotMessage);
|
|
38317
38333
|
}
|
|
38318
|
-
let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
38334
|
+
let anthropicTools2 = (_a4 = options.tools) == null ? void 0 : _a4.map((tool22) => {
|
|
38319
38335
|
return {
|
|
38320
|
-
name:
|
|
38321
|
-
description:
|
|
38336
|
+
name: tool22.name,
|
|
38337
|
+
description: tool22.description,
|
|
38322
38338
|
input_schema: {
|
|
38323
38339
|
type: "object",
|
|
38324
|
-
properties:
|
|
38325
|
-
required:
|
|
38340
|
+
properties: tool22.parameters.properties,
|
|
38341
|
+
required: tool22.parameters.required
|
|
38326
38342
|
}
|
|
38327
38343
|
};
|
|
38328
38344
|
});
|
|
@@ -38509,15 +38525,15 @@ var CerebrasClient = class extends LLMClient {
|
|
|
38509
38525
|
return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
|
|
38510
38526
|
}
|
|
38511
38527
|
});
|
|
38512
|
-
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
38528
|
+
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool22) => ({
|
|
38513
38529
|
type: "function",
|
|
38514
38530
|
function: {
|
|
38515
|
-
name:
|
|
38516
|
-
description:
|
|
38531
|
+
name: tool22.name,
|
|
38532
|
+
description: tool22.description,
|
|
38517
38533
|
parameters: {
|
|
38518
38534
|
type: "object",
|
|
38519
|
-
properties:
|
|
38520
|
-
required:
|
|
38535
|
+
properties: tool22.parameters.properties,
|
|
38536
|
+
required: tool22.parameters.required
|
|
38521
38537
|
}
|
|
38522
38538
|
}
|
|
38523
38539
|
}));
|
|
@@ -38810,18 +38826,18 @@ ${firstPartText.text}`;
|
|
|
38810
38826
|
}
|
|
38811
38827
|
return [
|
|
38812
38828
|
{
|
|
38813
|
-
functionDeclarations: tools.map((
|
|
38829
|
+
functionDeclarations: tools.map((tool22) => {
|
|
38814
38830
|
let parameters = void 0;
|
|
38815
|
-
if (
|
|
38831
|
+
if (tool22.parameters) {
|
|
38816
38832
|
parameters = {
|
|
38817
38833
|
type: import_genai4.Type.OBJECT,
|
|
38818
|
-
properties:
|
|
38819
|
-
required:
|
|
38834
|
+
properties: tool22.parameters.properties,
|
|
38835
|
+
required: tool22.parameters.required
|
|
38820
38836
|
};
|
|
38821
38837
|
}
|
|
38822
38838
|
return {
|
|
38823
|
-
name:
|
|
38824
|
-
description:
|
|
38839
|
+
name: tool22.name,
|
|
38840
|
+
description: tool22.description,
|
|
38825
38841
|
parameters
|
|
38826
38842
|
};
|
|
38827
38843
|
})
|
|
@@ -39097,15 +39113,15 @@ var GroqClient = class extends LLMClient {
|
|
|
39097
39113
|
return __spreadProps(__spreadValues({}, baseMessage), { role: "user" });
|
|
39098
39114
|
}
|
|
39099
39115
|
});
|
|
39100
|
-
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((
|
|
39116
|
+
let tools = (_a4 = options.tools) == null ? void 0 : _a4.map((tool22) => ({
|
|
39101
39117
|
type: "function",
|
|
39102
39118
|
function: {
|
|
39103
|
-
name:
|
|
39104
|
-
description:
|
|
39119
|
+
name: tool22.name,
|
|
39120
|
+
description: tool22.description,
|
|
39105
39121
|
parameters: {
|
|
39106
39122
|
type: "object",
|
|
39107
|
-
properties:
|
|
39108
|
-
required:
|
|
39123
|
+
properties: tool22.parameters.properties,
|
|
39124
|
+
required: tool22.parameters.required
|
|
39109
39125
|
}
|
|
39110
39126
|
}
|
|
39111
39127
|
}));
|
|
@@ -39482,11 +39498,11 @@ ${parsedSchema}
|
|
|
39482
39498
|
messages: formattedMessages,
|
|
39483
39499
|
response_format: responseFormat,
|
|
39484
39500
|
stream: false,
|
|
39485
|
-
tools: (_e = options.tools) == null ? void 0 : _e.map((
|
|
39501
|
+
tools: (_e = options.tools) == null ? void 0 : _e.map((tool22) => ({
|
|
39486
39502
|
function: {
|
|
39487
|
-
name:
|
|
39488
|
-
description:
|
|
39489
|
-
parameters:
|
|
39503
|
+
name: tool22.name,
|
|
39504
|
+
description: tool22.description,
|
|
39505
|
+
parameters: tool22.parameters
|
|
39490
39506
|
},
|
|
39491
39507
|
type: "function"
|
|
39492
39508
|
}))
|
|
@@ -42152,21 +42168,21 @@ function prepareChatTools({
|
|
|
42152
42168
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
42153
42169
|
}
|
|
42154
42170
|
const openaiTools2 = [];
|
|
42155
|
-
for (const
|
|
42156
|
-
switch (
|
|
42171
|
+
for (const tool22 of tools) {
|
|
42172
|
+
switch (tool22.type) {
|
|
42157
42173
|
case "function":
|
|
42158
42174
|
openaiTools2.push({
|
|
42159
42175
|
type: "function",
|
|
42160
42176
|
function: {
|
|
42161
|
-
name:
|
|
42162
|
-
description:
|
|
42163
|
-
parameters:
|
|
42177
|
+
name: tool22.name,
|
|
42178
|
+
description: tool22.description,
|
|
42179
|
+
parameters: tool22.inputSchema,
|
|
42164
42180
|
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
42165
42181
|
}
|
|
42166
42182
|
});
|
|
42167
42183
|
break;
|
|
42168
42184
|
default:
|
|
42169
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
42185
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
42170
42186
|
break;
|
|
42171
42187
|
}
|
|
42172
42188
|
}
|
|
@@ -44482,22 +44498,22 @@ function prepareResponsesTools(_0) {
|
|
|
44482
44498
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
44483
44499
|
}
|
|
44484
44500
|
const openaiTools2 = [];
|
|
44485
|
-
for (const
|
|
44486
|
-
switch (
|
|
44501
|
+
for (const tool22 of tools) {
|
|
44502
|
+
switch (tool22.type) {
|
|
44487
44503
|
case "function":
|
|
44488
44504
|
openaiTools2.push({
|
|
44489
44505
|
type: "function",
|
|
44490
|
-
name:
|
|
44491
|
-
description:
|
|
44492
|
-
parameters:
|
|
44506
|
+
name: tool22.name,
|
|
44507
|
+
description: tool22.description,
|
|
44508
|
+
parameters: tool22.inputSchema,
|
|
44493
44509
|
strict: strictJsonSchema
|
|
44494
44510
|
});
|
|
44495
44511
|
break;
|
|
44496
44512
|
case "provider-defined": {
|
|
44497
|
-
switch (
|
|
44513
|
+
switch (tool22.id) {
|
|
44498
44514
|
case "openai.file_search": {
|
|
44499
44515
|
const args = yield validateTypes({
|
|
44500
|
-
value:
|
|
44516
|
+
value: tool22.args,
|
|
44501
44517
|
schema: fileSearchArgsSchema
|
|
44502
44518
|
});
|
|
44503
44519
|
openaiTools2.push({
|
|
@@ -44520,7 +44536,7 @@ function prepareResponsesTools(_0) {
|
|
|
44520
44536
|
}
|
|
44521
44537
|
case "openai.web_search_preview": {
|
|
44522
44538
|
const args = yield validateTypes({
|
|
44523
|
-
value:
|
|
44539
|
+
value: tool22.args,
|
|
44524
44540
|
schema: webSearchPreviewArgsSchema
|
|
44525
44541
|
});
|
|
44526
44542
|
openaiTools2.push({
|
|
@@ -44532,7 +44548,7 @@ function prepareResponsesTools(_0) {
|
|
|
44532
44548
|
}
|
|
44533
44549
|
case "openai.web_search": {
|
|
44534
44550
|
const args = yield validateTypes({
|
|
44535
|
-
value:
|
|
44551
|
+
value: tool22.args,
|
|
44536
44552
|
schema: webSearchArgsSchema
|
|
44537
44553
|
});
|
|
44538
44554
|
openaiTools2.push({
|
|
@@ -44545,7 +44561,7 @@ function prepareResponsesTools(_0) {
|
|
|
44545
44561
|
}
|
|
44546
44562
|
case "openai.code_interpreter": {
|
|
44547
44563
|
const args = yield validateTypes({
|
|
44548
|
-
value:
|
|
44564
|
+
value: tool22.args,
|
|
44549
44565
|
schema: codeInterpreterArgsSchema
|
|
44550
44566
|
});
|
|
44551
44567
|
openaiTools2.push({
|
|
@@ -44556,7 +44572,7 @@ function prepareResponsesTools(_0) {
|
|
|
44556
44572
|
}
|
|
44557
44573
|
case "openai.image_generation": {
|
|
44558
44574
|
const args = yield validateTypes({
|
|
44559
|
-
value:
|
|
44575
|
+
value: tool22.args,
|
|
44560
44576
|
schema: imageGenerationArgsSchema
|
|
44561
44577
|
});
|
|
44562
44578
|
openaiTools2.push({
|
|
@@ -44580,7 +44596,7 @@ function prepareResponsesTools(_0) {
|
|
|
44580
44596
|
break;
|
|
44581
44597
|
}
|
|
44582
44598
|
default:
|
|
44583
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
44599
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
44584
44600
|
break;
|
|
44585
44601
|
}
|
|
44586
44602
|
}
|
|
@@ -44685,7 +44701,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
44685
44701
|
}
|
|
44686
44702
|
function hasOpenAITool(id) {
|
|
44687
44703
|
return (tools == null ? void 0 : tools.find(
|
|
44688
|
-
(
|
|
44704
|
+
(tool22) => tool22.type === "provider-defined" && tool22.id === id
|
|
44689
44705
|
)) != null;
|
|
44690
44706
|
}
|
|
44691
44707
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX : void 0;
|
|
@@ -44693,7 +44709,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
44693
44709
|
addInclude("message.output_text.logprobs");
|
|
44694
44710
|
}
|
|
44695
44711
|
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
44696
|
-
(
|
|
44712
|
+
(tool22) => tool22.type === "provider-defined" && (tool22.id === "openai.web_search" || tool22.id === "openai.web_search_preview")
|
|
44697
44713
|
)) == null ? void 0 : _c.name;
|
|
44698
44714
|
if (webSearchToolName) {
|
|
44699
44715
|
addInclude("web_search_call.action.sources");
|
|
@@ -48287,25 +48303,25 @@ function prepareTools({
|
|
|
48287
48303
|
if (tools == null) {
|
|
48288
48304
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
48289
48305
|
}
|
|
48290
|
-
const hasFunctionTools = tools.some((
|
|
48306
|
+
const hasFunctionTools = tools.some((tool22) => tool22.type === "function");
|
|
48291
48307
|
const hasProviderDefinedTools = tools.some(
|
|
48292
|
-
(
|
|
48308
|
+
(tool22) => tool22.type === "provider-defined"
|
|
48293
48309
|
);
|
|
48294
48310
|
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
48295
|
-
const functionTools = tools.filter((
|
|
48311
|
+
const functionTools = tools.filter((tool22) => tool22.type === "function");
|
|
48296
48312
|
toolWarnings.push({
|
|
48297
48313
|
type: "unsupported-tool",
|
|
48298
|
-
tool: tools.find((
|
|
48314
|
+
tool: tools.find((tool22) => tool22.type === "function"),
|
|
48299
48315
|
details: `Cannot mix function tools with provider-defined tools in the same request. Falling back to provider-defined tools only. The following function tools will be ignored: ${functionTools.map((t2) => t2.name).join(", ")}. Please use either function tools or provider-defined tools, but not both.`
|
|
48300
48316
|
});
|
|
48301
48317
|
}
|
|
48302
48318
|
if (hasProviderDefinedTools) {
|
|
48303
48319
|
const googleTools22 = [];
|
|
48304
48320
|
const providerDefinedTools = tools.filter(
|
|
48305
|
-
(
|
|
48321
|
+
(tool22) => tool22.type === "provider-defined"
|
|
48306
48322
|
);
|
|
48307
|
-
providerDefinedTools.forEach((
|
|
48308
|
-
switch (
|
|
48323
|
+
providerDefinedTools.forEach((tool22) => {
|
|
48324
|
+
switch (tool22.id) {
|
|
48309
48325
|
case "google.google_search":
|
|
48310
48326
|
if (isGemini2orNewer) {
|
|
48311
48327
|
googleTools22.push({ googleSearch: {} });
|
|
@@ -48313,8 +48329,8 @@ function prepareTools({
|
|
|
48313
48329
|
googleTools22.push({
|
|
48314
48330
|
googleSearchRetrieval: {
|
|
48315
48331
|
dynamicRetrievalConfig: {
|
|
48316
|
-
mode:
|
|
48317
|
-
dynamicThreshold:
|
|
48332
|
+
mode: tool22.args.mode,
|
|
48333
|
+
dynamicThreshold: tool22.args.dynamicThreshold
|
|
48318
48334
|
}
|
|
48319
48335
|
}
|
|
48320
48336
|
});
|
|
@@ -48328,7 +48344,7 @@ function prepareTools({
|
|
|
48328
48344
|
} else {
|
|
48329
48345
|
toolWarnings.push({
|
|
48330
48346
|
type: "unsupported-tool",
|
|
48331
|
-
tool:
|
|
48347
|
+
tool: tool22,
|
|
48332
48348
|
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
|
48333
48349
|
});
|
|
48334
48350
|
}
|
|
@@ -48339,18 +48355,18 @@ function prepareTools({
|
|
|
48339
48355
|
} else {
|
|
48340
48356
|
toolWarnings.push({
|
|
48341
48357
|
type: "unsupported-tool",
|
|
48342
|
-
tool:
|
|
48358
|
+
tool: tool22,
|
|
48343
48359
|
details: "The code execution tools is not supported with other Gemini models than Gemini 2."
|
|
48344
48360
|
});
|
|
48345
48361
|
}
|
|
48346
48362
|
break;
|
|
48347
48363
|
case "google.file_search":
|
|
48348
48364
|
if (supportsFileSearch) {
|
|
48349
|
-
googleTools22.push({ fileSearch: __spreadValues({},
|
|
48365
|
+
googleTools22.push({ fileSearch: __spreadValues({}, tool22.args) });
|
|
48350
48366
|
} else {
|
|
48351
48367
|
toolWarnings.push({
|
|
48352
48368
|
type: "unsupported-tool",
|
|
48353
|
-
tool:
|
|
48369
|
+
tool: tool22,
|
|
48354
48370
|
details: "The file search tool is only supported with Gemini 2.5 models."
|
|
48355
48371
|
});
|
|
48356
48372
|
}
|
|
@@ -48361,22 +48377,22 @@ function prepareTools({
|
|
|
48361
48377
|
retrieval: {
|
|
48362
48378
|
vertex_rag_store: {
|
|
48363
48379
|
rag_resources: {
|
|
48364
|
-
rag_corpus:
|
|
48380
|
+
rag_corpus: tool22.args.ragCorpus
|
|
48365
48381
|
},
|
|
48366
|
-
similarity_top_k:
|
|
48382
|
+
similarity_top_k: tool22.args.topK
|
|
48367
48383
|
}
|
|
48368
48384
|
}
|
|
48369
48385
|
});
|
|
48370
48386
|
} else {
|
|
48371
48387
|
toolWarnings.push({
|
|
48372
48388
|
type: "unsupported-tool",
|
|
48373
|
-
tool:
|
|
48389
|
+
tool: tool22,
|
|
48374
48390
|
details: "The RAG store tool is not supported with other Gemini models than Gemini 2."
|
|
48375
48391
|
});
|
|
48376
48392
|
}
|
|
48377
48393
|
break;
|
|
48378
48394
|
default:
|
|
48379
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
48395
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
48380
48396
|
break;
|
|
48381
48397
|
}
|
|
48382
48398
|
});
|
|
@@ -48387,17 +48403,17 @@ function prepareTools({
|
|
|
48387
48403
|
};
|
|
48388
48404
|
}
|
|
48389
48405
|
const functionDeclarations = [];
|
|
48390
|
-
for (const
|
|
48391
|
-
switch (
|
|
48406
|
+
for (const tool22 of tools) {
|
|
48407
|
+
switch (tool22.type) {
|
|
48392
48408
|
case "function":
|
|
48393
48409
|
functionDeclarations.push({
|
|
48394
|
-
name:
|
|
48395
|
-
description: (_a4 =
|
|
48396
|
-
parameters: convertJSONSchemaToOpenAPISchema(
|
|
48410
|
+
name: tool22.name,
|
|
48411
|
+
description: (_a4 = tool22.description) != null ? _a4 : "",
|
|
48412
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool22.inputSchema)
|
|
48397
48413
|
});
|
|
48398
48414
|
break;
|
|
48399
48415
|
default:
|
|
48400
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
48416
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
48401
48417
|
break;
|
|
48402
48418
|
}
|
|
48403
48419
|
}
|
|
@@ -48511,7 +48527,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
48511
48527
|
schema: googleGenerativeAIProviderOptions
|
|
48512
48528
|
});
|
|
48513
48529
|
if ((tools == null ? void 0 : tools.some(
|
|
48514
|
-
(
|
|
48530
|
+
(tool22) => tool22.type === "provider-defined" && tool22.id === "google.vertex_rag_store"
|
|
48515
48531
|
)) && !this.config.provider.startsWith("google.vertex.")) {
|
|
48516
48532
|
warnings.push({
|
|
48517
48533
|
type: "other",
|
|
@@ -50373,23 +50389,23 @@ function prepareTools2(_0) {
|
|
|
50373
50389
|
return { tools: void 0, toolChoice: void 0, toolWarnings, betas };
|
|
50374
50390
|
}
|
|
50375
50391
|
const anthropicTools2 = [];
|
|
50376
|
-
for (const
|
|
50377
|
-
switch (
|
|
50392
|
+
for (const tool22 of tools) {
|
|
50393
|
+
switch (tool22.type) {
|
|
50378
50394
|
case "function": {
|
|
50379
|
-
const cacheControl = validator3.getCacheControl(
|
|
50395
|
+
const cacheControl = validator3.getCacheControl(tool22.providerOptions, {
|
|
50380
50396
|
type: "tool definition",
|
|
50381
50397
|
canCache: true
|
|
50382
50398
|
});
|
|
50383
50399
|
anthropicTools2.push({
|
|
50384
|
-
name:
|
|
50385
|
-
description:
|
|
50386
|
-
input_schema:
|
|
50400
|
+
name: tool22.name,
|
|
50401
|
+
description: tool22.description,
|
|
50402
|
+
input_schema: tool22.inputSchema,
|
|
50387
50403
|
cache_control: cacheControl
|
|
50388
50404
|
});
|
|
50389
50405
|
break;
|
|
50390
50406
|
}
|
|
50391
50407
|
case "provider-defined": {
|
|
50392
|
-
switch (
|
|
50408
|
+
switch (tool22.id) {
|
|
50393
50409
|
case "anthropic.code_execution_20250522": {
|
|
50394
50410
|
betas.add("code-execution-2025-05-22");
|
|
50395
50411
|
anthropicTools2.push({
|
|
@@ -50412,9 +50428,9 @@ function prepareTools2(_0) {
|
|
|
50412
50428
|
anthropicTools2.push({
|
|
50413
50429
|
name: "computer",
|
|
50414
50430
|
type: "computer_20250124",
|
|
50415
|
-
display_width_px:
|
|
50416
|
-
display_height_px:
|
|
50417
|
-
display_number:
|
|
50431
|
+
display_width_px: tool22.args.displayWidthPx,
|
|
50432
|
+
display_height_px: tool22.args.displayHeightPx,
|
|
50433
|
+
display_number: tool22.args.displayNumber,
|
|
50418
50434
|
cache_control: void 0
|
|
50419
50435
|
});
|
|
50420
50436
|
break;
|
|
@@ -50424,9 +50440,9 @@ function prepareTools2(_0) {
|
|
|
50424
50440
|
anthropicTools2.push({
|
|
50425
50441
|
name: "computer",
|
|
50426
50442
|
type: "computer_20241022",
|
|
50427
|
-
display_width_px:
|
|
50428
|
-
display_height_px:
|
|
50429
|
-
display_number:
|
|
50443
|
+
display_width_px: tool22.args.displayWidthPx,
|
|
50444
|
+
display_height_px: tool22.args.displayHeightPx,
|
|
50445
|
+
display_number: tool22.args.displayNumber,
|
|
50430
50446
|
cache_control: void 0
|
|
50431
50447
|
});
|
|
50432
50448
|
break;
|
|
@@ -50460,7 +50476,7 @@ function prepareTools2(_0) {
|
|
|
50460
50476
|
}
|
|
50461
50477
|
case "anthropic.text_editor_20250728": {
|
|
50462
50478
|
const args = yield validateTypes2({
|
|
50463
|
-
value:
|
|
50479
|
+
value: tool22.args,
|
|
50464
50480
|
schema: textEditor_20250728ArgsSchema
|
|
50465
50481
|
});
|
|
50466
50482
|
anthropicTools2.push({
|
|
@@ -50500,7 +50516,7 @@ function prepareTools2(_0) {
|
|
|
50500
50516
|
case "anthropic.web_fetch_20250910": {
|
|
50501
50517
|
betas.add("web-fetch-2025-09-10");
|
|
50502
50518
|
const args = yield validateTypes2({
|
|
50503
|
-
value:
|
|
50519
|
+
value: tool22.args,
|
|
50504
50520
|
schema: webFetch_20250910ArgsSchema
|
|
50505
50521
|
});
|
|
50506
50522
|
anthropicTools2.push({
|
|
@@ -50517,7 +50533,7 @@ function prepareTools2(_0) {
|
|
|
50517
50533
|
}
|
|
50518
50534
|
case "anthropic.web_search_20250305": {
|
|
50519
50535
|
const args = yield validateTypes2({
|
|
50520
|
-
value:
|
|
50536
|
+
value: tool22.args,
|
|
50521
50537
|
schema: webSearch_20250305ArgsSchema
|
|
50522
50538
|
});
|
|
50523
50539
|
anthropicTools2.push({
|
|
@@ -50532,14 +50548,14 @@ function prepareTools2(_0) {
|
|
|
50532
50548
|
break;
|
|
50533
50549
|
}
|
|
50534
50550
|
default: {
|
|
50535
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
50551
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
50536
50552
|
break;
|
|
50537
50553
|
}
|
|
50538
50554
|
}
|
|
50539
50555
|
break;
|
|
50540
50556
|
}
|
|
50541
50557
|
default: {
|
|
50542
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
50558
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
50543
50559
|
break;
|
|
50544
50560
|
}
|
|
50545
50561
|
}
|
|
@@ -51498,7 +51514,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
51498
51514
|
betas.add("skills-2025-10-02");
|
|
51499
51515
|
betas.add("files-api-2025-04-14");
|
|
51500
51516
|
if (!(tools == null ? void 0 : tools.some(
|
|
51501
|
-
(
|
|
51517
|
+
(tool22) => tool22.type === "provider-defined" && tool22.id === "anthropic.code_execution_20250825"
|
|
51502
51518
|
))) {
|
|
51503
51519
|
warnings.push({
|
|
51504
51520
|
type: "other",
|
|
@@ -53336,24 +53352,24 @@ function prepareTools3({
|
|
|
53336
53352
|
if (tools == null) {
|
|
53337
53353
|
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
|
53338
53354
|
}
|
|
53339
|
-
const hasFunctionTools = tools.some((
|
|
53355
|
+
const hasFunctionTools = tools.some((tool22) => tool22.type === "function");
|
|
53340
53356
|
const hasProviderDefinedTools = tools.some(
|
|
53341
|
-
(
|
|
53357
|
+
(tool22) => tool22.type === "provider-defined"
|
|
53342
53358
|
);
|
|
53343
53359
|
if (hasFunctionTools && hasProviderDefinedTools) {
|
|
53344
53360
|
toolWarnings.push({
|
|
53345
53361
|
type: "unsupported-tool",
|
|
53346
|
-
tool: tools.find((
|
|
53362
|
+
tool: tools.find((tool22) => tool22.type === "function"),
|
|
53347
53363
|
details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
|
|
53348
53364
|
});
|
|
53349
53365
|
}
|
|
53350
53366
|
if (hasProviderDefinedTools) {
|
|
53351
53367
|
const googleTools22 = [];
|
|
53352
53368
|
const providerDefinedTools = tools.filter(
|
|
53353
|
-
(
|
|
53369
|
+
(tool22) => tool22.type === "provider-defined"
|
|
53354
53370
|
);
|
|
53355
|
-
providerDefinedTools.forEach((
|
|
53356
|
-
switch (
|
|
53371
|
+
providerDefinedTools.forEach((tool22) => {
|
|
53372
|
+
switch (tool22.id) {
|
|
53357
53373
|
case "google.google_search":
|
|
53358
53374
|
if (isGemini2) {
|
|
53359
53375
|
googleTools22.push({ googleSearch: {} });
|
|
@@ -53361,8 +53377,8 @@ function prepareTools3({
|
|
|
53361
53377
|
googleTools22.push({
|
|
53362
53378
|
googleSearchRetrieval: {
|
|
53363
53379
|
dynamicRetrievalConfig: {
|
|
53364
|
-
mode:
|
|
53365
|
-
dynamicThreshold:
|
|
53380
|
+
mode: tool22.args.mode,
|
|
53381
|
+
dynamicThreshold: tool22.args.dynamicThreshold
|
|
53366
53382
|
}
|
|
53367
53383
|
}
|
|
53368
53384
|
});
|
|
@@ -53376,7 +53392,7 @@ function prepareTools3({
|
|
|
53376
53392
|
} else {
|
|
53377
53393
|
toolWarnings.push({
|
|
53378
53394
|
type: "unsupported-tool",
|
|
53379
|
-
tool:
|
|
53395
|
+
tool: tool22,
|
|
53380
53396
|
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
|
53381
53397
|
});
|
|
53382
53398
|
}
|
|
@@ -53387,13 +53403,13 @@ function prepareTools3({
|
|
|
53387
53403
|
} else {
|
|
53388
53404
|
toolWarnings.push({
|
|
53389
53405
|
type: "unsupported-tool",
|
|
53390
|
-
tool:
|
|
53406
|
+
tool: tool22,
|
|
53391
53407
|
details: "The code execution tools is not supported with other Gemini models than Gemini 2."
|
|
53392
53408
|
});
|
|
53393
53409
|
}
|
|
53394
53410
|
break;
|
|
53395
53411
|
default:
|
|
53396
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
53412
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
53397
53413
|
break;
|
|
53398
53414
|
}
|
|
53399
53415
|
});
|
|
@@ -53404,17 +53420,17 @@ function prepareTools3({
|
|
|
53404
53420
|
};
|
|
53405
53421
|
}
|
|
53406
53422
|
const functionDeclarations = [];
|
|
53407
|
-
for (const
|
|
53408
|
-
switch (
|
|
53423
|
+
for (const tool22 of tools) {
|
|
53424
|
+
switch (tool22.type) {
|
|
53409
53425
|
case "function":
|
|
53410
53426
|
functionDeclarations.push({
|
|
53411
|
-
name:
|
|
53412
|
-
description: (_a4 =
|
|
53413
|
-
parameters: convertJSONSchemaToOpenAPISchema2(
|
|
53427
|
+
name: tool22.name,
|
|
53428
|
+
description: (_a4 = tool22.description) != null ? _a4 : "",
|
|
53429
|
+
parameters: convertJSONSchemaToOpenAPISchema2(tool22.inputSchema)
|
|
53414
53430
|
});
|
|
53415
53431
|
break;
|
|
53416
53432
|
default:
|
|
53417
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
53433
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
53418
53434
|
break;
|
|
53419
53435
|
}
|
|
53420
53436
|
}
|
|
@@ -54537,16 +54553,16 @@ function prepareTools4({
|
|
|
54537
54553
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
54538
54554
|
}
|
|
54539
54555
|
const openaiCompatTools = [];
|
|
54540
|
-
for (const
|
|
54541
|
-
if (
|
|
54542
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
54556
|
+
for (const tool22 of tools) {
|
|
54557
|
+
if (tool22.type === "provider-defined") {
|
|
54558
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
54543
54559
|
} else {
|
|
54544
54560
|
openaiCompatTools.push({
|
|
54545
54561
|
type: "function",
|
|
54546
54562
|
function: {
|
|
54547
|
-
name:
|
|
54548
|
-
description:
|
|
54549
|
-
parameters:
|
|
54563
|
+
name: tool22.name,
|
|
54564
|
+
description: tool22.description,
|
|
54565
|
+
parameters: tool22.inputSchema
|
|
54550
54566
|
}
|
|
54551
54567
|
});
|
|
54552
54568
|
}
|
|
@@ -55891,16 +55907,16 @@ function prepareTools5({
|
|
|
55891
55907
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
55892
55908
|
}
|
|
55893
55909
|
const xaiTools = [];
|
|
55894
|
-
for (const
|
|
55895
|
-
if (
|
|
55896
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
55910
|
+
for (const tool22 of tools) {
|
|
55911
|
+
if (tool22.type === "provider-defined") {
|
|
55912
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
55897
55913
|
} else {
|
|
55898
55914
|
xaiTools.push({
|
|
55899
55915
|
type: "function",
|
|
55900
55916
|
function: {
|
|
55901
|
-
name:
|
|
55902
|
-
description:
|
|
55903
|
-
parameters:
|
|
55917
|
+
name: tool22.name,
|
|
55918
|
+
description: tool22.description,
|
|
55919
|
+
parameters: tool22.inputSchema
|
|
55904
55920
|
}
|
|
55905
55921
|
});
|
|
55906
55922
|
}
|
|
@@ -56900,21 +56916,21 @@ function prepareChatTools2({
|
|
|
56900
56916
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
56901
56917
|
}
|
|
56902
56918
|
const openaiTools2 = [];
|
|
56903
|
-
for (const
|
|
56904
|
-
switch (
|
|
56919
|
+
for (const tool22 of tools) {
|
|
56920
|
+
switch (tool22.type) {
|
|
56905
56921
|
case "function":
|
|
56906
56922
|
openaiTools2.push({
|
|
56907
56923
|
type: "function",
|
|
56908
56924
|
function: {
|
|
56909
|
-
name:
|
|
56910
|
-
description:
|
|
56911
|
-
parameters:
|
|
56925
|
+
name: tool22.name,
|
|
56926
|
+
description: tool22.description,
|
|
56927
|
+
parameters: tool22.inputSchema,
|
|
56912
56928
|
strict: structuredOutputs ? strictJsonSchema : void 0
|
|
56913
56929
|
}
|
|
56914
56930
|
});
|
|
56915
56931
|
break;
|
|
56916
56932
|
default:
|
|
56917
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
56933
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
56918
56934
|
break;
|
|
56919
56935
|
}
|
|
56920
56936
|
}
|
|
@@ -59496,22 +59512,22 @@ function prepareResponsesTools2(_0) {
|
|
|
59496
59512
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
59497
59513
|
}
|
|
59498
59514
|
const openaiTools2 = [];
|
|
59499
|
-
for (const
|
|
59500
|
-
switch (
|
|
59515
|
+
for (const tool22 of tools) {
|
|
59516
|
+
switch (tool22.type) {
|
|
59501
59517
|
case "function":
|
|
59502
59518
|
openaiTools2.push({
|
|
59503
59519
|
type: "function",
|
|
59504
|
-
name:
|
|
59505
|
-
description:
|
|
59506
|
-
parameters:
|
|
59520
|
+
name: tool22.name,
|
|
59521
|
+
description: tool22.description,
|
|
59522
|
+
parameters: tool22.inputSchema,
|
|
59507
59523
|
strict: strictJsonSchema
|
|
59508
59524
|
});
|
|
59509
59525
|
break;
|
|
59510
59526
|
case "provider-defined": {
|
|
59511
|
-
switch (
|
|
59527
|
+
switch (tool22.id) {
|
|
59512
59528
|
case "openai.file_search": {
|
|
59513
59529
|
const args = yield validateTypes({
|
|
59514
|
-
value:
|
|
59530
|
+
value: tool22.args,
|
|
59515
59531
|
schema: fileSearchArgsSchema3
|
|
59516
59532
|
});
|
|
59517
59533
|
openaiTools2.push({
|
|
@@ -59534,7 +59550,7 @@ function prepareResponsesTools2(_0) {
|
|
|
59534
59550
|
}
|
|
59535
59551
|
case "openai.web_search_preview": {
|
|
59536
59552
|
const args = yield validateTypes({
|
|
59537
|
-
value:
|
|
59553
|
+
value: tool22.args,
|
|
59538
59554
|
schema: webSearchPreviewArgsSchema2
|
|
59539
59555
|
});
|
|
59540
59556
|
openaiTools2.push({
|
|
@@ -59546,7 +59562,7 @@ function prepareResponsesTools2(_0) {
|
|
|
59546
59562
|
}
|
|
59547
59563
|
case "openai.web_search": {
|
|
59548
59564
|
const args = yield validateTypes({
|
|
59549
|
-
value:
|
|
59565
|
+
value: tool22.args,
|
|
59550
59566
|
schema: webSearchArgsSchema2
|
|
59551
59567
|
});
|
|
59552
59568
|
openaiTools2.push({
|
|
@@ -59559,7 +59575,7 @@ function prepareResponsesTools2(_0) {
|
|
|
59559
59575
|
}
|
|
59560
59576
|
case "openai.code_interpreter": {
|
|
59561
59577
|
const args = yield validateTypes({
|
|
59562
|
-
value:
|
|
59578
|
+
value: tool22.args,
|
|
59563
59579
|
schema: codeInterpreterArgsSchema2
|
|
59564
59580
|
});
|
|
59565
59581
|
openaiTools2.push({
|
|
@@ -59570,7 +59586,7 @@ function prepareResponsesTools2(_0) {
|
|
|
59570
59586
|
}
|
|
59571
59587
|
case "openai.image_generation": {
|
|
59572
59588
|
const args = yield validateTypes({
|
|
59573
|
-
value:
|
|
59589
|
+
value: tool22.args,
|
|
59574
59590
|
schema: imageGenerationArgsSchema2
|
|
59575
59591
|
});
|
|
59576
59592
|
openaiTools2.push({
|
|
@@ -59594,7 +59610,7 @@ function prepareResponsesTools2(_0) {
|
|
|
59594
59610
|
break;
|
|
59595
59611
|
}
|
|
59596
59612
|
default:
|
|
59597
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
59613
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
59598
59614
|
break;
|
|
59599
59615
|
}
|
|
59600
59616
|
}
|
|
@@ -59699,7 +59715,7 @@ var OpenAIResponsesLanguageModel2 = class {
|
|
|
59699
59715
|
}
|
|
59700
59716
|
function hasOpenAITool(id) {
|
|
59701
59717
|
return (tools == null ? void 0 : tools.find(
|
|
59702
|
-
(
|
|
59718
|
+
(tool22) => tool22.type === "provider-defined" && tool22.id === id
|
|
59703
59719
|
)) != null;
|
|
59704
59720
|
}
|
|
59705
59721
|
const topLogprobs = typeof (openaiOptions == null ? void 0 : openaiOptions.logprobs) === "number" ? openaiOptions == null ? void 0 : openaiOptions.logprobs : (openaiOptions == null ? void 0 : openaiOptions.logprobs) === true ? TOP_LOGPROBS_MAX2 : void 0;
|
|
@@ -59707,7 +59723,7 @@ var OpenAIResponsesLanguageModel2 = class {
|
|
|
59707
59723
|
addInclude("message.output_text.logprobs");
|
|
59708
59724
|
}
|
|
59709
59725
|
const webSearchToolName = (_c = tools == null ? void 0 : tools.find(
|
|
59710
|
-
(
|
|
59726
|
+
(tool22) => tool22.type === "provider-defined" && (tool22.id === "openai.web_search" || tool22.id === "openai.web_search_preview")
|
|
59711
59727
|
)) == null ? void 0 : _c.name;
|
|
59712
59728
|
if (webSearchToolName) {
|
|
59713
59729
|
addInclude("web_search_call.action.sources");
|
|
@@ -60930,13 +60946,13 @@ function prepareTools6({
|
|
|
60930
60946
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
60931
60947
|
}
|
|
60932
60948
|
const groqTools2 = [];
|
|
60933
|
-
for (const
|
|
60934
|
-
if (
|
|
60935
|
-
if (
|
|
60949
|
+
for (const tool22 of tools) {
|
|
60950
|
+
if (tool22.type === "provider-defined") {
|
|
60951
|
+
if (tool22.id === "groq.browser_search") {
|
|
60936
60952
|
if (!isBrowserSearchSupportedModel(modelId)) {
|
|
60937
60953
|
toolWarnings.push({
|
|
60938
60954
|
type: "unsupported-tool",
|
|
60939
|
-
tool:
|
|
60955
|
+
tool: tool22,
|
|
60940
60956
|
details: `Browser search is only supported on the following models: ${getSupportedModelsString()}. Current model: ${modelId}`
|
|
60941
60957
|
});
|
|
60942
60958
|
} else {
|
|
@@ -60945,15 +60961,15 @@ function prepareTools6({
|
|
|
60945
60961
|
});
|
|
60946
60962
|
}
|
|
60947
60963
|
} else {
|
|
60948
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
60964
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
60949
60965
|
}
|
|
60950
60966
|
} else {
|
|
60951
60967
|
groqTools2.push({
|
|
60952
60968
|
type: "function",
|
|
60953
60969
|
function: {
|
|
60954
|
-
name:
|
|
60955
|
-
description:
|
|
60956
|
-
parameters:
|
|
60970
|
+
name: tool22.name,
|
|
60971
|
+
description: tool22.description,
|
|
60972
|
+
parameters: tool22.inputSchema
|
|
60957
60973
|
}
|
|
60958
60974
|
});
|
|
60959
60975
|
}
|
|
@@ -62005,16 +62021,16 @@ function prepareTools7({
|
|
|
62005
62021
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
62006
62022
|
}
|
|
62007
62023
|
const mistralTools = [];
|
|
62008
|
-
for (const
|
|
62009
|
-
if (
|
|
62010
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
62024
|
+
for (const tool22 of tools) {
|
|
62025
|
+
if (tool22.type === "provider-defined") {
|
|
62026
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
62011
62027
|
} else {
|
|
62012
62028
|
mistralTools.push({
|
|
62013
62029
|
type: "function",
|
|
62014
62030
|
function: {
|
|
62015
|
-
name:
|
|
62016
|
-
description:
|
|
62017
|
-
parameters:
|
|
62031
|
+
name: tool22.name,
|
|
62032
|
+
description: tool22.description,
|
|
62033
|
+
parameters: tool22.inputSchema
|
|
62018
62034
|
}
|
|
62019
62035
|
});
|
|
62020
62036
|
}
|
|
@@ -62034,7 +62050,7 @@ function prepareTools7({
|
|
|
62034
62050
|
case "tool":
|
|
62035
62051
|
return {
|
|
62036
62052
|
tools: mistralTools.filter(
|
|
62037
|
-
(
|
|
62053
|
+
(tool22) => tool22.function.name === toolChoice.toolName
|
|
62038
62054
|
),
|
|
62039
62055
|
toolChoice: "any",
|
|
62040
62056
|
toolWarnings
|
|
@@ -63817,10 +63833,10 @@ function prepareResponsesTools3({
|
|
|
63817
63833
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
63818
63834
|
}
|
|
63819
63835
|
const ollamaTools = [];
|
|
63820
|
-
for (const
|
|
63821
|
-
switch (
|
|
63836
|
+
for (const tool22 of tools) {
|
|
63837
|
+
switch (tool22.type) {
|
|
63822
63838
|
case "function": {
|
|
63823
|
-
let parameters =
|
|
63839
|
+
let parameters = tool22.inputSchema;
|
|
63824
63840
|
if (!parameters) {
|
|
63825
63841
|
parameters = {
|
|
63826
63842
|
type: "object",
|
|
@@ -63836,15 +63852,15 @@ function prepareResponsesTools3({
|
|
|
63836
63852
|
ollamaTools.push({
|
|
63837
63853
|
type: "function",
|
|
63838
63854
|
function: {
|
|
63839
|
-
name:
|
|
63840
|
-
description:
|
|
63855
|
+
name: tool22.name,
|
|
63856
|
+
description: tool22.description,
|
|
63841
63857
|
parameters
|
|
63842
63858
|
}
|
|
63843
63859
|
});
|
|
63844
63860
|
break;
|
|
63845
63861
|
}
|
|
63846
63862
|
default:
|
|
63847
|
-
toolWarnings.push({ type: "unsupported-tool", tool:
|
|
63863
|
+
toolWarnings.push({ type: "unsupported-tool", tool: tool22 });
|
|
63848
63864
|
break;
|
|
63849
63865
|
}
|
|
63850
63866
|
}
|
|
@@ -64642,13 +64658,13 @@ var resolveTools = (clients, userTools) => __async(null, null, function* () {
|
|
|
64642
64658
|
const clientTools = yield clientInstance.listTools({
|
|
64643
64659
|
cursor: nextCursor
|
|
64644
64660
|
});
|
|
64645
|
-
for (const
|
|
64646
|
-
tools[
|
|
64647
|
-
description:
|
|
64648
|
-
inputSchema: jsonSchemaToZod(
|
|
64661
|
+
for (const tool22 of clientTools.tools) {
|
|
64662
|
+
tools[tool22.name] = {
|
|
64663
|
+
description: tool22.description,
|
|
64664
|
+
inputSchema: jsonSchemaToZod(tool22.inputSchema),
|
|
64649
64665
|
execute: (input) => __async(null, null, function* () {
|
|
64650
64666
|
const result = yield clientInstance.callTool({
|
|
64651
|
-
name:
|
|
64667
|
+
name: tool22.name,
|
|
64652
64668
|
arguments: input
|
|
64653
64669
|
});
|
|
64654
64670
|
return result;
|
|
@@ -67705,6 +67721,7 @@ var _V3 = class _V3 {
|
|
|
67705
67721
|
);
|
|
67706
67722
|
}
|
|
67707
67723
|
const page = yield this.resolvePage(options == null ? void 0 : options.page);
|
|
67724
|
+
const actCacheLlmClient = (options == null ? void 0 : options.model) ? this.resolveLlmClient(options.model) : void 0;
|
|
67708
67725
|
let actCacheContext = null;
|
|
67709
67726
|
const canUseCache = typeof input === "string" && !this.isAgentReplayRecording() && this.actCache.enabled;
|
|
67710
67727
|
if (canUseCache) {
|
|
@@ -67717,7 +67734,8 @@ var _V3 = class _V3 {
|
|
|
67717
67734
|
const cachedResult = yield this.actCache.tryReplay(
|
|
67718
67735
|
actCacheContext,
|
|
67719
67736
|
page,
|
|
67720
|
-
options == null ? void 0 : options.timeout
|
|
67737
|
+
options == null ? void 0 : options.timeout,
|
|
67738
|
+
actCacheLlmClient
|
|
67721
67739
|
);
|
|
67722
67740
|
if (cachedResult) {
|
|
67723
67741
|
this.addToHistory(
|
|
@@ -68120,7 +68138,13 @@ var _V3 = class _V3 {
|
|
|
68120
68138
|
configSignature: agentConfigSignature,
|
|
68121
68139
|
page: yield this.ctx.awaitActivePage()
|
|
68122
68140
|
}) : null;
|
|
68123
|
-
return {
|
|
68141
|
+
return {
|
|
68142
|
+
handler,
|
|
68143
|
+
resolvedOptions,
|
|
68144
|
+
instruction,
|
|
68145
|
+
cacheContext,
|
|
68146
|
+
llmClient: agentLlmClient
|
|
68147
|
+
};
|
|
68124
68148
|
});
|
|
68125
68149
|
}
|
|
68126
68150
|
agent(options) {
|
|
@@ -68270,13 +68294,16 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
68270
68294
|
args: [instructionOrOptions]
|
|
68271
68295
|
});
|
|
68272
68296
|
if (isStreaming) {
|
|
68273
|
-
const { handler: handler2, resolvedOptions: resolvedOptions2, cacheContext: cacheContext2 } = yield this.prepareAgentExecution(
|
|
68297
|
+
const { handler: handler2, resolvedOptions: resolvedOptions2, cacheContext: cacheContext2, llmClient: llmClient2 } = yield this.prepareAgentExecution(
|
|
68274
68298
|
options,
|
|
68275
68299
|
instructionOrOptions,
|
|
68276
68300
|
agentConfigSignature
|
|
68277
68301
|
);
|
|
68278
68302
|
if (cacheContext2) {
|
|
68279
|
-
const replayed = yield this.agentCache.tryReplayAsStream(
|
|
68303
|
+
const replayed = yield this.agentCache.tryReplayAsStream(
|
|
68304
|
+
cacheContext2,
|
|
68305
|
+
llmClient2
|
|
68306
|
+
);
|
|
68280
68307
|
if (replayed) {
|
|
68281
68308
|
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
68282
68309
|
return replayed;
|
|
@@ -68299,13 +68326,16 @@ Do not ask follow up questions, the user will trust your judgement.`
|
|
|
68299
68326
|
SessionFileLogger.logAgentTaskCompleted();
|
|
68300
68327
|
return streamResult;
|
|
68301
68328
|
}
|
|
68302
|
-
const { handler, resolvedOptions, cacheContext } = yield this.prepareAgentExecution(
|
|
68329
|
+
const { handler, resolvedOptions, cacheContext, llmClient } = yield this.prepareAgentExecution(
|
|
68303
68330
|
options,
|
|
68304
68331
|
instructionOrOptions,
|
|
68305
68332
|
agentConfigSignature
|
|
68306
68333
|
);
|
|
68307
68334
|
if (cacheContext) {
|
|
68308
|
-
const replayed = yield this.agentCache.tryReplay(
|
|
68335
|
+
const replayed = yield this.agentCache.tryReplay(
|
|
68336
|
+
cacheContext,
|
|
68337
|
+
llmClient
|
|
68338
|
+
);
|
|
68309
68339
|
if (replayed) {
|
|
68310
68340
|
SessionFileLogger.logAgentTaskCompleted({ cacheHit: true });
|
|
68311
68341
|
return replayed;
|
|
@@ -68598,6 +68628,9 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
68598
68628
|
});
|
|
68599
68629
|
}
|
|
68600
68630
|
};
|
|
68631
|
+
|
|
68632
|
+
// lib/v3/index.ts
|
|
68633
|
+
var import_ai23 = require("ai");
|
|
68601
68634
|
// Annotate the CommonJS export names for ESM import in node:
|
|
68602
68635
|
0 && (module.exports = {
|
|
68603
68636
|
AISdkClient,
|
|
@@ -68680,6 +68713,7 @@ I'm providing ${screenshots.length} screenshots showing the progression of the t
|
|
|
68680
68713
|
providerEnvVarMap,
|
|
68681
68714
|
toGeminiSchema,
|
|
68682
68715
|
toJsonSchema,
|
|
68716
|
+
tool,
|
|
68683
68717
|
transformSchema,
|
|
68684
68718
|
trimTrailingTextNode,
|
|
68685
68719
|
validateZodSchema
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@browserbasehq/stagehand",
|
|
3
|
-
"version": "3.0.8-alpha-
|
|
3
|
+
"version": "3.0.8-alpha-72ac775a831d6f0f376ceda4426525f93cc21452",
|
|
4
4
|
"description": "An AI web browsing framework focused on simplicity and extensibility.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|