@dudousxd/nestjs-agent 1.19.3 → 1.21.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/index.cjs CHANGED
@@ -27,6 +27,9 @@ __export(index_exports, {
27
27
  AGENT_TOOL_BRAND: () => AGENT_TOOL_BRAND,
28
28
  AI_TOOL_METADATA: () => AI_TOOL_METADATA,
29
29
  ATTACHMENT_PAGE_SIZE: () => ATTACHMENT_PAGE_SIZE,
30
+ ActionProposalController: () => ActionProposalController,
31
+ ActionProposalService: () => ActionProposalService,
32
+ ActionProposalWorkerService: () => ActionProposalWorkerService,
30
33
  AgUiRunHandler: () => AgUiRunHandler,
31
34
  Agent: () => Agent,
32
35
  AgentApprovalPortAdapter: () => AgentApprovalPortAdapter,
@@ -74,20 +77,66 @@ __export(index_exports, {
74
77
  requestUserActorResolver: () => requestUserActorResolver,
75
78
  resolveSkillsConfig: () => resolveSkillsConfig,
76
79
  skillScope: () => skillScope,
80
+ threadPersona: () => threadPersona,
77
81
  toolNameFromClass: () => toolNameFromClass,
78
82
  utcDay: () => utcDay
79
83
  });
80
84
  module.exports = __toCommonJS(index_exports);
81
85
 
82
86
  // src/agent.module.ts
83
- var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
84
- var import_common23 = require("@nestjs/common");
87
+ var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
88
+ var import_common27 = require("@nestjs/common");
85
89
  var import_core4 = require("@nestjs/core");
86
90
 
87
91
  // src/agent-deps.factory.ts
88
92
  var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
89
93
  var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
94
+ var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
95
+ var import_common2 = require("@nestjs/common");
96
+
97
+ // src/genui/agent-genui.module.ts
98
+ var import_genui = require("@dudousxd/nestjs-agent-core/genui");
90
99
  var import_common = require("@nestjs/common");
100
+
101
+ // src/functional-tool.ts
102
+ var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
103
+ function brand(tool) {
104
+ return {
105
+ [AGENT_TOOL_BRAND]: true,
106
+ spec: tool.spec,
107
+ handler: tool.handler
108
+ };
109
+ }
110
+ __name(brand, "brand");
111
+ function isBrandedFunctionalTool(value) {
112
+ return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
113
+ }
114
+ __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
115
+ function provideAgentTool(factoryOrTool, inject) {
116
+ const provide = /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-instance");
117
+ if (typeof factoryOrTool === "function") {
118
+ return {
119
+ provide,
120
+ useFactory: /* @__PURE__ */ __name((...deps) => brand(factoryOrTool(...deps)), "useFactory"),
121
+ inject: inject ?? []
122
+ };
123
+ }
124
+ return {
125
+ provide,
126
+ useValue: brand(factoryOrTool)
127
+ };
128
+ }
129
+ __name(provideAgentTool, "provideAgentTool");
130
+ function provideAgentTools(factory, inject) {
131
+ return {
132
+ provide: /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-list"),
133
+ useFactory: /* @__PURE__ */ __name(async (...deps) => (await factory(...deps)).map(brand), "useFactory"),
134
+ inject: inject ?? []
135
+ };
136
+ }
137
+ __name(provideAgentTools, "provideAgentTools");
138
+
139
+ // src/genui/agent-genui.module.ts
91
140
  function _ts_decorate(decorators, target, key, desc) {
92
141
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
93
142
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -102,6 +151,124 @@ function _ts_decorate(decorators, target, key, desc) {
102
151
  return c > 3 && r && Object.defineProperty(target, key, r), r;
103
152
  }
104
153
  __name(_ts_decorate, "_ts_decorate");
154
+ var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
155
+ var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
156
+ var GenuiCatalogResolver = class {
157
+ static {
158
+ __name(this, "GenuiCatalogResolver");
159
+ }
160
+ };
161
+ function resolverProviders(resolver) {
162
+ if (resolver === void 0) return [];
163
+ return [
164
+ typeof resolver === "function" ? {
165
+ provide: GenuiCatalogResolver,
166
+ useClass: resolver
167
+ } : {
168
+ provide: GenuiCatalogResolver,
169
+ useValue: resolver
170
+ }
171
+ ];
172
+ }
173
+ __name(resolverProviders, "resolverProviders");
174
+ function toolOptions(options, resolver) {
175
+ const { catalog: _catalog, ...rest } = options;
176
+ return {
177
+ ...rest,
178
+ ...resolver !== void 0 ? {
179
+ resolveCatalog: /* @__PURE__ */ __name((scope) => resolver.resolve(scope), "resolveCatalog")
180
+ } : {}
181
+ };
182
+ }
183
+ __name(toolOptions, "toolOptions");
184
+ function coreProviders(resolver) {
185
+ return [
186
+ {
187
+ provide: GENUI_CATALOG,
188
+ useFactory: /* @__PURE__ */ __name((options) => options.catalog ?? (0, import_genui.defineCatalog)([]), "useFactory"),
189
+ inject: [
190
+ GENUI_OPTIONS
191
+ ]
192
+ },
193
+ ...resolverProviders(resolver),
194
+ // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
195
+ // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
196
+ provideAgentTools((options, catalog, perRequest) => (0, import_genui.genuiTools)(catalog, toolOptions(options, perRequest)), [
197
+ GENUI_OPTIONS,
198
+ GENUI_CATALOG,
199
+ {
200
+ token: GenuiCatalogResolver,
201
+ optional: true
202
+ }
203
+ ])
204
+ ];
205
+ }
206
+ __name(coreProviders, "coreProviders");
207
+ var EXPORTS = [
208
+ GENUI_CATALOG,
209
+ GENUI_OPTIONS
210
+ ];
211
+ var AgentGenuiModule = class _AgentGenuiModule {
212
+ static {
213
+ __name(this, "AgentGenuiModule");
214
+ }
215
+ static forRoot(options = {}) {
216
+ const { resolver, ...rest } = options;
217
+ return {
218
+ module: _AgentGenuiModule,
219
+ global: true,
220
+ providers: [
221
+ {
222
+ provide: GENUI_OPTIONS,
223
+ useValue: rest
224
+ },
225
+ ...coreProviders(resolver)
226
+ ],
227
+ exports: resolver === void 0 ? EXPORTS : [
228
+ ...EXPORTS,
229
+ GenuiCatalogResolver
230
+ ]
231
+ };
232
+ }
233
+ static forRootAsync(options) {
234
+ return {
235
+ module: _AgentGenuiModule,
236
+ global: true,
237
+ imports: options.imports ?? [],
238
+ providers: [
239
+ {
240
+ provide: GENUI_OPTIONS,
241
+ useFactory: options.useFactory,
242
+ inject: options.inject ?? []
243
+ },
244
+ ...coreProviders(options.resolver)
245
+ ],
246
+ exports: options.resolver === void 0 ? EXPORTS : [
247
+ ...EXPORTS,
248
+ GenuiCatalogResolver
249
+ ]
250
+ };
251
+ }
252
+ };
253
+ AgentGenuiModule = _ts_decorate([
254
+ (0, import_common.Module)({})
255
+ ], AgentGenuiModule);
256
+
257
+ // src/agent-deps.factory.ts
258
+ function _ts_decorate2(decorators, target, key, desc) {
259
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
260
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
261
+ r = Reflect.decorate(decorators, target, key, desc);
262
+ } else {
263
+ for (var i = decorators.length - 1; i >= 0; i--) {
264
+ if (d = decorators[i]) {
265
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
266
+ }
267
+ }
268
+ }
269
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
270
+ }
271
+ __name(_ts_decorate2, "_ts_decorate");
105
272
  function _ts_metadata(metadataKey, metadataValue) {
106
273
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
107
274
  return Reflect.metadata(metadataKey, metadataValue);
@@ -134,7 +301,9 @@ var AgentDepsFactory2 = class {
134
301
  pricingStore;
135
302
  skills;
136
303
  memory;
137
- constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory) {
304
+ uiCatalog;
305
+ uiCatalogResolver;
306
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory, uiCatalog, uiCatalogResolver) {
138
307
  this.options = options;
139
308
  this.model = model;
140
309
  this.store = store;
@@ -146,6 +315,9 @@ var AgentDepsFactory2 = class {
146
315
  this.pricingStore = pricingStore;
147
316
  this.skills = skills;
148
317
  this.memory = memory;
318
+ this.uiCatalog = uiCatalog;
319
+ this.uiCatalogResolver = uiCatalogResolver;
320
+ if (options.actionApprovalMode === "independent") (0, import_nestjs_agent_core.assertIndependentActionCapabilities)(store, options.backgroundActorResolver);
149
321
  }
150
322
  /** The turn's memory seam, shared with the read-back endpoint. Undefined → memory is not configured. */
151
323
  memoryConfig() {
@@ -171,7 +343,7 @@ var AgentDepsFactory2 = class {
171
343
  return void 0;
172
344
  }
173
345
  const delegated = (definition.delegatesTo ?? []).map((edge) => {
174
- const { agent, detached } = (0, import_nestjs_agent_core.normalizeDelegation)(edge);
346
+ const { agent, detached } = (0, import_nestjs_agent_core2.normalizeDelegation)(edge);
175
347
  return delegateToolName({
176
348
  target: agent,
177
349
  detached
@@ -185,8 +357,76 @@ var AgentDepsFactory2 = class {
185
357
  ...delegated
186
358
  ];
187
359
  }
360
+ /**
361
+ * The agent a name stands for: itself when it is a registered agent (or unknown — the bare
362
+ * assistant), else the agent whose persona took the name over (`Persona.aliases`) and that persona.
363
+ */
364
+ resolveAgent(name) {
365
+ if (this.agents.has(name)) {
366
+ return {
367
+ agentName: name
368
+ };
369
+ }
370
+ const alias = (0, import_nestjs_agent_core2.resolvePersonaAlias)(this.agents.list(), name);
371
+ return alias === void 0 ? {
372
+ agentName: name
373
+ } : {
374
+ agentName: alias.agent,
375
+ persona: alias.persona
376
+ };
377
+ }
378
+ /** `agentName`'s personas as a picker reads them. Empty when it declares none. */
379
+ personaCatalog(agentName) {
380
+ return (this.agents.get(agentName)?.personas ?? []).map(import_nestjs_agent_core2.personaCatalogEntry);
381
+ }
382
+ /** The persona `agentName` runs under when nothing names one. Undefined → none. */
383
+ defaultPersona(agentName) {
384
+ return this.agents.get(agentName)?.defaultPersona;
385
+ }
386
+ /**
387
+ * The persona a turn of `agentName` runs under, most specific first: the one the send names
388
+ * (refused with `400 persona_not_found` when the agent does not declare it), else the thread's
389
+ * pinned one when this agent declares it, else the agent's default. Undefined → none.
390
+ */
391
+ resolvePersona(args) {
392
+ const definition = this.agents.get(args.agentName);
393
+ if (args.requested !== void 0) {
394
+ if ((0, import_nestjs_agent_core2.findPersona)(definition, args.requested) === void 0) {
395
+ throw new import_common2.BadRequestException({
396
+ statusCode: 400,
397
+ code: "persona_not_found",
398
+ message: `agent "${args.agentName}" has no persona "${args.requested}"`
399
+ });
400
+ }
401
+ return args.requested;
402
+ }
403
+ const pinned = args.threadPersona ?? void 0;
404
+ if (pinned !== void 0 && (0, import_nestjs_agent_core2.findPersona)(definition, pinned) !== void 0) {
405
+ return pinned;
406
+ }
407
+ return definition?.defaultPersona;
408
+ }
409
+ forProposal(proposal, _actor) {
410
+ const name = proposal.executionContext?.agentName;
411
+ if (name !== void 0 && !this.agents.has(name) && !(name === "default" && this.defaultAgentName() === "default" && this.agents.list().length === 0)) throw new Error(`Recorded agent ${name} no longer exists`);
412
+ const deps = this.forAgent(name);
413
+ const id = proposal.executionContext?.persona;
414
+ if (id !== void 0) {
415
+ const persona = deps.personas?.find((persona2) => persona2.id === id);
416
+ if (!persona) throw new Error(`Recorded persona ${id} no longer exists`);
417
+ return this.withPersona(deps, persona);
418
+ }
419
+ return deps;
420
+ }
188
421
  forAgent(agentName) {
189
422
  const name = agentName ?? this.defaultAgentName();
423
+ if (agentName !== void 0 && !this.agents.has(agentName)) {
424
+ const alias = (0, import_nestjs_agent_core2.resolvePersonaAlias)(this.agents.list(), agentName);
425
+ const persona = alias === void 0 ? void 0 : (0, import_nestjs_agent_core2.findPersona)(this.agents.get(alias.agent), alias.persona);
426
+ if (alias !== void 0 && persona !== void 0) {
427
+ return this.withPersona(this.forAgent(alias.agent), persona);
428
+ }
429
+ }
190
430
  const definition = this.agents.get(name);
191
431
  const toolAllowList = this.effectiveTools(definition);
192
432
  const followUpsCount = this.followUpsCount();
@@ -196,12 +436,27 @@ var AgentDepsFactory2 = class {
196
436
  return {
197
437
  model: this.model,
198
438
  store: this.store,
439
+ ...this.options.actionApprovalMode !== void 0 ? {
440
+ actionApprovalMode: this.options.actionApprovalMode
441
+ } : {},
199
442
  sink: this.sink,
200
443
  rolesPolicy: this.rolesPolicy,
201
444
  ...this.options.approvalPolicy !== void 0 ? {
202
445
  approvalPolicy: this.options.approvalPolicy
203
446
  } : {},
204
447
  registry: this.registry,
448
+ ...this.uiCatalog !== void 0 || this.uiCatalogResolver !== void 0 ? {
449
+ resolveUiCatalog: /* @__PURE__ */ __name((scope) => {
450
+ const catalog = this.uiCatalogResolver?.resolve({
451
+ ...scope,
452
+ ...scope.actor.tenantRef !== void 0 ? {
453
+ tenant: scope.actor.tenantRef
454
+ } : {}
455
+ }) ?? this.uiCatalog;
456
+ if (!catalog) throw new Error("UI catalog unavailable");
457
+ return catalog;
458
+ }, "resolveUiCatalog")
459
+ } : {},
205
460
  promptContributors: this.promptContributors,
206
461
  systemPrompt: definition?.systemPrompt ?? this.options.systemPrompt ?? "You are a helpful assistant.",
207
462
  maxSteps: definition?.maxSteps ?? 8,
@@ -251,6 +506,9 @@ var AgentDepsFactory2 = class {
251
506
  ...toolAllowList !== void 0 ? {
252
507
  toolAllowList
253
508
  } : {},
509
+ ...definition?.personas !== void 0 ? {
510
+ personas: definition.personas
511
+ } : {},
254
512
  ...this.options.toolTimeoutMs !== void 0 ? {
255
513
  toolTimeoutMs: this.options.toolTimeoutMs
256
514
  } : {},
@@ -269,6 +527,45 @@ var AgentDepsFactory2 = class {
269
527
  };
270
528
  }
271
529
  /**
530
+ * A persona baked into an agent's deps — how a run journaled under an agent name that a persona
531
+ * has since taken over (`Persona.aliases`) is served. That run names no persona of its own (it
532
+ * predates them, and its input cannot change), so the persona applies the way the old agent's own
533
+ * config did: as config, re-read on every replay, with no checkpoint of its own.
534
+ */
535
+ withPersona(deps, persona) {
536
+ const base = deps.systemPrompt;
537
+ const ref = {
538
+ id: persona.id,
539
+ label: persona.label
540
+ };
541
+ const resolve = /* @__PURE__ */ __name(async (prompt, ctx) => typeof prompt === "function" ? prompt(ctx) : prompt, "resolve");
542
+ const own = persona.systemPrompt;
543
+ const systemPrompt = /* @__PURE__ */ __name(async (ctx) => {
544
+ const scoped = {
545
+ ...ctx,
546
+ persona: ref
547
+ };
548
+ if (own === void 0) {
549
+ return resolve(base, scoped);
550
+ }
551
+ const basePrompt = typeof own === "function" ? await resolve(base, scoped) : void 0;
552
+ return resolve(own, {
553
+ ...scoped,
554
+ ...basePrompt !== void 0 ? {
555
+ basePrompt
556
+ } : {}
557
+ });
558
+ }, "systemPrompt");
559
+ const toolAllowList = (0, import_nestjs_agent_core2.intersectAllowLists)(deps.toolAllowList, persona.allowedTools);
560
+ return {
561
+ ...deps,
562
+ systemPrompt,
563
+ ...toolAllowList !== void 0 ? {
564
+ toolAllowList
565
+ } : {}
566
+ };
567
+ }
568
+ /**
272
569
  * The ceiling on how much of a thread this agent's turns carry, most specific wins: the agent's
273
570
  * own `@Agent({ history })`, else a module-wide custom `historyPolicy`, else the module-wide
274
571
  * `history` window. Undefined → unbounded, the behaviour of a module that configures none.
@@ -284,7 +581,7 @@ var AgentDepsFactory2 = class {
284
581
  }
285
582
  /** Build the built-in window policy from the declarative `{ maxMessages, maxTokens, summarize }`. */
286
583
  window(config) {
287
- return (0, import_nestjs_agent_core.windowHistory)({
584
+ return (0, import_nestjs_agent_core2.windowHistory)({
288
585
  ...config.maxMessages !== void 0 ? {
289
586
  maxMessages: config.maxMessages
290
587
  } : {},
@@ -294,7 +591,7 @@ var AgentDepsFactory2 = class {
294
591
  // The shared module model, not a per-agent one: an agent's `modelId` is an accounting label,
295
592
  // and only one provider is ever bound.
296
593
  ...config.summarize === true ? {
297
- summarize: (0, import_nestjs_agent_core.summarizeWithModel)(this.model)
594
+ summarize: (0, import_nestjs_agent_core2.summarizeWithModel)(this.model)
298
595
  } : {}
299
596
  });
300
597
  }
@@ -310,22 +607,25 @@ var AgentDepsFactory2 = class {
310
607
  return void 0;
311
608
  }
312
609
  };
313
- AgentDepsFactory2 = _ts_decorate([
314
- (0, import_common.Injectable)(),
315
- _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core2.AGENT_OPTIONS)),
316
- _ts_param(1, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_MODEL)),
317
- _ts_param(2, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_STORE)),
318
- _ts_param(3, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_SINK)),
319
- _ts_param(4, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_ROLES_POLICY)),
320
- _ts_param(5, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_TOOL_REGISTRY)),
321
- _ts_param(6, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_REGISTRY)),
322
- _ts_param(7, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PROMPT_CONTRIBUTORS)),
323
- _ts_param(8, (0, import_common.Optional)()),
324
- _ts_param(8, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_PRICING_STORE)),
325
- _ts_param(9, (0, import_common.Optional)()),
326
- _ts_param(9, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_SKILLS)),
327
- _ts_param(10, (0, import_common.Optional)()),
328
- _ts_param(10, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_MEMORY)),
610
+ AgentDepsFactory2 = _ts_decorate2([
611
+ (0, import_common2.Injectable)(),
612
+ _ts_param(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
613
+ _ts_param(1, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_MODEL)),
614
+ _ts_param(2, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_STORE)),
615
+ _ts_param(3, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_SINK)),
616
+ _ts_param(4, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_ROLES_POLICY)),
617
+ _ts_param(5, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_TOOL_REGISTRY)),
618
+ _ts_param(6, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_REGISTRY)),
619
+ _ts_param(7, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_PROMPT_CONTRIBUTORS)),
620
+ _ts_param(8, (0, import_common2.Optional)()),
621
+ _ts_param(8, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_PRICING_STORE)),
622
+ _ts_param(9, (0, import_common2.Optional)()),
623
+ _ts_param(9, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_SKILLS)),
624
+ _ts_param(10, (0, import_common2.Optional)()),
625
+ _ts_param(10, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_MEMORY)),
626
+ _ts_param(11, (0, import_common2.Optional)()),
627
+ _ts_param(11, (0, import_common2.Inject)(GENUI_CATALOG)),
628
+ _ts_param(12, (0, import_common2.Optional)()),
329
629
  _ts_metadata("design:type", Function),
330
630
  _ts_metadata("design:paramtypes", [
331
631
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -333,18 +633,20 @@ AgentDepsFactory2 = _ts_decorate([
333
633
  typeof AgentStore === "undefined" ? Object : AgentStore,
334
634
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
335
635
  typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
336
- typeof import_nestjs_agent_core.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core.ToolRegistry,
337
- typeof import_nestjs_agent_core.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core.AgentRegistry,
636
+ typeof import_nestjs_agent_core2.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core2.ToolRegistry,
637
+ typeof import_nestjs_agent_core2.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core2.AgentRegistry,
338
638
  Array,
339
639
  Object,
340
640
  Object,
341
- Object
641
+ Object,
642
+ typeof Catalog === "undefined" ? Object : Catalog,
643
+ typeof GenuiCatalogResolver === "undefined" ? Object : GenuiCatalogResolver
342
644
  ])
343
645
  ], AgentDepsFactory2);
344
646
 
345
647
  // src/agent.service.ts
346
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
347
- var import_common4 = require("@nestjs/common");
648
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
649
+ var import_common6 = require("@nestjs/common");
348
650
 
349
651
  // src/agent-deps.ts
350
652
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -368,10 +670,10 @@ function childSinkWriter(writer) {
368
670
  }
369
671
  __name(childSinkWriter, "childSinkWriter");
370
672
 
371
- // src/queue/chat-queue.service.ts
372
- var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
373
- var import_common2 = require("@nestjs/common");
374
- function _ts_decorate2(decorators, target, key, desc) {
673
+ // src/proposals/action-proposal.service.ts
674
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
675
+ var import_common3 = require("@nestjs/common");
676
+ function _ts_decorate3(decorators, target, key, desc) {
375
677
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
376
678
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
377
679
  r = Reflect.decorate(decorators, target, key, desc);
@@ -384,7 +686,7 @@ function _ts_decorate2(decorators, target, key, desc) {
384
686
  }
385
687
  return c > 3 && r && Object.defineProperty(target, key, r), r;
386
688
  }
387
- __name(_ts_decorate2, "_ts_decorate");
689
+ __name(_ts_decorate3, "_ts_decorate");
388
690
  function _ts_metadata2(metadataKey, metadataValue) {
389
691
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
390
692
  return Reflect.metadata(metadataKey, metadataValue);
@@ -397,6 +699,168 @@ function _ts_param2(paramIndex, decorator) {
397
699
  };
398
700
  }
399
701
  __name(_ts_param2, "_ts_param");
702
+ var ActionProposalService = class {
703
+ static {
704
+ __name(this, "ActionProposalService");
705
+ }
706
+ store;
707
+ options;
708
+ constructor(store, options) {
709
+ this.store = store;
710
+ this.options = options;
711
+ }
712
+ capability() {
713
+ const store = this.store;
714
+ if (typeof store.getThreadActionProposalScope !== "function" || typeof store.listActionProposals !== "function") throw new import_common3.NotImplementedException("Action proposals are unavailable");
715
+ return store;
716
+ }
717
+ async scope(threadId, actor) {
718
+ const scope = await this.capability().getThreadActionProposalScope(threadId);
719
+ if (!scope) throw new import_common3.NotFoundException("Thread not found");
720
+ if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new import_common3.ForbiddenException("Wrong proposal tenant");
721
+ return scope;
722
+ }
723
+ mayDecide(actor, proposal) {
724
+ return (0, import_nestjs_agent_core4.mayDecideApproval)(this.options.approvalPolicy, actor, {
725
+ toolCallId: proposal.originToolCallId,
726
+ approver: proposal.approver,
727
+ requesterRef: proposal.actorRef
728
+ });
729
+ }
730
+ async listPage(threadId, actor, query = {}) {
731
+ const scope = await this.scope(threadId, actor);
732
+ const rows = await this.capability().listActionProposals(scope, {
733
+ limit: 1e3,
734
+ ...query
735
+ });
736
+ const visible = [];
737
+ for (const row of rows) if (scope.actorRef === actor.id || await this.mayDecide(actor, row)) visible.push(row);
738
+ const last = rows.at(-1);
739
+ return {
740
+ items: visible,
741
+ ...rows.length === 1e3 && last ? {
742
+ next: {
743
+ createdAt: last.createdAt,
744
+ id: last.id
745
+ }
746
+ } : {}
747
+ };
748
+ }
749
+ async list(threadId, actor) {
750
+ return (await this.listPage(threadId, actor)).items;
751
+ }
752
+ async decide(threadId, proposalId, actor, command) {
753
+ const scope = await this.scope(threadId, actor);
754
+ const proposal = await this.capability().getActionProposal(scope, proposalId);
755
+ if (!proposal) throw new import_common3.NotFoundException("Proposal not found");
756
+ if (!await this.mayDecide(actor, proposal)) throw new import_common3.ForbiddenException("May not decide this proposal");
757
+ return this.capability().decideActionProposal(scope, proposalId, {
758
+ decision: command.decision,
759
+ actorRef: actor.id,
760
+ via: command.via ?? "web",
761
+ ...command.remember !== void 0 ? {
762
+ remember: command.remember
763
+ } : {},
764
+ ...command.reason !== void 0 ? {
765
+ reason: command.reason
766
+ } : {}
767
+ });
768
+ }
769
+ async handleTextDecision(threadId, actor, text) {
770
+ const command = (0, import_nestjs_agent_core4.parseTextActionProposalCommand)(text);
771
+ if (command.status === "unmatched") return command;
772
+ if (command.proposalId !== void 0) {
773
+ const result2 = await this.decide(threadId, command.proposalId, actor, {
774
+ decision: command.decision,
775
+ remember: command.remember,
776
+ via: "text"
777
+ });
778
+ return this.textReceipt(threadId, result2);
779
+ }
780
+ const candidates = [];
781
+ const scope = await this.scope(threadId, actor);
782
+ const pending = await this.capability().listActionProposals(scope, {
783
+ decision: "pending",
784
+ limit: 1e3
785
+ });
786
+ for (const proposal of pending) if (await this.mayDecide(actor, proposal)) candidates.push(proposal);
787
+ const resolution = (0, import_nestjs_agent_core4.resolveTextActionProposalDecision)(text, candidates);
788
+ if (resolution.status === "unmatched") return resolution;
789
+ if (resolution.status === "ambiguous" || resolution.status === "decision" && pending.length === 1e3 && !text.includes("#")) return {
790
+ threadId,
791
+ proposalDecision: {
792
+ status: "ambiguous",
793
+ proposalIds: candidates.map(({ id }) => id)
794
+ },
795
+ text: `Choose the action to decide: ${candidates.map(({ id }) => id).map((id) => `#${id}`).join(", ")}`
796
+ };
797
+ const result = await this.decide(threadId, resolution.proposalId, actor, {
798
+ decision: resolution.decision,
799
+ remember: resolution.remember,
800
+ via: "text"
801
+ });
802
+ return this.textReceipt(threadId, result);
803
+ }
804
+ textReceipt(threadId, result) {
805
+ return {
806
+ threadId,
807
+ proposalDecision: result,
808
+ text: result.proposal?.decision === "approved" ? "Action approved and queued for execution." : `Action ${result.proposal?.decision ?? result.status}; no execution was performed by this decision.`
809
+ };
810
+ }
811
+ };
812
+ ActionProposalService = _ts_decorate3([
813
+ (0, import_common3.Injectable)(),
814
+ _ts_param2(0, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
815
+ _ts_param2(1, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
816
+ _ts_metadata2("design:type", Function),
817
+ _ts_metadata2("design:paramtypes", [
818
+ typeof AgentStore === "undefined" ? Object : AgentStore,
819
+ typeof Pick === "undefined" ? Object : Pick
820
+ ])
821
+ ], ActionProposalService);
822
+
823
+ // src/queue/chat-queue.service.ts
824
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
825
+ var import_common4 = require("@nestjs/common");
826
+
827
+ // src/thread-persona.ts
828
+ async function threadPersona(store, threadId) {
829
+ const projecting = store;
830
+ if (typeof projecting.personaForThread === "function") {
831
+ return projecting.personaForThread(threadId);
832
+ }
833
+ return (await store.getThread(threadId))?.persona ?? null;
834
+ }
835
+ __name(threadPersona, "threadPersona");
836
+
837
+ // src/queue/chat-queue.service.ts
838
+ function _ts_decorate4(decorators, target, key, desc) {
839
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
840
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
841
+ r = Reflect.decorate(decorators, target, key, desc);
842
+ } else {
843
+ for (var i = decorators.length - 1; i >= 0; i--) {
844
+ if (d = decorators[i]) {
845
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
846
+ }
847
+ }
848
+ }
849
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
850
+ }
851
+ __name(_ts_decorate4, "_ts_decorate");
852
+ function _ts_metadata3(metadataKey, metadataValue) {
853
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
854
+ return Reflect.metadata(metadataKey, metadataValue);
855
+ }
856
+ }
857
+ __name(_ts_metadata3, "_ts_metadata");
858
+ function _ts_param3(paramIndex, decorator) {
859
+ return function(target, key) {
860
+ decorator(target, key, paramIndex);
861
+ };
862
+ }
863
+ __name(_ts_param3, "_ts_param");
400
864
  var MAX_DRAIN_ATTEMPTS = 8;
401
865
  var ChatQueueService = class _ChatQueueService {
402
866
  static {
@@ -407,27 +871,29 @@ var ChatQueueService = class _ChatQueueService {
407
871
  quotaProvider;
408
872
  options;
409
873
  staging;
410
- logger = new import_common2.Logger(_ChatQueueService.name);
874
+ deps;
875
+ logger = new import_common4.Logger(_ChatQueueService.name);
411
876
  /**
412
877
  * Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
413
878
  * alive whatever the runner says — it simply has not registered the run yet.
414
879
  */
415
880
  starting = /* @__PURE__ */ new Set();
416
- constructor(store, sink, quotaProvider, options, staging) {
881
+ constructor(store, sink, quotaProvider, options, staging, deps) {
417
882
  this.store = store;
418
883
  this.sink = sink;
419
884
  this.quotaProvider = quotaProvider;
420
885
  this.options = options;
421
886
  this.staging = staging;
887
+ this.deps = deps;
422
888
  }
423
889
  /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
424
890
  get supported() {
425
- return (0, import_nestjs_agent_core3.isChatQueueStore)(this.store);
891
+ return (0, import_nestjs_agent_core5.isChatQueueStore)(this.store);
426
892
  }
427
893
  /** The bound store as a queue store, or a 501 naming what is missing. */
428
894
  queueStore() {
429
- if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
430
- throw new import_common2.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
895
+ if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
896
+ throw new import_common4.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
431
897
  }
432
898
  return this.store;
433
899
  }
@@ -438,7 +904,7 @@ var ChatQueueService = class _ChatQueueService {
438
904
  store.queuePause(threadId)
439
905
  ]);
440
906
  return {
441
- items: items.map(import_nestjs_agent_core3.queuedMessageView),
907
+ items: items.map(import_nestjs_agent_core5.queuedMessageView),
442
908
  paused
443
909
  };
444
910
  }
@@ -489,7 +955,7 @@ var ChatQueueService = class _ChatQueueService {
489
955
  * A no-op returning `{}` on a store without a queue.
490
956
  */
491
957
  async plan(args) {
492
- if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
958
+ if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
493
959
  return {};
494
960
  }
495
961
  const store = this.store;
@@ -589,7 +1055,7 @@ var ChatQueueService = class _ChatQueueService {
589
1055
  * (its settle drains) or while the queue is paused. Answers the started run's id, if any.
590
1056
  */
591
1057
  async kick(threadId, runner) {
592
- if (!(0, import_nestjs_agent_core3.isChatQueueStore)(this.store)) {
1058
+ if (!(0, import_nestjs_agent_core5.isChatQueueStore)(this.store)) {
593
1059
  return void 0;
594
1060
  }
595
1061
  const { live, stale } = await this.holder(threadId, runner);
@@ -654,6 +1120,9 @@ var ChatQueueService = class _ChatQueueService {
654
1120
  } : {},
655
1121
  ...input.pageContext !== void 0 ? {
656
1122
  pageContext: input.pageContext
1123
+ } : {},
1124
+ ...input.uiCapabilities !== void 0 ? {
1125
+ uiCapabilities: input.uiCapabilities
657
1126
  } : {}
658
1127
  });
659
1128
  await store.setQueuePause(threadId, {
@@ -690,7 +1159,7 @@ var ChatQueueService = class _ChatQueueService {
690
1159
  }
691
1160
  async write(runId, frame) {
692
1161
  const writer = await this.sink.open(runId);
693
- await writer.write((0, import_nestjs_agent_core3.encodeStreamEvent)(frame));
1162
+ await writer.write((0, import_nestjs_agent_core5.encodeStreamEvent)(frame));
694
1163
  }
695
1164
  /** Why `actor` may not start a turn now (the quota message), or `null`. */
696
1165
  async quotaBlock(actor) {
@@ -716,13 +1185,17 @@ var ChatQueueService = class _ChatQueueService {
716
1185
  */
717
1186
  async inputFor(message) {
718
1187
  const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
1188
+ const { agentName, persona } = await this.targetFor(message);
719
1189
  return {
720
1190
  threadId: message.threadId,
721
1191
  actor: message.actor,
722
1192
  userText: message.content,
723
1193
  day: utcDay(),
724
- ...message.agentName !== void 0 ? {
725
- agentName: message.agentName
1194
+ ...agentName !== void 0 ? {
1195
+ agentName
1196
+ } : {},
1197
+ ...persona !== void 0 ? {
1198
+ persona
726
1199
  } : {},
727
1200
  ...attachments.length > 0 ? {
728
1201
  attachments
@@ -730,11 +1203,45 @@ var ChatQueueService = class _ChatQueueService {
730
1203
  ...message.pageContext !== void 0 ? {
731
1204
  pageContext: message.pageContext
732
1205
  } : {},
1206
+ ...message.uiCapabilities !== void 0 ? {
1207
+ uiCapabilities: message.uiCapabilities
1208
+ } : {},
733
1209
  ...message.model !== void 0 ? {
734
1210
  model: message.model
735
1211
  } : {}
736
1212
  };
737
1213
  }
1214
+ /**
1215
+ * The agent and persona a queued message starts as. A message carries the persona its send
1216
+ * resolved; one that carries none — queued before personas existed, or by a host that sets none —
1217
+ * resolves it now, exactly as a send would: an agent name a persona took over, then the thread's
1218
+ * pinned persona, then the agent's default. Never refused here: nobody is waiting on a 400.
1219
+ */
1220
+ async targetFor(message) {
1221
+ const deps = this.deps;
1222
+ if (message.persona !== void 0 || deps === void 0 || message.agentName === void 0) {
1223
+ return {
1224
+ ...message.agentName !== void 0 ? {
1225
+ agentName: message.agentName
1226
+ } : {},
1227
+ ...message.persona !== void 0 ? {
1228
+ persona: message.persona
1229
+ } : {}
1230
+ };
1231
+ }
1232
+ const target = deps.resolveAgent(message.agentName);
1233
+ const hasPersonas = deps.personaCatalog(target.agentName).length > 0;
1234
+ const persona = target.persona ?? (hasPersonas ? deps.resolvePersona({
1235
+ agentName: target.agentName,
1236
+ threadPersona: await threadPersona(this.store, message.threadId)
1237
+ }) : void 0);
1238
+ return {
1239
+ agentName: target.agentName,
1240
+ ...persona !== void 0 ? {
1241
+ persona
1242
+ } : {}
1243
+ };
1244
+ }
738
1245
  async freshAttachments(actor, attachments) {
739
1246
  const staging = this.staging;
740
1247
  if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
@@ -752,24 +1259,27 @@ var ChatQueueService = class _ChatQueueService {
752
1259
  }));
753
1260
  }
754
1261
  };
755
- ChatQueueService = _ts_decorate2([
756
- (0, import_common2.Injectable)(),
757
- _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
758
- _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
759
- _ts_param2(2, (0, import_common2.Optional)()),
760
- _ts_param2(2, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_PROVIDER)),
761
- _ts_param2(3, (0, import_common2.Optional)()),
762
- _ts_param2(3, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_OPTIONS)),
763
- _ts_param2(4, (0, import_common2.Optional)()),
764
- _ts_param2(4, (0, import_common2.Inject)(import_nestjs_agent_core3.AGENT_ATTACHMENT_STAGING)),
765
- _ts_metadata2("design:type", Function),
766
- _ts_metadata2("design:paramtypes", [
767
- typeof AgentStore === "undefined" ? Object : AgentStore,
768
- typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
769
- typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
770
- typeof Pick === "undefined" ? Object : Pick,
771
- typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
772
- ])
1262
+ ChatQueueService = _ts_decorate4([
1263
+ (0, import_common4.Injectable)(),
1264
+ _ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
1265
+ _ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_SINK)),
1266
+ _ts_param3(2, (0, import_common4.Optional)()),
1267
+ _ts_param3(2, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_QUOTA_PROVIDER)),
1268
+ _ts_param3(3, (0, import_common4.Optional)()),
1269
+ _ts_param3(3, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
1270
+ _ts_param3(4, (0, import_common4.Optional)()),
1271
+ _ts_param3(4, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_ATTACHMENT_STAGING)),
1272
+ _ts_param3(5, (0, import_common4.Optional)()),
1273
+ _ts_param3(5, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
1274
+ _ts_metadata3("design:type", Function),
1275
+ _ts_metadata3("design:paramtypes", [
1276
+ typeof AgentStore === "undefined" ? Object : AgentStore,
1277
+ typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
1278
+ typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1279
+ typeof Pick === "undefined" ? Object : Pick,
1280
+ typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1281
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1282
+ ])
773
1283
  ], ChatQueueService);
774
1284
  function pauseReasonFor(outcome, head) {
775
1285
  if (outcome === "failed") {
@@ -785,7 +1295,7 @@ function queueFrame(items, paused, started) {
785
1295
  return {
786
1296
  kind: "queue",
787
1297
  queue: {
788
- items: items.map(import_nestjs_agent_core3.queuedMessageView),
1298
+ items: items.map(import_nestjs_agent_core5.queuedMessageView),
789
1299
  paused
790
1300
  },
791
1301
  ...started !== void 0 ? {
@@ -796,25 +1306,25 @@ function queueFrame(items, paused, started) {
796
1306
  __name(queueFrame, "queueFrame");
797
1307
 
798
1308
  // src/run-not-active.exception.ts
799
- var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
800
- var import_common3 = require("@nestjs/common");
801
- var RunNotActiveException = class extends import_common3.ConflictException {
1309
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1310
+ var import_common5 = require("@nestjs/common");
1311
+ var RunNotActiveException = class extends import_common5.ConflictException {
802
1312
  static {
803
1313
  __name(this, "RunNotActiveException");
804
1314
  }
805
1315
  runId;
806
- code = import_nestjs_agent_core4.RUN_NOT_ACTIVE_CODE;
1316
+ code = import_nestjs_agent_core6.RUN_NOT_ACTIVE_CODE;
807
1317
  constructor(runId) {
808
1318
  super({
809
1319
  statusCode: 409,
810
- code: import_nestjs_agent_core4.RUN_NOT_ACTIVE_CODE,
811
- message: import_nestjs_agent_core4.RUN_NOT_ACTIVE_MESSAGE
1320
+ code: import_nestjs_agent_core6.RUN_NOT_ACTIVE_CODE,
1321
+ message: import_nestjs_agent_core6.RUN_NOT_ACTIVE_MESSAGE
812
1322
  }), this.runId = runId;
813
1323
  }
814
1324
  };
815
1325
 
816
1326
  // src/agent.service.ts
817
- function _ts_decorate3(decorators, target, key, desc) {
1327
+ function _ts_decorate5(decorators, target, key, desc) {
818
1328
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
819
1329
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
820
1330
  r = Reflect.decorate(decorators, target, key, desc);
@@ -827,19 +1337,19 @@ function _ts_decorate3(decorators, target, key, desc) {
827
1337
  }
828
1338
  return c > 3 && r && Object.defineProperty(target, key, r), r;
829
1339
  }
830
- __name(_ts_decorate3, "_ts_decorate");
831
- function _ts_metadata3(metadataKey, metadataValue) {
1340
+ __name(_ts_decorate5, "_ts_decorate");
1341
+ function _ts_metadata4(metadataKey, metadataValue) {
832
1342
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
833
1343
  return Reflect.metadata(metadataKey, metadataValue);
834
1344
  }
835
1345
  }
836
- __name(_ts_metadata3, "_ts_metadata");
837
- function _ts_param3(paramIndex, decorator) {
1346
+ __name(_ts_metadata4, "_ts_metadata");
1347
+ function _ts_param4(paramIndex, decorator) {
838
1348
  return function(target, key) {
839
1349
  decorator(target, key, paramIndex);
840
1350
  };
841
1351
  }
842
- __name(_ts_param3, "_ts_param");
1352
+ __name(_ts_param4, "_ts_param");
843
1353
  var AgentService = class {
844
1354
  static {
845
1355
  __name(this, "AgentService");
@@ -852,7 +1362,8 @@ var AgentService = class {
852
1362
  quotaProvider;
853
1363
  options;
854
1364
  queue;
855
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
1365
+ proposals;
1366
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
856
1367
  this.runner = runner;
857
1368
  this.store = store;
858
1369
  this.deps = deps;
@@ -861,6 +1372,13 @@ var AgentService = class {
861
1372
  this.quotaProvider = quotaProvider;
862
1373
  this.options = options;
863
1374
  this.queue = queue;
1375
+ this.proposals = proposals;
1376
+ }
1377
+ async handleTextDecision(threadId, actor, text) {
1378
+ if (this.options?.actionApprovalMode !== "independent" || !this.proposals) return {
1379
+ status: "unmatched"
1380
+ };
1381
+ return this.proposals.handleTextDecision(threadId, actor, text);
864
1382
  }
865
1383
  /** The queue service when the bound store can hold a queue, else `undefined`. */
866
1384
  queueing() {
@@ -870,7 +1388,7 @@ var AgentService = class {
870
1388
  requireQueue() {
871
1389
  const queue = this.queueing();
872
1390
  if (queue === void 0) {
873
- throw new import_common4.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
1391
+ throw new import_common6.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
874
1392
  }
875
1393
  return queue;
876
1394
  }
@@ -907,12 +1425,12 @@ var AgentService = class {
907
1425
  actor
908
1426
  });
909
1427
  if (blocked !== void 0) {
910
- throw new import_common4.HttpException({
911
- statusCode: import_common4.HttpStatus.TOO_MANY_REQUESTS,
1428
+ throw new import_common6.HttpException({
1429
+ statusCode: import_common6.HttpStatus.TOO_MANY_REQUESTS,
912
1430
  code: "quota_exceeded",
913
1431
  period: blocked.period,
914
1432
  message: blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`
915
- }, import_common4.HttpStatus.TOO_MANY_REQUESTS);
1433
+ }, import_common6.HttpStatus.TOO_MANY_REQUESTS);
916
1434
  }
917
1435
  }
918
1436
  /**
@@ -940,17 +1458,17 @@ var AgentService = class {
940
1458
  */
941
1459
  async assertModelAllowed(actor, agent, model) {
942
1460
  if (this.models === void 0) {
943
- throw new import_common4.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
1461
+ throw new import_common6.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
944
1462
  }
945
- const entry = (0, import_nestjs_agent_core5.findCatalogModel)(await this.models.list({
1463
+ const entry = (0, import_nestjs_agent_core7.findCatalogModel)(await this.models.list({
946
1464
  actor,
947
1465
  agent
948
1466
  }), model);
949
1467
  if (entry === void 0) {
950
- throw new import_common4.BadRequestException(`model "${model}" is not offered`);
1468
+ throw new import_common6.BadRequestException(`model "${model}" is not offered`);
951
1469
  }
952
1470
  if (!entry.available) {
953
- throw new import_common4.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
1471
+ throw new import_common6.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
954
1472
  }
955
1473
  return entry.id;
956
1474
  }
@@ -966,7 +1484,7 @@ var AgentService = class {
966
1484
  })).locked : void 0;
967
1485
  if (locked !== void 0) {
968
1486
  if (requested !== void 0 && requested !== locked.model) {
969
- throw new import_common4.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
1487
+ throw new import_common6.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
970
1488
  }
971
1489
  return locked.model;
972
1490
  }
@@ -992,7 +1510,10 @@ var AgentService = class {
992
1510
  const result = await this.send({
993
1511
  ...params,
994
1512
  mode: "auto"
1513
+ }, {
1514
+ textDecisions: false
995
1515
  });
1516
+ if ("proposalDecision" in result) throw new Error("Unexpected text decision in run-only API");
996
1517
  if (result.queued !== true) {
997
1518
  return result;
998
1519
  }
@@ -1010,7 +1531,7 @@ var AgentService = class {
1010
1531
  };
1011
1532
  }
1012
1533
  await this.requireQueue().publish(result.threadId);
1013
- throw new import_common4.ConflictException({
1534
+ throw new import_common6.ConflictException({
1014
1535
  statusCode: 409,
1015
1536
  code: "run_active",
1016
1537
  message: `thread ${result.threadId} already has a turn running`
@@ -1020,15 +1541,21 @@ var AgentService = class {
1020
1541
  * Send a message: start a turn, or — when its thread already has one running — queue the message
1021
1542
  * to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
1022
1543
  */
1023
- async send(params) {
1544
+ async send(params, sendOptions = {}) {
1545
+ if (sendOptions.textDecisions !== false && this.options?.actionApprovalMode === "independent" && params.threadId !== void 0 && params.regenerate !== true && this.proposals) {
1546
+ const decision = await this.proposals.handleTextDecision(params.threadId, params.actor, params.message);
1547
+ if ("proposalDecision" in decision) return decision;
1548
+ }
1024
1549
  await this.assertWithinQuota(params.actor);
1025
- const agentName = await this.resolveAgentName(params.agentName, params.threadId);
1550
+ const target = this.deps.resolveAgent(await this.resolveAgentName(params.agentName, params.threadId));
1551
+ const agentName = target.agentName;
1552
+ const persona = await this.resolvePersona(agentName, params.personaId ?? target.persona, params.threadId);
1026
1553
  const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
1027
1554
  const attachments = await this.resolveAttachments(params.actor, params.attachments ?? []);
1028
1555
  let threadId = params.threadId;
1029
1556
  if (threadId === void 0) {
1030
1557
  if (params.regenerate === true) {
1031
- throw new import_common4.BadRequestException("regenerate requires an existing threadId");
1558
+ throw new import_common6.BadRequestException("regenerate requires an existing threadId");
1032
1559
  }
1033
1560
  const created = await this.store.createThread({
1034
1561
  actor: params.actor,
@@ -1037,11 +1564,17 @@ var AgentService = class {
1037
1564
  } : {},
1038
1565
  ...params.newThreadId !== void 0 ? {
1039
1566
  id: params.newThreadId
1567
+ } : {},
1568
+ ...params.personaId !== void 0 ? {
1569
+ persona: params.personaId
1040
1570
  } : {}
1041
1571
  });
1042
1572
  threadId = created.id;
1043
1573
  } else {
1044
1574
  await this.assertOwnsThread(params.actor, threadId);
1575
+ if (params.personaId !== void 0) {
1576
+ await this.pinThreadPersona(threadId, params.personaId);
1577
+ }
1045
1578
  }
1046
1579
  const input = {
1047
1580
  threadId,
@@ -1049,6 +1582,9 @@ var AgentService = class {
1049
1582
  userText: params.message,
1050
1583
  day: utcDay(),
1051
1584
  agentName,
1585
+ ...persona !== void 0 ? {
1586
+ persona
1587
+ } : {},
1052
1588
  ...params.regenerate === true ? {
1053
1589
  regenerate: true
1054
1590
  } : {},
@@ -1058,12 +1594,16 @@ var AgentService = class {
1058
1594
  ...params.pageContext !== void 0 ? {
1059
1595
  pageContext: params.pageContext
1060
1596
  } : {},
1597
+ ...params.uiCapabilities !== void 0 ? {
1598
+ uiCapabilities: params.uiCapabilities
1599
+ } : {},
1061
1600
  ...model !== void 0 ? {
1062
1601
  model
1063
1602
  } : {}
1064
1603
  };
1065
1604
  const queue = this.queueing();
1066
1605
  if (queue === void 0) {
1606
+ if (this.options?.actionApprovalMode === "independent") throw new Error("Independent actions require queued thread admission");
1067
1607
  const { runId } = await this.runner.start(input);
1068
1608
  await this.store.setActiveStream(threadId, runId);
1069
1609
  return {
@@ -1074,7 +1614,7 @@ var AgentService = class {
1074
1614
  const mode = params.mode ?? "auto";
1075
1615
  const { live, stale } = await queue.holder(threadId, this.runner);
1076
1616
  if (stale !== null) {
1077
- await (0, import_nestjs_agent_core5.settleDeadRun)(this.store, {
1617
+ await (0, import_nestjs_agent_core7.settleDeadRun)(this.store, {
1078
1618
  runId: stale
1079
1619
  });
1080
1620
  }
@@ -1090,7 +1630,7 @@ var AgentService = class {
1090
1630
  }
1091
1631
  }
1092
1632
  if (params.regenerate === true) {
1093
- throw new import_common4.ConflictException({
1633
+ throw new import_common6.ConflictException({
1094
1634
  statusCode: 409,
1095
1635
  code: "run_active",
1096
1636
  message: "cannot regenerate while a turn is running on this thread"
@@ -1135,12 +1675,18 @@ var AgentService = class {
1135
1675
  ...input.agentName !== void 0 ? {
1136
1676
  agentName: input.agentName
1137
1677
  } : {},
1678
+ ...input.persona !== void 0 ? {
1679
+ persona: input.persona
1680
+ } : {},
1138
1681
  ...input.model !== void 0 ? {
1139
1682
  model: input.model
1140
1683
  } : {},
1141
1684
  ...input.pageContext !== void 0 ? {
1142
1685
  pageContext: input.pageContext
1143
1686
  } : {},
1687
+ ...input.uiCapabilities !== void 0 ? {
1688
+ uiCapabilities: input.uiCapabilities
1689
+ } : {},
1144
1690
  ...interrupting !== void 0 ? {
1145
1691
  interrupt: true,
1146
1692
  at: "head"
@@ -1187,7 +1733,7 @@ var AgentService = class {
1187
1733
  const store = queue.queueStore();
1188
1734
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1189
1735
  if (patch.message !== void 0 && patch.message.trim().length === 0) {
1190
- throw new import_common4.BadRequestException("message must not be empty");
1736
+ throw new import_common6.BadRequestException("message must not be empty");
1191
1737
  }
1192
1738
  const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
1193
1739
  if (patch.message !== void 0 || attachments !== void 0) {
@@ -1200,15 +1746,15 @@ var AgentService = class {
1200
1746
  } : {}
1201
1747
  });
1202
1748
  if (updated === null) {
1203
- throw new import_common4.GoneException(`queued message ${messageId} already started or was removed`);
1749
+ throw new import_common6.GoneException(`queued message ${messageId} already started or was removed`);
1204
1750
  }
1205
1751
  }
1206
1752
  if (patch.position !== void 0) {
1207
1753
  if (!Number.isInteger(patch.position) || patch.position < 0) {
1208
- throw new import_common4.BadRequestException("position must be a non-negative integer");
1754
+ throw new import_common6.BadRequestException("position must be a non-negative integer");
1209
1755
  }
1210
1756
  if (!await store.moveQueuedMessage(messageId, patch.position)) {
1211
- throw new import_common4.GoneException(`queued message ${messageId} already started or was removed`);
1757
+ throw new import_common6.GoneException(`queued message ${messageId} already started or was removed`);
1212
1758
  }
1213
1759
  }
1214
1760
  return queue.publish(threadId);
@@ -1218,7 +1764,7 @@ var AgentService = class {
1218
1764
  const queue = this.requireQueue();
1219
1765
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1220
1766
  if (!await queue.queueStore().removeQueuedMessage(messageId)) {
1221
- throw new import_common4.GoneException(`queued message ${messageId} already started or was removed`);
1767
+ throw new import_common6.GoneException(`queued message ${messageId} already started or was removed`);
1222
1768
  }
1223
1769
  return queue.publish(threadId);
1224
1770
  }
@@ -1237,7 +1783,7 @@ var AgentService = class {
1237
1783
  const queue = this.requireQueue();
1238
1784
  const store = queue.queueStore();
1239
1785
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1240
- const gone = /* @__PURE__ */ __name(() => new import_common4.GoneException(`queued message ${messageId} already started or was removed`), "gone");
1786
+ const gone = /* @__PURE__ */ __name(() => new import_common6.GoneException(`queued message ${messageId} already started or was removed`), "gone");
1241
1787
  const marked = await store.updateQueuedMessage(messageId, {
1242
1788
  interrupt: true
1243
1789
  });
@@ -1245,7 +1791,7 @@ var AgentService = class {
1245
1791
  throw gone();
1246
1792
  }
1247
1793
  if (marked.interrupt !== true) {
1248
- throw new import_common4.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1794
+ throw new import_common6.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1249
1795
  }
1250
1796
  if (!await store.moveQueuedMessage(messageId, 0)) {
1251
1797
  throw gone();
@@ -1304,7 +1850,7 @@ var AgentService = class {
1304
1850
  async assertOwnsQueuedMessage(actor, messageId) {
1305
1851
  const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
1306
1852
  if (message === null) {
1307
- throw new import_common4.NotFoundException(`queued message ${messageId} not found`);
1853
+ throw new import_common6.NotFoundException(`queued message ${messageId} not found`);
1308
1854
  }
1309
1855
  await this.assertOwnsThread(actor, message.threadId);
1310
1856
  return message.threadId;
@@ -1325,7 +1871,7 @@ var AgentService = class {
1325
1871
  }
1326
1872
  const staging = this.staging;
1327
1873
  if (staging === void 0 || typeof staging.resolve !== "function") {
1328
- throw new import_common4.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1874
+ throw new import_common6.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1329
1875
  }
1330
1876
  const resolved = [];
1331
1877
  for (const ref of refs) {
@@ -1334,7 +1880,7 @@ var AgentService = class {
1334
1880
  actor
1335
1881
  });
1336
1882
  if (attachment === null) {
1337
- throw new import_common4.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
1883
+ throw new import_common6.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
1338
1884
  }
1339
1885
  resolved.push(attachment);
1340
1886
  }
@@ -1436,6 +1982,7 @@ var AgentService = class {
1436
1982
  * not the thread's own actor).
1437
1983
  */
1438
1984
  async signalToolCall(toolCallId2, reply) {
1985
+ if ((await this.store.toolCallApproval?.(toolCallId2))?.status === "proposed") throw new import_common6.ConflictException("Independent proposals require the scoped proposal decision route");
1439
1986
  await this.assertNotExpired(toolCallId2);
1440
1987
  const runId = await this.resolveRunForToolCall(toolCallId2);
1441
1988
  await this.assertRunWaiting(runId);
@@ -1456,7 +2003,7 @@ var AgentService = class {
1456
2003
  if (active) {
1457
2004
  return;
1458
2005
  }
1459
- await (0, import_nestjs_agent_core5.settleDeadRun)(this.store, {
2006
+ await (0, import_nestjs_agent_core7.settleDeadRun)(this.store, {
1460
2007
  runId
1461
2008
  });
1462
2009
  throw new RunNotActiveException(runId);
@@ -1476,7 +2023,7 @@ var AgentService = class {
1476
2023
  throw new RunNotActiveException(runId);
1477
2024
  }
1478
2025
  if (owner !== actor.id) {
1479
- throw new import_common4.ForbiddenException("run belongs to another actor");
2026
+ throw new import_common6.ForbiddenException("run belongs to another actor");
1480
2027
  }
1481
2028
  }
1482
2029
  /**
@@ -1529,16 +2076,22 @@ var AgentService = class {
1529
2076
  async updateThread(actor, threadId, patch) {
1530
2077
  const title = patch.title !== void 0 ? this.validateTitle(patch.title) : void 0;
1531
2078
  await this.assertOwnsThread(actor, threadId);
1532
- if (patch.defaultAgent === void 0 && patch.model === void 0) {
2079
+ if (patch.defaultAgent === void 0 && patch.model === void 0 && patch.persona === void 0) {
1533
2080
  if (title !== void 0) {
1534
2081
  await this.store.setTitle(threadId, title);
1535
2082
  }
1536
2083
  return;
1537
2084
  }
1538
2085
  if (this.store.updateThread === void 0) {
1539
- throw new import_common4.NotImplementedException("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
2086
+ throw new import_common6.NotImplementedException("Setting a thread's defaultAgent, model or persona requires an AgentStore that implements updateThread(); the bound store does not support it.");
1540
2087
  }
1541
2088
  const model = patch.model === void 0 || patch.model === null ? patch.model : await this.assertModelAllowed(actor, patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId), patch.model);
2089
+ if (patch.persona !== void 0 && patch.persona !== null) {
2090
+ this.deps.resolvePersona({
2091
+ agentName: this.deps.resolveAgent(patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId)).agentName,
2092
+ requested: patch.persona
2093
+ });
2094
+ }
1542
2095
  await this.store.updateThread(threadId, {
1543
2096
  ...title !== void 0 ? {
1544
2097
  title
@@ -1548,16 +2101,46 @@ var AgentService = class {
1548
2101
  } : {},
1549
2102
  ...model !== void 0 ? {
1550
2103
  model
2104
+ } : {},
2105
+ ...patch.persona !== void 0 ? {
2106
+ persona: patch.persona
2107
+ } : {}
2108
+ });
2109
+ }
2110
+ /**
2111
+ * The persona this send runs under — see {@link AgentDepsFactory.resolvePersona}. The thread's
2112
+ * pinned persona is read only when the send names none AND the agent has personas to pick from.
2113
+ */
2114
+ async resolvePersona(agentName, requested, threadId) {
2115
+ const needsThread = requested === void 0 && threadId !== void 0 && this.deps.personaCatalog(agentName).length > 0;
2116
+ return this.deps.resolvePersona({
2117
+ agentName,
2118
+ ...requested !== void 0 ? {
2119
+ requested
2120
+ } : {},
2121
+ ...needsThread ? {
2122
+ threadPersona: await threadPersona(this.store, threadId)
1551
2123
  } : {}
1552
2124
  });
1553
2125
  }
2126
+ /** Pin `persona` on the thread when it is not already — a no-op on a store that cannot. */
2127
+ async pinThreadPersona(threadId, persona) {
2128
+ if (this.store.updateThread === void 0) {
2129
+ return;
2130
+ }
2131
+ if (await threadPersona(this.store, threadId) !== persona) {
2132
+ await this.store.updateThread(threadId, {
2133
+ persona
2134
+ });
2135
+ }
2136
+ }
1554
2137
  validateTitle(title) {
1555
2138
  const trimmed = title.trim();
1556
2139
  if (trimmed.length === 0) {
1557
- throw new import_common4.BadRequestException("title must not be empty");
2140
+ throw new import_common6.BadRequestException("title must not be empty");
1558
2141
  }
1559
2142
  if (trimmed.length > 200) {
1560
- throw new import_common4.BadRequestException("title must be at most 200 characters");
2143
+ throw new import_common6.BadRequestException("title must be at most 200 characters");
1561
2144
  }
1562
2145
  return trimmed;
1563
2146
  }
@@ -1596,6 +2179,7 @@ var AgentService = class {
1596
2179
  ...thread,
1597
2180
  defaultAgent: thread.defaultAgent ?? null,
1598
2181
  model: thread.model ?? null,
2182
+ persona: thread.persona ?? null,
1599
2183
  activeRunId: await this.store.activeRunForThread?.(thread.id) ?? thread.activeRunId ?? null
1600
2184
  };
1601
2185
  }
@@ -1660,21 +2244,21 @@ var AgentService = class {
1660
2244
  */
1661
2245
  async setMessageFeedback(actor, messageId, input) {
1662
2246
  if (input.value !== null && input.value !== "up" && input.value !== "down") {
1663
- throw new import_common4.BadRequestException("value must be 'up', 'down' or null");
2247
+ throw new import_common6.BadRequestException("value must be 'up', 'down' or null");
1664
2248
  }
1665
2249
  if (input.comment !== void 0 && typeof input.comment !== "string") {
1666
- throw new import_common4.BadRequestException("comment must be a string");
2250
+ throw new import_common6.BadRequestException("comment must be a string");
1667
2251
  }
1668
2252
  const comment = input.comment?.trim();
1669
2253
  if (comment !== void 0 && comment.length > 2e3) {
1670
- throw new import_common4.BadRequestException("comment must be at most 2000 characters");
2254
+ throw new import_common6.BadRequestException("comment must be at most 2000 characters");
1671
2255
  }
1672
2256
  if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
1673
- throw new import_common4.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
2257
+ throw new import_common6.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
1674
2258
  }
1675
2259
  const threadId = await this.store.threadOfMessage(messageId);
1676
2260
  if (threadId === null) {
1677
- throw new import_common4.NotFoundException(`message ${messageId} not found`);
2261
+ throw new import_common6.NotFoundException(`message ${messageId} not found`);
1678
2262
  }
1679
2263
  await this.assertOwnsThread(actor, threadId);
1680
2264
  const feedback = input.value === null ? null : {
@@ -1722,7 +2306,7 @@ var AgentService = class {
1722
2306
  const list = this.attachmentInventory();
1723
2307
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
1724
2308
  if (referencedMediaIds === void 0) {
1725
- throw new import_common4.NotImplementedException("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
2309
+ throw new import_common6.NotImplementedException("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
1726
2310
  }
1727
2311
  const stagedBefore = options.olderThan.toISOString();
1728
2312
  const inventory = await list({
@@ -1744,7 +2328,7 @@ var AgentService = class {
1744
2328
  attachmentInventory() {
1745
2329
  const list = this.staging?.list?.bind(this.staging);
1746
2330
  if (list === void 0) {
1747
- throw new import_common4.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
2331
+ throw new import_common6.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
1748
2332
  }
1749
2333
  return list;
1750
2334
  }
@@ -1755,10 +2339,10 @@ var AgentService = class {
1755
2339
  async assertOwnsThread(actor, threadId) {
1756
2340
  const owner = await this.store.ownerOfThread(threadId);
1757
2341
  if (owner === null) {
1758
- throw new import_common4.NotFoundException(`thread ${threadId} not found`);
2342
+ throw new import_common6.NotFoundException(`thread ${threadId} not found`);
1759
2343
  }
1760
2344
  if (owner !== actor.id) {
1761
- throw new import_common4.ForbiddenException("thread belongs to another actor");
2345
+ throw new import_common6.ForbiddenException("thread belongs to another actor");
1762
2346
  }
1763
2347
  }
1764
2348
  /**
@@ -1769,10 +2353,10 @@ var AgentService = class {
1769
2353
  async assertOwnsToolCall(actor, toolCallId2) {
1770
2354
  const owner = await this.store.ownerOfToolCall(toolCallId2);
1771
2355
  if (owner === null) {
1772
- throw new import_common4.NotFoundException(`tool call ${toolCallId2} not found`);
2356
+ throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
1773
2357
  }
1774
2358
  if (owner !== actor.id) {
1775
- throw new import_common4.ForbiddenException("tool call belongs to another actor");
2359
+ throw new import_common6.ForbiddenException("tool call belongs to another actor");
1776
2360
  }
1777
2361
  }
1778
2362
  /**
@@ -1787,12 +2371,12 @@ var AgentService = class {
1787
2371
  if (this.store.toolCallInput === void 0) {
1788
2372
  return;
1789
2373
  }
1790
- const questions = (0, import_nestjs_agent_core5.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
2374
+ const questions = (0, import_nestjs_agent_core7.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
1791
2375
  for (const question of questions) {
1792
2376
  const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
1793
- const problem = (0, import_nestjs_agent_core5.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
2377
+ const problem = (0, import_nestjs_agent_core7.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
1794
2378
  if (problem !== null) {
1795
- throw new import_common4.BadRequestException(`answers["${question.id}"] ${problem}`);
2379
+ throw new import_common6.BadRequestException(`answers["${question.id}"] ${problem}`);
1796
2380
  }
1797
2381
  }
1798
2382
  }
@@ -1804,21 +2388,21 @@ var AgentService = class {
1804
2388
  */
1805
2389
  async assertMayDecide(actor, toolCallId2) {
1806
2390
  const approval = await this.store.toolCallApproval?.(toolCallId2);
1807
- const approver = approval?.approver ?? import_nestjs_agent_core5.REQUESTER_APPROVER;
1808
- if (approver === import_nestjs_agent_core5.REQUESTER_APPROVER) {
2391
+ const approver = approval?.approver ?? import_nestjs_agent_core7.REQUESTER_APPROVER;
2392
+ if (approver === import_nestjs_agent_core7.REQUESTER_APPROVER) {
1809
2393
  return this.assertOwnsToolCall(actor, toolCallId2);
1810
2394
  }
1811
2395
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1812
2396
  if (requesterRef === null) {
1813
- throw new import_common4.NotFoundException(`tool call ${toolCallId2} not found`);
2397
+ throw new import_common6.NotFoundException(`tool call ${toolCallId2} not found`);
1814
2398
  }
1815
- const allowed = await (0, import_nestjs_agent_core5.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
2399
+ const allowed = await (0, import_nestjs_agent_core7.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
1816
2400
  toolCallId: toolCallId2,
1817
2401
  approver,
1818
2402
  requesterRef
1819
2403
  });
1820
2404
  if (!allowed) {
1821
- throw new import_common4.ForbiddenException(`this approval is for ${approver}`);
2405
+ throw new import_common6.ForbiddenException(`this approval is for ${approver}`);
1822
2406
  }
1823
2407
  }
1824
2408
  /**
@@ -1834,7 +2418,7 @@ var AgentService = class {
1834
2418
  }
1835
2419
  const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
1836
2420
  if (lapsed) {
1837
- throw new import_common4.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
2421
+ throw new import_common6.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
1838
2422
  }
1839
2423
  }
1840
2424
  /**
@@ -1847,7 +2431,7 @@ var AgentService = class {
1847
2431
  async resolveRunForToolCall(toolCallId2) {
1848
2432
  const runId = await this.store.runForToolCall(toolCallId2);
1849
2433
  if (runId === null) {
1850
- throw new import_common4.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
2434
+ throw new import_common6.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
1851
2435
  }
1852
2436
  return runId;
1853
2437
  }
@@ -1855,29 +2439,30 @@ var AgentService = class {
1855
2439
  async assertOwnsActiveStream(actor, runId) {
1856
2440
  const owner = await this.store.ownerOfActiveStream(runId);
1857
2441
  if (owner === null) {
1858
- throw new import_common4.NotFoundException(`no active run ${runId}`);
2442
+ throw new import_common6.NotFoundException(`no active run ${runId}`);
1859
2443
  }
1860
2444
  if (owner !== actor.id) {
1861
- throw new import_common4.ForbiddenException("run belongs to another actor");
2445
+ throw new import_common6.ForbiddenException("run belongs to another actor");
1862
2446
  }
1863
2447
  }
1864
2448
  };
1865
- AgentService = _ts_decorate3([
1866
- (0, import_common4.Injectable)(),
1867
- _ts_param3(0, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_RUNNER)),
1868
- _ts_param3(1, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
1869
- _ts_param3(2, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
1870
- _ts_param3(3, (0, import_common4.Optional)()),
1871
- _ts_param3(3, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_ATTACHMENT_STAGING)),
1872
- _ts_param3(4, (0, import_common4.Optional)()),
1873
- _ts_param3(4, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_MODEL_CATALOG)),
1874
- _ts_param3(5, (0, import_common4.Optional)()),
1875
- _ts_param3(5, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_QUOTA_PROVIDER)),
1876
- _ts_param3(6, (0, import_common4.Optional)()),
1877
- _ts_param3(6, (0, import_common4.Inject)(import_nestjs_agent_core5.AGENT_OPTIONS)),
1878
- _ts_param3(7, (0, import_common4.Optional)()),
1879
- _ts_metadata3("design:type", Function),
1880
- _ts_metadata3("design:paramtypes", [
2449
+ AgentService = _ts_decorate5([
2450
+ (0, import_common6.Injectable)(),
2451
+ _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_RUNNER)),
2452
+ _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_STORE)),
2453
+ _ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_DEPS_FACTORY)),
2454
+ _ts_param4(3, (0, import_common6.Optional)()),
2455
+ _ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
2456
+ _ts_param4(4, (0, import_common6.Optional)()),
2457
+ _ts_param4(4, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_MODEL_CATALOG)),
2458
+ _ts_param4(5, (0, import_common6.Optional)()),
2459
+ _ts_param4(5, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_QUOTA_PROVIDER)),
2460
+ _ts_param4(6, (0, import_common6.Optional)()),
2461
+ _ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
2462
+ _ts_param4(7, (0, import_common6.Optional)()),
2463
+ _ts_param4(8, (0, import_common6.Optional)()),
2464
+ _ts_metadata4("design:type", Function),
2465
+ _ts_metadata4("design:paramtypes", [
1881
2466
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1882
2467
  typeof AgentStore === "undefined" ? Object : AgentStore,
1883
2468
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
@@ -1885,13 +2470,14 @@ AgentService = _ts_decorate3([
1885
2470
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1886
2471
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1887
2472
  typeof Pick === "undefined" ? Object : Pick,
1888
- typeof ChatQueueService === "undefined" ? Object : ChatQueueService
2473
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService,
2474
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
1889
2475
  ])
1890
2476
  ], AgentService);
1891
2477
 
1892
2478
  // src/approval-port.adapter.ts
1893
- var import_common5 = require("@nestjs/common");
1894
- function _ts_decorate4(decorators, target, key, desc) {
2479
+ var import_common7 = require("@nestjs/common");
2480
+ function _ts_decorate6(decorators, target, key, desc) {
1895
2481
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1896
2482
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1897
2483
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1904,20 +2490,48 @@ function _ts_decorate4(decorators, target, key, desc) {
1904
2490
  }
1905
2491
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1906
2492
  }
1907
- __name(_ts_decorate4, "_ts_decorate");
1908
- function _ts_metadata4(metadataKey, metadataValue) {
2493
+ __name(_ts_decorate6, "_ts_decorate");
2494
+ function _ts_metadata5(metadataKey, metadataValue) {
1909
2495
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1910
2496
  return Reflect.metadata(metadataKey, metadataValue);
1911
2497
  }
1912
2498
  }
1913
- __name(_ts_metadata4, "_ts_metadata");
2499
+ __name(_ts_metadata5, "_ts_metadata");
2500
+ function _ts_param5(paramIndex, decorator) {
2501
+ return function(target, key) {
2502
+ decorator(target, key, paramIndex);
2503
+ };
2504
+ }
2505
+ __name(_ts_param5, "_ts_param");
1914
2506
  var AgentApprovalPortAdapter = class {
1915
2507
  static {
1916
2508
  __name(this, "AgentApprovalPortAdapter");
1917
2509
  }
1918
2510
  agent;
1919
- constructor(agent) {
2511
+ proposals;
2512
+ constructor(agent, proposals) {
1920
2513
  this.agent = agent;
2514
+ this.proposals = proposals;
2515
+ }
2516
+ async approveActionProposal(actor, target, opts) {
2517
+ if (!this.proposals) throw new import_common7.NotImplementedException("Action proposals unavailable");
2518
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
2519
+ decision: "approved",
2520
+ ...opts?.remember !== void 0 ? {
2521
+ remember: opts.remember
2522
+ } : {},
2523
+ via: opts?.decidedVia ?? "console"
2524
+ });
2525
+ }
2526
+ async rejectActionProposal(actor, target, opts) {
2527
+ if (!this.proposals) throw new import_common7.NotImplementedException("Action proposals unavailable");
2528
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
2529
+ decision: "rejected",
2530
+ ...opts?.reason !== void 0 ? {
2531
+ reason: opts.reason
2532
+ } : {},
2533
+ via: opts?.decidedVia ?? "console"
2534
+ });
1921
2535
  }
1922
2536
  async approve(toolCallId2, opts) {
1923
2537
  await this.agent.signalToolCall(toolCallId2, {
@@ -1948,18 +2562,20 @@ var AgentApprovalPortAdapter = class {
1948
2562
  });
1949
2563
  }
1950
2564
  };
1951
- AgentApprovalPortAdapter = _ts_decorate4([
1952
- (0, import_common5.Injectable)(),
1953
- _ts_metadata4("design:type", Function),
1954
- _ts_metadata4("design:paramtypes", [
1955
- typeof AgentService === "undefined" ? Object : AgentService
2565
+ AgentApprovalPortAdapter = _ts_decorate6([
2566
+ (0, import_common7.Injectable)(),
2567
+ _ts_param5(1, (0, import_common7.Optional)()),
2568
+ _ts_metadata5("design:type", Function),
2569
+ _ts_metadata5("design:paramtypes", [
2570
+ typeof AgentService === "undefined" ? Object : AgentService,
2571
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
1956
2572
  ])
1957
2573
  ], AgentApprovalPortAdapter);
1958
2574
 
1959
2575
  // src/controller/agents.controller.ts
1960
- var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1961
- var import_common6 = require("@nestjs/common");
1962
- function _ts_decorate5(decorators, target, key, desc) {
2576
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
2577
+ var import_common8 = require("@nestjs/common");
2578
+ function _ts_decorate7(decorators, target, key, desc) {
1963
2579
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1964
2580
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1965
2581
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1972,19 +2588,19 @@ function _ts_decorate5(decorators, target, key, desc) {
1972
2588
  }
1973
2589
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1974
2590
  }
1975
- __name(_ts_decorate5, "_ts_decorate");
1976
- function _ts_metadata5(metadataKey, metadataValue) {
2591
+ __name(_ts_decorate7, "_ts_decorate");
2592
+ function _ts_metadata6(metadataKey, metadataValue) {
1977
2593
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1978
2594
  return Reflect.metadata(metadataKey, metadataValue);
1979
2595
  }
1980
2596
  }
1981
- __name(_ts_metadata5, "_ts_metadata");
1982
- function _ts_param4(paramIndex, decorator) {
2597
+ __name(_ts_metadata6, "_ts_metadata");
2598
+ function _ts_param6(paramIndex, decorator) {
1983
2599
  return function(target, key) {
1984
2600
  decorator(target, key, paramIndex);
1985
2601
  };
1986
2602
  }
1987
- __name(_ts_param4, "_ts_param");
2603
+ __name(_ts_param6, "_ts_param");
1988
2604
  var AgentsController = class {
1989
2605
  static {
1990
2606
  __name(this, "AgentsController");
@@ -1997,35 +2613,44 @@ var AgentsController = class {
1997
2613
  }
1998
2614
  list() {
1999
2615
  const defaultAgentName = this.depsFactory.defaultAgentName();
2000
- return this.agents.list().map((definition) => ({
2001
- name: definition.name,
2002
- description: definition.description ?? "",
2003
- ...definition.name === defaultAgentName ? {
2004
- isDefault: true
2005
- } : {}
2006
- }));
2616
+ return this.agents.list().map((definition) => {
2617
+ const personas = this.depsFactory.personaCatalog(definition.name);
2618
+ return {
2619
+ name: definition.name,
2620
+ description: definition.description ?? "",
2621
+ ...definition.name === defaultAgentName ? {
2622
+ isDefault: true
2623
+ } : {},
2624
+ ...personas.length > 0 ? {
2625
+ personas
2626
+ } : {},
2627
+ ...definition.defaultPersona !== void 0 ? {
2628
+ defaultPersona: definition.defaultPersona
2629
+ } : {}
2630
+ };
2631
+ });
2007
2632
  }
2008
2633
  };
2009
- _ts_decorate5([
2010
- (0, import_common6.Get)(),
2011
- _ts_metadata5("design:type", Function),
2012
- _ts_metadata5("design:paramtypes", []),
2013
- _ts_metadata5("design:returntype", Array)
2634
+ _ts_decorate7([
2635
+ (0, import_common8.Get)(),
2636
+ _ts_metadata6("design:type", Function),
2637
+ _ts_metadata6("design:paramtypes", []),
2638
+ _ts_metadata6("design:returntype", Array)
2014
2639
  ], AgentsController.prototype, "list", null);
2015
- AgentsController = _ts_decorate5([
2016
- (0, import_common6.Controller)("agents"),
2017
- _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_REGISTRY)),
2018
- _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_DEPS_FACTORY)),
2019
- _ts_metadata5("design:type", Function),
2020
- _ts_metadata5("design:paramtypes", [
2021
- typeof import_nestjs_agent_core6.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core6.AgentRegistry,
2640
+ AgentsController = _ts_decorate7([
2641
+ (0, import_common8.Controller)("agents"),
2642
+ _ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_REGISTRY)),
2643
+ _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_DEPS_FACTORY)),
2644
+ _ts_metadata6("design:type", Function),
2645
+ _ts_metadata6("design:paramtypes", [
2646
+ typeof import_nestjs_agent_core8.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core8.AgentRegistry,
2022
2647
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
2023
2648
  ])
2024
2649
  ], AgentsController);
2025
2650
 
2026
2651
  // src/controller/attachments.controller.ts
2027
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
2028
- var import_common7 = require("@nestjs/common");
2652
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
2653
+ var import_common9 = require("@nestjs/common");
2029
2654
  var import_platform_express = require("@nestjs/platform-express");
2030
2655
 
2031
2656
  // src/attachment-limits.ts
@@ -2054,7 +2679,7 @@ function attachmentLimits(options, staging) {
2054
2679
  __name(attachmentLimits, "attachmentLimits");
2055
2680
 
2056
2681
  // src/controller/attachments.controller.ts
2057
- function _ts_decorate6(decorators, target, key, desc) {
2682
+ function _ts_decorate8(decorators, target, key, desc) {
2058
2683
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2059
2684
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2060
2685
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2067,19 +2692,19 @@ function _ts_decorate6(decorators, target, key, desc) {
2067
2692
  }
2068
2693
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2069
2694
  }
2070
- __name(_ts_decorate6, "_ts_decorate");
2071
- function _ts_metadata6(metadataKey, metadataValue) {
2695
+ __name(_ts_decorate8, "_ts_decorate");
2696
+ function _ts_metadata7(metadataKey, metadataValue) {
2072
2697
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2073
2698
  return Reflect.metadata(metadataKey, metadataValue);
2074
2699
  }
2075
2700
  }
2076
- __name(_ts_metadata6, "_ts_metadata");
2077
- function _ts_param5(paramIndex, decorator) {
2701
+ __name(_ts_metadata7, "_ts_metadata");
2702
+ function _ts_param7(paramIndex, decorator) {
2078
2703
  return function(target, key) {
2079
2704
  decorator(target, key, paramIndex);
2080
2705
  };
2081
2706
  }
2082
- __name(_ts_param5, "_ts_param");
2707
+ __name(_ts_param7, "_ts_param");
2083
2708
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
2084
2709
  var ATTACHMENT_PAGE_SIZE = 50;
2085
2710
  var AttachmentsController = class {
@@ -2113,17 +2738,17 @@ var AttachmentsController = class {
2113
2738
  }
2114
2739
  async upload(req, file) {
2115
2740
  if (this.staging === void 0) {
2116
- throw new import_common7.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2741
+ throw new import_common9.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2117
2742
  }
2118
2743
  if (file === void 0) {
2119
- throw new import_common7.BadRequestException('multipart field "file" is required');
2744
+ throw new import_common9.BadRequestException('multipart field "file" is required');
2120
2745
  }
2121
2746
  const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
2122
2747
  if (!allowedContentTypes.includes(file.mimetype)) {
2123
- throw new import_common7.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
2748
+ throw new import_common9.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
2124
2749
  }
2125
2750
  if (file.size > maxBytes) {
2126
- throw new import_common7.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
2751
+ throw new import_common9.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
2127
2752
  }
2128
2753
  const actor = await this.actorResolver.resolve(req);
2129
2754
  return this.staging.stage({
@@ -2135,39 +2760,39 @@ var AttachmentsController = class {
2135
2760
  });
2136
2761
  }
2137
2762
  };
2138
- _ts_decorate6([
2139
- (0, import_common7.Get)(),
2140
- _ts_param5(0, (0, import_common7.Req)()),
2141
- _ts_metadata6("design:type", Function),
2142
- _ts_metadata6("design:paramtypes", [
2763
+ _ts_decorate8([
2764
+ (0, import_common9.Get)(),
2765
+ _ts_param7(0, (0, import_common9.Req)()),
2766
+ _ts_metadata7("design:type", Function),
2767
+ _ts_metadata7("design:paramtypes", [
2143
2768
  typeof Request === "undefined" ? Object : Request
2144
2769
  ]),
2145
- _ts_metadata6("design:returntype", Promise)
2770
+ _ts_metadata7("design:returntype", Promise)
2146
2771
  ], AttachmentsController.prototype, "list", null);
2147
- _ts_decorate6([
2148
- (0, import_common7.Post)(),
2149
- (0, import_common7.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
2772
+ _ts_decorate8([
2773
+ (0, import_common9.Post)(),
2774
+ (0, import_common9.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
2150
2775
  limits: {
2151
2776
  fileSize: HARD_MAX_ATTACHMENT_BYTES
2152
2777
  }
2153
2778
  })),
2154
- _ts_param5(0, (0, import_common7.Req)()),
2155
- _ts_param5(1, (0, import_common7.UploadedFile)()),
2156
- _ts_metadata6("design:type", Function),
2157
- _ts_metadata6("design:paramtypes", [
2779
+ _ts_param7(0, (0, import_common9.Req)()),
2780
+ _ts_param7(1, (0, import_common9.UploadedFile)()),
2781
+ _ts_metadata7("design:type", Function),
2782
+ _ts_metadata7("design:paramtypes", [
2158
2783
  typeof Request === "undefined" ? Object : Request,
2159
2784
  Object
2160
2785
  ]),
2161
- _ts_metadata6("design:returntype", Promise)
2786
+ _ts_metadata7("design:returntype", Promise)
2162
2787
  ], AttachmentsController.prototype, "upload", null);
2163
- AttachmentsController = _ts_decorate6([
2164
- (0, import_common7.Controller)("attachments"),
2165
- _ts_param5(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
2166
- _ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
2167
- _ts_param5(3, (0, import_common7.Optional)()),
2168
- _ts_param5(3, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
2169
- _ts_metadata6("design:type", Function),
2170
- _ts_metadata6("design:paramtypes", [
2788
+ AttachmentsController = _ts_decorate8([
2789
+ (0, import_common9.Controller)("attachments"),
2790
+ _ts_param7(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
2791
+ _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
2792
+ _ts_param7(3, (0, import_common9.Optional)()),
2793
+ _ts_param7(3, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
2794
+ _ts_metadata7("design:type", Function),
2795
+ _ts_metadata7("design:paramtypes", [
2171
2796
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2172
2797
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2173
2798
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -2176,9 +2801,10 @@ AttachmentsController = _ts_decorate6([
2176
2801
  ], AttachmentsController);
2177
2802
 
2178
2803
  // src/controller/chat.controller.ts
2179
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
2180
- var import_common8 = require("@nestjs/common");
2181
- function _ts_decorate7(decorators, target, key, desc) {
2804
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2805
+ var import_genui2 = require("@dudousxd/nestjs-agent-core/genui");
2806
+ var import_common10 = require("@nestjs/common");
2807
+ function _ts_decorate9(decorators, target, key, desc) {
2182
2808
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2183
2809
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2184
2810
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2191,19 +2817,19 @@ function _ts_decorate7(decorators, target, key, desc) {
2191
2817
  }
2192
2818
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2193
2819
  }
2194
- __name(_ts_decorate7, "_ts_decorate");
2195
- function _ts_metadata7(metadataKey, metadataValue) {
2820
+ __name(_ts_decorate9, "_ts_decorate");
2821
+ function _ts_metadata8(metadataKey, metadataValue) {
2196
2822
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2197
2823
  return Reflect.metadata(metadataKey, metadataValue);
2198
2824
  }
2199
2825
  }
2200
- __name(_ts_metadata7, "_ts_metadata");
2201
- function _ts_param6(paramIndex, decorator) {
2826
+ __name(_ts_metadata8, "_ts_metadata");
2827
+ function _ts_param8(paramIndex, decorator) {
2202
2828
  return function(target, key) {
2203
2829
  decorator(target, key, paramIndex);
2204
2830
  };
2205
2831
  }
2206
- __name(_ts_param6, "_ts_param");
2832
+ __name(_ts_param8, "_ts_param");
2207
2833
  function sendMode(body) {
2208
2834
  if (body.interrupt === true) {
2209
2835
  return "interrupt";
@@ -2214,7 +2840,7 @@ function sendMode(body) {
2214
2840
  if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2215
2841
  return body.mode;
2216
2842
  }
2217
- throw new import_common8.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
2843
+ throw new import_common10.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
2218
2844
  }
2219
2845
  __name(sendMode, "sendMode");
2220
2846
  function attachmentRefs(claimed) {
@@ -2222,21 +2848,21 @@ function attachmentRefs(claimed) {
2222
2848
  return [];
2223
2849
  }
2224
2850
  if (!Array.isArray(claimed)) {
2225
- throw new import_common8.BadRequestException("attachments must be an array of { mediaId }");
2851
+ throw new import_common10.BadRequestException("attachments must be an array of { mediaId }");
2226
2852
  }
2227
2853
  if (claimed.length > MAX_ATTACHMENTS_PER_MESSAGE) {
2228
- throw new import_common8.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2854
+ throw new import_common10.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2229
2855
  }
2230
2856
  return claimed.map((entry) => {
2231
2857
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
2232
- throw new import_common8.BadRequestException("each attachment must be an object with a mediaId");
2858
+ throw new import_common10.BadRequestException("each attachment must be an object with a mediaId");
2233
2859
  }
2234
2860
  if (Object.keys(entry).some((key) => key !== "mediaId")) {
2235
- throw new import_common8.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
2861
+ throw new import_common10.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
2236
2862
  }
2237
2863
  const { mediaId } = entry;
2238
2864
  if (typeof mediaId !== "string" || mediaId.length === 0) {
2239
- throw new import_common8.BadRequestException("each attachment must carry a non-empty string mediaId");
2865
+ throw new import_common10.BadRequestException("each attachment must carry a non-empty string mediaId");
2240
2866
  }
2241
2867
  return {
2242
2868
  mediaId
@@ -2264,15 +2890,27 @@ var ChatController = class {
2264
2890
  const actor = await this.actorResolver.resolve(req);
2265
2891
  const attachments = attachmentRefs(body.attachments);
2266
2892
  const mode = sendMode(body);
2893
+ let uiCapabilities;
2894
+ try {
2895
+ uiCapabilities = body.uiCapabilities === void 0 ? void 0 : (0, import_genui2.validateUiCapabilities)(body.uiCapabilities);
2896
+ } catch {
2897
+ throw new import_common10.BadRequestException("Invalid UI capabilities");
2898
+ }
2267
2899
  const result = await this.agent.send({
2268
2900
  actor,
2269
2901
  message: body.message,
2902
+ ...uiCapabilities !== void 0 ? {
2903
+ uiCapabilities
2904
+ } : {},
2270
2905
  ...body.threadId !== void 0 ? {
2271
2906
  threadId: body.threadId
2272
2907
  } : {},
2273
2908
  ...body.agent !== void 0 ? {
2274
2909
  agentName: body.agent
2275
2910
  } : {},
2911
+ ...typeof body.persona === "string" && body.persona.length > 0 ? {
2912
+ personaId: body.persona
2913
+ } : {},
2276
2914
  ...attachments.length > 0 ? {
2277
2915
  attachments
2278
2916
  } : {},
@@ -2290,6 +2928,10 @@ var ChatController = class {
2290
2928
  } : {},
2291
2929
  mode
2292
2930
  });
2931
+ if ("proposalDecision" in result) {
2932
+ res.status(200).json(result);
2933
+ return;
2934
+ }
2293
2935
  if (result.queued === true) {
2294
2936
  res.status(202).json(result);
2295
2937
  return;
@@ -2369,10 +3011,10 @@ data: ${line}
2369
3011
  }
2370
3012
  res.write("event: done\ndata: {}\n\n");
2371
3013
  } catch (error) {
2372
- const payload = error instanceof import_nestjs_agent_core8.AgentStreamError ? {
3014
+ const payload = error instanceof import_nestjs_agent_core10.AgentStreamError ? {
2373
3015
  code: error.code,
2374
3016
  message: error.message
2375
- } : (0, import_nestjs_agent_core8.streamFailure)(error);
3017
+ } : (0, import_nestjs_agent_core10.streamFailure)(error);
2376
3018
  res.write(`event: error
2377
3019
  data: ${JSON.stringify(payload)}
2378
3020
 
@@ -2381,50 +3023,50 @@ data: ${JSON.stringify(payload)}
2381
3023
  res.end();
2382
3024
  }
2383
3025
  };
2384
- _ts_decorate7([
2385
- (0, import_common8.Post)("chat"),
2386
- _ts_param6(0, (0, import_common8.Req)()),
2387
- _ts_param6(1, (0, import_common8.Res)()),
2388
- _ts_param6(2, (0, import_common8.Body)()),
2389
- _ts_metadata7("design:type", Function),
2390
- _ts_metadata7("design:paramtypes", [
3026
+ _ts_decorate9([
3027
+ (0, import_common10.Post)("chat"),
3028
+ _ts_param8(0, (0, import_common10.Req)()),
3029
+ _ts_param8(1, (0, import_common10.Res)()),
3030
+ _ts_param8(2, (0, import_common10.Body)()),
3031
+ _ts_metadata8("design:type", Function),
3032
+ _ts_metadata8("design:paramtypes", [
2391
3033
  typeof Request === "undefined" ? Object : Request,
2392
3034
  typeof Response === "undefined" ? Object : Response,
2393
3035
  typeof ChatBody === "undefined" ? Object : ChatBody
2394
3036
  ]),
2395
- _ts_metadata7("design:returntype", Promise)
3037
+ _ts_metadata8("design:returntype", Promise)
2396
3038
  ], ChatController.prototype, "chat", null);
2397
- _ts_decorate7([
2398
- (0, import_common8.Get)("chat/:runId/stream"),
2399
- _ts_param6(0, (0, import_common8.Req)()),
2400
- _ts_param6(1, (0, import_common8.Param)("runId")),
2401
- _ts_param6(2, (0, import_common8.Res)()),
2402
- _ts_param6(3, (0, import_common8.Query)("after")),
2403
- _ts_metadata7("design:type", Function),
2404
- _ts_metadata7("design:paramtypes", [
3039
+ _ts_decorate9([
3040
+ (0, import_common10.Get)("chat/:runId/stream"),
3041
+ _ts_param8(0, (0, import_common10.Req)()),
3042
+ _ts_param8(1, (0, import_common10.Param)("runId")),
3043
+ _ts_param8(2, (0, import_common10.Res)()),
3044
+ _ts_param8(3, (0, import_common10.Query)("after")),
3045
+ _ts_metadata8("design:type", Function),
3046
+ _ts_metadata8("design:paramtypes", [
2405
3047
  typeof Request === "undefined" ? Object : Request,
2406
3048
  String,
2407
3049
  typeof Response === "undefined" ? Object : Response,
2408
3050
  String
2409
3051
  ]),
2410
- _ts_metadata7("design:returntype", Promise)
3052
+ _ts_metadata8("design:returntype", Promise)
2411
3053
  ], ChatController.prototype, "stream", null);
2412
- _ts_decorate7([
2413
- (0, import_common8.Post)("chat/:runId/cancel"),
2414
- _ts_param6(0, (0, import_common8.Req)()),
2415
- _ts_param6(1, (0, import_common8.Param)("runId")),
2416
- _ts_metadata7("design:type", Function),
2417
- _ts_metadata7("design:paramtypes", [
3054
+ _ts_decorate9([
3055
+ (0, import_common10.Post)("chat/:runId/cancel"),
3056
+ _ts_param8(0, (0, import_common10.Req)()),
3057
+ _ts_param8(1, (0, import_common10.Param)("runId")),
3058
+ _ts_metadata8("design:type", Function),
3059
+ _ts_metadata8("design:paramtypes", [
2418
3060
  typeof Request === "undefined" ? Object : Request,
2419
3061
  String
2420
3062
  ]),
2421
- _ts_metadata7("design:returntype", Promise)
3063
+ _ts_metadata8("design:returntype", Promise)
2422
3064
  ], ChatController.prototype, "cancel", null);
2423
- ChatController = _ts_decorate7([
2424
- (0, import_common8.Controller)(),
2425
- _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
2426
- _ts_metadata7("design:type", Function),
2427
- _ts_metadata7("design:paramtypes", [
3065
+ ChatController = _ts_decorate9([
3066
+ (0, import_common10.Controller)(),
3067
+ _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
3068
+ _ts_metadata8("design:type", Function),
3069
+ _ts_metadata8("design:paramtypes", [
2428
3070
  typeof AgentService === "undefined" ? Object : AgentService,
2429
3071
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2430
3072
  ])
@@ -2440,8 +3082,8 @@ function parseCursor(raw) {
2440
3082
  __name(parseCursor, "parseCursor");
2441
3083
 
2442
3084
  // src/controller/config.controller.ts
2443
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
2444
- var import_common9 = require("@nestjs/common");
3085
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
3086
+ var import_common11 = require("@nestjs/common");
2445
3087
 
2446
3088
  // src/resolver/anonymous-actor-resolver.ts
2447
3089
  var import_node_crypto = require("crypto");
@@ -2531,7 +3173,7 @@ var AnonymousActorResolver = class {
2531
3173
  };
2532
3174
 
2533
3175
  // src/controller/config.controller.ts
2534
- function _ts_decorate8(decorators, target, key, desc) {
3176
+ function _ts_decorate10(decorators, target, key, desc) {
2535
3177
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2536
3178
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2537
3179
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2544,19 +3186,19 @@ function _ts_decorate8(decorators, target, key, desc) {
2544
3186
  }
2545
3187
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2546
3188
  }
2547
- __name(_ts_decorate8, "_ts_decorate");
2548
- function _ts_metadata8(metadataKey, metadataValue) {
3189
+ __name(_ts_decorate10, "_ts_decorate");
3190
+ function _ts_metadata9(metadataKey, metadataValue) {
2549
3191
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2550
3192
  return Reflect.metadata(metadataKey, metadataValue);
2551
3193
  }
2552
3194
  }
2553
- __name(_ts_metadata8, "_ts_metadata");
2554
- function _ts_param7(paramIndex, decorator) {
3195
+ __name(_ts_metadata9, "_ts_metadata");
3196
+ function _ts_param9(paramIndex, decorator) {
2555
3197
  return function(target, key) {
2556
3198
  decorator(target, key, paramIndex);
2557
3199
  };
2558
3200
  }
2559
- __name(_ts_param7, "_ts_param");
3201
+ __name(_ts_param9, "_ts_param");
2560
3202
  var ConfigController = class {
2561
3203
  static {
2562
3204
  __name(this, "ConfigController");
@@ -2587,25 +3229,25 @@ var ConfigController = class {
2587
3229
  };
2588
3230
  }
2589
3231
  };
2590
- _ts_decorate8([
2591
- (0, import_common9.Get)(),
2592
- _ts_param7(0, (0, import_common9.Req)()),
2593
- _ts_metadata8("design:type", Function),
2594
- _ts_metadata8("design:paramtypes", [
3232
+ _ts_decorate10([
3233
+ (0, import_common11.Get)(),
3234
+ _ts_param9(0, (0, import_common11.Req)()),
3235
+ _ts_metadata9("design:type", Function),
3236
+ _ts_metadata9("design:paramtypes", [
2595
3237
  typeof Request === "undefined" ? Object : Request
2596
3238
  ]),
2597
- _ts_metadata8("design:returntype", Promise)
3239
+ _ts_metadata9("design:returntype", Promise)
2598
3240
  ], ConfigController.prototype, "config", null);
2599
- ConfigController = _ts_decorate8([
2600
- (0, import_common9.Controller)("config"),
2601
- _ts_param7(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
2602
- _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
2603
- _ts_param7(2, (0, import_common9.Optional)()),
2604
- _ts_param7(2, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
2605
- _ts_param7(3, (0, import_common9.Optional)()),
2606
- _ts_param7(3, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_MODEL_CATALOG)),
2607
- _ts_metadata8("design:type", Function),
2608
- _ts_metadata8("design:paramtypes", [
3241
+ ConfigController = _ts_decorate10([
3242
+ (0, import_common11.Controller)("config"),
3243
+ _ts_param9(0, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_OPTIONS)),
3244
+ _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
3245
+ _ts_param9(2, (0, import_common11.Optional)()),
3246
+ _ts_param9(2, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ATTACHMENT_STAGING)),
3247
+ _ts_param9(3, (0, import_common11.Optional)()),
3248
+ _ts_param9(3, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_MODEL_CATALOG)),
3249
+ _ts_metadata9("design:type", Function),
3250
+ _ts_metadata9("design:paramtypes", [
2609
3251
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2610
3252
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2611
3253
  Object,
@@ -2614,9 +3256,9 @@ ConfigController = _ts_decorate8([
2614
3256
  ], ConfigController);
2615
3257
 
2616
3258
  // src/controller/memories.controller.ts
2617
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
2618
- var import_common10 = require("@nestjs/common");
2619
- function _ts_decorate9(decorators, target, key, desc) {
3259
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
3260
+ var import_common12 = require("@nestjs/common");
3261
+ function _ts_decorate11(decorators, target, key, desc) {
2620
3262
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2621
3263
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2622
3264
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2629,19 +3271,19 @@ function _ts_decorate9(decorators, target, key, desc) {
2629
3271
  }
2630
3272
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2631
3273
  }
2632
- __name(_ts_decorate9, "_ts_decorate");
2633
- function _ts_metadata9(metadataKey, metadataValue) {
3274
+ __name(_ts_decorate11, "_ts_decorate");
3275
+ function _ts_metadata10(metadataKey, metadataValue) {
2634
3276
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2635
3277
  return Reflect.metadata(metadataKey, metadataValue);
2636
3278
  }
2637
3279
  }
2638
- __name(_ts_metadata9, "_ts_metadata");
2639
- function _ts_param8(paramIndex, decorator) {
3280
+ __name(_ts_metadata10, "_ts_metadata");
3281
+ function _ts_param10(paramIndex, decorator) {
2640
3282
  return function(target, key) {
2641
3283
  decorator(target, key, paramIndex);
2642
3284
  };
2643
3285
  }
2644
- __name(_ts_param8, "_ts_param");
3286
+ __name(_ts_param10, "_ts_param");
2645
3287
  var MemoriesController = class {
2646
3288
  static {
2647
3289
  __name(this, "MemoriesController");
@@ -2675,20 +3317,20 @@ var MemoriesController = class {
2675
3317
  */
2676
3318
  async forget(req, id) {
2677
3319
  if (this.memory === void 0) {
2678
- throw new import_common10.NotFoundException("No memory is configured in this deployment.");
3320
+ throw new import_common12.NotFoundException("No memory is configured in this deployment.");
2679
3321
  }
2680
3322
  const actor = await this.actorResolver.resolve(req);
2681
3323
  const digest = await this.unbounded("", actor);
2682
3324
  const entry = digest.entries.find((candidate) => candidate.id === id);
2683
3325
  if (entry === void 0) {
2684
- throw new import_common10.NotFoundException(`No memory with id "${id}".`);
3326
+ throw new import_common12.NotFoundException(`No memory with id "${id}".`);
2685
3327
  }
2686
- const verdict = (0, import_nestjs_agent_core10.memoryForgetVerdict)({
3328
+ const verdict = (0, import_nestjs_agent_core12.memoryForgetVerdict)({
2687
3329
  record: entry,
2688
3330
  actor
2689
3331
  });
2690
3332
  if (!verdict.allowed) {
2691
- throw new import_common10.ForbiddenException(verdict.reason);
3333
+ throw new import_common12.ForbiddenException(verdict.reason);
2692
3334
  }
2693
3335
  return {
2694
3336
  forgotten: await this.memory.provider.forget({
@@ -2702,7 +3344,7 @@ var MemoriesController = class {
2702
3344
  }
2703
3345
  async unbounded(threadId, actor) {
2704
3346
  const config = this.memory;
2705
- return await (0, import_nestjs_agent_core10.offerMemories)({
3347
+ return await (0, import_nestjs_agent_core12.offerMemories)({
2706
3348
  config: {
2707
3349
  ...config,
2708
3350
  maxMemories: Number.POSITIVE_INFINITY
@@ -2714,44 +3356,44 @@ var MemoriesController = class {
2714
3356
  });
2715
3357
  }
2716
3358
  };
2717
- _ts_decorate9([
2718
- (0, import_common10.Get)(),
2719
- _ts_param8(0, (0, import_common10.Req)()),
2720
- _ts_param8(1, (0, import_common10.Query)("threadId")),
2721
- _ts_metadata9("design:type", Function),
2722
- _ts_metadata9("design:paramtypes", [
3359
+ _ts_decorate11([
3360
+ (0, import_common12.Get)(),
3361
+ _ts_param10(0, (0, import_common12.Req)()),
3362
+ _ts_param10(1, (0, import_common12.Query)("threadId")),
3363
+ _ts_metadata10("design:type", Function),
3364
+ _ts_metadata10("design:paramtypes", [
2723
3365
  typeof Request === "undefined" ? Object : Request,
2724
3366
  String
2725
3367
  ]),
2726
- _ts_metadata9("design:returntype", Promise)
3368
+ _ts_metadata10("design:returntype", Promise)
2727
3369
  ], MemoriesController.prototype, "list", null);
2728
- _ts_decorate9([
2729
- (0, import_common10.Delete)(":id"),
2730
- _ts_param8(0, (0, import_common10.Req)()),
2731
- _ts_param8(1, (0, import_common10.Param)("id")),
2732
- _ts_metadata9("design:type", Function),
2733
- _ts_metadata9("design:paramtypes", [
3370
+ _ts_decorate11([
3371
+ (0, import_common12.Delete)(":id"),
3372
+ _ts_param10(0, (0, import_common12.Req)()),
3373
+ _ts_param10(1, (0, import_common12.Param)("id")),
3374
+ _ts_metadata10("design:type", Function),
3375
+ _ts_metadata10("design:paramtypes", [
2734
3376
  typeof Request === "undefined" ? Object : Request,
2735
3377
  String
2736
3378
  ]),
2737
- _ts_metadata9("design:returntype", Promise)
3379
+ _ts_metadata10("design:returntype", Promise)
2738
3380
  ], MemoriesController.prototype, "forget", null);
2739
- MemoriesController = _ts_decorate9([
2740
- (0, import_common10.Controller)("memories"),
2741
- _ts_param8(0, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
2742
- _ts_param8(1, (0, import_common10.Optional)()),
2743
- _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_MEMORY)),
2744
- _ts_metadata9("design:type", Function),
2745
- _ts_metadata9("design:paramtypes", [
3381
+ MemoriesController = _ts_decorate11([
3382
+ (0, import_common12.Controller)("memories"),
3383
+ _ts_param10(0, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
3384
+ _ts_param10(1, (0, import_common12.Optional)()),
3385
+ _ts_param10(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_MEMORY)),
3386
+ _ts_metadata10("design:type", Function),
3387
+ _ts_metadata10("design:paramtypes", [
2746
3388
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2747
3389
  Object
2748
3390
  ])
2749
3391
  ], MemoriesController);
2750
3392
 
2751
3393
  // src/controller/messages.controller.ts
2752
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2753
- var import_common11 = require("@nestjs/common");
2754
- function _ts_decorate10(decorators, target, key, desc) {
3394
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
3395
+ var import_common13 = require("@nestjs/common");
3396
+ function _ts_decorate12(decorators, target, key, desc) {
2755
3397
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2756
3398
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2757
3399
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2764,19 +3406,19 @@ function _ts_decorate10(decorators, target, key, desc) {
2764
3406
  }
2765
3407
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2766
3408
  }
2767
- __name(_ts_decorate10, "_ts_decorate");
2768
- function _ts_metadata10(metadataKey, metadataValue) {
3409
+ __name(_ts_decorate12, "_ts_decorate");
3410
+ function _ts_metadata11(metadataKey, metadataValue) {
2769
3411
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2770
3412
  return Reflect.metadata(metadataKey, metadataValue);
2771
3413
  }
2772
3414
  }
2773
- __name(_ts_metadata10, "_ts_metadata");
2774
- function _ts_param9(paramIndex, decorator) {
3415
+ __name(_ts_metadata11, "_ts_metadata");
3416
+ function _ts_param11(paramIndex, decorator) {
2775
3417
  return function(target, key) {
2776
3418
  decorator(target, key, paramIndex);
2777
3419
  };
2778
3420
  }
2779
- __name(_ts_param9, "_ts_param");
3421
+ __name(_ts_param11, "_ts_param");
2780
3422
  var MessagesController = class {
2781
3423
  static {
2782
3424
  __name(this, "MessagesController");
@@ -2804,34 +3446,34 @@ var MessagesController = class {
2804
3446
  };
2805
3447
  }
2806
3448
  };
2807
- _ts_decorate10([
2808
- (0, import_common11.Post)(":id/feedback"),
2809
- (0, import_common11.HttpCode)(200),
2810
- _ts_param9(0, (0, import_common11.Req)()),
2811
- _ts_param9(1, (0, import_common11.Param)("id")),
2812
- _ts_param9(2, (0, import_common11.Body)()),
2813
- _ts_metadata10("design:type", Function),
2814
- _ts_metadata10("design:paramtypes", [
3449
+ _ts_decorate12([
3450
+ (0, import_common13.Post)(":id/feedback"),
3451
+ (0, import_common13.HttpCode)(200),
3452
+ _ts_param11(0, (0, import_common13.Req)()),
3453
+ _ts_param11(1, (0, import_common13.Param)("id")),
3454
+ _ts_param11(2, (0, import_common13.Body)()),
3455
+ _ts_metadata11("design:type", Function),
3456
+ _ts_metadata11("design:paramtypes", [
2815
3457
  typeof Request === "undefined" ? Object : Request,
2816
3458
  String,
2817
3459
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
2818
3460
  ]),
2819
- _ts_metadata10("design:returntype", Promise)
3461
+ _ts_metadata11("design:returntype", Promise)
2820
3462
  ], MessagesController.prototype, "feedback", null);
2821
- MessagesController = _ts_decorate10([
2822
- (0, import_common11.Controller)("messages"),
2823
- _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
2824
- _ts_metadata10("design:type", Function),
2825
- _ts_metadata10("design:paramtypes", [
3463
+ MessagesController = _ts_decorate12([
3464
+ (0, import_common13.Controller)("messages"),
3465
+ _ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3466
+ _ts_metadata11("design:type", Function),
3467
+ _ts_metadata11("design:paramtypes", [
2826
3468
  typeof AgentService === "undefined" ? Object : AgentService,
2827
3469
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2828
3470
  ])
2829
3471
  ], MessagesController);
2830
3472
 
2831
3473
  // src/controller/models.controller.ts
2832
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
2833
- var import_common12 = require("@nestjs/common");
2834
- function _ts_decorate11(decorators, target, key, desc) {
3474
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3475
+ var import_common14 = require("@nestjs/common");
3476
+ function _ts_decorate13(decorators, target, key, desc) {
2835
3477
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2836
3478
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2837
3479
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2844,19 +3486,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2844
3486
  }
2845
3487
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2846
3488
  }
2847
- __name(_ts_decorate11, "_ts_decorate");
2848
- function _ts_metadata11(metadataKey, metadataValue) {
3489
+ __name(_ts_decorate13, "_ts_decorate");
3490
+ function _ts_metadata12(metadataKey, metadataValue) {
2849
3491
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2850
3492
  return Reflect.metadata(metadataKey, metadataValue);
2851
3493
  }
2852
3494
  }
2853
- __name(_ts_metadata11, "_ts_metadata");
2854
- function _ts_param10(paramIndex, decorator) {
3495
+ __name(_ts_metadata12, "_ts_metadata");
3496
+ function _ts_param12(paramIndex, decorator) {
2855
3497
  return function(target, key) {
2856
3498
  decorator(target, key, paramIndex);
2857
3499
  };
2858
3500
  }
2859
- __name(_ts_param10, "_ts_param");
3501
+ __name(_ts_param12, "_ts_param");
2860
3502
  var ModelsController = class {
2861
3503
  static {
2862
3504
  __name(this, "ModelsController");
@@ -2876,31 +3518,31 @@ var ModelsController = class {
2876
3518
  return this.agent.listModels(actor, agent);
2877
3519
  }
2878
3520
  };
2879
- _ts_decorate11([
2880
- (0, import_common12.Get)(),
2881
- _ts_param10(0, (0, import_common12.Req)()),
2882
- _ts_param10(1, (0, import_common12.Query)("agent")),
2883
- _ts_metadata11("design:type", Function),
2884
- _ts_metadata11("design:paramtypes", [
3521
+ _ts_decorate13([
3522
+ (0, import_common14.Get)(),
3523
+ _ts_param12(0, (0, import_common14.Req)()),
3524
+ _ts_param12(1, (0, import_common14.Query)("agent")),
3525
+ _ts_metadata12("design:type", Function),
3526
+ _ts_metadata12("design:paramtypes", [
2885
3527
  typeof Request === "undefined" ? Object : Request,
2886
3528
  String
2887
3529
  ]),
2888
- _ts_metadata11("design:returntype", Promise)
3530
+ _ts_metadata12("design:returntype", Promise)
2889
3531
  ], ModelsController.prototype, "list", null);
2890
- ModelsController = _ts_decorate11([
2891
- (0, import_common12.Controller)("models"),
2892
- _ts_param10(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
2893
- _ts_metadata11("design:type", Function),
2894
- _ts_metadata11("design:paramtypes", [
3532
+ ModelsController = _ts_decorate13([
3533
+ (0, import_common14.Controller)("models"),
3534
+ _ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3535
+ _ts_metadata12("design:type", Function),
3536
+ _ts_metadata12("design:paramtypes", [
2895
3537
  typeof AgentService === "undefined" ? Object : AgentService,
2896
3538
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2897
3539
  ])
2898
3540
  ], ModelsController);
2899
3541
 
2900
3542
  // src/controller/queue.controller.ts
2901
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2902
- var import_common13 = require("@nestjs/common");
2903
- function _ts_decorate12(decorators, target, key, desc) {
3543
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3544
+ var import_common15 = require("@nestjs/common");
3545
+ function _ts_decorate14(decorators, target, key, desc) {
2904
3546
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2905
3547
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2906
3548
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2913,19 +3555,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2913
3555
  }
2914
3556
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2915
3557
  }
2916
- __name(_ts_decorate12, "_ts_decorate");
2917
- function _ts_metadata12(metadataKey, metadataValue) {
3558
+ __name(_ts_decorate14, "_ts_decorate");
3559
+ function _ts_metadata13(metadataKey, metadataValue) {
2918
3560
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2919
3561
  return Reflect.metadata(metadataKey, metadataValue);
2920
3562
  }
2921
3563
  }
2922
- __name(_ts_metadata12, "_ts_metadata");
2923
- function _ts_param11(paramIndex, decorator) {
3564
+ __name(_ts_metadata13, "_ts_metadata");
3565
+ function _ts_param13(paramIndex, decorator) {
2924
3566
  return function(target, key) {
2925
3567
  decorator(target, key, paramIndex);
2926
3568
  };
2927
3569
  }
2928
- __name(_ts_param11, "_ts_param");
3570
+ __name(_ts_param13, "_ts_param");
2929
3571
  var QueueController = class {
2930
3572
  static {
2931
3573
  __name(this, "QueueController");
@@ -2949,10 +3591,10 @@ var QueueController = class {
2949
3591
  async update(req, messageId, body) {
2950
3592
  const actor = await this.actorResolver.resolve(req);
2951
3593
  if (body.message !== void 0 && typeof body.message !== "string") {
2952
- throw new import_common13.BadRequestException("message must be a string");
3594
+ throw new import_common15.BadRequestException("message must be a string");
2953
3595
  }
2954
3596
  if (body.position !== void 0 && typeof body.position !== "number") {
2955
- throw new import_common13.BadRequestException("position must be a number");
3597
+ throw new import_common15.BadRequestException("position must be a number");
2956
3598
  }
2957
3599
  const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
2958
3600
  return this.agent.updateQueuedMessage(actor, messageId, {
@@ -2979,88 +3621,88 @@ var QueueController = class {
2979
3621
  return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
2980
3622
  }
2981
3623
  };
2982
- _ts_decorate12([
2983
- (0, import_common13.Get)("threads/:id/queue"),
2984
- _ts_param11(0, (0, import_common13.Req)()),
2985
- _ts_param11(1, (0, import_common13.Param)("id")),
2986
- _ts_metadata12("design:type", Function),
2987
- _ts_metadata12("design:paramtypes", [
3624
+ _ts_decorate14([
3625
+ (0, import_common15.Get)("threads/:id/queue"),
3626
+ _ts_param13(0, (0, import_common15.Req)()),
3627
+ _ts_param13(1, (0, import_common15.Param)("id")),
3628
+ _ts_metadata13("design:type", Function),
3629
+ _ts_metadata13("design:paramtypes", [
2988
3630
  typeof Request === "undefined" ? Object : Request,
2989
3631
  String
2990
3632
  ]),
2991
- _ts_metadata12("design:returntype", Promise)
3633
+ _ts_metadata13("design:returntype", Promise)
2992
3634
  ], QueueController.prototype, "list", null);
2993
- _ts_decorate12([
2994
- (0, import_common13.Delete)("threads/:id/queue"),
2995
- _ts_param11(0, (0, import_common13.Req)()),
2996
- _ts_param11(1, (0, import_common13.Param)("id")),
2997
- _ts_metadata12("design:type", Function),
2998
- _ts_metadata12("design:paramtypes", [
3635
+ _ts_decorate14([
3636
+ (0, import_common15.Delete)("threads/:id/queue"),
3637
+ _ts_param13(0, (0, import_common15.Req)()),
3638
+ _ts_param13(1, (0, import_common15.Param)("id")),
3639
+ _ts_metadata13("design:type", Function),
3640
+ _ts_metadata13("design:paramtypes", [
2999
3641
  typeof Request === "undefined" ? Object : Request,
3000
3642
  String
3001
3643
  ]),
3002
- _ts_metadata12("design:returntype", Promise)
3644
+ _ts_metadata13("design:returntype", Promise)
3003
3645
  ], QueueController.prototype, "clear", null);
3004
- _ts_decorate12([
3005
- (0, import_common13.Post)("threads/:id/queue/resume"),
3006
- _ts_param11(0, (0, import_common13.Req)()),
3007
- _ts_param11(1, (0, import_common13.Param)("id")),
3008
- _ts_metadata12("design:type", Function),
3009
- _ts_metadata12("design:paramtypes", [
3646
+ _ts_decorate14([
3647
+ (0, import_common15.Post)("threads/:id/queue/resume"),
3648
+ _ts_param13(0, (0, import_common15.Req)()),
3649
+ _ts_param13(1, (0, import_common15.Param)("id")),
3650
+ _ts_metadata13("design:type", Function),
3651
+ _ts_metadata13("design:paramtypes", [
3010
3652
  typeof Request === "undefined" ? Object : Request,
3011
3653
  String
3012
3654
  ]),
3013
- _ts_metadata12("design:returntype", Promise)
3655
+ _ts_metadata13("design:returntype", Promise)
3014
3656
  ], QueueController.prototype, "resume", null);
3015
- _ts_decorate12([
3016
- (0, import_common13.Patch)("queue/:messageId"),
3017
- _ts_param11(0, (0, import_common13.Req)()),
3018
- _ts_param11(1, (0, import_common13.Param)("messageId")),
3019
- _ts_param11(2, (0, import_common13.Body)()),
3020
- _ts_metadata12("design:type", Function),
3021
- _ts_metadata12("design:paramtypes", [
3657
+ _ts_decorate14([
3658
+ (0, import_common15.Patch)("queue/:messageId"),
3659
+ _ts_param13(0, (0, import_common15.Req)()),
3660
+ _ts_param13(1, (0, import_common15.Param)("messageId")),
3661
+ _ts_param13(2, (0, import_common15.Body)()),
3662
+ _ts_metadata13("design:type", Function),
3663
+ _ts_metadata13("design:paramtypes", [
3022
3664
  typeof Request === "undefined" ? Object : Request,
3023
3665
  String,
3024
3666
  typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
3025
3667
  ]),
3026
- _ts_metadata12("design:returntype", Promise)
3668
+ _ts_metadata13("design:returntype", Promise)
3027
3669
  ], QueueController.prototype, "update", null);
3028
- _ts_decorate12([
3029
- (0, import_common13.Post)("queue/:messageId/interrupt"),
3030
- _ts_param11(0, (0, import_common13.Req)()),
3031
- _ts_param11(1, (0, import_common13.Param)("messageId")),
3032
- _ts_metadata12("design:type", Function),
3033
- _ts_metadata12("design:paramtypes", [
3670
+ _ts_decorate14([
3671
+ (0, import_common15.Post)("queue/:messageId/interrupt"),
3672
+ _ts_param13(0, (0, import_common15.Req)()),
3673
+ _ts_param13(1, (0, import_common15.Param)("messageId")),
3674
+ _ts_metadata13("design:type", Function),
3675
+ _ts_metadata13("design:paramtypes", [
3034
3676
  typeof Request === "undefined" ? Object : Request,
3035
3677
  String
3036
3678
  ]),
3037
- _ts_metadata12("design:returntype", Promise)
3679
+ _ts_metadata13("design:returntype", Promise)
3038
3680
  ], QueueController.prototype, "interrupt", null);
3039
- _ts_decorate12([
3040
- (0, import_common13.Delete)("queue/:messageId"),
3041
- _ts_param11(0, (0, import_common13.Req)()),
3042
- _ts_param11(1, (0, import_common13.Param)("messageId")),
3043
- _ts_metadata12("design:type", Function),
3044
- _ts_metadata12("design:paramtypes", [
3681
+ _ts_decorate14([
3682
+ (0, import_common15.Delete)("queue/:messageId"),
3683
+ _ts_param13(0, (0, import_common15.Req)()),
3684
+ _ts_param13(1, (0, import_common15.Param)("messageId")),
3685
+ _ts_metadata13("design:type", Function),
3686
+ _ts_metadata13("design:paramtypes", [
3045
3687
  typeof Request === "undefined" ? Object : Request,
3046
3688
  String
3047
3689
  ]),
3048
- _ts_metadata12("design:returntype", Promise)
3690
+ _ts_metadata13("design:returntype", Promise)
3049
3691
  ], QueueController.prototype, "remove", null);
3050
- QueueController = _ts_decorate12([
3051
- (0, import_common13.Controller)(),
3052
- _ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3053
- _ts_metadata12("design:type", Function),
3054
- _ts_metadata12("design:paramtypes", [
3692
+ QueueController = _ts_decorate14([
3693
+ (0, import_common15.Controller)(),
3694
+ _ts_param13(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3695
+ _ts_metadata13("design:type", Function),
3696
+ _ts_metadata13("design:paramtypes", [
3055
3697
  typeof AgentService === "undefined" ? Object : AgentService,
3056
3698
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3057
3699
  ])
3058
3700
  ], QueueController);
3059
3701
 
3060
3702
  // src/controller/quota.controller.ts
3061
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3062
- var import_common14 = require("@nestjs/common");
3063
- function _ts_decorate13(decorators, target, key, desc) {
3703
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3704
+ var import_common16 = require("@nestjs/common");
3705
+ function _ts_decorate15(decorators, target, key, desc) {
3064
3706
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3065
3707
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3066
3708
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3073,19 +3715,19 @@ function _ts_decorate13(decorators, target, key, desc) {
3073
3715
  }
3074
3716
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3075
3717
  }
3076
- __name(_ts_decorate13, "_ts_decorate");
3077
- function _ts_metadata13(metadataKey, metadataValue) {
3718
+ __name(_ts_decorate15, "_ts_decorate");
3719
+ function _ts_metadata14(metadataKey, metadataValue) {
3078
3720
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3079
3721
  return Reflect.metadata(metadataKey, metadataValue);
3080
3722
  }
3081
3723
  }
3082
- __name(_ts_metadata13, "_ts_metadata");
3083
- function _ts_param12(paramIndex, decorator) {
3724
+ __name(_ts_metadata14, "_ts_metadata");
3725
+ function _ts_param14(paramIndex, decorator) {
3084
3726
  return function(target, key) {
3085
3727
  decorator(target, key, paramIndex);
3086
3728
  };
3087
3729
  }
3088
- __name(_ts_param12, "_ts_param");
3730
+ __name(_ts_param14, "_ts_param");
3089
3731
  var QuotaController = class {
3090
3732
  static {
3091
3733
  __name(this, "QuotaController");
@@ -3105,29 +3747,29 @@ var QuotaController = class {
3105
3747
  return this.agent.quotaReport(actor);
3106
3748
  }
3107
3749
  };
3108
- _ts_decorate13([
3109
- (0, import_common14.Get)(),
3110
- _ts_param12(0, (0, import_common14.Req)()),
3111
- _ts_metadata13("design:type", Function),
3112
- _ts_metadata13("design:paramtypes", [
3750
+ _ts_decorate15([
3751
+ (0, import_common16.Get)(),
3752
+ _ts_param14(0, (0, import_common16.Req)()),
3753
+ _ts_metadata14("design:type", Function),
3754
+ _ts_metadata14("design:paramtypes", [
3113
3755
  typeof Request === "undefined" ? Object : Request
3114
3756
  ]),
3115
- _ts_metadata13("design:returntype", Promise)
3757
+ _ts_metadata14("design:returntype", Promise)
3116
3758
  ], QuotaController.prototype, "report", null);
3117
- QuotaController = _ts_decorate13([
3118
- (0, import_common14.Controller)("quota"),
3119
- _ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3120
- _ts_metadata13("design:type", Function),
3121
- _ts_metadata13("design:paramtypes", [
3759
+ QuotaController = _ts_decorate15([
3760
+ (0, import_common16.Controller)("quota"),
3761
+ _ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3762
+ _ts_metadata14("design:type", Function),
3763
+ _ts_metadata14("design:paramtypes", [
3122
3764
  typeof AgentService === "undefined" ? Object : AgentService,
3123
3765
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3124
3766
  ])
3125
3767
  ], QuotaController);
3126
3768
 
3127
3769
  // src/controller/skills.controller.ts
3128
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3129
- var import_common15 = require("@nestjs/common");
3130
- function _ts_decorate14(decorators, target, key, desc) {
3770
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3771
+ var import_common17 = require("@nestjs/common");
3772
+ function _ts_decorate16(decorators, target, key, desc) {
3131
3773
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3132
3774
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3133
3775
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3140,19 +3782,19 @@ function _ts_decorate14(decorators, target, key, desc) {
3140
3782
  }
3141
3783
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3142
3784
  }
3143
- __name(_ts_decorate14, "_ts_decorate");
3144
- function _ts_metadata14(metadataKey, metadataValue) {
3785
+ __name(_ts_decorate16, "_ts_decorate");
3786
+ function _ts_metadata15(metadataKey, metadataValue) {
3145
3787
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3146
3788
  return Reflect.metadata(metadataKey, metadataValue);
3147
3789
  }
3148
3790
  }
3149
- __name(_ts_metadata14, "_ts_metadata");
3150
- function _ts_param13(paramIndex, decorator) {
3791
+ __name(_ts_metadata15, "_ts_metadata");
3792
+ function _ts_param15(paramIndex, decorator) {
3151
3793
  return function(target, key) {
3152
3794
  decorator(target, key, paramIndex);
3153
3795
  };
3154
3796
  }
3155
- __name(_ts_param13, "_ts_param");
3797
+ __name(_ts_param15, "_ts_param");
3156
3798
  var SkillsController = class {
3157
3799
  static {
3158
3800
  __name(this, "SkillsController");
@@ -3168,40 +3810,40 @@ var SkillsController = class {
3168
3810
  return [];
3169
3811
  }
3170
3812
  const actor = await this.actorResolver.resolve(req);
3171
- const offer = await (0, import_nestjs_agent_core15.offerSkills)(this.skills, {
3813
+ const offer = await (0, import_nestjs_agent_core17.offerSkills)(this.skills, {
3172
3814
  actor,
3173
3815
  threadId: threadId ?? ""
3174
3816
  });
3175
3817
  return offer.entries;
3176
3818
  }
3177
3819
  };
3178
- _ts_decorate14([
3179
- (0, import_common15.Get)(),
3180
- _ts_param13(0, (0, import_common15.Req)()),
3181
- _ts_param13(1, (0, import_common15.Query)("threadId")),
3182
- _ts_metadata14("design:type", Function),
3183
- _ts_metadata14("design:paramtypes", [
3820
+ _ts_decorate16([
3821
+ (0, import_common17.Get)(),
3822
+ _ts_param15(0, (0, import_common17.Req)()),
3823
+ _ts_param15(1, (0, import_common17.Query)("threadId")),
3824
+ _ts_metadata15("design:type", Function),
3825
+ _ts_metadata15("design:paramtypes", [
3184
3826
  typeof Request === "undefined" ? Object : Request,
3185
3827
  String
3186
3828
  ]),
3187
- _ts_metadata14("design:returntype", Promise)
3829
+ _ts_metadata15("design:returntype", Promise)
3188
3830
  ], SkillsController.prototype, "list", null);
3189
- SkillsController = _ts_decorate14([
3190
- (0, import_common15.Controller)("skills"),
3191
- _ts_param13(0, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3192
- _ts_param13(1, (0, import_common15.Optional)()),
3193
- _ts_param13(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_SKILLS)),
3194
- _ts_metadata14("design:type", Function),
3195
- _ts_metadata14("design:paramtypes", [
3831
+ SkillsController = _ts_decorate16([
3832
+ (0, import_common17.Controller)("skills"),
3833
+ _ts_param15(0, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3834
+ _ts_param15(1, (0, import_common17.Optional)()),
3835
+ _ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_SKILLS)),
3836
+ _ts_metadata15("design:type", Function),
3837
+ _ts_metadata15("design:paramtypes", [
3196
3838
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3197
3839
  Object
3198
3840
  ])
3199
3841
  ], SkillsController);
3200
3842
 
3201
3843
  // src/controller/threads.controller.ts
3202
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3203
- var import_common16 = require("@nestjs/common");
3204
- function _ts_decorate15(decorators, target, key, desc) {
3844
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3845
+ var import_common18 = require("@nestjs/common");
3846
+ function _ts_decorate17(decorators, target, key, desc) {
3205
3847
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3206
3848
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3207
3849
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3214,19 +3856,19 @@ function _ts_decorate15(decorators, target, key, desc) {
3214
3856
  }
3215
3857
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3216
3858
  }
3217
- __name(_ts_decorate15, "_ts_decorate");
3218
- function _ts_metadata15(metadataKey, metadataValue) {
3859
+ __name(_ts_decorate17, "_ts_decorate");
3860
+ function _ts_metadata16(metadataKey, metadataValue) {
3219
3861
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3220
3862
  return Reflect.metadata(metadataKey, metadataValue);
3221
3863
  }
3222
3864
  }
3223
- __name(_ts_metadata15, "_ts_metadata");
3224
- function _ts_param14(paramIndex, decorator) {
3865
+ __name(_ts_metadata16, "_ts_metadata");
3866
+ function _ts_param16(paramIndex, decorator) {
3225
3867
  return function(target, key) {
3226
3868
  decorator(target, key, paramIndex);
3227
3869
  };
3228
3870
  }
3229
- __name(_ts_param14, "_ts_param");
3871
+ __name(_ts_param16, "_ts_param");
3230
3872
  var ThreadsController = class {
3231
3873
  static {
3232
3874
  __name(this, "ThreadsController");
@@ -3272,6 +3914,9 @@ var ThreadsController = class {
3272
3914
  } : {},
3273
3915
  ..."model" in body ? {
3274
3916
  model: body.model ?? null
3917
+ } : {},
3918
+ ..."persona" in body ? {
3919
+ persona: body.persona ?? null
3275
3920
  } : {}
3276
3921
  });
3277
3922
  return {
@@ -3293,101 +3938,101 @@ var ThreadsController = class {
3293
3938
  };
3294
3939
  }
3295
3940
  };
3296
- _ts_decorate15([
3297
- (0, import_common16.Get)(),
3298
- _ts_param14(0, (0, import_common16.Req)()),
3299
- _ts_metadata15("design:type", Function),
3300
- _ts_metadata15("design:paramtypes", [
3941
+ _ts_decorate17([
3942
+ (0, import_common18.Get)(),
3943
+ _ts_param16(0, (0, import_common18.Req)()),
3944
+ _ts_metadata16("design:type", Function),
3945
+ _ts_metadata16("design:paramtypes", [
3301
3946
  typeof Request === "undefined" ? Object : Request
3302
3947
  ]),
3303
- _ts_metadata15("design:returntype", Promise)
3948
+ _ts_metadata16("design:returntype", Promise)
3304
3949
  ], ThreadsController.prototype, "list", null);
3305
- _ts_decorate15([
3306
- (0, import_common16.Get)(":id"),
3307
- _ts_param14(0, (0, import_common16.Req)()),
3308
- _ts_param14(1, (0, import_common16.Param)("id")),
3309
- _ts_metadata15("design:type", Function),
3310
- _ts_metadata15("design:paramtypes", [
3950
+ _ts_decorate17([
3951
+ (0, import_common18.Get)(":id"),
3952
+ _ts_param16(0, (0, import_common18.Req)()),
3953
+ _ts_param16(1, (0, import_common18.Param)("id")),
3954
+ _ts_metadata16("design:type", Function),
3955
+ _ts_metadata16("design:paramtypes", [
3311
3956
  typeof Request === "undefined" ? Object : Request,
3312
3957
  String
3313
3958
  ]),
3314
- _ts_metadata15("design:returntype", Promise)
3959
+ _ts_metadata16("design:returntype", Promise)
3315
3960
  ], ThreadsController.prototype, "detail", null);
3316
- _ts_decorate15([
3317
- (0, import_common16.Delete)(":id"),
3318
- _ts_param14(0, (0, import_common16.Req)()),
3319
- _ts_param14(1, (0, import_common16.Param)("id")),
3320
- _ts_metadata15("design:type", Function),
3321
- _ts_metadata15("design:paramtypes", [
3961
+ _ts_decorate17([
3962
+ (0, import_common18.Delete)(":id"),
3963
+ _ts_param16(0, (0, import_common18.Req)()),
3964
+ _ts_param16(1, (0, import_common18.Param)("id")),
3965
+ _ts_metadata16("design:type", Function),
3966
+ _ts_metadata16("design:paramtypes", [
3322
3967
  typeof Request === "undefined" ? Object : Request,
3323
3968
  String
3324
3969
  ]),
3325
- _ts_metadata15("design:returntype", Promise)
3970
+ _ts_metadata16("design:returntype", Promise)
3326
3971
  ], ThreadsController.prototype, "remove", null);
3327
- _ts_decorate15([
3328
- (0, import_common16.Post)(":id/fork-from/:messageId"),
3329
- _ts_param14(0, (0, import_common16.Req)()),
3330
- _ts_param14(1, (0, import_common16.Param)("id")),
3331
- _ts_param14(2, (0, import_common16.Param)("messageId")),
3332
- _ts_metadata15("design:type", Function),
3333
- _ts_metadata15("design:paramtypes", [
3972
+ _ts_decorate17([
3973
+ (0, import_common18.Post)(":id/fork-from/:messageId"),
3974
+ _ts_param16(0, (0, import_common18.Req)()),
3975
+ _ts_param16(1, (0, import_common18.Param)("id")),
3976
+ _ts_param16(2, (0, import_common18.Param)("messageId")),
3977
+ _ts_metadata16("design:type", Function),
3978
+ _ts_metadata16("design:paramtypes", [
3334
3979
  typeof Request === "undefined" ? Object : Request,
3335
3980
  String,
3336
3981
  String
3337
3982
  ]),
3338
- _ts_metadata15("design:returntype", Promise)
3983
+ _ts_metadata16("design:returntype", Promise)
3339
3984
  ], ThreadsController.prototype, "fork", null);
3340
- _ts_decorate15([
3341
- (0, import_common16.Patch)(":id"),
3342
- _ts_param14(0, (0, import_common16.Req)()),
3343
- _ts_param14(1, (0, import_common16.Param)("id")),
3344
- _ts_param14(2, (0, import_common16.Body)()),
3345
- _ts_metadata15("design:type", Function),
3346
- _ts_metadata15("design:paramtypes", [
3985
+ _ts_decorate17([
3986
+ (0, import_common18.Patch)(":id"),
3987
+ _ts_param16(0, (0, import_common18.Req)()),
3988
+ _ts_param16(1, (0, import_common18.Param)("id")),
3989
+ _ts_param16(2, (0, import_common18.Body)()),
3990
+ _ts_metadata16("design:type", Function),
3991
+ _ts_metadata16("design:paramtypes", [
3347
3992
  typeof Request === "undefined" ? Object : Request,
3348
3993
  String,
3349
3994
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
3350
3995
  ]),
3351
- _ts_metadata15("design:returntype", Promise)
3996
+ _ts_metadata16("design:returntype", Promise)
3352
3997
  ], ThreadsController.prototype, "update", null);
3353
- _ts_decorate15([
3354
- (0, import_common16.Post)(":id/promote"),
3355
- _ts_param14(0, (0, import_common16.Req)()),
3356
- _ts_param14(1, (0, import_common16.Param)("id")),
3357
- _ts_metadata15("design:type", Function),
3358
- _ts_metadata15("design:paramtypes", [
3998
+ _ts_decorate17([
3999
+ (0, import_common18.Post)(":id/promote"),
4000
+ _ts_param16(0, (0, import_common18.Req)()),
4001
+ _ts_param16(1, (0, import_common18.Param)("id")),
4002
+ _ts_metadata16("design:type", Function),
4003
+ _ts_metadata16("design:paramtypes", [
3359
4004
  typeof Request === "undefined" ? Object : Request,
3360
4005
  String
3361
4006
  ]),
3362
- _ts_metadata15("design:returntype", Promise)
4007
+ _ts_metadata16("design:returntype", Promise)
3363
4008
  ], ThreadsController.prototype, "promote", null);
3364
- _ts_decorate15([
3365
- (0, import_common16.Delete)(":id/from/:messageId"),
3366
- _ts_param14(0, (0, import_common16.Req)()),
3367
- _ts_param14(1, (0, import_common16.Param)("id")),
3368
- _ts_param14(2, (0, import_common16.Param)("messageId")),
3369
- _ts_metadata15("design:type", Function),
3370
- _ts_metadata15("design:paramtypes", [
4009
+ _ts_decorate17([
4010
+ (0, import_common18.Delete)(":id/from/:messageId"),
4011
+ _ts_param16(0, (0, import_common18.Req)()),
4012
+ _ts_param16(1, (0, import_common18.Param)("id")),
4013
+ _ts_param16(2, (0, import_common18.Param)("messageId")),
4014
+ _ts_metadata16("design:type", Function),
4015
+ _ts_metadata16("design:paramtypes", [
3371
4016
  typeof Request === "undefined" ? Object : Request,
3372
4017
  String,
3373
4018
  String
3374
4019
  ]),
3375
- _ts_metadata15("design:returntype", Promise)
4020
+ _ts_metadata16("design:returntype", Promise)
3376
4021
  ], ThreadsController.prototype, "truncateFrom", null);
3377
- ThreadsController = _ts_decorate15([
3378
- (0, import_common16.Controller)("threads"),
3379
- _ts_param14(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3380
- _ts_metadata15("design:type", Function),
3381
- _ts_metadata15("design:paramtypes", [
4022
+ ThreadsController = _ts_decorate17([
4023
+ (0, import_common18.Controller)("threads"),
4024
+ _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
4025
+ _ts_metadata16("design:type", Function),
4026
+ _ts_metadata16("design:paramtypes", [
3382
4027
  typeof AgentService === "undefined" ? Object : AgentService,
3383
4028
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3384
4029
  ])
3385
4030
  ], ThreadsController);
3386
4031
 
3387
4032
  // src/controller/tool-call.controller.ts
3388
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3389
- var import_common17 = require("@nestjs/common");
3390
- function _ts_decorate16(decorators, target, key, desc) {
4033
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
4034
+ var import_common19 = require("@nestjs/common");
4035
+ function _ts_decorate18(decorators, target, key, desc) {
3391
4036
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3392
4037
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3393
4038
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3400,19 +4045,19 @@ function _ts_decorate16(decorators, target, key, desc) {
3400
4045
  }
3401
4046
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3402
4047
  }
3403
- __name(_ts_decorate16, "_ts_decorate");
3404
- function _ts_metadata16(metadataKey, metadataValue) {
4048
+ __name(_ts_decorate18, "_ts_decorate");
4049
+ function _ts_metadata17(metadataKey, metadataValue) {
3405
4050
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3406
4051
  return Reflect.metadata(metadataKey, metadataValue);
3407
4052
  }
3408
4053
  }
3409
- __name(_ts_metadata16, "_ts_metadata");
3410
- function _ts_param15(paramIndex, decorator) {
4054
+ __name(_ts_metadata17, "_ts_metadata");
4055
+ function _ts_param17(paramIndex, decorator) {
3411
4056
  return function(target, key) {
3412
4057
  decorator(target, key, paramIndex);
3413
4058
  };
3414
4059
  }
3415
- __name(_ts_param15, "_ts_param");
4060
+ __name(_ts_param17, "_ts_param");
3416
4061
  var MAX_ANSWERED_QUESTIONS = 100;
3417
4062
  var MAX_VALUES_PER_QUESTION = 100;
3418
4063
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -3421,7 +4066,7 @@ var MAX_VIA_LENGTH = 64;
3421
4066
  var DEFAULT_VIA = "web";
3422
4067
  function toolCallId(claimed) {
3423
4068
  if (typeof claimed !== "string" || claimed.length === 0) {
3424
- throw new import_common17.BadRequestException("toolCallId must be a non-empty string");
4069
+ throw new import_common19.BadRequestException("toolCallId must be a non-empty string");
3425
4070
  }
3426
4071
  return claimed;
3427
4072
  }
@@ -3431,10 +4076,10 @@ function rejectReason(claimed) {
3431
4076
  return void 0;
3432
4077
  }
3433
4078
  if (typeof claimed !== "string") {
3434
- throw new import_common17.BadRequestException("reason must be a string");
4079
+ throw new import_common19.BadRequestException("reason must be a string");
3435
4080
  }
3436
4081
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
3437
- throw new import_common17.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
4082
+ throw new import_common19.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3438
4083
  }
3439
4084
  return claimed;
3440
4085
  }
@@ -3444,7 +4089,7 @@ function remember(claimed) {
3444
4089
  return false;
3445
4090
  }
3446
4091
  if (typeof claimed !== "boolean") {
3447
- throw new import_common17.BadRequestException("remember must be a boolean");
4092
+ throw new import_common19.BadRequestException("remember must be a boolean");
3448
4093
  }
3449
4094
  return claimed;
3450
4095
  }
@@ -3454,7 +4099,7 @@ function via(claimed) {
3454
4099
  return DEFAULT_VIA;
3455
4100
  }
3456
4101
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
3457
- throw new import_common17.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
4102
+ throw new import_common19.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
3458
4103
  }
3459
4104
  return claimed;
3460
4105
  }
@@ -3464,26 +4109,26 @@ function answers(claimed) {
3464
4109
  return void 0;
3465
4110
  }
3466
4111
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
3467
- throw new import_common17.BadRequestException("answers must be an object of questionId \u2192 chosen values");
4112
+ throw new import_common19.BadRequestException("answers must be an object of questionId \u2192 chosen values");
3468
4113
  }
3469
4114
  const entries = Object.entries(claimed);
3470
4115
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
3471
- throw new import_common17.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
4116
+ throw new import_common19.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3472
4117
  }
3473
4118
  const validated = /* @__PURE__ */ Object.create(null);
3474
4119
  for (const [questionId, values] of entries) {
3475
4120
  if (!Array.isArray(values)) {
3476
- throw new import_common17.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
4121
+ throw new import_common19.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
3477
4122
  }
3478
4123
  if (values.length > MAX_VALUES_PER_QUESTION) {
3479
- throw new import_common17.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
4124
+ throw new import_common19.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3480
4125
  }
3481
4126
  for (const value of values) {
3482
4127
  if (typeof value !== "string") {
3483
- throw new import_common17.BadRequestException(`answers["${questionId}"] must contain only strings`);
4128
+ throw new import_common19.BadRequestException(`answers["${questionId}"] must contain only strings`);
3484
4129
  }
3485
4130
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
3486
- throw new import_common17.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
4131
+ throw new import_common19.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
3487
4132
  }
3488
4133
  }
3489
4134
  validated[questionId] = values;
@@ -3545,64 +4190,64 @@ var ToolCallController = class {
3545
4190
  };
3546
4191
  }
3547
4192
  };
3548
- _ts_decorate16([
3549
- (0, import_common17.Post)("approve"),
3550
- _ts_param15(0, (0, import_common17.Req)()),
3551
- _ts_param15(1, (0, import_common17.Body)()),
3552
- _ts_metadata16("design:type", Function),
3553
- _ts_metadata16("design:paramtypes", [
4193
+ _ts_decorate18([
4194
+ (0, import_common19.Post)("approve"),
4195
+ _ts_param17(0, (0, import_common19.Req)()),
4196
+ _ts_param17(1, (0, import_common19.Body)()),
4197
+ _ts_metadata17("design:type", Function),
4198
+ _ts_metadata17("design:paramtypes", [
3554
4199
  typeof Request === "undefined" ? Object : Request,
3555
4200
  typeof ApproveBody === "undefined" ? Object : ApproveBody
3556
4201
  ]),
3557
- _ts_metadata16("design:returntype", Promise)
4202
+ _ts_metadata17("design:returntype", Promise)
3558
4203
  ], ToolCallController.prototype, "approve", null);
3559
- _ts_decorate16([
3560
- (0, import_common17.Post)("reject"),
3561
- _ts_param15(0, (0, import_common17.Req)()),
3562
- _ts_param15(1, (0, import_common17.Body)()),
3563
- _ts_metadata16("design:type", Function),
3564
- _ts_metadata16("design:paramtypes", [
4204
+ _ts_decorate18([
4205
+ (0, import_common19.Post)("reject"),
4206
+ _ts_param17(0, (0, import_common19.Req)()),
4207
+ _ts_param17(1, (0, import_common19.Body)()),
4208
+ _ts_metadata17("design:type", Function),
4209
+ _ts_metadata17("design:paramtypes", [
3565
4210
  typeof Request === "undefined" ? Object : Request,
3566
4211
  typeof RejectBody === "undefined" ? Object : RejectBody
3567
4212
  ]),
3568
- _ts_metadata16("design:returntype", Promise)
4213
+ _ts_metadata17("design:returntype", Promise)
3569
4214
  ], ToolCallController.prototype, "reject", null);
3570
- _ts_decorate16([
3571
- (0, import_common17.Post)("answer"),
3572
- _ts_param15(0, (0, import_common17.Req)()),
3573
- _ts_param15(1, (0, import_common17.Body)()),
3574
- _ts_metadata16("design:type", Function),
3575
- _ts_metadata16("design:paramtypes", [
4215
+ _ts_decorate18([
4216
+ (0, import_common19.Post)("answer"),
4217
+ _ts_param17(0, (0, import_common19.Req)()),
4218
+ _ts_param17(1, (0, import_common19.Body)()),
4219
+ _ts_metadata17("design:type", Function),
4220
+ _ts_metadata17("design:paramtypes", [
3576
4221
  typeof Request === "undefined" ? Object : Request,
3577
4222
  typeof AnswerBody === "undefined" ? Object : AnswerBody
3578
4223
  ]),
3579
- _ts_metadata16("design:returntype", Promise)
4224
+ _ts_metadata17("design:returntype", Promise)
3580
4225
  ], ToolCallController.prototype, "answer", null);
3581
- _ts_decorate16([
3582
- (0, import_common17.Post)("skip"),
3583
- _ts_param15(0, (0, import_common17.Req)()),
3584
- _ts_param15(1, (0, import_common17.Body)()),
3585
- _ts_metadata16("design:type", Function),
3586
- _ts_metadata16("design:paramtypes", [
4226
+ _ts_decorate18([
4227
+ (0, import_common19.Post)("skip"),
4228
+ _ts_param17(0, (0, import_common19.Req)()),
4229
+ _ts_param17(1, (0, import_common19.Body)()),
4230
+ _ts_metadata17("design:type", Function),
4231
+ _ts_metadata17("design:paramtypes", [
3587
4232
  typeof Request === "undefined" ? Object : Request,
3588
4233
  Object
3589
4234
  ]),
3590
- _ts_metadata16("design:returntype", Promise)
4235
+ _ts_metadata17("design:returntype", Promise)
3591
4236
  ], ToolCallController.prototype, "skip", null);
3592
- ToolCallController = _ts_decorate16([
3593
- (0, import_common17.Controller)("tool-call"),
3594
- _ts_param15(1, (0, import_common17.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3595
- _ts_metadata16("design:type", Function),
3596
- _ts_metadata16("design:paramtypes", [
4237
+ ToolCallController = _ts_decorate18([
4238
+ (0, import_common19.Controller)("tool-call"),
4239
+ _ts_param17(1, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
4240
+ _ts_metadata17("design:type", Function),
4241
+ _ts_metadata17("design:paramtypes", [
3597
4242
  typeof AgentService === "undefined" ? Object : AgentService,
3598
4243
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3599
4244
  ])
3600
4245
  ], ToolCallController);
3601
4246
 
3602
4247
  // src/controller/tools.controller.ts
3603
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3604
- var import_common18 = require("@nestjs/common");
3605
- function _ts_decorate17(decorators, target, key, desc) {
4248
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4249
+ var import_common20 = require("@nestjs/common");
4250
+ function _ts_decorate19(decorators, target, key, desc) {
3606
4251
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3607
4252
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3608
4253
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3615,19 +4260,19 @@ function _ts_decorate17(decorators, target, key, desc) {
3615
4260
  }
3616
4261
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3617
4262
  }
3618
- __name(_ts_decorate17, "_ts_decorate");
3619
- function _ts_metadata17(metadataKey, metadataValue) {
4263
+ __name(_ts_decorate19, "_ts_decorate");
4264
+ function _ts_metadata18(metadataKey, metadataValue) {
3620
4265
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3621
4266
  return Reflect.metadata(metadataKey, metadataValue);
3622
4267
  }
3623
4268
  }
3624
- __name(_ts_metadata17, "_ts_metadata");
3625
- function _ts_param16(paramIndex, decorator) {
4269
+ __name(_ts_metadata18, "_ts_metadata");
4270
+ function _ts_param18(paramIndex, decorator) {
3626
4271
  return function(target, key) {
3627
4272
  decorator(target, key, paramIndex);
3628
4273
  };
3629
4274
  }
3630
- __name(_ts_param16, "_ts_param");
4275
+ __name(_ts_param18, "_ts_param");
3631
4276
  var ToolsController = class {
3632
4277
  static {
3633
4278
  __name(this, "ToolsController");
@@ -3641,11 +4286,11 @@ var ToolsController = class {
3641
4286
  this.agents = agents;
3642
4287
  }
3643
4288
  async list(req, agent) {
3644
- if (agent !== void 0 && agent !== import_nestjs_agent_core18.ALL_AGENTS && this.agents.get(agent) === void 0) {
3645
- throw new import_common18.NotFoundException(`No agent named "${agent}"`);
4289
+ if (agent !== void 0 && agent !== import_nestjs_agent_core20.ALL_AGENTS && this.agents.get(agent) === void 0) {
4290
+ throw new import_common20.NotFoundException(`No agent named "${agent}"`);
3646
4291
  }
3647
4292
  const actor = await this.actorResolver.resolve(req);
3648
- const names = agent === import_nestjs_agent_core18.ALL_AGENTS ? [
4293
+ const names = agent === import_nestjs_agent_core20.ALL_AGENTS ? [
3649
4294
  void 0,
3650
4295
  ...this.agents.list().map((definition) => definition.name)
3651
4296
  ] : [
@@ -3671,33 +4316,33 @@ var ToolsController = class {
3671
4316
  ];
3672
4317
  }
3673
4318
  };
3674
- _ts_decorate17([
3675
- (0, import_common18.Get)(),
3676
- _ts_param16(0, (0, import_common18.Req)()),
3677
- _ts_param16(1, (0, import_common18.Query)("agent")),
3678
- _ts_metadata17("design:type", Function),
3679
- _ts_metadata17("design:paramtypes", [
4319
+ _ts_decorate19([
4320
+ (0, import_common20.Get)(),
4321
+ _ts_param18(0, (0, import_common20.Req)()),
4322
+ _ts_param18(1, (0, import_common20.Query)("agent")),
4323
+ _ts_metadata18("design:type", Function),
4324
+ _ts_metadata18("design:paramtypes", [
3680
4325
  typeof Request === "undefined" ? Object : Request,
3681
4326
  String
3682
4327
  ]),
3683
- _ts_metadata17("design:returntype", Promise)
4328
+ _ts_metadata18("design:returntype", Promise)
3684
4329
  ], ToolsController.prototype, "list", null);
3685
- ToolsController = _ts_decorate17([
3686
- (0, import_common18.Controller)("tools"),
3687
- _ts_param16(0, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
3688
- _ts_param16(1, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_DEPS_FACTORY)),
3689
- _ts_param16(2, (0, import_common18.Inject)(import_nestjs_agent_core18.AGENT_REGISTRY)),
3690
- _ts_metadata17("design:type", Function),
3691
- _ts_metadata17("design:paramtypes", [
4330
+ ToolsController = _ts_decorate19([
4331
+ (0, import_common20.Controller)("tools"),
4332
+ _ts_param18(0, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
4333
+ _ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_DEPS_FACTORY)),
4334
+ _ts_param18(2, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_REGISTRY)),
4335
+ _ts_metadata18("design:type", Function),
4336
+ _ts_metadata18("design:paramtypes", [
3692
4337
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3693
4338
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3694
- typeof import_nestjs_agent_core18.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core18.AgentRegistry
4339
+ typeof import_nestjs_agent_core20.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core20.AgentRegistry
3695
4340
  ])
3696
4341
  ], ToolsController);
3697
4342
 
3698
4343
  // src/discovery/agent-discovery.service.ts
3699
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
3700
- var import_common19 = require("@nestjs/common");
4344
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4345
+ var import_common21 = require("@nestjs/common");
3701
4346
  var import_core = require("@nestjs/core");
3702
4347
 
3703
4348
  // src/decorator/agent.decorator.ts
@@ -3732,7 +4377,7 @@ function SystemPromptContributor() {
3732
4377
  __name(SystemPromptContributor, "SystemPromptContributor");
3733
4378
 
3734
4379
  // src/discovery/agent-discovery.service.ts
3735
- function _ts_decorate18(decorators, target, key, desc) {
4380
+ function _ts_decorate20(decorators, target, key, desc) {
3736
4381
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3737
4382
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3738
4383
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3745,19 +4390,19 @@ function _ts_decorate18(decorators, target, key, desc) {
3745
4390
  }
3746
4391
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3747
4392
  }
3748
- __name(_ts_decorate18, "_ts_decorate");
3749
- function _ts_metadata18(metadataKey, metadataValue) {
4393
+ __name(_ts_decorate20, "_ts_decorate");
4394
+ function _ts_metadata19(metadataKey, metadataValue) {
3750
4395
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3751
4396
  return Reflect.metadata(metadataKey, metadataValue);
3752
4397
  }
3753
4398
  }
3754
- __name(_ts_metadata18, "_ts_metadata");
3755
- function _ts_param17(paramIndex, decorator) {
4399
+ __name(_ts_metadata19, "_ts_metadata");
4400
+ function _ts_param19(paramIndex, decorator) {
3756
4401
  return function(target, key) {
3757
4402
  decorator(target, key, paramIndex);
3758
4403
  };
3759
4404
  }
3760
- __name(_ts_param17, "_ts_param");
4405
+ __name(_ts_param19, "_ts_param");
3761
4406
  var AgentDiscoveryService = class _AgentDiscoveryService {
3762
4407
  static {
3763
4408
  __name(this, "AgentDiscoveryService");
@@ -3766,7 +4411,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3766
4411
  scanner;
3767
4412
  registry;
3768
4413
  contributors;
3769
- logger = new import_common19.Logger(_AgentDiscoveryService.name);
4414
+ logger = new import_common21.Logger(_AgentDiscoveryService.name);
3770
4415
  constructor(discovery, scanner, registry, contributors) {
3771
4416
  this.discovery = discovery;
3772
4417
  this.scanner = scanner;
@@ -3785,6 +4430,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3785
4430
  }
3786
4431
  this.collectContributors(instance);
3787
4432
  }
4433
+ this.assertPersonas(this.registry.list());
3788
4434
  }
3789
4435
  /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
3790
4436
  definitionFrom(instance, meta) {
@@ -3828,10 +4474,48 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3828
4474
  } : {},
3829
4475
  ...meta.handoff !== void 0 ? {
3830
4476
  delegatesTo: this.handoffEdges(meta)
4477
+ } : {},
4478
+ ...meta.personas !== void 0 ? {
4479
+ personas: meta.personas
4480
+ } : {},
4481
+ ...meta.defaultPersona !== void 0 ? {
4482
+ defaultPersona: meta.defaultPersona
3831
4483
  } : {}
3832
4484
  };
3833
4485
  }
3834
4486
  /**
4487
+ * Refuse to boot on a persona declaration that could only fail later, per request: a default that
4488
+ * names no persona, an id declared twice, an alias two personas claim, or an alias that is a real
4489
+ * agent's name (which would never be reached — a registered agent always wins).
4490
+ */
4491
+ assertPersonas(definitions) {
4492
+ const agentNames = new Set(definitions.map((definition) => definition.name));
4493
+ const aliasOwner = /* @__PURE__ */ new Map();
4494
+ for (const definition of definitions) {
4495
+ const ids = /* @__PURE__ */ new Set();
4496
+ for (const persona of definition.personas ?? []) {
4497
+ if (ids.has(persona.id)) {
4498
+ throw new Error(`Agent "${definition.name}" declares persona "${persona.id}" twice.`);
4499
+ }
4500
+ ids.add(persona.id);
4501
+ for (const alias of persona.aliases ?? []) {
4502
+ const owner = `${definition.name}/${persona.id}`;
4503
+ if (agentNames.has(alias)) {
4504
+ throw new Error(`Persona ${owner} claims the alias "${alias}", which is a registered agent's name.`);
4505
+ }
4506
+ const previous = aliasOwner.get(alias);
4507
+ if (previous !== void 0) {
4508
+ throw new Error(`Personas ${previous} and ${owner} both claim the alias "${alias}".`);
4509
+ }
4510
+ aliasOwner.set(alias, owner);
4511
+ }
4512
+ }
4513
+ if (definition.defaultPersona !== void 0 && !ids.has(definition.defaultPersona)) {
4514
+ throw new Error(`Agent "${definition.name}" names "${definition.defaultPersona}" as its default persona, but declares no persona with that id.`);
4515
+ }
4516
+ }
4517
+ }
4518
+ /**
3835
4519
  * Resolve each handoff entry to an {@link AgentDelegation} — its target's registered name, plus
3836
4520
  * whether that edge detaches (skipping non-agent classes). A bare name is kept for a plain edge
3837
4521
  * rather than an always-object form, so a definition an older host built by hand still reads.
@@ -3884,22 +4568,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3884
4568
  return (ctx) => candidate.call(instance, ctx);
3885
4569
  }
3886
4570
  };
3887
- AgentDiscoveryService = _ts_decorate18([
3888
- (0, import_common19.Injectable)(),
3889
- _ts_param17(2, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_REGISTRY)),
3890
- _ts_param17(3, (0, import_common19.Inject)(import_nestjs_agent_core19.AGENT_PROMPT_CONTRIBUTORS)),
3891
- _ts_metadata18("design:type", Function),
3892
- _ts_metadata18("design:paramtypes", [
4571
+ AgentDiscoveryService = _ts_decorate20([
4572
+ (0, import_common21.Injectable)(),
4573
+ _ts_param19(2, (0, import_common21.Inject)(import_nestjs_agent_core21.AGENT_REGISTRY)),
4574
+ _ts_param19(3, (0, import_common21.Inject)(import_nestjs_agent_core21.AGENT_PROMPT_CONTRIBUTORS)),
4575
+ _ts_metadata19("design:type", Function),
4576
+ _ts_metadata19("design:paramtypes", [
3893
4577
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
3894
4578
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
3895
- typeof import_nestjs_agent_core19.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core19.AgentRegistry,
4579
+ typeof import_nestjs_agent_core21.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core21.AgentRegistry,
3896
4580
  Array
3897
4581
  ])
3898
4582
  ], AgentDiscoveryService);
3899
4583
 
3900
4584
  // src/discovery/ai-tool-discovery.service.ts
3901
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
3902
- var import_common20 = require("@nestjs/common");
4585
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4586
+ var import_common22 = require("@nestjs/common");
3903
4587
  var import_core2 = require("@nestjs/core");
3904
4588
  var import_zod = require("zod");
3905
4589
 
@@ -3931,46 +4615,8 @@ function readAiToolMetadata(target) {
3931
4615
  }
3932
4616
  __name(readAiToolMetadata, "readAiToolMetadata");
3933
4617
 
3934
- // src/functional-tool.ts
3935
- var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
3936
- function brand(tool) {
3937
- return {
3938
- [AGENT_TOOL_BRAND]: true,
3939
- spec: tool.spec,
3940
- handler: tool.handler
3941
- };
3942
- }
3943
- __name(brand, "brand");
3944
- function isBrandedFunctionalTool(value) {
3945
- return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
3946
- }
3947
- __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
3948
- function provideAgentTool(factoryOrTool, inject) {
3949
- const provide = /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-instance");
3950
- if (typeof factoryOrTool === "function") {
3951
- return {
3952
- provide,
3953
- useFactory: /* @__PURE__ */ __name((...deps) => brand(factoryOrTool(...deps)), "useFactory"),
3954
- inject: inject ?? []
3955
- };
3956
- }
3957
- return {
3958
- provide,
3959
- useValue: brand(factoryOrTool)
3960
- };
3961
- }
3962
- __name(provideAgentTool, "provideAgentTool");
3963
- function provideAgentTools(factory, inject) {
3964
- return {
3965
- provide: /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-list"),
3966
- useFactory: /* @__PURE__ */ __name(async (...deps) => (await factory(...deps)).map(brand), "useFactory"),
3967
- inject: inject ?? []
3968
- };
3969
- }
3970
- __name(provideAgentTools, "provideAgentTools");
3971
-
3972
4618
  // src/discovery/ai-tool-discovery.service.ts
3973
- function _ts_decorate19(decorators, target, key, desc) {
4619
+ function _ts_decorate21(decorators, target, key, desc) {
3974
4620
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3975
4621
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3976
4622
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3983,19 +4629,19 @@ function _ts_decorate19(decorators, target, key, desc) {
3983
4629
  }
3984
4630
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3985
4631
  }
3986
- __name(_ts_decorate19, "_ts_decorate");
3987
- function _ts_metadata19(metadataKey, metadataValue) {
4632
+ __name(_ts_decorate21, "_ts_decorate");
4633
+ function _ts_metadata20(metadataKey, metadataValue) {
3988
4634
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3989
4635
  return Reflect.metadata(metadataKey, metadataValue);
3990
4636
  }
3991
4637
  }
3992
- __name(_ts_metadata19, "_ts_metadata");
3993
- function _ts_param18(paramIndex, decorator) {
4638
+ __name(_ts_metadata20, "_ts_metadata");
4639
+ function _ts_param20(paramIndex, decorator) {
3994
4640
  return function(target, key) {
3995
4641
  decorator(target, key, paramIndex);
3996
4642
  };
3997
4643
  }
3998
- __name(_ts_param18, "_ts_param");
4644
+ __name(_ts_param20, "_ts_param");
3999
4645
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
4000
4646
  static {
4001
4647
  __name(this, "AiToolDiscoveryService");
@@ -4004,7 +4650,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4004
4650
  registry;
4005
4651
  agents;
4006
4652
  options;
4007
- logger = new import_common20.Logger(_AiToolDiscoveryService.name);
4653
+ logger = new import_common22.Logger(_AiToolDiscoveryService.name);
4008
4654
  constructor(discovery, registry, agents, options) {
4009
4655
  this.discovery = discovery;
4010
4656
  this.registry = registry;
@@ -4063,9 +4709,15 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4063
4709
  } : {},
4064
4710
  ...meta.terminal === true ? {
4065
4711
  terminal: true
4712
+ } : {},
4713
+ ...meta.replacementKey !== void 0 ? {
4714
+ replacementKey: meta.replacementKey
4066
4715
  } : {}
4067
4716
  }, {
4068
4717
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
4718
+ ...typeof handler.preflight === "function" ? {
4719
+ preflight: /* @__PURE__ */ __name((input, ctx, options) => instance.preflight(input, ctx, options), "preflight")
4720
+ } : {},
4069
4721
  // Forwarded, not copied: the registry holds this wrapper rather than the provider, so an
4070
4722
  // `isEnabled()`/`canUse()` left behind here would be a gate that silently never applies.
4071
4723
  // Called through `instance` so each keeps its `this` (and its injected deps).
@@ -4089,7 +4741,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4089
4741
  let delegates = 0;
4090
4742
  for (const definition of this.agents.list()) {
4091
4743
  for (const edge of definition.delegatesTo ?? []) {
4092
- const { agent: target, detached } = (0, import_nestjs_agent_core20.normalizeDelegation)(edge);
4744
+ const { agent: target, detached } = (0, import_nestjs_agent_core22.normalizeDelegation)(edge);
4093
4745
  const targetDefinition = this.agents.get(target);
4094
4746
  if (targetDefinition === void 0) {
4095
4747
  throw new Error(`Agent "${definition.name}" hands off to "${target}", which is not a registered @Agent. Declare it as an @Agent provider or fix the reference.`);
@@ -4139,13 +4791,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4139
4791
  return true;
4140
4792
  }
4141
4793
  };
4142
- AiToolDiscoveryService = _ts_decorate19([
4143
- (0, import_common20.Injectable)(),
4144
- _ts_param18(1, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_TOOL_REGISTRY)),
4145
- _ts_param18(2, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_REGISTRY)),
4146
- _ts_param18(3, (0, import_common20.Inject)(import_nestjs_agent_core20.AGENT_OPTIONS)),
4147
- _ts_metadata19("design:type", Function),
4148
- _ts_metadata19("design:paramtypes", [
4794
+ AiToolDiscoveryService = _ts_decorate21([
4795
+ (0, import_common22.Injectable)(),
4796
+ _ts_param20(1, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_TOOL_REGISTRY)),
4797
+ _ts_param20(2, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_REGISTRY)),
4798
+ _ts_param20(3, (0, import_common22.Inject)(import_nestjs_agent_core22.AGENT_OPTIONS)),
4799
+ _ts_metadata20("design:type", Function),
4800
+ _ts_metadata20("design:paramtypes", [
4149
4801
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
4150
4802
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
4151
4803
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -4154,13 +4806,13 @@ AiToolDiscoveryService = _ts_decorate19([
4154
4806
  ], AiToolDiscoveryService);
4155
4807
 
4156
4808
  // src/discovery/skill-discovery.service.ts
4157
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4158
- var import_common21 = require("@nestjs/common");
4809
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4810
+ var import_common23 = require("@nestjs/common");
4159
4811
  var import_core3 = require("@nestjs/core");
4160
4812
 
4161
4813
  // src/decorator/skill.decorator.ts
4162
4814
  var import_reflect_metadata4 = require("reflect-metadata");
4163
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4815
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4164
4816
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
4165
4817
  function Skill(options) {
4166
4818
  return (target) => {
@@ -4173,12 +4825,12 @@ function readSkillMetadata(target) {
4173
4825
  }
4174
4826
  __name(readSkillMetadata, "readSkillMetadata");
4175
4827
  function skillScope(options) {
4176
- return options.scope ?? import_nestjs_agent_core21.GLOBAL_SCOPE;
4828
+ return options.scope ?? import_nestjs_agent_core23.GLOBAL_SCOPE;
4177
4829
  }
4178
4830
  __name(skillScope, "skillScope");
4179
4831
 
4180
4832
  // src/discovery/skill-discovery.service.ts
4181
- function _ts_decorate20(decorators, target, key, desc) {
4833
+ function _ts_decorate22(decorators, target, key, desc) {
4182
4834
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4183
4835
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4184
4836
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4191,26 +4843,26 @@ function _ts_decorate20(decorators, target, key, desc) {
4191
4843
  }
4192
4844
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4193
4845
  }
4194
- __name(_ts_decorate20, "_ts_decorate");
4195
- function _ts_metadata20(metadataKey, metadataValue) {
4846
+ __name(_ts_decorate22, "_ts_decorate");
4847
+ function _ts_metadata21(metadataKey, metadataValue) {
4196
4848
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4197
4849
  return Reflect.metadata(metadataKey, metadataValue);
4198
4850
  }
4199
4851
  }
4200
- __name(_ts_metadata20, "_ts_metadata");
4201
- function _ts_param19(paramIndex, decorator) {
4852
+ __name(_ts_metadata21, "_ts_metadata");
4853
+ function _ts_param21(paramIndex, decorator) {
4202
4854
  return function(target, key) {
4203
4855
  decorator(target, key, paramIndex);
4204
4856
  };
4205
4857
  }
4206
- __name(_ts_param19, "_ts_param");
4858
+ __name(_ts_param21, "_ts_param");
4207
4859
  var SkillDiscoveryService = class _SkillDiscoveryService {
4208
4860
  static {
4209
4861
  __name(this, "SkillDiscoveryService");
4210
4862
  }
4211
4863
  discovery;
4212
4864
  declared;
4213
- logger = new import_common21.Logger(_SkillDiscoveryService.name);
4865
+ logger = new import_common23.Logger(_SkillDiscoveryService.name);
4214
4866
  constructor(discovery, declared) {
4215
4867
  this.discovery = discovery;
4216
4868
  this.declared = declared;
@@ -4247,18 +4899,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
4247
4899
  return flat === void 0 ? void 0 : () => flat;
4248
4900
  }
4249
4901
  };
4250
- SkillDiscoveryService = _ts_decorate20([
4251
- (0, import_common21.Injectable)(),
4252
- _ts_param19(1, (0, import_common21.Inject)(import_nestjs_agent_core22.AGENT_SKILL_SOURCES)),
4253
- _ts_metadata20("design:type", Function),
4254
- _ts_metadata20("design:paramtypes", [
4902
+ SkillDiscoveryService = _ts_decorate22([
4903
+ (0, import_common23.Injectable)(),
4904
+ _ts_param21(1, (0, import_common23.Inject)(import_nestjs_agent_core24.AGENT_SKILL_SOURCES)),
4905
+ _ts_metadata21("design:type", Function),
4906
+ _ts_metadata21("design:paramtypes", [
4255
4907
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
4256
4908
  Array
4257
4909
  ])
4258
4910
  ], SkillDiscoveryService);
4259
4911
 
4260
4912
  // src/in-process-sink.ts
4261
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4913
+ var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4262
4914
  var InProcessTokenStreamSink = class {
4263
4915
  static {
4264
4916
  __name(this, "InProcessTokenStreamSink");
@@ -4313,7 +4965,7 @@ var InProcessTokenStreamSink = class {
4313
4965
  }
4314
4966
  if (buf.ended) {
4315
4967
  if (buf.failure !== void 0) {
4316
- throw new import_nestjs_agent_core23.AgentStreamError(buf.failure);
4968
+ throw new import_nestjs_agent_core25.AgentStreamError(buf.failure);
4317
4969
  }
4318
4970
  return;
4319
4971
  }
@@ -4326,7 +4978,7 @@ var InProcessTokenStreamSink = class {
4326
4978
  };
4327
4979
 
4328
4980
  // src/ledger-quota-provider.ts
4329
- var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4981
+ var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
4330
4982
  var LedgerQuotaProvider = class {
4331
4983
  static {
4332
4984
  __name(this, "LedgerQuotaProvider");
@@ -4346,12 +4998,12 @@ var LedgerQuotaProvider = class {
4346
4998
  await this.dayWindow(actorRef, now)
4347
4999
  ];
4348
5000
  if (this.store.usageBetween !== void 0) {
4349
- const range = (0, import_nestjs_agent_core24.quotaPeriodRange)("month", now);
5001
+ const range = (0, import_nestjs_agent_core26.quotaPeriodRange)("month", now);
4350
5002
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
4351
5003
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
4352
5004
  }
4353
- const blocked = (0, import_nestjs_agent_core24.exhaustedWindow)(windows);
4354
- const warning = (0, import_nestjs_agent_core24.quotaWarning)(windows);
5005
+ const blocked = (0, import_nestjs_agent_core26.exhaustedWindow)(windows);
5006
+ const warning = (0, import_nestjs_agent_core26.quotaWarning)(windows);
4355
5007
  return {
4356
5008
  windows,
4357
5009
  ...blocked !== void 0 ? {
@@ -4363,7 +5015,7 @@ var LedgerQuotaProvider = class {
4363
5015
  };
4364
5016
  }
4365
5017
  async dayWindow(actorRef, now) {
4366
- const range = (0, import_nestjs_agent_core24.quotaPeriodRange)("day", now);
5018
+ const range = (0, import_nestjs_agent_core26.quotaPeriodRange)("day", now);
4367
5019
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
4368
5020
  return this.window("day", usedTokens, costUsd, range.resetsAt);
4369
5021
  }
@@ -4387,13 +5039,248 @@ var LedgerQuotaProvider = class {
4387
5039
  }
4388
5040
  };
4389
5041
 
5042
+ // src/proposals/action-proposal-worker.service.ts
5043
+ var import_node_crypto2 = require("crypto");
5044
+ var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
5045
+ var import_common24 = require("@nestjs/common");
5046
+ function _ts_decorate23(decorators, target, key, desc) {
5047
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5048
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5049
+ r = Reflect.decorate(decorators, target, key, desc);
5050
+ } else {
5051
+ for (var i = decorators.length - 1; i >= 0; i--) {
5052
+ if (d = decorators[i]) {
5053
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5054
+ }
5055
+ }
5056
+ }
5057
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5058
+ }
5059
+ __name(_ts_decorate23, "_ts_decorate");
5060
+ function _ts_metadata22(metadataKey, metadataValue) {
5061
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5062
+ return Reflect.metadata(metadataKey, metadataValue);
5063
+ }
5064
+ }
5065
+ __name(_ts_metadata22, "_ts_metadata");
5066
+ function _ts_param22(paramIndex, decorator) {
5067
+ return function(target, key) {
5068
+ decorator(target, key, paramIndex);
5069
+ };
5070
+ }
5071
+ __name(_ts_param22, "_ts_param");
5072
+ var ActionProposalWorkerService = class _ActionProposalWorkerService {
5073
+ static {
5074
+ __name(this, "ActionProposalWorkerService");
5075
+ }
5076
+ store;
5077
+ options;
5078
+ deps;
5079
+ worker;
5080
+ logger = new import_common24.Logger(_ActionProposalWorkerService.name);
5081
+ constructor(store, options, deps) {
5082
+ this.store = store;
5083
+ this.options = options;
5084
+ this.deps = deps;
5085
+ }
5086
+ onModuleInit() {
5087
+ if (this.options.actionApprovalMode !== "independent") return;
5088
+ (0, import_nestjs_agent_core27.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
5089
+ if (this.options.surface === "http") return;
5090
+ const resolver = this.options.backgroundActorResolver;
5091
+ if (!resolver) throw new Error("BackgroundActorResolver is required");
5092
+ this.worker = new import_nestjs_agent_core27.ActionProposalWorker({
5093
+ store: this.store,
5094
+ workerId: (0, import_node_crypto2.randomUUID)(),
5095
+ ...this.options.actionProposalWorker,
5096
+ executor: new import_nestjs_agent_core27.ActionProposalExecutor({
5097
+ resolver,
5098
+ resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
5099
+ const deps = this.deps.forProposal(proposal, actor);
5100
+ return {
5101
+ registry: deps.registry,
5102
+ rolesPolicy: deps.rolesPolicy,
5103
+ ...deps.resolveUiCatalog !== void 0 ? {
5104
+ resolveUiCatalog: deps.resolveUiCatalog
5105
+ } : {},
5106
+ ...deps.toolAllowList !== void 0 ? {
5107
+ allowedTools: deps.toolAllowList
5108
+ } : {}
5109
+ };
5110
+ }, "resolveExecution")
5111
+ }),
5112
+ onError: /* @__PURE__ */ __name((error) => this.logger.error(error), "onError")
5113
+ });
5114
+ this.worker.start();
5115
+ }
5116
+ async onModuleDestroy() {
5117
+ await this.worker?.stop();
5118
+ }
5119
+ };
5120
+ ActionProposalWorkerService = _ts_decorate23([
5121
+ (0, import_common24.Injectable)(),
5122
+ _ts_param22(0, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_STORE)),
5123
+ _ts_param22(1, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_OPTIONS)),
5124
+ _ts_param22(2, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_DEPS_FACTORY)),
5125
+ _ts_metadata22("design:type", Function),
5126
+ _ts_metadata22("design:paramtypes", [
5127
+ typeof AgentStore === "undefined" ? Object : AgentStore,
5128
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
5129
+ typeof AgentDepsFactory2 === "undefined" ? Object : AgentDepsFactory2
5130
+ ])
5131
+ ], ActionProposalWorkerService);
5132
+
5133
+ // src/proposals/action-proposal.controller.ts
5134
+ var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
5135
+ var import_common25 = require("@nestjs/common");
5136
+ function _ts_decorate24(decorators, target, key, desc) {
5137
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5138
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5139
+ r = Reflect.decorate(decorators, target, key, desc);
5140
+ } else {
5141
+ for (var i = decorators.length - 1; i >= 0; i--) {
5142
+ if (d = decorators[i]) {
5143
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5144
+ }
5145
+ }
5146
+ }
5147
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5148
+ }
5149
+ __name(_ts_decorate24, "_ts_decorate");
5150
+ function _ts_metadata23(metadataKey, metadataValue) {
5151
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5152
+ return Reflect.metadata(metadataKey, metadataValue);
5153
+ }
5154
+ }
5155
+ __name(_ts_metadata23, "_ts_metadata");
5156
+ function _ts_param23(paramIndex, decorator) {
5157
+ return function(target, key) {
5158
+ decorator(target, key, paramIndex);
5159
+ };
5160
+ }
5161
+ __name(_ts_param23, "_ts_param");
5162
+ function bodyFields(body, field2) {
5163
+ if (body === void 0) return {};
5164
+ if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field2)) throw new import_common25.BadRequestException(`Only ${field2} is accepted`);
5165
+ const value = body;
5166
+ if (value[field2] !== void 0 && (field2 === "remember" && typeof value[field2] !== "boolean" || field2 === "reason" && typeof value[field2] !== "string")) throw new import_common25.BadRequestException(`Invalid ${field2}`);
5167
+ return value;
5168
+ }
5169
+ __name(bodyFields, "bodyFields");
5170
+ var ActionProposalController = class {
5171
+ static {
5172
+ __name(this, "ActionProposalController");
5173
+ }
5174
+ proposals;
5175
+ actors;
5176
+ constructor(proposals, actors) {
5177
+ this.proposals = proposals;
5178
+ this.actors = actors;
5179
+ }
5180
+ async list(threadId, request, cursor, response) {
5181
+ let query = {};
5182
+ if (cursor !== void 0) {
5183
+ try {
5184
+ if (typeof cursor !== "string") throw new Error("Invalid cursor");
5185
+ query = {
5186
+ after: JSON.parse(cursor)
5187
+ };
5188
+ (0, import_nestjs_agent_core28.validateActionProposalListQuery)(query);
5189
+ } catch {
5190
+ throw new import_common25.BadRequestException("Invalid action proposal cursor");
5191
+ }
5192
+ }
5193
+ const page = await this.proposals.listPage(threadId, await this.actors.resolve(request), query);
5194
+ if (page.next) {
5195
+ response.setHeader("X-Action-Proposals-Next", encodeURIComponent(JSON.stringify(page.next)));
5196
+ const exposed = response.getHeader("Access-Control-Expose-Headers");
5197
+ response.setHeader("Access-Control-Expose-Headers", `${exposed === void 0 ? "" : `${String(exposed)}, `}X-Action-Proposals-Next`);
5198
+ }
5199
+ return page.items;
5200
+ }
5201
+ async approve(threadId, proposalId, request, body) {
5202
+ const value = bodyFields(body, "remember");
5203
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
5204
+ decision: "approved",
5205
+ ...typeof value.remember === "boolean" ? {
5206
+ remember: value.remember
5207
+ } : {}
5208
+ });
5209
+ }
5210
+ async reject(threadId, proposalId, request, body) {
5211
+ const value = bodyFields(body, "reason");
5212
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
5213
+ decision: "rejected",
5214
+ ...typeof value.reason === "string" ? {
5215
+ reason: value.reason
5216
+ } : {}
5217
+ });
5218
+ }
5219
+ };
5220
+ _ts_decorate24([
5221
+ (0, import_common25.Get)(),
5222
+ _ts_param23(0, (0, import_common25.Param)("threadId")),
5223
+ _ts_param23(1, (0, import_common25.Req)()),
5224
+ _ts_param23(2, (0, import_common25.Query)("after")),
5225
+ _ts_param23(3, (0, import_common25.Res)({
5226
+ passthrough: true
5227
+ })),
5228
+ _ts_metadata23("design:type", Function),
5229
+ _ts_metadata23("design:paramtypes", [
5230
+ String,
5231
+ typeof Request === "undefined" ? Object : Request,
5232
+ Object,
5233
+ typeof Response === "undefined" ? Object : Response
5234
+ ]),
5235
+ _ts_metadata23("design:returntype", Promise)
5236
+ ], ActionProposalController.prototype, "list", null);
5237
+ _ts_decorate24([
5238
+ (0, import_common25.Post)(":proposalId/approve"),
5239
+ _ts_param23(0, (0, import_common25.Param)("threadId")),
5240
+ _ts_param23(1, (0, import_common25.Param)("proposalId")),
5241
+ _ts_param23(2, (0, import_common25.Req)()),
5242
+ _ts_param23(3, (0, import_common25.Body)()),
5243
+ _ts_metadata23("design:type", Function),
5244
+ _ts_metadata23("design:paramtypes", [
5245
+ String,
5246
+ String,
5247
+ typeof Request === "undefined" ? Object : Request,
5248
+ Object
5249
+ ]),
5250
+ _ts_metadata23("design:returntype", Promise)
5251
+ ], ActionProposalController.prototype, "approve", null);
5252
+ _ts_decorate24([
5253
+ (0, import_common25.Post)(":proposalId/reject"),
5254
+ _ts_param23(0, (0, import_common25.Param)("threadId")),
5255
+ _ts_param23(1, (0, import_common25.Param)("proposalId")),
5256
+ _ts_param23(2, (0, import_common25.Req)()),
5257
+ _ts_param23(3, (0, import_common25.Body)()),
5258
+ _ts_metadata23("design:type", Function),
5259
+ _ts_metadata23("design:paramtypes", [
5260
+ String,
5261
+ String,
5262
+ typeof Request === "undefined" ? Object : Request,
5263
+ Object
5264
+ ]),
5265
+ _ts_metadata23("design:returntype", Promise)
5266
+ ], ActionProposalController.prototype, "reject", null);
5267
+ ActionProposalController = _ts_decorate24([
5268
+ (0, import_common25.Controller)("threads/:threadId/action-proposals"),
5269
+ _ts_param23(1, (0, import_common25.Inject)(import_nestjs_agent_core28.AGENT_ACTOR_RESOLVER)),
5270
+ _ts_metadata23("design:type", Function),
5271
+ _ts_metadata23("design:paramtypes", [
5272
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
5273
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
5274
+ ])
5275
+ ], ActionProposalController);
5276
+
4390
5277
  // src/queue/chat-queue.token.ts
4391
5278
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
4392
5279
 
4393
5280
  // src/runner/inline-agent-runner.ts
4394
- var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4395
- var import_common22 = require("@nestjs/common");
4396
- function _ts_decorate21(decorators, target, key, desc) {
5281
+ var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
5282
+ var import_common26 = require("@nestjs/common");
5283
+ function _ts_decorate25(decorators, target, key, desc) {
4397
5284
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4398
5285
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4399
5286
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4406,19 +5293,19 @@ function _ts_decorate21(decorators, target, key, desc) {
4406
5293
  }
4407
5294
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4408
5295
  }
4409
- __name(_ts_decorate21, "_ts_decorate");
4410
- function _ts_metadata21(metadataKey, metadataValue) {
5296
+ __name(_ts_decorate25, "_ts_decorate");
5297
+ function _ts_metadata24(metadataKey, metadataValue) {
4411
5298
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4412
5299
  return Reflect.metadata(metadataKey, metadataValue);
4413
5300
  }
4414
5301
  }
4415
- __name(_ts_metadata21, "_ts_metadata");
4416
- function _ts_param20(paramIndex, decorator) {
5302
+ __name(_ts_metadata24, "_ts_metadata");
5303
+ function _ts_param24(paramIndex, decorator) {
4417
5304
  return function(target, key) {
4418
5305
  decorator(target, key, paramIndex);
4419
5306
  };
4420
5307
  }
4421
- __name(_ts_param20, "_ts_param");
5308
+ __name(_ts_param24, "_ts_param");
4422
5309
  var InlineAgentRunner = class _InlineAgentRunner {
4423
5310
  static {
4424
5311
  __name(this, "InlineAgentRunner");
@@ -4426,7 +5313,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4426
5313
  factory;
4427
5314
  store;
4428
5315
  queue;
4429
- logger = new import_common22.Logger(_InlineAgentRunner.name);
5316
+ logger = new import_common26.Logger(_InlineAgentRunner.name);
4430
5317
  pending = /* @__PURE__ */ new Map();
4431
5318
  /**
4432
5319
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -4475,18 +5362,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
4475
5362
  ],
4476
5363
  input
4477
5364
  });
4478
- void (0, import_nestjs_agent_core25.runAgentLoop)({
5365
+ void (0, import_nestjs_agent_core29.runAgentLoop)({
4479
5366
  ...deps,
4480
5367
  day
4481
- }, input, hooks).then(() => (0, import_nestjs_agent_core25.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
4482
- if (error instanceof import_nestjs_agent_core25.RunCancelledError) {
5368
+ }, input, hooks).then(() => (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
5369
+ if (error instanceof import_nestjs_agent_core29.RunCancelledError) {
4483
5370
  await this.settleCancelled(runId, input, deps);
4484
5371
  return;
4485
5372
  }
4486
5373
  const message = error instanceof Error ? error.message : String(error);
4487
- const code = (0, import_nestjs_agent_core25.agentFailureCode)(error);
5374
+ const code = (0, import_nestjs_agent_core29.agentFailureCode)(error);
4488
5375
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
4489
- (0, import_nestjs_agent_core25.publishAgentRunFailed)({
5376
+ (0, import_nestjs_agent_core29.publishAgentRunFailed)({
4490
5377
  runId,
4491
5378
  code,
4492
5379
  message
@@ -4497,11 +5384,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
4497
5384
  errorCode: code,
4498
5385
  errorMessage: message
4499
5386
  });
4500
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core25.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5387
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
4501
5388
  const writer = await deps.sink.open(runId);
4502
5389
  await this.settleQueue(writer, input, runId, "failed", message);
4503
- await (0, import_nestjs_agent_core25.releaseThreadRun)(this.store, input.threadId, runId);
4504
- await writer.fail((0, import_nestjs_agent_core25.streamFailure)(error));
5390
+ await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5391
+ await writer.fail((0, import_nestjs_agent_core29.streamFailure)(error));
4505
5392
  }).finally(() => {
4506
5393
  this.cancelled.delete(runId);
4507
5394
  this.live.delete(runId);
@@ -4537,7 +5424,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4537
5424
  for (const [key, waiter] of this.pending) {
4538
5425
  if (key.startsWith(`${runId}:`)) {
4539
5426
  this.pending.delete(key);
4540
- waiter.reject(new import_nestjs_agent_core25.RunCancelledError());
5427
+ waiter.reject(new import_nestjs_agent_core29.RunCancelledError());
4541
5428
  }
4542
5429
  }
4543
5430
  await Promise.resolve();
@@ -4552,8 +5439,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
4552
5439
  this.logger.log(`agent run ${runId} cancelled`);
4553
5440
  const writer = await deps.sink.open(runId);
4554
5441
  await this.settleQueue(writer, input, runId, "cancelled");
4555
- await (0, import_nestjs_agent_core25.releaseThreadRun)(this.store, input.threadId, runId);
4556
- await writer.write((0, import_nestjs_agent_core25.encodeStreamEvent)({
5442
+ await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5443
+ await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)({
4557
5444
  kind: "cancelled"
4558
5445
  }));
4559
5446
  await writer.end();
@@ -4588,7 +5475,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4588
5475
  runId: nextRunId
4589
5476
  }));
4590
5477
  if (frame !== void 0) {
4591
- await writer.write((0, import_nestjs_agent_core25.encodeStreamEvent)(frame));
5478
+ await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)(frame));
4592
5479
  }
4593
5480
  } catch (failure) {
4594
5481
  this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
@@ -4659,7 +5546,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4659
5546
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
4660
5547
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
4661
5548
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
4662
- parallel: import_nestjs_agent_core25.settleAll,
5549
+ parallel: import_nestjs_agent_core29.settleAll,
4663
5550
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
4664
5551
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
4665
5552
  agentName,
@@ -4710,7 +5597,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4710
5597
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
4711
5598
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
4712
5599
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
4713
- parallel: import_nestjs_agent_core25.settleAll,
5600
+ parallel: import_nestjs_agent_core29.settleAll,
4714
5601
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
4715
5602
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
4716
5603
  agentName: childName,
@@ -4743,7 +5630,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4743
5630
  }
4744
5631
  }), "startAgent")
4745
5632
  };
4746
- void (0, import_nestjs_agent_core25.runAgentLoop)({
5633
+ void (0, import_nestjs_agent_core29.runAgentLoop)({
4747
5634
  ...deps,
4748
5635
  day
4749
5636
  }, {
@@ -4757,13 +5644,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
4757
5644
  parentRunId,
4758
5645
  deliverTo
4759
5646
  }, hooks).catch(async (error) => {
4760
- const cancelled = error instanceof import_nestjs_agent_core25.RunCancelledError;
5647
+ const cancelled = error instanceof import_nestjs_agent_core29.RunCancelledError;
4761
5648
  const message = error instanceof Error ? error.message : String(error);
4762
5649
  if (!cancelled) {
4763
5650
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
4764
- (0, import_nestjs_agent_core25.publishAgentRunFailed)({
5651
+ (0, import_nestjs_agent_core29.publishAgentRunFailed)({
4765
5652
  runId,
4766
- code: (0, import_nestjs_agent_core25.agentFailureCode)(error),
5653
+ code: (0, import_nestjs_agent_core29.agentFailureCode)(error),
4767
5654
  message
4768
5655
  });
4769
5656
  }
@@ -4771,12 +5658,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
4771
5658
  runId,
4772
5659
  status: cancelled ? "cancelled" : "failed",
4773
5660
  ...cancelled ? {} : {
4774
- errorCode: (0, import_nestjs_agent_core25.agentFailureCode)(error),
5661
+ errorCode: (0, import_nestjs_agent_core29.agentFailureCode)(error),
4775
5662
  errorMessage: message
4776
5663
  }
4777
5664
  });
4778
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core25.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
4779
- await (0, import_nestjs_agent_core25.settleUnsettledDelegation)({
5665
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5666
+ await (0, import_nestjs_agent_core29.settleUnsettledDelegation)({
4780
5667
  store: this.store,
4781
5668
  delivery: deliverTo,
4782
5669
  agent: agentName,
@@ -4815,7 +5702,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4815
5702
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
4816
5703
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
4817
5704
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
4818
- parallel: import_nestjs_agent_core25.settleAll,
5705
+ parallel: import_nestjs_agent_core29.settleAll,
4819
5706
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
4820
5707
  // canceller names the top-level run, which is the only id that ever left the server.
4821
5708
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -4850,7 +5737,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4850
5737
  }), "startAgent")
4851
5738
  };
4852
5739
  try {
4853
- return await (0, import_nestjs_agent_core25.runAgentLoop)({
5740
+ return await (0, import_nestjs_agent_core29.runAgentLoop)({
4854
5741
  ...deps,
4855
5742
  day
4856
5743
  }, {
@@ -4869,13 +5756,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
4869
5756
  }
4870
5757
  }
4871
5758
  };
4872
- InlineAgentRunner = _ts_decorate21([
4873
- (0, import_common22.Injectable)(),
4874
- _ts_param20(0, (0, import_common22.Inject)(import_nestjs_agent_core25.AGENT_DEPS_FACTORY)),
4875
- _ts_param20(1, (0, import_common22.Inject)(import_nestjs_agent_core25.AGENT_STORE)),
4876
- _ts_param20(2, (0, import_common22.Optional)()),
4877
- _ts_metadata21("design:type", Function),
4878
- _ts_metadata21("design:paramtypes", [
5759
+ InlineAgentRunner = _ts_decorate25([
5760
+ (0, import_common26.Injectable)(),
5761
+ _ts_param24(0, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_DEPS_FACTORY)),
5762
+ _ts_param24(1, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_STORE)),
5763
+ _ts_param24(2, (0, import_common26.Optional)()),
5764
+ _ts_metadata24("design:type", Function),
5765
+ _ts_metadata24("design:paramtypes", [
4879
5766
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4880
5767
  typeof AgentStore === "undefined" ? Object : AgentStore,
4881
5768
  typeof ChatQueueService === "undefined" ? Object : ChatQueueService
@@ -4887,7 +5774,7 @@ function isThreadTurn(input) {
4887
5774
  __name(isThreadTurn, "isThreadTurn");
4888
5775
 
4889
5776
  // src/skills-config.ts
4890
- var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
5777
+ var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
4891
5778
  function declaredSkillProvider(declared) {
4892
5779
  return {
4893
5780
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -4913,7 +5800,7 @@ function resolveSkillsConfig(options, declared) {
4913
5800
  declaredSkillProvider(declared)
4914
5801
  ];
4915
5802
  return {
4916
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core26.compositeSkillProvider)(providers),
5803
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core30.compositeSkillProvider)(providers),
4917
5804
  ...options.scopes !== void 0 ? {
4918
5805
  scopes: options.scopes
4919
5806
  } : {},
@@ -4925,7 +5812,7 @@ function resolveSkillsConfig(options, declared) {
4925
5812
  __name(resolveSkillsConfig, "resolveSkillsConfig");
4926
5813
 
4927
5814
  // src/agent.module.ts
4928
- function _ts_decorate22(decorators, target, key, desc) {
5815
+ function _ts_decorate26(decorators, target, key, desc) {
4929
5816
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4930
5817
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4931
5818
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4938,13 +5825,13 @@ function _ts_decorate22(decorators, target, key, desc) {
4938
5825
  }
4939
5826
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4940
5827
  }
4941
- __name(_ts_decorate22, "_ts_decorate");
5828
+ __name(_ts_decorate26, "_ts_decorate");
4942
5829
  var DEFAULT_PATH = "agent";
4943
- var logger = new import_common23.Logger("AgentModule");
5830
+ var logger = new import_common27.Logger("AgentModule");
4944
5831
  function externalStoreWrapper(modules) {
4945
5832
  for (const module2 of modules.values()) {
4946
5833
  if (module2.metatype === AgentModule) continue;
4947
- const wrapper = module2.providers.get(import_nestjs_agent_core27.AGENT_STORE);
5834
+ const wrapper = module2.providers.get(import_nestjs_agent_core31.AGENT_STORE);
4948
5835
  if (wrapper !== void 0) return wrapper;
4949
5836
  }
4950
5837
  return void 0;
@@ -4975,7 +5862,7 @@ function resolveStore(options, modules) {
4975
5862
  const external = externalStoreWrapper(modules);
4976
5863
  if (external !== void 0) return forwardingStore(external);
4977
5864
  logger.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()).");
4978
- return new import_nestjs_agent_core27.InMemoryAgentStore();
5865
+ return new import_nestjs_agent_core31.InMemoryAgentStore();
4979
5866
  }
4980
5867
  __name(resolveStore, "resolveStore");
4981
5868
  function isQuotaProvider(quota) {
@@ -4991,99 +5878,99 @@ __name(resolveCatalog, "resolveCatalog");
4991
5878
  function sharedProviders(durable) {
4992
5879
  const providers = [
4993
5880
  {
4994
- provide: import_nestjs_agent_core27.AGENT_TOOL_REGISTRY,
4995
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core27.ToolRegistry(), "useFactory")
5881
+ provide: import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
5882
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.ToolRegistry(), "useFactory")
4996
5883
  },
4997
5884
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
4998
5885
  {
4999
- provide: import_nestjs_agent_core27.AGENT_REGISTRY,
5000
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core27.AgentRegistry(), "useFactory")
5886
+ provide: import_nestjs_agent_core31.AGENT_REGISTRY,
5887
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.AgentRegistry(), "useFactory")
5001
5888
  },
5002
5889
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
5003
5890
  {
5004
- provide: import_nestjs_agent_core27.AGENT_PROMPT_CONTRIBUTORS,
5891
+ provide: import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
5005
5892
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5006
5893
  },
5007
5894
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
5008
5895
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
5009
5896
  {
5010
- provide: import_nestjs_agent_core27.AGENT_SKILL_SOURCES,
5897
+ provide: import_nestjs_agent_core31.AGENT_SKILL_SOURCES,
5011
5898
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5012
5899
  },
5013
5900
  {
5014
5901
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
5015
5902
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
5016
5903
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
5017
- provide: import_nestjs_agent_core27.AGENT_SKILLS,
5904
+ provide: import_nestjs_agent_core31.AGENT_SKILLS,
5018
5905
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
5019
5906
  inject: [
5020
- import_nestjs_agent_core27.AGENT_OPTIONS,
5021
- import_nestjs_agent_core27.AGENT_SKILL_SOURCES
5907
+ import_nestjs_agent_core31.AGENT_OPTIONS,
5908
+ import_nestjs_agent_core31.AGENT_SKILL_SOURCES
5022
5909
  ]
5023
5910
  },
5024
5911
  {
5025
5912
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
5026
5913
  // shown what the model was shown, and two resolutions would eventually disagree about that.
5027
- provide: import_nestjs_agent_core27.AGENT_MEMORY,
5914
+ provide: import_nestjs_agent_core31.AGENT_MEMORY,
5028
5915
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
5029
5916
  inject: [
5030
- import_nestjs_agent_core27.AGENT_OPTIONS
5917
+ import_nestjs_agent_core31.AGENT_OPTIONS
5031
5918
  ]
5032
5919
  },
5033
5920
  {
5034
- provide: import_nestjs_agent_core27.AGENT_SINK,
5921
+ provide: import_nestjs_agent_core31.AGENT_SINK,
5035
5922
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
5036
5923
  inject: [
5037
- import_nestjs_agent_core27.AGENT_OPTIONS
5924
+ import_nestjs_agent_core31.AGENT_OPTIONS
5038
5925
  ]
5039
5926
  },
5040
5927
  {
5041
- provide: import_nestjs_agent_core27.AGENT_ROLES_POLICY,
5042
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new import_nestjs_agent_core27.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core27.DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
5928
+ provide: import_nestjs_agent_core31.AGENT_ROLES_POLICY,
5929
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new import_nestjs_agent_core31.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core31.DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
5043
5930
  inject: [
5044
- import_nestjs_agent_core27.AGENT_OPTIONS
5931
+ import_nestjs_agent_core31.AGENT_OPTIONS
5045
5932
  ]
5046
5933
  },
5047
5934
  {
5048
- provide: import_nestjs_agent_core27.AGENT_ACTOR_RESOLVER,
5935
+ provide: import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
5049
5936
  useFactory: /* @__PURE__ */ __name((options) => {
5050
5937
  if (options.actorResolver !== void 0) return options.actorResolver;
5051
5938
  logger.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.");
5052
5939
  return new AnonymousActorResolver();
5053
5940
  }, "useFactory"),
5054
5941
  inject: [
5055
- import_nestjs_agent_core27.AGENT_OPTIONS
5942
+ import_nestjs_agent_core31.AGENT_OPTIONS
5056
5943
  ]
5057
5944
  },
5058
5945
  {
5059
- provide: import_nestjs_agent_core27.AGENT_MODEL,
5946
+ provide: import_nestjs_agent_core31.AGENT_MODEL,
5060
5947
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
5061
5948
  inject: [
5062
- import_nestjs_agent_core27.AGENT_OPTIONS
5949
+ import_nestjs_agent_core31.AGENT_OPTIONS
5063
5950
  ]
5064
5951
  },
5065
5952
  {
5066
5953
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
5067
5954
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
5068
- provide: import_nestjs_agent_core27.AGENT_QUOTA_PROVIDER,
5955
+ provide: import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
5069
5956
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
5070
5957
  warnAt: o.quota.warnAt
5071
5958
  } : {}), "useFactory"),
5072
5959
  inject: [
5073
- import_nestjs_agent_core27.AGENT_OPTIONS,
5074
- import_nestjs_agent_core27.AGENT_STORE
5960
+ import_nestjs_agent_core31.AGENT_OPTIONS,
5961
+ import_nestjs_agent_core31.AGENT_STORE
5075
5962
  ]
5076
5963
  },
5077
5964
  {
5078
- provide: import_nestjs_agent_core27.AGENT_MODEL_CATALOG,
5965
+ provide: import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
5079
5966
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
5080
5967
  inject: [
5081
- import_nestjs_agent_core27.AGENT_OPTIONS
5968
+ import_nestjs_agent_core31.AGENT_OPTIONS
5082
5969
  ]
5083
5970
  },
5084
5971
  AgentDepsFactory2,
5085
5972
  {
5086
- provide: import_nestjs_agent_core27.AGENT_DEPS_FACTORY,
5973
+ provide: import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
5087
5974
  useExisting: AgentDepsFactory2
5088
5975
  },
5089
5976
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -5100,25 +5987,27 @@ function sharedProviders(durable) {
5100
5987
  },
5101
5988
  InlineAgentRunner,
5102
5989
  AgentService,
5990
+ ActionProposalService,
5991
+ ActionProposalWorkerService,
5103
5992
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
5104
5993
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
5105
5994
  AgentApprovalPortAdapter,
5106
5995
  {
5107
- provide: import_nestjs_agent_core27.AGENT_APPROVAL_PORT,
5996
+ provide: import_nestjs_agent_core31.AGENT_APPROVAL_PORT,
5108
5997
  useExisting: AgentApprovalPortAdapter
5109
5998
  }
5110
5999
  ];
5111
6000
  providers.push({
5112
- provide: import_nestjs_agent_core27.AGENT_STORE,
6001
+ provide: import_nestjs_agent_core31.AGENT_STORE,
5113
6002
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
5114
6003
  inject: [
5115
- import_nestjs_agent_core27.AGENT_OPTIONS,
6004
+ import_nestjs_agent_core31.AGENT_OPTIONS,
5116
6005
  import_core4.ModulesContainer
5117
6006
  ]
5118
6007
  });
5119
6008
  if (durable) {
5120
6009
  providers.push({
5121
- provide: import_nestjs_agent_core27.AGENT_RUNNER,
6010
+ provide: import_nestjs_agent_core31.AGENT_RUNNER,
5122
6011
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
5123
6012
  if (durableRunner === void 0) {
5124
6013
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -5127,14 +6016,14 @@ function sharedProviders(durable) {
5127
6016
  }, "useFactory"),
5128
6017
  inject: [
5129
6018
  {
5130
- token: import_nestjs_agent_core27.AGENT_DURABLE_RUNNER,
6019
+ token: import_nestjs_agent_core31.AGENT_DURABLE_RUNNER,
5131
6020
  optional: true
5132
6021
  }
5133
6022
  ]
5134
6023
  });
5135
6024
  } else {
5136
6025
  providers.push({
5137
- provide: import_nestjs_agent_core27.AGENT_RUNNER,
6026
+ provide: import_nestjs_agent_core31.AGENT_RUNNER,
5138
6027
  useExisting: InlineAgentRunner
5139
6028
  });
5140
6029
  }
@@ -5143,30 +6032,33 @@ function sharedProviders(durable) {
5143
6032
  __name(sharedProviders, "sharedProviders");
5144
6033
  function exportsFor() {
5145
6034
  return [
5146
- import_nestjs_agent_core27.AGENT_OPTIONS,
5147
- import_nestjs_agent_core27.AGENT_TOOL_REGISTRY,
5148
- import_nestjs_agent_core27.AGENT_REGISTRY,
5149
- import_nestjs_agent_core27.AGENT_SINK,
5150
- import_nestjs_agent_core27.AGENT_ROLES_POLICY,
5151
- import_nestjs_agent_core27.AGENT_ACTOR_RESOLVER,
5152
- import_nestjs_agent_core27.AGENT_MODEL,
5153
- import_nestjs_agent_core27.AGENT_STORE,
5154
- import_nestjs_agent_core27.AGENT_MODEL_CATALOG,
5155
- import_nestjs_agent_core27.AGENT_QUOTA_PROVIDER,
5156
- import_nestjs_agent_core27.AGENT_PROMPT_CONTRIBUTORS,
5157
- import_nestjs_agent_core27.AGENT_SKILLS,
5158
- import_nestjs_agent_core27.AGENT_MEMORY,
5159
- import_nestjs_agent_core27.AGENT_DEPS_FACTORY,
6035
+ import_nestjs_agent_core31.AGENT_OPTIONS,
6036
+ import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
6037
+ import_nestjs_agent_core31.AGENT_REGISTRY,
6038
+ import_nestjs_agent_core31.AGENT_SINK,
6039
+ import_nestjs_agent_core31.AGENT_ROLES_POLICY,
6040
+ import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
6041
+ import_nestjs_agent_core31.AGENT_MODEL,
6042
+ import_nestjs_agent_core31.AGENT_STORE,
6043
+ import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
6044
+ import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
6045
+ import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
6046
+ import_nestjs_agent_core31.AGENT_SKILLS,
6047
+ import_nestjs_agent_core31.AGENT_MEMORY,
6048
+ import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
5160
6049
  AgentDepsFactory2,
5161
6050
  AgentService,
6051
+ ActionProposalService,
6052
+ ActionProposalWorkerService,
5162
6053
  ChatQueueService,
5163
6054
  AGENT_CHAT_QUEUE,
5164
6055
  InlineAgentRunner,
5165
- import_nestjs_agent_core27.AGENT_APPROVAL_PORT
6056
+ import_nestjs_agent_core31.AGENT_APPROVAL_PORT
5166
6057
  ];
5167
6058
  }
5168
6059
  __name(exportsFor, "exportsFor");
5169
6060
  var BASE_CONTROLLERS = [
6061
+ ActionProposalController,
5170
6062
  ChatController,
5171
6063
  QueueController,
5172
6064
  ThreadsController,
@@ -5239,7 +6131,7 @@ var AgentModule = class _AgentModule {
5239
6131
  controllers: controllersForSurface(options.surface, options.adapters),
5240
6132
  providers: [
5241
6133
  {
5242
- provide: import_nestjs_agent_core27.AGENT_OPTIONS,
6134
+ provide: import_nestjs_agent_core31.AGENT_OPTIONS,
5243
6135
  useValue: options
5244
6136
  },
5245
6137
  ...sharedProviders(options.durable ?? false),
@@ -5263,7 +6155,7 @@ var AgentModule = class _AgentModule {
5263
6155
  controllers: controllersForSurface(options.surface, options.adapters),
5264
6156
  providers: [
5265
6157
  {
5266
- provide: import_nestjs_agent_core27.AGENT_OPTIONS,
6158
+ provide: import_nestjs_agent_core31.AGENT_OPTIONS,
5267
6159
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
5268
6160
  // authoritative on the async config object (they decided the actual wiring above), and
5269
6161
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -5285,16 +6177,16 @@ var AgentModule = class _AgentModule {
5285
6177
  };
5286
6178
  }
5287
6179
  };
5288
- AgentModule = _ts_decorate22([
5289
- (0, import_common23.Global)(),
5290
- (0, import_common23.Module)({})
6180
+ AgentModule = _ts_decorate26([
6181
+ (0, import_common27.Global)(),
6182
+ (0, import_common27.Module)({})
5291
6183
  ], AgentModule);
5292
6184
 
5293
6185
  // src/ag-ui/ag-ui.adapter.ts
5294
- var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
6186
+ var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
5295
6187
  var import_ag_ui = require("@dudousxd/nestjs-agent-core/ag-ui");
5296
- var import_common24 = require("@nestjs/common");
5297
- function _ts_decorate23(decorators, target, key, desc) {
6188
+ var import_common28 = require("@nestjs/common");
6189
+ function _ts_decorate27(decorators, target, key, desc) {
5298
6190
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5299
6191
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5300
6192
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5307,22 +6199,22 @@ function _ts_decorate23(decorators, target, key, desc) {
5307
6199
  }
5308
6200
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5309
6201
  }
5310
- __name(_ts_decorate23, "_ts_decorate");
5311
- function _ts_metadata22(metadataKey, metadataValue) {
6202
+ __name(_ts_decorate27, "_ts_decorate");
6203
+ function _ts_metadata25(metadataKey, metadataValue) {
5312
6204
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5313
6205
  return Reflect.metadata(metadataKey, metadataValue);
5314
6206
  }
5315
6207
  }
5316
- __name(_ts_metadata22, "_ts_metadata");
5317
- function _ts_param21(paramIndex, decorator) {
6208
+ __name(_ts_metadata25, "_ts_metadata");
6209
+ function _ts_param25(paramIndex, decorator) {
5318
6210
  return function(target, key) {
5319
6211
  decorator(target, key, paramIndex);
5320
6212
  };
5321
6213
  }
5322
- __name(_ts_param21, "_ts_param");
6214
+ __name(_ts_param25, "_ts_param");
5323
6215
  var AG_UI_VIA = "ag-ui";
5324
6216
  function invalid(code, message) {
5325
- return new import_common24.BadRequestException({
6217
+ return new import_common28.BadRequestException({
5326
6218
  statusCode: 400,
5327
6219
  code,
5328
6220
  message
@@ -5401,7 +6293,27 @@ var AgUiRunHandler = class {
5401
6293
  warnings.push(...turn.dropped);
5402
6294
  const owner = await this.agent.threadOwner(input.threadId);
5403
6295
  if (owner !== null && owner !== actor.id) {
5404
- throw new import_common24.ForbiddenException("thread belongs to another actor");
6296
+ throw new import_common28.ForbiddenException("thread belongs to another actor");
6297
+ }
6298
+ if (owner !== null && turn.media.length === 0) {
6299
+ const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
6300
+ if ("proposalDecision" in decision) {
6301
+ res.status(200);
6302
+ res.setHeader("Content-Type", "text/event-stream");
6303
+ res.setHeader("Cache-Control", "no-cache, no-transform");
6304
+ res.flushHeaders();
6305
+ for (const event of [
6306
+ ...warningEvents(warnings),
6307
+ ...(0, import_ag_ui.actionProposalDecisionEvents)({
6308
+ threadId: input.threadId,
6309
+ runId: input.runId,
6310
+ text: decision.text,
6311
+ proposalDecision: decision.proposalDecision
6312
+ })
6313
+ ]) res.write((0, import_ag_ui.agUiSse)(event));
6314
+ res.end();
6315
+ return;
6316
+ }
5405
6317
  }
5406
6318
  const refs = await this.stage(actor, turn.media, warnings);
5407
6319
  if (turn.text.trim().length === 0 && refs.length === 0) {
@@ -5425,9 +6337,15 @@ var AgUiRunHandler = class {
5425
6337
  ...forwarded.agent !== void 0 ? {
5426
6338
  agentName: forwarded.agent
5427
6339
  } : {},
6340
+ ...forwarded.persona !== void 0 ? {
6341
+ personaId: forwarded.persona
6342
+ } : {},
5428
6343
  ...forwarded.model !== void 0 ? {
5429
6344
  model: forwarded.model
5430
6345
  } : {},
6346
+ ...forwarded.uiCapabilities !== void 0 ? {
6347
+ uiCapabilities: forwarded.uiCapabilities
6348
+ } : {},
5431
6349
  ...pageContext !== void 0 ? {
5432
6350
  pageContext
5433
6351
  } : {},
@@ -5572,29 +6490,29 @@ function agUiAdapter(options = {}) {
5572
6490
  return this.handle(req, res, body);
5573
6491
  }
5574
6492
  };
5575
- _ts_decorate23([
5576
- (0, import_common24.Post)(path),
5577
- (0, import_common24.HttpCode)(200),
5578
- _ts_param21(0, (0, import_common24.Req)()),
5579
- _ts_param21(1, (0, import_common24.Res)()),
5580
- _ts_param21(2, (0, import_common24.Body)()),
5581
- _ts_metadata22("design:type", Function),
5582
- _ts_metadata22("design:paramtypes", [
6493
+ _ts_decorate27([
6494
+ (0, import_common28.Post)(path),
6495
+ (0, import_common28.HttpCode)(200),
6496
+ _ts_param25(0, (0, import_common28.Req)()),
6497
+ _ts_param25(1, (0, import_common28.Res)()),
6498
+ _ts_param25(2, (0, import_common28.Body)()),
6499
+ _ts_metadata25("design:type", Function),
6500
+ _ts_metadata25("design:paramtypes", [
5583
6501
  typeof Request === "undefined" ? Object : Request,
5584
6502
  typeof Response === "undefined" ? Object : Response,
5585
6503
  Object
5586
6504
  ]),
5587
- _ts_metadata22("design:returntype", typeof Promise === "undefined" ? Object : Promise)
6505
+ _ts_metadata25("design:returntype", typeof Promise === "undefined" ? Object : Promise)
5588
6506
  ], AgUiController.prototype, "run", null);
5589
- AgUiController = _ts_decorate23([
5590
- (0, import_common24.Controller)(),
5591
- _ts_param21(0, (0, import_common24.Inject)(AgentService)),
5592
- _ts_param21(1, (0, import_common24.Inject)(import_nestjs_agent_core28.AGENT_ACTOR_RESOLVER)),
5593
- _ts_param21(2, (0, import_common24.Inject)(import_nestjs_agent_core28.AGENT_OPTIONS)),
5594
- _ts_param21(3, (0, import_common24.Optional)()),
5595
- _ts_param21(3, (0, import_common24.Inject)(import_nestjs_agent_core28.AGENT_ATTACHMENT_STAGING)),
5596
- _ts_metadata22("design:type", Function),
5597
- _ts_metadata22("design:paramtypes", [
6507
+ AgUiController = _ts_decorate27([
6508
+ (0, import_common28.Controller)(),
6509
+ _ts_param25(0, (0, import_common28.Inject)(AgentService)),
6510
+ _ts_param25(1, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_ACTOR_RESOLVER)),
6511
+ _ts_param25(2, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_OPTIONS)),
6512
+ _ts_param25(3, (0, import_common28.Optional)()),
6513
+ _ts_param25(3, (0, import_common28.Inject)(import_nestjs_agent_core32.AGENT_ATTACHMENT_STAGING)),
6514
+ _ts_metadata25("design:type", Function),
6515
+ _ts_metadata25("design:paramtypes", [
5598
6516
  typeof AgentService === "undefined" ? Object : AgentService,
5599
6517
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
5600
6518
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -5611,7 +6529,7 @@ function agUiAdapter(options = {}) {
5611
6529
  __name(agUiAdapter, "agUiAdapter");
5612
6530
 
5613
6531
  // src/resolver/header-actor-resolver.ts
5614
- var import_common25 = require("@nestjs/common");
6532
+ var import_common29 = require("@nestjs/common");
5615
6533
  function readHeader(req, name) {
5616
6534
  if (typeof req !== "object" || req === null || !("headers" in req)) return void 0;
5617
6535
  const { headers } = req;
@@ -5627,7 +6545,7 @@ var HeaderActorResolver = class {
5627
6545
  resolve(req) {
5628
6546
  const id = readHeader(req, "x-actor-id");
5629
6547
  if (id === void 0 || id.length === 0) {
5630
- throw new import_common25.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.");
6548
+ throw new import_common29.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.");
5631
6549
  }
5632
6550
  const roles = (readHeader(req, "x-actor-role") ?? "").split(",").map((role) => role.trim()).filter((role) => role.length > 0);
5633
6551
  const tenantRef = readHeader(req, "x-tenant-ref");
@@ -5642,7 +6560,7 @@ var HeaderActorResolver = class {
5642
6560
  };
5643
6561
 
5644
6562
  // src/resolver/request-user-actor-resolver.ts
5645
- var import_common26 = require("@nestjs/common");
6563
+ var import_common30 = require("@nestjs/common");
5646
6564
  function field(user, ...names) {
5647
6565
  for (const name of names) {
5648
6566
  const value = user[name];
@@ -5654,7 +6572,7 @@ __name(field, "field");
5654
6572
  function defaultRequestUserMapper(user) {
5655
6573
  const id = field(user, "id", "sub", "_id", "userId");
5656
6574
  if (id === void 0) {
5657
- throw new import_common26.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
6575
+ throw new import_common30.UnauthorizedException("requestUserActorResolver: req.user has no id/sub/_id/userId \u2014 pass a mapper: requestUserActorResolver((user) => ({ id: \u2026, roles: \u2026 }))");
5658
6576
  }
5659
6577
  const rawRoles = field(user, "roles", "role");
5660
6578
  const roles = Array.isArray(rawRoles) ? rawRoles.map(String) : typeof rawRoles === "string" ? [
@@ -5675,7 +6593,7 @@ function requestUserActorResolver(map) {
5675
6593
  async resolve(req) {
5676
6594
  const user = typeof req === "object" && req !== null ? req.user : void 0;
5677
6595
  if (user === void 0 || user === null || user === false) {
5678
- throw new import_common26.UnauthorizedException("Sign in to use the agent.");
6596
+ throw new import_common30.UnauthorizedException("Sign in to use the agent.");
5679
6597
  }
5680
6598
  if (map !== void 0) return map(user, req);
5681
6599
  return defaultRequestUserMapper(user);
@@ -5693,6 +6611,9 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
5693
6611
  AGENT_TOOL_BRAND,
5694
6612
  AI_TOOL_METADATA,
5695
6613
  ATTACHMENT_PAGE_SIZE,
6614
+ ActionProposalController,
6615
+ ActionProposalService,
6616
+ ActionProposalWorkerService,
5696
6617
  AgUiRunHandler,
5697
6618
  Agent,
5698
6619
  AgentApprovalPortAdapter,
@@ -5740,6 +6661,7 @@ __reExport(index_exports, require("@dudousxd/nestjs-agent-core"), module.exports
5740
6661
  requestUserActorResolver,
5741
6662
  resolveSkillsConfig,
5742
6663
  skillScope,
6664
+ threadPersona,
5743
6665
  toolNameFromClass,
5744
6666
  utcDay,
5745
6667
  ...require("@dudousxd/nestjs-agent-core")