@dudousxd/nestjs-agent 1.21.0 → 1.23.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/README.md +7 -0
- package/dist/{chat-queue.service-XG9RQCjU.d.ts → chat-queue.service-CwxJDrBM.d.ts} +76 -5
- package/dist/{chat-queue.service-CGsR40Ct.d.cts → chat-queue.service-D1z3WjFI.d.cts} +76 -5
- package/dist/durable/index.cjs +398 -256
- 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 +186 -44
- package/dist/durable/index.js.map +1 -1
- package/dist/genui/index.cjs +1 -0
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.js +1 -0
- package/dist/genui/index.js.map +1 -1
- package/dist/index.cjs +468 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -14
- package/dist/index.d.ts +51 -14
- package/dist/index.js +249 -51
- package/dist/index.js.map +1 -1
- package/dist/sink-redis/index.cjs +7 -2
- package/dist/sink-redis/index.cjs.map +1 -1
- package/dist/sink-redis/index.d.cts +6 -3
- package/dist/sink-redis/index.d.ts +6 -3
- package/dist/sink-redis/index.js +7 -2
- package/dist/sink-redis/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -68,6 +68,7 @@ __export(index_exports, {
|
|
|
68
68
|
attachmentLimits: () => attachmentLimits,
|
|
69
69
|
declaredSkillProvider: () => declaredSkillProvider,
|
|
70
70
|
defaultRequestUserMapper: () => defaultRequestUserMapper,
|
|
71
|
+
defineTool: () => defineTool,
|
|
71
72
|
delegateToolName: () => delegateToolName,
|
|
72
73
|
provideAgentTool: () => provideAgentTool,
|
|
73
74
|
provideAgentTools: () => provideAgentTools,
|
|
@@ -84,14 +85,14 @@ __export(index_exports, {
|
|
|
84
85
|
module.exports = __toCommonJS(index_exports);
|
|
85
86
|
|
|
86
87
|
// src/agent.module.ts
|
|
87
|
-
var
|
|
88
|
+
var import_nestjs_agent_core33 = require("@dudousxd/nestjs-agent-core");
|
|
88
89
|
var import_common27 = require("@nestjs/common");
|
|
89
90
|
var import_core4 = require("@nestjs/core");
|
|
90
91
|
|
|
91
92
|
// src/agent-deps.factory.ts
|
|
92
|
-
var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
|
|
93
93
|
var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
|
|
94
94
|
var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
|
|
95
|
+
var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
|
|
95
96
|
var import_common2 = require("@nestjs/common");
|
|
96
97
|
|
|
97
98
|
// src/genui/agent-genui.module.ts
|
|
@@ -99,6 +100,7 @@ var import_genui = require("@dudousxd/nestjs-agent-core/genui");
|
|
|
99
100
|
var import_common = require("@nestjs/common");
|
|
100
101
|
|
|
101
102
|
// src/functional-tool.ts
|
|
103
|
+
var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
|
|
102
104
|
var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
|
|
103
105
|
function brand(tool) {
|
|
104
106
|
return {
|
|
@@ -135,6 +137,7 @@ function provideAgentTools(factory, inject) {
|
|
|
135
137
|
};
|
|
136
138
|
}
|
|
137
139
|
__name(provideAgentTools, "provideAgentTools");
|
|
140
|
+
var defineTool = import_nestjs_agent_core.createFunctionalTool;
|
|
138
141
|
|
|
139
142
|
// src/genui/agent-genui.module.ts
|
|
140
143
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -317,7 +320,7 @@ var AgentDepsFactory2 = class {
|
|
|
317
320
|
this.memory = memory;
|
|
318
321
|
this.uiCatalog = uiCatalog;
|
|
319
322
|
this.uiCatalogResolver = uiCatalogResolver;
|
|
320
|
-
if (options.actionApprovalMode === "independent") (0,
|
|
323
|
+
if (options.actionApprovalMode === "independent") (0, import_nestjs_agent_core2.assertIndependentActionCapabilities)(store, options.backgroundActorResolver);
|
|
321
324
|
}
|
|
322
325
|
/** The turn's memory seam, shared with the read-back endpoint. Undefined → memory is not configured. */
|
|
323
326
|
memoryConfig() {
|
|
@@ -343,7 +346,7 @@ var AgentDepsFactory2 = class {
|
|
|
343
346
|
return void 0;
|
|
344
347
|
}
|
|
345
348
|
const delegated = (definition.delegatesTo ?? []).map((edge) => {
|
|
346
|
-
const { agent, detached } = (0,
|
|
349
|
+
const { agent, detached } = (0, import_nestjs_agent_core3.normalizeDelegation)(edge);
|
|
347
350
|
return delegateToolName({
|
|
348
351
|
target: agent,
|
|
349
352
|
detached
|
|
@@ -367,7 +370,7 @@ var AgentDepsFactory2 = class {
|
|
|
367
370
|
agentName: name
|
|
368
371
|
};
|
|
369
372
|
}
|
|
370
|
-
const alias = (0,
|
|
373
|
+
const alias = (0, import_nestjs_agent_core3.resolvePersonaAlias)(this.agents.list(), name);
|
|
371
374
|
return alias === void 0 ? {
|
|
372
375
|
agentName: name
|
|
373
376
|
} : {
|
|
@@ -377,7 +380,7 @@ var AgentDepsFactory2 = class {
|
|
|
377
380
|
}
|
|
378
381
|
/** `agentName`'s personas as a picker reads them. Empty when it declares none. */
|
|
379
382
|
personaCatalog(agentName) {
|
|
380
|
-
return (this.agents.get(agentName)?.personas ?? []).map(
|
|
383
|
+
return (this.agents.get(agentName)?.personas ?? []).map(import_nestjs_agent_core3.personaCatalogEntry);
|
|
381
384
|
}
|
|
382
385
|
/** The persona `agentName` runs under when nothing names one. Undefined → none. */
|
|
383
386
|
defaultPersona(agentName) {
|
|
@@ -391,7 +394,7 @@ var AgentDepsFactory2 = class {
|
|
|
391
394
|
resolvePersona(args) {
|
|
392
395
|
const definition = this.agents.get(args.agentName);
|
|
393
396
|
if (args.requested !== void 0) {
|
|
394
|
-
if ((0,
|
|
397
|
+
if ((0, import_nestjs_agent_core3.findPersona)(definition, args.requested) === void 0) {
|
|
395
398
|
throw new import_common2.BadRequestException({
|
|
396
399
|
statusCode: 400,
|
|
397
400
|
code: "persona_not_found",
|
|
@@ -401,7 +404,7 @@ var AgentDepsFactory2 = class {
|
|
|
401
404
|
return args.requested;
|
|
402
405
|
}
|
|
403
406
|
const pinned = args.threadPersona ?? void 0;
|
|
404
|
-
if (pinned !== void 0 && (0,
|
|
407
|
+
if (pinned !== void 0 && (0, import_nestjs_agent_core3.findPersona)(definition, pinned) !== void 0) {
|
|
405
408
|
return pinned;
|
|
406
409
|
}
|
|
407
410
|
return definition?.defaultPersona;
|
|
@@ -421,8 +424,8 @@ var AgentDepsFactory2 = class {
|
|
|
421
424
|
forAgent(agentName) {
|
|
422
425
|
const name = agentName ?? this.defaultAgentName();
|
|
423
426
|
if (agentName !== void 0 && !this.agents.has(agentName)) {
|
|
424
|
-
const alias = (0,
|
|
425
|
-
const persona = alias === void 0 ? void 0 : (0,
|
|
427
|
+
const alias = (0, import_nestjs_agent_core3.resolvePersonaAlias)(this.agents.list(), agentName);
|
|
428
|
+
const persona = alias === void 0 ? void 0 : (0, import_nestjs_agent_core3.findPersona)(this.agents.get(alias.agent), alias.persona);
|
|
426
429
|
if (alias !== void 0 && persona !== void 0) {
|
|
427
430
|
return this.withPersona(this.forAgent(alias.agent), persona);
|
|
428
431
|
}
|
|
@@ -556,7 +559,7 @@ var AgentDepsFactory2 = class {
|
|
|
556
559
|
} : {}
|
|
557
560
|
});
|
|
558
561
|
}, "systemPrompt");
|
|
559
|
-
const toolAllowList = (0,
|
|
562
|
+
const toolAllowList = (0, import_nestjs_agent_core3.intersectAllowLists)(deps.toolAllowList, persona.allowedTools);
|
|
560
563
|
return {
|
|
561
564
|
...deps,
|
|
562
565
|
systemPrompt,
|
|
@@ -581,7 +584,7 @@ var AgentDepsFactory2 = class {
|
|
|
581
584
|
}
|
|
582
585
|
/** Build the built-in window policy from the declarative `{ maxMessages, maxTokens, summarize }`. */
|
|
583
586
|
window(config) {
|
|
584
|
-
return (0,
|
|
587
|
+
return (0, import_nestjs_agent_core3.windowHistory)({
|
|
585
588
|
...config.maxMessages !== void 0 ? {
|
|
586
589
|
maxMessages: config.maxMessages
|
|
587
590
|
} : {},
|
|
@@ -591,7 +594,7 @@ var AgentDepsFactory2 = class {
|
|
|
591
594
|
// The shared module model, not a per-agent one: an agent's `modelId` is an accounting label,
|
|
592
595
|
// and only one provider is ever bound.
|
|
593
596
|
...config.summarize === true ? {
|
|
594
|
-
summarize: (0,
|
|
597
|
+
summarize: (0, import_nestjs_agent_core3.summarizeWithModel)(this.model)
|
|
595
598
|
} : {}
|
|
596
599
|
});
|
|
597
600
|
}
|
|
@@ -609,20 +612,20 @@ var AgentDepsFactory2 = class {
|
|
|
609
612
|
};
|
|
610
613
|
AgentDepsFactory2 = _ts_decorate2([
|
|
611
614
|
(0, import_common2.Injectable)(),
|
|
612
|
-
_ts_param(0, (0, import_common2.Inject)(
|
|
613
|
-
_ts_param(1, (0, import_common2.Inject)(
|
|
614
|
-
_ts_param(2, (0, import_common2.Inject)(
|
|
615
|
-
_ts_param(3, (0, import_common2.Inject)(
|
|
616
|
-
_ts_param(4, (0, import_common2.Inject)(
|
|
617
|
-
_ts_param(5, (0, import_common2.Inject)(
|
|
618
|
-
_ts_param(6, (0, import_common2.Inject)(
|
|
619
|
-
_ts_param(7, (0, import_common2.Inject)(
|
|
615
|
+
_ts_param(0, (0, import_common2.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
|
|
616
|
+
_ts_param(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MODEL)),
|
|
617
|
+
_ts_param(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
|
|
618
|
+
_ts_param(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
|
|
619
|
+
_ts_param(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ROLES_POLICY)),
|
|
620
|
+
_ts_param(5, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_TOOL_REGISTRY)),
|
|
621
|
+
_ts_param(6, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_REGISTRY)),
|
|
622
|
+
_ts_param(7, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_PROMPT_CONTRIBUTORS)),
|
|
620
623
|
_ts_param(8, (0, import_common2.Optional)()),
|
|
621
|
-
_ts_param(8, (0, import_common2.Inject)(
|
|
624
|
+
_ts_param(8, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_PRICING_STORE)),
|
|
622
625
|
_ts_param(9, (0, import_common2.Optional)()),
|
|
623
|
-
_ts_param(9, (0, import_common2.Inject)(
|
|
626
|
+
_ts_param(9, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SKILLS)),
|
|
624
627
|
_ts_param(10, (0, import_common2.Optional)()),
|
|
625
|
-
_ts_param(10, (0, import_common2.Inject)(
|
|
628
|
+
_ts_param(10, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_MEMORY)),
|
|
626
629
|
_ts_param(11, (0, import_common2.Optional)()),
|
|
627
630
|
_ts_param(11, (0, import_common2.Inject)(GENUI_CATALOG)),
|
|
628
631
|
_ts_param(12, (0, import_common2.Optional)()),
|
|
@@ -633,8 +636,8 @@ AgentDepsFactory2 = _ts_decorate2([
|
|
|
633
636
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
634
637
|
typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
|
|
635
638
|
typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
|
|
636
|
-
typeof
|
|
637
|
-
typeof
|
|
639
|
+
typeof import_nestjs_agent_core3.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core3.ToolRegistry,
|
|
640
|
+
typeof import_nestjs_agent_core3.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core3.AgentRegistry,
|
|
638
641
|
Array,
|
|
639
642
|
Object,
|
|
640
643
|
Object,
|
|
@@ -645,7 +648,7 @@ AgentDepsFactory2 = _ts_decorate2([
|
|
|
645
648
|
], AgentDepsFactory2);
|
|
646
649
|
|
|
647
650
|
// src/agent.service.ts
|
|
648
|
-
var
|
|
651
|
+
var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
|
|
649
652
|
var import_common6 = require("@nestjs/common");
|
|
650
653
|
|
|
651
654
|
// src/agent-deps.ts
|
|
@@ -671,7 +674,7 @@ function childSinkWriter(writer) {
|
|
|
671
674
|
__name(childSinkWriter, "childSinkWriter");
|
|
672
675
|
|
|
673
676
|
// src/proposals/action-proposal.service.ts
|
|
674
|
-
var
|
|
677
|
+
var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
|
|
675
678
|
var import_common3 = require("@nestjs/common");
|
|
676
679
|
function _ts_decorate3(decorators, target, key, desc) {
|
|
677
680
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -708,7 +711,19 @@ var ActionProposalService = class {
|
|
|
708
711
|
constructor(store, options) {
|
|
709
712
|
this.store = store;
|
|
710
713
|
this.options = options;
|
|
714
|
+
const text = options.actionProposalText;
|
|
715
|
+
this.vocabulary = {
|
|
716
|
+
...import_nestjs_agent_core5.DEFAULT_TEXT_ACTION_PROPOSAL_VOCABULARY,
|
|
717
|
+
...text?.vocabulary
|
|
718
|
+
};
|
|
719
|
+
this.replies = {
|
|
720
|
+
...import_nestjs_agent_core5.DEFAULT_TEXT_ACTION_PROPOSAL_REPLIES,
|
|
721
|
+
...text?.replies
|
|
722
|
+
};
|
|
711
723
|
}
|
|
724
|
+
/** The words a text decision is made of, and what the agent answers — English unless configured. */
|
|
725
|
+
vocabulary;
|
|
726
|
+
replies;
|
|
712
727
|
capability() {
|
|
713
728
|
const store = this.store;
|
|
714
729
|
if (typeof store.getThreadActionProposalScope !== "function" || typeof store.listActionProposals !== "function") throw new import_common3.NotImplementedException("Action proposals are unavailable");
|
|
@@ -721,7 +736,7 @@ var ActionProposalService = class {
|
|
|
721
736
|
return scope;
|
|
722
737
|
}
|
|
723
738
|
mayDecide(actor, proposal) {
|
|
724
|
-
return (0,
|
|
739
|
+
return (0, import_nestjs_agent_core5.mayDecideApproval)(this.options.approvalPolicy, actor, {
|
|
725
740
|
toolCallId: proposal.originToolCallId,
|
|
726
741
|
approver: proposal.approver,
|
|
727
742
|
requesterRef: proposal.actorRef
|
|
@@ -737,7 +752,8 @@ var ActionProposalService = class {
|
|
|
737
752
|
for (const row of rows) if (scope.actorRef === actor.id || await this.mayDecide(actor, row)) visible.push(row);
|
|
738
753
|
const last = rows.at(-1);
|
|
739
754
|
return {
|
|
740
|
-
|
|
755
|
+
// The public view: a row carries the worker's lease token and the tool's idempotency key.
|
|
756
|
+
items: visible.map(import_nestjs_agent_core5.toActionProposalView),
|
|
741
757
|
...rows.length === 1e3 && last ? {
|
|
742
758
|
next: {
|
|
743
759
|
createdAt: last.createdAt,
|
|
@@ -754,7 +770,7 @@ var ActionProposalService = class {
|
|
|
754
770
|
const proposal = await this.capability().getActionProposal(scope, proposalId);
|
|
755
771
|
if (!proposal) throw new import_common3.NotFoundException("Proposal not found");
|
|
756
772
|
if (!await this.mayDecide(actor, proposal)) throw new import_common3.ForbiddenException("May not decide this proposal");
|
|
757
|
-
|
|
773
|
+
const result = await this.capability().decideActionProposal(scope, proposalId, {
|
|
758
774
|
decision: command.decision,
|
|
759
775
|
actorRef: actor.id,
|
|
760
776
|
via: command.via ?? "web",
|
|
@@ -765,9 +781,10 @@ var ActionProposalService = class {
|
|
|
765
781
|
reason: command.reason
|
|
766
782
|
} : {}
|
|
767
783
|
});
|
|
784
|
+
return (0, import_nestjs_agent_core5.toActionProposalMutationView)(result);
|
|
768
785
|
}
|
|
769
786
|
async handleTextDecision(threadId, actor, text) {
|
|
770
|
-
const command = (0,
|
|
787
|
+
const command = (0, import_nestjs_agent_core5.parseTextActionProposalCommand)(text, this.vocabulary);
|
|
771
788
|
if (command.status === "unmatched") return command;
|
|
772
789
|
if (command.proposalId !== void 0) {
|
|
773
790
|
const result2 = await this.decide(threadId, command.proposalId, actor, {
|
|
@@ -775,7 +792,7 @@ var ActionProposalService = class {
|
|
|
775
792
|
remember: command.remember,
|
|
776
793
|
via: "text"
|
|
777
794
|
});
|
|
778
|
-
return this.textReceipt(threadId, result2);
|
|
795
|
+
return this.textReceipt(threadId, result2, command.decision);
|
|
779
796
|
}
|
|
780
797
|
const candidates = [];
|
|
781
798
|
const scope = await this.scope(threadId, actor);
|
|
@@ -784,35 +801,43 @@ var ActionProposalService = class {
|
|
|
784
801
|
limit: 1e3
|
|
785
802
|
});
|
|
786
803
|
for (const proposal of pending) if (await this.mayDecide(actor, proposal)) candidates.push(proposal);
|
|
787
|
-
const resolution = (0,
|
|
804
|
+
const resolution = (0, import_nestjs_agent_core5.resolveTextActionProposalDecision)(text, candidates, this.vocabulary);
|
|
788
805
|
if (resolution.status === "unmatched") return resolution;
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
806
|
+
const saturated = pending.length === 1e3 && !text.includes("#");
|
|
807
|
+
if (resolution.status === "ambiguous" || saturated) {
|
|
808
|
+
const proposalIds = candidates.map(({ id }) => id);
|
|
809
|
+
return {
|
|
810
|
+
threadId,
|
|
811
|
+
proposalDecision: {
|
|
812
|
+
status: "ambiguous",
|
|
813
|
+
proposalIds
|
|
814
|
+
},
|
|
815
|
+
text: saturated ? this.replies.tooMany : this.replies.ambiguous(proposalIds)
|
|
816
|
+
};
|
|
817
|
+
}
|
|
797
818
|
const result = await this.decide(threadId, resolution.proposalId, actor, {
|
|
798
819
|
decision: resolution.decision,
|
|
799
820
|
remember: resolution.remember,
|
|
800
821
|
via: "text"
|
|
801
822
|
});
|
|
802
|
-
return this.textReceipt(threadId, result);
|
|
823
|
+
return this.textReceipt(threadId, result, resolution.decision);
|
|
803
824
|
}
|
|
804
|
-
textReceipt(threadId, result) {
|
|
825
|
+
textReceipt(threadId, result, decision) {
|
|
805
826
|
return {
|
|
806
827
|
threadId,
|
|
807
828
|
proposalDecision: result,
|
|
808
|
-
text:
|
|
829
|
+
text: this.reply(result, decision)
|
|
809
830
|
};
|
|
810
831
|
}
|
|
832
|
+
/** The configured reply to a decision the store answered with `result`. */
|
|
833
|
+
reply(result, decision) {
|
|
834
|
+
return (0, import_nestjs_agent_core5.textActionProposalReply)(result, decision, this.replies);
|
|
835
|
+
}
|
|
811
836
|
};
|
|
812
837
|
ActionProposalService = _ts_decorate3([
|
|
813
838
|
(0, import_common3.Injectable)(),
|
|
814
|
-
_ts_param2(0, (0, import_common3.Inject)(
|
|
815
|
-
_ts_param2(1, (0, import_common3.Inject)(
|
|
839
|
+
_ts_param2(0, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
|
|
840
|
+
_ts_param2(1, (0, import_common3.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
|
|
816
841
|
_ts_metadata2("design:type", Function),
|
|
817
842
|
_ts_metadata2("design:paramtypes", [
|
|
818
843
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
@@ -821,9 +846,36 @@ ActionProposalService = _ts_decorate3([
|
|
|
821
846
|
], ActionProposalService);
|
|
822
847
|
|
|
823
848
|
// src/queue/chat-queue.service.ts
|
|
824
|
-
var
|
|
849
|
+
var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
|
|
825
850
|
var import_common4 = require("@nestjs/common");
|
|
826
851
|
|
|
852
|
+
// src/quota-exceeded.ts
|
|
853
|
+
var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
|
|
854
|
+
function publishQuotaBlocked(actor, report, blocked) {
|
|
855
|
+
const window = report.windows.find((candidate) => candidate.period === blocked.period);
|
|
856
|
+
const payload = {
|
|
857
|
+
actorId: actor.id,
|
|
858
|
+
period: blocked.period,
|
|
859
|
+
...blocked.reason !== void 0 ? {
|
|
860
|
+
reason: blocked.reason
|
|
861
|
+
} : {},
|
|
862
|
+
...window?.usedTokens !== void 0 ? {
|
|
863
|
+
usedTokens: window.usedTokens
|
|
864
|
+
} : {},
|
|
865
|
+
...window?.limitTokens !== void 0 ? {
|
|
866
|
+
limitTokens: window.limitTokens
|
|
867
|
+
} : {},
|
|
868
|
+
...window !== void 0 ? {
|
|
869
|
+
usedUsd: window.usedUsd
|
|
870
|
+
} : {},
|
|
871
|
+
...window?.limitUsd !== void 0 ? {
|
|
872
|
+
limitUsd: window.limitUsd
|
|
873
|
+
} : {}
|
|
874
|
+
};
|
|
875
|
+
(0, import_nestjs_agent_core6.publishAgentQuotaExceeded)(payload);
|
|
876
|
+
}
|
|
877
|
+
__name(publishQuotaBlocked, "publishQuotaBlocked");
|
|
878
|
+
|
|
827
879
|
// src/thread-persona.ts
|
|
828
880
|
async function threadPersona(store, threadId) {
|
|
829
881
|
const projecting = store;
|
|
@@ -888,11 +940,11 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
888
940
|
}
|
|
889
941
|
/** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
|
|
890
942
|
get supported() {
|
|
891
|
-
return (0,
|
|
943
|
+
return (0, import_nestjs_agent_core7.isChatQueueStore)(this.store);
|
|
892
944
|
}
|
|
893
945
|
/** The bound store as a queue store, or a 501 naming what is missing. */
|
|
894
946
|
queueStore() {
|
|
895
|
-
if (!(0,
|
|
947
|
+
if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
|
|
896
948
|
throw new import_common4.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
|
|
897
949
|
}
|
|
898
950
|
return this.store;
|
|
@@ -904,7 +956,7 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
904
956
|
store.queuePause(threadId)
|
|
905
957
|
]);
|
|
906
958
|
return {
|
|
907
|
-
items: items.map(
|
|
959
|
+
items: items.map(import_nestjs_agent_core7.queuedMessageView),
|
|
908
960
|
paused
|
|
909
961
|
};
|
|
910
962
|
}
|
|
@@ -955,7 +1007,7 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
955
1007
|
* A no-op returning `{}` on a store without a queue.
|
|
956
1008
|
*/
|
|
957
1009
|
async plan(args) {
|
|
958
|
-
if (!(0,
|
|
1010
|
+
if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
|
|
959
1011
|
return {};
|
|
960
1012
|
}
|
|
961
1013
|
const store = this.store;
|
|
@@ -1055,7 +1107,7 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1055
1107
|
* (its settle drains) or while the queue is paused. Answers the started run's id, if any.
|
|
1056
1108
|
*/
|
|
1057
1109
|
async kick(threadId, runner) {
|
|
1058
|
-
if (!(0,
|
|
1110
|
+
if (!(0, import_nestjs_agent_core7.isChatQueueStore)(this.store)) {
|
|
1059
1111
|
return void 0;
|
|
1060
1112
|
}
|
|
1061
1113
|
const { live, stale } = await this.holder(threadId, runner);
|
|
@@ -1123,6 +1175,9 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1123
1175
|
} : {},
|
|
1124
1176
|
...input.uiCapabilities !== void 0 ? {
|
|
1125
1177
|
uiCapabilities: input.uiCapabilities
|
|
1178
|
+
} : {},
|
|
1179
|
+
...input.hostContext !== void 0 ? {
|
|
1180
|
+
hostContext: input.hostContext
|
|
1126
1181
|
} : {}
|
|
1127
1182
|
});
|
|
1128
1183
|
await store.setQueuePause(threadId, {
|
|
@@ -1159,7 +1214,7 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1159
1214
|
}
|
|
1160
1215
|
async write(runId, frame) {
|
|
1161
1216
|
const writer = await this.sink.open(runId);
|
|
1162
|
-
await writer.write((0,
|
|
1217
|
+
await writer.write((0, import_nestjs_agent_core7.encodeStreamEvent)(frame));
|
|
1163
1218
|
}
|
|
1164
1219
|
/** Why `actor` may not start a turn now (the quota message), or `null`. */
|
|
1165
1220
|
async quotaBlock(actor) {
|
|
@@ -1167,12 +1222,14 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1167
1222
|
return null;
|
|
1168
1223
|
}
|
|
1169
1224
|
try {
|
|
1170
|
-
const
|
|
1225
|
+
const report = await this.quotaProvider.report({
|
|
1171
1226
|
actor
|
|
1172
1227
|
});
|
|
1228
|
+
const { blocked } = report;
|
|
1173
1229
|
if (blocked === void 0) {
|
|
1174
1230
|
return null;
|
|
1175
1231
|
}
|
|
1232
|
+
publishQuotaBlocked(actor, report, blocked);
|
|
1176
1233
|
return blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`;
|
|
1177
1234
|
} catch {
|
|
1178
1235
|
return null;
|
|
@@ -1206,6 +1263,9 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1206
1263
|
...message.uiCapabilities !== void 0 ? {
|
|
1207
1264
|
uiCapabilities: message.uiCapabilities
|
|
1208
1265
|
} : {},
|
|
1266
|
+
...message.hostContext !== void 0 ? {
|
|
1267
|
+
hostContext: message.hostContext
|
|
1268
|
+
} : {},
|
|
1209
1269
|
...message.model !== void 0 ? {
|
|
1210
1270
|
model: message.model
|
|
1211
1271
|
} : {}
|
|
@@ -1261,16 +1321,16 @@ var ChatQueueService = class _ChatQueueService {
|
|
|
1261
1321
|
};
|
|
1262
1322
|
ChatQueueService = _ts_decorate4([
|
|
1263
1323
|
(0, import_common4.Injectable)(),
|
|
1264
|
-
_ts_param3(0, (0, import_common4.Inject)(
|
|
1265
|
-
_ts_param3(1, (0, import_common4.Inject)(
|
|
1324
|
+
_ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_STORE)),
|
|
1325
|
+
_ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_SINK)),
|
|
1266
1326
|
_ts_param3(2, (0, import_common4.Optional)()),
|
|
1267
|
-
_ts_param3(2, (0, import_common4.Inject)(
|
|
1327
|
+
_ts_param3(2, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_QUOTA_PROVIDER)),
|
|
1268
1328
|
_ts_param3(3, (0, import_common4.Optional)()),
|
|
1269
|
-
_ts_param3(3, (0, import_common4.Inject)(
|
|
1329
|
+
_ts_param3(3, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
|
|
1270
1330
|
_ts_param3(4, (0, import_common4.Optional)()),
|
|
1271
|
-
_ts_param3(4, (0, import_common4.Inject)(
|
|
1331
|
+
_ts_param3(4, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
|
|
1272
1332
|
_ts_param3(5, (0, import_common4.Optional)()),
|
|
1273
|
-
_ts_param3(5, (0, import_common4.Inject)(
|
|
1333
|
+
_ts_param3(5, (0, import_common4.Inject)(import_nestjs_agent_core7.AGENT_DEPS_FACTORY)),
|
|
1274
1334
|
_ts_metadata3("design:type", Function),
|
|
1275
1335
|
_ts_metadata3("design:paramtypes", [
|
|
1276
1336
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
@@ -1295,7 +1355,7 @@ function queueFrame(items, paused, started) {
|
|
|
1295
1355
|
return {
|
|
1296
1356
|
kind: "queue",
|
|
1297
1357
|
queue: {
|
|
1298
|
-
items: items.map(
|
|
1358
|
+
items: items.map(import_nestjs_agent_core7.queuedMessageView),
|
|
1299
1359
|
paused
|
|
1300
1360
|
},
|
|
1301
1361
|
...started !== void 0 ? {
|
|
@@ -1306,19 +1366,19 @@ function queueFrame(items, paused, started) {
|
|
|
1306
1366
|
__name(queueFrame, "queueFrame");
|
|
1307
1367
|
|
|
1308
1368
|
// src/run-not-active.exception.ts
|
|
1309
|
-
var
|
|
1369
|
+
var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
|
|
1310
1370
|
var import_common5 = require("@nestjs/common");
|
|
1311
1371
|
var RunNotActiveException = class extends import_common5.ConflictException {
|
|
1312
1372
|
static {
|
|
1313
1373
|
__name(this, "RunNotActiveException");
|
|
1314
1374
|
}
|
|
1315
1375
|
runId;
|
|
1316
|
-
code =
|
|
1376
|
+
code = import_nestjs_agent_core8.RUN_NOT_ACTIVE_CODE;
|
|
1317
1377
|
constructor(runId) {
|
|
1318
1378
|
super({
|
|
1319
1379
|
statusCode: 409,
|
|
1320
|
-
code:
|
|
1321
|
-
message:
|
|
1380
|
+
code: import_nestjs_agent_core8.RUN_NOT_ACTIVE_CODE,
|
|
1381
|
+
message: import_nestjs_agent_core8.RUN_NOT_ACTIVE_MESSAGE
|
|
1322
1382
|
}), this.runId = runId;
|
|
1323
1383
|
}
|
|
1324
1384
|
};
|
|
@@ -1374,6 +1434,21 @@ var AgentService = class {
|
|
|
1374
1434
|
this.queue = queue;
|
|
1375
1435
|
this.proposals = proposals;
|
|
1376
1436
|
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Decide one independent proposal through the scoped proposal service — what the native
|
|
1439
|
+
* `action-proposals/:id/approve|reject` routes call — and the reply to show for it. `404` when
|
|
1440
|
+
* proposals are not on, `403`/`404` when this actor may not decide it.
|
|
1441
|
+
*/
|
|
1442
|
+
async decideActionProposal(actor, threadId, proposalId, command) {
|
|
1443
|
+
if (this.options?.actionApprovalMode !== "independent" || !this.proposals) {
|
|
1444
|
+
throw new import_common6.NotFoundException("Proposal not found");
|
|
1445
|
+
}
|
|
1446
|
+
const result = await this.proposals.decide(threadId, proposalId, actor, command);
|
|
1447
|
+
return {
|
|
1448
|
+
proposalDecision: result,
|
|
1449
|
+
text: this.proposals.reply(result, command.decision)
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1377
1452
|
async handleTextDecision(threadId, actor, text) {
|
|
1378
1453
|
if (this.options?.actionApprovalMode !== "independent" || !this.proposals) return {
|
|
1379
1454
|
status: "unmatched"
|
|
@@ -1421,10 +1496,12 @@ var AgentService = class {
|
|
|
1421
1496
|
if (this.options?.quota === void 0 || this.quotaProvider === void 0) {
|
|
1422
1497
|
return;
|
|
1423
1498
|
}
|
|
1424
|
-
const
|
|
1499
|
+
const report = await this.quotaProvider.report({
|
|
1425
1500
|
actor
|
|
1426
1501
|
});
|
|
1502
|
+
const { blocked } = report;
|
|
1427
1503
|
if (blocked !== void 0) {
|
|
1504
|
+
publishQuotaBlocked(actor, report, blocked);
|
|
1428
1505
|
throw new import_common6.HttpException({
|
|
1429
1506
|
statusCode: import_common6.HttpStatus.TOO_MANY_REQUESTS,
|
|
1430
1507
|
code: "quota_exceeded",
|
|
@@ -1460,7 +1537,7 @@ var AgentService = class {
|
|
|
1460
1537
|
if (this.models === void 0) {
|
|
1461
1538
|
throw new import_common6.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
|
|
1462
1539
|
}
|
|
1463
|
-
const entry = (0,
|
|
1540
|
+
const entry = (0, import_nestjs_agent_core9.findCatalogModel)(await this.models.list({
|
|
1464
1541
|
actor,
|
|
1465
1542
|
agent
|
|
1466
1543
|
}), model);
|
|
@@ -1559,6 +1636,9 @@ var AgentService = class {
|
|
|
1559
1636
|
}
|
|
1560
1637
|
const created = await this.store.createThread({
|
|
1561
1638
|
actor: params.actor,
|
|
1639
|
+
...agentName !== void 0 ? {
|
|
1640
|
+
agentName
|
|
1641
|
+
} : {},
|
|
1562
1642
|
...params.transient === true ? {
|
|
1563
1643
|
transient: true
|
|
1564
1644
|
} : {},
|
|
@@ -1571,7 +1651,7 @@ var AgentService = class {
|
|
|
1571
1651
|
});
|
|
1572
1652
|
threadId = created.id;
|
|
1573
1653
|
} else {
|
|
1574
|
-
await this.assertOwnsThread(params.actor, threadId);
|
|
1654
|
+
if (params.authorized !== true) await this.assertOwnsThread(params.actor, threadId);
|
|
1575
1655
|
if (params.personaId !== void 0) {
|
|
1576
1656
|
await this.pinThreadPersona(threadId, params.personaId);
|
|
1577
1657
|
}
|
|
@@ -1597,6 +1677,9 @@ var AgentService = class {
|
|
|
1597
1677
|
...params.uiCapabilities !== void 0 ? {
|
|
1598
1678
|
uiCapabilities: params.uiCapabilities
|
|
1599
1679
|
} : {},
|
|
1680
|
+
...params.hostContext !== void 0 ? {
|
|
1681
|
+
hostContext: params.hostContext
|
|
1682
|
+
} : {},
|
|
1600
1683
|
...model !== void 0 ? {
|
|
1601
1684
|
model
|
|
1602
1685
|
} : {}
|
|
@@ -1614,12 +1697,12 @@ var AgentService = class {
|
|
|
1614
1697
|
const mode = params.mode ?? "auto";
|
|
1615
1698
|
const { live, stale } = await queue.holder(threadId, this.runner);
|
|
1616
1699
|
if (stale !== null) {
|
|
1617
|
-
await (0,
|
|
1700
|
+
await (0, import_nestjs_agent_core9.settleDeadRun)(this.store, {
|
|
1618
1701
|
runId: stale
|
|
1619
1702
|
});
|
|
1620
1703
|
}
|
|
1621
1704
|
if (live === null && mode !== "queue") {
|
|
1622
|
-
const runId = crypto.randomUUID();
|
|
1705
|
+
const runId = this.runner.runIdFor?.(input) ?? crypto.randomUUID();
|
|
1623
1706
|
if (await queue.queueStore().claimActiveStream(threadId, runId, stale !== null ? {
|
|
1624
1707
|
replacing: stale
|
|
1625
1708
|
} : {})) {
|
|
@@ -1687,6 +1770,9 @@ var AgentService = class {
|
|
|
1687
1770
|
...input.uiCapabilities !== void 0 ? {
|
|
1688
1771
|
uiCapabilities: input.uiCapabilities
|
|
1689
1772
|
} : {},
|
|
1773
|
+
...input.hostContext !== void 0 ? {
|
|
1774
|
+
hostContext: input.hostContext
|
|
1775
|
+
} : {},
|
|
1690
1776
|
...interrupting !== void 0 ? {
|
|
1691
1777
|
interrupt: true,
|
|
1692
1778
|
at: "head"
|
|
@@ -2003,7 +2089,7 @@ var AgentService = class {
|
|
|
2003
2089
|
if (active) {
|
|
2004
2090
|
return;
|
|
2005
2091
|
}
|
|
2006
|
-
await (0,
|
|
2092
|
+
await (0, import_nestjs_agent_core9.settleDeadRun)(this.store, {
|
|
2007
2093
|
runId
|
|
2008
2094
|
});
|
|
2009
2095
|
throw new RunNotActiveException(runId);
|
|
@@ -2371,10 +2457,10 @@ var AgentService = class {
|
|
|
2371
2457
|
if (this.store.toolCallInput === void 0) {
|
|
2372
2458
|
return;
|
|
2373
2459
|
}
|
|
2374
|
-
const questions = (0,
|
|
2460
|
+
const questions = (0, import_nestjs_agent_core9.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
|
|
2375
2461
|
for (const question of questions) {
|
|
2376
2462
|
const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
|
|
2377
|
-
const problem = (0,
|
|
2463
|
+
const problem = (0, import_nestjs_agent_core9.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
|
|
2378
2464
|
if (problem !== null) {
|
|
2379
2465
|
throw new import_common6.BadRequestException(`answers["${question.id}"] ${problem}`);
|
|
2380
2466
|
}
|
|
@@ -2388,15 +2474,15 @@ var AgentService = class {
|
|
|
2388
2474
|
*/
|
|
2389
2475
|
async assertMayDecide(actor, toolCallId2) {
|
|
2390
2476
|
const approval = await this.store.toolCallApproval?.(toolCallId2);
|
|
2391
|
-
const approver = approval?.approver ??
|
|
2392
|
-
if (approver ===
|
|
2477
|
+
const approver = approval?.approver ?? import_nestjs_agent_core9.REQUESTER_APPROVER;
|
|
2478
|
+
if (approver === import_nestjs_agent_core9.REQUESTER_APPROVER) {
|
|
2393
2479
|
return this.assertOwnsToolCall(actor, toolCallId2);
|
|
2394
2480
|
}
|
|
2395
2481
|
const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
|
|
2396
2482
|
if (requesterRef === null) {
|
|
2397
2483
|
throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
|
|
2398
2484
|
}
|
|
2399
|
-
const allowed = await (0,
|
|
2485
|
+
const allowed = await (0, import_nestjs_agent_core9.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
|
|
2400
2486
|
toolCallId: toolCallId2,
|
|
2401
2487
|
approver,
|
|
2402
2488
|
requesterRef
|
|
@@ -2448,17 +2534,17 @@ var AgentService = class {
|
|
|
2448
2534
|
};
|
|
2449
2535
|
AgentService = _ts_decorate5([
|
|
2450
2536
|
(0, import_common6.Injectable)(),
|
|
2451
|
-
_ts_param4(0, (0, import_common6.Inject)(
|
|
2452
|
-
_ts_param4(1, (0, import_common6.Inject)(
|
|
2453
|
-
_ts_param4(2, (0, import_common6.Inject)(
|
|
2537
|
+
_ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_RUNNER)),
|
|
2538
|
+
_ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_STORE)),
|
|
2539
|
+
_ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_DEPS_FACTORY)),
|
|
2454
2540
|
_ts_param4(3, (0, import_common6.Optional)()),
|
|
2455
|
-
_ts_param4(3, (0, import_common6.Inject)(
|
|
2541
|
+
_ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
|
|
2456
2542
|
_ts_param4(4, (0, import_common6.Optional)()),
|
|
2457
|
-
_ts_param4(4, (0, import_common6.Inject)(
|
|
2543
|
+
_ts_param4(4, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_MODEL_CATALOG)),
|
|
2458
2544
|
_ts_param4(5, (0, import_common6.Optional)()),
|
|
2459
|
-
_ts_param4(5, (0, import_common6.Inject)(
|
|
2545
|
+
_ts_param4(5, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_QUOTA_PROVIDER)),
|
|
2460
2546
|
_ts_param4(6, (0, import_common6.Optional)()),
|
|
2461
|
-
_ts_param4(6, (0, import_common6.Inject)(
|
|
2547
|
+
_ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
|
|
2462
2548
|
_ts_param4(7, (0, import_common6.Optional)()),
|
|
2463
2549
|
_ts_param4(8, (0, import_common6.Optional)()),
|
|
2464
2550
|
_ts_metadata4("design:type", Function),
|
|
@@ -2573,7 +2659,7 @@ AgentApprovalPortAdapter = _ts_decorate6([
|
|
|
2573
2659
|
], AgentApprovalPortAdapter);
|
|
2574
2660
|
|
|
2575
2661
|
// src/controller/agents.controller.ts
|
|
2576
|
-
var
|
|
2662
|
+
var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
|
|
2577
2663
|
var import_common8 = require("@nestjs/common");
|
|
2578
2664
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
2579
2665
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -2639,17 +2725,17 @@ _ts_decorate7([
|
|
|
2639
2725
|
], AgentsController.prototype, "list", null);
|
|
2640
2726
|
AgentsController = _ts_decorate7([
|
|
2641
2727
|
(0, import_common8.Controller)("agents"),
|
|
2642
|
-
_ts_param6(0, (0, import_common8.Inject)(
|
|
2643
|
-
_ts_param6(1, (0, import_common8.Inject)(
|
|
2728
|
+
_ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_REGISTRY)),
|
|
2729
|
+
_ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_DEPS_FACTORY)),
|
|
2644
2730
|
_ts_metadata6("design:type", Function),
|
|
2645
2731
|
_ts_metadata6("design:paramtypes", [
|
|
2646
|
-
typeof
|
|
2732
|
+
typeof import_nestjs_agent_core10.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core10.AgentRegistry,
|
|
2647
2733
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
|
|
2648
2734
|
])
|
|
2649
2735
|
], AgentsController);
|
|
2650
2736
|
|
|
2651
2737
|
// src/controller/attachments.controller.ts
|
|
2652
|
-
var
|
|
2738
|
+
var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
|
|
2653
2739
|
var import_common9 = require("@nestjs/common");
|
|
2654
2740
|
var import_platform_express = require("@nestjs/platform-express");
|
|
2655
2741
|
|
|
@@ -2787,10 +2873,10 @@ _ts_decorate8([
|
|
|
2787
2873
|
], AttachmentsController.prototype, "upload", null);
|
|
2788
2874
|
AttachmentsController = _ts_decorate8([
|
|
2789
2875
|
(0, import_common9.Controller)("attachments"),
|
|
2790
|
-
_ts_param7(0, (0, import_common9.Inject)(
|
|
2791
|
-
_ts_param7(1, (0, import_common9.Inject)(
|
|
2876
|
+
_ts_param7(0, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_OPTIONS)),
|
|
2877
|
+
_ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
|
|
2792
2878
|
_ts_param7(3, (0, import_common9.Optional)()),
|
|
2793
|
-
_ts_param7(3, (0, import_common9.Inject)(
|
|
2879
|
+
_ts_param7(3, (0, import_common9.Inject)(import_nestjs_agent_core11.AGENT_ATTACHMENT_STAGING)),
|
|
2794
2880
|
_ts_metadata7("design:type", Function),
|
|
2795
2881
|
_ts_metadata7("design:paramtypes", [
|
|
2796
2882
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -2801,7 +2887,7 @@ AttachmentsController = _ts_decorate8([
|
|
|
2801
2887
|
], AttachmentsController);
|
|
2802
2888
|
|
|
2803
2889
|
// src/controller/chat.controller.ts
|
|
2804
|
-
var
|
|
2890
|
+
var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
|
|
2805
2891
|
var import_genui2 = require("@dudousxd/nestjs-agent-core/genui");
|
|
2806
2892
|
var import_common10 = require("@nestjs/common");
|
|
2807
2893
|
function _ts_decorate9(decorators, target, key, desc) {
|
|
@@ -3011,10 +3097,10 @@ data: ${line}
|
|
|
3011
3097
|
}
|
|
3012
3098
|
res.write("event: done\ndata: {}\n\n");
|
|
3013
3099
|
} catch (error) {
|
|
3014
|
-
const payload = error instanceof
|
|
3100
|
+
const payload = error instanceof import_nestjs_agent_core12.AgentStreamError ? {
|
|
3015
3101
|
code: error.code,
|
|
3016
3102
|
message: error.message
|
|
3017
|
-
} : (0,
|
|
3103
|
+
} : (0, import_nestjs_agent_core12.streamFailure)(error);
|
|
3018
3104
|
res.write(`event: error
|
|
3019
3105
|
data: ${JSON.stringify(payload)}
|
|
3020
3106
|
|
|
@@ -3064,7 +3150,7 @@ _ts_decorate9([
|
|
|
3064
3150
|
], ChatController.prototype, "cancel", null);
|
|
3065
3151
|
ChatController = _ts_decorate9([
|
|
3066
3152
|
(0, import_common10.Controller)(),
|
|
3067
|
-
_ts_param8(1, (0, import_common10.Inject)(
|
|
3153
|
+
_ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
|
|
3068
3154
|
_ts_metadata8("design:type", Function),
|
|
3069
3155
|
_ts_metadata8("design:paramtypes", [
|
|
3070
3156
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -3082,7 +3168,7 @@ function parseCursor(raw) {
|
|
|
3082
3168
|
__name(parseCursor, "parseCursor");
|
|
3083
3169
|
|
|
3084
3170
|
// src/controller/config.controller.ts
|
|
3085
|
-
var
|
|
3171
|
+
var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
|
|
3086
3172
|
var import_common11 = require("@nestjs/common");
|
|
3087
3173
|
|
|
3088
3174
|
// src/resolver/anonymous-actor-resolver.ts
|
|
@@ -3240,12 +3326,12 @@ _ts_decorate10([
|
|
|
3240
3326
|
], ConfigController.prototype, "config", null);
|
|
3241
3327
|
ConfigController = _ts_decorate10([
|
|
3242
3328
|
(0, import_common11.Controller)("config"),
|
|
3243
|
-
_ts_param9(0, (0, import_common11.Inject)(
|
|
3244
|
-
_ts_param9(1, (0, import_common11.Inject)(
|
|
3329
|
+
_ts_param9(0, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
|
|
3330
|
+
_ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
|
|
3245
3331
|
_ts_param9(2, (0, import_common11.Optional)()),
|
|
3246
|
-
_ts_param9(2, (0, import_common11.Inject)(
|
|
3332
|
+
_ts_param9(2, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_ATTACHMENT_STAGING)),
|
|
3247
3333
|
_ts_param9(3, (0, import_common11.Optional)()),
|
|
3248
|
-
_ts_param9(3, (0, import_common11.Inject)(
|
|
3334
|
+
_ts_param9(3, (0, import_common11.Inject)(import_nestjs_agent_core13.AGENT_MODEL_CATALOG)),
|
|
3249
3335
|
_ts_metadata9("design:type", Function),
|
|
3250
3336
|
_ts_metadata9("design:paramtypes", [
|
|
3251
3337
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -3256,7 +3342,7 @@ ConfigController = _ts_decorate10([
|
|
|
3256
3342
|
], ConfigController);
|
|
3257
3343
|
|
|
3258
3344
|
// src/controller/memories.controller.ts
|
|
3259
|
-
var
|
|
3345
|
+
var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
|
|
3260
3346
|
var import_common12 = require("@nestjs/common");
|
|
3261
3347
|
function _ts_decorate11(decorators, target, key, desc) {
|
|
3262
3348
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3325,7 +3411,7 @@ var MemoriesController = class {
|
|
|
3325
3411
|
if (entry === void 0) {
|
|
3326
3412
|
throw new import_common12.NotFoundException(`No memory with id "${id}".`);
|
|
3327
3413
|
}
|
|
3328
|
-
const verdict = (0,
|
|
3414
|
+
const verdict = (0, import_nestjs_agent_core14.memoryForgetVerdict)({
|
|
3329
3415
|
record: entry,
|
|
3330
3416
|
actor
|
|
3331
3417
|
});
|
|
@@ -3344,7 +3430,7 @@ var MemoriesController = class {
|
|
|
3344
3430
|
}
|
|
3345
3431
|
async unbounded(threadId, actor) {
|
|
3346
3432
|
const config = this.memory;
|
|
3347
|
-
return await (0,
|
|
3433
|
+
return await (0, import_nestjs_agent_core14.offerMemories)({
|
|
3348
3434
|
config: {
|
|
3349
3435
|
...config,
|
|
3350
3436
|
maxMemories: Number.POSITIVE_INFINITY
|
|
@@ -3380,9 +3466,9 @@ _ts_decorate11([
|
|
|
3380
3466
|
], MemoriesController.prototype, "forget", null);
|
|
3381
3467
|
MemoriesController = _ts_decorate11([
|
|
3382
3468
|
(0, import_common12.Controller)("memories"),
|
|
3383
|
-
_ts_param10(0, (0, import_common12.Inject)(
|
|
3469
|
+
_ts_param10(0, (0, import_common12.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
|
|
3384
3470
|
_ts_param10(1, (0, import_common12.Optional)()),
|
|
3385
|
-
_ts_param10(1, (0, import_common12.Inject)(
|
|
3471
|
+
_ts_param10(1, (0, import_common12.Inject)(import_nestjs_agent_core14.AGENT_MEMORY)),
|
|
3386
3472
|
_ts_metadata10("design:type", Function),
|
|
3387
3473
|
_ts_metadata10("design:paramtypes", [
|
|
3388
3474
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
@@ -3391,7 +3477,7 @@ MemoriesController = _ts_decorate11([
|
|
|
3391
3477
|
], MemoriesController);
|
|
3392
3478
|
|
|
3393
3479
|
// src/controller/messages.controller.ts
|
|
3394
|
-
var
|
|
3480
|
+
var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
|
|
3395
3481
|
var import_common13 = require("@nestjs/common");
|
|
3396
3482
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
3397
3483
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3462,7 +3548,7 @@ _ts_decorate12([
|
|
|
3462
3548
|
], MessagesController.prototype, "feedback", null);
|
|
3463
3549
|
MessagesController = _ts_decorate12([
|
|
3464
3550
|
(0, import_common13.Controller)("messages"),
|
|
3465
|
-
_ts_param11(1, (0, import_common13.Inject)(
|
|
3551
|
+
_ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
|
|
3466
3552
|
_ts_metadata11("design:type", Function),
|
|
3467
3553
|
_ts_metadata11("design:paramtypes", [
|
|
3468
3554
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -3471,7 +3557,7 @@ MessagesController = _ts_decorate12([
|
|
|
3471
3557
|
], MessagesController);
|
|
3472
3558
|
|
|
3473
3559
|
// src/controller/models.controller.ts
|
|
3474
|
-
var
|
|
3560
|
+
var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
|
|
3475
3561
|
var import_common14 = require("@nestjs/common");
|
|
3476
3562
|
function _ts_decorate13(decorators, target, key, desc) {
|
|
3477
3563
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3531,7 +3617,7 @@ _ts_decorate13([
|
|
|
3531
3617
|
], ModelsController.prototype, "list", null);
|
|
3532
3618
|
ModelsController = _ts_decorate13([
|
|
3533
3619
|
(0, import_common14.Controller)("models"),
|
|
3534
|
-
_ts_param12(1, (0, import_common14.Inject)(
|
|
3620
|
+
_ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
|
|
3535
3621
|
_ts_metadata12("design:type", Function),
|
|
3536
3622
|
_ts_metadata12("design:paramtypes", [
|
|
3537
3623
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -3540,7 +3626,7 @@ ModelsController = _ts_decorate13([
|
|
|
3540
3626
|
], ModelsController);
|
|
3541
3627
|
|
|
3542
3628
|
// src/controller/queue.controller.ts
|
|
3543
|
-
var
|
|
3629
|
+
var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
|
|
3544
3630
|
var import_common15 = require("@nestjs/common");
|
|
3545
3631
|
function _ts_decorate14(decorators, target, key, desc) {
|
|
3546
3632
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3691,7 +3777,7 @@ _ts_decorate14([
|
|
|
3691
3777
|
], QueueController.prototype, "remove", null);
|
|
3692
3778
|
QueueController = _ts_decorate14([
|
|
3693
3779
|
(0, import_common15.Controller)(),
|
|
3694
|
-
_ts_param13(1, (0, import_common15.Inject)(
|
|
3780
|
+
_ts_param13(1, (0, import_common15.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
|
|
3695
3781
|
_ts_metadata13("design:type", Function),
|
|
3696
3782
|
_ts_metadata13("design:paramtypes", [
|
|
3697
3783
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -3700,7 +3786,7 @@ QueueController = _ts_decorate14([
|
|
|
3700
3786
|
], QueueController);
|
|
3701
3787
|
|
|
3702
3788
|
// src/controller/quota.controller.ts
|
|
3703
|
-
var
|
|
3789
|
+
var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
|
|
3704
3790
|
var import_common16 = require("@nestjs/common");
|
|
3705
3791
|
function _ts_decorate15(decorators, target, key, desc) {
|
|
3706
3792
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3758,7 +3844,7 @@ _ts_decorate15([
|
|
|
3758
3844
|
], QuotaController.prototype, "report", null);
|
|
3759
3845
|
QuotaController = _ts_decorate15([
|
|
3760
3846
|
(0, import_common16.Controller)("quota"),
|
|
3761
|
-
_ts_param14(1, (0, import_common16.Inject)(
|
|
3847
|
+
_ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
|
|
3762
3848
|
_ts_metadata14("design:type", Function),
|
|
3763
3849
|
_ts_metadata14("design:paramtypes", [
|
|
3764
3850
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -3767,7 +3853,7 @@ QuotaController = _ts_decorate15([
|
|
|
3767
3853
|
], QuotaController);
|
|
3768
3854
|
|
|
3769
3855
|
// src/controller/skills.controller.ts
|
|
3770
|
-
var
|
|
3856
|
+
var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
|
|
3771
3857
|
var import_common17 = require("@nestjs/common");
|
|
3772
3858
|
function _ts_decorate16(decorators, target, key, desc) {
|
|
3773
3859
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -3810,7 +3896,7 @@ var SkillsController = class {
|
|
|
3810
3896
|
return [];
|
|
3811
3897
|
}
|
|
3812
3898
|
const actor = await this.actorResolver.resolve(req);
|
|
3813
|
-
const offer = await (0,
|
|
3899
|
+
const offer = await (0, import_nestjs_agent_core19.offerSkills)(this.skills, {
|
|
3814
3900
|
actor,
|
|
3815
3901
|
threadId: threadId ?? ""
|
|
3816
3902
|
});
|
|
@@ -3830,9 +3916,9 @@ _ts_decorate16([
|
|
|
3830
3916
|
], SkillsController.prototype, "list", null);
|
|
3831
3917
|
SkillsController = _ts_decorate16([
|
|
3832
3918
|
(0, import_common17.Controller)("skills"),
|
|
3833
|
-
_ts_param15(0, (0, import_common17.Inject)(
|
|
3919
|
+
_ts_param15(0, (0, import_common17.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
|
|
3834
3920
|
_ts_param15(1, (0, import_common17.Optional)()),
|
|
3835
|
-
_ts_param15(1, (0, import_common17.Inject)(
|
|
3921
|
+
_ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core19.AGENT_SKILLS)),
|
|
3836
3922
|
_ts_metadata15("design:type", Function),
|
|
3837
3923
|
_ts_metadata15("design:paramtypes", [
|
|
3838
3924
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
@@ -3841,7 +3927,7 @@ SkillsController = _ts_decorate16([
|
|
|
3841
3927
|
], SkillsController);
|
|
3842
3928
|
|
|
3843
3929
|
// src/controller/threads.controller.ts
|
|
3844
|
-
var
|
|
3930
|
+
var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
|
|
3845
3931
|
var import_common18 = require("@nestjs/common");
|
|
3846
3932
|
function _ts_decorate17(decorators, target, key, desc) {
|
|
3847
3933
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4021,7 +4107,7 @@ _ts_decorate17([
|
|
|
4021
4107
|
], ThreadsController.prototype, "truncateFrom", null);
|
|
4022
4108
|
ThreadsController = _ts_decorate17([
|
|
4023
4109
|
(0, import_common18.Controller)("threads"),
|
|
4024
|
-
_ts_param16(1, (0, import_common18.Inject)(
|
|
4110
|
+
_ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
|
|
4025
4111
|
_ts_metadata16("design:type", Function),
|
|
4026
4112
|
_ts_metadata16("design:paramtypes", [
|
|
4027
4113
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -4030,7 +4116,7 @@ ThreadsController = _ts_decorate17([
|
|
|
4030
4116
|
], ThreadsController);
|
|
4031
4117
|
|
|
4032
4118
|
// src/controller/tool-call.controller.ts
|
|
4033
|
-
var
|
|
4119
|
+
var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
|
|
4034
4120
|
var import_common19 = require("@nestjs/common");
|
|
4035
4121
|
function _ts_decorate18(decorators, target, key, desc) {
|
|
4036
4122
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4236,7 +4322,7 @@ _ts_decorate18([
|
|
|
4236
4322
|
], ToolCallController.prototype, "skip", null);
|
|
4237
4323
|
ToolCallController = _ts_decorate18([
|
|
4238
4324
|
(0, import_common19.Controller)("tool-call"),
|
|
4239
|
-
_ts_param17(1, (0, import_common19.Inject)(
|
|
4325
|
+
_ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core21.AGENT_ACTOR_RESOLVER)),
|
|
4240
4326
|
_ts_metadata17("design:type", Function),
|
|
4241
4327
|
_ts_metadata17("design:paramtypes", [
|
|
4242
4328
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -4245,7 +4331,7 @@ ToolCallController = _ts_decorate18([
|
|
|
4245
4331
|
], ToolCallController);
|
|
4246
4332
|
|
|
4247
4333
|
// src/controller/tools.controller.ts
|
|
4248
|
-
var
|
|
4334
|
+
var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
|
|
4249
4335
|
var import_common20 = require("@nestjs/common");
|
|
4250
4336
|
function _ts_decorate19(decorators, target, key, desc) {
|
|
4251
4337
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4286,11 +4372,11 @@ var ToolsController = class {
|
|
|
4286
4372
|
this.agents = agents;
|
|
4287
4373
|
}
|
|
4288
4374
|
async list(req, agent) {
|
|
4289
|
-
if (agent !== void 0 && agent !==
|
|
4375
|
+
if (agent !== void 0 && agent !== import_nestjs_agent_core22.ALL_AGENTS && this.agents.get(agent) === void 0) {
|
|
4290
4376
|
throw new import_common20.NotFoundException(`No agent named "${agent}"`);
|
|
4291
4377
|
}
|
|
4292
4378
|
const actor = await this.actorResolver.resolve(req);
|
|
4293
|
-
const names = agent ===
|
|
4379
|
+
const names = agent === import_nestjs_agent_core22.ALL_AGENTS ? [
|
|
4294
4380
|
void 0,
|
|
4295
4381
|
...this.agents.list().map((definition) => definition.name)
|
|
4296
4382
|
] : [
|
|
@@ -4329,19 +4415,19 @@ _ts_decorate19([
|
|
|
4329
4415
|
], ToolsController.prototype, "list", null);
|
|
4330
4416
|
ToolsController = _ts_decorate19([
|
|
4331
4417
|
(0, import_common20.Controller)("tools"),
|
|
4332
|
-
_ts_param18(0, (0, import_common20.Inject)(
|
|
4333
|
-
_ts_param18(1, (0, import_common20.Inject)(
|
|
4334
|
-
_ts_param18(2, (0, import_common20.Inject)(
|
|
4418
|
+
_ts_param18(0, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_ACTOR_RESOLVER)),
|
|
4419
|
+
_ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_DEPS_FACTORY)),
|
|
4420
|
+
_ts_param18(2, (0, import_common20.Inject)(import_nestjs_agent_core22.AGENT_REGISTRY)),
|
|
4335
4421
|
_ts_metadata18("design:type", Function),
|
|
4336
4422
|
_ts_metadata18("design:paramtypes", [
|
|
4337
4423
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
4338
4424
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
4339
|
-
typeof
|
|
4425
|
+
typeof import_nestjs_agent_core22.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core22.AgentRegistry
|
|
4340
4426
|
])
|
|
4341
4427
|
], ToolsController);
|
|
4342
4428
|
|
|
4343
4429
|
// src/discovery/agent-discovery.service.ts
|
|
4344
|
-
var
|
|
4430
|
+
var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
|
|
4345
4431
|
var import_common21 = require("@nestjs/common");
|
|
4346
4432
|
var import_core = require("@nestjs/core");
|
|
4347
4433
|
|
|
@@ -4570,19 +4656,19 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
4570
4656
|
};
|
|
4571
4657
|
AgentDiscoveryService = _ts_decorate20([
|
|
4572
4658
|
(0, import_common21.Injectable)(),
|
|
4573
|
-
_ts_param19(2, (0, import_common21.Inject)(
|
|
4574
|
-
_ts_param19(3, (0, import_common21.Inject)(
|
|
4659
|
+
_ts_param19(2, (0, import_common21.Inject)(import_nestjs_agent_core23.AGENT_REGISTRY)),
|
|
4660
|
+
_ts_param19(3, (0, import_common21.Inject)(import_nestjs_agent_core23.AGENT_PROMPT_CONTRIBUTORS)),
|
|
4575
4661
|
_ts_metadata19("design:type", Function),
|
|
4576
4662
|
_ts_metadata19("design:paramtypes", [
|
|
4577
4663
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
4578
4664
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
4579
|
-
typeof
|
|
4665
|
+
typeof import_nestjs_agent_core23.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core23.AgentRegistry,
|
|
4580
4666
|
Array
|
|
4581
4667
|
])
|
|
4582
4668
|
], AgentDiscoveryService);
|
|
4583
4669
|
|
|
4584
4670
|
// src/discovery/ai-tool-discovery.service.ts
|
|
4585
|
-
var
|
|
4671
|
+
var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
|
|
4586
4672
|
var import_common22 = require("@nestjs/common");
|
|
4587
4673
|
var import_core2 = require("@nestjs/core");
|
|
4588
4674
|
var import_zod = require("zod");
|
|
@@ -4715,6 +4801,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
4715
4801
|
} : {}
|
|
4716
4802
|
}, {
|
|
4717
4803
|
execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
|
|
4804
|
+
...typeof handler.present === "function" ? {
|
|
4805
|
+
present: /* @__PURE__ */ __name((output, ctx) => instance.present(output, ctx), "present")
|
|
4806
|
+
} : {},
|
|
4718
4807
|
...typeof handler.preflight === "function" ? {
|
|
4719
4808
|
preflight: /* @__PURE__ */ __name((input, ctx, options) => instance.preflight(input, ctx, options), "preflight")
|
|
4720
4809
|
} : {},
|
|
@@ -4741,7 +4830,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
4741
4830
|
let delegates = 0;
|
|
4742
4831
|
for (const definition of this.agents.list()) {
|
|
4743
4832
|
for (const edge of definition.delegatesTo ?? []) {
|
|
4744
|
-
const { agent: target, detached } = (0,
|
|
4833
|
+
const { agent: target, detached } = (0, import_nestjs_agent_core24.normalizeDelegation)(edge);
|
|
4745
4834
|
const targetDefinition = this.agents.get(target);
|
|
4746
4835
|
if (targetDefinition === void 0) {
|
|
4747
4836
|
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.`);
|
|
@@ -4793,9 +4882,9 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
4793
4882
|
};
|
|
4794
4883
|
AiToolDiscoveryService = _ts_decorate21([
|
|
4795
4884
|
(0, import_common22.Injectable)(),
|
|
4796
|
-
_ts_param20(1, (0, import_common22.Inject)(
|
|
4797
|
-
_ts_param20(2, (0, import_common22.Inject)(
|
|
4798
|
-
_ts_param20(3, (0, import_common22.Inject)(
|
|
4885
|
+
_ts_param20(1, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_TOOL_REGISTRY)),
|
|
4886
|
+
_ts_param20(2, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_REGISTRY)),
|
|
4887
|
+
_ts_param20(3, (0, import_common22.Inject)(import_nestjs_agent_core24.AGENT_OPTIONS)),
|
|
4799
4888
|
_ts_metadata20("design:type", Function),
|
|
4800
4889
|
_ts_metadata20("design:paramtypes", [
|
|
4801
4890
|
typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
|
|
@@ -4806,13 +4895,13 @@ AiToolDiscoveryService = _ts_decorate21([
|
|
|
4806
4895
|
], AiToolDiscoveryService);
|
|
4807
4896
|
|
|
4808
4897
|
// src/discovery/skill-discovery.service.ts
|
|
4809
|
-
var
|
|
4898
|
+
var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
|
|
4810
4899
|
var import_common23 = require("@nestjs/common");
|
|
4811
4900
|
var import_core3 = require("@nestjs/core");
|
|
4812
4901
|
|
|
4813
4902
|
// src/decorator/skill.decorator.ts
|
|
4814
4903
|
var import_reflect_metadata4 = require("reflect-metadata");
|
|
4815
|
-
var
|
|
4904
|
+
var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
|
|
4816
4905
|
var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
|
|
4817
4906
|
function Skill(options) {
|
|
4818
4907
|
return (target) => {
|
|
@@ -4825,7 +4914,7 @@ function readSkillMetadata(target) {
|
|
|
4825
4914
|
}
|
|
4826
4915
|
__name(readSkillMetadata, "readSkillMetadata");
|
|
4827
4916
|
function skillScope(options) {
|
|
4828
|
-
return options.scope ??
|
|
4917
|
+
return options.scope ?? import_nestjs_agent_core25.GLOBAL_SCOPE;
|
|
4829
4918
|
}
|
|
4830
4919
|
__name(skillScope, "skillScope");
|
|
4831
4920
|
|
|
@@ -4901,7 +4990,7 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
|
|
|
4901
4990
|
};
|
|
4902
4991
|
SkillDiscoveryService = _ts_decorate22([
|
|
4903
4992
|
(0, import_common23.Injectable)(),
|
|
4904
|
-
_ts_param21(1, (0, import_common23.Inject)(
|
|
4993
|
+
_ts_param21(1, (0, import_common23.Inject)(import_nestjs_agent_core26.AGENT_SKILL_SOURCES)),
|
|
4905
4994
|
_ts_metadata21("design:type", Function),
|
|
4906
4995
|
_ts_metadata21("design:paramtypes", [
|
|
4907
4996
|
typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
|
|
@@ -4910,7 +4999,7 @@ SkillDiscoveryService = _ts_decorate22([
|
|
|
4910
4999
|
], SkillDiscoveryService);
|
|
4911
5000
|
|
|
4912
5001
|
// src/in-process-sink.ts
|
|
4913
|
-
var
|
|
5002
|
+
var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
|
|
4914
5003
|
var InProcessTokenStreamSink = class {
|
|
4915
5004
|
static {
|
|
4916
5005
|
__name(this, "InProcessTokenStreamSink");
|
|
@@ -4965,7 +5054,7 @@ var InProcessTokenStreamSink = class {
|
|
|
4965
5054
|
}
|
|
4966
5055
|
if (buf.ended) {
|
|
4967
5056
|
if (buf.failure !== void 0) {
|
|
4968
|
-
throw new
|
|
5057
|
+
throw new import_nestjs_agent_core27.AgentStreamError(buf.failure);
|
|
4969
5058
|
}
|
|
4970
5059
|
return;
|
|
4971
5060
|
}
|
|
@@ -4978,7 +5067,7 @@ var InProcessTokenStreamSink = class {
|
|
|
4978
5067
|
};
|
|
4979
5068
|
|
|
4980
5069
|
// src/ledger-quota-provider.ts
|
|
4981
|
-
var
|
|
5070
|
+
var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
|
|
4982
5071
|
var LedgerQuotaProvider = class {
|
|
4983
5072
|
static {
|
|
4984
5073
|
__name(this, "LedgerQuotaProvider");
|
|
@@ -4998,12 +5087,12 @@ var LedgerQuotaProvider = class {
|
|
|
4998
5087
|
await this.dayWindow(actorRef, now)
|
|
4999
5088
|
];
|
|
5000
5089
|
if (this.store.usageBetween !== void 0) {
|
|
5001
|
-
const range = (0,
|
|
5090
|
+
const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("month", now);
|
|
5002
5091
|
const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
|
|
5003
5092
|
windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
|
|
5004
5093
|
}
|
|
5005
|
-
const blocked = (0,
|
|
5006
|
-
const warning = (0,
|
|
5094
|
+
const blocked = (0, import_nestjs_agent_core28.exhaustedWindow)(windows);
|
|
5095
|
+
const warning = (0, import_nestjs_agent_core28.quotaWarning)(windows);
|
|
5007
5096
|
return {
|
|
5008
5097
|
windows,
|
|
5009
5098
|
...blocked !== void 0 ? {
|
|
@@ -5015,7 +5104,7 @@ var LedgerQuotaProvider = class {
|
|
|
5015
5104
|
};
|
|
5016
5105
|
}
|
|
5017
5106
|
async dayWindow(actorRef, now) {
|
|
5018
|
-
const range = (0,
|
|
5107
|
+
const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("day", now);
|
|
5019
5108
|
const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
|
|
5020
5109
|
return this.window("day", usedTokens, costUsd, range.resetsAt);
|
|
5021
5110
|
}
|
|
@@ -5041,7 +5130,7 @@ var LedgerQuotaProvider = class {
|
|
|
5041
5130
|
|
|
5042
5131
|
// src/proposals/action-proposal-worker.service.ts
|
|
5043
5132
|
var import_node_crypto2 = require("crypto");
|
|
5044
|
-
var
|
|
5133
|
+
var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
|
|
5045
5134
|
var import_common24 = require("@nestjs/common");
|
|
5046
5135
|
function _ts_decorate23(decorators, target, key, desc) {
|
|
5047
5136
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5085,15 +5174,15 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5085
5174
|
}
|
|
5086
5175
|
onModuleInit() {
|
|
5087
5176
|
if (this.options.actionApprovalMode !== "independent") return;
|
|
5088
|
-
(0,
|
|
5177
|
+
(0, import_nestjs_agent_core29.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
|
|
5089
5178
|
if (this.options.surface === "http") return;
|
|
5090
5179
|
const resolver = this.options.backgroundActorResolver;
|
|
5091
5180
|
if (!resolver) throw new Error("BackgroundActorResolver is required");
|
|
5092
|
-
this.worker = new
|
|
5181
|
+
this.worker = new import_nestjs_agent_core29.ActionProposalWorker({
|
|
5093
5182
|
store: this.store,
|
|
5094
5183
|
workerId: (0, import_node_crypto2.randomUUID)(),
|
|
5095
5184
|
...this.options.actionProposalWorker,
|
|
5096
|
-
executor: new
|
|
5185
|
+
executor: new import_nestjs_agent_core29.ActionProposalExecutor({
|
|
5097
5186
|
resolver,
|
|
5098
5187
|
resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
|
|
5099
5188
|
const deps = this.deps.forProposal(proposal, actor);
|
|
@@ -5119,9 +5208,9 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5119
5208
|
};
|
|
5120
5209
|
ActionProposalWorkerService = _ts_decorate23([
|
|
5121
5210
|
(0, import_common24.Injectable)(),
|
|
5122
|
-
_ts_param22(0, (0, import_common24.Inject)(
|
|
5123
|
-
_ts_param22(1, (0, import_common24.Inject)(
|
|
5124
|
-
_ts_param22(2, (0, import_common24.Inject)(
|
|
5211
|
+
_ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_STORE)),
|
|
5212
|
+
_ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_OPTIONS)),
|
|
5213
|
+
_ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_DEPS_FACTORY)),
|
|
5125
5214
|
_ts_metadata22("design:type", Function),
|
|
5126
5215
|
_ts_metadata22("design:paramtypes", [
|
|
5127
5216
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
@@ -5131,7 +5220,7 @@ ActionProposalWorkerService = _ts_decorate23([
|
|
|
5131
5220
|
], ActionProposalWorkerService);
|
|
5132
5221
|
|
|
5133
5222
|
// src/proposals/action-proposal.controller.ts
|
|
5134
|
-
var
|
|
5223
|
+
var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
|
|
5135
5224
|
var import_common25 = require("@nestjs/common");
|
|
5136
5225
|
function _ts_decorate24(decorators, target, key, desc) {
|
|
5137
5226
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5185,7 +5274,7 @@ var ActionProposalController = class {
|
|
|
5185
5274
|
query = {
|
|
5186
5275
|
after: JSON.parse(cursor)
|
|
5187
5276
|
};
|
|
5188
|
-
(0,
|
|
5277
|
+
(0, import_nestjs_agent_core30.validateActionProposalListQuery)(query);
|
|
5189
5278
|
} catch {
|
|
5190
5279
|
throw new import_common25.BadRequestException("Invalid action proposal cursor");
|
|
5191
5280
|
}
|
|
@@ -5266,7 +5355,7 @@ _ts_decorate24([
|
|
|
5266
5355
|
], ActionProposalController.prototype, "reject", null);
|
|
5267
5356
|
ActionProposalController = _ts_decorate24([
|
|
5268
5357
|
(0, import_common25.Controller)("threads/:threadId/action-proposals"),
|
|
5269
|
-
_ts_param23(1, (0, import_common25.Inject)(
|
|
5358
|
+
_ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_ACTOR_RESOLVER)),
|
|
5270
5359
|
_ts_metadata23("design:type", Function),
|
|
5271
5360
|
_ts_metadata23("design:paramtypes", [
|
|
5272
5361
|
typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
|
|
@@ -5278,7 +5367,7 @@ ActionProposalController = _ts_decorate24([
|
|
|
5278
5367
|
var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
|
|
5279
5368
|
|
|
5280
5369
|
// src/runner/inline-agent-runner.ts
|
|
5281
|
-
var
|
|
5370
|
+
var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
|
|
5282
5371
|
var import_common26 = require("@nestjs/common");
|
|
5283
5372
|
function _ts_decorate25(decorators, target, key, desc) {
|
|
5284
5373
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -5362,18 +5451,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5362
5451
|
],
|
|
5363
5452
|
input
|
|
5364
5453
|
});
|
|
5365
|
-
void (0,
|
|
5454
|
+
void (0, import_nestjs_agent_core31.runAgentLoop)({
|
|
5366
5455
|
...deps,
|
|
5367
5456
|
day
|
|
5368
|
-
}, input, hooks).then(() => (0,
|
|
5369
|
-
if (error instanceof
|
|
5457
|
+
}, input, hooks).then(() => (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
|
|
5458
|
+
if (error instanceof import_nestjs_agent_core31.RunCancelledError) {
|
|
5370
5459
|
await this.settleCancelled(runId, input, deps);
|
|
5371
5460
|
return;
|
|
5372
5461
|
}
|
|
5373
5462
|
const message = error instanceof Error ? error.message : String(error);
|
|
5374
|
-
const code = (0,
|
|
5463
|
+
const code = (0, import_nestjs_agent_core31.agentFailureCode)(error);
|
|
5375
5464
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
5376
|
-
(0,
|
|
5465
|
+
(0, import_nestjs_agent_core31.publishAgentRunFailed)({
|
|
5377
5466
|
runId,
|
|
5378
5467
|
code,
|
|
5379
5468
|
message
|
|
@@ -5384,11 +5473,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5384
5473
|
errorCode: code,
|
|
5385
5474
|
errorMessage: message
|
|
5386
5475
|
});
|
|
5387
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5476
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core31.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
5388
5477
|
const writer = await deps.sink.open(runId);
|
|
5389
5478
|
await this.settleQueue(writer, input, runId, "failed", message);
|
|
5390
|
-
await (0,
|
|
5391
|
-
await writer.fail((0,
|
|
5479
|
+
await (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5480
|
+
await writer.fail((0, import_nestjs_agent_core31.streamFailure)(error));
|
|
5392
5481
|
}).finally(() => {
|
|
5393
5482
|
this.cancelled.delete(runId);
|
|
5394
5483
|
this.live.delete(runId);
|
|
@@ -5424,7 +5513,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5424
5513
|
for (const [key, waiter] of this.pending) {
|
|
5425
5514
|
if (key.startsWith(`${runId}:`)) {
|
|
5426
5515
|
this.pending.delete(key);
|
|
5427
|
-
waiter.reject(new
|
|
5516
|
+
waiter.reject(new import_nestjs_agent_core31.RunCancelledError());
|
|
5428
5517
|
}
|
|
5429
5518
|
}
|
|
5430
5519
|
await Promise.resolve();
|
|
@@ -5439,8 +5528,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5439
5528
|
this.logger.log(`agent run ${runId} cancelled`);
|
|
5440
5529
|
const writer = await deps.sink.open(runId);
|
|
5441
5530
|
await this.settleQueue(writer, input, runId, "cancelled");
|
|
5442
|
-
await (0,
|
|
5443
|
-
await writer.write((0,
|
|
5531
|
+
await (0, import_nestjs_agent_core31.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5532
|
+
await writer.write((0, import_nestjs_agent_core31.encodeStreamEvent)({
|
|
5444
5533
|
kind: "cancelled"
|
|
5445
5534
|
}));
|
|
5446
5535
|
await writer.end();
|
|
@@ -5475,7 +5564,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5475
5564
|
runId: nextRunId
|
|
5476
5565
|
}));
|
|
5477
5566
|
if (frame !== void 0) {
|
|
5478
|
-
await writer.write((0,
|
|
5567
|
+
await writer.write((0, import_nestjs_agent_core31.encodeStreamEvent)(frame));
|
|
5479
5568
|
}
|
|
5480
5569
|
} catch (failure) {
|
|
5481
5570
|
this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
@@ -5546,7 +5635,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5546
5635
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5547
5636
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5548
5637
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5549
|
-
parallel:
|
|
5638
|
+
parallel: import_nestjs_agent_core31.settleAll,
|
|
5550
5639
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5551
5640
|
runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
|
|
5552
5641
|
agentName,
|
|
@@ -5597,7 +5686,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5597
5686
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5598
5687
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5599
5688
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5600
|
-
parallel:
|
|
5689
|
+
parallel: import_nestjs_agent_core31.settleAll,
|
|
5601
5690
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5602
5691
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
|
|
5603
5692
|
agentName: childName,
|
|
@@ -5630,7 +5719,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5630
5719
|
}
|
|
5631
5720
|
}), "startAgent")
|
|
5632
5721
|
};
|
|
5633
|
-
void (0,
|
|
5722
|
+
void (0, import_nestjs_agent_core31.runAgentLoop)({
|
|
5634
5723
|
...deps,
|
|
5635
5724
|
day
|
|
5636
5725
|
}, {
|
|
@@ -5644,13 +5733,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5644
5733
|
parentRunId,
|
|
5645
5734
|
deliverTo
|
|
5646
5735
|
}, hooks).catch(async (error) => {
|
|
5647
|
-
const cancelled = error instanceof
|
|
5736
|
+
const cancelled = error instanceof import_nestjs_agent_core31.RunCancelledError;
|
|
5648
5737
|
const message = error instanceof Error ? error.message : String(error);
|
|
5649
5738
|
if (!cancelled) {
|
|
5650
5739
|
this.logger.error(`detached agent run ${runId} failed: ${message}`);
|
|
5651
|
-
(0,
|
|
5740
|
+
(0, import_nestjs_agent_core31.publishAgentRunFailed)({
|
|
5652
5741
|
runId,
|
|
5653
|
-
code: (0,
|
|
5742
|
+
code: (0, import_nestjs_agent_core31.agentFailureCode)(error),
|
|
5654
5743
|
message
|
|
5655
5744
|
});
|
|
5656
5745
|
}
|
|
@@ -5658,12 +5747,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5658
5747
|
runId,
|
|
5659
5748
|
status: cancelled ? "cancelled" : "failed",
|
|
5660
5749
|
...cancelled ? {} : {
|
|
5661
|
-
errorCode: (0,
|
|
5750
|
+
errorCode: (0, import_nestjs_agent_core31.agentFailureCode)(error),
|
|
5662
5751
|
errorMessage: message
|
|
5663
5752
|
}
|
|
5664
5753
|
});
|
|
5665
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5666
|
-
await (0,
|
|
5754
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core31.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
5755
|
+
await (0, import_nestjs_agent_core31.settleUnsettledDelegation)({
|
|
5667
5756
|
store: this.store,
|
|
5668
5757
|
delivery: deliverTo,
|
|
5669
5758
|
agent: agentName,
|
|
@@ -5702,7 +5791,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5702
5791
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5703
5792
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5704
5793
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5705
|
-
parallel:
|
|
5794
|
+
parallel: import_nestjs_agent_core31.settleAll,
|
|
5706
5795
|
// A child stops when it is cancelled OR when the run a human is actually watching is: the
|
|
5707
5796
|
// canceller names the top-level run, which is the only id that ever left the server.
|
|
5708
5797
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
|
|
@@ -5737,7 +5826,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5737
5826
|
}), "startAgent")
|
|
5738
5827
|
};
|
|
5739
5828
|
try {
|
|
5740
|
-
return await (0,
|
|
5829
|
+
return await (0, import_nestjs_agent_core31.runAgentLoop)({
|
|
5741
5830
|
...deps,
|
|
5742
5831
|
day
|
|
5743
5832
|
}, {
|
|
@@ -5758,8 +5847,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5758
5847
|
};
|
|
5759
5848
|
InlineAgentRunner = _ts_decorate25([
|
|
5760
5849
|
(0, import_common26.Injectable)(),
|
|
5761
|
-
_ts_param24(0, (0, import_common26.Inject)(
|
|
5762
|
-
_ts_param24(1, (0, import_common26.Inject)(
|
|
5850
|
+
_ts_param24(0, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_DEPS_FACTORY)),
|
|
5851
|
+
_ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_STORE)),
|
|
5763
5852
|
_ts_param24(2, (0, import_common26.Optional)()),
|
|
5764
5853
|
_ts_metadata24("design:type", Function),
|
|
5765
5854
|
_ts_metadata24("design:paramtypes", [
|
|
@@ -5774,7 +5863,7 @@ function isThreadTurn(input) {
|
|
|
5774
5863
|
__name(isThreadTurn, "isThreadTurn");
|
|
5775
5864
|
|
|
5776
5865
|
// src/skills-config.ts
|
|
5777
|
-
var
|
|
5866
|
+
var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
|
|
5778
5867
|
function declaredSkillProvider(declared) {
|
|
5779
5868
|
return {
|
|
5780
5869
|
list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
|
|
@@ -5800,7 +5889,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
5800
5889
|
declaredSkillProvider(declared)
|
|
5801
5890
|
];
|
|
5802
5891
|
return {
|
|
5803
|
-
provider: providers.length === 1 ? providers[0] : (0,
|
|
5892
|
+
provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core32.compositeSkillProvider)(providers),
|
|
5804
5893
|
...options.scopes !== void 0 ? {
|
|
5805
5894
|
scopes: options.scopes
|
|
5806
5895
|
} : {},
|
|
@@ -5828,15 +5917,15 @@ function _ts_decorate26(decorators, target, key, desc) {
|
|
|
5828
5917
|
__name(_ts_decorate26, "_ts_decorate");
|
|
5829
5918
|
var DEFAULT_PATH = "agent";
|
|
5830
5919
|
var logger = new import_common27.Logger("AgentModule");
|
|
5831
|
-
function
|
|
5920
|
+
function externalWrapper(modules, token) {
|
|
5832
5921
|
for (const module2 of modules.values()) {
|
|
5833
5922
|
if (module2.metatype === AgentModule) continue;
|
|
5834
|
-
const wrapper = module2.providers.get(
|
|
5923
|
+
const wrapper = module2.providers.get(token);
|
|
5835
5924
|
if (wrapper !== void 0) return wrapper;
|
|
5836
5925
|
}
|
|
5837
5926
|
return void 0;
|
|
5838
5927
|
}
|
|
5839
|
-
__name(
|
|
5928
|
+
__name(externalWrapper, "externalWrapper");
|
|
5840
5929
|
function forwardingStore(wrapper) {
|
|
5841
5930
|
const target = /* @__PURE__ */ __name(() => {
|
|
5842
5931
|
const instance = wrapper.instance;
|
|
@@ -5859,118 +5948,143 @@ function forwardingStore(wrapper) {
|
|
|
5859
5948
|
__name(forwardingStore, "forwardingStore");
|
|
5860
5949
|
function resolveStore(options, modules) {
|
|
5861
5950
|
if (options.store !== void 0) return options.store;
|
|
5862
|
-
const external =
|
|
5951
|
+
const external = externalWrapper(modules, import_nestjs_agent_core33.AGENT_STORE);
|
|
5863
5952
|
if (external !== void 0) return forwardingStore(external);
|
|
5864
5953
|
logger.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
|
|
5865
|
-
return new
|
|
5954
|
+
return new import_nestjs_agent_core33.InMemoryAgentStore();
|
|
5866
5955
|
}
|
|
5867
5956
|
__name(resolveStore, "resolveStore");
|
|
5957
|
+
function resolveRolesPolicy(options, modules) {
|
|
5958
|
+
const external = externalWrapper(modules, import_nestjs_agent_core33.AGENT_ROLES_POLICY);
|
|
5959
|
+
if (options.rolesPolicy !== void 0) {
|
|
5960
|
+
if (external !== void 0) {
|
|
5961
|
+
logger.warn("Both a `rolesPolicy` option and a module binding AGENT_ROLES_POLICY (e.g. AgentAuthzModule) are configured \u2014 the `rolesPolicy` option wins.");
|
|
5962
|
+
}
|
|
5963
|
+
return options.rolesPolicy;
|
|
5964
|
+
}
|
|
5965
|
+
if (external !== void 0) return forwardingPolicy(external);
|
|
5966
|
+
return options.emptyRoles === "deny" ? new import_nestjs_agent_core33.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core33.DefaultRolesPolicy(options.defaultRoles);
|
|
5967
|
+
}
|
|
5968
|
+
__name(resolveRolesPolicy, "resolveRolesPolicy");
|
|
5969
|
+
function forwardingPolicy(wrapper) {
|
|
5970
|
+
return {
|
|
5971
|
+
can(actor, tool) {
|
|
5972
|
+
const policy = wrapper.instance;
|
|
5973
|
+
if (policy === void 0 || policy === null) {
|
|
5974
|
+
throw new Error("AgentModule: the AGENT_ROLES_POLICY bound by another module is not ready yet");
|
|
5975
|
+
}
|
|
5976
|
+
return policy.can(actor, tool);
|
|
5977
|
+
}
|
|
5978
|
+
};
|
|
5979
|
+
}
|
|
5980
|
+
__name(forwardingPolicy, "forwardingPolicy");
|
|
5868
5981
|
function isQuotaProvider(quota) {
|
|
5869
5982
|
return quota !== void 0 && typeof quota.report === "function";
|
|
5870
5983
|
}
|
|
5871
5984
|
__name(isQuotaProvider, "isQuotaProvider");
|
|
5872
5985
|
function resolveCatalog(options) {
|
|
5873
5986
|
if (options.models !== void 0) return options.models;
|
|
5874
|
-
const carried = options.model
|
|
5987
|
+
const carried = options.model?.catalog;
|
|
5875
5988
|
return carried !== void 0 && typeof carried.list === "function" ? carried : void 0;
|
|
5876
5989
|
}
|
|
5877
5990
|
__name(resolveCatalog, "resolveCatalog");
|
|
5878
|
-
function sharedProviders(durable) {
|
|
5991
|
+
function sharedProviders(durable, engine) {
|
|
5879
5992
|
const providers = [
|
|
5880
5993
|
{
|
|
5881
|
-
provide:
|
|
5882
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
5994
|
+
provide: import_nestjs_agent_core33.AGENT_TOOL_REGISTRY,
|
|
5995
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core33.ToolRegistry(), "useFactory")
|
|
5883
5996
|
},
|
|
5884
5997
|
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
5885
5998
|
{
|
|
5886
|
-
provide:
|
|
5887
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
5999
|
+
provide: import_nestjs_agent_core33.AGENT_REGISTRY,
|
|
6000
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core33.AgentRegistry(), "useFactory")
|
|
5888
6001
|
},
|
|
5889
6002
|
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
5890
6003
|
{
|
|
5891
|
-
provide:
|
|
6004
|
+
provide: import_nestjs_agent_core33.AGENT_PROMPT_CONTRIBUTORS,
|
|
5892
6005
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
5893
6006
|
},
|
|
5894
6007
|
// Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
|
|
5895
6008
|
// read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
|
|
5896
6009
|
{
|
|
5897
|
-
provide:
|
|
6010
|
+
provide: import_nestjs_agent_core33.AGENT_SKILL_SOURCES,
|
|
5898
6011
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
5899
6012
|
},
|
|
5900
6013
|
{
|
|
5901
6014
|
// One resolution, shared by the loop's deps and the listing endpoint: a second one would
|
|
5902
6015
|
// drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
|
|
5903
6016
|
// host configured none — which is what keeps the turn's checkpoint sequence unchanged.
|
|
5904
|
-
provide:
|
|
6017
|
+
provide: import_nestjs_agent_core33.AGENT_SKILLS,
|
|
5905
6018
|
useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
|
|
5906
6019
|
inject: [
|
|
5907
|
-
|
|
5908
|
-
|
|
6020
|
+
import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6021
|
+
import_nestjs_agent_core33.AGENT_SKILL_SOURCES
|
|
5909
6022
|
]
|
|
5910
6023
|
},
|
|
5911
6024
|
{
|
|
5912
6025
|
// One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
|
|
5913
6026
|
// shown what the model was shown, and two resolutions would eventually disagree about that.
|
|
5914
|
-
provide:
|
|
6027
|
+
provide: import_nestjs_agent_core33.AGENT_MEMORY,
|
|
5915
6028
|
useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
|
|
5916
6029
|
inject: [
|
|
5917
|
-
|
|
6030
|
+
import_nestjs_agent_core33.AGENT_OPTIONS
|
|
5918
6031
|
]
|
|
5919
6032
|
},
|
|
5920
6033
|
{
|
|
5921
|
-
provide:
|
|
6034
|
+
provide: import_nestjs_agent_core33.AGENT_SINK,
|
|
5922
6035
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
5923
6036
|
inject: [
|
|
5924
|
-
|
|
6037
|
+
import_nestjs_agent_core33.AGENT_OPTIONS
|
|
5925
6038
|
]
|
|
5926
6039
|
},
|
|
5927
6040
|
{
|
|
5928
|
-
provide:
|
|
5929
|
-
useFactory: /* @__PURE__ */ __name((options) =>
|
|
6041
|
+
provide: import_nestjs_agent_core33.AGENT_ROLES_POLICY,
|
|
6042
|
+
useFactory: /* @__PURE__ */ __name((options, modules) => resolveRolesPolicy(options, modules), "useFactory"),
|
|
5930
6043
|
inject: [
|
|
5931
|
-
|
|
6044
|
+
import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6045
|
+
import_core4.ModulesContainer
|
|
5932
6046
|
]
|
|
5933
6047
|
},
|
|
5934
6048
|
{
|
|
5935
|
-
provide:
|
|
6049
|
+
provide: import_nestjs_agent_core33.AGENT_ACTOR_RESOLVER,
|
|
5936
6050
|
useFactory: /* @__PURE__ */ __name((options) => {
|
|
5937
6051
|
if (options.actorResolver !== void 0) return options.actorResolver;
|
|
5938
6052
|
logger.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
|
|
5939
6053
|
return new AnonymousActorResolver();
|
|
5940
6054
|
}, "useFactory"),
|
|
5941
6055
|
inject: [
|
|
5942
|
-
|
|
6056
|
+
import_nestjs_agent_core33.AGENT_OPTIONS
|
|
5943
6057
|
]
|
|
5944
6058
|
},
|
|
5945
6059
|
{
|
|
5946
|
-
provide:
|
|
6060
|
+
provide: import_nestjs_agent_core33.AGENT_MODEL,
|
|
5947
6061
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
5948
6062
|
inject: [
|
|
5949
|
-
|
|
6063
|
+
import_nestjs_agent_core33.AGENT_OPTIONS
|
|
5950
6064
|
]
|
|
5951
6065
|
},
|
|
5952
6066
|
{
|
|
5953
6067
|
// `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
|
|
5954
6068
|
// omitted, the ledger provider still reports usage, with no ceiling to block on.
|
|
5955
|
-
provide:
|
|
6069
|
+
provide: import_nestjs_agent_core33.AGENT_QUOTA_PROVIDER,
|
|
5956
6070
|
useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
|
|
5957
6071
|
warnAt: o.quota.warnAt
|
|
5958
6072
|
} : {}), "useFactory"),
|
|
5959
6073
|
inject: [
|
|
5960
|
-
|
|
5961
|
-
|
|
6074
|
+
import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6075
|
+
import_nestjs_agent_core33.AGENT_STORE
|
|
5962
6076
|
]
|
|
5963
6077
|
},
|
|
5964
6078
|
{
|
|
5965
|
-
provide:
|
|
6079
|
+
provide: import_nestjs_agent_core33.AGENT_MODEL_CATALOG,
|
|
5966
6080
|
useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
|
|
5967
6081
|
inject: [
|
|
5968
|
-
|
|
6082
|
+
import_nestjs_agent_core33.AGENT_OPTIONS
|
|
5969
6083
|
]
|
|
5970
6084
|
},
|
|
5971
6085
|
AgentDepsFactory2,
|
|
5972
6086
|
{
|
|
5973
|
-
provide:
|
|
6087
|
+
provide: import_nestjs_agent_core33.AGENT_DEPS_FACTORY,
|
|
5974
6088
|
useExisting: AgentDepsFactory2
|
|
5975
6089
|
},
|
|
5976
6090
|
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
@@ -5993,21 +6107,26 @@ function sharedProviders(durable) {
|
|
|
5993
6107
|
// through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
|
|
5994
6108
|
AgentApprovalPortAdapter,
|
|
5995
6109
|
{
|
|
5996
|
-
provide:
|
|
6110
|
+
provide: import_nestjs_agent_core33.AGENT_APPROVAL_PORT,
|
|
5997
6111
|
useExisting: AgentApprovalPortAdapter
|
|
5998
6112
|
}
|
|
5999
6113
|
];
|
|
6000
6114
|
providers.push({
|
|
6001
|
-
provide:
|
|
6115
|
+
provide: import_nestjs_agent_core33.AGENT_STORE,
|
|
6002
6116
|
useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
|
|
6003
6117
|
inject: [
|
|
6004
|
-
|
|
6118
|
+
import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6005
6119
|
import_core4.ModulesContainer
|
|
6006
6120
|
]
|
|
6007
6121
|
});
|
|
6008
|
-
if (
|
|
6122
|
+
if (engine !== void 0) {
|
|
6123
|
+
providers.push(...engine.providers, {
|
|
6124
|
+
provide: import_nestjs_agent_core33.AGENT_RUNNER,
|
|
6125
|
+
useExisting: engine.runner
|
|
6126
|
+
});
|
|
6127
|
+
} else if (durable) {
|
|
6009
6128
|
providers.push({
|
|
6010
|
-
provide:
|
|
6129
|
+
provide: import_nestjs_agent_core33.AGENT_RUNNER,
|
|
6011
6130
|
useFactory: /* @__PURE__ */ __name((durableRunner) => {
|
|
6012
6131
|
if (durableRunner === void 0) {
|
|
6013
6132
|
throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
|
|
@@ -6016,36 +6135,37 @@ function sharedProviders(durable) {
|
|
|
6016
6135
|
}, "useFactory"),
|
|
6017
6136
|
inject: [
|
|
6018
6137
|
{
|
|
6019
|
-
token:
|
|
6138
|
+
token: import_nestjs_agent_core33.AGENT_DURABLE_RUNNER,
|
|
6020
6139
|
optional: true
|
|
6021
6140
|
}
|
|
6022
6141
|
]
|
|
6023
6142
|
});
|
|
6024
6143
|
} else {
|
|
6025
6144
|
providers.push({
|
|
6026
|
-
provide:
|
|
6145
|
+
provide: import_nestjs_agent_core33.AGENT_RUNNER,
|
|
6027
6146
|
useExisting: InlineAgentRunner
|
|
6028
6147
|
});
|
|
6029
6148
|
}
|
|
6030
6149
|
return providers;
|
|
6031
6150
|
}
|
|
6032
6151
|
__name(sharedProviders, "sharedProviders");
|
|
6033
|
-
function exportsFor() {
|
|
6152
|
+
function exportsFor(engine) {
|
|
6034
6153
|
return [
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6154
|
+
...engine?.exports ?? [],
|
|
6155
|
+
import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6156
|
+
import_nestjs_agent_core33.AGENT_TOOL_REGISTRY,
|
|
6157
|
+
import_nestjs_agent_core33.AGENT_REGISTRY,
|
|
6158
|
+
import_nestjs_agent_core33.AGENT_SINK,
|
|
6159
|
+
import_nestjs_agent_core33.AGENT_ROLES_POLICY,
|
|
6160
|
+
import_nestjs_agent_core33.AGENT_ACTOR_RESOLVER,
|
|
6161
|
+
import_nestjs_agent_core33.AGENT_MODEL,
|
|
6162
|
+
import_nestjs_agent_core33.AGENT_STORE,
|
|
6163
|
+
import_nestjs_agent_core33.AGENT_MODEL_CATALOG,
|
|
6164
|
+
import_nestjs_agent_core33.AGENT_QUOTA_PROVIDER,
|
|
6165
|
+
import_nestjs_agent_core33.AGENT_PROMPT_CONTRIBUTORS,
|
|
6166
|
+
import_nestjs_agent_core33.AGENT_SKILLS,
|
|
6167
|
+
import_nestjs_agent_core33.AGENT_MEMORY,
|
|
6168
|
+
import_nestjs_agent_core33.AGENT_DEPS_FACTORY,
|
|
6049
6169
|
AgentDepsFactory2,
|
|
6050
6170
|
AgentService,
|
|
6051
6171
|
ActionProposalService,
|
|
@@ -6053,7 +6173,7 @@ function exportsFor() {
|
|
|
6053
6173
|
ChatQueueService,
|
|
6054
6174
|
AGENT_CHAT_QUEUE,
|
|
6055
6175
|
InlineAgentRunner,
|
|
6056
|
-
|
|
6176
|
+
import_nestjs_agent_core33.AGENT_APPROVAL_PORT
|
|
6057
6177
|
];
|
|
6058
6178
|
}
|
|
6059
6179
|
__name(exportsFor, "exportsFor");
|
|
@@ -6081,10 +6201,11 @@ function adapterProviders(adapters) {
|
|
|
6081
6201
|
return (adapters ?? []).flatMap((adapter) => adapter.providers ?? []);
|
|
6082
6202
|
}
|
|
6083
6203
|
__name(adapterProviders, "adapterProviders");
|
|
6084
|
-
function controllersForSurface(surface, adapters) {
|
|
6204
|
+
function controllersForSurface(surface, adapters, engine) {
|
|
6085
6205
|
return surface === "engine" ? [] : [
|
|
6086
6206
|
...BASE_CONTROLLERS,
|
|
6087
|
-
...adapterControllers(adapters)
|
|
6207
|
+
...adapterControllers(adapters),
|
|
6208
|
+
...engine?.controllers ?? []
|
|
6088
6209
|
];
|
|
6089
6210
|
}
|
|
6090
6211
|
__name(controllersForSurface, "controllersForSurface");
|
|
@@ -6114,12 +6235,22 @@ function routerFor(path) {
|
|
|
6114
6235
|
]);
|
|
6115
6236
|
}
|
|
6116
6237
|
__name(routerFor, "routerFor");
|
|
6238
|
+
function assertRunnable(options) {
|
|
6239
|
+
if (options.engine !== void 0 && options.durable === true) {
|
|
6240
|
+
throw new Error(`AgentModule: \`durable: true\` runs turns on the library's loop, but the \`${options.engine.name}\` engine runs them instead. Drop \`durable\` (the engine decides how its turns survive a restart).`);
|
|
6241
|
+
}
|
|
6242
|
+
if (options.engine === void 0 && options.model === void 0) {
|
|
6243
|
+
throw new Error("AgentModule: set `model` (the loop runs the turns) or `engine` (something else does).");
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
__name(assertRunnable, "assertRunnable");
|
|
6117
6247
|
var AgentModule = class _AgentModule {
|
|
6118
6248
|
static {
|
|
6119
6249
|
__name(this, "AgentModule");
|
|
6120
6250
|
}
|
|
6121
6251
|
static forRoot(options) {
|
|
6122
6252
|
const path = options.path ?? DEFAULT_PATH;
|
|
6253
|
+
assertRunnable(options);
|
|
6123
6254
|
applyGuards(options.guards, options.adapters);
|
|
6124
6255
|
return {
|
|
6125
6256
|
module: _AgentModule,
|
|
@@ -6128,21 +6259,27 @@ var AgentModule = class _AgentModule {
|
|
|
6128
6259
|
import_core4.DiscoveryModule,
|
|
6129
6260
|
routerFor(path)
|
|
6130
6261
|
],
|
|
6131
|
-
controllers: controllersForSurface(options.surface, options.adapters),
|
|
6262
|
+
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6132
6263
|
providers: [
|
|
6133
6264
|
{
|
|
6134
|
-
provide:
|
|
6265
|
+
provide: import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6135
6266
|
useValue: options
|
|
6136
6267
|
},
|
|
6137
|
-
...sharedProviders(options.durable ?? false),
|
|
6268
|
+
...sharedProviders(options.durable ?? false, options.engine),
|
|
6138
6269
|
...guardProviders(options.guards),
|
|
6139
6270
|
...adapterProviders(options.adapters)
|
|
6140
6271
|
],
|
|
6141
|
-
exports: exportsFor()
|
|
6272
|
+
exports: exportsFor(options.engine)
|
|
6142
6273
|
};
|
|
6143
6274
|
}
|
|
6144
6275
|
static forRootAsync(options) {
|
|
6145
6276
|
const path = options.path ?? DEFAULT_PATH;
|
|
6277
|
+
if (options.engine !== void 0) {
|
|
6278
|
+
assertRunnable({
|
|
6279
|
+
engine: options.engine,
|
|
6280
|
+
durable: options.durable ?? false
|
|
6281
|
+
});
|
|
6282
|
+
}
|
|
6146
6283
|
applyGuards(options.guards, options.adapters);
|
|
6147
6284
|
return {
|
|
6148
6285
|
module: _AgentModule,
|
|
@@ -6152,28 +6289,35 @@ var AgentModule = class _AgentModule {
|
|
|
6152
6289
|
routerFor(path),
|
|
6153
6290
|
...options.imports ?? []
|
|
6154
6291
|
],
|
|
6155
|
-
controllers: controllersForSurface(options.surface, options.adapters),
|
|
6292
|
+
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6156
6293
|
providers: [
|
|
6157
6294
|
{
|
|
6158
|
-
provide:
|
|
6295
|
+
provide: import_nestjs_agent_core33.AGENT_OPTIONS,
|
|
6159
6296
|
// Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
|
|
6160
6297
|
// authoritative on the async config object (they decided the actual wiring above), and
|
|
6161
6298
|
// the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
|
|
6162
6299
|
// anything today (AgentDurableModule takes its own mirror option — see its doc for why),
|
|
6163
6300
|
// but it's stamped here too so the EFFECTIVE value is always observable off
|
|
6164
6301
|
// AGENT_OPTIONS, sync or async alike.
|
|
6165
|
-
useFactory: /* @__PURE__ */ __name(async (...args) =>
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6302
|
+
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
6303
|
+
const resolved = {
|
|
6304
|
+
...await options.useFactory(...args),
|
|
6305
|
+
durable: options.durable ?? false,
|
|
6306
|
+
surface: options.surface ?? "both",
|
|
6307
|
+
...options.engine !== void 0 ? {
|
|
6308
|
+
engine: options.engine
|
|
6309
|
+
} : {}
|
|
6310
|
+
};
|
|
6311
|
+
assertRunnable(resolved);
|
|
6312
|
+
return resolved;
|
|
6313
|
+
}, "useFactory"),
|
|
6170
6314
|
inject: options.inject ?? []
|
|
6171
6315
|
},
|
|
6172
|
-
...sharedProviders(options.durable ?? false),
|
|
6316
|
+
...sharedProviders(options.durable ?? false, options.engine),
|
|
6173
6317
|
...guardProviders(options.guards),
|
|
6174
6318
|
...adapterProviders(options.adapters)
|
|
6175
6319
|
],
|
|
6176
|
-
exports: exportsFor()
|
|
6320
|
+
exports: exportsFor(options.engine)
|
|
6177
6321
|
};
|
|
6178
6322
|
}
|
|
6179
6323
|
};
|
|
@@ -6183,7 +6327,7 @@ AgentModule = _ts_decorate26([
|
|
|
6183
6327
|
], AgentModule);
|
|
6184
6328
|
|
|
6185
6329
|
// src/ag-ui/ag-ui.adapter.ts
|
|
6186
|
-
var
|
|
6330
|
+
var import_nestjs_agent_core34 = require("@dudousxd/nestjs-agent-core");
|
|
6187
6331
|
var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
|
|
6188
6332
|
var import_common28 = require("@nestjs/common");
|
|
6189
6333
|
function _ts_decorate27(decorators, target, key, desc) {
|
|
@@ -6270,6 +6414,19 @@ var AgUiRunHandler = class {
|
|
|
6270
6414
|
warnings.push(`The resume entry ${id} answers an interrupt this agent did not raise.`);
|
|
6271
6415
|
}
|
|
6272
6416
|
const first = plan.decisions[0];
|
|
6417
|
+
if (first !== void 0 && plan.decisions.every((d) => d.address.kind === "proposal")) {
|
|
6418
|
+
const decided = await this.decideProposals(actor, plan.decisions);
|
|
6419
|
+
this.writeEvents(res, [
|
|
6420
|
+
...warningEvents(warnings),
|
|
6421
|
+
...decided.flatMap((outcome, index) => (0, import_ag_ui.actionProposalDecisionEvents)({
|
|
6422
|
+
threadId: input.threadId,
|
|
6423
|
+
runId: index === 0 ? input.runId : `${input.runId}:${index}`,
|
|
6424
|
+
text: outcome.text,
|
|
6425
|
+
proposalDecision: outcome.proposalDecision
|
|
6426
|
+
}))
|
|
6427
|
+
]);
|
|
6428
|
+
return;
|
|
6429
|
+
}
|
|
6273
6430
|
if (first !== void 0) {
|
|
6274
6431
|
const streamRunId = first.address.stream;
|
|
6275
6432
|
await this.agent.assertResumable(actor, streamRunId);
|
|
@@ -6298,11 +6455,7 @@ var AgUiRunHandler = class {
|
|
|
6298
6455
|
if (owner !== null && turn.media.length === 0) {
|
|
6299
6456
|
const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
|
|
6300
6457
|
if ("proposalDecision" in decision) {
|
|
6301
|
-
|
|
6302
|
-
res.setHeader("Content-Type", "text/event-stream");
|
|
6303
|
-
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
6304
|
-
res.flushHeaders();
|
|
6305
|
-
for (const event of [
|
|
6458
|
+
this.writeEvents(res, [
|
|
6306
6459
|
...warningEvents(warnings),
|
|
6307
6460
|
...(0, import_ag_ui.actionProposalDecisionEvents)({
|
|
6308
6461
|
threadId: input.threadId,
|
|
@@ -6310,8 +6463,7 @@ var AgUiRunHandler = class {
|
|
|
6310
6463
|
text: decision.text,
|
|
6311
6464
|
proposalDecision: decision.proposalDecision
|
|
6312
6465
|
})
|
|
6313
|
-
])
|
|
6314
|
-
res.end();
|
|
6466
|
+
]);
|
|
6315
6467
|
return;
|
|
6316
6468
|
}
|
|
6317
6469
|
}
|
|
@@ -6403,9 +6555,11 @@ var AgUiRunHandler = class {
|
|
|
6403
6555
|
*/
|
|
6404
6556
|
async settle(actor, decisions) {
|
|
6405
6557
|
const deliveries = [];
|
|
6558
|
+
const proposals = decisions.filter((decision) => decision.address.kind === "proposal");
|
|
6406
6559
|
for (const { address, entry } of decisions) {
|
|
6407
6560
|
const { toolCallId: toolCallId2 } = address;
|
|
6408
6561
|
const abandoned = entry.status === "cancelled";
|
|
6562
|
+
if (address.kind === "proposal") continue;
|
|
6409
6563
|
if (address.kind === "approval") {
|
|
6410
6564
|
await this.agent.checkDecision(actor, toolCallId2);
|
|
6411
6565
|
const decision = abandoned ? {
|
|
@@ -6442,9 +6596,53 @@ var AgUiRunHandler = class {
|
|
|
6442
6596
|
via: AG_UI_VIA
|
|
6443
6597
|
}));
|
|
6444
6598
|
}
|
|
6599
|
+
if (proposals.length > 0) await this.decideProposals(actor, proposals);
|
|
6445
6600
|
for (const deliver of deliveries) await deliver();
|
|
6446
6601
|
}
|
|
6447
6602
|
/**
|
|
6603
|
+
* Decide independent proposals through the proposal service — the call the native
|
|
6604
|
+
* `action-proposals/:id/approve|reject` routes make — never by signalling the origin run, which
|
|
6605
|
+
* is not waiting. Every payload is checked before the first decision; a refusal is the service's
|
|
6606
|
+
* own `403`/`404`.
|
|
6607
|
+
*/
|
|
6608
|
+
async decideProposals(actor, decisions) {
|
|
6609
|
+
const planned = decisions.map(({ address, entry }) => {
|
|
6610
|
+
const decision = entry.status === "cancelled" ? {
|
|
6611
|
+
approved: false
|
|
6612
|
+
} : (0, import_ag_ui.readApprovalPayload)(entry.payload);
|
|
6613
|
+
if (decision === null || address.proposalId === void 0 || address.threadId === void 0) {
|
|
6614
|
+
throw invalid("invalid_resume", "an approval is answered with { approved: boolean, reason?, remember? }");
|
|
6615
|
+
}
|
|
6616
|
+
return {
|
|
6617
|
+
address,
|
|
6618
|
+
decision
|
|
6619
|
+
};
|
|
6620
|
+
});
|
|
6621
|
+
const outcomes = [];
|
|
6622
|
+
for (const { address, decision } of planned) {
|
|
6623
|
+
outcomes.push(await this.agent.decideActionProposal(actor, address.threadId, address.proposalId, {
|
|
6624
|
+
decision: decision.approved ? "approved" : "rejected",
|
|
6625
|
+
via: AG_UI_VIA,
|
|
6626
|
+
...decision.remember !== void 0 ? {
|
|
6627
|
+
remember: decision.remember
|
|
6628
|
+
} : {},
|
|
6629
|
+
...decision.reason !== void 0 ? {
|
|
6630
|
+
reason: decision.reason
|
|
6631
|
+
} : {}
|
|
6632
|
+
}));
|
|
6633
|
+
}
|
|
6634
|
+
return outcomes;
|
|
6635
|
+
}
|
|
6636
|
+
/** Answer with a complete list of events, no run behind them. */
|
|
6637
|
+
writeEvents(res, events) {
|
|
6638
|
+
res.status(200);
|
|
6639
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
6640
|
+
res.setHeader("Cache-Control", "no-cache, no-transform");
|
|
6641
|
+
res.flushHeaders();
|
|
6642
|
+
for (const event of events) res.write((0, import_ag_ui.agUiSse)(event));
|
|
6643
|
+
res.end();
|
|
6644
|
+
}
|
|
6645
|
+
/**
|
|
6448
6646
|
* Pipe a run to the client as AG-UI 1.0 over SSE: one event per `data:` line, from `RUN_STARTED`
|
|
6449
6647
|
* to the run's terminal event. It ends when the run stops to ask — the library run stays parked,
|
|
6450
6648
|
* and the request that answers re-attaches to it.
|
|
@@ -6507,10 +6705,10 @@ function agUiAdapter(options = {}) {
|
|
|
6507
6705
|
AgUiController = _ts_decorate27([
|
|
6508
6706
|
(0, import_common28.Controller)(),
|
|
6509
6707
|
_ts_param25(0, (0, import_common28.Inject)(AgentService)),
|
|
6510
|
-
_ts_param25(1, (0, import_common28.Inject)(
|
|
6511
|
-
_ts_param25(2, (0, import_common28.Inject)(
|
|
6708
|
+
_ts_param25(1, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER)),
|
|
6709
|
+
_ts_param25(2, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_OPTIONS)),
|
|
6512
6710
|
_ts_param25(3, (0, import_common28.Optional)()),
|
|
6513
|
-
_ts_param25(3, (0, import_common28.Inject)(
|
|
6711
|
+
_ts_param25(3, (0, import_common28.Inject)(import_nestjs_agent_core34.AGENT_ATTACHMENT_STAGING)),
|
|
6514
6712
|
_ts_metadata25("design:type", Function),
|
|
6515
6713
|
_ts_metadata25("design:paramtypes", [
|
|
6516
6714
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
@@ -6652,6 +6850,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
|
|
|
6652
6850
|
attachmentLimits,
|
|
6653
6851
|
declaredSkillProvider,
|
|
6654
6852
|
defaultRequestUserMapper,
|
|
6853
|
+
defineTool,
|
|
6655
6854
|
delegateToolName,
|
|
6656
6855
|
provideAgentTool,
|
|
6657
6856
|
provideAgentTools,
|