@genesislcap/ai-assistant 15.9.0 → 15.10.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/chat-driver.cjs +196 -7
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +196 -7
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/dts/components/chat-driver/chat-driver.invocation-scope.test.d.ts +2 -0
- package/dist/dts/components/chat-driver/chat-driver.invocation-scope.test.d.ts.map +1 -0
- package/dist/esm/components/chat-driver/chat-driver.invocation-scope.test.js +238 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -17
- package/src/components/chat-driver/chat-driver.invocation-scope.test.ts +285 -0
package/dist/chat-driver.mjs
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
// ../../../../node_modules/tslib/tslib.es6.mjs
|
|
2
|
+
function __rest(s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
}
|
|
2
13
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) {
|
|
4
15
|
return value instanceof P ? value : new P(function(resolve) {
|
|
@@ -1055,6 +1066,188 @@ function scaleTemperature(normalized, { defaultTemp, maxTemp }) {
|
|
|
1055
1066
|
return t <= DEFAULT_ANCHOR ? t / DEFAULT_ANCHOR * defaultTemp : defaultTemp + (t - DEFAULT_ANCHOR) / (1 - DEFAULT_ANCHOR) * (maxTemp - defaultTemp);
|
|
1056
1067
|
}
|
|
1057
1068
|
|
|
1069
|
+
// ../../foundation-ai/dist/esm/utils/tool-schema.js
|
|
1070
|
+
var SCHEMA_MAP_KEYS = ["properties", "patternProperties", "$defs", "definitions"];
|
|
1071
|
+
var SCHEMA_LIST_KEYS = ["anyOf", "oneOf", "allOf", "prefixItems"];
|
|
1072
|
+
var SCHEMA_VALUE_KEYS = [
|
|
1073
|
+
"items",
|
|
1074
|
+
"not",
|
|
1075
|
+
"additionalProperties",
|
|
1076
|
+
"propertyNames",
|
|
1077
|
+
"contains"
|
|
1078
|
+
];
|
|
1079
|
+
var isPlainObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
1080
|
+
function cloneValue(value) {
|
|
1081
|
+
if (Array.isArray(value))
|
|
1082
|
+
return value.map(cloneValue);
|
|
1083
|
+
if (isPlainObject2(value)) {
|
|
1084
|
+
const out = {};
|
|
1085
|
+
for (const [k, v] of Object.entries(value))
|
|
1086
|
+
out[k] = cloneValue(v);
|
|
1087
|
+
return out;
|
|
1088
|
+
}
|
|
1089
|
+
return value;
|
|
1090
|
+
}
|
|
1091
|
+
function mapChildSchemas(node, visit, path) {
|
|
1092
|
+
const out = {};
|
|
1093
|
+
for (const [key, value] of Object.entries(node)) {
|
|
1094
|
+
const here = `${path}/${key}`;
|
|
1095
|
+
if (SCHEMA_MAP_KEYS.includes(key) && isPlainObject2(value)) {
|
|
1096
|
+
out[key] = Object.fromEntries(Object.entries(value).map(([name, child]) => [
|
|
1097
|
+
name,
|
|
1098
|
+
isPlainObject2(child) ? visit(child, `${here}/${name}`) : cloneValue(child)
|
|
1099
|
+
]));
|
|
1100
|
+
} else if (SCHEMA_LIST_KEYS.includes(key) && Array.isArray(value)) {
|
|
1101
|
+
out[key] = value.map((child, i) => isPlainObject2(child) ? visit(child, `${here}/${i}`) : cloneValue(child));
|
|
1102
|
+
} else if (SCHEMA_VALUE_KEYS.includes(key)) {
|
|
1103
|
+
if (isPlainObject2(value))
|
|
1104
|
+
out[key] = visit(value, here);
|
|
1105
|
+
else if (Array.isArray(value))
|
|
1106
|
+
out[key] = value.map((child, i) => isPlainObject2(child) ? visit(child, `${here}/${i}`) : cloneValue(child));
|
|
1107
|
+
else
|
|
1108
|
+
out[key] = cloneValue(value);
|
|
1109
|
+
} else {
|
|
1110
|
+
out[key] = cloneValue(value);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
return out;
|
|
1114
|
+
}
|
|
1115
|
+
function mapSchema(node, transform, path = "") {
|
|
1116
|
+
return transform(mapChildSchemas(node, (child, childPath) => mapSchema(child, transform, childPath), path), path);
|
|
1117
|
+
}
|
|
1118
|
+
var UNENFORCEABLE_KEYWORDS = [
|
|
1119
|
+
"minimum",
|
|
1120
|
+
"maximum",
|
|
1121
|
+
"exclusiveMinimum",
|
|
1122
|
+
"exclusiveMaximum",
|
|
1123
|
+
"multipleOf",
|
|
1124
|
+
"maxItems",
|
|
1125
|
+
"uniqueItems",
|
|
1126
|
+
"minProperties",
|
|
1127
|
+
"maxProperties"
|
|
1128
|
+
];
|
|
1129
|
+
var UNDROPPABLE_KEYWORDS = ["oneOf", "not"];
|
|
1130
|
+
function toEnforcedAnthropicSchema(parameters) {
|
|
1131
|
+
const stripped = [];
|
|
1132
|
+
const overridden = [];
|
|
1133
|
+
const undroppable = [];
|
|
1134
|
+
const schema = mapSchema(parameters, (node, path) => {
|
|
1135
|
+
for (const keyword of UNENFORCEABLE_KEYWORDS) {
|
|
1136
|
+
if (keyword in node) {
|
|
1137
|
+
delete node[keyword];
|
|
1138
|
+
stripped.push(`${path}/${keyword}`);
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (typeof node.minItems === "number" && node.minItems > 1) {
|
|
1142
|
+
delete node.minItems;
|
|
1143
|
+
stripped.push(`${path}/minItems`);
|
|
1144
|
+
}
|
|
1145
|
+
for (const keyword of UNDROPPABLE_KEYWORDS) {
|
|
1146
|
+
if (keyword in node)
|
|
1147
|
+
undroppable.push(`${path}/${keyword}`);
|
|
1148
|
+
}
|
|
1149
|
+
const isObjectNode = node.type === "object" || Array.isArray(node.type) && node.type.includes("object") || isPlainObject2(node.properties);
|
|
1150
|
+
if (isObjectNode) {
|
|
1151
|
+
if (node.additionalProperties !== false) {
|
|
1152
|
+
if (node.additionalProperties !== void 0) {
|
|
1153
|
+
overridden.push(`${path}/additionalProperties`);
|
|
1154
|
+
}
|
|
1155
|
+
node.additionalProperties = false;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return node;
|
|
1159
|
+
});
|
|
1160
|
+
return { schema, stripped, overridden, undroppable };
|
|
1161
|
+
}
|
|
1162
|
+
function enforceAnthropicToolSchema(parameters, toolName) {
|
|
1163
|
+
const { schema, stripped, overridden, undroppable } = toEnforcedAnthropicSchema(parameters);
|
|
1164
|
+
if (stripped.length) {
|
|
1165
|
+
logger.warn(`AnthropicTransport: tool "${toolName}" requested schema enforcement; these keywords cannot be enforced and were removed \u2014 validate them yourself: ${stripped.join(", ")}`);
|
|
1166
|
+
}
|
|
1167
|
+
if (overridden.length) {
|
|
1168
|
+
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.`);
|
|
1169
|
+
}
|
|
1170
|
+
if (undroppable.length) {
|
|
1171
|
+
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.`);
|
|
1172
|
+
}
|
|
1173
|
+
return schema;
|
|
1174
|
+
}
|
|
1175
|
+
var GEMINI_UNSUPPORTED_KEYWORDS = [
|
|
1176
|
+
"additionalProperties",
|
|
1177
|
+
"examples",
|
|
1178
|
+
"multipleOf",
|
|
1179
|
+
"patternProperties",
|
|
1180
|
+
// Both spellings of the definitions block. `$defs` would also fall to the
|
|
1181
|
+
// `$`-prefix sweep below, but the draft-07 spelling has no `$` and would
|
|
1182
|
+
// otherwise survive inlining and 400 the request — so list the pair together.
|
|
1183
|
+
"$defs",
|
|
1184
|
+
"definitions"
|
|
1185
|
+
];
|
|
1186
|
+
function resolvePointer(root, ref) {
|
|
1187
|
+
if (!ref.startsWith("#/"))
|
|
1188
|
+
return void 0;
|
|
1189
|
+
let current = root;
|
|
1190
|
+
for (const segment of ref.slice(2).split("/")) {
|
|
1191
|
+
if (!isPlainObject2(current))
|
|
1192
|
+
return void 0;
|
|
1193
|
+
current = current[segment.replace(/~1/g, "/").replace(/~0/g, "~")];
|
|
1194
|
+
}
|
|
1195
|
+
return isPlainObject2(current) ? current : void 0;
|
|
1196
|
+
}
|
|
1197
|
+
function inlineRefs(root, node, seen, unresolved) {
|
|
1198
|
+
let current = node;
|
|
1199
|
+
let visited = seen;
|
|
1200
|
+
let ref = typeof current.$ref === "string" ? current.$ref : void 0;
|
|
1201
|
+
while (ref && !visited.has(ref)) {
|
|
1202
|
+
const target = resolvePointer(root, ref);
|
|
1203
|
+
if (!target)
|
|
1204
|
+
break;
|
|
1205
|
+
const { $ref: _dropped } = current, siblings = __rest(current, ["$ref"]);
|
|
1206
|
+
current = Object.assign(Object.assign({}, cloneValue(target)), siblings);
|
|
1207
|
+
visited = /* @__PURE__ */ new Set([...visited, ref]);
|
|
1208
|
+
ref = typeof current.$ref === "string" ? current.$ref : void 0;
|
|
1209
|
+
}
|
|
1210
|
+
if (typeof current.$ref === "string")
|
|
1211
|
+
unresolved.push(current.$ref);
|
|
1212
|
+
return mapChildSchemas(current, (child) => inlineRefs(root, child, visited, unresolved), "");
|
|
1213
|
+
}
|
|
1214
|
+
function toGeminiSchema(parameters) {
|
|
1215
|
+
const unresolved = [];
|
|
1216
|
+
const inlined = inlineRefs(parameters, parameters, /* @__PURE__ */ new Set(), unresolved);
|
|
1217
|
+
if (unresolved.length) {
|
|
1218
|
+
logger.warn(`GeminiTransport: these \`$ref\` pointers could not be inlined \u2014 a cycle, a typo, or an external ref: ${[...new Set(unresolved)].join(", ")}. They are left in the schema, so Gemini will reject this declaration; that is deliberate, because dropping them would send a node that constrains nothing.`);
|
|
1219
|
+
}
|
|
1220
|
+
const translated = mapSchema(inlined, (node) => {
|
|
1221
|
+
if (Array.isArray(node.type)) {
|
|
1222
|
+
const types = node.type.filter((t) => t !== "null");
|
|
1223
|
+
if (types.length === 1 && node.type.length !== types.length) {
|
|
1224
|
+
node.type = types[0];
|
|
1225
|
+
node.nullable = true;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
if (Array.isArray(node.anyOf)) {
|
|
1229
|
+
const branches = node.anyOf.filter(isPlainObject2);
|
|
1230
|
+
const nonNull = branches.filter((b) => b.type !== "null");
|
|
1231
|
+
if (branches.length === 2 && nonNull.length === 1) {
|
|
1232
|
+
const { anyOf: _dropped } = node, siblings = __rest(node, ["anyOf"]);
|
|
1233
|
+
return Object.assign(Object.assign(Object.assign({}, nonNull[0]), siblings), { nullable: true });
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
if ("const" in node) {
|
|
1237
|
+
node.enum = [node.const];
|
|
1238
|
+
delete node.const;
|
|
1239
|
+
}
|
|
1240
|
+
for (const keyword of GEMINI_UNSUPPORTED_KEYWORDS)
|
|
1241
|
+
delete node[keyword];
|
|
1242
|
+
for (const key of Object.keys(node)) {
|
|
1243
|
+
if (key.startsWith("$") && key !== "$ref")
|
|
1244
|
+
delete node[key];
|
|
1245
|
+
}
|
|
1246
|
+
return node;
|
|
1247
|
+
});
|
|
1248
|
+
return translated;
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1058
1251
|
// ../../foundation-ai/dist/esm/utils/abort-reason.js
|
|
1059
1252
|
function authoritativeAbortReason(error, timeoutSignal, callerSignal) {
|
|
1060
1253
|
const abortShaped = (error instanceof DOMException || error instanceof Error) && (error.name === "AbortError" || error.name === "TimeoutError");
|
|
@@ -1405,11 +1598,7 @@ var AnthropicTransport = class _AnthropicTransport {
|
|
|
1405
1598
|
if (options === null || options === void 0 ? void 0 : options.systemPrompt)
|
|
1406
1599
|
body.system = options.systemPrompt;
|
|
1407
1600
|
if ((_a = options === null || options === void 0 ? void 0 : options.tools) === null || _a === void 0 ? void 0 : _a.length) {
|
|
1408
|
-
body.tools = options.tools.map((t) => ({
|
|
1409
|
-
name: t.name,
|
|
1410
|
-
description: t.description,
|
|
1411
|
-
input_schema: t.parameters
|
|
1412
|
-
}));
|
|
1601
|
+
body.tools = options.tools.map((t) => Object.assign({ name: t.name, description: t.description, input_schema: t.enforceSchema ? enforceAnthropicToolSchema(t.parameters, t.name) : t.parameters }, t.enforceSchema ? { strict: true } : {}));
|
|
1413
1602
|
}
|
|
1414
1603
|
if ((_b = body.tools) === null || _b === void 0 ? void 0 : _b.length) {
|
|
1415
1604
|
const toolChoice = toAnthropicToolChoice(options === null || options === void 0 ? void 0 : options.toolChoice);
|
|
@@ -2059,7 +2248,7 @@ var GeminiTransport = class _GeminiTransport {
|
|
|
2059
2248
|
functionDeclarations: options.tools.map((t) => ({
|
|
2060
2249
|
name: t.name,
|
|
2061
2250
|
description: t.description,
|
|
2062
|
-
parameters: t.parameters
|
|
2251
|
+
parameters: toGeminiSchema(t.parameters)
|
|
2063
2252
|
}))
|
|
2064
2253
|
}
|
|
2065
2254
|
] : void 0;
|
|
@@ -2082,7 +2271,7 @@ var GeminiTransport = class _GeminiTransport {
|
|
|
2082
2271
|
systemInstruction,
|
|
2083
2272
|
toolConfig,
|
|
2084
2273
|
generationConfig
|
|
2085
|
-
}, applyResponseSchema ? { responseSchema: options.responseSchema } : {}), options === null || options === void 0 ? void 0 : options.signal);
|
|
2274
|
+
}, applyResponseSchema ? { responseSchema: toGeminiSchema(options.responseSchema) } : {}), options === null || options === void 0 ? void 0 : options.signal);
|
|
2086
2275
|
return this.fromGeminiResponse(response, offeredToolNames);
|
|
2087
2276
|
});
|
|
2088
2277
|
}
|