@cognipeer/agent-sdk 0.8.10 → 0.8.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +294 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.mjs +293 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2024,6 +2024,177 @@ function extractMessageText2(message) {
|
|
|
2024
2024
|
return "";
|
|
2025
2025
|
}
|
|
2026
2026
|
|
|
2027
|
+
// src/smart/toolArgCoercion.ts
|
|
2028
|
+
var PLACEHOLDER_TEXT = /* @__PURE__ */ new Set(["", "null", "undefined", "none", "nil", "n/a", "na"]);
|
|
2029
|
+
var ENVELOPE_KEYS = ["input", "args", "arguments", "params", "parameters", "payload"];
|
|
2030
|
+
function defOf(schema) {
|
|
2031
|
+
const def = schema?._def;
|
|
2032
|
+
return def && typeof def === "object" ? def : null;
|
|
2033
|
+
}
|
|
2034
|
+
function isPlaceholder(value) {
|
|
2035
|
+
return typeof value === "string" && PLACEHOLDER_TEXT.has(value.trim().toLowerCase());
|
|
2036
|
+
}
|
|
2037
|
+
function parseJsonish(value) {
|
|
2038
|
+
const text = value.trim();
|
|
2039
|
+
if (!text.startsWith("{") && !text.startsWith("[")) return { ok: false };
|
|
2040
|
+
try {
|
|
2041
|
+
return { ok: true, value: JSON.parse(text) };
|
|
2042
|
+
} catch {
|
|
2043
|
+
return { ok: false };
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
function safeParses(schema, value) {
|
|
2047
|
+
try {
|
|
2048
|
+
return schema.safeParse(value).success === true;
|
|
2049
|
+
} catch {
|
|
2050
|
+
return false;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
function coerceToolArgs(schema, value) {
|
|
2054
|
+
try {
|
|
2055
|
+
return coerceNode(schema, value, 0);
|
|
2056
|
+
} catch {
|
|
2057
|
+
return value;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
function coerceNode(schema, value, depth) {
|
|
2061
|
+
if (depth > 12) return value;
|
|
2062
|
+
const def = defOf(schema);
|
|
2063
|
+
if (!def) return value;
|
|
2064
|
+
switch (def.typeName) {
|
|
2065
|
+
case "ZodOptional":
|
|
2066
|
+
case "ZodNullable": {
|
|
2067
|
+
if (value === void 0 || value === null) return value;
|
|
2068
|
+
if (isPlaceholder(value)) return void 0;
|
|
2069
|
+
return coerceNode(def.innerType, value, depth + 1);
|
|
2070
|
+
}
|
|
2071
|
+
case "ZodDefault":
|
|
2072
|
+
case "ZodCatch":
|
|
2073
|
+
case "ZodReadonly":
|
|
2074
|
+
case "ZodBranded":
|
|
2075
|
+
return coerceNode(def.innerType, value, depth + 1);
|
|
2076
|
+
case "ZodEffects":
|
|
2077
|
+
return coerceNode(def.schema, value, depth + 1);
|
|
2078
|
+
case "ZodPipeline":
|
|
2079
|
+
return coerceNode(def.in, value, depth + 1);
|
|
2080
|
+
case "ZodLazy":
|
|
2081
|
+
return coerceNode(def.getter(), value, depth + 1);
|
|
2082
|
+
case "ZodObject":
|
|
2083
|
+
return coerceObject(def, value, depth);
|
|
2084
|
+
case "ZodRecord": {
|
|
2085
|
+
const unwrapped = unwrapJsonString(value);
|
|
2086
|
+
if (!unwrapped || typeof unwrapped !== "object" || Array.isArray(unwrapped)) return unwrapped ?? value;
|
|
2087
|
+
const out = {};
|
|
2088
|
+
for (const [key, entry] of Object.entries(unwrapped)) {
|
|
2089
|
+
out[key] = def.valueType ? coerceNode(def.valueType, entry, depth + 1) : entry;
|
|
2090
|
+
}
|
|
2091
|
+
return out;
|
|
2092
|
+
}
|
|
2093
|
+
case "ZodArray": {
|
|
2094
|
+
const unwrapped = unwrapJsonString(value);
|
|
2095
|
+
const items = Array.isArray(unwrapped) ? unwrapped : unwrapped === void 0 || unwrapped === null ? unwrapped : [unwrapped];
|
|
2096
|
+
if (!Array.isArray(items)) return items;
|
|
2097
|
+
return items.map((item) => coerceNode(def.type, item, depth + 1));
|
|
2098
|
+
}
|
|
2099
|
+
case "ZodTuple": {
|
|
2100
|
+
const unwrapped = unwrapJsonString(value);
|
|
2101
|
+
if (!Array.isArray(unwrapped)) return unwrapped ?? value;
|
|
2102
|
+
const items = def.items ?? [];
|
|
2103
|
+
return unwrapped.map((item, index) => items[index] ? coerceNode(items[index], item, depth + 1) : item);
|
|
2104
|
+
}
|
|
2105
|
+
case "ZodNumber": {
|
|
2106
|
+
if (typeof value === "number") return value;
|
|
2107
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
2108
|
+
const parsed = Number(value.trim());
|
|
2109
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
2110
|
+
}
|
|
2111
|
+
if (typeof value === "boolean") return value ? 1 : 0;
|
|
2112
|
+
return value;
|
|
2113
|
+
}
|
|
2114
|
+
case "ZodBoolean": {
|
|
2115
|
+
if (typeof value === "boolean") return value;
|
|
2116
|
+
if (typeof value === "string") {
|
|
2117
|
+
const text = value.trim().toLowerCase();
|
|
2118
|
+
if (text === "true" || text === "yes" || text === "1") return true;
|
|
2119
|
+
if (text === "false" || text === "no" || text === "0") return false;
|
|
2120
|
+
}
|
|
2121
|
+
if (value === 1) return true;
|
|
2122
|
+
if (value === 0) return false;
|
|
2123
|
+
return value;
|
|
2124
|
+
}
|
|
2125
|
+
case "ZodString": {
|
|
2126
|
+
if (typeof value === "string") return value;
|
|
2127
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
2128
|
+
if (value && typeof value === "object") {
|
|
2129
|
+
try {
|
|
2130
|
+
return JSON.stringify(value);
|
|
2131
|
+
} catch {
|
|
2132
|
+
return value;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
return value;
|
|
2136
|
+
}
|
|
2137
|
+
case "ZodEnum": {
|
|
2138
|
+
if (typeof value !== "string") return value;
|
|
2139
|
+
const values = def.values ?? [];
|
|
2140
|
+
if (values.includes(value)) return value;
|
|
2141
|
+
const match = values.find((option) => option.toLowerCase() === value.trim().toLowerCase());
|
|
2142
|
+
return match ?? value;
|
|
2143
|
+
}
|
|
2144
|
+
case "ZodNativeEnum": {
|
|
2145
|
+
if (typeof value !== "string") return value;
|
|
2146
|
+
const values = Object.values(def.values ?? {}).filter((option) => typeof option === "string");
|
|
2147
|
+
if (values.includes(value)) return value;
|
|
2148
|
+
return values.find((option) => option.toLowerCase() === value.trim().toLowerCase()) ?? value;
|
|
2149
|
+
}
|
|
2150
|
+
case "ZodUnion":
|
|
2151
|
+
case "ZodDiscriminatedUnion": {
|
|
2152
|
+
const options = def.options ? Array.isArray(def.options) ? def.options : Array.from(def.options.values()) : [];
|
|
2153
|
+
for (const option of options) {
|
|
2154
|
+
const candidate = coerceNode(option, value, depth + 1);
|
|
2155
|
+
if (safeParses(option, candidate)) return candidate;
|
|
2156
|
+
}
|
|
2157
|
+
return value;
|
|
2158
|
+
}
|
|
2159
|
+
default:
|
|
2160
|
+
return value;
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
function unwrapJsonString(value) {
|
|
2164
|
+
if (typeof value !== "string") return value;
|
|
2165
|
+
if (isPlaceholder(value)) return void 0;
|
|
2166
|
+
const parsed = parseJsonish(value);
|
|
2167
|
+
return parsed.ok ? parsed.value : value;
|
|
2168
|
+
}
|
|
2169
|
+
function coerceObject(def, value, depth) {
|
|
2170
|
+
const unwrapped = unwrapJsonString(value);
|
|
2171
|
+
if (!unwrapped || typeof unwrapped !== "object" || Array.isArray(unwrapped)) return unwrapped ?? value;
|
|
2172
|
+
const shape = typeof def.shape === "function" ? def.shape() : def.shape ?? {};
|
|
2173
|
+
const shapeKeys = Object.keys(shape);
|
|
2174
|
+
let source = unwrapped;
|
|
2175
|
+
if (depth === 0 && shapeKeys.length > 0) {
|
|
2176
|
+
const keys = Object.keys(source);
|
|
2177
|
+
if (keys.length === 1 && !shapeKeys.includes(keys[0]) && ENVELOPE_KEYS.includes(keys[0].toLowerCase())) {
|
|
2178
|
+
const inner = unwrapJsonString(source[keys[0]]);
|
|
2179
|
+
if (inner && typeof inner === "object" && !Array.isArray(inner)) {
|
|
2180
|
+
source = inner;
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
}
|
|
2184
|
+
const out = {};
|
|
2185
|
+
for (const [key, entry] of Object.entries(source)) {
|
|
2186
|
+
const field = shape[key];
|
|
2187
|
+
if (!field) {
|
|
2188
|
+
out[key] = entry;
|
|
2189
|
+
continue;
|
|
2190
|
+
}
|
|
2191
|
+
const coerced = coerceNode(field, entry, depth + 1);
|
|
2192
|
+
if (coerced === void 0) continue;
|
|
2193
|
+
out[key] = coerced;
|
|
2194
|
+
}
|
|
2195
|
+
return out;
|
|
2196
|
+
}
|
|
2197
|
+
|
|
2027
2198
|
// src/smart/toolResponses.ts
|
|
2028
2199
|
var CONTROL_PLANE_TOOL_NAMES = [
|
|
2029
2200
|
"response",
|
|
@@ -2226,17 +2397,60 @@ Use get_tool_response with executionId "${refId}" only if you must recover the o
|
|
|
2226
2397
|
}
|
|
2227
2398
|
function validateToolArgs(tool, args) {
|
|
2228
2399
|
const schema = tool.schema;
|
|
2229
|
-
if (!schema || typeof schema.
|
|
2400
|
+
if (!schema || typeof schema.safeParse !== "function") {
|
|
2230
2401
|
return { ok: true, value: args };
|
|
2231
2402
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
}
|
|
2239
|
-
|
|
2403
|
+
const direct = schema.safeParse(args);
|
|
2404
|
+
if (direct.success) {
|
|
2405
|
+
return { ok: true, value: direct.data };
|
|
2406
|
+
}
|
|
2407
|
+
const repaired = schema.safeParse(coerceToolArgs(schema, args));
|
|
2408
|
+
if (repaired.success) {
|
|
2409
|
+
return { ok: true, value: repaired.data, coerced: true };
|
|
2410
|
+
}
|
|
2411
|
+
const error = direct.error;
|
|
2412
|
+
if (error instanceof zod.ZodError) {
|
|
2413
|
+
const issues = error.issues.map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`).join("; ");
|
|
2414
|
+
const expected = describeExpectedArgs(schema);
|
|
2415
|
+
return { ok: false, message: expected ? `${issues}. Expected arguments: ${expected}` : issues };
|
|
2416
|
+
}
|
|
2417
|
+
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
2418
|
+
}
|
|
2419
|
+
function describeExpectedArgs(schema) {
|
|
2420
|
+
const shape = typeof schema?._def?.shape === "function" ? schema._def.shape() : schema?._def?.shape;
|
|
2421
|
+
if (!shape || typeof shape !== "object") return null;
|
|
2422
|
+
const parts = Object.entries(shape).map(([key, field]) => {
|
|
2423
|
+
const { typeName, optional } = describeField(field);
|
|
2424
|
+
return `${key}${optional ? "?" : ""}: ${typeName}`;
|
|
2425
|
+
});
|
|
2426
|
+
return parts.length > 0 ? parts.join(", ") : null;
|
|
2427
|
+
}
|
|
2428
|
+
function describeField(field, depth = 0) {
|
|
2429
|
+
const def = field?._def;
|
|
2430
|
+
if (!def || depth > 6) return { typeName: "value", optional: false };
|
|
2431
|
+
switch (def.typeName) {
|
|
2432
|
+
case "ZodOptional":
|
|
2433
|
+
case "ZodNullable":
|
|
2434
|
+
case "ZodDefault":
|
|
2435
|
+
return { typeName: describeField(def.innerType, depth + 1).typeName, optional: true };
|
|
2436
|
+
case "ZodEffects":
|
|
2437
|
+
return { ...describeField(def.schema, depth + 1), optional: describeField(def.schema, depth + 1).optional };
|
|
2438
|
+
case "ZodObject":
|
|
2439
|
+
return { typeName: "object", optional: false };
|
|
2440
|
+
case "ZodArray":
|
|
2441
|
+
return { typeName: `array of ${describeField(def.type, depth + 1).typeName}`, optional: false };
|
|
2442
|
+
case "ZodRecord":
|
|
2443
|
+
return { typeName: "object", optional: false };
|
|
2444
|
+
case "ZodString":
|
|
2445
|
+
return { typeName: "string", optional: false };
|
|
2446
|
+
case "ZodNumber":
|
|
2447
|
+
return { typeName: "number", optional: false };
|
|
2448
|
+
case "ZodBoolean":
|
|
2449
|
+
return { typeName: "boolean", optional: false };
|
|
2450
|
+
case "ZodEnum":
|
|
2451
|
+
return { typeName: `one of ${(def.values ?? []).join("|")}`, optional: false };
|
|
2452
|
+
default:
|
|
2453
|
+
return { typeName: "value", optional: false };
|
|
2240
2454
|
}
|
|
2241
2455
|
}
|
|
2242
2456
|
|
|
@@ -5095,7 +5309,10 @@ function shouldSignalSummarization(state, threshold) {
|
|
|
5095
5309
|
});
|
|
5096
5310
|
const tokenCount = countMessagesTokens(tokCountMessages);
|
|
5097
5311
|
if (tokenCount <= threshold) return "skip";
|
|
5098
|
-
if (state.ctx?.__summarizationExhausted)
|
|
5312
|
+
if (state.ctx?.__summarizationExhausted) {
|
|
5313
|
+
const exhaustedAt = state.ctx?.__summarizationExhaustedAtToolCount;
|
|
5314
|
+
if (typeof exhaustedAt !== "number" || (state.toolHistory || []).length <= exhaustedAt) return "skip";
|
|
5315
|
+
}
|
|
5099
5316
|
const hasFreshSummary = (state.messages || []).some(
|
|
5100
5317
|
(m) => m.role === "tool" && typeof m.content === "string" && (m.content === "SUMMARIZED" || m.content.startsWith("SUMMARIZED_TOOL_RESPONSE"))
|
|
5101
5318
|
);
|
|
@@ -6140,6 +6357,20 @@ function extractCanonicalFacts(messages) {
|
|
|
6140
6357
|
function isSummarizedToolPlaceholder(content) {
|
|
6141
6358
|
return typeof content === "string" && (content === "SUMMARIZED" || content.startsWith("SUMMARIZED_TOOL_RESPONSE") || content.startsWith("ARCHIVED_TOOL_RESPONSE") || content.startsWith("STRUCTURED_TOOL_RESPONSE") || content.startsWith("DROPPED_TOOL_RESPONSE"));
|
|
6142
6359
|
}
|
|
6360
|
+
function collectLatestTurnToolCallIds(messages) {
|
|
6361
|
+
const ids = /* @__PURE__ */ new Set();
|
|
6362
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6363
|
+
const m = messages[i];
|
|
6364
|
+
if (isSyntheticSummaryMessage(m)) continue;
|
|
6365
|
+
if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
|
|
6366
|
+
for (const tc of m.tool_calls) {
|
|
6367
|
+
if (tc.id) ids.add(tc.id);
|
|
6368
|
+
}
|
|
6369
|
+
break;
|
|
6370
|
+
}
|
|
6371
|
+
}
|
|
6372
|
+
return ids;
|
|
6373
|
+
}
|
|
6143
6374
|
function findToolHistoryEntry(state, toolCallId, toolName) {
|
|
6144
6375
|
const entries = [
|
|
6145
6376
|
...state.toolHistory || [],
|
|
@@ -6234,6 +6465,10 @@ function createContextSummarizeNode(opts) {
|
|
|
6234
6465
|
if (compressableMessages.length === 0) {
|
|
6235
6466
|
return {};
|
|
6236
6467
|
}
|
|
6468
|
+
const protectedToolCallIds = collectLatestTurnToolCallIds(messages);
|
|
6469
|
+
if (compressableMessages.every((m) => m.tool_call_id && protectedToolCallIds.has(m.tool_call_id))) {
|
|
6470
|
+
return {};
|
|
6471
|
+
}
|
|
6237
6472
|
const tokenCountBefore = countMessagesTokens(messages);
|
|
6238
6473
|
const summaryPromptMaxTokens = config.summaryPromptMaxTokens;
|
|
6239
6474
|
const availableTokensForConversation = summaryPromptMaxTokens - 500;
|
|
@@ -6253,7 +6488,8 @@ function createContextSummarizeNode(opts) {
|
|
|
6253
6488
|
const historyEntry = findToolHistoryEntry(state, m.tool_call_id, m.name);
|
|
6254
6489
|
if (historyEntry) {
|
|
6255
6490
|
const original = historyEntry.rawOutput ?? historyEntry.output;
|
|
6256
|
-
|
|
6491
|
+
const recovered = typeof original === "string" ? original : JSON.stringify(original);
|
|
6492
|
+
if (typeof recovered === "string") content = recovered;
|
|
6257
6493
|
}
|
|
6258
6494
|
}
|
|
6259
6495
|
const maxContentLength = 2e3;
|
|
@@ -6392,22 +6628,6 @@ ${canonicalFacts.length > 0 ? canonicalFacts.map((fact) => `- ${fact.key}: ${fac
|
|
|
6392
6628
|
});
|
|
6393
6629
|
}
|
|
6394
6630
|
});
|
|
6395
|
-
const protectedToolCallIds = /* @__PURE__ */ new Set();
|
|
6396
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6397
|
-
const m = messages[i];
|
|
6398
|
-
if (m.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0) {
|
|
6399
|
-
const thisToolCallIds = new Set(m.tool_calls.map((tc) => tc.id).filter(Boolean));
|
|
6400
|
-
const otherCompressable = compressableMessages.filter(
|
|
6401
|
-
(cm) => !thisToolCallIds.has(cm.tool_call_id)
|
|
6402
|
-
);
|
|
6403
|
-
if (otherCompressable.length > 0) {
|
|
6404
|
-
for (const tc of m.tool_calls) {
|
|
6405
|
-
if (tc.id) protectedToolCallIds.add(tc.id);
|
|
6406
|
-
}
|
|
6407
|
-
}
|
|
6408
|
-
break;
|
|
6409
|
-
}
|
|
6410
|
-
}
|
|
6411
6631
|
const retentionDeclarations = collectToolRetentionDeclarations(state.agent?.tools);
|
|
6412
6632
|
const digestableToolCallIds = /* @__PURE__ */ new Set();
|
|
6413
6633
|
for (const m of messages) {
|
|
@@ -7992,11 +8212,16 @@ function createSmartAgent(opts) {
|
|
|
7992
8212
|
if (!summarizer) return { state: currentState, rawMessages: currentRawMessages, compressed: false };
|
|
7993
8213
|
const delta = await summarizer(currentState);
|
|
7994
8214
|
if (!delta || Object.keys(delta).length === 0) {
|
|
7995
|
-
const ctx2 = {
|
|
8215
|
+
const ctx2 = {
|
|
8216
|
+
...currentState.ctx || {},
|
|
8217
|
+
__summarizationExhausted: true,
|
|
8218
|
+
__summarizationExhaustedAtToolCount: (currentState.toolHistory || []).length
|
|
8219
|
+
};
|
|
7996
8220
|
return { state: { ...currentState, ctx: ctx2 }, rawMessages: currentRawMessages, compressed: false };
|
|
7997
8221
|
}
|
|
7998
8222
|
const ctx = { ...currentState.ctx || {} };
|
|
7999
8223
|
delete ctx.__summarizationExhausted;
|
|
8224
|
+
delete ctx.__summarizationExhaustedAtToolCount;
|
|
8000
8225
|
const updated = await persistLatestSummary(syncPlanStateWith(ref, { ...currentState, ...delta, ctx }));
|
|
8001
8226
|
return { state: updated, rawMessages: [...updated.messages || currentRawMessages], compressed: true };
|
|
8002
8227
|
}
|
|
@@ -11059,6 +11284,43 @@ function convertToJsonSchema(schema, strict = false) {
|
|
|
11059
11284
|
}
|
|
11060
11285
|
return converted;
|
|
11061
11286
|
}
|
|
11287
|
+
function simplifyOptionalNullableUnions(schema, required = null) {
|
|
11288
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
11289
|
+
const clone2 = { ...schema };
|
|
11290
|
+
if (clone2.properties && typeof clone2.properties === "object") {
|
|
11291
|
+
const requiredKeys = new Set(Array.isArray(clone2.required) ? clone2.required : []);
|
|
11292
|
+
const properties = {};
|
|
11293
|
+
for (const [key, value] of Object.entries(clone2.properties)) {
|
|
11294
|
+
const child = simplifyOptionalNullableUnions(value, requiredKeys);
|
|
11295
|
+
properties[key] = requiredKeys.has(key) ? child : dropNullBranch(child);
|
|
11296
|
+
}
|
|
11297
|
+
clone2.properties = properties;
|
|
11298
|
+
}
|
|
11299
|
+
if (clone2.items) clone2.items = simplifyOptionalNullableUnions(clone2.items, required);
|
|
11300
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
11301
|
+
if (Array.isArray(clone2[key])) {
|
|
11302
|
+
clone2[key] = clone2[key].map((entry) => simplifyOptionalNullableUnions(entry, required));
|
|
11303
|
+
}
|
|
11304
|
+
}
|
|
11305
|
+
return clone2;
|
|
11306
|
+
}
|
|
11307
|
+
function dropNullBranch(schema) {
|
|
11308
|
+
if (!schema || typeof schema !== "object") return schema;
|
|
11309
|
+
if (Array.isArray(schema.type) && schema.type.includes("null") && schema.type.length === 2) {
|
|
11310
|
+
return { ...schema, type: schema.type.find((entry) => entry !== "null") };
|
|
11311
|
+
}
|
|
11312
|
+
if (Array.isArray(schema.anyOf)) {
|
|
11313
|
+
const branches = schema.anyOf.filter((entry) => entry?.type !== "null");
|
|
11314
|
+
if (branches.length === 1 && branches.length !== schema.anyOf.length) {
|
|
11315
|
+
const { anyOf, ...rest } = schema;
|
|
11316
|
+
return { ...branches[0], ...rest };
|
|
11317
|
+
}
|
|
11318
|
+
if (branches.length !== schema.anyOf.length && branches.length > 1) {
|
|
11319
|
+
return { ...schema, anyOf: branches };
|
|
11320
|
+
}
|
|
11321
|
+
}
|
|
11322
|
+
return schema;
|
|
11323
|
+
}
|
|
11062
11324
|
function normalizeStrictSchema(schema) {
|
|
11063
11325
|
if (!schema || typeof schema !== "object") return schema;
|
|
11064
11326
|
const clone2 = { ...schema };
|
|
@@ -11123,6 +11385,8 @@ function toToolDefinition(tool, strict) {
|
|
|
11123
11385
|
parameters = convertToJsonSchema(rawSchema, useStrict);
|
|
11124
11386
|
if (useStrict) {
|
|
11125
11387
|
parameters = normalizeStrictSchema(parameters);
|
|
11388
|
+
} else {
|
|
11389
|
+
parameters = simplifyOptionalNullableUnions(parameters);
|
|
11126
11390
|
}
|
|
11127
11391
|
return { name, description, parameters, ...useStrict ? { strict: true } : {} };
|
|
11128
11392
|
}
|
|
@@ -11295,6 +11559,7 @@ exports.canOpenSkill = canOpenSkill;
|
|
|
11295
11559
|
exports.canSpawn = canSpawn;
|
|
11296
11560
|
exports.captureSnapshot = captureSnapshot;
|
|
11297
11561
|
exports.codePresenceRule = codePresenceRule;
|
|
11562
|
+
exports.coerceToolArgs = coerceToolArgs;
|
|
11298
11563
|
exports.cognipeerSink = cognipeerSink;
|
|
11299
11564
|
exports.collectToolRetentionDeclarations = collectToolRetentionDeclarations;
|
|
11300
11565
|
exports.composeToolSets = composeToolSets;
|
|
@@ -11389,6 +11654,7 @@ exports.summarizeObject = summarizeObject;
|
|
|
11389
11654
|
exports.tokenize = tokenize;
|
|
11390
11655
|
exports.traceSessionToOtlp = traceSessionToOtlp;
|
|
11391
11656
|
exports.validateReasoningConfig = validateReasoningConfig;
|
|
11657
|
+
exports.validateToolArgs = validateToolArgs;
|
|
11392
11658
|
exports.withTools = withTools;
|
|
11393
11659
|
exports.withinDepth = withinDepth;
|
|
11394
11660
|
exports.writeSummaryFactsToMemory = writeSummaryFactsToMemory;
|