@ax-llm/ax 11.0.7 → 11.0.9
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/index.cjs +49 -21
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -2
- package/index.d.ts +1 -2
- package/index.js +49 -21
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -905,7 +905,8 @@ var AxBaseAI = class {
|
|
|
905
905
|
const startTime = performance.now();
|
|
906
906
|
let isError = false;
|
|
907
907
|
try {
|
|
908
|
-
|
|
908
|
+
const result = await this._chat1(req, options);
|
|
909
|
+
return result;
|
|
909
910
|
} catch (error) {
|
|
910
911
|
isError = true;
|
|
911
912
|
throw error;
|
|
@@ -958,13 +959,31 @@ var AxBaseAI = class {
|
|
|
958
959
|
}
|
|
959
960
|
return await this._chat2(model, modelConfig, req, options);
|
|
960
961
|
}
|
|
962
|
+
cleanupFunctionSchema(fn) {
|
|
963
|
+
const cleanFn = { ...fn };
|
|
964
|
+
if (cleanFn.parameters) {
|
|
965
|
+
const cleanParams = { ...cleanFn.parameters };
|
|
966
|
+
if (Array.isArray(cleanParams.required) && cleanParams.required.length === 0) {
|
|
967
|
+
delete cleanParams.required;
|
|
968
|
+
}
|
|
969
|
+
if (cleanParams.properties && Object.keys(cleanParams.properties).length === 0) {
|
|
970
|
+
delete cleanParams.properties;
|
|
971
|
+
}
|
|
972
|
+
if (Object.keys(cleanParams).length === 0 || Object.keys(cleanParams).length === 1 && cleanParams.type === "object") {
|
|
973
|
+
delete cleanFn.parameters;
|
|
974
|
+
} else {
|
|
975
|
+
cleanFn.parameters = cleanParams;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
return cleanFn;
|
|
979
|
+
}
|
|
961
980
|
async _chat2(model, modelConfig, chatReq, options, span) {
|
|
962
981
|
if (!this.aiImpl.createChatReq) {
|
|
963
982
|
throw new Error("generateChatReq not implemented");
|
|
964
983
|
}
|
|
965
984
|
let functions;
|
|
966
985
|
if (chatReq.functions && chatReq.functions.length > 0) {
|
|
967
|
-
functions = chatReq.functions;
|
|
986
|
+
functions = chatReq.functions.map((fn2) => this.cleanupFunctionSchema(fn2));
|
|
968
987
|
}
|
|
969
988
|
const req = {
|
|
970
989
|
...chatReq,
|
|
@@ -2657,7 +2676,7 @@ var safetySettings = [
|
|
|
2657
2676
|
}
|
|
2658
2677
|
];
|
|
2659
2678
|
var axAIGoogleGeminiDefaultConfig = () => structuredClone({
|
|
2660
|
-
model: "gemini-
|
|
2679
|
+
model: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2661
2680
|
embedModel: "text-embedding-004" /* TextEmbedding004 */,
|
|
2662
2681
|
safetySettings,
|
|
2663
2682
|
...axBaseAIDefaultConfig()
|
|
@@ -4596,6 +4615,9 @@ var LRUCache = class {
|
|
|
4596
4615
|
};
|
|
4597
4616
|
var globalPrefixCache = new LRUCache(500);
|
|
4598
4617
|
function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPrefixCache) {
|
|
4618
|
+
if (/^\s*$/.test(content)) {
|
|
4619
|
+
return -3;
|
|
4620
|
+
}
|
|
4599
4621
|
const exactMatchIndex = content.indexOf(prefix, startIndex);
|
|
4600
4622
|
if (exactMatchIndex !== -1) {
|
|
4601
4623
|
return exactMatchIndex;
|
|
@@ -5320,6 +5342,9 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
|
|
|
5320
5342
|
// Field is not found, continue to the next field
|
|
5321
5343
|
case -2:
|
|
5322
5344
|
return true;
|
|
5345
|
+
// Partial match at end, skip and gather more content
|
|
5346
|
+
case -3:
|
|
5347
|
+
return true;
|
|
5323
5348
|
}
|
|
5324
5349
|
let prefixLen = prefix.length;
|
|
5325
5350
|
if (xstate.currField) {
|
|
@@ -6103,14 +6128,20 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
|
|
|
6103
6128
|
injectionKeys
|
|
6104
6129
|
);
|
|
6105
6130
|
const originalFunc = processedFunction.func;
|
|
6106
|
-
processedFunction.func = (childArgs, funcOptions) =>
|
|
6107
|
-
{
|
|
6131
|
+
processedFunction.func = (childArgs, funcOptions) => {
|
|
6132
|
+
const updatedChildArgs = {
|
|
6108
6133
|
...childArgs,
|
|
6109
6134
|
...pick(parentValues, injectionKeys)
|
|
6110
|
-
}
|
|
6111
|
-
|
|
6112
|
-
|
|
6135
|
+
};
|
|
6136
|
+
if (options.debug && injectionKeys.length > 0) {
|
|
6137
|
+
process.stdout.write(
|
|
6138
|
+
`Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
|
|
6139
|
+
);
|
|
6140
|
+
}
|
|
6141
|
+
return originalFunc(updatedChildArgs, funcOptions);
|
|
6142
|
+
};
|
|
6113
6143
|
}
|
|
6144
|
+
return processedFunction;
|
|
6114
6145
|
}
|
|
6115
6146
|
if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
|
|
6116
6147
|
processedFunction.parameters = addModelParameter(
|
|
@@ -6122,14 +6153,12 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
|
|
|
6122
6153
|
}
|
|
6123
6154
|
var AxAgent = class {
|
|
6124
6155
|
ai;
|
|
6125
|
-
signature;
|
|
6126
6156
|
program;
|
|
6127
6157
|
functions;
|
|
6128
6158
|
agents;
|
|
6129
6159
|
disableSmartModelRouting;
|
|
6130
6160
|
excludeFieldsFromPassthrough;
|
|
6131
6161
|
name;
|
|
6132
|
-
description;
|
|
6133
6162
|
subAgentList;
|
|
6134
6163
|
func;
|
|
6135
6164
|
constructor({
|
|
@@ -6145,8 +6174,8 @@ var AxAgent = class {
|
|
|
6145
6174
|
this.functions = functions;
|
|
6146
6175
|
this.disableSmartModelRouting = options?.disableSmartModelRouting;
|
|
6147
6176
|
this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
|
|
6148
|
-
|
|
6149
|
-
|
|
6177
|
+
const sig = new AxSignature(signature);
|
|
6178
|
+
sig.setDescription(description);
|
|
6150
6179
|
if (!name || name.length < 5) {
|
|
6151
6180
|
throw new Error(
|
|
6152
6181
|
`Agent name must be at least 10 characters (more descriptive): ${name}`
|
|
@@ -6157,17 +6186,16 @@ var AxAgent = class {
|
|
|
6157
6186
|
`Agent description must be at least 20 characters (explain in detail what the agent does): ${description}`
|
|
6158
6187
|
);
|
|
6159
6188
|
}
|
|
6160
|
-
this.program = new AxGen(
|
|
6189
|
+
this.program = new AxGen(sig, options);
|
|
6161
6190
|
for (const agent of agents ?? []) {
|
|
6162
6191
|
this.program.register(agent);
|
|
6163
6192
|
}
|
|
6164
6193
|
this.name = name;
|
|
6165
|
-
this.description = description;
|
|
6166
6194
|
this.subAgentList = agents?.map((a) => a.getFunction().name).join(", ");
|
|
6167
6195
|
this.func = {
|
|
6168
6196
|
name: toCamelCase(this.name),
|
|
6169
|
-
description
|
|
6170
|
-
parameters:
|
|
6197
|
+
description,
|
|
6198
|
+
parameters: sig.toJSONSchema(),
|
|
6171
6199
|
func: () => this.forward
|
|
6172
6200
|
};
|
|
6173
6201
|
const mm = ai?.getModelList();
|
|
@@ -6223,11 +6251,12 @@ var AxAgent = class {
|
|
|
6223
6251
|
init(parentAi, values, options) {
|
|
6224
6252
|
const ai = this.ai ?? parentAi;
|
|
6225
6253
|
const mm = ai?.getModelList();
|
|
6226
|
-
const parentSchema = this.
|
|
6227
|
-
const parentKeys = parentSchema.
|
|
6254
|
+
const parentSchema = this.program.getSignature().getInputFields();
|
|
6255
|
+
const parentKeys = parentSchema.map((p) => p.name);
|
|
6228
6256
|
const agentFuncs = this.agents?.map((agent) => {
|
|
6229
6257
|
const f = agent.getFeatures();
|
|
6230
6258
|
const processOptions = {
|
|
6259
|
+
debug: ai?.getOptions()?.debug ?? false,
|
|
6231
6260
|
disableSmartModelRouting: !!this.disableSmartModelRouting,
|
|
6232
6261
|
excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
|
|
6233
6262
|
canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
|
|
@@ -6270,8 +6299,7 @@ var AxAgent = class {
|
|
|
6270
6299
|
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6271
6300
|
);
|
|
6272
6301
|
}
|
|
6273
|
-
this.description
|
|
6274
|
-
this.signature.setDescription(description);
|
|
6302
|
+
this.program.getSignature().setDescription(description);
|
|
6275
6303
|
this.func.description = description;
|
|
6276
6304
|
}
|
|
6277
6305
|
};
|
|
@@ -6298,7 +6326,7 @@ function addModelParameter(parameters, models) {
|
|
|
6298
6326
|
const modelProperty = {
|
|
6299
6327
|
type: "string",
|
|
6300
6328
|
enum: models.map((m) => m.key),
|
|
6301
|
-
description: `The AI model to use for this function call. Available options: ${models.map((m) =>
|
|
6329
|
+
description: `The AI model to use for this function call. Available options: ${models.map((m) => `\`${m.key}\` ${m.description}`).join(", ")}`
|
|
6302
6330
|
};
|
|
6303
6331
|
const newProperties = {
|
|
6304
6332
|
...baseSchema.properties ?? {},
|