@agentforge/patterns 0.16.68 → 0.16.69

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/dist/index.cjs CHANGED
@@ -475,14 +475,55 @@ function createReasoningNode(llm, tools, systemPrompt, maxIterations, verbose =
475
475
  }
476
476
 
477
477
  // src/shared/error-handling.ts
478
+ function getErrorName(error) {
479
+ try {
480
+ return typeof error.name === "string" ? error.name : void 0;
481
+ } catch {
482
+ return void 0;
483
+ }
484
+ }
485
+ function getConstructorName(error) {
486
+ let constructorValue;
487
+ try {
488
+ constructorValue = error.constructor;
489
+ } catch {
490
+ return void 0;
491
+ }
492
+ if (constructorValue === void 0) {
493
+ return void 0;
494
+ }
495
+ if (constructorValue !== null && typeof constructorValue === "object") {
496
+ try {
497
+ const constructorName = constructorValue.name;
498
+ return typeof constructorName === "string" ? constructorName : void 0;
499
+ } catch {
500
+ return void 0;
501
+ }
502
+ }
503
+ return typeof constructorValue === "function" ? constructorValue.name : void 0;
504
+ }
478
505
  function isGraphInterrupt(error) {
479
- return error !== null && typeof error === "object" && "constructor" in error && error.constructor.name === "GraphInterrupt";
506
+ if (error === null || typeof error !== "object") {
507
+ return false;
508
+ }
509
+ const errorRecord = error;
510
+ return getErrorName(errorRecord) === "GraphInterrupt" || getConstructorName(errorRecord) === "GraphInterrupt";
511
+ }
512
+ function toErrorMessage(error) {
513
+ if (error instanceof Error) {
514
+ return error.message;
515
+ }
516
+ try {
517
+ return String(error);
518
+ } catch {
519
+ return "Unknown error";
520
+ }
480
521
  }
481
522
  function handleNodeError(error, context, verbose = false) {
482
523
  if (isGraphInterrupt(error)) {
483
524
  throw error;
484
525
  }
485
- const errorMessage = error instanceof Error ? error.message : String(error);
526
+ const errorMessage = toErrorMessage(error);
486
527
  if (verbose) {
487
528
  console.error(`[${context}] Error:`, errorMessage);
488
529
  if (error instanceof Error && error.stack) {
@@ -2601,14 +2642,34 @@ function isReActAgent(obj) {
2601
2642
  }
2602
2643
 
2603
2644
  // src/multi-agent/utils-shared.ts
2645
+ var import_runnables = require("@langchain/core/runnables");
2604
2646
  function isRecord2(value) {
2605
2647
  return typeof value === "object" && value !== null && !Array.isArray(value);
2606
2648
  }
2649
+ function removeUndefinedEntries(value) {
2650
+ const filtered = Object.fromEntries(
2651
+ Object.entries(value).filter(([, entryValue]) => entryValue !== void 0)
2652
+ );
2653
+ return Object.keys(filtered).length > 0 ? filtered : void 0;
2654
+ }
2607
2655
  function toRunnableConfig(config) {
2608
2656
  if (!isRecord2(config)) {
2609
2657
  return void 0;
2610
2658
  }
2611
- return config;
2659
+ const runnableConfig = (0, import_runnables.pickRunnableConfigKeys)(config);
2660
+ if (!runnableConfig || !isRecord2(runnableConfig)) {
2661
+ return void 0;
2662
+ }
2663
+ const cleanedConfig = removeUndefinedEntries(runnableConfig);
2664
+ if (!cleanedConfig) {
2665
+ return void 0;
2666
+ }
2667
+ const { configurable, ...restConfig } = cleanedConfig;
2668
+ const cleanedConfigurable = isRecord2(configurable) ? removeUndefinedEntries(configurable) : void 0;
2669
+ return {
2670
+ ...restConfig,
2671
+ ...cleanedConfigurable !== void 0 ? { configurable: cleanedConfigurable } : {}
2672
+ };
2612
2673
  }
2613
2674
  function getReActResultShape(value) {
2614
2675
  if (!isRecord2(value)) {
package/dist/index.js CHANGED
@@ -377,14 +377,55 @@ function createReasoningNode(llm, tools, systemPrompt, maxIterations, verbose =
377
377
  }
378
378
 
379
379
  // src/shared/error-handling.ts
380
+ function getErrorName(error) {
381
+ try {
382
+ return typeof error.name === "string" ? error.name : void 0;
383
+ } catch {
384
+ return void 0;
385
+ }
386
+ }
387
+ function getConstructorName(error) {
388
+ let constructorValue;
389
+ try {
390
+ constructorValue = error.constructor;
391
+ } catch {
392
+ return void 0;
393
+ }
394
+ if (constructorValue === void 0) {
395
+ return void 0;
396
+ }
397
+ if (constructorValue !== null && typeof constructorValue === "object") {
398
+ try {
399
+ const constructorName = constructorValue.name;
400
+ return typeof constructorName === "string" ? constructorName : void 0;
401
+ } catch {
402
+ return void 0;
403
+ }
404
+ }
405
+ return typeof constructorValue === "function" ? constructorValue.name : void 0;
406
+ }
380
407
  function isGraphInterrupt(error) {
381
- return error !== null && typeof error === "object" && "constructor" in error && error.constructor.name === "GraphInterrupt";
408
+ if (error === null || typeof error !== "object") {
409
+ return false;
410
+ }
411
+ const errorRecord = error;
412
+ return getErrorName(errorRecord) === "GraphInterrupt" || getConstructorName(errorRecord) === "GraphInterrupt";
413
+ }
414
+ function toErrorMessage(error) {
415
+ if (error instanceof Error) {
416
+ return error.message;
417
+ }
418
+ try {
419
+ return String(error);
420
+ } catch {
421
+ return "Unknown error";
422
+ }
382
423
  }
383
424
  function handleNodeError(error, context, verbose = false) {
384
425
  if (isGraphInterrupt(error)) {
385
426
  throw error;
386
427
  }
387
- const errorMessage = error instanceof Error ? error.message : String(error);
428
+ const errorMessage = toErrorMessage(error);
388
429
  if (verbose) {
389
430
  console.error(`[${context}] Error:`, errorMessage);
390
431
  if (error instanceof Error && error.stack) {
@@ -2503,14 +2544,34 @@ function isReActAgent(obj) {
2503
2544
  }
2504
2545
 
2505
2546
  // src/multi-agent/utils-shared.ts
2547
+ import { pickRunnableConfigKeys } from "@langchain/core/runnables";
2506
2548
  function isRecord2(value) {
2507
2549
  return typeof value === "object" && value !== null && !Array.isArray(value);
2508
2550
  }
2551
+ function removeUndefinedEntries(value) {
2552
+ const filtered = Object.fromEntries(
2553
+ Object.entries(value).filter(([, entryValue]) => entryValue !== void 0)
2554
+ );
2555
+ return Object.keys(filtered).length > 0 ? filtered : void 0;
2556
+ }
2509
2557
  function toRunnableConfig(config) {
2510
2558
  if (!isRecord2(config)) {
2511
2559
  return void 0;
2512
2560
  }
2513
- return config;
2561
+ const runnableConfig = pickRunnableConfigKeys(config);
2562
+ if (!runnableConfig || !isRecord2(runnableConfig)) {
2563
+ return void 0;
2564
+ }
2565
+ const cleanedConfig = removeUndefinedEntries(runnableConfig);
2566
+ if (!cleanedConfig) {
2567
+ return void 0;
2568
+ }
2569
+ const { configurable, ...restConfig } = cleanedConfig;
2570
+ const cleanedConfigurable = isRecord2(configurable) ? removeUndefinedEntries(configurable) : void 0;
2571
+ return {
2572
+ ...restConfig,
2573
+ ...cleanedConfigurable !== void 0 ? { configurable: cleanedConfigurable } : {}
2574
+ };
2514
2575
  }
2515
2576
  function getReActResultShape(value) {
2516
2577
  if (!isRecord2(value)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentforge/patterns",
3
- "version": "0.16.68",
3
+ "version": "0.16.69",
4
4
  "description": "Production-ready agent workflow patterns for TypeScript including ReAct and Planner-Executor, built on LangGraph.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -41,13 +41,13 @@
41
41
  "url": "https://github.com/TVScoundrel/agentforge/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@agentforge/core": "0.16.68",
44
+ "@agentforge/core": "0.16.69",
45
45
  "@langchain/core": "^1.1.17",
46
46
  "@langchain/langgraph": "^1.1.2",
47
47
  "zod": "^3.23.8"
48
48
  },
49
49
  "devDependencies": {
50
- "@agentforge/testing": "0.16.68",
50
+ "@agentforge/testing": "0.16.69",
51
51
  "@eslint/js": "^9.17.0",
52
52
  "@types/node": "^22.10.2",
53
53
  "eslint": "^9.17.0",