@dudousxd/nestjs-agent 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-deps.factory-DpVkZYCy.d.cts → agent-deps.factory-BM_RB6br.d.cts} +65 -4
- package/dist/{agent-deps.factory-DpVkZYCy.d.ts → agent-deps.factory-BM_RB6br.d.ts} +65 -4
- package/dist/durable/index.cjs +529 -272
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +4 -4
- package/dist/durable/index.d.ts +4 -4
- package/dist/durable/index.js +484 -227
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +520 -269
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -5
- package/dist/index.d.ts +53 -5
- package/dist/index.js +472 -224
- package/dist/index.js.map +1 -1
- package/dist/sink-redis/index.cjs +144 -0
- package/dist/sink-redis/index.cjs.map +1 -0
- package/dist/sink-redis/index.d.cts +39 -0
- package/dist/sink-redis/index.d.ts +39 -0
- package/dist/sink-redis/index.js +119 -0
- package/dist/sink-redis/index.js.map +1 -0
- package/package.json +27 -5
package/dist/durable/index.cjs
CHANGED
|
@@ -111,10 +111,12 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
111
111
|
}, "runAgent")
|
|
112
112
|
};
|
|
113
113
|
try {
|
|
114
|
-
|
|
114
|
+
const result = await (0, import_nestjs_agent_core.runAgentLoop)({
|
|
115
115
|
...deps,
|
|
116
116
|
day
|
|
117
117
|
}, input, hooks);
|
|
118
|
+
await ctx.step("deactivate", () => this.store.setActiveStream(input.threadId, null));
|
|
119
|
+
return result;
|
|
118
120
|
} catch (error) {
|
|
119
121
|
if (error instanceof import_nestjs_durable_core.WorkflowSuspended || error instanceof import_nestjs_durable_core.ContinueAsNew) {
|
|
120
122
|
throw error;
|
|
@@ -126,6 +128,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
126
128
|
code,
|
|
127
129
|
message
|
|
128
130
|
});
|
|
131
|
+
await ctx.step("deactivate", () => this.store.setActiveStream(input.threadId, null));
|
|
129
132
|
const writer = await hooks.openSink();
|
|
130
133
|
await writer.fail({
|
|
131
134
|
code,
|
|
@@ -151,7 +154,9 @@ AgentRunWorkflow = _ts_decorate([
|
|
|
151
154
|
], AgentRunWorkflow);
|
|
152
155
|
|
|
153
156
|
// src/durable/durable-agent-runner.ts
|
|
157
|
+
var import_node_crypto = require("crypto");
|
|
154
158
|
var import_nestjs_durable2 = require("@dudousxd/nestjs-durable");
|
|
159
|
+
var import_nestjs_durable_core2 = require("@dudousxd/nestjs-durable-core");
|
|
155
160
|
var import_common2 = require("@nestjs/common");
|
|
156
161
|
function _ts_decorate2(decorators, target, key, desc) {
|
|
157
162
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -177,9 +182,16 @@ var DurableAgentRunner = class {
|
|
|
177
182
|
...input,
|
|
178
183
|
day: input.day ?? utcDay()
|
|
179
184
|
};
|
|
180
|
-
const
|
|
185
|
+
const runId = (0, import_node_crypto.randomUUID)();
|
|
186
|
+
try {
|
|
187
|
+
await this.workflows.start(AgentRunWorkflow, stamped, runId);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (!(error instanceof import_nestjs_durable_core2.WorkflowSuspended)) {
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
181
193
|
return {
|
|
182
|
-
runId
|
|
194
|
+
runId
|
|
183
195
|
};
|
|
184
196
|
}
|
|
185
197
|
async signal(runId, toolCallId, decision) {
|
|
@@ -242,8 +254,8 @@ AgentDurableModule = _ts_decorate3([
|
|
|
242
254
|
], AgentDurableModule);
|
|
243
255
|
|
|
244
256
|
// src/agent.module.ts
|
|
245
|
-
var
|
|
246
|
-
var
|
|
257
|
+
var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
|
|
258
|
+
var import_common15 = require("@nestjs/common");
|
|
247
259
|
var import_core3 = require("@nestjs/core");
|
|
248
260
|
|
|
249
261
|
// src/agent-deps.factory.ts
|
|
@@ -284,7 +296,8 @@ var AgentDepsFactory2 = class {
|
|
|
284
296
|
agents;
|
|
285
297
|
promptContributors;
|
|
286
298
|
quota;
|
|
287
|
-
|
|
299
|
+
pricingStore;
|
|
300
|
+
constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota, pricingStore) {
|
|
288
301
|
this.options = options;
|
|
289
302
|
this.model = model;
|
|
290
303
|
this.store = store;
|
|
@@ -294,6 +307,7 @@ var AgentDepsFactory2 = class {
|
|
|
294
307
|
this.agents = agents;
|
|
295
308
|
this.promptContributors = promptContributors;
|
|
296
309
|
this.quota = quota;
|
|
310
|
+
this.pricingStore = pricingStore;
|
|
297
311
|
}
|
|
298
312
|
/**
|
|
299
313
|
* The agent a turn uses when the caller names none: the explicit `defaultAgent` option, else the
|
|
@@ -340,6 +354,9 @@ var AgentDepsFactory2 = class {
|
|
|
340
354
|
...this.quota !== void 0 ? {
|
|
341
355
|
quota: this.quota
|
|
342
356
|
} : {},
|
|
357
|
+
...this.pricingStore !== void 0 ? {
|
|
358
|
+
pricingStore: this.pricingStore
|
|
359
|
+
} : {},
|
|
343
360
|
...toolAllowList !== void 0 ? {
|
|
344
361
|
toolAllowList
|
|
345
362
|
} : {},
|
|
@@ -380,6 +397,8 @@ AgentDepsFactory2 = _ts_decorate4([
|
|
|
380
397
|
_ts_param2(6, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_REGISTRY)),
|
|
381
398
|
_ts_param2(7, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_PROMPT_CONTRIBUTORS)),
|
|
382
399
|
_ts_param2(8, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_STORE)),
|
|
400
|
+
_ts_param2(9, (0, import_common4.Optional)()),
|
|
401
|
+
_ts_param2(9, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_PRICING_STORE)),
|
|
383
402
|
_ts_metadata3("design:type", Function),
|
|
384
403
|
_ts_metadata3("design:paramtypes", [
|
|
385
404
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -390,6 +409,7 @@ AgentDepsFactory2 = _ts_decorate4([
|
|
|
390
409
|
typeof import_nestjs_agent_core3.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core3.ToolRegistry,
|
|
391
410
|
typeof import_nestjs_agent_core3.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core3.AgentRegistry,
|
|
392
411
|
Array,
|
|
412
|
+
Object,
|
|
393
413
|
Object
|
|
394
414
|
])
|
|
395
415
|
], AgentDepsFactory2);
|
|
@@ -429,7 +449,7 @@ var AgentService = class {
|
|
|
429
449
|
this.quota = quota;
|
|
430
450
|
}
|
|
431
451
|
async chat(params) {
|
|
432
|
-
const agentName = params.agentName
|
|
452
|
+
const agentName = await this.resolveAgentName(params.agentName, params.threadId);
|
|
433
453
|
let threadId = params.threadId;
|
|
434
454
|
if (threadId === void 0) {
|
|
435
455
|
if (params.regenerate === true) {
|
|
@@ -454,6 +474,9 @@ var AgentService = class {
|
|
|
454
474
|
...params.regenerate === true ? {
|
|
455
475
|
regenerate: true
|
|
456
476
|
} : {},
|
|
477
|
+
...params.attachments !== void 0 ? {
|
|
478
|
+
attachments: params.attachments
|
|
479
|
+
} : {},
|
|
457
480
|
...params.pageContext !== void 0 ? {
|
|
458
481
|
pageContext: params.pageContext
|
|
459
482
|
} : {}
|
|
@@ -487,12 +510,14 @@ var AgentService = class {
|
|
|
487
510
|
await this.assertOwnsActiveStream(actor, runId);
|
|
488
511
|
return this.runner.cancel(runId);
|
|
489
512
|
}
|
|
490
|
-
listThreads(actorRef) {
|
|
491
|
-
|
|
513
|
+
async listThreads(actorRef) {
|
|
514
|
+
const threads = await this.store.listThreads(actorRef);
|
|
515
|
+
return Promise.all(threads.map((thread) => this.toSummaryView(thread)));
|
|
492
516
|
}
|
|
493
517
|
async getThread(actor, threadId) {
|
|
494
518
|
await this.assertOwnsThread(actor, threadId);
|
|
495
|
-
|
|
519
|
+
const thread = await this.store.getThread(threadId);
|
|
520
|
+
return thread === null ? null : this.toDetailView(thread);
|
|
496
521
|
}
|
|
497
522
|
async deleteThread(actor, threadId) {
|
|
498
523
|
await this.assertOwnsThread(actor, threadId);
|
|
@@ -502,7 +527,38 @@ var AgentService = class {
|
|
|
502
527
|
await this.assertOwnsThread(actor, threadId);
|
|
503
528
|
return this.store.forkThread(threadId, fromMessageId);
|
|
504
529
|
}
|
|
530
|
+
/** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
|
|
505
531
|
async renameThread(actor, threadId, title) {
|
|
532
|
+
return this.updateThread(actor, threadId, {
|
|
533
|
+
title
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Rename a thread and/or set its default agent. Title-only patches work against ANY store (via
|
|
538
|
+
* the required `setTitle`); a `defaultAgent` change requires the bound store to implement the
|
|
539
|
+
* optional `updateThread` — 501 with a clear message when it doesn't, rather than silently
|
|
540
|
+
* dropping the field.
|
|
541
|
+
*/
|
|
542
|
+
async updateThread(actor, threadId, patch) {
|
|
543
|
+
const title = patch.title !== void 0 ? this.validateTitle(patch.title) : void 0;
|
|
544
|
+
await this.assertOwnsThread(actor, threadId);
|
|
545
|
+
if (patch.defaultAgent === void 0) {
|
|
546
|
+
if (title !== void 0) {
|
|
547
|
+
await this.store.setTitle(threadId, title);
|
|
548
|
+
}
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
if (this.store.updateThread === void 0) {
|
|
552
|
+
throw new import_common5.NotImplementedException("Setting a thread's defaultAgent requires an AgentStore that implements updateThread(); the bound store does not support it.");
|
|
553
|
+
}
|
|
554
|
+
await this.store.updateThread(threadId, {
|
|
555
|
+
...title !== void 0 ? {
|
|
556
|
+
title
|
|
557
|
+
} : {},
|
|
558
|
+
defaultAgent: patch.defaultAgent
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
validateTitle(title) {
|
|
506
562
|
const trimmed = title.trim();
|
|
507
563
|
if (trimmed.length === 0) {
|
|
508
564
|
throw new import_common5.BadRequestException("title must not be empty");
|
|
@@ -510,8 +566,41 @@ var AgentService = class {
|
|
|
510
566
|
if (trimmed.length > 200) {
|
|
511
567
|
throw new import_common5.BadRequestException("title must be at most 200 characters");
|
|
512
568
|
}
|
|
513
|
-
|
|
514
|
-
|
|
569
|
+
return trimmed;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Agent-selection precedence for a `chat()` call with no explicit `agentName`: the thread's own
|
|
573
|
+
* `defaultAgent` (if the thread exists and one is set) wins over the module's configured default.
|
|
574
|
+
* Skips the thread lookup entirely when the caller already named an agent or there's no thread yet.
|
|
575
|
+
*/
|
|
576
|
+
async resolveAgentName(agentName, threadId) {
|
|
577
|
+
if (agentName !== void 0) {
|
|
578
|
+
return agentName;
|
|
579
|
+
}
|
|
580
|
+
if (threadId !== void 0) {
|
|
581
|
+
const thread = await this.store.getThread(threadId);
|
|
582
|
+
if (thread?.defaultAgent !== void 0 && thread.defaultAgent !== null) {
|
|
583
|
+
return thread.defaultAgent;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return this.deps.defaultAgentName();
|
|
587
|
+
}
|
|
588
|
+
async toSummaryView(thread) {
|
|
589
|
+
return {
|
|
590
|
+
...thread,
|
|
591
|
+
defaultAgent: thread.defaultAgent ?? null,
|
|
592
|
+
activeRunId: await this.store.activeRunForThread?.(thread.id) ?? null
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
async toDetailView(thread) {
|
|
596
|
+
const summary = await this.toSummaryView(thread);
|
|
597
|
+
return {
|
|
598
|
+
...summary,
|
|
599
|
+
messages: thread.messages,
|
|
600
|
+
...thread.activeStreamId !== void 0 ? {
|
|
601
|
+
activeStreamId: thread.activeStreamId
|
|
602
|
+
} : {}
|
|
603
|
+
};
|
|
515
604
|
}
|
|
516
605
|
async promoteThread(actor, threadId) {
|
|
517
606
|
await this.assertOwnsThread(actor, threadId);
|
|
@@ -667,9 +756,10 @@ AgentsController = _ts_decorate6([
|
|
|
667
756
|
])
|
|
668
757
|
], AgentsController);
|
|
669
758
|
|
|
670
|
-
// src/controller/
|
|
759
|
+
// src/controller/attachments.controller.ts
|
|
671
760
|
var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
|
|
672
761
|
var import_common7 = require("@nestjs/common");
|
|
762
|
+
var import_platform_express = require("@nestjs/platform-express");
|
|
673
763
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
674
764
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
675
765
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -687,6 +777,110 @@ function _ts_param5(paramIndex, decorator) {
|
|
|
687
777
|
};
|
|
688
778
|
}
|
|
689
779
|
__name(_ts_param5, "_ts_param");
|
|
780
|
+
var DEFAULT_MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
781
|
+
var DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES = [
|
|
782
|
+
"image/png",
|
|
783
|
+
"image/jpeg",
|
|
784
|
+
"image/gif",
|
|
785
|
+
"image/webp",
|
|
786
|
+
"application/pdf",
|
|
787
|
+
"text/plain",
|
|
788
|
+
"text/csv"
|
|
789
|
+
];
|
|
790
|
+
var AttachmentsController = class {
|
|
791
|
+
static {
|
|
792
|
+
__name(this, "AttachmentsController");
|
|
793
|
+
}
|
|
794
|
+
options;
|
|
795
|
+
actorResolver;
|
|
796
|
+
staging;
|
|
797
|
+
constructor(options, actorResolver, staging) {
|
|
798
|
+
this.options = options;
|
|
799
|
+
this.actorResolver = actorResolver;
|
|
800
|
+
this.staging = staging;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* `attachments.upload: true` is what mounts this controller at all (see `agent.module.ts`), so by
|
|
804
|
+
* the time an instance exists the host clearly intends uploads to work. Fail boot loudly rather
|
|
805
|
+
* than mounting a controller that would 501 on every single request because nobody bound
|
|
806
|
+
* `AGENT_ATTACHMENT_STAGING`.
|
|
807
|
+
*/
|
|
808
|
+
onModuleInit() {
|
|
809
|
+
if (this.options.attachments?.upload === true && this.staging === void 0) {
|
|
810
|
+
throw new Error("AgentModule: attachments.upload is true but no AGENT_ATTACHMENT_STAGING provider is bound. Bind one (e.g. `{ provide: AGENT_ATTACHMENT_STAGING, useClass: MyStagingStore }`) in a module imported alongside AgentModule, or set attachments.upload to false.");
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
async upload(req, file) {
|
|
814
|
+
if (this.staging === void 0) {
|
|
815
|
+
throw new import_common7.NotImplementedException("Attachment upload is not configured on this server.");
|
|
816
|
+
}
|
|
817
|
+
if (file === void 0) {
|
|
818
|
+
throw new import_common7.BadRequestException('multipart field "file" is required');
|
|
819
|
+
}
|
|
820
|
+
const allowedContentTypes = this.options.attachments?.allowedContentTypes ?? DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES;
|
|
821
|
+
if (!allowedContentTypes.includes(file.mimetype)) {
|
|
822
|
+
throw new import_common7.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
|
|
823
|
+
}
|
|
824
|
+
const maxBytes = this.options.attachments?.maxBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES;
|
|
825
|
+
if (file.size > maxBytes) {
|
|
826
|
+
throw new import_common7.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
|
|
827
|
+
}
|
|
828
|
+
const actor = await this.actorResolver.resolve(req);
|
|
829
|
+
return this.staging.stage({
|
|
830
|
+
data: file.buffer,
|
|
831
|
+
filename: file.originalname,
|
|
832
|
+
contentType: file.mimetype,
|
|
833
|
+
sizeBytes: file.size,
|
|
834
|
+
actor
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
_ts_decorate7([
|
|
839
|
+
(0, import_common7.Post)(),
|
|
840
|
+
(0, import_common7.UseInterceptors)((0, import_platform_express.FileInterceptor)("file")),
|
|
841
|
+
_ts_param5(0, (0, import_common7.Req)()),
|
|
842
|
+
_ts_param5(1, (0, import_common7.UploadedFile)()),
|
|
843
|
+
_ts_metadata6("design:type", Function),
|
|
844
|
+
_ts_metadata6("design:paramtypes", [
|
|
845
|
+
typeof Request === "undefined" ? Object : Request,
|
|
846
|
+
Object
|
|
847
|
+
]),
|
|
848
|
+
_ts_metadata6("design:returntype", Promise)
|
|
849
|
+
], AttachmentsController.prototype, "upload", null);
|
|
850
|
+
AttachmentsController = _ts_decorate7([
|
|
851
|
+
(0, import_common7.Controller)("attachments"),
|
|
852
|
+
_ts_param5(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
|
|
853
|
+
_ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
|
|
854
|
+
_ts_param5(2, (0, import_common7.Optional)()),
|
|
855
|
+
_ts_param5(2, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
|
|
856
|
+
_ts_metadata6("design:type", Function),
|
|
857
|
+
_ts_metadata6("design:paramtypes", [
|
|
858
|
+
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
859
|
+
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
860
|
+
Object
|
|
861
|
+
])
|
|
862
|
+
], AttachmentsController);
|
|
863
|
+
|
|
864
|
+
// src/controller/chat.controller.ts
|
|
865
|
+
var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
|
|
866
|
+
var import_common8 = require("@nestjs/common");
|
|
867
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
868
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
869
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
870
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
871
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
872
|
+
}
|
|
873
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
874
|
+
function _ts_metadata7(k, v) {
|
|
875
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
876
|
+
}
|
|
877
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
878
|
+
function _ts_param6(paramIndex, decorator) {
|
|
879
|
+
return function(target, key) {
|
|
880
|
+
decorator(target, key, paramIndex);
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
__name(_ts_param6, "_ts_param");
|
|
690
884
|
var ChatController = class {
|
|
691
885
|
static {
|
|
692
886
|
__name(this, "ChatController");
|
|
@@ -708,6 +902,9 @@ var ChatController = class {
|
|
|
708
902
|
...body.agent !== void 0 ? {
|
|
709
903
|
agentName: body.agent
|
|
710
904
|
} : {},
|
|
905
|
+
...body.attachments !== void 0 ? {
|
|
906
|
+
attachments: body.attachments
|
|
907
|
+
} : {},
|
|
711
908
|
...body.pageContext !== void 0 ? {
|
|
712
909
|
pageContext: body.pageContext
|
|
713
910
|
} : {},
|
|
@@ -746,17 +943,32 @@ data: ${JSON.stringify({
|
|
|
746
943
|
|
|
747
944
|
`);
|
|
748
945
|
const decoder = new TextDecoder();
|
|
946
|
+
let buffer = "";
|
|
749
947
|
try {
|
|
750
948
|
for await (const chunk of this.agent.subscribe(runId)) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
})
|
|
949
|
+
buffer += decoder.decode(chunk, {
|
|
950
|
+
stream: true
|
|
951
|
+
});
|
|
952
|
+
let newline = buffer.indexOf("\n");
|
|
953
|
+
while (newline !== -1) {
|
|
954
|
+
const line = buffer.slice(0, newline);
|
|
955
|
+
buffer = buffer.slice(newline + 1);
|
|
956
|
+
if (line.length > 0) {
|
|
957
|
+
res.write(`data: ${line}
|
|
958
|
+
|
|
959
|
+
`);
|
|
960
|
+
}
|
|
961
|
+
newline = buffer.indexOf("\n");
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
if (buffer.length > 0) {
|
|
965
|
+
res.write(`data: ${buffer}
|
|
754
966
|
|
|
755
967
|
`);
|
|
756
968
|
}
|
|
757
969
|
res.write("event: done\ndata: {}\n\n");
|
|
758
970
|
} catch (error) {
|
|
759
|
-
const payload = error instanceof
|
|
971
|
+
const payload = error instanceof import_nestjs_agent_core8.AgentStreamError ? {
|
|
760
972
|
code: error.code,
|
|
761
973
|
message: error.message
|
|
762
974
|
} : {
|
|
@@ -771,71 +983,71 @@ data: ${JSON.stringify(payload)}
|
|
|
771
983
|
res.end();
|
|
772
984
|
}
|
|
773
985
|
};
|
|
774
|
-
|
|
775
|
-
(0,
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
986
|
+
_ts_decorate8([
|
|
987
|
+
(0, import_common8.Post)("chat"),
|
|
988
|
+
_ts_param6(0, (0, import_common8.Req)()),
|
|
989
|
+
_ts_param6(1, (0, import_common8.Res)()),
|
|
990
|
+
_ts_param6(2, (0, import_common8.Body)()),
|
|
991
|
+
_ts_metadata7("design:type", Function),
|
|
992
|
+
_ts_metadata7("design:paramtypes", [
|
|
781
993
|
typeof Request === "undefined" ? Object : Request,
|
|
782
994
|
typeof Response === "undefined" ? Object : Response,
|
|
783
995
|
typeof ChatBody === "undefined" ? Object : ChatBody
|
|
784
996
|
]),
|
|
785
|
-
|
|
997
|
+
_ts_metadata7("design:returntype", Promise)
|
|
786
998
|
], ChatController.prototype, "chat", null);
|
|
787
|
-
|
|
788
|
-
(0,
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
999
|
+
_ts_decorate8([
|
|
1000
|
+
(0, import_common8.Get)("chat/:runId/stream"),
|
|
1001
|
+
_ts_param6(0, (0, import_common8.Param)("runId")),
|
|
1002
|
+
_ts_param6(1, (0, import_common8.Res)()),
|
|
1003
|
+
_ts_metadata7("design:type", Function),
|
|
1004
|
+
_ts_metadata7("design:paramtypes", [
|
|
793
1005
|
String,
|
|
794
1006
|
typeof Response === "undefined" ? Object : Response
|
|
795
1007
|
]),
|
|
796
|
-
|
|
1008
|
+
_ts_metadata7("design:returntype", Promise)
|
|
797
1009
|
], ChatController.prototype, "stream", null);
|
|
798
|
-
|
|
799
|
-
(0,
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
1010
|
+
_ts_decorate8([
|
|
1011
|
+
(0, import_common8.Post)("chat/:runId/cancel"),
|
|
1012
|
+
_ts_param6(0, (0, import_common8.Req)()),
|
|
1013
|
+
_ts_param6(1, (0, import_common8.Param)("runId")),
|
|
1014
|
+
_ts_metadata7("design:type", Function),
|
|
1015
|
+
_ts_metadata7("design:paramtypes", [
|
|
804
1016
|
typeof Request === "undefined" ? Object : Request,
|
|
805
1017
|
String
|
|
806
1018
|
]),
|
|
807
|
-
|
|
1019
|
+
_ts_metadata7("design:returntype", Promise)
|
|
808
1020
|
], ChatController.prototype, "cancel", null);
|
|
809
|
-
ChatController =
|
|
810
|
-
(0,
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
1021
|
+
ChatController = _ts_decorate8([
|
|
1022
|
+
(0, import_common8.Controller)(),
|
|
1023
|
+
_ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
|
|
1024
|
+
_ts_metadata7("design:type", Function),
|
|
1025
|
+
_ts_metadata7("design:paramtypes", [
|
|
814
1026
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
815
1027
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
816
1028
|
])
|
|
817
1029
|
], ChatController);
|
|
818
1030
|
|
|
819
1031
|
// src/controller/quota.controller.ts
|
|
820
|
-
var
|
|
821
|
-
var
|
|
822
|
-
function
|
|
1032
|
+
var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
|
|
1033
|
+
var import_common9 = require("@nestjs/common");
|
|
1034
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
823
1035
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
824
1036
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
825
1037
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
826
1038
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
827
1039
|
}
|
|
828
|
-
__name(
|
|
829
|
-
function
|
|
1040
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1041
|
+
function _ts_metadata8(k, v) {
|
|
830
1042
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
831
1043
|
}
|
|
832
|
-
__name(
|
|
833
|
-
function
|
|
1044
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1045
|
+
function _ts_param7(paramIndex, decorator) {
|
|
834
1046
|
return function(target, key) {
|
|
835
1047
|
decorator(target, key, paramIndex);
|
|
836
1048
|
};
|
|
837
1049
|
}
|
|
838
|
-
__name(
|
|
1050
|
+
__name(_ts_param7, "_ts_param");
|
|
839
1051
|
var QuotaController = class {
|
|
840
1052
|
static {
|
|
841
1053
|
__name(this, "QuotaController");
|
|
@@ -851,45 +1063,45 @@ var QuotaController = class {
|
|
|
851
1063
|
return this.agent.quotaToday(actor.id);
|
|
852
1064
|
}
|
|
853
1065
|
};
|
|
854
|
-
|
|
855
|
-
(0,
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1066
|
+
_ts_decorate9([
|
|
1067
|
+
(0, import_common9.Get)("today"),
|
|
1068
|
+
_ts_param7(0, (0, import_common9.Req)()),
|
|
1069
|
+
_ts_metadata8("design:type", Function),
|
|
1070
|
+
_ts_metadata8("design:paramtypes", [
|
|
859
1071
|
typeof Request === "undefined" ? Object : Request
|
|
860
1072
|
]),
|
|
861
|
-
|
|
1073
|
+
_ts_metadata8("design:returntype", Promise)
|
|
862
1074
|
], QuotaController.prototype, "today", null);
|
|
863
|
-
QuotaController =
|
|
864
|
-
(0,
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
1075
|
+
QuotaController = _ts_decorate9([
|
|
1076
|
+
(0, import_common9.Controller)("quota"),
|
|
1077
|
+
_ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
|
|
1078
|
+
_ts_metadata8("design:type", Function),
|
|
1079
|
+
_ts_metadata8("design:paramtypes", [
|
|
868
1080
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
869
1081
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
870
1082
|
])
|
|
871
1083
|
], QuotaController);
|
|
872
1084
|
|
|
873
1085
|
// src/controller/threads.controller.ts
|
|
874
|
-
var
|
|
875
|
-
var
|
|
876
|
-
function
|
|
1086
|
+
var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
|
|
1087
|
+
var import_common10 = require("@nestjs/common");
|
|
1088
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
877
1089
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
878
1090
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
879
1091
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
880
1092
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
881
1093
|
}
|
|
882
|
-
__name(
|
|
883
|
-
function
|
|
1094
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1095
|
+
function _ts_metadata9(k, v) {
|
|
884
1096
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
885
1097
|
}
|
|
886
|
-
__name(
|
|
887
|
-
function
|
|
1098
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1099
|
+
function _ts_param8(paramIndex, decorator) {
|
|
888
1100
|
return function(target, key) {
|
|
889
1101
|
decorator(target, key, paramIndex);
|
|
890
1102
|
};
|
|
891
1103
|
}
|
|
892
|
-
__name(
|
|
1104
|
+
__name(_ts_param8, "_ts_param");
|
|
893
1105
|
var ThreadsController = class {
|
|
894
1106
|
static {
|
|
895
1107
|
__name(this, "ThreadsController");
|
|
@@ -919,9 +1131,21 @@ var ThreadsController = class {
|
|
|
919
1131
|
const actor = await this.actorResolver.resolve(req);
|
|
920
1132
|
return this.agent.forkThread(actor, id, messageId);
|
|
921
1133
|
}
|
|
922
|
-
|
|
1134
|
+
/**
|
|
1135
|
+
* Renames the thread and/or sets its default agent. `defaultAgent` is only present in the request
|
|
1136
|
+
* body when the client actually sent the key (JSON has no `undefined`), so `'defaultAgent' in body`
|
|
1137
|
+
* distinguishes "leave it alone" from "set it to null" (clear it) unambiguously.
|
|
1138
|
+
*/
|
|
1139
|
+
async update(req, id, body) {
|
|
923
1140
|
const actor = await this.actorResolver.resolve(req);
|
|
924
|
-
await this.agent.
|
|
1141
|
+
await this.agent.updateThread(actor, id, {
|
|
1142
|
+
...body.title !== void 0 ? {
|
|
1143
|
+
title: body.title
|
|
1144
|
+
} : {},
|
|
1145
|
+
..."defaultAgent" in body ? {
|
|
1146
|
+
defaultAgent: body.defaultAgent ?? null
|
|
1147
|
+
} : {}
|
|
1148
|
+
});
|
|
925
1149
|
return {
|
|
926
1150
|
ok: true
|
|
927
1151
|
};
|
|
@@ -941,117 +1165,117 @@ var ThreadsController = class {
|
|
|
941
1165
|
};
|
|
942
1166
|
}
|
|
943
1167
|
};
|
|
944
|
-
|
|
945
|
-
(0,
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1168
|
+
_ts_decorate10([
|
|
1169
|
+
(0, import_common10.Get)(),
|
|
1170
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1171
|
+
_ts_metadata9("design:type", Function),
|
|
1172
|
+
_ts_metadata9("design:paramtypes", [
|
|
949
1173
|
typeof Request === "undefined" ? Object : Request
|
|
950
1174
|
]),
|
|
951
|
-
|
|
1175
|
+
_ts_metadata9("design:returntype", Promise)
|
|
952
1176
|
], ThreadsController.prototype, "list", null);
|
|
953
|
-
|
|
954
|
-
(0,
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1177
|
+
_ts_decorate10([
|
|
1178
|
+
(0, import_common10.Get)(":id"),
|
|
1179
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1180
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1181
|
+
_ts_metadata9("design:type", Function),
|
|
1182
|
+
_ts_metadata9("design:paramtypes", [
|
|
959
1183
|
typeof Request === "undefined" ? Object : Request,
|
|
960
1184
|
String
|
|
961
1185
|
]),
|
|
962
|
-
|
|
1186
|
+
_ts_metadata9("design:returntype", Promise)
|
|
963
1187
|
], ThreadsController.prototype, "detail", null);
|
|
964
|
-
|
|
965
|
-
(0,
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1188
|
+
_ts_decorate10([
|
|
1189
|
+
(0, import_common10.Delete)(":id"),
|
|
1190
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1191
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1192
|
+
_ts_metadata9("design:type", Function),
|
|
1193
|
+
_ts_metadata9("design:paramtypes", [
|
|
970
1194
|
typeof Request === "undefined" ? Object : Request,
|
|
971
1195
|
String
|
|
972
1196
|
]),
|
|
973
|
-
|
|
1197
|
+
_ts_metadata9("design:returntype", Promise)
|
|
974
1198
|
], ThreadsController.prototype, "remove", null);
|
|
975
|
-
|
|
976
|
-
(0,
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1199
|
+
_ts_decorate10([
|
|
1200
|
+
(0, import_common10.Post)(":id/fork-from/:messageId"),
|
|
1201
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1202
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1203
|
+
_ts_param8(2, (0, import_common10.Param)("messageId")),
|
|
1204
|
+
_ts_metadata9("design:type", Function),
|
|
1205
|
+
_ts_metadata9("design:paramtypes", [
|
|
982
1206
|
typeof Request === "undefined" ? Object : Request,
|
|
983
1207
|
String,
|
|
984
1208
|
String
|
|
985
1209
|
]),
|
|
986
|
-
|
|
1210
|
+
_ts_metadata9("design:returntype", Promise)
|
|
987
1211
|
], ThreadsController.prototype, "fork", null);
|
|
988
|
-
|
|
989
|
-
(0,
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1212
|
+
_ts_decorate10([
|
|
1213
|
+
(0, import_common10.Patch)(":id"),
|
|
1214
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1215
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1216
|
+
_ts_param8(2, (0, import_common10.Body)()),
|
|
1217
|
+
_ts_metadata9("design:type", Function),
|
|
1218
|
+
_ts_metadata9("design:paramtypes", [
|
|
995
1219
|
typeof Request === "undefined" ? Object : Request,
|
|
996
1220
|
String,
|
|
997
|
-
typeof
|
|
1221
|
+
typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
|
|
998
1222
|
]),
|
|
999
|
-
|
|
1000
|
-
], ThreadsController.prototype, "
|
|
1001
|
-
|
|
1002
|
-
(0,
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1223
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1224
|
+
], ThreadsController.prototype, "update", null);
|
|
1225
|
+
_ts_decorate10([
|
|
1226
|
+
(0, import_common10.Post)(":id/promote"),
|
|
1227
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1228
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1229
|
+
_ts_metadata9("design:type", Function),
|
|
1230
|
+
_ts_metadata9("design:paramtypes", [
|
|
1007
1231
|
typeof Request === "undefined" ? Object : Request,
|
|
1008
1232
|
String
|
|
1009
1233
|
]),
|
|
1010
|
-
|
|
1234
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1011
1235
|
], ThreadsController.prototype, "promote", null);
|
|
1012
|
-
|
|
1013
|
-
(0,
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1236
|
+
_ts_decorate10([
|
|
1237
|
+
(0, import_common10.Delete)(":id/from/:messageId"),
|
|
1238
|
+
_ts_param8(0, (0, import_common10.Req)()),
|
|
1239
|
+
_ts_param8(1, (0, import_common10.Param)("id")),
|
|
1240
|
+
_ts_param8(2, (0, import_common10.Param)("messageId")),
|
|
1241
|
+
_ts_metadata9("design:type", Function),
|
|
1242
|
+
_ts_metadata9("design:paramtypes", [
|
|
1019
1243
|
typeof Request === "undefined" ? Object : Request,
|
|
1020
1244
|
String,
|
|
1021
1245
|
String
|
|
1022
1246
|
]),
|
|
1023
|
-
|
|
1247
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1024
1248
|
], ThreadsController.prototype, "truncateFrom", null);
|
|
1025
|
-
ThreadsController =
|
|
1026
|
-
(0,
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1249
|
+
ThreadsController = _ts_decorate10([
|
|
1250
|
+
(0, import_common10.Controller)("threads"),
|
|
1251
|
+
_ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
|
|
1252
|
+
_ts_metadata9("design:type", Function),
|
|
1253
|
+
_ts_metadata9("design:paramtypes", [
|
|
1030
1254
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
1031
1255
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
1032
1256
|
])
|
|
1033
1257
|
], ThreadsController);
|
|
1034
1258
|
|
|
1035
1259
|
// src/controller/tool-call.controller.ts
|
|
1036
|
-
var
|
|
1037
|
-
var
|
|
1038
|
-
function
|
|
1260
|
+
var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
|
|
1261
|
+
var import_common11 = require("@nestjs/common");
|
|
1262
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1039
1263
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1040
1264
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1041
1265
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1042
1266
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1043
1267
|
}
|
|
1044
|
-
__name(
|
|
1045
|
-
function
|
|
1268
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1269
|
+
function _ts_metadata10(k, v) {
|
|
1046
1270
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1047
1271
|
}
|
|
1048
|
-
__name(
|
|
1049
|
-
function
|
|
1272
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1273
|
+
function _ts_param9(paramIndex, decorator) {
|
|
1050
1274
|
return function(target, key) {
|
|
1051
1275
|
decorator(target, key, paramIndex);
|
|
1052
1276
|
};
|
|
1053
1277
|
}
|
|
1054
|
-
__name(
|
|
1278
|
+
__name(_ts_param9, "_ts_param");
|
|
1055
1279
|
var ToolCallController = class {
|
|
1056
1280
|
static {
|
|
1057
1281
|
__name(this, "ToolCallController");
|
|
@@ -1077,41 +1301,41 @@ var ToolCallController = class {
|
|
|
1077
1301
|
};
|
|
1078
1302
|
}
|
|
1079
1303
|
};
|
|
1080
|
-
|
|
1081
|
-
(0,
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1304
|
+
_ts_decorate11([
|
|
1305
|
+
(0, import_common11.Post)("approve"),
|
|
1306
|
+
_ts_param9(0, (0, import_common11.Req)()),
|
|
1307
|
+
_ts_param9(1, (0, import_common11.Body)()),
|
|
1308
|
+
_ts_metadata10("design:type", Function),
|
|
1309
|
+
_ts_metadata10("design:paramtypes", [
|
|
1086
1310
|
typeof Request === "undefined" ? Object : Request,
|
|
1087
1311
|
typeof ApproveBody === "undefined" ? Object : ApproveBody
|
|
1088
1312
|
]),
|
|
1089
|
-
|
|
1313
|
+
_ts_metadata10("design:returntype", Promise)
|
|
1090
1314
|
], ToolCallController.prototype, "approve", null);
|
|
1091
|
-
|
|
1092
|
-
(0,
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1315
|
+
_ts_decorate11([
|
|
1316
|
+
(0, import_common11.Post)("reject"),
|
|
1317
|
+
_ts_param9(0, (0, import_common11.Req)()),
|
|
1318
|
+
_ts_param9(1, (0, import_common11.Body)()),
|
|
1319
|
+
_ts_metadata10("design:type", Function),
|
|
1320
|
+
_ts_metadata10("design:paramtypes", [
|
|
1097
1321
|
typeof Request === "undefined" ? Object : Request,
|
|
1098
1322
|
typeof RejectBody === "undefined" ? Object : RejectBody
|
|
1099
1323
|
]),
|
|
1100
|
-
|
|
1324
|
+
_ts_metadata10("design:returntype", Promise)
|
|
1101
1325
|
], ToolCallController.prototype, "reject", null);
|
|
1102
|
-
ToolCallController =
|
|
1103
|
-
(0,
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1326
|
+
ToolCallController = _ts_decorate11([
|
|
1327
|
+
(0, import_common11.Controller)("tool-call"),
|
|
1328
|
+
_ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
|
|
1329
|
+
_ts_metadata10("design:type", Function),
|
|
1330
|
+
_ts_metadata10("design:paramtypes", [
|
|
1107
1331
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
1108
1332
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
1109
1333
|
])
|
|
1110
1334
|
], ToolCallController);
|
|
1111
1335
|
|
|
1112
1336
|
// src/discovery/agent-discovery.service.ts
|
|
1113
|
-
var
|
|
1114
|
-
var
|
|
1337
|
+
var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
|
|
1338
|
+
var import_common12 = require("@nestjs/common");
|
|
1115
1339
|
var import_core = require("@nestjs/core");
|
|
1116
1340
|
|
|
1117
1341
|
// src/decorator/agent.decorator.ts
|
|
@@ -1128,23 +1352,23 @@ var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
|
|
|
1128
1352
|
var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
|
|
1129
1353
|
|
|
1130
1354
|
// src/discovery/agent-discovery.service.ts
|
|
1131
|
-
function
|
|
1355
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
1132
1356
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1133
1357
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1134
1358
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1135
1359
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1136
1360
|
}
|
|
1137
|
-
__name(
|
|
1138
|
-
function
|
|
1361
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1362
|
+
function _ts_metadata11(k, v) {
|
|
1139
1363
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1140
1364
|
}
|
|
1141
|
-
__name(
|
|
1142
|
-
function
|
|
1365
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1366
|
+
function _ts_param10(paramIndex, decorator) {
|
|
1143
1367
|
return function(target, key) {
|
|
1144
1368
|
decorator(target, key, paramIndex);
|
|
1145
1369
|
};
|
|
1146
1370
|
}
|
|
1147
|
-
__name(
|
|
1371
|
+
__name(_ts_param10, "_ts_param");
|
|
1148
1372
|
var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
1149
1373
|
static {
|
|
1150
1374
|
__name(this, "AgentDiscoveryService");
|
|
@@ -1153,7 +1377,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
1153
1377
|
scanner;
|
|
1154
1378
|
registry;
|
|
1155
1379
|
contributors;
|
|
1156
|
-
logger = new
|
|
1380
|
+
logger = new import_common12.Logger(_AgentDiscoveryService.name);
|
|
1157
1381
|
constructor(discovery, scanner, registry, contributors) {
|
|
1158
1382
|
this.discovery = discovery;
|
|
1159
1383
|
this.scanner = scanner;
|
|
@@ -1241,22 +1465,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
1241
1465
|
return (ctx) => candidate.call(instance, ctx);
|
|
1242
1466
|
}
|
|
1243
1467
|
};
|
|
1244
|
-
AgentDiscoveryService =
|
|
1245
|
-
(0,
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1468
|
+
AgentDiscoveryService = _ts_decorate12([
|
|
1469
|
+
(0, import_common12.Injectable)(),
|
|
1470
|
+
_ts_param10(2, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_REGISTRY)),
|
|
1471
|
+
_ts_param10(3, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_PROMPT_CONTRIBUTORS)),
|
|
1472
|
+
_ts_metadata11("design:type", Function),
|
|
1473
|
+
_ts_metadata11("design:paramtypes", [
|
|
1250
1474
|
typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
|
|
1251
1475
|
typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
|
|
1252
|
-
typeof
|
|
1476
|
+
typeof import_nestjs_agent_core12.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core12.AgentRegistry,
|
|
1253
1477
|
Array
|
|
1254
1478
|
])
|
|
1255
1479
|
], AgentDiscoveryService);
|
|
1256
1480
|
|
|
1257
1481
|
// src/discovery/ai-tool-discovery.service.ts
|
|
1258
|
-
var
|
|
1259
|
-
var
|
|
1482
|
+
var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
|
|
1483
|
+
var import_common13 = require("@nestjs/common");
|
|
1260
1484
|
var import_core2 = require("@nestjs/core");
|
|
1261
1485
|
var import_zod = require("zod");
|
|
1262
1486
|
|
|
@@ -1276,23 +1500,23 @@ function isBrandedFunctionalTool(value) {
|
|
|
1276
1500
|
__name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
|
|
1277
1501
|
|
|
1278
1502
|
// src/discovery/ai-tool-discovery.service.ts
|
|
1279
|
-
function
|
|
1503
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
1280
1504
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1281
1505
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1282
1506
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1283
1507
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1284
1508
|
}
|
|
1285
|
-
__name(
|
|
1286
|
-
function
|
|
1509
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1510
|
+
function _ts_metadata12(k, v) {
|
|
1287
1511
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1288
1512
|
}
|
|
1289
|
-
__name(
|
|
1290
|
-
function
|
|
1513
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1514
|
+
function _ts_param11(paramIndex, decorator) {
|
|
1291
1515
|
return function(target, key) {
|
|
1292
1516
|
decorator(target, key, paramIndex);
|
|
1293
1517
|
};
|
|
1294
1518
|
}
|
|
1295
|
-
__name(
|
|
1519
|
+
__name(_ts_param11, "_ts_param");
|
|
1296
1520
|
var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
1297
1521
|
static {
|
|
1298
1522
|
__name(this, "AiToolDiscoveryService");
|
|
@@ -1301,7 +1525,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
1301
1525
|
registry;
|
|
1302
1526
|
agents;
|
|
1303
1527
|
options;
|
|
1304
|
-
logger = new
|
|
1528
|
+
logger = new import_common13.Logger(_AiToolDiscoveryService.name);
|
|
1305
1529
|
constructor(discovery, registry, agents, options) {
|
|
1306
1530
|
this.discovery = discovery;
|
|
1307
1531
|
this.registry = registry;
|
|
@@ -1399,13 +1623,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
1399
1623
|
return true;
|
|
1400
1624
|
}
|
|
1401
1625
|
};
|
|
1402
|
-
AiToolDiscoveryService =
|
|
1403
|
-
(0,
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1626
|
+
AiToolDiscoveryService = _ts_decorate13([
|
|
1627
|
+
(0, import_common13.Injectable)(),
|
|
1628
|
+
_ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_TOOL_REGISTRY)),
|
|
1629
|
+
_ts_param11(2, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_REGISTRY)),
|
|
1630
|
+
_ts_param11(3, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
|
|
1631
|
+
_ts_metadata12("design:type", Function),
|
|
1632
|
+
_ts_metadata12("design:paramtypes", [
|
|
1409
1633
|
typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
|
|
1410
1634
|
typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
|
|
1411
1635
|
typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
|
|
@@ -1414,7 +1638,7 @@ AiToolDiscoveryService = _ts_decorate12([
|
|
|
1414
1638
|
], AiToolDiscoveryService);
|
|
1415
1639
|
|
|
1416
1640
|
// src/in-process-sink.ts
|
|
1417
|
-
var
|
|
1641
|
+
var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
|
|
1418
1642
|
var InProcessTokenStreamSink = class {
|
|
1419
1643
|
static {
|
|
1420
1644
|
__name(this, "InProcessTokenStreamSink");
|
|
@@ -1469,7 +1693,7 @@ var InProcessTokenStreamSink = class {
|
|
|
1469
1693
|
}
|
|
1470
1694
|
if (buf.ended) {
|
|
1471
1695
|
if (buf.failure !== void 0) {
|
|
1472
|
-
throw new
|
|
1696
|
+
throw new import_nestjs_agent_core14.AgentStreamError(buf.failure);
|
|
1473
1697
|
}
|
|
1474
1698
|
return;
|
|
1475
1699
|
}
|
|
@@ -1505,32 +1729,32 @@ var LedgerQuotaStore = class {
|
|
|
1505
1729
|
};
|
|
1506
1730
|
|
|
1507
1731
|
// src/runner/inline-agent-runner.ts
|
|
1508
|
-
var
|
|
1509
|
-
var
|
|
1510
|
-
function
|
|
1732
|
+
var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
|
|
1733
|
+
var import_common14 = require("@nestjs/common");
|
|
1734
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
1511
1735
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1512
1736
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1513
1737
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1514
1738
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1515
1739
|
}
|
|
1516
|
-
__name(
|
|
1517
|
-
function
|
|
1740
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1741
|
+
function _ts_metadata13(k, v) {
|
|
1518
1742
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1519
1743
|
}
|
|
1520
|
-
__name(
|
|
1521
|
-
function
|
|
1744
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1745
|
+
function _ts_param12(paramIndex, decorator) {
|
|
1522
1746
|
return function(target, key) {
|
|
1523
1747
|
decorator(target, key, paramIndex);
|
|
1524
1748
|
};
|
|
1525
1749
|
}
|
|
1526
|
-
__name(
|
|
1750
|
+
__name(_ts_param12, "_ts_param");
|
|
1527
1751
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
1528
1752
|
static {
|
|
1529
1753
|
__name(this, "InlineAgentRunner");
|
|
1530
1754
|
}
|
|
1531
1755
|
factory;
|
|
1532
1756
|
store;
|
|
1533
|
-
logger = new
|
|
1757
|
+
logger = new import_common14.Logger(_InlineAgentRunner.name);
|
|
1534
1758
|
pending = /* @__PURE__ */ new Map();
|
|
1535
1759
|
constructor(factory, store) {
|
|
1536
1760
|
this.factory = factory;
|
|
@@ -1541,18 +1765,19 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1541
1765
|
const day = input.day ?? utcDay();
|
|
1542
1766
|
const deps = this.factory.forAgent(input.agentName);
|
|
1543
1767
|
const hooks = this.topLevelHooks(runId, deps, input.actor, day);
|
|
1544
|
-
void (0,
|
|
1768
|
+
void (0, import_nestjs_agent_core15.runAgentLoop)({
|
|
1545
1769
|
...deps,
|
|
1546
1770
|
day
|
|
1547
|
-
}, input, hooks).catch(async (error) => {
|
|
1771
|
+
}, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
|
|
1548
1772
|
const message = error instanceof Error ? error.message : String(error);
|
|
1549
|
-
const code = error instanceof
|
|
1773
|
+
const code = error instanceof import_nestjs_agent_core15.QuotaExceededError ? "quota_exceeded" : "run_failed";
|
|
1550
1774
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
1551
|
-
(0,
|
|
1775
|
+
(0, import_nestjs_agent_core15.publishAgentRunFailed)({
|
|
1552
1776
|
runId,
|
|
1553
1777
|
code,
|
|
1554
1778
|
message
|
|
1555
1779
|
});
|
|
1780
|
+
await this.store.setActiveStream(input.threadId, null);
|
|
1556
1781
|
const writer = await deps.sink.open(runId);
|
|
1557
1782
|
await writer.fail({
|
|
1558
1783
|
code,
|
|
@@ -1610,98 +1835,102 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1610
1835
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
1611
1836
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested(childName, childTask, actor, day, depth + 1, sinkRunId), "runAgent")
|
|
1612
1837
|
};
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1838
|
+
try {
|
|
1839
|
+
return await (0, import_nestjs_agent_core15.runAgentLoop)({
|
|
1840
|
+
...deps,
|
|
1841
|
+
day
|
|
1842
|
+
}, {
|
|
1843
|
+
threadId: subThread.id,
|
|
1844
|
+
actor,
|
|
1845
|
+
userText: task,
|
|
1846
|
+
agentName,
|
|
1847
|
+
day,
|
|
1848
|
+
delegationDepth: depth,
|
|
1849
|
+
sinkRunId
|
|
1850
|
+
}, hooks);
|
|
1851
|
+
} finally {
|
|
1852
|
+
await this.store.setActiveStream(subThread.id, null);
|
|
1853
|
+
}
|
|
1625
1854
|
}
|
|
1626
1855
|
};
|
|
1627
|
-
InlineAgentRunner =
|
|
1628
|
-
(0,
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1856
|
+
InlineAgentRunner = _ts_decorate14([
|
|
1857
|
+
(0, import_common14.Injectable)(),
|
|
1858
|
+
_ts_param12(0, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_DEPS_FACTORY)),
|
|
1859
|
+
_ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_STORE)),
|
|
1860
|
+
_ts_metadata13("design:type", Function),
|
|
1861
|
+
_ts_metadata13("design:paramtypes", [
|
|
1633
1862
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
1634
1863
|
typeof AgentStore === "undefined" ? Object : AgentStore
|
|
1635
1864
|
])
|
|
1636
1865
|
], InlineAgentRunner);
|
|
1637
1866
|
|
|
1638
1867
|
// src/agent.module.ts
|
|
1639
|
-
function
|
|
1868
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
1640
1869
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1641
1870
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1642
1871
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1643
1872
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1644
1873
|
}
|
|
1645
|
-
__name(
|
|
1874
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1646
1875
|
var DEFAULT_PATH = "agent";
|
|
1647
1876
|
function sharedProviders(durable, includeStore) {
|
|
1648
1877
|
const providers = [
|
|
1649
1878
|
{
|
|
1650
|
-
provide:
|
|
1651
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
1879
|
+
provide: import_nestjs_agent_core16.AGENT_TOOL_REGISTRY,
|
|
1880
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core16.ToolRegistry(), "useFactory")
|
|
1652
1881
|
},
|
|
1653
1882
|
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
1654
1883
|
{
|
|
1655
|
-
provide:
|
|
1656
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
1884
|
+
provide: import_nestjs_agent_core16.AGENT_REGISTRY,
|
|
1885
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core16.AgentRegistry(), "useFactory")
|
|
1657
1886
|
},
|
|
1658
1887
|
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
1659
1888
|
{
|
|
1660
|
-
provide:
|
|
1889
|
+
provide: import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS,
|
|
1661
1890
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
1662
1891
|
},
|
|
1663
1892
|
{
|
|
1664
|
-
provide:
|
|
1893
|
+
provide: import_nestjs_agent_core16.AGENT_SINK,
|
|
1665
1894
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
1666
1895
|
inject: [
|
|
1667
|
-
|
|
1896
|
+
import_nestjs_agent_core16.AGENT_OPTIONS
|
|
1668
1897
|
]
|
|
1669
1898
|
},
|
|
1670
1899
|
{
|
|
1671
|
-
provide:
|
|
1672
|
-
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new
|
|
1900
|
+
provide: import_nestjs_agent_core16.AGENT_ROLES_POLICY,
|
|
1901
|
+
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core16.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
|
|
1673
1902
|
inject: [
|
|
1674
|
-
|
|
1903
|
+
import_nestjs_agent_core16.AGENT_OPTIONS
|
|
1675
1904
|
]
|
|
1676
1905
|
},
|
|
1677
1906
|
{
|
|
1678
|
-
provide:
|
|
1907
|
+
provide: import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER,
|
|
1679
1908
|
useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
|
|
1680
1909
|
inject: [
|
|
1681
|
-
|
|
1910
|
+
import_nestjs_agent_core16.AGENT_OPTIONS
|
|
1682
1911
|
]
|
|
1683
1912
|
},
|
|
1684
1913
|
{
|
|
1685
|
-
provide:
|
|
1914
|
+
provide: import_nestjs_agent_core16.AGENT_MODEL,
|
|
1686
1915
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
1687
1916
|
inject: [
|
|
1688
|
-
|
|
1917
|
+
import_nestjs_agent_core16.AGENT_OPTIONS
|
|
1689
1918
|
]
|
|
1690
1919
|
},
|
|
1691
1920
|
{
|
|
1692
1921
|
// An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
|
|
1693
1922
|
// store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
|
|
1694
1923
|
// the loop already writes, so enforcement needs no extra shared state across replicas.
|
|
1695
|
-
provide:
|
|
1924
|
+
provide: import_nestjs_agent_core16.AGENT_QUOTA_STORE,
|
|
1696
1925
|
useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
|
|
1697
1926
|
inject: [
|
|
1698
|
-
|
|
1699
|
-
|
|
1927
|
+
import_nestjs_agent_core16.AGENT_OPTIONS,
|
|
1928
|
+
import_nestjs_agent_core16.AGENT_STORE
|
|
1700
1929
|
]
|
|
1701
1930
|
},
|
|
1702
1931
|
AgentDepsFactory2,
|
|
1703
1932
|
{
|
|
1704
|
-
provide:
|
|
1933
|
+
provide: import_nestjs_agent_core16.AGENT_DEPS_FACTORY,
|
|
1705
1934
|
useExisting: AgentDepsFactory2
|
|
1706
1935
|
},
|
|
1707
1936
|
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
@@ -1713,16 +1942,16 @@ function sharedProviders(durable, includeStore) {
|
|
|
1713
1942
|
];
|
|
1714
1943
|
if (includeStore) {
|
|
1715
1944
|
providers.push({
|
|
1716
|
-
provide:
|
|
1945
|
+
provide: import_nestjs_agent_core16.AGENT_STORE,
|
|
1717
1946
|
useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
|
|
1718
1947
|
inject: [
|
|
1719
|
-
|
|
1948
|
+
import_nestjs_agent_core16.AGENT_OPTIONS
|
|
1720
1949
|
]
|
|
1721
1950
|
});
|
|
1722
1951
|
}
|
|
1723
1952
|
if (durable) {
|
|
1724
1953
|
providers.push({
|
|
1725
|
-
provide:
|
|
1954
|
+
provide: import_nestjs_agent_core16.AGENT_RUNNER,
|
|
1726
1955
|
useFactory: /* @__PURE__ */ __name((durableRunner) => {
|
|
1727
1956
|
if (durableRunner === void 0) {
|
|
1728
1957
|
throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
|
|
@@ -1731,14 +1960,14 @@ function sharedProviders(durable, includeStore) {
|
|
|
1731
1960
|
}, "useFactory"),
|
|
1732
1961
|
inject: [
|
|
1733
1962
|
{
|
|
1734
|
-
token:
|
|
1963
|
+
token: import_nestjs_agent_core16.AGENT_DURABLE_RUNNER,
|
|
1735
1964
|
optional: true
|
|
1736
1965
|
}
|
|
1737
1966
|
]
|
|
1738
1967
|
});
|
|
1739
1968
|
} else {
|
|
1740
1969
|
providers.push({
|
|
1741
|
-
provide:
|
|
1970
|
+
provide: import_nestjs_agent_core16.AGENT_RUNNER,
|
|
1742
1971
|
useExisting: InlineAgentRunner
|
|
1743
1972
|
});
|
|
1744
1973
|
}
|
|
@@ -1747,32 +1976,57 @@ function sharedProviders(durable, includeStore) {
|
|
|
1747
1976
|
__name(sharedProviders, "sharedProviders");
|
|
1748
1977
|
function exportsFor(includeStore) {
|
|
1749
1978
|
return [
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1979
|
+
import_nestjs_agent_core16.AGENT_OPTIONS,
|
|
1980
|
+
import_nestjs_agent_core16.AGENT_TOOL_REGISTRY,
|
|
1981
|
+
import_nestjs_agent_core16.AGENT_REGISTRY,
|
|
1982
|
+
import_nestjs_agent_core16.AGENT_SINK,
|
|
1983
|
+
import_nestjs_agent_core16.AGENT_ROLES_POLICY,
|
|
1984
|
+
import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER,
|
|
1985
|
+
import_nestjs_agent_core16.AGENT_MODEL,
|
|
1757
1986
|
...includeStore ? [
|
|
1758
|
-
|
|
1987
|
+
import_nestjs_agent_core16.AGENT_STORE
|
|
1759
1988
|
] : [],
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1989
|
+
import_nestjs_agent_core16.AGENT_QUOTA_STORE,
|
|
1990
|
+
import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS,
|
|
1991
|
+
import_nestjs_agent_core16.AGENT_DEPS_FACTORY,
|
|
1763
1992
|
AgentDepsFactory2,
|
|
1764
1993
|
AgentService,
|
|
1765
1994
|
InlineAgentRunner
|
|
1766
1995
|
];
|
|
1767
1996
|
}
|
|
1768
1997
|
__name(exportsFor, "exportsFor");
|
|
1769
|
-
var
|
|
1998
|
+
var BASE_CONTROLLERS = [
|
|
1770
1999
|
ChatController,
|
|
1771
2000
|
ThreadsController,
|
|
1772
2001
|
ToolCallController,
|
|
1773
2002
|
QuotaController,
|
|
1774
2003
|
AgentsController
|
|
1775
2004
|
];
|
|
2005
|
+
var GUARDABLE_CONTROLLERS = [
|
|
2006
|
+
...BASE_CONTROLLERS,
|
|
2007
|
+
AttachmentsController
|
|
2008
|
+
];
|
|
2009
|
+
function controllersFor(mountAttachments) {
|
|
2010
|
+
return mountAttachments ? [
|
|
2011
|
+
...BASE_CONTROLLERS,
|
|
2012
|
+
AttachmentsController
|
|
2013
|
+
] : BASE_CONTROLLERS;
|
|
2014
|
+
}
|
|
2015
|
+
__name(controllersFor, "controllersFor");
|
|
2016
|
+
var GUARDS_METADATA = "__guards__";
|
|
2017
|
+
function applyGuards(guards) {
|
|
2018
|
+
const resolved = guards ?? [];
|
|
2019
|
+
for (const controller of GUARDABLE_CONTROLLERS) {
|
|
2020
|
+
Reflect.defineMetadata(GUARDS_METADATA, resolved, controller);
|
|
2021
|
+
}
|
|
2022
|
+
}
|
|
2023
|
+
__name(applyGuards, "applyGuards");
|
|
2024
|
+
function guardProviders(guards) {
|
|
2025
|
+
return [
|
|
2026
|
+
...new Set(guards ?? [])
|
|
2027
|
+
];
|
|
2028
|
+
}
|
|
2029
|
+
__name(guardProviders, "guardProviders");
|
|
1776
2030
|
function routerFor(path) {
|
|
1777
2031
|
return import_core3.RouterModule.register([
|
|
1778
2032
|
{
|
|
@@ -1789,6 +2043,7 @@ var AgentModule = class _AgentModule {
|
|
|
1789
2043
|
static forRoot(options) {
|
|
1790
2044
|
const path = options.path ?? DEFAULT_PATH;
|
|
1791
2045
|
const includeStore = options.store !== void 0;
|
|
2046
|
+
applyGuards(options.guards);
|
|
1792
2047
|
return {
|
|
1793
2048
|
module: _AgentModule,
|
|
1794
2049
|
global: true,
|
|
@@ -1796,19 +2051,22 @@ var AgentModule = class _AgentModule {
|
|
|
1796
2051
|
import_core3.DiscoveryModule,
|
|
1797
2052
|
routerFor(path)
|
|
1798
2053
|
],
|
|
1799
|
-
controllers:
|
|
2054
|
+
controllers: controllersFor(options.attachments?.upload === true),
|
|
1800
2055
|
providers: [
|
|
1801
2056
|
{
|
|
1802
|
-
provide:
|
|
2057
|
+
provide: import_nestjs_agent_core16.AGENT_OPTIONS,
|
|
1803
2058
|
useValue: options
|
|
1804
2059
|
},
|
|
1805
|
-
...sharedProviders(options.durable ?? false, includeStore)
|
|
2060
|
+
...sharedProviders(options.durable ?? false, includeStore),
|
|
2061
|
+
...guardProviders(options.guards)
|
|
1806
2062
|
],
|
|
1807
2063
|
exports: exportsFor(includeStore)
|
|
1808
2064
|
};
|
|
1809
2065
|
}
|
|
1810
2066
|
static forRootAsync(options) {
|
|
1811
2067
|
const path = options.path ?? DEFAULT_PATH;
|
|
2068
|
+
const includeStore = options.externalStore !== true;
|
|
2069
|
+
applyGuards(options.guards);
|
|
1812
2070
|
return {
|
|
1813
2071
|
module: _AgentModule,
|
|
1814
2072
|
global: true,
|
|
@@ -1817,24 +2075,23 @@ var AgentModule = class _AgentModule {
|
|
|
1817
2075
|
routerFor(path),
|
|
1818
2076
|
...options.imports ?? []
|
|
1819
2077
|
],
|
|
1820
|
-
controllers:
|
|
2078
|
+
controllers: controllersFor(options.attachmentsUpload === true),
|
|
1821
2079
|
providers: [
|
|
1822
2080
|
{
|
|
1823
|
-
provide:
|
|
2081
|
+
provide: import_nestjs_agent_core16.AGENT_OPTIONS,
|
|
1824
2082
|
useFactory: options.useFactory,
|
|
1825
2083
|
inject: options.inject ?? []
|
|
1826
2084
|
},
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
...sharedProviders(options.durable ?? false, true)
|
|
2085
|
+
...sharedProviders(options.durable ?? false, includeStore),
|
|
2086
|
+
...guardProviders(options.guards)
|
|
1830
2087
|
],
|
|
1831
|
-
exports: exportsFor(
|
|
2088
|
+
exports: exportsFor(includeStore)
|
|
1832
2089
|
};
|
|
1833
2090
|
}
|
|
1834
2091
|
};
|
|
1835
|
-
AgentModule =
|
|
1836
|
-
(0,
|
|
1837
|
-
(0,
|
|
2092
|
+
AgentModule = _ts_decorate15([
|
|
2093
|
+
(0, import_common15.Global)(),
|
|
2094
|
+
(0, import_common15.Module)({})
|
|
1838
2095
|
], AgentModule);
|
|
1839
2096
|
|
|
1840
2097
|
// src/durable/agent-durable.ts
|