@dudousxd/nestjs-agent 0.1.0 → 0.3.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/dist/{agent-deps.factory-D9BHJJqm.d.cts → agent-deps.factory-DpVkZYCy.d.cts} +17 -20
- package/dist/{agent-deps.factory-D9BHJJqm.d.ts → agent-deps.factory-DpVkZYCy.d.ts} +17 -20
- package/dist/durable/index.cjs +368 -162
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +1 -1
- package/dist/durable/index.d.ts +1 -1
- package/dist/durable/index.js +332 -126
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +402 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -18
- package/dist/index.d.ts +106 -18
- package/dist/index.js +358 -125
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -22,9 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
// src/index.ts
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
|
+
AGENT_METADATA: () => AGENT_METADATA,
|
|
25
26
|
AGENT_TOOL_BRAND: () => AGENT_TOOL_BRAND,
|
|
26
27
|
AI_TOOL_METADATA: () => AI_TOOL_METADATA,
|
|
28
|
+
Agent: () => Agent,
|
|
27
29
|
AgentDepsFactory: () => AgentDepsFactory2,
|
|
30
|
+
AgentDiscoveryService: () => AgentDiscoveryService,
|
|
28
31
|
AgentModule: () => AgentModule,
|
|
29
32
|
AgentService: () => AgentService,
|
|
30
33
|
AiTool: () => AiTool,
|
|
@@ -33,17 +36,22 @@ __export(index_exports, {
|
|
|
33
36
|
InProcessTokenStreamSink: () => InProcessTokenStreamSink,
|
|
34
37
|
InlineAgentRunner: () => InlineAgentRunner,
|
|
35
38
|
LedgerQuotaStore: () => LedgerQuotaStore,
|
|
39
|
+
SYSTEM_PROMPT_CONTRIBUTOR_METADATA: () => SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
|
|
40
|
+
SYSTEM_PROMPT_METADATA: () => SYSTEM_PROMPT_METADATA,
|
|
41
|
+
SystemPrompt: () => SystemPrompt,
|
|
42
|
+
SystemPromptContributor: () => SystemPromptContributor,
|
|
36
43
|
delegateToolName: () => delegateToolName,
|
|
37
44
|
provideAgentTool: () => provideAgentTool,
|
|
45
|
+
readAgentMetadata: () => readAgentMetadata,
|
|
38
46
|
readAiToolMetadata: () => readAiToolMetadata,
|
|
39
47
|
utcDay: () => utcDay
|
|
40
48
|
});
|
|
41
49
|
module.exports = __toCommonJS(index_exports);
|
|
42
50
|
|
|
43
51
|
// src/agent.module.ts
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
52
|
+
var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
|
|
53
|
+
var import_common10 = require("@nestjs/common");
|
|
54
|
+
var import_core3 = require("@nestjs/core");
|
|
47
55
|
|
|
48
56
|
// src/agent-deps.factory.ts
|
|
49
57
|
var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
|
|
@@ -81,8 +89,9 @@ var AgentDepsFactory2 = class {
|
|
|
81
89
|
rolesPolicy;
|
|
82
90
|
registry;
|
|
83
91
|
agents;
|
|
92
|
+
promptContributors;
|
|
84
93
|
quota;
|
|
85
|
-
constructor(options, model, store, sink, rolesPolicy, registry, agents, quota) {
|
|
94
|
+
constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota) {
|
|
86
95
|
this.options = options;
|
|
87
96
|
this.model = model;
|
|
88
97
|
this.store = store;
|
|
@@ -90,10 +99,19 @@ var AgentDepsFactory2 = class {
|
|
|
90
99
|
this.rolesPolicy = rolesPolicy;
|
|
91
100
|
this.registry = registry;
|
|
92
101
|
this.agents = agents;
|
|
102
|
+
this.promptContributors = promptContributors;
|
|
93
103
|
this.quota = quota;
|
|
94
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The agent a turn uses when the caller names none: the explicit `defaultAgent` option, else the
|
|
107
|
+
* sole registered `@Agent` when there is exactly one, else `'default'` (a bare assistant).
|
|
108
|
+
*/
|
|
95
109
|
defaultAgentName() {
|
|
96
|
-
|
|
110
|
+
if (this.options.defaultAgent !== void 0) {
|
|
111
|
+
return this.options.defaultAgent;
|
|
112
|
+
}
|
|
113
|
+
const registered = this.agents.list();
|
|
114
|
+
return registered.length === 1 ? registered[0]?.name ?? "default" : "default";
|
|
97
115
|
}
|
|
98
116
|
effectiveTools(definition) {
|
|
99
117
|
if (definition === void 0) {
|
|
@@ -111,10 +129,6 @@ var AgentDepsFactory2 = class {
|
|
|
111
129
|
forAgent(agentName) {
|
|
112
130
|
const name = agentName ?? this.defaultAgentName();
|
|
113
131
|
const definition = this.agents.get(name);
|
|
114
|
-
const personas = /* @__PURE__ */ new Map();
|
|
115
|
-
for (const persona of definition?.personas ?? []) {
|
|
116
|
-
personas.set(persona.id, persona);
|
|
117
|
-
}
|
|
118
132
|
const toolAllowList = this.effectiveTools(definition);
|
|
119
133
|
const followUpsCount = this.followUpsCount();
|
|
120
134
|
const retrieval = this.options.retrieval;
|
|
@@ -124,10 +138,9 @@ var AgentDepsFactory2 = class {
|
|
|
124
138
|
sink: this.sink,
|
|
125
139
|
rolesPolicy: this.rolesPolicy,
|
|
126
140
|
registry: this.registry,
|
|
141
|
+
promptContributors: this.promptContributors,
|
|
127
142
|
systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
|
|
128
143
|
maxSteps: definition?.maxSteps ?? 8,
|
|
129
|
-
personas,
|
|
130
|
-
defaultPersona: definition?.defaultPersona ?? "default",
|
|
131
144
|
...definition?.modelId !== void 0 ? {
|
|
132
145
|
modelId: definition.modelId
|
|
133
146
|
} : {},
|
|
@@ -172,7 +185,8 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
172
185
|
_ts_param(4, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_ROLES_POLICY)),
|
|
173
186
|
_ts_param(5, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_TOOL_REGISTRY)),
|
|
174
187
|
_ts_param(6, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_REGISTRY)),
|
|
175
|
-
_ts_param(7, (0, import_common.Inject)(import_nestjs_agent_core.
|
|
188
|
+
_ts_param(7, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PROMPT_CONTRIBUTORS)),
|
|
189
|
+
_ts_param(8, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_QUOTA_STORE)),
|
|
176
190
|
_ts_metadata("design:type", Function),
|
|
177
191
|
_ts_metadata("design:paramtypes", [
|
|
178
192
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -182,6 +196,7 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
182
196
|
typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
|
|
183
197
|
typeof import_nestjs_agent_core.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core.ToolRegistry,
|
|
184
198
|
typeof import_nestjs_agent_core.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core.AgentRegistry,
|
|
199
|
+
Array,
|
|
185
200
|
Object
|
|
186
201
|
])
|
|
187
202
|
], AgentDepsFactory2);
|
|
@@ -231,10 +246,12 @@ var AgentService = class {
|
|
|
231
246
|
runner;
|
|
232
247
|
store;
|
|
233
248
|
deps;
|
|
234
|
-
|
|
249
|
+
quota;
|
|
250
|
+
constructor(runner, store, deps, quota) {
|
|
235
251
|
this.runner = runner;
|
|
236
252
|
this.store = store;
|
|
237
253
|
this.deps = deps;
|
|
254
|
+
this.quota = quota;
|
|
238
255
|
}
|
|
239
256
|
async chat(params) {
|
|
240
257
|
const agentName = params.agentName ?? this.deps.defaultAgentName();
|
|
@@ -245,13 +262,14 @@ var AgentService = class {
|
|
|
245
262
|
}
|
|
246
263
|
const created = await this.store.createThread({
|
|
247
264
|
actor: params.actor,
|
|
248
|
-
|
|
265
|
+
...params.transient === true ? {
|
|
266
|
+
transient: true
|
|
267
|
+
} : {}
|
|
249
268
|
});
|
|
250
269
|
threadId = created.id;
|
|
251
270
|
} else if (params.regenerate === true) {
|
|
252
271
|
await this.assertOwnsThread(params.actor, threadId);
|
|
253
272
|
}
|
|
254
|
-
const persona = this.resolvePersona(agentName, params.personaId);
|
|
255
273
|
const input = {
|
|
256
274
|
threadId,
|
|
257
275
|
actor: params.actor,
|
|
@@ -261,9 +279,6 @@ var AgentService = class {
|
|
|
261
279
|
...params.regenerate === true ? {
|
|
262
280
|
regenerate: true
|
|
263
281
|
} : {},
|
|
264
|
-
...persona !== void 0 ? {
|
|
265
|
-
persona
|
|
266
|
-
} : {},
|
|
267
282
|
...params.pageContext !== void 0 ? {
|
|
268
283
|
pageContext: params.pageContext
|
|
269
284
|
} : {}
|
|
@@ -297,18 +312,6 @@ var AgentService = class {
|
|
|
297
312
|
await this.assertOwnsActiveStream(actor, runId);
|
|
298
313
|
return this.runner.cancel(runId);
|
|
299
314
|
}
|
|
300
|
-
resolvePersona(agentName, id) {
|
|
301
|
-
const deps = this.deps.forAgent(agentName);
|
|
302
|
-
return deps.personas.get(id ?? deps.defaultPersona);
|
|
303
|
-
}
|
|
304
|
-
personaCatalog(agentName) {
|
|
305
|
-
return [
|
|
306
|
-
...this.deps.forAgent(agentName).personas.values()
|
|
307
|
-
].map((persona) => ({
|
|
308
|
-
id: persona.id,
|
|
309
|
-
label: persona.label
|
|
310
|
-
}));
|
|
311
|
-
}
|
|
312
315
|
listThreads(actorRef) {
|
|
313
316
|
return this.store.listThreads(actorRef);
|
|
314
317
|
}
|
|
@@ -324,8 +327,53 @@ var AgentService = class {
|
|
|
324
327
|
await this.assertOwnsThread(actor, threadId);
|
|
325
328
|
return this.store.forkThread(threadId, fromMessageId);
|
|
326
329
|
}
|
|
330
|
+
async renameThread(actor, threadId, title) {
|
|
331
|
+
const trimmed = title.trim();
|
|
332
|
+
if (trimmed.length === 0) {
|
|
333
|
+
throw new import_common2.BadRequestException("title must not be empty");
|
|
334
|
+
}
|
|
335
|
+
if (trimmed.length > 200) {
|
|
336
|
+
throw new import_common2.BadRequestException("title must be at most 200 characters");
|
|
337
|
+
}
|
|
338
|
+
await this.assertOwnsThread(actor, threadId);
|
|
339
|
+
return this.store.setTitle(threadId, trimmed);
|
|
340
|
+
}
|
|
341
|
+
async promoteThread(actor, threadId) {
|
|
342
|
+
await this.assertOwnsThread(actor, threadId);
|
|
343
|
+
return this.store.promoteThread(threadId);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Drop a message and everything after it — the "edit and resend" / "delete from here" primitive.
|
|
347
|
+
* The client then sends a fresh turn on the truncated thread. Ownership-gated like the other
|
|
348
|
+
* thread-scoped mutations.
|
|
349
|
+
*/
|
|
350
|
+
async truncateThreadFrom(actor, threadId, messageId) {
|
|
351
|
+
await this.assertOwnsThread(actor, threadId);
|
|
352
|
+
return this.store.truncateFrom(threadId, messageId);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* The day's usage for the badge: tokens + summed USD cost from the store, and the configured
|
|
356
|
+
* limit from the quota store (null → unlimited). `withinLimit` comes from the quota store so it
|
|
357
|
+
* can never drift from what enforcement uses.
|
|
358
|
+
*/
|
|
327
359
|
async quotaToday(actorRef) {
|
|
328
|
-
|
|
360
|
+
const day = utcDay();
|
|
361
|
+
const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, day);
|
|
362
|
+
if (this.quota === void 0) {
|
|
363
|
+
return {
|
|
364
|
+
usedTokens,
|
|
365
|
+
costUsd,
|
|
366
|
+
limitTokens: null,
|
|
367
|
+
withinLimit: true
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const state = await this.quota.check(actorRef, day);
|
|
371
|
+
return {
|
|
372
|
+
usedTokens: state.usedTokens,
|
|
373
|
+
costUsd,
|
|
374
|
+
limitTokens: state.limitTokens,
|
|
375
|
+
withinLimit: state.withinLimit
|
|
376
|
+
};
|
|
329
377
|
}
|
|
330
378
|
/**
|
|
331
379
|
* Authorization seam for thread-scoped endpoints: the caller must own the thread. A missing
|
|
@@ -376,11 +424,13 @@ AgentService = _ts_decorate2([
|
|
|
376
424
|
_ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_RUNNER)),
|
|
377
425
|
_ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
|
|
378
426
|
_ts_param2(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_DEPS_FACTORY)),
|
|
427
|
+
_ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_STORE)),
|
|
379
428
|
_ts_metadata2("design:type", Function),
|
|
380
429
|
_ts_metadata2("design:paramtypes", [
|
|
381
430
|
typeof AgentRunner === "undefined" ? Object : AgentRunner,
|
|
382
431
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
383
|
-
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
|
|
432
|
+
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
433
|
+
Object
|
|
384
434
|
])
|
|
385
435
|
], AgentService);
|
|
386
436
|
|
|
@@ -425,14 +475,14 @@ var ChatController = class {
|
|
|
425
475
|
...body.agent !== void 0 ? {
|
|
426
476
|
agentName: body.agent
|
|
427
477
|
} : {},
|
|
428
|
-
...body.persona !== void 0 ? {
|
|
429
|
-
personaId: body.persona
|
|
430
|
-
} : {},
|
|
431
478
|
...body.pageContext !== void 0 ? {
|
|
432
479
|
pageContext: body.pageContext
|
|
433
480
|
} : {},
|
|
434
481
|
...body.regenerate === true ? {
|
|
435
482
|
regenerate: true
|
|
483
|
+
} : {},
|
|
484
|
+
...body.transient === true ? {
|
|
485
|
+
transient: true
|
|
436
486
|
} : {}
|
|
437
487
|
});
|
|
438
488
|
await this.pipe(res, runId, threadId);
|
|
@@ -621,9 +671,6 @@ var ThreadsController = class {
|
|
|
621
671
|
const actor = await this.actorResolver.resolve(req);
|
|
622
672
|
return this.agent.listThreads(actor.id);
|
|
623
673
|
}
|
|
624
|
-
personas() {
|
|
625
|
-
return this.agent.personaCatalog();
|
|
626
|
-
}
|
|
627
674
|
async detail(req, id) {
|
|
628
675
|
const actor = await this.actorResolver.resolve(req);
|
|
629
676
|
return this.agent.getThread(actor, id);
|
|
@@ -639,6 +686,27 @@ var ThreadsController = class {
|
|
|
639
686
|
const actor = await this.actorResolver.resolve(req);
|
|
640
687
|
return this.agent.forkThread(actor, id, messageId);
|
|
641
688
|
}
|
|
689
|
+
async rename(req, id, body) {
|
|
690
|
+
const actor = await this.actorResolver.resolve(req);
|
|
691
|
+
await this.agent.renameThread(actor, id, body.title);
|
|
692
|
+
return {
|
|
693
|
+
ok: true
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
async promote(req, id) {
|
|
697
|
+
const actor = await this.actorResolver.resolve(req);
|
|
698
|
+
await this.agent.promoteThread(actor, id);
|
|
699
|
+
return {
|
|
700
|
+
ok: true
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
async truncateFrom(req, id, messageId) {
|
|
704
|
+
const actor = await this.actorResolver.resolve(req);
|
|
705
|
+
await this.agent.truncateThreadFrom(actor, id, messageId);
|
|
706
|
+
return {
|
|
707
|
+
ok: true
|
|
708
|
+
};
|
|
709
|
+
}
|
|
642
710
|
};
|
|
643
711
|
_ts_decorate5([
|
|
644
712
|
(0, import_common5.Get)(),
|
|
@@ -649,12 +717,6 @@ _ts_decorate5([
|
|
|
649
717
|
]),
|
|
650
718
|
_ts_metadata5("design:returntype", Promise)
|
|
651
719
|
], ThreadsController.prototype, "list", null);
|
|
652
|
-
_ts_decorate5([
|
|
653
|
-
(0, import_common5.Get)("personas/catalog"),
|
|
654
|
-
_ts_metadata5("design:type", Function),
|
|
655
|
-
_ts_metadata5("design:paramtypes", []),
|
|
656
|
-
_ts_metadata5("design:returntype", void 0)
|
|
657
|
-
], ThreadsController.prototype, "personas", null);
|
|
658
720
|
_ts_decorate5([
|
|
659
721
|
(0, import_common5.Get)(":id"),
|
|
660
722
|
_ts_param5(0, (0, import_common5.Req)()),
|
|
@@ -690,6 +752,43 @@ _ts_decorate5([
|
|
|
690
752
|
]),
|
|
691
753
|
_ts_metadata5("design:returntype", Promise)
|
|
692
754
|
], ThreadsController.prototype, "fork", null);
|
|
755
|
+
_ts_decorate5([
|
|
756
|
+
(0, import_common5.Patch)(":id"),
|
|
757
|
+
_ts_param5(0, (0, import_common5.Req)()),
|
|
758
|
+
_ts_param5(1, (0, import_common5.Param)("id")),
|
|
759
|
+
_ts_param5(2, (0, import_common5.Body)()),
|
|
760
|
+
_ts_metadata5("design:type", Function),
|
|
761
|
+
_ts_metadata5("design:paramtypes", [
|
|
762
|
+
typeof Request === "undefined" ? Object : Request,
|
|
763
|
+
String,
|
|
764
|
+
typeof RenameThreadBody === "undefined" ? Object : RenameThreadBody
|
|
765
|
+
]),
|
|
766
|
+
_ts_metadata5("design:returntype", Promise)
|
|
767
|
+
], ThreadsController.prototype, "rename", null);
|
|
768
|
+
_ts_decorate5([
|
|
769
|
+
(0, import_common5.Post)(":id/promote"),
|
|
770
|
+
_ts_param5(0, (0, import_common5.Req)()),
|
|
771
|
+
_ts_param5(1, (0, import_common5.Param)("id")),
|
|
772
|
+
_ts_metadata5("design:type", Function),
|
|
773
|
+
_ts_metadata5("design:paramtypes", [
|
|
774
|
+
typeof Request === "undefined" ? Object : Request,
|
|
775
|
+
String
|
|
776
|
+
]),
|
|
777
|
+
_ts_metadata5("design:returntype", Promise)
|
|
778
|
+
], ThreadsController.prototype, "promote", null);
|
|
779
|
+
_ts_decorate5([
|
|
780
|
+
(0, import_common5.Delete)(":id/from/:messageId"),
|
|
781
|
+
_ts_param5(0, (0, import_common5.Req)()),
|
|
782
|
+
_ts_param5(1, (0, import_common5.Param)("id")),
|
|
783
|
+
_ts_param5(2, (0, import_common5.Param)("messageId")),
|
|
784
|
+
_ts_metadata5("design:type", Function),
|
|
785
|
+
_ts_metadata5("design:paramtypes", [
|
|
786
|
+
typeof Request === "undefined" ? Object : Request,
|
|
787
|
+
String,
|
|
788
|
+
String
|
|
789
|
+
]),
|
|
790
|
+
_ts_metadata5("design:returntype", Promise)
|
|
791
|
+
], ThreadsController.prototype, "truncateFrom", null);
|
|
693
792
|
ThreadsController = _ts_decorate5([
|
|
694
793
|
(0, import_common5.Controller)("threads"),
|
|
695
794
|
_ts_param5(1, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_ACTOR_RESOLVER)),
|
|
@@ -777,14 +876,174 @@ ToolCallController = _ts_decorate6([
|
|
|
777
876
|
])
|
|
778
877
|
], ToolCallController);
|
|
779
878
|
|
|
780
|
-
// src/discovery/
|
|
879
|
+
// src/discovery/agent-discovery.service.ts
|
|
781
880
|
var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
|
|
782
881
|
var import_common7 = require("@nestjs/common");
|
|
783
882
|
var import_core = require("@nestjs/core");
|
|
883
|
+
|
|
884
|
+
// src/decorator/agent.decorator.ts
|
|
885
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
886
|
+
var AGENT_METADATA = Symbol.for("@dudousxd/nestjs-agent:agent-metadata");
|
|
887
|
+
function Agent(options) {
|
|
888
|
+
return (target) => {
|
|
889
|
+
Reflect.defineMetadata(AGENT_METADATA, options, target);
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
__name(Agent, "Agent");
|
|
893
|
+
function readAgentMetadata(target) {
|
|
894
|
+
return Reflect.getMetadata(AGENT_METADATA, target);
|
|
895
|
+
}
|
|
896
|
+
__name(readAgentMetadata, "readAgentMetadata");
|
|
897
|
+
|
|
898
|
+
// src/decorator/system-prompt.decorator.ts
|
|
899
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
900
|
+
var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
|
|
901
|
+
var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
|
|
902
|
+
function SystemPrompt() {
|
|
903
|
+
return (target, key) => {
|
|
904
|
+
Reflect.defineMetadata(SYSTEM_PROMPT_METADATA, true, target, key);
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
__name(SystemPrompt, "SystemPrompt");
|
|
908
|
+
function SystemPromptContributor() {
|
|
909
|
+
return (target, key) => {
|
|
910
|
+
Reflect.defineMetadata(SYSTEM_PROMPT_CONTRIBUTOR_METADATA, true, target, key);
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
__name(SystemPromptContributor, "SystemPromptContributor");
|
|
914
|
+
|
|
915
|
+
// src/discovery/agent-discovery.service.ts
|
|
916
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
917
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
918
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
919
|
+
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;
|
|
920
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
921
|
+
}
|
|
922
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
923
|
+
function _ts_metadata7(k, v) {
|
|
924
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
925
|
+
}
|
|
926
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
927
|
+
function _ts_param7(paramIndex, decorator) {
|
|
928
|
+
return function(target, key) {
|
|
929
|
+
decorator(target, key, paramIndex);
|
|
930
|
+
};
|
|
931
|
+
}
|
|
932
|
+
__name(_ts_param7, "_ts_param");
|
|
933
|
+
var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
934
|
+
static {
|
|
935
|
+
__name(this, "AgentDiscoveryService");
|
|
936
|
+
}
|
|
937
|
+
discovery;
|
|
938
|
+
scanner;
|
|
939
|
+
registry;
|
|
940
|
+
contributors;
|
|
941
|
+
logger = new import_common7.Logger(_AgentDiscoveryService.name);
|
|
942
|
+
constructor(discovery, scanner, registry, contributors) {
|
|
943
|
+
this.discovery = discovery;
|
|
944
|
+
this.scanner = scanner;
|
|
945
|
+
this.registry = registry;
|
|
946
|
+
this.contributors = contributors;
|
|
947
|
+
}
|
|
948
|
+
onModuleInit() {
|
|
949
|
+
for (const wrapper of this.discovery.getProviders()) {
|
|
950
|
+
const instance = wrapper.instance;
|
|
951
|
+
if (instance === null || typeof instance !== "object") {
|
|
952
|
+
continue;
|
|
953
|
+
}
|
|
954
|
+
const meta = readAgentMetadata(instance.constructor);
|
|
955
|
+
if (meta !== void 0) {
|
|
956
|
+
this.registry.register(this.definitionFrom(instance, meta));
|
|
957
|
+
}
|
|
958
|
+
this.collectContributors(instance);
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
/** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
|
|
962
|
+
definitionFrom(instance, meta) {
|
|
963
|
+
const promptMethod = this.methodWith(instance, SYSTEM_PROMPT_METADATA);
|
|
964
|
+
const systemPrompt = promptMethod !== void 0 ? (ctx) => promptMethod(ctx) : meta.systemPrompt ?? "You are a helpful assistant.";
|
|
965
|
+
return {
|
|
966
|
+
name: meta.name,
|
|
967
|
+
systemPrompt,
|
|
968
|
+
...meta.tools !== void 0 ? {
|
|
969
|
+
tools: meta.tools
|
|
970
|
+
} : {},
|
|
971
|
+
...meta.model !== void 0 ? {
|
|
972
|
+
modelId: meta.model
|
|
973
|
+
} : {},
|
|
974
|
+
...meta.maxSteps !== void 0 ? {
|
|
975
|
+
maxSteps: meta.maxSteps
|
|
976
|
+
} : {},
|
|
977
|
+
...meta.handoff !== void 0 ? {
|
|
978
|
+
delegatesTo: this.handoffNames(meta)
|
|
979
|
+
} : {}
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
/** Resolve each handoff `@Agent` class to its registered name (skipping non-agent classes). */
|
|
983
|
+
handoffNames(meta) {
|
|
984
|
+
const names = [];
|
|
985
|
+
for (const target of meta.handoff ?? []) {
|
|
986
|
+
const targetMeta = readAgentMetadata(target);
|
|
987
|
+
if (targetMeta === void 0) {
|
|
988
|
+
this.logger.warn(`Agent "${meta.name}" hands off to ${target.name}, which is not an @Agent \u2014 skipped.`);
|
|
989
|
+
continue;
|
|
990
|
+
}
|
|
991
|
+
names.push(targetMeta.name);
|
|
992
|
+
}
|
|
993
|
+
return names;
|
|
994
|
+
}
|
|
995
|
+
/** Push every `@SystemPromptContributor()` method on `instance` (bound) into the contributor list. */
|
|
996
|
+
collectContributors(instance) {
|
|
997
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
998
|
+
for (const name of this.scanner.getAllMethodNames(prototype)) {
|
|
999
|
+
if (Reflect.getMetadata(SYSTEM_PROMPT_CONTRIBUTOR_METADATA, prototype, name) === true) {
|
|
1000
|
+
const method = this.boundMethod(instance, name);
|
|
1001
|
+
if (method !== void 0) {
|
|
1002
|
+
this.contributors.push((ctx) => method(ctx));
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
/** The single method on `instance` carrying `metadataKey`, bound to the instance, or undefined. */
|
|
1008
|
+
methodWith(instance, metadataKey) {
|
|
1009
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
1010
|
+
for (const name of this.scanner.getAllMethodNames(prototype)) {
|
|
1011
|
+
if (Reflect.getMetadata(metadataKey, prototype, name) === true) {
|
|
1012
|
+
return this.boundMethod(instance, name);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
return void 0;
|
|
1016
|
+
}
|
|
1017
|
+
/** Bind a named method to its instance, guarding that it is actually a function. */
|
|
1018
|
+
boundMethod(instance, name) {
|
|
1019
|
+
const candidate = instance[name];
|
|
1020
|
+
if (typeof candidate !== "function") {
|
|
1021
|
+
return void 0;
|
|
1022
|
+
}
|
|
1023
|
+
return (ctx) => candidate.call(instance, ctx);
|
|
1024
|
+
}
|
|
1025
|
+
};
|
|
1026
|
+
AgentDiscoveryService = _ts_decorate7([
|
|
1027
|
+
(0, import_common7.Injectable)(),
|
|
1028
|
+
_ts_param7(2, (0, import_common7.Inject)(import_nestjs_agent_core8.AGENT_REGISTRY)),
|
|
1029
|
+
_ts_param7(3, (0, import_common7.Inject)(import_nestjs_agent_core8.AGENT_PROMPT_CONTRIBUTORS)),
|
|
1030
|
+
_ts_metadata7("design:type", Function),
|
|
1031
|
+
_ts_metadata7("design:paramtypes", [
|
|
1032
|
+
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1033
|
+
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1034
|
+
typeof import_nestjs_agent_core8.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core8.AgentRegistry,
|
|
1035
|
+
Array
|
|
1036
|
+
])
|
|
1037
|
+
], AgentDiscoveryService);
|
|
1038
|
+
|
|
1039
|
+
// src/discovery/ai-tool-discovery.service.ts
|
|
1040
|
+
var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
|
|
1041
|
+
var import_common8 = require("@nestjs/common");
|
|
1042
|
+
var import_core2 = require("@nestjs/core");
|
|
784
1043
|
var import_zod = require("zod");
|
|
785
1044
|
|
|
786
1045
|
// src/decorator/ai-tool.decorator.ts
|
|
787
|
-
var
|
|
1046
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
788
1047
|
var AI_TOOL_METADATA = Symbol("nestjs-agent:ai-tool");
|
|
789
1048
|
function AiTool(options) {
|
|
790
1049
|
return (target) => {
|
|
@@ -828,23 +1087,23 @@ function provideAgentTool(factoryOrTool, inject) {
|
|
|
828
1087
|
__name(provideAgentTool, "provideAgentTool");
|
|
829
1088
|
|
|
830
1089
|
// src/discovery/ai-tool-discovery.service.ts
|
|
831
|
-
function
|
|
1090
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
832
1091
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
833
1092
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
834
1093
|
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;
|
|
835
1094
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
836
1095
|
}
|
|
837
|
-
__name(
|
|
838
|
-
function
|
|
1096
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
1097
|
+
function _ts_metadata8(k, v) {
|
|
839
1098
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
840
1099
|
}
|
|
841
|
-
__name(
|
|
842
|
-
function
|
|
1100
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1101
|
+
function _ts_param8(paramIndex, decorator) {
|
|
843
1102
|
return function(target, key) {
|
|
844
1103
|
decorator(target, key, paramIndex);
|
|
845
1104
|
};
|
|
846
1105
|
}
|
|
847
|
-
__name(
|
|
1106
|
+
__name(_ts_param8, "_ts_param");
|
|
848
1107
|
var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
849
1108
|
static {
|
|
850
1109
|
__name(this, "AiToolDiscoveryService");
|
|
@@ -853,7 +1112,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
853
1112
|
registry;
|
|
854
1113
|
agents;
|
|
855
1114
|
options;
|
|
856
|
-
logger = new
|
|
1115
|
+
logger = new import_common8.Logger(_AiToolDiscoveryService.name);
|
|
857
1116
|
constructor(discovery, registry, agents, options) {
|
|
858
1117
|
this.discovery = discovery;
|
|
859
1118
|
this.registry = registry;
|
|
@@ -911,7 +1170,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
911
1170
|
for (const target of definition.delegatesTo ?? []) {
|
|
912
1171
|
const targetDefinition = this.agents.get(target);
|
|
913
1172
|
if (targetDefinition === void 0) {
|
|
914
|
-
throw new Error(`Agent "${definition.name}"
|
|
1173
|
+
throw new Error(`Agent "${definition.name}" hands off to "${target}", which is not a registered @Agent. Declare it as an @Agent provider or fix the reference.`);
|
|
915
1174
|
}
|
|
916
1175
|
const name = delegateToolName(target);
|
|
917
1176
|
if (this.registry.has(name)) {
|
|
@@ -951,14 +1210,14 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
951
1210
|
return true;
|
|
952
1211
|
}
|
|
953
1212
|
};
|
|
954
|
-
AiToolDiscoveryService =
|
|
955
|
-
(0,
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
typeof
|
|
1213
|
+
AiToolDiscoveryService = _ts_decorate8([
|
|
1214
|
+
(0, import_common8.Injectable)(),
|
|
1215
|
+
_ts_param8(1, (0, import_common8.Inject)(import_nestjs_agent_core9.AGENT_TOOL_REGISTRY)),
|
|
1216
|
+
_ts_param8(2, (0, import_common8.Inject)(import_nestjs_agent_core9.AGENT_REGISTRY)),
|
|
1217
|
+
_ts_param8(3, (0, import_common8.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
|
|
1218
|
+
_ts_metadata8("design:type", Function),
|
|
1219
|
+
_ts_metadata8("design:paramtypes", [
|
|
1220
|
+
typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
|
|
962
1221
|
typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
|
|
963
1222
|
typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
|
|
964
1223
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions
|
|
@@ -966,7 +1225,7 @@ AiToolDiscoveryService = _ts_decorate7([
|
|
|
966
1225
|
], AiToolDiscoveryService);
|
|
967
1226
|
|
|
968
1227
|
// src/in-process-sink.ts
|
|
969
|
-
var
|
|
1228
|
+
var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
|
|
970
1229
|
var InProcessTokenStreamSink = class {
|
|
971
1230
|
static {
|
|
972
1231
|
__name(this, "InProcessTokenStreamSink");
|
|
@@ -1021,7 +1280,7 @@ var InProcessTokenStreamSink = class {
|
|
|
1021
1280
|
}
|
|
1022
1281
|
if (buf.ended) {
|
|
1023
1282
|
if (buf.failure !== void 0) {
|
|
1024
|
-
throw new
|
|
1283
|
+
throw new import_nestjs_agent_core10.AgentStreamError(buf.failure);
|
|
1025
1284
|
}
|
|
1026
1285
|
return;
|
|
1027
1286
|
}
|
|
@@ -1057,32 +1316,32 @@ var LedgerQuotaStore = class {
|
|
|
1057
1316
|
};
|
|
1058
1317
|
|
|
1059
1318
|
// src/runner/inline-agent-runner.ts
|
|
1060
|
-
var
|
|
1061
|
-
var
|
|
1062
|
-
function
|
|
1319
|
+
var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
|
|
1320
|
+
var import_common9 = require("@nestjs/common");
|
|
1321
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1063
1322
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1064
1323
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1065
1324
|
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;
|
|
1066
1325
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1067
1326
|
}
|
|
1068
|
-
__name(
|
|
1069
|
-
function
|
|
1327
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1328
|
+
function _ts_metadata9(k, v) {
|
|
1070
1329
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1071
1330
|
}
|
|
1072
|
-
__name(
|
|
1073
|
-
function
|
|
1331
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1332
|
+
function _ts_param9(paramIndex, decorator) {
|
|
1074
1333
|
return function(target, key) {
|
|
1075
1334
|
decorator(target, key, paramIndex);
|
|
1076
1335
|
};
|
|
1077
1336
|
}
|
|
1078
|
-
__name(
|
|
1337
|
+
__name(_ts_param9, "_ts_param");
|
|
1079
1338
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
1080
1339
|
static {
|
|
1081
1340
|
__name(this, "InlineAgentRunner");
|
|
1082
1341
|
}
|
|
1083
1342
|
factory;
|
|
1084
1343
|
store;
|
|
1085
|
-
logger = new
|
|
1344
|
+
logger = new import_common9.Logger(_InlineAgentRunner.name);
|
|
1086
1345
|
pending = /* @__PURE__ */ new Map();
|
|
1087
1346
|
constructor(factory, store) {
|
|
1088
1347
|
this.factory = factory;
|
|
@@ -1093,14 +1352,14 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1093
1352
|
const day = input.day ?? utcDay();
|
|
1094
1353
|
const deps = this.factory.forAgent(input.agentName);
|
|
1095
1354
|
const hooks = this.topLevelHooks(runId, deps, input.actor, day);
|
|
1096
|
-
void (0,
|
|
1355
|
+
void (0, import_nestjs_agent_core11.runAgentLoop)({
|
|
1097
1356
|
...deps,
|
|
1098
1357
|
day
|
|
1099
1358
|
}, input, hooks).catch(async (error) => {
|
|
1100
1359
|
const message = error instanceof Error ? error.message : String(error);
|
|
1101
|
-
const code = error instanceof
|
|
1360
|
+
const code = error instanceof import_nestjs_agent_core11.QuotaExceededError ? "quota_exceeded" : "run_failed";
|
|
1102
1361
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
1103
|
-
(0,
|
|
1362
|
+
(0, import_nestjs_agent_core11.publishAgentRunFailed)({
|
|
1104
1363
|
runId,
|
|
1105
1364
|
code,
|
|
1106
1365
|
message
|
|
@@ -1147,7 +1406,6 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1147
1406
|
async runNested(agentName, task, actor, day, depth, sinkRunId) {
|
|
1148
1407
|
const subThread = await this.store.createThread({
|
|
1149
1408
|
actor,
|
|
1150
|
-
persona: "default",
|
|
1151
1409
|
transient: true
|
|
1152
1410
|
});
|
|
1153
1411
|
const runId = crypto.randomUUID();
|
|
@@ -1163,7 +1421,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1163
1421
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
1164
1422
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested(childName, childTask, actor, day, depth + 1, sinkRunId), "runAgent")
|
|
1165
1423
|
};
|
|
1166
|
-
return (0,
|
|
1424
|
+
return (0, import_nestjs_agent_core11.runAgentLoop)({
|
|
1167
1425
|
...deps,
|
|
1168
1426
|
day
|
|
1169
1427
|
}, {
|
|
@@ -1177,111 +1435,105 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1177
1435
|
}, hooks);
|
|
1178
1436
|
}
|
|
1179
1437
|
};
|
|
1180
|
-
InlineAgentRunner =
|
|
1181
|
-
(0,
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1438
|
+
InlineAgentRunner = _ts_decorate9([
|
|
1439
|
+
(0, import_common9.Injectable)(),
|
|
1440
|
+
_ts_param9(0, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_DEPS_FACTORY)),
|
|
1441
|
+
_ts_param9(1, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_STORE)),
|
|
1442
|
+
_ts_metadata9("design:type", Function),
|
|
1443
|
+
_ts_metadata9("design:paramtypes", [
|
|
1186
1444
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
1187
1445
|
typeof AgentStore === "undefined" ? Object : AgentStore
|
|
1188
1446
|
])
|
|
1189
1447
|
], InlineAgentRunner);
|
|
1190
1448
|
|
|
1191
1449
|
// src/agent.module.ts
|
|
1192
|
-
function
|
|
1450
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1193
1451
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1194
1452
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1195
1453
|
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;
|
|
1196
1454
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1197
1455
|
}
|
|
1198
|
-
__name(
|
|
1199
|
-
var FEATURE_INIT = Symbol("nestjs-agent:feature-init");
|
|
1456
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1200
1457
|
var DEFAULT_PATH = "agent";
|
|
1201
|
-
function defaultDefinition(options) {
|
|
1202
|
-
return {
|
|
1203
|
-
name: "default",
|
|
1204
|
-
...options.defaultAgent
|
|
1205
|
-
};
|
|
1206
|
-
}
|
|
1207
|
-
__name(defaultDefinition, "defaultDefinition");
|
|
1208
1458
|
function sharedProviders(durable, includeStore) {
|
|
1209
1459
|
const providers = [
|
|
1210
1460
|
{
|
|
1211
|
-
provide:
|
|
1212
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
1461
|
+
provide: import_nestjs_agent_core12.AGENT_TOOL_REGISTRY,
|
|
1462
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core12.ToolRegistry(), "useFactory")
|
|
1213
1463
|
},
|
|
1464
|
+
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
1214
1465
|
{
|
|
1215
|
-
provide:
|
|
1216
|
-
useFactory: /* @__PURE__ */ __name((
|
|
1217
|
-
const registry = new import_nestjs_agent_core11.AgentRegistry();
|
|
1218
|
-
registry.register(defaultDefinition(options));
|
|
1219
|
-
return registry;
|
|
1220
|
-
}, "useFactory"),
|
|
1221
|
-
inject: [
|
|
1222
|
-
import_nestjs_agent_core11.AGENT_OPTIONS
|
|
1223
|
-
]
|
|
1466
|
+
provide: import_nestjs_agent_core12.AGENT_REGISTRY,
|
|
1467
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core12.AgentRegistry(), "useFactory")
|
|
1224
1468
|
},
|
|
1469
|
+
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
1225
1470
|
{
|
|
1226
|
-
provide:
|
|
1471
|
+
provide: import_nestjs_agent_core12.AGENT_PROMPT_CONTRIBUTORS,
|
|
1472
|
+
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
1473
|
+
},
|
|
1474
|
+
{
|
|
1475
|
+
provide: import_nestjs_agent_core12.AGENT_SINK,
|
|
1227
1476
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
1228
1477
|
inject: [
|
|
1229
|
-
|
|
1478
|
+
import_nestjs_agent_core12.AGENT_OPTIONS
|
|
1230
1479
|
]
|
|
1231
1480
|
},
|
|
1232
1481
|
{
|
|
1233
|
-
provide:
|
|
1234
|
-
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new
|
|
1482
|
+
provide: import_nestjs_agent_core12.AGENT_ROLES_POLICY,
|
|
1483
|
+
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core12.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
|
|
1235
1484
|
inject: [
|
|
1236
|
-
|
|
1485
|
+
import_nestjs_agent_core12.AGENT_OPTIONS
|
|
1237
1486
|
]
|
|
1238
1487
|
},
|
|
1239
1488
|
{
|
|
1240
|
-
provide:
|
|
1489
|
+
provide: import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER,
|
|
1241
1490
|
useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
|
|
1242
1491
|
inject: [
|
|
1243
|
-
|
|
1492
|
+
import_nestjs_agent_core12.AGENT_OPTIONS
|
|
1244
1493
|
]
|
|
1245
1494
|
},
|
|
1246
1495
|
{
|
|
1247
|
-
provide:
|
|
1496
|
+
provide: import_nestjs_agent_core12.AGENT_MODEL,
|
|
1248
1497
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
1249
1498
|
inject: [
|
|
1250
|
-
|
|
1499
|
+
import_nestjs_agent_core12.AGENT_OPTIONS
|
|
1251
1500
|
]
|
|
1252
1501
|
},
|
|
1253
1502
|
{
|
|
1254
1503
|
// An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
|
|
1255
1504
|
// store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
|
|
1256
1505
|
// the loop already writes, so enforcement needs no extra shared state across replicas.
|
|
1257
|
-
provide:
|
|
1506
|
+
provide: import_nestjs_agent_core12.AGENT_QUOTA_STORE,
|
|
1258
1507
|
useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
|
|
1259
1508
|
inject: [
|
|
1260
|
-
|
|
1261
|
-
|
|
1509
|
+
import_nestjs_agent_core12.AGENT_OPTIONS,
|
|
1510
|
+
import_nestjs_agent_core12.AGENT_STORE
|
|
1262
1511
|
]
|
|
1263
1512
|
},
|
|
1264
1513
|
AgentDepsFactory2,
|
|
1265
1514
|
{
|
|
1266
|
-
provide:
|
|
1515
|
+
provide: import_nestjs_agent_core12.AGENT_DEPS_FACTORY,
|
|
1267
1516
|
useExisting: AgentDepsFactory2
|
|
1268
1517
|
},
|
|
1518
|
+
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
1519
|
+
// handoff tools (onApplicationBootstrap) reads the registry.
|
|
1520
|
+
AgentDiscoveryService,
|
|
1269
1521
|
AiToolDiscoveryService,
|
|
1270
1522
|
InlineAgentRunner,
|
|
1271
1523
|
AgentService
|
|
1272
1524
|
];
|
|
1273
1525
|
if (includeStore) {
|
|
1274
1526
|
providers.push({
|
|
1275
|
-
provide:
|
|
1527
|
+
provide: import_nestjs_agent_core12.AGENT_STORE,
|
|
1276
1528
|
useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
|
|
1277
1529
|
inject: [
|
|
1278
|
-
|
|
1530
|
+
import_nestjs_agent_core12.AGENT_OPTIONS
|
|
1279
1531
|
]
|
|
1280
1532
|
});
|
|
1281
1533
|
}
|
|
1282
1534
|
if (durable) {
|
|
1283
1535
|
providers.push({
|
|
1284
|
-
provide:
|
|
1536
|
+
provide: import_nestjs_agent_core12.AGENT_RUNNER,
|
|
1285
1537
|
useFactory: /* @__PURE__ */ __name((durableRunner) => {
|
|
1286
1538
|
if (durableRunner === void 0) {
|
|
1287
1539
|
throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
|
|
@@ -1290,14 +1542,14 @@ function sharedProviders(durable, includeStore) {
|
|
|
1290
1542
|
}, "useFactory"),
|
|
1291
1543
|
inject: [
|
|
1292
1544
|
{
|
|
1293
|
-
token:
|
|
1545
|
+
token: import_nestjs_agent_core12.AGENT_DURABLE_RUNNER,
|
|
1294
1546
|
optional: true
|
|
1295
1547
|
}
|
|
1296
1548
|
]
|
|
1297
1549
|
});
|
|
1298
1550
|
} else {
|
|
1299
1551
|
providers.push({
|
|
1300
|
-
provide:
|
|
1552
|
+
provide: import_nestjs_agent_core12.AGENT_RUNNER,
|
|
1301
1553
|
useExisting: InlineAgentRunner
|
|
1302
1554
|
});
|
|
1303
1555
|
}
|
|
@@ -1306,18 +1558,19 @@ function sharedProviders(durable, includeStore) {
|
|
|
1306
1558
|
__name(sharedProviders, "sharedProviders");
|
|
1307
1559
|
function exportsFor(includeStore) {
|
|
1308
1560
|
return [
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1561
|
+
import_nestjs_agent_core12.AGENT_OPTIONS,
|
|
1562
|
+
import_nestjs_agent_core12.AGENT_TOOL_REGISTRY,
|
|
1563
|
+
import_nestjs_agent_core12.AGENT_REGISTRY,
|
|
1564
|
+
import_nestjs_agent_core12.AGENT_SINK,
|
|
1565
|
+
import_nestjs_agent_core12.AGENT_ROLES_POLICY,
|
|
1566
|
+
import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER,
|
|
1567
|
+
import_nestjs_agent_core12.AGENT_MODEL,
|
|
1316
1568
|
...includeStore ? [
|
|
1317
|
-
|
|
1569
|
+
import_nestjs_agent_core12.AGENT_STORE
|
|
1318
1570
|
] : [],
|
|
1319
|
-
|
|
1320
|
-
|
|
1571
|
+
import_nestjs_agent_core12.AGENT_QUOTA_STORE,
|
|
1572
|
+
import_nestjs_agent_core12.AGENT_PROMPT_CONTRIBUTORS,
|
|
1573
|
+
import_nestjs_agent_core12.AGENT_DEPS_FACTORY,
|
|
1321
1574
|
AgentDepsFactory2,
|
|
1322
1575
|
AgentService,
|
|
1323
1576
|
InlineAgentRunner
|
|
@@ -1331,7 +1584,7 @@ var CONTROLLERS = [
|
|
|
1331
1584
|
QuotaController
|
|
1332
1585
|
];
|
|
1333
1586
|
function routerFor(path) {
|
|
1334
|
-
return
|
|
1587
|
+
return import_core3.RouterModule.register([
|
|
1335
1588
|
{
|
|
1336
1589
|
path,
|
|
1337
1590
|
module: AgentModule
|
|
@@ -1350,13 +1603,13 @@ var AgentModule = class _AgentModule {
|
|
|
1350
1603
|
module: _AgentModule,
|
|
1351
1604
|
global: true,
|
|
1352
1605
|
imports: [
|
|
1353
|
-
|
|
1606
|
+
import_core3.DiscoveryModule,
|
|
1354
1607
|
routerFor(path)
|
|
1355
1608
|
],
|
|
1356
1609
|
controllers: CONTROLLERS,
|
|
1357
1610
|
providers: [
|
|
1358
1611
|
{
|
|
1359
|
-
provide:
|
|
1612
|
+
provide: import_nestjs_agent_core12.AGENT_OPTIONS,
|
|
1360
1613
|
useValue: options
|
|
1361
1614
|
},
|
|
1362
1615
|
...sharedProviders(options.durable ?? false, includeStore)
|
|
@@ -1370,14 +1623,14 @@ var AgentModule = class _AgentModule {
|
|
|
1370
1623
|
module: _AgentModule,
|
|
1371
1624
|
global: true,
|
|
1372
1625
|
imports: [
|
|
1373
|
-
|
|
1626
|
+
import_core3.DiscoveryModule,
|
|
1374
1627
|
routerFor(path),
|
|
1375
1628
|
...options.imports ?? []
|
|
1376
1629
|
],
|
|
1377
1630
|
controllers: CONTROLLERS,
|
|
1378
1631
|
providers: [
|
|
1379
1632
|
{
|
|
1380
|
-
provide:
|
|
1633
|
+
provide: import_nestjs_agent_core12.AGENT_OPTIONS,
|
|
1381
1634
|
useFactory: options.useFactory,
|
|
1382
1635
|
inject: options.inject ?? []
|
|
1383
1636
|
},
|
|
@@ -1388,30 +1641,10 @@ var AgentModule = class _AgentModule {
|
|
|
1388
1641
|
exports: exportsFor(true)
|
|
1389
1642
|
};
|
|
1390
1643
|
}
|
|
1391
|
-
/** Register additional named agents (an orchestrator + its sub-agents). */
|
|
1392
|
-
static forFeature(definitions) {
|
|
1393
|
-
return {
|
|
1394
|
-
module: _AgentModule,
|
|
1395
|
-
providers: [
|
|
1396
|
-
{
|
|
1397
|
-
provide: FEATURE_INIT,
|
|
1398
|
-
useFactory: /* @__PURE__ */ __name((registry) => {
|
|
1399
|
-
for (const definition of definitions) {
|
|
1400
|
-
registry.register(definition);
|
|
1401
|
-
}
|
|
1402
|
-
return true;
|
|
1403
|
-
}, "useFactory"),
|
|
1404
|
-
inject: [
|
|
1405
|
-
import_nestjs_agent_core11.AGENT_REGISTRY
|
|
1406
|
-
]
|
|
1407
|
-
}
|
|
1408
|
-
]
|
|
1409
|
-
};
|
|
1410
|
-
}
|
|
1411
1644
|
};
|
|
1412
|
-
AgentModule =
|
|
1413
|
-
(0,
|
|
1414
|
-
(0,
|
|
1645
|
+
AgentModule = _ts_decorate10([
|
|
1646
|
+
(0, import_common10.Global)(),
|
|
1647
|
+
(0, import_common10.Module)({})
|
|
1415
1648
|
], AgentModule);
|
|
1416
1649
|
|
|
1417
1650
|
// src/resolver/header-actor-resolver.ts
|
|
@@ -1448,9 +1681,12 @@ var HeaderActorResolver = class {
|
|
|
1448
1681
|
__reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports);
|
|
1449
1682
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1450
1683
|
0 && (module.exports = {
|
|
1684
|
+
AGENT_METADATA,
|
|
1451
1685
|
AGENT_TOOL_BRAND,
|
|
1452
1686
|
AI_TOOL_METADATA,
|
|
1687
|
+
Agent,
|
|
1453
1688
|
AgentDepsFactory,
|
|
1689
|
+
AgentDiscoveryService,
|
|
1454
1690
|
AgentModule,
|
|
1455
1691
|
AgentService,
|
|
1456
1692
|
AiTool,
|
|
@@ -1459,8 +1695,13 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
|
|
|
1459
1695
|
InProcessTokenStreamSink,
|
|
1460
1696
|
InlineAgentRunner,
|
|
1461
1697
|
LedgerQuotaStore,
|
|
1698
|
+
SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
|
|
1699
|
+
SYSTEM_PROMPT_METADATA,
|
|
1700
|
+
SystemPrompt,
|
|
1701
|
+
SystemPromptContributor,
|
|
1462
1702
|
delegateToolName,
|
|
1463
1703
|
provideAgentTool,
|
|
1704
|
+
readAgentMetadata,
|
|
1464
1705
|
readAiToolMetadata,
|
|
1465
1706
|
utcDay,
|
|
1466
1707
|
...require("@dudousxd/nestjs-agent-core")
|