@ax-llm/ax 12.0.14 → 12.0.16

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 CHANGED
@@ -6298,9 +6298,10 @@ var MemoryImpl = class {
6298
6298
  }
6299
6299
  }
6300
6300
  };
6301
- if (!lastItem || lastItem.role !== "assistant") {
6301
+ if (!lastItem || lastItem.role !== "assistant" || lastItem.role === "assistant" && !lastItem.updatable) {
6302
6302
  this.data.push({
6303
6303
  role: "assistant",
6304
+ updatable: true,
6304
6305
  chat: [
6305
6306
  { index, value: structuredClone({ content, name, functionCalls }) }
6306
6307
  ]
@@ -6317,13 +6318,16 @@ var MemoryImpl = class {
6317
6318
  log();
6318
6319
  return;
6319
6320
  }
6320
- if ("content" in chat.value && typeof content === "string" && content.trim() !== "") {
6321
+ if (typeof content === "string" && content.trim() !== "") {
6322
+ ;
6321
6323
  chat.value.content = content;
6322
6324
  }
6323
- if ("name" in chat.value && name && name.trim() !== "") {
6325
+ if (typeof name === "string" && name.trim() !== "") {
6326
+ ;
6324
6327
  chat.value.name = name;
6325
6328
  }
6326
- if ("functionCalls" in chat.value && functionCalls && functionCalls.length > 0) {
6329
+ if (Array.isArray(functionCalls) && functionCalls.length > 0) {
6330
+ ;
6327
6331
  chat.value.functionCalls = functionCalls;
6328
6332
  }
6329
6333
  log();
@@ -7710,6 +7714,22 @@ function parseFunctionCalls(ai, functionCalls, values, model) {
7710
7714
  }));
7711
7715
  return funcs;
7712
7716
  }
7717
+ function createFunctionConfig(functionList, definedFunctionCall, firstStep) {
7718
+ let functionCall = definedFunctionCall;
7719
+ if (!firstStep && (functionCall === "required" || typeof functionCall === "function")) {
7720
+ return { functions: [], functionCall: void 0 };
7721
+ }
7722
+ if (!functionList) {
7723
+ return { functions: [], functionCall };
7724
+ }
7725
+ const functions = functionList.map((f2) => {
7726
+ if ("toFunction" in f2) {
7727
+ return f2.toFunction();
7728
+ }
7729
+ return f2;
7730
+ }).flat();
7731
+ return { functions, functionCall };
7732
+ }
7713
7733
 
7714
7734
  // dsp/processResponse.ts
7715
7735
  var import_web5 = require("stream/web");
@@ -10158,7 +10178,8 @@ var AxGen = class extends AxProgramWithSignature {
10158
10178
  mem,
10159
10179
  options,
10160
10180
  traceContext,
10161
- firstStep
10181
+ functions,
10182
+ functionCall
10162
10183
  }) {
10163
10184
  const {
10164
10185
  sessionId,
@@ -10166,8 +10187,6 @@ var AxGen = class extends AxProgramWithSignature {
10166
10187
  model,
10167
10188
  rateLimiter,
10168
10189
  stream,
10169
- functions: _functions,
10170
- functionCall: _functionCall,
10171
10190
  thinkingTokenBudget,
10172
10191
  showThoughts
10173
10192
  } = options ?? {};
@@ -10178,11 +10197,6 @@ var AxGen = class extends AxProgramWithSignature {
10178
10197
  if (chatPrompt.length === 0) {
10179
10198
  throw new Error("No chat prompt found");
10180
10199
  }
10181
- const functions = _functions?.map((f2) => "toFunction" in f2 ? f2.toFunction() : f2)?.flat();
10182
- let functionCall = _functionCall ?? this.options?.functionCall;
10183
- if (!firstStep && (functionCall === "required" || typeof functionCall === "function")) {
10184
- functionCall = void 0;
10185
- }
10186
10200
  const modelConfig = {
10187
10201
  ...options?.modelConfig,
10188
10202
  ...options?.sampleCount ? { n: options.sampleCount } : {},
@@ -10219,18 +10233,24 @@ var AxGen = class extends AxProgramWithSignature {
10219
10233
  span,
10220
10234
  traceContext
10221
10235
  }) {
10222
- const { sessionId, traceId, functions: _functions } = options ?? {};
10236
+ const { sessionId, traceId, functions: functionList } = options ?? {};
10237
+ const definedFunctionCall = options?.functionCall ?? this.options?.functionCall;
10223
10238
  const strictMode = options?.strictMode ?? false;
10224
10239
  const model = options.model;
10225
10240
  const states = this.createStates(options.sampleCount ?? 1);
10226
10241
  const usage = this.usage;
10227
- const functions = _functions?.map((f2) => "toFunction" in f2 ? f2.toFunction() : f2)?.flat() ?? [];
10242
+ const { functions, functionCall } = createFunctionConfig(
10243
+ functionList,
10244
+ definedFunctionCall,
10245
+ firstStep
10246
+ );
10228
10247
  const res = await this.forwardSendRequest({
10229
10248
  ai,
10230
10249
  mem,
10231
10250
  options,
10232
10251
  traceContext,
10233
- firstStep
10252
+ functions,
10253
+ functionCall
10234
10254
  });
10235
10255
  if (res instanceof import_web6.ReadableStream) {
10236
10256
  yield* processStreamingResponse({