nestjs-langchain 2.0.0 → 2.2.0

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.
Files changed (112) hide show
  1. package/README.md +71 -6
  2. package/dist/agent.d.ts +21 -4
  3. package/dist/agent.d.ts.map +1 -1
  4. package/dist/agent.js +73 -33
  5. package/dist/agent.js.map +1 -1
  6. package/dist/constants.d.ts +16 -0
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +21 -0
  9. package/dist/constants.js.map +1 -1
  10. package/dist/errors/agent-aborted.error.d.ts +21 -0
  11. package/dist/errors/agent-aborted.error.d.ts.map +1 -0
  12. package/dist/errors/agent-aborted.error.js +22 -0
  13. package/dist/errors/agent-aborted.error.js.map +1 -0
  14. package/dist/errors/agent-recursion-limit.error.d.ts +23 -0
  15. package/dist/errors/agent-recursion-limit.error.d.ts.map +1 -0
  16. package/dist/errors/agent-recursion-limit.error.js +24 -0
  17. package/dist/errors/agent-recursion-limit.error.js.map +1 -0
  18. package/dist/errors/index.d.ts +5 -0
  19. package/dist/errors/index.d.ts.map +1 -1
  20. package/dist/errors/index.js +5 -0
  21. package/dist/errors/index.js.map +1 -1
  22. package/dist/errors/messages.d.ts +10 -0
  23. package/dist/errors/messages.d.ts.map +1 -1
  24. package/dist/errors/messages.js +24 -3
  25. package/dist/errors/messages.js.map +1 -1
  26. package/dist/errors/run-error.util.d.ts +21 -0
  27. package/dist/errors/run-error.util.d.ts.map +1 -0
  28. package/dist/errors/run-error.util.js +33 -0
  29. package/dist/errors/run-error.util.js.map +1 -0
  30. package/dist/errors/structured-output.error.d.ts +22 -0
  31. package/dist/errors/structured-output.error.d.ts.map +1 -0
  32. package/dist/errors/structured-output.error.js +23 -0
  33. package/dist/errors/structured-output.error.js.map +1 -0
  34. package/dist/errors/unwrap-middleware-error.util.d.ts +10 -0
  35. package/dist/errors/unwrap-middleware-error.util.d.ts.map +1 -0
  36. package/dist/errors/unwrap-middleware-error.util.js +17 -0
  37. package/dist/errors/unwrap-middleware-error.util.js.map +1 -0
  38. package/dist/index.d.ts +3 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +2 -1
  41. package/dist/index.js.map +1 -1
  42. package/dist/interfaces/completed-run.interface.d.ts +1 -1
  43. package/dist/interfaces/completed-run.interface.d.ts.map +1 -1
  44. package/dist/interfaces/langchain-module-options.interface.d.ts +6 -0
  45. package/dist/interfaces/langchain-module-options.interface.d.ts.map +1 -1
  46. package/dist/interfaces/run-options.interface.d.ts +34 -0
  47. package/dist/interfaces/run-options.interface.d.ts.map +1 -0
  48. package/dist/interfaces/run-options.interface.js +2 -0
  49. package/dist/interfaces/run-options.interface.js.map +1 -0
  50. package/dist/output/index.d.ts +3 -0
  51. package/dist/output/index.d.ts.map +1 -0
  52. package/dist/output/index.js +3 -0
  53. package/dist/output/index.js.map +1 -0
  54. package/dist/output/run-output.d.ts +43 -0
  55. package/dist/output/run-output.d.ts.map +1 -0
  56. package/dist/output/run-output.js +107 -0
  57. package/dist/output/run-output.js.map +1 -0
  58. package/dist/output/structured-output.middleware.d.ts +22 -0
  59. package/dist/output/structured-output.middleware.d.ts.map +1 -0
  60. package/dist/output/structured-output.middleware.js +40 -0
  61. package/dist/output/structured-output.middleware.js.map +1 -0
  62. package/dist/run/answered-calls.util.d.ts +10 -0
  63. package/dist/run/answered-calls.util.d.ts.map +1 -0
  64. package/dist/run/answered-calls.util.js +12 -0
  65. package/dist/run/answered-calls.util.js.map +1 -0
  66. package/dist/run/index.d.ts +3 -0
  67. package/dist/run/index.d.ts.map +1 -1
  68. package/dist/run/index.js +3 -0
  69. package/dist/run/index.js.map +1 -1
  70. package/dist/run/recursion-limit.util.d.ts +10 -0
  71. package/dist/run/recursion-limit.util.d.ts.map +1 -0
  72. package/dist/run/recursion-limit.util.js +11 -0
  73. package/dist/run/recursion-limit.util.js.map +1 -0
  74. package/dist/run/run-summary.util.d.ts +10 -3
  75. package/dist/run/run-summary.util.d.ts.map +1 -1
  76. package/dist/run/run-summary.util.js +18 -6
  77. package/dist/run/run-summary.util.js.map +1 -1
  78. package/dist/run/usage-aside.d.ts +23 -0
  79. package/dist/run/usage-aside.d.ts.map +1 -0
  80. package/dist/run/usage-aside.js +33 -0
  81. package/dist/run/usage-aside.js.map +1 -0
  82. package/dist/tools/tool-errors.middleware.d.ts +7 -1
  83. package/dist/tools/tool-errors.middleware.d.ts.map +1 -1
  84. package/dist/tools/tool-errors.middleware.js +81 -16
  85. package/dist/tools/tool-errors.middleware.js.map +1 -1
  86. package/dist/tools/tool-name.util.d.ts.map +1 -1
  87. package/dist/tools/tool-name.util.js +1 -3
  88. package/dist/tools/tool-name.util.js.map +1 -1
  89. package/lib/agent.ts +119 -32
  90. package/lib/constants.ts +24 -0
  91. package/lib/errors/agent-aborted.error.ts +22 -0
  92. package/lib/errors/agent-recursion-limit.error.ts +24 -0
  93. package/lib/errors/index.ts +5 -0
  94. package/lib/errors/messages.ts +55 -3
  95. package/lib/errors/run-error.util.ts +57 -0
  96. package/lib/errors/structured-output.error.ts +23 -0
  97. package/lib/errors/unwrap-middleware-error.util.ts +19 -0
  98. package/lib/index.ts +9 -1
  99. package/lib/interfaces/completed-run.interface.ts +1 -1
  100. package/lib/interfaces/langchain-module-options.interface.ts +6 -0
  101. package/lib/interfaces/run-options.interface.ts +34 -0
  102. package/lib/output/index.ts +5 -0
  103. package/lib/output/run-output.ts +154 -0
  104. package/lib/output/structured-output.middleware.ts +44 -0
  105. package/lib/run/answered-calls.util.ts +16 -0
  106. package/lib/run/index.ts +3 -0
  107. package/lib/run/recursion-limit.util.ts +11 -0
  108. package/lib/run/run-summary.util.ts +33 -11
  109. package/lib/run/usage-aside.ts +41 -0
  110. package/lib/tools/tool-errors.middleware.ts +104 -10
  111. package/lib/tools/tool-name.util.ts +1 -4
  112. package/package.json +31 -12
@@ -36,9 +36,10 @@ export const cannotInferSchema = (where, param, declared) => `${where}: cannot i
36
36
  'Pass a `schema` to @ToolParam, or use string, number or boolean.';
37
37
  export const schemaContradictsSignature = (where, param, declared, expected) => `${where}: the schema for "${param}" describes ${declared.join(' | ')} ` +
38
38
  `but the signature declares ${expected}.`;
39
- export const noJsonSchemaForm = (where, param, reason) => `${where}: "${param}" has no JSON Schema form (${reason}). ` +
40
- 'Declare a schema JSON Schema can express and convert it with .transform(), ' +
41
- 'such as z.iso.datetime() for a date.';
39
+ // The advice of both messages on a schema with no JSON Schema form.
40
+ const jsonSchemaAdvice = 'Declare a schema JSON Schema can express and convert it with .transform(), ' +
41
+ 'such as z.iso.date() or z.iso.datetime() for a date.';
42
+ export const noJsonSchemaForm = (where, param, reason) => `${where}: "${param}" has no JSON Schema form (${reason}). ${jsonSchemaAdvice}`;
42
43
  export const duplicateParamName = (where, name, first, second) => `${where}: parameters ${first + 1} and ${second + 1} are both named "${name}". ` +
43
44
  'Give each @ToolParam its own name.';
44
45
  export const notAChatModel = (prefix) => `The ${prefix}agent's \`model\` is neither a LangChain chat model nor a ` +
@@ -63,5 +64,25 @@ export const agentRunFailed = (prefix, cause) => `The ${prefix}agent's run faile
63
64
  export const modelNeverReplied = (prefix, last) => `The ${prefix}agent's loop ended before the model replied. ` +
64
65
  `The last message was ${last ? `a ${last} message` : 'never produced'}.`;
65
66
  export const modelReplyEmpty = (prefix) => `The ${prefix}agent's model replied with no text content.`;
67
+ export const runAborted = (prefix) => `The ${prefix}agent's run was aborted.`;
68
+ export const recursionLimitReached = (prefix, limit) => `The ${prefix}agent's run reached its recursion limit of ${limit} steps ` +
69
+ 'without an answer. Raise `recursionLimit`, or check what makes the model ' +
70
+ 'keep calling tools.';
71
+ export const invalidRecursionLimit = (prefix, limit) => `The ${prefix}agent's \`recursionLimit\` must be an integer of at least 1, ` +
72
+ `not ${typeof limit === 'string' ? `"${limit}"` : String(limit)}.`;
73
+ export const noOutputJsonSchemaForm = (prefix, reason) => `The ${prefix}agent's \`output\` schema has no JSON Schema form (${reason}). ` +
74
+ jsonSchemaAdvice;
75
+ export const outputNotAnObject = (prefix) => `The ${prefix}agent's \`output\` schema is not an object with named fields: ` +
76
+ "the model fills it in as a tool's parameters. Wrap it, such as " +
77
+ '`z.object({ items: z.array(...) })`.';
78
+ export const structuredOutputMissing = (prefix) => `The ${prefix}agent's model replied without the requested structured output.`;
79
+ export const structuredOutputInvalid = (prefix, reason) => `The ${prefix}agent's model replied with an output that does not match ` +
80
+ `the schema: ${reason}`;
81
+ export const structuredOutputMultiple = (prefix, count) => `The ${prefix}agent's model replied with ${count} outputs instead of one.`;
66
82
  export const unknownTool = () => 'not a tool of this agent';
83
+ // LangChain's answer to a tool the agent does not have, restated:
84
+ // `getInvalidToolError` is not exported. See #264.
85
+ export const invalidTool = (tool, tools) => `Error: ${tool} is not a valid tool, try one of [${tools.join(', ')}].`;
86
+ export const toolNotRun = (tool) => `Error: '${tool}' was not run: it came with the final answer. ` +
87
+ 'Call it on its own first if it is needed.';
67
88
  //# sourceMappingURL=messages.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../lib/errors/messages.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAU,EAAE,CACnD,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;AAE7C,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,QAAkB,EAAU,EAAE,CACzE,0BAA0B,QAAQ,CAAC,MAAM,GAAG;IAC5C,UAAU,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG;IAC7C,yBAAyB,MAAM,UAAU;IACzC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,EAAE,CAAC,CAAC,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AAO,MAAM,sDAAsD,MAAM,KAAK;IAC9E,gBAAgB,CAAC;AAEnB,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE,CAC1D,OAAO,MAAM,gEAAgE;IAC7E,iEAAiE;IACjE,sCAAsC,CAAC;AAEzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAc,EAAU,EAAE,CAChE,OAAO,MAAM,gEAAgE,CAAC;AAEhF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,MAAc,EACd,MAAc,EACN,EAAE,CACV,OAAO,MAAM,2DAA2D;IACxE,eAAe,MAAM,EAAE,CAAC;AAE1B,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,MAAc,EACd,KAAa,EACL,EAAE,CACV,OAAO,MAAM,8BAA8B,KAAK,0BAA0B,CAAC;AAE7E,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,0BAA0B,CAAC;AAEpE,kEAAkE;AAClE,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,KAAe,EAAU,EAAE,CACnE,UAAU,IAAI,qCAAqC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AAE1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CACjD,WAAW,IAAI,gDAAgD;IAC/D,2CAA2C,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ interface FailedRun {
3
+ agent: string;
4
+ /** Empty for the unnamed agent, `'MATH '` otherwise. */
5
+ prefix: string;
6
+ signal?: AbortSignal;
7
+ /** The limit the run was given. */
8
+ recursionLimit: number;
9
+ }
10
+ /**
11
+ * The `AgentRunError` `run()` throws for what the agent's graph threw.
12
+ *
13
+ * @internal
14
+ * @param thrown What the graph threw.
15
+ * @param run The run that failed.
16
+ * @returns The error itself when it is one already, else the subclass of its
17
+ * kind, the original in `cause`.
18
+ */
19
+ export declare const toRunError: (thrown: unknown, { agent, prefix, signal, recursionLimit }: FailedRun) => AgentRunError;
20
+ export {};
21
+ //# sourceMappingURL=run-error.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-error.util.d.ts","sourceRoot":"","sources":["../../lib/errors/run-error.util.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAQrD,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,mCAAmC;IACnC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,QAAQ,OAAO,EACf,2CAA2C,SAAS,KACnD,aAyBF,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { AgentAbortedError } from './agent-aborted.error.js';
2
+ import { AgentRecursionLimitError } from './agent-recursion-limit.error.js';
3
+ import { AgentRunError } from './agent-run.error.js';
4
+ import { agentRunFailed, recursionLimitReached, runAborted, } from './messages.js';
5
+ import { unwrapMiddlewareError } from './unwrap-middleware-error.util.js';
6
+ /**
7
+ * The `AgentRunError` `run()` throws for what the agent's graph threw.
8
+ *
9
+ * @internal
10
+ * @param thrown What the graph threw.
11
+ * @param run The run that failed.
12
+ * @returns The error itself when it is one already, else the subclass of its
13
+ * kind, the original in `cause`.
14
+ */
15
+ export const toRunError = (thrown, { agent, prefix, signal, recursionLimit }) => {
16
+ const cause = unwrapMiddlewareError(thrown);
17
+ if (cause instanceof AgentRunError) {
18
+ return cause;
19
+ }
20
+ // The reason itself, which LangChain may have wrapped on its way out.
21
+ if (signal?.aborted) {
22
+ return new AgentAbortedError(runAborted(prefix), agent, {
23
+ cause: signal.reason,
24
+ });
25
+ }
26
+ // By name, as LangGraph tells its errors apart; it is not a dependency of
27
+ // ours. See #194.
28
+ if (cause instanceof Error && cause.name === 'GraphRecursionError') {
29
+ return new AgentRecursionLimitError(recursionLimitReached(prefix, recursionLimit), agent, { cause });
30
+ }
31
+ return new AgentRunError(agentRunFailed(prefix, cause), agent, { cause });
32
+ };
33
+ //# sourceMappingURL=run-error.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-error.util.js","sourceRoot":"","sources":["../../lib/errors/run-error.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,UAAU,GACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAW1E;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAAe,EACf,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAa,EACrC,EAAE;IACjB,MAAM,KAAK,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE5C,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,sEAAsE;IACtE,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;QACpB,OAAO,IAAI,iBAAiB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE;YACtD,KAAK,EAAE,MAAM,CAAC,MAAM;SACrB,CAAC,CAAC;IACL,CAAC;IAED,0EAA0E;IAC1E,kBAAkB;IAClB,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,qBAAqB,EAAE,CAAC;QACnE,OAAO,IAAI,wBAAwB,CACjC,qBAAqB,CAAC,MAAM,EAAE,cAAc,CAAC,EAC7C,KAAK,EACL,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;IAED,OAAO,IAAI,aAAa,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;AAC5E,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The model's answer to a run with an `output` schema never came, or does not
4
+ * match the schema. LangChain's or Zod's error, if any, is in `cause`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * try {
9
+ * const { output } = await agent.run(ticket, { output: Classification });
10
+ * } catch (error) {
11
+ * if (error instanceof StructuredOutputError) {
12
+ * console.error(error.message, error.cause);
13
+ * }
14
+ * }
15
+ * ```
16
+ */
17
+ export declare class StructuredOutputError extends AgentRunError {
18
+ constructor(message: string, agent: string, options?: {
19
+ cause?: unknown;
20
+ });
21
+ }
22
+ //# sourceMappingURL=structured-output.error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-output.error.d.ts","sourceRoot":"","sources":["../../lib/errors/structured-output.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;gBAC1C,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAI1E"}
@@ -0,0 +1,23 @@
1
+ import { AgentRunError } from './agent-run.error.js';
2
+ /**
3
+ * The model's answer to a run with an `output` schema never came, or does not
4
+ * match the schema. LangChain's or Zod's error, if any, is in `cause`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * try {
9
+ * const { output } = await agent.run(ticket, { output: Classification });
10
+ * } catch (error) {
11
+ * if (error instanceof StructuredOutputError) {
12
+ * console.error(error.message, error.cause);
13
+ * }
14
+ * }
15
+ * ```
16
+ */
17
+ export class StructuredOutputError extends AgentRunError {
18
+ constructor(message, agent, options) {
19
+ super(message, agent, options);
20
+ this.name = 'StructuredOutputError';
21
+ }
22
+ }
23
+ //# sourceMappingURL=structured-output.error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-output.error.js","sourceRoot":"","sources":["../../lib/errors/structured-output.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,qBAAsB,SAAQ,aAAa;IACtD,YAAY,OAAe,EAAE,KAAa,EAAE,OAA6B;QACvE,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The error as thrown, without the `MiddlewareError` LangChain wraps it in at
3
+ * each `wrapModelCall` middleware it crosses, a provider error included.
4
+ *
5
+ * @internal
6
+ * @param error What the agent's graph threw.
7
+ * @returns The innermost error.
8
+ */
9
+ export declare const unwrapMiddlewareError: (error: unknown) => unknown;
10
+ //# sourceMappingURL=unwrap-middleware-error.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap-middleware-error.util.d.ts","sourceRoot":"","sources":["../../lib/errors/unwrap-middleware-error.util.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAAI,OAAO,OAAO,KAAG,OAQtD,CAAC"}
@@ -0,0 +1,17 @@
1
+ import { MiddlewareError } from 'langchain';
2
+ /**
3
+ * The error as thrown, without the `MiddlewareError` LangChain wraps it in at
4
+ * each `wrapModelCall` middleware it crosses, a provider error included.
5
+ *
6
+ * @internal
7
+ * @param error What the agent's graph threw.
8
+ * @returns The innermost error.
9
+ */
10
+ export const unwrapMiddlewareError = (error) => {
11
+ let unwrapped = error;
12
+ while (MiddlewareError.isInstance(unwrapped) && unwrapped.cause) {
13
+ unwrapped = unwrapped.cause;
14
+ }
15
+ return unwrapped;
16
+ };
17
+ //# sourceMappingURL=unwrap-middleware-error.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unwrap-middleware-error.util.js","sourceRoot":"","sources":["../../lib/errors/unwrap-middleware-error.util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAc,EAAW,EAAE;IAC/D,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,OAAO,eAAe,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,KAAK,EAAE,CAAC;QAChE,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;IAC9B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  export { LangChainModule } from './langchain.module.js';
2
2
  export { getAgentToken } from './langchain.module-definition.js';
3
3
  export { Agent } from './agent.js';
4
- export { AgentRunError, ToolConfigurationError } from './errors/index.js';
4
+ export { OUTPUT_TOOL } from './constants.js';
5
+ export { AgentAbortedError, AgentRecursionLimitError, AgentRunError, StructuredOutputError, ToolConfigurationError, } from './errors/index.js';
5
6
  export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
6
7
  export type { ToolOptions, ToolParamOptions } from './decorators/index.js';
7
8
  export type { AgentObserver, ModelErrorEvent, RunErrorEvent, RunFinishEvent, ToolEndEvent, ToolErrorEvent, ToolStartEvent, } from './interfaces/agent-observer.interface.js';
8
9
  export type { CompletedRun } from './interfaces/completed-run.interface.js';
10
+ export type { RunOptions } from './interfaces/run-options.interface.js';
9
11
  export type { AgentCallback, LangChainModuleOptions, LangChainOptionsFactory, ModelConfig, ModelOption, ToolModule, } from './interfaces/langchain-module-options.interface.js';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,YAAY,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,0CAA0C,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5E,YAAY,EACV,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,oDAAoD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACrE,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC3E,YAAY,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,EACd,cAAc,GACf,MAAM,0CAA0C,CAAC;AAClD,YAAY,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AAC5E,YAAY,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACxE,YAAY,EACV,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,oDAAoD,CAAC"}
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  export { LangChainModule } from './langchain.module.js';
4
4
  export { getAgentToken } from './langchain.module-definition.js';
5
5
  export { Agent } from './agent.js';
6
- export { AgentRunError, ToolConfigurationError } from './errors/index.js';
6
+ export { OUTPUT_TOOL } from './constants.js';
7
+ export { AgentAbortedError, AgentRecursionLimitError, AgentRunError, StructuredOutputError, ToolConfigurationError, } from './errors/index.js';
7
8
  export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
8
9
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,uBAAuB;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,aAAa,EACb,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC"}
@@ -6,7 +6,7 @@ import type { RunSummary } from '../run/index.js';
6
6
  export interface CompletedRun<TOutput = string> extends RunSummary {
7
7
  /** Always `'completed'`: a run that fails throws instead. */
8
8
  status: 'completed';
9
- /** The model's text answer. */
9
+ /** The model's text answer, or the object the run's `output` schema parsed. */
10
10
  output: TOutput;
11
11
  /** How long the run took. */
12
12
  durationMs: number;
@@ -1 +1 @@
1
- {"version":3,"file":"completed-run.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/completed-run.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG,MAAM,CAAE,SAAQ,UAAU;IAChE,6DAA6D;IAC7D,MAAM,EAAE,WAAW,CAAC;IACpB,+BAA+B;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"completed-run.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/completed-run.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG,MAAM,CAAE,SAAQ,UAAU;IAChE,6DAA6D;IAC7D,MAAM,EAAE,WAAW,CAAC;IACpB,+EAA+E;IAC/E,MAAM,EAAE,OAAO,CAAC;IAChB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB"}
@@ -64,6 +64,12 @@ export interface LangChainModuleOptions {
64
64
  observer?: AgentObserver;
65
65
  /** LangChain-native run callbacks, for handlers written against its API. */
66
66
  callbacks?: AgentCallback[];
67
+ /**
68
+ * The most steps a run may take, each model call and each round of tool
69
+ * calls counting as one: LangGraph's 25 when omitted. A run's own
70
+ * `recursionLimit` overrides it.
71
+ */
72
+ recursionLimit?: number;
67
73
  }
68
74
  /**
69
75
  * A class building an agent's options, for `registerAsync({ useClass })` or
@@ -1 +1 @@
1
- {"version":3,"file":"langchain-module-options.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/langchain-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,UAAU,aAAa;IACrB,uBAAuB;IACvB,MAAM,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,8DAA8D;IAC9D,SAAS,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IACtC,kCAAkC;IAClC,qBAAqB,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;CAClD;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,aAAa,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,sBAAsB,CAAC;AAEzE,mEAAmE;AACnE,MAAM,WAAW,sBAAsB;IACrC,wEAAwE;IACxE,KAAK,EAAE,WAAW,CAAC;IACnB,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;CAC7B;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,sBAAsB,IACpB,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAC5D"}
1
+ {"version":3,"file":"langchain-module-options.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/langchain-module-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,WAAW,CAA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}
@@ -0,0 +1,34 @@
1
+ import type { ZodType } from 'zod';
2
+ /**
3
+ * The options of one run. Passed inline, they type `output` from the schema;
4
+ * typed `RunOptions`, `output` is `unknown`.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const { output } = await agent.run(email, { output: Ticket }); // a Ticket
9
+ * await agent.run(question, { signal: AbortSignal.timeout(30_000) });
10
+ *
11
+ * const ask = (question: string, options?: RunOptions) =>
12
+ * agent.run(question, options); // `output` is unknown
13
+ * ```
14
+ */
15
+ export interface RunOptions {
16
+ /**
17
+ * The schema the answer must match. `output` is then the object it parses,
18
+ * typed from it, instead of the model's text.
19
+ */
20
+ output?: ZodType;
21
+ /**
22
+ * Aborts the run: `run()` throws an `AgentAbortedError`, the signal's
23
+ * `reason` in `cause`. A tool already running ends in the background, its
24
+ * result dropped.
25
+ */
26
+ signal?: AbortSignal;
27
+ /**
28
+ * The most steps the run may take, each model call and each round of tool
29
+ * calls counting as one, instead of the agent's `recursionLimit`. Past it,
30
+ * `run()` throws an `AgentRecursionLimitError`.
31
+ */
32
+ recursionLimit?: number;
33
+ }
34
+ //# sourceMappingURL=run-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-options.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/run-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=run-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/run-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { RunOutput } from './run-output.js';
2
+ export { outputConfig, structuredOutput, } from './structured-output.middleware.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/output/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,gBAAgB,GACjB,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { RunOutput } from './run-output.js';
2
+ export { outputConfig, structuredOutput, } from './structured-output.middleware.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/output/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,YAAY,EACZ,gBAAgB,GACjB,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { TypedToolStrategy } from 'langchain';
2
+ import { ZodType } from 'zod';
3
+ /**
4
+ * The structured output one run asked for: the strategy its model calls use,
5
+ * and the answer parsed by the schema.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare class RunOutput {
10
+ #private;
11
+ private readonly schema;
12
+ private readonly agent;
13
+ /**
14
+ * Through a tool, whatever the model (see #274). One per run, which counts
15
+ * its own retries (see #151).
16
+ */
17
+ readonly strategy: TypedToolStrategy;
18
+ /** The tool the model answers through. */
19
+ readonly toolName: "extract-output";
20
+ private readonly prefix;
21
+ /**
22
+ * @param schema The run's `output` schema.
23
+ * @param agent The agent's name, for the errors.
24
+ * @throws AgentRunError when the schema has no JSON Schema form, or is not
25
+ * an object with named fields.
26
+ */
27
+ constructor(schema: ZodType, agent: string);
28
+ private retry;
29
+ /**
30
+ * @param error What a model call threw.
31
+ * @returns A `StructuredOutputError` for LangChain's parsing failures, the
32
+ * error itself otherwise.
33
+ */
34
+ failure(error: unknown): unknown;
35
+ /**
36
+ * @param structuredResponse What the run left in `structuredResponse`.
37
+ * @returns The answer, as the schema parses it.
38
+ * @throws StructuredOutputError when the answer is missing or invalid.
39
+ */
40
+ read(structuredResponse: unknown): unknown;
41
+ private invalid;
42
+ }
43
+ //# sourceMappingURL=run-output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-output.d.ts","sourceRoot":"","sources":["../../lib/output/run-output.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,iBAAiB,EAClB,MAAM,WAAW,CAAC;AACnB,OAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAqBjC;;;;;GAKG;AACH,qBAAa,SAAS;;IAkBlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAlBxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;IACrC,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,mBAAe;IAEhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAEhC;;;;;OAKG;gBAEgB,MAAM,EAAE,OAAO,EACf,KAAK,EAAE,MAAM;IAqChC,OAAO,CAAC,KAAK;IAUb;;;;OAIG;IACH,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAiBhC;;;;OAIG;IACH,IAAI,CAAC,kBAAkB,EAAE,OAAO,GAAG,OAAO;IAmB1C,OAAO,CAAC,OAAO;CAOhB"}
@@ -0,0 +1,107 @@
1
+ import { toJsonSchema } from '@langchain/core/utils/json_schema';
2
+ import { MultipleStructuredOutputsError, StructuredOutputParsingError, toolStrategy, } from 'langchain';
3
+ import z from 'zod';
4
+ import { OUTPUT_TOOL } from '../constants.js';
5
+ import { AgentRunError, StructuredOutputError } from '../errors/index.js';
6
+ import { agentPrefix, noOutputJsonSchemaForm, outputNotAnObject, structuredOutputInvalid, structuredOutputMissing, structuredOutputMultiple, } from '../errors/messages.js';
7
+ import { messageOf } from '../logging/index.js';
8
+ // The default of LangChain's own retry middlewares. See #151.
9
+ const MAX_RETRIES = 2;
10
+ // LangChain's default for a Zod schema, which its JSON Schema path leaves
11
+ // empty. See #282.
12
+ const OUTPUT_DESCRIPTION = "Tool for extracting structured output from the model's response.";
13
+ /**
14
+ * The structured output one run asked for: the strategy its model calls use,
15
+ * and the answer parsed by the schema.
16
+ *
17
+ * @internal
18
+ */
19
+ export class RunOutput {
20
+ schema;
21
+ agent;
22
+ /**
23
+ * Through a tool, whatever the model (see #274). One per run, which counts
24
+ * its own retries (see #151).
25
+ */
26
+ strategy;
27
+ /** The tool the model answers through. */
28
+ toolName = OUTPUT_TOOL;
29
+ #retries = 0;
30
+ prefix;
31
+ /**
32
+ * @param schema The run's `output` schema.
33
+ * @param agent The agent's name, for the errors.
34
+ * @throws AgentRunError when the schema has no JSON Schema form, or is not
35
+ * an object with named fields.
36
+ */
37
+ constructor(schema, agent) {
38
+ this.schema = schema;
39
+ this.agent = agent;
40
+ this.prefix = agentPrefix(agent);
41
+ // LangChain's own conversion, run before any model call.
42
+ let json;
43
+ try {
44
+ json = toJsonSchema(schema);
45
+ }
46
+ catch (error) {
47
+ throw new AgentRunError(noOutputJsonSchemaForm(this.prefix, messageOf(error)), agent, { cause: error });
48
+ }
49
+ // A tool's parameters. LangChain takes them as a JSON Schema with
50
+ // `properties` at every version, as a Zod schema other than an object at
51
+ // recent ones only. See #282.
52
+ if (json.type !== 'object' || !('properties' in json)) {
53
+ throw new AgentRunError(outputNotAnObject(this.prefix), agent);
54
+ }
55
+ // LangChain names the tool after the title.
56
+ this.strategy = toolStrategy({
57
+ ...json,
58
+ type: 'object',
59
+ title: OUTPUT_TOOL,
60
+ description: json.description ?? OUTPUT_DESCRIPTION,
61
+ }, { handleError: (error) => this.retry(error) });
62
+ }
63
+ // What LangChain sends back by default, until the retries run out.
64
+ retry(error) {
65
+ this.#retries += 1;
66
+ if (this.#retries > MAX_RETRIES) {
67
+ throw error;
68
+ }
69
+ return error.message;
70
+ }
71
+ /**
72
+ * @param error What a model call threw.
73
+ * @returns A `StructuredOutputError` for LangChain's parsing failures, the
74
+ * error itself otherwise.
75
+ */
76
+ failure(error) {
77
+ // Never LangChain's messages, which name the internal tool.
78
+ if (error instanceof StructuredOutputParsingError) {
79
+ return this.invalid(error.errors.join(' '), error);
80
+ }
81
+ if (error instanceof MultipleStructuredOutputsError) {
82
+ return new StructuredOutputError(structuredOutputMultiple(this.prefix, error.toolNames.length), this.agent, { cause: error });
83
+ }
84
+ return error;
85
+ }
86
+ /**
87
+ * @param structuredResponse What the run left in `structuredResponse`.
88
+ * @returns The answer, as the schema parses it.
89
+ * @throws StructuredOutputError when the answer is missing or invalid.
90
+ */
91
+ read(structuredResponse) {
92
+ if (structuredResponse === undefined) {
93
+ throw new StructuredOutputError(structuredOutputMissing(this.prefix), this.agent);
94
+ }
95
+ // LangChain checks the JSON Schema only: Zod also applies transforms and
96
+ // refinements. See #151.
97
+ const parsed = this.schema.safeParse(structuredResponse);
98
+ if (!parsed.success) {
99
+ throw this.invalid(z.prettifyError(parsed.error), parsed.error);
100
+ }
101
+ return parsed.data;
102
+ }
103
+ invalid(reason, cause) {
104
+ return new StructuredOutputError(structuredOutputInvalid(this.prefix, reason), this.agent, { cause });
105
+ }
106
+ }
107
+ //# sourceMappingURL=run-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-output.js","sourceRoot":"","sources":["../../lib/output/run-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AACjE,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC5B,YAAY,GAEb,MAAM,WAAW,CAAC;AACnB,OAAO,CAAc,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OA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AAI,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;QAEzD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAEO,OAAO,CAAC,MAAc,EAAE,KAAc;QAC5C,OAAO,IAAI,qBAAqB,CAC9B,uBAAuB,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5C,IAAI,CAAC,KAAK,EACV,EAAE,KAAK,EAAE,CACV,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { RunOutput } from './run-output.js';
2
+ /**
3
+ * The `configurable` entry that hands a run's output to the middleware. A
4
+ * text run sets it to `null`, or it would inherit the output of the run it is
5
+ * nested in, which LangChain hands down. See #295.
6
+ *
7
+ * @internal
8
+ * @param output The run's output, if it asked for one.
9
+ * @returns The entry to put in `configurable`.
10
+ */
11
+ export declare const outputConfig: (output: RunOutput | undefined) => {
12
+ "nestjs-langchain:output": RunOutput | null;
13
+ };
14
+ /**
15
+ * Sets the `responseFormat` of each model call of a run that asked for an
16
+ * `output`, so that one compiled agent serves text and structured runs.
17
+ * LangChain's parsing failures come out as a `StructuredOutputError`.
18
+ *
19
+ * @internal
20
+ */
21
+ export declare const structuredOutput: () => import("langchain").AgentMiddleware<undefined, undefined, unknown, readonly (import("@langchain/core/tools").ServerTool | import("@langchain/core/tools").ClientTool)[], readonly []>;
22
+ //# sourceMappingURL=structured-output.middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-output.middleware.d.ts","sourceRoot":"","sources":["../../lib/output/structured-output.middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAM5C;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,SAAS,GAAG,SAAS;;CAExD,CAAC;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,6LAgBzB,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { createMiddleware } from 'langchain';
2
+ import { RunOutput } from './run-output.js';
3
+ // The run's output travels under our own key in `configurable`, which
4
+ // LangGraph keeps out of the trace metadata and checkpoints. See #151.
5
+ const OUTPUT_KEY = 'nestjs-langchain:output';
6
+ /**
7
+ * The `configurable` entry that hands a run's output to the middleware. A
8
+ * text run sets it to `null`, or it would inherit the output of the run it is
9
+ * nested in, which LangChain hands down. See #295.
10
+ *
11
+ * @internal
12
+ * @param output The run's output, if it asked for one.
13
+ * @returns The entry to put in `configurable`.
14
+ */
15
+ export const outputConfig = (output) => ({
16
+ [OUTPUT_KEY]: output ?? null,
17
+ });
18
+ /**
19
+ * Sets the `responseFormat` of each model call of a run that asked for an
20
+ * `output`, so that one compiled agent serves text and structured runs.
21
+ * LangChain's parsing failures come out as a `StructuredOutputError`.
22
+ *
23
+ * @internal
24
+ */
25
+ export const structuredOutput = () => createMiddleware({
26
+ name: 'structuredOutput',
27
+ wrapModelCall: async (request, handler) => {
28
+ const output = request.runtime.configurable?.[OUTPUT_KEY];
29
+ if (!(output instanceof RunOutput)) {
30
+ return handler(request);
31
+ }
32
+ try {
33
+ return await handler({ ...request, responseFormat: output.strategy });
34
+ }
35
+ catch (error) {
36
+ throw output.failure(error);
37
+ }
38
+ },
39
+ });
40
+ //# sourceMappingURL=structured-output.middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structured-output.middleware.js","sourceRoot":"","sources":["../../lib/output/structured-output.middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,sEAAsE;AACtE,uEAAuE;AACvE,MAAM,UAAU,GAAG,yBAAyB,CAAC;AAE7C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAA6B,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,IAAI;CAC7B,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE,CACnC,gBAAgB,CAAC;IACf,IAAI,EAAE,kBAAkB;IACxB,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACxC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,CAAC,CAAC;QAE1D,IAAI,CAAC,CAAC,MAAM,YAAY,SAAS,CAAC,EAAE,CAAC;YACnC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QAED,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,cAAc,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The ids of the tool calls the messages answer: the tool node answers every
3
+ * call it runs. Structural rather than `BaseMessage`. See #52.
4
+ *
5
+ * @internal
6
+ * @param messages A run's messages.
7
+ * @returns The ids their `tool_call_id`s answer.
8
+ */
9
+ export declare const answeredCalls: (messages: readonly object[]) => Set<string>;
10
+ //# sourceMappingURL=answered-calls.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answered-calls.util.d.ts","sourceRoot":"","sources":["../../lib/run/answered-calls.util.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,SAAS,MAAM,EAAE,KAAG,GAAG,CAAC,MAAM,CAOnE,CAAC"}