@ax-llm/ax 11.0.6 → 11.0.8
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 +118 -9
- package/index.cjs.map +1 -1
- package/index.d.cts +25 -0
- package/index.d.ts +25 -0
- package/index.js +118 -9
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -2657,7 +2657,7 @@ var safetySettings = [
|
|
|
2657
2657
|
}
|
|
2658
2658
|
];
|
|
2659
2659
|
var axAIGoogleGeminiDefaultConfig = () => structuredClone({
|
|
2660
|
-
model: "gemini-
|
|
2660
|
+
model: "gemini-2.0-flash" /* Gemini20Flash */,
|
|
2661
2661
|
embedModel: "text-embedding-004" /* TextEmbedding004 */,
|
|
2662
2662
|
safetySettings,
|
|
2663
2663
|
...axBaseAIDefaultConfig()
|
|
@@ -4596,6 +4596,9 @@ var LRUCache = class {
|
|
|
4596
4596
|
};
|
|
4597
4597
|
var globalPrefixCache = new LRUCache(500);
|
|
4598
4598
|
function matchesContent(content, prefix, startIndex = 0, prefixCache = globalPrefixCache) {
|
|
4599
|
+
if (/^\s*$/.test(content)) {
|
|
4600
|
+
return -3;
|
|
4601
|
+
}
|
|
4599
4602
|
const exactMatchIndex = content.indexOf(prefix, startIndex);
|
|
4600
4603
|
if (exactMatchIndex !== -1) {
|
|
4601
4604
|
return exactMatchIndex;
|
|
@@ -5320,6 +5323,9 @@ var streamingExtractValues = (sig, values, xstate, content, streamingValidation
|
|
|
5320
5323
|
// Field is not found, continue to the next field
|
|
5321
5324
|
case -2:
|
|
5322
5325
|
return true;
|
|
5326
|
+
// Partial match at end, skip and gather more content
|
|
5327
|
+
case -3:
|
|
5328
|
+
return true;
|
|
5323
5329
|
}
|
|
5324
5330
|
let prefixLen = prefix.length;
|
|
5325
5331
|
if (xstate.currField) {
|
|
@@ -6089,6 +6095,43 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6089
6095
|
};
|
|
6090
6096
|
|
|
6091
6097
|
// prompts/agent.ts
|
|
6098
|
+
function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
|
|
6099
|
+
let processedFunction = { ...childFunction };
|
|
6100
|
+
if (processedFunction.parameters) {
|
|
6101
|
+
const childKeys = processedFunction.parameters.properties ? Object.keys(processedFunction.parameters.properties) : [];
|
|
6102
|
+
const commonKeys = parentInputKeys.filter((key) => childKeys.includes(key)).filter((key) => key !== "model");
|
|
6103
|
+
const injectionKeys = commonKeys.filter(
|
|
6104
|
+
(key) => !options.excludeFieldsFromPassthrough.includes(key)
|
|
6105
|
+
);
|
|
6106
|
+
if (injectionKeys.length > 0) {
|
|
6107
|
+
processedFunction.parameters = removePropertiesFromSchema(
|
|
6108
|
+
processedFunction.parameters,
|
|
6109
|
+
injectionKeys
|
|
6110
|
+
);
|
|
6111
|
+
const originalFunc = processedFunction.func;
|
|
6112
|
+
processedFunction.func = (childArgs, funcOptions) => {
|
|
6113
|
+
const updatedChildArgs = {
|
|
6114
|
+
...childArgs,
|
|
6115
|
+
...pick(parentValues, injectionKeys)
|
|
6116
|
+
};
|
|
6117
|
+
if (options.debug && injectionKeys.length > 0) {
|
|
6118
|
+
process.stdout.write(
|
|
6119
|
+
`Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`
|
|
6120
|
+
);
|
|
6121
|
+
}
|
|
6122
|
+
return originalFunc(updatedChildArgs, funcOptions);
|
|
6123
|
+
};
|
|
6124
|
+
}
|
|
6125
|
+
return processedFunction;
|
|
6126
|
+
}
|
|
6127
|
+
if (modelList && !options.disableSmartModelRouting && options.canConfigureSmartModelRouting) {
|
|
6128
|
+
processedFunction.parameters = addModelParameter(
|
|
6129
|
+
processedFunction.parameters,
|
|
6130
|
+
modelList
|
|
6131
|
+
);
|
|
6132
|
+
}
|
|
6133
|
+
return processedFunction;
|
|
6134
|
+
}
|
|
6092
6135
|
var AxAgent = class {
|
|
6093
6136
|
ai;
|
|
6094
6137
|
signature;
|
|
@@ -6096,6 +6139,7 @@ var AxAgent = class {
|
|
|
6096
6139
|
functions;
|
|
6097
6140
|
agents;
|
|
6098
6141
|
disableSmartModelRouting;
|
|
6142
|
+
excludeFieldsFromPassthrough;
|
|
6099
6143
|
name;
|
|
6100
6144
|
description;
|
|
6101
6145
|
subAgentList;
|
|
@@ -6112,6 +6156,7 @@ var AxAgent = class {
|
|
|
6112
6156
|
this.agents = agents;
|
|
6113
6157
|
this.functions = functions;
|
|
6114
6158
|
this.disableSmartModelRouting = options?.disableSmartModelRouting;
|
|
6159
|
+
this.excludeFieldsFromPassthrough = options?.excludeFieldsFromPassthrough ?? [];
|
|
6115
6160
|
this.signature = new AxSignature(signature);
|
|
6116
6161
|
this.signature.setDescription(description);
|
|
6117
6162
|
if (!name || name.length < 5) {
|
|
@@ -6180,15 +6225,34 @@ var AxAgent = class {
|
|
|
6180
6225
|
}
|
|
6181
6226
|
getFeatures() {
|
|
6182
6227
|
return {
|
|
6183
|
-
canConfigureSmartModelRouting: this.ai
|
|
6228
|
+
canConfigureSmartModelRouting: this.ai === void 0,
|
|
6229
|
+
excludeFieldsFromPassthrough: this.excludeFieldsFromPassthrough
|
|
6184
6230
|
};
|
|
6185
6231
|
}
|
|
6186
|
-
|
|
6232
|
+
/**
|
|
6233
|
+
* Initializes the agent's execution context, processing child agents and their functions.
|
|
6234
|
+
*/
|
|
6235
|
+
init(parentAi, values, options) {
|
|
6187
6236
|
const ai = this.ai ?? parentAi;
|
|
6188
6237
|
const mm = ai?.getModelList();
|
|
6189
|
-
const
|
|
6190
|
-
|
|
6191
|
-
)
|
|
6238
|
+
const parentSchema = this.signature.getInputFields();
|
|
6239
|
+
const parentKeys = parentSchema.map((p) => p.name);
|
|
6240
|
+
const agentFuncs = this.agents?.map((agent) => {
|
|
6241
|
+
const f = agent.getFeatures();
|
|
6242
|
+
const processOptions = {
|
|
6243
|
+
debug: ai?.getOptions()?.debug ?? false,
|
|
6244
|
+
disableSmartModelRouting: !!this.disableSmartModelRouting,
|
|
6245
|
+
excludeFieldsFromPassthrough: f.excludeFieldsFromPassthrough,
|
|
6246
|
+
canConfigureSmartModelRouting: f.canConfigureSmartModelRouting
|
|
6247
|
+
};
|
|
6248
|
+
return processChildAgentFunction(
|
|
6249
|
+
agent.getFunction(),
|
|
6250
|
+
values,
|
|
6251
|
+
parentKeys,
|
|
6252
|
+
mm,
|
|
6253
|
+
processOptions
|
|
6254
|
+
);
|
|
6255
|
+
});
|
|
6192
6256
|
const functions = [
|
|
6193
6257
|
...options?.functions ?? this.functions ?? [],
|
|
6194
6258
|
...agentFuncs ?? []
|
|
@@ -6196,16 +6260,33 @@ var AxAgent = class {
|
|
|
6196
6260
|
return { ai, functions };
|
|
6197
6261
|
}
|
|
6198
6262
|
async forward(parentAi, values, options) {
|
|
6199
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6263
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6200
6264
|
return await this.program.forward(ai, values, { ...options, functions });
|
|
6201
6265
|
}
|
|
6202
6266
|
async *streamingForward(parentAi, values, options) {
|
|
6203
|
-
const { ai, functions } = this.init(parentAi, options);
|
|
6267
|
+
const { ai, functions } = this.init(parentAi, values, options);
|
|
6204
6268
|
return yield* this.program.streamingForward(ai, values, {
|
|
6205
6269
|
...options,
|
|
6206
6270
|
functions
|
|
6207
6271
|
});
|
|
6208
6272
|
}
|
|
6273
|
+
/**
|
|
6274
|
+
* Updates the agent's description.
|
|
6275
|
+
* This updates both the stored description and the function's description.
|
|
6276
|
+
*
|
|
6277
|
+
* @param description - New description for the agent (must be at least 20 characters)
|
|
6278
|
+
* @throws Error if description is too short
|
|
6279
|
+
*/
|
|
6280
|
+
setDescription(description) {
|
|
6281
|
+
if (!description || description.length < 20) {
|
|
6282
|
+
throw new Error(
|
|
6283
|
+
"Agent description must be at least 20 characters (explain in detail what the agent does)"
|
|
6284
|
+
);
|
|
6285
|
+
}
|
|
6286
|
+
this.description = description;
|
|
6287
|
+
this.signature.setDescription(description);
|
|
6288
|
+
this.func.description = description;
|
|
6289
|
+
}
|
|
6209
6290
|
};
|
|
6210
6291
|
function toCamelCase(inputString) {
|
|
6211
6292
|
const words = inputString.split(/[^a-zA-Z0-9]/);
|
|
@@ -6230,7 +6311,7 @@ function addModelParameter(parameters, models) {
|
|
|
6230
6311
|
const modelProperty = {
|
|
6231
6312
|
type: "string",
|
|
6232
6313
|
enum: models.map((m) => m.key),
|
|
6233
|
-
description: `The AI model to use for this function call. Available options: ${models.map((m) =>
|
|
6314
|
+
description: `The AI model to use for this function call. Available options: ${models.map((m) => `\`${m.key}\` ${m.description}`).join(", ")}`
|
|
6234
6315
|
};
|
|
6235
6316
|
const newProperties = {
|
|
6236
6317
|
...baseSchema.properties ?? {},
|
|
@@ -6243,6 +6324,34 @@ function addModelParameter(parameters, models) {
|
|
|
6243
6324
|
required: newRequired
|
|
6244
6325
|
};
|
|
6245
6326
|
}
|
|
6327
|
+
function removePropertiesFromSchema(schema, keys) {
|
|
6328
|
+
const newSchema = structuredClone(schema);
|
|
6329
|
+
if (newSchema.properties) {
|
|
6330
|
+
for (const key of keys) {
|
|
6331
|
+
delete newSchema.properties[key];
|
|
6332
|
+
}
|
|
6333
|
+
}
|
|
6334
|
+
if (Array.isArray(newSchema.required)) {
|
|
6335
|
+
const filteredRequired = newSchema.required.filter(
|
|
6336
|
+
(r) => !keys.includes(r)
|
|
6337
|
+
);
|
|
6338
|
+
Object.defineProperty(newSchema, "required", {
|
|
6339
|
+
value: filteredRequired,
|
|
6340
|
+
writable: true,
|
|
6341
|
+
configurable: true
|
|
6342
|
+
});
|
|
6343
|
+
}
|
|
6344
|
+
return newSchema;
|
|
6345
|
+
}
|
|
6346
|
+
function pick(obj, keys) {
|
|
6347
|
+
const result = {};
|
|
6348
|
+
for (const key of keys) {
|
|
6349
|
+
if (key in obj) {
|
|
6350
|
+
result[key] = obj[key];
|
|
6351
|
+
}
|
|
6352
|
+
}
|
|
6353
|
+
return result;
|
|
6354
|
+
}
|
|
6246
6355
|
|
|
6247
6356
|
// docs/tika.ts
|
|
6248
6357
|
var import_node_fs = require("fs");
|