@genesislcap/ai-assistant 15.7.1 → 15.7.2-GENC-1480.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,17 @@ __export(chat_driver_node_exports, {
46
46
  module.exports = __toCommonJS(chat_driver_node_exports);
47
47
 
48
48
  // ../../../../node_modules/tslib/tslib.es6.mjs
49
+ function __rest(s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ }
49
60
  function __awaiter(thisArg, _arguments, P, generator) {
50
61
  function adopt(value) {
51
62
  return value instanceof P ? value : new P(function(resolve) {
@@ -1102,6 +1113,178 @@ function scaleTemperature(normalized, { defaultTemp, maxTemp }) {
1102
1113
  return t <= DEFAULT_ANCHOR ? t / DEFAULT_ANCHOR * defaultTemp : defaultTemp + (t - DEFAULT_ANCHOR) / (1 - DEFAULT_ANCHOR) * (maxTemp - defaultTemp);
1103
1114
  }
1104
1115
 
1116
+ // ../../foundation-ai/dist/esm/utils/tool-schema.js
1117
+ var SCHEMA_MAP_KEYS = ["properties", "patternProperties", "$defs", "definitions"];
1118
+ var SCHEMA_LIST_KEYS = ["anyOf", "oneOf", "allOf", "prefixItems"];
1119
+ var SCHEMA_VALUE_KEYS = [
1120
+ "items",
1121
+ "not",
1122
+ "additionalProperties",
1123
+ "propertyNames",
1124
+ "contains"
1125
+ ];
1126
+ var isPlainObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
1127
+ function cloneValue(value) {
1128
+ if (Array.isArray(value))
1129
+ return value.map(cloneValue);
1130
+ if (isPlainObject2(value)) {
1131
+ const out = {};
1132
+ for (const [k, v] of Object.entries(value))
1133
+ out[k] = cloneValue(v);
1134
+ return out;
1135
+ }
1136
+ return value;
1137
+ }
1138
+ function mapChildSchemas(node, visit, path) {
1139
+ const out = {};
1140
+ for (const [key, value] of Object.entries(node)) {
1141
+ const here = `${path}/${key}`;
1142
+ if (SCHEMA_MAP_KEYS.includes(key) && isPlainObject2(value)) {
1143
+ out[key] = Object.fromEntries(Object.entries(value).map(([name, child]) => [
1144
+ name,
1145
+ isPlainObject2(child) ? visit(child, `${here}/${name}`) : cloneValue(child)
1146
+ ]));
1147
+ } else if (SCHEMA_LIST_KEYS.includes(key) && Array.isArray(value)) {
1148
+ out[key] = value.map((child, i) => isPlainObject2(child) ? visit(child, `${here}/${i}`) : cloneValue(child));
1149
+ } else if (SCHEMA_VALUE_KEYS.includes(key)) {
1150
+ if (isPlainObject2(value))
1151
+ out[key] = visit(value, here);
1152
+ else if (Array.isArray(value))
1153
+ out[key] = value.map((child, i) => isPlainObject2(child) ? visit(child, `${here}/${i}`) : cloneValue(child));
1154
+ else
1155
+ out[key] = cloneValue(value);
1156
+ } else {
1157
+ out[key] = cloneValue(value);
1158
+ }
1159
+ }
1160
+ return out;
1161
+ }
1162
+ function mapSchema(node, transform, path = "") {
1163
+ return transform(mapChildSchemas(node, (child, childPath) => mapSchema(child, transform, childPath), path), path);
1164
+ }
1165
+ var UNENFORCEABLE_KEYWORDS = [
1166
+ "minimum",
1167
+ "maximum",
1168
+ "exclusiveMinimum",
1169
+ "exclusiveMaximum",
1170
+ "multipleOf",
1171
+ "maxItems",
1172
+ "uniqueItems",
1173
+ "minProperties",
1174
+ "maxProperties"
1175
+ ];
1176
+ var UNDROPPABLE_KEYWORDS = ["oneOf", "not"];
1177
+ function toEnforcedAnthropicSchema(parameters) {
1178
+ const stripped = [];
1179
+ const overridden = [];
1180
+ const undroppable = [];
1181
+ const schema = mapSchema(parameters, (node, path) => {
1182
+ for (const keyword of UNENFORCEABLE_KEYWORDS) {
1183
+ if (keyword in node) {
1184
+ delete node[keyword];
1185
+ stripped.push(`${path}/${keyword}`);
1186
+ }
1187
+ }
1188
+ if (typeof node.minItems === "number" && node.minItems > 1) {
1189
+ delete node.minItems;
1190
+ stripped.push(`${path}/minItems`);
1191
+ }
1192
+ for (const keyword of UNDROPPABLE_KEYWORDS) {
1193
+ if (keyword in node)
1194
+ undroppable.push(`${path}/${keyword}`);
1195
+ }
1196
+ if (node.type === "object" || isPlainObject2(node.properties)) {
1197
+ if (node.additionalProperties !== false) {
1198
+ if (node.additionalProperties !== void 0)
1199
+ overridden.push(`${path}/additionalProperties`);
1200
+ node.additionalProperties = false;
1201
+ }
1202
+ }
1203
+ return node;
1204
+ });
1205
+ return { schema, stripped, overridden, undroppable };
1206
+ }
1207
+ function enforcedAnthropicSchema(parameters, toolName) {
1208
+ const { schema, stripped, overridden, undroppable } = toEnforcedAnthropicSchema(parameters);
1209
+ if (stripped.length) {
1210
+ logger.warn(`AnthropicTransport: tool "${toolName}" requested schema enforcement; these keywords cannot be enforced and were removed \u2014 validate them yourself: ${stripped.join(", ")}`);
1211
+ }
1212
+ if (overridden.length) {
1213
+ logger.warn(`AnthropicTransport: tool "${toolName}" requested schema enforcement, which requires closed objects; \`additionalProperties\` was set to false at: ${overridden.join(", ")}. The tool now accepts fewer inputs than its schema declared.`);
1214
+ }
1215
+ if (undroppable.length) {
1216
+ logger.warn(`AnthropicTransport: tool "${toolName}" uses schema keywords enforcement cannot express (${undroppable.join(", ")}). They cannot be removed without changing the schema's meaning, so the request will be rejected. Rewrite them or drop enforceSchema for this tool.`);
1217
+ }
1218
+ return schema;
1219
+ }
1220
+ var GEMINI_UNSUPPORTED_KEYWORDS = [
1221
+ "additionalProperties",
1222
+ "examples",
1223
+ "multipleOf",
1224
+ "patternProperties",
1225
+ // Both spellings of the definitions block. `$defs` would also fall to the
1226
+ // `$`-prefix sweep below, but the draft-07 spelling has no `$` and would
1227
+ // otherwise survive inlining and 400 the request — so list the pair together.
1228
+ "$defs",
1229
+ "definitions"
1230
+ ];
1231
+ function resolvePointer(root, ref) {
1232
+ if (!ref.startsWith("#/"))
1233
+ return void 0;
1234
+ let current = root;
1235
+ for (const segment of ref.slice(2).split("/")) {
1236
+ if (!isPlainObject2(current))
1237
+ return void 0;
1238
+ current = current[segment.replace(/~1/g, "/").replace(/~0/g, "~")];
1239
+ }
1240
+ return isPlainObject2(current) ? current : void 0;
1241
+ }
1242
+ function inlineRefs(root, node, seen) {
1243
+ let current = node;
1244
+ let visited = seen;
1245
+ const ref = typeof current.$ref === "string" ? current.$ref : void 0;
1246
+ if (ref && !visited.has(ref)) {
1247
+ const target = resolvePointer(root, ref);
1248
+ if (target) {
1249
+ const { $ref: _dropped } = current, siblings = __rest(current, ["$ref"]);
1250
+ current = Object.assign(Object.assign({}, cloneValue(target)), siblings);
1251
+ visited = /* @__PURE__ */ new Set([...visited, ref]);
1252
+ }
1253
+ }
1254
+ return mapChildSchemas(current, (child) => inlineRefs(root, child, visited), "");
1255
+ }
1256
+ function toGeminiSchema(parameters) {
1257
+ const inlined = inlineRefs(parameters, parameters, /* @__PURE__ */ new Set());
1258
+ const translated = mapSchema(inlined, (node) => {
1259
+ if (Array.isArray(node.type)) {
1260
+ const types = node.type.filter((t) => t !== "null");
1261
+ if (types.length === 1 && node.type.length !== types.length) {
1262
+ node.type = types[0];
1263
+ node.nullable = true;
1264
+ }
1265
+ }
1266
+ if (Array.isArray(node.anyOf)) {
1267
+ const branches = node.anyOf.filter(isPlainObject2);
1268
+ const nonNull = branches.filter((b) => b.type !== "null");
1269
+ if (branches.length === 2 && nonNull.length === 1) {
1270
+ const { anyOf: _dropped } = node, siblings = __rest(node, ["anyOf"]);
1271
+ return Object.assign(Object.assign(Object.assign({}, nonNull[0]), siblings), { nullable: true });
1272
+ }
1273
+ }
1274
+ if ("const" in node) {
1275
+ node.enum = [node.const];
1276
+ delete node.const;
1277
+ }
1278
+ for (const keyword of GEMINI_UNSUPPORTED_KEYWORDS)
1279
+ delete node[keyword];
1280
+ for (const key of Object.keys(node))
1281
+ if (key.startsWith("$"))
1282
+ delete node[key];
1283
+ return node;
1284
+ });
1285
+ return translated;
1286
+ }
1287
+
1105
1288
  // ../../foundation-ai/dist/esm/utils/abort-reason.js
1106
1289
  function authoritativeAbortReason(error, timeoutSignal, callerSignal) {
1107
1290
  const abortShaped = (error instanceof DOMException || error instanceof Error) && (error.name === "AbortError" || error.name === "TimeoutError");
@@ -1440,11 +1623,7 @@ var AnthropicTransport = class _AnthropicTransport {
1440
1623
  if (options === null || options === void 0 ? void 0 : options.systemPrompt)
1441
1624
  body.system = options.systemPrompt;
1442
1625
  if ((_a = options === null || options === void 0 ? void 0 : options.tools) === null || _a === void 0 ? void 0 : _a.length) {
1443
- body.tools = options.tools.map((t) => ({
1444
- name: t.name,
1445
- description: t.description,
1446
- input_schema: t.parameters
1447
- }));
1626
+ body.tools = options.tools.map((t) => Object.assign({ name: t.name, description: t.description, input_schema: t.enforceSchema ? enforcedAnthropicSchema(t.parameters, t.name) : t.parameters }, t.enforceSchema ? { strict: true } : {}));
1448
1627
  }
1449
1628
  if ((_b = body.tools) === null || _b === void 0 ? void 0 : _b.length) {
1450
1629
  const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
@@ -2094,7 +2273,7 @@ var GeminiTransport = class _GeminiTransport {
2094
2273
  functionDeclarations: options.tools.map((t) => ({
2095
2274
  name: t.name,
2096
2275
  description: t.description,
2097
- parameters: t.parameters
2276
+ parameters: toGeminiSchema(t.parameters)
2098
2277
  }))
2099
2278
  }
2100
2279
  ] : void 0;
@@ -2117,7 +2296,7 @@ var GeminiTransport = class _GeminiTransport {
2117
2296
  systemInstruction,
2118
2297
  toolConfig,
2119
2298
  generationConfig
2120
- }, applyResponseSchema ? { responseSchema: options.responseSchema } : {}), options === null || options === void 0 ? void 0 : options.signal);
2299
+ }, applyResponseSchema ? { responseSchema: toGeminiSchema(options.responseSchema) } : {}), options === null || options === void 0 ? void 0 : options.signal);
2121
2300
  return this.fromGeminiResponse(response, offeredToolNames);
2122
2301
  });
2123
2302
  }