@dudousxd/nestjs-agent 1.25.2 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -0
- package/dist/{chat-queue.service-Crf9uwum.d.cts → chat-queue.service-Cu2nJpXz.d.cts} +44 -1
- package/dist/{chat-queue.service-ZQkqb1Yw.d.ts → chat-queue.service-uD1vR8fs.d.ts} +44 -1
- package/dist/durable/index.cjs +273 -169
- 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 +195 -91
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +306 -202
- 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 +218 -114
- 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
|
|
@@ -5190,7 +5190,7 @@ var LedgerQuotaProvider = class {
|
|
|
5190
5190
|
if (this.store.usageBetween !== void 0) {
|
|
5191
5191
|
const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("month", now);
|
|
5192
5192
|
const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
|
|
5193
|
-
windows.push(this.window("month", used.usedTokens, used
|
|
5193
|
+
windows.push(this.window("month", used.usedTokens, this.usd(used), range.resetsAt));
|
|
5194
5194
|
}
|
|
5195
5195
|
const blocked = (0, import_nestjs_agent_core28.exhaustedWindow)(windows);
|
|
5196
5196
|
const warning = (0, import_nestjs_agent_core28.quotaWarning)(windows);
|
|
@@ -5206,8 +5206,15 @@ var LedgerQuotaProvider = class {
|
|
|
5206
5206
|
}
|
|
5207
5207
|
async dayWindow(actorRef, now) {
|
|
5208
5208
|
const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("day", now);
|
|
5209
|
-
const
|
|
5210
|
-
return this.window("day", usedTokens,
|
|
5209
|
+
const used = await this.store.quotaToday(actorRef, range.fromDay);
|
|
5210
|
+
return this.window("day", used.usedTokens, this.usd(used), range.resetsAt);
|
|
5211
|
+
}
|
|
5212
|
+
/** The window's USD: every priced row, or (with `countEstimatedCost: false`) reported cost only. */
|
|
5213
|
+
usd(used) {
|
|
5214
|
+
if (this.options.countEstimatedCost === false) {
|
|
5215
|
+
return Math.max(0, used.costUsd - (used.estimatedCostUsd ?? 0));
|
|
5216
|
+
}
|
|
5217
|
+
return used.costUsd;
|
|
5211
5218
|
}
|
|
5212
5219
|
window(period, usedTokens, usedUsd, resetsAt) {
|
|
5213
5220
|
const limits = this.limits[period] ?? {};
|
|
@@ -5229,8 +5236,7 @@ var LedgerQuotaProvider = class {
|
|
|
5229
5236
|
}
|
|
5230
5237
|
};
|
|
5231
5238
|
|
|
5232
|
-
// src/
|
|
5233
|
-
var import_node_crypto2 = require("crypto");
|
|
5239
|
+
// src/pricing-boot.service.ts
|
|
5234
5240
|
var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
|
|
5235
5241
|
var import_common24 = require("@nestjs/common");
|
|
5236
5242
|
function _ts_decorate23(decorators, target, key, desc) {
|
|
@@ -5259,6 +5265,96 @@ function _ts_param22(paramIndex, decorator) {
|
|
|
5259
5265
|
};
|
|
5260
5266
|
}
|
|
5261
5267
|
__name(_ts_param22, "_ts_param");
|
|
5268
|
+
var logger = new import_common24.Logger("AgentPricing");
|
|
5269
|
+
var PricingBootService = class {
|
|
5270
|
+
static {
|
|
5271
|
+
__name(this, "PricingBootService");
|
|
5272
|
+
}
|
|
5273
|
+
options;
|
|
5274
|
+
model;
|
|
5275
|
+
pricingStore;
|
|
5276
|
+
#run = null;
|
|
5277
|
+
constructor(options, model, pricingStore) {
|
|
5278
|
+
this.options = options;
|
|
5279
|
+
this.model = model;
|
|
5280
|
+
this.pricingStore = pricingStore;
|
|
5281
|
+
}
|
|
5282
|
+
onApplicationBootstrap() {
|
|
5283
|
+
this.#run = this.check();
|
|
5284
|
+
}
|
|
5285
|
+
/** Awaits a check still in flight, so a test (or a fast shutdown) never leaks it. */
|
|
5286
|
+
async onApplicationShutdown() {
|
|
5287
|
+
await this.#run;
|
|
5288
|
+
this.#run = null;
|
|
5289
|
+
}
|
|
5290
|
+
/** The check itself; resolves once it is done (exposed for tests). */
|
|
5291
|
+
async check() {
|
|
5292
|
+
let models;
|
|
5293
|
+
try {
|
|
5294
|
+
models = this.model?.describeModels?.() ?? [];
|
|
5295
|
+
} catch (error) {
|
|
5296
|
+
logger.warn(`describeModels() threw; boot pricing skipped: ${String(error)}`);
|
|
5297
|
+
return;
|
|
5298
|
+
}
|
|
5299
|
+
if (models.length === 0) return;
|
|
5300
|
+
const catalog = this.options.priceCatalog;
|
|
5301
|
+
if (catalog === void 0 && process.env.NODE_ENV === "test") return;
|
|
5302
|
+
await (0, import_nestjs_agent_core29.ensureModelPricing)({
|
|
5303
|
+
models,
|
|
5304
|
+
pricingStore: this.pricingStore,
|
|
5305
|
+
catalog: catalog ?? {},
|
|
5306
|
+
log: {
|
|
5307
|
+
info: /* @__PURE__ */ __name((message) => logger.log(message), "info"),
|
|
5308
|
+
warn: /* @__PURE__ */ __name((message) => logger.warn(message), "warn")
|
|
5309
|
+
}
|
|
5310
|
+
}).catch(() => void 0);
|
|
5311
|
+
}
|
|
5312
|
+
};
|
|
5313
|
+
PricingBootService = _ts_decorate23([
|
|
5314
|
+
(0, import_common24.Injectable)(),
|
|
5315
|
+
_ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_OPTIONS)),
|
|
5316
|
+
_ts_param22(1, (0, import_common24.Optional)()),
|
|
5317
|
+
_ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_MODEL)),
|
|
5318
|
+
_ts_param22(2, (0, import_common24.Optional)()),
|
|
5319
|
+
_ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core29.AGENT_PRICING_STORE)),
|
|
5320
|
+
_ts_metadata22("design:type", Function),
|
|
5321
|
+
_ts_metadata22("design:paramtypes", [
|
|
5322
|
+
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
5323
|
+
Object,
|
|
5324
|
+
Object
|
|
5325
|
+
])
|
|
5326
|
+
], PricingBootService);
|
|
5327
|
+
|
|
5328
|
+
// src/proposals/action-proposal-worker.service.ts
|
|
5329
|
+
var import_node_crypto2 = require("crypto");
|
|
5330
|
+
var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
|
|
5331
|
+
var import_common25 = require("@nestjs/common");
|
|
5332
|
+
function _ts_decorate24(decorators, target, key, desc) {
|
|
5333
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5334
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5335
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
5336
|
+
} else {
|
|
5337
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
5338
|
+
if (d = decorators[i]) {
|
|
5339
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5342
|
+
}
|
|
5343
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5344
|
+
}
|
|
5345
|
+
__name(_ts_decorate24, "_ts_decorate");
|
|
5346
|
+
function _ts_metadata23(metadataKey, metadataValue) {
|
|
5347
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5348
|
+
return Reflect.metadata(metadataKey, metadataValue);
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
__name(_ts_metadata23, "_ts_metadata");
|
|
5352
|
+
function _ts_param23(paramIndex, decorator) {
|
|
5353
|
+
return function(target, key) {
|
|
5354
|
+
decorator(target, key, paramIndex);
|
|
5355
|
+
};
|
|
5356
|
+
}
|
|
5357
|
+
__name(_ts_param23, "_ts_param");
|
|
5262
5358
|
var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
5263
5359
|
static {
|
|
5264
5360
|
__name(this, "ActionProposalWorkerService");
|
|
@@ -5267,7 +5363,7 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5267
5363
|
options;
|
|
5268
5364
|
deps;
|
|
5269
5365
|
worker;
|
|
5270
|
-
logger = new
|
|
5366
|
+
logger = new import_common25.Logger(_ActionProposalWorkerService.name);
|
|
5271
5367
|
settledListeners = /* @__PURE__ */ new Set();
|
|
5272
5368
|
/**
|
|
5273
5369
|
* Run `listener` after every proposal this process's worker settles — how a module relays an
|
|
@@ -5303,16 +5399,16 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5303
5399
|
}
|
|
5304
5400
|
onModuleInit() {
|
|
5305
5401
|
if (this.options.actionApprovalMode !== "independent") return;
|
|
5306
|
-
(0,
|
|
5402
|
+
(0, import_nestjs_agent_core30.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
|
|
5307
5403
|
if (this.options.surface === "http") return;
|
|
5308
5404
|
const resolver = this.options.backgroundActorResolver;
|
|
5309
5405
|
if (!resolver) throw new Error("BackgroundActorResolver is required");
|
|
5310
|
-
this.worker = new
|
|
5406
|
+
this.worker = new import_nestjs_agent_core30.ActionProposalWorker({
|
|
5311
5407
|
store: this.store,
|
|
5312
5408
|
workerId: (0, import_node_crypto2.randomUUID)(),
|
|
5313
5409
|
...this.options.actionProposalWorker,
|
|
5314
5410
|
onSettled: /* @__PURE__ */ __name((proposal) => this.settled(proposal), "onSettled"),
|
|
5315
|
-
executor: new
|
|
5411
|
+
executor: new import_nestjs_agent_core30.ActionProposalExecutor({
|
|
5316
5412
|
resolver,
|
|
5317
5413
|
resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
|
|
5318
5414
|
const deps = this.deps.forProposal(proposal, actor);
|
|
@@ -5336,13 +5432,13 @@ var ActionProposalWorkerService = class _ActionProposalWorkerService {
|
|
|
5336
5432
|
await this.worker?.stop();
|
|
5337
5433
|
}
|
|
5338
5434
|
};
|
|
5339
|
-
ActionProposalWorkerService =
|
|
5340
|
-
(0,
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5435
|
+
ActionProposalWorkerService = _ts_decorate24([
|
|
5436
|
+
(0, import_common25.Injectable)(),
|
|
5437
|
+
_ts_param23(0, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_STORE)),
|
|
5438
|
+
_ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_OPTIONS)),
|
|
5439
|
+
_ts_param23(2, (0, import_common25.Inject)(import_nestjs_agent_core30.AGENT_DEPS_FACTORY)),
|
|
5440
|
+
_ts_metadata23("design:type", Function),
|
|
5441
|
+
_ts_metadata23("design:paramtypes", [
|
|
5346
5442
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
5347
5443
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
5348
5444
|
typeof AgentDepsFactory2 === "undefined" ? Object : AgentDepsFactory2
|
|
@@ -5350,9 +5446,9 @@ ActionProposalWorkerService = _ts_decorate23([
|
|
|
5350
5446
|
], ActionProposalWorkerService);
|
|
5351
5447
|
|
|
5352
5448
|
// src/proposals/action-proposal.controller.ts
|
|
5353
|
-
var
|
|
5354
|
-
var
|
|
5355
|
-
function
|
|
5449
|
+
var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
|
|
5450
|
+
var import_common26 = require("@nestjs/common");
|
|
5451
|
+
function _ts_decorate25(decorators, target, key, desc) {
|
|
5356
5452
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5357
5453
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5358
5454
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5365,24 +5461,24 @@ function _ts_decorate24(decorators, target, key, desc) {
|
|
|
5365
5461
|
}
|
|
5366
5462
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5367
5463
|
}
|
|
5368
|
-
__name(
|
|
5369
|
-
function
|
|
5464
|
+
__name(_ts_decorate25, "_ts_decorate");
|
|
5465
|
+
function _ts_metadata24(metadataKey, metadataValue) {
|
|
5370
5466
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5371
5467
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
5372
5468
|
}
|
|
5373
5469
|
}
|
|
5374
|
-
__name(
|
|
5375
|
-
function
|
|
5470
|
+
__name(_ts_metadata24, "_ts_metadata");
|
|
5471
|
+
function _ts_param24(paramIndex, decorator) {
|
|
5376
5472
|
return function(target, key) {
|
|
5377
5473
|
decorator(target, key, paramIndex);
|
|
5378
5474
|
};
|
|
5379
5475
|
}
|
|
5380
|
-
__name(
|
|
5476
|
+
__name(_ts_param24, "_ts_param");
|
|
5381
5477
|
function bodyFields(body, field2) {
|
|
5382
5478
|
if (body === void 0) return {};
|
|
5383
|
-
if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field2)) throw new
|
|
5479
|
+
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
5480
|
const value = body;
|
|
5385
|
-
if (value[field2] !== void 0 && (field2 === "remember" && typeof value[field2] !== "boolean" || field2 === "reason" && typeof value[field2] !== "string")) throw new
|
|
5481
|
+
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
5482
|
return value;
|
|
5387
5483
|
}
|
|
5388
5484
|
__name(bodyFields, "bodyFields");
|
|
@@ -5404,9 +5500,9 @@ var ActionProposalController = class {
|
|
|
5404
5500
|
query = {
|
|
5405
5501
|
after: JSON.parse(cursor)
|
|
5406
5502
|
};
|
|
5407
|
-
(0,
|
|
5503
|
+
(0, import_nestjs_agent_core31.validateActionProposalListQuery)(query);
|
|
5408
5504
|
} catch {
|
|
5409
|
-
throw new
|
|
5505
|
+
throw new import_common26.BadRequestException("Invalid action proposal cursor");
|
|
5410
5506
|
}
|
|
5411
5507
|
}
|
|
5412
5508
|
const page = await this.proposals.listPage(threadId, await this.actors.resolve(request), query);
|
|
@@ -5436,58 +5532,58 @@ var ActionProposalController = class {
|
|
|
5436
5532
|
});
|
|
5437
5533
|
}
|
|
5438
5534
|
};
|
|
5439
|
-
|
|
5440
|
-
(0,
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5535
|
+
_ts_decorate25([
|
|
5536
|
+
(0, import_common26.Get)(),
|
|
5537
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5538
|
+
_ts_param24(1, (0, import_common26.Req)()),
|
|
5539
|
+
_ts_param24(2, (0, import_common26.Query)("after")),
|
|
5540
|
+
_ts_param24(3, (0, import_common26.Res)({
|
|
5445
5541
|
passthrough: true
|
|
5446
5542
|
})),
|
|
5447
|
-
|
|
5448
|
-
|
|
5543
|
+
_ts_metadata24("design:type", Function),
|
|
5544
|
+
_ts_metadata24("design:paramtypes", [
|
|
5449
5545
|
String,
|
|
5450
5546
|
typeof Request === "undefined" ? Object : Request,
|
|
5451
5547
|
Object,
|
|
5452
5548
|
typeof Response === "undefined" ? Object : Response
|
|
5453
5549
|
]),
|
|
5454
|
-
|
|
5550
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5455
5551
|
], ActionProposalController.prototype, "list", null);
|
|
5456
|
-
|
|
5457
|
-
(0,
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
|
|
5552
|
+
_ts_decorate25([
|
|
5553
|
+
(0, import_common26.Post)(":proposalId/approve"),
|
|
5554
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5555
|
+
_ts_param24(1, (0, import_common26.Param)("proposalId")),
|
|
5556
|
+
_ts_param24(2, (0, import_common26.Req)()),
|
|
5557
|
+
_ts_param24(3, (0, import_common26.Body)()),
|
|
5558
|
+
_ts_metadata24("design:type", Function),
|
|
5559
|
+
_ts_metadata24("design:paramtypes", [
|
|
5464
5560
|
String,
|
|
5465
5561
|
String,
|
|
5466
5562
|
typeof Request === "undefined" ? Object : Request,
|
|
5467
5563
|
Object
|
|
5468
5564
|
]),
|
|
5469
|
-
|
|
5565
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5470
5566
|
], ActionProposalController.prototype, "approve", null);
|
|
5471
|
-
|
|
5472
|
-
(0,
|
|
5473
|
-
|
|
5474
|
-
|
|
5475
|
-
|
|
5476
|
-
|
|
5477
|
-
|
|
5478
|
-
|
|
5567
|
+
_ts_decorate25([
|
|
5568
|
+
(0, import_common26.Post)(":proposalId/reject"),
|
|
5569
|
+
_ts_param24(0, (0, import_common26.Param)("threadId")),
|
|
5570
|
+
_ts_param24(1, (0, import_common26.Param)("proposalId")),
|
|
5571
|
+
_ts_param24(2, (0, import_common26.Req)()),
|
|
5572
|
+
_ts_param24(3, (0, import_common26.Body)()),
|
|
5573
|
+
_ts_metadata24("design:type", Function),
|
|
5574
|
+
_ts_metadata24("design:paramtypes", [
|
|
5479
5575
|
String,
|
|
5480
5576
|
String,
|
|
5481
5577
|
typeof Request === "undefined" ? Object : Request,
|
|
5482
5578
|
Object
|
|
5483
5579
|
]),
|
|
5484
|
-
|
|
5580
|
+
_ts_metadata24("design:returntype", Promise)
|
|
5485
5581
|
], ActionProposalController.prototype, "reject", null);
|
|
5486
|
-
ActionProposalController =
|
|
5487
|
-
(0,
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5582
|
+
ActionProposalController = _ts_decorate25([
|
|
5583
|
+
(0, import_common26.Controller)("threads/:threadId/action-proposals"),
|
|
5584
|
+
_ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER)),
|
|
5585
|
+
_ts_metadata24("design:type", Function),
|
|
5586
|
+
_ts_metadata24("design:paramtypes", [
|
|
5491
5587
|
typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
|
|
5492
5588
|
typeof ActorResolver === "undefined" ? Object : ActorResolver
|
|
5493
5589
|
])
|
|
@@ -5497,9 +5593,9 @@ ActionProposalController = _ts_decorate24([
|
|
|
5497
5593
|
var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
|
|
5498
5594
|
|
|
5499
5595
|
// src/runner/inline-agent-runner.ts
|
|
5500
|
-
var
|
|
5501
|
-
var
|
|
5502
|
-
function
|
|
5596
|
+
var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
|
|
5597
|
+
var import_common27 = require("@nestjs/common");
|
|
5598
|
+
function _ts_decorate26(decorators, target, key, desc) {
|
|
5503
5599
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
5504
5600
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
5505
5601
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -5512,19 +5608,19 @@ function _ts_decorate25(decorators, target, key, desc) {
|
|
|
5512
5608
|
}
|
|
5513
5609
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
5514
5610
|
}
|
|
5515
|
-
__name(
|
|
5516
|
-
function
|
|
5611
|
+
__name(_ts_decorate26, "_ts_decorate");
|
|
5612
|
+
function _ts_metadata25(metadataKey, metadataValue) {
|
|
5517
5613
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
5518
5614
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
5519
5615
|
}
|
|
5520
5616
|
}
|
|
5521
|
-
__name(
|
|
5522
|
-
function
|
|
5617
|
+
__name(_ts_metadata25, "_ts_metadata");
|
|
5618
|
+
function _ts_param25(paramIndex, decorator) {
|
|
5523
5619
|
return function(target, key) {
|
|
5524
5620
|
decorator(target, key, paramIndex);
|
|
5525
5621
|
};
|
|
5526
5622
|
}
|
|
5527
|
-
__name(
|
|
5623
|
+
__name(_ts_param25, "_ts_param");
|
|
5528
5624
|
var InlineAgentRunner = class _InlineAgentRunner {
|
|
5529
5625
|
static {
|
|
5530
5626
|
__name(this, "InlineAgentRunner");
|
|
@@ -5532,7 +5628,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5532
5628
|
factory;
|
|
5533
5629
|
store;
|
|
5534
5630
|
queue;
|
|
5535
|
-
logger = new
|
|
5631
|
+
logger = new import_common27.Logger(_InlineAgentRunner.name);
|
|
5536
5632
|
pending = /* @__PURE__ */ new Map();
|
|
5537
5633
|
/**
|
|
5538
5634
|
* Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
|
|
@@ -5586,18 +5682,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5586
5682
|
],
|
|
5587
5683
|
input
|
|
5588
5684
|
});
|
|
5589
|
-
void (0,
|
|
5685
|
+
void (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5590
5686
|
...deps,
|
|
5591
5687
|
day
|
|
5592
|
-
}, input, hooks).then(() => (0,
|
|
5593
|
-
if (error instanceof
|
|
5688
|
+
}, input, hooks).then(() => (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
|
|
5689
|
+
if (error instanceof import_nestjs_agent_core32.RunCancelledError) {
|
|
5594
5690
|
await this.settleCancelled(runId, input, deps);
|
|
5595
5691
|
return;
|
|
5596
5692
|
}
|
|
5597
5693
|
const message = error instanceof Error ? error.message : String(error);
|
|
5598
|
-
const code = (0,
|
|
5694
|
+
const code = (0, import_nestjs_agent_core32.agentFailureCode)(error);
|
|
5599
5695
|
this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
|
|
5600
|
-
(0,
|
|
5696
|
+
(0, import_nestjs_agent_core32.publishAgentRunFailed)({
|
|
5601
5697
|
runId,
|
|
5602
5698
|
code,
|
|
5603
5699
|
message
|
|
@@ -5608,11 +5704,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5608
5704
|
errorCode: code,
|
|
5609
5705
|
errorMessage: message
|
|
5610
5706
|
});
|
|
5611
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5707
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core32.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
5612
5708
|
const writer = await deps.sink.open(runId);
|
|
5613
5709
|
await this.settleQueue(writer, input, runId, "failed", message);
|
|
5614
|
-
await (0,
|
|
5615
|
-
await writer.fail((0,
|
|
5710
|
+
await (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5711
|
+
await writer.fail((0, import_nestjs_agent_core32.streamFailure)(error));
|
|
5616
5712
|
}).finally(() => {
|
|
5617
5713
|
this.forgetCancel(runId);
|
|
5618
5714
|
this.live.delete(runId);
|
|
@@ -5647,11 +5743,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5647
5743
|
*/
|
|
5648
5744
|
async cancel(runId) {
|
|
5649
5745
|
this.cancelled.add(runId);
|
|
5650
|
-
this.aborts.get(runId)?.abort(new
|
|
5746
|
+
this.aborts.get(runId)?.abort(new import_nestjs_agent_core32.RunCancelledError());
|
|
5651
5747
|
for (const [key, waiter] of this.pending) {
|
|
5652
5748
|
if (key.startsWith(`${runId}:`)) {
|
|
5653
5749
|
this.pending.delete(key);
|
|
5654
|
-
waiter.reject(new
|
|
5750
|
+
waiter.reject(new import_nestjs_agent_core32.RunCancelledError());
|
|
5655
5751
|
}
|
|
5656
5752
|
}
|
|
5657
5753
|
await Promise.resolve();
|
|
@@ -5680,8 +5776,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5680
5776
|
this.logger.log(`agent run ${runId} cancelled`);
|
|
5681
5777
|
const writer = await deps.sink.open(runId);
|
|
5682
5778
|
await this.settleQueue(writer, input, runId, "cancelled");
|
|
5683
|
-
await (0,
|
|
5684
|
-
await writer.write((0,
|
|
5779
|
+
await (0, import_nestjs_agent_core32.releaseThreadRun)(this.store, input.threadId, runId);
|
|
5780
|
+
await writer.write((0, import_nestjs_agent_core32.encodeStreamEvent)({
|
|
5685
5781
|
kind: "cancelled"
|
|
5686
5782
|
}));
|
|
5687
5783
|
await writer.end();
|
|
@@ -5716,7 +5812,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5716
5812
|
runId: nextRunId
|
|
5717
5813
|
}));
|
|
5718
5814
|
if (frame !== void 0) {
|
|
5719
|
-
await writer.write((0,
|
|
5815
|
+
await writer.write((0, import_nestjs_agent_core32.encodeStreamEvent)(frame));
|
|
5720
5816
|
}
|
|
5721
5817
|
} catch (failure) {
|
|
5722
5818
|
this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
@@ -5787,7 +5883,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5787
5883
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5788
5884
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5789
5885
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5790
|
-
parallel:
|
|
5886
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5791
5887
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5792
5888
|
abortSignal: this.abortSignalFor(runId),
|
|
5793
5889
|
runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
|
|
@@ -5839,7 +5935,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5839
5935
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5840
5936
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5841
5937
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5842
|
-
parallel:
|
|
5938
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5843
5939
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
|
|
5844
5940
|
abortSignal: this.abortSignalFor(runId),
|
|
5845
5941
|
runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
|
|
@@ -5873,7 +5969,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5873
5969
|
}
|
|
5874
5970
|
}), "startAgent")
|
|
5875
5971
|
};
|
|
5876
|
-
void (0,
|
|
5972
|
+
void (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5877
5973
|
...deps,
|
|
5878
5974
|
day
|
|
5879
5975
|
}, {
|
|
@@ -5887,13 +5983,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5887
5983
|
parentRunId,
|
|
5888
5984
|
deliverTo
|
|
5889
5985
|
}, hooks).catch(async (error) => {
|
|
5890
|
-
const cancelled = error instanceof
|
|
5986
|
+
const cancelled = error instanceof import_nestjs_agent_core32.RunCancelledError;
|
|
5891
5987
|
const message = error instanceof Error ? error.message : String(error);
|
|
5892
5988
|
if (!cancelled) {
|
|
5893
5989
|
this.logger.error(`detached agent run ${runId} failed: ${message}`);
|
|
5894
|
-
(0,
|
|
5990
|
+
(0, import_nestjs_agent_core32.publishAgentRunFailed)({
|
|
5895
5991
|
runId,
|
|
5896
|
-
code: (0,
|
|
5992
|
+
code: (0, import_nestjs_agent_core32.agentFailureCode)(error),
|
|
5897
5993
|
message
|
|
5898
5994
|
});
|
|
5899
5995
|
}
|
|
@@ -5901,12 +5997,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5901
5997
|
runId,
|
|
5902
5998
|
status: cancelled ? "cancelled" : "failed",
|
|
5903
5999
|
...cancelled ? {} : {
|
|
5904
|
-
errorCode: (0,
|
|
6000
|
+
errorCode: (0, import_nestjs_agent_core32.agentFailureCode)(error),
|
|
5905
6001
|
errorMessage: message
|
|
5906
6002
|
}
|
|
5907
6003
|
});
|
|
5908
|
-
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId,
|
|
5909
|
-
await (0,
|
|
6004
|
+
await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core32.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
|
|
6005
|
+
await (0, import_nestjs_agent_core32.settleUnsettledDelegation)({
|
|
5910
6006
|
store: this.store,
|
|
5911
6007
|
delivery: deliverTo,
|
|
5912
6008
|
agent: agentName,
|
|
@@ -5945,7 +6041,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5945
6041
|
awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
|
|
5946
6042
|
awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
|
|
5947
6043
|
step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
|
|
5948
|
-
parallel:
|
|
6044
|
+
parallel: import_nestjs_agent_core32.settleAll,
|
|
5949
6045
|
// A child stops when it is cancelled OR when the run a human is actually watching is: the
|
|
5950
6046
|
// canceller names the top-level run, which is the only id that ever left the server.
|
|
5951
6047
|
cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
|
|
@@ -5982,7 +6078,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
5982
6078
|
}), "startAgent")
|
|
5983
6079
|
};
|
|
5984
6080
|
try {
|
|
5985
|
-
return await (0,
|
|
6081
|
+
return await (0, import_nestjs_agent_core32.runAgentLoop)({
|
|
5986
6082
|
...deps,
|
|
5987
6083
|
day
|
|
5988
6084
|
}, {
|
|
@@ -6001,13 +6097,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
|
|
|
6001
6097
|
}
|
|
6002
6098
|
}
|
|
6003
6099
|
};
|
|
6004
|
-
InlineAgentRunner =
|
|
6005
|
-
(0,
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6100
|
+
InlineAgentRunner = _ts_decorate26([
|
|
6101
|
+
(0, import_common27.Injectable)(),
|
|
6102
|
+
_ts_param25(0, (0, import_common27.Inject)(import_nestjs_agent_core32.AGENT_DEPS_FACTORY)),
|
|
6103
|
+
_ts_param25(1, (0, import_common27.Inject)(import_nestjs_agent_core32.AGENT_STORE)),
|
|
6104
|
+
_ts_param25(2, (0, import_common27.Optional)()),
|
|
6105
|
+
_ts_metadata25("design:type", Function),
|
|
6106
|
+
_ts_metadata25("design:paramtypes", [
|
|
6011
6107
|
typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
|
|
6012
6108
|
typeof AgentStore === "undefined" ? Object : AgentStore,
|
|
6013
6109
|
typeof ChatQueueService === "undefined" ? Object : ChatQueueService
|
|
@@ -6019,7 +6115,7 @@ function isThreadTurn(input) {
|
|
|
6019
6115
|
__name(isThreadTurn, "isThreadTurn");
|
|
6020
6116
|
|
|
6021
6117
|
// src/skills-config.ts
|
|
6022
|
-
var
|
|
6118
|
+
var import_nestjs_agent_core33 = require("@dudousxd/nestjs-agent-core");
|
|
6023
6119
|
function declaredSkillProvider(declared) {
|
|
6024
6120
|
return {
|
|
6025
6121
|
list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
|
|
@@ -6045,7 +6141,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
6045
6141
|
declaredSkillProvider(declared)
|
|
6046
6142
|
];
|
|
6047
6143
|
return {
|
|
6048
|
-
provider: providers.length === 1 ? providers[0] : (0,
|
|
6144
|
+
provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core33.compositeSkillProvider)(providers),
|
|
6049
6145
|
...options.scopes !== void 0 ? {
|
|
6050
6146
|
scopes: options.scopes
|
|
6051
6147
|
} : {},
|
|
@@ -6057,7 +6153,7 @@ function resolveSkillsConfig(options, declared) {
|
|
|
6057
6153
|
__name(resolveSkillsConfig, "resolveSkillsConfig");
|
|
6058
6154
|
|
|
6059
6155
|
// src/agent.module.ts
|
|
6060
|
-
function
|
|
6156
|
+
function _ts_decorate27(decorators, target, key, desc) {
|
|
6061
6157
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6062
6158
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
6063
6159
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6070,9 +6166,9 @@ function _ts_decorate26(decorators, target, key, desc) {
|
|
|
6070
6166
|
}
|
|
6071
6167
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6072
6168
|
}
|
|
6073
|
-
__name(
|
|
6169
|
+
__name(_ts_decorate27, "_ts_decorate");
|
|
6074
6170
|
var DEFAULT_PATH = "agent";
|
|
6075
|
-
var
|
|
6171
|
+
var logger2 = new import_common28.Logger("AgentModule");
|
|
6076
6172
|
function externalWrapper(modules, token) {
|
|
6077
6173
|
for (const module2 of modules.values()) {
|
|
6078
6174
|
if (module2.metatype === AgentModule) continue;
|
|
@@ -6104,22 +6200,22 @@ function forwardingStore(wrapper) {
|
|
|
6104
6200
|
__name(forwardingStore, "forwardingStore");
|
|
6105
6201
|
function resolveStore(options, modules) {
|
|
6106
6202
|
if (options.store !== void 0) return options.store;
|
|
6107
|
-
const external = externalWrapper(modules,
|
|
6203
|
+
const external = externalWrapper(modules, import_nestjs_agent_core34.AGENT_STORE);
|
|
6108
6204
|
if (external !== void 0) return forwardingStore(external);
|
|
6109
|
-
|
|
6110
|
-
return new
|
|
6205
|
+
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()).");
|
|
6206
|
+
return new import_nestjs_agent_core34.InMemoryAgentStore();
|
|
6111
6207
|
}
|
|
6112
6208
|
__name(resolveStore, "resolveStore");
|
|
6113
6209
|
function resolveRolesPolicy(options, modules) {
|
|
6114
|
-
const external = externalWrapper(modules,
|
|
6210
|
+
const external = externalWrapper(modules, import_nestjs_agent_core34.AGENT_ROLES_POLICY);
|
|
6115
6211
|
if (options.rolesPolicy !== void 0) {
|
|
6116
6212
|
if (external !== void 0) {
|
|
6117
|
-
|
|
6213
|
+
logger2.warn("Both a `rolesPolicy` option and a module binding AGENT_ROLES_POLICY (e.g. AgentAuthzModule) are configured \u2014 the `rolesPolicy` option wins.");
|
|
6118
6214
|
}
|
|
6119
6215
|
return options.rolesPolicy;
|
|
6120
6216
|
}
|
|
6121
6217
|
if (external !== void 0) return forwardingPolicy(external);
|
|
6122
|
-
return options.emptyRoles === "deny" ? new
|
|
6218
|
+
return options.emptyRoles === "deny" ? new import_nestjs_agent_core34.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core34.DefaultRolesPolicy(options.defaultRoles);
|
|
6123
6219
|
}
|
|
6124
6220
|
__name(resolveRolesPolicy, "resolveRolesPolicy");
|
|
6125
6221
|
function forwardingPolicy(wrapper) {
|
|
@@ -6147,102 +6243,110 @@ __name(resolveCatalog, "resolveCatalog");
|
|
|
6147
6243
|
function sharedProviders(durable, engine) {
|
|
6148
6244
|
const providers = [
|
|
6149
6245
|
{
|
|
6150
|
-
provide:
|
|
6151
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
6246
|
+
provide: import_nestjs_agent_core34.AGENT_TOOL_REGISTRY,
|
|
6247
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core34.ToolRegistry(), "useFactory")
|
|
6152
6248
|
},
|
|
6153
6249
|
// Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
|
|
6154
6250
|
{
|
|
6155
|
-
provide:
|
|
6156
|
-
useFactory: /* @__PURE__ */ __name(() => new
|
|
6251
|
+
provide: import_nestjs_agent_core34.AGENT_REGISTRY,
|
|
6252
|
+
useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core34.AgentRegistry(), "useFactory")
|
|
6157
6253
|
},
|
|
6158
6254
|
// A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
|
|
6159
6255
|
{
|
|
6160
|
-
provide:
|
|
6256
|
+
provide: import_nestjs_agent_core34.AGENT_PROMPT_CONTRIBUTORS,
|
|
6161
6257
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
6162
6258
|
},
|
|
6163
6259
|
// Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
|
|
6164
6260
|
// read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
|
|
6165
6261
|
{
|
|
6166
|
-
provide:
|
|
6262
|
+
provide: import_nestjs_agent_core34.AGENT_SKILL_SOURCES,
|
|
6167
6263
|
useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
|
|
6168
6264
|
},
|
|
6169
6265
|
{
|
|
6170
6266
|
// One resolution, shared by the loop's deps and the listing endpoint: a second one would
|
|
6171
6267
|
// drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
|
|
6172
6268
|
// host configured none — which is what keeps the turn's checkpoint sequence unchanged.
|
|
6173
|
-
provide:
|
|
6269
|
+
provide: import_nestjs_agent_core34.AGENT_SKILLS,
|
|
6174
6270
|
useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
|
|
6175
6271
|
inject: [
|
|
6176
|
-
|
|
6177
|
-
|
|
6272
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6273
|
+
import_nestjs_agent_core34.AGENT_SKILL_SOURCES
|
|
6178
6274
|
]
|
|
6179
6275
|
},
|
|
6180
6276
|
{
|
|
6181
6277
|
// One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
|
|
6182
6278
|
// shown what the model was shown, and two resolutions would eventually disagree about that.
|
|
6183
|
-
provide:
|
|
6279
|
+
provide: import_nestjs_agent_core34.AGENT_MEMORY,
|
|
6184
6280
|
useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
|
|
6185
6281
|
inject: [
|
|
6186
|
-
|
|
6282
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6187
6283
|
]
|
|
6188
6284
|
},
|
|
6189
6285
|
{
|
|
6190
|
-
provide:
|
|
6286
|
+
provide: import_nestjs_agent_core34.AGENT_SINK,
|
|
6191
6287
|
useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
|
|
6192
6288
|
inject: [
|
|
6193
|
-
|
|
6289
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6194
6290
|
]
|
|
6195
6291
|
},
|
|
6196
6292
|
{
|
|
6197
|
-
provide:
|
|
6293
|
+
provide: import_nestjs_agent_core34.AGENT_ROLES_POLICY,
|
|
6198
6294
|
useFactory: /* @__PURE__ */ __name((options, modules) => resolveRolesPolicy(options, modules), "useFactory"),
|
|
6199
6295
|
inject: [
|
|
6200
|
-
|
|
6296
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6201
6297
|
import_core4.ModulesContainer
|
|
6202
6298
|
]
|
|
6203
6299
|
},
|
|
6204
6300
|
{
|
|
6205
|
-
provide:
|
|
6301
|
+
provide: import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER,
|
|
6206
6302
|
useFactory: /* @__PURE__ */ __name((options) => {
|
|
6207
6303
|
if (options.actorResolver !== void 0) return options.actorResolver;
|
|
6208
|
-
|
|
6304
|
+
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
6305
|
return new AnonymousActorResolver();
|
|
6210
6306
|
}, "useFactory"),
|
|
6211
6307
|
inject: [
|
|
6212
|
-
|
|
6308
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6213
6309
|
]
|
|
6214
6310
|
},
|
|
6215
6311
|
{
|
|
6216
|
-
provide:
|
|
6312
|
+
provide: import_nestjs_agent_core34.AGENT_MODEL,
|
|
6217
6313
|
useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
|
|
6218
6314
|
inject: [
|
|
6219
|
-
|
|
6315
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6220
6316
|
]
|
|
6221
6317
|
},
|
|
6222
6318
|
{
|
|
6223
6319
|
// `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
|
|
6224
6320
|
// omitted, the ledger provider still reports usage, with no ceiling to block on.
|
|
6225
|
-
provide:
|
|
6226
|
-
useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits,
|
|
6227
|
-
|
|
6228
|
-
|
|
6321
|
+
provide: import_nestjs_agent_core34.AGENT_QUOTA_PROVIDER,
|
|
6322
|
+
useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, {
|
|
6323
|
+
...o.quota?.warnAt !== void 0 ? {
|
|
6324
|
+
warnAt: o.quota.warnAt
|
|
6325
|
+
} : {},
|
|
6326
|
+
...o.quota?.countEstimatedCost !== void 0 ? {
|
|
6327
|
+
countEstimatedCost: o.quota.countEstimatedCost
|
|
6328
|
+
} : {}
|
|
6329
|
+
}), "useFactory"),
|
|
6229
6330
|
inject: [
|
|
6230
|
-
|
|
6231
|
-
|
|
6331
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6332
|
+
import_nestjs_agent_core34.AGENT_STORE
|
|
6232
6333
|
]
|
|
6233
6334
|
},
|
|
6234
6335
|
{
|
|
6235
|
-
provide:
|
|
6336
|
+
provide: import_nestjs_agent_core34.AGENT_MODEL_CATALOG,
|
|
6236
6337
|
useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
|
|
6237
6338
|
inject: [
|
|
6238
|
-
|
|
6339
|
+
import_nestjs_agent_core34.AGENT_OPTIONS
|
|
6239
6340
|
]
|
|
6240
6341
|
},
|
|
6241
6342
|
AgentDepsFactory2,
|
|
6242
6343
|
{
|
|
6243
|
-
provide:
|
|
6344
|
+
provide: import_nestjs_agent_core34.AGENT_DEPS_FACTORY,
|
|
6244
6345
|
useExisting: AgentDepsFactory2
|
|
6245
6346
|
},
|
|
6347
|
+
// Seeds a configured model's missing price row from models.dev and warns about one that would
|
|
6348
|
+
// record no cost (`priceCatalog`), once the app has bootstrapped.
|
|
6349
|
+
PricingBootService,
|
|
6246
6350
|
// Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
|
|
6247
6351
|
// handoff tools (onApplicationBootstrap) reads the registry.
|
|
6248
6352
|
AgentDiscoveryService,
|
|
@@ -6263,26 +6367,26 @@ function sharedProviders(durable, engine) {
|
|
|
6263
6367
|
// through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
|
|
6264
6368
|
AgentApprovalPortAdapter,
|
|
6265
6369
|
{
|
|
6266
|
-
provide:
|
|
6370
|
+
provide: import_nestjs_agent_core34.AGENT_APPROVAL_PORT,
|
|
6267
6371
|
useExisting: AgentApprovalPortAdapter
|
|
6268
6372
|
}
|
|
6269
6373
|
];
|
|
6270
6374
|
providers.push({
|
|
6271
|
-
provide:
|
|
6375
|
+
provide: import_nestjs_agent_core34.AGENT_STORE,
|
|
6272
6376
|
useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
|
|
6273
6377
|
inject: [
|
|
6274
|
-
|
|
6378
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6275
6379
|
import_core4.ModulesContainer
|
|
6276
6380
|
]
|
|
6277
6381
|
});
|
|
6278
6382
|
if (engine !== void 0) {
|
|
6279
6383
|
providers.push(...engine.providers, {
|
|
6280
|
-
provide:
|
|
6384
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6281
6385
|
useExisting: engine.runner
|
|
6282
6386
|
});
|
|
6283
6387
|
} else if (durable) {
|
|
6284
6388
|
providers.push({
|
|
6285
|
-
provide:
|
|
6389
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6286
6390
|
useFactory: /* @__PURE__ */ __name((durableRunner) => {
|
|
6287
6391
|
if (durableRunner === void 0) {
|
|
6288
6392
|
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 +6395,14 @@ function sharedProviders(durable, engine) {
|
|
|
6291
6395
|
}, "useFactory"),
|
|
6292
6396
|
inject: [
|
|
6293
6397
|
{
|
|
6294
|
-
token:
|
|
6398
|
+
token: import_nestjs_agent_core34.AGENT_DURABLE_RUNNER,
|
|
6295
6399
|
optional: true
|
|
6296
6400
|
}
|
|
6297
6401
|
]
|
|
6298
6402
|
});
|
|
6299
6403
|
} else {
|
|
6300
6404
|
providers.push({
|
|
6301
|
-
provide:
|
|
6405
|
+
provide: import_nestjs_agent_core34.AGENT_RUNNER,
|
|
6302
6406
|
useExisting: InlineAgentRunner
|
|
6303
6407
|
});
|
|
6304
6408
|
}
|
|
@@ -6308,20 +6412,20 @@ __name(sharedProviders, "sharedProviders");
|
|
|
6308
6412
|
function exportsFor(engine) {
|
|
6309
6413
|
return [
|
|
6310
6414
|
...engine?.exports ?? [],
|
|
6311
|
-
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6316
|
-
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6415
|
+
import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6416
|
+
import_nestjs_agent_core34.AGENT_TOOL_REGISTRY,
|
|
6417
|
+
import_nestjs_agent_core34.AGENT_REGISTRY,
|
|
6418
|
+
import_nestjs_agent_core34.AGENT_SINK,
|
|
6419
|
+
import_nestjs_agent_core34.AGENT_ROLES_POLICY,
|
|
6420
|
+
import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER,
|
|
6421
|
+
import_nestjs_agent_core34.AGENT_MODEL,
|
|
6422
|
+
import_nestjs_agent_core34.AGENT_STORE,
|
|
6423
|
+
import_nestjs_agent_core34.AGENT_MODEL_CATALOG,
|
|
6424
|
+
import_nestjs_agent_core34.AGENT_QUOTA_PROVIDER,
|
|
6425
|
+
import_nestjs_agent_core34.AGENT_PROMPT_CONTRIBUTORS,
|
|
6426
|
+
import_nestjs_agent_core34.AGENT_SKILLS,
|
|
6427
|
+
import_nestjs_agent_core34.AGENT_MEMORY,
|
|
6428
|
+
import_nestjs_agent_core34.AGENT_DEPS_FACTORY,
|
|
6325
6429
|
AgentDepsFactory2,
|
|
6326
6430
|
AgentService,
|
|
6327
6431
|
ActionProposalService,
|
|
@@ -6329,7 +6433,7 @@ function exportsFor(engine) {
|
|
|
6329
6433
|
ChatQueueService,
|
|
6330
6434
|
AGENT_CHAT_QUEUE,
|
|
6331
6435
|
InlineAgentRunner,
|
|
6332
|
-
|
|
6436
|
+
import_nestjs_agent_core34.AGENT_APPROVAL_PORT
|
|
6333
6437
|
];
|
|
6334
6438
|
}
|
|
6335
6439
|
__name(exportsFor, "exportsFor");
|
|
@@ -6418,7 +6522,7 @@ var AgentModule = class _AgentModule {
|
|
|
6418
6522
|
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6419
6523
|
providers: [
|
|
6420
6524
|
{
|
|
6421
|
-
provide:
|
|
6525
|
+
provide: import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6422
6526
|
useValue: options
|
|
6423
6527
|
},
|
|
6424
6528
|
...sharedProviders(options.durable ?? false, options.engine),
|
|
@@ -6448,7 +6552,7 @@ var AgentModule = class _AgentModule {
|
|
|
6448
6552
|
controllers: controllersForSurface(options.surface, options.adapters, options.engine),
|
|
6449
6553
|
providers: [
|
|
6450
6554
|
{
|
|
6451
|
-
provide:
|
|
6555
|
+
provide: import_nestjs_agent_core34.AGENT_OPTIONS,
|
|
6452
6556
|
// Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
|
|
6453
6557
|
// authoritative on the async config object (they decided the actual wiring above), and
|
|
6454
6558
|
// the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
|
|
@@ -6477,16 +6581,16 @@ var AgentModule = class _AgentModule {
|
|
|
6477
6581
|
};
|
|
6478
6582
|
}
|
|
6479
6583
|
};
|
|
6480
|
-
AgentModule =
|
|
6481
|
-
(0,
|
|
6482
|
-
(0,
|
|
6584
|
+
AgentModule = _ts_decorate27([
|
|
6585
|
+
(0, import_common28.Global)(),
|
|
6586
|
+
(0, import_common28.Module)({})
|
|
6483
6587
|
], AgentModule);
|
|
6484
6588
|
|
|
6485
6589
|
// src/ag-ui/ag-ui.adapter.ts
|
|
6486
|
-
var
|
|
6590
|
+
var import_nestjs_agent_core35 = require("@dudousxd/nestjs-agent-core");
|
|
6487
6591
|
var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
|
|
6488
|
-
var
|
|
6489
|
-
function
|
|
6592
|
+
var import_common29 = require("@nestjs/common");
|
|
6593
|
+
function _ts_decorate28(decorators, target, key, desc) {
|
|
6490
6594
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6491
6595
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
|
|
6492
6596
|
r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -6499,22 +6603,22 @@ function _ts_decorate27(decorators, target, key, desc) {
|
|
|
6499
6603
|
}
|
|
6500
6604
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6501
6605
|
}
|
|
6502
|
-
__name(
|
|
6503
|
-
function
|
|
6606
|
+
__name(_ts_decorate28, "_ts_decorate");
|
|
6607
|
+
function _ts_metadata26(metadataKey, metadataValue) {
|
|
6504
6608
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
|
|
6505
6609
|
return Reflect.metadata(metadataKey, metadataValue);
|
|
6506
6610
|
}
|
|
6507
6611
|
}
|
|
6508
|
-
__name(
|
|
6509
|
-
function
|
|
6612
|
+
__name(_ts_metadata26, "_ts_metadata");
|
|
6613
|
+
function _ts_param26(paramIndex, decorator) {
|
|
6510
6614
|
return function(target, key) {
|
|
6511
6615
|
decorator(target, key, paramIndex);
|
|
6512
6616
|
};
|
|
6513
6617
|
}
|
|
6514
|
-
__name(
|
|
6618
|
+
__name(_ts_param26, "_ts_param");
|
|
6515
6619
|
var AG_UI_VIA = "ag-ui";
|
|
6516
6620
|
function invalid(code, message) {
|
|
6517
|
-
return new
|
|
6621
|
+
return new import_common29.BadRequestException({
|
|
6518
6622
|
statusCode: 400,
|
|
6519
6623
|
code,
|
|
6520
6624
|
message
|
|
@@ -6606,7 +6710,7 @@ var AgUiRunHandler = class {
|
|
|
6606
6710
|
warnings.push(...turn.dropped);
|
|
6607
6711
|
const owner = await this.agent.threadOwner(input.threadId);
|
|
6608
6712
|
if (owner !== null && owner !== actor.id) {
|
|
6609
|
-
throw new
|
|
6713
|
+
throw new import_common29.ForbiddenException("thread belongs to another actor");
|
|
6610
6714
|
}
|
|
6611
6715
|
if (forwarded.regenerate === true && owner === null) {
|
|
6612
6716
|
throw invalid("invalid_input", "regenerate needs a thread that already has an exchange");
|
|
@@ -6871,29 +6975,29 @@ function agUiAdapter(options = {}) {
|
|
|
6871
6975
|
return this.handle(req, res, body);
|
|
6872
6976
|
}
|
|
6873
6977
|
};
|
|
6874
|
-
|
|
6875
|
-
(0,
|
|
6876
|
-
(0,
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6881
|
-
|
|
6978
|
+
_ts_decorate28([
|
|
6979
|
+
(0, import_common29.Post)(path),
|
|
6980
|
+
(0, import_common29.HttpCode)(200),
|
|
6981
|
+
_ts_param26(0, (0, import_common29.Req)()),
|
|
6982
|
+
_ts_param26(1, (0, import_common29.Res)()),
|
|
6983
|
+
_ts_param26(2, (0, import_common29.Body)()),
|
|
6984
|
+
_ts_metadata26("design:type", Function),
|
|
6985
|
+
_ts_metadata26("design:paramtypes", [
|
|
6882
6986
|
typeof Request === "undefined" ? Object : Request,
|
|
6883
6987
|
typeof Response === "undefined" ? Object : Response,
|
|
6884
6988
|
Object
|
|
6885
6989
|
]),
|
|
6886
|
-
|
|
6990
|
+
_ts_metadata26("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
6887
6991
|
], AgUiController.prototype, "run", null);
|
|
6888
|
-
AgUiController =
|
|
6889
|
-
(0,
|
|
6890
|
-
|
|
6891
|
-
|
|
6892
|
-
|
|
6893
|
-
|
|
6894
|
-
|
|
6895
|
-
|
|
6896
|
-
|
|
6992
|
+
AgUiController = _ts_decorate28([
|
|
6993
|
+
(0, import_common29.Controller)(),
|
|
6994
|
+
_ts_param26(0, (0, import_common29.Inject)(AgentService)),
|
|
6995
|
+
_ts_param26(1, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_ACTOR_RESOLVER)),
|
|
6996
|
+
_ts_param26(2, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_OPTIONS)),
|
|
6997
|
+
_ts_param26(3, (0, import_common29.Optional)()),
|
|
6998
|
+
_ts_param26(3, (0, import_common29.Inject)(import_nestjs_agent_core35.AGENT_ATTACHMENT_STAGING)),
|
|
6999
|
+
_ts_metadata26("design:type", Function),
|
|
7000
|
+
_ts_metadata26("design:paramtypes", [
|
|
6897
7001
|
typeof AgentService === "undefined" ? Object : AgentService,
|
|
6898
7002
|
typeof ActorResolver === "undefined" ? Object : ActorResolver,
|
|
6899
7003
|
typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
|
|
@@ -6910,7 +7014,7 @@ function agUiAdapter(options = {}) {
|
|
|
6910
7014
|
__name(agUiAdapter, "agUiAdapter");
|
|
6911
7015
|
|
|
6912
7016
|
// src/resolver/header-actor-resolver.ts
|
|
6913
|
-
var
|
|
7017
|
+
var import_common30 = require("@nestjs/common");
|
|
6914
7018
|
function readHeader(req, name) {
|
|
6915
7019
|
if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
|
|
6916
7020
|
const { headers } = req;
|
|
@@ -6926,7 +7030,7 @@ var HeaderActorResolver = class {
|
|
|
6926
7030
|
resolve(req) {
|
|
6927
7031
|
const id = readHeader(req, "x-actor-id");
|
|
6928
7032
|
if (id === void 0 || id.length === 0) {
|
|
6929
|
-
throw new
|
|
7033
|
+
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
7034
|
}
|
|
6931
7035
|
const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
|
|
6932
7036
|
const tenantRef = readHeader(req, "x-tenant-ref");
|
|
@@ -6941,7 +7045,7 @@ var HeaderActorResolver = class {
|
|
|
6941
7045
|
};
|
|
6942
7046
|
|
|
6943
7047
|
// src/resolver/request-user-actor-resolver.ts
|
|
6944
|
-
var
|
|
7048
|
+
var import_common31 = require("@nestjs/common");
|
|
6945
7049
|
function field(user, ...names) {
|
|
6946
7050
|
for (const name of names) {
|
|
6947
7051
|
const value = user[name];
|
|
@@ -6953,7 +7057,7 @@ __name(field, "field");
|
|
|
6953
7057
|
function defaultRequestUserMapper(user) {
|
|
6954
7058
|
const id = field(user, "id", "sub", "_id", "userId");
|
|
6955
7059
|
if (id === void 0) {
|
|
6956
|
-
throw new
|
|
7060
|
+
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
7061
|
}
|
|
6958
7062
|
const rawRoles = field(user, "roles", "role");
|
|
6959
7063
|
const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
|
|
@@ -6974,7 +7078,7 @@ function requestUserActorResolver(map) {
|
|
|
6974
7078
|
async resolve(req) {
|
|
6975
7079
|
const user = typeof req === "object" && req !== null ? req.user : void 0;
|
|
6976
7080
|
if (user === void 0 || user === null || user === false) {
|
|
6977
|
-
throw new
|
|
7081
|
+
throw new import_common31.UnauthorizedException("Sign in to use the agent.");
|
|
6978
7082
|
}
|
|
6979
7083
|
if (map !== void 0) return map(user, req);
|
|
6980
7084
|
return defaultRequestUserMapper(user);
|