@ax-llm/ax 11.0.58 → 11.0.60
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 +66 -61
- package/index.cjs.map +1 -1
- package/index.d.cts +231 -241
- package/index.d.ts +231 -241
- package/index.js +65 -61
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -116,6 +116,7 @@ __export(index_exports, {
|
|
|
116
116
|
AxPromptTemplate: () => AxPromptTemplate,
|
|
117
117
|
AxRAG: () => AxRAG,
|
|
118
118
|
AxRateLimiterTokenUsage: () => AxRateLimiterTokenUsage,
|
|
119
|
+
AxRewriter: () => AxRewriter,
|
|
119
120
|
AxSignature: () => AxSignature,
|
|
120
121
|
AxSimpleClassifier: () => AxSimpleClassifier,
|
|
121
122
|
AxSimpleClassifierClass: () => AxSimpleClassifierClass,
|
|
@@ -1202,6 +1203,9 @@ var AxBaseAI = class {
|
|
|
1202
1203
|
`Model ${model} does not support thinkingTokenBudget.`
|
|
1203
1204
|
);
|
|
1204
1205
|
}
|
|
1206
|
+
if (options?.showThoughts && !this.getFeatures(model).hasShowThoughts) {
|
|
1207
|
+
throw new Error(`Model ${model} does not support showThoughts.`);
|
|
1208
|
+
}
|
|
1205
1209
|
modelConfig.stream = (options?.stream !== void 0 ? options.stream : modelConfig.stream) ?? true;
|
|
1206
1210
|
const canStream = this.getFeatures(model).streaming;
|
|
1207
1211
|
if (!canStream) {
|
|
@@ -1310,13 +1314,6 @@ var AxBaseAI = class {
|
|
|
1310
1314
|
const wrappedRespFn = (state) => (resp) => {
|
|
1311
1315
|
const res2 = respFn(resp, state);
|
|
1312
1316
|
res2.sessionId = options?.sessionId;
|
|
1313
|
-
if (options?.hideThought) {
|
|
1314
|
-
res2.results.forEach((result) => {
|
|
1315
|
-
if (result.thought) {
|
|
1316
|
-
result.thought = void 0;
|
|
1317
|
-
}
|
|
1318
|
-
});
|
|
1319
|
-
}
|
|
1320
1317
|
if (!res2.modelUsage) {
|
|
1321
1318
|
res2.modelUsage = {
|
|
1322
1319
|
ai: this.name,
|
|
@@ -1355,13 +1352,6 @@ var AxBaseAI = class {
|
|
|
1355
1352
|
}
|
|
1356
1353
|
const res = this.aiImpl.createChatResp(rv);
|
|
1357
1354
|
res.sessionId = options?.sessionId;
|
|
1358
|
-
if (options?.hideThought) {
|
|
1359
|
-
res.results.forEach((result) => {
|
|
1360
|
-
if (result.thought) {
|
|
1361
|
-
result.thought = void 0;
|
|
1362
|
-
}
|
|
1363
|
-
});
|
|
1364
|
-
}
|
|
1365
1355
|
if (!res.modelUsage) {
|
|
1366
1356
|
const tokenUsage = this.aiImpl.getTokenUsage();
|
|
1367
1357
|
if (tokenUsage) {
|
|
@@ -1582,7 +1572,14 @@ function setChatResponseEvents(res, span, excludeContentFromTrace) {
|
|
|
1582
1572
|
if (!res.results) {
|
|
1583
1573
|
return;
|
|
1584
1574
|
}
|
|
1585
|
-
for (
|
|
1575
|
+
for (let index = 0; index < res.results.length; index++) {
|
|
1576
|
+
const result = res.results[index];
|
|
1577
|
+
if (!result) {
|
|
1578
|
+
continue;
|
|
1579
|
+
}
|
|
1580
|
+
if (!result.content && !result.thought && !result.functionCalls?.length && !result.finishReason) {
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
1586
1583
|
const toolCalls = result.functionCalls?.map((call) => {
|
|
1587
1584
|
return {
|
|
1588
1585
|
id: call.id,
|
|
@@ -3497,6 +3494,9 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3497
3494
|
break;
|
|
3498
3495
|
}
|
|
3499
3496
|
}
|
|
3497
|
+
if (config.showThoughts !== void 0) {
|
|
3498
|
+
thinkingConfig.includeThoughts = config.showThoughts;
|
|
3499
|
+
}
|
|
3500
3500
|
const generationConfig = {
|
|
3501
3501
|
maxOutputTokens: req.modelConfig?.maxTokens ?? this.config.maxTokens,
|
|
3502
3502
|
temperature: req.modelConfig?.temperature ?? this.config.temperature,
|
|
@@ -4285,7 +4285,7 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4285
4285
|
}
|
|
4286
4286
|
return items;
|
|
4287
4287
|
}
|
|
4288
|
-
createChatReq(req,
|
|
4288
|
+
createChatReq(req, config) {
|
|
4289
4289
|
const model = req.model;
|
|
4290
4290
|
const apiConfig = { name: "/responses" };
|
|
4291
4291
|
let instructionsFromPrompt = null;
|
|
@@ -4308,6 +4308,10 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4308
4308
|
parameters: v.parameters ?? {}
|
|
4309
4309
|
})
|
|
4310
4310
|
);
|
|
4311
|
+
const includeFields = [];
|
|
4312
|
+
if (config.showThoughts) {
|
|
4313
|
+
includeFields.push("reasoning.encrypted_content");
|
|
4314
|
+
}
|
|
4311
4315
|
let mutableReq = {
|
|
4312
4316
|
model,
|
|
4313
4317
|
input: "",
|
|
@@ -4322,7 +4326,7 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4322
4326
|
// Sourced from modelConfig or global config
|
|
4323
4327
|
// Optional fields from AxAIOpenAIResponsesRequest that need to be in Mutable for initialization
|
|
4324
4328
|
background: void 0,
|
|
4325
|
-
include: void 0,
|
|
4329
|
+
include: includeFields.length > 0 ? includeFields : void 0,
|
|
4326
4330
|
metadata: void 0,
|
|
4327
4331
|
parallel_tool_calls: this.config.parallelToolCalls,
|
|
4328
4332
|
previous_response_id: void 0,
|
|
@@ -4395,9 +4399,13 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4395
4399
|
break;
|
|
4396
4400
|
case "reasoning":
|
|
4397
4401
|
currentResult.id = item.id;
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4402
|
+
if (item.encrypted_content) {
|
|
4403
|
+
currentResult.thought = item.encrypted_content;
|
|
4404
|
+
} else {
|
|
4405
|
+
currentResult.thought = item.summary.map(
|
|
4406
|
+
(s) => typeof s === "object" ? JSON.stringify(s) : s
|
|
4407
|
+
).join("\n");
|
|
4408
|
+
}
|
|
4401
4409
|
break;
|
|
4402
4410
|
case "file_search_call":
|
|
4403
4411
|
currentResult.id = item.id;
|
|
@@ -4715,7 +4723,9 @@ var AxAIOpenAIResponsesImpl = class {
|
|
|
4715
4723
|
{
|
|
4716
4724
|
const reasoningItem = event.item;
|
|
4717
4725
|
baseResult.id = event.item.id;
|
|
4718
|
-
if (reasoningItem.
|
|
4726
|
+
if (reasoningItem.encrypted_content) {
|
|
4727
|
+
baseResult.thought = reasoningItem.encrypted_content;
|
|
4728
|
+
} else if (reasoningItem.summary) {
|
|
4719
4729
|
baseResult.thought = reasoningItem.summary.map(
|
|
4720
4730
|
(s) => typeof s === "object" ? JSON.stringify(s) : s
|
|
4721
4731
|
).join("\n");
|
|
@@ -6156,24 +6166,11 @@ ${outputFields}`);
|
|
|
6156
6166
|
);
|
|
6157
6167
|
messageContent = userMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
|
|
6158
6168
|
} else if (message.role === "assistant") {
|
|
6159
|
-
const
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
if (value !== void 0 && value !== null && (typeof value === "string" ? value !== "" : true)) {
|
|
6165
|
-
const renderedValue = processValue(field, value);
|
|
6166
|
-
assistantContentParts.push(`${field.name}: ${renderedValue}`);
|
|
6167
|
-
} else {
|
|
6168
|
-
const isThoughtField = field.name === this.thoughtFieldName;
|
|
6169
|
-
if (!field.isOptional && !field.isInternal && !isThoughtField) {
|
|
6170
|
-
throw new Error(
|
|
6171
|
-
`Value for output field '${field.name}' ('${field.title}') is required in assistant message history but was not found or was empty.`
|
|
6172
|
-
);
|
|
6173
|
-
}
|
|
6174
|
-
}
|
|
6175
|
-
}
|
|
6176
|
-
messageContent = assistantContentParts.join("\n");
|
|
6169
|
+
const assistantMsgParts = this.renderInputFields(
|
|
6170
|
+
message.values
|
|
6171
|
+
// Cast message.values (AxGenIn) to T (which extends AxGenIn)
|
|
6172
|
+
);
|
|
6173
|
+
messageContent = assistantMsgParts.map((part) => part.type === "text" ? part.text : "").join("").trim();
|
|
6177
6174
|
}
|
|
6178
6175
|
if (messageContent) {
|
|
6179
6176
|
if (lastRole === message.role && userMessages.length > 0) {
|
|
@@ -8162,7 +8159,8 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
8162
8159
|
stream,
|
|
8163
8160
|
functions: _functions,
|
|
8164
8161
|
functionCall: _functionCall,
|
|
8165
|
-
thinkingTokenBudget
|
|
8162
|
+
thinkingTokenBudget,
|
|
8163
|
+
showThoughts
|
|
8166
8164
|
} = options ?? {};
|
|
8167
8165
|
const chatPrompt = mem?.history(sessionId) ?? [];
|
|
8168
8166
|
if (chatPrompt.length === 0) {
|
|
@@ -8188,6 +8186,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
8188
8186
|
stream,
|
|
8189
8187
|
debug: false,
|
|
8190
8188
|
thinkingTokenBudget,
|
|
8189
|
+
showThoughts,
|
|
8191
8190
|
traceContext,
|
|
8192
8191
|
abortSignal: options?.abortSignal
|
|
8193
8192
|
}
|
|
@@ -8602,6 +8601,7 @@ Content: ${result.content}`
|
|
|
8602
8601
|
...funcNames ? { provided_functions: funcNames } : {},
|
|
8603
8602
|
...options?.model ? { model: options.model } : {},
|
|
8604
8603
|
...options?.thinkingTokenBudget ? { thinking_token_budget: options.thinkingTokenBudget } : {},
|
|
8604
|
+
...options?.showThoughts ? { show_thoughts: options.showThoughts } : {},
|
|
8605
8605
|
...options?.maxSteps ? { max_steps: options.maxSteps } : {},
|
|
8606
8606
|
...options?.maxRetries ? { max_retries: options.maxRetries } : {},
|
|
8607
8607
|
...options?.fastFail ? { fast_fail: options.fastFail } : {}
|
|
@@ -10213,6 +10213,23 @@ var getTopInPercent = (entries, percent = 0.1) => {
|
|
|
10213
10213
|
return sortedEntries.slice(0, topTenPercentCount);
|
|
10214
10214
|
};
|
|
10215
10215
|
|
|
10216
|
+
// docs/rewriter.ts
|
|
10217
|
+
var AxDefaultQueryRewriter = class extends AxGen {
|
|
10218
|
+
constructor(options) {
|
|
10219
|
+
const signature = `"You are a query rewriter assistant tasked with rewriting a given query to improve its clarity, specificity, and relevance. Your role involves analyzing the query to identify any ambiguities, generalizations, or irrelevant information and then rephrasing it to make it more focused and precise. The rewritten query should be concise, easy to understand, and directly related to the original query. Output only the rewritten query."
|
|
10220
|
+
query: string -> rewrittenQuery: string`;
|
|
10221
|
+
super(signature, options);
|
|
10222
|
+
}
|
|
10223
|
+
};
|
|
10224
|
+
var AxRewriter = class extends AxGen {
|
|
10225
|
+
constructor(options) {
|
|
10226
|
+
super(
|
|
10227
|
+
'"Rewrite a given text to be clear and concise" original -> rewritten "improved text"',
|
|
10228
|
+
options
|
|
10229
|
+
);
|
|
10230
|
+
}
|
|
10231
|
+
};
|
|
10232
|
+
|
|
10216
10233
|
// funcs/docker.ts
|
|
10217
10234
|
var AxDockerSession = class {
|
|
10218
10235
|
apiUrl;
|
|
@@ -11846,15 +11863,6 @@ var AxChainOfThought = class extends AxGen {
|
|
|
11846
11863
|
}
|
|
11847
11864
|
};
|
|
11848
11865
|
|
|
11849
|
-
// docs/rewriter.ts
|
|
11850
|
-
var AxDefaultQueryRewriter = class extends AxGen {
|
|
11851
|
-
constructor(options) {
|
|
11852
|
-
const signature = `"You are a query rewriter assistant tasked with rewriting a given query to improve its clarity, specificity, and relevance. Your role involves analyzing the query to identify any ambiguities, generalizations, or irrelevant information and then rephrasing it to make it more focused and precise. The rewritten query should be concise, easy to understand, and directly related to the original query. Output only the rewritten query."
|
|
11853
|
-
query: string -> rewrittenQuery: string`;
|
|
11854
|
-
super(signature, options);
|
|
11855
|
-
}
|
|
11856
|
-
};
|
|
11857
|
-
|
|
11858
11866
|
// dsp/strutil.ts
|
|
11859
11867
|
var trimNonAlphaNum = (str) => {
|
|
11860
11868
|
return str.replace(/^\W+|\W+$/g, "");
|
|
@@ -13688,20 +13696,16 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
13688
13696
|
this.register(this.genQuery);
|
|
13689
13697
|
}
|
|
13690
13698
|
async forward(ai, { question }, options) {
|
|
13699
|
+
let hop = 0;
|
|
13691
13700
|
let context3 = [];
|
|
13692
|
-
|
|
13693
|
-
const
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
question
|
|
13698
|
-
},
|
|
13699
|
-
options
|
|
13700
|
-
);
|
|
13701
|
-
const val = await this.queryFn(query);
|
|
13702
|
-
context3 = AxStringUtil.dedup([...context3, val]);
|
|
13701
|
+
while (hop < this.maxHops) {
|
|
13702
|
+
const query = await this.genQuery.forward(ai, { context: context3, question });
|
|
13703
|
+
const queryResult = await this.queryFn(query.query);
|
|
13704
|
+
context3 = AxStringUtil.dedup([...context3, queryResult]);
|
|
13705
|
+
hop++;
|
|
13703
13706
|
}
|
|
13704
|
-
|
|
13707
|
+
const res = await super.forward(ai, { context: context3, question }, options);
|
|
13708
|
+
return res;
|
|
13705
13709
|
}
|
|
13706
13710
|
};
|
|
13707
13711
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -13792,6 +13796,7 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
13792
13796
|
AxPromptTemplate,
|
|
13793
13797
|
AxRAG,
|
|
13794
13798
|
AxRateLimiterTokenUsage,
|
|
13799
|
+
AxRewriter,
|
|
13795
13800
|
AxSignature,
|
|
13796
13801
|
AxSimpleClassifier,
|
|
13797
13802
|
AxSimpleClassifierClass,
|