@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.js CHANGED
@@ -2,14 +2,59 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
4
  // src/agent.module.ts
5
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER13, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_DURABLE_RUNNER, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS7, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, ClosedRolesPolicy, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
6
- import { Global, Logger as Logger6, Module } from "@nestjs/common";
5
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER14, AGENT_APPROVAL_PORT, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY7, AGENT_DURABLE_RUNNER, AGENT_MEMORY as AGENT_MEMORY3, AGENT_MODEL as AGENT_MODEL2, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG3, AGENT_OPTIONS as AGENT_OPTIONS9, AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER3, AGENT_REGISTRY as AGENT_REGISTRY6, AGENT_ROLES_POLICY as AGENT_ROLES_POLICY2, AGENT_RUNNER as AGENT_RUNNER2, AGENT_SINK as AGENT_SINK3, AGENT_SKILLS as AGENT_SKILLS3, AGENT_SKILL_SOURCES as AGENT_SKILL_SOURCES2, AGENT_STORE as AGENT_STORE7, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY3, AgentRegistry as AgentRegistry6, ClosedRolesPolicy, DefaultRolesPolicy, InMemoryAgentStore, ToolRegistry as ToolRegistry3 } from "@dudousxd/nestjs-agent-core";
6
+ import { Global, Logger as Logger7, Module as Module2 } from "@nestjs/common";
7
7
  import { DiscoveryModule, ModulesContainer, RouterModule } from "@nestjs/core";
8
8
 
9
9
  // src/agent-deps.factory.ts
10
- import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_SKILLS, AGENT_STORE, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, normalizeDelegation, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
10
+ import { assertIndependentActionCapabilities } from "@dudousxd/nestjs-agent-core";
11
+ import { AGENT_MEMORY, AGENT_MODEL, AGENT_PRICING_STORE, AGENT_PROMPT_CONTRIBUTORS, AGENT_REGISTRY, AGENT_ROLES_POLICY, AGENT_SINK, AGENT_SKILLS, AGENT_STORE, AGENT_TOOL_REGISTRY, AgentRegistry as AgentRegistry2, ToolRegistry as ToolRegistry2, findPersona, intersectAllowLists, normalizeDelegation, personaCatalogEntry, resolvePersonaAlias, summarizeWithModel, windowHistory } from "@dudousxd/nestjs-agent-core";
11
12
  import { AGENT_OPTIONS } from "@dudousxd/nestjs-agent-core";
12
- import { Inject, Injectable, Optional } from "@nestjs/common";
13
+ import { BadRequestException, Inject as Inject2, Injectable, Optional } from "@nestjs/common";
14
+
15
+ // src/genui/agent-genui.module.ts
16
+ import { defineCatalog, genuiTools } from "@dudousxd/nestjs-agent-core/genui";
17
+ import { Inject, Module } from "@nestjs/common";
18
+
19
+ // src/functional-tool.ts
20
+ var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
21
+ function brand(tool) {
22
+ return {
23
+ [AGENT_TOOL_BRAND]: true,
24
+ spec: tool.spec,
25
+ handler: tool.handler
26
+ };
27
+ }
28
+ __name(brand, "brand");
29
+ function isBrandedFunctionalTool(value) {
30
+ return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
31
+ }
32
+ __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
33
+ function provideAgentTool(factoryOrTool, inject) {
34
+ const provide = /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-instance");
35
+ if (typeof factoryOrTool === "function") {
36
+ return {
37
+ provide,
38
+ useFactory: /* @__PURE__ */ __name((...deps) => brand(factoryOrTool(...deps)), "useFactory"),
39
+ inject: inject ?? []
40
+ };
41
+ }
42
+ return {
43
+ provide,
44
+ useValue: brand(factoryOrTool)
45
+ };
46
+ }
47
+ __name(provideAgentTool, "provideAgentTool");
48
+ function provideAgentTools(factory, inject) {
49
+ return {
50
+ provide: /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-list"),
51
+ useFactory: /* @__PURE__ */ __name(async (...deps) => (await factory(...deps)).map(brand), "useFactory"),
52
+ inject: inject ?? []
53
+ };
54
+ }
55
+ __name(provideAgentTools, "provideAgentTools");
56
+
57
+ // src/genui/agent-genui.module.ts
13
58
  function _ts_decorate(decorators, target, key, desc) {
14
59
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
60
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -24,6 +69,124 @@ function _ts_decorate(decorators, target, key, desc) {
24
69
  return c > 3 && r && Object.defineProperty(target, key, r), r;
25
70
  }
26
71
  __name(_ts_decorate, "_ts_decorate");
72
+ var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
73
+ var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
74
+ var GenuiCatalogResolver = class {
75
+ static {
76
+ __name(this, "GenuiCatalogResolver");
77
+ }
78
+ };
79
+ function resolverProviders(resolver) {
80
+ if (resolver === void 0) return [];
81
+ return [
82
+ typeof resolver === "function" ? {
83
+ provide: GenuiCatalogResolver,
84
+ useClass: resolver
85
+ } : {
86
+ provide: GenuiCatalogResolver,
87
+ useValue: resolver
88
+ }
89
+ ];
90
+ }
91
+ __name(resolverProviders, "resolverProviders");
92
+ function toolOptions(options, resolver) {
93
+ const { catalog: _catalog, ...rest } = options;
94
+ return {
95
+ ...rest,
96
+ ...resolver !== void 0 ? {
97
+ resolveCatalog: /* @__PURE__ */ __name((scope) => resolver.resolve(scope), "resolveCatalog")
98
+ } : {}
99
+ };
100
+ }
101
+ __name(toolOptions, "toolOptions");
102
+ function coreProviders(resolver) {
103
+ return [
104
+ {
105
+ provide: GENUI_CATALOG,
106
+ useFactory: /* @__PURE__ */ __name((options) => options.catalog ?? defineCatalog([]), "useFactory"),
107
+ inject: [
108
+ GENUI_OPTIONS
109
+ ]
110
+ },
111
+ ...resolverProviders(resolver),
112
+ // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
113
+ // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
114
+ provideAgentTools((options, catalog, perRequest) => genuiTools(catalog, toolOptions(options, perRequest)), [
115
+ GENUI_OPTIONS,
116
+ GENUI_CATALOG,
117
+ {
118
+ token: GenuiCatalogResolver,
119
+ optional: true
120
+ }
121
+ ])
122
+ ];
123
+ }
124
+ __name(coreProviders, "coreProviders");
125
+ var EXPORTS = [
126
+ GENUI_CATALOG,
127
+ GENUI_OPTIONS
128
+ ];
129
+ var AgentGenuiModule = class _AgentGenuiModule {
130
+ static {
131
+ __name(this, "AgentGenuiModule");
132
+ }
133
+ static forRoot(options = {}) {
134
+ const { resolver, ...rest } = options;
135
+ return {
136
+ module: _AgentGenuiModule,
137
+ global: true,
138
+ providers: [
139
+ {
140
+ provide: GENUI_OPTIONS,
141
+ useValue: rest
142
+ },
143
+ ...coreProviders(resolver)
144
+ ],
145
+ exports: resolver === void 0 ? EXPORTS : [
146
+ ...EXPORTS,
147
+ GenuiCatalogResolver
148
+ ]
149
+ };
150
+ }
151
+ static forRootAsync(options) {
152
+ return {
153
+ module: _AgentGenuiModule,
154
+ global: true,
155
+ imports: options.imports ?? [],
156
+ providers: [
157
+ {
158
+ provide: GENUI_OPTIONS,
159
+ useFactory: options.useFactory,
160
+ inject: options.inject ?? []
161
+ },
162
+ ...coreProviders(options.resolver)
163
+ ],
164
+ exports: options.resolver === void 0 ? EXPORTS : [
165
+ ...EXPORTS,
166
+ GenuiCatalogResolver
167
+ ]
168
+ };
169
+ }
170
+ };
171
+ AgentGenuiModule = _ts_decorate([
172
+ Module({})
173
+ ], AgentGenuiModule);
174
+
175
+ // src/agent-deps.factory.ts
176
+ function _ts_decorate2(decorators, target, key, desc) {
177
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
178
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
179
+ r = Reflect.decorate(decorators, target, key, desc);
180
+ } else {
181
+ for (var i = decorators.length - 1; i >= 0; i--) {
182
+ if (d = decorators[i]) {
183
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
184
+ }
185
+ }
186
+ }
187
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
188
+ }
189
+ __name(_ts_decorate2, "_ts_decorate");
27
190
  function _ts_metadata(metadataKey, metadataValue) {
28
191
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
29
192
  return Reflect.metadata(metadataKey, metadataValue);
@@ -56,7 +219,9 @@ var AgentDepsFactory2 = class {
56
219
  pricingStore;
57
220
  skills;
58
221
  memory;
59
- constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory) {
222
+ uiCatalog;
223
+ uiCatalogResolver;
224
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory, uiCatalog, uiCatalogResolver) {
60
225
  this.options = options;
61
226
  this.model = model;
62
227
  this.store = store;
@@ -68,6 +233,9 @@ var AgentDepsFactory2 = class {
68
233
  this.pricingStore = pricingStore;
69
234
  this.skills = skills;
70
235
  this.memory = memory;
236
+ this.uiCatalog = uiCatalog;
237
+ this.uiCatalogResolver = uiCatalogResolver;
238
+ if (options.actionApprovalMode === "independent") assertIndependentActionCapabilities(store, options.backgroundActorResolver);
71
239
  }
72
240
  /** The turn's memory seam, shared with the read-back endpoint. Undefined → memory is not configured. */
73
241
  memoryConfig() {
@@ -107,8 +275,76 @@ var AgentDepsFactory2 = class {
107
275
  ...delegated
108
276
  ];
109
277
  }
278
+ /**
279
+ * The agent a name stands for: itself when it is a registered agent (or unknown — the bare
280
+ * assistant), else the agent whose persona took the name over (`Persona.aliases`) and that persona.
281
+ */
282
+ resolveAgent(name) {
283
+ if (this.agents.has(name)) {
284
+ return {
285
+ agentName: name
286
+ };
287
+ }
288
+ const alias = resolvePersonaAlias(this.agents.list(), name);
289
+ return alias === void 0 ? {
290
+ agentName: name
291
+ } : {
292
+ agentName: alias.agent,
293
+ persona: alias.persona
294
+ };
295
+ }
296
+ /** `agentName`'s personas as a picker reads them. Empty when it declares none. */
297
+ personaCatalog(agentName) {
298
+ return (this.agents.get(agentName)?.personas ?? []).map(personaCatalogEntry);
299
+ }
300
+ /** The persona `agentName` runs under when nothing names one. Undefined → none. */
301
+ defaultPersona(agentName) {
302
+ return this.agents.get(agentName)?.defaultPersona;
303
+ }
304
+ /**
305
+ * The persona a turn of `agentName` runs under, most specific first: the one the send names
306
+ * (refused with `400 persona_not_found` when the agent does not declare it), else the thread's
307
+ * pinned one when this agent declares it, else the agent's default. Undefined → none.
308
+ */
309
+ resolvePersona(args) {
310
+ const definition = this.agents.get(args.agentName);
311
+ if (args.requested !== void 0) {
312
+ if (findPersona(definition, args.requested) === void 0) {
313
+ throw new BadRequestException({
314
+ statusCode: 400,
315
+ code: "persona_not_found",
316
+ message: `agent "${args.agentName}" has no persona "${args.requested}"`
317
+ });
318
+ }
319
+ return args.requested;
320
+ }
321
+ const pinned = args.threadPersona ?? void 0;
322
+ if (pinned !== void 0 && findPersona(definition, pinned) !== void 0) {
323
+ return pinned;
324
+ }
325
+ return definition?.defaultPersona;
326
+ }
327
+ forProposal(proposal, _actor) {
328
+ const name = proposal.executionContext?.agentName;
329
+ 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`);
330
+ const deps = this.forAgent(name);
331
+ const id = proposal.executionContext?.persona;
332
+ if (id !== void 0) {
333
+ const persona = deps.personas?.find((persona2) => persona2.id === id);
334
+ if (!persona) throw new Error(`Recorded persona ${id} no longer exists`);
335
+ return this.withPersona(deps, persona);
336
+ }
337
+ return deps;
338
+ }
110
339
  forAgent(agentName) {
111
340
  const name = agentName ?? this.defaultAgentName();
341
+ if (agentName !== void 0 && !this.agents.has(agentName)) {
342
+ const alias = resolvePersonaAlias(this.agents.list(), agentName);
343
+ const persona = alias === void 0 ? void 0 : findPersona(this.agents.get(alias.agent), alias.persona);
344
+ if (alias !== void 0 && persona !== void 0) {
345
+ return this.withPersona(this.forAgent(alias.agent), persona);
346
+ }
347
+ }
112
348
  const definition = this.agents.get(name);
113
349
  const toolAllowList = this.effectiveTools(definition);
114
350
  const followUpsCount = this.followUpsCount();
@@ -118,12 +354,27 @@ var AgentDepsFactory2 = class {
118
354
  return {
119
355
  model: this.model,
120
356
  store: this.store,
357
+ ...this.options.actionApprovalMode !== void 0 ? {
358
+ actionApprovalMode: this.options.actionApprovalMode
359
+ } : {},
121
360
  sink: this.sink,
122
361
  rolesPolicy: this.rolesPolicy,
123
362
  ...this.options.approvalPolicy !== void 0 ? {
124
363
  approvalPolicy: this.options.approvalPolicy
125
364
  } : {},
126
365
  registry: this.registry,
366
+ ...this.uiCatalog !== void 0 || this.uiCatalogResolver !== void 0 ? {
367
+ resolveUiCatalog: /* @__PURE__ */ __name((scope) => {
368
+ const catalog = this.uiCatalogResolver?.resolve({
369
+ ...scope,
370
+ ...scope.actor.tenantRef !== void 0 ? {
371
+ tenant: scope.actor.tenantRef
372
+ } : {}
373
+ }) ?? this.uiCatalog;
374
+ if (!catalog) throw new Error("UI catalog unavailable");
375
+ return catalog;
376
+ }, "resolveUiCatalog")
377
+ } : {},
127
378
  promptContributors: this.promptContributors,
128
379
  systemPrompt: definition?.systemPrompt ?? this.options.systemPrompt ?? "You are a helpful assistant.",
129
380
  maxSteps: definition?.maxSteps ?? 8,
@@ -173,6 +424,9 @@ var AgentDepsFactory2 = class {
173
424
  ...toolAllowList !== void 0 ? {
174
425
  toolAllowList
175
426
  } : {},
427
+ ...definition?.personas !== void 0 ? {
428
+ personas: definition.personas
429
+ } : {},
176
430
  ...this.options.toolTimeoutMs !== void 0 ? {
177
431
  toolTimeoutMs: this.options.toolTimeoutMs
178
432
  } : {},
@@ -191,6 +445,45 @@ var AgentDepsFactory2 = class {
191
445
  };
192
446
  }
193
447
  /**
448
+ * A persona baked into an agent's deps — how a run journaled under an agent name that a persona
449
+ * has since taken over (`Persona.aliases`) is served. That run names no persona of its own (it
450
+ * predates them, and its input cannot change), so the persona applies the way the old agent's own
451
+ * config did: as config, re-read on every replay, with no checkpoint of its own.
452
+ */
453
+ withPersona(deps, persona) {
454
+ const base = deps.systemPrompt;
455
+ const ref = {
456
+ id: persona.id,
457
+ label: persona.label
458
+ };
459
+ const resolve = /* @__PURE__ */ __name(async (prompt, ctx) => typeof prompt === "function" ? prompt(ctx) : prompt, "resolve");
460
+ const own = persona.systemPrompt;
461
+ const systemPrompt = /* @__PURE__ */ __name(async (ctx) => {
462
+ const scoped = {
463
+ ...ctx,
464
+ persona: ref
465
+ };
466
+ if (own === void 0) {
467
+ return resolve(base, scoped);
468
+ }
469
+ const basePrompt = typeof own === "function" ? await resolve(base, scoped) : void 0;
470
+ return resolve(own, {
471
+ ...scoped,
472
+ ...basePrompt !== void 0 ? {
473
+ basePrompt
474
+ } : {}
475
+ });
476
+ }, "systemPrompt");
477
+ const toolAllowList = intersectAllowLists(deps.toolAllowList, persona.allowedTools);
478
+ return {
479
+ ...deps,
480
+ systemPrompt,
481
+ ...toolAllowList !== void 0 ? {
482
+ toolAllowList
483
+ } : {}
484
+ };
485
+ }
486
+ /**
194
487
  * The ceiling on how much of a thread this agent's turns carry, most specific wins: the agent's
195
488
  * own `@Agent({ history })`, else a module-wide custom `historyPolicy`, else the module-wide
196
489
  * `history` window. Undefined → unbounded, the behaviour of a module that configures none.
@@ -232,22 +525,25 @@ var AgentDepsFactory2 = class {
232
525
  return void 0;
233
526
  }
234
527
  };
235
- AgentDepsFactory2 = _ts_decorate([
528
+ AgentDepsFactory2 = _ts_decorate2([
236
529
  Injectable(),
237
- _ts_param(0, Inject(AGENT_OPTIONS)),
238
- _ts_param(1, Inject(AGENT_MODEL)),
239
- _ts_param(2, Inject(AGENT_STORE)),
240
- _ts_param(3, Inject(AGENT_SINK)),
241
- _ts_param(4, Inject(AGENT_ROLES_POLICY)),
242
- _ts_param(5, Inject(AGENT_TOOL_REGISTRY)),
243
- _ts_param(6, Inject(AGENT_REGISTRY)),
244
- _ts_param(7, Inject(AGENT_PROMPT_CONTRIBUTORS)),
530
+ _ts_param(0, Inject2(AGENT_OPTIONS)),
531
+ _ts_param(1, Inject2(AGENT_MODEL)),
532
+ _ts_param(2, Inject2(AGENT_STORE)),
533
+ _ts_param(3, Inject2(AGENT_SINK)),
534
+ _ts_param(4, Inject2(AGENT_ROLES_POLICY)),
535
+ _ts_param(5, Inject2(AGENT_TOOL_REGISTRY)),
536
+ _ts_param(6, Inject2(AGENT_REGISTRY)),
537
+ _ts_param(7, Inject2(AGENT_PROMPT_CONTRIBUTORS)),
245
538
  _ts_param(8, Optional()),
246
- _ts_param(8, Inject(AGENT_PRICING_STORE)),
539
+ _ts_param(8, Inject2(AGENT_PRICING_STORE)),
247
540
  _ts_param(9, Optional()),
248
- _ts_param(9, Inject(AGENT_SKILLS)),
541
+ _ts_param(9, Inject2(AGENT_SKILLS)),
249
542
  _ts_param(10, Optional()),
250
- _ts_param(10, Inject(AGENT_MEMORY)),
543
+ _ts_param(10, Inject2(AGENT_MEMORY)),
544
+ _ts_param(11, Optional()),
545
+ _ts_param(11, Inject2(GENUI_CATALOG)),
546
+ _ts_param(12, Optional()),
251
547
  _ts_metadata("design:type", Function),
252
548
  _ts_metadata("design:paramtypes", [
253
549
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -260,13 +556,15 @@ AgentDepsFactory2 = _ts_decorate([
260
556
  Array,
261
557
  Object,
262
558
  Object,
263
- Object
559
+ Object,
560
+ typeof Catalog === "undefined" ? Object : Catalog,
561
+ typeof GenuiCatalogResolver === "undefined" ? Object : GenuiCatalogResolver
264
562
  ])
265
563
  ], AgentDepsFactory2);
266
564
 
267
565
  // src/agent.service.ts
268
- import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE3, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval, readElicitationQuestions, settleDeadRun, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
269
- import { BadRequestException, ConflictException as ConflictException2, ForbiddenException, GoneException, HttpException, HttpStatus, Inject as Inject3, Injectable as Injectable3, NotFoundException, NotImplementedException as NotImplementedException2, Optional as Optional3 } from "@nestjs/common";
566
+ import { AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING2, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_MODEL_CATALOG, AGENT_OPTIONS as AGENT_OPTIONS4, AGENT_QUOTA_PROVIDER as AGENT_QUOTA_PROVIDER2, AGENT_RUNNER, AGENT_STORE as AGENT_STORE4, REQUESTER_APPROVER, findCatalogModel, mayDecideApproval as mayDecideApproval2, readElicitationQuestions, settleDeadRun, validateElicitationAnswer } from "@dudousxd/nestjs-agent-core";
567
+ import { BadRequestException as BadRequestException2, ConflictException as ConflictException2, ForbiddenException as ForbiddenException2, GoneException, HttpException, HttpStatus, Inject as Inject5, Injectable as Injectable4, NotFoundException as NotFoundException2, NotImplementedException as NotImplementedException3, Optional as Optional3 } from "@nestjs/common";
270
568
 
271
569
  // src/agent-deps.ts
272
570
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -290,10 +588,10 @@ function childSinkWriter(writer) {
290
588
  }
291
589
  __name(childSinkWriter, "childSinkWriter");
292
590
 
293
- // src/queue/chat-queue.service.ts
294
- import { AGENT_ATTACHMENT_STAGING, AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_QUOTA_PROVIDER, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE2, encodeStreamEvent, isChatQueueStore, queuedMessageView } from "@dudousxd/nestjs-agent-core";
295
- import { Inject as Inject2, Injectable as Injectable2, Logger, NotImplementedException, Optional as Optional2 } from "@nestjs/common";
296
- function _ts_decorate2(decorators, target, key, desc) {
591
+ // src/proposals/action-proposal.service.ts
592
+ import { AGENT_OPTIONS as AGENT_OPTIONS2, AGENT_STORE as AGENT_STORE2, mayDecideApproval, parseTextActionProposalCommand, resolveTextActionProposalDecision } from "@dudousxd/nestjs-agent-core";
593
+ import { ForbiddenException, Inject as Inject3, Injectable as Injectable2, NotFoundException, NotImplementedException } from "@nestjs/common";
594
+ function _ts_decorate3(decorators, target, key, desc) {
297
595
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
298
596
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
299
597
  r = Reflect.decorate(decorators, target, key, desc);
@@ -306,7 +604,7 @@ function _ts_decorate2(decorators, target, key, desc) {
306
604
  }
307
605
  return c > 3 && r && Object.defineProperty(target, key, r), r;
308
606
  }
309
- __name(_ts_decorate2, "_ts_decorate");
607
+ __name(_ts_decorate3, "_ts_decorate");
310
608
  function _ts_metadata2(metadataKey, metadataValue) {
311
609
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
312
610
  return Reflect.metadata(metadataKey, metadataValue);
@@ -319,6 +617,168 @@ function _ts_param2(paramIndex, decorator) {
319
617
  };
320
618
  }
321
619
  __name(_ts_param2, "_ts_param");
620
+ var ActionProposalService = class {
621
+ static {
622
+ __name(this, "ActionProposalService");
623
+ }
624
+ store;
625
+ options;
626
+ constructor(store, options) {
627
+ this.store = store;
628
+ this.options = options;
629
+ }
630
+ capability() {
631
+ const store = this.store;
632
+ if (typeof store.getThreadActionProposalScope !== "function" || typeof store.listActionProposals !== "function") throw new NotImplementedException("Action proposals are unavailable");
633
+ return store;
634
+ }
635
+ async scope(threadId, actor) {
636
+ const scope = await this.capability().getThreadActionProposalScope(threadId);
637
+ if (!scope) throw new NotFoundException("Thread not found");
638
+ if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new ForbiddenException("Wrong proposal tenant");
639
+ return scope;
640
+ }
641
+ mayDecide(actor, proposal) {
642
+ return mayDecideApproval(this.options.approvalPolicy, actor, {
643
+ toolCallId: proposal.originToolCallId,
644
+ approver: proposal.approver,
645
+ requesterRef: proposal.actorRef
646
+ });
647
+ }
648
+ async listPage(threadId, actor, query = {}) {
649
+ const scope = await this.scope(threadId, actor);
650
+ const rows = await this.capability().listActionProposals(scope, {
651
+ limit: 1e3,
652
+ ...query
653
+ });
654
+ const visible = [];
655
+ for (const row of rows) if (scope.actorRef === actor.id || await this.mayDecide(actor, row)) visible.push(row);
656
+ const last = rows.at(-1);
657
+ return {
658
+ items: visible,
659
+ ...rows.length === 1e3 && last ? {
660
+ next: {
661
+ createdAt: last.createdAt,
662
+ id: last.id
663
+ }
664
+ } : {}
665
+ };
666
+ }
667
+ async list(threadId, actor) {
668
+ return (await this.listPage(threadId, actor)).items;
669
+ }
670
+ async decide(threadId, proposalId, actor, command) {
671
+ const scope = await this.scope(threadId, actor);
672
+ const proposal = await this.capability().getActionProposal(scope, proposalId);
673
+ if (!proposal) throw new NotFoundException("Proposal not found");
674
+ if (!await this.mayDecide(actor, proposal)) throw new ForbiddenException("May not decide this proposal");
675
+ return this.capability().decideActionProposal(scope, proposalId, {
676
+ decision: command.decision,
677
+ actorRef: actor.id,
678
+ via: command.via ?? "web",
679
+ ...command.remember !== void 0 ? {
680
+ remember: command.remember
681
+ } : {},
682
+ ...command.reason !== void 0 ? {
683
+ reason: command.reason
684
+ } : {}
685
+ });
686
+ }
687
+ async handleTextDecision(threadId, actor, text) {
688
+ const command = parseTextActionProposalCommand(text);
689
+ if (command.status === "unmatched") return command;
690
+ if (command.proposalId !== void 0) {
691
+ const result2 = await this.decide(threadId, command.proposalId, actor, {
692
+ decision: command.decision,
693
+ remember: command.remember,
694
+ via: "text"
695
+ });
696
+ return this.textReceipt(threadId, result2);
697
+ }
698
+ const candidates = [];
699
+ const scope = await this.scope(threadId, actor);
700
+ const pending = await this.capability().listActionProposals(scope, {
701
+ decision: "pending",
702
+ limit: 1e3
703
+ });
704
+ for (const proposal of pending) if (await this.mayDecide(actor, proposal)) candidates.push(proposal);
705
+ const resolution = resolveTextActionProposalDecision(text, candidates);
706
+ if (resolution.status === "unmatched") return resolution;
707
+ if (resolution.status === "ambiguous" || resolution.status === "decision" && pending.length === 1e3 && !text.includes("#")) return {
708
+ threadId,
709
+ proposalDecision: {
710
+ status: "ambiguous",
711
+ proposalIds: candidates.map(({ id }) => id)
712
+ },
713
+ text: `Choose the action to decide: ${candidates.map(({ id }) => id).map((id) => `#${id}`).join(", ")}`
714
+ };
715
+ const result = await this.decide(threadId, resolution.proposalId, actor, {
716
+ decision: resolution.decision,
717
+ remember: resolution.remember,
718
+ via: "text"
719
+ });
720
+ return this.textReceipt(threadId, result);
721
+ }
722
+ textReceipt(threadId, result) {
723
+ return {
724
+ threadId,
725
+ proposalDecision: result,
726
+ text: result.proposal?.decision === "approved" ? "Action approved and queued for execution." : `Action ${result.proposal?.decision ?? result.status}; no execution was performed by this decision.`
727
+ };
728
+ }
729
+ };
730
+ ActionProposalService = _ts_decorate3([
731
+ Injectable2(),
732
+ _ts_param2(0, Inject3(AGENT_STORE2)),
733
+ _ts_param2(1, Inject3(AGENT_OPTIONS2)),
734
+ _ts_metadata2("design:type", Function),
735
+ _ts_metadata2("design:paramtypes", [
736
+ typeof AgentStore === "undefined" ? Object : AgentStore,
737
+ typeof Pick === "undefined" ? Object : Pick
738
+ ])
739
+ ], ActionProposalService);
740
+
741
+ // src/queue/chat-queue.service.ts
742
+ import { AGENT_ATTACHMENT_STAGING, AGENT_DEPS_FACTORY, AGENT_OPTIONS as AGENT_OPTIONS3, AGENT_QUOTA_PROVIDER, AGENT_SINK as AGENT_SINK2, AGENT_STORE as AGENT_STORE3, encodeStreamEvent, isChatQueueStore, queuedMessageView } from "@dudousxd/nestjs-agent-core";
743
+ import { Inject as Inject4, Injectable as Injectable3, Logger, NotImplementedException as NotImplementedException2, Optional as Optional2 } from "@nestjs/common";
744
+
745
+ // src/thread-persona.ts
746
+ async function threadPersona(store, threadId) {
747
+ const projecting = store;
748
+ if (typeof projecting.personaForThread === "function") {
749
+ return projecting.personaForThread(threadId);
750
+ }
751
+ return (await store.getThread(threadId))?.persona ?? null;
752
+ }
753
+ __name(threadPersona, "threadPersona");
754
+
755
+ // src/queue/chat-queue.service.ts
756
+ function _ts_decorate4(decorators, target, key, desc) {
757
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
758
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
759
+ r = Reflect.decorate(decorators, target, key, desc);
760
+ } else {
761
+ for (var i = decorators.length - 1; i >= 0; i--) {
762
+ if (d = decorators[i]) {
763
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
764
+ }
765
+ }
766
+ }
767
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
768
+ }
769
+ __name(_ts_decorate4, "_ts_decorate");
770
+ function _ts_metadata3(metadataKey, metadataValue) {
771
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
772
+ return Reflect.metadata(metadataKey, metadataValue);
773
+ }
774
+ }
775
+ __name(_ts_metadata3, "_ts_metadata");
776
+ function _ts_param3(paramIndex, decorator) {
777
+ return function(target, key) {
778
+ decorator(target, key, paramIndex);
779
+ };
780
+ }
781
+ __name(_ts_param3, "_ts_param");
322
782
  var MAX_DRAIN_ATTEMPTS = 8;
323
783
  var ChatQueueService = class _ChatQueueService {
324
784
  static {
@@ -329,18 +789,20 @@ var ChatQueueService = class _ChatQueueService {
329
789
  quotaProvider;
330
790
  options;
331
791
  staging;
792
+ deps;
332
793
  logger = new Logger(_ChatQueueService.name);
333
794
  /**
334
795
  * Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
335
796
  * alive whatever the runner says — it simply has not registered the run yet.
336
797
  */
337
798
  starting = /* @__PURE__ */ new Set();
338
- constructor(store, sink, quotaProvider, options, staging) {
799
+ constructor(store, sink, quotaProvider, options, staging, deps) {
339
800
  this.store = store;
340
801
  this.sink = sink;
341
802
  this.quotaProvider = quotaProvider;
342
803
  this.options = options;
343
804
  this.staging = staging;
805
+ this.deps = deps;
344
806
  }
345
807
  /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
346
808
  get supported() {
@@ -349,7 +811,7 @@ var ChatQueueService = class _ChatQueueService {
349
811
  /** The bound store as a queue store, or a 501 naming what is missing. */
350
812
  queueStore() {
351
813
  if (!isChatQueueStore(this.store)) {
352
- throw new NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
814
+ throw new NotImplementedException2("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
353
815
  }
354
816
  return this.store;
355
817
  }
@@ -576,6 +1038,9 @@ var ChatQueueService = class _ChatQueueService {
576
1038
  } : {},
577
1039
  ...input.pageContext !== void 0 ? {
578
1040
  pageContext: input.pageContext
1041
+ } : {},
1042
+ ...input.uiCapabilities !== void 0 ? {
1043
+ uiCapabilities: input.uiCapabilities
579
1044
  } : {}
580
1045
  });
581
1046
  await store.setQueuePause(threadId, {
@@ -638,13 +1103,17 @@ var ChatQueueService = class _ChatQueueService {
638
1103
  */
639
1104
  async inputFor(message) {
640
1105
  const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
1106
+ const { agentName, persona } = await this.targetFor(message);
641
1107
  return {
642
1108
  threadId: message.threadId,
643
1109
  actor: message.actor,
644
1110
  userText: message.content,
645
1111
  day: utcDay(),
646
- ...message.agentName !== void 0 ? {
647
- agentName: message.agentName
1112
+ ...agentName !== void 0 ? {
1113
+ agentName
1114
+ } : {},
1115
+ ...persona !== void 0 ? {
1116
+ persona
648
1117
  } : {},
649
1118
  ...attachments.length > 0 ? {
650
1119
  attachments
@@ -652,11 +1121,45 @@ var ChatQueueService = class _ChatQueueService {
652
1121
  ...message.pageContext !== void 0 ? {
653
1122
  pageContext: message.pageContext
654
1123
  } : {},
1124
+ ...message.uiCapabilities !== void 0 ? {
1125
+ uiCapabilities: message.uiCapabilities
1126
+ } : {},
655
1127
  ...message.model !== void 0 ? {
656
1128
  model: message.model
657
1129
  } : {}
658
1130
  };
659
1131
  }
1132
+ /**
1133
+ * The agent and persona a queued message starts as. A message carries the persona its send
1134
+ * resolved; one that carries none — queued before personas existed, or by a host that sets none —
1135
+ * resolves it now, exactly as a send would: an agent name a persona took over, then the thread's
1136
+ * pinned persona, then the agent's default. Never refused here: nobody is waiting on a 400.
1137
+ */
1138
+ async targetFor(message) {
1139
+ const deps = this.deps;
1140
+ if (message.persona !== void 0 || deps === void 0 || message.agentName === void 0) {
1141
+ return {
1142
+ ...message.agentName !== void 0 ? {
1143
+ agentName: message.agentName
1144
+ } : {},
1145
+ ...message.persona !== void 0 ? {
1146
+ persona: message.persona
1147
+ } : {}
1148
+ };
1149
+ }
1150
+ const target = deps.resolveAgent(message.agentName);
1151
+ const hasPersonas = deps.personaCatalog(target.agentName).length > 0;
1152
+ const persona = target.persona ?? (hasPersonas ? deps.resolvePersona({
1153
+ agentName: target.agentName,
1154
+ threadPersona: await threadPersona(this.store, message.threadId)
1155
+ }) : void 0);
1156
+ return {
1157
+ agentName: target.agentName,
1158
+ ...persona !== void 0 ? {
1159
+ persona
1160
+ } : {}
1161
+ };
1162
+ }
660
1163
  async freshAttachments(actor, attachments) {
661
1164
  const staging = this.staging;
662
1165
  if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
@@ -674,23 +1177,26 @@ var ChatQueueService = class _ChatQueueService {
674
1177
  }));
675
1178
  }
676
1179
  };
677
- ChatQueueService = _ts_decorate2([
678
- Injectable2(),
679
- _ts_param2(0, Inject2(AGENT_STORE2)),
680
- _ts_param2(1, Inject2(AGENT_SINK2)),
681
- _ts_param2(2, Optional2()),
682
- _ts_param2(2, Inject2(AGENT_QUOTA_PROVIDER)),
683
- _ts_param2(3, Optional2()),
684
- _ts_param2(3, Inject2(AGENT_OPTIONS2)),
685
- _ts_param2(4, Optional2()),
686
- _ts_param2(4, Inject2(AGENT_ATTACHMENT_STAGING)),
687
- _ts_metadata2("design:type", Function),
688
- _ts_metadata2("design:paramtypes", [
1180
+ ChatQueueService = _ts_decorate4([
1181
+ Injectable3(),
1182
+ _ts_param3(0, Inject4(AGENT_STORE3)),
1183
+ _ts_param3(1, Inject4(AGENT_SINK2)),
1184
+ _ts_param3(2, Optional2()),
1185
+ _ts_param3(2, Inject4(AGENT_QUOTA_PROVIDER)),
1186
+ _ts_param3(3, Optional2()),
1187
+ _ts_param3(3, Inject4(AGENT_OPTIONS3)),
1188
+ _ts_param3(4, Optional2()),
1189
+ _ts_param3(4, Inject4(AGENT_ATTACHMENT_STAGING)),
1190
+ _ts_param3(5, Optional2()),
1191
+ _ts_param3(5, Inject4(AGENT_DEPS_FACTORY)),
1192
+ _ts_metadata3("design:type", Function),
1193
+ _ts_metadata3("design:paramtypes", [
689
1194
  typeof AgentStore === "undefined" ? Object : AgentStore,
690
1195
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
691
1196
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
692
1197
  typeof Pick === "undefined" ? Object : Pick,
693
- typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
1198
+ typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
1199
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
694
1200
  ])
695
1201
  ], ChatQueueService);
696
1202
  function pauseReasonFor(outcome, head) {
@@ -736,7 +1242,7 @@ var RunNotActiveException = class extends ConflictException {
736
1242
  };
737
1243
 
738
1244
  // src/agent.service.ts
739
- function _ts_decorate3(decorators, target, key, desc) {
1245
+ function _ts_decorate5(decorators, target, key, desc) {
740
1246
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
741
1247
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
742
1248
  r = Reflect.decorate(decorators, target, key, desc);
@@ -749,19 +1255,19 @@ function _ts_decorate3(decorators, target, key, desc) {
749
1255
  }
750
1256
  return c > 3 && r && Object.defineProperty(target, key, r), r;
751
1257
  }
752
- __name(_ts_decorate3, "_ts_decorate");
753
- function _ts_metadata3(metadataKey, metadataValue) {
1258
+ __name(_ts_decorate5, "_ts_decorate");
1259
+ function _ts_metadata4(metadataKey, metadataValue) {
754
1260
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
755
1261
  return Reflect.metadata(metadataKey, metadataValue);
756
1262
  }
757
1263
  }
758
- __name(_ts_metadata3, "_ts_metadata");
759
- function _ts_param3(paramIndex, decorator) {
1264
+ __name(_ts_metadata4, "_ts_metadata");
1265
+ function _ts_param4(paramIndex, decorator) {
760
1266
  return function(target, key) {
761
1267
  decorator(target, key, paramIndex);
762
1268
  };
763
1269
  }
764
- __name(_ts_param3, "_ts_param");
1270
+ __name(_ts_param4, "_ts_param");
765
1271
  var AgentService = class {
766
1272
  static {
767
1273
  __name(this, "AgentService");
@@ -774,7 +1280,8 @@ var AgentService = class {
774
1280
  quotaProvider;
775
1281
  options;
776
1282
  queue;
777
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
1283
+ proposals;
1284
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
778
1285
  this.runner = runner;
779
1286
  this.store = store;
780
1287
  this.deps = deps;
@@ -783,8 +1290,15 @@ var AgentService = class {
783
1290
  this.quotaProvider = quotaProvider;
784
1291
  this.options = options;
785
1292
  this.queue = queue;
1293
+ this.proposals = proposals;
786
1294
  }
787
- /** The queue service when the bound store can hold a queue, else `undefined`. */
1295
+ async handleTextDecision(threadId, actor, text) {
1296
+ if (this.options?.actionApprovalMode !== "independent" || !this.proposals) return {
1297
+ status: "unmatched"
1298
+ };
1299
+ return this.proposals.handleTextDecision(threadId, actor, text);
1300
+ }
1301
+ /** The queue service when the bound store can hold a queue, else `undefined`. */
788
1302
  queueing() {
789
1303
  return this.queue?.supported === true ? this.queue : void 0;
790
1304
  }
@@ -792,7 +1306,7 @@ var AgentService = class {
792
1306
  requireQueue() {
793
1307
  const queue = this.queueing();
794
1308
  if (queue === void 0) {
795
- throw new NotImplementedException2("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
1309
+ throw new NotImplementedException3("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
796
1310
  }
797
1311
  return queue;
798
1312
  }
@@ -862,17 +1376,17 @@ var AgentService = class {
862
1376
  */
863
1377
  async assertModelAllowed(actor, agent, model) {
864
1378
  if (this.models === void 0) {
865
- throw new BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
1379
+ throw new BadRequestException2(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
866
1380
  }
867
1381
  const entry = findCatalogModel(await this.models.list({
868
1382
  actor,
869
1383
  agent
870
1384
  }), model);
871
1385
  if (entry === void 0) {
872
- throw new BadRequestException(`model "${model}" is not offered`);
1386
+ throw new BadRequestException2(`model "${model}" is not offered`);
873
1387
  }
874
1388
  if (!entry.available) {
875
- throw new BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
1389
+ throw new BadRequestException2(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
876
1390
  }
877
1391
  return entry.id;
878
1392
  }
@@ -888,7 +1402,7 @@ var AgentService = class {
888
1402
  })).locked : void 0;
889
1403
  if (locked !== void 0) {
890
1404
  if (requested !== void 0 && requested !== locked.model) {
891
- throw new BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
1405
+ throw new BadRequestException2(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
892
1406
  }
893
1407
  return locked.model;
894
1408
  }
@@ -914,7 +1428,10 @@ var AgentService = class {
914
1428
  const result = await this.send({
915
1429
  ...params,
916
1430
  mode: "auto"
1431
+ }, {
1432
+ textDecisions: false
917
1433
  });
1434
+ if ("proposalDecision" in result) throw new Error("Unexpected text decision in run-only API");
918
1435
  if (result.queued !== true) {
919
1436
  return result;
920
1437
  }
@@ -942,15 +1459,21 @@ var AgentService = class {
942
1459
  * Send a message: start a turn, or — when its thread already has one running — queue the message
943
1460
  * to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
944
1461
  */
945
- async send(params) {
1462
+ async send(params, sendOptions = {}) {
1463
+ if (sendOptions.textDecisions !== false && this.options?.actionApprovalMode === "independent" && params.threadId !== void 0 && params.regenerate !== true && this.proposals) {
1464
+ const decision = await this.proposals.handleTextDecision(params.threadId, params.actor, params.message);
1465
+ if ("proposalDecision" in decision) return decision;
1466
+ }
946
1467
  await this.assertWithinQuota(params.actor);
947
- const agentName = await this.resolveAgentName(params.agentName, params.threadId);
1468
+ const target = this.deps.resolveAgent(await this.resolveAgentName(params.agentName, params.threadId));
1469
+ const agentName = target.agentName;
1470
+ const persona = await this.resolvePersona(agentName, params.personaId ?? target.persona, params.threadId);
948
1471
  const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
949
1472
  const attachments = await this.resolveAttachments(params.actor, params.attachments ?? []);
950
1473
  let threadId = params.threadId;
951
1474
  if (threadId === void 0) {
952
1475
  if (params.regenerate === true) {
953
- throw new BadRequestException("regenerate requires an existing threadId");
1476
+ throw new BadRequestException2("regenerate requires an existing threadId");
954
1477
  }
955
1478
  const created = await this.store.createThread({
956
1479
  actor: params.actor,
@@ -959,11 +1482,17 @@ var AgentService = class {
959
1482
  } : {},
960
1483
  ...params.newThreadId !== void 0 ? {
961
1484
  id: params.newThreadId
1485
+ } : {},
1486
+ ...params.personaId !== void 0 ? {
1487
+ persona: params.personaId
962
1488
  } : {}
963
1489
  });
964
1490
  threadId = created.id;
965
1491
  } else {
966
1492
  await this.assertOwnsThread(params.actor, threadId);
1493
+ if (params.personaId !== void 0) {
1494
+ await this.pinThreadPersona(threadId, params.personaId);
1495
+ }
967
1496
  }
968
1497
  const input = {
969
1498
  threadId,
@@ -971,6 +1500,9 @@ var AgentService = class {
971
1500
  userText: params.message,
972
1501
  day: utcDay(),
973
1502
  agentName,
1503
+ ...persona !== void 0 ? {
1504
+ persona
1505
+ } : {},
974
1506
  ...params.regenerate === true ? {
975
1507
  regenerate: true
976
1508
  } : {},
@@ -980,12 +1512,16 @@ var AgentService = class {
980
1512
  ...params.pageContext !== void 0 ? {
981
1513
  pageContext: params.pageContext
982
1514
  } : {},
1515
+ ...params.uiCapabilities !== void 0 ? {
1516
+ uiCapabilities: params.uiCapabilities
1517
+ } : {},
983
1518
  ...model !== void 0 ? {
984
1519
  model
985
1520
  } : {}
986
1521
  };
987
1522
  const queue = this.queueing();
988
1523
  if (queue === void 0) {
1524
+ if (this.options?.actionApprovalMode === "independent") throw new Error("Independent actions require queued thread admission");
989
1525
  const { runId } = await this.runner.start(input);
990
1526
  await this.store.setActiveStream(threadId, runId);
991
1527
  return {
@@ -1057,12 +1593,18 @@ var AgentService = class {
1057
1593
  ...input.agentName !== void 0 ? {
1058
1594
  agentName: input.agentName
1059
1595
  } : {},
1596
+ ...input.persona !== void 0 ? {
1597
+ persona: input.persona
1598
+ } : {},
1060
1599
  ...input.model !== void 0 ? {
1061
1600
  model: input.model
1062
1601
  } : {},
1063
1602
  ...input.pageContext !== void 0 ? {
1064
1603
  pageContext: input.pageContext
1065
1604
  } : {},
1605
+ ...input.uiCapabilities !== void 0 ? {
1606
+ uiCapabilities: input.uiCapabilities
1607
+ } : {},
1066
1608
  ...interrupting !== void 0 ? {
1067
1609
  interrupt: true,
1068
1610
  at: "head"
@@ -1109,7 +1651,7 @@ var AgentService = class {
1109
1651
  const store = queue.queueStore();
1110
1652
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
1111
1653
  if (patch.message !== void 0 && patch.message.trim().length === 0) {
1112
- throw new BadRequestException("message must not be empty");
1654
+ throw new BadRequestException2("message must not be empty");
1113
1655
  }
1114
1656
  const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
1115
1657
  if (patch.message !== void 0 || attachments !== void 0) {
@@ -1127,7 +1669,7 @@ var AgentService = class {
1127
1669
  }
1128
1670
  if (patch.position !== void 0) {
1129
1671
  if (!Number.isInteger(patch.position) || patch.position < 0) {
1130
- throw new BadRequestException("position must be a non-negative integer");
1672
+ throw new BadRequestException2("position must be a non-negative integer");
1131
1673
  }
1132
1674
  if (!await store.moveQueuedMessage(messageId, patch.position)) {
1133
1675
  throw new GoneException(`queued message ${messageId} already started or was removed`);
@@ -1167,7 +1709,7 @@ var AgentService = class {
1167
1709
  throw gone();
1168
1710
  }
1169
1711
  if (marked.interrupt !== true) {
1170
- throw new NotImplementedException2("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1712
+ throw new NotImplementedException3("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
1171
1713
  }
1172
1714
  if (!await store.moveQueuedMessage(messageId, 0)) {
1173
1715
  throw gone();
@@ -1226,7 +1768,7 @@ var AgentService = class {
1226
1768
  async assertOwnsQueuedMessage(actor, messageId) {
1227
1769
  const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
1228
1770
  if (message === null) {
1229
- throw new NotFoundException(`queued message ${messageId} not found`);
1771
+ throw new NotFoundException2(`queued message ${messageId} not found`);
1230
1772
  }
1231
1773
  await this.assertOwnsThread(actor, message.threadId);
1232
1774
  return message.threadId;
@@ -1247,7 +1789,7 @@ var AgentService = class {
1247
1789
  }
1248
1790
  const staging = this.staging;
1249
1791
  if (staging === void 0 || typeof staging.resolve !== "function") {
1250
- throw new NotImplementedException2("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1792
+ throw new NotImplementedException3("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
1251
1793
  }
1252
1794
  const resolved = [];
1253
1795
  for (const ref of refs) {
@@ -1256,7 +1798,7 @@ var AgentService = class {
1256
1798
  actor
1257
1799
  });
1258
1800
  if (attachment === null) {
1259
- throw new ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
1801
+ throw new ForbiddenException2(`attachment ${ref.mediaId} is not available to this actor`);
1260
1802
  }
1261
1803
  resolved.push(attachment);
1262
1804
  }
@@ -1358,6 +1900,7 @@ var AgentService = class {
1358
1900
  * not the thread's own actor).
1359
1901
  */
1360
1902
  async signalToolCall(toolCallId2, reply) {
1903
+ if ((await this.store.toolCallApproval?.(toolCallId2))?.status === "proposed") throw new ConflictException2("Independent proposals require the scoped proposal decision route");
1361
1904
  await this.assertNotExpired(toolCallId2);
1362
1905
  const runId = await this.resolveRunForToolCall(toolCallId2);
1363
1906
  await this.assertRunWaiting(runId);
@@ -1398,7 +1941,7 @@ var AgentService = class {
1398
1941
  throw new RunNotActiveException(runId);
1399
1942
  }
1400
1943
  if (owner !== actor.id) {
1401
- throw new ForbiddenException("run belongs to another actor");
1944
+ throw new ForbiddenException2("run belongs to another actor");
1402
1945
  }
1403
1946
  }
1404
1947
  /**
@@ -1451,16 +1994,22 @@ var AgentService = class {
1451
1994
  async updateThread(actor, threadId, patch) {
1452
1995
  const title = patch.title !== void 0 ? this.validateTitle(patch.title) : void 0;
1453
1996
  await this.assertOwnsThread(actor, threadId);
1454
- if (patch.defaultAgent === void 0 && patch.model === void 0) {
1997
+ if (patch.defaultAgent === void 0 && patch.model === void 0 && patch.persona === void 0) {
1455
1998
  if (title !== void 0) {
1456
1999
  await this.store.setTitle(threadId, title);
1457
2000
  }
1458
2001
  return;
1459
2002
  }
1460
2003
  if (this.store.updateThread === void 0) {
1461
- throw new NotImplementedException2("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
2004
+ throw new NotImplementedException3("Setting a thread's defaultAgent, model or persona requires an AgentStore that implements updateThread(); the bound store does not support it.");
1462
2005
  }
1463
2006
  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);
2007
+ if (patch.persona !== void 0 && patch.persona !== null) {
2008
+ this.deps.resolvePersona({
2009
+ agentName: this.deps.resolveAgent(patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId)).agentName,
2010
+ requested: patch.persona
2011
+ });
2012
+ }
1464
2013
  await this.store.updateThread(threadId, {
1465
2014
  ...title !== void 0 ? {
1466
2015
  title
@@ -1470,16 +2019,46 @@ var AgentService = class {
1470
2019
  } : {},
1471
2020
  ...model !== void 0 ? {
1472
2021
  model
2022
+ } : {},
2023
+ ...patch.persona !== void 0 ? {
2024
+ persona: patch.persona
1473
2025
  } : {}
1474
2026
  });
1475
2027
  }
2028
+ /**
2029
+ * The persona this send runs under — see {@link AgentDepsFactory.resolvePersona}. The thread's
2030
+ * pinned persona is read only when the send names none AND the agent has personas to pick from.
2031
+ */
2032
+ async resolvePersona(agentName, requested, threadId) {
2033
+ const needsThread = requested === void 0 && threadId !== void 0 && this.deps.personaCatalog(agentName).length > 0;
2034
+ return this.deps.resolvePersona({
2035
+ agentName,
2036
+ ...requested !== void 0 ? {
2037
+ requested
2038
+ } : {},
2039
+ ...needsThread ? {
2040
+ threadPersona: await threadPersona(this.store, threadId)
2041
+ } : {}
2042
+ });
2043
+ }
2044
+ /** Pin `persona` on the thread when it is not already — a no-op on a store that cannot. */
2045
+ async pinThreadPersona(threadId, persona) {
2046
+ if (this.store.updateThread === void 0) {
2047
+ return;
2048
+ }
2049
+ if (await threadPersona(this.store, threadId) !== persona) {
2050
+ await this.store.updateThread(threadId, {
2051
+ persona
2052
+ });
2053
+ }
2054
+ }
1476
2055
  validateTitle(title) {
1477
2056
  const trimmed = title.trim();
1478
2057
  if (trimmed.length === 0) {
1479
- throw new BadRequestException("title must not be empty");
2058
+ throw new BadRequestException2("title must not be empty");
1480
2059
  }
1481
2060
  if (trimmed.length > 200) {
1482
- throw new BadRequestException("title must be at most 200 characters");
2061
+ throw new BadRequestException2("title must be at most 200 characters");
1483
2062
  }
1484
2063
  return trimmed;
1485
2064
  }
@@ -1518,6 +2097,7 @@ var AgentService = class {
1518
2097
  ...thread,
1519
2098
  defaultAgent: thread.defaultAgent ?? null,
1520
2099
  model: thread.model ?? null,
2100
+ persona: thread.persona ?? null,
1521
2101
  activeRunId: await this.store.activeRunForThread?.(thread.id) ?? thread.activeRunId ?? null
1522
2102
  };
1523
2103
  }
@@ -1582,21 +2162,21 @@ var AgentService = class {
1582
2162
  */
1583
2163
  async setMessageFeedback(actor, messageId, input) {
1584
2164
  if (input.value !== null && input.value !== "up" && input.value !== "down") {
1585
- throw new BadRequestException("value must be 'up', 'down' or null");
2165
+ throw new BadRequestException2("value must be 'up', 'down' or null");
1586
2166
  }
1587
2167
  if (input.comment !== void 0 && typeof input.comment !== "string") {
1588
- throw new BadRequestException("comment must be a string");
2168
+ throw new BadRequestException2("comment must be a string");
1589
2169
  }
1590
2170
  const comment = input.comment?.trim();
1591
2171
  if (comment !== void 0 && comment.length > 2e3) {
1592
- throw new BadRequestException("comment must be at most 2000 characters");
2172
+ throw new BadRequestException2("comment must be at most 2000 characters");
1593
2173
  }
1594
2174
  if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
1595
- throw new NotImplementedException2("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
2175
+ throw new NotImplementedException3("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
1596
2176
  }
1597
2177
  const threadId = await this.store.threadOfMessage(messageId);
1598
2178
  if (threadId === null) {
1599
- throw new NotFoundException(`message ${messageId} not found`);
2179
+ throw new NotFoundException2(`message ${messageId} not found`);
1600
2180
  }
1601
2181
  await this.assertOwnsThread(actor, threadId);
1602
2182
  const feedback = input.value === null ? null : {
@@ -1644,7 +2224,7 @@ var AgentService = class {
1644
2224
  const list = this.attachmentInventory();
1645
2225
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
1646
2226
  if (referencedMediaIds === void 0) {
1647
- throw new NotImplementedException2("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.");
2227
+ throw new NotImplementedException3("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.");
1648
2228
  }
1649
2229
  const stagedBefore = options.olderThan.toISOString();
1650
2230
  const inventory = await list({
@@ -1666,7 +2246,7 @@ var AgentService = class {
1666
2246
  attachmentInventory() {
1667
2247
  const list = this.staging?.list?.bind(this.staging);
1668
2248
  if (list === void 0) {
1669
- throw new NotImplementedException2("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
2249
+ throw new NotImplementedException3("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
1670
2250
  }
1671
2251
  return list;
1672
2252
  }
@@ -1677,10 +2257,10 @@ var AgentService = class {
1677
2257
  async assertOwnsThread(actor, threadId) {
1678
2258
  const owner = await this.store.ownerOfThread(threadId);
1679
2259
  if (owner === null) {
1680
- throw new NotFoundException(`thread ${threadId} not found`);
2260
+ throw new NotFoundException2(`thread ${threadId} not found`);
1681
2261
  }
1682
2262
  if (owner !== actor.id) {
1683
- throw new ForbiddenException("thread belongs to another actor");
2263
+ throw new ForbiddenException2("thread belongs to another actor");
1684
2264
  }
1685
2265
  }
1686
2266
  /**
@@ -1691,10 +2271,10 @@ var AgentService = class {
1691
2271
  async assertOwnsToolCall(actor, toolCallId2) {
1692
2272
  const owner = await this.store.ownerOfToolCall(toolCallId2);
1693
2273
  if (owner === null) {
1694
- throw new NotFoundException(`tool call ${toolCallId2} not found`);
2274
+ throw new NotFoundException2(`tool call ${toolCallId2} not found`);
1695
2275
  }
1696
2276
  if (owner !== actor.id) {
1697
- throw new ForbiddenException("tool call belongs to another actor");
2277
+ throw new ForbiddenException2("tool call belongs to another actor");
1698
2278
  }
1699
2279
  }
1700
2280
  /**
@@ -1714,7 +2294,7 @@ var AgentService = class {
1714
2294
  const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
1715
2295
  const problem = validateElicitationAnswer(question, submitted ?? question.defaults ?? []);
1716
2296
  if (problem !== null) {
1717
- throw new BadRequestException(`answers["${question.id}"] ${problem}`);
2297
+ throw new BadRequestException2(`answers["${question.id}"] ${problem}`);
1718
2298
  }
1719
2299
  }
1720
2300
  }
@@ -1732,15 +2312,15 @@ var AgentService = class {
1732
2312
  }
1733
2313
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
1734
2314
  if (requesterRef === null) {
1735
- throw new NotFoundException(`tool call ${toolCallId2} not found`);
2315
+ throw new NotFoundException2(`tool call ${toolCallId2} not found`);
1736
2316
  }
1737
- const allowed = await mayDecideApproval(this.deps.forAgent().approvalPolicy, actor, {
2317
+ const allowed = await mayDecideApproval2(this.deps.forAgent().approvalPolicy, actor, {
1738
2318
  toolCallId: toolCallId2,
1739
2319
  approver,
1740
2320
  requesterRef
1741
2321
  });
1742
2322
  if (!allowed) {
1743
- throw new ForbiddenException(`this approval is for ${approver}`);
2323
+ throw new ForbiddenException2(`this approval is for ${approver}`);
1744
2324
  }
1745
2325
  }
1746
2326
  /**
@@ -1769,7 +2349,7 @@ var AgentService = class {
1769
2349
  async resolveRunForToolCall(toolCallId2) {
1770
2350
  const runId = await this.store.runForToolCall(toolCallId2);
1771
2351
  if (runId === null) {
1772
- throw new NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
2352
+ throw new NotFoundException2(`tool call ${toolCallId2} has no active run to signal`);
1773
2353
  }
1774
2354
  return runId;
1775
2355
  }
@@ -1777,29 +2357,30 @@ var AgentService = class {
1777
2357
  async assertOwnsActiveStream(actor, runId) {
1778
2358
  const owner = await this.store.ownerOfActiveStream(runId);
1779
2359
  if (owner === null) {
1780
- throw new NotFoundException(`no active run ${runId}`);
2360
+ throw new NotFoundException2(`no active run ${runId}`);
1781
2361
  }
1782
2362
  if (owner !== actor.id) {
1783
- throw new ForbiddenException("run belongs to another actor");
2363
+ throw new ForbiddenException2("run belongs to another actor");
1784
2364
  }
1785
2365
  }
1786
2366
  };
1787
- AgentService = _ts_decorate3([
1788
- Injectable3(),
1789
- _ts_param3(0, Inject3(AGENT_RUNNER)),
1790
- _ts_param3(1, Inject3(AGENT_STORE3)),
1791
- _ts_param3(2, Inject3(AGENT_DEPS_FACTORY)),
1792
- _ts_param3(3, Optional3()),
1793
- _ts_param3(3, Inject3(AGENT_ATTACHMENT_STAGING2)),
1794
- _ts_param3(4, Optional3()),
1795
- _ts_param3(4, Inject3(AGENT_MODEL_CATALOG)),
1796
- _ts_param3(5, Optional3()),
1797
- _ts_param3(5, Inject3(AGENT_QUOTA_PROVIDER2)),
1798
- _ts_param3(6, Optional3()),
1799
- _ts_param3(6, Inject3(AGENT_OPTIONS3)),
1800
- _ts_param3(7, Optional3()),
1801
- _ts_metadata3("design:type", Function),
1802
- _ts_metadata3("design:paramtypes", [
2367
+ AgentService = _ts_decorate5([
2368
+ Injectable4(),
2369
+ _ts_param4(0, Inject5(AGENT_RUNNER)),
2370
+ _ts_param4(1, Inject5(AGENT_STORE4)),
2371
+ _ts_param4(2, Inject5(AGENT_DEPS_FACTORY2)),
2372
+ _ts_param4(3, Optional3()),
2373
+ _ts_param4(3, Inject5(AGENT_ATTACHMENT_STAGING2)),
2374
+ _ts_param4(4, Optional3()),
2375
+ _ts_param4(4, Inject5(AGENT_MODEL_CATALOG)),
2376
+ _ts_param4(5, Optional3()),
2377
+ _ts_param4(5, Inject5(AGENT_QUOTA_PROVIDER2)),
2378
+ _ts_param4(6, Optional3()),
2379
+ _ts_param4(6, Inject5(AGENT_OPTIONS4)),
2380
+ _ts_param4(7, Optional3()),
2381
+ _ts_param4(8, Optional3()),
2382
+ _ts_metadata4("design:type", Function),
2383
+ _ts_metadata4("design:paramtypes", [
1803
2384
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
1804
2385
  typeof AgentStore === "undefined" ? Object : AgentStore,
1805
2386
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
@@ -1807,13 +2388,14 @@ AgentService = _ts_decorate3([
1807
2388
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
1808
2389
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1809
2390
  typeof Pick === "undefined" ? Object : Pick,
1810
- typeof ChatQueueService === "undefined" ? Object : ChatQueueService
2391
+ typeof ChatQueueService === "undefined" ? Object : ChatQueueService,
2392
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
1811
2393
  ])
1812
2394
  ], AgentService);
1813
2395
 
1814
2396
  // src/approval-port.adapter.ts
1815
- import { Injectable as Injectable4 } from "@nestjs/common";
1816
- function _ts_decorate4(decorators, target, key, desc) {
2397
+ import { Injectable as Injectable5, NotImplementedException as NotImplementedException4, Optional as Optional4 } from "@nestjs/common";
2398
+ function _ts_decorate6(decorators, target, key, desc) {
1817
2399
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1818
2400
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1819
2401
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1826,20 +2408,48 @@ function _ts_decorate4(decorators, target, key, desc) {
1826
2408
  }
1827
2409
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1828
2410
  }
1829
- __name(_ts_decorate4, "_ts_decorate");
1830
- function _ts_metadata4(metadataKey, metadataValue) {
2411
+ __name(_ts_decorate6, "_ts_decorate");
2412
+ function _ts_metadata5(metadataKey, metadataValue) {
1831
2413
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1832
2414
  return Reflect.metadata(metadataKey, metadataValue);
1833
2415
  }
1834
2416
  }
1835
- __name(_ts_metadata4, "_ts_metadata");
2417
+ __name(_ts_metadata5, "_ts_metadata");
2418
+ function _ts_param5(paramIndex, decorator) {
2419
+ return function(target, key) {
2420
+ decorator(target, key, paramIndex);
2421
+ };
2422
+ }
2423
+ __name(_ts_param5, "_ts_param");
1836
2424
  var AgentApprovalPortAdapter = class {
1837
2425
  static {
1838
2426
  __name(this, "AgentApprovalPortAdapter");
1839
2427
  }
1840
2428
  agent;
1841
- constructor(agent) {
2429
+ proposals;
2430
+ constructor(agent, proposals) {
1842
2431
  this.agent = agent;
2432
+ this.proposals = proposals;
2433
+ }
2434
+ async approveActionProposal(actor, target, opts) {
2435
+ if (!this.proposals) throw new NotImplementedException4("Action proposals unavailable");
2436
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
2437
+ decision: "approved",
2438
+ ...opts?.remember !== void 0 ? {
2439
+ remember: opts.remember
2440
+ } : {},
2441
+ via: opts?.decidedVia ?? "console"
2442
+ });
2443
+ }
2444
+ async rejectActionProposal(actor, target, opts) {
2445
+ if (!this.proposals) throw new NotImplementedException4("Action proposals unavailable");
2446
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
2447
+ decision: "rejected",
2448
+ ...opts?.reason !== void 0 ? {
2449
+ reason: opts.reason
2450
+ } : {},
2451
+ via: opts?.decidedVia ?? "console"
2452
+ });
1843
2453
  }
1844
2454
  async approve(toolCallId2, opts) {
1845
2455
  await this.agent.signalToolCall(toolCallId2, {
@@ -1870,18 +2480,20 @@ var AgentApprovalPortAdapter = class {
1870
2480
  });
1871
2481
  }
1872
2482
  };
1873
- AgentApprovalPortAdapter = _ts_decorate4([
1874
- Injectable4(),
1875
- _ts_metadata4("design:type", Function),
1876
- _ts_metadata4("design:paramtypes", [
1877
- typeof AgentService === "undefined" ? Object : AgentService
2483
+ AgentApprovalPortAdapter = _ts_decorate6([
2484
+ Injectable5(),
2485
+ _ts_param5(1, Optional4()),
2486
+ _ts_metadata5("design:type", Function),
2487
+ _ts_metadata5("design:paramtypes", [
2488
+ typeof AgentService === "undefined" ? Object : AgentService,
2489
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
1878
2490
  ])
1879
2491
  ], AgentApprovalPortAdapter);
1880
2492
 
1881
2493
  // src/controller/agents.controller.ts
1882
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY2, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
1883
- import { Controller, Get, Inject as Inject4 } from "@nestjs/common";
1884
- function _ts_decorate5(decorators, target, key, desc) {
2494
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_REGISTRY as AGENT_REGISTRY2, AgentRegistry as AgentRegistry3 } from "@dudousxd/nestjs-agent-core";
2495
+ import { Controller, Get, Inject as Inject6 } from "@nestjs/common";
2496
+ function _ts_decorate7(decorators, target, key, desc) {
1885
2497
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1886
2498
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1887
2499
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1894,19 +2506,19 @@ function _ts_decorate5(decorators, target, key, desc) {
1894
2506
  }
1895
2507
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1896
2508
  }
1897
- __name(_ts_decorate5, "_ts_decorate");
1898
- function _ts_metadata5(metadataKey, metadataValue) {
2509
+ __name(_ts_decorate7, "_ts_decorate");
2510
+ function _ts_metadata6(metadataKey, metadataValue) {
1899
2511
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1900
2512
  return Reflect.metadata(metadataKey, metadataValue);
1901
2513
  }
1902
2514
  }
1903
- __name(_ts_metadata5, "_ts_metadata");
1904
- function _ts_param4(paramIndex, decorator) {
2515
+ __name(_ts_metadata6, "_ts_metadata");
2516
+ function _ts_param6(paramIndex, decorator) {
1905
2517
  return function(target, key) {
1906
2518
  decorator(target, key, paramIndex);
1907
2519
  };
1908
2520
  }
1909
- __name(_ts_param4, "_ts_param");
2521
+ __name(_ts_param6, "_ts_param");
1910
2522
  var AgentsController = class {
1911
2523
  static {
1912
2524
  __name(this, "AgentsController");
@@ -1919,35 +2531,44 @@ var AgentsController = class {
1919
2531
  }
1920
2532
  list() {
1921
2533
  const defaultAgentName = this.depsFactory.defaultAgentName();
1922
- return this.agents.list().map((definition) => ({
1923
- name: definition.name,
1924
- description: definition.description ?? "",
1925
- ...definition.name === defaultAgentName ? {
1926
- isDefault: true
1927
- } : {}
1928
- }));
2534
+ return this.agents.list().map((definition) => {
2535
+ const personas = this.depsFactory.personaCatalog(definition.name);
2536
+ return {
2537
+ name: definition.name,
2538
+ description: definition.description ?? "",
2539
+ ...definition.name === defaultAgentName ? {
2540
+ isDefault: true
2541
+ } : {},
2542
+ ...personas.length > 0 ? {
2543
+ personas
2544
+ } : {},
2545
+ ...definition.defaultPersona !== void 0 ? {
2546
+ defaultPersona: definition.defaultPersona
2547
+ } : {}
2548
+ };
2549
+ });
1929
2550
  }
1930
2551
  };
1931
- _ts_decorate5([
2552
+ _ts_decorate7([
1932
2553
  Get(),
1933
- _ts_metadata5("design:type", Function),
1934
- _ts_metadata5("design:paramtypes", []),
1935
- _ts_metadata5("design:returntype", Array)
2554
+ _ts_metadata6("design:type", Function),
2555
+ _ts_metadata6("design:paramtypes", []),
2556
+ _ts_metadata6("design:returntype", Array)
1936
2557
  ], AgentsController.prototype, "list", null);
1937
- AgentsController = _ts_decorate5([
2558
+ AgentsController = _ts_decorate7([
1938
2559
  Controller("agents"),
1939
- _ts_param4(0, Inject4(AGENT_REGISTRY2)),
1940
- _ts_param4(1, Inject4(AGENT_DEPS_FACTORY2)),
1941
- _ts_metadata5("design:type", Function),
1942
- _ts_metadata5("design:paramtypes", [
2560
+ _ts_param6(0, Inject6(AGENT_REGISTRY2)),
2561
+ _ts_param6(1, Inject6(AGENT_DEPS_FACTORY3)),
2562
+ _ts_metadata6("design:type", Function),
2563
+ _ts_metadata6("design:paramtypes", [
1943
2564
  typeof AgentRegistry3 === "undefined" ? Object : AgentRegistry3,
1944
2565
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1945
2566
  ])
1946
2567
  ], AgentsController);
1947
2568
 
1948
2569
  // src/controller/attachments.controller.ts
1949
- import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS4 } from "@dudousxd/nestjs-agent-core";
1950
- import { BadRequestException as BadRequestException2, Controller as Controller2, Get as Get2, Inject as Inject5, NotImplementedException as NotImplementedException3, Optional as Optional4, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
2570
+ import { AGENT_ACTOR_RESOLVER, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING3, AGENT_OPTIONS as AGENT_OPTIONS5 } from "@dudousxd/nestjs-agent-core";
2571
+ import { BadRequestException as BadRequestException3, Controller as Controller2, Get as Get2, Inject as Inject7, NotImplementedException as NotImplementedException5, Optional as Optional5, PayloadTooLargeException, Post, Req, UnsupportedMediaTypeException, UploadedFile, UseInterceptors } from "@nestjs/common";
1951
2572
  import { FileInterceptor } from "@nestjs/platform-express";
1952
2573
 
1953
2574
  // src/attachment-limits.ts
@@ -1976,7 +2597,7 @@ function attachmentLimits(options, staging) {
1976
2597
  __name(attachmentLimits, "attachmentLimits");
1977
2598
 
1978
2599
  // src/controller/attachments.controller.ts
1979
- function _ts_decorate6(decorators, target, key, desc) {
2600
+ function _ts_decorate8(decorators, target, key, desc) {
1980
2601
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1981
2602
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1982
2603
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1989,19 +2610,19 @@ function _ts_decorate6(decorators, target, key, desc) {
1989
2610
  }
1990
2611
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1991
2612
  }
1992
- __name(_ts_decorate6, "_ts_decorate");
1993
- function _ts_metadata6(metadataKey, metadataValue) {
2613
+ __name(_ts_decorate8, "_ts_decorate");
2614
+ function _ts_metadata7(metadataKey, metadataValue) {
1994
2615
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1995
2616
  return Reflect.metadata(metadataKey, metadataValue);
1996
2617
  }
1997
2618
  }
1998
- __name(_ts_metadata6, "_ts_metadata");
1999
- function _ts_param5(paramIndex, decorator) {
2619
+ __name(_ts_metadata7, "_ts_metadata");
2620
+ function _ts_param7(paramIndex, decorator) {
2000
2621
  return function(target, key) {
2001
2622
  decorator(target, key, paramIndex);
2002
2623
  };
2003
2624
  }
2004
- __name(_ts_param5, "_ts_param");
2625
+ __name(_ts_param7, "_ts_param");
2005
2626
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
2006
2627
  var ATTACHMENT_PAGE_SIZE = 50;
2007
2628
  var AttachmentsController = class {
@@ -2035,10 +2656,10 @@ var AttachmentsController = class {
2035
2656
  }
2036
2657
  async upload(req, file) {
2037
2658
  if (this.staging === void 0) {
2038
- throw new NotImplementedException3("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2659
+ throw new NotImplementedException5("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
2039
2660
  }
2040
2661
  if (file === void 0) {
2041
- throw new BadRequestException2('multipart field "file" is required');
2662
+ throw new BadRequestException3('multipart field "file" is required');
2042
2663
  }
2043
2664
  const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
2044
2665
  if (!allowedContentTypes.includes(file.mimetype)) {
@@ -2057,39 +2678,39 @@ var AttachmentsController = class {
2057
2678
  });
2058
2679
  }
2059
2680
  };
2060
- _ts_decorate6([
2681
+ _ts_decorate8([
2061
2682
  Get2(),
2062
- _ts_param5(0, Req()),
2063
- _ts_metadata6("design:type", Function),
2064
- _ts_metadata6("design:paramtypes", [
2683
+ _ts_param7(0, Req()),
2684
+ _ts_metadata7("design:type", Function),
2685
+ _ts_metadata7("design:paramtypes", [
2065
2686
  typeof Request === "undefined" ? Object : Request
2066
2687
  ]),
2067
- _ts_metadata6("design:returntype", Promise)
2688
+ _ts_metadata7("design:returntype", Promise)
2068
2689
  ], AttachmentsController.prototype, "list", null);
2069
- _ts_decorate6([
2690
+ _ts_decorate8([
2070
2691
  Post(),
2071
2692
  UseInterceptors(FileInterceptor("file", {
2072
2693
  limits: {
2073
2694
  fileSize: HARD_MAX_ATTACHMENT_BYTES
2074
2695
  }
2075
2696
  })),
2076
- _ts_param5(0, Req()),
2077
- _ts_param5(1, UploadedFile()),
2078
- _ts_metadata6("design:type", Function),
2079
- _ts_metadata6("design:paramtypes", [
2697
+ _ts_param7(0, Req()),
2698
+ _ts_param7(1, UploadedFile()),
2699
+ _ts_metadata7("design:type", Function),
2700
+ _ts_metadata7("design:paramtypes", [
2080
2701
  typeof Request === "undefined" ? Object : Request,
2081
2702
  Object
2082
2703
  ]),
2083
- _ts_metadata6("design:returntype", Promise)
2704
+ _ts_metadata7("design:returntype", Promise)
2084
2705
  ], AttachmentsController.prototype, "upload", null);
2085
- AttachmentsController = _ts_decorate6([
2706
+ AttachmentsController = _ts_decorate8([
2086
2707
  Controller2("attachments"),
2087
- _ts_param5(0, Inject5(AGENT_OPTIONS4)),
2088
- _ts_param5(1, Inject5(AGENT_ACTOR_RESOLVER)),
2089
- _ts_param5(3, Optional4()),
2090
- _ts_param5(3, Inject5(AGENT_ATTACHMENT_STAGING3)),
2091
- _ts_metadata6("design:type", Function),
2092
- _ts_metadata6("design:paramtypes", [
2708
+ _ts_param7(0, Inject7(AGENT_OPTIONS5)),
2709
+ _ts_param7(1, Inject7(AGENT_ACTOR_RESOLVER)),
2710
+ _ts_param7(3, Optional5()),
2711
+ _ts_param7(3, Inject7(AGENT_ATTACHMENT_STAGING3)),
2712
+ _ts_metadata7("design:type", Function),
2713
+ _ts_metadata7("design:paramtypes", [
2093
2714
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2094
2715
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2095
2716
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -2099,8 +2720,9 @@ AttachmentsController = _ts_decorate6([
2099
2720
 
2100
2721
  // src/controller/chat.controller.ts
2101
2722
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER2, AgentStreamError, streamFailure } from "@dudousxd/nestjs-agent-core";
2102
- import { BadRequestException as BadRequestException3, Body, Controller as Controller3, Get as Get3, Inject as Inject6, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
2103
- function _ts_decorate7(decorators, target, key, desc) {
2723
+ import { validateUiCapabilities } from "@dudousxd/nestjs-agent-core/genui";
2724
+ import { BadRequestException as BadRequestException4, Body, Controller as Controller3, Get as Get3, Inject as Inject8, Param, Post as Post2, Query, Req as Req2, Res } from "@nestjs/common";
2725
+ function _ts_decorate9(decorators, target, key, desc) {
2104
2726
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2105
2727
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2106
2728
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2113,19 +2735,19 @@ function _ts_decorate7(decorators, target, key, desc) {
2113
2735
  }
2114
2736
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2115
2737
  }
2116
- __name(_ts_decorate7, "_ts_decorate");
2117
- function _ts_metadata7(metadataKey, metadataValue) {
2738
+ __name(_ts_decorate9, "_ts_decorate");
2739
+ function _ts_metadata8(metadataKey, metadataValue) {
2118
2740
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2119
2741
  return Reflect.metadata(metadataKey, metadataValue);
2120
2742
  }
2121
2743
  }
2122
- __name(_ts_metadata7, "_ts_metadata");
2123
- function _ts_param6(paramIndex, decorator) {
2744
+ __name(_ts_metadata8, "_ts_metadata");
2745
+ function _ts_param8(paramIndex, decorator) {
2124
2746
  return function(target, key) {
2125
2747
  decorator(target, key, paramIndex);
2126
2748
  };
2127
2749
  }
2128
- __name(_ts_param6, "_ts_param");
2750
+ __name(_ts_param8, "_ts_param");
2129
2751
  function sendMode(body) {
2130
2752
  if (body.interrupt === true) {
2131
2753
  return "interrupt";
@@ -2136,7 +2758,7 @@ function sendMode(body) {
2136
2758
  if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
2137
2759
  return body.mode;
2138
2760
  }
2139
- throw new BadRequestException3("mode must be 'auto', 'queue' or 'interrupt'");
2761
+ throw new BadRequestException4("mode must be 'auto', 'queue' or 'interrupt'");
2140
2762
  }
2141
2763
  __name(sendMode, "sendMode");
2142
2764
  function attachmentRefs(claimed) {
@@ -2144,21 +2766,21 @@ function attachmentRefs(claimed) {
2144
2766
  return [];
2145
2767
  }
2146
2768
  if (!Array.isArray(claimed)) {
2147
- throw new BadRequestException3("attachments must be an array of { mediaId }");
2769
+ throw new BadRequestException4("attachments must be an array of { mediaId }");
2148
2770
  }
2149
2771
  if (claimed.length > MAX_ATTACHMENTS_PER_MESSAGE) {
2150
- throw new BadRequestException3(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2772
+ throw new BadRequestException4(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
2151
2773
  }
2152
2774
  return claimed.map((entry) => {
2153
2775
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
2154
- throw new BadRequestException3("each attachment must be an object with a mediaId");
2776
+ throw new BadRequestException4("each attachment must be an object with a mediaId");
2155
2777
  }
2156
2778
  if (Object.keys(entry).some((key) => key !== "mediaId")) {
2157
- throw new BadRequestException3("attachments are { mediaId } refs \u2014 send nothing but the id");
2779
+ throw new BadRequestException4("attachments are { mediaId } refs \u2014 send nothing but the id");
2158
2780
  }
2159
2781
  const { mediaId } = entry;
2160
2782
  if (typeof mediaId !== "string" || mediaId.length === 0) {
2161
- throw new BadRequestException3("each attachment must carry a non-empty string mediaId");
2783
+ throw new BadRequestException4("each attachment must carry a non-empty string mediaId");
2162
2784
  }
2163
2785
  return {
2164
2786
  mediaId
@@ -2186,15 +2808,27 @@ var ChatController = class {
2186
2808
  const actor = await this.actorResolver.resolve(req);
2187
2809
  const attachments = attachmentRefs(body.attachments);
2188
2810
  const mode = sendMode(body);
2811
+ let uiCapabilities;
2812
+ try {
2813
+ uiCapabilities = body.uiCapabilities === void 0 ? void 0 : validateUiCapabilities(body.uiCapabilities);
2814
+ } catch {
2815
+ throw new BadRequestException4("Invalid UI capabilities");
2816
+ }
2189
2817
  const result = await this.agent.send({
2190
2818
  actor,
2191
2819
  message: body.message,
2820
+ ...uiCapabilities !== void 0 ? {
2821
+ uiCapabilities
2822
+ } : {},
2192
2823
  ...body.threadId !== void 0 ? {
2193
2824
  threadId: body.threadId
2194
2825
  } : {},
2195
2826
  ...body.agent !== void 0 ? {
2196
2827
  agentName: body.agent
2197
2828
  } : {},
2829
+ ...typeof body.persona === "string" && body.persona.length > 0 ? {
2830
+ personaId: body.persona
2831
+ } : {},
2198
2832
  ...attachments.length > 0 ? {
2199
2833
  attachments
2200
2834
  } : {},
@@ -2212,6 +2846,10 @@ var ChatController = class {
2212
2846
  } : {},
2213
2847
  mode
2214
2848
  });
2849
+ if ("proposalDecision" in result) {
2850
+ res.status(200).json(result);
2851
+ return;
2852
+ }
2215
2853
  if (result.queued === true) {
2216
2854
  res.status(202).json(result);
2217
2855
  return;
@@ -2303,50 +2941,50 @@ data: ${JSON.stringify(payload)}
2303
2941
  res.end();
2304
2942
  }
2305
2943
  };
2306
- _ts_decorate7([
2944
+ _ts_decorate9([
2307
2945
  Post2("chat"),
2308
- _ts_param6(0, Req2()),
2309
- _ts_param6(1, Res()),
2310
- _ts_param6(2, Body()),
2311
- _ts_metadata7("design:type", Function),
2312
- _ts_metadata7("design:paramtypes", [
2946
+ _ts_param8(0, Req2()),
2947
+ _ts_param8(1, Res()),
2948
+ _ts_param8(2, Body()),
2949
+ _ts_metadata8("design:type", Function),
2950
+ _ts_metadata8("design:paramtypes", [
2313
2951
  typeof Request === "undefined" ? Object : Request,
2314
2952
  typeof Response === "undefined" ? Object : Response,
2315
2953
  typeof ChatBody === "undefined" ? Object : ChatBody
2316
2954
  ]),
2317
- _ts_metadata7("design:returntype", Promise)
2955
+ _ts_metadata8("design:returntype", Promise)
2318
2956
  ], ChatController.prototype, "chat", null);
2319
- _ts_decorate7([
2957
+ _ts_decorate9([
2320
2958
  Get3("chat/:runId/stream"),
2321
- _ts_param6(0, Req2()),
2322
- _ts_param6(1, Param("runId")),
2323
- _ts_param6(2, Res()),
2324
- _ts_param6(3, Query("after")),
2325
- _ts_metadata7("design:type", Function),
2326
- _ts_metadata7("design:paramtypes", [
2959
+ _ts_param8(0, Req2()),
2960
+ _ts_param8(1, Param("runId")),
2961
+ _ts_param8(2, Res()),
2962
+ _ts_param8(3, Query("after")),
2963
+ _ts_metadata8("design:type", Function),
2964
+ _ts_metadata8("design:paramtypes", [
2327
2965
  typeof Request === "undefined" ? Object : Request,
2328
2966
  String,
2329
2967
  typeof Response === "undefined" ? Object : Response,
2330
2968
  String
2331
2969
  ]),
2332
- _ts_metadata7("design:returntype", Promise)
2970
+ _ts_metadata8("design:returntype", Promise)
2333
2971
  ], ChatController.prototype, "stream", null);
2334
- _ts_decorate7([
2972
+ _ts_decorate9([
2335
2973
  Post2("chat/:runId/cancel"),
2336
- _ts_param6(0, Req2()),
2337
- _ts_param6(1, Param("runId")),
2338
- _ts_metadata7("design:type", Function),
2339
- _ts_metadata7("design:paramtypes", [
2974
+ _ts_param8(0, Req2()),
2975
+ _ts_param8(1, Param("runId")),
2976
+ _ts_metadata8("design:type", Function),
2977
+ _ts_metadata8("design:paramtypes", [
2340
2978
  typeof Request === "undefined" ? Object : Request,
2341
2979
  String
2342
2980
  ]),
2343
- _ts_metadata7("design:returntype", Promise)
2981
+ _ts_metadata8("design:returntype", Promise)
2344
2982
  ], ChatController.prototype, "cancel", null);
2345
- ChatController = _ts_decorate7([
2983
+ ChatController = _ts_decorate9([
2346
2984
  Controller3(),
2347
- _ts_param6(1, Inject6(AGENT_ACTOR_RESOLVER2)),
2348
- _ts_metadata7("design:type", Function),
2349
- _ts_metadata7("design:paramtypes", [
2985
+ _ts_param8(1, Inject8(AGENT_ACTOR_RESOLVER2)),
2986
+ _ts_metadata8("design:type", Function),
2987
+ _ts_metadata8("design:paramtypes", [
2350
2988
  typeof AgentService === "undefined" ? Object : AgentService,
2351
2989
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2352
2990
  ])
@@ -2362,8 +3000,8 @@ function parseCursor(raw) {
2362
3000
  __name(parseCursor, "parseCursor");
2363
3001
 
2364
3002
  // src/controller/config.controller.ts
2365
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING4, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS5 } from "@dudousxd/nestjs-agent-core";
2366
- import { Controller as Controller4, Get as Get4, Inject as Inject7, Optional as Optional5, Req as Req3 } from "@nestjs/common";
3003
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER3, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING4, AGENT_MODEL_CATALOG as AGENT_MODEL_CATALOG2, AGENT_OPTIONS as AGENT_OPTIONS6 } from "@dudousxd/nestjs-agent-core";
3004
+ import { Controller as Controller4, Get as Get4, Inject as Inject9, Optional as Optional6, Req as Req3 } from "@nestjs/common";
2367
3005
 
2368
3006
  // src/resolver/anonymous-actor-resolver.ts
2369
3007
  import { createHash, randomBytes } from "crypto";
@@ -2453,7 +3091,7 @@ var AnonymousActorResolver = class {
2453
3091
  };
2454
3092
 
2455
3093
  // src/controller/config.controller.ts
2456
- function _ts_decorate8(decorators, target, key, desc) {
3094
+ function _ts_decorate10(decorators, target, key, desc) {
2457
3095
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2458
3096
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2459
3097
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2466,19 +3104,19 @@ function _ts_decorate8(decorators, target, key, desc) {
2466
3104
  }
2467
3105
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2468
3106
  }
2469
- __name(_ts_decorate8, "_ts_decorate");
2470
- function _ts_metadata8(metadataKey, metadataValue) {
3107
+ __name(_ts_decorate10, "_ts_decorate");
3108
+ function _ts_metadata9(metadataKey, metadataValue) {
2471
3109
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2472
3110
  return Reflect.metadata(metadataKey, metadataValue);
2473
3111
  }
2474
3112
  }
2475
- __name(_ts_metadata8, "_ts_metadata");
2476
- function _ts_param7(paramIndex, decorator) {
3113
+ __name(_ts_metadata9, "_ts_metadata");
3114
+ function _ts_param9(paramIndex, decorator) {
2477
3115
  return function(target, key) {
2478
3116
  decorator(target, key, paramIndex);
2479
3117
  };
2480
3118
  }
2481
- __name(_ts_param7, "_ts_param");
3119
+ __name(_ts_param9, "_ts_param");
2482
3120
  var ConfigController = class {
2483
3121
  static {
2484
3122
  __name(this, "ConfigController");
@@ -2509,25 +3147,25 @@ var ConfigController = class {
2509
3147
  };
2510
3148
  }
2511
3149
  };
2512
- _ts_decorate8([
3150
+ _ts_decorate10([
2513
3151
  Get4(),
2514
- _ts_param7(0, Req3()),
2515
- _ts_metadata8("design:type", Function),
2516
- _ts_metadata8("design:paramtypes", [
3152
+ _ts_param9(0, Req3()),
3153
+ _ts_metadata9("design:type", Function),
3154
+ _ts_metadata9("design:paramtypes", [
2517
3155
  typeof Request === "undefined" ? Object : Request
2518
3156
  ]),
2519
- _ts_metadata8("design:returntype", Promise)
3157
+ _ts_metadata9("design:returntype", Promise)
2520
3158
  ], ConfigController.prototype, "config", null);
2521
- ConfigController = _ts_decorate8([
3159
+ ConfigController = _ts_decorate10([
2522
3160
  Controller4("config"),
2523
- _ts_param7(0, Inject7(AGENT_OPTIONS5)),
2524
- _ts_param7(1, Inject7(AGENT_ACTOR_RESOLVER3)),
2525
- _ts_param7(2, Optional5()),
2526
- _ts_param7(2, Inject7(AGENT_ATTACHMENT_STAGING4)),
2527
- _ts_param7(3, Optional5()),
2528
- _ts_param7(3, Inject7(AGENT_MODEL_CATALOG2)),
2529
- _ts_metadata8("design:type", Function),
2530
- _ts_metadata8("design:paramtypes", [
3161
+ _ts_param9(0, Inject9(AGENT_OPTIONS6)),
3162
+ _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER3)),
3163
+ _ts_param9(2, Optional6()),
3164
+ _ts_param9(2, Inject9(AGENT_ATTACHMENT_STAGING4)),
3165
+ _ts_param9(3, Optional6()),
3166
+ _ts_param9(3, Inject9(AGENT_MODEL_CATALOG2)),
3167
+ _ts_metadata9("design:type", Function),
3168
+ _ts_metadata9("design:paramtypes", [
2531
3169
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
2532
3170
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2533
3171
  Object,
@@ -2537,8 +3175,8 @@ ConfigController = _ts_decorate8([
2537
3175
 
2538
3176
  // src/controller/memories.controller.ts
2539
3177
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER4, AGENT_MEMORY as AGENT_MEMORY2, memoryForgetVerdict, offerMemories } from "@dudousxd/nestjs-agent-core";
2540
- import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException2, Get as Get5, Inject as Inject8, NotFoundException as NotFoundException2, Optional as Optional6, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
2541
- function _ts_decorate9(decorators, target, key, desc) {
3178
+ import { Controller as Controller5, Delete, ForbiddenException as ForbiddenException3, Get as Get5, Inject as Inject10, NotFoundException as NotFoundException3, Optional as Optional7, Param as Param2, Query as Query2, Req as Req4 } from "@nestjs/common";
3179
+ function _ts_decorate11(decorators, target, key, desc) {
2542
3180
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2543
3181
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2544
3182
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2551,19 +3189,19 @@ function _ts_decorate9(decorators, target, key, desc) {
2551
3189
  }
2552
3190
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2553
3191
  }
2554
- __name(_ts_decorate9, "_ts_decorate");
2555
- function _ts_metadata9(metadataKey, metadataValue) {
3192
+ __name(_ts_decorate11, "_ts_decorate");
3193
+ function _ts_metadata10(metadataKey, metadataValue) {
2556
3194
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2557
3195
  return Reflect.metadata(metadataKey, metadataValue);
2558
3196
  }
2559
3197
  }
2560
- __name(_ts_metadata9, "_ts_metadata");
2561
- function _ts_param8(paramIndex, decorator) {
3198
+ __name(_ts_metadata10, "_ts_metadata");
3199
+ function _ts_param10(paramIndex, decorator) {
2562
3200
  return function(target, key) {
2563
3201
  decorator(target, key, paramIndex);
2564
3202
  };
2565
3203
  }
2566
- __name(_ts_param8, "_ts_param");
3204
+ __name(_ts_param10, "_ts_param");
2567
3205
  var MemoriesController = class {
2568
3206
  static {
2569
3207
  __name(this, "MemoriesController");
@@ -2597,20 +3235,20 @@ var MemoriesController = class {
2597
3235
  */
2598
3236
  async forget(req, id) {
2599
3237
  if (this.memory === void 0) {
2600
- throw new NotFoundException2("No memory is configured in this deployment.");
3238
+ throw new NotFoundException3("No memory is configured in this deployment.");
2601
3239
  }
2602
3240
  const actor = await this.actorResolver.resolve(req);
2603
3241
  const digest = await this.unbounded("", actor);
2604
3242
  const entry = digest.entries.find((candidate) => candidate.id === id);
2605
3243
  if (entry === void 0) {
2606
- throw new NotFoundException2(`No memory with id "${id}".`);
3244
+ throw new NotFoundException3(`No memory with id "${id}".`);
2607
3245
  }
2608
3246
  const verdict = memoryForgetVerdict({
2609
3247
  record: entry,
2610
3248
  actor
2611
3249
  });
2612
3250
  if (!verdict.allowed) {
2613
- throw new ForbiddenException2(verdict.reason);
3251
+ throw new ForbiddenException3(verdict.reason);
2614
3252
  }
2615
3253
  return {
2616
3254
  forgotten: await this.memory.provider.forget({
@@ -2636,35 +3274,35 @@ var MemoriesController = class {
2636
3274
  });
2637
3275
  }
2638
3276
  };
2639
- _ts_decorate9([
3277
+ _ts_decorate11([
2640
3278
  Get5(),
2641
- _ts_param8(0, Req4()),
2642
- _ts_param8(1, Query2("threadId")),
2643
- _ts_metadata9("design:type", Function),
2644
- _ts_metadata9("design:paramtypes", [
3279
+ _ts_param10(0, Req4()),
3280
+ _ts_param10(1, Query2("threadId")),
3281
+ _ts_metadata10("design:type", Function),
3282
+ _ts_metadata10("design:paramtypes", [
2645
3283
  typeof Request === "undefined" ? Object : Request,
2646
3284
  String
2647
3285
  ]),
2648
- _ts_metadata9("design:returntype", Promise)
3286
+ _ts_metadata10("design:returntype", Promise)
2649
3287
  ], MemoriesController.prototype, "list", null);
2650
- _ts_decorate9([
3288
+ _ts_decorate11([
2651
3289
  Delete(":id"),
2652
- _ts_param8(0, Req4()),
2653
- _ts_param8(1, Param2("id")),
2654
- _ts_metadata9("design:type", Function),
2655
- _ts_metadata9("design:paramtypes", [
3290
+ _ts_param10(0, Req4()),
3291
+ _ts_param10(1, Param2("id")),
3292
+ _ts_metadata10("design:type", Function),
3293
+ _ts_metadata10("design:paramtypes", [
2656
3294
  typeof Request === "undefined" ? Object : Request,
2657
3295
  String
2658
3296
  ]),
2659
- _ts_metadata9("design:returntype", Promise)
3297
+ _ts_metadata10("design:returntype", Promise)
2660
3298
  ], MemoriesController.prototype, "forget", null);
2661
- MemoriesController = _ts_decorate9([
3299
+ MemoriesController = _ts_decorate11([
2662
3300
  Controller5("memories"),
2663
- _ts_param8(0, Inject8(AGENT_ACTOR_RESOLVER4)),
2664
- _ts_param8(1, Optional6()),
2665
- _ts_param8(1, Inject8(AGENT_MEMORY2)),
2666
- _ts_metadata9("design:type", Function),
2667
- _ts_metadata9("design:paramtypes", [
3301
+ _ts_param10(0, Inject10(AGENT_ACTOR_RESOLVER4)),
3302
+ _ts_param10(1, Optional7()),
3303
+ _ts_param10(1, Inject10(AGENT_MEMORY2)),
3304
+ _ts_metadata10("design:type", Function),
3305
+ _ts_metadata10("design:paramtypes", [
2668
3306
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
2669
3307
  Object
2670
3308
  ])
@@ -2672,8 +3310,8 @@ MemoriesController = _ts_decorate9([
2672
3310
 
2673
3311
  // src/controller/messages.controller.ts
2674
3312
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER5 } from "@dudousxd/nestjs-agent-core";
2675
- import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject9, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
2676
- function _ts_decorate10(decorators, target, key, desc) {
3313
+ import { Body as Body2, Controller as Controller6, HttpCode, Inject as Inject11, Param as Param3, Post as Post3, Req as Req5 } from "@nestjs/common";
3314
+ function _ts_decorate12(decorators, target, key, desc) {
2677
3315
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2678
3316
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2679
3317
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2686,19 +3324,19 @@ function _ts_decorate10(decorators, target, key, desc) {
2686
3324
  }
2687
3325
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2688
3326
  }
2689
- __name(_ts_decorate10, "_ts_decorate");
2690
- function _ts_metadata10(metadataKey, metadataValue) {
3327
+ __name(_ts_decorate12, "_ts_decorate");
3328
+ function _ts_metadata11(metadataKey, metadataValue) {
2691
3329
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2692
3330
  return Reflect.metadata(metadataKey, metadataValue);
2693
3331
  }
2694
3332
  }
2695
- __name(_ts_metadata10, "_ts_metadata");
2696
- function _ts_param9(paramIndex, decorator) {
3333
+ __name(_ts_metadata11, "_ts_metadata");
3334
+ function _ts_param11(paramIndex, decorator) {
2697
3335
  return function(target, key) {
2698
3336
  decorator(target, key, paramIndex);
2699
3337
  };
2700
3338
  }
2701
- __name(_ts_param9, "_ts_param");
3339
+ __name(_ts_param11, "_ts_param");
2702
3340
  var MessagesController = class {
2703
3341
  static {
2704
3342
  __name(this, "MessagesController");
@@ -2726,25 +3364,25 @@ var MessagesController = class {
2726
3364
  };
2727
3365
  }
2728
3366
  };
2729
- _ts_decorate10([
3367
+ _ts_decorate12([
2730
3368
  Post3(":id/feedback"),
2731
3369
  HttpCode(200),
2732
- _ts_param9(0, Req5()),
2733
- _ts_param9(1, Param3("id")),
2734
- _ts_param9(2, Body2()),
2735
- _ts_metadata10("design:type", Function),
2736
- _ts_metadata10("design:paramtypes", [
3370
+ _ts_param11(0, Req5()),
3371
+ _ts_param11(1, Param3("id")),
3372
+ _ts_param11(2, Body2()),
3373
+ _ts_metadata11("design:type", Function),
3374
+ _ts_metadata11("design:paramtypes", [
2737
3375
  typeof Request === "undefined" ? Object : Request,
2738
3376
  String,
2739
3377
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
2740
3378
  ]),
2741
- _ts_metadata10("design:returntype", Promise)
3379
+ _ts_metadata11("design:returntype", Promise)
2742
3380
  ], MessagesController.prototype, "feedback", null);
2743
- MessagesController = _ts_decorate10([
3381
+ MessagesController = _ts_decorate12([
2744
3382
  Controller6("messages"),
2745
- _ts_param9(1, Inject9(AGENT_ACTOR_RESOLVER5)),
2746
- _ts_metadata10("design:type", Function),
2747
- _ts_metadata10("design:paramtypes", [
3383
+ _ts_param11(1, Inject11(AGENT_ACTOR_RESOLVER5)),
3384
+ _ts_metadata11("design:type", Function),
3385
+ _ts_metadata11("design:paramtypes", [
2748
3386
  typeof AgentService === "undefined" ? Object : AgentService,
2749
3387
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2750
3388
  ])
@@ -2752,8 +3390,8 @@ MessagesController = _ts_decorate10([
2752
3390
 
2753
3391
  // src/controller/models.controller.ts
2754
3392
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER6 } from "@dudousxd/nestjs-agent-core";
2755
- import { Controller as Controller7, Get as Get6, Inject as Inject10, Query as Query3, Req as Req6 } from "@nestjs/common";
2756
- function _ts_decorate11(decorators, target, key, desc) {
3393
+ import { Controller as Controller7, Get as Get6, Inject as Inject12, Query as Query3, Req as Req6 } from "@nestjs/common";
3394
+ function _ts_decorate13(decorators, target, key, desc) {
2757
3395
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2758
3396
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2759
3397
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2766,19 +3404,19 @@ function _ts_decorate11(decorators, target, key, desc) {
2766
3404
  }
2767
3405
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2768
3406
  }
2769
- __name(_ts_decorate11, "_ts_decorate");
2770
- function _ts_metadata11(metadataKey, metadataValue) {
3407
+ __name(_ts_decorate13, "_ts_decorate");
3408
+ function _ts_metadata12(metadataKey, metadataValue) {
2771
3409
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2772
3410
  return Reflect.metadata(metadataKey, metadataValue);
2773
3411
  }
2774
3412
  }
2775
- __name(_ts_metadata11, "_ts_metadata");
2776
- function _ts_param10(paramIndex, decorator) {
3413
+ __name(_ts_metadata12, "_ts_metadata");
3414
+ function _ts_param12(paramIndex, decorator) {
2777
3415
  return function(target, key) {
2778
3416
  decorator(target, key, paramIndex);
2779
3417
  };
2780
3418
  }
2781
- __name(_ts_param10, "_ts_param");
3419
+ __name(_ts_param12, "_ts_param");
2782
3420
  var ModelsController = class {
2783
3421
  static {
2784
3422
  __name(this, "ModelsController");
@@ -2798,22 +3436,22 @@ var ModelsController = class {
2798
3436
  return this.agent.listModels(actor, agent);
2799
3437
  }
2800
3438
  };
2801
- _ts_decorate11([
3439
+ _ts_decorate13([
2802
3440
  Get6(),
2803
- _ts_param10(0, Req6()),
2804
- _ts_param10(1, Query3("agent")),
2805
- _ts_metadata11("design:type", Function),
2806
- _ts_metadata11("design:paramtypes", [
3441
+ _ts_param12(0, Req6()),
3442
+ _ts_param12(1, Query3("agent")),
3443
+ _ts_metadata12("design:type", Function),
3444
+ _ts_metadata12("design:paramtypes", [
2807
3445
  typeof Request === "undefined" ? Object : Request,
2808
3446
  String
2809
3447
  ]),
2810
- _ts_metadata11("design:returntype", Promise)
3448
+ _ts_metadata12("design:returntype", Promise)
2811
3449
  ], ModelsController.prototype, "list", null);
2812
- ModelsController = _ts_decorate11([
3450
+ ModelsController = _ts_decorate13([
2813
3451
  Controller7("models"),
2814
- _ts_param10(1, Inject10(AGENT_ACTOR_RESOLVER6)),
2815
- _ts_metadata11("design:type", Function),
2816
- _ts_metadata11("design:paramtypes", [
3452
+ _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER6)),
3453
+ _ts_metadata12("design:type", Function),
3454
+ _ts_metadata12("design:paramtypes", [
2817
3455
  typeof AgentService === "undefined" ? Object : AgentService,
2818
3456
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2819
3457
  ])
@@ -2821,8 +3459,8 @@ ModelsController = _ts_decorate11([
2821
3459
 
2822
3460
  // src/controller/queue.controller.ts
2823
3461
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER7 } from "@dudousxd/nestjs-agent-core";
2824
- import { BadRequestException as BadRequestException4, Body as Body3, Controller as Controller8, Delete as Delete2, Get as Get7, Inject as Inject11, Param as Param4, Patch, Post as Post4, Req as Req7 } from "@nestjs/common";
2825
- function _ts_decorate12(decorators, target, key, desc) {
3462
+ import { BadRequestException as BadRequestException5, Body as Body3, Controller as Controller8, Delete as Delete2, Get as Get7, Inject as Inject13, Param as Param4, Patch, Post as Post4, Req as Req7 } from "@nestjs/common";
3463
+ function _ts_decorate14(decorators, target, key, desc) {
2826
3464
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2827
3465
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2828
3466
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2835,19 +3473,19 @@ function _ts_decorate12(decorators, target, key, desc) {
2835
3473
  }
2836
3474
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2837
3475
  }
2838
- __name(_ts_decorate12, "_ts_decorate");
2839
- function _ts_metadata12(metadataKey, metadataValue) {
3476
+ __name(_ts_decorate14, "_ts_decorate");
3477
+ function _ts_metadata13(metadataKey, metadataValue) {
2840
3478
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2841
3479
  return Reflect.metadata(metadataKey, metadataValue);
2842
3480
  }
2843
3481
  }
2844
- __name(_ts_metadata12, "_ts_metadata");
2845
- function _ts_param11(paramIndex, decorator) {
3482
+ __name(_ts_metadata13, "_ts_metadata");
3483
+ function _ts_param13(paramIndex, decorator) {
2846
3484
  return function(target, key) {
2847
3485
  decorator(target, key, paramIndex);
2848
3486
  };
2849
3487
  }
2850
- __name(_ts_param11, "_ts_param");
3488
+ __name(_ts_param13, "_ts_param");
2851
3489
  var QueueController = class {
2852
3490
  static {
2853
3491
  __name(this, "QueueController");
@@ -2871,10 +3509,10 @@ var QueueController = class {
2871
3509
  async update(req, messageId, body) {
2872
3510
  const actor = await this.actorResolver.resolve(req);
2873
3511
  if (body.message !== void 0 && typeof body.message !== "string") {
2874
- throw new BadRequestException4("message must be a string");
3512
+ throw new BadRequestException5("message must be a string");
2875
3513
  }
2876
3514
  if (body.position !== void 0 && typeof body.position !== "number") {
2877
- throw new BadRequestException4("position must be a number");
3515
+ throw new BadRequestException5("position must be a number");
2878
3516
  }
2879
3517
  const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
2880
3518
  return this.agent.updateQueuedMessage(actor, messageId, {
@@ -2901,79 +3539,79 @@ var QueueController = class {
2901
3539
  return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
2902
3540
  }
2903
3541
  };
2904
- _ts_decorate12([
3542
+ _ts_decorate14([
2905
3543
  Get7("threads/:id/queue"),
2906
- _ts_param11(0, Req7()),
2907
- _ts_param11(1, Param4("id")),
2908
- _ts_metadata12("design:type", Function),
2909
- _ts_metadata12("design:paramtypes", [
3544
+ _ts_param13(0, Req7()),
3545
+ _ts_param13(1, Param4("id")),
3546
+ _ts_metadata13("design:type", Function),
3547
+ _ts_metadata13("design:paramtypes", [
2910
3548
  typeof Request === "undefined" ? Object : Request,
2911
3549
  String
2912
3550
  ]),
2913
- _ts_metadata12("design:returntype", Promise)
3551
+ _ts_metadata13("design:returntype", Promise)
2914
3552
  ], QueueController.prototype, "list", null);
2915
- _ts_decorate12([
3553
+ _ts_decorate14([
2916
3554
  Delete2("threads/:id/queue"),
2917
- _ts_param11(0, Req7()),
2918
- _ts_param11(1, Param4("id")),
2919
- _ts_metadata12("design:type", Function),
2920
- _ts_metadata12("design:paramtypes", [
3555
+ _ts_param13(0, Req7()),
3556
+ _ts_param13(1, Param4("id")),
3557
+ _ts_metadata13("design:type", Function),
3558
+ _ts_metadata13("design:paramtypes", [
2921
3559
  typeof Request === "undefined" ? Object : Request,
2922
3560
  String
2923
3561
  ]),
2924
- _ts_metadata12("design:returntype", Promise)
3562
+ _ts_metadata13("design:returntype", Promise)
2925
3563
  ], QueueController.prototype, "clear", null);
2926
- _ts_decorate12([
3564
+ _ts_decorate14([
2927
3565
  Post4("threads/:id/queue/resume"),
2928
- _ts_param11(0, Req7()),
2929
- _ts_param11(1, Param4("id")),
2930
- _ts_metadata12("design:type", Function),
2931
- _ts_metadata12("design:paramtypes", [
3566
+ _ts_param13(0, Req7()),
3567
+ _ts_param13(1, Param4("id")),
3568
+ _ts_metadata13("design:type", Function),
3569
+ _ts_metadata13("design:paramtypes", [
2932
3570
  typeof Request === "undefined" ? Object : Request,
2933
3571
  String
2934
3572
  ]),
2935
- _ts_metadata12("design:returntype", Promise)
3573
+ _ts_metadata13("design:returntype", Promise)
2936
3574
  ], QueueController.prototype, "resume", null);
2937
- _ts_decorate12([
3575
+ _ts_decorate14([
2938
3576
  Patch("queue/:messageId"),
2939
- _ts_param11(0, Req7()),
2940
- _ts_param11(1, Param4("messageId")),
2941
- _ts_param11(2, Body3()),
2942
- _ts_metadata12("design:type", Function),
2943
- _ts_metadata12("design:paramtypes", [
3577
+ _ts_param13(0, Req7()),
3578
+ _ts_param13(1, Param4("messageId")),
3579
+ _ts_param13(2, Body3()),
3580
+ _ts_metadata13("design:type", Function),
3581
+ _ts_metadata13("design:paramtypes", [
2944
3582
  typeof Request === "undefined" ? Object : Request,
2945
3583
  String,
2946
3584
  typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
2947
3585
  ]),
2948
- _ts_metadata12("design:returntype", Promise)
3586
+ _ts_metadata13("design:returntype", Promise)
2949
3587
  ], QueueController.prototype, "update", null);
2950
- _ts_decorate12([
3588
+ _ts_decorate14([
2951
3589
  Post4("queue/:messageId/interrupt"),
2952
- _ts_param11(0, Req7()),
2953
- _ts_param11(1, Param4("messageId")),
2954
- _ts_metadata12("design:type", Function),
2955
- _ts_metadata12("design:paramtypes", [
3590
+ _ts_param13(0, Req7()),
3591
+ _ts_param13(1, Param4("messageId")),
3592
+ _ts_metadata13("design:type", Function),
3593
+ _ts_metadata13("design:paramtypes", [
2956
3594
  typeof Request === "undefined" ? Object : Request,
2957
3595
  String
2958
3596
  ]),
2959
- _ts_metadata12("design:returntype", Promise)
3597
+ _ts_metadata13("design:returntype", Promise)
2960
3598
  ], QueueController.prototype, "interrupt", null);
2961
- _ts_decorate12([
3599
+ _ts_decorate14([
2962
3600
  Delete2("queue/:messageId"),
2963
- _ts_param11(0, Req7()),
2964
- _ts_param11(1, Param4("messageId")),
2965
- _ts_metadata12("design:type", Function),
2966
- _ts_metadata12("design:paramtypes", [
3601
+ _ts_param13(0, Req7()),
3602
+ _ts_param13(1, Param4("messageId")),
3603
+ _ts_metadata13("design:type", Function),
3604
+ _ts_metadata13("design:paramtypes", [
2967
3605
  typeof Request === "undefined" ? Object : Request,
2968
3606
  String
2969
3607
  ]),
2970
- _ts_metadata12("design:returntype", Promise)
3608
+ _ts_metadata13("design:returntype", Promise)
2971
3609
  ], QueueController.prototype, "remove", null);
2972
- QueueController = _ts_decorate12([
3610
+ QueueController = _ts_decorate14([
2973
3611
  Controller8(),
2974
- _ts_param11(1, Inject11(AGENT_ACTOR_RESOLVER7)),
2975
- _ts_metadata12("design:type", Function),
2976
- _ts_metadata12("design:paramtypes", [
3612
+ _ts_param13(1, Inject13(AGENT_ACTOR_RESOLVER7)),
3613
+ _ts_metadata13("design:type", Function),
3614
+ _ts_metadata13("design:paramtypes", [
2977
3615
  typeof AgentService === "undefined" ? Object : AgentService,
2978
3616
  typeof ActorResolver === "undefined" ? Object : ActorResolver
2979
3617
  ])
@@ -2981,8 +3619,8 @@ QueueController = _ts_decorate12([
2981
3619
 
2982
3620
  // src/controller/quota.controller.ts
2983
3621
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER8 } from "@dudousxd/nestjs-agent-core";
2984
- import { Controller as Controller9, Get as Get8, Inject as Inject12, Req as Req8 } from "@nestjs/common";
2985
- function _ts_decorate13(decorators, target, key, desc) {
3622
+ import { Controller as Controller9, Get as Get8, Inject as Inject14, Req as Req8 } from "@nestjs/common";
3623
+ function _ts_decorate15(decorators, target, key, desc) {
2986
3624
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2987
3625
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2988
3626
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2995,19 +3633,19 @@ function _ts_decorate13(decorators, target, key, desc) {
2995
3633
  }
2996
3634
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2997
3635
  }
2998
- __name(_ts_decorate13, "_ts_decorate");
2999
- function _ts_metadata13(metadataKey, metadataValue) {
3636
+ __name(_ts_decorate15, "_ts_decorate");
3637
+ function _ts_metadata14(metadataKey, metadataValue) {
3000
3638
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3001
3639
  return Reflect.metadata(metadataKey, metadataValue);
3002
3640
  }
3003
3641
  }
3004
- __name(_ts_metadata13, "_ts_metadata");
3005
- function _ts_param12(paramIndex, decorator) {
3642
+ __name(_ts_metadata14, "_ts_metadata");
3643
+ function _ts_param14(paramIndex, decorator) {
3006
3644
  return function(target, key) {
3007
3645
  decorator(target, key, paramIndex);
3008
3646
  };
3009
3647
  }
3010
- __name(_ts_param12, "_ts_param");
3648
+ __name(_ts_param14, "_ts_param");
3011
3649
  var QuotaController = class {
3012
3650
  static {
3013
3651
  __name(this, "QuotaController");
@@ -3027,20 +3665,20 @@ var QuotaController = class {
3027
3665
  return this.agent.quotaReport(actor);
3028
3666
  }
3029
3667
  };
3030
- _ts_decorate13([
3668
+ _ts_decorate15([
3031
3669
  Get8(),
3032
- _ts_param12(0, Req8()),
3033
- _ts_metadata13("design:type", Function),
3034
- _ts_metadata13("design:paramtypes", [
3670
+ _ts_param14(0, Req8()),
3671
+ _ts_metadata14("design:type", Function),
3672
+ _ts_metadata14("design:paramtypes", [
3035
3673
  typeof Request === "undefined" ? Object : Request
3036
3674
  ]),
3037
- _ts_metadata13("design:returntype", Promise)
3675
+ _ts_metadata14("design:returntype", Promise)
3038
3676
  ], QuotaController.prototype, "report", null);
3039
- QuotaController = _ts_decorate13([
3677
+ QuotaController = _ts_decorate15([
3040
3678
  Controller9("quota"),
3041
- _ts_param12(1, Inject12(AGENT_ACTOR_RESOLVER8)),
3042
- _ts_metadata13("design:type", Function),
3043
- _ts_metadata13("design:paramtypes", [
3679
+ _ts_param14(1, Inject14(AGENT_ACTOR_RESOLVER8)),
3680
+ _ts_metadata14("design:type", Function),
3681
+ _ts_metadata14("design:paramtypes", [
3044
3682
  typeof AgentService === "undefined" ? Object : AgentService,
3045
3683
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3046
3684
  ])
@@ -3048,8 +3686,8 @@ QuotaController = _ts_decorate13([
3048
3686
 
3049
3687
  // src/controller/skills.controller.ts
3050
3688
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER9, AGENT_SKILLS as AGENT_SKILLS2, offerSkills } from "@dudousxd/nestjs-agent-core";
3051
- import { Controller as Controller10, Get as Get9, Inject as Inject13, Optional as Optional7, Query as Query4, Req as Req9 } from "@nestjs/common";
3052
- function _ts_decorate14(decorators, target, key, desc) {
3689
+ import { Controller as Controller10, Get as Get9, Inject as Inject15, Optional as Optional8, Query as Query4, Req as Req9 } from "@nestjs/common";
3690
+ function _ts_decorate16(decorators, target, key, desc) {
3053
3691
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3054
3692
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3055
3693
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3062,19 +3700,19 @@ function _ts_decorate14(decorators, target, key, desc) {
3062
3700
  }
3063
3701
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3064
3702
  }
3065
- __name(_ts_decorate14, "_ts_decorate");
3066
- function _ts_metadata14(metadataKey, metadataValue) {
3703
+ __name(_ts_decorate16, "_ts_decorate");
3704
+ function _ts_metadata15(metadataKey, metadataValue) {
3067
3705
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3068
3706
  return Reflect.metadata(metadataKey, metadataValue);
3069
3707
  }
3070
3708
  }
3071
- __name(_ts_metadata14, "_ts_metadata");
3072
- function _ts_param13(paramIndex, decorator) {
3709
+ __name(_ts_metadata15, "_ts_metadata");
3710
+ function _ts_param15(paramIndex, decorator) {
3073
3711
  return function(target, key) {
3074
3712
  decorator(target, key, paramIndex);
3075
3713
  };
3076
3714
  }
3077
- __name(_ts_param13, "_ts_param");
3715
+ __name(_ts_param15, "_ts_param");
3078
3716
  var SkillsController = class {
3079
3717
  static {
3080
3718
  __name(this, "SkillsController");
@@ -3097,24 +3735,24 @@ var SkillsController = class {
3097
3735
  return offer.entries;
3098
3736
  }
3099
3737
  };
3100
- _ts_decorate14([
3738
+ _ts_decorate16([
3101
3739
  Get9(),
3102
- _ts_param13(0, Req9()),
3103
- _ts_param13(1, Query4("threadId")),
3104
- _ts_metadata14("design:type", Function),
3105
- _ts_metadata14("design:paramtypes", [
3740
+ _ts_param15(0, Req9()),
3741
+ _ts_param15(1, Query4("threadId")),
3742
+ _ts_metadata15("design:type", Function),
3743
+ _ts_metadata15("design:paramtypes", [
3106
3744
  typeof Request === "undefined" ? Object : Request,
3107
3745
  String
3108
3746
  ]),
3109
- _ts_metadata14("design:returntype", Promise)
3747
+ _ts_metadata15("design:returntype", Promise)
3110
3748
  ], SkillsController.prototype, "list", null);
3111
- SkillsController = _ts_decorate14([
3749
+ SkillsController = _ts_decorate16([
3112
3750
  Controller10("skills"),
3113
- _ts_param13(0, Inject13(AGENT_ACTOR_RESOLVER9)),
3114
- _ts_param13(1, Optional7()),
3115
- _ts_param13(1, Inject13(AGENT_SKILLS2)),
3116
- _ts_metadata14("design:type", Function),
3117
- _ts_metadata14("design:paramtypes", [
3751
+ _ts_param15(0, Inject15(AGENT_ACTOR_RESOLVER9)),
3752
+ _ts_param15(1, Optional8()),
3753
+ _ts_param15(1, Inject15(AGENT_SKILLS2)),
3754
+ _ts_metadata15("design:type", Function),
3755
+ _ts_metadata15("design:paramtypes", [
3118
3756
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3119
3757
  Object
3120
3758
  ])
@@ -3122,8 +3760,8 @@ SkillsController = _ts_decorate14([
3122
3760
 
3123
3761
  // src/controller/threads.controller.ts
3124
3762
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER10 } from "@dudousxd/nestjs-agent-core";
3125
- import { Body as Body4, Controller as Controller11, Delete as Delete3, Get as Get10, Inject as Inject14, Param as Param5, Patch as Patch2, Post as Post5, Req as Req10 } from "@nestjs/common";
3126
- function _ts_decorate15(decorators, target, key, desc) {
3763
+ import { Body as Body4, Controller as Controller11, Delete as Delete3, Get as Get10, Inject as Inject16, Param as Param5, Patch as Patch2, Post as Post5, Req as Req10 } from "@nestjs/common";
3764
+ function _ts_decorate17(decorators, target, key, desc) {
3127
3765
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3128
3766
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3129
3767
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3136,19 +3774,19 @@ function _ts_decorate15(decorators, target, key, desc) {
3136
3774
  }
3137
3775
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3138
3776
  }
3139
- __name(_ts_decorate15, "_ts_decorate");
3140
- function _ts_metadata15(metadataKey, metadataValue) {
3777
+ __name(_ts_decorate17, "_ts_decorate");
3778
+ function _ts_metadata16(metadataKey, metadataValue) {
3141
3779
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3142
3780
  return Reflect.metadata(metadataKey, metadataValue);
3143
3781
  }
3144
3782
  }
3145
- __name(_ts_metadata15, "_ts_metadata");
3146
- function _ts_param14(paramIndex, decorator) {
3783
+ __name(_ts_metadata16, "_ts_metadata");
3784
+ function _ts_param16(paramIndex, decorator) {
3147
3785
  return function(target, key) {
3148
3786
  decorator(target, key, paramIndex);
3149
3787
  };
3150
3788
  }
3151
- __name(_ts_param14, "_ts_param");
3789
+ __name(_ts_param16, "_ts_param");
3152
3790
  var ThreadsController = class {
3153
3791
  static {
3154
3792
  __name(this, "ThreadsController");
@@ -3194,6 +3832,9 @@ var ThreadsController = class {
3194
3832
  } : {},
3195
3833
  ..."model" in body ? {
3196
3834
  model: body.model ?? null
3835
+ } : {},
3836
+ ..."persona" in body ? {
3837
+ persona: body.persona ?? null
3197
3838
  } : {}
3198
3839
  });
3199
3840
  return {
@@ -3215,92 +3856,92 @@ var ThreadsController = class {
3215
3856
  };
3216
3857
  }
3217
3858
  };
3218
- _ts_decorate15([
3859
+ _ts_decorate17([
3219
3860
  Get10(),
3220
- _ts_param14(0, Req10()),
3221
- _ts_metadata15("design:type", Function),
3222
- _ts_metadata15("design:paramtypes", [
3861
+ _ts_param16(0, Req10()),
3862
+ _ts_metadata16("design:type", Function),
3863
+ _ts_metadata16("design:paramtypes", [
3223
3864
  typeof Request === "undefined" ? Object : Request
3224
3865
  ]),
3225
- _ts_metadata15("design:returntype", Promise)
3866
+ _ts_metadata16("design:returntype", Promise)
3226
3867
  ], ThreadsController.prototype, "list", null);
3227
- _ts_decorate15([
3868
+ _ts_decorate17([
3228
3869
  Get10(":id"),
3229
- _ts_param14(0, Req10()),
3230
- _ts_param14(1, Param5("id")),
3231
- _ts_metadata15("design:type", Function),
3232
- _ts_metadata15("design:paramtypes", [
3870
+ _ts_param16(0, Req10()),
3871
+ _ts_param16(1, Param5("id")),
3872
+ _ts_metadata16("design:type", Function),
3873
+ _ts_metadata16("design:paramtypes", [
3233
3874
  typeof Request === "undefined" ? Object : Request,
3234
3875
  String
3235
3876
  ]),
3236
- _ts_metadata15("design:returntype", Promise)
3877
+ _ts_metadata16("design:returntype", Promise)
3237
3878
  ], ThreadsController.prototype, "detail", null);
3238
- _ts_decorate15([
3879
+ _ts_decorate17([
3239
3880
  Delete3(":id"),
3240
- _ts_param14(0, Req10()),
3241
- _ts_param14(1, Param5("id")),
3242
- _ts_metadata15("design:type", Function),
3243
- _ts_metadata15("design:paramtypes", [
3881
+ _ts_param16(0, Req10()),
3882
+ _ts_param16(1, Param5("id")),
3883
+ _ts_metadata16("design:type", Function),
3884
+ _ts_metadata16("design:paramtypes", [
3244
3885
  typeof Request === "undefined" ? Object : Request,
3245
3886
  String
3246
3887
  ]),
3247
- _ts_metadata15("design:returntype", Promise)
3888
+ _ts_metadata16("design:returntype", Promise)
3248
3889
  ], ThreadsController.prototype, "remove", null);
3249
- _ts_decorate15([
3890
+ _ts_decorate17([
3250
3891
  Post5(":id/fork-from/:messageId"),
3251
- _ts_param14(0, Req10()),
3252
- _ts_param14(1, Param5("id")),
3253
- _ts_param14(2, Param5("messageId")),
3254
- _ts_metadata15("design:type", Function),
3255
- _ts_metadata15("design:paramtypes", [
3892
+ _ts_param16(0, Req10()),
3893
+ _ts_param16(1, Param5("id")),
3894
+ _ts_param16(2, Param5("messageId")),
3895
+ _ts_metadata16("design:type", Function),
3896
+ _ts_metadata16("design:paramtypes", [
3256
3897
  typeof Request === "undefined" ? Object : Request,
3257
3898
  String,
3258
3899
  String
3259
3900
  ]),
3260
- _ts_metadata15("design:returntype", Promise)
3901
+ _ts_metadata16("design:returntype", Promise)
3261
3902
  ], ThreadsController.prototype, "fork", null);
3262
- _ts_decorate15([
3903
+ _ts_decorate17([
3263
3904
  Patch2(":id"),
3264
- _ts_param14(0, Req10()),
3265
- _ts_param14(1, Param5("id")),
3266
- _ts_param14(2, Body4()),
3267
- _ts_metadata15("design:type", Function),
3268
- _ts_metadata15("design:paramtypes", [
3905
+ _ts_param16(0, Req10()),
3906
+ _ts_param16(1, Param5("id")),
3907
+ _ts_param16(2, Body4()),
3908
+ _ts_metadata16("design:type", Function),
3909
+ _ts_metadata16("design:paramtypes", [
3269
3910
  typeof Request === "undefined" ? Object : Request,
3270
3911
  String,
3271
3912
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
3272
3913
  ]),
3273
- _ts_metadata15("design:returntype", Promise)
3914
+ _ts_metadata16("design:returntype", Promise)
3274
3915
  ], ThreadsController.prototype, "update", null);
3275
- _ts_decorate15([
3916
+ _ts_decorate17([
3276
3917
  Post5(":id/promote"),
3277
- _ts_param14(0, Req10()),
3278
- _ts_param14(1, Param5("id")),
3279
- _ts_metadata15("design:type", Function),
3280
- _ts_metadata15("design:paramtypes", [
3918
+ _ts_param16(0, Req10()),
3919
+ _ts_param16(1, Param5("id")),
3920
+ _ts_metadata16("design:type", Function),
3921
+ _ts_metadata16("design:paramtypes", [
3281
3922
  typeof Request === "undefined" ? Object : Request,
3282
3923
  String
3283
3924
  ]),
3284
- _ts_metadata15("design:returntype", Promise)
3925
+ _ts_metadata16("design:returntype", Promise)
3285
3926
  ], ThreadsController.prototype, "promote", null);
3286
- _ts_decorate15([
3927
+ _ts_decorate17([
3287
3928
  Delete3(":id/from/:messageId"),
3288
- _ts_param14(0, Req10()),
3289
- _ts_param14(1, Param5("id")),
3290
- _ts_param14(2, Param5("messageId")),
3291
- _ts_metadata15("design:type", Function),
3292
- _ts_metadata15("design:paramtypes", [
3929
+ _ts_param16(0, Req10()),
3930
+ _ts_param16(1, Param5("id")),
3931
+ _ts_param16(2, Param5("messageId")),
3932
+ _ts_metadata16("design:type", Function),
3933
+ _ts_metadata16("design:paramtypes", [
3293
3934
  typeof Request === "undefined" ? Object : Request,
3294
3935
  String,
3295
3936
  String
3296
3937
  ]),
3297
- _ts_metadata15("design:returntype", Promise)
3938
+ _ts_metadata16("design:returntype", Promise)
3298
3939
  ], ThreadsController.prototype, "truncateFrom", null);
3299
- ThreadsController = _ts_decorate15([
3940
+ ThreadsController = _ts_decorate17([
3300
3941
  Controller11("threads"),
3301
- _ts_param14(1, Inject14(AGENT_ACTOR_RESOLVER10)),
3302
- _ts_metadata15("design:type", Function),
3303
- _ts_metadata15("design:paramtypes", [
3942
+ _ts_param16(1, Inject16(AGENT_ACTOR_RESOLVER10)),
3943
+ _ts_metadata16("design:type", Function),
3944
+ _ts_metadata16("design:paramtypes", [
3304
3945
  typeof AgentService === "undefined" ? Object : AgentService,
3305
3946
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3306
3947
  ])
@@ -3308,8 +3949,8 @@ ThreadsController = _ts_decorate15([
3308
3949
 
3309
3950
  // src/controller/tool-call.controller.ts
3310
3951
  import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER11 } from "@dudousxd/nestjs-agent-core";
3311
- import { BadRequestException as BadRequestException5, Body as Body5, Controller as Controller12, Inject as Inject15, Post as Post6, Req as Req11 } from "@nestjs/common";
3312
- function _ts_decorate16(decorators, target, key, desc) {
3952
+ import { BadRequestException as BadRequestException6, Body as Body5, Controller as Controller12, Inject as Inject17, Post as Post6, Req as Req11 } from "@nestjs/common";
3953
+ function _ts_decorate18(decorators, target, key, desc) {
3313
3954
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3314
3955
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3315
3956
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3322,19 +3963,19 @@ function _ts_decorate16(decorators, target, key, desc) {
3322
3963
  }
3323
3964
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3324
3965
  }
3325
- __name(_ts_decorate16, "_ts_decorate");
3326
- function _ts_metadata16(metadataKey, metadataValue) {
3966
+ __name(_ts_decorate18, "_ts_decorate");
3967
+ function _ts_metadata17(metadataKey, metadataValue) {
3327
3968
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3328
3969
  return Reflect.metadata(metadataKey, metadataValue);
3329
3970
  }
3330
3971
  }
3331
- __name(_ts_metadata16, "_ts_metadata");
3332
- function _ts_param15(paramIndex, decorator) {
3972
+ __name(_ts_metadata17, "_ts_metadata");
3973
+ function _ts_param17(paramIndex, decorator) {
3333
3974
  return function(target, key) {
3334
3975
  decorator(target, key, paramIndex);
3335
3976
  };
3336
3977
  }
3337
- __name(_ts_param15, "_ts_param");
3978
+ __name(_ts_param17, "_ts_param");
3338
3979
  var MAX_ANSWERED_QUESTIONS = 100;
3339
3980
  var MAX_VALUES_PER_QUESTION = 100;
3340
3981
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -3343,7 +3984,7 @@ var MAX_VIA_LENGTH = 64;
3343
3984
  var DEFAULT_VIA = "web";
3344
3985
  function toolCallId(claimed) {
3345
3986
  if (typeof claimed !== "string" || claimed.length === 0) {
3346
- throw new BadRequestException5("toolCallId must be a non-empty string");
3987
+ throw new BadRequestException6("toolCallId must be a non-empty string");
3347
3988
  }
3348
3989
  return claimed;
3349
3990
  }
@@ -3353,10 +3994,10 @@ function rejectReason(claimed) {
3353
3994
  return void 0;
3354
3995
  }
3355
3996
  if (typeof claimed !== "string") {
3356
- throw new BadRequestException5("reason must be a string");
3997
+ throw new BadRequestException6("reason must be a string");
3357
3998
  }
3358
3999
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
3359
- throw new BadRequestException5(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
4000
+ throw new BadRequestException6(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
3360
4001
  }
3361
4002
  return claimed;
3362
4003
  }
@@ -3366,7 +4007,7 @@ function remember(claimed) {
3366
4007
  return false;
3367
4008
  }
3368
4009
  if (typeof claimed !== "boolean") {
3369
- throw new BadRequestException5("remember must be a boolean");
4010
+ throw new BadRequestException6("remember must be a boolean");
3370
4011
  }
3371
4012
  return claimed;
3372
4013
  }
@@ -3376,7 +4017,7 @@ function via(claimed) {
3376
4017
  return DEFAULT_VIA;
3377
4018
  }
3378
4019
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
3379
- throw new BadRequestException5(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
4020
+ throw new BadRequestException6(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
3380
4021
  }
3381
4022
  return claimed;
3382
4023
  }
@@ -3386,26 +4027,26 @@ function answers(claimed) {
3386
4027
  return void 0;
3387
4028
  }
3388
4029
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
3389
- throw new BadRequestException5("answers must be an object of questionId \u2192 chosen values");
4030
+ throw new BadRequestException6("answers must be an object of questionId \u2192 chosen values");
3390
4031
  }
3391
4032
  const entries = Object.entries(claimed);
3392
4033
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
3393
- throw new BadRequestException5(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
4034
+ throw new BadRequestException6(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
3394
4035
  }
3395
4036
  const validated = /* @__PURE__ */ Object.create(null);
3396
4037
  for (const [questionId, values] of entries) {
3397
4038
  if (!Array.isArray(values)) {
3398
- throw new BadRequestException5(`answers["${questionId}"] must be an array of chosen values`);
4039
+ throw new BadRequestException6(`answers["${questionId}"] must be an array of chosen values`);
3399
4040
  }
3400
4041
  if (values.length > MAX_VALUES_PER_QUESTION) {
3401
- throw new BadRequestException5(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
4042
+ throw new BadRequestException6(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
3402
4043
  }
3403
4044
  for (const value of values) {
3404
4045
  if (typeof value !== "string") {
3405
- throw new BadRequestException5(`answers["${questionId}"] must contain only strings`);
4046
+ throw new BadRequestException6(`answers["${questionId}"] must contain only strings`);
3406
4047
  }
3407
4048
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
3408
- throw new BadRequestException5(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
4049
+ throw new BadRequestException6(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
3409
4050
  }
3410
4051
  }
3411
4052
  validated[questionId] = values;
@@ -3467,64 +4108,64 @@ var ToolCallController = class {
3467
4108
  };
3468
4109
  }
3469
4110
  };
3470
- _ts_decorate16([
4111
+ _ts_decorate18([
3471
4112
  Post6("approve"),
3472
- _ts_param15(0, Req11()),
3473
- _ts_param15(1, Body5()),
3474
- _ts_metadata16("design:type", Function),
3475
- _ts_metadata16("design:paramtypes", [
4113
+ _ts_param17(0, Req11()),
4114
+ _ts_param17(1, Body5()),
4115
+ _ts_metadata17("design:type", Function),
4116
+ _ts_metadata17("design:paramtypes", [
3476
4117
  typeof Request === "undefined" ? Object : Request,
3477
4118
  typeof ApproveBody === "undefined" ? Object : ApproveBody
3478
4119
  ]),
3479
- _ts_metadata16("design:returntype", Promise)
4120
+ _ts_metadata17("design:returntype", Promise)
3480
4121
  ], ToolCallController.prototype, "approve", null);
3481
- _ts_decorate16([
4122
+ _ts_decorate18([
3482
4123
  Post6("reject"),
3483
- _ts_param15(0, Req11()),
3484
- _ts_param15(1, Body5()),
3485
- _ts_metadata16("design:type", Function),
3486
- _ts_metadata16("design:paramtypes", [
4124
+ _ts_param17(0, Req11()),
4125
+ _ts_param17(1, Body5()),
4126
+ _ts_metadata17("design:type", Function),
4127
+ _ts_metadata17("design:paramtypes", [
3487
4128
  typeof Request === "undefined" ? Object : Request,
3488
4129
  typeof RejectBody === "undefined" ? Object : RejectBody
3489
4130
  ]),
3490
- _ts_metadata16("design:returntype", Promise)
4131
+ _ts_metadata17("design:returntype", Promise)
3491
4132
  ], ToolCallController.prototype, "reject", null);
3492
- _ts_decorate16([
4133
+ _ts_decorate18([
3493
4134
  Post6("answer"),
3494
- _ts_param15(0, Req11()),
3495
- _ts_param15(1, Body5()),
3496
- _ts_metadata16("design:type", Function),
3497
- _ts_metadata16("design:paramtypes", [
4135
+ _ts_param17(0, Req11()),
4136
+ _ts_param17(1, Body5()),
4137
+ _ts_metadata17("design:type", Function),
4138
+ _ts_metadata17("design:paramtypes", [
3498
4139
  typeof Request === "undefined" ? Object : Request,
3499
4140
  typeof AnswerBody === "undefined" ? Object : AnswerBody
3500
4141
  ]),
3501
- _ts_metadata16("design:returntype", Promise)
4142
+ _ts_metadata17("design:returntype", Promise)
3502
4143
  ], ToolCallController.prototype, "answer", null);
3503
- _ts_decorate16([
4144
+ _ts_decorate18([
3504
4145
  Post6("skip"),
3505
- _ts_param15(0, Req11()),
3506
- _ts_param15(1, Body5()),
3507
- _ts_metadata16("design:type", Function),
3508
- _ts_metadata16("design:paramtypes", [
4146
+ _ts_param17(0, Req11()),
4147
+ _ts_param17(1, Body5()),
4148
+ _ts_metadata17("design:type", Function),
4149
+ _ts_metadata17("design:paramtypes", [
3509
4150
  typeof Request === "undefined" ? Object : Request,
3510
4151
  Object
3511
4152
  ]),
3512
- _ts_metadata16("design:returntype", Promise)
4153
+ _ts_metadata17("design:returntype", Promise)
3513
4154
  ], ToolCallController.prototype, "skip", null);
3514
- ToolCallController = _ts_decorate16([
4155
+ ToolCallController = _ts_decorate18([
3515
4156
  Controller12("tool-call"),
3516
- _ts_param15(1, Inject15(AGENT_ACTOR_RESOLVER11)),
3517
- _ts_metadata16("design:type", Function),
3518
- _ts_metadata16("design:paramtypes", [
4157
+ _ts_param17(1, Inject17(AGENT_ACTOR_RESOLVER11)),
4158
+ _ts_metadata17("design:type", Function),
4159
+ _ts_metadata17("design:paramtypes", [
3519
4160
  typeof AgentService === "undefined" ? Object : AgentService,
3520
4161
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3521
4162
  ])
3522
4163
  ], ToolCallController);
3523
4164
 
3524
4165
  // src/controller/tools.controller.ts
3525
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER12, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY3, AGENT_REGISTRY as AGENT_REGISTRY3, ALL_AGENTS, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
3526
- import { Controller as Controller13, Get as Get11, Inject as Inject16, NotFoundException as NotFoundException3, Query as Query5, Req as Req12 } from "@nestjs/common";
3527
- function _ts_decorate17(decorators, target, key, desc) {
4166
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER12, AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_REGISTRY as AGENT_REGISTRY3, ALL_AGENTS, AgentRegistry as AgentRegistry4 } from "@dudousxd/nestjs-agent-core";
4167
+ import { Controller as Controller13, Get as Get11, Inject as Inject18, NotFoundException as NotFoundException4, Query as Query5, Req as Req12 } from "@nestjs/common";
4168
+ function _ts_decorate19(decorators, target, key, desc) {
3528
4169
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3529
4170
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3530
4171
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3537,19 +4178,19 @@ function _ts_decorate17(decorators, target, key, desc) {
3537
4178
  }
3538
4179
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3539
4180
  }
3540
- __name(_ts_decorate17, "_ts_decorate");
3541
- function _ts_metadata17(metadataKey, metadataValue) {
4181
+ __name(_ts_decorate19, "_ts_decorate");
4182
+ function _ts_metadata18(metadataKey, metadataValue) {
3542
4183
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3543
4184
  return Reflect.metadata(metadataKey, metadataValue);
3544
4185
  }
3545
4186
  }
3546
- __name(_ts_metadata17, "_ts_metadata");
3547
- function _ts_param16(paramIndex, decorator) {
4187
+ __name(_ts_metadata18, "_ts_metadata");
4188
+ function _ts_param18(paramIndex, decorator) {
3548
4189
  return function(target, key) {
3549
4190
  decorator(target, key, paramIndex);
3550
4191
  };
3551
4192
  }
3552
- __name(_ts_param16, "_ts_param");
4193
+ __name(_ts_param18, "_ts_param");
3553
4194
  var ToolsController = class {
3554
4195
  static {
3555
4196
  __name(this, "ToolsController");
@@ -3564,7 +4205,7 @@ var ToolsController = class {
3564
4205
  }
3565
4206
  async list(req, agent) {
3566
4207
  if (agent !== void 0 && agent !== ALL_AGENTS && this.agents.get(agent) === void 0) {
3567
- throw new NotFoundException3(`No agent named "${agent}"`);
4208
+ throw new NotFoundException4(`No agent named "${agent}"`);
3568
4209
  }
3569
4210
  const actor = await this.actorResolver.resolve(req);
3570
4211
  const names = agent === ALL_AGENTS ? [
@@ -3593,24 +4234,24 @@ var ToolsController = class {
3593
4234
  ];
3594
4235
  }
3595
4236
  };
3596
- _ts_decorate17([
4237
+ _ts_decorate19([
3597
4238
  Get11(),
3598
- _ts_param16(0, Req12()),
3599
- _ts_param16(1, Query5("agent")),
3600
- _ts_metadata17("design:type", Function),
3601
- _ts_metadata17("design:paramtypes", [
4239
+ _ts_param18(0, Req12()),
4240
+ _ts_param18(1, Query5("agent")),
4241
+ _ts_metadata18("design:type", Function),
4242
+ _ts_metadata18("design:paramtypes", [
3602
4243
  typeof Request === "undefined" ? Object : Request,
3603
4244
  String
3604
4245
  ]),
3605
- _ts_metadata17("design:returntype", Promise)
4246
+ _ts_metadata18("design:returntype", Promise)
3606
4247
  ], ToolsController.prototype, "list", null);
3607
- ToolsController = _ts_decorate17([
4248
+ ToolsController = _ts_decorate19([
3608
4249
  Controller13("tools"),
3609
- _ts_param16(0, Inject16(AGENT_ACTOR_RESOLVER12)),
3610
- _ts_param16(1, Inject16(AGENT_DEPS_FACTORY3)),
3611
- _ts_param16(2, Inject16(AGENT_REGISTRY3)),
3612
- _ts_metadata17("design:type", Function),
3613
- _ts_metadata17("design:paramtypes", [
4250
+ _ts_param18(0, Inject18(AGENT_ACTOR_RESOLVER12)),
4251
+ _ts_param18(1, Inject18(AGENT_DEPS_FACTORY4)),
4252
+ _ts_param18(2, Inject18(AGENT_REGISTRY3)),
4253
+ _ts_metadata18("design:type", Function),
4254
+ _ts_metadata18("design:paramtypes", [
3614
4255
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3615
4256
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
3616
4257
  typeof AgentRegistry4 === "undefined" ? Object : AgentRegistry4
@@ -3619,7 +4260,7 @@ ToolsController = _ts_decorate17([
3619
4260
 
3620
4261
  // src/discovery/agent-discovery.service.ts
3621
4262
  import { AGENT_PROMPT_CONTRIBUTORS as AGENT_PROMPT_CONTRIBUTORS2, AGENT_REGISTRY as AGENT_REGISTRY4, AgentRegistry as AgentRegistry5 } from "@dudousxd/nestjs-agent-core";
3622
- import { Inject as Inject17, Injectable as Injectable5, Logger as Logger2 } from "@nestjs/common";
4263
+ import { Inject as Inject19, Injectable as Injectable6, Logger as Logger2 } from "@nestjs/common";
3623
4264
  import { DiscoveryService, MetadataScanner } from "@nestjs/core";
3624
4265
 
3625
4266
  // src/decorator/agent.decorator.ts
@@ -3654,7 +4295,7 @@ function SystemPromptContributor() {
3654
4295
  __name(SystemPromptContributor, "SystemPromptContributor");
3655
4296
 
3656
4297
  // src/discovery/agent-discovery.service.ts
3657
- function _ts_decorate18(decorators, target, key, desc) {
4298
+ function _ts_decorate20(decorators, target, key, desc) {
3658
4299
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3659
4300
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3660
4301
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3667,19 +4308,19 @@ function _ts_decorate18(decorators, target, key, desc) {
3667
4308
  }
3668
4309
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3669
4310
  }
3670
- __name(_ts_decorate18, "_ts_decorate");
3671
- function _ts_metadata18(metadataKey, metadataValue) {
4311
+ __name(_ts_decorate20, "_ts_decorate");
4312
+ function _ts_metadata19(metadataKey, metadataValue) {
3672
4313
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3673
4314
  return Reflect.metadata(metadataKey, metadataValue);
3674
4315
  }
3675
4316
  }
3676
- __name(_ts_metadata18, "_ts_metadata");
3677
- function _ts_param17(paramIndex, decorator) {
4317
+ __name(_ts_metadata19, "_ts_metadata");
4318
+ function _ts_param19(paramIndex, decorator) {
3678
4319
  return function(target, key) {
3679
4320
  decorator(target, key, paramIndex);
3680
4321
  };
3681
4322
  }
3682
- __name(_ts_param17, "_ts_param");
4323
+ __name(_ts_param19, "_ts_param");
3683
4324
  var AgentDiscoveryService = class _AgentDiscoveryService {
3684
4325
  static {
3685
4326
  __name(this, "AgentDiscoveryService");
@@ -3707,6 +4348,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3707
4348
  }
3708
4349
  this.collectContributors(instance);
3709
4350
  }
4351
+ this.assertPersonas(this.registry.list());
3710
4352
  }
3711
4353
  /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
3712
4354
  definitionFrom(instance, meta) {
@@ -3750,10 +4392,48 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3750
4392
  } : {},
3751
4393
  ...meta.handoff !== void 0 ? {
3752
4394
  delegatesTo: this.handoffEdges(meta)
4395
+ } : {},
4396
+ ...meta.personas !== void 0 ? {
4397
+ personas: meta.personas
4398
+ } : {},
4399
+ ...meta.defaultPersona !== void 0 ? {
4400
+ defaultPersona: meta.defaultPersona
3753
4401
  } : {}
3754
4402
  };
3755
4403
  }
3756
4404
  /**
4405
+ * Refuse to boot on a persona declaration that could only fail later, per request: a default that
4406
+ * names no persona, an id declared twice, an alias two personas claim, or an alias that is a real
4407
+ * agent's name (which would never be reached — a registered agent always wins).
4408
+ */
4409
+ assertPersonas(definitions) {
4410
+ const agentNames = new Set(definitions.map((definition) => definition.name));
4411
+ const aliasOwner = /* @__PURE__ */ new Map();
4412
+ for (const definition of definitions) {
4413
+ const ids = /* @__PURE__ */ new Set();
4414
+ for (const persona of definition.personas ?? []) {
4415
+ if (ids.has(persona.id)) {
4416
+ throw new Error(`Agent "${definition.name}" declares persona "${persona.id}" twice.`);
4417
+ }
4418
+ ids.add(persona.id);
4419
+ for (const alias of persona.aliases ?? []) {
4420
+ const owner = `${definition.name}/${persona.id}`;
4421
+ if (agentNames.has(alias)) {
4422
+ throw new Error(`Persona ${owner} claims the alias "${alias}", which is a registered agent's name.`);
4423
+ }
4424
+ const previous = aliasOwner.get(alias);
4425
+ if (previous !== void 0) {
4426
+ throw new Error(`Personas ${previous} and ${owner} both claim the alias "${alias}".`);
4427
+ }
4428
+ aliasOwner.set(alias, owner);
4429
+ }
4430
+ }
4431
+ if (definition.defaultPersona !== void 0 && !ids.has(definition.defaultPersona)) {
4432
+ throw new Error(`Agent "${definition.name}" names "${definition.defaultPersona}" as its default persona, but declares no persona with that id.`);
4433
+ }
4434
+ }
4435
+ }
4436
+ /**
3757
4437
  * Resolve each handoff entry to an {@link AgentDelegation} — its target's registered name, plus
3758
4438
  * whether that edge detaches (skipping non-agent classes). A bare name is kept for a plain edge
3759
4439
  * rather than an always-object form, so a definition an older host built by hand still reads.
@@ -3806,12 +4486,12 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
3806
4486
  return (ctx) => candidate.call(instance, ctx);
3807
4487
  }
3808
4488
  };
3809
- AgentDiscoveryService = _ts_decorate18([
3810
- Injectable5(),
3811
- _ts_param17(2, Inject17(AGENT_REGISTRY4)),
3812
- _ts_param17(3, Inject17(AGENT_PROMPT_CONTRIBUTORS2)),
3813
- _ts_metadata18("design:type", Function),
3814
- _ts_metadata18("design:paramtypes", [
4489
+ AgentDiscoveryService = _ts_decorate20([
4490
+ Injectable6(),
4491
+ _ts_param19(2, Inject19(AGENT_REGISTRY4)),
4492
+ _ts_param19(3, Inject19(AGENT_PROMPT_CONTRIBUTORS2)),
4493
+ _ts_metadata19("design:type", Function),
4494
+ _ts_metadata19("design:paramtypes", [
3815
4495
  typeof DiscoveryService === "undefined" ? Object : DiscoveryService,
3816
4496
  typeof MetadataScanner === "undefined" ? Object : MetadataScanner,
3817
4497
  typeof AgentRegistry5 === "undefined" ? Object : AgentRegistry5,
@@ -3820,8 +4500,8 @@ AgentDiscoveryService = _ts_decorate18([
3820
4500
  ], AgentDiscoveryService);
3821
4501
 
3822
4502
  // src/discovery/ai-tool-discovery.service.ts
3823
- import { AGENT_OPTIONS as AGENT_OPTIONS6, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
3824
- import { Inject as Inject18, Injectable as Injectable6, Logger as Logger3 } from "@nestjs/common";
4503
+ import { AGENT_OPTIONS as AGENT_OPTIONS7, AGENT_REGISTRY as AGENT_REGISTRY5, AGENT_TOOL_REGISTRY as AGENT_TOOL_REGISTRY2, normalizeDelegation as normalizeDelegation2 } from "@dudousxd/nestjs-agent-core";
4504
+ import { Inject as Inject20, Injectable as Injectable7, Logger as Logger3 } from "@nestjs/common";
3825
4505
  import { DiscoveryService as DiscoveryService2 } from "@nestjs/core";
3826
4506
  import { z } from "zod";
3827
4507
 
@@ -3853,46 +4533,8 @@ function readAiToolMetadata(target) {
3853
4533
  }
3854
4534
  __name(readAiToolMetadata, "readAiToolMetadata");
3855
4535
 
3856
- // src/functional-tool.ts
3857
- var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
3858
- function brand(tool) {
3859
- return {
3860
- [AGENT_TOOL_BRAND]: true,
3861
- spec: tool.spec,
3862
- handler: tool.handler
3863
- };
3864
- }
3865
- __name(brand, "brand");
3866
- function isBrandedFunctionalTool(value) {
3867
- return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
3868
- }
3869
- __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
3870
- function provideAgentTool(factoryOrTool, inject) {
3871
- const provide = /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-instance");
3872
- if (typeof factoryOrTool === "function") {
3873
- return {
3874
- provide,
3875
- useFactory: /* @__PURE__ */ __name((...deps) => brand(factoryOrTool(...deps)), "useFactory"),
3876
- inject: inject ?? []
3877
- };
3878
- }
3879
- return {
3880
- provide,
3881
- useValue: brand(factoryOrTool)
3882
- };
3883
- }
3884
- __name(provideAgentTool, "provideAgentTool");
3885
- function provideAgentTools(factory, inject) {
3886
- return {
3887
- provide: /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-list"),
3888
- useFactory: /* @__PURE__ */ __name(async (...deps) => (await factory(...deps)).map(brand), "useFactory"),
3889
- inject: inject ?? []
3890
- };
3891
- }
3892
- __name(provideAgentTools, "provideAgentTools");
3893
-
3894
4536
  // src/discovery/ai-tool-discovery.service.ts
3895
- function _ts_decorate19(decorators, target, key, desc) {
4537
+ function _ts_decorate21(decorators, target, key, desc) {
3896
4538
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3897
4539
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3898
4540
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3905,19 +4547,19 @@ function _ts_decorate19(decorators, target, key, desc) {
3905
4547
  }
3906
4548
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3907
4549
  }
3908
- __name(_ts_decorate19, "_ts_decorate");
3909
- function _ts_metadata19(metadataKey, metadataValue) {
4550
+ __name(_ts_decorate21, "_ts_decorate");
4551
+ function _ts_metadata20(metadataKey, metadataValue) {
3910
4552
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3911
4553
  return Reflect.metadata(metadataKey, metadataValue);
3912
4554
  }
3913
4555
  }
3914
- __name(_ts_metadata19, "_ts_metadata");
3915
- function _ts_param18(paramIndex, decorator) {
4556
+ __name(_ts_metadata20, "_ts_metadata");
4557
+ function _ts_param20(paramIndex, decorator) {
3916
4558
  return function(target, key) {
3917
4559
  decorator(target, key, paramIndex);
3918
4560
  };
3919
4561
  }
3920
- __name(_ts_param18, "_ts_param");
4562
+ __name(_ts_param20, "_ts_param");
3921
4563
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
3922
4564
  static {
3923
4565
  __name(this, "AiToolDiscoveryService");
@@ -3985,9 +4627,15 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
3985
4627
  } : {},
3986
4628
  ...meta.terminal === true ? {
3987
4629
  terminal: true
4630
+ } : {},
4631
+ ...meta.replacementKey !== void 0 ? {
4632
+ replacementKey: meta.replacementKey
3988
4633
  } : {}
3989
4634
  }, {
3990
4635
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
4636
+ ...typeof handler.preflight === "function" ? {
4637
+ preflight: /* @__PURE__ */ __name((input, ctx, options) => instance.preflight(input, ctx, options), "preflight")
4638
+ } : {},
3991
4639
  // Forwarded, not copied: the registry holds this wrapper rather than the provider, so an
3992
4640
  // `isEnabled()`/`canUse()` left behind here would be a gate that silently never applies.
3993
4641
  // Called through `instance` so each keeps its `this` (and its injected deps).
@@ -4061,13 +4709,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4061
4709
  return true;
4062
4710
  }
4063
4711
  };
4064
- AiToolDiscoveryService = _ts_decorate19([
4065
- Injectable6(),
4066
- _ts_param18(1, Inject18(AGENT_TOOL_REGISTRY2)),
4067
- _ts_param18(2, Inject18(AGENT_REGISTRY5)),
4068
- _ts_param18(3, Inject18(AGENT_OPTIONS6)),
4069
- _ts_metadata19("design:type", Function),
4070
- _ts_metadata19("design:paramtypes", [
4712
+ AiToolDiscoveryService = _ts_decorate21([
4713
+ Injectable7(),
4714
+ _ts_param20(1, Inject20(AGENT_TOOL_REGISTRY2)),
4715
+ _ts_param20(2, Inject20(AGENT_REGISTRY5)),
4716
+ _ts_param20(3, Inject20(AGENT_OPTIONS7)),
4717
+ _ts_metadata20("design:type", Function),
4718
+ _ts_metadata20("design:paramtypes", [
4071
4719
  typeof DiscoveryService2 === "undefined" ? Object : DiscoveryService2,
4072
4720
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
4073
4721
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -4077,7 +4725,7 @@ AiToolDiscoveryService = _ts_decorate19([
4077
4725
 
4078
4726
  // src/discovery/skill-discovery.service.ts
4079
4727
  import { AGENT_SKILL_SOURCES } from "@dudousxd/nestjs-agent-core";
4080
- import { Inject as Inject19, Injectable as Injectable7, Logger as Logger4 } from "@nestjs/common";
4728
+ import { Inject as Inject21, Injectable as Injectable8, Logger as Logger4 } from "@nestjs/common";
4081
4729
  import { DiscoveryService as DiscoveryService3 } from "@nestjs/core";
4082
4730
 
4083
4731
  // src/decorator/skill.decorator.ts
@@ -4100,7 +4748,7 @@ function skillScope(options) {
4100
4748
  __name(skillScope, "skillScope");
4101
4749
 
4102
4750
  // src/discovery/skill-discovery.service.ts
4103
- function _ts_decorate20(decorators, target, key, desc) {
4751
+ function _ts_decorate22(decorators, target, key, desc) {
4104
4752
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4105
4753
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4106
4754
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4113,19 +4761,19 @@ function _ts_decorate20(decorators, target, key, desc) {
4113
4761
  }
4114
4762
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4115
4763
  }
4116
- __name(_ts_decorate20, "_ts_decorate");
4117
- function _ts_metadata20(metadataKey, metadataValue) {
4764
+ __name(_ts_decorate22, "_ts_decorate");
4765
+ function _ts_metadata21(metadataKey, metadataValue) {
4118
4766
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4119
4767
  return Reflect.metadata(metadataKey, metadataValue);
4120
4768
  }
4121
4769
  }
4122
- __name(_ts_metadata20, "_ts_metadata");
4123
- function _ts_param19(paramIndex, decorator) {
4770
+ __name(_ts_metadata21, "_ts_metadata");
4771
+ function _ts_param21(paramIndex, decorator) {
4124
4772
  return function(target, key) {
4125
4773
  decorator(target, key, paramIndex);
4126
4774
  };
4127
4775
  }
4128
- __name(_ts_param19, "_ts_param");
4776
+ __name(_ts_param21, "_ts_param");
4129
4777
  var SkillDiscoveryService = class _SkillDiscoveryService {
4130
4778
  static {
4131
4779
  __name(this, "SkillDiscoveryService");
@@ -4169,11 +4817,11 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
4169
4817
  return flat === void 0 ? void 0 : () => flat;
4170
4818
  }
4171
4819
  };
4172
- SkillDiscoveryService = _ts_decorate20([
4173
- Injectable7(),
4174
- _ts_param19(1, Inject19(AGENT_SKILL_SOURCES)),
4175
- _ts_metadata20("design:type", Function),
4176
- _ts_metadata20("design:paramtypes", [
4820
+ SkillDiscoveryService = _ts_decorate22([
4821
+ Injectable8(),
4822
+ _ts_param21(1, Inject21(AGENT_SKILL_SOURCES)),
4823
+ _ts_metadata21("design:type", Function),
4824
+ _ts_metadata21("design:paramtypes", [
4177
4825
  typeof DiscoveryService3 === "undefined" ? Object : DiscoveryService3,
4178
4826
  Array
4179
4827
  ])
@@ -4309,13 +4957,248 @@ var LedgerQuotaProvider = class {
4309
4957
  }
4310
4958
  };
4311
4959
 
4960
+ // src/proposals/action-proposal-worker.service.ts
4961
+ import { randomUUID } from "crypto";
4962
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY5, AGENT_OPTIONS as AGENT_OPTIONS8, AGENT_STORE as AGENT_STORE5, ActionProposalExecutor, ActionProposalWorker, assertIndependentActionCapabilities as assertIndependentActionCapabilities2 } from "@dudousxd/nestjs-agent-core";
4963
+ import { Inject as Inject22, Injectable as Injectable9, Logger as Logger5 } from "@nestjs/common";
4964
+ function _ts_decorate23(decorators, target, key, desc) {
4965
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4966
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4967
+ r = Reflect.decorate(decorators, target, key, desc);
4968
+ } else {
4969
+ for (var i = decorators.length - 1; i >= 0; i--) {
4970
+ if (d = decorators[i]) {
4971
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4972
+ }
4973
+ }
4974
+ }
4975
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
4976
+ }
4977
+ __name(_ts_decorate23, "_ts_decorate");
4978
+ function _ts_metadata22(metadataKey, metadataValue) {
4979
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4980
+ return Reflect.metadata(metadataKey, metadataValue);
4981
+ }
4982
+ }
4983
+ __name(_ts_metadata22, "_ts_metadata");
4984
+ function _ts_param22(paramIndex, decorator) {
4985
+ return function(target, key) {
4986
+ decorator(target, key, paramIndex);
4987
+ };
4988
+ }
4989
+ __name(_ts_param22, "_ts_param");
4990
+ var ActionProposalWorkerService = class _ActionProposalWorkerService {
4991
+ static {
4992
+ __name(this, "ActionProposalWorkerService");
4993
+ }
4994
+ store;
4995
+ options;
4996
+ deps;
4997
+ worker;
4998
+ logger = new Logger5(_ActionProposalWorkerService.name);
4999
+ constructor(store, options, deps) {
5000
+ this.store = store;
5001
+ this.options = options;
5002
+ this.deps = deps;
5003
+ }
5004
+ onModuleInit() {
5005
+ if (this.options.actionApprovalMode !== "independent") return;
5006
+ assertIndependentActionCapabilities2(this.store, this.options.backgroundActorResolver);
5007
+ if (this.options.surface === "http") return;
5008
+ const resolver = this.options.backgroundActorResolver;
5009
+ if (!resolver) throw new Error("BackgroundActorResolver is required");
5010
+ this.worker = new ActionProposalWorker({
5011
+ store: this.store,
5012
+ workerId: randomUUID(),
5013
+ ...this.options.actionProposalWorker,
5014
+ executor: new ActionProposalExecutor({
5015
+ resolver,
5016
+ resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
5017
+ const deps = this.deps.forProposal(proposal, actor);
5018
+ return {
5019
+ registry: deps.registry,
5020
+ rolesPolicy: deps.rolesPolicy,
5021
+ ...deps.resolveUiCatalog !== void 0 ? {
5022
+ resolveUiCatalog: deps.resolveUiCatalog
5023
+ } : {},
5024
+ ...deps.toolAllowList !== void 0 ? {
5025
+ allowedTools: deps.toolAllowList
5026
+ } : {}
5027
+ };
5028
+ }, "resolveExecution")
5029
+ }),
5030
+ onError: /* @__PURE__ */ __name((error) => this.logger.error(error), "onError")
5031
+ });
5032
+ this.worker.start();
5033
+ }
5034
+ async onModuleDestroy() {
5035
+ await this.worker?.stop();
5036
+ }
5037
+ };
5038
+ ActionProposalWorkerService = _ts_decorate23([
5039
+ Injectable9(),
5040
+ _ts_param22(0, Inject22(AGENT_STORE5)),
5041
+ _ts_param22(1, Inject22(AGENT_OPTIONS8)),
5042
+ _ts_param22(2, Inject22(AGENT_DEPS_FACTORY5)),
5043
+ _ts_metadata22("design:type", Function),
5044
+ _ts_metadata22("design:paramtypes", [
5045
+ typeof AgentStore === "undefined" ? Object : AgentStore,
5046
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
5047
+ typeof AgentDepsFactory2 === "undefined" ? Object : AgentDepsFactory2
5048
+ ])
5049
+ ], ActionProposalWorkerService);
5050
+
5051
+ // src/proposals/action-proposal.controller.ts
5052
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER13, validateActionProposalListQuery } from "@dudousxd/nestjs-agent-core";
5053
+ import { BadRequestException as BadRequestException7, Body as Body6, Controller as Controller14, Get as Get12, Inject as Inject23, Param as Param6, Post as Post7, Query as Query6, Req as Req13, Res as Res2 } from "@nestjs/common";
5054
+ function _ts_decorate24(decorators, target, key, desc) {
5055
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5056
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5057
+ r = Reflect.decorate(decorators, target, key, desc);
5058
+ } else {
5059
+ for (var i = decorators.length - 1; i >= 0; i--) {
5060
+ if (d = decorators[i]) {
5061
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5062
+ }
5063
+ }
5064
+ }
5065
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
5066
+ }
5067
+ __name(_ts_decorate24, "_ts_decorate");
5068
+ function _ts_metadata23(metadataKey, metadataValue) {
5069
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5070
+ return Reflect.metadata(metadataKey, metadataValue);
5071
+ }
5072
+ }
5073
+ __name(_ts_metadata23, "_ts_metadata");
5074
+ function _ts_param23(paramIndex, decorator) {
5075
+ return function(target, key) {
5076
+ decorator(target, key, paramIndex);
5077
+ };
5078
+ }
5079
+ __name(_ts_param23, "_ts_param");
5080
+ function bodyFields(body, field2) {
5081
+ if (body === void 0) return {};
5082
+ if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field2)) throw new BadRequestException7(`Only ${field2} is accepted`);
5083
+ const value = body;
5084
+ if (value[field2] !== void 0 && (field2 === "remember" && typeof value[field2] !== "boolean" || field2 === "reason" && typeof value[field2] !== "string")) throw new BadRequestException7(`Invalid ${field2}`);
5085
+ return value;
5086
+ }
5087
+ __name(bodyFields, "bodyFields");
5088
+ var ActionProposalController = class {
5089
+ static {
5090
+ __name(this, "ActionProposalController");
5091
+ }
5092
+ proposals;
5093
+ actors;
5094
+ constructor(proposals, actors) {
5095
+ this.proposals = proposals;
5096
+ this.actors = actors;
5097
+ }
5098
+ async list(threadId, request, cursor, response) {
5099
+ let query = {};
5100
+ if (cursor !== void 0) {
5101
+ try {
5102
+ if (typeof cursor !== "string") throw new Error("Invalid cursor");
5103
+ query = {
5104
+ after: JSON.parse(cursor)
5105
+ };
5106
+ validateActionProposalListQuery(query);
5107
+ } catch {
5108
+ throw new BadRequestException7("Invalid action proposal cursor");
5109
+ }
5110
+ }
5111
+ const page = await this.proposals.listPage(threadId, await this.actors.resolve(request), query);
5112
+ if (page.next) {
5113
+ response.setHeader("X-Action-Proposals-Next", encodeURIComponent(JSON.stringify(page.next)));
5114
+ const exposed = response.getHeader("Access-Control-Expose-Headers");
5115
+ response.setHeader("Access-Control-Expose-Headers", `${exposed === void 0 ? "" : `${String(exposed)}, `}X-Action-Proposals-Next`);
5116
+ }
5117
+ return page.items;
5118
+ }
5119
+ async approve(threadId, proposalId, request, body) {
5120
+ const value = bodyFields(body, "remember");
5121
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
5122
+ decision: "approved",
5123
+ ...typeof value.remember === "boolean" ? {
5124
+ remember: value.remember
5125
+ } : {}
5126
+ });
5127
+ }
5128
+ async reject(threadId, proposalId, request, body) {
5129
+ const value = bodyFields(body, "reason");
5130
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
5131
+ decision: "rejected",
5132
+ ...typeof value.reason === "string" ? {
5133
+ reason: value.reason
5134
+ } : {}
5135
+ });
5136
+ }
5137
+ };
5138
+ _ts_decorate24([
5139
+ Get12(),
5140
+ _ts_param23(0, Param6("threadId")),
5141
+ _ts_param23(1, Req13()),
5142
+ _ts_param23(2, Query6("after")),
5143
+ _ts_param23(3, Res2({
5144
+ passthrough: true
5145
+ })),
5146
+ _ts_metadata23("design:type", Function),
5147
+ _ts_metadata23("design:paramtypes", [
5148
+ String,
5149
+ typeof Request === "undefined" ? Object : Request,
5150
+ Object,
5151
+ typeof Response === "undefined" ? Object : Response
5152
+ ]),
5153
+ _ts_metadata23("design:returntype", Promise)
5154
+ ], ActionProposalController.prototype, "list", null);
5155
+ _ts_decorate24([
5156
+ Post7(":proposalId/approve"),
5157
+ _ts_param23(0, Param6("threadId")),
5158
+ _ts_param23(1, Param6("proposalId")),
5159
+ _ts_param23(2, Req13()),
5160
+ _ts_param23(3, Body6()),
5161
+ _ts_metadata23("design:type", Function),
5162
+ _ts_metadata23("design:paramtypes", [
5163
+ String,
5164
+ String,
5165
+ typeof Request === "undefined" ? Object : Request,
5166
+ Object
5167
+ ]),
5168
+ _ts_metadata23("design:returntype", Promise)
5169
+ ], ActionProposalController.prototype, "approve", null);
5170
+ _ts_decorate24([
5171
+ Post7(":proposalId/reject"),
5172
+ _ts_param23(0, Param6("threadId")),
5173
+ _ts_param23(1, Param6("proposalId")),
5174
+ _ts_param23(2, Req13()),
5175
+ _ts_param23(3, Body6()),
5176
+ _ts_metadata23("design:type", Function),
5177
+ _ts_metadata23("design:paramtypes", [
5178
+ String,
5179
+ String,
5180
+ typeof Request === "undefined" ? Object : Request,
5181
+ Object
5182
+ ]),
5183
+ _ts_metadata23("design:returntype", Promise)
5184
+ ], ActionProposalController.prototype, "reject", null);
5185
+ ActionProposalController = _ts_decorate24([
5186
+ Controller14("threads/:threadId/action-proposals"),
5187
+ _ts_param23(1, Inject23(AGENT_ACTOR_RESOLVER13)),
5188
+ _ts_metadata23("design:type", Function),
5189
+ _ts_metadata23("design:paramtypes", [
5190
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
5191
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
5192
+ ])
5193
+ ], ActionProposalController);
5194
+
4312
5195
  // src/queue/chat-queue.token.ts
4313
5196
  var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-queue");
4314
5197
 
4315
5198
  // src/runner/inline-agent-runner.ts
4316
- import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY4, AGENT_STORE as AGENT_STORE4, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
4317
- import { Inject as Inject20, Injectable as Injectable8, Logger as Logger5, Optional as Optional8 } from "@nestjs/common";
4318
- function _ts_decorate21(decorators, target, key, desc) {
5199
+ import { AGENT_DEPS_FACTORY as AGENT_DEPS_FACTORY6, AGENT_STORE as AGENT_STORE6, RUN_ENDED_BEFORE_TOOL_CALL, RunCancelledError, agentFailureCode, encodeStreamEvent as encodeStreamEvent2, publishAgentRunFailed, releaseThreadRun, runAgentLoop, settleAll, settleUnsettledDelegation, streamFailure as streamFailure2 } from "@dudousxd/nestjs-agent-core";
5200
+ import { Inject as Inject24, Injectable as Injectable10, Logger as Logger6, Optional as Optional9 } from "@nestjs/common";
5201
+ function _ts_decorate25(decorators, target, key, desc) {
4319
5202
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4320
5203
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4321
5204
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4328,19 +5211,19 @@ function _ts_decorate21(decorators, target, key, desc) {
4328
5211
  }
4329
5212
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4330
5213
  }
4331
- __name(_ts_decorate21, "_ts_decorate");
4332
- function _ts_metadata21(metadataKey, metadataValue) {
5214
+ __name(_ts_decorate25, "_ts_decorate");
5215
+ function _ts_metadata24(metadataKey, metadataValue) {
4333
5216
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4334
5217
  return Reflect.metadata(metadataKey, metadataValue);
4335
5218
  }
4336
5219
  }
4337
- __name(_ts_metadata21, "_ts_metadata");
4338
- function _ts_param20(paramIndex, decorator) {
5220
+ __name(_ts_metadata24, "_ts_metadata");
5221
+ function _ts_param24(paramIndex, decorator) {
4339
5222
  return function(target, key) {
4340
5223
  decorator(target, key, paramIndex);
4341
5224
  };
4342
5225
  }
4343
- __name(_ts_param20, "_ts_param");
5226
+ __name(_ts_param24, "_ts_param");
4344
5227
  var InlineAgentRunner = class _InlineAgentRunner {
4345
5228
  static {
4346
5229
  __name(this, "InlineAgentRunner");
@@ -4348,7 +5231,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
4348
5231
  factory;
4349
5232
  store;
4350
5233
  queue;
4351
- logger = new Logger5(_InlineAgentRunner.name);
5234
+ logger = new Logger6(_InlineAgentRunner.name);
4352
5235
  pending = /* @__PURE__ */ new Map();
4353
5236
  /**
4354
5237
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -4791,13 +5674,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
4791
5674
  }
4792
5675
  }
4793
5676
  };
4794
- InlineAgentRunner = _ts_decorate21([
4795
- Injectable8(),
4796
- _ts_param20(0, Inject20(AGENT_DEPS_FACTORY4)),
4797
- _ts_param20(1, Inject20(AGENT_STORE4)),
4798
- _ts_param20(2, Optional8()),
4799
- _ts_metadata21("design:type", Function),
4800
- _ts_metadata21("design:paramtypes", [
5677
+ InlineAgentRunner = _ts_decorate25([
5678
+ Injectable10(),
5679
+ _ts_param24(0, Inject24(AGENT_DEPS_FACTORY6)),
5680
+ _ts_param24(1, Inject24(AGENT_STORE6)),
5681
+ _ts_param24(2, Optional9()),
5682
+ _ts_metadata24("design:type", Function),
5683
+ _ts_metadata24("design:paramtypes", [
4801
5684
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4802
5685
  typeof AgentStore === "undefined" ? Object : AgentStore,
4803
5686
  typeof ChatQueueService === "undefined" ? Object : ChatQueueService
@@ -4847,7 +5730,7 @@ function resolveSkillsConfig(options, declared) {
4847
5730
  __name(resolveSkillsConfig, "resolveSkillsConfig");
4848
5731
 
4849
5732
  // src/agent.module.ts
4850
- function _ts_decorate22(decorators, target, key, desc) {
5733
+ function _ts_decorate26(decorators, target, key, desc) {
4851
5734
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4852
5735
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4853
5736
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4860,13 +5743,13 @@ function _ts_decorate22(decorators, target, key, desc) {
4860
5743
  }
4861
5744
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4862
5745
  }
4863
- __name(_ts_decorate22, "_ts_decorate");
5746
+ __name(_ts_decorate26, "_ts_decorate");
4864
5747
  var DEFAULT_PATH = "agent";
4865
- var logger = new Logger6("AgentModule");
5748
+ var logger = new Logger7("AgentModule");
4866
5749
  function externalStoreWrapper(modules) {
4867
5750
  for (const module of modules.values()) {
4868
5751
  if (module.metatype === AgentModule) continue;
4869
- const wrapper = module.providers.get(AGENT_STORE5);
5752
+ const wrapper = module.providers.get(AGENT_STORE7);
4870
5753
  if (wrapper !== void 0) return wrapper;
4871
5754
  }
4872
5755
  return void 0;
@@ -4939,7 +5822,7 @@ function sharedProviders(durable) {
4939
5822
  provide: AGENT_SKILLS3,
4940
5823
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
4941
5824
  inject: [
4942
- AGENT_OPTIONS7,
5825
+ AGENT_OPTIONS9,
4943
5826
  AGENT_SKILL_SOURCES2
4944
5827
  ]
4945
5828
  },
@@ -4949,39 +5832,39 @@ function sharedProviders(durable) {
4949
5832
  provide: AGENT_MEMORY3,
4950
5833
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
4951
5834
  inject: [
4952
- AGENT_OPTIONS7
5835
+ AGENT_OPTIONS9
4953
5836
  ]
4954
5837
  },
4955
5838
  {
4956
5839
  provide: AGENT_SINK3,
4957
5840
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
4958
5841
  inject: [
4959
- AGENT_OPTIONS7
5842
+ AGENT_OPTIONS9
4960
5843
  ]
4961
5844
  },
4962
5845
  {
4963
5846
  provide: AGENT_ROLES_POLICY2,
4964
5847
  useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new ClosedRolesPolicy(options.defaultRoles) : new DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
4965
5848
  inject: [
4966
- AGENT_OPTIONS7
5849
+ AGENT_OPTIONS9
4967
5850
  ]
4968
5851
  },
4969
5852
  {
4970
- provide: AGENT_ACTOR_RESOLVER13,
5853
+ provide: AGENT_ACTOR_RESOLVER14,
4971
5854
  useFactory: /* @__PURE__ */ __name((options) => {
4972
5855
  if (options.actorResolver !== void 0) return options.actorResolver;
4973
5856
  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.");
4974
5857
  return new AnonymousActorResolver();
4975
5858
  }, "useFactory"),
4976
5859
  inject: [
4977
- AGENT_OPTIONS7
5860
+ AGENT_OPTIONS9
4978
5861
  ]
4979
5862
  },
4980
5863
  {
4981
5864
  provide: AGENT_MODEL2,
4982
5865
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
4983
5866
  inject: [
4984
- AGENT_OPTIONS7
5867
+ AGENT_OPTIONS9
4985
5868
  ]
4986
5869
  },
4987
5870
  {
@@ -4992,20 +5875,20 @@ function sharedProviders(durable) {
4992
5875
  warnAt: o.quota.warnAt
4993
5876
  } : {}), "useFactory"),
4994
5877
  inject: [
4995
- AGENT_OPTIONS7,
4996
- AGENT_STORE5
5878
+ AGENT_OPTIONS9,
5879
+ AGENT_STORE7
4997
5880
  ]
4998
5881
  },
4999
5882
  {
5000
5883
  provide: AGENT_MODEL_CATALOG3,
5001
5884
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
5002
5885
  inject: [
5003
- AGENT_OPTIONS7
5886
+ AGENT_OPTIONS9
5004
5887
  ]
5005
5888
  },
5006
5889
  AgentDepsFactory2,
5007
5890
  {
5008
- provide: AGENT_DEPS_FACTORY5,
5891
+ provide: AGENT_DEPS_FACTORY7,
5009
5892
  useExisting: AgentDepsFactory2
5010
5893
  },
5011
5894
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -5022,6 +5905,8 @@ function sharedProviders(durable) {
5022
5905
  },
5023
5906
  InlineAgentRunner,
5024
5907
  AgentService,
5908
+ ActionProposalService,
5909
+ ActionProposalWorkerService,
5025
5910
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
5026
5911
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
5027
5912
  AgentApprovalPortAdapter,
@@ -5031,10 +5916,10 @@ function sharedProviders(durable) {
5031
5916
  }
5032
5917
  ];
5033
5918
  providers.push({
5034
- provide: AGENT_STORE5,
5919
+ provide: AGENT_STORE7,
5035
5920
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
5036
5921
  inject: [
5037
- AGENT_OPTIONS7,
5922
+ AGENT_OPTIONS9,
5038
5923
  ModulesContainer
5039
5924
  ]
5040
5925
  });
@@ -5065,22 +5950,24 @@ function sharedProviders(durable) {
5065
5950
  __name(sharedProviders, "sharedProviders");
5066
5951
  function exportsFor() {
5067
5952
  return [
5068
- AGENT_OPTIONS7,
5953
+ AGENT_OPTIONS9,
5069
5954
  AGENT_TOOL_REGISTRY3,
5070
5955
  AGENT_REGISTRY6,
5071
5956
  AGENT_SINK3,
5072
5957
  AGENT_ROLES_POLICY2,
5073
- AGENT_ACTOR_RESOLVER13,
5958
+ AGENT_ACTOR_RESOLVER14,
5074
5959
  AGENT_MODEL2,
5075
- AGENT_STORE5,
5960
+ AGENT_STORE7,
5076
5961
  AGENT_MODEL_CATALOG3,
5077
5962
  AGENT_QUOTA_PROVIDER3,
5078
5963
  AGENT_PROMPT_CONTRIBUTORS3,
5079
5964
  AGENT_SKILLS3,
5080
5965
  AGENT_MEMORY3,
5081
- AGENT_DEPS_FACTORY5,
5966
+ AGENT_DEPS_FACTORY7,
5082
5967
  AgentDepsFactory2,
5083
5968
  AgentService,
5969
+ ActionProposalService,
5970
+ ActionProposalWorkerService,
5084
5971
  ChatQueueService,
5085
5972
  AGENT_CHAT_QUEUE,
5086
5973
  InlineAgentRunner,
@@ -5089,6 +5976,7 @@ function exportsFor() {
5089
5976
  }
5090
5977
  __name(exportsFor, "exportsFor");
5091
5978
  var BASE_CONTROLLERS = [
5979
+ ActionProposalController,
5092
5980
  ChatController,
5093
5981
  QueueController,
5094
5982
  ThreadsController,
@@ -5161,7 +6049,7 @@ var AgentModule = class _AgentModule {
5161
6049
  controllers: controllersForSurface(options.surface, options.adapters),
5162
6050
  providers: [
5163
6051
  {
5164
- provide: AGENT_OPTIONS7,
6052
+ provide: AGENT_OPTIONS9,
5165
6053
  useValue: options
5166
6054
  },
5167
6055
  ...sharedProviders(options.durable ?? false),
@@ -5185,7 +6073,7 @@ var AgentModule = class _AgentModule {
5185
6073
  controllers: controllersForSurface(options.surface, options.adapters),
5186
6074
  providers: [
5187
6075
  {
5188
- provide: AGENT_OPTIONS7,
6076
+ provide: AGENT_OPTIONS9,
5189
6077
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
5190
6078
  // authoritative on the async config object (they decided the actual wiring above), and
5191
6079
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -5207,16 +6095,16 @@ var AgentModule = class _AgentModule {
5207
6095
  };
5208
6096
  }
5209
6097
  };
5210
- AgentModule = _ts_decorate22([
6098
+ AgentModule = _ts_decorate26([
5211
6099
  Global(),
5212
- Module({})
6100
+ Module2({})
5213
6101
  ], AgentModule);
5214
6102
 
5215
6103
  // src/ag-ui/ag-ui.adapter.ts
5216
- import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER14, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING5, AGENT_OPTIONS as AGENT_OPTIONS8 } from "@dudousxd/nestjs-agent-core";
5217
- import { AG_UI_CUSTOM, agUiEvents, agUiFramesFromNdjson, agUiSse, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn } from "@dudousxd/nestjs-agent-core/ag-ui";
5218
- import { BadRequestException as BadRequestException6, Body as Body6, Controller as Controller14, ForbiddenException as ForbiddenException3, HttpCode as HttpCode2, Inject as Inject21, Optional as Optional9, Post as Post7, Req as Req13, Res as Res2 } from "@nestjs/common";
5219
- function _ts_decorate23(decorators, target, key, desc) {
6104
+ import { AGENT_ACTOR_RESOLVER as AGENT_ACTOR_RESOLVER15, AGENT_ATTACHMENT_STAGING as AGENT_ATTACHMENT_STAGING5, AGENT_OPTIONS as AGENT_OPTIONS10 } from "@dudousxd/nestjs-agent-core";
6105
+ import { AG_UI_CUSTOM, actionProposalDecisionEvents, agUiEvents, agUiFramesFromNdjson, agUiSse, parseRunInput, planResume, readAnswersPayload, readApprovalPayload, readContext, readForwardedProps, readUserTurn } from "@dudousxd/nestjs-agent-core/ag-ui";
6106
+ import { BadRequestException as BadRequestException8, Body as Body7, Controller as Controller15, ForbiddenException as ForbiddenException4, HttpCode as HttpCode2, Inject as Inject25, Optional as Optional10, Post as Post8, Req as Req14, Res as Res3 } from "@nestjs/common";
6107
+ function _ts_decorate27(decorators, target, key, desc) {
5220
6108
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5221
6109
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5222
6110
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5229,22 +6117,22 @@ function _ts_decorate23(decorators, target, key, desc) {
5229
6117
  }
5230
6118
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5231
6119
  }
5232
- __name(_ts_decorate23, "_ts_decorate");
5233
- function _ts_metadata22(metadataKey, metadataValue) {
6120
+ __name(_ts_decorate27, "_ts_decorate");
6121
+ function _ts_metadata25(metadataKey, metadataValue) {
5234
6122
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5235
6123
  return Reflect.metadata(metadataKey, metadataValue);
5236
6124
  }
5237
6125
  }
5238
- __name(_ts_metadata22, "_ts_metadata");
5239
- function _ts_param21(paramIndex, decorator) {
6126
+ __name(_ts_metadata25, "_ts_metadata");
6127
+ function _ts_param25(paramIndex, decorator) {
5240
6128
  return function(target, key) {
5241
6129
  decorator(target, key, paramIndex);
5242
6130
  };
5243
6131
  }
5244
- __name(_ts_param21, "_ts_param");
6132
+ __name(_ts_param25, "_ts_param");
5245
6133
  var AG_UI_VIA = "ag-ui";
5246
6134
  function invalid(code, message) {
5247
- return new BadRequestException6({
6135
+ return new BadRequestException8({
5248
6136
  statusCode: 400,
5249
6137
  code,
5250
6138
  message
@@ -5323,7 +6211,27 @@ var AgUiRunHandler = class {
5323
6211
  warnings.push(...turn.dropped);
5324
6212
  const owner = await this.agent.threadOwner(input.threadId);
5325
6213
  if (owner !== null && owner !== actor.id) {
5326
- throw new ForbiddenException3("thread belongs to another actor");
6214
+ throw new ForbiddenException4("thread belongs to another actor");
6215
+ }
6216
+ if (owner !== null && turn.media.length === 0) {
6217
+ const decision = await this.agent.handleTextDecision(input.threadId, actor, turn.text);
6218
+ if ("proposalDecision" in decision) {
6219
+ res.status(200);
6220
+ res.setHeader("Content-Type", "text/event-stream");
6221
+ res.setHeader("Cache-Control", "no-cache, no-transform");
6222
+ res.flushHeaders();
6223
+ for (const event of [
6224
+ ...warningEvents(warnings),
6225
+ ...actionProposalDecisionEvents({
6226
+ threadId: input.threadId,
6227
+ runId: input.runId,
6228
+ text: decision.text,
6229
+ proposalDecision: decision.proposalDecision
6230
+ })
6231
+ ]) res.write(agUiSse(event));
6232
+ res.end();
6233
+ return;
6234
+ }
5327
6235
  }
5328
6236
  const refs = await this.stage(actor, turn.media, warnings);
5329
6237
  if (turn.text.trim().length === 0 && refs.length === 0) {
@@ -5347,9 +6255,15 @@ var AgUiRunHandler = class {
5347
6255
  ...forwarded.agent !== void 0 ? {
5348
6256
  agentName: forwarded.agent
5349
6257
  } : {},
6258
+ ...forwarded.persona !== void 0 ? {
6259
+ personaId: forwarded.persona
6260
+ } : {},
5350
6261
  ...forwarded.model !== void 0 ? {
5351
6262
  model: forwarded.model
5352
6263
  } : {},
6264
+ ...forwarded.uiCapabilities !== void 0 ? {
6265
+ uiCapabilities: forwarded.uiCapabilities
6266
+ } : {},
5353
6267
  ...pageContext !== void 0 ? {
5354
6268
  pageContext
5355
6269
  } : {},
@@ -5494,29 +6408,29 @@ function agUiAdapter(options = {}) {
5494
6408
  return this.handle(req, res, body);
5495
6409
  }
5496
6410
  };
5497
- _ts_decorate23([
5498
- Post7(path),
6411
+ _ts_decorate27([
6412
+ Post8(path),
5499
6413
  HttpCode2(200),
5500
- _ts_param21(0, Req13()),
5501
- _ts_param21(1, Res2()),
5502
- _ts_param21(2, Body6()),
5503
- _ts_metadata22("design:type", Function),
5504
- _ts_metadata22("design:paramtypes", [
6414
+ _ts_param25(0, Req14()),
6415
+ _ts_param25(1, Res3()),
6416
+ _ts_param25(2, Body7()),
6417
+ _ts_metadata25("design:type", Function),
6418
+ _ts_metadata25("design:paramtypes", [
5505
6419
  typeof Request === "undefined" ? Object : Request,
5506
6420
  typeof Response === "undefined" ? Object : Response,
5507
6421
  Object
5508
6422
  ]),
5509
- _ts_metadata22("design:returntype", typeof Promise === "undefined" ? Object : Promise)
6423
+ _ts_metadata25("design:returntype", typeof Promise === "undefined" ? Object : Promise)
5510
6424
  ], AgUiController.prototype, "run", null);
5511
- AgUiController = _ts_decorate23([
5512
- Controller14(),
5513
- _ts_param21(0, Inject21(AgentService)),
5514
- _ts_param21(1, Inject21(AGENT_ACTOR_RESOLVER14)),
5515
- _ts_param21(2, Inject21(AGENT_OPTIONS8)),
5516
- _ts_param21(3, Optional9()),
5517
- _ts_param21(3, Inject21(AGENT_ATTACHMENT_STAGING5)),
5518
- _ts_metadata22("design:type", Function),
5519
- _ts_metadata22("design:paramtypes", [
6425
+ AgUiController = _ts_decorate27([
6426
+ Controller15(),
6427
+ _ts_param25(0, Inject25(AgentService)),
6428
+ _ts_param25(1, Inject25(AGENT_ACTOR_RESOLVER15)),
6429
+ _ts_param25(2, Inject25(AGENT_OPTIONS10)),
6430
+ _ts_param25(3, Optional10()),
6431
+ _ts_param25(3, Inject25(AGENT_ATTACHMENT_STAGING5)),
6432
+ _ts_metadata25("design:type", Function),
6433
+ _ts_metadata25("design:paramtypes", [
5520
6434
  typeof AgentService === "undefined" ? Object : AgentService,
5521
6435
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
5522
6436
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -5614,6 +6528,9 @@ export {
5614
6528
  AGENT_TOOL_BRAND,
5615
6529
  AI_TOOL_METADATA,
5616
6530
  ATTACHMENT_PAGE_SIZE,
6531
+ ActionProposalController,
6532
+ ActionProposalService,
6533
+ ActionProposalWorkerService,
5617
6534
  AgUiRunHandler,
5618
6535
  Agent,
5619
6536
  AgentApprovalPortAdapter,
@@ -5661,6 +6578,7 @@ export {
5661
6578
  requestUserActorResolver,
5662
6579
  resolveSkillsConfig,
5663
6580
  skillScope,
6581
+ threadPersona,
5664
6582
  toolNameFromClass,
5665
6583
  utcDay
5666
6584
  };