@opentiny/next-sdk 0.2.5 → 0.2.6-beta.1
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/agent/utils/generateReActPrompt.ts +36 -20
- package/dist/index.d.ts +1 -0
- package/dist/index.es.dev.js +852 -210
- package/dist/index.es.js +11035 -10504
- package/dist/index.js +1433 -1337
- package/dist/index.umd.dev.js +852 -210
- package/dist/index.umd.js +75 -73
- package/dist/page-tool-bridge.d.ts +114 -0
- package/dist/skills/index.d.ts +7 -2
- package/dist/webagent.dev.js +700 -196
- package/dist/webagent.es.dev.js +700 -196
- package/dist/webagent.es.js +11494 -11057
- package/dist/webagent.js +81 -79
- package/index.ts +3 -0
- package/package.json +1 -1
- package/page-tool-bridge.ts +365 -0
- package/skills/index.ts +47 -17
package/dist/webagent.es.dev.js
CHANGED
|
@@ -8165,25 +8165,30 @@ function combineHeaders$1(...headers) {
|
|
|
8165
8165
|
}
|
|
8166
8166
|
function createToolNameMapping({
|
|
8167
8167
|
tools = [],
|
|
8168
|
-
providerToolNames
|
|
8168
|
+
providerToolNames,
|
|
8169
|
+
resolveProviderToolName
|
|
8169
8170
|
}) {
|
|
8171
|
+
var _a22;
|
|
8170
8172
|
const customToolNameToProviderToolName = {};
|
|
8171
8173
|
const providerToolNameToCustomToolName = {};
|
|
8172
8174
|
for (const tool2 of tools) {
|
|
8173
|
-
if (tool2.type === "provider"
|
|
8174
|
-
const providerToolName = providerToolNames[tool2.id];
|
|
8175
|
+
if (tool2.type === "provider") {
|
|
8176
|
+
const providerToolName = (_a22 = resolveProviderToolName == null ? void 0 : resolveProviderToolName(tool2)) != null ? _a22 : tool2.id in providerToolNames ? providerToolNames[tool2.id] : void 0;
|
|
8177
|
+
if (providerToolName == null) {
|
|
8178
|
+
continue;
|
|
8179
|
+
}
|
|
8175
8180
|
customToolNameToProviderToolName[tool2.name] = providerToolName;
|
|
8176
8181
|
providerToolNameToCustomToolName[providerToolName] = tool2.name;
|
|
8177
8182
|
}
|
|
8178
8183
|
}
|
|
8179
8184
|
return {
|
|
8180
8185
|
toProviderToolName: (customToolName) => {
|
|
8181
|
-
var
|
|
8182
|
-
return (
|
|
8186
|
+
var _a32;
|
|
8187
|
+
return (_a32 = customToolNameToProviderToolName[customToolName]) != null ? _a32 : customToolName;
|
|
8183
8188
|
},
|
|
8184
8189
|
toCustomToolName: (providerToolName) => {
|
|
8185
|
-
var
|
|
8186
|
-
return (
|
|
8190
|
+
var _a32;
|
|
8191
|
+
return (_a32 = providerToolNameToCustomToolName[providerToolName]) != null ? _a32 : providerToolName;
|
|
8187
8192
|
}
|
|
8188
8193
|
};
|
|
8189
8194
|
}
|
|
@@ -8376,8 +8381,103 @@ async function readResponseWithSizeLimit({
|
|
|
8376
8381
|
}
|
|
8377
8382
|
return result;
|
|
8378
8383
|
}
|
|
8384
|
+
function validateDownloadUrl(url2) {
|
|
8385
|
+
let parsed;
|
|
8386
|
+
try {
|
|
8387
|
+
parsed = new URL(url2);
|
|
8388
|
+
} catch (e) {
|
|
8389
|
+
throw new DownloadError({
|
|
8390
|
+
url: url2,
|
|
8391
|
+
message: `Invalid URL: ${url2}`
|
|
8392
|
+
});
|
|
8393
|
+
}
|
|
8394
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
8395
|
+
throw new DownloadError({
|
|
8396
|
+
url: url2,
|
|
8397
|
+
message: `URL scheme must be http or https, got ${parsed.protocol}`
|
|
8398
|
+
});
|
|
8399
|
+
}
|
|
8400
|
+
const hostname2 = parsed.hostname;
|
|
8401
|
+
if (!hostname2) {
|
|
8402
|
+
throw new DownloadError({
|
|
8403
|
+
url: url2,
|
|
8404
|
+
message: `URL must have a hostname`
|
|
8405
|
+
});
|
|
8406
|
+
}
|
|
8407
|
+
if (hostname2 === "localhost" || hostname2.endsWith(".local") || hostname2.endsWith(".localhost")) {
|
|
8408
|
+
throw new DownloadError({
|
|
8409
|
+
url: url2,
|
|
8410
|
+
message: `URL with hostname ${hostname2} is not allowed`
|
|
8411
|
+
});
|
|
8412
|
+
}
|
|
8413
|
+
if (hostname2.startsWith("[") && hostname2.endsWith("]")) {
|
|
8414
|
+
const ipv62 = hostname2.slice(1, -1);
|
|
8415
|
+
if (isPrivateIPv6(ipv62)) {
|
|
8416
|
+
throw new DownloadError({
|
|
8417
|
+
url: url2,
|
|
8418
|
+
message: `URL with IPv6 address ${hostname2} is not allowed`
|
|
8419
|
+
});
|
|
8420
|
+
}
|
|
8421
|
+
return;
|
|
8422
|
+
}
|
|
8423
|
+
if (isIPv4(hostname2)) {
|
|
8424
|
+
if (isPrivateIPv4(hostname2)) {
|
|
8425
|
+
throw new DownloadError({
|
|
8426
|
+
url: url2,
|
|
8427
|
+
message: `URL with IP address ${hostname2} is not allowed`
|
|
8428
|
+
});
|
|
8429
|
+
}
|
|
8430
|
+
return;
|
|
8431
|
+
}
|
|
8432
|
+
}
|
|
8433
|
+
function isIPv4(hostname2) {
|
|
8434
|
+
const parts = hostname2.split(".");
|
|
8435
|
+
if (parts.length !== 4) return false;
|
|
8436
|
+
return parts.every((part) => {
|
|
8437
|
+
const num = Number(part);
|
|
8438
|
+
return Number.isInteger(num) && num >= 0 && num <= 255 && String(num) === part;
|
|
8439
|
+
});
|
|
8440
|
+
}
|
|
8441
|
+
function isPrivateIPv4(ip) {
|
|
8442
|
+
const parts = ip.split(".").map(Number);
|
|
8443
|
+
const [a, b] = parts;
|
|
8444
|
+
if (a === 0) return true;
|
|
8445
|
+
if (a === 10) return true;
|
|
8446
|
+
if (a === 127) return true;
|
|
8447
|
+
if (a === 169 && b === 254) return true;
|
|
8448
|
+
if (a === 172 && b >= 16 && b <= 31) return true;
|
|
8449
|
+
if (a === 192 && b === 168) return true;
|
|
8450
|
+
return false;
|
|
8451
|
+
}
|
|
8452
|
+
function isPrivateIPv6(ip) {
|
|
8453
|
+
const normalized = ip.toLowerCase();
|
|
8454
|
+
if (normalized === "::1") return true;
|
|
8455
|
+
if (normalized === "::") return true;
|
|
8456
|
+
if (normalized.startsWith("::ffff:")) {
|
|
8457
|
+
const mappedPart = normalized.slice(7);
|
|
8458
|
+
if (isIPv4(mappedPart)) {
|
|
8459
|
+
return isPrivateIPv4(mappedPart);
|
|
8460
|
+
}
|
|
8461
|
+
const hexParts = mappedPart.split(":");
|
|
8462
|
+
if (hexParts.length === 2) {
|
|
8463
|
+
const high = parseInt(hexParts[0], 16);
|
|
8464
|
+
const low = parseInt(hexParts[1], 16);
|
|
8465
|
+
if (!isNaN(high) && !isNaN(low)) {
|
|
8466
|
+
const a = high >> 8 & 255;
|
|
8467
|
+
const b = high & 255;
|
|
8468
|
+
const c = low >> 8 & 255;
|
|
8469
|
+
const d = low & 255;
|
|
8470
|
+
return isPrivateIPv4(`${a}.${b}.${c}.${d}`);
|
|
8471
|
+
}
|
|
8472
|
+
}
|
|
8473
|
+
}
|
|
8474
|
+
if (normalized.startsWith("fc") || normalized.startsWith("fd")) return true;
|
|
8475
|
+
if (normalized.startsWith("fe80")) return true;
|
|
8476
|
+
return false;
|
|
8477
|
+
}
|
|
8379
8478
|
async function downloadBlob(url2, options) {
|
|
8380
8479
|
var _a22, _b22;
|
|
8480
|
+
validateDownloadUrl(url2);
|
|
8381
8481
|
try {
|
|
8382
8482
|
const response = await fetch(url2, {
|
|
8383
8483
|
signal: options == null ? void 0 : options.abortSignal
|
|
@@ -8543,7 +8643,7 @@ function withUserAgentSuffix$1(headers, ...userAgentSuffixParts) {
|
|
|
8543
8643
|
);
|
|
8544
8644
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
8545
8645
|
}
|
|
8546
|
-
var VERSION$7 = "4.0.
|
|
8646
|
+
var VERSION$7 = "4.0.19";
|
|
8547
8647
|
var getOriginalFetch = () => globalThis.fetch;
|
|
8548
8648
|
var getFromApi = async ({
|
|
8549
8649
|
url: url2,
|
|
@@ -8686,8 +8786,8 @@ function mediaTypeToExtension(mediaType) {
|
|
|
8686
8786
|
"x-m4a": "m4a"
|
|
8687
8787
|
}[subtype]) != null ? _a22 : subtype;
|
|
8688
8788
|
}
|
|
8689
|
-
var suspectProtoRx$1 = /"
|
|
8690
|
-
var suspectConstructorRx$1 = /"
|
|
8789
|
+
var suspectProtoRx$1 = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
|
|
8790
|
+
var suspectConstructorRx$1 = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
8691
8791
|
function _parse$1(text2) {
|
|
8692
8792
|
const obj = JSON.parse(text2);
|
|
8693
8793
|
if (obj === null || typeof obj !== "object") {
|
|
@@ -8707,7 +8807,7 @@ function filter$1(obj) {
|
|
|
8707
8807
|
if (Object.prototype.hasOwnProperty.call(node, "__proto__")) {
|
|
8708
8808
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
8709
8809
|
}
|
|
8710
|
-
if (Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
8810
|
+
if (Object.prototype.hasOwnProperty.call(node, "constructor") && node.constructor !== null && typeof node.constructor === "object" && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
|
|
8711
8811
|
throw new SyntaxError("Object contains forbidden prototype property");
|
|
8712
8812
|
}
|
|
8713
8813
|
for (const key in node) {
|
|
@@ -10194,6 +10294,33 @@ function tool(tool2) {
|
|
|
10194
10294
|
function dynamicTool(tool2) {
|
|
10195
10295
|
return { ...tool2, type: "dynamic" };
|
|
10196
10296
|
}
|
|
10297
|
+
function createProviderToolFactory({
|
|
10298
|
+
id: id2,
|
|
10299
|
+
inputSchema
|
|
10300
|
+
}) {
|
|
10301
|
+
return ({
|
|
10302
|
+
execute,
|
|
10303
|
+
outputSchema: outputSchema2,
|
|
10304
|
+
needsApproval,
|
|
10305
|
+
toModelOutput,
|
|
10306
|
+
onInputStart,
|
|
10307
|
+
onInputDelta,
|
|
10308
|
+
onInputAvailable,
|
|
10309
|
+
...args
|
|
10310
|
+
}) => tool({
|
|
10311
|
+
type: "provider",
|
|
10312
|
+
id: id2,
|
|
10313
|
+
args,
|
|
10314
|
+
inputSchema,
|
|
10315
|
+
outputSchema: outputSchema2,
|
|
10316
|
+
execute,
|
|
10317
|
+
needsApproval,
|
|
10318
|
+
toModelOutput,
|
|
10319
|
+
onInputStart,
|
|
10320
|
+
onInputDelta,
|
|
10321
|
+
onInputAvailable
|
|
10322
|
+
});
|
|
10323
|
+
}
|
|
10197
10324
|
function createProviderToolFactoryWithOutputSchema({
|
|
10198
10325
|
id: id2,
|
|
10199
10326
|
inputSchema,
|
|
@@ -11667,7 +11794,7 @@ async function getVercelRequestId() {
|
|
|
11667
11794
|
var _a92;
|
|
11668
11795
|
return (_a92 = indexBrowserExports.getContext().headers) == null ? void 0 : _a92["x-vercel-id"];
|
|
11669
11796
|
}
|
|
11670
|
-
var VERSION$6 = "3.0.
|
|
11797
|
+
var VERSION$6 = "3.0.66";
|
|
11671
11798
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
11672
11799
|
function createGatewayProvider(options = {}) {
|
|
11673
11800
|
var _a92, _b9;
|
|
@@ -12800,6 +12927,19 @@ var RetryError = class extends AISDKError$1 {
|
|
|
12800
12927
|
}
|
|
12801
12928
|
};
|
|
12802
12929
|
_a19 = symbol19;
|
|
12930
|
+
function asArray(value) {
|
|
12931
|
+
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
12932
|
+
}
|
|
12933
|
+
async function notify(options) {
|
|
12934
|
+
for (const callback of asArray(options.callbacks)) {
|
|
12935
|
+
if (callback == null)
|
|
12936
|
+
continue;
|
|
12937
|
+
try {
|
|
12938
|
+
await callback(options.event);
|
|
12939
|
+
} catch (_ignored) {
|
|
12940
|
+
}
|
|
12941
|
+
}
|
|
12942
|
+
}
|
|
12803
12943
|
function formatWarning({
|
|
12804
12944
|
warning,
|
|
12805
12945
|
provider,
|
|
@@ -13100,7 +13240,7 @@ function detectMediaType({
|
|
|
13100
13240
|
}
|
|
13101
13241
|
return void 0;
|
|
13102
13242
|
}
|
|
13103
|
-
var VERSION$4 = "6.0.
|
|
13243
|
+
var VERSION$4 = "6.0.116";
|
|
13104
13244
|
var download = async ({
|
|
13105
13245
|
url: url2,
|
|
13106
13246
|
maxBytes,
|
|
@@ -13108,6 +13248,7 @@ var download = async ({
|
|
|
13108
13248
|
}) => {
|
|
13109
13249
|
var _a21;
|
|
13110
13250
|
const urlText = url2.toString();
|
|
13251
|
+
validateDownloadUrl(urlText);
|
|
13111
13252
|
try {
|
|
13112
13253
|
const response = await fetch(urlText, {
|
|
13113
13254
|
headers: withUserAgentSuffix$1(
|
|
@@ -13208,9 +13349,6 @@ function convertDataContentToBase64String(content) {
|
|
|
13208
13349
|
}
|
|
13209
13350
|
return convertUint8ArrayToBase64$1(content);
|
|
13210
13351
|
}
|
|
13211
|
-
function asArray(value) {
|
|
13212
|
-
return value === void 0 ? [] : Array.isArray(value) ? value : [value];
|
|
13213
|
-
}
|
|
13214
13352
|
async function convertToLanguageModelPrompt({
|
|
13215
13353
|
prompt,
|
|
13216
13354
|
supportedUrls,
|
|
@@ -14216,6 +14354,44 @@ function stringifyForTelemetry(prompt) {
|
|
|
14216
14354
|
}))
|
|
14217
14355
|
);
|
|
14218
14356
|
}
|
|
14357
|
+
function getGlobalTelemetryIntegrations() {
|
|
14358
|
+
var _a21;
|
|
14359
|
+
return (_a21 = globalThis.AI_SDK_TELEMETRY_INTEGRATIONS) != null ? _a21 : [];
|
|
14360
|
+
}
|
|
14361
|
+
function getGlobalTelemetryIntegration() {
|
|
14362
|
+
const globalIntegrations = getGlobalTelemetryIntegrations();
|
|
14363
|
+
return (integrations) => {
|
|
14364
|
+
const localIntegrations = asArray(integrations);
|
|
14365
|
+
const allIntegrations = [...globalIntegrations, ...localIntegrations];
|
|
14366
|
+
function createTelemetryComposite(getListenerFromIntegration) {
|
|
14367
|
+
const listeners = allIntegrations.map(getListenerFromIntegration).filter(Boolean);
|
|
14368
|
+
return async (event) => {
|
|
14369
|
+
for (const listener of listeners) {
|
|
14370
|
+
try {
|
|
14371
|
+
await listener(event);
|
|
14372
|
+
} catch (_ignored) {
|
|
14373
|
+
}
|
|
14374
|
+
}
|
|
14375
|
+
};
|
|
14376
|
+
}
|
|
14377
|
+
return {
|
|
14378
|
+
onStart: createTelemetryComposite((integration) => integration.onStart),
|
|
14379
|
+
onStepStart: createTelemetryComposite(
|
|
14380
|
+
(integration) => integration.onStepStart
|
|
14381
|
+
),
|
|
14382
|
+
onToolCallStart: createTelemetryComposite(
|
|
14383
|
+
(integration) => integration.onToolCallStart
|
|
14384
|
+
),
|
|
14385
|
+
onToolCallFinish: createTelemetryComposite(
|
|
14386
|
+
(integration) => integration.onToolCallFinish
|
|
14387
|
+
),
|
|
14388
|
+
onStepFinish: createTelemetryComposite(
|
|
14389
|
+
(integration) => integration.onStepFinish
|
|
14390
|
+
),
|
|
14391
|
+
onFinish: createTelemetryComposite((integration) => integration.onFinish)
|
|
14392
|
+
};
|
|
14393
|
+
};
|
|
14394
|
+
}
|
|
14219
14395
|
function asLanguageModelUsage(usage) {
|
|
14220
14396
|
return {
|
|
14221
14397
|
inputTokens: usage.inputTokens.total,
|
|
@@ -14577,10 +14753,7 @@ async function executeToolCall({
|
|
|
14577
14753
|
tracer,
|
|
14578
14754
|
fn: async (span) => {
|
|
14579
14755
|
let output;
|
|
14580
|
-
|
|
14581
|
-
await (onToolCallStart == null ? void 0 : onToolCallStart(baseCallbackEvent));
|
|
14582
|
-
} catch (_ignored) {
|
|
14583
|
-
}
|
|
14756
|
+
await notify({ event: baseCallbackEvent, callbacks: onToolCallStart });
|
|
14584
14757
|
const startTime = now();
|
|
14585
14758
|
try {
|
|
14586
14759
|
const stream = executeTool({
|
|
@@ -14607,15 +14780,15 @@ async function executeToolCall({
|
|
|
14607
14780
|
}
|
|
14608
14781
|
} catch (error) {
|
|
14609
14782
|
const durationMs2 = now() - startTime;
|
|
14610
|
-
|
|
14611
|
-
|
|
14783
|
+
await notify({
|
|
14784
|
+
event: {
|
|
14612
14785
|
...baseCallbackEvent,
|
|
14613
14786
|
success: false,
|
|
14614
14787
|
error,
|
|
14615
14788
|
durationMs: durationMs2
|
|
14616
|
-
}
|
|
14617
|
-
|
|
14618
|
-
}
|
|
14789
|
+
},
|
|
14790
|
+
callbacks: onToolCallFinish
|
|
14791
|
+
});
|
|
14619
14792
|
recordErrorOnSpan(span, error);
|
|
14620
14793
|
return {
|
|
14621
14794
|
type: "tool-error",
|
|
@@ -14628,15 +14801,15 @@ async function executeToolCall({
|
|
|
14628
14801
|
};
|
|
14629
14802
|
}
|
|
14630
14803
|
const durationMs = now() - startTime;
|
|
14631
|
-
|
|
14632
|
-
|
|
14804
|
+
await notify({
|
|
14805
|
+
event: {
|
|
14633
14806
|
...baseCallbackEvent,
|
|
14634
14807
|
success: true,
|
|
14635
14808
|
output,
|
|
14636
14809
|
durationMs
|
|
14637
|
-
}
|
|
14638
|
-
|
|
14639
|
-
}
|
|
14810
|
+
},
|
|
14811
|
+
callbacks: onToolCallFinish
|
|
14812
|
+
});
|
|
14640
14813
|
try {
|
|
14641
14814
|
span.setAttributes(
|
|
14642
14815
|
await selectTelemetryAttributes({
|
|
@@ -15769,6 +15942,7 @@ async function generateText({
|
|
|
15769
15942
|
...settings
|
|
15770
15943
|
}) {
|
|
15771
15944
|
const model = resolveLanguageModel(modelArg);
|
|
15945
|
+
const createGlobalTelemetry = getGlobalTelemetryIntegration();
|
|
15772
15946
|
const stopConditions = asArray(stopWhen);
|
|
15773
15947
|
const totalTimeoutMs = getTotalTimeoutMs(timeout);
|
|
15774
15948
|
const stepTimeoutMs = getStepTimeoutMs(timeout);
|
|
@@ -15799,8 +15973,9 @@ async function generateText({
|
|
|
15799
15973
|
prompt,
|
|
15800
15974
|
messages
|
|
15801
15975
|
});
|
|
15802
|
-
|
|
15803
|
-
|
|
15976
|
+
const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
|
|
15977
|
+
await notify({
|
|
15978
|
+
event: {
|
|
15804
15979
|
model: modelInfo,
|
|
15805
15980
|
system,
|
|
15806
15981
|
prompt,
|
|
@@ -15827,9 +16002,12 @@ async function generateText({
|
|
|
15827
16002
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
15828
16003
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
15829
16004
|
experimental_context
|
|
15830
|
-
}
|
|
15831
|
-
|
|
15832
|
-
|
|
16005
|
+
},
|
|
16006
|
+
callbacks: [
|
|
16007
|
+
onStart,
|
|
16008
|
+
globalTelemetry.onStart
|
|
16009
|
+
]
|
|
16010
|
+
});
|
|
15833
16011
|
const tracer = getTracer(telemetry);
|
|
15834
16012
|
try {
|
|
15835
16013
|
return await recordSpan({
|
|
@@ -15873,8 +16051,14 @@ async function generateText({
|
|
|
15873
16051
|
experimental_context,
|
|
15874
16052
|
stepNumber: 0,
|
|
15875
16053
|
model: modelInfo,
|
|
15876
|
-
onToolCallStart
|
|
15877
|
-
|
|
16054
|
+
onToolCallStart: [
|
|
16055
|
+
onToolCallStart,
|
|
16056
|
+
globalTelemetry.onToolCallStart
|
|
16057
|
+
],
|
|
16058
|
+
onToolCallFinish: [
|
|
16059
|
+
onToolCallFinish,
|
|
16060
|
+
globalTelemetry.onToolCallFinish
|
|
16061
|
+
]
|
|
15878
16062
|
});
|
|
15879
16063
|
const toolContent = [];
|
|
15880
16064
|
for (const output2 of toolOutputs) {
|
|
@@ -15883,7 +16067,7 @@ async function generateText({
|
|
|
15883
16067
|
input: output2.input,
|
|
15884
16068
|
tool: tools == null ? void 0 : tools[output2.toolName],
|
|
15885
16069
|
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
15886
|
-
errorMode: output2.type === "tool-error" ? "
|
|
16070
|
+
errorMode: output2.type === "tool-error" ? "text" : "none"
|
|
15887
16071
|
});
|
|
15888
16072
|
toolContent.push({
|
|
15889
16073
|
type: "tool-result",
|
|
@@ -15979,8 +16163,8 @@ async function generateText({
|
|
|
15979
16163
|
providerOptions,
|
|
15980
16164
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
15981
16165
|
);
|
|
15982
|
-
|
|
15983
|
-
|
|
16166
|
+
await notify({
|
|
16167
|
+
event: {
|
|
15984
16168
|
stepNumber: steps.length,
|
|
15985
16169
|
model: stepModelInfo,
|
|
15986
16170
|
system: stepSystem,
|
|
@@ -15999,9 +16183,12 @@ async function generateText({
|
|
|
15999
16183
|
functionId: telemetry == null ? void 0 : telemetry.functionId,
|
|
16000
16184
|
metadata: telemetry == null ? void 0 : telemetry.metadata,
|
|
16001
16185
|
experimental_context
|
|
16002
|
-
}
|
|
16003
|
-
|
|
16004
|
-
|
|
16186
|
+
},
|
|
16187
|
+
callbacks: [
|
|
16188
|
+
onStepStart,
|
|
16189
|
+
globalTelemetry.onStepStart
|
|
16190
|
+
]
|
|
16191
|
+
});
|
|
16005
16192
|
currentModelResponse = await retry(
|
|
16006
16193
|
() => {
|
|
16007
16194
|
var _a22;
|
|
@@ -16178,8 +16365,14 @@ async function generateText({
|
|
|
16178
16365
|
experimental_context,
|
|
16179
16366
|
stepNumber: steps.length,
|
|
16180
16367
|
model: stepModelInfo,
|
|
16181
|
-
onToolCallStart
|
|
16182
|
-
|
|
16368
|
+
onToolCallStart: [
|
|
16369
|
+
onToolCallStart,
|
|
16370
|
+
globalTelemetry.onToolCallStart
|
|
16371
|
+
],
|
|
16372
|
+
onToolCallFinish: [
|
|
16373
|
+
onToolCallFinish,
|
|
16374
|
+
globalTelemetry.onToolCallFinish
|
|
16375
|
+
]
|
|
16183
16376
|
})
|
|
16184
16377
|
);
|
|
16185
16378
|
}
|
|
@@ -16246,7 +16439,10 @@ async function generateText({
|
|
|
16246
16439
|
model: stepModelInfo.modelId
|
|
16247
16440
|
});
|
|
16248
16441
|
steps.push(currentStepResult);
|
|
16249
|
-
await (
|
|
16442
|
+
await notify({
|
|
16443
|
+
event: currentStepResult,
|
|
16444
|
+
callbacks: [onStepFinish, globalTelemetry.onStepFinish]
|
|
16445
|
+
});
|
|
16250
16446
|
} finally {
|
|
16251
16447
|
if (stepTimeoutId != null) {
|
|
16252
16448
|
clearTimeout(stepTimeoutId);
|
|
@@ -16298,34 +16494,40 @@ async function generateText({
|
|
|
16298
16494
|
cachedInputTokens: void 0
|
|
16299
16495
|
}
|
|
16300
16496
|
);
|
|
16301
|
-
await (
|
|
16302
|
-
|
|
16303
|
-
|
|
16304
|
-
|
|
16305
|
-
|
|
16306
|
-
|
|
16307
|
-
|
|
16308
|
-
|
|
16309
|
-
|
|
16310
|
-
|
|
16311
|
-
|
|
16312
|
-
|
|
16313
|
-
|
|
16314
|
-
|
|
16315
|
-
|
|
16316
|
-
|
|
16317
|
-
|
|
16318
|
-
|
|
16319
|
-
|
|
16320
|
-
|
|
16321
|
-
|
|
16322
|
-
|
|
16323
|
-
|
|
16324
|
-
|
|
16325
|
-
|
|
16326
|
-
|
|
16327
|
-
|
|
16328
|
-
|
|
16497
|
+
await notify({
|
|
16498
|
+
event: {
|
|
16499
|
+
stepNumber: lastStep.stepNumber,
|
|
16500
|
+
model: lastStep.model,
|
|
16501
|
+
functionId: lastStep.functionId,
|
|
16502
|
+
metadata: lastStep.metadata,
|
|
16503
|
+
experimental_context: lastStep.experimental_context,
|
|
16504
|
+
finishReason: lastStep.finishReason,
|
|
16505
|
+
rawFinishReason: lastStep.rawFinishReason,
|
|
16506
|
+
usage: lastStep.usage,
|
|
16507
|
+
content: lastStep.content,
|
|
16508
|
+
text: lastStep.text,
|
|
16509
|
+
reasoningText: lastStep.reasoningText,
|
|
16510
|
+
reasoning: lastStep.reasoning,
|
|
16511
|
+
files: lastStep.files,
|
|
16512
|
+
sources: lastStep.sources,
|
|
16513
|
+
toolCalls: lastStep.toolCalls,
|
|
16514
|
+
staticToolCalls: lastStep.staticToolCalls,
|
|
16515
|
+
dynamicToolCalls: lastStep.dynamicToolCalls,
|
|
16516
|
+
toolResults: lastStep.toolResults,
|
|
16517
|
+
staticToolResults: lastStep.staticToolResults,
|
|
16518
|
+
dynamicToolResults: lastStep.dynamicToolResults,
|
|
16519
|
+
request: lastStep.request,
|
|
16520
|
+
response: lastStep.response,
|
|
16521
|
+
warnings: lastStep.warnings,
|
|
16522
|
+
providerMetadata: lastStep.providerMetadata,
|
|
16523
|
+
steps,
|
|
16524
|
+
totalUsage
|
|
16525
|
+
},
|
|
16526
|
+
callbacks: [
|
|
16527
|
+
onFinish,
|
|
16528
|
+
globalTelemetry.onFinish
|
|
16529
|
+
]
|
|
16530
|
+
});
|
|
16329
16531
|
let resolvedOutput;
|
|
16330
16532
|
if (lastStep.finishReason === "stop") {
|
|
16331
16533
|
const outputSpecification = output != null ? output : text();
|
|
@@ -16943,7 +17145,8 @@ function processUIMessageStream({
|
|
|
16943
17145
|
state.message.parts.push({
|
|
16944
17146
|
type: "file",
|
|
16945
17147
|
mediaType: chunk.mediaType,
|
|
16946
|
-
url: chunk.url
|
|
17148
|
+
url: chunk.url,
|
|
17149
|
+
...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
|
|
16947
17150
|
});
|
|
16948
17151
|
write();
|
|
16949
17152
|
break;
|
|
@@ -17068,7 +17271,9 @@ function processUIMessageStream({
|
|
|
17068
17271
|
break;
|
|
17069
17272
|
}
|
|
17070
17273
|
case "tool-input-error": {
|
|
17071
|
-
|
|
17274
|
+
const existingPart = state.message.parts.filter(isToolUIPart).find((p) => p.toolCallId === chunk.toolCallId);
|
|
17275
|
+
const isDynamic = existingPart != null ? existingPart.type === "dynamic-tool" : !!chunk.dynamic;
|
|
17276
|
+
if (isDynamic) {
|
|
17072
17277
|
updateDynamicToolPart({
|
|
17073
17278
|
toolCallId: chunk.toolCallId,
|
|
17074
17279
|
toolName: chunk.toolName,
|
|
@@ -17598,7 +17803,8 @@ function runToolsTransformation({
|
|
|
17598
17803
|
file: new DefaultGeneratedFileWithType({
|
|
17599
17804
|
data: chunk.data,
|
|
17600
17805
|
mediaType: chunk.mediaType
|
|
17601
|
-
})
|
|
17806
|
+
}),
|
|
17807
|
+
...chunk.providerMetadata != null ? { providerMetadata: chunk.providerMetadata } : {}
|
|
17602
17808
|
});
|
|
17603
17809
|
break;
|
|
17604
17810
|
}
|
|
@@ -17986,6 +18192,8 @@ var DefaultStreamTextResult = class {
|
|
|
17986
18192
|
this.outputSpecification = output;
|
|
17987
18193
|
this.includeRawChunks = includeRawChunks;
|
|
17988
18194
|
this.tools = tools;
|
|
18195
|
+
const createGlobalTelemetry = getGlobalTelemetryIntegration();
|
|
18196
|
+
const globalTelemetry = createGlobalTelemetry(telemetry == null ? void 0 : telemetry.integrations);
|
|
17989
18197
|
let stepFinish;
|
|
17990
18198
|
let recordedContent = [];
|
|
17991
18199
|
const recordedResponseMessages = [];
|
|
@@ -18087,7 +18295,11 @@ var DefaultStreamTextResult = class {
|
|
|
18087
18295
|
delete activeReasoningContent[part.id];
|
|
18088
18296
|
}
|
|
18089
18297
|
if (part.type === "file") {
|
|
18090
|
-
recordedContent.push({
|
|
18298
|
+
recordedContent.push({
|
|
18299
|
+
type: "file",
|
|
18300
|
+
file: part.file,
|
|
18301
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
18302
|
+
});
|
|
18091
18303
|
}
|
|
18092
18304
|
if (part.type === "source") {
|
|
18093
18305
|
recordedContent.push(part);
|
|
@@ -18133,7 +18345,10 @@ var DefaultStreamTextResult = class {
|
|
|
18133
18345
|
},
|
|
18134
18346
|
providerMetadata: part.providerMetadata
|
|
18135
18347
|
});
|
|
18136
|
-
await (
|
|
18348
|
+
await notify({
|
|
18349
|
+
event: currentStepResult,
|
|
18350
|
+
callbacks: [onStepFinish, globalTelemetry.onStepFinish]
|
|
18351
|
+
});
|
|
18137
18352
|
logWarnings({
|
|
18138
18353
|
warnings: recordedWarnings,
|
|
18139
18354
|
provider: modelInfo.provider,
|
|
@@ -18168,34 +18383,40 @@ var DefaultStreamTextResult = class {
|
|
|
18168
18383
|
self2._totalUsage.resolve(totalUsage);
|
|
18169
18384
|
self2._steps.resolve(recordedSteps);
|
|
18170
18385
|
const finalStep = recordedSteps[recordedSteps.length - 1];
|
|
18171
|
-
await (
|
|
18172
|
-
|
|
18173
|
-
|
|
18174
|
-
|
|
18175
|
-
|
|
18176
|
-
|
|
18177
|
-
|
|
18178
|
-
|
|
18179
|
-
|
|
18180
|
-
|
|
18181
|
-
|
|
18182
|
-
|
|
18183
|
-
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
|
|
18190
|
-
|
|
18191
|
-
|
|
18192
|
-
|
|
18193
|
-
|
|
18194
|
-
|
|
18195
|
-
|
|
18196
|
-
|
|
18197
|
-
|
|
18198
|
-
|
|
18386
|
+
await notify({
|
|
18387
|
+
event: {
|
|
18388
|
+
stepNumber: finalStep.stepNumber,
|
|
18389
|
+
model: finalStep.model,
|
|
18390
|
+
functionId: finalStep.functionId,
|
|
18391
|
+
metadata: finalStep.metadata,
|
|
18392
|
+
experimental_context: finalStep.experimental_context,
|
|
18393
|
+
finishReason: finalStep.finishReason,
|
|
18394
|
+
rawFinishReason: finalStep.rawFinishReason,
|
|
18395
|
+
totalUsage,
|
|
18396
|
+
usage: finalStep.usage,
|
|
18397
|
+
content: finalStep.content,
|
|
18398
|
+
text: finalStep.text,
|
|
18399
|
+
reasoningText: finalStep.reasoningText,
|
|
18400
|
+
reasoning: finalStep.reasoning,
|
|
18401
|
+
files: finalStep.files,
|
|
18402
|
+
sources: finalStep.sources,
|
|
18403
|
+
toolCalls: finalStep.toolCalls,
|
|
18404
|
+
staticToolCalls: finalStep.staticToolCalls,
|
|
18405
|
+
dynamicToolCalls: finalStep.dynamicToolCalls,
|
|
18406
|
+
toolResults: finalStep.toolResults,
|
|
18407
|
+
staticToolResults: finalStep.staticToolResults,
|
|
18408
|
+
dynamicToolResults: finalStep.dynamicToolResults,
|
|
18409
|
+
request: finalStep.request,
|
|
18410
|
+
response: finalStep.response,
|
|
18411
|
+
warnings: finalStep.warnings,
|
|
18412
|
+
providerMetadata: finalStep.providerMetadata,
|
|
18413
|
+
steps: recordedSteps
|
|
18414
|
+
},
|
|
18415
|
+
callbacks: [
|
|
18416
|
+
onFinish,
|
|
18417
|
+
globalTelemetry.onFinish
|
|
18418
|
+
]
|
|
18419
|
+
});
|
|
18199
18420
|
rootSpan.setAttributes(
|
|
18200
18421
|
await selectTelemetryAttributes({
|
|
18201
18422
|
telemetry,
|
|
@@ -18323,8 +18544,8 @@ var DefaultStreamTextResult = class {
|
|
|
18323
18544
|
prompt,
|
|
18324
18545
|
messages
|
|
18325
18546
|
});
|
|
18326
|
-
|
|
18327
|
-
|
|
18547
|
+
await notify({
|
|
18548
|
+
event: {
|
|
18328
18549
|
model: modelInfo,
|
|
18329
18550
|
system,
|
|
18330
18551
|
prompt,
|
|
@@ -18350,9 +18571,12 @@ var DefaultStreamTextResult = class {
|
|
|
18350
18571
|
include,
|
|
18351
18572
|
...callbackTelemetryProps,
|
|
18352
18573
|
experimental_context
|
|
18353
|
-
}
|
|
18354
|
-
|
|
18355
|
-
|
|
18574
|
+
},
|
|
18575
|
+
callbacks: [
|
|
18576
|
+
onStart,
|
|
18577
|
+
globalTelemetry.onStart
|
|
18578
|
+
]
|
|
18579
|
+
});
|
|
18356
18580
|
const initialMessages = initialPrompt.messages;
|
|
18357
18581
|
const initialResponseMessages = [];
|
|
18358
18582
|
const { approvedToolApprovals, deniedToolApprovals } = collectToolApprovals({ messages: initialMessages });
|
|
@@ -18401,8 +18625,14 @@ var DefaultStreamTextResult = class {
|
|
|
18401
18625
|
experimental_context,
|
|
18402
18626
|
stepNumber: recordedSteps.length,
|
|
18403
18627
|
model: modelInfo,
|
|
18404
|
-
onToolCallStart
|
|
18405
|
-
|
|
18628
|
+
onToolCallStart: [
|
|
18629
|
+
onToolCallStart,
|
|
18630
|
+
globalTelemetry.onToolCallStart
|
|
18631
|
+
],
|
|
18632
|
+
onToolCallFinish: [
|
|
18633
|
+
onToolCallFinish,
|
|
18634
|
+
globalTelemetry.onToolCallFinish
|
|
18635
|
+
],
|
|
18406
18636
|
onPreliminaryToolResult: (result2) => {
|
|
18407
18637
|
toolExecutionStepStreamController == null ? void 0 : toolExecutionStepStreamController.enqueue(result2);
|
|
18408
18638
|
}
|
|
@@ -18439,7 +18669,7 @@ var DefaultStreamTextResult = class {
|
|
|
18439
18669
|
input: output2.input,
|
|
18440
18670
|
tool: tools == null ? void 0 : tools[output2.toolName],
|
|
18441
18671
|
output: output2.type === "tool-result" ? output2.output : output2.error,
|
|
18442
|
-
errorMode: output2.type === "tool-error" ? "
|
|
18672
|
+
errorMode: output2.type === "tool-error" ? "text" : "none"
|
|
18443
18673
|
})
|
|
18444
18674
|
});
|
|
18445
18675
|
}
|
|
@@ -18533,8 +18763,8 @@ var DefaultStreamTextResult = class {
|
|
|
18533
18763
|
providerOptions,
|
|
18534
18764
|
prepareStepResult == null ? void 0 : prepareStepResult.providerOptions
|
|
18535
18765
|
);
|
|
18536
|
-
|
|
18537
|
-
|
|
18766
|
+
await notify({
|
|
18767
|
+
event: {
|
|
18538
18768
|
stepNumber: recordedSteps.length,
|
|
18539
18769
|
model: stepModelInfo,
|
|
18540
18770
|
system: stepSystem,
|
|
@@ -18552,9 +18782,12 @@ var DefaultStreamTextResult = class {
|
|
|
18552
18782
|
include,
|
|
18553
18783
|
...callbackTelemetryProps,
|
|
18554
18784
|
experimental_context
|
|
18555
|
-
}
|
|
18556
|
-
|
|
18557
|
-
|
|
18785
|
+
},
|
|
18786
|
+
callbacks: [
|
|
18787
|
+
onStepStart,
|
|
18788
|
+
globalTelemetry.onStepStart
|
|
18789
|
+
]
|
|
18790
|
+
});
|
|
18558
18791
|
const {
|
|
18559
18792
|
result: { stream: stream2, response, request },
|
|
18560
18793
|
doStreamSpan,
|
|
@@ -18629,8 +18862,14 @@ var DefaultStreamTextResult = class {
|
|
|
18629
18862
|
generateId: generateId2,
|
|
18630
18863
|
stepNumber: recordedSteps.length,
|
|
18631
18864
|
model: stepModelInfo,
|
|
18632
|
-
onToolCallStart
|
|
18633
|
-
|
|
18865
|
+
onToolCallStart: [
|
|
18866
|
+
onToolCallStart,
|
|
18867
|
+
globalTelemetry.onToolCallStart
|
|
18868
|
+
],
|
|
18869
|
+
onToolCallFinish: [
|
|
18870
|
+
onToolCallFinish,
|
|
18871
|
+
globalTelemetry.onToolCallFinish
|
|
18872
|
+
]
|
|
18634
18873
|
});
|
|
18635
18874
|
const stepRequest = ((_i = include == null ? void 0 : include.requestBody) != null ? _i : true) ? request != null ? request : {} : { ...request, body: void 0 };
|
|
18636
18875
|
const stepToolCalls = [];
|
|
@@ -19212,7 +19451,8 @@ var DefaultStreamTextResult = class {
|
|
|
19212
19451
|
controller.enqueue({
|
|
19213
19452
|
type: "file",
|
|
19214
19453
|
mediaType: part.file.mediaType,
|
|
19215
|
-
url: `data:${part.file.mediaType};base64,${part.file.base64}
|
|
19454
|
+
url: `data:${part.file.mediaType};base64,${part.file.base64}`,
|
|
19455
|
+
...part.providerMetadata != null ? { providerMetadata: part.providerMetadata } : {}
|
|
19216
19456
|
});
|
|
19217
19457
|
break;
|
|
19218
19458
|
}
|
|
@@ -24282,7 +24522,7 @@ var openaiFailedResponseHandler = createJsonErrorResponseHandler$1({
|
|
|
24282
24522
|
function getOpenAILanguageModelCapabilities(modelId) {
|
|
24283
24523
|
const supportsFlexProcessing = modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
24284
24524
|
const supportsPriorityProcessing = modelId.startsWith("gpt-4") || modelId.startsWith("gpt-5-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-nano") && !modelId.startsWith("gpt-5-chat") || modelId.startsWith("o3") || modelId.startsWith("o4-mini");
|
|
24285
|
-
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("
|
|
24525
|
+
const isReasoningModel = modelId.startsWith("o1") || modelId.startsWith("o3") || modelId.startsWith("o4-mini") || modelId.startsWith("gpt-5") && !modelId.startsWith("gpt-5-chat");
|
|
24286
24526
|
const supportsNonReasoningParameters = modelId.startsWith("gpt-5.1") || modelId.startsWith("gpt-5.2");
|
|
24287
24527
|
const systemMessageMode = isReasoningModel ? "developer" : "system";
|
|
24288
24528
|
return {
|
|
@@ -25217,7 +25457,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
25217
25457
|
for (const toolCallDelta of delta.tool_calls) {
|
|
25218
25458
|
const index = toolCallDelta.index;
|
|
25219
25459
|
if (toolCalls[index] == null) {
|
|
25220
|
-
if (toolCallDelta.type !== "function") {
|
|
25460
|
+
if (toolCallDelta.type != null && toolCallDelta.type !== "function") {
|
|
25221
25461
|
throw new InvalidResponseDataError$1({
|
|
25222
25462
|
data: toolCallDelta,
|
|
25223
25463
|
message: `Expected 'function' type.`
|
|
@@ -25911,6 +26151,7 @@ var modelMaxImagesPerCall = {
|
|
|
25911
26151
|
"chatgpt-image-latest": 10
|
|
25912
26152
|
};
|
|
25913
26153
|
var defaultResponseFormatPrefixes = [
|
|
26154
|
+
"chatgpt-image-",
|
|
25914
26155
|
"gpt-image-1-mini",
|
|
25915
26156
|
"gpt-image-1.5",
|
|
25916
26157
|
"gpt-image-1"
|
|
@@ -26188,6 +26429,30 @@ var codeInterpreterToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
|
26188
26429
|
var codeInterpreter = (args = {}) => {
|
|
26189
26430
|
return codeInterpreterToolFactory(args);
|
|
26190
26431
|
};
|
|
26432
|
+
var customArgsSchema = lazySchema(
|
|
26433
|
+
() => zodSchema(
|
|
26434
|
+
object$1({
|
|
26435
|
+
name: string(),
|
|
26436
|
+
description: string().optional(),
|
|
26437
|
+
format: union([
|
|
26438
|
+
object$1({
|
|
26439
|
+
type: literal("grammar"),
|
|
26440
|
+
syntax: _enum$1(["regex", "lark"]),
|
|
26441
|
+
definition: string()
|
|
26442
|
+
}),
|
|
26443
|
+
object$1({
|
|
26444
|
+
type: literal("text")
|
|
26445
|
+
})
|
|
26446
|
+
]).optional()
|
|
26447
|
+
})
|
|
26448
|
+
)
|
|
26449
|
+
);
|
|
26450
|
+
var customInputSchema = lazySchema(() => zodSchema(string()));
|
|
26451
|
+
var customToolFactory = createProviderToolFactory({
|
|
26452
|
+
id: "openai.custom",
|
|
26453
|
+
inputSchema: customInputSchema
|
|
26454
|
+
});
|
|
26455
|
+
var customTool = (args) => customToolFactory(args);
|
|
26191
26456
|
var comparisonFilterSchema = object$1({
|
|
26192
26457
|
key: string(),
|
|
26193
26458
|
type: _enum$1(["eq", "ne", "gt", "gte", "lt", "lte", "in", "nin"]),
|
|
@@ -26540,6 +26805,16 @@ var openaiTools = {
|
|
|
26540
26805
|
*
|
|
26541
26806
|
*/
|
|
26542
26807
|
applyPatch,
|
|
26808
|
+
/**
|
|
26809
|
+
* Custom tools let callers constrain model output to a grammar (regex or
|
|
26810
|
+
* Lark syntax). The model returns a `custom_tool_call` output item whose
|
|
26811
|
+
* `input` field is a string matching the specified grammar.
|
|
26812
|
+
*
|
|
26813
|
+
* @param name - The name of the custom tool.
|
|
26814
|
+
* @param description - An optional description of the tool.
|
|
26815
|
+
* @param format - The output format constraint (grammar type, syntax, and definition).
|
|
26816
|
+
*/
|
|
26817
|
+
customTool,
|
|
26543
26818
|
/**
|
|
26544
26819
|
* The Code Interpreter tool allows models to write and run Python code in a
|
|
26545
26820
|
* sandboxed environment to solve complex problems in domains like data analysis,
|
|
@@ -26580,7 +26855,7 @@ var openaiTools = {
|
|
|
26580
26855
|
* Local shell is a tool that allows agents to run shell commands locally
|
|
26581
26856
|
* on a machine you or the user provides.
|
|
26582
26857
|
*
|
|
26583
|
-
* Supported models: `gpt-5-codex`
|
|
26858
|
+
* Supported models: `gpt-5-codex`
|
|
26584
26859
|
*/
|
|
26585
26860
|
localShell,
|
|
26586
26861
|
/**
|
|
@@ -26678,7 +26953,8 @@ async function convertToOpenAIResponsesInput({
|
|
|
26678
26953
|
hasConversation = false,
|
|
26679
26954
|
hasLocalShellTool = false,
|
|
26680
26955
|
hasShellTool = false,
|
|
26681
|
-
hasApplyPatchTool = false
|
|
26956
|
+
hasApplyPatchTool = false,
|
|
26957
|
+
customProviderToolNames
|
|
26682
26958
|
}) {
|
|
26683
26959
|
var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
26684
26960
|
const input = [];
|
|
@@ -26761,7 +27037,9 @@ async function convertToOpenAIResponsesInput({
|
|
|
26761
27037
|
for (const part of content) {
|
|
26762
27038
|
switch (part.type) {
|
|
26763
27039
|
case "text": {
|
|
26764
|
-
const
|
|
27040
|
+
const providerOpts = (_a10 = part.providerOptions) == null ? void 0 : _a10[providerOptionsName];
|
|
27041
|
+
const id2 = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
27042
|
+
const phase = providerOpts == null ? void 0 : providerOpts.phase;
|
|
26765
27043
|
if (hasConversation && id2 != null) {
|
|
26766
27044
|
break;
|
|
26767
27045
|
}
|
|
@@ -26772,12 +27050,13 @@ async function convertToOpenAIResponsesInput({
|
|
|
26772
27050
|
input.push({
|
|
26773
27051
|
role: "assistant",
|
|
26774
27052
|
content: [{ type: "output_text", text: part.text }],
|
|
26775
|
-
id: id2
|
|
27053
|
+
id: id2,
|
|
27054
|
+
...phase != null && { phase }
|
|
26776
27055
|
});
|
|
26777
27056
|
break;
|
|
26778
27057
|
}
|
|
26779
27058
|
case "tool-call": {
|
|
26780
|
-
const id2 = (
|
|
27059
|
+
const id2 = (_f = (_c = (_b9 = part.providerOptions) == null ? void 0 : _b9[providerOptionsName]) == null ? void 0 : _c.itemId) != null ? _f : (_e = (_d = part.providerMetadata) == null ? void 0 : _d[providerOptionsName]) == null ? void 0 : _e.itemId;
|
|
26781
27060
|
if (hasConversation && id2 != null) {
|
|
26782
27061
|
break;
|
|
26783
27062
|
}
|
|
@@ -26846,6 +27125,16 @@ async function convertToOpenAIResponsesInput({
|
|
|
26846
27125
|
});
|
|
26847
27126
|
break;
|
|
26848
27127
|
}
|
|
27128
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
27129
|
+
input.push({
|
|
27130
|
+
type: "custom_tool_call",
|
|
27131
|
+
call_id: part.toolCallId,
|
|
27132
|
+
name: resolvedToolName,
|
|
27133
|
+
input: typeof part.input === "string" ? part.input : JSON.stringify(part.input),
|
|
27134
|
+
id: id2
|
|
27135
|
+
});
|
|
27136
|
+
break;
|
|
27137
|
+
}
|
|
26849
27138
|
input.push({
|
|
26850
27139
|
type: "function_call",
|
|
26851
27140
|
call_id: part.toolCallId,
|
|
@@ -26888,7 +27177,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
26888
27177
|
break;
|
|
26889
27178
|
}
|
|
26890
27179
|
if (store) {
|
|
26891
|
-
const itemId = (
|
|
27180
|
+
const itemId = (_i = (_h = (_g = part.providerOptions) == null ? void 0 : _g[providerOptionsName]) == null ? void 0 : _h.itemId) != null ? _i : part.toolCallId;
|
|
26892
27181
|
input.push({ type: "item_reference", id: itemId });
|
|
26893
27182
|
} else {
|
|
26894
27183
|
warnings.push({
|
|
@@ -26948,10 +27237,26 @@ async function convertToOpenAIResponsesInput({
|
|
|
26948
27237
|
}
|
|
26949
27238
|
}
|
|
26950
27239
|
} else {
|
|
26951
|
-
|
|
26952
|
-
|
|
26953
|
-
|
|
26954
|
-
|
|
27240
|
+
const encryptedContent = providerOptions == null ? void 0 : providerOptions.reasoningEncryptedContent;
|
|
27241
|
+
if (encryptedContent != null) {
|
|
27242
|
+
const summaryParts = [];
|
|
27243
|
+
if (part.text.length > 0) {
|
|
27244
|
+
summaryParts.push({
|
|
27245
|
+
type: "summary_text",
|
|
27246
|
+
text: part.text
|
|
27247
|
+
});
|
|
27248
|
+
}
|
|
27249
|
+
input.push({
|
|
27250
|
+
type: "reasoning",
|
|
27251
|
+
encrypted_content: encryptedContent,
|
|
27252
|
+
summary: summaryParts
|
|
27253
|
+
});
|
|
27254
|
+
} else {
|
|
27255
|
+
warnings.push({
|
|
27256
|
+
type: "other",
|
|
27257
|
+
message: `Non-OpenAI reasoning parts are not supported. Skipping reasoning part: ${JSON.stringify(part)}.`
|
|
27258
|
+
});
|
|
27259
|
+
}
|
|
26955
27260
|
}
|
|
26956
27261
|
break;
|
|
26957
27262
|
}
|
|
@@ -26982,7 +27287,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
26982
27287
|
}
|
|
26983
27288
|
const output = part.output;
|
|
26984
27289
|
if (output.type === "execution-denied") {
|
|
26985
|
-
const approvalId = (
|
|
27290
|
+
const approvalId = (_k = (_j = output.providerOptions) == null ? void 0 : _j.openai) == null ? void 0 : _k.approvalId;
|
|
26986
27291
|
if (approvalId) {
|
|
26987
27292
|
continue;
|
|
26988
27293
|
}
|
|
@@ -27034,6 +27339,61 @@ async function convertToOpenAIResponsesInput({
|
|
|
27034
27339
|
});
|
|
27035
27340
|
continue;
|
|
27036
27341
|
}
|
|
27342
|
+
if (customProviderToolNames == null ? void 0 : customProviderToolNames.has(resolvedToolName)) {
|
|
27343
|
+
let outputValue;
|
|
27344
|
+
switch (output.type) {
|
|
27345
|
+
case "text":
|
|
27346
|
+
case "error-text":
|
|
27347
|
+
outputValue = output.value;
|
|
27348
|
+
break;
|
|
27349
|
+
case "execution-denied":
|
|
27350
|
+
outputValue = (_l = output.reason) != null ? _l : "Tool execution denied.";
|
|
27351
|
+
break;
|
|
27352
|
+
case "json":
|
|
27353
|
+
case "error-json":
|
|
27354
|
+
outputValue = JSON.stringify(output.value);
|
|
27355
|
+
break;
|
|
27356
|
+
case "content":
|
|
27357
|
+
outputValue = output.value.map((item) => {
|
|
27358
|
+
var _a22;
|
|
27359
|
+
switch (item.type) {
|
|
27360
|
+
case "text":
|
|
27361
|
+
return { type: "input_text", text: item.text };
|
|
27362
|
+
case "image-data":
|
|
27363
|
+
return {
|
|
27364
|
+
type: "input_image",
|
|
27365
|
+
image_url: `data:${item.mediaType};base64,${item.data}`
|
|
27366
|
+
};
|
|
27367
|
+
case "image-url":
|
|
27368
|
+
return {
|
|
27369
|
+
type: "input_image",
|
|
27370
|
+
image_url: item.url
|
|
27371
|
+
};
|
|
27372
|
+
case "file-data":
|
|
27373
|
+
return {
|
|
27374
|
+
type: "input_file",
|
|
27375
|
+
filename: (_a22 = item.filename) != null ? _a22 : "data",
|
|
27376
|
+
file_data: `data:${item.mediaType};base64,${item.data}`
|
|
27377
|
+
};
|
|
27378
|
+
default:
|
|
27379
|
+
warnings.push({
|
|
27380
|
+
type: "other",
|
|
27381
|
+
message: `unsupported custom tool content part type: ${item.type}`
|
|
27382
|
+
});
|
|
27383
|
+
return void 0;
|
|
27384
|
+
}
|
|
27385
|
+
}).filter(isNonNullable);
|
|
27386
|
+
break;
|
|
27387
|
+
default:
|
|
27388
|
+
outputValue = "";
|
|
27389
|
+
}
|
|
27390
|
+
input.push({
|
|
27391
|
+
type: "custom_tool_call_output",
|
|
27392
|
+
call_id: part.toolCallId,
|
|
27393
|
+
output: outputValue
|
|
27394
|
+
});
|
|
27395
|
+
continue;
|
|
27396
|
+
}
|
|
27037
27397
|
let contentValue;
|
|
27038
27398
|
switch (output.type) {
|
|
27039
27399
|
case "text":
|
|
@@ -27168,7 +27528,8 @@ var openaiResponsesChunkSchema = lazySchema(
|
|
|
27168
27528
|
item: discriminatedUnion("type", [
|
|
27169
27529
|
object$1({
|
|
27170
27530
|
type: literal("message"),
|
|
27171
|
-
id: string()
|
|
27531
|
+
id: string(),
|
|
27532
|
+
phase: _enum$1(["commentary", "final_answer"]).nullish()
|
|
27172
27533
|
}),
|
|
27173
27534
|
object$1({
|
|
27174
27535
|
type: literal("reasoning"),
|
|
@@ -27249,6 +27610,13 @@ var openaiResponsesChunkSchema = lazySchema(
|
|
|
27249
27610
|
})
|
|
27250
27611
|
])
|
|
27251
27612
|
}),
|
|
27613
|
+
object$1({
|
|
27614
|
+
type: literal("custom_tool_call"),
|
|
27615
|
+
id: string(),
|
|
27616
|
+
call_id: string(),
|
|
27617
|
+
name: string(),
|
|
27618
|
+
input: string()
|
|
27619
|
+
}),
|
|
27252
27620
|
object$1({
|
|
27253
27621
|
type: literal("shell_call"),
|
|
27254
27622
|
id: string(),
|
|
@@ -27285,7 +27653,8 @@ var openaiResponsesChunkSchema = lazySchema(
|
|
|
27285
27653
|
item: discriminatedUnion("type", [
|
|
27286
27654
|
object$1({
|
|
27287
27655
|
type: literal("message"),
|
|
27288
|
-
id: string()
|
|
27656
|
+
id: string(),
|
|
27657
|
+
phase: _enum$1(["commentary", "final_answer"]).nullish()
|
|
27289
27658
|
}),
|
|
27290
27659
|
object$1({
|
|
27291
27660
|
type: literal("reasoning"),
|
|
@@ -27300,6 +27669,14 @@ var openaiResponsesChunkSchema = lazySchema(
|
|
|
27300
27669
|
arguments: string(),
|
|
27301
27670
|
status: literal("completed")
|
|
27302
27671
|
}),
|
|
27672
|
+
object$1({
|
|
27673
|
+
type: literal("custom_tool_call"),
|
|
27674
|
+
id: string(),
|
|
27675
|
+
call_id: string(),
|
|
27676
|
+
name: string(),
|
|
27677
|
+
input: string(),
|
|
27678
|
+
status: literal("completed")
|
|
27679
|
+
}),
|
|
27303
27680
|
object$1({
|
|
27304
27681
|
type: literal("code_interpreter_call"),
|
|
27305
27682
|
id: string(),
|
|
@@ -27483,6 +27860,12 @@ var openaiResponsesChunkSchema = lazySchema(
|
|
|
27483
27860
|
output_index: number$1(),
|
|
27484
27861
|
delta: string()
|
|
27485
27862
|
}),
|
|
27863
|
+
object$1({
|
|
27864
|
+
type: literal("response.custom_tool_call_input.delta"),
|
|
27865
|
+
item_id: string(),
|
|
27866
|
+
output_index: number$1(),
|
|
27867
|
+
delta: string()
|
|
27868
|
+
}),
|
|
27486
27869
|
object$1({
|
|
27487
27870
|
type: literal("response.image_generation_call.partial_image"),
|
|
27488
27871
|
item_id: string(),
|
|
@@ -27597,6 +27980,7 @@ var openaiResponsesResponseSchema = lazySchema(
|
|
|
27597
27980
|
type: literal("message"),
|
|
27598
27981
|
role: literal("assistant"),
|
|
27599
27982
|
id: string(),
|
|
27983
|
+
phase: _enum$1(["commentary", "final_answer"]).nullish(),
|
|
27600
27984
|
content: array$1(
|
|
27601
27985
|
object$1({
|
|
27602
27986
|
type: literal("output_text"),
|
|
@@ -27729,6 +28113,13 @@ var openaiResponsesResponseSchema = lazySchema(
|
|
|
27729
28113
|
arguments: string(),
|
|
27730
28114
|
id: string()
|
|
27731
28115
|
}),
|
|
28116
|
+
object$1({
|
|
28117
|
+
type: literal("custom_tool_call"),
|
|
28118
|
+
call_id: string(),
|
|
28119
|
+
name: string(),
|
|
28120
|
+
input: string(),
|
|
28121
|
+
id: string()
|
|
28122
|
+
}),
|
|
27732
28123
|
object$1({
|
|
27733
28124
|
type: literal("computer_call"),
|
|
27734
28125
|
id: string(),
|
|
@@ -28012,14 +28403,18 @@ var openaiLanguageModelResponsesOptionsSchema = lazySchema(
|
|
|
28012
28403
|
);
|
|
28013
28404
|
async function prepareResponsesTools({
|
|
28014
28405
|
tools,
|
|
28015
|
-
toolChoice
|
|
28406
|
+
toolChoice,
|
|
28407
|
+
toolNameMapping,
|
|
28408
|
+
customProviderToolNames
|
|
28016
28409
|
}) {
|
|
28410
|
+
var _a10;
|
|
28017
28411
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
28018
28412
|
const toolWarnings = [];
|
|
28019
28413
|
if (tools == null) {
|
|
28020
28414
|
return { tools: void 0, toolChoice: void 0, toolWarnings };
|
|
28021
28415
|
}
|
|
28022
28416
|
const openaiTools2 = [];
|
|
28417
|
+
const resolvedCustomProviderToolNames = customProviderToolNames != null ? customProviderToolNames : /* @__PURE__ */ new Set();
|
|
28023
28418
|
for (const tool2 of tools) {
|
|
28024
28419
|
switch (tool2.type) {
|
|
28025
28420
|
case "function":
|
|
@@ -28161,6 +28556,20 @@ async function prepareResponsesTools({
|
|
|
28161
28556
|
});
|
|
28162
28557
|
break;
|
|
28163
28558
|
}
|
|
28559
|
+
case "openai.custom": {
|
|
28560
|
+
const args = await validateTypes$1({
|
|
28561
|
+
value: tool2.args,
|
|
28562
|
+
schema: customArgsSchema
|
|
28563
|
+
});
|
|
28564
|
+
openaiTools2.push({
|
|
28565
|
+
type: "custom",
|
|
28566
|
+
name: args.name,
|
|
28567
|
+
description: args.description,
|
|
28568
|
+
format: args.format
|
|
28569
|
+
});
|
|
28570
|
+
resolvedCustomProviderToolNames.add(args.name);
|
|
28571
|
+
break;
|
|
28572
|
+
}
|
|
28164
28573
|
}
|
|
28165
28574
|
break;
|
|
28166
28575
|
}
|
|
@@ -28181,12 +28590,14 @@ async function prepareResponsesTools({
|
|
|
28181
28590
|
case "none":
|
|
28182
28591
|
case "required":
|
|
28183
28592
|
return { tools: openaiTools2, toolChoice: type2, toolWarnings };
|
|
28184
|
-
case "tool":
|
|
28593
|
+
case "tool": {
|
|
28594
|
+
const resolvedToolName = (_a10 = toolNameMapping == null ? void 0 : toolNameMapping.toProviderToolName(toolChoice.toolName)) != null ? _a10 : toolChoice.toolName;
|
|
28185
28595
|
return {
|
|
28186
28596
|
tools: openaiTools2,
|
|
28187
|
-
toolChoice:
|
|
28597
|
+
toolChoice: resolvedToolName === "code_interpreter" || resolvedToolName === "file_search" || resolvedToolName === "image_generation" || resolvedToolName === "web_search_preview" || resolvedToolName === "web_search" || resolvedToolName === "mcp" || resolvedToolName === "apply_patch" ? { type: resolvedToolName } : resolvedCustomProviderToolNames.has(resolvedToolName) ? { type: "custom", name: resolvedToolName } : { type: "function", name: resolvedToolName },
|
|
28188
28598
|
toolWarnings
|
|
28189
28599
|
};
|
|
28600
|
+
}
|
|
28190
28601
|
default: {
|
|
28191
28602
|
const _exhaustiveCheck = type2;
|
|
28192
28603
|
throw new UnsupportedFunctionalityError$1({
|
|
@@ -28335,7 +28746,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28335
28746
|
"openai.web_search_preview": "web_search_preview",
|
|
28336
28747
|
"openai.mcp": "mcp",
|
|
28337
28748
|
"openai.apply_patch": "apply_patch"
|
|
28338
|
-
}
|
|
28749
|
+
},
|
|
28750
|
+
resolveProviderToolName: (tool2) => tool2.id === "openai.custom" ? tool2.args.name : void 0
|
|
28751
|
+
});
|
|
28752
|
+
const customProviderToolNames = /* @__PURE__ */ new Set();
|
|
28753
|
+
const {
|
|
28754
|
+
tools: openaiTools2,
|
|
28755
|
+
toolChoice: openaiToolChoice,
|
|
28756
|
+
toolWarnings
|
|
28757
|
+
} = await prepareResponsesTools({
|
|
28758
|
+
tools,
|
|
28759
|
+
toolChoice,
|
|
28760
|
+
toolNameMapping,
|
|
28761
|
+
customProviderToolNames
|
|
28339
28762
|
});
|
|
28340
28763
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
28341
28764
|
prompt,
|
|
@@ -28347,7 +28770,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28347
28770
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
28348
28771
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
28349
28772
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
28350
|
-
hasApplyPatchTool: hasOpenAITool("openai.apply_patch")
|
|
28773
|
+
hasApplyPatchTool: hasOpenAITool("openai.apply_patch"),
|
|
28774
|
+
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
28351
28775
|
});
|
|
28352
28776
|
warnings.push(...inputWarnings);
|
|
28353
28777
|
const strictJsonSchema = (_d = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _d : true;
|
|
@@ -28480,14 +28904,6 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28480
28904
|
});
|
|
28481
28905
|
delete baseArgs.service_tier;
|
|
28482
28906
|
}
|
|
28483
|
-
const {
|
|
28484
|
-
tools: openaiTools2,
|
|
28485
|
-
toolChoice: openaiToolChoice,
|
|
28486
|
-
toolWarnings
|
|
28487
|
-
} = await prepareResponsesTools({
|
|
28488
|
-
tools,
|
|
28489
|
-
toolChoice
|
|
28490
|
-
});
|
|
28491
28907
|
const shellToolEnvType = (_i = (_h = (_g = tools == null ? void 0 : tools.find(
|
|
28492
28908
|
(tool2) => tool2.type === "provider" && tool2.id === "openai.shell"
|
|
28493
28909
|
)) == null ? void 0 : _g.args) == null ? void 0 : _h.environment) == null ? void 0 : _i.type;
|
|
@@ -28648,6 +29064,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28648
29064
|
}
|
|
28649
29065
|
const providerMetadata2 = {
|
|
28650
29066
|
itemId: part.id,
|
|
29067
|
+
...part.phase != null && { phase: part.phase },
|
|
28651
29068
|
...contentPart.annotations.length > 0 && {
|
|
28652
29069
|
annotations: contentPart.annotations
|
|
28653
29070
|
}
|
|
@@ -28736,6 +29153,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28736
29153
|
});
|
|
28737
29154
|
break;
|
|
28738
29155
|
}
|
|
29156
|
+
case "custom_tool_call": {
|
|
29157
|
+
hasFunctionCall = true;
|
|
29158
|
+
const toolName = toolNameMapping.toCustomToolName(part.name);
|
|
29159
|
+
content.push({
|
|
29160
|
+
type: "tool-call",
|
|
29161
|
+
toolCallId: part.call_id,
|
|
29162
|
+
toolName,
|
|
29163
|
+
input: JSON.stringify(part.input),
|
|
29164
|
+
providerMetadata: {
|
|
29165
|
+
[providerOptionsName]: {
|
|
29166
|
+
itemId: part.id
|
|
29167
|
+
}
|
|
29168
|
+
}
|
|
29169
|
+
});
|
|
29170
|
+
break;
|
|
29171
|
+
}
|
|
28739
29172
|
case "web_search_call": {
|
|
28740
29173
|
content.push({
|
|
28741
29174
|
type: "tool-call",
|
|
@@ -28962,6 +29395,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28962
29395
|
let responseId = null;
|
|
28963
29396
|
const ongoingToolCalls = {};
|
|
28964
29397
|
const ongoingAnnotations = [];
|
|
29398
|
+
let activeMessagePhase;
|
|
28965
29399
|
let hasFunctionCall = false;
|
|
28966
29400
|
const activeReasoning = {};
|
|
28967
29401
|
let serviceTier;
|
|
@@ -28972,7 +29406,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28972
29406
|
controller.enqueue({ type: "stream-start", warnings });
|
|
28973
29407
|
},
|
|
28974
29408
|
transform(chunk, controller) {
|
|
28975
|
-
var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
|
|
29409
|
+
var _a10, _b9, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
|
|
28976
29410
|
if (options.includeRawChunks) {
|
|
28977
29411
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
28978
29412
|
}
|
|
@@ -28993,6 +29427,19 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
28993
29427
|
id: value.item.call_id,
|
|
28994
29428
|
toolName: value.item.name
|
|
28995
29429
|
});
|
|
29430
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
29431
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
29432
|
+
value.item.name
|
|
29433
|
+
);
|
|
29434
|
+
ongoingToolCalls[value.output_index] = {
|
|
29435
|
+
toolName,
|
|
29436
|
+
toolCallId: value.item.call_id
|
|
29437
|
+
};
|
|
29438
|
+
controller.enqueue({
|
|
29439
|
+
type: "tool-input-start",
|
|
29440
|
+
id: value.item.call_id,
|
|
29441
|
+
toolName
|
|
29442
|
+
});
|
|
28996
29443
|
} else if (value.item.type === "web_search_call") {
|
|
28997
29444
|
ongoingToolCalls[value.output_index] = {
|
|
28998
29445
|
toolName: toolNameMapping.toCustomToolName(
|
|
@@ -29113,12 +29560,16 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29113
29560
|
} else if (value.item.type === "shell_call_output") ;
|
|
29114
29561
|
else if (value.item.type === "message") {
|
|
29115
29562
|
ongoingAnnotations.splice(0, ongoingAnnotations.length);
|
|
29563
|
+
activeMessagePhase = (_a10 = value.item.phase) != null ? _a10 : void 0;
|
|
29116
29564
|
controller.enqueue({
|
|
29117
29565
|
type: "text-start",
|
|
29118
29566
|
id: value.item.id,
|
|
29119
29567
|
providerMetadata: {
|
|
29120
29568
|
[providerOptionsName]: {
|
|
29121
|
-
itemId: value.item.id
|
|
29569
|
+
itemId: value.item.id,
|
|
29570
|
+
...value.item.phase != null && {
|
|
29571
|
+
phase: value.item.phase
|
|
29572
|
+
}
|
|
29122
29573
|
}
|
|
29123
29574
|
}
|
|
29124
29575
|
});
|
|
@@ -29133,19 +29584,22 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29133
29584
|
providerMetadata: {
|
|
29134
29585
|
[providerOptionsName]: {
|
|
29135
29586
|
itemId: value.item.id,
|
|
29136
|
-
reasoningEncryptedContent: (
|
|
29587
|
+
reasoningEncryptedContent: (_b9 = value.item.encrypted_content) != null ? _b9 : null
|
|
29137
29588
|
}
|
|
29138
29589
|
}
|
|
29139
29590
|
});
|
|
29140
29591
|
}
|
|
29141
29592
|
} else if (isResponseOutputItemDoneChunk(value)) {
|
|
29142
29593
|
if (value.item.type === "message") {
|
|
29594
|
+
const phase = (_c = value.item.phase) != null ? _c : activeMessagePhase;
|
|
29595
|
+
activeMessagePhase = void 0;
|
|
29143
29596
|
controller.enqueue({
|
|
29144
29597
|
type: "text-end",
|
|
29145
29598
|
id: value.item.id,
|
|
29146
29599
|
providerMetadata: {
|
|
29147
29600
|
[providerOptionsName]: {
|
|
29148
29601
|
itemId: value.item.id,
|
|
29602
|
+
...phase != null && { phase },
|
|
29149
29603
|
...ongoingAnnotations.length > 0 && {
|
|
29150
29604
|
annotations: ongoingAnnotations
|
|
29151
29605
|
}
|
|
@@ -29170,6 +29624,27 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29170
29624
|
}
|
|
29171
29625
|
}
|
|
29172
29626
|
});
|
|
29627
|
+
} else if (value.item.type === "custom_tool_call") {
|
|
29628
|
+
ongoingToolCalls[value.output_index] = void 0;
|
|
29629
|
+
hasFunctionCall = true;
|
|
29630
|
+
const toolName = toolNameMapping.toCustomToolName(
|
|
29631
|
+
value.item.name
|
|
29632
|
+
);
|
|
29633
|
+
controller.enqueue({
|
|
29634
|
+
type: "tool-input-end",
|
|
29635
|
+
id: value.item.call_id
|
|
29636
|
+
});
|
|
29637
|
+
controller.enqueue({
|
|
29638
|
+
type: "tool-call",
|
|
29639
|
+
toolCallId: value.item.call_id,
|
|
29640
|
+
toolName,
|
|
29641
|
+
input: JSON.stringify(value.item.input),
|
|
29642
|
+
providerMetadata: {
|
|
29643
|
+
[providerOptionsName]: {
|
|
29644
|
+
itemId: value.item.id
|
|
29645
|
+
}
|
|
29646
|
+
}
|
|
29647
|
+
});
|
|
29173
29648
|
} else if (value.item.type === "web_search_call") {
|
|
29174
29649
|
ongoingToolCalls[value.output_index] = void 0;
|
|
29175
29650
|
controller.enqueue({
|
|
@@ -29210,13 +29685,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29210
29685
|
toolName: toolNameMapping.toCustomToolName("file_search"),
|
|
29211
29686
|
result: {
|
|
29212
29687
|
queries: value.item.queries,
|
|
29213
|
-
results: (
|
|
29688
|
+
results: (_e = (_d = value.item.results) == null ? void 0 : _d.map((result) => ({
|
|
29214
29689
|
attributes: result.attributes,
|
|
29215
29690
|
fileId: result.file_id,
|
|
29216
29691
|
filename: result.filename,
|
|
29217
29692
|
score: result.score,
|
|
29218
29693
|
text: result.text
|
|
29219
|
-
}))) != null ?
|
|
29694
|
+
}))) != null ? _e : null
|
|
29220
29695
|
}
|
|
29221
29696
|
});
|
|
29222
29697
|
} else if (value.item.type === "code_interpreter_call") {
|
|
@@ -29240,10 +29715,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29240
29715
|
});
|
|
29241
29716
|
} else if (value.item.type === "mcp_call") {
|
|
29242
29717
|
ongoingToolCalls[value.output_index] = void 0;
|
|
29243
|
-
const approvalRequestId = (
|
|
29244
|
-
const aliasedToolCallId = approvalRequestId != null ? (
|
|
29718
|
+
const approvalRequestId = (_f = value.item.approval_request_id) != null ? _f : void 0;
|
|
29719
|
+
const aliasedToolCallId = approvalRequestId != null ? (_h = (_g = approvalRequestIdToDummyToolCallIdFromStream.get(
|
|
29245
29720
|
approvalRequestId
|
|
29246
|
-
)) != null ?
|
|
29721
|
+
)) != null ? _g : approvalRequestIdToDummyToolCallIdFromPrompt[approvalRequestId]) != null ? _h : value.item.id : value.item.id;
|
|
29247
29722
|
const toolName = `mcp.${value.item.name}`;
|
|
29248
29723
|
controller.enqueue({
|
|
29249
29724
|
type: "tool-call",
|
|
@@ -29313,8 +29788,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29313
29788
|
ongoingToolCalls[value.output_index] = void 0;
|
|
29314
29789
|
} else if (value.item.type === "mcp_approval_request") {
|
|
29315
29790
|
ongoingToolCalls[value.output_index] = void 0;
|
|
29316
|
-
const dummyToolCallId = (
|
|
29317
|
-
const approvalRequestId = (
|
|
29791
|
+
const dummyToolCallId = (_k = (_j = (_i = self2.config).generateId) == null ? void 0 : _j.call(_i)) != null ? _k : generateId$1();
|
|
29792
|
+
const approvalRequestId = (_l = value.item.approval_request_id) != null ? _l : value.item.id;
|
|
29318
29793
|
approvalRequestIdToDummyToolCallIdFromStream.set(
|
|
29319
29794
|
approvalRequestId,
|
|
29320
29795
|
dummyToolCallId
|
|
@@ -29403,7 +29878,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29403
29878
|
providerMetadata: {
|
|
29404
29879
|
[providerOptionsName]: {
|
|
29405
29880
|
itemId: value.item.id,
|
|
29406
|
-
reasoningEncryptedContent: (
|
|
29881
|
+
reasoningEncryptedContent: (_m = value.item.encrypted_content) != null ? _m : null
|
|
29407
29882
|
}
|
|
29408
29883
|
}
|
|
29409
29884
|
});
|
|
@@ -29419,6 +29894,15 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29419
29894
|
delta: value.delta
|
|
29420
29895
|
});
|
|
29421
29896
|
}
|
|
29897
|
+
} else if (isResponseCustomToolCallInputDeltaChunk(value)) {
|
|
29898
|
+
const toolCall = ongoingToolCalls[value.output_index];
|
|
29899
|
+
if (toolCall != null) {
|
|
29900
|
+
controller.enqueue({
|
|
29901
|
+
type: "tool-input-delta",
|
|
29902
|
+
id: toolCall.toolCallId,
|
|
29903
|
+
delta: value.delta
|
|
29904
|
+
});
|
|
29905
|
+
}
|
|
29422
29906
|
} else if (isResponseApplyPatchCallOperationDiffDeltaChunk(value)) {
|
|
29423
29907
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
29424
29908
|
if (toolCall == null ? void 0 : toolCall.applyPatch) {
|
|
@@ -29507,7 +29991,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29507
29991
|
id: value.item_id,
|
|
29508
29992
|
delta: value.delta
|
|
29509
29993
|
});
|
|
29510
|
-
if (((
|
|
29994
|
+
if (((_o = (_n = options.providerOptions) == null ? void 0 : _n[providerOptionsName]) == null ? void 0 : _o.logprobs) && value.logprobs) {
|
|
29511
29995
|
logprobs.push(value.logprobs);
|
|
29512
29996
|
}
|
|
29513
29997
|
} else if (value.type === "response.reasoning_summary_part.added") {
|
|
@@ -29536,7 +30020,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29536
30020
|
providerMetadata: {
|
|
29537
30021
|
[providerOptionsName]: {
|
|
29538
30022
|
itemId: value.item_id,
|
|
29539
|
-
reasoningEncryptedContent: (
|
|
30023
|
+
reasoningEncryptedContent: (_q = (_p = activeReasoning[value.item_id]) == null ? void 0 : _p.encryptedContent) != null ? _q : null
|
|
29540
30024
|
}
|
|
29541
30025
|
}
|
|
29542
30026
|
});
|
|
@@ -29570,10 +30054,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29570
30054
|
} else if (isResponseFinishedChunk(value)) {
|
|
29571
30055
|
finishReason = {
|
|
29572
30056
|
unified: mapOpenAIResponseFinishReason({
|
|
29573
|
-
finishReason: (
|
|
30057
|
+
finishReason: (_r = value.response.incomplete_details) == null ? void 0 : _r.reason,
|
|
29574
30058
|
hasFunctionCall
|
|
29575
30059
|
}),
|
|
29576
|
-
raw: (
|
|
30060
|
+
raw: (_t = (_s = value.response.incomplete_details) == null ? void 0 : _s.reason) != null ? _t : void 0
|
|
29577
30061
|
};
|
|
29578
30062
|
usage = value.response.usage;
|
|
29579
30063
|
if (typeof value.response.service_tier === "string") {
|
|
@@ -29585,7 +30069,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29585
30069
|
controller.enqueue({
|
|
29586
30070
|
type: "source",
|
|
29587
30071
|
sourceType: "url",
|
|
29588
|
-
id: (
|
|
30072
|
+
id: (_w = (_v = (_u = self2.config).generateId) == null ? void 0 : _v.call(_u)) != null ? _w : generateId$1(),
|
|
29589
30073
|
url: value.annotation.url,
|
|
29590
30074
|
title: value.annotation.title
|
|
29591
30075
|
});
|
|
@@ -29593,7 +30077,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29593
30077
|
controller.enqueue({
|
|
29594
30078
|
type: "source",
|
|
29595
30079
|
sourceType: "document",
|
|
29596
|
-
id: (
|
|
30080
|
+
id: (_z = (_y = (_x = self2.config).generateId) == null ? void 0 : _y.call(_x)) != null ? _z : generateId$1(),
|
|
29597
30081
|
mediaType: "text/plain",
|
|
29598
30082
|
title: value.annotation.filename,
|
|
29599
30083
|
filename: value.annotation.filename,
|
|
@@ -29609,7 +30093,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29609
30093
|
controller.enqueue({
|
|
29610
30094
|
type: "source",
|
|
29611
30095
|
sourceType: "document",
|
|
29612
|
-
id: (
|
|
30096
|
+
id: (_C = (_B = (_A = self2.config).generateId) == null ? void 0 : _B.call(_A)) != null ? _C : generateId$1(),
|
|
29613
30097
|
mediaType: "text/plain",
|
|
29614
30098
|
title: value.annotation.filename,
|
|
29615
30099
|
filename: value.annotation.filename,
|
|
@@ -29625,7 +30109,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
29625
30109
|
controller.enqueue({
|
|
29626
30110
|
type: "source",
|
|
29627
30111
|
sourceType: "document",
|
|
29628
|
-
id: (
|
|
30112
|
+
id: (_F = (_E = (_D = self2.config).generateId) == null ? void 0 : _E.call(_D)) != null ? _F : generateId$1(),
|
|
29629
30113
|
mediaType: "application/octet-stream",
|
|
29630
30114
|
title: value.annotation.file_id,
|
|
29631
30115
|
filename: value.annotation.file_id,
|
|
@@ -29679,6 +30163,9 @@ function isResponseCreatedChunk(chunk) {
|
|
|
29679
30163
|
function isResponseFunctionCallArgumentsDeltaChunk(chunk) {
|
|
29680
30164
|
return chunk.type === "response.function_call_arguments.delta";
|
|
29681
30165
|
}
|
|
30166
|
+
function isResponseCustomToolCallInputDeltaChunk(chunk) {
|
|
30167
|
+
return chunk.type === "response.custom_tool_call_input.delta";
|
|
30168
|
+
}
|
|
29682
30169
|
function isResponseImageGenerationCallPartialImageChunk(chunk) {
|
|
29683
30170
|
return chunk.type === "response.image_generation_call.partial_image";
|
|
29684
30171
|
}
|
|
@@ -30060,7 +30547,7 @@ var OpenAITranscriptionModel = class {
|
|
|
30060
30547
|
};
|
|
30061
30548
|
}
|
|
30062
30549
|
};
|
|
30063
|
-
var VERSION$2 = "3.0.
|
|
30550
|
+
var VERSION$2 = "3.0.41";
|
|
30064
30551
|
function createOpenAI(options = {}) {
|
|
30065
30552
|
var _a10, _b9;
|
|
30066
30553
|
const baseURL = (_a10 = withoutTrailingSlash$1(
|
|
@@ -36037,7 +36524,7 @@ function requireUtils$2() {
|
|
|
36037
36524
|
if (hasRequiredUtils$2) return utils$2;
|
|
36038
36525
|
hasRequiredUtils$2 = 1;
|
|
36039
36526
|
const isUUID = RegExp.prototype.test.bind(/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iu);
|
|
36040
|
-
const
|
|
36527
|
+
const isIPv42 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
36041
36528
|
function stringArrayToHexStripped(input) {
|
|
36042
36529
|
let acc = "";
|
|
36043
36530
|
let code2 = 0;
|
|
@@ -36260,7 +36747,7 @@ function requireUtils$2() {
|
|
|
36260
36747
|
}
|
|
36261
36748
|
if (component.host !== void 0) {
|
|
36262
36749
|
let host = unescape(component.host);
|
|
36263
|
-
if (!
|
|
36750
|
+
if (!isIPv42(host)) {
|
|
36264
36751
|
const ipV6res = normalizeIPv6(host);
|
|
36265
36752
|
if (ipV6res.isIPV6 === true) {
|
|
36266
36753
|
host = `[${ipV6res.escapedHost}]`;
|
|
@@ -36281,7 +36768,7 @@ function requireUtils$2() {
|
|
|
36281
36768
|
recomposeAuthority,
|
|
36282
36769
|
normalizeComponentEncoding,
|
|
36283
36770
|
removeDotSegments,
|
|
36284
|
-
isIPv4,
|
|
36771
|
+
isIPv4: isIPv42,
|
|
36285
36772
|
isUUID,
|
|
36286
36773
|
normalizeIPv6,
|
|
36287
36774
|
stringArrayToHexStripped
|
|
@@ -36502,7 +36989,7 @@ var hasRequiredFastUri;
|
|
|
36502
36989
|
function requireFastUri() {
|
|
36503
36990
|
if (hasRequiredFastUri) return fastUri.exports;
|
|
36504
36991
|
hasRequiredFastUri = 1;
|
|
36505
|
-
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4, nonSimpleDomain } = requireUtils$2();
|
|
36992
|
+
const { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizeComponentEncoding, isIPv4: isIPv42, nonSimpleDomain } = requireUtils$2();
|
|
36506
36993
|
const { SCHEMES, getSchemeHandler } = requireSchemes();
|
|
36507
36994
|
function normalize(uri2, options) {
|
|
36508
36995
|
if (typeof uri2 === "string") {
|
|
@@ -36683,7 +37170,7 @@ function requireFastUri() {
|
|
|
36683
37170
|
parsed.port = matches[5];
|
|
36684
37171
|
}
|
|
36685
37172
|
if (parsed.host) {
|
|
36686
|
-
const ipv4result =
|
|
37173
|
+
const ipv4result = isIPv42(parsed.host);
|
|
36687
37174
|
if (ipv4result === false) {
|
|
36688
37175
|
const ipv6result = normalizeIPv6(parsed.host);
|
|
36689
37176
|
parsed.host = ipv6result.host.toLowerCase();
|
|
@@ -41946,9 +42433,13 @@ function generateReActToolsPrompt(tools) {
|
|
|
41946
42433
|
if (toolEntries.length === 0) {
|
|
41947
42434
|
return "";
|
|
41948
42435
|
}
|
|
41949
|
-
let prompt =
|
|
41950
|
-
|
|
41951
|
-
|
|
42436
|
+
let prompt = `
|
|
42437
|
+
# 工具调用
|
|
42438
|
+
|
|
42439
|
+
你可以根据需要调用以下工具:
|
|
42440
|
+
|
|
42441
|
+
<tools>
|
|
42442
|
+
`;
|
|
41952
42443
|
toolEntries.forEach(([toolName, tool2]) => {
|
|
41953
42444
|
const toolInfo = tool2;
|
|
41954
42445
|
const description2 = toolInfo.description || "无描述";
|
|
@@ -41961,23 +42452,36 @@ function generateReActToolsPrompt(tools) {
|
|
|
41961
42452
|
prompt += `${JSON.stringify(toolJson, null, 2)}
|
|
41962
42453
|
`;
|
|
41963
42454
|
});
|
|
41964
|
-
prompt +=
|
|
41965
|
-
|
|
41966
|
-
|
|
41967
|
-
|
|
41968
|
-
|
|
41969
|
-
|
|
41970
|
-
|
|
41971
|
-
|
|
41972
|
-
|
|
41973
|
-
|
|
41974
|
-
|
|
41975
|
-
|
|
41976
|
-
|
|
41977
|
-
|
|
41978
|
-
|
|
41979
|
-
|
|
41980
|
-
|
|
42455
|
+
prompt += `
|
|
42456
|
+
</tools>
|
|
42457
|
+
|
|
42458
|
+
## 工具调用格式
|
|
42459
|
+
|
|
42460
|
+
要调用工具,请使用以下 XML 格式:
|
|
42461
|
+
Thought: [你的思考过程]
|
|
42462
|
+
<tool_call>
|
|
42463
|
+
{"name": "toolName", "arguments": {"arg1": "value1"}}
|
|
42464
|
+
</tool_call>
|
|
42465
|
+
|
|
42466
|
+
工具执行后,你将收到 <tool_response> 格式的结果。你可以继续思考或调用其他工具。
|
|
42467
|
+
|
|
42468
|
+
## 使用示例
|
|
42469
|
+
|
|
42470
|
+
如果用户要求"获取今天的日期",你可以这样调用工具:
|
|
42471
|
+
Thought: 用户想要获取今天的日期,我需要调用日期相关的工具。
|
|
42472
|
+
<tool_call>{"name": "get-today", "arguments": {}}</tool_call>
|
|
42473
|
+
|
|
42474
|
+
然后等待工具返回结果(Observation),再根据结果给出最终答案。
|
|
42475
|
+
|
|
42476
|
+
## 任务完成
|
|
42477
|
+
|
|
42478
|
+
当任务完成或无法继续时,直接给出最终答案即可。
|
|
42479
|
+
|
|
42480
|
+
**重要提示**:
|
|
42481
|
+
- 必须严格按照 XML 格式调用工具
|
|
42482
|
+
- arguments 必须是有效的 JSON 格式
|
|
42483
|
+
- 如果不需要调用工具,直接给出最终答案即可
|
|
42484
|
+
`;
|
|
41981
42485
|
return prompt;
|
|
41982
42486
|
}
|
|
41983
42487
|
function parseReActAction(text2, availableTools) {
|