@meetsmore-oss/use-ai-server 1.6.0 → 1.8.0
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/agents/AISDKAgent.d.ts +29 -6
- package/dist/agents/AISDKAgent.d.ts.map +1 -1
- package/dist/agents/AISDKAgent.maxSteps.test.d.ts +2 -0
- package/dist/agents/AISDKAgent.maxSteps.test.d.ts.map +1 -0
- package/dist/agents/toolApproval.d.ts.map +1 -1
- package/dist/agents/toolApproval.test.d.ts +2 -0
- package/dist/agents/toolApproval.test.d.ts.map +1 -0
- package/dist/agents/types.d.ts +5 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1883 -276
- package/dist/instrumentation.d.ts +48 -2
- package/dist/instrumentation.d.ts.map +1 -1
- package/dist/instrumentation.test.d.ts +1 -1
- package/dist/mcp/RemoteMcpToolsProvider.d.ts +1 -1
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/span-processors.integration.test.d.ts +8 -0
- package/dist/span-processors.integration.test.d.ts.map +1 -0
- package/dist/src/agents/AISDKAgent.d.ts +29 -6
- package/dist/src/agents/AISDKAgent.d.ts.map +1 -1
- package/dist/src/agents/AISDKAgent.maxSteps.test.d.ts +2 -0
- package/dist/src/agents/AISDKAgent.maxSteps.test.d.ts.map +1 -0
- package/dist/src/agents/toolApproval.d.ts.map +1 -1
- package/dist/src/agents/toolApproval.test.d.ts +2 -0
- package/dist/src/agents/toolApproval.test.d.ts.map +1 -0
- package/dist/src/agents/types.d.ts +5 -0
- package/dist/src/agents/types.d.ts.map +1 -1
- package/dist/src/index.d.ts +5 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/instrumentation.d.ts +48 -2
- package/dist/src/instrumentation.d.ts.map +1 -1
- package/dist/src/instrumentation.test.d.ts +1 -1
- package/dist/src/mcp/RemoteMcpToolsProvider.d.ts +1 -1
- package/dist/src/server.d.ts +1 -0
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/span-processors.integration.test.d.ts +8 -0
- package/dist/src/span-processors.integration.test.d.ts.map +1 -0
- package/dist/src/telemetry.d.ts +41 -0
- package/dist/src/telemetry.d.ts.map +1 -0
- package/dist/src/telemetry.test.d.ts +2 -0
- package/dist/src/telemetry.test.d.ts.map +1 -0
- package/dist/src/test-preload.d.ts +4 -0
- package/dist/src/test-preload.d.ts.map +1 -1
- package/dist/src/tools/defineServerTool.d.ts +54 -0
- package/dist/src/tools/defineServerTool.d.ts.map +1 -0
- package/dist/src/tools/defineServerTool.test.d.ts +2 -0
- package/dist/src/tools/defineServerTool.test.d.ts.map +1 -0
- package/dist/src/tools/index.d.ts +4 -0
- package/dist/src/tools/index.d.ts.map +1 -0
- package/dist/src/tools/serverToolExecutor.d.ts +20 -0
- package/dist/src/tools/serverToolExecutor.d.ts.map +1 -0
- package/dist/src/tools/serverToolExecutor.test.d.ts +2 -0
- package/dist/src/tools/serverToolExecutor.test.d.ts.map +1 -0
- package/dist/src/tools/types.d.ts +51 -0
- package/dist/src/tools/types.d.ts.map +1 -0
- package/dist/src/types.d.ts +36 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/utils/index.d.ts +1 -1
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/toolConverter.d.ts.map +1 -1
- package/dist/src/utils/toolConverter.test.d.ts +2 -0
- package/dist/src/utils/toolConverter.test.d.ts.map +1 -0
- package/dist/src/utils/toolFilters.d.ts +16 -0
- package/dist/src/utils/toolFilters.d.ts.map +1 -1
- package/dist/src/utils/toolFilters.test.d.ts +2 -0
- package/dist/src/utils/toolFilters.test.d.ts.map +1 -0
- package/dist/telemetry.d.ts +41 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.test.d.ts +2 -0
- package/dist/telemetry.test.d.ts.map +1 -0
- package/dist/test/test-utils.d.ts +1 -0
- package/dist/test/test-utils.d.ts.map +1 -1
- package/dist/test-preload.d.ts +4 -0
- package/dist/test-preload.d.ts.map +1 -1
- package/dist/tools/defineServerTool.d.ts +54 -0
- package/dist/tools/defineServerTool.d.ts.map +1 -0
- package/dist/tools/defineServerTool.test.d.ts +2 -0
- package/dist/tools/defineServerTool.test.d.ts.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/serverToolExecutor.d.ts +20 -0
- package/dist/tools/serverToolExecutor.d.ts.map +1 -0
- package/dist/tools/serverToolExecutor.test.d.ts +2 -0
- package/dist/tools/serverToolExecutor.test.d.ts.map +1 -0
- package/dist/tools/types.d.ts +51 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +36 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/toolConverter.d.ts.map +1 -1
- package/dist/utils/toolConverter.test.d.ts +2 -0
- package/dist/utils/toolConverter.test.d.ts.map +1 -0
- package/dist/utils/toolFilters.d.ts +16 -0
- package/dist/utils/toolFilters.d.ts.map +1 -1
- package/dist/utils/toolFilters.test.d.ts +2 -0
- package/dist/utils/toolFilters.test.d.ts.map +1 -0
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -5,39 +5,60 @@ var __defProp = Object.defineProperty;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
8
13
|
var __toESM = (mod2, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod2 != null && typeof mod2 === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod2);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
9
21
|
target = mod2 != null ? __create(__getProtoOf(mod2)) : {};
|
|
10
22
|
const to = isNodeMode || !mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target;
|
|
11
23
|
for (let key of __getOwnPropNames(mod2))
|
|
12
24
|
if (!__hasOwnProp.call(to, key))
|
|
13
25
|
__defProp(to, key, {
|
|
14
|
-
get: (
|
|
26
|
+
get: __accessProp.bind(mod2, key),
|
|
15
27
|
enumerable: true
|
|
16
28
|
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod2, to);
|
|
17
31
|
return to;
|
|
18
32
|
};
|
|
19
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
20
33
|
var __toCommonJS = (from) => {
|
|
21
|
-
var entry = __moduleCache.get(from), desc;
|
|
34
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
22
35
|
if (entry)
|
|
23
36
|
return entry;
|
|
24
37
|
entry = __defProp({}, "__esModule", { value: true });
|
|
25
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (var key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(entry, key))
|
|
41
|
+
__defProp(entry, key, {
|
|
42
|
+
get: __accessProp.bind(from, key),
|
|
43
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
44
|
+
});
|
|
45
|
+
}
|
|
30
46
|
__moduleCache.set(from, entry);
|
|
31
47
|
return entry;
|
|
32
48
|
};
|
|
49
|
+
var __moduleCache;
|
|
33
50
|
var __commonJS = (cb, mod2) => () => (mod2 || cb((mod2 = { exports: {} }).exports, mod2), mod2.exports);
|
|
51
|
+
var __returnValue = (v) => v;
|
|
52
|
+
function __exportSetter(name, newValue) {
|
|
53
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
54
|
+
}
|
|
34
55
|
var __export = (target, all) => {
|
|
35
56
|
for (var name in all)
|
|
36
57
|
__defProp(target, name, {
|
|
37
58
|
get: all[name],
|
|
38
59
|
enumerable: true,
|
|
39
60
|
configurable: true,
|
|
40
|
-
set: (
|
|
61
|
+
set: __exportSetter.bind(all, name)
|
|
41
62
|
});
|
|
42
63
|
};
|
|
43
64
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
@@ -81212,15 +81233,29 @@ var __getProtoOf2 = Object.getPrototypeOf;
|
|
|
81212
81233
|
var __defProp2 = Object.defineProperty;
|
|
81213
81234
|
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
81214
81235
|
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
81236
|
+
function __accessProp2(key) {
|
|
81237
|
+
return this[key];
|
|
81238
|
+
}
|
|
81239
|
+
var __toESMCache_node2;
|
|
81240
|
+
var __toESMCache_esm2;
|
|
81215
81241
|
var __toESM2 = (mod2, isNodeMode, target) => {
|
|
81242
|
+
var canCache = mod2 != null && typeof mod2 === "object";
|
|
81243
|
+
if (canCache) {
|
|
81244
|
+
var cache = isNodeMode ? __toESMCache_node2 ??= new WeakMap : __toESMCache_esm2 ??= new WeakMap;
|
|
81245
|
+
var cached = cache.get(mod2);
|
|
81246
|
+
if (cached)
|
|
81247
|
+
return cached;
|
|
81248
|
+
}
|
|
81216
81249
|
target = mod2 != null ? __create2(__getProtoOf2(mod2)) : {};
|
|
81217
81250
|
const to = isNodeMode || !mod2 || !mod2.__esModule ? __defProp2(target, "default", { value: mod2, enumerable: true }) : target;
|
|
81218
81251
|
for (let key of __getOwnPropNames2(mod2))
|
|
81219
81252
|
if (!__hasOwnProp2.call(to, key))
|
|
81220
81253
|
__defProp2(to, key, {
|
|
81221
|
-
get: (
|
|
81254
|
+
get: __accessProp2.bind(mod2, key),
|
|
81222
81255
|
enumerable: true
|
|
81223
81256
|
});
|
|
81257
|
+
if (canCache)
|
|
81258
|
+
cache.set(mod2, to);
|
|
81224
81259
|
return to;
|
|
81225
81260
|
};
|
|
81226
81261
|
var __commonJS2 = (cb, mod2) => () => (mod2 || cb((mod2 = { exports: {} }).exports, mod2), mod2.exports);
|
|
@@ -85873,56 +85908,6 @@ class Logger {
|
|
|
85873
85908
|
}
|
|
85874
85909
|
var logger2 = new Logger;
|
|
85875
85910
|
|
|
85876
|
-
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
|
|
85877
|
-
var byteToHex = [];
|
|
85878
|
-
for (let i = 0;i < 256; ++i) {
|
|
85879
|
-
byteToHex.push((i + 256).toString(16).slice(1));
|
|
85880
|
-
}
|
|
85881
|
-
function unsafeStringify(arr, offset = 0) {
|
|
85882
|
-
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
85883
|
-
}
|
|
85884
|
-
|
|
85885
|
-
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
|
|
85886
|
-
import { randomFillSync } from "crypto";
|
|
85887
|
-
var rnds8Pool = new Uint8Array(256);
|
|
85888
|
-
var poolPtr = rnds8Pool.length;
|
|
85889
|
-
function rng() {
|
|
85890
|
-
if (poolPtr > rnds8Pool.length - 16) {
|
|
85891
|
-
randomFillSync(rnds8Pool);
|
|
85892
|
-
poolPtr = 0;
|
|
85893
|
-
}
|
|
85894
|
-
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
85895
|
-
}
|
|
85896
|
-
|
|
85897
|
-
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
|
|
85898
|
-
import { randomUUID } from "crypto";
|
|
85899
|
-
var native_default = { randomUUID };
|
|
85900
|
-
|
|
85901
|
-
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
|
|
85902
|
-
function v4(options, buf, offset) {
|
|
85903
|
-
if (native_default.randomUUID && !buf && !options) {
|
|
85904
|
-
return native_default.randomUUID();
|
|
85905
|
-
}
|
|
85906
|
-
options = options || {};
|
|
85907
|
-
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
85908
|
-
if (rnds.length < 16) {
|
|
85909
|
-
throw new Error("Random bytes length must be >= 16");
|
|
85910
|
-
}
|
|
85911
|
-
rnds[6] = rnds[6] & 15 | 64;
|
|
85912
|
-
rnds[8] = rnds[8] & 63 | 128;
|
|
85913
|
-
if (buf) {
|
|
85914
|
-
offset = offset || 0;
|
|
85915
|
-
if (offset < 0 || offset + 16 > buf.length) {
|
|
85916
|
-
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
85917
|
-
}
|
|
85918
|
-
for (let i = 0;i < 16; ++i) {
|
|
85919
|
-
buf[offset + i] = rnds[i];
|
|
85920
|
-
}
|
|
85921
|
-
return buf;
|
|
85922
|
-
}
|
|
85923
|
-
return unsafeStringify(rnds);
|
|
85924
|
-
}
|
|
85925
|
-
var v4_default = v4;
|
|
85926
85911
|
// ../../node_modules/.bun/mustache@4.2.0/node_modules/mustache/mustache.mjs
|
|
85927
85912
|
/*!
|
|
85928
85913
|
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
|
@@ -89293,28 +89278,55 @@ function popTraceIdForRun(runId) {
|
|
|
89293
89278
|
}
|
|
89294
89279
|
return traceId;
|
|
89295
89280
|
}
|
|
89296
|
-
function
|
|
89297
|
-
|
|
89298
|
-
|
|
89299
|
-
|
|
89281
|
+
function recordErrorTrace(params) {
|
|
89282
|
+
if (!langfuse.enabled || !langfuse.client)
|
|
89283
|
+
return;
|
|
89284
|
+
try {
|
|
89285
|
+
const trace2 = langfuse.client.trace({
|
|
89286
|
+
id: params.runId,
|
|
89287
|
+
name: "use-ai-error",
|
|
89288
|
+
sessionId: params.sessionId,
|
|
89289
|
+
input: { threadId: params.threadId, errorCategory: params.errorCategory },
|
|
89290
|
+
output: { error: params.errorMessage },
|
|
89291
|
+
metadata: {
|
|
89292
|
+
errorCategory: params.errorCategory,
|
|
89293
|
+
ipAddress: params.ipAddress,
|
|
89294
|
+
source: "use-ai-server",
|
|
89295
|
+
...params.metadata
|
|
89296
|
+
},
|
|
89297
|
+
tags: ["error", params.errorCategory]
|
|
89298
|
+
});
|
|
89299
|
+
trace2.span({
|
|
89300
|
+
name: params.errorCategory,
|
|
89301
|
+
level: "ERROR",
|
|
89302
|
+
statusMessage: params.errorMessage,
|
|
89303
|
+
input: { threadId: params.threadId, errorCategory: params.errorCategory },
|
|
89304
|
+
output: { error: params.errorMessage }
|
|
89305
|
+
});
|
|
89306
|
+
} catch (error) {
|
|
89307
|
+
logger2.debug("Failed to record error trace in Langfuse", {
|
|
89308
|
+
error: error instanceof Error ? error.message : String(error),
|
|
89309
|
+
runId: params.runId
|
|
89310
|
+
});
|
|
89300
89311
|
}
|
|
89301
|
-
|
|
89302
|
-
|
|
89303
|
-
|
|
89304
|
-
|
|
89305
|
-
|
|
89306
|
-
|
|
89307
|
-
|
|
89308
|
-
|
|
89312
|
+
}
|
|
89313
|
+
var _tracingEnabled = false;
|
|
89314
|
+
function isTracingEnabled() {
|
|
89315
|
+
return _tracingEnabled;
|
|
89316
|
+
}
|
|
89317
|
+
var _tracingStarted = false;
|
|
89318
|
+
var _spanProcessors = [];
|
|
89319
|
+
async function flushTracing() {
|
|
89320
|
+
await Promise.all(_spanProcessors.map((p) => p.forceFlush()));
|
|
89321
|
+
}
|
|
89322
|
+
function startTracing(customProcessors = []) {
|
|
89323
|
+
if (_tracingStarted)
|
|
89324
|
+
return;
|
|
89325
|
+
_tracingStarted = true;
|
|
89326
|
+
if (!langfuse.enabled && customProcessors.length === 0)
|
|
89327
|
+
return;
|
|
89309
89328
|
try {
|
|
89310
89329
|
const { NodeSDK } = require_src32();
|
|
89311
|
-
const { LangfuseSpanProcessor } = require_dist5();
|
|
89312
|
-
const langfuseSpanProcessor = new LangfuseSpanProcessor({
|
|
89313
|
-
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
89314
|
-
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
89315
|
-
baseUrl,
|
|
89316
|
-
release
|
|
89317
|
-
});
|
|
89318
89330
|
const traceIdCaptureProcessor = {
|
|
89319
89331
|
onStart(span) {
|
|
89320
89332
|
const runId = span.attributes?.["ai.telemetry.metadata.runId"];
|
|
@@ -89330,33 +89342,101 @@ function _initializeLangfuse() {
|
|
|
89330
89342
|
return Promise.resolve();
|
|
89331
89343
|
}
|
|
89332
89344
|
};
|
|
89333
|
-
const
|
|
89334
|
-
|
|
89335
|
-
|
|
89345
|
+
const spanProcessors = [traceIdCaptureProcessor];
|
|
89346
|
+
let langfuseSpanProcessor;
|
|
89347
|
+
if (langfuse.enabled) {
|
|
89348
|
+
const { LangfuseSpanProcessor } = require_dist5();
|
|
89349
|
+
langfuseSpanProcessor = new LangfuseSpanProcessor({
|
|
89350
|
+
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
89351
|
+
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
89352
|
+
baseUrl: process.env.LANGFUSE_BASE_URL || "https://cloud.langfuse.com",
|
|
89353
|
+
release: process.env.LANGFUSE_RELEASE || "use-ai"
|
|
89354
|
+
});
|
|
89355
|
+
spanProcessors.push(langfuseSpanProcessor);
|
|
89356
|
+
}
|
|
89357
|
+
spanProcessors.push(...customProcessors);
|
|
89358
|
+
const sdk = new NodeSDK({ spanProcessors });
|
|
89336
89359
|
sdk.start();
|
|
89337
|
-
|
|
89338
|
-
|
|
89339
|
-
|
|
89340
|
-
|
|
89341
|
-
|
|
89342
|
-
|
|
89343
|
-
await langfuseClient.flushAsync();
|
|
89344
|
-
}
|
|
89345
|
-
};
|
|
89360
|
+
_tracingEnabled = true;
|
|
89361
|
+
_spanProcessors = spanProcessors;
|
|
89362
|
+
logger2.info("OpenTelemetry tracing started", {
|
|
89363
|
+
langfuseEnabled: langfuse.enabled,
|
|
89364
|
+
customProcessorCount: customProcessors.length
|
|
89365
|
+
});
|
|
89346
89366
|
} catch (error) {
|
|
89347
|
-
logger2.warn("Failed to
|
|
89367
|
+
logger2.warn("Failed to start OpenTelemetry tracing. Install @opentelemetry/sdk-node for tracing.", {
|
|
89348
89368
|
error: error instanceof Error ? error.message : "Unknown error"
|
|
89349
89369
|
});
|
|
89350
|
-
return {
|
|
89351
|
-
enabled: true,
|
|
89352
|
-
client: langfuseClient,
|
|
89353
|
-
flush: async () => {
|
|
89354
|
-
await langfuseClient.flushAsync();
|
|
89355
|
-
}
|
|
89356
|
-
};
|
|
89357
89370
|
}
|
|
89358
89371
|
}
|
|
89372
|
+
function _initializeLangfuse() {
|
|
89373
|
+
const enabled = Boolean(process.env.LANGFUSE_PUBLIC_KEY && process.env.LANGFUSE_SECRET_KEY);
|
|
89374
|
+
if (!enabled) {
|
|
89375
|
+
return { enabled: false };
|
|
89376
|
+
}
|
|
89377
|
+
const baseUrl = process.env.LANGFUSE_BASE_URL || "https://cloud.langfuse.com";
|
|
89378
|
+
const release = process.env.LANGFUSE_RELEASE || "use-ai";
|
|
89379
|
+
const client = new Langfuse({
|
|
89380
|
+
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
|
89381
|
+
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
89382
|
+
baseUrl,
|
|
89383
|
+
release
|
|
89384
|
+
});
|
|
89385
|
+
return {
|
|
89386
|
+
enabled: true,
|
|
89387
|
+
client
|
|
89388
|
+
};
|
|
89389
|
+
}
|
|
89390
|
+
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/native.js
|
|
89391
|
+
import { randomUUID } from "crypto";
|
|
89392
|
+
var native_default = { randomUUID };
|
|
89393
|
+
|
|
89394
|
+
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/rng.js
|
|
89395
|
+
import { randomFillSync } from "crypto";
|
|
89396
|
+
var rnds8Pool = new Uint8Array(256);
|
|
89397
|
+
var poolPtr = rnds8Pool.length;
|
|
89398
|
+
function rng() {
|
|
89399
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
89400
|
+
randomFillSync(rnds8Pool);
|
|
89401
|
+
poolPtr = 0;
|
|
89402
|
+
}
|
|
89403
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
89404
|
+
}
|
|
89359
89405
|
|
|
89406
|
+
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/stringify.js
|
|
89407
|
+
var byteToHex = [];
|
|
89408
|
+
for (let i = 0;i < 256; ++i) {
|
|
89409
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
89410
|
+
}
|
|
89411
|
+
function unsafeStringify(arr, offset = 0) {
|
|
89412
|
+
return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
|
|
89413
|
+
}
|
|
89414
|
+
|
|
89415
|
+
// ../../node_modules/.bun/uuid@11.1.0/node_modules/uuid/dist/esm/v4.js
|
|
89416
|
+
function v4(options, buf, offset) {
|
|
89417
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
89418
|
+
return native_default.randomUUID();
|
|
89419
|
+
}
|
|
89420
|
+
options = options || {};
|
|
89421
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
89422
|
+
if (rnds.length < 16) {
|
|
89423
|
+
throw new Error("Random bytes length must be >= 16");
|
|
89424
|
+
}
|
|
89425
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
89426
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
89427
|
+
if (buf) {
|
|
89428
|
+
offset = offset || 0;
|
|
89429
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
89430
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
89431
|
+
}
|
|
89432
|
+
for (let i = 0;i < 16; ++i) {
|
|
89433
|
+
buf[offset + i] = rnds[i];
|
|
89434
|
+
}
|
|
89435
|
+
return buf;
|
|
89436
|
+
}
|
|
89437
|
+
return unsafeStringify(rnds);
|
|
89438
|
+
}
|
|
89439
|
+
var v4_default = v4;
|
|
89360
89440
|
// src/plugins/FeedbackPlugin.ts
|
|
89361
89441
|
class FeedbackPlugin {
|
|
89362
89442
|
langfuseClient = null;
|
|
@@ -89446,6 +89526,30 @@ function findMatch(str, patternMap) {
|
|
|
89446
89526
|
return;
|
|
89447
89527
|
}
|
|
89448
89528
|
|
|
89529
|
+
// src/utils/toolFilters.ts
|
|
89530
|
+
function isRemoteTool(tool) {
|
|
89531
|
+
return tool._remote !== undefined;
|
|
89532
|
+
}
|
|
89533
|
+
function isServerTool(tool) {
|
|
89534
|
+
return tool._server !== undefined;
|
|
89535
|
+
}
|
|
89536
|
+
function and(...filters) {
|
|
89537
|
+
return (tool) => filters.every((f) => f(tool));
|
|
89538
|
+
}
|
|
89539
|
+
function or(...filters) {
|
|
89540
|
+
return (tool) => filters.some((f) => f(tool));
|
|
89541
|
+
}
|
|
89542
|
+
function not(filter) {
|
|
89543
|
+
return (tool) => !filter(tool);
|
|
89544
|
+
}
|
|
89545
|
+
function createGlobFilter(patterns) {
|
|
89546
|
+
return (tool) => {
|
|
89547
|
+
if (patterns.length === 0)
|
|
89548
|
+
return false;
|
|
89549
|
+
return patterns.some((pattern) => matchesPattern(tool.name, pattern));
|
|
89550
|
+
};
|
|
89551
|
+
}
|
|
89552
|
+
|
|
89449
89553
|
// src/mcp/RemoteMcpToolsProvider.ts
|
|
89450
89554
|
class RemoteMcpToolsProvider {
|
|
89451
89555
|
url;
|
|
@@ -89680,8 +89784,10 @@ class UseAIServer {
|
|
|
89680
89784
|
plugins = [];
|
|
89681
89785
|
messageHandlers = new Map;
|
|
89682
89786
|
mcpEndpoints = [];
|
|
89787
|
+
serverTools = [];
|
|
89683
89788
|
clientIpTracker;
|
|
89684
89789
|
constructor(config) {
|
|
89790
|
+
startTracing(config.spanProcessors);
|
|
89685
89791
|
this.config = {
|
|
89686
89792
|
port: config.port ?? 8081,
|
|
89687
89793
|
rateLimitMaxRequests: config.rateLimitMaxRequests ?? 0,
|
|
@@ -89712,6 +89818,21 @@ class UseAIServer {
|
|
|
89712
89818
|
endpoints: this.mcpEndpoints.map((e) => e.getUrl())
|
|
89713
89819
|
});
|
|
89714
89820
|
}
|
|
89821
|
+
if (config.tools) {
|
|
89822
|
+
this.serverTools = Object.entries(config.tools).map(([name, toolConfig]) => ({
|
|
89823
|
+
name,
|
|
89824
|
+
description: toolConfig.description,
|
|
89825
|
+
parameters: toolConfig.parameters,
|
|
89826
|
+
annotations: toolConfig.annotations,
|
|
89827
|
+
_server: {
|
|
89828
|
+
execute: toolConfig.execute
|
|
89829
|
+
}
|
|
89830
|
+
}));
|
|
89831
|
+
logger2.info("[Server Tools] Registered server tools", {
|
|
89832
|
+
count: this.serverTools.length,
|
|
89833
|
+
names: this.serverTools.map((t) => t.name)
|
|
89834
|
+
});
|
|
89835
|
+
}
|
|
89715
89836
|
this.plugins = config.plugins ?? [];
|
|
89716
89837
|
this.initializePlugins();
|
|
89717
89838
|
this.runtimeAdapter = createRuntimeAdapter(config.runtime ?? "auto");
|
|
@@ -89812,6 +89933,19 @@ class UseAIServer {
|
|
|
89812
89933
|
error: error instanceof Error ? error.message : "Unknown error",
|
|
89813
89934
|
clientId
|
|
89814
89935
|
});
|
|
89936
|
+
if (message.type === "run_agent") {
|
|
89937
|
+
const runAgentData = message.data;
|
|
89938
|
+
const unhandledForwardedProps = runAgentData?.forwardedProps;
|
|
89939
|
+
recordErrorTrace({
|
|
89940
|
+
runId: runAgentData?.runId || socket.id,
|
|
89941
|
+
errorCategory: "unhandled_error",
|
|
89942
|
+
errorMessage: error instanceof Error ? error.message : "Unknown error",
|
|
89943
|
+
sessionId: clientId,
|
|
89944
|
+
threadId: runAgentData?.threadId,
|
|
89945
|
+
ipAddress: session?.ipAddress,
|
|
89946
|
+
metadata: { ...unhandledForwardedProps?.telemetryMetadata }
|
|
89947
|
+
});
|
|
89948
|
+
}
|
|
89815
89949
|
this.sendEvent(socket, {
|
|
89816
89950
|
type: export_EventType.RUN_ERROR,
|
|
89817
89951
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
@@ -89821,6 +89955,7 @@ class UseAIServer {
|
|
|
89821
89955
|
});
|
|
89822
89956
|
socket.on("disconnect", () => {
|
|
89823
89957
|
logger2.info("Client disconnected", { clientId, ipAddress });
|
|
89958
|
+
session.abortController?.abort();
|
|
89824
89959
|
this.clientIpTracker.removePollingConnection(conn.id);
|
|
89825
89960
|
for (const plugin of this.plugins) {
|
|
89826
89961
|
plugin.onClientDisconnect?.(session);
|
|
@@ -89857,7 +89992,8 @@ class UseAIServer {
|
|
|
89857
89992
|
}
|
|
89858
89993
|
}
|
|
89859
89994
|
async handleRunAgent(session, message) {
|
|
89860
|
-
const { threadId, runId, messages, tools, state, context, forwardedProps } = message.data;
|
|
89995
|
+
const { threadId, runId, messages, tools, state, context, forwardedProps: rawForwardedProps } = message.data;
|
|
89996
|
+
const forwardedProps = rawForwardedProps;
|
|
89861
89997
|
const mcpHeaders = forwardedProps?.mcpHeaders;
|
|
89862
89998
|
const requestedAgent = forwardedProps?.agent;
|
|
89863
89999
|
let selectedAgent = this.agent;
|
|
@@ -89872,6 +90008,15 @@ class UseAIServer {
|
|
|
89872
90008
|
requested: requestedAgent,
|
|
89873
90009
|
available: availableAgents
|
|
89874
90010
|
});
|
|
90011
|
+
recordErrorTrace({
|
|
90012
|
+
runId,
|
|
90013
|
+
errorCategory: "agent_not_found",
|
|
90014
|
+
errorMessage: `Agent "${requestedAgent}" not found`,
|
|
90015
|
+
sessionId: session.clientId,
|
|
90016
|
+
threadId,
|
|
90017
|
+
ipAddress: session.ipAddress,
|
|
90018
|
+
metadata: { requestedAgent, availableAgents, ...forwardedProps?.telemetryMetadata }
|
|
90019
|
+
});
|
|
89875
90020
|
this.sendEvent(session.socket, {
|
|
89876
90021
|
type: export_EventType.RUN_ERROR,
|
|
89877
90022
|
message: `Agent "${requestedAgent}" not found. Available agents: ${availableAgents.join(", ")}`,
|
|
@@ -89883,6 +90028,15 @@ class UseAIServer {
|
|
|
89883
90028
|
const rateLimitCheck = this.rateLimiter.checkLimit(session.ipAddress);
|
|
89884
90029
|
if (!rateLimitCheck.allowed) {
|
|
89885
90030
|
const retryAfterSeconds = Math.ceil((rateLimitCheck.retryAfterMs || 0) / 1000);
|
|
90031
|
+
recordErrorTrace({
|
|
90032
|
+
runId,
|
|
90033
|
+
errorCategory: "rate_limit_exceeded",
|
|
90034
|
+
errorMessage: "Rate limit exceeded",
|
|
90035
|
+
sessionId: session.clientId,
|
|
90036
|
+
threadId,
|
|
90037
|
+
ipAddress: session.ipAddress,
|
|
90038
|
+
metadata: { retryAfterSeconds, ...forwardedProps?.telemetryMetadata }
|
|
90039
|
+
});
|
|
89886
90040
|
this.sendEvent(session.socket, {
|
|
89887
90041
|
type: export_EventType.RUN_ERROR,
|
|
89888
90042
|
message: `Rate limit exceeded. Please try again in ${retryAfterSeconds} seconds.`,
|
|
@@ -89899,6 +90053,7 @@ class UseAIServer {
|
|
|
89899
90053
|
}
|
|
89900
90054
|
session.threadId = threadId;
|
|
89901
90055
|
session.currentRunId = runId;
|
|
90056
|
+
session.abortController = new AbortController;
|
|
89902
90057
|
session.currentMcpHeaders = mcpHeaders;
|
|
89903
90058
|
const clientTools = tools.map((t) => ({
|
|
89904
90059
|
...t,
|
|
@@ -89908,11 +90063,12 @@ class UseAIServer {
|
|
|
89908
90063
|
if (this.mcpEndpoints.length > 0) {
|
|
89909
90064
|
mcpTools = await this.getMcpToolsForSession(session, mcpHeaders);
|
|
89910
90065
|
}
|
|
89911
|
-
session.tools = [...clientTools, ...mcpTools];
|
|
89912
|
-
if (mcpTools.length > 0) {
|
|
89913
|
-
logger2.debug("
|
|
90066
|
+
session.tools = [...clientTools, ...mcpTools, ...this.serverTools];
|
|
90067
|
+
if (mcpTools.length > 0 || this.serverTools.length > 0) {
|
|
90068
|
+
logger2.debug("Merged tools", {
|
|
89914
90069
|
clientTools: clientTools.length,
|
|
89915
90070
|
mcpTools: mcpTools.length,
|
|
90071
|
+
serverTools: this.serverTools.length,
|
|
89916
90072
|
total: session.tools.length
|
|
89917
90073
|
});
|
|
89918
90074
|
}
|
|
@@ -90038,19 +90194,37 @@ ${block.text}`
|
|
|
90038
90194
|
}
|
|
90039
90195
|
}
|
|
90040
90196
|
buildSystemPrompt(session, state) {
|
|
90041
|
-
|
|
90042
|
-
|
|
90043
|
-
|
|
90044
|
-
parts.push("");
|
|
90045
|
-
parts.push(JSON.stringify(state, null, 2));
|
|
90046
|
-
parts.push("");
|
|
90047
|
-
parts.push("Use the available tools to interact with and modify the UI based on user requests.");
|
|
90048
|
-
}
|
|
90049
|
-
return parts.length > 0 ? parts.join(`
|
|
90050
|
-
`) : undefined;
|
|
90197
|
+
if (!state)
|
|
90198
|
+
return;
|
|
90199
|
+
return "You are interacting with a web application. Use the available tools to interact with and modify the UI based on user requests.";
|
|
90051
90200
|
}
|
|
90052
90201
|
handleToolResult(session, message) {
|
|
90053
|
-
const { toolCallId, content } = message.data;
|
|
90202
|
+
const { toolCallId, content, forwardedProps } = message.data;
|
|
90203
|
+
const tools = forwardedProps?.tools;
|
|
90204
|
+
const state = forwardedProps?.state;
|
|
90205
|
+
if (tools && tools.length > 0) {
|
|
90206
|
+
const existingRemoteTools = session.tools.filter(isRemoteTool);
|
|
90207
|
+
const existingServerTools = session.tools.filter(isServerTool);
|
|
90208
|
+
const updatedClientTools = tools.map((t) => ({
|
|
90209
|
+
...t,
|
|
90210
|
+
parameters: t.parameters || { type: "object", properties: {}, required: [] }
|
|
90211
|
+
}));
|
|
90212
|
+
session.tools = [...updatedClientTools, ...existingRemoteTools, ...existingServerTools];
|
|
90213
|
+
logger2.debug("Tools updated mid-run", {
|
|
90214
|
+
clientId: session.clientId,
|
|
90215
|
+
toolCount: session.tools.length,
|
|
90216
|
+
clientToolCount: updatedClientTools.length,
|
|
90217
|
+
mcpToolCount: existingRemoteTools.length,
|
|
90218
|
+
serverToolCount: existingServerTools.length,
|
|
90219
|
+
toolNames: session.tools.map((t) => t.name)
|
|
90220
|
+
});
|
|
90221
|
+
}
|
|
90222
|
+
if (state !== undefined) {
|
|
90223
|
+
session.state = state;
|
|
90224
|
+
logger2.debug("State updated mid-run", {
|
|
90225
|
+
clientId: session.clientId
|
|
90226
|
+
});
|
|
90227
|
+
}
|
|
90054
90228
|
const resolver = session.pendingToolCalls.get(toolCallId);
|
|
90055
90229
|
if (resolver) {
|
|
90056
90230
|
resolver(content);
|
|
@@ -90078,6 +90252,7 @@ ${block.text}`
|
|
|
90078
90252
|
}
|
|
90079
90253
|
handleAbortRun(session, message) {
|
|
90080
90254
|
const { runId } = message.data;
|
|
90255
|
+
session.abortController?.abort();
|
|
90081
90256
|
session.pendingToolCalls.clear();
|
|
90082
90257
|
session.pendingToolApprovals.clear();
|
|
90083
90258
|
session.currentRunId = undefined;
|
|
@@ -90170,6 +90345,7 @@ ${block.text}`
|
|
|
90170
90345
|
async close() {
|
|
90171
90346
|
clearInterval(this.cleanupInterval);
|
|
90172
90347
|
this.mcpEndpoints.forEach((endpoint) => endpoint.destroy());
|
|
90348
|
+
await Promise.all(Object.values(this.agents).map((agent) => agent.flushTelemetry?.()));
|
|
90173
90349
|
await Promise.all(this.plugins.map((plugin) => plugin.close?.()));
|
|
90174
90350
|
this.io.close();
|
|
90175
90351
|
if (this.serverHandle) {
|
|
@@ -113488,34 +113664,112 @@ var marker142 = `vercel.ai.error.${name142}`;
|
|
|
113488
113664
|
var symbol142 = Symbol.for(marker142);
|
|
113489
113665
|
var _a142;
|
|
113490
113666
|
_a142 = symbol142;
|
|
113667
|
+
|
|
113668
|
+
// src/telemetry.ts
|
|
113669
|
+
var import_api4 = __toESM(require_src2(), 1);
|
|
113670
|
+
function startRunSpan(config2) {
|
|
113671
|
+
const { runId, sessionId } = config2;
|
|
113672
|
+
if (!langfuse.enabled && !isTracingEnabled()) {
|
|
113673
|
+
return {
|
|
113674
|
+
active: false,
|
|
113675
|
+
wrap: (fn) => fn(),
|
|
113676
|
+
setInput: () => {},
|
|
113677
|
+
setOutput: () => {},
|
|
113678
|
+
end: () => {
|
|
113679
|
+
popTraceIdForRun(runId);
|
|
113680
|
+
},
|
|
113681
|
+
endWithError: () => {
|
|
113682
|
+
popTraceIdForRun(runId);
|
|
113683
|
+
},
|
|
113684
|
+
popTraceId: () => popTraceIdForRun(runId),
|
|
113685
|
+
recordError: () => {}
|
|
113686
|
+
};
|
|
113687
|
+
}
|
|
113688
|
+
const parentSpan = import_api4.trace.getTracer("use-ai").startSpan("use-ai.agent.run", {
|
|
113689
|
+
attributes: {
|
|
113690
|
+
"ai.telemetry.functionId": "use-ai",
|
|
113691
|
+
"ai.telemetry.metadata.runId": runId,
|
|
113692
|
+
"ai.telemetry.metadata.sessionId": sessionId,
|
|
113693
|
+
...config2.attributes
|
|
113694
|
+
}
|
|
113695
|
+
});
|
|
113696
|
+
const parentOtelContext = import_api4.trace.setSpan(import_api4.context.active(), parentSpan);
|
|
113697
|
+
return {
|
|
113698
|
+
active: true,
|
|
113699
|
+
wrap(fn) {
|
|
113700
|
+
return import_api4.context.with(parentOtelContext, fn);
|
|
113701
|
+
},
|
|
113702
|
+
setInput(value) {
|
|
113703
|
+
parentSpan.setAttribute("langfuse.observation.input", typeof value === "string" ? value : JSON.stringify(value));
|
|
113704
|
+
},
|
|
113705
|
+
setOutput(value) {
|
|
113706
|
+
parentSpan.setAttribute("langfuse.observation.output", typeof value === "string" ? value : JSON.stringify(value));
|
|
113707
|
+
},
|
|
113708
|
+
end() {
|
|
113709
|
+
parentSpan.setStatus({ code: import_api4.SpanStatusCode.OK });
|
|
113710
|
+
parentSpan.end();
|
|
113711
|
+
popTraceIdForRun(runId);
|
|
113712
|
+
},
|
|
113713
|
+
endWithError(message) {
|
|
113714
|
+
parentSpan.setStatus({ code: import_api4.SpanStatusCode.ERROR, message });
|
|
113715
|
+
parentSpan.end();
|
|
113716
|
+
popTraceIdForRun(runId);
|
|
113717
|
+
},
|
|
113718
|
+
popTraceId() {
|
|
113719
|
+
return popTraceIdForRun(runId);
|
|
113720
|
+
},
|
|
113721
|
+
recordError(params) {
|
|
113722
|
+
recordErrorTrace(params);
|
|
113723
|
+
}
|
|
113724
|
+
};
|
|
113725
|
+
}
|
|
113726
|
+
async function flushTelemetry() {
|
|
113727
|
+
await flushTracing();
|
|
113728
|
+
await langfuse.client?.flushAsync();
|
|
113729
|
+
}
|
|
113491
113730
|
// src/utils/toolConverter.ts
|
|
113492
113731
|
function createClientToolExecutor(session) {
|
|
113493
113732
|
return async (args, { toolCallId }) => {
|
|
113494
|
-
const result = await new Promise((resolve2) => {
|
|
113733
|
+
const result = await new Promise((resolve2, reject) => {
|
|
113734
|
+
if (session.abortController?.signal.aborted) {
|
|
113735
|
+
reject(new Error("Run aborted"));
|
|
113736
|
+
return;
|
|
113737
|
+
}
|
|
113495
113738
|
session.pendingToolCalls.set(toolCallId, resolve2);
|
|
113739
|
+
session.abortController?.signal.addEventListener("abort", () => {
|
|
113740
|
+
session.pendingToolCalls.delete(toolCallId);
|
|
113741
|
+
reject(new Error("Run aborted"));
|
|
113742
|
+
}, { once: true });
|
|
113496
113743
|
});
|
|
113497
113744
|
return JSON.parse(result);
|
|
113498
113745
|
};
|
|
113499
113746
|
}
|
|
113500
113747
|
|
|
113501
|
-
// src/
|
|
113502
|
-
function
|
|
113503
|
-
return
|
|
113504
|
-
|
|
113505
|
-
|
|
113506
|
-
|
|
113507
|
-
}
|
|
113508
|
-
|
|
113509
|
-
|
|
113510
|
-
|
|
113511
|
-
|
|
113512
|
-
|
|
113513
|
-
}
|
|
113514
|
-
|
|
113515
|
-
|
|
113516
|
-
|
|
113517
|
-
|
|
113518
|
-
|
|
113748
|
+
// src/tools/serverToolExecutor.ts
|
|
113749
|
+
function createServerToolExecutor(serverTool, session) {
|
|
113750
|
+
return async (args, { toolCallId }) => {
|
|
113751
|
+
logger2.info("[Server Tool] Executing", {
|
|
113752
|
+
toolName: serverTool.name,
|
|
113753
|
+
toolCallId
|
|
113754
|
+
});
|
|
113755
|
+
const context = {
|
|
113756
|
+
session,
|
|
113757
|
+
state: session.state,
|
|
113758
|
+
runId: session.currentRunId || "",
|
|
113759
|
+
toolCallId
|
|
113760
|
+
};
|
|
113761
|
+
try {
|
|
113762
|
+
const result = await serverTool._server.execute(args, context);
|
|
113763
|
+
return result;
|
|
113764
|
+
} catch (error40) {
|
|
113765
|
+
const errorMsg = error40 instanceof Error ? error40.message : String(error40);
|
|
113766
|
+
logger2.error("[Server Tool] Execution failed", {
|
|
113767
|
+
toolName: serverTool.name,
|
|
113768
|
+
toolCallId,
|
|
113769
|
+
error: errorMsg
|
|
113770
|
+
});
|
|
113771
|
+
throw error40;
|
|
113772
|
+
}
|
|
113519
113773
|
};
|
|
113520
113774
|
}
|
|
113521
113775
|
|
|
@@ -113584,8 +113838,16 @@ function toolNeedsApproval(toolDef) {
|
|
|
113584
113838
|
return annotations?.destructiveHint === true;
|
|
113585
113839
|
}
|
|
113586
113840
|
function waitForApproval(session, toolCallId) {
|
|
113587
|
-
return new Promise((resolve2) => {
|
|
113841
|
+
return new Promise((resolve2, reject) => {
|
|
113842
|
+
if (session.abortController?.signal.aborted) {
|
|
113843
|
+
reject(new Error("Run aborted"));
|
|
113844
|
+
return;
|
|
113845
|
+
}
|
|
113588
113846
|
session.pendingToolApprovals.set(toolCallId, resolve2);
|
|
113847
|
+
session.abortController?.signal.addEventListener("abort", () => {
|
|
113848
|
+
session.pendingToolApprovals.delete(toolCallId);
|
|
113849
|
+
reject(new Error("Run aborted"));
|
|
113850
|
+
}, { once: true });
|
|
113589
113851
|
});
|
|
113590
113852
|
}
|
|
113591
113853
|
function createApprovalWrapper(toolDef, session, events, actualExecutor) {
|
|
@@ -113622,16 +113884,18 @@ function createApprovalWrapper(toolDef, session, events, actualExecutor) {
|
|
|
113622
113884
|
|
|
113623
113885
|
// src/agents/AISDKAgent.ts
|
|
113624
113886
|
var DEFAULT_MAX_OUTPUT_TOKENS = 4096;
|
|
113887
|
+
var DEFAULT_MAX_STEPS = 10;
|
|
113625
113888
|
|
|
113626
113889
|
class AISDKAgent {
|
|
113627
113890
|
model;
|
|
113628
113891
|
name;
|
|
113629
113892
|
annotation;
|
|
113630
|
-
langfuse;
|
|
113631
113893
|
toolFilter;
|
|
113632
113894
|
systemPrompt;
|
|
113633
113895
|
cacheBreakpoint;
|
|
113634
113896
|
maxOutputTokens;
|
|
113897
|
+
temperature;
|
|
113898
|
+
maxSteps;
|
|
113635
113899
|
constructor(config2) {
|
|
113636
113900
|
this.model = config2.model;
|
|
113637
113901
|
this.name = config2.name || "ai-sdk";
|
|
@@ -113640,7 +113904,8 @@ class AISDKAgent {
|
|
|
113640
113904
|
this.systemPrompt = config2.systemPrompt;
|
|
113641
113905
|
this.cacheBreakpoint = config2.cacheBreakpoint;
|
|
113642
113906
|
this.maxOutputTokens = config2.maxOutputTokens ?? DEFAULT_MAX_OUTPUT_TOKENS;
|
|
113643
|
-
this.
|
|
113907
|
+
this.temperature = config2.temperature;
|
|
113908
|
+
this.maxSteps = config2.maxSteps ?? DEFAULT_MAX_STEPS;
|
|
113644
113909
|
}
|
|
113645
113910
|
getName() {
|
|
113646
113911
|
return this.name;
|
|
@@ -113649,14 +113914,15 @@ class AISDKAgent {
|
|
|
113649
113914
|
return this.annotation;
|
|
113650
113915
|
}
|
|
113651
113916
|
async flushTelemetry() {
|
|
113652
|
-
|
|
113653
|
-
await this.langfuse.flush();
|
|
113654
|
-
}
|
|
113917
|
+
await flushTelemetry();
|
|
113655
113918
|
}
|
|
113656
113919
|
async run(input, events) {
|
|
113657
113920
|
const { session, runId, messages, tools, state, systemPrompt: runtimeSystemPrompt, originalInput } = input;
|
|
113921
|
+
if (session.tools.length === 0 && tools.length > 0) {
|
|
113922
|
+
session.tools = tools;
|
|
113923
|
+
}
|
|
113658
113924
|
const configSystemPrompt = await this.resolveSystemPrompt();
|
|
113659
|
-
const
|
|
113925
|
+
const staticSystemMessages = this.buildStaticSystemMessages(configSystemPrompt, runtimeSystemPrompt);
|
|
113660
113926
|
events.emit({
|
|
113661
113927
|
type: export_EventType.RUN_STARTED,
|
|
113662
113928
|
threadId: session.threadId,
|
|
@@ -113674,6 +113940,12 @@ class AISDKAgent {
|
|
|
113674
113940
|
snapshot: state,
|
|
113675
113941
|
timestamp: Date.now()
|
|
113676
113942
|
});
|
|
113943
|
+
let streamTextStarted = false;
|
|
113944
|
+
const span = startRunSpan({ runId, sessionId: session.clientId });
|
|
113945
|
+
const lastUserMessage = [...messages].reverse().find((m) => m.role === "user");
|
|
113946
|
+
if (lastUserMessage) {
|
|
113947
|
+
span.setInput(lastUserMessage.content);
|
|
113948
|
+
}
|
|
113677
113949
|
try {
|
|
113678
113950
|
logger2.info("Sending to AI SDK model (streaming)", {
|
|
113679
113951
|
clientId: session.clientId,
|
|
@@ -113681,10 +113953,7 @@ class AISDKAgent {
|
|
|
113681
113953
|
toolCount: tools.length
|
|
113682
113954
|
});
|
|
113683
113955
|
const sanitizedInputMessages = this.sanitizeMessages(messages);
|
|
113684
|
-
|
|
113685
|
-
...systemMessages || [],
|
|
113686
|
-
...sanitizedInputMessages
|
|
113687
|
-
];
|
|
113956
|
+
let currentMessages = [...sanitizedInputMessages];
|
|
113688
113957
|
logger2.apiRequest({
|
|
113689
113958
|
tools: tools.map((t) => t.name),
|
|
113690
113959
|
messageCount: messages.length,
|
|
@@ -113692,146 +113961,187 @@ class AISDKAgent {
|
|
|
113692
113961
|
role: msg.role,
|
|
113693
113962
|
preview: typeof msg.content === "string" ? msg.content.substring(0, 80) + (msg.content.length > 80 ? "..." : "") : Array.isArray(msg.content) ? `${msg.content.length} content blocks` : "complex content"
|
|
113694
113963
|
})),
|
|
113695
|
-
systemMessages:
|
|
113696
|
-
});
|
|
113697
|
-
const messagesWithCache = applyCacheBreakpoints(messagesWithSystem, this.cacheBreakpoint, this.model);
|
|
113698
|
-
const stream = streamText({
|
|
113699
|
-
model: this.model,
|
|
113700
|
-
messages: messagesWithCache,
|
|
113701
|
-
tools: tools.length > 0 ? this.sanitizeToolsForAPI(this.filterTools(tools), session, events) : undefined,
|
|
113702
|
-
stopWhen: stepCountIs(10),
|
|
113703
|
-
maxOutputTokens: this.maxOutputTokens,
|
|
113704
|
-
abortSignal: session.abortController?.signal,
|
|
113705
|
-
experimental_telemetry: this.langfuse?.enabled ? {
|
|
113706
|
-
isEnabled: true,
|
|
113707
|
-
functionId: "use-ai",
|
|
113708
|
-
metadata: {
|
|
113709
|
-
sessionId: session.clientId,
|
|
113710
|
-
threadId: session.threadId,
|
|
113711
|
-
runId,
|
|
113712
|
-
ipAddress: session.ipAddress,
|
|
113713
|
-
toolCount: tools.length
|
|
113714
|
-
}
|
|
113715
|
-
} : undefined,
|
|
113716
|
-
onStepFinish: ({ usage, finishReason }) => {
|
|
113717
|
-
logger2.debug("Step finished", { usage, finishReason });
|
|
113718
|
-
}
|
|
113964
|
+
systemMessages: staticSystemMessages?.map((m) => m.content.substring(0, 80) + (m.content.length > 80 ? "..." : ""))
|
|
113719
113965
|
});
|
|
113720
113966
|
let messageId = null;
|
|
113721
113967
|
let hasEmittedTextStart = false;
|
|
113722
113968
|
let finalText = "";
|
|
113723
113969
|
let currentStepNumber = 0;
|
|
113724
113970
|
let hasAnyContent = false;
|
|
113725
|
-
|
|
113726
|
-
|
|
113727
|
-
|
|
113728
|
-
|
|
113729
|
-
|
|
113730
|
-
|
|
113731
|
-
|
|
113732
|
-
|
|
113733
|
-
|
|
113734
|
-
|
|
113971
|
+
let response = null;
|
|
113972
|
+
const allResponseMessages = [];
|
|
113973
|
+
for (let stepIteration = 0;stepIteration < this.maxSteps; stepIteration++) {
|
|
113974
|
+
const currentTools = session.tools;
|
|
113975
|
+
logger2.debug("Starting step iteration", {
|
|
113976
|
+
stepIteration,
|
|
113977
|
+
toolCount: currentTools.length,
|
|
113978
|
+
toolNames: currentTools.map((t) => t.name)
|
|
113979
|
+
});
|
|
113980
|
+
const stateMessage = this.buildStateMessage(session.state);
|
|
113981
|
+
const messagesForStep = [
|
|
113982
|
+
...staticSystemMessages || [],
|
|
113983
|
+
...stateMessage ? [stateMessage] : [],
|
|
113984
|
+
...currentMessages
|
|
113985
|
+
];
|
|
113986
|
+
const messagesWithCache = applyCacheBreakpoints(messagesForStep, this.cacheBreakpoint, this.model);
|
|
113987
|
+
streamTextStarted = true;
|
|
113988
|
+
const createStream = () => streamText({
|
|
113989
|
+
model: this.model,
|
|
113990
|
+
messages: messagesWithCache,
|
|
113991
|
+
tools: currentTools.length > 0 ? this.sanitizeToolsForAPI(this.filterTools(currentTools), session, events) : undefined,
|
|
113992
|
+
stopWhen: stepCountIs(1),
|
|
113993
|
+
maxOutputTokens: this.maxOutputTokens,
|
|
113994
|
+
temperature: this.temperature,
|
|
113995
|
+
abortSignal: session.abortController?.signal,
|
|
113996
|
+
experimental_telemetry: span.active ? {
|
|
113997
|
+
isEnabled: true,
|
|
113998
|
+
functionId: "use-ai",
|
|
113999
|
+
metadata: {
|
|
114000
|
+
sessionId: session.clientId,
|
|
114001
|
+
threadId: session.threadId,
|
|
114002
|
+
runId,
|
|
114003
|
+
ipAddress: session.ipAddress,
|
|
114004
|
+
toolCount: currentTools.length,
|
|
114005
|
+
stepIteration,
|
|
114006
|
+
...originalInput.forwardedProps?.telemetryMetadata || {}
|
|
114007
|
+
}
|
|
114008
|
+
} : undefined,
|
|
114009
|
+
onStepFinish: ({ usage, finishReason }) => {
|
|
114010
|
+
logger2.debug("Step finished", { usage, finishReason, stepIteration });
|
|
113735
114011
|
}
|
|
113736
|
-
|
|
113737
|
-
|
|
113738
|
-
|
|
113739
|
-
|
|
114012
|
+
});
|
|
114013
|
+
const stream = span.wrap(createStream);
|
|
114014
|
+
const activeToolCalls = new Map;
|
|
114015
|
+
let stepHadToolCalls = false;
|
|
114016
|
+
for await (const chunk of stream.fullStream) {
|
|
114017
|
+
switch (chunk.type) {
|
|
114018
|
+
case "start-step": {
|
|
114019
|
+
events.emit({
|
|
114020
|
+
type: export_EventType.STEP_STARTED,
|
|
114021
|
+
stepName: `step-${currentStepNumber++}`,
|
|
114022
|
+
timestamp: Date.now()
|
|
114023
|
+
});
|
|
114024
|
+
break;
|
|
114025
|
+
}
|
|
114026
|
+
case "text-delta": {
|
|
114027
|
+
hasAnyContent = true;
|
|
114028
|
+
if (!hasEmittedTextStart) {
|
|
114029
|
+
messageId = v4_default();
|
|
114030
|
+
events.emit({
|
|
114031
|
+
type: export_EventType.TEXT_MESSAGE_START,
|
|
114032
|
+
messageId,
|
|
114033
|
+
role: "assistant",
|
|
114034
|
+
timestamp: Date.now()
|
|
114035
|
+
});
|
|
114036
|
+
hasEmittedTextStart = true;
|
|
114037
|
+
}
|
|
113740
114038
|
events.emit({
|
|
113741
|
-
type: export_EventType.
|
|
114039
|
+
type: export_EventType.TEXT_MESSAGE_CONTENT,
|
|
113742
114040
|
messageId,
|
|
113743
|
-
|
|
114041
|
+
delta: chunk.text,
|
|
113744
114042
|
timestamp: Date.now()
|
|
113745
114043
|
});
|
|
113746
|
-
|
|
114044
|
+
finalText += chunk.text;
|
|
114045
|
+
break;
|
|
113747
114046
|
}
|
|
113748
|
-
|
|
113749
|
-
|
|
113750
|
-
|
|
113751
|
-
delta: chunk.text,
|
|
113752
|
-
timestamp: Date.now()
|
|
113753
|
-
});
|
|
113754
|
-
finalText += chunk.text;
|
|
113755
|
-
break;
|
|
113756
|
-
}
|
|
113757
|
-
case "reasoning-delta": {
|
|
113758
|
-
logger2.debug("Reasoning", { text: chunk.text });
|
|
113759
|
-
break;
|
|
113760
|
-
}
|
|
113761
|
-
case "tool-input-start": {
|
|
113762
|
-
hasAnyContent = true;
|
|
113763
|
-
const toolDef = tools.find((t) => t.name === chunk.toolName);
|
|
113764
|
-
const annotations = getToolAnnotations(toolDef);
|
|
113765
|
-
const toolCallStartEvent = {
|
|
113766
|
-
type: export_EventType.TOOL_CALL_START,
|
|
113767
|
-
toolCallId: chunk.id,
|
|
113768
|
-
toolCallName: chunk.toolName,
|
|
113769
|
-
parentMessageId: messageId ?? v4_default(),
|
|
113770
|
-
timestamp: Date.now()
|
|
113771
|
-
};
|
|
113772
|
-
if (annotations) {
|
|
113773
|
-
toolCallStartEvent.annotations = annotations;
|
|
114047
|
+
case "reasoning-delta": {
|
|
114048
|
+
logger2.debug("Reasoning", { text: chunk.text });
|
|
114049
|
+
break;
|
|
113774
114050
|
}
|
|
113775
|
-
|
|
113776
|
-
|
|
113777
|
-
|
|
113778
|
-
|
|
113779
|
-
|
|
113780
|
-
|
|
113781
|
-
|
|
113782
|
-
toolCall.args += chunk.delta;
|
|
113783
|
-
events.emit({
|
|
113784
|
-
type: export_EventType.TOOL_CALL_ARGS,
|
|
114051
|
+
case "tool-input-start": {
|
|
114052
|
+
hasAnyContent = true;
|
|
114053
|
+
stepHadToolCalls = true;
|
|
114054
|
+
const toolDef = currentTools.find((t) => t.name === chunk.toolName);
|
|
114055
|
+
const annotations = getToolAnnotations(toolDef);
|
|
114056
|
+
const toolCallStartEvent = {
|
|
114057
|
+
type: export_EventType.TOOL_CALL_START,
|
|
113785
114058
|
toolCallId: chunk.id,
|
|
113786
|
-
|
|
114059
|
+
toolCallName: chunk.toolName,
|
|
114060
|
+
parentMessageId: messageId ?? v4_default(),
|
|
113787
114061
|
timestamp: Date.now()
|
|
113788
|
-
}
|
|
114062
|
+
};
|
|
114063
|
+
if (annotations) {
|
|
114064
|
+
toolCallStartEvent.annotations = annotations;
|
|
114065
|
+
}
|
|
114066
|
+
events.emit(toolCallStartEvent);
|
|
114067
|
+
activeToolCalls.set(chunk.id, { name: chunk.toolName, args: "" });
|
|
114068
|
+
break;
|
|
113789
114069
|
}
|
|
113790
|
-
|
|
113791
|
-
|
|
113792
|
-
|
|
113793
|
-
|
|
113794
|
-
|
|
113795
|
-
|
|
114070
|
+
case "tool-input-delta": {
|
|
114071
|
+
const toolCall = activeToolCalls.get(chunk.id);
|
|
114072
|
+
if (toolCall) {
|
|
114073
|
+
toolCall.args += chunk.delta;
|
|
114074
|
+
events.emit({
|
|
114075
|
+
type: export_EventType.TOOL_CALL_ARGS,
|
|
114076
|
+
toolCallId: chunk.id,
|
|
114077
|
+
delta: chunk.delta,
|
|
114078
|
+
timestamp: Date.now()
|
|
114079
|
+
});
|
|
114080
|
+
}
|
|
114081
|
+
break;
|
|
114082
|
+
}
|
|
114083
|
+
case "tool-call": {
|
|
114084
|
+
stepHadToolCalls = true;
|
|
114085
|
+
const toolCall = activeToolCalls.get(chunk.toolCallId);
|
|
114086
|
+
const finalArgs = JSON.stringify(chunk.input);
|
|
114087
|
+
if (toolCall && toolCall.args.length === 0) {
|
|
114088
|
+
events.emit({
|
|
114089
|
+
type: export_EventType.TOOL_CALL_ARGS,
|
|
114090
|
+
toolCallId: chunk.toolCallId,
|
|
114091
|
+
delta: finalArgs,
|
|
114092
|
+
timestamp: Date.now()
|
|
114093
|
+
});
|
|
114094
|
+
toolCall.args = finalArgs;
|
|
114095
|
+
}
|
|
113796
114096
|
events.emit({
|
|
113797
|
-
type: export_EventType.
|
|
114097
|
+
type: export_EventType.TOOL_CALL_END,
|
|
113798
114098
|
toolCallId: chunk.toolCallId,
|
|
113799
|
-
delta: finalArgs,
|
|
113800
114099
|
timestamp: Date.now()
|
|
113801
114100
|
});
|
|
113802
|
-
|
|
114101
|
+
break;
|
|
114102
|
+
}
|
|
114103
|
+
case "tool-result": {
|
|
114104
|
+
logger2.toolResult(chunk.toolName, JSON.stringify(chunk.output));
|
|
114105
|
+
break;
|
|
114106
|
+
}
|
|
114107
|
+
case "finish-step": {
|
|
114108
|
+
events.emit({
|
|
114109
|
+
type: export_EventType.STEP_FINISHED,
|
|
114110
|
+
stepName: `step-${currentStepNumber - 1}`,
|
|
114111
|
+
timestamp: Date.now()
|
|
114112
|
+
});
|
|
114113
|
+
break;
|
|
114114
|
+
}
|
|
114115
|
+
case "error": {
|
|
114116
|
+
throw chunk.error;
|
|
113803
114117
|
}
|
|
113804
|
-
events.emit({
|
|
113805
|
-
type: export_EventType.TOOL_CALL_END,
|
|
113806
|
-
toolCallId: chunk.toolCallId,
|
|
113807
|
-
timestamp: Date.now()
|
|
113808
|
-
});
|
|
113809
|
-
break;
|
|
113810
|
-
}
|
|
113811
|
-
case "tool-result": {
|
|
113812
|
-
logger2.toolResult(chunk.toolName, JSON.stringify(chunk.output));
|
|
113813
|
-
break;
|
|
113814
|
-
}
|
|
113815
|
-
case "finish-step": {
|
|
113816
|
-
events.emit({
|
|
113817
|
-
type: export_EventType.STEP_FINISHED,
|
|
113818
|
-
stepName: `step-${currentStepNumber - 1}`,
|
|
113819
|
-
timestamp: Date.now()
|
|
113820
|
-
});
|
|
113821
|
-
break;
|
|
113822
|
-
}
|
|
113823
|
-
case "error": {
|
|
113824
|
-
throw chunk.error;
|
|
113825
114118
|
}
|
|
113826
114119
|
}
|
|
113827
|
-
|
|
113828
|
-
|
|
113829
|
-
|
|
113830
|
-
|
|
113831
|
-
|
|
113832
|
-
|
|
114120
|
+
if (session.abortController?.signal.aborted) {
|
|
114121
|
+
span.endWithError("Run aborted by user");
|
|
114122
|
+
events.emit({
|
|
114123
|
+
type: export_EventType.RUN_ERROR,
|
|
114124
|
+
message: "Run aborted by user",
|
|
114125
|
+
timestamp: Date.now()
|
|
114126
|
+
});
|
|
114127
|
+
return { success: false, error: "Run aborted", conversationHistory: session.conversationHistory };
|
|
114128
|
+
}
|
|
114129
|
+
response = await stream.response;
|
|
114130
|
+
const stepMessages = this.sanitizeMessages(response.messages);
|
|
114131
|
+
allResponseMessages.push(...stepMessages);
|
|
114132
|
+
if (!stepHadToolCalls) {
|
|
114133
|
+
logger2.debug("Step had no tool calls, finishing run", { stepIteration });
|
|
114134
|
+
break;
|
|
114135
|
+
}
|
|
114136
|
+
currentMessages = [
|
|
114137
|
+
...currentMessages,
|
|
114138
|
+
...stepMessages
|
|
114139
|
+
];
|
|
114140
|
+
logger2.debug("Continuing to next step after tool calls", {
|
|
114141
|
+
stepIteration,
|
|
114142
|
+
newMessageCount: currentMessages.length,
|
|
114143
|
+
updatedToolCount: session.tools.length
|
|
113833
114144
|
});
|
|
113834
|
-
return { success: false, error: "Run aborted", conversationHistory: session.conversationHistory };
|
|
113835
114145
|
}
|
|
113836
114146
|
if (hasEmittedTextStart && messageId) {
|
|
113837
114147
|
events.emit({
|
|
@@ -113841,6 +114151,7 @@ class AISDKAgent {
|
|
|
113841
114151
|
});
|
|
113842
114152
|
}
|
|
113843
114153
|
if (!hasAnyContent) {
|
|
114154
|
+
span.endWithError("Empty response from AI");
|
|
113844
114155
|
events.emit({
|
|
113845
114156
|
type: export_EventType.RUN_ERROR,
|
|
113846
114157
|
message: "AI returned an empty response. This may be due to an ambiguous request. Please try being more specific.",
|
|
@@ -113852,23 +114163,16 @@ class AISDKAgent {
|
|
|
113852
114163
|
conversationHistory: messages
|
|
113853
114164
|
};
|
|
113854
114165
|
}
|
|
113855
|
-
|
|
113856
|
-
|
|
113857
|
-
|
|
113858
|
-
|
|
113859
|
-
let includesInputMessages = false;
|
|
113860
|
-
if (firstResponseMsg && lastInputMsg) {
|
|
113861
|
-
const firstMsg = firstResponseMsg;
|
|
113862
|
-
const lastMsg = lastInputMsg;
|
|
113863
|
-
includesInputMessages = firstMsg.role === "user" && lastMsg.role === "user" && typeof firstMsg.content === "string" && typeof lastMsg.content === "string" && firstMsg.content === lastMsg.content;
|
|
113864
|
-
}
|
|
113865
|
-
const newMessages = includesInputMessages ? responseMessages.slice(session.conversationHistory.length) : responseMessages;
|
|
113866
|
-
const sanitizedMessages = this.sanitizeMessages(newMessages);
|
|
113867
|
-
session.conversationHistory.push(...sanitizedMessages);
|
|
114166
|
+
if (!response) {
|
|
114167
|
+
throw new Error("No response from AI SDK");
|
|
114168
|
+
}
|
|
114169
|
+
session.conversationHistory.push(...allResponseMessages);
|
|
113868
114170
|
if (finalText) {
|
|
113869
114171
|
logger2.aiResponse([finalText]);
|
|
113870
114172
|
}
|
|
113871
|
-
|
|
114173
|
+
span.setOutput(finalText);
|
|
114174
|
+
const traceId = span.popTraceId();
|
|
114175
|
+
span.end();
|
|
113872
114176
|
events.emit({
|
|
113873
114177
|
type: export_EventType.RUN_FINISHED,
|
|
113874
114178
|
threadId: session.threadId,
|
|
@@ -113881,6 +114185,7 @@ class AISDKAgent {
|
|
|
113881
114185
|
conversationHistory: session.conversationHistory
|
|
113882
114186
|
};
|
|
113883
114187
|
} catch (error40) {
|
|
114188
|
+
span.endWithError(error40 instanceof Error ? error40.message : String(error40));
|
|
113884
114189
|
logger2.error("Error calling AI SDK model", {
|
|
113885
114190
|
error: error40 instanceof Error ? error40.message : "Unknown error",
|
|
113886
114191
|
clientId: session.clientId
|
|
@@ -113900,6 +114205,18 @@ class AISDKAgent {
|
|
|
113900
114205
|
errorCode = ErrorCode.RATE_LIMITED;
|
|
113901
114206
|
}
|
|
113902
114207
|
}
|
|
114208
|
+
if (!streamTextStarted) {
|
|
114209
|
+
const telemetryMetadata = originalInput.forwardedProps?.telemetryMetadata;
|
|
114210
|
+
span.recordError({
|
|
114211
|
+
runId,
|
|
114212
|
+
errorCategory: "pre_stream_error",
|
|
114213
|
+
errorMessage,
|
|
114214
|
+
sessionId: session.clientId,
|
|
114215
|
+
threadId: session.threadId,
|
|
114216
|
+
ipAddress: session.ipAddress,
|
|
114217
|
+
metadata: { errorCode, toolCount: tools.length, messageCount: messages.length, ...telemetryMetadata }
|
|
114218
|
+
});
|
|
114219
|
+
}
|
|
113903
114220
|
events.emit({
|
|
113904
114221
|
type: export_EventType.RUN_ERROR,
|
|
113905
114222
|
message: errorCode,
|
|
@@ -113922,7 +114239,7 @@ class AISDKAgent {
|
|
|
113922
114239
|
const result = await this.systemPrompt();
|
|
113923
114240
|
return result || undefined;
|
|
113924
114241
|
}
|
|
113925
|
-
|
|
114242
|
+
buildStaticSystemMessages(configPrompt, runtimePrompt) {
|
|
113926
114243
|
const messages = [];
|
|
113927
114244
|
if (configPrompt) {
|
|
113928
114245
|
messages.push({ role: "system", content: configPrompt });
|
|
@@ -113932,6 +114249,16 @@ class AISDKAgent {
|
|
|
113932
114249
|
}
|
|
113933
114250
|
return messages.length > 0 ? messages : undefined;
|
|
113934
114251
|
}
|
|
114252
|
+
buildStateMessage(state) {
|
|
114253
|
+
if (!state)
|
|
114254
|
+
return;
|
|
114255
|
+
return {
|
|
114256
|
+
role: "system",
|
|
114257
|
+
content: `Current application state:
|
|
114258
|
+
|
|
114259
|
+
${JSON.stringify(state, null, 2)}`
|
|
114260
|
+
};
|
|
114261
|
+
}
|
|
113935
114262
|
filterTools(tools) {
|
|
113936
114263
|
if (!this.toolFilter) {
|
|
113937
114264
|
return tools;
|
|
@@ -113975,7 +114302,14 @@ class AISDKAgent {
|
|
|
113975
114302
|
for (const toolDef of tools) {
|
|
113976
114303
|
const rawParams = toolDef.parameters;
|
|
113977
114304
|
const inputSchema = rawParams && typeof rawParams === "object" ? { ...rawParams, type: rawParams.type || "object" } : { type: "object", properties: {} };
|
|
113978
|
-
|
|
114305
|
+
let baseExecutor;
|
|
114306
|
+
if (isRemoteTool(toolDef)) {
|
|
114307
|
+
baseExecutor = this.createMcpToolExecutor(toolDef, session);
|
|
114308
|
+
} else if (isServerTool(toolDef)) {
|
|
114309
|
+
baseExecutor = createServerToolExecutor(toolDef, session);
|
|
114310
|
+
} else {
|
|
114311
|
+
baseExecutor = clientToolExecutor;
|
|
114312
|
+
}
|
|
113979
114313
|
const execute = toolNeedsApproval(toolDef) ? createApprovalWrapper(toolDef, session, events, baseExecutor) : baseExecutor;
|
|
113980
114314
|
toolsObject[toolDef.name] = {
|
|
113981
114315
|
description: toolDef.description,
|
|
@@ -114053,12 +114387,1285 @@ ${val.text}`
|
|
|
114053
114387
|
}
|
|
114054
114388
|
}
|
|
114055
114389
|
}
|
|
114390
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/Options.js
|
|
114391
|
+
var ignoreOverride2 = Symbol("Let zodToJsonSchema decide on which parser to use");
|
|
114392
|
+
var defaultOptions2 = {
|
|
114393
|
+
name: undefined,
|
|
114394
|
+
$refStrategy: "root",
|
|
114395
|
+
basePath: ["#"],
|
|
114396
|
+
effectStrategy: "input",
|
|
114397
|
+
pipeStrategy: "all",
|
|
114398
|
+
dateStrategy: "format:date-time",
|
|
114399
|
+
mapStrategy: "entries",
|
|
114400
|
+
removeAdditionalStrategy: "passthrough",
|
|
114401
|
+
allowedAdditionalProperties: true,
|
|
114402
|
+
rejectedAdditionalProperties: false,
|
|
114403
|
+
definitionPath: "definitions",
|
|
114404
|
+
target: "jsonSchema7",
|
|
114405
|
+
strictUnions: false,
|
|
114406
|
+
definitions: {},
|
|
114407
|
+
errorMessages: false,
|
|
114408
|
+
markdownDescription: false,
|
|
114409
|
+
patternStrategy: "escape",
|
|
114410
|
+
applyRegexFlags: false,
|
|
114411
|
+
emailStrategy: "format:email",
|
|
114412
|
+
base64Strategy: "contentEncoding:base64",
|
|
114413
|
+
nameStrategy: "ref",
|
|
114414
|
+
openAiAnyTypeName: "OpenAiAnyType"
|
|
114415
|
+
};
|
|
114416
|
+
var getDefaultOptions2 = (options) => typeof options === "string" ? {
|
|
114417
|
+
...defaultOptions2,
|
|
114418
|
+
name: options
|
|
114419
|
+
} : {
|
|
114420
|
+
...defaultOptions2,
|
|
114421
|
+
...options
|
|
114422
|
+
};
|
|
114423
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/Refs.js
|
|
114424
|
+
var getRefs2 = (options) => {
|
|
114425
|
+
const _options = getDefaultOptions2(options);
|
|
114426
|
+
const currentPath = _options.name !== undefined ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
|
|
114427
|
+
return {
|
|
114428
|
+
..._options,
|
|
114429
|
+
flags: { hasReferencedOpenAiAnyType: false },
|
|
114430
|
+
currentPath,
|
|
114431
|
+
propertyPath: undefined,
|
|
114432
|
+
seen: new Map(Object.entries(_options.definitions).map(([name15, def]) => [
|
|
114433
|
+
def._def,
|
|
114434
|
+
{
|
|
114435
|
+
def: def._def,
|
|
114436
|
+
path: [..._options.basePath, _options.definitionPath, name15],
|
|
114437
|
+
jsonSchema: undefined
|
|
114438
|
+
}
|
|
114439
|
+
]))
|
|
114440
|
+
};
|
|
114441
|
+
};
|
|
114442
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
|
|
114443
|
+
function addErrorMessage(res, key, errorMessage, refs) {
|
|
114444
|
+
if (!refs?.errorMessages)
|
|
114445
|
+
return;
|
|
114446
|
+
if (errorMessage) {
|
|
114447
|
+
res.errorMessage = {
|
|
114448
|
+
...res.errorMessage,
|
|
114449
|
+
[key]: errorMessage
|
|
114450
|
+
};
|
|
114451
|
+
}
|
|
114452
|
+
}
|
|
114453
|
+
function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
|
|
114454
|
+
res[key] = value;
|
|
114455
|
+
addErrorMessage(res, key, errorMessage, refs);
|
|
114456
|
+
}
|
|
114457
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js
|
|
114458
|
+
var getRelativePath2 = (pathA, pathB) => {
|
|
114459
|
+
let i = 0;
|
|
114460
|
+
for (;i < pathA.length && i < pathB.length; i++) {
|
|
114461
|
+
if (pathA[i] !== pathB[i])
|
|
114462
|
+
break;
|
|
114463
|
+
}
|
|
114464
|
+
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
114465
|
+
};
|
|
114466
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
|
|
114467
|
+
function parseAnyDef2(refs) {
|
|
114468
|
+
if (refs.target !== "openAi") {
|
|
114469
|
+
return {};
|
|
114470
|
+
}
|
|
114471
|
+
const anyDefinitionPath = [
|
|
114472
|
+
...refs.basePath,
|
|
114473
|
+
refs.definitionPath,
|
|
114474
|
+
refs.openAiAnyTypeName
|
|
114475
|
+
];
|
|
114476
|
+
refs.flags.hasReferencedOpenAiAnyType = true;
|
|
114477
|
+
return {
|
|
114478
|
+
$ref: refs.$refStrategy === "relative" ? getRelativePath2(anyDefinitionPath, refs.currentPath) : anyDefinitionPath.join("/")
|
|
114479
|
+
};
|
|
114480
|
+
}
|
|
114481
|
+
|
|
114482
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
|
|
114483
|
+
function parseArrayDef2(def, refs) {
|
|
114484
|
+
const res = {
|
|
114485
|
+
type: "array"
|
|
114486
|
+
};
|
|
114487
|
+
if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
|
|
114488
|
+
res.items = parseDef2(def.type._def, {
|
|
114489
|
+
...refs,
|
|
114490
|
+
currentPath: [...refs.currentPath, "items"]
|
|
114491
|
+
});
|
|
114492
|
+
}
|
|
114493
|
+
if (def.minLength) {
|
|
114494
|
+
setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
|
|
114495
|
+
}
|
|
114496
|
+
if (def.maxLength) {
|
|
114497
|
+
setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
|
|
114498
|
+
}
|
|
114499
|
+
if (def.exactLength) {
|
|
114500
|
+
setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
|
|
114501
|
+
setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
|
|
114502
|
+
}
|
|
114503
|
+
return res;
|
|
114504
|
+
}
|
|
114505
|
+
|
|
114506
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
|
|
114507
|
+
function parseBigintDef2(def, refs) {
|
|
114508
|
+
const res = {
|
|
114509
|
+
type: "integer",
|
|
114510
|
+
format: "int64"
|
|
114511
|
+
};
|
|
114512
|
+
if (!def.checks)
|
|
114513
|
+
return res;
|
|
114514
|
+
for (const check2 of def.checks) {
|
|
114515
|
+
switch (check2.kind) {
|
|
114516
|
+
case "min":
|
|
114517
|
+
if (refs.target === "jsonSchema7") {
|
|
114518
|
+
if (check2.inclusive) {
|
|
114519
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
114520
|
+
} else {
|
|
114521
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
114522
|
+
}
|
|
114523
|
+
} else {
|
|
114524
|
+
if (!check2.inclusive) {
|
|
114525
|
+
res.exclusiveMinimum = true;
|
|
114526
|
+
}
|
|
114527
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
114528
|
+
}
|
|
114529
|
+
break;
|
|
114530
|
+
case "max":
|
|
114531
|
+
if (refs.target === "jsonSchema7") {
|
|
114532
|
+
if (check2.inclusive) {
|
|
114533
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
114534
|
+
} else {
|
|
114535
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
114536
|
+
}
|
|
114537
|
+
} else {
|
|
114538
|
+
if (!check2.inclusive) {
|
|
114539
|
+
res.exclusiveMaximum = true;
|
|
114540
|
+
}
|
|
114541
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
114542
|
+
}
|
|
114543
|
+
break;
|
|
114544
|
+
case "multipleOf":
|
|
114545
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
114546
|
+
break;
|
|
114547
|
+
}
|
|
114548
|
+
}
|
|
114549
|
+
return res;
|
|
114550
|
+
}
|
|
114551
|
+
|
|
114552
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
|
|
114553
|
+
function parseBooleanDef2() {
|
|
114554
|
+
return {
|
|
114555
|
+
type: "boolean"
|
|
114556
|
+
};
|
|
114557
|
+
}
|
|
114558
|
+
|
|
114559
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
|
|
114560
|
+
function parseBrandedDef2(_def, refs) {
|
|
114561
|
+
return parseDef2(_def.type._def, refs);
|
|
114562
|
+
}
|
|
114563
|
+
|
|
114564
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
|
|
114565
|
+
var parseCatchDef2 = (def, refs) => {
|
|
114566
|
+
return parseDef2(def.innerType._def, refs);
|
|
114567
|
+
};
|
|
114568
|
+
|
|
114569
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
|
|
114570
|
+
function parseDateDef2(def, refs, overrideDateStrategy) {
|
|
114571
|
+
const strategy = overrideDateStrategy ?? refs.dateStrategy;
|
|
114572
|
+
if (Array.isArray(strategy)) {
|
|
114573
|
+
return {
|
|
114574
|
+
anyOf: strategy.map((item, i) => parseDateDef2(def, refs, item))
|
|
114575
|
+
};
|
|
114576
|
+
}
|
|
114577
|
+
switch (strategy) {
|
|
114578
|
+
case "string":
|
|
114579
|
+
case "format:date-time":
|
|
114580
|
+
return {
|
|
114581
|
+
type: "string",
|
|
114582
|
+
format: "date-time"
|
|
114583
|
+
};
|
|
114584
|
+
case "format:date":
|
|
114585
|
+
return {
|
|
114586
|
+
type: "string",
|
|
114587
|
+
format: "date"
|
|
114588
|
+
};
|
|
114589
|
+
case "integer":
|
|
114590
|
+
return integerDateParser2(def, refs);
|
|
114591
|
+
}
|
|
114592
|
+
}
|
|
114593
|
+
var integerDateParser2 = (def, refs) => {
|
|
114594
|
+
const res = {
|
|
114595
|
+
type: "integer",
|
|
114596
|
+
format: "unix-time"
|
|
114597
|
+
};
|
|
114598
|
+
if (refs.target === "openApi3") {
|
|
114599
|
+
return res;
|
|
114600
|
+
}
|
|
114601
|
+
for (const check2 of def.checks) {
|
|
114602
|
+
switch (check2.kind) {
|
|
114603
|
+
case "min":
|
|
114604
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
114605
|
+
break;
|
|
114606
|
+
case "max":
|
|
114607
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
114608
|
+
break;
|
|
114609
|
+
}
|
|
114610
|
+
}
|
|
114611
|
+
return res;
|
|
114612
|
+
};
|
|
114613
|
+
|
|
114614
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
|
|
114615
|
+
function parseDefaultDef2(_def, refs) {
|
|
114616
|
+
return {
|
|
114617
|
+
...parseDef2(_def.innerType._def, refs),
|
|
114618
|
+
default: _def.defaultValue()
|
|
114619
|
+
};
|
|
114620
|
+
}
|
|
114621
|
+
|
|
114622
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
|
|
114623
|
+
function parseEffectsDef2(_def, refs) {
|
|
114624
|
+
return refs.effectStrategy === "input" ? parseDef2(_def.schema._def, refs) : parseAnyDef2(refs);
|
|
114625
|
+
}
|
|
114626
|
+
|
|
114627
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
|
|
114628
|
+
function parseEnumDef2(def) {
|
|
114629
|
+
return {
|
|
114630
|
+
type: "string",
|
|
114631
|
+
enum: Array.from(def.values)
|
|
114632
|
+
};
|
|
114633
|
+
}
|
|
114634
|
+
|
|
114635
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
|
|
114636
|
+
var isJsonSchema7AllOfType2 = (type) => {
|
|
114637
|
+
if ("type" in type && type.type === "string")
|
|
114638
|
+
return false;
|
|
114639
|
+
return "allOf" in type;
|
|
114640
|
+
};
|
|
114641
|
+
function parseIntersectionDef2(def, refs) {
|
|
114642
|
+
const allOf = [
|
|
114643
|
+
parseDef2(def.left._def, {
|
|
114644
|
+
...refs,
|
|
114645
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
114646
|
+
}),
|
|
114647
|
+
parseDef2(def.right._def, {
|
|
114648
|
+
...refs,
|
|
114649
|
+
currentPath: [...refs.currentPath, "allOf", "1"]
|
|
114650
|
+
})
|
|
114651
|
+
].filter((x) => !!x);
|
|
114652
|
+
let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : undefined;
|
|
114653
|
+
const mergedAllOf = [];
|
|
114654
|
+
allOf.forEach((schema) => {
|
|
114655
|
+
if (isJsonSchema7AllOfType2(schema)) {
|
|
114656
|
+
mergedAllOf.push(...schema.allOf);
|
|
114657
|
+
if (schema.unevaluatedProperties === undefined) {
|
|
114658
|
+
unevaluatedProperties = undefined;
|
|
114659
|
+
}
|
|
114660
|
+
} else {
|
|
114661
|
+
let nestedSchema = schema;
|
|
114662
|
+
if ("additionalProperties" in schema && schema.additionalProperties === false) {
|
|
114663
|
+
const { additionalProperties, ...rest } = schema;
|
|
114664
|
+
nestedSchema = rest;
|
|
114665
|
+
} else {
|
|
114666
|
+
unevaluatedProperties = undefined;
|
|
114667
|
+
}
|
|
114668
|
+
mergedAllOf.push(nestedSchema);
|
|
114669
|
+
}
|
|
114670
|
+
});
|
|
114671
|
+
return mergedAllOf.length ? {
|
|
114672
|
+
allOf: mergedAllOf,
|
|
114673
|
+
...unevaluatedProperties
|
|
114674
|
+
} : undefined;
|
|
114675
|
+
}
|
|
114676
|
+
|
|
114677
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
|
|
114678
|
+
function parseLiteralDef2(def, refs) {
|
|
114679
|
+
const parsedType4 = typeof def.value;
|
|
114680
|
+
if (parsedType4 !== "bigint" && parsedType4 !== "number" && parsedType4 !== "boolean" && parsedType4 !== "string") {
|
|
114681
|
+
return {
|
|
114682
|
+
type: Array.isArray(def.value) ? "array" : "object"
|
|
114683
|
+
};
|
|
114684
|
+
}
|
|
114685
|
+
if (refs.target === "openApi3") {
|
|
114686
|
+
return {
|
|
114687
|
+
type: parsedType4 === "bigint" ? "integer" : parsedType4,
|
|
114688
|
+
enum: [def.value]
|
|
114689
|
+
};
|
|
114690
|
+
}
|
|
114691
|
+
return {
|
|
114692
|
+
type: parsedType4 === "bigint" ? "integer" : parsedType4,
|
|
114693
|
+
const: def.value
|
|
114694
|
+
};
|
|
114695
|
+
}
|
|
114696
|
+
|
|
114697
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
|
|
114698
|
+
var emojiRegex3 = undefined;
|
|
114699
|
+
var zodPatterns2 = {
|
|
114700
|
+
cuid: /^[cC][^\s-]{8,}$/,
|
|
114701
|
+
cuid2: /^[0-9a-z]+$/,
|
|
114702
|
+
ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
|
|
114703
|
+
email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
|
|
114704
|
+
emoji: () => {
|
|
114705
|
+
if (emojiRegex3 === undefined) {
|
|
114706
|
+
emojiRegex3 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
|
|
114707
|
+
}
|
|
114708
|
+
return emojiRegex3;
|
|
114709
|
+
},
|
|
114710
|
+
uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
|
|
114711
|
+
ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
|
|
114712
|
+
ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
|
|
114713
|
+
ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
|
|
114714
|
+
ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
|
|
114715
|
+
base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
|
|
114716
|
+
base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
|
|
114717
|
+
nanoid: /^[a-zA-Z0-9_-]{21}$/,
|
|
114718
|
+
jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
|
|
114719
|
+
};
|
|
114720
|
+
function parseStringDef2(def, refs) {
|
|
114721
|
+
const res = {
|
|
114722
|
+
type: "string"
|
|
114723
|
+
};
|
|
114724
|
+
if (def.checks) {
|
|
114725
|
+
for (const check2 of def.checks) {
|
|
114726
|
+
switch (check2.kind) {
|
|
114727
|
+
case "min":
|
|
114728
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
114729
|
+
break;
|
|
114730
|
+
case "max":
|
|
114731
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
114732
|
+
break;
|
|
114733
|
+
case "email":
|
|
114734
|
+
switch (refs.emailStrategy) {
|
|
114735
|
+
case "format:email":
|
|
114736
|
+
addFormat2(res, "email", check2.message, refs);
|
|
114737
|
+
break;
|
|
114738
|
+
case "format:idn-email":
|
|
114739
|
+
addFormat2(res, "idn-email", check2.message, refs);
|
|
114740
|
+
break;
|
|
114741
|
+
case "pattern:zod":
|
|
114742
|
+
addPattern2(res, zodPatterns2.email, check2.message, refs);
|
|
114743
|
+
break;
|
|
114744
|
+
}
|
|
114745
|
+
break;
|
|
114746
|
+
case "url":
|
|
114747
|
+
addFormat2(res, "uri", check2.message, refs);
|
|
114748
|
+
break;
|
|
114749
|
+
case "uuid":
|
|
114750
|
+
addFormat2(res, "uuid", check2.message, refs);
|
|
114751
|
+
break;
|
|
114752
|
+
case "regex":
|
|
114753
|
+
addPattern2(res, check2.regex, check2.message, refs);
|
|
114754
|
+
break;
|
|
114755
|
+
case "cuid":
|
|
114756
|
+
addPattern2(res, zodPatterns2.cuid, check2.message, refs);
|
|
114757
|
+
break;
|
|
114758
|
+
case "cuid2":
|
|
114759
|
+
addPattern2(res, zodPatterns2.cuid2, check2.message, refs);
|
|
114760
|
+
break;
|
|
114761
|
+
case "startsWith":
|
|
114762
|
+
addPattern2(res, RegExp(`^${escapeLiteralCheckValue2(check2.value, refs)}`), check2.message, refs);
|
|
114763
|
+
break;
|
|
114764
|
+
case "endsWith":
|
|
114765
|
+
addPattern2(res, RegExp(`${escapeLiteralCheckValue2(check2.value, refs)}$`), check2.message, refs);
|
|
114766
|
+
break;
|
|
114767
|
+
case "datetime":
|
|
114768
|
+
addFormat2(res, "date-time", check2.message, refs);
|
|
114769
|
+
break;
|
|
114770
|
+
case "date":
|
|
114771
|
+
addFormat2(res, "date", check2.message, refs);
|
|
114772
|
+
break;
|
|
114773
|
+
case "time":
|
|
114774
|
+
addFormat2(res, "time", check2.message, refs);
|
|
114775
|
+
break;
|
|
114776
|
+
case "duration":
|
|
114777
|
+
addFormat2(res, "duration", check2.message, refs);
|
|
114778
|
+
break;
|
|
114779
|
+
case "length":
|
|
114780
|
+
setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check2.value) : check2.value, check2.message, refs);
|
|
114781
|
+
setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check2.value) : check2.value, check2.message, refs);
|
|
114782
|
+
break;
|
|
114783
|
+
case "includes": {
|
|
114784
|
+
addPattern2(res, RegExp(escapeLiteralCheckValue2(check2.value, refs)), check2.message, refs);
|
|
114785
|
+
break;
|
|
114786
|
+
}
|
|
114787
|
+
case "ip": {
|
|
114788
|
+
if (check2.version !== "v6") {
|
|
114789
|
+
addFormat2(res, "ipv4", check2.message, refs);
|
|
114790
|
+
}
|
|
114791
|
+
if (check2.version !== "v4") {
|
|
114792
|
+
addFormat2(res, "ipv6", check2.message, refs);
|
|
114793
|
+
}
|
|
114794
|
+
break;
|
|
114795
|
+
}
|
|
114796
|
+
case "base64url":
|
|
114797
|
+
addPattern2(res, zodPatterns2.base64url, check2.message, refs);
|
|
114798
|
+
break;
|
|
114799
|
+
case "jwt":
|
|
114800
|
+
addPattern2(res, zodPatterns2.jwt, check2.message, refs);
|
|
114801
|
+
break;
|
|
114802
|
+
case "cidr": {
|
|
114803
|
+
if (check2.version !== "v6") {
|
|
114804
|
+
addPattern2(res, zodPatterns2.ipv4Cidr, check2.message, refs);
|
|
114805
|
+
}
|
|
114806
|
+
if (check2.version !== "v4") {
|
|
114807
|
+
addPattern2(res, zodPatterns2.ipv6Cidr, check2.message, refs);
|
|
114808
|
+
}
|
|
114809
|
+
break;
|
|
114810
|
+
}
|
|
114811
|
+
case "emoji":
|
|
114812
|
+
addPattern2(res, zodPatterns2.emoji(), check2.message, refs);
|
|
114813
|
+
break;
|
|
114814
|
+
case "ulid": {
|
|
114815
|
+
addPattern2(res, zodPatterns2.ulid, check2.message, refs);
|
|
114816
|
+
break;
|
|
114817
|
+
}
|
|
114818
|
+
case "base64": {
|
|
114819
|
+
switch (refs.base64Strategy) {
|
|
114820
|
+
case "format:binary": {
|
|
114821
|
+
addFormat2(res, "binary", check2.message, refs);
|
|
114822
|
+
break;
|
|
114823
|
+
}
|
|
114824
|
+
case "contentEncoding:base64": {
|
|
114825
|
+
setResponseValueAndErrors(res, "contentEncoding", "base64", check2.message, refs);
|
|
114826
|
+
break;
|
|
114827
|
+
}
|
|
114828
|
+
case "pattern:zod": {
|
|
114829
|
+
addPattern2(res, zodPatterns2.base64, check2.message, refs);
|
|
114830
|
+
break;
|
|
114831
|
+
}
|
|
114832
|
+
}
|
|
114833
|
+
break;
|
|
114834
|
+
}
|
|
114835
|
+
case "nanoid": {
|
|
114836
|
+
addPattern2(res, zodPatterns2.nanoid, check2.message, refs);
|
|
114837
|
+
}
|
|
114838
|
+
case "toLowerCase":
|
|
114839
|
+
case "toUpperCase":
|
|
114840
|
+
case "trim":
|
|
114841
|
+
break;
|
|
114842
|
+
default:
|
|
114843
|
+
((_) => {})(check2);
|
|
114844
|
+
}
|
|
114845
|
+
}
|
|
114846
|
+
}
|
|
114847
|
+
return res;
|
|
114848
|
+
}
|
|
114849
|
+
function escapeLiteralCheckValue2(literal2, refs) {
|
|
114850
|
+
return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric2(literal2) : literal2;
|
|
114851
|
+
}
|
|
114852
|
+
var ALPHA_NUMERIC2 = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
|
|
114853
|
+
function escapeNonAlphaNumeric2(source) {
|
|
114854
|
+
let result = "";
|
|
114855
|
+
for (let i = 0;i < source.length; i++) {
|
|
114856
|
+
if (!ALPHA_NUMERIC2.has(source[i])) {
|
|
114857
|
+
result += "\\";
|
|
114858
|
+
}
|
|
114859
|
+
result += source[i];
|
|
114860
|
+
}
|
|
114861
|
+
return result;
|
|
114862
|
+
}
|
|
114863
|
+
function addFormat2(schema, value, message, refs) {
|
|
114864
|
+
if (schema.format || schema.anyOf?.some((x) => x.format)) {
|
|
114865
|
+
if (!schema.anyOf) {
|
|
114866
|
+
schema.anyOf = [];
|
|
114867
|
+
}
|
|
114868
|
+
if (schema.format) {
|
|
114869
|
+
schema.anyOf.push({
|
|
114870
|
+
format: schema.format,
|
|
114871
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
114872
|
+
errorMessage: { format: schema.errorMessage.format }
|
|
114873
|
+
}
|
|
114874
|
+
});
|
|
114875
|
+
delete schema.format;
|
|
114876
|
+
if (schema.errorMessage) {
|
|
114877
|
+
delete schema.errorMessage.format;
|
|
114878
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
114879
|
+
delete schema.errorMessage;
|
|
114880
|
+
}
|
|
114881
|
+
}
|
|
114882
|
+
}
|
|
114883
|
+
schema.anyOf.push({
|
|
114884
|
+
format: value,
|
|
114885
|
+
...message && refs.errorMessages && { errorMessage: { format: message } }
|
|
114886
|
+
});
|
|
114887
|
+
} else {
|
|
114888
|
+
setResponseValueAndErrors(schema, "format", value, message, refs);
|
|
114889
|
+
}
|
|
114890
|
+
}
|
|
114891
|
+
function addPattern2(schema, regex, message, refs) {
|
|
114892
|
+
if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
|
|
114893
|
+
if (!schema.allOf) {
|
|
114894
|
+
schema.allOf = [];
|
|
114895
|
+
}
|
|
114896
|
+
if (schema.pattern) {
|
|
114897
|
+
schema.allOf.push({
|
|
114898
|
+
pattern: schema.pattern,
|
|
114899
|
+
...schema.errorMessage && refs.errorMessages && {
|
|
114900
|
+
errorMessage: { pattern: schema.errorMessage.pattern }
|
|
114901
|
+
}
|
|
114902
|
+
});
|
|
114903
|
+
delete schema.pattern;
|
|
114904
|
+
if (schema.errorMessage) {
|
|
114905
|
+
delete schema.errorMessage.pattern;
|
|
114906
|
+
if (Object.keys(schema.errorMessage).length === 0) {
|
|
114907
|
+
delete schema.errorMessage;
|
|
114908
|
+
}
|
|
114909
|
+
}
|
|
114910
|
+
}
|
|
114911
|
+
schema.allOf.push({
|
|
114912
|
+
pattern: stringifyRegExpWithFlags2(regex, refs),
|
|
114913
|
+
...message && refs.errorMessages && { errorMessage: { pattern: message } }
|
|
114914
|
+
});
|
|
114915
|
+
} else {
|
|
114916
|
+
setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags2(regex, refs), message, refs);
|
|
114917
|
+
}
|
|
114918
|
+
}
|
|
114919
|
+
function stringifyRegExpWithFlags2(regex, refs) {
|
|
114920
|
+
if (!refs.applyRegexFlags || !regex.flags) {
|
|
114921
|
+
return regex.source;
|
|
114922
|
+
}
|
|
114923
|
+
const flags = {
|
|
114924
|
+
i: regex.flags.includes("i"),
|
|
114925
|
+
m: regex.flags.includes("m"),
|
|
114926
|
+
s: regex.flags.includes("s")
|
|
114927
|
+
};
|
|
114928
|
+
const source = flags.i ? regex.source.toLowerCase() : regex.source;
|
|
114929
|
+
let pattern = "";
|
|
114930
|
+
let isEscaped = false;
|
|
114931
|
+
let inCharGroup = false;
|
|
114932
|
+
let inCharRange = false;
|
|
114933
|
+
for (let i = 0;i < source.length; i++) {
|
|
114934
|
+
if (isEscaped) {
|
|
114935
|
+
pattern += source[i];
|
|
114936
|
+
isEscaped = false;
|
|
114937
|
+
continue;
|
|
114938
|
+
}
|
|
114939
|
+
if (flags.i) {
|
|
114940
|
+
if (inCharGroup) {
|
|
114941
|
+
if (source[i].match(/[a-z]/)) {
|
|
114942
|
+
if (inCharRange) {
|
|
114943
|
+
pattern += source[i];
|
|
114944
|
+
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
114945
|
+
inCharRange = false;
|
|
114946
|
+
} else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
|
|
114947
|
+
pattern += source[i];
|
|
114948
|
+
inCharRange = true;
|
|
114949
|
+
} else {
|
|
114950
|
+
pattern += `${source[i]}${source[i].toUpperCase()}`;
|
|
114951
|
+
}
|
|
114952
|
+
continue;
|
|
114953
|
+
}
|
|
114954
|
+
} else if (source[i].match(/[a-z]/)) {
|
|
114955
|
+
pattern += `[${source[i]}${source[i].toUpperCase()}]`;
|
|
114956
|
+
continue;
|
|
114957
|
+
}
|
|
114958
|
+
}
|
|
114959
|
+
if (flags.m) {
|
|
114960
|
+
if (source[i] === "^") {
|
|
114961
|
+
pattern += `(^|(?<=[\r
|
|
114962
|
+
]))`;
|
|
114963
|
+
continue;
|
|
114964
|
+
} else if (source[i] === "$") {
|
|
114965
|
+
pattern += `($|(?=[\r
|
|
114966
|
+
]))`;
|
|
114967
|
+
continue;
|
|
114968
|
+
}
|
|
114969
|
+
}
|
|
114970
|
+
if (flags.s && source[i] === ".") {
|
|
114971
|
+
pattern += inCharGroup ? `${source[i]}\r
|
|
114972
|
+
` : `[${source[i]}\r
|
|
114973
|
+
]`;
|
|
114974
|
+
continue;
|
|
114975
|
+
}
|
|
114976
|
+
pattern += source[i];
|
|
114977
|
+
if (source[i] === "\\") {
|
|
114978
|
+
isEscaped = true;
|
|
114979
|
+
} else if (inCharGroup && source[i] === "]") {
|
|
114980
|
+
inCharGroup = false;
|
|
114981
|
+
} else if (!inCharGroup && source[i] === "[") {
|
|
114982
|
+
inCharGroup = true;
|
|
114983
|
+
}
|
|
114984
|
+
}
|
|
114985
|
+
try {
|
|
114986
|
+
new RegExp(pattern);
|
|
114987
|
+
} catch {
|
|
114988
|
+
console.warn(`Could not convert regex pattern at ${refs.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`);
|
|
114989
|
+
return regex.source;
|
|
114990
|
+
}
|
|
114991
|
+
return pattern;
|
|
114992
|
+
}
|
|
114993
|
+
|
|
114994
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
|
|
114995
|
+
function parseRecordDef2(def, refs) {
|
|
114996
|
+
if (refs.target === "openAi") {
|
|
114997
|
+
console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
|
|
114998
|
+
}
|
|
114999
|
+
if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
115000
|
+
return {
|
|
115001
|
+
type: "object",
|
|
115002
|
+
required: def.keyType._def.values,
|
|
115003
|
+
properties: def.keyType._def.values.reduce((acc, key) => ({
|
|
115004
|
+
...acc,
|
|
115005
|
+
[key]: parseDef2(def.valueType._def, {
|
|
115006
|
+
...refs,
|
|
115007
|
+
currentPath: [...refs.currentPath, "properties", key]
|
|
115008
|
+
}) ?? parseAnyDef2(refs)
|
|
115009
|
+
}), {}),
|
|
115010
|
+
additionalProperties: refs.rejectedAdditionalProperties
|
|
115011
|
+
};
|
|
115012
|
+
}
|
|
115013
|
+
const schema = {
|
|
115014
|
+
type: "object",
|
|
115015
|
+
additionalProperties: parseDef2(def.valueType._def, {
|
|
115016
|
+
...refs,
|
|
115017
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
115018
|
+
}) ?? refs.allowedAdditionalProperties
|
|
115019
|
+
};
|
|
115020
|
+
if (refs.target === "openApi3") {
|
|
115021
|
+
return schema;
|
|
115022
|
+
}
|
|
115023
|
+
if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
|
|
115024
|
+
const { type, ...keyType } = parseStringDef2(def.keyType._def, refs);
|
|
115025
|
+
return {
|
|
115026
|
+
...schema,
|
|
115027
|
+
propertyNames: keyType
|
|
115028
|
+
};
|
|
115029
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
|
|
115030
|
+
return {
|
|
115031
|
+
...schema,
|
|
115032
|
+
propertyNames: {
|
|
115033
|
+
enum: def.keyType._def.values
|
|
115034
|
+
}
|
|
115035
|
+
};
|
|
115036
|
+
} else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
|
|
115037
|
+
const { type, ...keyType } = parseBrandedDef2(def.keyType._def, refs);
|
|
115038
|
+
return {
|
|
115039
|
+
...schema,
|
|
115040
|
+
propertyNames: keyType
|
|
115041
|
+
};
|
|
115042
|
+
}
|
|
115043
|
+
return schema;
|
|
115044
|
+
}
|
|
115045
|
+
|
|
115046
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
|
|
115047
|
+
function parseMapDef2(def, refs) {
|
|
115048
|
+
if (refs.mapStrategy === "record") {
|
|
115049
|
+
return parseRecordDef2(def, refs);
|
|
115050
|
+
}
|
|
115051
|
+
const keys = parseDef2(def.keyType._def, {
|
|
115052
|
+
...refs,
|
|
115053
|
+
currentPath: [...refs.currentPath, "items", "items", "0"]
|
|
115054
|
+
}) || parseAnyDef2(refs);
|
|
115055
|
+
const values = parseDef2(def.valueType._def, {
|
|
115056
|
+
...refs,
|
|
115057
|
+
currentPath: [...refs.currentPath, "items", "items", "1"]
|
|
115058
|
+
}) || parseAnyDef2(refs);
|
|
115059
|
+
return {
|
|
115060
|
+
type: "array",
|
|
115061
|
+
maxItems: 125,
|
|
115062
|
+
items: {
|
|
115063
|
+
type: "array",
|
|
115064
|
+
items: [keys, values],
|
|
115065
|
+
minItems: 2,
|
|
115066
|
+
maxItems: 2
|
|
115067
|
+
}
|
|
115068
|
+
};
|
|
115069
|
+
}
|
|
115070
|
+
|
|
115071
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
|
|
115072
|
+
function parseNativeEnumDef2(def) {
|
|
115073
|
+
const object3 = def.values;
|
|
115074
|
+
const actualKeys = Object.keys(def.values).filter((key) => {
|
|
115075
|
+
return typeof object3[object3[key]] !== "number";
|
|
115076
|
+
});
|
|
115077
|
+
const actualValues = actualKeys.map((key) => object3[key]);
|
|
115078
|
+
const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
|
|
115079
|
+
return {
|
|
115080
|
+
type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
|
|
115081
|
+
enum: actualValues
|
|
115082
|
+
};
|
|
115083
|
+
}
|
|
115084
|
+
|
|
115085
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
|
|
115086
|
+
function parseNeverDef2(refs) {
|
|
115087
|
+
return refs.target === "openAi" ? undefined : {
|
|
115088
|
+
not: parseAnyDef2({
|
|
115089
|
+
...refs,
|
|
115090
|
+
currentPath: [...refs.currentPath, "not"]
|
|
115091
|
+
})
|
|
115092
|
+
};
|
|
115093
|
+
}
|
|
115094
|
+
|
|
115095
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
|
|
115096
|
+
function parseNullDef2(refs) {
|
|
115097
|
+
return refs.target === "openApi3" ? {
|
|
115098
|
+
enum: ["null"],
|
|
115099
|
+
nullable: true
|
|
115100
|
+
} : {
|
|
115101
|
+
type: "null"
|
|
115102
|
+
};
|
|
115103
|
+
}
|
|
115104
|
+
|
|
115105
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
|
|
115106
|
+
var primitiveMappings2 = {
|
|
115107
|
+
ZodString: "string",
|
|
115108
|
+
ZodNumber: "number",
|
|
115109
|
+
ZodBigInt: "integer",
|
|
115110
|
+
ZodBoolean: "boolean",
|
|
115111
|
+
ZodNull: "null"
|
|
115112
|
+
};
|
|
115113
|
+
function parseUnionDef2(def, refs) {
|
|
115114
|
+
if (refs.target === "openApi3")
|
|
115115
|
+
return asAnyOf2(def, refs);
|
|
115116
|
+
const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
|
|
115117
|
+
if (options.every((x) => (x._def.typeName in primitiveMappings2) && (!x._def.checks || !x._def.checks.length))) {
|
|
115118
|
+
const types2 = options.reduce((types3, x) => {
|
|
115119
|
+
const type = primitiveMappings2[x._def.typeName];
|
|
115120
|
+
return type && !types3.includes(type) ? [...types3, type] : types3;
|
|
115121
|
+
}, []);
|
|
115122
|
+
return {
|
|
115123
|
+
type: types2.length > 1 ? types2 : types2[0]
|
|
115124
|
+
};
|
|
115125
|
+
} else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
|
|
115126
|
+
const types2 = options.reduce((acc, x) => {
|
|
115127
|
+
const type = typeof x._def.value;
|
|
115128
|
+
switch (type) {
|
|
115129
|
+
case "string":
|
|
115130
|
+
case "number":
|
|
115131
|
+
case "boolean":
|
|
115132
|
+
return [...acc, type];
|
|
115133
|
+
case "bigint":
|
|
115134
|
+
return [...acc, "integer"];
|
|
115135
|
+
case "object":
|
|
115136
|
+
if (x._def.value === null)
|
|
115137
|
+
return [...acc, "null"];
|
|
115138
|
+
case "symbol":
|
|
115139
|
+
case "undefined":
|
|
115140
|
+
case "function":
|
|
115141
|
+
default:
|
|
115142
|
+
return acc;
|
|
115143
|
+
}
|
|
115144
|
+
}, []);
|
|
115145
|
+
if (types2.length === options.length) {
|
|
115146
|
+
const uniqueTypes = types2.filter((x, i, a) => a.indexOf(x) === i);
|
|
115147
|
+
return {
|
|
115148
|
+
type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
|
|
115149
|
+
enum: options.reduce((acc, x) => {
|
|
115150
|
+
return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
|
|
115151
|
+
}, [])
|
|
115152
|
+
};
|
|
115153
|
+
}
|
|
115154
|
+
} else if (options.every((x) => x._def.typeName === "ZodEnum")) {
|
|
115155
|
+
return {
|
|
115156
|
+
type: "string",
|
|
115157
|
+
enum: options.reduce((acc, x) => [
|
|
115158
|
+
...acc,
|
|
115159
|
+
...x._def.values.filter((x2) => !acc.includes(x2))
|
|
115160
|
+
], [])
|
|
115161
|
+
};
|
|
115162
|
+
}
|
|
115163
|
+
return asAnyOf2(def, refs);
|
|
115164
|
+
}
|
|
115165
|
+
var asAnyOf2 = (def, refs) => {
|
|
115166
|
+
const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef2(x._def, {
|
|
115167
|
+
...refs,
|
|
115168
|
+
currentPath: [...refs.currentPath, "anyOf", `${i}`]
|
|
115169
|
+
})).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
|
|
115170
|
+
return anyOf.length ? { anyOf } : undefined;
|
|
115171
|
+
};
|
|
115172
|
+
|
|
115173
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
|
|
115174
|
+
function parseNullableDef2(def, refs) {
|
|
115175
|
+
if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
|
|
115176
|
+
if (refs.target === "openApi3") {
|
|
115177
|
+
return {
|
|
115178
|
+
type: primitiveMappings2[def.innerType._def.typeName],
|
|
115179
|
+
nullable: true
|
|
115180
|
+
};
|
|
115181
|
+
}
|
|
115182
|
+
return {
|
|
115183
|
+
type: [
|
|
115184
|
+
primitiveMappings2[def.innerType._def.typeName],
|
|
115185
|
+
"null"
|
|
115186
|
+
]
|
|
115187
|
+
};
|
|
115188
|
+
}
|
|
115189
|
+
if (refs.target === "openApi3") {
|
|
115190
|
+
const base2 = parseDef2(def.innerType._def, {
|
|
115191
|
+
...refs,
|
|
115192
|
+
currentPath: [...refs.currentPath]
|
|
115193
|
+
});
|
|
115194
|
+
if (base2 && "$ref" in base2)
|
|
115195
|
+
return { allOf: [base2], nullable: true };
|
|
115196
|
+
return base2 && { ...base2, nullable: true };
|
|
115197
|
+
}
|
|
115198
|
+
const base = parseDef2(def.innerType._def, {
|
|
115199
|
+
...refs,
|
|
115200
|
+
currentPath: [...refs.currentPath, "anyOf", "0"]
|
|
115201
|
+
});
|
|
115202
|
+
return base && { anyOf: [base, { type: "null" }] };
|
|
115203
|
+
}
|
|
115204
|
+
|
|
115205
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
|
|
115206
|
+
function parseNumberDef2(def, refs) {
|
|
115207
|
+
const res = {
|
|
115208
|
+
type: "number"
|
|
115209
|
+
};
|
|
115210
|
+
if (!def.checks)
|
|
115211
|
+
return res;
|
|
115212
|
+
for (const check2 of def.checks) {
|
|
115213
|
+
switch (check2.kind) {
|
|
115214
|
+
case "int":
|
|
115215
|
+
res.type = "integer";
|
|
115216
|
+
addErrorMessage(res, "type", check2.message, refs);
|
|
115217
|
+
break;
|
|
115218
|
+
case "min":
|
|
115219
|
+
if (refs.target === "jsonSchema7") {
|
|
115220
|
+
if (check2.inclusive) {
|
|
115221
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
115222
|
+
} else {
|
|
115223
|
+
setResponseValueAndErrors(res, "exclusiveMinimum", check2.value, check2.message, refs);
|
|
115224
|
+
}
|
|
115225
|
+
} else {
|
|
115226
|
+
if (!check2.inclusive) {
|
|
115227
|
+
res.exclusiveMinimum = true;
|
|
115228
|
+
}
|
|
115229
|
+
setResponseValueAndErrors(res, "minimum", check2.value, check2.message, refs);
|
|
115230
|
+
}
|
|
115231
|
+
break;
|
|
115232
|
+
case "max":
|
|
115233
|
+
if (refs.target === "jsonSchema7") {
|
|
115234
|
+
if (check2.inclusive) {
|
|
115235
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
115236
|
+
} else {
|
|
115237
|
+
setResponseValueAndErrors(res, "exclusiveMaximum", check2.value, check2.message, refs);
|
|
115238
|
+
}
|
|
115239
|
+
} else {
|
|
115240
|
+
if (!check2.inclusive) {
|
|
115241
|
+
res.exclusiveMaximum = true;
|
|
115242
|
+
}
|
|
115243
|
+
setResponseValueAndErrors(res, "maximum", check2.value, check2.message, refs);
|
|
115244
|
+
}
|
|
115245
|
+
break;
|
|
115246
|
+
case "multipleOf":
|
|
115247
|
+
setResponseValueAndErrors(res, "multipleOf", check2.value, check2.message, refs);
|
|
115248
|
+
break;
|
|
115249
|
+
}
|
|
115250
|
+
}
|
|
115251
|
+
return res;
|
|
115252
|
+
}
|
|
115253
|
+
|
|
115254
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
|
|
115255
|
+
function parseObjectDef2(def, refs) {
|
|
115256
|
+
const forceOptionalIntoNullable = refs.target === "openAi";
|
|
115257
|
+
const result = {
|
|
115258
|
+
type: "object",
|
|
115259
|
+
properties: {}
|
|
115260
|
+
};
|
|
115261
|
+
const required2 = [];
|
|
115262
|
+
const shape = def.shape();
|
|
115263
|
+
for (const propName in shape) {
|
|
115264
|
+
let propDef = shape[propName];
|
|
115265
|
+
if (propDef === undefined || propDef._def === undefined) {
|
|
115266
|
+
continue;
|
|
115267
|
+
}
|
|
115268
|
+
let propOptional = safeIsOptional2(propDef);
|
|
115269
|
+
if (propOptional && forceOptionalIntoNullable) {
|
|
115270
|
+
if (propDef._def.typeName === "ZodOptional") {
|
|
115271
|
+
propDef = propDef._def.innerType;
|
|
115272
|
+
}
|
|
115273
|
+
if (!propDef.isNullable()) {
|
|
115274
|
+
propDef = propDef.nullable();
|
|
115275
|
+
}
|
|
115276
|
+
propOptional = false;
|
|
115277
|
+
}
|
|
115278
|
+
const parsedDef = parseDef2(propDef._def, {
|
|
115279
|
+
...refs,
|
|
115280
|
+
currentPath: [...refs.currentPath, "properties", propName],
|
|
115281
|
+
propertyPath: [...refs.currentPath, "properties", propName]
|
|
115282
|
+
});
|
|
115283
|
+
if (parsedDef === undefined) {
|
|
115284
|
+
continue;
|
|
115285
|
+
}
|
|
115286
|
+
result.properties[propName] = parsedDef;
|
|
115287
|
+
if (!propOptional) {
|
|
115288
|
+
required2.push(propName);
|
|
115289
|
+
}
|
|
115290
|
+
}
|
|
115291
|
+
if (required2.length) {
|
|
115292
|
+
result.required = required2;
|
|
115293
|
+
}
|
|
115294
|
+
const additionalProperties = decideAdditionalProperties2(def, refs);
|
|
115295
|
+
if (additionalProperties !== undefined) {
|
|
115296
|
+
result.additionalProperties = additionalProperties;
|
|
115297
|
+
}
|
|
115298
|
+
return result;
|
|
115299
|
+
}
|
|
115300
|
+
function decideAdditionalProperties2(def, refs) {
|
|
115301
|
+
if (def.catchall._def.typeName !== "ZodNever") {
|
|
115302
|
+
return parseDef2(def.catchall._def, {
|
|
115303
|
+
...refs,
|
|
115304
|
+
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
115305
|
+
});
|
|
115306
|
+
}
|
|
115307
|
+
switch (def.unknownKeys) {
|
|
115308
|
+
case "passthrough":
|
|
115309
|
+
return refs.allowedAdditionalProperties;
|
|
115310
|
+
case "strict":
|
|
115311
|
+
return refs.rejectedAdditionalProperties;
|
|
115312
|
+
case "strip":
|
|
115313
|
+
return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
|
|
115314
|
+
}
|
|
115315
|
+
}
|
|
115316
|
+
function safeIsOptional2(schema) {
|
|
115317
|
+
try {
|
|
115318
|
+
return schema.isOptional();
|
|
115319
|
+
} catch {
|
|
115320
|
+
return true;
|
|
115321
|
+
}
|
|
115322
|
+
}
|
|
115323
|
+
|
|
115324
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
|
|
115325
|
+
var parseOptionalDef2 = (def, refs) => {
|
|
115326
|
+
if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
|
|
115327
|
+
return parseDef2(def.innerType._def, refs);
|
|
115328
|
+
}
|
|
115329
|
+
const innerSchema = parseDef2(def.innerType._def, {
|
|
115330
|
+
...refs,
|
|
115331
|
+
currentPath: [...refs.currentPath, "anyOf", "1"]
|
|
115332
|
+
});
|
|
115333
|
+
return innerSchema ? {
|
|
115334
|
+
anyOf: [
|
|
115335
|
+
{
|
|
115336
|
+
not: parseAnyDef2(refs)
|
|
115337
|
+
},
|
|
115338
|
+
innerSchema
|
|
115339
|
+
]
|
|
115340
|
+
} : parseAnyDef2(refs);
|
|
115341
|
+
};
|
|
115342
|
+
|
|
115343
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
|
|
115344
|
+
var parsePipelineDef2 = (def, refs) => {
|
|
115345
|
+
if (refs.pipeStrategy === "input") {
|
|
115346
|
+
return parseDef2(def.in._def, refs);
|
|
115347
|
+
} else if (refs.pipeStrategy === "output") {
|
|
115348
|
+
return parseDef2(def.out._def, refs);
|
|
115349
|
+
}
|
|
115350
|
+
const a = parseDef2(def.in._def, {
|
|
115351
|
+
...refs,
|
|
115352
|
+
currentPath: [...refs.currentPath, "allOf", "0"]
|
|
115353
|
+
});
|
|
115354
|
+
const b = parseDef2(def.out._def, {
|
|
115355
|
+
...refs,
|
|
115356
|
+
currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
|
|
115357
|
+
});
|
|
115358
|
+
return {
|
|
115359
|
+
allOf: [a, b].filter((x) => x !== undefined)
|
|
115360
|
+
};
|
|
115361
|
+
};
|
|
115362
|
+
|
|
115363
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
|
|
115364
|
+
function parsePromiseDef2(def, refs) {
|
|
115365
|
+
return parseDef2(def.type._def, refs);
|
|
115366
|
+
}
|
|
115367
|
+
|
|
115368
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
|
|
115369
|
+
function parseSetDef2(def, refs) {
|
|
115370
|
+
const items = parseDef2(def.valueType._def, {
|
|
115371
|
+
...refs,
|
|
115372
|
+
currentPath: [...refs.currentPath, "items"]
|
|
115373
|
+
});
|
|
115374
|
+
const schema = {
|
|
115375
|
+
type: "array",
|
|
115376
|
+
uniqueItems: true,
|
|
115377
|
+
items
|
|
115378
|
+
};
|
|
115379
|
+
if (def.minSize) {
|
|
115380
|
+
setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
|
|
115381
|
+
}
|
|
115382
|
+
if (def.maxSize) {
|
|
115383
|
+
setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
|
|
115384
|
+
}
|
|
115385
|
+
return schema;
|
|
115386
|
+
}
|
|
115387
|
+
|
|
115388
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
|
|
115389
|
+
function parseTupleDef2(def, refs) {
|
|
115390
|
+
if (def.rest) {
|
|
115391
|
+
return {
|
|
115392
|
+
type: "array",
|
|
115393
|
+
minItems: def.items.length,
|
|
115394
|
+
items: def.items.map((x, i) => parseDef2(x._def, {
|
|
115395
|
+
...refs,
|
|
115396
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
115397
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], []),
|
|
115398
|
+
additionalItems: parseDef2(def.rest._def, {
|
|
115399
|
+
...refs,
|
|
115400
|
+
currentPath: [...refs.currentPath, "additionalItems"]
|
|
115401
|
+
})
|
|
115402
|
+
};
|
|
115403
|
+
} else {
|
|
115404
|
+
return {
|
|
115405
|
+
type: "array",
|
|
115406
|
+
minItems: def.items.length,
|
|
115407
|
+
maxItems: def.items.length,
|
|
115408
|
+
items: def.items.map((x, i) => parseDef2(x._def, {
|
|
115409
|
+
...refs,
|
|
115410
|
+
currentPath: [...refs.currentPath, "items", `${i}`]
|
|
115411
|
+
})).reduce((acc, x) => x === undefined ? acc : [...acc, x], [])
|
|
115412
|
+
};
|
|
115413
|
+
}
|
|
115414
|
+
}
|
|
115415
|
+
|
|
115416
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
|
|
115417
|
+
function parseUndefinedDef2(refs) {
|
|
115418
|
+
return {
|
|
115419
|
+
not: parseAnyDef2(refs)
|
|
115420
|
+
};
|
|
115421
|
+
}
|
|
115422
|
+
|
|
115423
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
|
|
115424
|
+
function parseUnknownDef2(refs) {
|
|
115425
|
+
return parseAnyDef2(refs);
|
|
115426
|
+
}
|
|
115427
|
+
|
|
115428
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
|
|
115429
|
+
var parseReadonlyDef2 = (def, refs) => {
|
|
115430
|
+
return parseDef2(def.innerType._def, refs);
|
|
115431
|
+
};
|
|
115432
|
+
|
|
115433
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/selectParser.js
|
|
115434
|
+
var selectParser2 = (def, typeName, refs) => {
|
|
115435
|
+
switch (typeName) {
|
|
115436
|
+
case ZodFirstPartyTypeKind.ZodString:
|
|
115437
|
+
return parseStringDef2(def, refs);
|
|
115438
|
+
case ZodFirstPartyTypeKind.ZodNumber:
|
|
115439
|
+
return parseNumberDef2(def, refs);
|
|
115440
|
+
case ZodFirstPartyTypeKind.ZodObject:
|
|
115441
|
+
return parseObjectDef2(def, refs);
|
|
115442
|
+
case ZodFirstPartyTypeKind.ZodBigInt:
|
|
115443
|
+
return parseBigintDef2(def, refs);
|
|
115444
|
+
case ZodFirstPartyTypeKind.ZodBoolean:
|
|
115445
|
+
return parseBooleanDef2();
|
|
115446
|
+
case ZodFirstPartyTypeKind.ZodDate:
|
|
115447
|
+
return parseDateDef2(def, refs);
|
|
115448
|
+
case ZodFirstPartyTypeKind.ZodUndefined:
|
|
115449
|
+
return parseUndefinedDef2(refs);
|
|
115450
|
+
case ZodFirstPartyTypeKind.ZodNull:
|
|
115451
|
+
return parseNullDef2(refs);
|
|
115452
|
+
case ZodFirstPartyTypeKind.ZodArray:
|
|
115453
|
+
return parseArrayDef2(def, refs);
|
|
115454
|
+
case ZodFirstPartyTypeKind.ZodUnion:
|
|
115455
|
+
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
|
|
115456
|
+
return parseUnionDef2(def, refs);
|
|
115457
|
+
case ZodFirstPartyTypeKind.ZodIntersection:
|
|
115458
|
+
return parseIntersectionDef2(def, refs);
|
|
115459
|
+
case ZodFirstPartyTypeKind.ZodTuple:
|
|
115460
|
+
return parseTupleDef2(def, refs);
|
|
115461
|
+
case ZodFirstPartyTypeKind.ZodRecord:
|
|
115462
|
+
return parseRecordDef2(def, refs);
|
|
115463
|
+
case ZodFirstPartyTypeKind.ZodLiteral:
|
|
115464
|
+
return parseLiteralDef2(def, refs);
|
|
115465
|
+
case ZodFirstPartyTypeKind.ZodEnum:
|
|
115466
|
+
return parseEnumDef2(def);
|
|
115467
|
+
case ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
115468
|
+
return parseNativeEnumDef2(def);
|
|
115469
|
+
case ZodFirstPartyTypeKind.ZodNullable:
|
|
115470
|
+
return parseNullableDef2(def, refs);
|
|
115471
|
+
case ZodFirstPartyTypeKind.ZodOptional:
|
|
115472
|
+
return parseOptionalDef2(def, refs);
|
|
115473
|
+
case ZodFirstPartyTypeKind.ZodMap:
|
|
115474
|
+
return parseMapDef2(def, refs);
|
|
115475
|
+
case ZodFirstPartyTypeKind.ZodSet:
|
|
115476
|
+
return parseSetDef2(def, refs);
|
|
115477
|
+
case ZodFirstPartyTypeKind.ZodLazy:
|
|
115478
|
+
return () => def.getter()._def;
|
|
115479
|
+
case ZodFirstPartyTypeKind.ZodPromise:
|
|
115480
|
+
return parsePromiseDef2(def, refs);
|
|
115481
|
+
case ZodFirstPartyTypeKind.ZodNaN:
|
|
115482
|
+
case ZodFirstPartyTypeKind.ZodNever:
|
|
115483
|
+
return parseNeverDef2(refs);
|
|
115484
|
+
case ZodFirstPartyTypeKind.ZodEffects:
|
|
115485
|
+
return parseEffectsDef2(def, refs);
|
|
115486
|
+
case ZodFirstPartyTypeKind.ZodAny:
|
|
115487
|
+
return parseAnyDef2(refs);
|
|
115488
|
+
case ZodFirstPartyTypeKind.ZodUnknown:
|
|
115489
|
+
return parseUnknownDef2(refs);
|
|
115490
|
+
case ZodFirstPartyTypeKind.ZodDefault:
|
|
115491
|
+
return parseDefaultDef2(def, refs);
|
|
115492
|
+
case ZodFirstPartyTypeKind.ZodBranded:
|
|
115493
|
+
return parseBrandedDef2(def, refs);
|
|
115494
|
+
case ZodFirstPartyTypeKind.ZodReadonly:
|
|
115495
|
+
return parseReadonlyDef2(def, refs);
|
|
115496
|
+
case ZodFirstPartyTypeKind.ZodCatch:
|
|
115497
|
+
return parseCatchDef2(def, refs);
|
|
115498
|
+
case ZodFirstPartyTypeKind.ZodPipeline:
|
|
115499
|
+
return parsePipelineDef2(def, refs);
|
|
115500
|
+
case ZodFirstPartyTypeKind.ZodFunction:
|
|
115501
|
+
case ZodFirstPartyTypeKind.ZodVoid:
|
|
115502
|
+
case ZodFirstPartyTypeKind.ZodSymbol:
|
|
115503
|
+
return;
|
|
115504
|
+
default:
|
|
115505
|
+
return ((_) => {
|
|
115506
|
+
return;
|
|
115507
|
+
})(typeName);
|
|
115508
|
+
}
|
|
115509
|
+
};
|
|
115510
|
+
|
|
115511
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/parseDef.js
|
|
115512
|
+
function parseDef2(def, refs, forceResolution = false) {
|
|
115513
|
+
const seenItem = refs.seen.get(def);
|
|
115514
|
+
if (refs.override) {
|
|
115515
|
+
const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
|
|
115516
|
+
if (overrideResult !== ignoreOverride2) {
|
|
115517
|
+
return overrideResult;
|
|
115518
|
+
}
|
|
115519
|
+
}
|
|
115520
|
+
if (seenItem && !forceResolution) {
|
|
115521
|
+
const seenSchema = get$ref2(seenItem, refs);
|
|
115522
|
+
if (seenSchema !== undefined) {
|
|
115523
|
+
return seenSchema;
|
|
115524
|
+
}
|
|
115525
|
+
}
|
|
115526
|
+
const newItem = { def, path: refs.currentPath, jsonSchema: undefined };
|
|
115527
|
+
refs.seen.set(def, newItem);
|
|
115528
|
+
const jsonSchemaOrGetter = selectParser2(def, def.typeName, refs);
|
|
115529
|
+
const jsonSchema2 = typeof jsonSchemaOrGetter === "function" ? parseDef2(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
|
|
115530
|
+
if (jsonSchema2) {
|
|
115531
|
+
addMeta2(def, refs, jsonSchema2);
|
|
115532
|
+
}
|
|
115533
|
+
if (refs.postProcess) {
|
|
115534
|
+
const postProcessResult = refs.postProcess(jsonSchema2, def, refs);
|
|
115535
|
+
newItem.jsonSchema = jsonSchema2;
|
|
115536
|
+
return postProcessResult;
|
|
115537
|
+
}
|
|
115538
|
+
newItem.jsonSchema = jsonSchema2;
|
|
115539
|
+
return jsonSchema2;
|
|
115540
|
+
}
|
|
115541
|
+
var get$ref2 = (item, refs) => {
|
|
115542
|
+
switch (refs.$refStrategy) {
|
|
115543
|
+
case "root":
|
|
115544
|
+
return { $ref: item.path.join("/") };
|
|
115545
|
+
case "relative":
|
|
115546
|
+
return { $ref: getRelativePath2(refs.currentPath, item.path) };
|
|
115547
|
+
case "none":
|
|
115548
|
+
case "seen": {
|
|
115549
|
+
if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
|
|
115550
|
+
console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
|
|
115551
|
+
return parseAnyDef2(refs);
|
|
115552
|
+
}
|
|
115553
|
+
return refs.$refStrategy === "seen" ? parseAnyDef2(refs) : undefined;
|
|
115554
|
+
}
|
|
115555
|
+
}
|
|
115556
|
+
};
|
|
115557
|
+
var addMeta2 = (def, refs, jsonSchema2) => {
|
|
115558
|
+
if (def.description) {
|
|
115559
|
+
jsonSchema2.description = def.description;
|
|
115560
|
+
if (refs.markdownDescription) {
|
|
115561
|
+
jsonSchema2.markdownDescription = def.description;
|
|
115562
|
+
}
|
|
115563
|
+
}
|
|
115564
|
+
return jsonSchema2;
|
|
115565
|
+
};
|
|
115566
|
+
// ../../node_modules/.bun/zod-to-json-schema@3.25.1+27912429049419a2/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
|
|
115567
|
+
var zodToJsonSchema = (schema, options) => {
|
|
115568
|
+
const refs = getRefs2(options);
|
|
115569
|
+
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce((acc, [name17, schema2]) => ({
|
|
115570
|
+
...acc,
|
|
115571
|
+
[name17]: parseDef2(schema2._def, {
|
|
115572
|
+
...refs,
|
|
115573
|
+
currentPath: [...refs.basePath, refs.definitionPath, name17]
|
|
115574
|
+
}, true) ?? parseAnyDef2(refs)
|
|
115575
|
+
}), {}) : undefined;
|
|
115576
|
+
const name15 = typeof options === "string" ? options : options?.nameStrategy === "title" ? undefined : options?.name;
|
|
115577
|
+
const main = parseDef2(schema._def, name15 === undefined ? refs : {
|
|
115578
|
+
...refs,
|
|
115579
|
+
currentPath: [...refs.basePath, refs.definitionPath, name15]
|
|
115580
|
+
}, false) ?? parseAnyDef2(refs);
|
|
115581
|
+
const title = typeof options === "object" && options.name !== undefined && options.nameStrategy === "title" ? options.name : undefined;
|
|
115582
|
+
if (title !== undefined) {
|
|
115583
|
+
main.title = title;
|
|
115584
|
+
}
|
|
115585
|
+
if (refs.flags.hasReferencedOpenAiAnyType) {
|
|
115586
|
+
if (!definitions) {
|
|
115587
|
+
definitions = {};
|
|
115588
|
+
}
|
|
115589
|
+
if (!definitions[refs.openAiAnyTypeName]) {
|
|
115590
|
+
definitions[refs.openAiAnyTypeName] = {
|
|
115591
|
+
type: ["string", "number", "integer", "boolean", "array", "null"],
|
|
115592
|
+
items: {
|
|
115593
|
+
$ref: refs.$refStrategy === "relative" ? "1" : [
|
|
115594
|
+
...refs.basePath,
|
|
115595
|
+
refs.definitionPath,
|
|
115596
|
+
refs.openAiAnyTypeName
|
|
115597
|
+
].join("/")
|
|
115598
|
+
}
|
|
115599
|
+
};
|
|
115600
|
+
}
|
|
115601
|
+
}
|
|
115602
|
+
const combined = name15 === undefined ? definitions ? {
|
|
115603
|
+
...main,
|
|
115604
|
+
[refs.definitionPath]: definitions
|
|
115605
|
+
} : main : {
|
|
115606
|
+
$ref: [
|
|
115607
|
+
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
115608
|
+
refs.definitionPath,
|
|
115609
|
+
name15
|
|
115610
|
+
].join("/"),
|
|
115611
|
+
[refs.definitionPath]: {
|
|
115612
|
+
...definitions,
|
|
115613
|
+
[name15]: main
|
|
115614
|
+
}
|
|
115615
|
+
};
|
|
115616
|
+
if (refs.target === "jsonSchema7") {
|
|
115617
|
+
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
115618
|
+
} else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
|
|
115619
|
+
combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
|
|
115620
|
+
}
|
|
115621
|
+
if (refs.target === "openAi" && (("anyOf" in combined) || ("oneOf" in combined) || ("allOf" in combined) || ("type" in combined) && Array.isArray(combined.type))) {
|
|
115622
|
+
console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
|
|
115623
|
+
}
|
|
115624
|
+
return combined;
|
|
115625
|
+
};
|
|
115626
|
+
// src/tools/defineServerTool.ts
|
|
115627
|
+
function defineServerTool(description, schemaOrExecute, executeOrOptions, options) {
|
|
115628
|
+
const isNoParamForm = typeof schemaOrExecute === "function";
|
|
115629
|
+
let parameters;
|
|
115630
|
+
let execute;
|
|
115631
|
+
let actualOptions;
|
|
115632
|
+
if (isNoParamForm) {
|
|
115633
|
+
parameters = { type: "object", properties: {} };
|
|
115634
|
+
execute = schemaOrExecute;
|
|
115635
|
+
actualOptions = executeOrOptions || {};
|
|
115636
|
+
} else {
|
|
115637
|
+
const schema = schemaOrExecute;
|
|
115638
|
+
const jsonSchema2 = zodToJsonSchema(schema, { target: "openApi3" });
|
|
115639
|
+
parameters = {
|
|
115640
|
+
type: "object",
|
|
115641
|
+
properties: jsonSchema2.properties || {}
|
|
115642
|
+
};
|
|
115643
|
+
if (jsonSchema2.required && jsonSchema2.required.length > 0) {
|
|
115644
|
+
parameters.required = jsonSchema2.required;
|
|
115645
|
+
}
|
|
115646
|
+
execute = executeOrOptions;
|
|
115647
|
+
actualOptions = options || {};
|
|
115648
|
+
}
|
|
115649
|
+
const config2 = {
|
|
115650
|
+
description,
|
|
115651
|
+
parameters,
|
|
115652
|
+
execute
|
|
115653
|
+
};
|
|
115654
|
+
if (actualOptions.annotations) {
|
|
115655
|
+
config2.annotations = actualOptions.annotations;
|
|
115656
|
+
}
|
|
115657
|
+
return config2;
|
|
115658
|
+
}
|
|
114056
115659
|
export {
|
|
115660
|
+
startRunSpan,
|
|
114057
115661
|
or,
|
|
114058
115662
|
not,
|
|
114059
115663
|
logger2 as logger,
|
|
115664
|
+
isServerTool,
|
|
114060
115665
|
isRemoteTool,
|
|
114061
115666
|
getToolAnnotations,
|
|
115667
|
+
flushTelemetry,
|
|
115668
|
+
defineServerTool,
|
|
114062
115669
|
createGlobFilter,
|
|
114063
115670
|
createClientToolExecutor,
|
|
114064
115671
|
and,
|