@dudousxd/nestjs-agent 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +253 -160
- 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 +210 -117
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +287 -159
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -14
- package/dist/index.d.ts +85 -14
- package/dist/index.js +236 -116
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,12 +2,12 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/agent.module.ts
|
|
5
|
-
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_DURABLE_RUNNER, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_REGISTRY as
|
|
5
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_DURABLE_RUNNER, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_REGISTRY as AGENT_REGISTRY4, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry4, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
6
6
|
import { Global, Module } from "@nestjs/common";
|
|
7
7
|
import { DiscoveryModule, RouterModule } from "@nestjs/core";
|
|
8
8
|
|
|
9
9
|
// src/agent-deps.factory.ts
|
|
10
|
-
import { AGENT_MODEL, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
|
|
10
|
+
import { AGENT_MODEL, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
|
|
11
11
|
import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
|
|
12
12
|
import { Inject, Injectable } from "@nestjs/common";
|
|
13
13
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -42,8 +42,9 @@ var AgentDepsFactory2 = class {
|
|
|
42
42
|
rolesPolicy;
|
|
43
43
|
registry;
|
|
44
44
|
agents;
|
|
45
|
+
promptContributors;
|
|
45
46
|
quota;
|
|
46
|
-
constructor(options, model, store, sink, rolesPolicy, registry, agents, quota) {
|
|
47
|
+
constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota) {
|
|
47
48
|
this.options = options;
|
|
48
49
|
this.model = model;
|
|
49
50
|
this.store = store;
|
|
@@ -51,10 +52,19 @@ var AgentDepsFactory2 = class {
|
|
|
51
52
|
this.rolesPolicy = rolesPolicy;
|
|
52
53
|
this.registry = registry;
|
|
53
54
|
this.agents = agents;
|
|
55
|
+
this.promptContributors = promptContributors;
|
|
54
56
|
this.quota = quota;
|
|
55
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* The agent a turn uses when the caller names none: the explicit `defaultAgent` option, else the
|
|
60
|
+
* sole registered `@Agent` when there is exactly one, else `'default'` (a bare assistant).
|
|
61
|
+
*/
|
|
56
62
|
defaultAgentName() {
|
|
57
|
-
|
|
63
|
+
if (this.options.defaultAgent !== void 0) {
|
|
64
|
+
return this.options.defaultAgent;
|
|
65
|
+
}
|
|
66
|
+
const registered = this.agents.list();
|
|
67
|
+
return registered.length === 1 ? registered[0]?.name ?? "default" : "default";
|
|
58
68
|
}
|
|
59
69
|
effectiveTools(definition) {
|
|
60
70
|
if (definition === void 0) {
|
|
@@ -72,10 +82,6 @@ var AgentDepsFactory2 = class {
|
|
|
72
82
|
forAgent(agentName) {
|
|
73
83
|
const name = agentName ?? this.defaultAgentName();
|
|
74
84
|
const definition = this.agents.get(name);
|
|
75
|
-
const personas = /* @__PURE__ */ new Map();
|
|
76
|
-
for (const persona of definition?.personas ?? []) {
|
|
77
|
-
personas.set(persona.id, persona);
|
|
78
|
-
}
|
|
79
85
|
const toolAllowList = this.effectiveTools(definition);
|
|
80
86
|
const followUpsCount = this.followUpsCount();
|
|
81
87
|
const retrieval = this.options.retrieval;
|
|
@@ -85,10 +91,9 @@ var AgentDepsFactory2 = class {
|
|
|
85
91
|
sink: this.sink,
|
|
86
92
|
rolesPolicy: this.rolesPolicy,
|
|
87
93
|
registry: this.registry,
|
|
94
|
+
promptContributors: this.promptContributors,
|
|
88
95
|
systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
|
|
89
96
|
maxSteps: definition?.maxSteps ?? 8,
|
|
90
|
-
personas,
|
|
91
|
-
defaultPersona: definition?.defaultPersona ?? "default",
|
|
92
97
|
...definition?.modelId !== void 0 ? {
|
|
93
98
|
modelId: definition.modelId
|
|
94
99
|
} : {},
|
|
@@ -133,7 +138,8 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
133
138
|
_ts_param(4, Inject(AGENT_ROLES_POLICY)),
|
|
134
139
|
_ts_param(5, Inject(AGENT_TOOL_REGISTRY)),
|
|
135
140
|
_ts_param(6, Inject(AGENT_REGISTRY)),
|
|
136
|
-
_ts_param(7, Inject(
|
|
141
|
+
_ts_param(7, Inject(AGENT_PROMPT_CONTRIBUTORS)),
|
|
142
|
+
_ts_param(8, Inject(AGENT_QUOTA_STORE)),
|
|
137
143
|
_ts_metadata("design:type", Function),
|
|
138
144
|
_ts_metadata("design:paramtypes", [
|
|
139
145
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -143,6 +149,7 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
143
149
|
typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
|
|
144
150
|
typeof ToolRegistry2 === "undefined" ? Object : ToolRegistry2,
|
|
145
151
|
typeof AgentRegistry2 === "undefined" ? Object : AgentRegistry2,
|
|
152
|
+
Array,
|
|
146
153
|
Object
|
|
147
154
|
])
|
|
148
155
|
], AgentDepsFactory2);
|
|
@@ -205,14 +212,12 @@ var AgentService = class {
|
|
|
205
212
|
throw new BadRequestException("regenerate requires an existing threadId");
|
|
206
213
|
}
|
|
207
214
|
const created = await this.store.createThread({
|
|
208
|
-
actor: params.actor
|
|
209
|
-
persona: params.personaId ?? this.deps.forAgent(agentName).defaultPersona
|
|
215
|
+
actor: params.actor
|
|
210
216
|
});
|
|
211
217
|
threadId = created.id;
|
|
212
218
|
} else if (params.regenerate === true) {
|
|
213
219
|
await this.assertOwnsThread(params.actor, threadId);
|
|
214
220
|
}
|
|
215
|
-
const persona = this.resolvePersona(agentName, params.personaId);
|
|
216
221
|
const input = {
|
|
217
222
|
threadId,
|
|
218
223
|
actor: params.actor,
|
|
@@ -222,9 +227,6 @@ var AgentService = class {
|
|
|
222
227
|
...params.regenerate === true ? {
|
|
223
228
|
regenerate: true
|
|
224
229
|
} : {},
|
|
225
|
-
...persona !== void 0 ? {
|
|
226
|
-
persona
|
|
227
|
-
} : {},
|
|
228
230
|
...params.pageContext !== void 0 ? {
|
|
229
231
|
pageContext: params.pageContext
|
|
230
232
|
} : {}
|
|
@@ -258,18 +260,6 @@ var AgentService = class {
|
|
|
258
260
|
await this.assertOwnsActiveStream(actor, runId);
|
|
259
261
|
return this.runner.cancel(runId);
|
|
260
262
|
}
|
|
261
|
-
resolvePersona(agentName, id) {
|
|
262
|
-
const deps = this.deps.forAgent(agentName);
|
|
263
|
-
return deps.personas.get(id ?? deps.defaultPersona);
|
|
264
|
-
}
|
|
265
|
-
personaCatalog(agentName) {
|
|
266
|
-
return [
|
|
267
|
-
...this.deps.forAgent(agentName).personas.values()
|
|
268
|
-
].map((persona) => ({
|
|
269
|
-
id: persona.id,
|
|
270
|
-
label: persona.label
|
|
271
|
-
}));
|
|
272
|
-
}
|
|
273
263
|
listThreads(actorRef) {
|
|
274
264
|
return this.store.listThreads(actorRef);
|
|
275
265
|
}
|
|
@@ -386,9 +376,6 @@ var ChatController = class {
|
|
|
386
376
|
...body.agent !== void 0 ? {
|
|
387
377
|
agentName: body.agent
|
|
388
378
|
} : {},
|
|
389
|
-
...body.persona !== void 0 ? {
|
|
390
|
-
personaId: body.persona
|
|
391
|
-
} : {},
|
|
392
379
|
...body.pageContext !== void 0 ? {
|
|
393
380
|
pageContext: body.pageContext
|
|
394
381
|
} : {},
|
|
@@ -582,9 +569,6 @@ var ThreadsController = class {
|
|
|
582
569
|
const actor = await this.actorResolver.resolve(req);
|
|
583
570
|
return this.agent.listThreads(actor.id);
|
|
584
571
|
}
|
|
585
|
-
personas() {
|
|
586
|
-
return this.agent.personaCatalog();
|
|
587
|
-
}
|
|
588
572
|
async detail(req, id) {
|
|
589
573
|
const actor = await this.actorResolver.resolve(req);
|
|
590
574
|
return this.agent.getThread(actor, id);
|
|
@@ -610,12 +594,6 @@ _ts_decorate5([
|
|
|
610
594
|
]),
|
|
611
595
|
_ts_metadata5("design:returntype", Promise)
|
|
612
596
|
], ThreadsController.prototype, "list", null);
|
|
613
|
-
_ts_decorate5([
|
|
614
|
-
Get3("personas/catalog"),
|
|
615
|
-
_ts_metadata5("design:type", Function),
|
|
616
|
-
_ts_metadata5("design:paramtypes", []),
|
|
617
|
-
_ts_metadata5("design:returntype", void 0)
|
|
618
|
-
], ThreadsController.prototype, "personas", null);
|
|
619
597
|
_ts_decorate5([
|
|
620
598
|
Get3(":id"),
|
|
621
599
|
_ts_param5(0, Req3()),
|
|
@@ -738,10 +716,170 @@ ToolCallController = _ts_decorate6([
|
|
|
738
716
|
])
|
|
739
717
|
], ToolCallController);
|
|
740
718
|
|
|
741
|
-
// src/discovery/
|
|
742
|
-
import {
|
|
719
|
+
// src/discovery/agent-discovery.service.ts
|
|
720
|
+
import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
743
721
|
import { Inject as Inject7, Injectable as Injectable3, Logger } from "@nestjs/common";
|
|
744
|
-
import { DiscoveryService } from "@nestjs/core";
|
|
722
|
+
import { DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
723
|
+
|
|
724
|
+
// src/decorator/agent.decorator.ts
|
|
725
|
+
import "reflect-metadata";
|
|
726
|
+
var AGENT_METADATA = Symbol.for("@dudousxd/nestjs-agent:agent-metadata");
|
|
727
|
+
function Agent(options) {
|
|
728
|
+
return (target) => {
|
|
729
|
+
Reflect.defineMetadata(AGENT_METADATA, options, target);
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
__name(Agent, "Agent");
|
|
733
|
+
function readAgentMetadata(target) {
|
|
734
|
+
return Reflect.getMetadata(AGENT_METADATA, target);
|
|
735
|
+
}
|
|
736
|
+
__name(readAgentMetadata, "readAgentMetadata");
|
|
737
|
+
|
|
738
|
+
// src/decorator/system-prompt.decorator.ts
|
|
739
|
+
import "reflect-metadata";
|
|
740
|
+
var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
|
|
741
|
+
var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
|
|
742
|
+
function SystemPrompt() {
|
|
743
|
+
return (target, key) => {
|
|
744
|
+
Reflect.defineMetadata(SYSTEM_PROMPT_METADATA, true, target, key);
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
__name(SystemPrompt, "SystemPrompt");
|
|
748
|
+
function SystemPromptContributor() {
|
|
749
|
+
return (target, key) => {
|
|
750
|
+
Reflect.defineMetadata(SYSTEM_PROMPT_CONTRIBUTOR_METADATA, true, target, key);
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
__name(SystemPromptContributor, "SystemPromptContributor");
|
|
754
|
+
|
|
755
|
+
// src/discovery/agent-discovery.service.ts
|
|
756
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
757
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
758
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
759
|
+
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;
|
|
760
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
761
|
+
}
|
|
762
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
763
|
+
function _ts_metadata7(k, v) {
|
|
764
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
765
|
+
}
|
|
766
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
767
|
+
function _ts_param7(paramIndex, decorator) {
|
|
768
|
+
return function(target, key) {
|
|
769
|
+
decorator(target, key, paramIndex);
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
__name(_ts_param7, "_ts_param");
|
|
773
|
+
var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
774
|
+
static {
|
|
775
|
+
__name(this, "AgentDiscoveryService");
|
|
776
|
+
}
|
|
777
|
+
discovery;
|
|
778
|
+
scanner;
|
|
779
|
+
registry;
|
|
780
|
+
contributors;
|
|
781
|
+
logger = new Logger(_AgentDiscoveryService.name);
|
|
782
|
+
constructor(discovery, scanner, registry, contributors) {
|
|
783
|
+
this.discovery = discovery;
|
|
784
|
+
this.scanner = scanner;
|
|
785
|
+
this.registry = registry;
|
|
786
|
+
this.contributors = contributors;
|
|
787
|
+
}
|
|
788
|
+
onModuleInit() {
|
|
789
|
+
for (const wrapper of this.discovery.getProviders()) {
|
|
790
|
+
const instance = wrapper.instance;
|
|
791
|
+
if (instance === null || typeof instance !== "object") {
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const meta = readAgentMetadata(instance.constructor);
|
|
795
|
+
if (meta !== void 0) {
|
|
796
|
+
this.registry.register(this.definitionFrom(instance, meta));
|
|
797
|
+
}
|
|
798
|
+
this.collectContributors(instance);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
/** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
|
|
802
|
+
definitionFrom(instance, meta) {
|
|
803
|
+
const promptMethod = this.methodWith(instance, SYSTEM_PROMPT_METADATA);
|
|
804
|
+
const systemPrompt = promptMethod !== void 0 ? (ctx) => promptMethod(ctx) : meta.systemPrompt ?? "You are a helpful assistant.";
|
|
805
|
+
return {
|
|
806
|
+
name: meta.name,
|
|
807
|
+
systemPrompt,
|
|
808
|
+
...meta.tools !== void 0 ? {
|
|
809
|
+
tools: meta.tools
|
|
810
|
+
} : {},
|
|
811
|
+
...meta.model !== void 0 ? {
|
|
812
|
+
modelId: meta.model
|
|
813
|
+
} : {},
|
|
814
|
+
...meta.maxSteps !== void 0 ? {
|
|
815
|
+
maxSteps: meta.maxSteps
|
|
816
|
+
} : {},
|
|
817
|
+
...meta.handoff !== void 0 ? {
|
|
818
|
+
delegatesTo: this.handoffNames(meta)
|
|
819
|
+
} : {}
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
/** Resolve each handoff `@Agent` class to its registered name (skipping non-agent classes). */
|
|
823
|
+
handoffNames(meta) {
|
|
824
|
+
const names = [];
|
|
825
|
+
for (const target of meta.handoff ?? []) {
|
|
826
|
+
const targetMeta = readAgentMetadata(target);
|
|
827
|
+
if (targetMeta === void 0) {
|
|
828
|
+
this.logger.warn(`Agent "${meta.name}" hands off to ${target.name}, which is not an @Agent \u2014 skipped.`);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
names.push(targetMeta.name);
|
|
832
|
+
}
|
|
833
|
+
return names;
|
|
834
|
+
}
|
|
835
|
+
/** Push every `@SystemPromptContributor()` method on `instance` (bound) into the contributor list. */
|
|
836
|
+
collectContributors(instance) {
|
|
837
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
838
|
+
for (const name of this.scanner.getAllMethodNames(prototype)) {
|
|
839
|
+
if (Reflect.getMetadata(SYSTEM_PROMPT_CONTRIBUTOR_METADATA, prototype, name) === true) {
|
|
840
|
+
const method = this.boundMethod(instance, name);
|
|
841
|
+
if (method !== void 0) {
|
|
842
|
+
this.contributors.push((ctx) => method(ctx));
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
/** The single method on `instance` carrying `metadataKey`, bound to the instance, or undefined. */
|
|
848
|
+
methodWith(instance, metadataKey) {
|
|
849
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
850
|
+
for (const name of this.scanner.getAllMethodNames(prototype)) {
|
|
851
|
+
if (Reflect.getMetadata(metadataKey, prototype, name) === true) {
|
|
852
|
+
return this.boundMethod(instance, name);
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
/** Bind a named method to its instance, guarding that it is actually a function. */
|
|
858
|
+
boundMethod(instance, name) {
|
|
859
|
+
const candidate = instance[name];
|
|
860
|
+
if (typeof candidate !== "function") {
|
|
861
|
+
return void 0;
|
|
862
|
+
}
|
|
863
|
+
return (ctx) => candidate.call(instance, ctx);
|
|
864
|
+
}
|
|
865
|
+
};
|
|
866
|
+
AgentDiscoveryService = _ts_decorate7([
|
|
867
|
+
Injectable3(),
|
|
868
|
+
_ts_param7(2, Inject7(AGENT_REGISTRY2)),
|
|
869
|
+
_ts_param7(3, Inject7(AGENT_PROMPT_CONTRIBUTORS2)),
|
|
870
|
+
_ts_metadata7("design:type", Function),
|
|
871
|
+
_ts_metadata7("design:paramtypes", [
|
|
872
|
+
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
873
|
+
typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
|
|
874
|
+
typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
|
|
875
|
+
Array
|
|
876
|
+
])
|
|
877
|
+
], AgentDiscoveryService);
|
|
878
|
+
|
|
879
|
+
// src/discovery/ai-tool-discovery.service.ts
|
|
880
|
+
import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_REGISTRY as AGENT_REGISTRY3, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2 } from "@dudousxd/nestjs-agent-core";
|
|
881
|
+
import { Inject as Inject8, Injectable as Injectable4, Logger as Logger2 } from "@nestjs/common";
|
|
882
|
+
import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
|
|
745
883
|
import { z } from "zod";
|
|
746
884
|
|
|
747
885
|
// src/decorator/ai-tool.decorator.ts
|
|
@@ -789,23 +927,23 @@ function provideAgentTool(factoryOrTool, inject) {
|
|
|
789
927
|
__name(provideAgentTool, "provideAgentTool");
|
|
790
928
|
|
|
791
929
|
// src/discovery/ai-tool-discovery.service.ts
|
|
792
|
-
function
|
|
930
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
793
931
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
794
932
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
795
933
|
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;
|
|
796
934
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
797
935
|
}
|
|
798
|
-
__name(
|
|
799
|
-
function
|
|
936
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
937
|
+
function _ts_metadata8(k, v) {
|
|
800
938
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
801
939
|
}
|
|
802
|
-
__name(
|
|
803
|
-
function
|
|
940
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
941
|
+
function _ts_param8(paramIndex, decorator) {
|
|
804
942
|
return function(target, key) {
|
|
805
943
|
decorator(target, key, paramIndex);
|
|
806
944
|
};
|
|
807
945
|
}
|
|
808
|
-
__name(
|
|
946
|
+
__name(_ts_param8, "_ts_param");
|
|
809
947
|
var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
810
948
|
static {
|
|
811
949
|
__name(this, "AiToolDiscoveryService");
|
|
@@ -814,7 +952,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
814
952
|
registry;
|
|
815
953
|
agents;
|
|
816
954
|
options;
|
|
817
|
-
logger = new
|
|
955
|
+
logger = new Logger2(_AiToolDiscoveryService.name);
|
|
818
956
|
constructor(discovery, registry, agents, options) {
|
|
819
957
|
this.discovery = discovery;
|
|
820
958
|
this.registry = registry;
|
|
@@ -872,7 +1010,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
872
1010
|
for (const target of definition.delegatesTo ?? []) {
|
|
873
1011
|
const targetDefinition = this.agents.get(target);
|
|
874
1012
|
if (targetDefinition === void 0) {
|
|
875
|
-
throw new Error(`Agent "${definition.name}"
|
|
1013
|
+
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.`);
|
|
876
1014
|
}
|
|
877
1015
|
const name = delegateToolName(target);
|
|
878
1016
|
if (this.registry.has(name)) {
|
|
@@ -912,14 +1050,14 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
912
1050
|
return true;
|
|
913
1051
|
}
|
|
914
1052
|
};
|
|
915
|
-
AiToolDiscoveryService =
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
typeof
|
|
1053
|
+
AiToolDiscoveryService = _ts_decorate8([
|
|
1054
|
+
Injectable4(),
|
|
1055
|
+
_ts_param8(1, Inject8(AGENT_TOOL_REGISTRY2)),
|
|
1056
|
+
_ts_param8(2, Inject8(AGENT_REGISTRY3)),
|
|
1057
|
+
_ts_param8(3, Inject8(AGENT_OPTIONS2)),
|
|
1058
|
+
_ts_metadata8("design:type", Function),
|
|
1059
|
+
_ts_metadata8("design:paramtypes", [
|
|
1060
|
+
typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
|
|
923
1061
|
typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
|
|
924
1062
|
typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
|
|
925
1063
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions
|
|
@@ -1019,31 +1157,31 @@ var LedgerQuotaStore = class {
|
|
|
1019
1157
|
|
|
1020
1158
|
// src/runner/inline-agent-runner.ts
|
|
1021
1159
|
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_STORE as AGENT_STORE3, QuotaExceededError, publishAgentRunFailed, runAgentLoop } from "@dudousxd/nestjs-agent-core";
|
|
1022
|
-
import { Inject as
|
|
1023
|
-
function
|
|
1160
|
+
import { Inject as Inject9, Injectable as Injectable5, Logger as Logger3 } from "@nestjs/common";
|
|
1161
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
1024
1162
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1025
1163
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1026
1164
|
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;
|
|
1027
1165
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1028
1166
|
}
|
|
1029
|
-
__name(
|
|
1030
|
-
function
|
|
1167
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1168
|
+
function _ts_metadata9(k, v) {
|
|
1031
1169
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1032
1170
|
}
|
|
1033
|
-
__name(
|
|
1034
|
-
function
|
|
1171
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1172
|
+
function _ts_param9(paramIndex, decorator) {
|
|
1035
1173
|
return function(target, key) {
|
|
1036
1174
|
decorator(target, key, paramIndex);
|
|
1037
1175
|
};
|
|
1038
1176
|
}
|
|
1039
|
-
__name(
|
|
1177
|
+
__name(_ts_param9, "_ts_param");
|
|
1040
1178
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
1041
1179
|
static {
|
|
1042
1180
|
__name(this, "InlineAgentRunner");
|
|
1043
1181
|
}
|
|
1044
1182
|
factory;
|
|
1045
1183
|
store;
|
|
1046
|
-
logger = new
|
|
1184
|
+
logger = new Logger3(_InlineAgentRunner.name);
|
|
1047
1185
|
pending = /* @__PURE__ */ new Map();
|
|
1048
1186
|
constructor(factory, store) {
|
|
1049
1187
|
this.factory = factory;
|
|
@@ -1108,7 +1246,6 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1108
1246
|
async runNested(agentName, task, actor, day, depth, sinkRunId) {
|
|
1109
1247
|
const subThread = await this.store.createThread({
|
|
1110
1248
|
actor,
|
|
1111
|
-
persona: "default",
|
|
1112
1249
|
transient: true
|
|
1113
1250
|
});
|
|
1114
1251
|
const runId = crypto.randomUUID();
|
|
@@ -1138,50 +1275,41 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1138
1275
|
}, hooks);
|
|
1139
1276
|
}
|
|
1140
1277
|
};
|
|
1141
|
-
InlineAgentRunner =
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1278
|
+
InlineAgentRunner = _ts_decorate9([
|
|
1279
|
+
Injectable5(),
|
|
1280
|
+
_ts_param9(0, Inject9(AGENT_DEPS_FACTORY2)),
|
|
1281
|
+
_ts_param9(1, Inject9(AGENT_STORE3)),
|
|
1282
|
+
_ts_metadata9("design:type", Function),
|
|
1283
|
+
_ts_metadata9("design:paramtypes", [
|
|
1147
1284
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
1148
1285
|
typeof AgentStore === "undefined" ? Object : AgentStore
|
|
1149
1286
|
])
|
|
1150
1287
|
], InlineAgentRunner);
|
|
1151
1288
|
|
|
1152
1289
|
// src/agent.module.ts
|
|
1153
|
-
function
|
|
1290
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
1154
1291
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1155
1292
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1156
1293
|
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;
|
|
1157
1294
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1158
1295
|
}
|
|
1159
|
-
__name(
|
|
1160
|
-
var FEATURE_INIT = Symbol("nestjs-agent:feature-init");
|
|
1296
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1161
1297
|
var DEFAULT_PATH = "agent";
|
|
1162
|
-
function defaultDefinition(options) {
|
|
1163
|
-
return {
|
|
1164
|
-
name: "default",
|
|
1165
|
-
...options.defaultAgent
|
|
1166
|
-
};
|
|
1167
|
-
}
|
|
1168
|
-
__name(defaultDefinition, "defaultDefinition");
|
|
1169
1298
|
function sharedProviders(durable, includeStore) {
|
|
1170
1299
|
const providers = [
|
|
1171
1300
|
{
|
|
1172
1301
|
provide: AGENT_TOOL_REGISTRY3,
|
|
1173
1302
|
useFactory: /* @__PURE__ */ __name(() => new ToolRegistry3(), "useFactory")
|
|
1174
1303
|
},
|
|
1304
|
+
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
1175
1305
|
{
|
|
1176
|
-
provide:
|
|
1177
|
-
useFactory: /* @__PURE__ */ __name((
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
AGENT_OPTIONS3
|
|
1184
|
-
]
|
|
1306
|
+
provide: AGENT_REGISTRY4,
|
|
1307
|
+
useFactory: /* @__PURE__ */ __name(() => new AgentRegistry4(), "useFactory")
|
|
1308
|
+
},
|
|
1309
|
+
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
1310
|
+
{
|
|
1311
|
+
provide: AGENT_PROMPT_CONTRIBUTORS3,
|
|
1312
|
+
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
1185
1313
|
},
|
|
1186
1314
|
{
|
|
1187
1315
|
provide: AGENT_SINK2,
|
|
@@ -1227,6 +1355,9 @@ function sharedProviders(durable, includeStore) {
|
|
|
1227
1355
|
provide: AGENT_DEPS_FACTORY3,
|
|
1228
1356
|
useExisting: AgentDepsFactory2
|
|
1229
1357
|
},
|
|
1358
|
+
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
1359
|
+
// handoff tools (onApplicationBootstrap) reads the registry.
|
|
1360
|
+
AgentDiscoveryService,
|
|
1230
1361
|
AiToolDiscoveryService,
|
|
1231
1362
|
InlineAgentRunner,
|
|
1232
1363
|
AgentService
|
|
@@ -1269,7 +1400,7 @@ function exportsFor(includeStore) {
|
|
|
1269
1400
|
return [
|
|
1270
1401
|
AGENT_OPTIONS3,
|
|
1271
1402
|
AGENT_TOOL_REGISTRY3,
|
|
1272
|
-
|
|
1403
|
+
AGENT_REGISTRY4,
|
|
1273
1404
|
AGENT_SINK2,
|
|
1274
1405
|
AGENT_ROLES_POLICY2,
|
|
1275
1406
|
AGENT_ACTOR_RESOLVER5,
|
|
@@ -1278,6 +1409,7 @@ function exportsFor(includeStore) {
|
|
|
1278
1409
|
AGENT_STORE4
|
|
1279
1410
|
] : [],
|
|
1280
1411
|
AGENT_QUOTA_STORE2,
|
|
1412
|
+
AGENT_PROMPT_CONTRIBUTORS3,
|
|
1281
1413
|
AGENT_DEPS_FACTORY3,
|
|
1282
1414
|
AgentDepsFactory2,
|
|
1283
1415
|
AgentService,
|
|
@@ -1349,28 +1481,8 @@ var AgentModule = class _AgentModule {
|
|
|
1349
1481
|
exports: exportsFor(true)
|
|
1350
1482
|
};
|
|
1351
1483
|
}
|
|
1352
|
-
/** Register additional named agents (an orchestrator + its sub-agents). */
|
|
1353
|
-
static forFeature(definitions) {
|
|
1354
|
-
return {
|
|
1355
|
-
module: _AgentModule,
|
|
1356
|
-
providers: [
|
|
1357
|
-
{
|
|
1358
|
-
provide: FEATURE_INIT,
|
|
1359
|
-
useFactory: /* @__PURE__ */ __name((registry) => {
|
|
1360
|
-
for (const definition of definitions) {
|
|
1361
|
-
registry.register(definition);
|
|
1362
|
-
}
|
|
1363
|
-
return true;
|
|
1364
|
-
}, "useFactory"),
|
|
1365
|
-
inject: [
|
|
1366
|
-
AGENT_REGISTRY3
|
|
1367
|
-
]
|
|
1368
|
-
}
|
|
1369
|
-
]
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
1484
|
};
|
|
1373
|
-
AgentModule =
|
|
1485
|
+
AgentModule = _ts_decorate10([
|
|
1374
1486
|
Global(),
|
|
1375
1487
|
Module({})
|
|
1376
1488
|
], AgentModule);
|
|
@@ -1408,9 +1520,12 @@ var HeaderActorResolver = class {
|
|
|
1408
1520
|
// src/index.ts
|
|
1409
1521
|
export * from "@dudousxd/nestjs-agent-core";
|
|
1410
1522
|
export {
|
|
1523
|
+
AGENT_METADATA,
|
|
1411
1524
|
AGENT_TOOL_BRAND,
|
|
1412
1525
|
AI_TOOL_METADATA,
|
|
1526
|
+
Agent,
|
|
1413
1527
|
AgentDepsFactory2 as AgentDepsFactory,
|
|
1528
|
+
AgentDiscoveryService,
|
|
1414
1529
|
AgentModule,
|
|
1415
1530
|
AgentService,
|
|
1416
1531
|
AiTool,
|
|
@@ -1419,8 +1534,13 @@ export {
|
|
|
1419
1534
|
InProcessTokenStreamSink,
|
|
1420
1535
|
InlineAgentRunner,
|
|
1421
1536
|
LedgerQuotaStore,
|
|
1537
|
+
SYSTEM_PROMPT_CONTRIBUTOR_METADATA,
|
|
1538
|
+
SYSTEM_PROMPT_METADATA,
|
|
1539
|
+
SystemPrompt,
|
|
1540
|
+
SystemPromptContributor,
|
|
1422
1541
|
delegateToolName,
|
|
1423
1542
|
provideAgentTool,
|
|
1543
|
+
readAgentMetadata,
|
|
1424
1544
|
readAiToolMetadata,
|
|
1425
1545
|
utcDay
|
|
1426
1546
|
};
|