nestjs-langchain 1.0.2 → 2.0.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.
- package/LICENSE +21 -21
- package/README.md +344 -254
- package/dist/agent.d.ts +63 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +189 -0
- package/dist/agent.js.map +1 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +14 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/index.d.ts +4 -2
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +3 -18
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/inject-agent.decorator.d.ts +12 -0
- package/dist/decorators/inject-agent.decorator.d.ts.map +1 -0
- package/dist/decorators/inject-agent.decorator.js +15 -7
- package/dist/decorators/inject-agent.decorator.js.map +1 -0
- package/dist/decorators/tool.decorator.d.ts +54 -6
- package/dist/decorators/tool.decorator.d.ts.map +1 -0
- package/dist/decorators/tool.decorator.js +40 -16
- package/dist/decorators/tool.decorator.js.map +1 -0
- package/dist/errors/agent-run.error.d.ts +27 -0
- package/dist/errors/agent-run.error.d.ts.map +1 -0
- package/dist/errors/agent-run.error.js +26 -0
- package/dist/errors/agent-run.error.js.map +1 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +3 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/messages.d.ts +26 -0
- package/dist/errors/messages.d.ts.map +1 -0
- package/dist/errors/messages.js +67 -0
- package/dist/errors/messages.js.map +1 -0
- package/dist/errors/tool-configuration.error.d.ts +23 -0
- package/dist/errors/tool-configuration.error.d.ts.map +1 -0
- package/dist/errors/tool-configuration.error.js +27 -0
- package/dist/errors/tool-configuration.error.js.map +1 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -19
- package/dist/index.js.map +1 -0
- package/dist/interfaces/agent-observer.interface.d.ts +107 -0
- package/dist/interfaces/agent-observer.interface.d.ts.map +1 -0
- package/dist/interfaces/agent-observer.interface.js +2 -0
- package/dist/interfaces/agent-observer.interface.js.map +1 -0
- package/dist/interfaces/completed-run.interface.d.ts +14 -0
- package/dist/interfaces/completed-run.interface.d.ts.map +1 -0
- package/dist/interfaces/completed-run.interface.js +2 -0
- package/dist/interfaces/completed-run.interface.js.map +1 -0
- package/dist/interfaces/langchain-module-options.interface.d.ts +73 -5
- package/dist/interfaces/langchain-module-options.interface.d.ts.map +1 -0
- package/dist/interfaces/langchain-module-options.interface.js +2 -2
- package/dist/interfaces/langchain-module-options.interface.js.map +1 -0
- package/dist/langchain.module-definition.d.ts +26 -6
- package/dist/langchain.module-definition.d.ts.map +1 -0
- package/dist/langchain.module-definition.js +26 -13
- package/dist/langchain.module-definition.js.map +1 -0
- package/dist/langchain.module.d.ts +60 -3
- package/dist/langchain.module.d.ts.map +1 -0
- package/dist/langchain.module.js +87 -24
- package/dist/langchain.module.js.map +1 -0
- package/dist/logging/index.d.ts +3 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +3 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/observe-tool-call.util.d.ts +13 -0
- package/dist/logging/observe-tool-call.util.d.ts.map +1 -0
- package/dist/logging/observe-tool-call.util.js +34 -0
- package/dist/logging/observe-tool-call.util.js.map +1 -0
- package/dist/logging/run-reporter.d.ts +26 -0
- package/dist/logging/run-reporter.d.ts.map +1 -0
- package/dist/logging/run-reporter.js +39 -0
- package/dist/logging/run-reporter.js.map +1 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.d.ts.map +1 -0
- package/dist/run/index.js +2 -0
- package/dist/run/index.js.map +1 -0
- package/dist/run/run-summary.util.d.ts +31 -0
- package/dist/run/run-summary.util.d.ts.map +1 -0
- package/dist/run/run-summary.util.js +28 -0
- package/dist/run/run-summary.util.js.map +1 -0
- package/dist/tools/index.d.ts +3 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/tool-discovery.service.d.ts +31 -0
- package/dist/tools/tool-discovery.service.d.ts.map +1 -0
- package/dist/tools/tool-discovery.service.js +132 -0
- package/dist/tools/tool-discovery.service.js.map +1 -0
- package/dist/tools/tool-errors.middleware.d.ts +21 -0
- package/dist/tools/tool-errors.middleware.d.ts.map +1 -0
- package/dist/tools/tool-errors.middleware.js +55 -0
- package/dist/tools/tool-errors.middleware.js.map +1 -0
- package/dist/tools/tool-method.util.d.ts +21 -0
- package/dist/tools/tool-method.util.d.ts.map +1 -0
- package/dist/tools/tool-method.util.js +39 -0
- package/dist/tools/tool-method.util.js.map +1 -0
- package/dist/tools/tool-modules.util.d.ts +14 -0
- package/dist/tools/tool-modules.util.d.ts.map +1 -0
- package/dist/tools/tool-modules.util.js +61 -0
- package/dist/tools/tool-modules.util.js.map +1 -0
- package/dist/tools/tool-name.util.d.ts +10 -0
- package/dist/tools/tool-name.util.d.ts.map +1 -0
- package/dist/tools/tool-name.util.js +35 -0
- package/dist/tools/tool-name.util.js.map +1 -0
- package/dist/tools/tool-schema.factory.d.ts +4 -0
- package/dist/tools/tool-schema.factory.d.ts.map +1 -0
- package/dist/tools/tool-schema.factory.js +87 -0
- package/dist/tools/tool-schema.factory.js.map +1 -0
- package/dist/tools/tool.factory.d.ts +9 -0
- package/dist/tools/tool.factory.d.ts.map +1 -0
- package/dist/tools/tool.factory.js +34 -0
- package/dist/tools/tool.factory.js.map +1 -0
- package/lib/agent.ts +257 -0
- package/lib/constants.ts +15 -0
- package/lib/decorators/index.ts +3 -0
- package/lib/decorators/inject-agent.decorator.ts +15 -0
- package/lib/decorators/tool.decorator.ts +86 -0
- package/lib/errors/agent-run.error.ts +29 -0
- package/lib/errors/index.ts +2 -0
- package/lib/errors/messages.ts +158 -0
- package/lib/errors/tool-configuration.error.ts +24 -0
- package/lib/index.ts +26 -0
- package/lib/interfaces/agent-observer.interface.ts +113 -0
- package/lib/interfaces/completed-run.interface.ts +14 -0
- package/lib/interfaces/langchain-module-options.interface.ts +91 -0
- package/lib/langchain.module-definition.ts +36 -0
- package/lib/langchain.module.ts +138 -0
- package/lib/logging/index.ts +2 -0
- package/lib/logging/observe-tool-call.util.ts +59 -0
- package/lib/logging/run-reporter.ts +56 -0
- package/lib/run/index.ts +2 -0
- package/lib/run/run-summary.util.ts +51 -0
- package/lib/tools/index.ts +2 -0
- package/lib/tools/tool-discovery.service.ts +191 -0
- package/lib/tools/tool-errors.middleware.ts +68 -0
- package/lib/tools/tool-method.util.ts +81 -0
- package/lib/tools/tool-modules.util.ts +104 -0
- package/lib/tools/tool-name.util.ts +57 -0
- package/lib/tools/tool-schema.factory.ts +142 -0
- package/lib/tools/tool.factory.ts +56 -0
- package/package.json +112 -91
- package/dist/factories/message.factory.d.ts +0 -7
- package/dist/factories/message.factory.js +0 -28
- package/dist/langchain.service.d.ts +0 -18
- package/dist/langchain.service.js +0 -69
- package/dist/tool-discovery.service.d.ts +0 -11
- package/dist/tool-discovery.service.js +0 -79
- package/dist/types/message.d.ts +0 -69
- package/dist/types/message.js +0 -104
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Message construction, kept together so the wording stays consistent.
|
|
2
|
+
import { UNNAMED_AGENT } from '../langchain.module-definition.js';
|
|
3
|
+
// `'MATH '` for a named agent, empty for the unnamed one: "the MATH agent".
|
|
4
|
+
export const agentPrefix = (agent) => agent === UNNAMED_AGENT ? '' : `${agent} `;
|
|
5
|
+
export const toolProblems = (prefix, problems) => `nestjs-langchain found ${problems.length} ` +
|
|
6
|
+
`problem${problems.length === 1 ? '' : 's'} ` +
|
|
7
|
+
`with the tools of the ${prefix}agent:\n` +
|
|
8
|
+
problems.map((problem) => ` - ${problem}`).join('\n');
|
|
9
|
+
export const notAToolModule = (entry) => `${entry} is listed in \`tools\` but is not a module in the Nest context. ` +
|
|
10
|
+
'Pass a class decorated with @Module, imported alongside LangChainModule.';
|
|
11
|
+
export const toolModuleNotImported = (entry) => `${entry} is listed in \`tools\` but is not imported into the Nest context. ` +
|
|
12
|
+
'Add it to the `imports` of the module registering the agent.';
|
|
13
|
+
export const severalToolModuleInstances = (entry, count) => `${entry} is listed in \`tools\`, but the Nest context holds ${count} ` +
|
|
14
|
+
'instances of it, so their tools cannot be told apart. Import it once, or ' +
|
|
15
|
+
'give each configuration its own module class.';
|
|
16
|
+
export const toolModuleWithoutTools = (entry) => `${entry} is listed in \`tools\` but declares no @Tool method. ` +
|
|
17
|
+
'Tools are read from the providers a module declares, not from the ' +
|
|
18
|
+
'modules it imports.';
|
|
19
|
+
export const toolParamWithoutTool = (where) => `${where} has @ToolParam but no @Tool, so the model never sees it. ` +
|
|
20
|
+
'Add @Tool({ description }) to expose it, or remove the @ToolParam.';
|
|
21
|
+
export const toolParamOutsideMethod = () => '@ToolParam can only be used on method parameters.';
|
|
22
|
+
export const toolOnNonSingleton = (provider, scope, methods) => `${provider} ${{
|
|
23
|
+
request: 'is request-scoped',
|
|
24
|
+
transient: 'is transient',
|
|
25
|
+
'request-dependency': 'depends on a request-scoped provider',
|
|
26
|
+
}[scope]}, so its @Tool methods (${methods.join(', ')}) cannot be called by an ` +
|
|
27
|
+
'agent, which is a singleton. Make it a default-scoped provider.';
|
|
28
|
+
export const duplicateToolName = (name, first, second) => `Two tools are named "${name}": ${first} and ${second}. ` +
|
|
29
|
+
'Give one of them a `name` in @Tool().';
|
|
30
|
+
export const invalidToolName = (where, name, pattern, fromMethodName) => `${where}: "${name}" is not a valid tool name, providers match ${pattern}` +
|
|
31
|
+
(fromMethodName ? '. Pass a `name` to @Tool().' : '.');
|
|
32
|
+
export const reservedToolName = (where, name, prefix) => `${where}: "${name}" starts with "${prefix}", a prefix LangChain reserves ` +
|
|
33
|
+
'for structured output, so the agent would never run it. Give it another ' +
|
|
34
|
+
'`name` in @Tool().';
|
|
35
|
+
export const cannotInferSchema = (where, param, declared) => `${where}: cannot infer a schema for "${param}" declared as ${declared}. ` +
|
|
36
|
+
'Pass a `schema` to @ToolParam, or use string, number or boolean.';
|
|
37
|
+
export const schemaContradictsSignature = (where, param, declared, expected) => `${where}: the schema for "${param}" describes ${declared.join(' | ')} ` +
|
|
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.';
|
|
42
|
+
export const duplicateParamName = (where, name, first, second) => `${where}: parameters ${first + 1} and ${second + 1} are both named "${name}". ` +
|
|
43
|
+
'Give each @ToolParam its own name.';
|
|
44
|
+
export const notAChatModel = (prefix) => `The ${prefix}agent's \`model\` is neither a LangChain chat model nor a ` +
|
|
45
|
+
"`{ model: 'provider:name' }` configuration. Pass a chat model instance " +
|
|
46
|
+
'(e.g. `new ChatOpenAI(...)`) or a configuration.';
|
|
47
|
+
export const modelNotBuilt = (prefix, cause) => `The ${prefix}agent's model could not be built: ` +
|
|
48
|
+
(cause instanceof Error ? cause.message : String(cause));
|
|
49
|
+
export const agentNotBootstrapped = (prefix) => `The ${prefix}agent ran before the application bootstrapped. ` +
|
|
50
|
+
'Call `app.init()` or `app.listen()` first.';
|
|
51
|
+
export const duplicateAgentName = (name) => name === undefined
|
|
52
|
+
? 'Two agents are registered without a name. ' +
|
|
53
|
+
'Give all but one a `name` and inject them with @InjectAgent().'
|
|
54
|
+
: `Two agents are registered as "${name}". ` +
|
|
55
|
+
'Give each LangChainModule registration its own `name`.';
|
|
56
|
+
export const reservedAgentName = (name) => name === ''
|
|
57
|
+
? "An agent's `name` cannot be empty. " +
|
|
58
|
+
'Omit it to register the unnamed agent.'
|
|
59
|
+
: `"${name}" cannot be an agent's \`name\`: it stands for the agent ` +
|
|
60
|
+
'registered without one. Pick another name.';
|
|
61
|
+
export const agentRunFailed = (prefix, cause) => `The ${prefix}agent's run failed: ` +
|
|
62
|
+
(cause instanceof Error ? cause.message : String(cause));
|
|
63
|
+
export const modelNeverReplied = (prefix, last) => `The ${prefix}agent's loop ended before the model replied. ` +
|
|
64
|
+
`The last message was ${last ? `a ${last} message` : 'never produced'}.`;
|
|
65
|
+
export const modelReplyEmpty = (prefix) => `The ${prefix}agent's model replied with no text content.`;
|
|
66
|
+
export const unknownTool = () => 'not a tool of this agent';
|
|
67
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +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,IAAI,CAAC,IAAI,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE,CACtD,GAAG,KAAK,mEAAmE;IAC3E,0EAA0E,CAAC;AAE7E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAU,EAAE,CAC7D,GAAG,KAAK,qEAAqE;IAC7E,8DAA8D,CAAC;AAEjE,MAAM,CA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,iDAAiD;IAC9D,4CAA4C,CAAC;AAE/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAwB,EAAU,EAAE,CACrE,IAAI,KAAK,SAAS;IAChB,CAAC,CAAC,4CAA4C;QAC5C,gEAAgE;IAClE,CAAC,CAAC,iCAAiC,IAAI,KAAK;QAC1C,wDAAwD,CAAC;AAE/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAU,EAAE,CACxD,IAAI,KAAK,EAAE;IACT,CAAC,CAAC,qCAAqC;QACrC,wCAAwC;IAC1C,CAAC,CAAC,IAAI,IAAI,2DAA2D;QACnE,4CAA4C,CAAC;AAEnD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,KAAc,EAAU,EAAE,CACvE,OAAO,MAAM,sBAAsB;IACnC,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,IAAwB,EAChB,EAAE,CACV,OAAO,MAAM,+CAA+C;IAC5D,wBAAwB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,UAAU,CAAC,CAAC,CAAC,gBAAgB,GAAG,CAAC;AAE3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE,CACxD,OAAO,MAAM,6CAA6C,CAAC;AAE7D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAW,EAAE,CAAC,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent's tools are misconfigured, which fails the bootstrap. Lists every
|
|
3
|
+
* problem found while assembling them, not only the first.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const app = await Test.createTestingModule({ imports: [AppModule] }).compile();
|
|
8
|
+
*
|
|
9
|
+
* await expect(app.init()).rejects.toThrow(ToolConfigurationError);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare class ToolConfigurationError extends Error {
|
|
13
|
+
/** One message per problem, in the order they were found. */
|
|
14
|
+
readonly problems: string[];
|
|
15
|
+
/** `'default'` when the agent was registered without a name. */
|
|
16
|
+
readonly agent: string;
|
|
17
|
+
constructor(
|
|
18
|
+
/** One message per problem, in the order they were found. */
|
|
19
|
+
problems: string[],
|
|
20
|
+
/** `'default'` when the agent was registered without a name. */
|
|
21
|
+
agent: string);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=tool-configuration.error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-configuration.error.d.ts","sourceRoot":"","sources":["../../lib/errors/tool-configuration.error.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAE7C,6DAA6D;IAC7D,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE;IAC3B,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM;;IAHtB,6DAA6D;IACpD,QAAQ,EAAE,MAAM,EAAE;IAC3B,gEAAgE;IACvD,KAAK,EAAE,MAAM;CAKzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { agentPrefix, toolProblems } from './messages.js';
|
|
2
|
+
/**
|
|
3
|
+
* An agent's tools are misconfigured, which fails the bootstrap. Lists every
|
|
4
|
+
* problem found while assembling them, not only the first.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* const app = await Test.createTestingModule({ imports: [AppModule] }).compile();
|
|
9
|
+
*
|
|
10
|
+
* await expect(app.init()).rejects.toThrow(ToolConfigurationError);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export class ToolConfigurationError extends Error {
|
|
14
|
+
problems;
|
|
15
|
+
agent;
|
|
16
|
+
constructor(
|
|
17
|
+
/** One message per problem, in the order they were found. */
|
|
18
|
+
problems,
|
|
19
|
+
/** `'default'` when the agent was registered without a name. */
|
|
20
|
+
agent) {
|
|
21
|
+
super(toolProblems(agentPrefix(agent), problems));
|
|
22
|
+
this.problems = problems;
|
|
23
|
+
this.agent = agent;
|
|
24
|
+
this.name = 'ToolConfigurationError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=tool-configuration.error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-configuration.error.js","sourceRoot":"","sources":["../../lib/errors/tool-configuration.error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAGpC;IAEA;IAJX;IACE,6DAA6D;IACpD,QAAkB;IAC3B,gEAAgE;IACvD,KAAa;QAEtB,KAAK,CAAC,YAAY,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;QAJzC,aAAQ,GAAR,QAAQ,CAAU;QAElB,UAAK,GAAL,KAAK,CAAQ;QAGtB,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { LangChainModule } from './langchain.module.js';
|
|
2
|
+
export { getAgentToken } from './langchain.module-definition.js';
|
|
3
|
+
export { Agent } from './agent.js';
|
|
4
|
+
export { AgentRunError, ToolConfigurationError } from './errors/index.js';
|
|
5
|
+
export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
|
|
6
|
+
export type { ToolOptions, ToolParamOptions } from './decorators/index.js';
|
|
7
|
+
export type { AgentObserver, ModelErrorEvent, RunErrorEvent, RunFinishEvent, ToolEndEvent, ToolErrorEvent, ToolStartEvent, } from './interfaces/agent-observer.interface.js';
|
|
8
|
+
export type { CompletedRun } from './interfaces/completed-run.interface.js';
|
|
9
|
+
export type { AgentCallback, LangChainModuleOptions, LangChainOptionsFactory, ModelConfig, ModelOption, ToolModule, } from './interfaces/langchain-module-options.interface.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./langchain.module"), exports);
|
|
18
|
-
__exportStar(require("./decorators"), exports);
|
|
19
|
-
__exportStar(require("./langchain.service"), exports);
|
|
1
|
+
// The public surface, the one path `exports` opens. Named, so each export is
|
|
2
|
+
// a decision. See #82.
|
|
3
|
+
export { LangChainModule } from './langchain.module.js';
|
|
4
|
+
export { getAgentToken } from './langchain.module-definition.js';
|
|
5
|
+
export { Agent } from './agent.js';
|
|
6
|
+
export { AgentRunError, ToolConfigurationError } from './errors/index.js';
|
|
7
|
+
export { InjectAgent, Tool, ToolParam } from './decorators/index.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { AgentRunError } from '../errors/agent-run.error.js';
|
|
2
|
+
import type { RunSummary } from '../run/index.js';
|
|
3
|
+
interface ToolEvent {
|
|
4
|
+
/** `'default'` when the agent was registered without a name. */
|
|
5
|
+
agent: string;
|
|
6
|
+
/** The tool's name, as the model called it. */
|
|
7
|
+
tool: string;
|
|
8
|
+
/**
|
|
9
|
+
* The id the model gave this call. Pairs a start with its end or error. A
|
|
10
|
+
* call that never reached the tool has an error and no start.
|
|
11
|
+
*/
|
|
12
|
+
callId: string;
|
|
13
|
+
}
|
|
14
|
+
/** A tool call about to run, its arguments validated. */
|
|
15
|
+
export interface ToolStartEvent extends ToolEvent {
|
|
16
|
+
/** The arguments, parsed and validated against the tool's schema. */
|
|
17
|
+
args: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
/** A tool call that returned. */
|
|
20
|
+
export interface ToolEndEvent extends ToolEvent {
|
|
21
|
+
/** What the method returned, before it is serialised for the model. */
|
|
22
|
+
output: unknown;
|
|
23
|
+
/** How long the method took. */
|
|
24
|
+
durationMs: number;
|
|
25
|
+
}
|
|
26
|
+
/** A tool call that failed, or never reached its tool. */
|
|
27
|
+
export interface ToolErrorEvent extends ToolEvent {
|
|
28
|
+
/**
|
|
29
|
+
* Why the call failed: the agent has no such tool, the schema rejected the
|
|
30
|
+
* arguments, or the tool threw. Only `'threw'` follows an `onToolStart`.
|
|
31
|
+
* May gain values in a minor release: keep a `default` branch when
|
|
32
|
+
* switching on it.
|
|
33
|
+
*/
|
|
34
|
+
reason: 'unknown-tool' | 'invalid-arguments' | 'threw';
|
|
35
|
+
/** What the tool threw, or why the call never reached it. */
|
|
36
|
+
error: unknown;
|
|
37
|
+
/** `0` when the tool never ran. */
|
|
38
|
+
durationMs: number;
|
|
39
|
+
}
|
|
40
|
+
/** A model call that failed. The run may still retry or fail. */
|
|
41
|
+
export interface ModelErrorEvent {
|
|
42
|
+
/** `'default'` when the agent was registered without a name. */
|
|
43
|
+
agent: string;
|
|
44
|
+
/** What the provider threw. */
|
|
45
|
+
error: unknown;
|
|
46
|
+
}
|
|
47
|
+
/** A run that returned, with what it cost. */
|
|
48
|
+
export interface RunFinishEvent extends RunSummary {
|
|
49
|
+
/** `'default'` when the agent was registered without a name. */
|
|
50
|
+
agent: string;
|
|
51
|
+
/** How long the run took. */
|
|
52
|
+
durationMs: number;
|
|
53
|
+
}
|
|
54
|
+
/** A run that threw. */
|
|
55
|
+
export interface RunErrorEvent {
|
|
56
|
+
/** `'default'` when the agent was registered without a name. */
|
|
57
|
+
agent: string;
|
|
58
|
+
/** How long the run took before it failed. */
|
|
59
|
+
durationMs: number;
|
|
60
|
+
/** The same error the caller of `run()` receives. */
|
|
61
|
+
error: AgentRunError;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Called as a run goes. Every method is optional and may be async. It is
|
|
65
|
+
* never awaited, and a throw or a rejection is logged and swallowed, never
|
|
66
|
+
* propagated into the run.
|
|
67
|
+
*/
|
|
68
|
+
export interface AgentObserver {
|
|
69
|
+
/**
|
|
70
|
+
* Before a tool runs, once its arguments are validated.
|
|
71
|
+
*
|
|
72
|
+
* @param event The call and its arguments.
|
|
73
|
+
*/
|
|
74
|
+
onToolStart?(event: ToolStartEvent): void | Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* After a tool returns.
|
|
77
|
+
*
|
|
78
|
+
* @param event The call, its output and its duration.
|
|
79
|
+
*/
|
|
80
|
+
onToolEnd?(event: ToolEndEvent): void | Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* After a tool call fails: the tool threw, or the call never reached it.
|
|
83
|
+
*
|
|
84
|
+
* @param event The call, why it failed and the error.
|
|
85
|
+
*/
|
|
86
|
+
onToolError?(event: ToolErrorEvent): void | Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* After a model call fails.
|
|
89
|
+
*
|
|
90
|
+
* @param event The error the provider threw.
|
|
91
|
+
*/
|
|
92
|
+
onModelError?(event: ModelErrorEvent): void | Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Only for a run that returns.
|
|
95
|
+
*
|
|
96
|
+
* @param event The run's duration, tools and tokens.
|
|
97
|
+
*/
|
|
98
|
+
onRunFinish?(event: RunFinishEvent): void | Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* For every run that throws, whatever the cause.
|
|
101
|
+
*
|
|
102
|
+
* @param event The run's duration and the error its caller receives.
|
|
103
|
+
*/
|
|
104
|
+
onRunError?(event: RunErrorEvent): void | Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
export {};
|
|
107
|
+
//# sourceMappingURL=agent-observer.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observer.interface.d.ts","sourceRoot":"","sources":["../../lib/interfaces/agent-observer.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,UAAU,SAAS;IACjB,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,yDAAyD;AACzD,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,iCAAiC;AACjC,MAAM,WAAW,YAAa,SAAQ,SAAS;IAC7C,uEAAuE;IACvE,MAAM,EAAE,OAAO,CAAC;IAChB,gCAAgC;IAChC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,0DAA0D;AAC1D,MAAM,WAAW,cAAe,SAAQ,SAAS;IAC/C;;;;;OAKG;IACH,MAAM,EAAE,cAAc,GAAG,mBAAmB,GAAG,OAAO,CAAC;IACvD,6DAA6D;IAC7D,KAAK,EAAE,OAAO,CAAC;IACf,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,iEAAiE;AACjE,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,8CAA8C;AAC9C,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAwB;AACxB,MAAM,WAAW,aAAa;IAC5B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,8CAA8C;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,KAAK,EAAE,aAAa,CAAC;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D;;;;OAIG;IACH,SAAS,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD;;;;OAIG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D;;;;OAIG;IACH,YAAY,CAAC,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D;;;;OAIG;IACH,WAAW,CAAC,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D;;;;OAIG;IACH,UAAU,CAAC,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observer.interface.js","sourceRoot":"","sources":["../../lib/interfaces/agent-observer.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RunSummary } from '../run/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* A run that went to completion. `status` may gain values in a minor release:
|
|
4
|
+
* keep a `default` branch when switching on it.
|
|
5
|
+
*/
|
|
6
|
+
export interface CompletedRun<TOutput = string> extends RunSummary {
|
|
7
|
+
/** Always `'completed'`: a run that fails throws instead. */
|
|
8
|
+
status: 'completed';
|
|
9
|
+
/** The model's text answer. */
|
|
10
|
+
output: TOutput;
|
|
11
|
+
/** How long the run took. */
|
|
12
|
+
durationMs: number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=completed-run.interface.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"completed-run.interface.js","sourceRoot":"","sources":["../../lib/interfaces/completed-run.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,14 +1,82 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ModuleMetadata } from '@nestjs/common';
|
|
2
|
+
import type { BaseCallbackHandler, CallbackHandlerMethods } from '@langchain/core/callbacks/base';
|
|
3
|
+
import type { AgentObserver } from './agent-observer.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Model configuration, resolved at bootstrap through `initChatModel`. Its
|
|
6
|
+
* fields go as they are to the provider class, and a provider that names one
|
|
7
|
+
* differently ignores it (`ChatOllama` reads `numPredict`, not `maxTokens`):
|
|
8
|
+
* pass a model instance then.
|
|
9
|
+
*/
|
|
10
|
+
export type ModelConfig = {
|
|
11
|
+
/** Provider-qualified name, e.g. `openai:gpt-5-mini`. */
|
|
3
12
|
model: string;
|
|
4
|
-
|
|
13
|
+
/** Omit it to let the provider read its own env var, or to use IAM/ADC. */
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
/** The sampling temperature. */
|
|
5
16
|
temperature?: number;
|
|
17
|
+
/** The longest answer, in tokens. */
|
|
6
18
|
maxTokens?: number;
|
|
19
|
+
/** How long one model call may take, in milliseconds. */
|
|
7
20
|
timeout?: number;
|
|
21
|
+
/** How many times a failed model call is retried. */
|
|
8
22
|
maxRetries?: number;
|
|
9
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* A LangChain chat model instance, by the members `createAgent` checks for.
|
|
26
|
+
* Structural rather than `BaseChatModel`: a CommonJS application types its
|
|
27
|
+
* model from `@langchain/core`'s other declaration files. See #169.
|
|
28
|
+
*/
|
|
29
|
+
interface ChatModelLike {
|
|
30
|
+
/** Calls the model. */
|
|
31
|
+
invoke(...args: never[]): Promise<unknown>;
|
|
32
|
+
/** Optional, as on `BaseChatModel`; required at bootstrap. */
|
|
33
|
+
bindTools?(...args: never[]): unknown;
|
|
34
|
+
/** Streams the model's answer. */
|
|
35
|
+
_streamResponseChunks(...args: never[]): unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A configuration to resolve, or a model that is already built. The instance
|
|
39
|
+
* form takes anything {@link ModelConfig} cannot express.
|
|
40
|
+
*/
|
|
41
|
+
export type ModelOption = ModelConfig | ChatModelLike;
|
|
42
|
+
/**
|
|
43
|
+
* What Nest's own `imports` accepts: a module class, a dynamic module, a
|
|
44
|
+
* promise of one, or a forward reference.
|
|
45
|
+
*/
|
|
46
|
+
export type ToolModule = NonNullable<ModuleMetadata['imports']>[number];
|
|
47
|
+
/**
|
|
48
|
+
* Anything LangChain accepts as a run callback. Every method is optional, so a
|
|
49
|
+
* plain object of the `handle*` you care about is enough.
|
|
50
|
+
*/
|
|
51
|
+
export type AgentCallback = BaseCallbackHandler | CallbackHandlerMethods;
|
|
52
|
+
/** The options of one agent, for `register` or `registerAsync`. */
|
|
10
53
|
export interface LangChainModuleOptions {
|
|
11
|
-
model:
|
|
54
|
+
/** The chat model: a `provider:model` configuration, or an instance. */
|
|
55
|
+
model: ModelOption;
|
|
56
|
+
/** The instructions the model receives before every run. */
|
|
12
57
|
systemPrompt?: string;
|
|
13
|
-
|
|
58
|
+
/**
|
|
59
|
+
* The modules declaring this agent's `@Tool()` providers. Each must also be
|
|
60
|
+
* imported into the Nest context, as a single instance.
|
|
61
|
+
*/
|
|
62
|
+
tools?: ToolModule[];
|
|
63
|
+
/** Called as a run goes, so you decide what is worth recording. */
|
|
64
|
+
observer?: AgentObserver;
|
|
65
|
+
/** LangChain-native run callbacks, for handlers written against its API. */
|
|
66
|
+
callbacks?: AgentCallback[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A class building an agent's options, for `registerAsync({ useClass })` or
|
|
70
|
+
* `useExisting`. Declare the method's return type, so that a key the options
|
|
71
|
+
* do not declare is rejected.
|
|
72
|
+
*/
|
|
73
|
+
export interface LangChainOptionsFactory {
|
|
74
|
+
/**
|
|
75
|
+
* Builds the agent's options.
|
|
76
|
+
*
|
|
77
|
+
* @returns The options, or a promise of them.
|
|
78
|
+
*/
|
|
79
|
+
createLangChainOptions(): LangChainModuleOptions | Promise<LangChainModuleOptions>;
|
|
14
80
|
}
|
|
81
|
+
export {};
|
|
82
|
+
//# sourceMappingURL=langchain-module-options.interface.d.ts.map
|
|
@@ -0,0 +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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W,uBAAuB;IACtC;;;;OAIG;IACH,sBAAsB,IACpB,sBAAsB,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;CAC5D"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=langchain-module-options.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain-module-options.interface.js","sourceRoot":"","sources":["../../lib/interfaces/langchain-module-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,29 @@
|
|
|
1
|
-
import { LangChainModuleOptions } from './interfaces/langchain-module-options.interface';
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { LangChainModuleOptions } from './interfaces/langchain-module-options.interface.js';
|
|
2
|
+
/** The base class and tokens Nest generates for `LangChainModule`. */
|
|
3
|
+
export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<LangChainModuleOptions, "register", "createLangChainOptions", {
|
|
4
|
+
name?: string;
|
|
4
5
|
}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: LangChainModuleOptions & Partial<{
|
|
5
|
-
name
|
|
6
|
-
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<LangChainModuleOptions, "
|
|
7
|
-
name
|
|
6
|
+
name?: string;
|
|
7
|
+
}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<LangChainModuleOptions, "createLangChainOptions"> & Partial<{
|
|
8
|
+
name?: string;
|
|
8
9
|
}>;
|
|
10
|
+
/** The agent's own name. */
|
|
11
|
+
export declare const AGENT_NAME_TOKEN = "nestjs-langchain:agent-name";
|
|
12
|
+
/** The name the unnamed agent carries in logs and observer events. */
|
|
13
|
+
export declare const UNNAMED_AGENT = "default";
|
|
14
|
+
/**
|
|
15
|
+
* The injection token of the agent registered under `name`, for the places
|
|
16
|
+
* `@InjectAgent` cannot go: `overrideProvider` in a test, a factory's
|
|
17
|
+
* `inject`. The string it returns is not part of the API.
|
|
18
|
+
*
|
|
19
|
+
* @param name The `name` the agent was registered with.
|
|
20
|
+
* @returns The agent's injection token.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* Test.createTestingModule({ imports: [AppModule] })
|
|
24
|
+
* .overrideProvider(getAgentToken('MATH_AGENT'))
|
|
25
|
+
* .useValue({ run: async () => ({ status: 'completed', output: '42' }) });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
9
28
|
export declare const getAgentToken: (name: string) => string;
|
|
29
|
+
//# sourceMappingURL=langchain.module-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain.module-definition.d.ts","sourceRoot":"","sources":["../lib/langchain.module-definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oDAAoD,CAAC;AAE5F,sEAAsE;AACtE,eAAO,MACL,uBAAuB;WAKH,MAAM;IAJ1B,oBAAoB,mBACpB,YAAY;WAGQ,MAAM;IAF1B,kBAAkB;WAEE,MAAM;EAElB,CAAC;AAEX,4BAA4B;AAC5B,eAAO,MAAM,gBAAgB,gCAAgC,CAAC;AAE9D,sEAAsE;AACtE,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,MACX,CAAC"}
|
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ConfigurableModuleBuilder } from '@nestjs/common';
|
|
2
|
+
/** The base class and tokens Nest generates for `LangChainModule`. */
|
|
3
|
+
export const { ConfigurableModuleClass, MODULE_OPTIONS_TOKEN, OPTIONS_TYPE, ASYNC_OPTIONS_TYPE, } = new ConfigurableModuleBuilder()
|
|
4
|
+
.setExtras({ name: undefined })
|
|
5
|
+
.setFactoryMethodName('createLangChainOptions')
|
|
6
|
+
.build();
|
|
7
|
+
/** The agent's own name. */
|
|
8
|
+
export const AGENT_NAME_TOKEN = 'nestjs-langchain:agent-name';
|
|
9
|
+
/** The name the unnamed agent carries in logs and observer events. */
|
|
10
|
+
export const UNNAMED_AGENT = 'default';
|
|
11
|
+
/**
|
|
12
|
+
* The injection token of the agent registered under `name`, for the places
|
|
13
|
+
* `@InjectAgent` cannot go: `overrideProvider` in a test, a factory's
|
|
14
|
+
* `inject`. The string it returns is not part of the API.
|
|
15
|
+
*
|
|
16
|
+
* @param name The `name` the agent was registered with.
|
|
17
|
+
* @returns The agent's injection token.
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* Test.createTestingModule({ imports: [AppModule] })
|
|
21
|
+
* .overrideProvider(getAgentToken('MATH_AGENT'))
|
|
22
|
+
* .useValue({ run: async () => ({ status: 'completed', output: '42' }) });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const getAgentToken = (name) => `nestjs-langchain:agent:${name}`;
|
|
26
|
+
//# sourceMappingURL=langchain.module-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain.module-definition.js","sourceRoot":"","sources":["../lib/langchain.module-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,sEAAsE;AACtE,MAAM,CAAC,MAAM,EACX,uBAAuB,EACvB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,GACnB,GAAG,IAAI,yBAAyB,EAA0B;KACxD,SAAS,CAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACjD,oBAAoB,CAAC,wBAAwB,CAAC;KAC9C,KAAK,EAAE,CAAC;AAEX,4BAA4B;AAC5B,MAAM,CAAC,MAAM,gBAAgB,GAAG,6BAA6B,CAAC;AAE9D,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CACpD,0BAA0B,IAAI,EAAE,CAAC"}
|
|
@@ -1,7 +1,64 @@
|
|
|
1
|
-
import { DynamicModule } from '@nestjs/common';
|
|
2
|
-
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from './langchain.module-definition';
|
|
1
|
+
import { DynamicModule, Type } from '@nestjs/common';
|
|
2
|
+
import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from './langchain.module-definition.js';
|
|
3
|
+
import { LangChainModuleOptions, LangChainOptionsFactory } from './interfaces/langchain-module-options.interface.js';
|
|
4
|
+
/**
|
|
5
|
+
* Registers agents as Nest providers: each `register` or `registerAsync`
|
|
6
|
+
* adds one. Give each a `name` when there are several.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* imports: [
|
|
11
|
+
* MathModule,
|
|
12
|
+
* LangChainModule.register({
|
|
13
|
+
* model: { model: 'openai:gpt-5-mini' },
|
|
14
|
+
* tools: [MathModule],
|
|
15
|
+
* }),
|
|
16
|
+
* ],
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
3
19
|
export declare class LangChainModule extends ConfigurableModuleClass {
|
|
20
|
+
/**
|
|
21
|
+
* Registers an agent from its options.
|
|
22
|
+
*
|
|
23
|
+
* @param options The agent's options, with its `name` when there are several.
|
|
24
|
+
* @returns The module providing the agent.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* LangChainModule.register({
|
|
28
|
+
* name: 'MATH_AGENT',
|
|
29
|
+
* model: { model: 'openai:gpt-5-mini' },
|
|
30
|
+
* tools: [MathModule],
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
4
34
|
static register(options: typeof OPTIONS_TYPE): DynamicModule;
|
|
5
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Registers an agent whose options other providers build, through
|
|
37
|
+
* `useFactory`, `useClass` or `useExisting`. `name` stays outside the
|
|
38
|
+
* factory: it names the token `@InjectAgent()` resolves.
|
|
39
|
+
*
|
|
40
|
+
* @param options How to build the agent's options, and its `name`.
|
|
41
|
+
* @returns The module providing the agent.
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* LangChainModule.registerAsync({
|
|
45
|
+
* name: 'MATH_AGENT',
|
|
46
|
+
* imports: [ConfigModule],
|
|
47
|
+
* inject: [ConfigService],
|
|
48
|
+
* useFactory: (config: ConfigService) => ({
|
|
49
|
+
* model: {
|
|
50
|
+
* model: 'openai:gpt-5-mini',
|
|
51
|
+
* apiKey: config.getOrThrow<string>('OPENAI_API_KEY'),
|
|
52
|
+
* },
|
|
53
|
+
* }),
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static registerAsync<T extends LangChainModuleOptions & Record<Exclude<keyof T, keyof LangChainModuleOptions>, never>>(options: Omit<typeof ASYNC_OPTIONS_TYPE, 'useFactory' | 'useClass' | 'useExisting'> & {
|
|
58
|
+
useFactory?: (...args: any[]) => T | Promise<T>;
|
|
59
|
+
useClass?: Type<LangChainOptionsFactory>;
|
|
60
|
+
useExisting?: Type<LangChainOptionsFactory>;
|
|
61
|
+
}): DynamicModule;
|
|
6
62
|
private static addDynamicAgentProvider;
|
|
7
63
|
}
|
|
64
|
+
//# sourceMappingURL=langchain.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain.module.d.ts","sourceRoot":"","sources":["../lib/langchain.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAEL,kBAAkB,EAClB,uBAAuB,EAEvB,YAAY,EAEb,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,oDAAoD,CAAC;AAK5D;;;;;;;;;;;;;;GAcG;AACH,qBAIa,eAAgB,SAAQ,uBAAuB;IAC1D;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,YAAY,GAAG,aAAa;IAK5D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,aAAa,CAGlB,CAAC,SAAS,sBAAsB,GAC9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,sBAAsB,CAAC,EAAE,KAAK,CAAC,EAE/D,OAAO,EAAE,IAAI,CACX,OAAO,kBAAkB,EACzB,YAAY,GAAG,UAAU,GAAG,aAAa,CAC1C,GAAG;QAIF,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QAChD,QAAQ,CAAC,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACzC,WAAW,CAAC,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;KAC7C,GACA,aAAa;IAKhB,OAAO,CAAC,MAAM,CAAC,uBAAuB;CAoCvC"}
|