@dudousxd/nestjs-agent 0.2.0 → 0.3.1
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/durable/index.cjs +117 -4
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.js +125 -12
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +117 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -6
- package/dist/index.d.ts +27 -6
- package/dist/index.js +125 -12
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/agent.module.ts
|
|
5
|
-
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_DURABLE_RUNNER, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as
|
|
5
|
+
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_DURABLE_RUNNER, AGENT_MODEL as AGENT_MODEL2, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE3, AGENT_REGISTRY as AGENT_REGISTRY4, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE4, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry4, DefaultRolesPolicy, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
|
|
6
6
|
import { Global, Module } from "@nestjs/common";
|
|
7
7
|
import { DiscoveryModule, RouterModule } from "@nestjs/core";
|
|
8
8
|
|
|
@@ -155,7 +155,7 @@ AgentDepsFactory2 = _ts_decorate([
|
|
|
155
155
|
], AgentDepsFactory2);
|
|
156
156
|
|
|
157
157
|
// src/agent.service.ts
|
|
158
|
-
import { AGENT_DEPS_FACTORY, AGENT_RUNNER, AGENT_STORE as AGENT_STORE2 } from "@dudousxd/nestjs-agent-core";
|
|
158
|
+
import { AGENT_DEPS_FACTORY, AGENT_QUOTA_STORE as AGENT_QUOTA_STORE2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE2 } from "@dudousxd/nestjs-agent-core";
|
|
159
159
|
import { BadRequestException, ForbiddenException, Inject as Inject2, Injectable as Injectable2, NotFoundException } from "@nestjs/common";
|
|
160
160
|
|
|
161
161
|
// src/agent-deps.ts
|
|
@@ -199,10 +199,12 @@ var AgentService = class {
|
|
|
199
199
|
runner;
|
|
200
200
|
store;
|
|
201
201
|
deps;
|
|
202
|
-
|
|
202
|
+
quota;
|
|
203
|
+
constructor(runner, store, deps, quota) {
|
|
203
204
|
this.runner = runner;
|
|
204
205
|
this.store = store;
|
|
205
206
|
this.deps = deps;
|
|
207
|
+
this.quota = quota;
|
|
206
208
|
}
|
|
207
209
|
async chat(params) {
|
|
208
210
|
const agentName = params.agentName ?? this.deps.defaultAgentName();
|
|
@@ -212,7 +214,10 @@ var AgentService = class {
|
|
|
212
214
|
throw new BadRequestException("regenerate requires an existing threadId");
|
|
213
215
|
}
|
|
214
216
|
const created = await this.store.createThread({
|
|
215
|
-
actor: params.actor
|
|
217
|
+
actor: params.actor,
|
|
218
|
+
...params.transient === true ? {
|
|
219
|
+
transient: true
|
|
220
|
+
} : {}
|
|
216
221
|
});
|
|
217
222
|
threadId = created.id;
|
|
218
223
|
} else if (params.regenerate === true) {
|
|
@@ -275,8 +280,53 @@ var AgentService = class {
|
|
|
275
280
|
await this.assertOwnsThread(actor, threadId);
|
|
276
281
|
return this.store.forkThread(threadId, fromMessageId);
|
|
277
282
|
}
|
|
283
|
+
async renameThread(actor, threadId, title) {
|
|
284
|
+
const trimmed = title.trim();
|
|
285
|
+
if (trimmed.length === 0) {
|
|
286
|
+
throw new BadRequestException("title must not be empty");
|
|
287
|
+
}
|
|
288
|
+
if (trimmed.length > 200) {
|
|
289
|
+
throw new BadRequestException("title must be at most 200 characters");
|
|
290
|
+
}
|
|
291
|
+
await this.assertOwnsThread(actor, threadId);
|
|
292
|
+
return this.store.setTitle(threadId, trimmed);
|
|
293
|
+
}
|
|
294
|
+
async promoteThread(actor, threadId) {
|
|
295
|
+
await this.assertOwnsThread(actor, threadId);
|
|
296
|
+
return this.store.promoteThread(threadId);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Drop a message and everything after it — the "edit and resend" / "delete from here" primitive.
|
|
300
|
+
* The client then sends a fresh turn on the truncated thread. Ownership-gated like the other
|
|
301
|
+
* thread-scoped mutations.
|
|
302
|
+
*/
|
|
303
|
+
async truncateThreadFrom(actor, threadId, messageId) {
|
|
304
|
+
await this.assertOwnsThread(actor, threadId);
|
|
305
|
+
return this.store.truncateFrom(threadId, messageId);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* The day's usage for the badge: tokens + summed USD cost from the store, and the configured
|
|
309
|
+
* limit from the quota store (null → unlimited). `withinLimit` comes from the quota store so it
|
|
310
|
+
* can never drift from what enforcement uses.
|
|
311
|
+
*/
|
|
278
312
|
async quotaToday(actorRef) {
|
|
279
|
-
|
|
313
|
+
const day = utcDay();
|
|
314
|
+
const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, day);
|
|
315
|
+
if (this.quota === void 0) {
|
|
316
|
+
return {
|
|
317
|
+
usedTokens,
|
|
318
|
+
costUsd,
|
|
319
|
+
limitTokens: null,
|
|
320
|
+
withinLimit: true
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
const state = await this.quota.check(actorRef, day);
|
|
324
|
+
return {
|
|
325
|
+
usedTokens: state.usedTokens,
|
|
326
|
+
costUsd,
|
|
327
|
+
limitTokens: state.limitTokens,
|
|
328
|
+
withinLimit: state.withinLimit
|
|
329
|
+
};
|
|
280
330
|
}
|
|
281
331
|
/**
|
|
282
332
|
* Authorization seam for thread-scoped endpoints: the caller must own the thread. A missing
|
|
@@ -327,11 +377,13 @@ AgentService = _ts_decorate2([
|
|
|
327
377
|
_ts_param2(0, Inject2(AGENT_RUNNER)),
|
|
328
378
|
_ts_param2(1, Inject2(AGENT_STORE2)),
|
|
329
379
|
_ts_param2(2, Inject2(AGENT_DEPS_FACTORY)),
|
|
380
|
+
_ts_param2(3, Inject2(AGENT_QUOTA_STORE2)),
|
|
330
381
|
_ts_metadata2("design:type", Function),
|
|
331
382
|
_ts_metadata2("design:paramtypes", [
|
|
332
383
|
typeof AgentRunner === "undefined" ? Object : AgentRunner,
|
|
333
384
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
334
|
-
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
|
|
385
|
+
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
386
|
+
Object
|
|
335
387
|
])
|
|
336
388
|
], AgentService);
|
|
337
389
|
|
|
@@ -381,6 +433,9 @@ var ChatController = class {
|
|
|
381
433
|
} : {},
|
|
382
434
|
...body.regenerate === true ? {
|
|
383
435
|
regenerate: true
|
|
436
|
+
} : {},
|
|
437
|
+
...body.transient === true ? {
|
|
438
|
+
transient: true
|
|
384
439
|
} : {}
|
|
385
440
|
});
|
|
386
441
|
await this.pipe(res, runId, threadId);
|
|
@@ -537,7 +592,7 @@ QuotaController = _ts_decorate4([
|
|
|
537
592
|
|
|
538
593
|
// src/controller/threads.controller.ts
|
|
539
594
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3 } from "@dudousxd/nestjs-agent-core";
|
|
540
|
-
import { Controller as Controller3, Delete, Get as Get3, Inject as Inject5, Param as Param2, Post as Post2, Req as Req3 } from "@nestjs/common";
|
|
595
|
+
import { Body as Body2, Controller as Controller3, Delete, Get as Get3, Inject as Inject5, Param as Param2, Patch, Post as Post2, Req as Req3 } from "@nestjs/common";
|
|
541
596
|
function _ts_decorate5(decorators, target, key, desc) {
|
|
542
597
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
543
598
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -584,6 +639,27 @@ var ThreadsController = class {
|
|
|
584
639
|
const actor = await this.actorResolver.resolve(req);
|
|
585
640
|
return this.agent.forkThread(actor, id, messageId);
|
|
586
641
|
}
|
|
642
|
+
async rename(req, id, body) {
|
|
643
|
+
const actor = await this.actorResolver.resolve(req);
|
|
644
|
+
await this.agent.renameThread(actor, id, body.title);
|
|
645
|
+
return {
|
|
646
|
+
ok: true
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
async promote(req, id) {
|
|
650
|
+
const actor = await this.actorResolver.resolve(req);
|
|
651
|
+
await this.agent.promoteThread(actor, id);
|
|
652
|
+
return {
|
|
653
|
+
ok: true
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
async truncateFrom(req, id, messageId) {
|
|
657
|
+
const actor = await this.actorResolver.resolve(req);
|
|
658
|
+
await this.agent.truncateThreadFrom(actor, id, messageId);
|
|
659
|
+
return {
|
|
660
|
+
ok: true
|
|
661
|
+
};
|
|
662
|
+
}
|
|
587
663
|
};
|
|
588
664
|
_ts_decorate5([
|
|
589
665
|
Get3(),
|
|
@@ -629,6 +705,43 @@ _ts_decorate5([
|
|
|
629
705
|
]),
|
|
630
706
|
_ts_metadata5("design:returntype", Promise)
|
|
631
707
|
], ThreadsController.prototype, "fork", null);
|
|
708
|
+
_ts_decorate5([
|
|
709
|
+
Patch(":id"),
|
|
710
|
+
_ts_param5(0, Req3()),
|
|
711
|
+
_ts_param5(1, Param2("id")),
|
|
712
|
+
_ts_param5(2, Body2()),
|
|
713
|
+
_ts_metadata5("design:type", Function),
|
|
714
|
+
_ts_metadata5("design:paramtypes", [
|
|
715
|
+
typeof Request === "undefined" ? Object : Request,
|
|
716
|
+
String,
|
|
717
|
+
typeof RenameThreadBody === "undefined" ? Object : RenameThreadBody
|
|
718
|
+
]),
|
|
719
|
+
_ts_metadata5("design:returntype", Promise)
|
|
720
|
+
], ThreadsController.prototype, "rename", null);
|
|
721
|
+
_ts_decorate5([
|
|
722
|
+
Post2(":id/promote"),
|
|
723
|
+
_ts_param5(0, Req3()),
|
|
724
|
+
_ts_param5(1, Param2("id")),
|
|
725
|
+
_ts_metadata5("design:type", Function),
|
|
726
|
+
_ts_metadata5("design:paramtypes", [
|
|
727
|
+
typeof Request === "undefined" ? Object : Request,
|
|
728
|
+
String
|
|
729
|
+
]),
|
|
730
|
+
_ts_metadata5("design:returntype", Promise)
|
|
731
|
+
], ThreadsController.prototype, "promote", null);
|
|
732
|
+
_ts_decorate5([
|
|
733
|
+
Delete(":id/from/:messageId"),
|
|
734
|
+
_ts_param5(0, Req3()),
|
|
735
|
+
_ts_param5(1, Param2("id")),
|
|
736
|
+
_ts_param5(2, Param2("messageId")),
|
|
737
|
+
_ts_metadata5("design:type", Function),
|
|
738
|
+
_ts_metadata5("design:paramtypes", [
|
|
739
|
+
typeof Request === "undefined" ? Object : Request,
|
|
740
|
+
String,
|
|
741
|
+
String
|
|
742
|
+
]),
|
|
743
|
+
_ts_metadata5("design:returntype", Promise)
|
|
744
|
+
], ThreadsController.prototype, "truncateFrom", null);
|
|
632
745
|
ThreadsController = _ts_decorate5([
|
|
633
746
|
Controller3("threads"),
|
|
634
747
|
_ts_param5(1, Inject5(AGENT_ACTOR_RESOLVER3)),
|
|
@@ -641,7 +754,7 @@ ThreadsController = _ts_decorate5([
|
|
|
641
754
|
|
|
642
755
|
// src/controller/tool-call.controller.ts
|
|
643
756
|
import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4 } from "@dudousxd/nestjs-agent-core";
|
|
644
|
-
import { Body as
|
|
757
|
+
import { Body as Body3, Controller as Controller4, Inject as Inject6, Post as Post3, Req as Req4 } from "@nestjs/common";
|
|
645
758
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
646
759
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
647
760
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -687,7 +800,7 @@ var ToolCallController = class {
|
|
|
687
800
|
_ts_decorate6([
|
|
688
801
|
Post3("approve"),
|
|
689
802
|
_ts_param6(0, Req4()),
|
|
690
|
-
_ts_param6(1,
|
|
803
|
+
_ts_param6(1, Body3()),
|
|
691
804
|
_ts_metadata6("design:type", Function),
|
|
692
805
|
_ts_metadata6("design:paramtypes", [
|
|
693
806
|
typeof Request === "undefined" ? Object : Request,
|
|
@@ -698,7 +811,7 @@ _ts_decorate6([
|
|
|
698
811
|
_ts_decorate6([
|
|
699
812
|
Post3("reject"),
|
|
700
813
|
_ts_param6(0, Req4()),
|
|
701
|
-
_ts_param6(1,
|
|
814
|
+
_ts_param6(1, Body3()),
|
|
702
815
|
_ts_metadata6("design:type", Function),
|
|
703
816
|
_ts_metadata6("design:paramtypes", [
|
|
704
817
|
typeof Request === "undefined" ? Object : Request,
|
|
@@ -1343,7 +1456,7 @@ function sharedProviders(durable, includeStore) {
|
|
|
1343
1456
|
// An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
|
|
1344
1457
|
// store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
|
|
1345
1458
|
// the loop already writes, so enforcement needs no extra shared state across replicas.
|
|
1346
|
-
provide:
|
|
1459
|
+
provide: AGENT_QUOTA_STORE3,
|
|
1347
1460
|
useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
|
|
1348
1461
|
inject: [
|
|
1349
1462
|
AGENT_OPTIONS3,
|
|
@@ -1408,7 +1521,7 @@ function exportsFor(includeStore) {
|
|
|
1408
1521
|
...includeStore ? [
|
|
1409
1522
|
AGENT_STORE4
|
|
1410
1523
|
] : [],
|
|
1411
|
-
|
|
1524
|
+
AGENT_QUOTA_STORE3,
|
|
1412
1525
|
AGENT_PROMPT_CONTRIBUTORS3,
|
|
1413
1526
|
AGENT_DEPS_FACTORY3,
|
|
1414
1527
|
AgentDepsFactory2,
|