nestjs-langchain 1.0.0 → 2.0.0-rc.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 -0
- package/README.md +344 -0
- 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 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +3 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/inject-agent.decorator.d.ts +13 -0
- package/dist/decorators/inject-agent.decorator.d.ts.map +1 -0
- package/dist/decorators/inject-agent.decorator.js +15 -0
- package/dist/decorators/inject-agent.decorator.js.map +1 -0
- package/dist/decorators/tool.decorator.d.ts +61 -0
- package/dist/decorators/tool.decorator.d.ts.map +1 -0
- package/dist/decorators/tool.decorator.js +45 -0
- 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 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- 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 +82 -0
- package/dist/interfaces/langchain-module-options.interface.d.ts.map +1 -0
- package/dist/interfaces/langchain-module-options.interface.js +2 -0
- package/dist/interfaces/langchain-module-options.interface.js.map +1 -0
- package/dist/langchain.module-definition.d.ts +29 -0
- package/dist/langchain.module-definition.d.ts.map +1 -0
- package/dist/langchain.module-definition.js +26 -0
- package/dist/langchain.module-definition.js.map +1 -0
- package/dist/langchain.module.d.ts +64 -0
- package/dist/langchain.module.d.ts.map +1 -0
- package/dist/langchain.module.js +110 -0
- 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 +107 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Martin-Bruel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
A <a href="https://nestjs.com/">Nest</a> module wrapper for building AI agents with <a href="https://www.langchain.com/">LangChain</a>.
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://github.com/Martin-Bruel/nestjs-langchain/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/Martin-Bruel/nestjs-langchain/actions/workflows/ci.yml/badge.svg?branch=main"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/nestjs-langchain"><img alt="npm version" src="https://img.shields.io/npm/v/nestjs-langchain"></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/nestjs-langchain"><img alt="npm downloads" src="https://img.shields.io/npm/dm/nestjs-langchain"></a>
|
|
13
|
+
<a href="https://github.com/Martin-Bruel/nestjs-langchain/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/nestjs-langchain"></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://github.com/Martin-Bruel/nestjs-langchain/commits/main"><img alt="Last commit" src="https://img.shields.io/github/last-commit/Martin-Bruel/nestjs-langchain"></a>
|
|
18
|
+
<a href="https://github.com/Martin-Bruel/nestjs-langchain/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/Martin-Bruel/nestjs-langchain"></a>
|
|
19
|
+
<a href="https://github.com/Martin-Bruel/nestjs-langchain/issues"><img alt="Open issues" src="https://img.shields.io/github/issues/Martin-Bruel/nestjs-langchain"></a>
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
**Table of Contents**
|
|
23
|
+
|
|
24
|
+
- [Description](#description)
|
|
25
|
+
- [Installation](#installation)
|
|
26
|
+
- [Quick start](#quick-start)
|
|
27
|
+
- [Defining tools](#defining-tools)
|
|
28
|
+
- [Multi-agent support](#multi-agent-support)
|
|
29
|
+
- [Async configuration](#async-configuration)
|
|
30
|
+
- [Testing](#testing)
|
|
31
|
+
- [Logging and observing](#logging-and-observing)
|
|
32
|
+
- [Contributing](#contributing)
|
|
33
|
+
- [License](#license)
|
|
34
|
+
|
|
35
|
+
## Description
|
|
36
|
+
|
|
37
|
+
**nestjs-langchain** is a powerful, decorator-driven wrapper that integrates LangChain agents seamlessly into the NestJS ecosystem. It allows you to transform standard NestJS services into AI tools and manage multiple isolated agents with distinct roles and configurations.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install nestjs-langchain @langchain/<ai-provider>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Requires **NestJS 11.1.18+ or 12.0.1+**, **`langchain` 1.5.4+**, **Zod 4**, **Node 22.12+** and
|
|
46
|
+
**TypeScript 5.8+**.
|
|
47
|
+
|
|
48
|
+
> **_NOTE:_** Yarn does not install `langchain`, `@langchain/core` and `zod` as peer dependencies, so add them explicitly:
|
|
49
|
+
>
|
|
50
|
+
> ```bash
|
|
51
|
+
> yarn add nestjs-langchain @langchain/<ai-provider> langchain @langchain/core zod
|
|
52
|
+
> ```
|
|
53
|
+
|
|
54
|
+
Having troubles configuring `nestjs-langchain`? Clone this repository and run a sample, whose
|
|
55
|
+
README says what it needs:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install
|
|
59
|
+
npm run build
|
|
60
|
+
cd samples/chat
|
|
61
|
+
npm run start
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Requirements in detail, CommonJS applications and Jest: [docs/setup.md](docs/setup.md).
|
|
65
|
+
|
|
66
|
+
## Quick start
|
|
67
|
+
|
|
68
|
+
### 1. Register an agent
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { Module } from '@nestjs/common';
|
|
72
|
+
import { LangChainModule } from 'nestjs-langchain';
|
|
73
|
+
import { AppService } from './app.service.js';
|
|
74
|
+
|
|
75
|
+
@Module({
|
|
76
|
+
imports: [
|
|
77
|
+
LangChainModule.register({
|
|
78
|
+
// `provider:model`. Without an `apiKey`, the provider reads its own
|
|
79
|
+
// environment variable, here OPENAI_API_KEY.
|
|
80
|
+
model: { model: 'openai:gpt-5-mini' },
|
|
81
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
82
|
+
}),
|
|
83
|
+
],
|
|
84
|
+
providers: [AppService],
|
|
85
|
+
})
|
|
86
|
+
export class AppModule {}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
> **_NOTE:_** The model property allows you to select your AI engine based on the provider (OpenAI, Anthropic, Google, etc.). You can find the list of all available integrations here:
|
|
90
|
+
> 👉 [LangChain Chat Integrations](https://docs.langchain.com/oss/javascript/integrations/chat/index)
|
|
91
|
+
|
|
92
|
+
> **_NOTE:_** `model` also accepts a chat model you built yourself, such as
|
|
93
|
+
> `new ChatOpenAI({ ... })`, for what the configuration cannot express: a proxy, an Azure
|
|
94
|
+
> deployment, a fake in tests.
|
|
95
|
+
|
|
96
|
+
Model options and providers: [docs/models.md](docs/models.md).
|
|
97
|
+
|
|
98
|
+
### 2. Inject the agent
|
|
99
|
+
|
|
100
|
+
Inject `Agent` and run it:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { Injectable } from '@nestjs/common';
|
|
104
|
+
import { Agent } from 'nestjs-langchain';
|
|
105
|
+
|
|
106
|
+
@Injectable()
|
|
107
|
+
export class AppService {
|
|
108
|
+
constructor(private readonly agent: Agent) {}
|
|
109
|
+
|
|
110
|
+
async ask(question: string): Promise<string> {
|
|
111
|
+
const { output } = await this.agent.run(question);
|
|
112
|
+
return output;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Defining Tools
|
|
118
|
+
|
|
119
|
+
### 1. Define the tool
|
|
120
|
+
|
|
121
|
+
Turn a service method into a tool with `@Tool()`, and describe its parameters with `@ToolParam()`:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { Injectable } from '@nestjs/common';
|
|
125
|
+
import { Tool, ToolParam } from 'nestjs-langchain';
|
|
126
|
+
|
|
127
|
+
@Injectable()
|
|
128
|
+
export class MathService {
|
|
129
|
+
@Tool({ description: 'Adds two numbers.' })
|
|
130
|
+
add(
|
|
131
|
+
@ToolParam({ name: 'a', description: 'The first number.' }) a: number,
|
|
132
|
+
@ToolParam({ name: 'b', description: 'The second number.' }) b: number,
|
|
133
|
+
): number {
|
|
134
|
+
return a + b;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The tool is named after the method, unless `@Tool()` takes a `name`.
|
|
140
|
+
|
|
141
|
+
### 2. Declare the parameter types
|
|
142
|
+
|
|
143
|
+
Use a Zod `schema` for any parameter that is not a `string`, `number` or `boolean`.
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { z } from 'zod';
|
|
147
|
+
|
|
148
|
+
@Tool({ description: 'Searches the catalogue.' })
|
|
149
|
+
search(
|
|
150
|
+
@ToolParam({ name: 'query' }) query: string,
|
|
151
|
+
@ToolParam({
|
|
152
|
+
name: 'filter',
|
|
153
|
+
description: 'Restricts the results.',
|
|
154
|
+
schema: z.object({ field: z.string(), value: z.string() }),
|
|
155
|
+
})
|
|
156
|
+
filter: { field: string; value: string },
|
|
157
|
+
@ToolParam({ name: 'limit', optional: true }) limit?: number,
|
|
158
|
+
): Promise<Result[]> {
|
|
159
|
+
// ...
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### 3. Attach tool to the agent
|
|
164
|
+
|
|
165
|
+
List the module that declares the service in `tools`, and import it:
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
import { Module } from '@nestjs/common';
|
|
169
|
+
import { LangChainModule } from 'nestjs-langchain';
|
|
170
|
+
import { MathModule } from './math/math.module.js';
|
|
171
|
+
|
|
172
|
+
@Module({
|
|
173
|
+
imports: [
|
|
174
|
+
MathModule,
|
|
175
|
+
LangChainModule.register({
|
|
176
|
+
model: { model: 'openai:gpt-5-mini' },
|
|
177
|
+
tools: [MathModule],
|
|
178
|
+
}),
|
|
179
|
+
],
|
|
180
|
+
})
|
|
181
|
+
export class AppModule {}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Naming, parameter types, tool modules and the checks at bootstrap: [docs/tools.md](docs/tools.md).
|
|
185
|
+
Before exposing tools to users, read [docs/security.md](docs/security.md).
|
|
186
|
+
|
|
187
|
+
## Multi-Agent Support
|
|
188
|
+
|
|
189
|
+
Give each agent a `name`, and inject it with `@InjectAgent()`.
|
|
190
|
+
|
|
191
|
+
### 1. Register a specific agent
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
@Module({
|
|
195
|
+
imports: [
|
|
196
|
+
MathModule,
|
|
197
|
+
MongoModule,
|
|
198
|
+
LangChainModule.register({
|
|
199
|
+
name: 'MATH_AGENT',
|
|
200
|
+
model: { model: 'openai:gpt-5-mini' },
|
|
201
|
+
tools: [MathModule],
|
|
202
|
+
}),
|
|
203
|
+
LangChainModule.register({
|
|
204
|
+
name: 'MONGO_AGENT',
|
|
205
|
+
model: { model: 'openai:gpt-5-mini' },
|
|
206
|
+
tools: [MongoModule],
|
|
207
|
+
}),
|
|
208
|
+
],
|
|
209
|
+
providers: [AppService],
|
|
210
|
+
})
|
|
211
|
+
export class AppModule {}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### 2. Use a specific agent
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
@Injectable()
|
|
218
|
+
export class AppService {
|
|
219
|
+
constructor(
|
|
220
|
+
@InjectAgent('MATH_AGENT') private readonly math: Agent,
|
|
221
|
+
@InjectAgent('MONGO_AGENT') private readonly mongo: Agent,
|
|
222
|
+
) {}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`Agent` without `@InjectAgent()` is the agent registered without a name.
|
|
227
|
+
|
|
228
|
+
## Async Configuration
|
|
229
|
+
|
|
230
|
+
Build the options from other providers with `registerAsync`:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
234
|
+
|
|
235
|
+
LangChainModule.registerAsync({
|
|
236
|
+
// Outside the factory: it names the token `@InjectAgent()` resolves.
|
|
237
|
+
name: 'MATH_AGENT',
|
|
238
|
+
imports: [ConfigModule],
|
|
239
|
+
inject: [ConfigService],
|
|
240
|
+
useFactory: (config: ConfigService) => ({
|
|
241
|
+
model: {
|
|
242
|
+
model: 'openai:gpt-5-mini',
|
|
243
|
+
apiKey: config.getOrThrow<string>('OPENAI_API_KEY'),
|
|
244
|
+
},
|
|
245
|
+
tools: [MathModule],
|
|
246
|
+
}),
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
`useClass` and `useExisting` take a class implementing `LangChainOptionsFactory`.
|
|
251
|
+
|
|
252
|
+
`useClass`, `name` and agent names in detail: [docs/setup.md](docs/setup.md#registerasync).
|
|
253
|
+
|
|
254
|
+
## Testing
|
|
255
|
+
|
|
256
|
+
Replace an agent with `overrideProvider`: `Agent` for the agent registered without a name,
|
|
257
|
+
`getAgentToken(name)` for a named one.
|
|
258
|
+
|
|
259
|
+
```ts
|
|
260
|
+
import { Test } from '@nestjs/testing';
|
|
261
|
+
import { getAgentToken } from 'nestjs-langchain';
|
|
262
|
+
|
|
263
|
+
const moduleRef = await Test.createTestingModule({ imports: [AppModule] })
|
|
264
|
+
.overrideProvider(getAgentToken('MATH_AGENT'))
|
|
265
|
+
.useValue({
|
|
266
|
+
run: async () => ({ status: 'completed', output: '42', tools: [], durationMs: 0 }),
|
|
267
|
+
})
|
|
268
|
+
.compile();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Or run the real agent and its tools against LangChain's `fakeModel()`, which replays the answers
|
|
272
|
+
and tool calls you queue:
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
import { Test } from '@nestjs/testing';
|
|
276
|
+
import { AIMessage } from '@langchain/core/messages';
|
|
277
|
+
import { fakeModel } from '@langchain/core/testing';
|
|
278
|
+
import { Agent, LangChainModule } from 'nestjs-langchain';
|
|
279
|
+
import { MathModule } from './math/math.module.js';
|
|
280
|
+
|
|
281
|
+
const model = fakeModel()
|
|
282
|
+
.respondWithTools([{ name: 'add', args: { a: 1, b: 2 } }])
|
|
283
|
+
.respond(new AIMessage('The result is 3.'));
|
|
284
|
+
|
|
285
|
+
const moduleRef = await Test.createTestingModule({
|
|
286
|
+
imports: [MathModule, LangChainModule.register({ model, tools: [MathModule] })],
|
|
287
|
+
}).compile();
|
|
288
|
+
// The agent is built on init, which `compile()` does not run.
|
|
289
|
+
await moduleRef.init();
|
|
290
|
+
|
|
291
|
+
const { output } = await moduleRef.get(Agent).run('1 + 2?');
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Testing with Jest: [docs/setup.md](docs/setup.md#testing-with-jest).
|
|
295
|
+
|
|
296
|
+
## Logging and observing
|
|
297
|
+
|
|
298
|
+
Record what a run does through `observer`:
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
LangChainModule.register({
|
|
302
|
+
model: { model: 'openai:gpt-5-mini' },
|
|
303
|
+
tools: [MathModule],
|
|
304
|
+
observer: {
|
|
305
|
+
onToolStart: ({ tool, args }) => console.log(`${tool} called with`, args),
|
|
306
|
+
onToolError: ({ tool, reason, error }) =>
|
|
307
|
+
console.error(`${tool} failed (${reason})`, error),
|
|
308
|
+
onRunFinish: ({ durationMs, tools, tokens }) =>
|
|
309
|
+
console.log({ durationMs, tools, tokens }),
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
With `LANGSMITH_TRACING=true` and `LANGSMITH_API_KEY` set, every run is also traced in LangSmith.
|
|
315
|
+
|
|
316
|
+
Every event, the errors, the log lines and `callbacks`: [docs/observing.md](docs/observing.md).
|
|
317
|
+
|
|
318
|
+
### Errors
|
|
319
|
+
|
|
320
|
+
Everything `run()` throws is an `AgentRunError`, with the `agent` that failed and the original
|
|
321
|
+
error in `cause`:
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
import { AgentRunError } from 'nestjs-langchain';
|
|
325
|
+
|
|
326
|
+
try {
|
|
327
|
+
await agent.run(question);
|
|
328
|
+
} catch (error) {
|
|
329
|
+
if (error instanceof AgentRunError) {
|
|
330
|
+
console.error(error.agent, error.message, error.cause);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
## Contributing
|
|
336
|
+
|
|
337
|
+
Contributions are welcome. Read the
|
|
338
|
+
[contributing guidelines](https://github.com/Martin-Bruel/nestjs-langchain/blob/main/CONTRIBUTING.md)
|
|
339
|
+
and the [code of conduct](https://github.com/Martin-Bruel/nestjs-langchain/blob/main/CODE_OF_CONDUCT.md)
|
|
340
|
+
first.
|
|
341
|
+
|
|
342
|
+
## License
|
|
343
|
+
|
|
344
|
+
This project is released under the terms of the MIT License.
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
3
|
+
import { LangChainModuleOptions } from './interfaces/langchain-module-options.interface.js';
|
|
4
|
+
import { CompletedRun } from './interfaces/completed-run.interface.js';
|
|
5
|
+
import { ToolDiscoveryService } from './tools/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* One agent, registered through `LangChainModule`. Inject it directly for the
|
|
8
|
+
* unnamed agent, or with `@InjectAgent(name)` for a named one.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* constructor(private readonly agent: Agent) {}
|
|
13
|
+
*
|
|
14
|
+
* async ask(question: string): Promise<string> {
|
|
15
|
+
* const { output } = await this.agent.run(question);
|
|
16
|
+
* return output;
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class Agent implements OnModuleInit {
|
|
21
|
+
#private;
|
|
22
|
+
private readonly options;
|
|
23
|
+
private readonly agentName;
|
|
24
|
+
private readonly toolDiscovery;
|
|
25
|
+
private readonly discovery;
|
|
26
|
+
private readonly logger;
|
|
27
|
+
private readonly prefix;
|
|
28
|
+
private readonly reporter;
|
|
29
|
+
private readonly modelErrors;
|
|
30
|
+
/** @internal Built by `LangChainModule`, never by hand. */
|
|
31
|
+
constructor(options: LangChainModuleOptions, agentName: string, toolDiscovery: ToolDiscoveryService, discovery: DiscoveryService);
|
|
32
|
+
/**
|
|
33
|
+
* Called by Nest: builds the agent, once the tool modules' providers exist.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
onModuleInit(): Promise<void>;
|
|
38
|
+
private assertUniqueName;
|
|
39
|
+
/**
|
|
40
|
+
* Build the model from its configuration, or hand back the instance the
|
|
41
|
+
* caller already built. Recognised by the members `createAgent` checks,
|
|
42
|
+
* never by `instanceof`, which two copies of `@langchain/core` break.
|
|
43
|
+
* See #52.
|
|
44
|
+
*
|
|
45
|
+
* @param option The `model` option.
|
|
46
|
+
* @returns The model `createAgent` receives.
|
|
47
|
+
*/
|
|
48
|
+
private resolveModel;
|
|
49
|
+
/**
|
|
50
|
+
* Runs the agent to completion on one user message. Every failure is thrown
|
|
51
|
+
* as an `AgentRunError`, the original error in its `cause`.
|
|
52
|
+
*
|
|
53
|
+
* @param input The user's message.
|
|
54
|
+
* @returns The model's answer, the tools it called and what the run cost.
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const { output, tools } = await agent.run('What is 6 times 7?');
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
run(input: string): Promise<CompletedRun>;
|
|
61
|
+
private complete;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../lib/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAOhD,OAAO,EACL,sBAAsB,EAEvB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACL,oBAAoB,EAGrB,MAAM,kBAAkB,CAAC;AAsB1B;;;;;;;;;;;;;GAaG;AACH,qBACa,KAAM,YAAW,YAAY;;IActC,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAd5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAc;IAGvC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsB;IAElD,2DAA2D;gBAGxC,OAAO,EAAE,sBAAsB,EAE/B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,oBAAoB,EACnC,SAAS,EAAE,gBAAgB;IAmB9C;;;;OAIG;IACG,YAAY;IAwBlB,OAAO,CAAC,gBAAgB;IAiBxB;;;;;;;;OAQG;YACW,YAAY;IA8B1B;;;;;;;;;;OAUG;IACG,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;YAsCjC,QAAQ;CA+BvB"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
14
|
+
import { DiscoveryService } from '@nestjs/core';
|
|
15
|
+
import { createAgent, initChatModel } from 'langchain';
|
|
16
|
+
import { AGENT_NAME_TOKEN, MODULE_OPTIONS_TOKEN, UNNAMED_AGENT, } from './langchain.module-definition.js';
|
|
17
|
+
import { ToolDiscoveryService, toolErrors, unknownTools, } from './tools/index.js';
|
|
18
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
19
|
+
import { LOG_CONTEXT, messageOf, RunReporter } from './logging/index.js';
|
|
20
|
+
import { summariseRun } from './run/index.js';
|
|
21
|
+
import { AgentRunError } from './errors/index.js';
|
|
22
|
+
import { agentNotBootstrapped, agentPrefix, agentRunFailed, duplicateAgentName, modelNeverReplied, modelNotBuilt, modelReplyEmpty, notAChatModel, } from './errors/messages.js';
|
|
23
|
+
/**
|
|
24
|
+
* One agent, registered through `LangChainModule`. Inject it directly for the
|
|
25
|
+
* unnamed agent, or with `@InjectAgent(name)` for a named one.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* constructor(private readonly agent: Agent) {}
|
|
30
|
+
*
|
|
31
|
+
* async ask(question: string): Promise<string> {
|
|
32
|
+
* const { output } = await this.agent.run(question);
|
|
33
|
+
* return output;
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
let Agent = class Agent {
|
|
38
|
+
options;
|
|
39
|
+
agentName;
|
|
40
|
+
toolDiscovery;
|
|
41
|
+
discovery;
|
|
42
|
+
// Assembled in `onModuleInit`, once every tool module's providers exist.
|
|
43
|
+
#graph;
|
|
44
|
+
// Without a context, since Nest appends the instance's to each call's own.
|
|
45
|
+
logger = new Logger();
|
|
46
|
+
prefix;
|
|
47
|
+
reporter;
|
|
48
|
+
// Model failures, which only LangChain's callbacks see. Tool calls are
|
|
49
|
+
// reported by their wrapper and the tool middlewares.
|
|
50
|
+
modelErrors;
|
|
51
|
+
/** @internal Built by `LangChainModule`, never by hand. */
|
|
52
|
+
constructor(options, agentName, toolDiscovery, discovery) {
|
|
53
|
+
this.options = options;
|
|
54
|
+
this.agentName = agentName;
|
|
55
|
+
this.toolDiscovery = toolDiscovery;
|
|
56
|
+
this.discovery = discovery;
|
|
57
|
+
this.prefix = agentPrefix(agentName);
|
|
58
|
+
this.reporter = new RunReporter({
|
|
59
|
+
logger: this.logger,
|
|
60
|
+
agent: agentName,
|
|
61
|
+
prefix: this.prefix,
|
|
62
|
+
observer: options.observer,
|
|
63
|
+
});
|
|
64
|
+
this.modelErrors = BaseCallbackHandler.fromMethods({
|
|
65
|
+
handleLLMError: (error) => {
|
|
66
|
+
this.reporter.logError(`the model failed: ${messageOf(error)}`);
|
|
67
|
+
this.reporter.notify((observer) => observer.onModelError?.({ agent: agentName, error }));
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Called by Nest: builds the agent, once the tool modules' providers exist.
|
|
73
|
+
*
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
76
|
+
async onModuleInit() {
|
|
77
|
+
this.assertUniqueName();
|
|
78
|
+
const tools = await this.toolDiscovery.getToolsFromModules(this.options.tools ?? [], this.reporter);
|
|
79
|
+
this.#graph = createAgent({
|
|
80
|
+
model: await this.resolveModel(this.options.model),
|
|
81
|
+
tools,
|
|
82
|
+
systemPrompt: this.options.systemPrompt,
|
|
83
|
+
// The first wraps the next: `toolErrors` sits right around the tool.
|
|
84
|
+
middleware: [unknownTools(this.reporter), toolErrors(this.reporter)],
|
|
85
|
+
});
|
|
86
|
+
this.logger.log(`${this.prefix}ready with ${tools.length} tool${tools.length === 1 ? '' : 's'}`, LOG_CONTEXT);
|
|
87
|
+
}
|
|
88
|
+
// Every registration provides its own name, so a name found twice in the
|
|
89
|
+
// container is two agents behind one token.
|
|
90
|
+
assertUniqueName() {
|
|
91
|
+
const registered = this.discovery
|
|
92
|
+
.getProviders()
|
|
93
|
+
.filter(({ token, instance }) => token === AGENT_NAME_TOKEN && instance === this.agentName);
|
|
94
|
+
if (registered.length > 1) {
|
|
95
|
+
throw new Error(duplicateAgentName(this.agentName === UNNAMED_AGENT ? undefined : this.agentName));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Build the model from its configuration, or hand back the instance the
|
|
100
|
+
* caller already built. Recognised by the members `createAgent` checks,
|
|
101
|
+
* never by `instanceof`, which two copies of `@langchain/core` break.
|
|
102
|
+
* See #52.
|
|
103
|
+
*
|
|
104
|
+
* @param option The `model` option.
|
|
105
|
+
* @returns The model `createAgent` receives.
|
|
106
|
+
*/
|
|
107
|
+
async resolveModel(option) {
|
|
108
|
+
// The types forbid a primitive, an untyped configuration does not. See #236.
|
|
109
|
+
const given = option;
|
|
110
|
+
if (typeof given !== 'object' || given === null) {
|
|
111
|
+
throw new Error(notAChatModel(this.prefix));
|
|
112
|
+
}
|
|
113
|
+
if (!('invoke' in option)) {
|
|
114
|
+
const { model, ...fields } = option;
|
|
115
|
+
try {
|
|
116
|
+
return await initChatModel(model, fields);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(modelNotBuilt(this.prefix, error), { cause: error });
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (typeof option.invoke !== 'function' ||
|
|
123
|
+
typeof option.bindTools !== 'function' ||
|
|
124
|
+
typeof option._streamResponseChunks !== 'function') {
|
|
125
|
+
throw new Error(notAChatModel(this.prefix));
|
|
126
|
+
}
|
|
127
|
+
// The same object, typed from the declarations `createAgent` reads.
|
|
128
|
+
return option;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Runs the agent to completion on one user message. Every failure is thrown
|
|
132
|
+
* as an `AgentRunError`, the original error in its `cause`.
|
|
133
|
+
*
|
|
134
|
+
* @param input The user's message.
|
|
135
|
+
* @returns The model's answer, the tools it called and what the run cost.
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const { output, tools } = await agent.run('What is 6 times 7?');
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
async run(input) {
|
|
142
|
+
const startedAt = Date.now();
|
|
143
|
+
const durationMs = () => Date.now() - startedAt;
|
|
144
|
+
try {
|
|
145
|
+
const { answer, messages } = await this.complete(input);
|
|
146
|
+
const finished = {
|
|
147
|
+
durationMs: durationMs(),
|
|
148
|
+
...summariseRun(messages),
|
|
149
|
+
};
|
|
150
|
+
this.reporter.notify((observer) => observer.onRunFinish?.({ agent: this.agentName, ...finished }));
|
|
151
|
+
return { status: 'completed', output: answer, ...finished };
|
|
152
|
+
}
|
|
153
|
+
catch (thrown) {
|
|
154
|
+
const error = thrown instanceof AgentRunError
|
|
155
|
+
? thrown
|
|
156
|
+
: new AgentRunError(agentRunFailed(this.prefix, thrown), this.agentName, { cause: thrown });
|
|
157
|
+
this.reporter.notify((observer) => observer.onRunError?.({
|
|
158
|
+
agent: this.agentName,
|
|
159
|
+
durationMs: durationMs(),
|
|
160
|
+
error,
|
|
161
|
+
}));
|
|
162
|
+
throw error;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
async complete(input) {
|
|
166
|
+
if (!this.#graph) {
|
|
167
|
+
throw new AgentRunError(agentNotBootstrapped(this.prefix), this.agentName);
|
|
168
|
+
}
|
|
169
|
+
const { messages } = await this.#graph.invoke({ messages: [{ role: 'user', content: input }] }, { callbacks: [this.modelErrors, ...(this.options.callbacks ?? [])] });
|
|
170
|
+
const last = messages[messages.length - 1];
|
|
171
|
+
if (!last || last.type !== 'ai') {
|
|
172
|
+
throw new AgentRunError(modelNeverReplied(this.prefix, last?.type), this.agentName);
|
|
173
|
+
}
|
|
174
|
+
// `text`, not `content`: block answers are an array.
|
|
175
|
+
if (!last.text) {
|
|
176
|
+
throw new AgentRunError(modelReplyEmpty(this.prefix), this.agentName);
|
|
177
|
+
}
|
|
178
|
+
return { answer: last.text, messages };
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
Agent = __decorate([
|
|
182
|
+
Injectable(),
|
|
183
|
+
__param(0, Inject(MODULE_OPTIONS_TOKEN)),
|
|
184
|
+
__param(1, Inject(AGENT_NAME_TOKEN)),
|
|
185
|
+
__metadata("design:paramtypes", [Object, String, ToolDiscoveryService,
|
|
186
|
+
DiscoveryService])
|
|
187
|
+
], Agent);
|
|
188
|
+
export { Agent };
|
|
189
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../lib/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAgB,M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AAC,CAAC;QACxE,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC;IACzC,CAAC;CACF,CAAA;AA1MY,KAAK;IADjB,UAAU,EAAE;IAcR,WAAA,MAAM,CAAC,oBAAoB,CAAC,CAAA;IAE5B,WAAA,MAAM,CAAC,gBAAgB,CAAC,CAAA;qDAEO,oBAAoB;QACxB,gBAAgB;GAlBnC,KAAK,CA0MjB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const TOOL_METADATA = "nestjs-langchain:tool";
|
|
2
|
+
export declare const TOOL_PARAMS_METADATA = "nestjs-langchain:tool-params";
|
|
3
|
+
export declare const PARAM_TYPES_METADATA = "design:paramtypes";
|
|
4
|
+
export declare const MODULE_METADATA_KEYS: string[];
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,0BAA0B,CAAC;AACrD,eAAO,MAAM,oBAAoB,iCAAiC,CAAC;AAGnE,eAAO,MAAM,oBAAoB,sBAAsB,CAAC;AAIxD,eAAO,MAAM,oBAAoB,UAKhC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Namespaced like the other tokens, so another library's marks are not read.
|
|
2
|
+
export const TOOL_METADATA = 'nestjs-langchain:tool';
|
|
3
|
+
export const TOOL_PARAMS_METADATA = 'nestjs-langchain:tool-params';
|
|
4
|
+
// Emitted by `emitDecoratorMetadata` on every decorated method.
|
|
5
|
+
export const PARAM_TYPES_METADATA = 'design:paramtypes';
|
|
6
|
+
// The keys `@Module()` writes, restated: `@nestjs/common/constants` is
|
|
7
|
+
// internal. See #97.
|
|
8
|
+
export const MODULE_METADATA_KEYS = [
|
|
9
|
+
'imports',
|
|
10
|
+
'providers',
|
|
11
|
+
'controllers',
|
|
12
|
+
'exports',
|
|
13
|
+
];
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../lib/constants.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,CAAC,MAAM,aAAa,GAAG,uBAAuB,CAAC;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC;AAEnE,gEAAgE;AAChE,MAAM,CAAC,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAExD,uEAAuE;AACvE,qBAAqB;AACrB,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,SAAS;IACT,WAAW;IACX,aAAa;IACb,SAAS;CACV,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/decorators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACtD,YAAY,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC"}
|