@dudousxd/nestjs-agent 1.25.2 → 1.26.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/{chat-queue.service-Crf9uwum.d.cts → chat-queue.service-BN6Ljswx.d.cts} +13 -1
- package/dist/{chat-queue.service-ZQkqb1Yw.d.ts → chat-queue.service-DG44iDJA.d.ts} +13 -1
- package/dist/durable/index.cjs +255 -163
- 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 +177 -85
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +288 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +200 -108
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -86,8 +86,8 @@ __export(index_exports, {
|
|
|
86
86
|
module.exports = __toCommonJS(index_exports);
|
|
87
87
|
|
|
88
88
|
// src/agent.module.ts
|
|
89
|
-
var
|
|
90
|
-
var
|
|
89
|
+
var import_nestjs_agent_core34 = require("@dudousxd/nestjs-agent-core");
|
|
90
|
+
var import_common28 = require("@nestjs/common");
|
|
91
91
|
var import_core4 = require("@nestjs/core");
|
|
92
92
|
|
|
93
93
|
// src/agent-deps.factory.ts
|
|
@@ -5229,8 +5229,7 @@ var LedgerQuotaProvider = class {
|
|
|
5229
5229
|
}
|
|
5230
5230
|
};
|
|
5231
5231
|
|
|
5232
|
-
// src/
|
|
5233
|
-
var import_node_crypto2 = require("crypto");
|
|
5232
|
+
// src/pricing-boot.service.ts
|
|
5234
5233
|
var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
|
|
5235
5234
|
var import_common24 = require("@nestjs/common");
|
|
5236
5235
|
function _ts_decorate23(decorators, target, key, desc) {
|
|
@@ -5259,6 +5258,96 @@ function _ts_param22(paramIndex, decorator) {
|
|
|
5259
5258
|
};
|
|
5260
5259
|
}
|
|
5261
5260
|
__name(_ts_param22, "_ts_param");
|
|
5261
|
+
var logger = new import_common24.Logger("AgentPricing");
|
|
5262
|
+
var PricingBootService = class {
|
|
5263
|
+
static {
|
|
5264
|
+
__name(this, "PricingBootService");
|
|
5265
|
+
}
|
|
5266
|
+
options;
|
|
5267
|
+
model;
|
|
5268
|
+
pricingStore;
|
|
5269
|
+
#run = null;
|
|
5270
|
+
constructor(options, model, pricingStore) {
|
|
5271
|
+
this.options = options;
|
|
5272
|
+
this.model = model;
|
|
5273
|
+
this.pricingStore = pricingStore;
|
|
5274
|
+
}
|
|
5275
|
+
onApplicationBootstrap() {
|
|
5276
|
+
this.#run = this.check();
|
|
5277
|
+
}
|
|
5278
|
+
/** Awaits a check still in flight, so a test (or a fast shutdown) never leaks it. */
|
|
5279
|
+
async onApplicationShutdown() {
|
|
5280
|
+
await this.#run;
|
|
5281
|
+
this.#run = null;
|
|
5282
|
+
}
|
|
5283
|
+
/** The check itself; resolves once it is done (exposed for tests). */
|
|
5284
|
+
async check() {
|
|
5285
|
+
let models;
|
|
5286
|
+
try {
|
|
5287
|
+
models = this.model?.describeModels?.() ?? [];
|
|
5288
|
+
} catch (error) {
|
|
5289
|
+
logger.warn(`describeModels() threw; boot pricing skipped: ${String(error)}`);
|
|
5290
|
+
return;
|
|
5291
|
+
}
|
|
5292
|
+
if (models.length === 0) return;
|
|
5293
|
+
const catalog = this.options.priceCatalog;
|
|
5294
|
+
if (catalog === void 0 && process.env.NODE_ENV === "test") return;
|
|
5295
|
+
await (0, import_nestjs_agent_core29.ensureModelPricing)({
|
|
5296
|
+
models,
|
|
5297
|
+
pricingStore: this.pricingStore,
|
|
5298
|
+
catalog: catalog ?? {},
|
|
5299
|
+
log: {
|
|
5300
|
+
info: /* @__PURE__ */ __name((message) => logger.log(message), "info"),
|
|
5301
|
+
warn: /* @__PURE__ */ __name((message) => logger.warn(message), "warn")
|
|
5302
|
+
}
|
|
5303
|
+
}).catch(() => void 0);
|
|
5304
|
+
}
|
|
5305
|
+
};
|
|
5306
|
+
PricingBootService = _ts_decorate23([
|
|
5307
|
+
(0, import_common24.Injectable)(),
|
|
5308
|
+
_ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_OPTIONS)),
|
|
5309
|
+
_ts_param22(1, (0, import_common24.Optional)()),
|
|
5310
|
+
_ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_MODEL)),
|
|
5311
|
+
_ts_param22(2, (0, import_common24.Optional)()),
|
|
5312
|
+
_ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_PRICING_STORE)),
|
|
5313
|
+
_ts_metadata22("design:type", Function),
|
|
5314
|
+
_ts_metadata22("design:paramtypes", [
|
|
5315
|
+
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
5316
|
+
Object,
|
|
5317
|
+
Object
|
|
5318
|
+
])
|
|
5319
|
+
], PricingBootService);
|
|
5320
|
+
|
|
5321
|
+
// src/proposals/action-proposal-worker.service.ts
|
|
5322
|
+
var import_node_crypto2 = require("crypto");
|
|
5323
|
+
var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
|
|
5324
|
+
var import_common25 = require("@nestjs/common");
|
|
5325
|
+
function _ts_decorate24(decorators, target, key, desc) {
|
|
5326
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5327
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5328
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5329
|
+
} else {
|
|
5330
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
5331
|
+
if (d = decorators[i]) {
|
|
5332
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5333
|
+
}
|
|
5334
|
+
}
|
|
5335
|
+
}
|
|
5336
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5337
|
+
}
|
|
5338
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
5339
|
+
function _ts_metadata23(metadataKey, metadataValue) {
|
|
5340
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5341
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
__name(_ts_metadata23, "_ts_metadata");
|
|
5345
|
+
function _ts_param23(paramIndex, decorator) {
|
|
5346
|
+
return function(target, key) {
|
|
5347
|
+
decorator(target, key, paramIndex);
|
|
5348
|
+
};
|
|
5349
|
+
}
|
|
5350
|
+
__name(_ts_param23, "_ts_param");
|
|
5262
5351
|
var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
5263
5352
|
static {
|
|
5264
5353
|
__name(this, "ActionProposalWorkerService");
|
|
@@ -5267,7 +5356,7 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5267
5356
|
options;
|
|
5268
5357
|
deps;
|
|
5269
5358
|
worker;
|
|
5270
|
-
logger = new
|
|
5359
|
+
logger = new import_common25.Logger(_ActionProposalWorkerService.name);
|
|
5271
5360
|
settledListeners = /* @__PURE__ */ new Set();
|
|
5272
5361
|
/**
|
|
5273
5362
|
* Run `listener` after every proposal this process's worker settles — how a module relays an
|
|
@@ -5303,16 +5392,16 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5303
5392
|
}
|
|
5304
5393
|
onModuleInit() {
|
|
5305
5394
|
if (this.options.actionApprovalMode !== "independent") return;
|
|
5306
|
-
(0,
|
|
5395
|
+
(0, import_nestjs_agent_core30.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
|
|
5307
5396
|
if (this.options.surface === "http") return;
|
|
5308
5397
|
const resolver = this.options.backgroundActorResolver;
|
|
5309
5398
|
if (!resolver) throw new Error("BackgroundActorResolver is required");
|
|
5310
|
-
this.worker = new
|
|
5399
|
+
this.worker = new import_nestjs_agent_core30.ActionProposalWorker({
|
|
5311
5400
|
store: this.store,
|
|
5312
5401
|
workerId: (0, import_node_crypto2.randomUUID)(),
|
|
5313
5402
|
...this.options.actionProposalWorker,
|
|
5314
5403
|
onSettled: /* @__PURE__ */ __name((proposal) => this.settled(proposal), "onSettled"),
|
|
5315
|
-
executor: new
|
|
5404
|
+
executor: new import_nestjs_agent_core30.ActionProposalExecutor({
|
|
5316
5405
|
resolver,
|
|
5317
5406
|
resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
|
|
5318
5407
|
const deps = this.deps.forProposal(proposal, actor);
|
|
@@ -5336,13 +5425,13 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5336
5425
|
await this.worker?.stop();
|
|
5337
5426
|
}
|
|
5338
5427
|
};
|
|
5339
|
-
ActionProposalWorkerService =
|
|
5340
|
-
(0,
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5428
|
+
ActionProposalWorkerService = _ts_decorate24([
|
|
5429
|
+
(0, import_common25.Injectable)(),
|
|
5430
|
+
_ts_param23(0, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_STORE)),
|
|
5431
|
+
_ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_OPTIONS)),
|
|
5432
|
+
_ts_param23(2, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_DEPS_FACTORY)),
|
|
5433
|
+
_ts_metadata23("design:type", Function),
|
|
5434
|
+
_ts_metadata23("design:paramtypes", [
|
|
5346
5435
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
5347
5436
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
5348
5437
|
typeof AgentDepsFactory2 === "undefined" ? Object : AgentDepsFactory2
|
|
@@ -5350,9 +5439,9 @@ ActionProposalWorkerService = _ts_decorate23([
|
|
|
5350
5439
|
], ActionProposalWorkerService);
|
|
5351
5440
|
|
|
5352
5441
|
// src/proposals/action-proposal.controller.ts
|
|
5353
|
-
var
|
|
5354
|
-
var
|
|
5355
|
-
function
|
|
5442
|
+
var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
|
|
5443
|
+
var import_common26 = require("@nestjs/common");
|
|
5444
|
+
function _ts_decorate25(decorators, target, key, desc) {
|
|
5356
5445
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5357
5446
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5358
5447
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5365,24 +5454,24 @@ function _ts_decorate24(decorators, target, key, desc) {
|
|
|
5365
5454
|
}
|
|
5366
5455
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5367
5456
|
}
|
|
5368
|
-
__name(
|
|
5369
|
-
function
|
|
5457
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
5458
|
+
function _ts_metadata24(metadataKey, metadataValue) {
|
|
5370
5459
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5371
5460
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
5372
5461
|
}
|
|
5373
5462
|
}
|
|
5374
|
-
__name(
|
|
5375
|
-
function
|
|
5463
|
+
__name(_ts_metadata24, "_ts_metadata");
|
|
5464
|
+
function _ts_param24(paramIndex, decorator) {
|
|
5376
5465
|
return function(target, key) {
|
|
5377
5466
|
decorator(target, key, paramIndex);
|
|
5378
5467
|
};
|
|
5379
5468
|
}
|
|
5380
|
-
__name(
|
|
5469
|
+
__name(_ts_param24, "_ts_param");
|
|
5381
5470
|
function bodyFields(body, field2) {
|
|
5382
5471
|
if (body === void 0) return {};
|
|
5383
|
-
if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field2)) throw new
|
|
5472
|
+
if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field2)) throw new import_common26.BadRequestException(`Only ${field2} is accepted`);
|
|
5384
5473
|
const value = body;
|
|
5385
|
-
if (value[field2] !== void 0 && (field2 === "remember" && typeof value[field2] !== "boolean" || field2 === "reason" && typeof value[field2] !== "string")) throw new
|
|
5474
|
+
if (value[field2] !== void 0 && (field2 === "remember" && typeof value[field2] !== "boolean" || field2 === "reason" && typeof value[field2] !== "string")) throw new import_common26.BadRequestException(`Invalid ${field2}`);
|
|
5386
5475
|
return value;
|
|
5387
5476
|
}
|
|
5388
5477
|
__name(bodyFields, "bodyFields");
|
|
@@ -5404,9 +5493,9 @@ var ActionProposalController = class {
|
|
|
5404
5493
|
query = {
|
|
5405
5494
|
after: JSON.parse(cursor)
|
|
5406
5495
|
};
|
|
5407
|
-
(0,
|
|
5496
|
+
(0, import_nestjs_agent_core31.validateActionProposalListQuery)(query);
|
|
5408
5497
|
} catch {
|
|
5409
|
-
throw new
|
|
5498
|
+
throw new import_common26.BadRequestException("Invalid action proposal cursor");
|
|
5410
5499
|
}
|
|
5411
5500
|
}
|
|
5412
5501
|
const page = await this.proposals.listPage(threadId, await this.actors.resolve(request), query);
|
|
@@ -5436,58 +5525,58 @@ var ActionProposalController = class {
|
|
|
5436
5525
|
});
|
|
5437
5526
|
}
|
|
5438
5527
|
};
|
|
5439
|
-
|
|
5440
|
-
(0,
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5528
|
+
_ts_decorate25([
|
|
5529
|
+
(0, import_common26.Get)(),
|
|
5530
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5531
|
+
_ts_param24(1, (0, import_common26.Req)()),
|
|
5532
|
+
_ts_param24(2, (0, import_common26.Query)("after")),
|
|
5533
|
+
_ts_param24(3, (0, import_common26.Res)({
|
|
5445
5534
|
passthrough: true
|
|
5446
5535
|
})),
|
|
5447
|
-
|
|
5448
|
-
|
|
5536
|
+
_ts_metadata24("design:type", Function),
|
|
5537
|
+
_ts_metadata24("design:paramtypes", [
|
|
5449
5538
|
String,
|
|
5450
5539
|
typeof Request === "undefined" ? Object : Request,
|
|
5451
5540
|
Object,
|
|
5452
5541
|
typeof Response === "undefined" ? Object : Response
|
|
5453
5542
|
]),
|
|
5454
|
-
|
|
5543
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5455
5544
|
], ActionProposalController.prototype, "list", null);
|
|
5456
|
-
|
|
5457
|
-
(0,
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5545
|
+
_ts_decorate25([
|
|
5546
|
+
(0, import_common26.Post)(":proposalId/approve"),
|
|
5547
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5548
|
+
_ts_param24(1, (0, import_common26.Param)("proposalId")),
|
|
5549
|
+
_ts_param24(2, (0, import_common26.Req)()),
|
|
5550
|
+
_ts_param24(3, (0, import_common26.Body)()),
|
|
5551
|
+
_ts_metadata24("design:type", Function),
|
|
5552
|
+
_ts_metadata24("design:paramtypes", [
|
|
5464
5553
|
String,
|
|
5465
5554
|
String,
|
|
5466
5555
|
typeof Request === "undefined" ? Object : Request,
|
|
5467
5556
|
Object
|
|
5468
5557
|
]),
|
|
5469
|
-
|
|
5558
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5470
5559
|
], ActionProposalController.prototype, "approve", null);
|
|
5471
|
-
|
|
5472
|
-
(0,
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5560
|
+
_ts_decorate25([
|
|
5561
|
+
(0, import_common26.Post)(":proposalId/reject"),
|
|
5562
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5563
|
+
_ts_param24(1, (0, import_common26.Param)("proposalId")),
|
|
5564
|
+
_ts_param24(2, (0, import_common26.Req)()),
|
|
5565
|
+
_ts_param24(3, (0, import_common26.Body)()),
|
|
5566
|
+
_ts_metadata24("design:type", Function),
|
|
5567
|
+
_ts_metadata24("design:paramtypes", [
|
|
5479
5568
|
String,
|
|
5480
5569
|
String,
|
|
5481
5570
|
typeof Request === "undefined" ? Object : Request,
|
|
5482
5571
|
Object
|
|
5483
5572
|
]),
|
|
5484
|
-
|
|
5573
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5485
5574
|
], ActionProposalController.prototype, "reject", null);
|
|
5486
|
-
ActionProposalController =
|
|
5487
|
-
(0,
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5575
|
+
ActionProposalController = _ts_decorate25([
|
|
5576
|
+
(0, import_common26.Controller)("threads/:threadId/action-proposals"),
|
|
5577
|
+
_ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER)),
|
|
5578
|
+
_ts_metadata24("design:type", Function),
|
|
5579
|
+
_ts_metadata24("design:paramtypes", [
|
|
5491
5580
|
typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
|
|
5492
5581
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
5493
5582
|
])
|
|
@@ -5497,9 +5586,9 @@ ActionProposalController = _ts_decorate24([
|
|
|
5497
5586
|
var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
|
|
5498
5587
|
|
|
5499
5588
|
// src/runner/inline-agent-runner.ts
|
|
5500
|
-
var
|
|
5501
|
-
var
|
|
5502
|
-
function
|
|
5589
|
+
var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
|
|
5590
|
+
var import_common27 = require("@nestjs/common");
|
|
5591
|
+
function _ts_decorate26(decorators, target, key, desc) {
|
|
5503
5592
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5504
5593
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5505
5594
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5512,19 +5601,19 @@ function _ts_decorate25(decorators, target, key, desc) {
|
|
|
5512
5601
|
}
|
|
5513
5602
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5514
5603
|
}
|
|
5515
|
-
__name(
|
|
5516
|
-
function
|
|
5604
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
5605
|
+
function _ts_metadata25(metadataKey, metadataValue) {
|
|
5517
5606
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5518
5607
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
5519
5608
|
}
|
|
5520
5609
|
}
|
|
5521
|
-
__name(
|
|
5522
|
-
function
|
|
5610
|
+
__name(_ts_metadata25, "_ts_metadata");
|
|
5611
|
+
function _ts_param25(paramIndex, decorator) {
|
|
5523
5612
|
return function(target, key) {
|
|
5524
5613
|
decorator(target, key, paramIndex);
|
|
5525
5614
|
};
|
|
5526
5615
|
}
|
|
5527
|
-
__name(
|
|
5616
|
+
__name(_ts_param25, "_ts_param");
|
|
5528
5617
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
5529
5618
|
static {
|
|
5530
5619
|
__name(this, "InlineAgentRunner");
|
|
@@ -5532,7 +5621,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5532
5621
|
factory;
|
|
5533
5622
|
store;
|
|
5534
5623
|
queue;
|
|
5535
|
-
logger = new
|
|
5624
|
+
logger = new import_common27.Logger(_InlineAgentRunner.name);
|
|
5536
5625
|
pending = /* @__PURE__ */ new Map();
|
|
5537
5626
|
/**
|
|
5538
5627
|
* Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
|
|
@@ -5586,18 +5675,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5586
5675
|
],
|
|
5587
5676
|
input
|
|
5588
5677
|
});
|
|
5589
|
-
void (0,
|
|
5678
|
+
void (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5590
5679
|
...deps,
|
|
5591
5680
|
day
|
|
5592
|
-
}, input, hooks).then(() => (0,
|
|
5593
|
-
if (error instanceof
|
|
5681
|
+
}, input, hooks).then(() => (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
|
|
5682
|
+
if (error instanceof import_nestjs_agent_core32.RunCancelledError) {
|
|
5594
5683
|
await this.settleCancelled(runId, input, deps);
|
|
5595
5684
|
return;
|
|
5596
5685
|
}
|
|
5597
5686
|
const message = error instanceof Error ? error.message : String(error);
|
|
5598
|
-
const code = (0,
|
|
5687
|
+
const code = (0, import_nestjs_agent_core32.agentFailureCode)(error);
|
|
5599
5688
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
5600
|
-
(0,
|
|
5689
|
+
(0, import_nestjs_agent_core32.publishAgentRunFailed)({
|
|
5601
5690
|
runId,
|
|
5602
5691
|
code,
|
|
5603
5692
|
message
|
|
@@ -5608,11 +5697,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5608
5697
|
errorCode: code,
|
|
5609
5698
|
errorMessage: message
|
|
5610
5699
|
});
|
|
5611
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5700
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core32.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
5612
5701
|
const writer = await deps.sink.open(runId);
|
|
5613
5702
|
await this.settleQueue(writer, input, runId, "failed", message);
|
|
5614
|
-
await (0,
|
|
5615
|
-
await writer.fail((0,
|
|
5703
|
+
await (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5704
|
+
await writer.fail((0, import_nestjs_agent_core32.streamFailure)(error));
|
|
5616
5705
|
}).finally(() => {
|
|
5617
5706
|
this.forgetCancel(runId);
|
|
5618
5707
|
this.live.delete(runId);
|
|
@@ -5647,11 +5736,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5647
5736
|
*/
|
|
5648
5737
|
async cancel(runId) {
|
|
5649
5738
|
this.cancelled.add(runId);
|
|
5650
|
-
this.aborts.get(runId)?.abort(new
|
|
5739
|
+
this.aborts.get(runId)?.abort(new import_nestjs_agent_core32.RunCancelledError());
|
|
5651
5740
|
for (const [key, waiter] of this.pending) {
|
|
5652
5741
|
if (key.startsWith(`${runId}:`)) {
|
|
5653
5742
|
this.pending.delete(key);
|
|
5654
|
-
waiter.reject(new
|
|
5743
|
+
waiter.reject(new import_nestjs_agent_core32.RunCancelledError());
|
|
5655
5744
|
}
|
|
5656
5745
|
}
|
|
5657
5746
|
await Promise.resolve();
|
|
@@ -5680,8 +5769,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5680
5769
|
this.logger.log(`agent run ${runId} cancelled`);
|
|
5681
5770
|
const writer = await deps.sink.open(runId);
|
|
5682
5771
|
await this.settleQueue(writer, input, runId, "cancelled");
|
|
5683
|
-
await (0,
|
|
5684
|
-
await writer.write((0,
|
|
5772
|
+
await (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5773
|
+
await writer.write((0, import_nestjs_agent_core32.encodeStreamEvent)({
|
|
5685
5774
|
kind: "cancelled"
|
|
5686
5775
|
}));
|
|
5687
5776
|
await writer.end();
|
|
@@ -5716,7 +5805,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5716
5805
|
runId: nextRunId
|
|
5717
5806
|
}));
|
|
5718
5807
|
if (frame !== void 0) {
|
|
5719
|
-
await writer.write((0,
|
|
5808
|
+
await writer.write((0, import_nestjs_agent_core32.encodeStreamEvent)(frame));
|
|
5720
5809
|
}
|
|
5721
5810
|
} catch (failure) {
|
|
5722
5811
|
this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
@@ -5787,7 +5876,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5787
5876
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5788
5877
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5789
5878
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5790
|
-
parallel:
|
|
5879
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5791
5880
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5792
5881
|
abortSignal: this.abortSignalFor(runId),
|
|
5793
5882
|
runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
|
|
@@ -5839,7 +5928,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5839
5928
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5840
5929
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5841
5930
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5842
|
-
parallel:
|
|
5931
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5843
5932
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5844
5933
|
abortSignal: this.abortSignalFor(runId),
|
|
5845
5934
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
|
|
@@ -5873,7 +5962,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5873
5962
|
}
|
|
5874
5963
|
}), "startAgent")
|
|
5875
5964
|
};
|
|
5876
|
-
void (0,
|
|
5965
|
+
void (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5877
5966
|
...deps,
|
|
5878
5967
|
day
|
|
5879
5968
|
}, {
|
|
@@ -5887,13 +5976,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5887
5976
|
parentRunId,
|
|
5888
5977
|
deliverTo
|
|
5889
5978
|
}, hooks).catch(async (error) => {
|
|
5890
|
-
const cancelled = error instanceof
|
|
5979
|
+
const cancelled = error instanceof import_nestjs_agent_core32.RunCancelledError;
|
|
5891
5980
|
const message = error instanceof Error ? error.message : String(error);
|
|
5892
5981
|
if (!cancelled) {
|
|
5893
5982
|
this.logger.error(`detached agent run ${runId} failed: ${message}`);
|
|
5894
|
-
(0,
|
|
5983
|
+
(0, import_nestjs_agent_core32.publishAgentRunFailed)({
|
|
5895
5984
|
runId,
|
|
5896
|
-
code: (0,
|
|
5985
|
+
code: (0, import_nestjs_agent_core32.agentFailureCode)(error),
|
|
5897
5986
|
message
|
|
5898
5987
|
});
|
|
5899
5988
|
}
|
|
@@ -5901,12 +5990,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5901
5990
|
runId,
|
|
5902
5991
|
status: cancelled ? "cancelled" : "failed",
|
|
5903
5992
|
...cancelled ? {} : {
|
|
5904
|
-
errorCode: (0,
|
|
5993
|
+
errorCode: (0, import_nestjs_agent_core32.agentFailureCode)(error),
|
|
5905
5994
|
errorMessage: message
|
|
5906
5995
|
}
|
|
5907
5996
|
});
|
|
5908
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5909
|
-
await (0,
|
|
5997
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core32.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
5998
|
+
await (0, import_nestjs_agent_core32.settleUnsettledDelegation)({
|
|
5910
5999
|
store: this.store,
|
|
5911
6000
|
delivery: deliverTo,
|
|
5912
6001
|
agent: agentName,
|
|
@@ -5945,7 +6034,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5945
6034
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5946
6035
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5947
6036
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5948
|
-
parallel:
|
|
6037
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5949
6038
|
// A child stops when it is cancelled OR when the run a human is actually watching is: the
|
|
5950
6039
|
// canceller names the top-level run, which is the only id that ever left the server.
|
|
5951
6040
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
|
|
@@ -5982,7 +6071,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5982
6071
|
}), "startAgent")
|
|
5983
6072
|
};
|
|
5984
6073
|
try {
|
|
5985
|
-
return await (0,
|
|
6074
|
+
return await (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5986
6075
|
...deps,
|
|
5987
6076
|
day
|
|
5988
6077
|
}, {
|
|
@@ -6001,13 +6090,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6001
6090
|
}
|
|
6002
6091
|
}
|
|
6003
6092
|
};
|
|
6004
|
-
InlineAgentRunner =
|
|
6005
|
-
(0,
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6093
|
+
InlineAgentRunner = _ts_decorate26([
|
|
6094
|
+
(0, import_common27.Injectable)(),
|
|
6095
|
+
_ts_param25(0, (0, import_common27.Inject)(import_nestjs_agent_core32.AGENT_DEPS_FACTORY)),
|
|
6096
|
+
_ts_param25(1, (0, import_common27.Inject)(import_nestjs_agent_core32.AGENT_STORE)),
|
|
6097
|
+
_ts_param25(2, (0, import_common27.Optional)()),
|
|
6098
|
+
_ts_metadata25("design:type", Function),
|
|
6099
|
+
_ts_metadata25("design:paramtypes", [
|
|
6011
6100
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
6012
6101
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
6013
6102
|
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
@@ -6019,7 +6108,7 @@ function isThreadTurn(input) {
|
|
|
6019
6108
|
__name(isThreadTurn, "isThreadTurn");
|
|
6020
6109
|
|
|
6021
6110
|
// src/skills-config.ts
|
|
6022
|
-
var
|
|
6111
|
+
var import_nestjs_agent_core33 = require("@dudousxd/nestjs-agent-core");
|
|
6023
6112
|
function declaredSkillProvider(declared) {
|
|
6024
6113
|
return {
|
|
6025
6114
|
list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
|
|
@@ -6045,7 +6134,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
6045
6134
|
declaredSkillProvider(declared)
|
|
6046
6135
|
];
|
|
6047
6136
|
return {
|
|
6048
|
-
provider: providers.length === 1 ? providers[0] : (0,
|
|
6137
|
+
provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core33.compositeSkillProvider)(providers),
|
|
6049
6138
|
...options.scopes !== void 0 ? {
|
|
6050
6139
|
scopes: options.scopes
|
|
6051
6140
|
} : {},
|
|
@@ -6057,7 +6146,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
6057
6146
|
__name(resolveSkillsConfig, "resolveSkillsConfig");
|
|
6058
6147
|
|
|
6059
6148
|
// src/agent.module.ts
|
|
6060
|
-
function
|
|
6149
|
+
function _ts_decorate27(decorators, target, key, desc) {
|
|
6061
6150
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6062
6151
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
6063
6152
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6070,9 +6159,9 @@ function _ts_decorate26(decorators, target, key, desc) {
|
|
|
6070
6159
|
}
|
|
6071
6160
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6072
6161
|
}
|
|
6073
|
-
__name(
|
|
6162
|
+
__name(_ts_decorate27, "_ts_decorate");
|
|
6074
6163
|
var DEFAULT_PATH = "agent";
|
|
6075
|
-
var
|
|
6164
|
+
var logger2 = new import_common28.Logger("AgentModule");
|
|
6076
6165
|
function externalWrapper(modules, token) {
|
|
6077
6166
|
for (const module2 of modules.values()) {
|
|
6078
6167
|
if (module2.metatype === AgentModule) continue;
|
|
@@ -6104,22 +6193,22 @@ function forwardingStore(wrapper) {
|
|
|
6104
6193
|
__name(forwardingStore, "forwardingStore");
|
|
6105
6194
|
function resolveStore(options, modules) {
|
|
6106
6195
|
if (options.store !== void 0) return options.store;
|
|
6107
|
-
const external = externalWrapper(modules,
|
|
6196
|
+
const external = externalWrapper(modules, import_nestjs_agent_core34.AGENT_STORE);
|
|
6108
6197
|
if (external !== void 0) return forwardingStore(external);
|
|
6109
|
-
|
|
6110
|
-
return new
|
|
6198
|
+
logger2.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
|
|
6199
|
+
return new import_nestjs_agent_core34.InMemoryAgentStore();
|
|
6111
6200
|
}
|
|
6112
6201
|
__name(resolveStore, "resolveStore");
|
|
6113
6202
|
function resolveRolesPolicy(options, modules) {
|
|
6114
|
-
const external = externalWrapper(modules,
|
|
6203
|
+
const external = externalWrapper(modules, import_nestjs_agent_core34.AGENT_ROLES_POLICY);
|
|
6115
6204
|
if (options.rolesPolicy !== void 0) {
|
|
6116
6205
|
if (external !== void 0) {
|
|
6117
|
-
|
|
6206
|
+
logger2.warn("Both a `rolesPolicy` option and a module binding AGENT_ROLES_POLICY (e.g. AgentAuthzModule) are configured \u2014 the `rolesPolicy` option wins.");
|
|
6118
6207
|
}
|
|
6119
6208
|
return options.rolesPolicy;
|
|
6120
6209
|
}
|
|
6121
6210
|
if (external !== void 0) return forwardingPolicy(external);
|
|
6122
|
-
return options.emptyRoles === "deny" ? new
|
|
6211
|
+
return options.emptyRoles === "deny" ? new import_nestjs_agent_core34.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core34.DefaultRolesPolicy(options.defaultRoles);
|
|
6123
6212
|
}
|
|
6124
6213
|
__name(resolveRolesPolicy, "resolveRolesPolicy");
|
|
6125
6214
|
function forwardingPolicy(wrapper) {
|
|
@@ -6147,102 +6236,105 @@ __name(resolveCatalog, "resolveCatalog");
|
|
|
6147
6236
|
function sharedProviders(durable, engine) {
|
|
6148
6237
|
const providers = [
|
|
6149
6238
|
{
|
|
6150
|
-
provide:
|
|
6151
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
6239
|
+
provide: import_nestjs_agent_core34.AGENT_TOOL_REGISTRY,
|
|
6240
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core34.ToolRegistry(), "useFactory")
|
|
6152
6241
|
},
|
|
6153
6242
|
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
6154
6243
|
{
|
|
6155
|
-
provide:
|
|
6156
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
6244
|
+
provide: import_nestjs_agent_core34.AGENT_REGISTRY,
|
|
6245
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core34.AgentRegistry(), "useFactory")
|
|
6157
6246
|
},
|
|
6158
6247
|
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
6159
6248
|
{
|
|
6160
|
-
provide:
|
|
6249
|
+
provide: import_nestjs_agent_core34.AGENT_PROMPT_CONTRIBUTORS,
|
|
6161
6250
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
6162
6251
|
},
|
|
6163
6252
|
// Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
|
|
6164
6253
|
// read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
|
|
6165
6254
|
{
|
|
6166
|
-
provide:
|
|
6255
|
+
provide: import_nestjs_agent_core34.AGENT_SKILL_SOURCES,
|
|
6167
6256
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
6168
6257
|
},
|
|
6169
6258
|
{
|
|
6170
6259
|
// One resolution, shared by the loop's deps and the listing endpoint: a second one would
|
|
6171
6260
|
// drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
|
|
6172
6261
|
// host configured none — which is what keeps the turn's checkpoint sequence unchanged.
|
|
6173
|
-
provide:
|
|
6262
|
+
provide: import_nestjs_agent_core34.AGENT_SKILLS,
|
|
6174
6263
|
useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
|
|
6175
6264
|
inject: [
|
|
6176
|
-
|
|
6177
|
-
|
|
6265
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6266
|
+
import_nestjs_agent_core34.AGENT_SKILL_SOURCES
|
|
6178
6267
|
]
|
|
6179
6268
|
},
|
|
6180
6269
|
{
|
|
6181
6270
|
// One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
|
|
6182
6271
|
// shown what the model was shown, and two resolutions would eventually disagree about that.
|
|
6183
|
-
provide:
|
|
6272
|
+
provide: import_nestjs_agent_core34.AGENT_MEMORY,
|
|
6184
6273
|
useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
|
|
6185
6274
|
inject: [
|
|
6186
|
-
|
|
6275
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6187
6276
|
]
|
|
6188
6277
|
},
|
|
6189
6278
|
{
|
|
6190
|
-
provide:
|
|
6279
|
+
provide: import_nestjs_agent_core34.AGENT_SINK,
|
|
6191
6280
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
6192
6281
|
inject: [
|
|
6193
|
-
|
|
6282
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6194
6283
|
]
|
|
6195
6284
|
},
|
|
6196
6285
|
{
|
|
6197
|
-
provide:
|
|
6286
|
+
provide: import_nestjs_agent_core34.AGENT_ROLES_POLICY,
|
|
6198
6287
|
useFactory: /* @__PURE__ */ __name((options, modules) => resolveRolesPolicy(options, modules), "useFactory"),
|
|
6199
6288
|
inject: [
|
|
6200
|
-
|
|
6289
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6201
6290
|
import_core4.ModulesContainer
|
|
6202
6291
|
]
|
|
6203
6292
|
},
|
|
6204
6293
|
{
|
|
6205
|
-
provide:
|
|
6294
|
+
provide: import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER,
|
|
6206
6295
|
useFactory: /* @__PURE__ */ __name((options) => {
|
|
6207
6296
|
if (options.actorResolver !== void 0) return options.actorResolver;
|
|
6208
|
-
|
|
6297
|
+
logger2.warn("No `actorResolver` configured \u2014 the agent endpoints are PUBLIC: every browser gets its own anonymous identity (an HttpOnly cookie). Set `actorResolver: requestUserActorResolver()` (or your own) to require login.");
|
|
6209
6298
|
return new AnonymousActorResolver();
|
|
6210
6299
|
}, "useFactory"),
|
|
6211
6300
|
inject: [
|
|
6212
|
-
|
|
6301
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6213
6302
|
]
|
|
6214
6303
|
},
|
|
6215
6304
|
{
|
|
6216
|
-
provide:
|
|
6305
|
+
provide: import_nestjs_agent_core34.AGENT_MODEL,
|
|
6217
6306
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
6218
6307
|
inject: [
|
|
6219
|
-
|
|
6308
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6220
6309
|
]
|
|
6221
6310
|
},
|
|
6222
6311
|
{
|
|
6223
6312
|
// `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
|
|
6224
6313
|
// omitted, the ledger provider still reports usage, with no ceiling to block on.
|
|
6225
|
-
provide:
|
|
6314
|
+
provide: import_nestjs_agent_core34.AGENT_QUOTA_PROVIDER,
|
|
6226
6315
|
useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
|
|
6227
6316
|
warnAt: o.quota.warnAt
|
|
6228
6317
|
} : {}), "useFactory"),
|
|
6229
6318
|
inject: [
|
|
6230
|
-
|
|
6231
|
-
|
|
6319
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6320
|
+
import_nestjs_agent_core34.AGENT_STORE
|
|
6232
6321
|
]
|
|
6233
6322
|
},
|
|
6234
6323
|
{
|
|
6235
|
-
provide:
|
|
6324
|
+
provide: import_nestjs_agent_core34.AGENT_MODEL_CATALOG,
|
|
6236
6325
|
useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
|
|
6237
6326
|
inject: [
|
|
6238
|
-
|
|
6327
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6239
6328
|
]
|
|
6240
6329
|
},
|
|
6241
6330
|
AgentDepsFactory2,
|
|
6242
6331
|
{
|
|
6243
|
-
provide:
|
|
6332
|
+
provide: import_nestjs_agent_core34.AGENT_DEPS_FACTORY,
|
|
6244
6333
|
useExisting: AgentDepsFactory2
|
|
6245
6334
|
},
|
|
6335
|
+
// Seeds a configured model's missing price row from models.dev and warns about one that would
|
|
6336
|
+
// record no cost (`priceCatalog`), once the app has bootstrapped.
|
|
6337
|
+
PricingBootService,
|
|
6246
6338
|
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
6247
6339
|
// handoff tools (onApplicationBootstrap) reads the registry.
|
|
6248
6340
|
AgentDiscoveryService,
|
|
@@ -6263,26 +6355,26 @@ function sharedProviders(durable, engine) {
|
|
|
6263
6355
|
// through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
|
|
6264
6356
|
AgentApprovalPortAdapter,
|
|
6265
6357
|
{
|
|
6266
|
-
provide:
|
|
6358
|
+
provide: import_nestjs_agent_core34.AGENT_APPROVAL_PORT,
|
|
6267
6359
|
useExisting: AgentApprovalPortAdapter
|
|
6268
6360
|
}
|
|
6269
6361
|
];
|
|
6270
6362
|
providers.push({
|
|
6271
|
-
provide:
|
|
6363
|
+
provide: import_nestjs_agent_core34.AGENT_STORE,
|
|
6272
6364
|
useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
|
|
6273
6365
|
inject: [
|
|
6274
|
-
|
|
6366
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6275
6367
|
import_core4.ModulesContainer
|
|
6276
6368
|
]
|
|
6277
6369
|
});
|
|
6278
6370
|
if (engine !== void 0) {
|
|
6279
6371
|
providers.push(...engine.providers, {
|
|
6280
|
-
provide:
|
|
6372
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6281
6373
|
useExisting: engine.runner
|
|
6282
6374
|
});
|
|
6283
6375
|
} else if (durable) {
|
|
6284
6376
|
providers.push({
|
|
6285
|
-
provide:
|
|
6377
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6286
6378
|
useFactory: /* @__PURE__ */ __name((durableRunner) => {
|
|
6287
6379
|
if (durableRunner === void 0) {
|
|
6288
6380
|
throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
|
|
@@ -6291,14 +6383,14 @@ function sharedProviders(durable, engine) {
|
|
|
6291
6383
|
}, "useFactory"),
|
|
6292
6384
|
inject: [
|
|
6293
6385
|
{
|
|
6294
|
-
token:
|
|
6386
|
+
token: import_nestjs_agent_core34.AGENT_DURABLE_RUNNER,
|
|
6295
6387
|
optional: true
|
|
6296
6388
|
}
|
|
6297
6389
|
]
|
|
6298
6390
|
});
|
|
6299
6391
|
} else {
|
|
6300
6392
|
providers.push({
|
|
6301
|
-
provide:
|
|
6393
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6302
6394
|
useExisting: InlineAgentRunner
|
|
6303
6395
|
});
|
|
6304
6396
|
}
|
|
@@ -6308,20 +6400,20 @@ __name(sharedProviders, "sharedProviders");
|
|
|
6308
6400
|
function exportsFor(engine) {
|
|
6309
6401
|
return [
|
|
6310
6402
|
...engine?.exports ?? [],
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6403
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6404
|
+
import_nestjs_agent_core34.AGENT_TOOL_REGISTRY,
|
|
6405
|
+
import_nestjs_agent_core34.AGENT_REGISTRY,
|
|
6406
|
+
import_nestjs_agent_core34.AGENT_SINK,
|
|
6407
|
+
import_nestjs_agent_core34.AGENT_ROLES_POLICY,
|
|
6408
|
+
import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER,
|
|
6409
|
+
import_nestjs_agent_core34.AGENT_MODEL,
|
|
6410
|
+
import_nestjs_agent_core34.AGENT_STORE,
|
|
6411
|
+
import_nestjs_agent_core34.AGENT_MODEL_CATALOG,
|
|
6412
|
+
import_nestjs_agent_core34.AGENT_QUOTA_PROVIDER,
|
|
6413
|
+
import_nestjs_agent_core34.AGENT_PROMPT_CONTRIBUTORS,
|
|
6414
|
+
import_nestjs_agent_core34.AGENT_SKILLS,
|
|
6415
|
+
import_nestjs_agent_core34.AGENT_MEMORY,
|
|
6416
|
+
import_nestjs_agent_core34.AGENT_DEPS_FACTORY,
|
|
6325
6417
|
AgentDepsFactory2,
|
|
6326
6418
|
AgentService,
|
|
6327
6419
|
ActionProposalService,
|
|
@@ -6329,7 +6421,7 @@ function exportsFor(engine) {
|
|
|
6329
6421
|
ChatQueueService,
|
|
6330
6422
|
AGENT_CHAT_QUEUE,
|
|
6331
6423
|
InlineAgentRunner,
|
|
6332
|
-
|
|
6424
|
+
import_nestjs_agent_core34.AGENT_APPROVAL_PORT
|
|
6333
6425
|
];
|
|
6334
6426
|
}
|
|
6335
6427
|
__name(exportsFor, "exportsFor");
|
|
@@ -6418,7 +6510,7 @@ var AgentModule = class _AgentModule {
|
|
|
6418
6510
|
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6419
6511
|
providers: [
|
|
6420
6512
|
{
|
|
6421
|
-
provide:
|
|
6513
|
+
provide: import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6422
6514
|
useValue: options
|
|
6423
6515
|
},
|
|
6424
6516
|
...sharedProviders(options.durable ?? false, options.engine),
|
|
@@ -6448,7 +6540,7 @@ var AgentModule = class _AgentModule {
|
|
|
6448
6540
|
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6449
6541
|
providers: [
|
|
6450
6542
|
{
|
|
6451
|
-
provide:
|
|
6543
|
+
provide: import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6452
6544
|
// Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
|
|
6453
6545
|
// authoritative on the async config object (they decided the actual wiring above), and
|
|
6454
6546
|
// the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
|
|
@@ -6477,16 +6569,16 @@ var AgentModule = class _AgentModule {
|
|
|
6477
6569
|
};
|
|
6478
6570
|
}
|
|
6479
6571
|
};
|
|
6480
|
-
AgentModule =
|
|
6481
|
-
(0,
|
|
6482
|
-
(0,
|
|
6572
|
+
AgentModule = _ts_decorate27([
|
|
6573
|
+
(0, import_common28.Global)(),
|
|
6574
|
+
(0, import_common28.Module)({})
|
|
6483
6575
|
], AgentModule);
|
|
6484
6576
|
|
|
6485
6577
|
// src/ag-ui/ag-ui.adapter.ts
|
|
6486
|
-
var
|
|
6578
|
+
var import_nestjs_agent_core35 = require("@dudousxd/nestjs-agent-core");
|
|
6487
6579
|
var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
|
|
6488
|
-
var
|
|
6489
|
-
function
|
|
6580
|
+
var import_common29 = require("@nestjs/common");
|
|
6581
|
+
function _ts_decorate28(decorators, target, key, desc) {
|
|
6490
6582
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6491
6583
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
6492
6584
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6499,22 +6591,22 @@ function _ts_decorate27(decorators, target, key, desc) {
|
|
|
6499
6591
|
}
|
|
6500
6592
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6501
6593
|
}
|
|
6502
|
-
__name(
|
|
6503
|
-
function
|
|
6594
|
+
__name(_ts_decorate28, "_ts_decorate");
|
|
6595
|
+
function _ts_metadata26(metadataKey, metadataValue) {
|
|
6504
6596
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
6505
6597
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
6506
6598
|
}
|
|
6507
6599
|
}
|
|
6508
|
-
__name(
|
|
6509
|
-
function
|
|
6600
|
+
__name(_ts_metadata26, "_ts_metadata");
|
|
6601
|
+
function _ts_param26(paramIndex, decorator) {
|
|
6510
6602
|
return function(target, key) {
|
|
6511
6603
|
decorator(target, key, paramIndex);
|
|
6512
6604
|
};
|
|
6513
6605
|
}
|
|
6514
|
-
__name(
|
|
6606
|
+
__name(_ts_param26, "_ts_param");
|
|
6515
6607
|
var AG_UI_VIA = "ag-ui";
|
|
6516
6608
|
function invalid(code, message) {
|
|
6517
|
-
return new
|
|
6609
|
+
return new import_common29.BadRequestException({
|
|
6518
6610
|
statusCode: 400,
|
|
6519
6611
|
code,
|
|
6520
6612
|
message
|
|
@@ -6606,7 +6698,7 @@ var AgUiRunHandler = class {
|
|
|
6606
6698
|
warnings.push(...turn.dropped);
|
|
6607
6699
|
const owner = await this.agent.threadOwner(input.threadId);
|
|
6608
6700
|
if (owner !== null && owner !== actor.id) {
|
|
6609
|
-
throw new
|
|
6701
|
+
throw new import_common29.ForbiddenException("thread belongs to another actor");
|
|
6610
6702
|
}
|
|
6611
6703
|
if (forwarded.regenerate === true && owner === null) {
|
|
6612
6704
|
throw invalid("invalid_input", "regenerate needs a thread that already has an exchange");
|
|
@@ -6871,29 +6963,29 @@ function agUiAdapter(options = {}) {
|
|
|
6871
6963
|
return this.handle(req, res, body);
|
|
6872
6964
|
}
|
|
6873
6965
|
};
|
|
6874
|
-
|
|
6875
|
-
(0,
|
|
6876
|
-
(0,
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6966
|
+
_ts_decorate28([
|
|
6967
|
+
(0, import_common29.Post)(path),
|
|
6968
|
+
(0, import_common29.HttpCode)(200),
|
|
6969
|
+
_ts_param26(0, (0, import_common29.Req)()),
|
|
6970
|
+
_ts_param26(1, (0, import_common29.Res)()),
|
|
6971
|
+
_ts_param26(2, (0, import_common29.Body)()),
|
|
6972
|
+
_ts_metadata26("design:type", Function),
|
|
6973
|
+
_ts_metadata26("design:paramtypes", [
|
|
6882
6974
|
typeof Request === "undefined" ? Object : Request,
|
|
6883
6975
|
typeof Response === "undefined" ? Object : Response,
|
|
6884
6976
|
Object
|
|
6885
6977
|
]),
|
|
6886
|
-
|
|
6978
|
+
_ts_metadata26("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
6887
6979
|
], AgUiController.prototype, "run", null);
|
|
6888
|
-
AgUiController =
|
|
6889
|
-
(0,
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6980
|
+
AgUiController = _ts_decorate28([
|
|
6981
|
+
(0, import_common29.Controller)(),
|
|
6982
|
+
_ts_param26(0, (0, import_common29.Inject)(AgentService)),
|
|
6983
|
+
_ts_param26(1, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_ACTOR_RESOLVER)),
|
|
6984
|
+
_ts_param26(2, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_OPTIONS)),
|
|
6985
|
+
_ts_param26(3, (0, import_common29.Optional)()),
|
|
6986
|
+
_ts_param26(3, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_ATTACHMENT_STAGING)),
|
|
6987
|
+
_ts_metadata26("design:type", Function),
|
|
6988
|
+
_ts_metadata26("design:paramtypes", [
|
|
6897
6989
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
6898
6990
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
6899
6991
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -6910,7 +7002,7 @@ function agUiAdapter(options = {}) {
|
|
|
6910
7002
|
__name(agUiAdapter, "agUiAdapter");
|
|
6911
7003
|
|
|
6912
7004
|
// src/resolver/header-actor-resolver.ts
|
|
6913
|
-
var
|
|
7005
|
+
var import_common30 = require("@nestjs/common");
|
|
6914
7006
|
function readHeader(req, name) {
|
|
6915
7007
|
if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
|
|
6916
7008
|
const { headers } = req;
|
|
@@ -6926,7 +7018,7 @@ var HeaderActorResolver = class {
|
|
|
6926
7018
|
resolve(req) {
|
|
6927
7019
|
const id = readHeader(req, "x-actor-id");
|
|
6928
7020
|
if (id === void 0 || id.length === 0) {
|
|
6929
|
-
throw new
|
|
7021
|
+
throw new import_common30.UnauthorizedException("HeaderActorResolver: missing x-actor-id header. No default actor is fabricated. Send x-actor-id from a trusted gateway, or configure AgentModule.forRoot({ actorResolver }) with a resolver that reads your authenticated principal.");
|
|
6930
7022
|
}
|
|
6931
7023
|
const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
|
|
6932
7024
|
const tenantRef = readHeader(req, "x-tenant-ref");
|
|
@@ -6941,7 +7033,7 @@ var HeaderActorResolver = class {
|
|
|
6941
7033
|
};
|
|
6942
7034
|
|
|
6943
7035
|
// src/resolver/request-user-actor-resolver.ts
|
|
6944
|
-
var
|
|
7036
|
+
var import_common31 = require("@nestjs/common");
|
|
6945
7037
|
function field(user, ...names) {
|
|
6946
7038
|
for (const name of names) {
|
|
6947
7039
|
const value = user[name];
|
|
@@ -6953,7 +7045,7 @@ __name(field, "field");
|
|
|
6953
7045
|
function defaultRequestUserMapper(user) {
|
|
6954
7046
|
const id = field(user, "id", "sub", "_id", "userId");
|
|
6955
7047
|
if (id === void 0) {
|
|
6956
|
-
throw new
|
|
7048
|
+
throw new import_common31.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
|
|
6957
7049
|
}
|
|
6958
7050
|
const rawRoles = field(user, "roles", "role");
|
|
6959
7051
|
const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
|
|
@@ -6974,7 +7066,7 @@ function requestUserActorResolver(map) {
|
|
|
6974
7066
|
async resolve(req) {
|
|
6975
7067
|
const user = typeof req === "object" && req !== null ? req.user : void 0;
|
|
6976
7068
|
if (user === void 0 || user === null || user === false) {
|
|
6977
|
-
throw new
|
|
7069
|
+
throw new import_common31.UnauthorizedException("Sign in to use the agent.");
|
|
6978
7070
|
}
|
|
6979
7071
|
if (map !== void 0) return map(user, req);
|
|
6980
7072
|
return defaultRequestUserMapper(user);
|