@stackfactor/agent-utils 1.0.8 → 1.0.11

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.
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAwaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAyqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA5hBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAi1BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAj5B8B,GAAG,KAAG,MAAM;;AA48BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAyqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA5hBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAi1BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAj5B8B,GAAG,KAAG,MAAM;;AA48BzD,wBAOE"}
@@ -50,11 +50,10 @@ CRITICAL - Your response must be valid JSON. Escape ALL special characters in st
50
50
  Do NOT include raw newlines, tabs, or unescaped quotes inside JSON string values.
51
51
  `.trim();
52
52
  const REPORT_PROGRESS_TOOL = `
53
- ---
54
- ### Report Progress to User
55
- BEFORE EACH task or step CALL the tool report_progress with:
56
- message: brief description of work you plan to do that makes sense for individuals in Learning and Development or Business Strategy roles. Don't include JSON word in any of the messages.
57
- percent: cumulative completion percentage with values between {minPercent}% and {maxPercent}%. Don't report percentage completion outside of this range.
53
+ Report Progress to User
54
+ Before each task or step, call the tool report_progress with:
55
+ message: brief description of work you plan to do that makes sense for individuals in Learning and Development or Business Strategy roles. Don't include the word JSON in any of the messages.
56
+ percent: cumulative completion percentage with values between {minPercent}% and {maxPercent}%. Don't report percentage completion outside of this range.
58
57
  `;
59
58
  /**
60
59
  * Converts a Zod validation error object into a human-readable multi-line string.
@@ -265,10 +264,12 @@ const safeJsonParse = (line) => {
265
264
  * @returns A LangChain tool instance configured with a Zod schema for `{ stage, message, percent }`
266
265
  */
267
266
  const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => langchain_1.default.tool(async ({ stage, message, percent }) => {
267
+ let clampedPct = 0;
268
268
  try {
269
- // Clamp percent to be within minPercent and maxPercent bounds
270
- const rawPct = typeof percent === "number" ? percent : 0;
271
- const clampedPct = Math.max(minPercent, Math.min(maxPercent, rawPct));
269
+ // Coerce percent to number and clamp to be within minPercent and maxPercent bounds
270
+ const rawPct = typeof percent === "number" ? percent : parseFloat(percent) || 0;
271
+ clampedPct = Math.max(minPercent, Math.min(maxPercent, rawPct));
272
+ // NOTE: Monotonicity is not enforced here; implement if needed per session/context.
272
273
  if (onProgress &&
273
274
  minPercent <= clampedPct &&
274
275
  clampedPct <= maxPercent) {
@@ -277,6 +278,8 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
277
278
  message: message,
278
279
  });
279
280
  }
281
+ }
282
+ finally {
280
283
  return JSON.stringify({
281
284
  acknowledged: true,
282
285
  receivedAt: Date.now(),
@@ -284,12 +287,6 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
284
287
  percent: clampedPct,
285
288
  });
286
289
  }
287
- catch (err) {
288
- return JSON.stringify({
289
- acknowledged: false,
290
- error: err?.message || String(err),
291
- });
292
- }
293
290
  }, {
294
291
  name: "report_progress",
295
292
  description: `Mandatory after each phase: call with {stage, message, percent}. Percent must be between ${minPercent} and ${maxPercent} and monotonically increase.`,
@@ -298,8 +295,6 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
298
295
  message: zod_1.z.string().describe("Progress message to display"),
299
296
  percent: zod_1.z
300
297
  .number()
301
- .min(minPercent)
302
- .max(maxPercent)
303
298
  .describe(`Progress percentage (${minPercent}-${maxPercent})`),
304
299
  }),
305
300
  });
@@ -1 +1 @@
1
- {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAwaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAyqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA5hBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAi1BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAj5B8B,GAAG,KAAG,MAAM;;AA48BzD,wBAOE"}
1
+ {"version":3,"file":"langChain.d.ts","sourceRoot":"","sources":["../../src/langChain.ts"],"names":[],"mappings":";wBAoaQ,MAAM,aACD,MAAM,gBACH,MAAM,SACb,GAAG,EAAE,kBACI,GAAG,UACX,GAAG,qBACO,QAAQ,GAAG,IAAI,eACrB,MAAM,eACN,MAAM,KACjB,GAAG;sBAyCG,GAAG,UACF,MAAM,UACN,GAAG,eACC,QAAQ,GAAG,IAAI,KAC1B,OAAO,CAAC,GAAG,CAAC;wCAyqBF,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,KACpB,GAAG;oCA5hBO,MAAM,UACT,GAAG,UACH,GAAG,oBACO,GAAG,eACT,MAAM,eACN,MAAM,wBACG,OAAO,WACpB,GAAG,cACA,MAAM,UACV,GAAG,EAAE,KACX,OAAO,CAAC,GAAG,CAAC;sDAi1BF,MAAM,UACT,GAAG,UACH,MAAM,YACL,GAAG,KACX,OAAO,CAAC,GAAG,CAAC;0CAj5B8B,GAAG,KAAG,MAAM;;AA48BzD,wBAOE"}
@@ -45,11 +45,10 @@ CRITICAL - Your response must be valid JSON. Escape ALL special characters in st
45
45
  Do NOT include raw newlines, tabs, or unescaped quotes inside JSON string values.
46
46
  `.trim();
47
47
  const REPORT_PROGRESS_TOOL = `
48
- ---
49
- ### Report Progress to User
50
- BEFORE EACH task or step CALL the tool report_progress with:
51
- message: brief description of work you plan to do that makes sense for individuals in Learning and Development or Business Strategy roles. Don't include JSON word in any of the messages.
52
- percent: cumulative completion percentage with values between {minPercent}% and {maxPercent}%. Don't report percentage completion outside of this range.
48
+ Report Progress to User
49
+ Before each task or step, call the tool report_progress with:
50
+ message: brief description of work you plan to do that makes sense for individuals in Learning and Development or Business Strategy roles. Don't include the word JSON in any of the messages.
51
+ percent: cumulative completion percentage with values between {minPercent}% and {maxPercent}%. Don't report percentage completion outside of this range.
53
52
  `;
54
53
  /**
55
54
  * Converts a Zod validation error object into a human-readable multi-line string.
@@ -260,10 +259,12 @@ const safeJsonParse = (line) => {
260
259
  * @returns A LangChain tool instance configured with a Zod schema for `{ stage, message, percent }`
261
260
  */
262
261
  const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => langChain.tool(async ({ stage, message, percent }) => {
262
+ let clampedPct = 0;
263
263
  try {
264
- // Clamp percent to be within minPercent and maxPercent bounds
265
- const rawPct = typeof percent === "number" ? percent : 0;
266
- const clampedPct = Math.max(minPercent, Math.min(maxPercent, rawPct));
264
+ // Coerce percent to number and clamp to be within minPercent and maxPercent bounds
265
+ const rawPct = typeof percent === "number" ? percent : parseFloat(percent) || 0;
266
+ clampedPct = Math.max(minPercent, Math.min(maxPercent, rawPct));
267
+ // NOTE: Monotonicity is not enforced here; implement if needed per session/context.
267
268
  if (onProgress &&
268
269
  minPercent <= clampedPct &&
269
270
  clampedPct <= maxPercent) {
@@ -272,6 +273,8 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
272
273
  message: message,
273
274
  });
274
275
  }
276
+ }
277
+ finally {
275
278
  return JSON.stringify({
276
279
  acknowledged: true,
277
280
  receivedAt: Date.now(),
@@ -279,12 +282,6 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
279
282
  percent: clampedPct,
280
283
  });
281
284
  }
282
- catch (err) {
283
- return JSON.stringify({
284
- acknowledged: false,
285
- error: err?.message || String(err),
286
- });
287
- }
288
285
  }, {
289
286
  name: "report_progress",
290
287
  description: `Mandatory after each phase: call with {stage, message, percent}. Percent must be between ${minPercent} and ${maxPercent} and monotonically increase.`,
@@ -293,8 +290,6 @@ const getAIProgressTool = (onProgress, minPercent = 0, maxPercent = 100) => lang
293
290
  message: z.string().describe("Progress message to display"),
294
291
  percent: z
295
292
  .number()
296
- .min(minPercent)
297
- .max(maxPercent)
298
293
  .describe(`Progress percentage (${minPercent}-${maxPercent})`),
299
294
  }),
300
295
  });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "restricted"
5
5
  },
6
- "version": "1.0.8",
6
+ "version": "1.0.11",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",