@dudousxd/nestjs-agent 0.3.3 → 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-D4KyREOv.d.cts → agent-deps.factory-BM_RB6br.d.cts} +54 -4
- package/dist/{agent-deps.factory-D4KyREOv.d.ts → agent-deps.factory-BM_RB6br.d.ts} +54 -4
- package/dist/durable/index.cjs +492 -264
- 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 +447 -219
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +494 -263
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -5
- package/dist/index.d.ts +51 -5
- package/dist/index.js +446 -218
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
package/dist/durable/index.js
CHANGED
|
@@ -84,10 +84,12 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
84
84
|
}, "runAgent")
|
|
85
85
|
};
|
|
86
86
|
try {
|
|
87
|
-
|
|
87
|
+
const result = await runAgentLoop({
|
|
88
88
|
...deps,
|
|
89
89
|
day
|
|
90
90
|
}, input, hooks);
|
|
91
|
+
await ctx.step("deactivate", () => this.store.setActiveStream(input.threadId, null));
|
|
92
|
+
return result;
|
|
91
93
|
} catch (error) {
|
|
92
94
|
if (error instanceof WorkflowSuspended || error instanceof ContinueAsNew) {
|
|
93
95
|
throw error;
|
|
@@ -99,6 +101,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
|
|
|
99
101
|
code,
|
|
100
102
|
message
|
|
101
103
|
});
|
|
104
|
+
await ctx.step("deactivate", () => this.store.setActiveStream(input.threadId, null));
|
|
102
105
|
const writer = await hooks.openSink();
|
|
103
106
|
await writer.fail({
|
|
104
107
|
code,
|
|
@@ -224,14 +227,14 @@ AgentDurableModule = _ts_decorate3([
|
|
|
224
227
|
], AgentDurableModule);
|
|
225
228
|
|
|
226
229
|
// src/agent.module.ts
|
|
227
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
230
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER6, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_DURABLE_RUNNER as AGENT_DURABLE_RUNNER2, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry5, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
228
231
|
import { Global as Global2, Module as Module2 } from "@nestjs/common";
|
|
229
232
|
import { DiscoveryModule, RouterModule } from "@nestjs/core";
|
|
230
233
|
|
|
231
234
|
// src/agent-deps.factory.ts
|
|
232
|
-
import { AGENT_MODEL, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE as AGENT_STORE2, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
|
|
235
|
+
import { AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_QUOTA_STORE, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_STORE as AGENT_STORE2, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2 } from "@dudousxd/nestjs-agent-core";
|
|
233
236
|
import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
|
|
234
|
-
import { Inject as Inject2, Injectable as Injectable3 } from "@nestjs/common";
|
|
237
|
+
import { Inject as Inject2, Injectable as Injectable3, Optional } from "@nestjs/common";
|
|
235
238
|
function _ts_decorate4(decorators, target, key, desc) {
|
|
236
239
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
237
240
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -266,7 +269,8 @@ var AgentDepsFactory2 = class {
|
|
|
266
269
|
agents;
|
|
267
270
|
promptContributors;
|
|
268
271
|
quota;
|
|
269
|
-
|
|
272
|
+
pricingStore;
|
|
273
|
+
constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, quota, pricingStore) {
|
|
270
274
|
this.options = options;
|
|
271
275
|
this.model = model;
|
|
272
276
|
this.store = store;
|
|
@@ -276,6 +280,7 @@ var AgentDepsFactory2 = class {
|
|
|
276
280
|
this.agents = agents;
|
|
277
281
|
this.promptContributors = promptContributors;
|
|
278
282
|
this.quota = quota;
|
|
283
|
+
this.pricingStore = pricingStore;
|
|
279
284
|
}
|
|
280
285
|
/**
|
|
281
286
|
* The agent a turn uses when the caller names none: the explicit `defaultAgent` option, else the
|
|
@@ -322,6 +327,9 @@ var AgentDepsFactory2 = class {
|
|
|
322
327
|
...this.quota !== void 0 ? {
|
|
323
328
|
quota: this.quota
|
|
324
329
|
} : {},
|
|
330
|
+
...this.pricingStore !== void 0 ? {
|
|
331
|
+
pricingStore: this.pricingStore
|
|
332
|
+
} : {},
|
|
325
333
|
...toolAllowList !== void 0 ? {
|
|
326
334
|
toolAllowList
|
|
327
335
|
} : {},
|
|
@@ -362,6 +370,8 @@ AgentDepsFactory2 = _ts_decorate4([
|
|
|
362
370
|
_ts_param2(6, Inject2(AGENT_REGISTRY)),
|
|
363
371
|
_ts_param2(7, Inject2(AGENT_PROMPT_CONTRIBUTORS)),
|
|
364
372
|
_ts_param2(8, Inject2(AGENT_QUOTA_STORE)),
|
|
373
|
+
_ts_param2(9, Optional()),
|
|
374
|
+
_ts_param2(9, Inject2(AGENT_PRICING_STORE)),
|
|
365
375
|
_ts_metadata3("design:type", Function),
|
|
366
376
|
_ts_metadata3("design:paramtypes", [
|
|
367
377
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -372,13 +382,14 @@ AgentDepsFactory2 = _ts_decorate4([
|
|
|
372
382
|
typeof ToolRegistry2 === "undefined" ? Object : ToolRegistry2,
|
|
373
383
|
typeof AgentRegistry2 === "undefined" ? Object : AgentRegistry2,
|
|
374
384
|
Array,
|
|
385
|
+
Object,
|
|
375
386
|
Object
|
|
376
387
|
])
|
|
377
388
|
], AgentDepsFactory2);
|
|
378
389
|
|
|
379
390
|
// src/agent.service.ts
|
|
380
391
|
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE3 } from "@dudousxd/nestjs-agent-core";
|
|
381
|
-
import { BadRequestException, ForbiddenException, Inject as Inject3, Injectable as Injectable4, NotFoundException } from "@nestjs/common";
|
|
392
|
+
import { BadRequestException, ForbiddenException, Inject as Inject3, Injectable as Injectable4, NotFoundException, NotImplementedException } from "@nestjs/common";
|
|
382
393
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
383
394
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
384
395
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -411,7 +422,7 @@ var AgentService = class {
|
|
|
411
422
|
this.quota = quota;
|
|
412
423
|
}
|
|
413
424
|
async chat(params) {
|
|
414
|
-
const agentName = params.agentName
|
|
425
|
+
const agentName = await this.resolveAgentName(params.agentName, params.threadId);
|
|
415
426
|
let threadId = params.threadId;
|
|
416
427
|
if (threadId === void 0) {
|
|
417
428
|
if (params.regenerate === true) {
|
|
@@ -472,12 +483,14 @@ var AgentService = class {
|
|
|
472
483
|
await this.assertOwnsActiveStream(actor, runId);
|
|
473
484
|
return this.runner.cancel(runId);
|
|
474
485
|
}
|
|
475
|
-
listThreads(actorRef) {
|
|
476
|
-
|
|
486
|
+
async listThreads(actorRef) {
|
|
487
|
+
const threads = await this.store.listThreads(actorRef);
|
|
488
|
+
return Promise.all(threads.map((thread) => this.toSummaryView(thread)));
|
|
477
489
|
}
|
|
478
490
|
async getThread(actor, threadId) {
|
|
479
491
|
await this.assertOwnsThread(actor, threadId);
|
|
480
|
-
|
|
492
|
+
const thread = await this.store.getThread(threadId);
|
|
493
|
+
return thread === null ? null : this.toDetailView(thread);
|
|
481
494
|
}
|
|
482
495
|
async deleteThread(actor, threadId) {
|
|
483
496
|
await this.assertOwnsThread(actor, threadId);
|
|
@@ -487,7 +500,38 @@ var AgentService = class {
|
|
|
487
500
|
await this.assertOwnsThread(actor, threadId);
|
|
488
501
|
return this.store.forkThread(threadId, fromMessageId);
|
|
489
502
|
}
|
|
503
|
+
/** Kept for source compatibility — a thin wrapper over the more general `updateThread`. */
|
|
490
504
|
async renameThread(actor, threadId, title) {
|
|
505
|
+
return this.updateThread(actor, threadId, {
|
|
506
|
+
title
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Rename a thread and/or set its default agent. Title-only patches work against ANY store (via
|
|
511
|
+
* the required `setTitle`); a `defaultAgent` change requires the bound store to implement the
|
|
512
|
+
* optional `updateThread` — 501 with a clear message when it doesn't, rather than silently
|
|
513
|
+
* dropping the field.
|
|
514
|
+
*/
|
|
515
|
+
async updateThread(actor, threadId, patch) {
|
|
516
|
+
const title = patch.title !== void 0 ? this.validateTitle(patch.title) : void 0;
|
|
517
|
+
await this.assertOwnsThread(actor, threadId);
|
|
518
|
+
if (patch.defaultAgent === void 0) {
|
|
519
|
+
if (title !== void 0) {
|
|
520
|
+
await this.store.setTitle(threadId, title);
|
|
521
|
+
}
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
if (this.store.updateThread === void 0) {
|
|
525
|
+
throw new NotImplementedException("Setting a thread's defaultAgent requires an AgentStore that implements updateThread(); the bound store does not support it.");
|
|
526
|
+
}
|
|
527
|
+
await this.store.updateThread(threadId, {
|
|
528
|
+
...title !== void 0 ? {
|
|
529
|
+
title
|
|
530
|
+
} : {},
|
|
531
|
+
defaultAgent: patch.defaultAgent
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
validateTitle(title) {
|
|
491
535
|
const trimmed = title.trim();
|
|
492
536
|
if (trimmed.length === 0) {
|
|
493
537
|
throw new BadRequestException("title must not be empty");
|
|
@@ -495,8 +539,41 @@ var AgentService = class {
|
|
|
495
539
|
if (trimmed.length > 200) {
|
|
496
540
|
throw new BadRequestException("title must be at most 200 characters");
|
|
497
541
|
}
|
|
498
|
-
|
|
499
|
-
|
|
542
|
+
return trimmed;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Agent-selection precedence for a `chat()` call with no explicit `agentName`: the thread's own
|
|
546
|
+
* `defaultAgent` (if the thread exists and one is set) wins over the module's configured default.
|
|
547
|
+
* Skips the thread lookup entirely when the caller already named an agent or there's no thread yet.
|
|
548
|
+
*/
|
|
549
|
+
async resolveAgentName(agentName, threadId) {
|
|
550
|
+
if (agentName !== void 0) {
|
|
551
|
+
return agentName;
|
|
552
|
+
}
|
|
553
|
+
if (threadId !== void 0) {
|
|
554
|
+
const thread = await this.store.getThread(threadId);
|
|
555
|
+
if (thread?.defaultAgent !== void 0 && thread.defaultAgent !== null) {
|
|
556
|
+
return thread.defaultAgent;
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return this.deps.defaultAgentName();
|
|
560
|
+
}
|
|
561
|
+
async toSummaryView(thread) {
|
|
562
|
+
return {
|
|
563
|
+
...thread,
|
|
564
|
+
defaultAgent: thread.defaultAgent ?? null,
|
|
565
|
+
activeRunId: await this.store.activeRunForThread?.(thread.id) ?? null
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
async toDetailView(thread) {
|
|
569
|
+
const summary = await this.toSummaryView(thread);
|
|
570
|
+
return {
|
|
571
|
+
...summary,
|
|
572
|
+
messages: thread.messages,
|
|
573
|
+
...thread.activeStreamId !== void 0 ? {
|
|
574
|
+
activeStreamId: thread.activeStreamId
|
|
575
|
+
} : {}
|
|
576
|
+
};
|
|
500
577
|
}
|
|
501
578
|
async promoteThread(actor, threadId) {
|
|
502
579
|
await this.assertOwnsThread(actor, threadId);
|
|
@@ -652,9 +729,10 @@ AgentsController = _ts_decorate6([
|
|
|
652
729
|
])
|
|
653
730
|
], AgentsController);
|
|
654
731
|
|
|
655
|
-
// src/controller/
|
|
656
|
-
import { AGENT_ACTOR_RESOLVER,
|
|
657
|
-
import {
|
|
732
|
+
// src/controller/attachments.controller.ts
|
|
733
|
+
import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING, AGENT_OPTIONS as AGENT_OPTIONS2 } from "@dudousxd/nestjs-agent-core";
|
|
734
|
+
import { BadRequestException as BadRequestException2, Controller as Controller2, Inject as Inject5, NotImplementedException as NotImplementedException2, Optional as Optional2, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
|
|
735
|
+
import { FileInterceptor } from "@nestjs/platform-express";
|
|
658
736
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
659
737
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
660
738
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -672,6 +750,110 @@ function _ts_param5(paramIndex, decorator) {
|
|
|
672
750
|
};
|
|
673
751
|
}
|
|
674
752
|
__name(_ts_param5, "_ts_param");
|
|
753
|
+
var DEFAULT_MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
|
|
754
|
+
var DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES = [
|
|
755
|
+
"image/png",
|
|
756
|
+
"image/jpeg",
|
|
757
|
+
"image/gif",
|
|
758
|
+
"image/webp",
|
|
759
|
+
"application/pdf",
|
|
760
|
+
"text/plain",
|
|
761
|
+
"text/csv"
|
|
762
|
+
];
|
|
763
|
+
var AttachmentsController = class {
|
|
764
|
+
static {
|
|
765
|
+
__name(this, "AttachmentsController");
|
|
766
|
+
}
|
|
767
|
+
options;
|
|
768
|
+
actorResolver;
|
|
769
|
+
staging;
|
|
770
|
+
constructor(options, actorResolver, staging) {
|
|
771
|
+
this.options = options;
|
|
772
|
+
this.actorResolver = actorResolver;
|
|
773
|
+
this.staging = staging;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* `attachments.upload: true` is what mounts this controller at all (see `agent.module.ts`), so by
|
|
777
|
+
* the time an instance exists the host clearly intends uploads to work. Fail boot loudly rather
|
|
778
|
+
* than mounting a controller that would 501 on every single request because nobody bound
|
|
779
|
+
* `AGENT_ATTACHMENT_STAGING`.
|
|
780
|
+
*/
|
|
781
|
+
onModuleInit() {
|
|
782
|
+
if (this.options.attachments?.upload === true && this.staging === void 0) {
|
|
783
|
+
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.");
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
async upload(req, file) {
|
|
787
|
+
if (this.staging === void 0) {
|
|
788
|
+
throw new NotImplementedException2("Attachment upload is not configured on this server.");
|
|
789
|
+
}
|
|
790
|
+
if (file === void 0) {
|
|
791
|
+
throw new BadRequestException2('multipart field "file" is required');
|
|
792
|
+
}
|
|
793
|
+
const allowedContentTypes = this.options.attachments?.allowedContentTypes ?? DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES;
|
|
794
|
+
if (!allowedContentTypes.includes(file.mimetype)) {
|
|
795
|
+
throw new UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
|
|
796
|
+
}
|
|
797
|
+
const maxBytes = this.options.attachments?.maxBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES;
|
|
798
|
+
if (file.size > maxBytes) {
|
|
799
|
+
throw new PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
|
|
800
|
+
}
|
|
801
|
+
const actor = await this.actorResolver.resolve(req);
|
|
802
|
+
return this.staging.stage({
|
|
803
|
+
data: file.buffer,
|
|
804
|
+
filename: file.originalname,
|
|
805
|
+
contentType: file.mimetype,
|
|
806
|
+
sizeBytes: file.size,
|
|
807
|
+
actor
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
_ts_decorate7([
|
|
812
|
+
Post(),
|
|
813
|
+
UseInterceptors(FileInterceptor("file")),
|
|
814
|
+
_ts_param5(0, Req()),
|
|
815
|
+
_ts_param5(1, UploadedFile()),
|
|
816
|
+
_ts_metadata6("design:type", Function),
|
|
817
|
+
_ts_metadata6("design:paramtypes", [
|
|
818
|
+
typeof Request === "undefined" ? Object : Request,
|
|
819
|
+
Object
|
|
820
|
+
]),
|
|
821
|
+
_ts_metadata6("design:returntype", Promise)
|
|
822
|
+
], AttachmentsController.prototype, "upload", null);
|
|
823
|
+
AttachmentsController = _ts_decorate7([
|
|
824
|
+
Controller2("attachments"),
|
|
825
|
+
_ts_param5(0, Inject5(AGENT_OPTIONS2)),
|
|
826
|
+
_ts_param5(1, Inject5(AGENT_ACTOR_RESOLVER)),
|
|
827
|
+
_ts_param5(2, Optional2()),
|
|
828
|
+
_ts_param5(2, Inject5(AGENT_ATTACHMENT_STAGING)),
|
|
829
|
+
_ts_metadata6("design:type", Function),
|
|
830
|
+
_ts_metadata6("design:paramtypes", [
|
|
831
|
+
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
832
|
+
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
833
|
+
Object
|
|
834
|
+
])
|
|
835
|
+
], AttachmentsController);
|
|
836
|
+
|
|
837
|
+
// src/controller/chat.controller.ts
|
|
838
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError } from "@dudousxd/nestjs-agent-core";
|
|
839
|
+
import { Body, Controller as Controller3, Get as Get2, Inject as Inject6, Param, Post as Post2, Req as Req2, Res } from "@nestjs/common";
|
|
840
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
841
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
842
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
843
|
+
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;
|
|
844
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
845
|
+
}
|
|
846
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
847
|
+
function _ts_metadata7(k, v) {
|
|
848
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
849
|
+
}
|
|
850
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
851
|
+
function _ts_param6(paramIndex, decorator) {
|
|
852
|
+
return function(target, key) {
|
|
853
|
+
decorator(target, key, paramIndex);
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
__name(_ts_param6, "_ts_param");
|
|
675
857
|
var ChatController = class {
|
|
676
858
|
static {
|
|
677
859
|
__name(this, "ChatController");
|
|
@@ -774,71 +956,71 @@ data: ${JSON.stringify(payload)}
|
|
|
774
956
|
res.end();
|
|
775
957
|
}
|
|
776
958
|
};
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
959
|
+
_ts_decorate8([
|
|
960
|
+
Post2("chat"),
|
|
961
|
+
_ts_param6(0, Req2()),
|
|
962
|
+
_ts_param6(1, Res()),
|
|
963
|
+
_ts_param6(2, Body()),
|
|
964
|
+
_ts_metadata7("design:type", Function),
|
|
965
|
+
_ts_metadata7("design:paramtypes", [
|
|
784
966
|
typeof Request === "undefined" ? Object : Request,
|
|
785
967
|
typeof Response === "undefined" ? Object : Response,
|
|
786
968
|
typeof ChatBody === "undefined" ? Object : ChatBody
|
|
787
969
|
]),
|
|
788
|
-
|
|
970
|
+
_ts_metadata7("design:returntype", Promise)
|
|
789
971
|
], ChatController.prototype, "chat", null);
|
|
790
|
-
|
|
972
|
+
_ts_decorate8([
|
|
791
973
|
Get2("chat/:runId/stream"),
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
974
|
+
_ts_param6(0, Param("runId")),
|
|
975
|
+
_ts_param6(1, Res()),
|
|
976
|
+
_ts_metadata7("design:type", Function),
|
|
977
|
+
_ts_metadata7("design:paramtypes", [
|
|
796
978
|
String,
|
|
797
979
|
typeof Response === "undefined" ? Object : Response
|
|
798
980
|
]),
|
|
799
|
-
|
|
981
|
+
_ts_metadata7("design:returntype", Promise)
|
|
800
982
|
], ChatController.prototype, "stream", null);
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
983
|
+
_ts_decorate8([
|
|
984
|
+
Post2("chat/:runId/cancel"),
|
|
985
|
+
_ts_param6(0, Req2()),
|
|
986
|
+
_ts_param6(1, Param("runId")),
|
|
987
|
+
_ts_metadata7("design:type", Function),
|
|
988
|
+
_ts_metadata7("design:paramtypes", [
|
|
807
989
|
typeof Request === "undefined" ? Object : Request,
|
|
808
990
|
String
|
|
809
991
|
]),
|
|
810
|
-
|
|
992
|
+
_ts_metadata7("design:returntype", Promise)
|
|
811
993
|
], ChatController.prototype, "cancel", null);
|
|
812
|
-
ChatController =
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
994
|
+
ChatController = _ts_decorate8([
|
|
995
|
+
Controller3(),
|
|
996
|
+
_ts_param6(1, Inject6(AGENT_ACTOR_RESOLVER2)),
|
|
997
|
+
_ts_metadata7("design:type", Function),
|
|
998
|
+
_ts_metadata7("design:paramtypes", [
|
|
817
999
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
818
1000
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
819
1001
|
])
|
|
820
1002
|
], ChatController);
|
|
821
1003
|
|
|
822
1004
|
// src/controller/quota.controller.ts
|
|
823
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
824
|
-
import { Controller as
|
|
825
|
-
function
|
|
1005
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3 } from "@dudousxd/nestjs-agent-core";
|
|
1006
|
+
import { Controller as Controller4, Get as Get3, Inject as Inject7, Req as Req3 } from "@nestjs/common";
|
|
1007
|
+
function _ts_decorate9(decorators, target, key, desc) {
|
|
826
1008
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
827
1009
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
828
1010
|
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;
|
|
829
1011
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
830
1012
|
}
|
|
831
|
-
__name(
|
|
832
|
-
function
|
|
1013
|
+
__name(_ts_decorate9, "_ts_decorate");
|
|
1014
|
+
function _ts_metadata8(k, v) {
|
|
833
1015
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
834
1016
|
}
|
|
835
|
-
__name(
|
|
836
|
-
function
|
|
1017
|
+
__name(_ts_metadata8, "_ts_metadata");
|
|
1018
|
+
function _ts_param7(paramIndex, decorator) {
|
|
837
1019
|
return function(target, key) {
|
|
838
1020
|
decorator(target, key, paramIndex);
|
|
839
1021
|
};
|
|
840
1022
|
}
|
|
841
|
-
__name(
|
|
1023
|
+
__name(_ts_param7, "_ts_param");
|
|
842
1024
|
var QuotaController = class {
|
|
843
1025
|
static {
|
|
844
1026
|
__name(this, "QuotaController");
|
|
@@ -854,45 +1036,45 @@ var QuotaController = class {
|
|
|
854
1036
|
return this.agent.quotaToday(actor.id);
|
|
855
1037
|
}
|
|
856
1038
|
};
|
|
857
|
-
|
|
1039
|
+
_ts_decorate9([
|
|
858
1040
|
Get3("today"),
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
1041
|
+
_ts_param7(0, Req3()),
|
|
1042
|
+
_ts_metadata8("design:type", Function),
|
|
1043
|
+
_ts_metadata8("design:paramtypes", [
|
|
862
1044
|
typeof Request === "undefined" ? Object : Request
|
|
863
1045
|
]),
|
|
864
|
-
|
|
1046
|
+
_ts_metadata8("design:returntype", Promise)
|
|
865
1047
|
], QuotaController.prototype, "today", null);
|
|
866
|
-
QuotaController =
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
1048
|
+
QuotaController = _ts_decorate9([
|
|
1049
|
+
Controller4("quota"),
|
|
1050
|
+
_ts_param7(1, Inject7(AGENT_ACTOR_RESOLVER3)),
|
|
1051
|
+
_ts_metadata8("design:type", Function),
|
|
1052
|
+
_ts_metadata8("design:paramtypes", [
|
|
871
1053
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
872
1054
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
873
1055
|
])
|
|
874
1056
|
], QuotaController);
|
|
875
1057
|
|
|
876
1058
|
// src/controller/threads.controller.ts
|
|
877
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
878
|
-
import { Body as Body2, Controller as
|
|
879
|
-
function
|
|
1059
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4 } from "@dudousxd/nestjs-agent-core";
|
|
1060
|
+
import { Body as Body2, Controller as Controller5, Delete, Get as Get4, Inject as Inject8, Param as Param2, Patch, Post as Post3, Req as Req4 } from "@nestjs/common";
|
|
1061
|
+
function _ts_decorate10(decorators, target, key, desc) {
|
|
880
1062
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
881
1063
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
882
1064
|
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;
|
|
883
1065
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
884
1066
|
}
|
|
885
|
-
__name(
|
|
886
|
-
function
|
|
1067
|
+
__name(_ts_decorate10, "_ts_decorate");
|
|
1068
|
+
function _ts_metadata9(k, v) {
|
|
887
1069
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
888
1070
|
}
|
|
889
|
-
__name(
|
|
890
|
-
function
|
|
1071
|
+
__name(_ts_metadata9, "_ts_metadata");
|
|
1072
|
+
function _ts_param8(paramIndex, decorator) {
|
|
891
1073
|
return function(target, key) {
|
|
892
1074
|
decorator(target, key, paramIndex);
|
|
893
1075
|
};
|
|
894
1076
|
}
|
|
895
|
-
__name(
|
|
1077
|
+
__name(_ts_param8, "_ts_param");
|
|
896
1078
|
var ThreadsController = class {
|
|
897
1079
|
static {
|
|
898
1080
|
__name(this, "ThreadsController");
|
|
@@ -922,9 +1104,21 @@ var ThreadsController = class {
|
|
|
922
1104
|
const actor = await this.actorResolver.resolve(req);
|
|
923
1105
|
return this.agent.forkThread(actor, id, messageId);
|
|
924
1106
|
}
|
|
925
|
-
|
|
1107
|
+
/**
|
|
1108
|
+
* Renames the thread and/or sets its default agent. `defaultAgent` is only present in the request
|
|
1109
|
+
* body when the client actually sent the key (JSON has no `undefined`), so `'defaultAgent' in body`
|
|
1110
|
+
* distinguishes "leave it alone" from "set it to null" (clear it) unambiguously.
|
|
1111
|
+
*/
|
|
1112
|
+
async update(req, id, body) {
|
|
926
1113
|
const actor = await this.actorResolver.resolve(req);
|
|
927
|
-
await this.agent.
|
|
1114
|
+
await this.agent.updateThread(actor, id, {
|
|
1115
|
+
...body.title !== void 0 ? {
|
|
1116
|
+
title: body.title
|
|
1117
|
+
} : {},
|
|
1118
|
+
..."defaultAgent" in body ? {
|
|
1119
|
+
defaultAgent: body.defaultAgent ?? null
|
|
1120
|
+
} : {}
|
|
1121
|
+
});
|
|
928
1122
|
return {
|
|
929
1123
|
ok: true
|
|
930
1124
|
};
|
|
@@ -944,117 +1138,117 @@ var ThreadsController = class {
|
|
|
944
1138
|
};
|
|
945
1139
|
}
|
|
946
1140
|
};
|
|
947
|
-
|
|
1141
|
+
_ts_decorate10([
|
|
948
1142
|
Get4(),
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1143
|
+
_ts_param8(0, Req4()),
|
|
1144
|
+
_ts_metadata9("design:type", Function),
|
|
1145
|
+
_ts_metadata9("design:paramtypes", [
|
|
952
1146
|
typeof Request === "undefined" ? Object : Request
|
|
953
1147
|
]),
|
|
954
|
-
|
|
1148
|
+
_ts_metadata9("design:returntype", Promise)
|
|
955
1149
|
], ThreadsController.prototype, "list", null);
|
|
956
|
-
|
|
1150
|
+
_ts_decorate10([
|
|
957
1151
|
Get4(":id"),
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1152
|
+
_ts_param8(0, Req4()),
|
|
1153
|
+
_ts_param8(1, Param2("id")),
|
|
1154
|
+
_ts_metadata9("design:type", Function),
|
|
1155
|
+
_ts_metadata9("design:paramtypes", [
|
|
962
1156
|
typeof Request === "undefined" ? Object : Request,
|
|
963
1157
|
String
|
|
964
1158
|
]),
|
|
965
|
-
|
|
1159
|
+
_ts_metadata9("design:returntype", Promise)
|
|
966
1160
|
], ThreadsController.prototype, "detail", null);
|
|
967
|
-
|
|
1161
|
+
_ts_decorate10([
|
|
968
1162
|
Delete(":id"),
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1163
|
+
_ts_param8(0, Req4()),
|
|
1164
|
+
_ts_param8(1, Param2("id")),
|
|
1165
|
+
_ts_metadata9("design:type", Function),
|
|
1166
|
+
_ts_metadata9("design:paramtypes", [
|
|
973
1167
|
typeof Request === "undefined" ? Object : Request,
|
|
974
1168
|
String
|
|
975
1169
|
]),
|
|
976
|
-
|
|
1170
|
+
_ts_metadata9("design:returntype", Promise)
|
|
977
1171
|
], ThreadsController.prototype, "remove", null);
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1172
|
+
_ts_decorate10([
|
|
1173
|
+
Post3(":id/fork-from/:messageId"),
|
|
1174
|
+
_ts_param8(0, Req4()),
|
|
1175
|
+
_ts_param8(1, Param2("id")),
|
|
1176
|
+
_ts_param8(2, Param2("messageId")),
|
|
1177
|
+
_ts_metadata9("design:type", Function),
|
|
1178
|
+
_ts_metadata9("design:paramtypes", [
|
|
985
1179
|
typeof Request === "undefined" ? Object : Request,
|
|
986
1180
|
String,
|
|
987
1181
|
String
|
|
988
1182
|
]),
|
|
989
|
-
|
|
1183
|
+
_ts_metadata9("design:returntype", Promise)
|
|
990
1184
|
], ThreadsController.prototype, "fork", null);
|
|
991
|
-
|
|
1185
|
+
_ts_decorate10([
|
|
992
1186
|
Patch(":id"),
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1187
|
+
_ts_param8(0, Req4()),
|
|
1188
|
+
_ts_param8(1, Param2("id")),
|
|
1189
|
+
_ts_param8(2, Body2()),
|
|
1190
|
+
_ts_metadata9("design:type", Function),
|
|
1191
|
+
_ts_metadata9("design:paramtypes", [
|
|
998
1192
|
typeof Request === "undefined" ? Object : Request,
|
|
999
1193
|
String,
|
|
1000
|
-
typeof
|
|
1194
|
+
typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
|
|
1001
1195
|
]),
|
|
1002
|
-
|
|
1003
|
-
], ThreadsController.prototype, "
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1196
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1197
|
+
], ThreadsController.prototype, "update", null);
|
|
1198
|
+
_ts_decorate10([
|
|
1199
|
+
Post3(":id/promote"),
|
|
1200
|
+
_ts_param8(0, Req4()),
|
|
1201
|
+
_ts_param8(1, Param2("id")),
|
|
1202
|
+
_ts_metadata9("design:type", Function),
|
|
1203
|
+
_ts_metadata9("design:paramtypes", [
|
|
1010
1204
|
typeof Request === "undefined" ? Object : Request,
|
|
1011
1205
|
String
|
|
1012
1206
|
]),
|
|
1013
|
-
|
|
1207
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1014
1208
|
], ThreadsController.prototype, "promote", null);
|
|
1015
|
-
|
|
1209
|
+
_ts_decorate10([
|
|
1016
1210
|
Delete(":id/from/:messageId"),
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1211
|
+
_ts_param8(0, Req4()),
|
|
1212
|
+
_ts_param8(1, Param2("id")),
|
|
1213
|
+
_ts_param8(2, Param2("messageId")),
|
|
1214
|
+
_ts_metadata9("design:type", Function),
|
|
1215
|
+
_ts_metadata9("design:paramtypes", [
|
|
1022
1216
|
typeof Request === "undefined" ? Object : Request,
|
|
1023
1217
|
String,
|
|
1024
1218
|
String
|
|
1025
1219
|
]),
|
|
1026
|
-
|
|
1220
|
+
_ts_metadata9("design:returntype", Promise)
|
|
1027
1221
|
], ThreadsController.prototype, "truncateFrom", null);
|
|
1028
|
-
ThreadsController =
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1222
|
+
ThreadsController = _ts_decorate10([
|
|
1223
|
+
Controller5("threads"),
|
|
1224
|
+
_ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER4)),
|
|
1225
|
+
_ts_metadata9("design:type", Function),
|
|
1226
|
+
_ts_metadata9("design:paramtypes", [
|
|
1033
1227
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
1034
1228
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
1035
1229
|
])
|
|
1036
1230
|
], ThreadsController);
|
|
1037
1231
|
|
|
1038
1232
|
// src/controller/tool-call.controller.ts
|
|
1039
|
-
import { AGENT_ACTOR_RESOLVER as
|
|
1040
|
-
import { Body as Body3, Controller as
|
|
1041
|
-
function
|
|
1233
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5 } from "@dudousxd/nestjs-agent-core";
|
|
1234
|
+
import { Body as Body3, Controller as Controller6, Inject as Inject9, Post as Post4, Req as Req5 } from "@nestjs/common";
|
|
1235
|
+
function _ts_decorate11(decorators, target, key, desc) {
|
|
1042
1236
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1043
1237
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1044
1238
|
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;
|
|
1045
1239
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1046
1240
|
}
|
|
1047
|
-
__name(
|
|
1048
|
-
function
|
|
1241
|
+
__name(_ts_decorate11, "_ts_decorate");
|
|
1242
|
+
function _ts_metadata10(k, v) {
|
|
1049
1243
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1050
1244
|
}
|
|
1051
|
-
__name(
|
|
1052
|
-
function
|
|
1245
|
+
__name(_ts_metadata10, "_ts_metadata");
|
|
1246
|
+
function _ts_param9(paramIndex, decorator) {
|
|
1053
1247
|
return function(target, key) {
|
|
1054
1248
|
decorator(target, key, paramIndex);
|
|
1055
1249
|
};
|
|
1056
1250
|
}
|
|
1057
|
-
__name(
|
|
1251
|
+
__name(_ts_param9, "_ts_param");
|
|
1058
1252
|
var ToolCallController = class {
|
|
1059
1253
|
static {
|
|
1060
1254
|
__name(this, "ToolCallController");
|
|
@@ -1080,33 +1274,33 @@ var ToolCallController = class {
|
|
|
1080
1274
|
};
|
|
1081
1275
|
}
|
|
1082
1276
|
};
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1277
|
+
_ts_decorate11([
|
|
1278
|
+
Post4("approve"),
|
|
1279
|
+
_ts_param9(0, Req5()),
|
|
1280
|
+
_ts_param9(1, Body3()),
|
|
1281
|
+
_ts_metadata10("design:type", Function),
|
|
1282
|
+
_ts_metadata10("design:paramtypes", [
|
|
1089
1283
|
typeof Request === "undefined" ? Object : Request,
|
|
1090
1284
|
typeof ApproveBody === "undefined" ? Object : ApproveBody
|
|
1091
1285
|
]),
|
|
1092
|
-
|
|
1286
|
+
_ts_metadata10("design:returntype", Promise)
|
|
1093
1287
|
], ToolCallController.prototype, "approve", null);
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1288
|
+
_ts_decorate11([
|
|
1289
|
+
Post4("reject"),
|
|
1290
|
+
_ts_param9(0, Req5()),
|
|
1291
|
+
_ts_param9(1, Body3()),
|
|
1292
|
+
_ts_metadata10("design:type", Function),
|
|
1293
|
+
_ts_metadata10("design:paramtypes", [
|
|
1100
1294
|
typeof Request === "undefined" ? Object : Request,
|
|
1101
1295
|
typeof RejectBody === "undefined" ? Object : RejectBody
|
|
1102
1296
|
]),
|
|
1103
|
-
|
|
1297
|
+
_ts_metadata10("design:returntype", Promise)
|
|
1104
1298
|
], ToolCallController.prototype, "reject", null);
|
|
1105
|
-
ToolCallController =
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1299
|
+
ToolCallController = _ts_decorate11([
|
|
1300
|
+
Controller6("tool-call"),
|
|
1301
|
+
_ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER5)),
|
|
1302
|
+
_ts_metadata10("design:type", Function),
|
|
1303
|
+
_ts_metadata10("design:paramtypes", [
|
|
1110
1304
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
1111
1305
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
1112
1306
|
])
|
|
@@ -1114,7 +1308,7 @@ ToolCallController = _ts_decorate10([
|
|
|
1114
1308
|
|
|
1115
1309
|
// src/discovery/agent-discovery.service.ts
|
|
1116
1310
|
import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY3, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
|
|
1117
|
-
import { Inject as
|
|
1311
|
+
import { Inject as Inject10, Injectable as Injectable5, Logger } from "@nestjs/common";
|
|
1118
1312
|
import { DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
1119
1313
|
|
|
1120
1314
|
// src/decorator/agent.decorator.ts
|
|
@@ -1131,23 +1325,23 @@ var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
|
|
|
1131
1325
|
var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
|
|
1132
1326
|
|
|
1133
1327
|
// src/discovery/agent-discovery.service.ts
|
|
1134
|
-
function
|
|
1328
|
+
function _ts_decorate12(decorators, target, key, desc) {
|
|
1135
1329
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1136
1330
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1137
1331
|
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;
|
|
1138
1332
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1139
1333
|
}
|
|
1140
|
-
__name(
|
|
1141
|
-
function
|
|
1334
|
+
__name(_ts_decorate12, "_ts_decorate");
|
|
1335
|
+
function _ts_metadata11(k, v) {
|
|
1142
1336
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1143
1337
|
}
|
|
1144
|
-
__name(
|
|
1145
|
-
function
|
|
1338
|
+
__name(_ts_metadata11, "_ts_metadata");
|
|
1339
|
+
function _ts_param10(paramIndex, decorator) {
|
|
1146
1340
|
return function(target, key) {
|
|
1147
1341
|
decorator(target, key, paramIndex);
|
|
1148
1342
|
};
|
|
1149
1343
|
}
|
|
1150
|
-
__name(
|
|
1344
|
+
__name(_ts_param10, "_ts_param");
|
|
1151
1345
|
var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
1152
1346
|
static {
|
|
1153
1347
|
__name(this, "AgentDiscoveryService");
|
|
@@ -1244,12 +1438,12 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
|
|
|
1244
1438
|
return (ctx) => candidate.call(instance, ctx);
|
|
1245
1439
|
}
|
|
1246
1440
|
};
|
|
1247
|
-
AgentDiscoveryService =
|
|
1441
|
+
AgentDiscoveryService = _ts_decorate12([
|
|
1248
1442
|
Injectable5(),
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1443
|
+
_ts_param10(2, Inject10(AGENT_REGISTRY3)),
|
|
1444
|
+
_ts_param10(3, Inject10(AGENT_PROMPT_CONTRIBUTORS2)),
|
|
1445
|
+
_ts_metadata11("design:type", Function),
|
|
1446
|
+
_ts_metadata11("design:paramtypes", [
|
|
1253
1447
|
typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
|
|
1254
1448
|
typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
|
|
1255
1449
|
typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4,
|
|
@@ -1258,8 +1452,8 @@ AgentDiscoveryService = _ts_decorate11([
|
|
|
1258
1452
|
], AgentDiscoveryService);
|
|
1259
1453
|
|
|
1260
1454
|
// src/discovery/ai-tool-discovery.service.ts
|
|
1261
|
-
import { AGENT_OPTIONS as
|
|
1262
|
-
import { Inject as
|
|
1455
|
+
import { AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_REGISTRY as AGENT_REGISTRY4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2 } from "@dudousxd/nestjs-agent-core";
|
|
1456
|
+
import { Inject as Inject11, Injectable as Injectable6, Logger as Logger2 } from "@nestjs/common";
|
|
1263
1457
|
import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
|
|
1264
1458
|
import { z } from "zod";
|
|
1265
1459
|
|
|
@@ -1279,23 +1473,23 @@ function isBrandedFunctionalTool(value) {
|
|
|
1279
1473
|
__name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
|
|
1280
1474
|
|
|
1281
1475
|
// src/discovery/ai-tool-discovery.service.ts
|
|
1282
|
-
function
|
|
1476
|
+
function _ts_decorate13(decorators, target, key, desc) {
|
|
1283
1477
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1284
1478
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1285
1479
|
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;
|
|
1286
1480
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1287
1481
|
}
|
|
1288
|
-
__name(
|
|
1289
|
-
function
|
|
1482
|
+
__name(_ts_decorate13, "_ts_decorate");
|
|
1483
|
+
function _ts_metadata12(k, v) {
|
|
1290
1484
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1291
1485
|
}
|
|
1292
|
-
__name(
|
|
1293
|
-
function
|
|
1486
|
+
__name(_ts_metadata12, "_ts_metadata");
|
|
1487
|
+
function _ts_param11(paramIndex, decorator) {
|
|
1294
1488
|
return function(target, key) {
|
|
1295
1489
|
decorator(target, key, paramIndex);
|
|
1296
1490
|
};
|
|
1297
1491
|
}
|
|
1298
|
-
__name(
|
|
1492
|
+
__name(_ts_param11, "_ts_param");
|
|
1299
1493
|
var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
1300
1494
|
static {
|
|
1301
1495
|
__name(this, "AiToolDiscoveryService");
|
|
@@ -1402,13 +1596,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
|
|
|
1402
1596
|
return true;
|
|
1403
1597
|
}
|
|
1404
1598
|
};
|
|
1405
|
-
AiToolDiscoveryService =
|
|
1599
|
+
AiToolDiscoveryService = _ts_decorate13([
|
|
1406
1600
|
Injectable6(),
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1601
|
+
_ts_param11(1, Inject11(AGENT_TOOL_REGISTRY2)),
|
|
1602
|
+
_ts_param11(2, Inject11(AGENT_REGISTRY4)),
|
|
1603
|
+
_ts_param11(3, Inject11(AGENT_OPTIONS3)),
|
|
1604
|
+
_ts_metadata12("design:type", Function),
|
|
1605
|
+
_ts_metadata12("design:paramtypes", [
|
|
1412
1606
|
typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
|
|
1413
1607
|
typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
|
|
1414
1608
|
typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
|
|
@@ -1509,24 +1703,24 @@ var LedgerQuotaStore = class {
|
|
|
1509
1703
|
|
|
1510
1704
|
// src/runner/inline-agent-runner.ts
|
|
1511
1705
|
import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_STORE as AGENT_STORE4, QuotaExceededError as QuotaExceededError2, publishAgentRunFailed as publishAgentRunFailed2, runAgentLoop as runAgentLoop2 } from "@dudousxd/nestjs-agent-core";
|
|
1512
|
-
import { Inject as
|
|
1513
|
-
function
|
|
1706
|
+
import { Inject as Inject12, Injectable as Injectable7, Logger as Logger3 } from "@nestjs/common";
|
|
1707
|
+
function _ts_decorate14(decorators, target, key, desc) {
|
|
1514
1708
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1515
1709
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1516
1710
|
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;
|
|
1517
1711
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1518
1712
|
}
|
|
1519
|
-
__name(
|
|
1520
|
-
function
|
|
1713
|
+
__name(_ts_decorate14, "_ts_decorate");
|
|
1714
|
+
function _ts_metadata13(k, v) {
|
|
1521
1715
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
1522
1716
|
}
|
|
1523
|
-
__name(
|
|
1524
|
-
function
|
|
1717
|
+
__name(_ts_metadata13, "_ts_metadata");
|
|
1718
|
+
function _ts_param12(paramIndex, decorator) {
|
|
1525
1719
|
return function(target, key) {
|
|
1526
1720
|
decorator(target, key, paramIndex);
|
|
1527
1721
|
};
|
|
1528
1722
|
}
|
|
1529
|
-
__name(
|
|
1723
|
+
__name(_ts_param12, "_ts_param");
|
|
1530
1724
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
1531
1725
|
static {
|
|
1532
1726
|
__name(this, "InlineAgentRunner");
|
|
@@ -1547,7 +1741,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1547
1741
|
void runAgentLoop2({
|
|
1548
1742
|
...deps,
|
|
1549
1743
|
day
|
|
1550
|
-
}, input, hooks).catch(async (error) => {
|
|
1744
|
+
}, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
|
|
1551
1745
|
const message = error instanceof Error ? error.message : String(error);
|
|
1552
1746
|
const code = error instanceof QuotaExceededError2 ? "quota_exceeded" : "run_failed";
|
|
1553
1747
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
@@ -1556,6 +1750,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1556
1750
|
code,
|
|
1557
1751
|
message
|
|
1558
1752
|
});
|
|
1753
|
+
await this.store.setActiveStream(input.threadId, null);
|
|
1559
1754
|
const writer = await deps.sink.open(runId);
|
|
1560
1755
|
await writer.fail({
|
|
1561
1756
|
code,
|
|
@@ -1613,39 +1808,43 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
1613
1808
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
1614
1809
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested(childName, childTask, actor, day, depth + 1, sinkRunId), "runAgent")
|
|
1615
1810
|
};
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1811
|
+
try {
|
|
1812
|
+
return await runAgentLoop2({
|
|
1813
|
+
...deps,
|
|
1814
|
+
day
|
|
1815
|
+
}, {
|
|
1816
|
+
threadId: subThread.id,
|
|
1817
|
+
actor,
|
|
1818
|
+
userText: task,
|
|
1819
|
+
agentName,
|
|
1820
|
+
day,
|
|
1821
|
+
delegationDepth: depth,
|
|
1822
|
+
sinkRunId
|
|
1823
|
+
}, hooks);
|
|
1824
|
+
} finally {
|
|
1825
|
+
await this.store.setActiveStream(subThread.id, null);
|
|
1826
|
+
}
|
|
1628
1827
|
}
|
|
1629
1828
|
};
|
|
1630
|
-
InlineAgentRunner =
|
|
1829
|
+
InlineAgentRunner = _ts_decorate14([
|
|
1631
1830
|
Injectable7(),
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1831
|
+
_ts_param12(0, Inject12(AGENT_DEPS_FACTORY4)),
|
|
1832
|
+
_ts_param12(1, Inject12(AGENT_STORE4)),
|
|
1833
|
+
_ts_metadata13("design:type", Function),
|
|
1834
|
+
_ts_metadata13("design:paramtypes", [
|
|
1636
1835
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
1637
1836
|
typeof AgentStore === "undefined" ? Object : AgentStore
|
|
1638
1837
|
])
|
|
1639
1838
|
], InlineAgentRunner);
|
|
1640
1839
|
|
|
1641
1840
|
// src/agent.module.ts
|
|
1642
|
-
function
|
|
1841
|
+
function _ts_decorate15(decorators, target, key, desc) {
|
|
1643
1842
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1644
1843
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1645
1844
|
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;
|
|
1646
1845
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1647
1846
|
}
|
|
1648
|
-
__name(
|
|
1847
|
+
__name(_ts_decorate15, "_ts_decorate");
|
|
1649
1848
|
var DEFAULT_PATH = "agent";
|
|
1650
1849
|
function sharedProviders(durable, includeStore) {
|
|
1651
1850
|
const providers = [
|
|
@@ -1667,28 +1866,28 @@ function sharedProviders(durable, includeStore) {
|
|
|
1667
1866
|
provide: AGENT_SINK2,
|
|
1668
1867
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
1669
1868
|
inject: [
|
|
1670
|
-
|
|
1869
|
+
AGENT_OPTIONS4
|
|
1671
1870
|
]
|
|
1672
1871
|
},
|
|
1673
1872
|
{
|
|
1674
1873
|
provide: AGENT_ROLES_POLICY2,
|
|
1675
1874
|
useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new DefaultRolesPolicy(options.defaultRoles), "useFactory"),
|
|
1676
1875
|
inject: [
|
|
1677
|
-
|
|
1876
|
+
AGENT_OPTIONS4
|
|
1678
1877
|
]
|
|
1679
1878
|
},
|
|
1680
1879
|
{
|
|
1681
|
-
provide:
|
|
1880
|
+
provide: AGENT_ACTOR_RESOLVER6,
|
|
1682
1881
|
useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
|
|
1683
1882
|
inject: [
|
|
1684
|
-
|
|
1883
|
+
AGENT_OPTIONS4
|
|
1685
1884
|
]
|
|
1686
1885
|
},
|
|
1687
1886
|
{
|
|
1688
1887
|
provide: AGENT_MODEL2,
|
|
1689
1888
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
1690
1889
|
inject: [
|
|
1691
|
-
|
|
1890
|
+
AGENT_OPTIONS4
|
|
1692
1891
|
]
|
|
1693
1892
|
},
|
|
1694
1893
|
{
|
|
@@ -1698,7 +1897,7 @@ function sharedProviders(durable, includeStore) {
|
|
|
1698
1897
|
provide: AGENT_QUOTA_STORE3,
|
|
1699
1898
|
useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
|
|
1700
1899
|
inject: [
|
|
1701
|
-
|
|
1900
|
+
AGENT_OPTIONS4,
|
|
1702
1901
|
AGENT_STORE5
|
|
1703
1902
|
]
|
|
1704
1903
|
},
|
|
@@ -1719,7 +1918,7 @@ function sharedProviders(durable, includeStore) {
|
|
|
1719
1918
|
provide: AGENT_STORE5,
|
|
1720
1919
|
useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
|
|
1721
1920
|
inject: [
|
|
1722
|
-
|
|
1921
|
+
AGENT_OPTIONS4
|
|
1723
1922
|
]
|
|
1724
1923
|
});
|
|
1725
1924
|
}
|
|
@@ -1750,12 +1949,12 @@ function sharedProviders(durable, includeStore) {
|
|
|
1750
1949
|
__name(sharedProviders, "sharedProviders");
|
|
1751
1950
|
function exportsFor(includeStore) {
|
|
1752
1951
|
return [
|
|
1753
|
-
|
|
1952
|
+
AGENT_OPTIONS4,
|
|
1754
1953
|
AGENT_TOOL_REGISTRY3,
|
|
1755
1954
|
AGENT_REGISTRY5,
|
|
1756
1955
|
AGENT_SINK2,
|
|
1757
1956
|
AGENT_ROLES_POLICY2,
|
|
1758
|
-
|
|
1957
|
+
AGENT_ACTOR_RESOLVER6,
|
|
1759
1958
|
AGENT_MODEL2,
|
|
1760
1959
|
...includeStore ? [
|
|
1761
1960
|
AGENT_STORE5
|
|
@@ -1769,13 +1968,38 @@ function exportsFor(includeStore) {
|
|
|
1769
1968
|
];
|
|
1770
1969
|
}
|
|
1771
1970
|
__name(exportsFor, "exportsFor");
|
|
1772
|
-
var
|
|
1971
|
+
var BASE_CONTROLLERS = [
|
|
1773
1972
|
ChatController,
|
|
1774
1973
|
ThreadsController,
|
|
1775
1974
|
ToolCallController,
|
|
1776
1975
|
QuotaController,
|
|
1777
1976
|
AgentsController
|
|
1778
1977
|
];
|
|
1978
|
+
var GUARDABLE_CONTROLLERS = [
|
|
1979
|
+
...BASE_CONTROLLERS,
|
|
1980
|
+
AttachmentsController
|
|
1981
|
+
];
|
|
1982
|
+
function controllersFor(mountAttachments) {
|
|
1983
|
+
return mountAttachments ? [
|
|
1984
|
+
...BASE_CONTROLLERS,
|
|
1985
|
+
AttachmentsController
|
|
1986
|
+
] : BASE_CONTROLLERS;
|
|
1987
|
+
}
|
|
1988
|
+
__name(controllersFor, "controllersFor");
|
|
1989
|
+
var GUARDS_METADATA = "__guards__";
|
|
1990
|
+
function applyGuards(guards) {
|
|
1991
|
+
const resolved = guards ?? [];
|
|
1992
|
+
for (const controller of GUARDABLE_CONTROLLERS) {
|
|
1993
|
+
Reflect.defineMetadata(GUARDS_METADATA, resolved, controller);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
__name(applyGuards, "applyGuards");
|
|
1997
|
+
function guardProviders(guards) {
|
|
1998
|
+
return [
|
|
1999
|
+
...new Set(guards ?? [])
|
|
2000
|
+
];
|
|
2001
|
+
}
|
|
2002
|
+
__name(guardProviders, "guardProviders");
|
|
1779
2003
|
function routerFor(path) {
|
|
1780
2004
|
return RouterModule.register([
|
|
1781
2005
|
{
|
|
@@ -1792,6 +2016,7 @@ var AgentModule = class _AgentModule {
|
|
|
1792
2016
|
static forRoot(options) {
|
|
1793
2017
|
const path = options.path ?? DEFAULT_PATH;
|
|
1794
2018
|
const includeStore = options.store !== void 0;
|
|
2019
|
+
applyGuards(options.guards);
|
|
1795
2020
|
return {
|
|
1796
2021
|
module: _AgentModule,
|
|
1797
2022
|
global: true,
|
|
@@ -1799,13 +2024,14 @@ var AgentModule = class _AgentModule {
|
|
|
1799
2024
|
DiscoveryModule,
|
|
1800
2025
|
routerFor(path)
|
|
1801
2026
|
],
|
|
1802
|
-
controllers:
|
|
2027
|
+
controllers: controllersFor(options.attachments?.upload === true),
|
|
1803
2028
|
providers: [
|
|
1804
2029
|
{
|
|
1805
|
-
provide:
|
|
2030
|
+
provide: AGENT_OPTIONS4,
|
|
1806
2031
|
useValue: options
|
|
1807
2032
|
},
|
|
1808
|
-
...sharedProviders(options.durable ?? false, includeStore)
|
|
2033
|
+
...sharedProviders(options.durable ?? false, includeStore),
|
|
2034
|
+
...guardProviders(options.guards)
|
|
1809
2035
|
],
|
|
1810
2036
|
exports: exportsFor(includeStore)
|
|
1811
2037
|
};
|
|
@@ -1813,6 +2039,7 @@ var AgentModule = class _AgentModule {
|
|
|
1813
2039
|
static forRootAsync(options) {
|
|
1814
2040
|
const path = options.path ?? DEFAULT_PATH;
|
|
1815
2041
|
const includeStore = options.externalStore !== true;
|
|
2042
|
+
applyGuards(options.guards);
|
|
1816
2043
|
return {
|
|
1817
2044
|
module: _AgentModule,
|
|
1818
2045
|
global: true,
|
|
@@ -1821,20 +2048,21 @@ var AgentModule = class _AgentModule {
|
|
|
1821
2048
|
routerFor(path),
|
|
1822
2049
|
...options.imports ?? []
|
|
1823
2050
|
],
|
|
1824
|
-
controllers:
|
|
2051
|
+
controllers: controllersFor(options.attachmentsUpload === true),
|
|
1825
2052
|
providers: [
|
|
1826
2053
|
{
|
|
1827
|
-
provide:
|
|
2054
|
+
provide: AGENT_OPTIONS4,
|
|
1828
2055
|
useFactory: options.useFactory,
|
|
1829
2056
|
inject: options.inject ?? []
|
|
1830
2057
|
},
|
|
1831
|
-
...sharedProviders(options.durable ?? false, includeStore)
|
|
2058
|
+
...sharedProviders(options.durable ?? false, includeStore),
|
|
2059
|
+
...guardProviders(options.guards)
|
|
1832
2060
|
],
|
|
1833
2061
|
exports: exportsFor(includeStore)
|
|
1834
2062
|
};
|
|
1835
2063
|
}
|
|
1836
2064
|
};
|
|
1837
|
-
AgentModule =
|
|
2065
|
+
AgentModule = _ts_decorate15([
|
|
1838
2066
|
Global2(),
|
|
1839
2067
|
Module2({})
|
|
1840
2068
|
], AgentModule);
|