@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.
@@ -30,7 +30,7 @@ __export(durable_exports, {
30
30
  module.exports = __toCommonJS(durable_exports);
31
31
 
32
32
  // src/durable/agent-run.workflow.ts
33
- var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
33
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
34
34
  var import_nestjs_durable2 = require("@dudousxd/nestjs-durable");
35
35
  var import_nestjs_durable_core2 = require("@dudousxd/nestjs-durable-core");
36
36
  var import_common2 = require("@nestjs/common");
@@ -62,6 +62,8 @@ var AGENT_CHAT_QUEUE = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:chat-q
62
62
 
63
63
  // src/durable/agent-run.steps.ts
64
64
  var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
65
+ var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
66
+ var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
65
67
  var import_nestjs_durable = require("@dudousxd/nestjs-durable");
66
68
  var import_common = require("@nestjs/common");
67
69
 
@@ -122,24 +124,34 @@ var AgentRunSteps = class {
122
124
  }
123
125
  async runLlm(input) {
124
126
  const deps = this.factory.forAgent(input.agentName);
125
- const tools = (0, import_nestjs_agent_core.withMemoryTool)({
126
- tools: (0, import_nestjs_agent_core.withSkillTool)({
127
- tools: (0, import_nestjs_agent_core.withAskTool)({
128
- tools: await deps.registry.definitionsFor(input.actor, deps.rolesPolicy, deps.toolAllowList, {
129
- ...input.threadId !== void 0 ? {
130
- threadId: input.threadId
131
- } : {},
132
- ...input.agentName !== void 0 ? {
133
- agentName: input.agentName
134
- } : {}
135
- }),
127
+ const tools = (0, import_nestjs_agent_core3.withMemoryTool)({
128
+ tools: (0, import_nestjs_agent_core3.withSkillTool)({
129
+ tools: (0, import_nestjs_agent_core3.withAskTool)({
130
+ tools: await deps.registry.definitionsFor(
131
+ input.actor,
132
+ deps.rolesPolicy,
133
+ // The persona narrowing the loop journaled in `persona:resolve` rides the envelope:
134
+ // this worker's own persona config may already say something else.
135
+ (0, import_nestjs_agent_core3.intersectAllowLists)(deps.toolAllowList, input.personaAllowedTools),
136
+ {
137
+ ...input.threadId !== void 0 ? {
138
+ threadId: input.threadId
139
+ } : {},
140
+ ...input.preflightContext?.uiCapabilities !== void 0 ? {
141
+ uiCapabilities: input.preflightContext.uiCapabilities
142
+ } : {},
143
+ ...input.agentName !== void 0 ? {
144
+ agentName: input.agentName
145
+ } : {}
146
+ }
147
+ ),
136
148
  ask: deps.ask
137
149
  }),
138
150
  enabled: deps.skills !== void 0
139
151
  }),
140
152
  enabled: deps.memory?.provider.write !== void 0
141
153
  });
142
- const buffer = input.bufferOutput === true ? (0, import_nestjs_agent_core.createFrameBuffer)() : void 0;
154
+ const buffer = input.bufferOutput === true ? (0, import_nestjs_agent_core3.createFrameBuffer)() : void 0;
143
155
  let writer;
144
156
  if (buffer !== void 0) {
145
157
  writer = buffer.writer;
@@ -147,8 +159,8 @@ var AgentRunSteps = class {
147
159
  const opened = await deps.sink.open(input.sinkRunId);
148
160
  writer = input.childSink ? childSinkWriter(opened) : opened;
149
161
  }
150
- const frames = (0, import_nestjs_agent_core.observeTurnFrames)(writer);
151
- const turn = (0, import_nestjs_agent_core.withTurnFrames)(await (0, import_nestjs_agent_core.traceLlmTurn)(input.runId, input.step, () => deps.model.runTurn({
162
+ const frames = (0, import_nestjs_agent_core3.observeTurnFrames)(writer);
163
+ const turn = (0, import_nestjs_agent_core3.withTurnFrames)(await (0, import_nestjs_agent_core3.traceLlmTurn)(input.runId, input.step, () => deps.model.runTurn({
152
164
  system: input.system,
153
165
  messages: input.messages,
154
166
  tools,
@@ -157,7 +169,68 @@ var AgentRunSteps = class {
157
169
  model: input.model
158
170
  } : {}
159
171
  })), frames.summary());
160
- const stamped = (0, import_nestjs_agent_core.stampToolKinds)(turn, deps);
172
+ const stamped = (0, import_nestjs_agent_core3.stampToolKinds)(turn, deps);
173
+ const allowedTools = (0, import_nestjs_agent_core3.intersectAllowLists)(deps.toolAllowList, input.personaAllowedTools);
174
+ for (const call of stamped.toolCalls) {
175
+ if (call.kind !== "action") continue;
176
+ try {
177
+ const context = input.preflightContext ?? {
178
+ actor: input.actor,
179
+ threadId: input.threadId ?? "",
180
+ runId: input.runId,
181
+ requestId: input.runId,
182
+ ...input.agentName !== void 0 ? {
183
+ agentName: input.agentName
184
+ } : {}
185
+ };
186
+ if (input.actionApprovalMode === "independent") {
187
+ const spec = deps.registry.spec(call.name);
188
+ call.actionApproval = await (0, import_nestjs_agent_core2.resolveActionProposalApproval)({
189
+ actor: input.actor,
190
+ store: deps.store,
191
+ tool: {
192
+ name: call.name,
193
+ kind: "action",
194
+ ...spec !== void 0 ? {
195
+ spec
196
+ } : {}
197
+ },
198
+ thread: {
199
+ threadId: context.threadId,
200
+ runId: input.runId,
201
+ ...input.agentName !== void 0 ? {
202
+ agentName: input.agentName
203
+ } : {}
204
+ },
205
+ ...deps.approvalPolicy !== void 0 ? {
206
+ policy: deps.approvalPolicy
207
+ } : {}
208
+ });
209
+ }
210
+ if (call.actionApproval?.mode === "ask") {
211
+ call.prepared = await (0, import_nestjs_agent_core2.prepareActionProposal)(deps.registry, call.name, call.input, {
212
+ ...(0, import_nestjs_agent_core3.toolCallContext)(context, call.id),
213
+ emitUi: (0, import_nestjs_agent_core3.createNoopEmitUi)(call.id)
214
+ }, deps.rolesPolicy, allowedTools === void 0 ? {} : {
215
+ allowedTools
216
+ });
217
+ call.preflight = call.prepared.preflight;
218
+ } else {
219
+ call.preflight = await deps.registry.prepare(call.name, call.input, {
220
+ ...(0, import_nestjs_agent_core3.toolCallContext)(context, call.id),
221
+ emitUi: (0, import_nestjs_agent_core3.createNoopEmitUi)(call.id)
222
+ }, deps.rolesPolicy, allowedTools === void 0 ? {} : {
223
+ allowedTools
224
+ });
225
+ }
226
+ } catch (error) {
227
+ if ((0, import_nestjs_agent_core3.isControlFlowSignal)(error) || (0, import_nestjs_agent_core3.isReplayIntegrityError)(error)) throw error;
228
+ call.preflight = {
229
+ status: "failed",
230
+ error: error instanceof Error ? error.message : String(error)
231
+ };
232
+ }
233
+ }
161
234
  return buffer === void 0 ? stamped : {
162
235
  ...stamped,
163
236
  bufferedFrames: buffer.frames()
@@ -183,12 +256,12 @@ var AgentRunSteps = class {
183
256
  }
184
257
  const sinkRunId = input.sinkRunId;
185
258
  let opened;
186
- const ui = (0, import_nestjs_agent_core.createUiCollector)(input.toolCallId, sinkRunId === void 0 ? void 0 : async (event) => {
259
+ const ui = (0, import_nestjs_agent_core.createNegotiatedUiCollector)(input.toolCallId, input.ctx, deps.resolveUiCatalog, sinkRunId === void 0 ? void 0 : async (event) => {
187
260
  opened ??= Promise.resolve(deps.sink.open(sinkRunId)).then((writer) => input.childSink === true ? childSinkWriter(writer) : writer);
188
- await (await opened).write((0, import_nestjs_agent_core.encodeStreamEvent)(event));
261
+ await (await opened).write((0, import_nestjs_agent_core3.encodeStreamEvent)(event));
189
262
  });
190
263
  const ctx = {
191
- ...(0, import_nestjs_agent_core.toolCallContext)(input.ctx, input.toolCallId),
264
+ ...(0, import_nestjs_agent_core3.toolCallContext)(input.ctx, input.toolCallId),
192
265
  emitUi: ui.emit
193
266
  };
194
267
  const localClassify = deps.toolTransientRetry !== false ? deps.toolTransientRetry?.classify : void 0;
@@ -199,25 +272,38 @@ var AgentRunSteps = class {
199
272
  classify: localClassify
200
273
  } : {}
201
274
  };
202
- const output = await (0, import_nestjs_agent_core.traceToolExecution)(input.ctx.runId, {
203
- toolCallId: input.toolCallId,
204
- toolName: input.toolName,
205
- toolType: input.toolType
206
- }, () => (0, import_nestjs_agent_core.invokeWithTransientRetry)(() => {
207
- ui.restart();
208
- const invocation = deps.registry.invoke(input.toolName, input.input, ctx, deps.rolesPolicy);
209
- return input.timeoutMs !== void 0 ? (0, import_nestjs_agent_core.withToolTimeout)(invocation, input.timeoutMs, input.toolName) : invocation;
210
- }, transientRetry, {
211
- onRetry: /* @__PURE__ */ __name((attempt, error) => {
212
- (0, import_nestjs_agent_core.publishAgentToolRetry)({
213
- toolName: input.toolName,
214
- toolCallId: input.toolCallId,
215
- attempt,
216
- message: error instanceof Error ? error.message : String(error)
275
+ const allowedTools = (0, import_nestjs_agent_core3.intersectAllowLists)(deps.toolAllowList, input.allowedTools === void 0 ? void 0 : [
276
+ ...input.allowedTools
277
+ ]);
278
+ let output;
279
+ try {
280
+ output = await (0, import_nestjs_agent_core3.traceToolExecution)(input.ctx.runId, {
281
+ toolCallId: input.toolCallId,
282
+ toolName: input.toolName,
283
+ toolType: input.toolType
284
+ }, () => (0, import_nestjs_agent_core3.invokeWithTransientRetry)(() => {
285
+ ui.restart();
286
+ const invocation = deps.registry.invoke(input.toolName, input.input, ctx, deps.rolesPolicy, allowedTools === void 0 ? {} : {
287
+ allowedTools
217
288
  });
218
- }, "onRetry")
219
- }));
220
- return input.collectUi === true ? (0, import_nestjs_agent_core.wrapToolStepOutput)(output, ui.components()) : output;
289
+ return input.timeoutMs !== void 0 ? (0, import_nestjs_agent_core3.withToolTimeout)(invocation, input.timeoutMs, input.toolName) : invocation;
290
+ }, transientRetry, {
291
+ onRetry: /* @__PURE__ */ __name((attempt, error) => {
292
+ (0, import_nestjs_agent_core3.publishAgentToolRetry)({
293
+ toolName: input.toolName,
294
+ toolCallId: input.toolCallId,
295
+ attempt,
296
+ message: error instanceof Error ? error.message : String(error)
297
+ });
298
+ }, "onRetry")
299
+ }));
300
+ } catch (error) {
301
+ if (error instanceof Error && error.name === "ToolPreflightDeniedError") {
302
+ return (0, import_nestjs_agent_core3.wrapToolPreflightDenied)(error.message);
303
+ }
304
+ throw error;
305
+ }
306
+ return input.collectUi === true ? (0, import_nestjs_agent_core3.wrapToolStepOutput)(output, ui.components(), ui.text()) : output;
221
307
  }
222
308
  };
223
309
  _ts_decorate([
@@ -240,7 +326,7 @@ _ts_decorate([
240
326
  ], AgentRunSteps.prototype, "tool", null);
241
327
  AgentRunSteps = _ts_decorate([
242
328
  (0, import_common.Injectable)(),
243
- _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_DEPS_FACTORY)),
329
+ _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core3.AGENT_DEPS_FACTORY)),
244
330
  _ts_metadata("design:type", Function),
245
331
  _ts_metadata("design:paramtypes", [
246
332
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
@@ -424,7 +510,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
424
510
  if (delivery === void 0) {
425
511
  return;
426
512
  }
427
- await stepOf(ctx)("deliver:detached:unsettled", () => (0, import_nestjs_agent_core2.settleUnsettledDelegation)({
513
+ await stepOf(ctx)("deliver:detached:unsettled", () => (0, import_nestjs_agent_core4.settleUnsettledDelegation)({
428
514
  store: this.store,
429
515
  delivery,
430
516
  agent: input.agentName ?? "default",
@@ -465,7 +551,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
465
551
  end: /* @__PURE__ */ __name(async () => {
466
552
  const frame = await this.advanceQueue(ctx, input, "completed");
467
553
  if (frame !== void 0) {
468
- await writer.write((0, import_nestjs_agent_core2.encodeStreamEvent)(frame));
554
+ await writer.write((0, import_nestjs_agent_core4.encodeStreamEvent)(frame));
469
555
  }
470
556
  await writer.end();
471
557
  }, "end")
@@ -497,7 +583,7 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
497
583
  // await, so launching a batch in one tick — what `settleAll` does — fixes the block of
498
584
  // positions in call order however the tools then settle. `ctx.patched` keeps a run that
499
585
  // recorded the one-call-at-a-time shape replaying against that shape.
500
- parallel: import_nestjs_agent_core2.settleAll,
586
+ parallel: import_nestjs_agent_core4.settleAll,
501
587
  cancelled: /* @__PURE__ */ __name(() => this.isCancelled(ctx.runId), "cancelled"),
502
588
  patched: /* @__PURE__ */ __name((id) => ctx.patched(id), "patched"),
503
589
  // Dispatched-step suspends must escape the loop's tool catch — control flow, not a tool
@@ -600,33 +686,33 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
600
686
  } : {}
601
687
  };
602
688
  try {
603
- const result = await (0, import_nestjs_agent_core2.runAgentLoop)({
689
+ const result = await (0, import_nestjs_agent_core4.runAgentLoop)({
604
690
  ...deps,
605
691
  day
606
692
  }, input, hooks);
607
- await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core2.releaseThreadRun)(this.store, input.threadId, ctx.runId));
693
+ await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core4.releaseThreadRun)(this.store, input.threadId, ctx.runId));
608
694
  return result;
609
695
  } catch (error) {
610
696
  if ((0, import_nestjs_durable_core2.isWorkflowControlFlowSignal)(error)) {
611
697
  throw error;
612
698
  }
613
- if (error instanceof import_nestjs_agent_core2.RunCancelledError) {
614
- await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core2.releaseThreadRun)(this.store, input.threadId, ctx.runId));
699
+ if (error instanceof import_nestjs_agent_core4.RunCancelledError) {
700
+ await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core4.releaseThreadRun)(this.store, input.threadId, ctx.runId));
615
701
  await this.settleDetachedParent(ctx, input, {
616
702
  status: "cancelled"
617
703
  });
618
704
  throw error;
619
705
  }
620
- if ((0, import_nestjs_agent_core2.isReplayIntegrityError)(error)) {
706
+ if ((0, import_nestjs_agent_core4.isReplayIntegrityError)(error)) {
621
707
  const detail = error.message;
622
- const code2 = (0, import_nestjs_agent_core2.agentFailureCode)(error);
708
+ const code2 = (0, import_nestjs_agent_core4.agentFailureCode)(error);
623
709
  this.logger.error(`agent run ${ctx.runId} failed (${code2}): ${detail}`);
624
- (0, import_nestjs_agent_core2.publishAgentRunFailed)({
710
+ (0, import_nestjs_agent_core4.publishAgentRunFailed)({
625
711
  runId: ctx.runId,
626
712
  code: code2,
627
713
  message: detail
628
714
  });
629
- await (0, import_nestjs_agent_core2.settleDeadRun)(this.store, {
715
+ await (0, import_nestjs_agent_core4.settleDeadRun)(this.store, {
630
716
  runId: ctx.runId,
631
717
  threadId: input.threadId,
632
718
  failure: {
@@ -634,13 +720,13 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
634
720
  message: detail
635
721
  }
636
722
  });
637
- await (await hooks.openSink()).fail((0, import_nestjs_agent_core2.streamFailure)(error));
723
+ await (await hooks.openSink()).fail((0, import_nestjs_agent_core4.streamFailure)(error));
638
724
  throw error;
639
725
  }
640
726
  const message = error instanceof Error ? error.message : String(error);
641
- const code = (0, import_nestjs_agent_core2.agentFailureCode)(error);
727
+ const code = (0, import_nestjs_agent_core4.agentFailureCode)(error);
642
728
  this.logger.error(`agent run ${ctx.runId} failed (${code}): ${message}`);
643
- (0, import_nestjs_agent_core2.publishAgentRunFailed)({
729
+ (0, import_nestjs_agent_core4.publishAgentRunFailed)({
644
730
  runId: ctx.runId,
645
731
  code,
646
732
  message
@@ -652,19 +738,19 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
652
738
  errorCode: code,
653
739
  errorMessage: message
654
740
  });
655
- await Promise.resolve(this.store.failUnsettledToolCalls?.(ctx.runId, import_nestjs_agent_core2.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
741
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(ctx.runId, import_nestjs_agent_core4.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
656
742
  });
657
743
  const queueFrame2 = await this.advanceQueue(ctx, input, "failed", message);
658
- await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core2.releaseThreadRun)(this.store, input.threadId, ctx.runId));
744
+ await stepOf(ctx)("deactivate", () => (0, import_nestjs_agent_core4.releaseThreadRun)(this.store, input.threadId, ctx.runId));
659
745
  await this.settleDetachedParent(ctx, input, {
660
746
  status: "failed",
661
747
  error: message
662
748
  });
663
749
  const writer = await hooks.openSink();
664
750
  if (queueFrame2 !== void 0) {
665
- await writer.write((0, import_nestjs_agent_core2.encodeStreamEvent)(queueFrame2));
751
+ await writer.write((0, import_nestjs_agent_core4.encodeStreamEvent)(queueFrame2));
666
752
  }
667
- await writer.fail((0, import_nestjs_agent_core2.streamFailure)(error));
753
+ await writer.fail((0, import_nestjs_agent_core4.streamFailure)(error));
668
754
  throw error;
669
755
  }
670
756
  }
@@ -675,8 +761,8 @@ AgentRunWorkflow = _ts_decorate2([
675
761
  name: "agent.run",
676
762
  version: "1"
677
763
  }),
678
- _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_DEPS_FACTORY)),
679
- _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_STORE)),
764
+ _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core4.AGENT_DEPS_FACTORY)),
765
+ _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
680
766
  _ts_param2(2, (0, import_common2.Optional)()),
681
767
  _ts_param2(2, (0, import_common2.Inject)(import_nestjs_durable2.RUN_GATEWAY)),
682
768
  _ts_param2(3, (0, import_common2.Optional)()),
@@ -698,13 +784,13 @@ __name(isSignalTimeout, "isSignalTimeout");
698
784
 
699
785
  // src/durable/durable-agent-runner.ts
700
786
  var import_node_crypto = require("crypto");
701
- var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
787
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
702
788
  var import_nestjs_durable3 = require("@dudousxd/nestjs-durable");
703
789
  var import_nestjs_durable_core3 = require("@dudousxd/nestjs-durable-core");
704
790
  var import_common3 = require("@nestjs/common");
705
791
 
706
792
  // src/in-process-sink.ts
707
- var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
793
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
708
794
  var InProcessTokenStreamSink = class {
709
795
  static {
710
796
  __name(this, "InProcessTokenStreamSink");
@@ -759,7 +845,7 @@ var InProcessTokenStreamSink = class {
759
845
  }
760
846
  if (buf.ended) {
761
847
  if (buf.failure !== void 0) {
762
- throw new import_nestjs_agent_core3.AgentStreamError(buf.failure);
848
+ throw new import_nestjs_agent_core5.AgentStreamError(buf.failure);
763
849
  }
764
850
  return;
765
851
  }
@@ -924,15 +1010,15 @@ var DurableAgentRunner = class _DurableAgentRunner {
924
1010
  runId: nextRunId
925
1011
  }));
926
1012
  if (frame !== void 0) {
927
- await writer.write((0, import_nestjs_agent_core4.encodeStreamEvent)(frame));
1013
+ await writer.write((0, import_nestjs_agent_core6.encodeStreamEvent)(frame));
928
1014
  }
929
1015
  } catch (error) {
930
1016
  this.logger.error(`could not advance the queue of thread ${threadId} after cancelling ${runId}: ${error instanceof Error ? error.message : String(error)}`);
931
1017
  }
932
1018
  }
933
- await (0, import_nestjs_agent_core4.releaseThreadRun)(this.store, threadId, runId);
1019
+ await (0, import_nestjs_agent_core6.releaseThreadRun)(this.store, threadId, runId);
934
1020
  }
935
- await writer.write((0, import_nestjs_agent_core4.encodeStreamEvent)({
1021
+ await writer.write((0, import_nestjs_agent_core6.encodeStreamEvent)({
936
1022
  kind: "cancelled"
937
1023
  }));
938
1024
  await writer.end();
@@ -955,7 +1041,7 @@ var DurableAgentRunner = class _DurableAgentRunner {
955
1041
  return;
956
1042
  }
957
1043
  try {
958
- await (0, import_nestjs_agent_core4.settleUnsettledDelegation)({
1044
+ await (0, import_nestjs_agent_core6.settleUnsettledDelegation)({
959
1045
  store: this.store,
960
1046
  delivery: target.delivery,
961
1047
  agent: target.agent,
@@ -978,11 +1064,11 @@ var DurableAgentRunner = class _DurableAgentRunner {
978
1064
  }
979
1065
  const subThreadId = threadOfRun(child.run.input);
980
1066
  if (subThreadId !== void 0) {
981
- await (0, import_nestjs_agent_core4.releaseThreadRun)(this.store, subThreadId, childId);
1067
+ await (0, import_nestjs_agent_core6.releaseThreadRun)(this.store, subThreadId, childId);
982
1068
  }
983
1069
  await this.settleCancelledDelegation(childId, child.run.input);
984
1070
  const writer = await this.sink.open(childId);
985
- await writer.write((0, import_nestjs_agent_core4.encodeStreamEvent)({
1071
+ await writer.write((0, import_nestjs_agent_core6.encodeStreamEvent)({
986
1072
  kind: "cancelled"
987
1073
  }));
988
1074
  await writer.end();
@@ -1012,8 +1098,8 @@ var DurableAgentRunner = class _DurableAgentRunner {
1012
1098
  DurableAgentRunner = _ts_decorate3([
1013
1099
  (0, import_common3.Injectable)(),
1014
1100
  _ts_param3(1, (0, import_common3.Inject)(import_nestjs_durable3.RUN_GATEWAY)),
1015
- _ts_param3(2, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_STORE)),
1016
- _ts_param3(3, (0, import_common3.Inject)(import_nestjs_agent_core4.AGENT_SINK)),
1101
+ _ts_param3(2, (0, import_common3.Inject)(import_nestjs_agent_core6.AGENT_STORE)),
1102
+ _ts_param3(3, (0, import_common3.Inject)(import_nestjs_agent_core6.AGENT_SINK)),
1017
1103
  _ts_param3(4, (0, import_common3.Optional)()),
1018
1104
  _ts_param3(4, (0, import_common3.Inject)(AGENT_CHAT_QUEUE)),
1019
1105
  _ts_metadata3("design:type", Function),
@@ -1027,7 +1113,7 @@ DurableAgentRunner = _ts_decorate3([
1027
1113
  ], DurableAgentRunner);
1028
1114
 
1029
1115
  // src/durable/agent-durable.module.ts
1030
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
1116
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
1031
1117
  var import_common4 = require("@nestjs/common");
1032
1118
  function _ts_decorate4(decorators, target, key, desc) {
1033
1119
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1047,7 +1133,7 @@ function runnerProviders() {
1047
1133
  return [
1048
1134
  DurableAgentRunner,
1049
1135
  {
1050
- provide: import_nestjs_agent_core5.AGENT_DURABLE_RUNNER,
1136
+ provide: import_nestjs_agent_core7.AGENT_DURABLE_RUNNER,
1051
1137
  useExisting: DurableAgentRunner
1052
1138
  }
1053
1139
  ];
@@ -1066,7 +1152,7 @@ AgentDurableHttpModule = _ts_decorate4([
1066
1152
  ...runnerProviders()
1067
1153
  ],
1068
1154
  exports: [
1069
- import_nestjs_agent_core5.AGENT_DURABLE_RUNNER,
1155
+ import_nestjs_agent_core7.AGENT_DURABLE_RUNNER,
1070
1156
  AgentRunWorkflow
1071
1157
  ]
1072
1158
  })
@@ -1105,7 +1191,7 @@ AgentDurableModule = _ts_decorate4([
1105
1191
  ...runnerProviders()
1106
1192
  ],
1107
1193
  exports: [
1108
- import_nestjs_agent_core5.AGENT_DURABLE_RUNNER,
1194
+ import_nestjs_agent_core7.AGENT_DURABLE_RUNNER,
1109
1195
  AgentRunWorkflow,
1110
1196
  AgentRunSteps
1111
1197
  ]
@@ -1113,14 +1199,44 @@ AgentDurableModule = _ts_decorate4([
1113
1199
  ], AgentDurableModule);
1114
1200
 
1115
1201
  // src/agent.module.ts
1116
- var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
1117
- var import_common27 = require("@nestjs/common");
1202
+ var import_nestjs_agent_core37 = require("@dudousxd/nestjs-agent-core");
1203
+ var import_common31 = require("@nestjs/common");
1118
1204
  var import_core4 = require("@nestjs/core");
1119
1205
 
1120
1206
  // src/agent-deps.factory.ts
1121
- var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
1122
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
1207
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1208
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1209
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1210
+ var import_common6 = require("@nestjs/common");
1211
+
1212
+ // src/genui/agent-genui.module.ts
1213
+ var import_genui = require("@dudousxd/nestjs-agent-core/genui");
1123
1214
  var import_common5 = require("@nestjs/common");
1215
+
1216
+ // src/functional-tool.ts
1217
+ var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
1218
+ function brand(tool) {
1219
+ return {
1220
+ [AGENT_TOOL_BRAND]: true,
1221
+ spec: tool.spec,
1222
+ handler: tool.handler
1223
+ };
1224
+ }
1225
+ __name(brand, "brand");
1226
+ function isBrandedFunctionalTool(value) {
1227
+ return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
1228
+ }
1229
+ __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
1230
+ function provideAgentTools(factory, inject) {
1231
+ return {
1232
+ provide: /* @__PURE__ */ Symbol("nestjs-agent:functional-tool-list"),
1233
+ useFactory: /* @__PURE__ */ __name(async (...deps) => (await factory(...deps)).map(brand), "useFactory"),
1234
+ inject: inject ?? []
1235
+ };
1236
+ }
1237
+ __name(provideAgentTools, "provideAgentTools");
1238
+
1239
+ // src/genui/agent-genui.module.ts
1124
1240
  function _ts_decorate5(decorators, target, key, desc) {
1125
1241
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1126
1242
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -1135,6 +1251,124 @@ function _ts_decorate5(decorators, target, key, desc) {
1135
1251
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1136
1252
  }
1137
1253
  __name(_ts_decorate5, "_ts_decorate");
1254
+ var GENUI_CATALOG = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-catalog");
1255
+ var GENUI_OPTIONS = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:genui-options");
1256
+ var GenuiCatalogResolver = class {
1257
+ static {
1258
+ __name(this, "GenuiCatalogResolver");
1259
+ }
1260
+ };
1261
+ function resolverProviders(resolver) {
1262
+ if (resolver === void 0) return [];
1263
+ return [
1264
+ typeof resolver === "function" ? {
1265
+ provide: GenuiCatalogResolver,
1266
+ useClass: resolver
1267
+ } : {
1268
+ provide: GenuiCatalogResolver,
1269
+ useValue: resolver
1270
+ }
1271
+ ];
1272
+ }
1273
+ __name(resolverProviders, "resolverProviders");
1274
+ function toolOptions(options, resolver) {
1275
+ const { catalog: _catalog, ...rest } = options;
1276
+ return {
1277
+ ...rest,
1278
+ ...resolver !== void 0 ? {
1279
+ resolveCatalog: /* @__PURE__ */ __name((scope) => resolver.resolve(scope), "resolveCatalog")
1280
+ } : {}
1281
+ };
1282
+ }
1283
+ __name(toolOptions, "toolOptions");
1284
+ function coreProviders(resolver) {
1285
+ return [
1286
+ {
1287
+ provide: GENUI_CATALOG,
1288
+ useFactory: /* @__PURE__ */ __name((options) => options.catalog ?? (0, import_genui.defineCatalog)([]), "useFactory"),
1289
+ inject: [
1290
+ GENUI_OPTIONS
1291
+ ]
1292
+ },
1293
+ ...resolverProviders(resolver),
1294
+ // The generated tools, registered by the agent module's discovery like any `provideAgentTool`.
1295
+ // Built from the injected catalog, so `overrideProvider(GENUI_CATALOG)` changes them too.
1296
+ provideAgentTools((options, catalog, perRequest) => (0, import_genui.genuiTools)(catalog, toolOptions(options, perRequest)), [
1297
+ GENUI_OPTIONS,
1298
+ GENUI_CATALOG,
1299
+ {
1300
+ token: GenuiCatalogResolver,
1301
+ optional: true
1302
+ }
1303
+ ])
1304
+ ];
1305
+ }
1306
+ __name(coreProviders, "coreProviders");
1307
+ var EXPORTS = [
1308
+ GENUI_CATALOG,
1309
+ GENUI_OPTIONS
1310
+ ];
1311
+ var AgentGenuiModule = class _AgentGenuiModule {
1312
+ static {
1313
+ __name(this, "AgentGenuiModule");
1314
+ }
1315
+ static forRoot(options = {}) {
1316
+ const { resolver, ...rest } = options;
1317
+ return {
1318
+ module: _AgentGenuiModule,
1319
+ global: true,
1320
+ providers: [
1321
+ {
1322
+ provide: GENUI_OPTIONS,
1323
+ useValue: rest
1324
+ },
1325
+ ...coreProviders(resolver)
1326
+ ],
1327
+ exports: resolver === void 0 ? EXPORTS : [
1328
+ ...EXPORTS,
1329
+ GenuiCatalogResolver
1330
+ ]
1331
+ };
1332
+ }
1333
+ static forRootAsync(options) {
1334
+ return {
1335
+ module: _AgentGenuiModule,
1336
+ global: true,
1337
+ imports: options.imports ?? [],
1338
+ providers: [
1339
+ {
1340
+ provide: GENUI_OPTIONS,
1341
+ useFactory: options.useFactory,
1342
+ inject: options.inject ?? []
1343
+ },
1344
+ ...coreProviders(options.resolver)
1345
+ ],
1346
+ exports: options.resolver === void 0 ? EXPORTS : [
1347
+ ...EXPORTS,
1348
+ GenuiCatalogResolver
1349
+ ]
1350
+ };
1351
+ }
1352
+ };
1353
+ AgentGenuiModule = _ts_decorate5([
1354
+ (0, import_common5.Module)({})
1355
+ ], AgentGenuiModule);
1356
+
1357
+ // src/agent-deps.factory.ts
1358
+ function _ts_decorate6(decorators, target, key, desc) {
1359
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1360
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1361
+ r = Reflect.decorate(decorators, target, key, desc);
1362
+ } else {
1363
+ for (var i = decorators.length - 1; i >= 0; i--) {
1364
+ if (d = decorators[i]) {
1365
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1366
+ }
1367
+ }
1368
+ }
1369
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1370
+ }
1371
+ __name(_ts_decorate6, "_ts_decorate");
1138
1372
  function _ts_metadata4(metadataKey, metadataValue) {
1139
1373
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1140
1374
  return Reflect.metadata(metadataKey, metadataValue);
@@ -1167,7 +1401,9 @@ var AgentDepsFactory2 = class {
1167
1401
  pricingStore;
1168
1402
  skills;
1169
1403
  memory;
1170
- constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory) {
1404
+ uiCatalog;
1405
+ uiCatalogResolver;
1406
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, promptContributors, pricingStore, skills, memory, uiCatalog, uiCatalogResolver) {
1171
1407
  this.options = options;
1172
1408
  this.model = model;
1173
1409
  this.store = store;
@@ -1179,6 +1415,9 @@ var AgentDepsFactory2 = class {
1179
1415
  this.pricingStore = pricingStore;
1180
1416
  this.skills = skills;
1181
1417
  this.memory = memory;
1418
+ this.uiCatalog = uiCatalog;
1419
+ this.uiCatalogResolver = uiCatalogResolver;
1420
+ if (options.actionApprovalMode === "independent") (0, import_nestjs_agent_core8.assertIndependentActionCapabilities)(store, options.backgroundActorResolver);
1182
1421
  }
1183
1422
  /** The turn's memory seam, shared with the read-back endpoint. Undefined → memory is not configured. */
1184
1423
  memoryConfig() {
@@ -1204,7 +1443,7 @@ var AgentDepsFactory2 = class {
1204
1443
  return void 0;
1205
1444
  }
1206
1445
  const delegated = (definition.delegatesTo ?? []).map((edge) => {
1207
- const { agent, detached } = (0, import_nestjs_agent_core6.normalizeDelegation)(edge);
1446
+ const { agent, detached } = (0, import_nestjs_agent_core9.normalizeDelegation)(edge);
1208
1447
  return delegateToolName({
1209
1448
  target: agent,
1210
1449
  detached
@@ -1218,8 +1457,76 @@ var AgentDepsFactory2 = class {
1218
1457
  ...delegated
1219
1458
  ];
1220
1459
  }
1460
+ /**
1461
+ * The agent a name stands for: itself when it is a registered agent (or unknown — the bare
1462
+ * assistant), else the agent whose persona took the name over (`Persona.aliases`) and that persona.
1463
+ */
1464
+ resolveAgent(name) {
1465
+ if (this.agents.has(name)) {
1466
+ return {
1467
+ agentName: name
1468
+ };
1469
+ }
1470
+ const alias = (0, import_nestjs_agent_core9.resolvePersonaAlias)(this.agents.list(), name);
1471
+ return alias === void 0 ? {
1472
+ agentName: name
1473
+ } : {
1474
+ agentName: alias.agent,
1475
+ persona: alias.persona
1476
+ };
1477
+ }
1478
+ /** `agentName`'s personas as a picker reads them. Empty when it declares none. */
1479
+ personaCatalog(agentName) {
1480
+ return (this.agents.get(agentName)?.personas ?? []).map(import_nestjs_agent_core9.personaCatalogEntry);
1481
+ }
1482
+ /** The persona `agentName` runs under when nothing names one. Undefined → none. */
1483
+ defaultPersona(agentName) {
1484
+ return this.agents.get(agentName)?.defaultPersona;
1485
+ }
1486
+ /**
1487
+ * The persona a turn of `agentName` runs under, most specific first: the one the send names
1488
+ * (refused with `400 persona_not_found` when the agent does not declare it), else the thread's
1489
+ * pinned one when this agent declares it, else the agent's default. Undefined → none.
1490
+ */
1491
+ resolvePersona(args) {
1492
+ const definition = this.agents.get(args.agentName);
1493
+ if (args.requested !== void 0) {
1494
+ if ((0, import_nestjs_agent_core9.findPersona)(definition, args.requested) === void 0) {
1495
+ throw new import_common6.BadRequestException({
1496
+ statusCode: 400,
1497
+ code: "persona_not_found",
1498
+ message: `agent "${args.agentName}" has no persona "${args.requested}"`
1499
+ });
1500
+ }
1501
+ return args.requested;
1502
+ }
1503
+ const pinned = args.threadPersona ?? void 0;
1504
+ if (pinned !== void 0 && (0, import_nestjs_agent_core9.findPersona)(definition, pinned) !== void 0) {
1505
+ return pinned;
1506
+ }
1507
+ return definition?.defaultPersona;
1508
+ }
1509
+ forProposal(proposal, _actor) {
1510
+ const name = proposal.executionContext?.agentName;
1511
+ 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`);
1512
+ const deps = this.forAgent(name);
1513
+ const id = proposal.executionContext?.persona;
1514
+ if (id !== void 0) {
1515
+ const persona = deps.personas?.find((persona2) => persona2.id === id);
1516
+ if (!persona) throw new Error(`Recorded persona ${id} no longer exists`);
1517
+ return this.withPersona(deps, persona);
1518
+ }
1519
+ return deps;
1520
+ }
1221
1521
  forAgent(agentName) {
1222
1522
  const name = agentName ?? this.defaultAgentName();
1523
+ if (agentName !== void 0 && !this.agents.has(agentName)) {
1524
+ const alias = (0, import_nestjs_agent_core9.resolvePersonaAlias)(this.agents.list(), agentName);
1525
+ const persona = alias === void 0 ? void 0 : (0, import_nestjs_agent_core9.findPersona)(this.agents.get(alias.agent), alias.persona);
1526
+ if (alias !== void 0 && persona !== void 0) {
1527
+ return this.withPersona(this.forAgent(alias.agent), persona);
1528
+ }
1529
+ }
1223
1530
  const definition = this.agents.get(name);
1224
1531
  const toolAllowList = this.effectiveTools(definition);
1225
1532
  const followUpsCount = this.followUpsCount();
@@ -1229,12 +1536,27 @@ var AgentDepsFactory2 = class {
1229
1536
  return {
1230
1537
  model: this.model,
1231
1538
  store: this.store,
1539
+ ...this.options.actionApprovalMode !== void 0 ? {
1540
+ actionApprovalMode: this.options.actionApprovalMode
1541
+ } : {},
1232
1542
  sink: this.sink,
1233
1543
  rolesPolicy: this.rolesPolicy,
1234
1544
  ...this.options.approvalPolicy !== void 0 ? {
1235
1545
  approvalPolicy: this.options.approvalPolicy
1236
1546
  } : {},
1237
1547
  registry: this.registry,
1548
+ ...this.uiCatalog !== void 0 || this.uiCatalogResolver !== void 0 ? {
1549
+ resolveUiCatalog: /* @__PURE__ */ __name((scope) => {
1550
+ const catalog = this.uiCatalogResolver?.resolve({
1551
+ ...scope,
1552
+ ...scope.actor.tenantRef !== void 0 ? {
1553
+ tenant: scope.actor.tenantRef
1554
+ } : {}
1555
+ }) ?? this.uiCatalog;
1556
+ if (!catalog) throw new Error("UI catalog unavailable");
1557
+ return catalog;
1558
+ }, "resolveUiCatalog")
1559
+ } : {},
1238
1560
  promptContributors: this.promptContributors,
1239
1561
  systemPrompt: definition?.systemPrompt ?? this.options.systemPrompt ?? "You are a helpful assistant.",
1240
1562
  maxSteps: definition?.maxSteps ?? 8,
@@ -1284,6 +1606,9 @@ var AgentDepsFactory2 = class {
1284
1606
  ...toolAllowList !== void 0 ? {
1285
1607
  toolAllowList
1286
1608
  } : {},
1609
+ ...definition?.personas !== void 0 ? {
1610
+ personas: definition.personas
1611
+ } : {},
1287
1612
  ...this.options.toolTimeoutMs !== void 0 ? {
1288
1613
  toolTimeoutMs: this.options.toolTimeoutMs
1289
1614
  } : {},
@@ -1302,6 +1627,45 @@ var AgentDepsFactory2 = class {
1302
1627
  };
1303
1628
  }
1304
1629
  /**
1630
+ * A persona baked into an agent's deps — how a run journaled under an agent name that a persona
1631
+ * has since taken over (`Persona.aliases`) is served. That run names no persona of its own (it
1632
+ * predates them, and its input cannot change), so the persona applies the way the old agent's own
1633
+ * config did: as config, re-read on every replay, with no checkpoint of its own.
1634
+ */
1635
+ withPersona(deps, persona) {
1636
+ const base = deps.systemPrompt;
1637
+ const ref = {
1638
+ id: persona.id,
1639
+ label: persona.label
1640
+ };
1641
+ const resolve = /* @__PURE__ */ __name(async (prompt, ctx) => typeof prompt === "function" ? prompt(ctx) : prompt, "resolve");
1642
+ const own = persona.systemPrompt;
1643
+ const systemPrompt = /* @__PURE__ */ __name(async (ctx) => {
1644
+ const scoped = {
1645
+ ...ctx,
1646
+ persona: ref
1647
+ };
1648
+ if (own === void 0) {
1649
+ return resolve(base, scoped);
1650
+ }
1651
+ const basePrompt = typeof own === "function" ? await resolve(base, scoped) : void 0;
1652
+ return resolve(own, {
1653
+ ...scoped,
1654
+ ...basePrompt !== void 0 ? {
1655
+ basePrompt
1656
+ } : {}
1657
+ });
1658
+ }, "systemPrompt");
1659
+ const toolAllowList = (0, import_nestjs_agent_core9.intersectAllowLists)(deps.toolAllowList, persona.allowedTools);
1660
+ return {
1661
+ ...deps,
1662
+ systemPrompt,
1663
+ ...toolAllowList !== void 0 ? {
1664
+ toolAllowList
1665
+ } : {}
1666
+ };
1667
+ }
1668
+ /**
1305
1669
  * The ceiling on how much of a thread this agent's turns carry, most specific wins: the agent's
1306
1670
  * own `@Agent({ history })`, else a module-wide custom `historyPolicy`, else the module-wide
1307
1671
  * `history` window. Undefined → unbounded, the behaviour of a module that configures none.
@@ -1317,7 +1681,7 @@ var AgentDepsFactory2 = class {
1317
1681
  }
1318
1682
  /** Build the built-in window policy from the declarative `{ maxMessages, maxTokens, summarize }`. */
1319
1683
  window(config) {
1320
- return (0, import_nestjs_agent_core6.windowHistory)({
1684
+ return (0, import_nestjs_agent_core9.windowHistory)({
1321
1685
  ...config.maxMessages !== void 0 ? {
1322
1686
  maxMessages: config.maxMessages
1323
1687
  } : {},
@@ -1327,7 +1691,7 @@ var AgentDepsFactory2 = class {
1327
1691
  // The shared module model, not a per-agent one: an agent's `modelId` is an accounting label,
1328
1692
  // and only one provider is ever bound.
1329
1693
  ...config.summarize === true ? {
1330
- summarize: (0, import_nestjs_agent_core6.summarizeWithModel)(this.model)
1694
+ summarize: (0, import_nestjs_agent_core9.summarizeWithModel)(this.model)
1331
1695
  } : {}
1332
1696
  });
1333
1697
  }
@@ -1343,22 +1707,25 @@ var AgentDepsFactory2 = class {
1343
1707
  return void 0;
1344
1708
  }
1345
1709
  };
1346
- AgentDepsFactory2 = _ts_decorate5([
1347
- (0, import_common5.Injectable)(),
1348
- _ts_param4(0, (0, import_common5.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
1349
- _ts_param4(1, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_MODEL)),
1350
- _ts_param4(2, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_STORE)),
1351
- _ts_param4(3, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_SINK)),
1352
- _ts_param4(4, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_ROLES_POLICY)),
1353
- _ts_param4(5, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_TOOL_REGISTRY)),
1354
- _ts_param4(6, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_REGISTRY)),
1355
- _ts_param4(7, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_PROMPT_CONTRIBUTORS)),
1356
- _ts_param4(8, (0, import_common5.Optional)()),
1357
- _ts_param4(8, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_PRICING_STORE)),
1358
- _ts_param4(9, (0, import_common5.Optional)()),
1359
- _ts_param4(9, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_SKILLS)),
1360
- _ts_param4(10, (0, import_common5.Optional)()),
1361
- _ts_param4(10, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_MEMORY)),
1710
+ AgentDepsFactory2 = _ts_decorate6([
1711
+ (0, import_common6.Injectable)(),
1712
+ _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core10.AGENT_OPTIONS)),
1713
+ _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_MODEL)),
1714
+ _ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_STORE)),
1715
+ _ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_SINK)),
1716
+ _ts_param4(4, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_ROLES_POLICY)),
1717
+ _ts_param4(5, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_TOOL_REGISTRY)),
1718
+ _ts_param4(6, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_REGISTRY)),
1719
+ _ts_param4(7, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_PROMPT_CONTRIBUTORS)),
1720
+ _ts_param4(8, (0, import_common6.Optional)()),
1721
+ _ts_param4(8, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_PRICING_STORE)),
1722
+ _ts_param4(9, (0, import_common6.Optional)()),
1723
+ _ts_param4(9, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_SKILLS)),
1724
+ _ts_param4(10, (0, import_common6.Optional)()),
1725
+ _ts_param4(10, (0, import_common6.Inject)(import_nestjs_agent_core9.AGENT_MEMORY)),
1726
+ _ts_param4(11, (0, import_common6.Optional)()),
1727
+ _ts_param4(11, (0, import_common6.Inject)(GENUI_CATALOG)),
1728
+ _ts_param4(12, (0, import_common6.Optional)()),
1362
1729
  _ts_metadata4("design:type", Function),
1363
1730
  _ts_metadata4("design:paramtypes", [
1364
1731
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
@@ -1366,23 +1733,25 @@ AgentDepsFactory2 = _ts_decorate5([
1366
1733
  typeof AgentStore === "undefined" ? Object : AgentStore,
1367
1734
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
1368
1735
  typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
1369
- typeof import_nestjs_agent_core6.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core6.ToolRegistry,
1370
- typeof import_nestjs_agent_core6.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core6.AgentRegistry,
1736
+ typeof import_nestjs_agent_core9.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core9.ToolRegistry,
1737
+ typeof import_nestjs_agent_core9.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core9.AgentRegistry,
1371
1738
  Array,
1372
1739
  Object,
1373
1740
  Object,
1374
- Object
1741
+ Object,
1742
+ typeof Catalog === "undefined" ? Object : Catalog,
1743
+ typeof GenuiCatalogResolver === "undefined" ? Object : GenuiCatalogResolver
1375
1744
  ])
1376
1745
  ], AgentDepsFactory2);
1377
1746
 
1378
1747
  // src/agent.service.ts
1379
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1380
- var import_common8 = require("@nestjs/common");
1748
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
1749
+ var import_common10 = require("@nestjs/common");
1381
1750
 
1382
- // src/queue/chat-queue.service.ts
1383
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
1384
- var import_common6 = require("@nestjs/common");
1385
- function _ts_decorate6(decorators, target, key, desc) {
1751
+ // src/proposals/action-proposal.service.ts
1752
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
1753
+ var import_common7 = require("@nestjs/common");
1754
+ function _ts_decorate7(decorators, target, key, desc) {
1386
1755
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1387
1756
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1388
1757
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1395,7 +1764,7 @@ function _ts_decorate6(decorators, target, key, desc) {
1395
1764
  }
1396
1765
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1397
1766
  }
1398
- __name(_ts_decorate6, "_ts_decorate");
1767
+ __name(_ts_decorate7, "_ts_decorate");
1399
1768
  function _ts_metadata5(metadataKey, metadataValue) {
1400
1769
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1401
1770
  return Reflect.metadata(metadataKey, metadataValue);
@@ -1408,6 +1777,168 @@ function _ts_param5(paramIndex, decorator) {
1408
1777
  };
1409
1778
  }
1410
1779
  __name(_ts_param5, "_ts_param");
1780
+ var ActionProposalService = class {
1781
+ static {
1782
+ __name(this, "ActionProposalService");
1783
+ }
1784
+ store;
1785
+ options;
1786
+ constructor(store, options) {
1787
+ this.store = store;
1788
+ this.options = options;
1789
+ }
1790
+ capability() {
1791
+ const store = this.store;
1792
+ if (typeof store.getThreadActionProposalScope !== "function" || typeof store.listActionProposals !== "function") throw new import_common7.NotImplementedException("Action proposals are unavailable");
1793
+ return store;
1794
+ }
1795
+ async scope(threadId, actor) {
1796
+ const scope = await this.capability().getThreadActionProposalScope(threadId);
1797
+ if (!scope) throw new import_common7.NotFoundException("Thread not found");
1798
+ if (scope.tenantRef !== (actor.tenantRef ?? null)) throw new import_common7.ForbiddenException("Wrong proposal tenant");
1799
+ return scope;
1800
+ }
1801
+ mayDecide(actor, proposal) {
1802
+ return (0, import_nestjs_agent_core11.mayDecideApproval)(this.options.approvalPolicy, actor, {
1803
+ toolCallId: proposal.originToolCallId,
1804
+ approver: proposal.approver,
1805
+ requesterRef: proposal.actorRef
1806
+ });
1807
+ }
1808
+ async listPage(threadId, actor, query = {}) {
1809
+ const scope = await this.scope(threadId, actor);
1810
+ const rows = await this.capability().listActionProposals(scope, {
1811
+ limit: 1e3,
1812
+ ...query
1813
+ });
1814
+ const visible = [];
1815
+ for (const row of rows) if (scope.actorRef === actor.id || await this.mayDecide(actor, row)) visible.push(row);
1816
+ const last = rows.at(-1);
1817
+ return {
1818
+ items: visible,
1819
+ ...rows.length === 1e3 && last ? {
1820
+ next: {
1821
+ createdAt: last.createdAt,
1822
+ id: last.id
1823
+ }
1824
+ } : {}
1825
+ };
1826
+ }
1827
+ async list(threadId, actor) {
1828
+ return (await this.listPage(threadId, actor)).items;
1829
+ }
1830
+ async decide(threadId, proposalId, actor, command) {
1831
+ const scope = await this.scope(threadId, actor);
1832
+ const proposal = await this.capability().getActionProposal(scope, proposalId);
1833
+ if (!proposal) throw new import_common7.NotFoundException("Proposal not found");
1834
+ if (!await this.mayDecide(actor, proposal)) throw new import_common7.ForbiddenException("May not decide this proposal");
1835
+ return this.capability().decideActionProposal(scope, proposalId, {
1836
+ decision: command.decision,
1837
+ actorRef: actor.id,
1838
+ via: command.via ?? "web",
1839
+ ...command.remember !== void 0 ? {
1840
+ remember: command.remember
1841
+ } : {},
1842
+ ...command.reason !== void 0 ? {
1843
+ reason: command.reason
1844
+ } : {}
1845
+ });
1846
+ }
1847
+ async handleTextDecision(threadId, actor, text) {
1848
+ const command = (0, import_nestjs_agent_core11.parseTextActionProposalCommand)(text);
1849
+ if (command.status === "unmatched") return command;
1850
+ if (command.proposalId !== void 0) {
1851
+ const result2 = await this.decide(threadId, command.proposalId, actor, {
1852
+ decision: command.decision,
1853
+ remember: command.remember,
1854
+ via: "text"
1855
+ });
1856
+ return this.textReceipt(threadId, result2);
1857
+ }
1858
+ const candidates = [];
1859
+ const scope = await this.scope(threadId, actor);
1860
+ const pending = await this.capability().listActionProposals(scope, {
1861
+ decision: "pending",
1862
+ limit: 1e3
1863
+ });
1864
+ for (const proposal of pending) if (await this.mayDecide(actor, proposal)) candidates.push(proposal);
1865
+ const resolution = (0, import_nestjs_agent_core11.resolveTextActionProposalDecision)(text, candidates);
1866
+ if (resolution.status === "unmatched") return resolution;
1867
+ if (resolution.status === "ambiguous" || resolution.status === "decision" && pending.length === 1e3 && !text.includes("#")) return {
1868
+ threadId,
1869
+ proposalDecision: {
1870
+ status: "ambiguous",
1871
+ proposalIds: candidates.map(({ id }) => id)
1872
+ },
1873
+ text: `Choose the action to decide: ${candidates.map(({ id }) => id).map((id) => `#${id}`).join(", ")}`
1874
+ };
1875
+ const result = await this.decide(threadId, resolution.proposalId, actor, {
1876
+ decision: resolution.decision,
1877
+ remember: resolution.remember,
1878
+ via: "text"
1879
+ });
1880
+ return this.textReceipt(threadId, result);
1881
+ }
1882
+ textReceipt(threadId, result) {
1883
+ return {
1884
+ threadId,
1885
+ proposalDecision: result,
1886
+ text: result.proposal?.decision === "approved" ? "Action approved and queued for execution." : `Action ${result.proposal?.decision ?? result.status}; no execution was performed by this decision.`
1887
+ };
1888
+ }
1889
+ };
1890
+ ActionProposalService = _ts_decorate7([
1891
+ (0, import_common7.Injectable)(),
1892
+ _ts_param5(0, (0, import_common7.Inject)(import_nestjs_agent_core11.AGENT_STORE)),
1893
+ _ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core11.AGENT_OPTIONS)),
1894
+ _ts_metadata5("design:type", Function),
1895
+ _ts_metadata5("design:paramtypes", [
1896
+ typeof AgentStore === "undefined" ? Object : AgentStore,
1897
+ typeof Pick === "undefined" ? Object : Pick
1898
+ ])
1899
+ ], ActionProposalService);
1900
+
1901
+ // src/queue/chat-queue.service.ts
1902
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
1903
+ var import_common8 = require("@nestjs/common");
1904
+
1905
+ // src/thread-persona.ts
1906
+ async function threadPersona(store, threadId) {
1907
+ const projecting = store;
1908
+ if (typeof projecting.personaForThread === "function") {
1909
+ return projecting.personaForThread(threadId);
1910
+ }
1911
+ return (await store.getThread(threadId))?.persona ?? null;
1912
+ }
1913
+ __name(threadPersona, "threadPersona");
1914
+
1915
+ // src/queue/chat-queue.service.ts
1916
+ function _ts_decorate8(decorators, target, key, desc) {
1917
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1918
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1919
+ r = Reflect.decorate(decorators, target, key, desc);
1920
+ } else {
1921
+ for (var i = decorators.length - 1; i >= 0; i--) {
1922
+ if (d = decorators[i]) {
1923
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1924
+ }
1925
+ }
1926
+ }
1927
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1928
+ }
1929
+ __name(_ts_decorate8, "_ts_decorate");
1930
+ function _ts_metadata6(metadataKey, metadataValue) {
1931
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1932
+ return Reflect.metadata(metadataKey, metadataValue);
1933
+ }
1934
+ }
1935
+ __name(_ts_metadata6, "_ts_metadata");
1936
+ function _ts_param6(paramIndex, decorator) {
1937
+ return function(target, key) {
1938
+ decorator(target, key, paramIndex);
1939
+ };
1940
+ }
1941
+ __name(_ts_param6, "_ts_param");
1411
1942
  var MAX_DRAIN_ATTEMPTS = 8;
1412
1943
  var ChatQueueService2 = class _ChatQueueService {
1413
1944
  static {
@@ -1418,27 +1949,29 @@ var ChatQueueService2 = class _ChatQueueService {
1418
1949
  quotaProvider;
1419
1950
  options;
1420
1951
  staging;
1421
- logger = new import_common6.Logger(_ChatQueueService.name);
1952
+ deps;
1953
+ logger = new import_common8.Logger(_ChatQueueService.name);
1422
1954
  /**
1423
1955
  * Runs this process claimed a thread for and has not handed to a runner yet. A holder in here is
1424
1956
  * alive whatever the runner says — it simply has not registered the run yet.
1425
1957
  */
1426
1958
  starting = /* @__PURE__ */ new Set();
1427
- constructor(store, sink, quotaProvider, options, staging) {
1959
+ constructor(store, sink, quotaProvider, options, staging, deps) {
1428
1960
  this.store = store;
1429
1961
  this.sink = sink;
1430
1962
  this.quotaProvider = quotaProvider;
1431
1963
  this.options = options;
1432
1964
  this.staging = staging;
1965
+ this.deps = deps;
1433
1966
  }
1434
1967
  /** Whether the bound store can hold a queue. Without one, a busy thread is not queued. */
1435
1968
  get supported() {
1436
- return (0, import_nestjs_agent_core8.isChatQueueStore)(this.store);
1969
+ return (0, import_nestjs_agent_core12.isChatQueueStore)(this.store);
1437
1970
  }
1438
1971
  /** The bound store as a queue store, or a 501 naming what is missing. */
1439
1972
  queueStore() {
1440
- if (!(0, import_nestjs_agent_core8.isChatQueueStore)(this.store)) {
1441
- throw new import_common6.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
1973
+ if (!(0, import_nestjs_agent_core12.isChatQueueStore)(this.store)) {
1974
+ throw new import_common8.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore (enqueueMessage, listQueue, \u2026, claimActiveStream, releaseActiveStream); the bound store does not.");
1442
1975
  }
1443
1976
  return this.store;
1444
1977
  }
@@ -1449,7 +1982,7 @@ var ChatQueueService2 = class _ChatQueueService {
1449
1982
  store.queuePause(threadId)
1450
1983
  ]);
1451
1984
  return {
1452
- items: items.map(import_nestjs_agent_core8.queuedMessageView),
1985
+ items: items.map(import_nestjs_agent_core12.queuedMessageView),
1453
1986
  paused
1454
1987
  };
1455
1988
  }
@@ -1500,7 +2033,7 @@ var ChatQueueService2 = class _ChatQueueService {
1500
2033
  * A no-op returning `{}` on a store without a queue.
1501
2034
  */
1502
2035
  async plan(args) {
1503
- if (!(0, import_nestjs_agent_core8.isChatQueueStore)(this.store)) {
2036
+ if (!(0, import_nestjs_agent_core12.isChatQueueStore)(this.store)) {
1504
2037
  return {};
1505
2038
  }
1506
2039
  const store = this.store;
@@ -1600,7 +2133,7 @@ var ChatQueueService2 = class _ChatQueueService {
1600
2133
  * (its settle drains) or while the queue is paused. Answers the started run's id, if any.
1601
2134
  */
1602
2135
  async kick(threadId, runner) {
1603
- if (!(0, import_nestjs_agent_core8.isChatQueueStore)(this.store)) {
2136
+ if (!(0, import_nestjs_agent_core12.isChatQueueStore)(this.store)) {
1604
2137
  return void 0;
1605
2138
  }
1606
2139
  const { live, stale } = await this.holder(threadId, runner);
@@ -1665,6 +2198,9 @@ var ChatQueueService2 = class _ChatQueueService {
1665
2198
  } : {},
1666
2199
  ...input.pageContext !== void 0 ? {
1667
2200
  pageContext: input.pageContext
2201
+ } : {},
2202
+ ...input.uiCapabilities !== void 0 ? {
2203
+ uiCapabilities: input.uiCapabilities
1668
2204
  } : {}
1669
2205
  });
1670
2206
  await store.setQueuePause(threadId, {
@@ -1701,7 +2237,7 @@ var ChatQueueService2 = class _ChatQueueService {
1701
2237
  }
1702
2238
  async write(runId, frame) {
1703
2239
  const writer = await this.sink.open(runId);
1704
- await writer.write((0, import_nestjs_agent_core8.encodeStreamEvent)(frame));
2240
+ await writer.write((0, import_nestjs_agent_core12.encodeStreamEvent)(frame));
1705
2241
  }
1706
2242
  /** Why `actor` may not start a turn now (the quota message), or `null`. */
1707
2243
  async quotaBlock(actor) {
@@ -1727,13 +2263,17 @@ var ChatQueueService2 = class _ChatQueueService {
1727
2263
  */
1728
2264
  async inputFor(message) {
1729
2265
  const attachments = await this.freshAttachments(message.actor, message.attachments ?? []);
2266
+ const { agentName, persona } = await this.targetFor(message);
1730
2267
  return {
1731
2268
  threadId: message.threadId,
1732
2269
  actor: message.actor,
1733
2270
  userText: message.content,
1734
2271
  day: utcDay(),
1735
- ...message.agentName !== void 0 ? {
1736
- agentName: message.agentName
2272
+ ...agentName !== void 0 ? {
2273
+ agentName
2274
+ } : {},
2275
+ ...persona !== void 0 ? {
2276
+ persona
1737
2277
  } : {},
1738
2278
  ...attachments.length > 0 ? {
1739
2279
  attachments
@@ -1741,13 +2281,47 @@ var ChatQueueService2 = class _ChatQueueService {
1741
2281
  ...message.pageContext !== void 0 ? {
1742
2282
  pageContext: message.pageContext
1743
2283
  } : {},
2284
+ ...message.uiCapabilities !== void 0 ? {
2285
+ uiCapabilities: message.uiCapabilities
2286
+ } : {},
1744
2287
  ...message.model !== void 0 ? {
1745
2288
  model: message.model
1746
2289
  } : {}
1747
2290
  };
1748
2291
  }
1749
- async freshAttachments(actor, attachments) {
1750
- const staging = this.staging;
2292
+ /**
2293
+ * The agent and persona a queued message starts as. A message carries the persona its send
2294
+ * resolved; one that carries none — queued before personas existed, or by a host that sets none —
2295
+ * resolves it now, exactly as a send would: an agent name a persona took over, then the thread's
2296
+ * pinned persona, then the agent's default. Never refused here: nobody is waiting on a 400.
2297
+ */
2298
+ async targetFor(message) {
2299
+ const deps = this.deps;
2300
+ if (message.persona !== void 0 || deps === void 0 || message.agentName === void 0) {
2301
+ return {
2302
+ ...message.agentName !== void 0 ? {
2303
+ agentName: message.agentName
2304
+ } : {},
2305
+ ...message.persona !== void 0 ? {
2306
+ persona: message.persona
2307
+ } : {}
2308
+ };
2309
+ }
2310
+ const target = deps.resolveAgent(message.agentName);
2311
+ const hasPersonas = deps.personaCatalog(target.agentName).length > 0;
2312
+ const persona = target.persona ?? (hasPersonas ? deps.resolvePersona({
2313
+ agentName: target.agentName,
2314
+ threadPersona: await threadPersona(this.store, message.threadId)
2315
+ }) : void 0);
2316
+ return {
2317
+ agentName: target.agentName,
2318
+ ...persona !== void 0 ? {
2319
+ persona
2320
+ } : {}
2321
+ };
2322
+ }
2323
+ async freshAttachments(actor, attachments) {
2324
+ const staging = this.staging;
1751
2325
  if (attachments.length === 0 || staging === void 0 || typeof staging.resolve !== "function") {
1752
2326
  return attachments;
1753
2327
  }
@@ -1763,23 +2337,26 @@ var ChatQueueService2 = class _ChatQueueService {
1763
2337
  }));
1764
2338
  }
1765
2339
  };
1766
- ChatQueueService2 = _ts_decorate6([
1767
- (0, import_common6.Injectable)(),
1768
- _ts_param5(0, (0, import_common6.Inject)(import_nestjs_agent_core8.AGENT_STORE)),
1769
- _ts_param5(1, (0, import_common6.Inject)(import_nestjs_agent_core8.AGENT_SINK)),
1770
- _ts_param5(2, (0, import_common6.Optional)()),
1771
- _ts_param5(2, (0, import_common6.Inject)(import_nestjs_agent_core8.AGENT_QUOTA_PROVIDER)),
1772
- _ts_param5(3, (0, import_common6.Optional)()),
1773
- _ts_param5(3, (0, import_common6.Inject)(import_nestjs_agent_core8.AGENT_OPTIONS)),
1774
- _ts_param5(4, (0, import_common6.Optional)()),
1775
- _ts_param5(4, (0, import_common6.Inject)(import_nestjs_agent_core8.AGENT_ATTACHMENT_STAGING)),
1776
- _ts_metadata5("design:type", Function),
1777
- _ts_metadata5("design:paramtypes", [
2340
+ ChatQueueService2 = _ts_decorate8([
2341
+ (0, import_common8.Injectable)(),
2342
+ _ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_STORE)),
2343
+ _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_SINK)),
2344
+ _ts_param6(2, (0, import_common8.Optional)()),
2345
+ _ts_param6(2, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_QUOTA_PROVIDER)),
2346
+ _ts_param6(3, (0, import_common8.Optional)()),
2347
+ _ts_param6(3, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_OPTIONS)),
2348
+ _ts_param6(4, (0, import_common8.Optional)()),
2349
+ _ts_param6(4, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_ATTACHMENT_STAGING)),
2350
+ _ts_param6(5, (0, import_common8.Optional)()),
2351
+ _ts_param6(5, (0, import_common8.Inject)(import_nestjs_agent_core12.AGENT_DEPS_FACTORY)),
2352
+ _ts_metadata6("design:type", Function),
2353
+ _ts_metadata6("design:paramtypes", [
1778
2354
  typeof AgentStore === "undefined" ? Object : AgentStore,
1779
2355
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
1780
2356
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
1781
2357
  typeof Pick === "undefined" ? Object : Pick,
1782
- typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore
2358
+ typeof AttachmentStagingStore === "undefined" ? Object : AttachmentStagingStore,
2359
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
1783
2360
  ])
1784
2361
  ], ChatQueueService2);
1785
2362
  function pauseReasonFor(outcome, head) {
@@ -1796,7 +2373,7 @@ function queueFrame(items, paused, started) {
1796
2373
  return {
1797
2374
  kind: "queue",
1798
2375
  queue: {
1799
- items: items.map(import_nestjs_agent_core8.queuedMessageView),
2376
+ items: items.map(import_nestjs_agent_core12.queuedMessageView),
1800
2377
  paused
1801
2378
  },
1802
2379
  ...started !== void 0 ? {
@@ -1807,25 +2384,25 @@ function queueFrame(items, paused, started) {
1807
2384
  __name(queueFrame, "queueFrame");
1808
2385
 
1809
2386
  // src/run-not-active.exception.ts
1810
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1811
- var import_common7 = require("@nestjs/common");
1812
- var RunNotActiveException = class extends import_common7.ConflictException {
2387
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
2388
+ var import_common9 = require("@nestjs/common");
2389
+ var RunNotActiveException = class extends import_common9.ConflictException {
1813
2390
  static {
1814
2391
  __name(this, "RunNotActiveException");
1815
2392
  }
1816
2393
  runId;
1817
- code = import_nestjs_agent_core9.RUN_NOT_ACTIVE_CODE;
2394
+ code = import_nestjs_agent_core13.RUN_NOT_ACTIVE_CODE;
1818
2395
  constructor(runId) {
1819
2396
  super({
1820
2397
  statusCode: 409,
1821
- code: import_nestjs_agent_core9.RUN_NOT_ACTIVE_CODE,
1822
- message: import_nestjs_agent_core9.RUN_NOT_ACTIVE_MESSAGE
2398
+ code: import_nestjs_agent_core13.RUN_NOT_ACTIVE_CODE,
2399
+ message: import_nestjs_agent_core13.RUN_NOT_ACTIVE_MESSAGE
1823
2400
  }), this.runId = runId;
1824
2401
  }
1825
2402
  };
1826
2403
 
1827
2404
  // src/agent.service.ts
1828
- function _ts_decorate7(decorators, target, key, desc) {
2405
+ function _ts_decorate9(decorators, target, key, desc) {
1829
2406
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1830
2407
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
1831
2408
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1838,19 +2415,19 @@ function _ts_decorate7(decorators, target, key, desc) {
1838
2415
  }
1839
2416
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1840
2417
  }
1841
- __name(_ts_decorate7, "_ts_decorate");
1842
- function _ts_metadata6(metadataKey, metadataValue) {
2418
+ __name(_ts_decorate9, "_ts_decorate");
2419
+ function _ts_metadata7(metadataKey, metadataValue) {
1843
2420
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
1844
2421
  return Reflect.metadata(metadataKey, metadataValue);
1845
2422
  }
1846
2423
  }
1847
- __name(_ts_metadata6, "_ts_metadata");
1848
- function _ts_param6(paramIndex, decorator) {
2424
+ __name(_ts_metadata7, "_ts_metadata");
2425
+ function _ts_param7(paramIndex, decorator) {
1849
2426
  return function(target, key) {
1850
2427
  decorator(target, key, paramIndex);
1851
2428
  };
1852
2429
  }
1853
- __name(_ts_param6, "_ts_param");
2430
+ __name(_ts_param7, "_ts_param");
1854
2431
  var AgentService = class {
1855
2432
  static {
1856
2433
  __name(this, "AgentService");
@@ -1863,7 +2440,8 @@ var AgentService = class {
1863
2440
  quotaProvider;
1864
2441
  options;
1865
2442
  queue;
1866
- constructor(runner, store, deps, staging, models, quotaProvider, options, queue) {
2443
+ proposals;
2444
+ constructor(runner, store, deps, staging, models, quotaProvider, options, queue, proposals) {
1867
2445
  this.runner = runner;
1868
2446
  this.store = store;
1869
2447
  this.deps = deps;
@@ -1872,6 +2450,13 @@ var AgentService = class {
1872
2450
  this.quotaProvider = quotaProvider;
1873
2451
  this.options = options;
1874
2452
  this.queue = queue;
2453
+ this.proposals = proposals;
2454
+ }
2455
+ async handleTextDecision(threadId, actor, text) {
2456
+ if (this.options?.actionApprovalMode !== "independent" || !this.proposals) return {
2457
+ status: "unmatched"
2458
+ };
2459
+ return this.proposals.handleTextDecision(threadId, actor, text);
1875
2460
  }
1876
2461
  /** The queue service when the bound store can hold a queue, else `undefined`. */
1877
2462
  queueing() {
@@ -1881,7 +2466,7 @@ var AgentService = class {
1881
2466
  requireQueue() {
1882
2467
  const queue = this.queueing();
1883
2468
  if (queue === void 0) {
1884
- throw new import_common8.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
2469
+ throw new import_common10.NotImplementedException("Queueing messages requires an AgentStore that implements ChatQueueStore; the bound store does not.");
1885
2470
  }
1886
2471
  return queue;
1887
2472
  }
@@ -1918,12 +2503,12 @@ var AgentService = class {
1918
2503
  actor
1919
2504
  });
1920
2505
  if (blocked !== void 0) {
1921
- throw new import_common8.HttpException({
1922
- statusCode: import_common8.HttpStatus.TOO_MANY_REQUESTS,
2506
+ throw new import_common10.HttpException({
2507
+ statusCode: import_common10.HttpStatus.TOO_MANY_REQUESTS,
1923
2508
  code: "quota_exceeded",
1924
2509
  period: blocked.period,
1925
2510
  message: blocked.reason ?? `The ${blocked.period === "day" ? "daily" : "monthly"} quota is used up`
1926
- }, import_common8.HttpStatus.TOO_MANY_REQUESTS);
2511
+ }, import_common10.HttpStatus.TOO_MANY_REQUESTS);
1927
2512
  }
1928
2513
  }
1929
2514
  /**
@@ -1951,17 +2536,17 @@ var AgentService = class {
1951
2536
  */
1952
2537
  async assertModelAllowed(actor, agent, model) {
1953
2538
  if (this.models === void 0) {
1954
- throw new import_common8.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
2539
+ throw new import_common10.BadRequestException(`model "${model}" cannot be selected: no ModelCatalog is configured (AgentModule.forRoot({ models }))`);
1955
2540
  }
1956
- const entry = (0, import_nestjs_agent_core10.findCatalogModel)(await this.models.list({
2541
+ const entry = (0, import_nestjs_agent_core14.findCatalogModel)(await this.models.list({
1957
2542
  actor,
1958
2543
  agent
1959
2544
  }), model);
1960
2545
  if (entry === void 0) {
1961
- throw new import_common8.BadRequestException(`model "${model}" is not offered`);
2546
+ throw new import_common10.BadRequestException(`model "${model}" is not offered`);
1962
2547
  }
1963
2548
  if (!entry.available) {
1964
- throw new import_common8.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
2549
+ throw new import_common10.BadRequestException(`model "${model}" is not available${entry.unavailableReason ? `: ${entry.unavailableReason}` : ""}`);
1965
2550
  }
1966
2551
  return entry.id;
1967
2552
  }
@@ -1977,7 +2562,7 @@ var AgentService = class {
1977
2562
  })).locked : void 0;
1978
2563
  if (locked !== void 0) {
1979
2564
  if (requested !== void 0 && requested !== locked.model) {
1980
- throw new import_common8.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
2565
+ throw new import_common10.BadRequestException(`model "${requested}" cannot be selected: ${locked.reason ?? `this agent always uses "${locked.model}"`}`);
1981
2566
  }
1982
2567
  return locked.model;
1983
2568
  }
@@ -2003,7 +2588,10 @@ var AgentService = class {
2003
2588
  const result = await this.send({
2004
2589
  ...params,
2005
2590
  mode: "auto"
2591
+ }, {
2592
+ textDecisions: false
2006
2593
  });
2594
+ if ("proposalDecision" in result) throw new Error("Unexpected text decision in run-only API");
2007
2595
  if (result.queued !== true) {
2008
2596
  return result;
2009
2597
  }
@@ -2021,7 +2609,7 @@ var AgentService = class {
2021
2609
  };
2022
2610
  }
2023
2611
  await this.requireQueue().publish(result.threadId);
2024
- throw new import_common8.ConflictException({
2612
+ throw new import_common10.ConflictException({
2025
2613
  statusCode: 409,
2026
2614
  code: "run_active",
2027
2615
  message: `thread ${result.threadId} already has a turn running`
@@ -2031,15 +2619,21 @@ var AgentService = class {
2031
2619
  * Send a message: start a turn, or — when its thread already has one running — queue the message
2032
2620
  * to run after it (see {@link ChatSendMode}). What `POST <base>/chat` calls.
2033
2621
  */
2034
- async send(params) {
2622
+ async send(params, sendOptions = {}) {
2623
+ if (sendOptions.textDecisions !== false && this.options?.actionApprovalMode === "independent" && params.threadId !== void 0 && params.regenerate !== true && this.proposals) {
2624
+ const decision = await this.proposals.handleTextDecision(params.threadId, params.actor, params.message);
2625
+ if ("proposalDecision" in decision) return decision;
2626
+ }
2035
2627
  await this.assertWithinQuota(params.actor);
2036
- const agentName = await this.resolveAgentName(params.agentName, params.threadId);
2628
+ const target = this.deps.resolveAgent(await this.resolveAgentName(params.agentName, params.threadId));
2629
+ const agentName = target.agentName;
2630
+ const persona = await this.resolvePersona(agentName, params.personaId ?? target.persona, params.threadId);
2037
2631
  const model = await this.resolveModel(params.actor, agentName, params.model, params.threadId);
2038
2632
  const attachments = await this.resolveAttachments(params.actor, params.attachments ?? []);
2039
2633
  let threadId = params.threadId;
2040
2634
  if (threadId === void 0) {
2041
2635
  if (params.regenerate === true) {
2042
- throw new import_common8.BadRequestException("regenerate requires an existing threadId");
2636
+ throw new import_common10.BadRequestException("regenerate requires an existing threadId");
2043
2637
  }
2044
2638
  const created = await this.store.createThread({
2045
2639
  actor: params.actor,
@@ -2048,11 +2642,17 @@ var AgentService = class {
2048
2642
  } : {},
2049
2643
  ...params.newThreadId !== void 0 ? {
2050
2644
  id: params.newThreadId
2645
+ } : {},
2646
+ ...params.personaId !== void 0 ? {
2647
+ persona: params.personaId
2051
2648
  } : {}
2052
2649
  });
2053
2650
  threadId = created.id;
2054
2651
  } else {
2055
2652
  await this.assertOwnsThread(params.actor, threadId);
2653
+ if (params.personaId !== void 0) {
2654
+ await this.pinThreadPersona(threadId, params.personaId);
2655
+ }
2056
2656
  }
2057
2657
  const input = {
2058
2658
  threadId,
@@ -2060,6 +2660,9 @@ var AgentService = class {
2060
2660
  userText: params.message,
2061
2661
  day: utcDay(),
2062
2662
  agentName,
2663
+ ...persona !== void 0 ? {
2664
+ persona
2665
+ } : {},
2063
2666
  ...params.regenerate === true ? {
2064
2667
  regenerate: true
2065
2668
  } : {},
@@ -2069,12 +2672,16 @@ var AgentService = class {
2069
2672
  ...params.pageContext !== void 0 ? {
2070
2673
  pageContext: params.pageContext
2071
2674
  } : {},
2675
+ ...params.uiCapabilities !== void 0 ? {
2676
+ uiCapabilities: params.uiCapabilities
2677
+ } : {},
2072
2678
  ...model !== void 0 ? {
2073
2679
  model
2074
2680
  } : {}
2075
2681
  };
2076
2682
  const queue = this.queueing();
2077
2683
  if (queue === void 0) {
2684
+ if (this.options?.actionApprovalMode === "independent") throw new Error("Independent actions require queued thread admission");
2078
2685
  const { runId } = await this.runner.start(input);
2079
2686
  await this.store.setActiveStream(threadId, runId);
2080
2687
  return {
@@ -2085,7 +2692,7 @@ var AgentService = class {
2085
2692
  const mode = params.mode ?? "auto";
2086
2693
  const { live, stale } = await queue.holder(threadId, this.runner);
2087
2694
  if (stale !== null) {
2088
- await (0, import_nestjs_agent_core10.settleDeadRun)(this.store, {
2695
+ await (0, import_nestjs_agent_core14.settleDeadRun)(this.store, {
2089
2696
  runId: stale
2090
2697
  });
2091
2698
  }
@@ -2101,7 +2708,7 @@ var AgentService = class {
2101
2708
  }
2102
2709
  }
2103
2710
  if (params.regenerate === true) {
2104
- throw new import_common8.ConflictException({
2711
+ throw new import_common10.ConflictException({
2105
2712
  statusCode: 409,
2106
2713
  code: "run_active",
2107
2714
  message: "cannot regenerate while a turn is running on this thread"
@@ -2146,12 +2753,18 @@ var AgentService = class {
2146
2753
  ...input.agentName !== void 0 ? {
2147
2754
  agentName: input.agentName
2148
2755
  } : {},
2756
+ ...input.persona !== void 0 ? {
2757
+ persona: input.persona
2758
+ } : {},
2149
2759
  ...input.model !== void 0 ? {
2150
2760
  model: input.model
2151
2761
  } : {},
2152
2762
  ...input.pageContext !== void 0 ? {
2153
2763
  pageContext: input.pageContext
2154
2764
  } : {},
2765
+ ...input.uiCapabilities !== void 0 ? {
2766
+ uiCapabilities: input.uiCapabilities
2767
+ } : {},
2155
2768
  ...interrupting !== void 0 ? {
2156
2769
  interrupt: true,
2157
2770
  at: "head"
@@ -2198,7 +2811,7 @@ var AgentService = class {
2198
2811
  const store = queue.queueStore();
2199
2812
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
2200
2813
  if (patch.message !== void 0 && patch.message.trim().length === 0) {
2201
- throw new import_common8.BadRequestException("message must not be empty");
2814
+ throw new import_common10.BadRequestException("message must not be empty");
2202
2815
  }
2203
2816
  const attachments = patch.attachments === void 0 || patch.attachments === null ? patch.attachments : await this.resolveAttachments(actor, patch.attachments);
2204
2817
  if (patch.message !== void 0 || attachments !== void 0) {
@@ -2211,15 +2824,15 @@ var AgentService = class {
2211
2824
  } : {}
2212
2825
  });
2213
2826
  if (updated === null) {
2214
- throw new import_common8.GoneException(`queued message ${messageId} already started or was removed`);
2827
+ throw new import_common10.GoneException(`queued message ${messageId} already started or was removed`);
2215
2828
  }
2216
2829
  }
2217
2830
  if (patch.position !== void 0) {
2218
2831
  if (!Number.isInteger(patch.position) || patch.position < 0) {
2219
- throw new import_common8.BadRequestException("position must be a non-negative integer");
2832
+ throw new import_common10.BadRequestException("position must be a non-negative integer");
2220
2833
  }
2221
2834
  if (!await store.moveQueuedMessage(messageId, patch.position)) {
2222
- throw new import_common8.GoneException(`queued message ${messageId} already started or was removed`);
2835
+ throw new import_common10.GoneException(`queued message ${messageId} already started or was removed`);
2223
2836
  }
2224
2837
  }
2225
2838
  return queue.publish(threadId);
@@ -2229,7 +2842,7 @@ var AgentService = class {
2229
2842
  const queue = this.requireQueue();
2230
2843
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
2231
2844
  if (!await queue.queueStore().removeQueuedMessage(messageId)) {
2232
- throw new import_common8.GoneException(`queued message ${messageId} already started or was removed`);
2845
+ throw new import_common10.GoneException(`queued message ${messageId} already started or was removed`);
2233
2846
  }
2234
2847
  return queue.publish(threadId);
2235
2848
  }
@@ -2248,7 +2861,7 @@ var AgentService = class {
2248
2861
  const queue = this.requireQueue();
2249
2862
  const store = queue.queueStore();
2250
2863
  const threadId = await this.assertOwnsQueuedMessage(actor, messageId);
2251
- const gone = /* @__PURE__ */ __name(() => new import_common8.GoneException(`queued message ${messageId} already started or was removed`), "gone");
2864
+ const gone = /* @__PURE__ */ __name(() => new import_common10.GoneException(`queued message ${messageId} already started or was removed`), "gone");
2252
2865
  const marked = await store.updateQueuedMessage(messageId, {
2253
2866
  interrupt: true
2254
2867
  });
@@ -2256,7 +2869,7 @@ var AgentService = class {
2256
2869
  throw gone();
2257
2870
  }
2258
2871
  if (marked.interrupt !== true) {
2259
- throw new import_common8.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
2872
+ throw new import_common10.NotImplementedException("Interrupting a queued message requires a ChatQueueStore whose updateQueuedMessage stores `interrupt`; the bound store ignored it.");
2260
2873
  }
2261
2874
  if (!await store.moveQueuedMessage(messageId, 0)) {
2262
2875
  throw gone();
@@ -2315,7 +2928,7 @@ var AgentService = class {
2315
2928
  async assertOwnsQueuedMessage(actor, messageId) {
2316
2929
  const message = await this.requireQueue().queueStore().getQueuedMessage(messageId);
2317
2930
  if (message === null) {
2318
- throw new import_common8.NotFoundException(`queued message ${messageId} not found`);
2931
+ throw new import_common10.NotFoundException(`queued message ${messageId} not found`);
2319
2932
  }
2320
2933
  await this.assertOwnsThread(actor, message.threadId);
2321
2934
  return message.threadId;
@@ -2336,7 +2949,7 @@ var AgentService = class {
2336
2949
  }
2337
2950
  const staging = this.staging;
2338
2951
  if (staging === void 0 || typeof staging.resolve !== "function") {
2339
- throw new import_common8.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
2952
+ throw new import_common10.NotImplementedException("Message attachments require an AGENT_ATTACHMENT_STAGING provider implementing resolve(); attachment urls are never taken from the request.");
2340
2953
  }
2341
2954
  const resolved = [];
2342
2955
  for (const ref of refs) {
@@ -2345,7 +2958,7 @@ var AgentService = class {
2345
2958
  actor
2346
2959
  });
2347
2960
  if (attachment === null) {
2348
- throw new import_common8.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
2961
+ throw new import_common10.ForbiddenException(`attachment ${ref.mediaId} is not available to this actor`);
2349
2962
  }
2350
2963
  resolved.push(attachment);
2351
2964
  }
@@ -2447,6 +3060,7 @@ var AgentService = class {
2447
3060
  * not the thread's own actor).
2448
3061
  */
2449
3062
  async signalToolCall(toolCallId2, reply) {
3063
+ if ((await this.store.toolCallApproval?.(toolCallId2))?.status === "proposed") throw new import_common10.ConflictException("Independent proposals require the scoped proposal decision route");
2450
3064
  await this.assertNotExpired(toolCallId2);
2451
3065
  const runId = await this.resolveRunForToolCall(toolCallId2);
2452
3066
  await this.assertRunWaiting(runId);
@@ -2467,7 +3081,7 @@ var AgentService = class {
2467
3081
  if (active) {
2468
3082
  return;
2469
3083
  }
2470
- await (0, import_nestjs_agent_core10.settleDeadRun)(this.store, {
3084
+ await (0, import_nestjs_agent_core14.settleDeadRun)(this.store, {
2471
3085
  runId
2472
3086
  });
2473
3087
  throw new RunNotActiveException(runId);
@@ -2487,7 +3101,7 @@ var AgentService = class {
2487
3101
  throw new RunNotActiveException(runId);
2488
3102
  }
2489
3103
  if (owner !== actor.id) {
2490
- throw new import_common8.ForbiddenException("run belongs to another actor");
3104
+ throw new import_common10.ForbiddenException("run belongs to another actor");
2491
3105
  }
2492
3106
  }
2493
3107
  /**
@@ -2540,16 +3154,22 @@ var AgentService = class {
2540
3154
  async updateThread(actor, threadId, patch) {
2541
3155
  const title = patch.title !== void 0 ? this.validateTitle(patch.title) : void 0;
2542
3156
  await this.assertOwnsThread(actor, threadId);
2543
- if (patch.defaultAgent === void 0 && patch.model === void 0) {
3157
+ if (patch.defaultAgent === void 0 && patch.model === void 0 && patch.persona === void 0) {
2544
3158
  if (title !== void 0) {
2545
3159
  await this.store.setTitle(threadId, title);
2546
3160
  }
2547
3161
  return;
2548
3162
  }
2549
3163
  if (this.store.updateThread === void 0) {
2550
- throw new import_common8.NotImplementedException("Setting a thread's defaultAgent or model requires an AgentStore that implements updateThread(); the bound store does not support it.");
3164
+ throw new import_common10.NotImplementedException("Setting a thread's defaultAgent, model or persona requires an AgentStore that implements updateThread(); the bound store does not support it.");
2551
3165
  }
2552
3166
  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);
3167
+ if (patch.persona !== void 0 && patch.persona !== null) {
3168
+ this.deps.resolvePersona({
3169
+ agentName: this.deps.resolveAgent(patch.defaultAgent ?? await this.resolveAgentName(void 0, threadId)).agentName,
3170
+ requested: patch.persona
3171
+ });
3172
+ }
2553
3173
  await this.store.updateThread(threadId, {
2554
3174
  ...title !== void 0 ? {
2555
3175
  title
@@ -2559,16 +3179,46 @@ var AgentService = class {
2559
3179
  } : {},
2560
3180
  ...model !== void 0 ? {
2561
3181
  model
3182
+ } : {},
3183
+ ...patch.persona !== void 0 ? {
3184
+ persona: patch.persona
3185
+ } : {}
3186
+ });
3187
+ }
3188
+ /**
3189
+ * The persona this send runs under — see {@link AgentDepsFactory.resolvePersona}. The thread's
3190
+ * pinned persona is read only when the send names none AND the agent has personas to pick from.
3191
+ */
3192
+ async resolvePersona(agentName, requested, threadId) {
3193
+ const needsThread = requested === void 0 && threadId !== void 0 && this.deps.personaCatalog(agentName).length > 0;
3194
+ return this.deps.resolvePersona({
3195
+ agentName,
3196
+ ...requested !== void 0 ? {
3197
+ requested
3198
+ } : {},
3199
+ ...needsThread ? {
3200
+ threadPersona: await threadPersona(this.store, threadId)
2562
3201
  } : {}
2563
3202
  });
2564
3203
  }
3204
+ /** Pin `persona` on the thread when it is not already — a no-op on a store that cannot. */
3205
+ async pinThreadPersona(threadId, persona) {
3206
+ if (this.store.updateThread === void 0) {
3207
+ return;
3208
+ }
3209
+ if (await threadPersona(this.store, threadId) !== persona) {
3210
+ await this.store.updateThread(threadId, {
3211
+ persona
3212
+ });
3213
+ }
3214
+ }
2565
3215
  validateTitle(title) {
2566
3216
  const trimmed = title.trim();
2567
3217
  if (trimmed.length === 0) {
2568
- throw new import_common8.BadRequestException("title must not be empty");
3218
+ throw new import_common10.BadRequestException("title must not be empty");
2569
3219
  }
2570
3220
  if (trimmed.length > 200) {
2571
- throw new import_common8.BadRequestException("title must be at most 200 characters");
3221
+ throw new import_common10.BadRequestException("title must be at most 200 characters");
2572
3222
  }
2573
3223
  return trimmed;
2574
3224
  }
@@ -2607,6 +3257,7 @@ var AgentService = class {
2607
3257
  ...thread,
2608
3258
  defaultAgent: thread.defaultAgent ?? null,
2609
3259
  model: thread.model ?? null,
3260
+ persona: thread.persona ?? null,
2610
3261
  activeRunId: await this.store.activeRunForThread?.(thread.id) ?? thread.activeRunId ?? null
2611
3262
  };
2612
3263
  }
@@ -2671,21 +3322,21 @@ var AgentService = class {
2671
3322
  */
2672
3323
  async setMessageFeedback(actor, messageId, input) {
2673
3324
  if (input.value !== null && input.value !== "up" && input.value !== "down") {
2674
- throw new import_common8.BadRequestException("value must be 'up', 'down' or null");
3325
+ throw new import_common10.BadRequestException("value must be 'up', 'down' or null");
2675
3326
  }
2676
3327
  if (input.comment !== void 0 && typeof input.comment !== "string") {
2677
- throw new import_common8.BadRequestException("comment must be a string");
3328
+ throw new import_common10.BadRequestException("comment must be a string");
2678
3329
  }
2679
3330
  const comment = input.comment?.trim();
2680
3331
  if (comment !== void 0 && comment.length > 2e3) {
2681
- throw new import_common8.BadRequestException("comment must be at most 2000 characters");
3332
+ throw new import_common10.BadRequestException("comment must be at most 2000 characters");
2682
3333
  }
2683
3334
  if (this.store.threadOfMessage === void 0 || this.store.setMessageFeedback === void 0) {
2684
- throw new import_common8.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
3335
+ throw new import_common10.NotImplementedException("Message feedback requires an AgentStore that implements threadOfMessage() and setMessageFeedback(); the bound store does not support it.");
2685
3336
  }
2686
3337
  const threadId = await this.store.threadOfMessage(messageId);
2687
3338
  if (threadId === null) {
2688
- throw new import_common8.NotFoundException(`message ${messageId} not found`);
3339
+ throw new import_common10.NotFoundException(`message ${messageId} not found`);
2689
3340
  }
2690
3341
  await this.assertOwnsThread(actor, threadId);
2691
3342
  const feedback = input.value === null ? null : {
@@ -2733,7 +3384,7 @@ var AgentService = class {
2733
3384
  const list = this.attachmentInventory();
2734
3385
  const referencedMediaIds = this.store.referencedMediaIds?.bind(this.store);
2735
3386
  if (referencedMediaIds === void 0) {
2736
- throw new import_common8.NotImplementedException("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
3387
+ throw new import_common10.NotImplementedException("Collecting attachments requires an AgentStore that implements referencedMediaIds(); the bound store cannot say which media a message still references, and guessing would delete files that are in use.");
2737
3388
  }
2738
3389
  const stagedBefore = options.olderThan.toISOString();
2739
3390
  const inventory = await list({
@@ -2755,7 +3406,7 @@ var AgentService = class {
2755
3406
  attachmentInventory() {
2756
3407
  const list = this.staging?.list?.bind(this.staging);
2757
3408
  if (list === void 0) {
2758
- throw new import_common8.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
3409
+ throw new import_common10.NotImplementedException("Listing attachments requires an AGENT_ATTACHMENT_STAGING provider implementing list(); the host owns the staged bytes, so only it can enumerate them.");
2759
3410
  }
2760
3411
  return list;
2761
3412
  }
@@ -2766,10 +3417,10 @@ var AgentService = class {
2766
3417
  async assertOwnsThread(actor, threadId) {
2767
3418
  const owner = await this.store.ownerOfThread(threadId);
2768
3419
  if (owner === null) {
2769
- throw new import_common8.NotFoundException(`thread ${threadId} not found`);
3420
+ throw new import_common10.NotFoundException(`thread ${threadId} not found`);
2770
3421
  }
2771
3422
  if (owner !== actor.id) {
2772
- throw new import_common8.ForbiddenException("thread belongs to another actor");
3423
+ throw new import_common10.ForbiddenException("thread belongs to another actor");
2773
3424
  }
2774
3425
  }
2775
3426
  /**
@@ -2780,10 +3431,10 @@ var AgentService = class {
2780
3431
  async assertOwnsToolCall(actor, toolCallId2) {
2781
3432
  const owner = await this.store.ownerOfToolCall(toolCallId2);
2782
3433
  if (owner === null) {
2783
- throw new import_common8.NotFoundException(`tool call ${toolCallId2} not found`);
3434
+ throw new import_common10.NotFoundException(`tool call ${toolCallId2} not found`);
2784
3435
  }
2785
3436
  if (owner !== actor.id) {
2786
- throw new import_common8.ForbiddenException("tool call belongs to another actor");
3437
+ throw new import_common10.ForbiddenException("tool call belongs to another actor");
2787
3438
  }
2788
3439
  }
2789
3440
  /**
@@ -2798,12 +3449,12 @@ var AgentService = class {
2798
3449
  if (this.store.toolCallInput === void 0) {
2799
3450
  return;
2800
3451
  }
2801
- const questions = (0, import_nestjs_agent_core10.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
3452
+ const questions = (0, import_nestjs_agent_core14.readElicitationQuestions)(await this.store.toolCallInput(toolCallId2));
2802
3453
  for (const question of questions) {
2803
3454
  const submitted = Object.hasOwn(answers2, question.id) ? answers2[question.id] : void 0;
2804
- const problem = (0, import_nestjs_agent_core10.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
3455
+ const problem = (0, import_nestjs_agent_core14.validateElicitationAnswer)(question, submitted ?? question.defaults ?? []);
2805
3456
  if (problem !== null) {
2806
- throw new import_common8.BadRequestException(`answers["${question.id}"] ${problem}`);
3457
+ throw new import_common10.BadRequestException(`answers["${question.id}"] ${problem}`);
2807
3458
  }
2808
3459
  }
2809
3460
  }
@@ -2815,21 +3466,21 @@ var AgentService = class {
2815
3466
  */
2816
3467
  async assertMayDecide(actor, toolCallId2) {
2817
3468
  const approval = await this.store.toolCallApproval?.(toolCallId2);
2818
- const approver = approval?.approver ?? import_nestjs_agent_core10.REQUESTER_APPROVER;
2819
- if (approver === import_nestjs_agent_core10.REQUESTER_APPROVER) {
3469
+ const approver = approval?.approver ?? import_nestjs_agent_core14.REQUESTER_APPROVER;
3470
+ if (approver === import_nestjs_agent_core14.REQUESTER_APPROVER) {
2820
3471
  return this.assertOwnsToolCall(actor, toolCallId2);
2821
3472
  }
2822
3473
  const requesterRef = await this.store.ownerOfToolCall(toolCallId2);
2823
3474
  if (requesterRef === null) {
2824
- throw new import_common8.NotFoundException(`tool call ${toolCallId2} not found`);
3475
+ throw new import_common10.NotFoundException(`tool call ${toolCallId2} not found`);
2825
3476
  }
2826
- const allowed = await (0, import_nestjs_agent_core10.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
3477
+ const allowed = await (0, import_nestjs_agent_core14.mayDecideApproval)(this.deps.forAgent().approvalPolicy, actor, {
2827
3478
  toolCallId: toolCallId2,
2828
3479
  approver,
2829
3480
  requesterRef
2830
3481
  });
2831
3482
  if (!allowed) {
2832
- throw new import_common8.ForbiddenException(`this approval is for ${approver}`);
3483
+ throw new import_common10.ForbiddenException(`this approval is for ${approver}`);
2833
3484
  }
2834
3485
  }
2835
3486
  /**
@@ -2845,7 +3496,7 @@ var AgentService = class {
2845
3496
  }
2846
3497
  const lapsed = approval.status === "expired" || approval.status === "pending_approval" && approval.expiresAt !== null && Date.parse(approval.expiresAt) <= Date.now();
2847
3498
  if (lapsed) {
2848
- throw new import_common8.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
3499
+ throw new import_common10.GoneException(`the approval request for tool call ${toolCallId2} has expired`);
2849
3500
  }
2850
3501
  }
2851
3502
  /**
@@ -2858,7 +3509,7 @@ var AgentService = class {
2858
3509
  async resolveRunForToolCall(toolCallId2) {
2859
3510
  const runId = await this.store.runForToolCall(toolCallId2);
2860
3511
  if (runId === null) {
2861
- throw new import_common8.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
3512
+ throw new import_common10.NotFoundException(`tool call ${toolCallId2} has no active run to signal`);
2862
3513
  }
2863
3514
  return runId;
2864
3515
  }
@@ -2866,29 +3517,30 @@ var AgentService = class {
2866
3517
  async assertOwnsActiveStream(actor, runId) {
2867
3518
  const owner = await this.store.ownerOfActiveStream(runId);
2868
3519
  if (owner === null) {
2869
- throw new import_common8.NotFoundException(`no active run ${runId}`);
3520
+ throw new import_common10.NotFoundException(`no active run ${runId}`);
2870
3521
  }
2871
3522
  if (owner !== actor.id) {
2872
- throw new import_common8.ForbiddenException("run belongs to another actor");
3523
+ throw new import_common10.ForbiddenException("run belongs to another actor");
2873
3524
  }
2874
3525
  }
2875
3526
  };
2876
- AgentService = _ts_decorate7([
2877
- (0, import_common8.Injectable)(),
2878
- _ts_param6(0, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_RUNNER)),
2879
- _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_STORE)),
2880
- _ts_param6(2, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_DEPS_FACTORY)),
2881
- _ts_param6(3, (0, import_common8.Optional)()),
2882
- _ts_param6(3, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_ATTACHMENT_STAGING)),
2883
- _ts_param6(4, (0, import_common8.Optional)()),
2884
- _ts_param6(4, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_MODEL_CATALOG)),
2885
- _ts_param6(5, (0, import_common8.Optional)()),
2886
- _ts_param6(5, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_QUOTA_PROVIDER)),
2887
- _ts_param6(6, (0, import_common8.Optional)()),
2888
- _ts_param6(6, (0, import_common8.Inject)(import_nestjs_agent_core10.AGENT_OPTIONS)),
2889
- _ts_param6(7, (0, import_common8.Optional)()),
2890
- _ts_metadata6("design:type", Function),
2891
- _ts_metadata6("design:paramtypes", [
3527
+ AgentService = _ts_decorate9([
3528
+ (0, import_common10.Injectable)(),
3529
+ _ts_param7(0, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_RUNNER)),
3530
+ _ts_param7(1, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_STORE)),
3531
+ _ts_param7(2, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_DEPS_FACTORY)),
3532
+ _ts_param7(3, (0, import_common10.Optional)()),
3533
+ _ts_param7(3, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_ATTACHMENT_STAGING)),
3534
+ _ts_param7(4, (0, import_common10.Optional)()),
3535
+ _ts_param7(4, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_MODEL_CATALOG)),
3536
+ _ts_param7(5, (0, import_common10.Optional)()),
3537
+ _ts_param7(5, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_QUOTA_PROVIDER)),
3538
+ _ts_param7(6, (0, import_common10.Optional)()),
3539
+ _ts_param7(6, (0, import_common10.Inject)(import_nestjs_agent_core14.AGENT_OPTIONS)),
3540
+ _ts_param7(7, (0, import_common10.Optional)()),
3541
+ _ts_param7(8, (0, import_common10.Optional)()),
3542
+ _ts_metadata7("design:type", Function),
3543
+ _ts_metadata7("design:paramtypes", [
2892
3544
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
2893
3545
  typeof AgentStore === "undefined" ? Object : AgentStore,
2894
3546
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
@@ -2896,13 +3548,14 @@ AgentService = _ts_decorate7([
2896
3548
  typeof ModelCatalog === "undefined" ? Object : ModelCatalog,
2897
3549
  typeof QuotaProvider === "undefined" ? Object : QuotaProvider,
2898
3550
  typeof Pick === "undefined" ? Object : Pick,
2899
- typeof ChatQueueService2 === "undefined" ? Object : ChatQueueService2
3551
+ typeof ChatQueueService2 === "undefined" ? Object : ChatQueueService2,
3552
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
2900
3553
  ])
2901
3554
  ], AgentService);
2902
3555
 
2903
3556
  // src/approval-port.adapter.ts
2904
- var import_common9 = require("@nestjs/common");
2905
- function _ts_decorate8(decorators, target, key, desc) {
3557
+ var import_common11 = require("@nestjs/common");
3558
+ function _ts_decorate10(decorators, target, key, desc) {
2906
3559
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2907
3560
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2908
3561
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2915,20 +3568,48 @@ function _ts_decorate8(decorators, target, key, desc) {
2915
3568
  }
2916
3569
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2917
3570
  }
2918
- __name(_ts_decorate8, "_ts_decorate");
2919
- function _ts_metadata7(metadataKey, metadataValue) {
3571
+ __name(_ts_decorate10, "_ts_decorate");
3572
+ function _ts_metadata8(metadataKey, metadataValue) {
2920
3573
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2921
3574
  return Reflect.metadata(metadataKey, metadataValue);
2922
3575
  }
2923
3576
  }
2924
- __name(_ts_metadata7, "_ts_metadata");
3577
+ __name(_ts_metadata8, "_ts_metadata");
3578
+ function _ts_param8(paramIndex, decorator) {
3579
+ return function(target, key) {
3580
+ decorator(target, key, paramIndex);
3581
+ };
3582
+ }
3583
+ __name(_ts_param8, "_ts_param");
2925
3584
  var AgentApprovalPortAdapter = class {
2926
3585
  static {
2927
3586
  __name(this, "AgentApprovalPortAdapter");
2928
3587
  }
2929
3588
  agent;
2930
- constructor(agent) {
3589
+ proposals;
3590
+ constructor(agent, proposals) {
2931
3591
  this.agent = agent;
3592
+ this.proposals = proposals;
3593
+ }
3594
+ async approveActionProposal(actor, target, opts) {
3595
+ if (!this.proposals) throw new import_common11.NotImplementedException("Action proposals unavailable");
3596
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
3597
+ decision: "approved",
3598
+ ...opts?.remember !== void 0 ? {
3599
+ remember: opts.remember
3600
+ } : {},
3601
+ via: opts?.decidedVia ?? "console"
3602
+ });
3603
+ }
3604
+ async rejectActionProposal(actor, target, opts) {
3605
+ if (!this.proposals) throw new import_common11.NotImplementedException("Action proposals unavailable");
3606
+ return this.proposals.decide(target.threadId, target.proposalId, actor, {
3607
+ decision: "rejected",
3608
+ ...opts?.reason !== void 0 ? {
3609
+ reason: opts.reason
3610
+ } : {},
3611
+ via: opts?.decidedVia ?? "console"
3612
+ });
2932
3613
  }
2933
3614
  async approve(toolCallId2, opts) {
2934
3615
  await this.agent.signalToolCall(toolCallId2, {
@@ -2959,18 +3640,20 @@ var AgentApprovalPortAdapter = class {
2959
3640
  });
2960
3641
  }
2961
3642
  };
2962
- AgentApprovalPortAdapter = _ts_decorate8([
2963
- (0, import_common9.Injectable)(),
2964
- _ts_metadata7("design:type", Function),
2965
- _ts_metadata7("design:paramtypes", [
2966
- typeof AgentService === "undefined" ? Object : AgentService
3643
+ AgentApprovalPortAdapter = _ts_decorate10([
3644
+ (0, import_common11.Injectable)(),
3645
+ _ts_param8(1, (0, import_common11.Optional)()),
3646
+ _ts_metadata8("design:type", Function),
3647
+ _ts_metadata8("design:paramtypes", [
3648
+ typeof AgentService === "undefined" ? Object : AgentService,
3649
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService
2967
3650
  ])
2968
3651
  ], AgentApprovalPortAdapter);
2969
3652
 
2970
3653
  // src/controller/agents.controller.ts
2971
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
2972
- var import_common10 = require("@nestjs/common");
2973
- function _ts_decorate9(decorators, target, key, desc) {
3654
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3655
+ var import_common12 = require("@nestjs/common");
3656
+ function _ts_decorate11(decorators, target, key, desc) {
2974
3657
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2975
3658
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
2976
3659
  r = Reflect.decorate(decorators, target, key, desc);
@@ -2983,19 +3666,19 @@ function _ts_decorate9(decorators, target, key, desc) {
2983
3666
  }
2984
3667
  return c > 3 && r && Object.defineProperty(target, key, r), r;
2985
3668
  }
2986
- __name(_ts_decorate9, "_ts_decorate");
2987
- function _ts_metadata8(metadataKey, metadataValue) {
3669
+ __name(_ts_decorate11, "_ts_decorate");
3670
+ function _ts_metadata9(metadataKey, metadataValue) {
2988
3671
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
2989
3672
  return Reflect.metadata(metadataKey, metadataValue);
2990
3673
  }
2991
3674
  }
2992
- __name(_ts_metadata8, "_ts_metadata");
2993
- function _ts_param7(paramIndex, decorator) {
3675
+ __name(_ts_metadata9, "_ts_metadata");
3676
+ function _ts_param9(paramIndex, decorator) {
2994
3677
  return function(target, key) {
2995
3678
  decorator(target, key, paramIndex);
2996
3679
  };
2997
3680
  }
2998
- __name(_ts_param7, "_ts_param");
3681
+ __name(_ts_param9, "_ts_param");
2999
3682
  var AgentsController = class {
3000
3683
  static {
3001
3684
  __name(this, "AgentsController");
@@ -3008,35 +3691,44 @@ var AgentsController = class {
3008
3691
  }
3009
3692
  list() {
3010
3693
  const defaultAgentName = this.depsFactory.defaultAgentName();
3011
- return this.agents.list().map((definition) => ({
3012
- name: definition.name,
3013
- description: definition.description ?? "",
3014
- ...definition.name === defaultAgentName ? {
3015
- isDefault: true
3016
- } : {}
3017
- }));
3694
+ return this.agents.list().map((definition) => {
3695
+ const personas = this.depsFactory.personaCatalog(definition.name);
3696
+ return {
3697
+ name: definition.name,
3698
+ description: definition.description ?? "",
3699
+ ...definition.name === defaultAgentName ? {
3700
+ isDefault: true
3701
+ } : {},
3702
+ ...personas.length > 0 ? {
3703
+ personas
3704
+ } : {},
3705
+ ...definition.defaultPersona !== void 0 ? {
3706
+ defaultPersona: definition.defaultPersona
3707
+ } : {}
3708
+ };
3709
+ });
3018
3710
  }
3019
3711
  };
3020
- _ts_decorate9([
3021
- (0, import_common10.Get)(),
3022
- _ts_metadata8("design:type", Function),
3023
- _ts_metadata8("design:paramtypes", []),
3024
- _ts_metadata8("design:returntype", Array)
3712
+ _ts_decorate11([
3713
+ (0, import_common12.Get)(),
3714
+ _ts_metadata9("design:type", Function),
3715
+ _ts_metadata9("design:paramtypes", []),
3716
+ _ts_metadata9("design:returntype", Array)
3025
3717
  ], AgentsController.prototype, "list", null);
3026
- AgentsController = _ts_decorate9([
3027
- (0, import_common10.Controller)("agents"),
3028
- _ts_param7(0, (0, import_common10.Inject)(import_nestjs_agent_core11.AGENT_REGISTRY)),
3029
- _ts_param7(1, (0, import_common10.Inject)(import_nestjs_agent_core11.AGENT_DEPS_FACTORY)),
3030
- _ts_metadata8("design:type", Function),
3031
- _ts_metadata8("design:paramtypes", [
3032
- typeof import_nestjs_agent_core11.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core11.AgentRegistry,
3718
+ AgentsController = _ts_decorate11([
3719
+ (0, import_common12.Controller)("agents"),
3720
+ _ts_param9(0, (0, import_common12.Inject)(import_nestjs_agent_core15.AGENT_REGISTRY)),
3721
+ _ts_param9(1, (0, import_common12.Inject)(import_nestjs_agent_core15.AGENT_DEPS_FACTORY)),
3722
+ _ts_metadata9("design:type", Function),
3723
+ _ts_metadata9("design:paramtypes", [
3724
+ typeof import_nestjs_agent_core15.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core15.AgentRegistry,
3033
3725
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
3034
3726
  ])
3035
3727
  ], AgentsController);
3036
3728
 
3037
3729
  // src/controller/attachments.controller.ts
3038
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
3039
- var import_common11 = require("@nestjs/common");
3730
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3731
+ var import_common13 = require("@nestjs/common");
3040
3732
  var import_platform_express = require("@nestjs/platform-express");
3041
3733
 
3042
3734
  // src/attachment-limits.ts
@@ -3065,7 +3757,7 @@ function attachmentLimits(options, staging) {
3065
3757
  __name(attachmentLimits, "attachmentLimits");
3066
3758
 
3067
3759
  // src/controller/attachments.controller.ts
3068
- function _ts_decorate10(decorators, target, key, desc) {
3760
+ function _ts_decorate12(decorators, target, key, desc) {
3069
3761
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3070
3762
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3071
3763
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3078,19 +3770,19 @@ function _ts_decorate10(decorators, target, key, desc) {
3078
3770
  }
3079
3771
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3080
3772
  }
3081
- __name(_ts_decorate10, "_ts_decorate");
3082
- function _ts_metadata9(metadataKey, metadataValue) {
3773
+ __name(_ts_decorate12, "_ts_decorate");
3774
+ function _ts_metadata10(metadataKey, metadataValue) {
3083
3775
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3084
3776
  return Reflect.metadata(metadataKey, metadataValue);
3085
3777
  }
3086
3778
  }
3087
- __name(_ts_metadata9, "_ts_metadata");
3088
- function _ts_param8(paramIndex, decorator) {
3779
+ __name(_ts_metadata10, "_ts_metadata");
3780
+ function _ts_param10(paramIndex, decorator) {
3089
3781
  return function(target, key) {
3090
3782
  decorator(target, key, paramIndex);
3091
3783
  };
3092
3784
  }
3093
- __name(_ts_param8, "_ts_param");
3785
+ __name(_ts_param10, "_ts_param");
3094
3786
  var HARD_MAX_ATTACHMENT_BYTES = 32 * 1024 * 1024;
3095
3787
  var ATTACHMENT_PAGE_SIZE = 50;
3096
3788
  var AttachmentsController = class {
@@ -3124,17 +3816,17 @@ var AttachmentsController = class {
3124
3816
  }
3125
3817
  async upload(req, file) {
3126
3818
  if (this.staging === void 0) {
3127
- throw new import_common11.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
3819
+ throw new import_common13.NotImplementedException("Attachment upload is not configured on this server: bind AGENT_ATTACHMENT_STAGING (e.g. import AgentMediaAttachmentsModule).");
3128
3820
  }
3129
3821
  if (file === void 0) {
3130
- throw new import_common11.BadRequestException('multipart field "file" is required');
3822
+ throw new import_common13.BadRequestException('multipart field "file" is required');
3131
3823
  }
3132
3824
  const { allowedContentTypes, maxBytes } = attachmentLimits(this.options, this.staging);
3133
3825
  if (!allowedContentTypes.includes(file.mimetype)) {
3134
- throw new import_common11.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
3826
+ throw new import_common13.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
3135
3827
  }
3136
3828
  if (file.size > maxBytes) {
3137
- throw new import_common11.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
3829
+ throw new import_common13.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
3138
3830
  }
3139
3831
  const actor = await this.actorResolver.resolve(req);
3140
3832
  return this.staging.stage({
@@ -3146,39 +3838,39 @@ var AttachmentsController = class {
3146
3838
  });
3147
3839
  }
3148
3840
  };
3149
- _ts_decorate10([
3150
- (0, import_common11.Get)(),
3151
- _ts_param8(0, (0, import_common11.Req)()),
3152
- _ts_metadata9("design:type", Function),
3153
- _ts_metadata9("design:paramtypes", [
3841
+ _ts_decorate12([
3842
+ (0, import_common13.Get)(),
3843
+ _ts_param10(0, (0, import_common13.Req)()),
3844
+ _ts_metadata10("design:type", Function),
3845
+ _ts_metadata10("design:paramtypes", [
3154
3846
  typeof Request === "undefined" ? Object : Request
3155
3847
  ]),
3156
- _ts_metadata9("design:returntype", Promise)
3848
+ _ts_metadata10("design:returntype", Promise)
3157
3849
  ], AttachmentsController.prototype, "list", null);
3158
- _ts_decorate10([
3159
- (0, import_common11.Post)(),
3160
- (0, import_common11.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
3850
+ _ts_decorate12([
3851
+ (0, import_common13.Post)(),
3852
+ (0, import_common13.UseInterceptors)((0, import_platform_express.FileInterceptor)("file", {
3161
3853
  limits: {
3162
3854
  fileSize: HARD_MAX_ATTACHMENT_BYTES
3163
3855
  }
3164
3856
  })),
3165
- _ts_param8(0, (0, import_common11.Req)()),
3166
- _ts_param8(1, (0, import_common11.UploadedFile)()),
3167
- _ts_metadata9("design:type", Function),
3168
- _ts_metadata9("design:paramtypes", [
3857
+ _ts_param10(0, (0, import_common13.Req)()),
3858
+ _ts_param10(1, (0, import_common13.UploadedFile)()),
3859
+ _ts_metadata10("design:type", Function),
3860
+ _ts_metadata10("design:paramtypes", [
3169
3861
  typeof Request === "undefined" ? Object : Request,
3170
3862
  Object
3171
3863
  ]),
3172
- _ts_metadata9("design:returntype", Promise)
3864
+ _ts_metadata10("design:returntype", Promise)
3173
3865
  ], AttachmentsController.prototype, "upload", null);
3174
- AttachmentsController = _ts_decorate10([
3175
- (0, import_common11.Controller)("attachments"),
3176
- _ts_param8(0, (0, import_common11.Inject)(import_nestjs_agent_core12.AGENT_OPTIONS)),
3177
- _ts_param8(1, (0, import_common11.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
3178
- _ts_param8(3, (0, import_common11.Optional)()),
3179
- _ts_param8(3, (0, import_common11.Inject)(import_nestjs_agent_core12.AGENT_ATTACHMENT_STAGING)),
3180
- _ts_metadata9("design:type", Function),
3181
- _ts_metadata9("design:paramtypes", [
3866
+ AttachmentsController = _ts_decorate12([
3867
+ (0, import_common13.Controller)("attachments"),
3868
+ _ts_param10(0, (0, import_common13.Inject)(import_nestjs_agent_core16.AGENT_OPTIONS)),
3869
+ _ts_param10(1, (0, import_common13.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3870
+ _ts_param10(3, (0, import_common13.Optional)()),
3871
+ _ts_param10(3, (0, import_common13.Inject)(import_nestjs_agent_core16.AGENT_ATTACHMENT_STAGING)),
3872
+ _ts_metadata10("design:type", Function),
3873
+ _ts_metadata10("design:paramtypes", [
3182
3874
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
3183
3875
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3184
3876
  typeof AgentService === "undefined" ? Object : AgentService,
@@ -3187,9 +3879,10 @@ AttachmentsController = _ts_decorate10([
3187
3879
  ], AttachmentsController);
3188
3880
 
3189
3881
  // src/controller/chat.controller.ts
3190
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
3191
- var import_common12 = require("@nestjs/common");
3192
- function _ts_decorate11(decorators, target, key, desc) {
3882
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3883
+ var import_genui2 = require("@dudousxd/nestjs-agent-core/genui");
3884
+ var import_common14 = require("@nestjs/common");
3885
+ function _ts_decorate13(decorators, target, key, desc) {
3193
3886
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3194
3887
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3195
3888
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3202,19 +3895,19 @@ function _ts_decorate11(decorators, target, key, desc) {
3202
3895
  }
3203
3896
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3204
3897
  }
3205
- __name(_ts_decorate11, "_ts_decorate");
3206
- function _ts_metadata10(metadataKey, metadataValue) {
3898
+ __name(_ts_decorate13, "_ts_decorate");
3899
+ function _ts_metadata11(metadataKey, metadataValue) {
3207
3900
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3208
3901
  return Reflect.metadata(metadataKey, metadataValue);
3209
3902
  }
3210
3903
  }
3211
- __name(_ts_metadata10, "_ts_metadata");
3212
- function _ts_param9(paramIndex, decorator) {
3904
+ __name(_ts_metadata11, "_ts_metadata");
3905
+ function _ts_param11(paramIndex, decorator) {
3213
3906
  return function(target, key) {
3214
3907
  decorator(target, key, paramIndex);
3215
3908
  };
3216
3909
  }
3217
- __name(_ts_param9, "_ts_param");
3910
+ __name(_ts_param11, "_ts_param");
3218
3911
  function sendMode(body) {
3219
3912
  if (body.interrupt === true) {
3220
3913
  return "interrupt";
@@ -3225,7 +3918,7 @@ function sendMode(body) {
3225
3918
  if (body.mode === "auto" || body.mode === "queue" || body.mode === "interrupt") {
3226
3919
  return body.mode;
3227
3920
  }
3228
- throw new import_common12.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
3921
+ throw new import_common14.BadRequestException("mode must be 'auto', 'queue' or 'interrupt'");
3229
3922
  }
3230
3923
  __name(sendMode, "sendMode");
3231
3924
  function attachmentRefs(claimed) {
@@ -3233,21 +3926,21 @@ function attachmentRefs(claimed) {
3233
3926
  return [];
3234
3927
  }
3235
3928
  if (!Array.isArray(claimed)) {
3236
- throw new import_common12.BadRequestException("attachments must be an array of { mediaId }");
3929
+ throw new import_common14.BadRequestException("attachments must be an array of { mediaId }");
3237
3930
  }
3238
3931
  if (claimed.length > MAX_ATTACHMENTS_PER_MESSAGE) {
3239
- throw new import_common12.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
3932
+ throw new import_common14.BadRequestException(`a message may carry at most ${MAX_ATTACHMENTS_PER_MESSAGE} attachments`);
3240
3933
  }
3241
3934
  return claimed.map((entry) => {
3242
3935
  if (typeof entry !== "object" || entry === null || !("mediaId" in entry)) {
3243
- throw new import_common12.BadRequestException("each attachment must be an object with a mediaId");
3936
+ throw new import_common14.BadRequestException("each attachment must be an object with a mediaId");
3244
3937
  }
3245
3938
  if (Object.keys(entry).some((key) => key !== "mediaId")) {
3246
- throw new import_common12.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
3939
+ throw new import_common14.BadRequestException("attachments are { mediaId } refs \u2014 send nothing but the id");
3247
3940
  }
3248
3941
  const { mediaId } = entry;
3249
3942
  if (typeof mediaId !== "string" || mediaId.length === 0) {
3250
- throw new import_common12.BadRequestException("each attachment must carry a non-empty string mediaId");
3943
+ throw new import_common14.BadRequestException("each attachment must carry a non-empty string mediaId");
3251
3944
  }
3252
3945
  return {
3253
3946
  mediaId
@@ -3275,15 +3968,27 @@ var ChatController = class {
3275
3968
  const actor = await this.actorResolver.resolve(req);
3276
3969
  const attachments = attachmentRefs(body.attachments);
3277
3970
  const mode = sendMode(body);
3971
+ let uiCapabilities;
3972
+ try {
3973
+ uiCapabilities = body.uiCapabilities === void 0 ? void 0 : (0, import_genui2.validateUiCapabilities)(body.uiCapabilities);
3974
+ } catch {
3975
+ throw new import_common14.BadRequestException("Invalid UI capabilities");
3976
+ }
3278
3977
  const result = await this.agent.send({
3279
3978
  actor,
3280
3979
  message: body.message,
3980
+ ...uiCapabilities !== void 0 ? {
3981
+ uiCapabilities
3982
+ } : {},
3281
3983
  ...body.threadId !== void 0 ? {
3282
3984
  threadId: body.threadId
3283
3985
  } : {},
3284
3986
  ...body.agent !== void 0 ? {
3285
3987
  agentName: body.agent
3286
3988
  } : {},
3989
+ ...typeof body.persona === "string" && body.persona.length > 0 ? {
3990
+ personaId: body.persona
3991
+ } : {},
3287
3992
  ...attachments.length > 0 ? {
3288
3993
  attachments
3289
3994
  } : {},
@@ -3301,6 +4006,10 @@ var ChatController = class {
3301
4006
  } : {},
3302
4007
  mode
3303
4008
  });
4009
+ if ("proposalDecision" in result) {
4010
+ res.status(200).json(result);
4011
+ return;
4012
+ }
3304
4013
  if (result.queued === true) {
3305
4014
  res.status(202).json(result);
3306
4015
  return;
@@ -3380,10 +4089,10 @@ data: ${line}
3380
4089
  }
3381
4090
  res.write("event: done\ndata: {}\n\n");
3382
4091
  } catch (error) {
3383
- const payload = error instanceof import_nestjs_agent_core13.AgentStreamError ? {
4092
+ const payload = error instanceof import_nestjs_agent_core17.AgentStreamError ? {
3384
4093
  code: error.code,
3385
4094
  message: error.message
3386
- } : (0, import_nestjs_agent_core13.streamFailure)(error);
4095
+ } : (0, import_nestjs_agent_core17.streamFailure)(error);
3387
4096
  res.write(`event: error
3388
4097
  data: ${JSON.stringify(payload)}
3389
4098
 
@@ -3392,50 +4101,50 @@ data: ${JSON.stringify(payload)}
3392
4101
  res.end();
3393
4102
  }
3394
4103
  };
3395
- _ts_decorate11([
3396
- (0, import_common12.Post)("chat"),
3397
- _ts_param9(0, (0, import_common12.Req)()),
3398
- _ts_param9(1, (0, import_common12.Res)()),
3399
- _ts_param9(2, (0, import_common12.Body)()),
3400
- _ts_metadata10("design:type", Function),
3401
- _ts_metadata10("design:paramtypes", [
4104
+ _ts_decorate13([
4105
+ (0, import_common14.Post)("chat"),
4106
+ _ts_param11(0, (0, import_common14.Req)()),
4107
+ _ts_param11(1, (0, import_common14.Res)()),
4108
+ _ts_param11(2, (0, import_common14.Body)()),
4109
+ _ts_metadata11("design:type", Function),
4110
+ _ts_metadata11("design:paramtypes", [
3402
4111
  typeof Request === "undefined" ? Object : Request,
3403
4112
  typeof Response === "undefined" ? Object : Response,
3404
4113
  typeof ChatBody === "undefined" ? Object : ChatBody
3405
4114
  ]),
3406
- _ts_metadata10("design:returntype", Promise)
4115
+ _ts_metadata11("design:returntype", Promise)
3407
4116
  ], ChatController.prototype, "chat", null);
3408
- _ts_decorate11([
3409
- (0, import_common12.Get)("chat/:runId/stream"),
3410
- _ts_param9(0, (0, import_common12.Req)()),
3411
- _ts_param9(1, (0, import_common12.Param)("runId")),
3412
- _ts_param9(2, (0, import_common12.Res)()),
3413
- _ts_param9(3, (0, import_common12.Query)("after")),
3414
- _ts_metadata10("design:type", Function),
3415
- _ts_metadata10("design:paramtypes", [
4117
+ _ts_decorate13([
4118
+ (0, import_common14.Get)("chat/:runId/stream"),
4119
+ _ts_param11(0, (0, import_common14.Req)()),
4120
+ _ts_param11(1, (0, import_common14.Param)("runId")),
4121
+ _ts_param11(2, (0, import_common14.Res)()),
4122
+ _ts_param11(3, (0, import_common14.Query)("after")),
4123
+ _ts_metadata11("design:type", Function),
4124
+ _ts_metadata11("design:paramtypes", [
3416
4125
  typeof Request === "undefined" ? Object : Request,
3417
4126
  String,
3418
4127
  typeof Response === "undefined" ? Object : Response,
3419
4128
  String
3420
4129
  ]),
3421
- _ts_metadata10("design:returntype", Promise)
4130
+ _ts_metadata11("design:returntype", Promise)
3422
4131
  ], ChatController.prototype, "stream", null);
3423
- _ts_decorate11([
3424
- (0, import_common12.Post)("chat/:runId/cancel"),
3425
- _ts_param9(0, (0, import_common12.Req)()),
3426
- _ts_param9(1, (0, import_common12.Param)("runId")),
3427
- _ts_metadata10("design:type", Function),
3428
- _ts_metadata10("design:paramtypes", [
4132
+ _ts_decorate13([
4133
+ (0, import_common14.Post)("chat/:runId/cancel"),
4134
+ _ts_param11(0, (0, import_common14.Req)()),
4135
+ _ts_param11(1, (0, import_common14.Param)("runId")),
4136
+ _ts_metadata11("design:type", Function),
4137
+ _ts_metadata11("design:paramtypes", [
3429
4138
  typeof Request === "undefined" ? Object : Request,
3430
4139
  String
3431
4140
  ]),
3432
- _ts_metadata10("design:returntype", Promise)
4141
+ _ts_metadata11("design:returntype", Promise)
3433
4142
  ], ChatController.prototype, "cancel", null);
3434
- ChatController = _ts_decorate11([
3435
- (0, import_common12.Controller)(),
3436
- _ts_param9(1, (0, import_common12.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
3437
- _ts_metadata10("design:type", Function),
3438
- _ts_metadata10("design:paramtypes", [
4143
+ ChatController = _ts_decorate13([
4144
+ (0, import_common14.Controller)(),
4145
+ _ts_param11(1, (0, import_common14.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
4146
+ _ts_metadata11("design:type", Function),
4147
+ _ts_metadata11("design:paramtypes", [
3439
4148
  typeof AgentService === "undefined" ? Object : AgentService,
3440
4149
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3441
4150
  ])
@@ -3451,8 +4160,8 @@ function parseCursor(raw) {
3451
4160
  __name(parseCursor, "parseCursor");
3452
4161
 
3453
4162
  // src/controller/config.controller.ts
3454
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
3455
- var import_common13 = require("@nestjs/common");
4163
+ var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
4164
+ var import_common15 = require("@nestjs/common");
3456
4165
 
3457
4166
  // src/resolver/anonymous-actor-resolver.ts
3458
4167
  var import_node_crypto2 = require("crypto");
@@ -3542,7 +4251,7 @@ var AnonymousActorResolver = class {
3542
4251
  };
3543
4252
 
3544
4253
  // src/controller/config.controller.ts
3545
- function _ts_decorate12(decorators, target, key, desc) {
4254
+ function _ts_decorate14(decorators, target, key, desc) {
3546
4255
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3547
4256
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3548
4257
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3555,19 +4264,19 @@ function _ts_decorate12(decorators, target, key, desc) {
3555
4264
  }
3556
4265
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3557
4266
  }
3558
- __name(_ts_decorate12, "_ts_decorate");
3559
- function _ts_metadata11(metadataKey, metadataValue) {
4267
+ __name(_ts_decorate14, "_ts_decorate");
4268
+ function _ts_metadata12(metadataKey, metadataValue) {
3560
4269
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3561
4270
  return Reflect.metadata(metadataKey, metadataValue);
3562
4271
  }
3563
4272
  }
3564
- __name(_ts_metadata11, "_ts_metadata");
3565
- function _ts_param10(paramIndex, decorator) {
4273
+ __name(_ts_metadata12, "_ts_metadata");
4274
+ function _ts_param12(paramIndex, decorator) {
3566
4275
  return function(target, key) {
3567
4276
  decorator(target, key, paramIndex);
3568
4277
  };
3569
4278
  }
3570
- __name(_ts_param10, "_ts_param");
4279
+ __name(_ts_param12, "_ts_param");
3571
4280
  var ConfigController = class {
3572
4281
  static {
3573
4282
  __name(this, "ConfigController");
@@ -3598,25 +4307,25 @@ var ConfigController = class {
3598
4307
  };
3599
4308
  }
3600
4309
  };
3601
- _ts_decorate12([
3602
- (0, import_common13.Get)(),
3603
- _ts_param10(0, (0, import_common13.Req)()),
3604
- _ts_metadata11("design:type", Function),
3605
- _ts_metadata11("design:paramtypes", [
4310
+ _ts_decorate14([
4311
+ (0, import_common15.Get)(),
4312
+ _ts_param12(0, (0, import_common15.Req)()),
4313
+ _ts_metadata12("design:type", Function),
4314
+ _ts_metadata12("design:paramtypes", [
3606
4315
  typeof Request === "undefined" ? Object : Request
3607
4316
  ]),
3608
- _ts_metadata11("design:returntype", Promise)
4317
+ _ts_metadata12("design:returntype", Promise)
3609
4318
  ], ConfigController.prototype, "config", null);
3610
- ConfigController = _ts_decorate12([
3611
- (0, import_common13.Controller)("config"),
3612
- _ts_param10(0, (0, import_common13.Inject)(import_nestjs_agent_core14.AGENT_OPTIONS)),
3613
- _ts_param10(1, (0, import_common13.Inject)(import_nestjs_agent_core14.AGENT_ACTOR_RESOLVER)),
3614
- _ts_param10(2, (0, import_common13.Optional)()),
3615
- _ts_param10(2, (0, import_common13.Inject)(import_nestjs_agent_core14.AGENT_ATTACHMENT_STAGING)),
3616
- _ts_param10(3, (0, import_common13.Optional)()),
3617
- _ts_param10(3, (0, import_common13.Inject)(import_nestjs_agent_core14.AGENT_MODEL_CATALOG)),
3618
- _ts_metadata11("design:type", Function),
3619
- _ts_metadata11("design:paramtypes", [
4319
+ ConfigController = _ts_decorate14([
4320
+ (0, import_common15.Controller)("config"),
4321
+ _ts_param12(0, (0, import_common15.Inject)(import_nestjs_agent_core18.AGENT_OPTIONS)),
4322
+ _ts_param12(1, (0, import_common15.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
4323
+ _ts_param12(2, (0, import_common15.Optional)()),
4324
+ _ts_param12(2, (0, import_common15.Inject)(import_nestjs_agent_core18.AGENT_ATTACHMENT_STAGING)),
4325
+ _ts_param12(3, (0, import_common15.Optional)()),
4326
+ _ts_param12(3, (0, import_common15.Inject)(import_nestjs_agent_core18.AGENT_MODEL_CATALOG)),
4327
+ _ts_metadata12("design:type", Function),
4328
+ _ts_metadata12("design:paramtypes", [
3620
4329
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
3621
4330
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3622
4331
  Object,
@@ -3625,9 +4334,9 @@ ConfigController = _ts_decorate12([
3625
4334
  ], ConfigController);
3626
4335
 
3627
4336
  // src/controller/memories.controller.ts
3628
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
3629
- var import_common14 = require("@nestjs/common");
3630
- function _ts_decorate13(decorators, target, key, desc) {
4337
+ var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
4338
+ var import_common16 = require("@nestjs/common");
4339
+ function _ts_decorate15(decorators, target, key, desc) {
3631
4340
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3632
4341
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3633
4342
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3640,19 +4349,19 @@ function _ts_decorate13(decorators, target, key, desc) {
3640
4349
  }
3641
4350
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3642
4351
  }
3643
- __name(_ts_decorate13, "_ts_decorate");
3644
- function _ts_metadata12(metadataKey, metadataValue) {
4352
+ __name(_ts_decorate15, "_ts_decorate");
4353
+ function _ts_metadata13(metadataKey, metadataValue) {
3645
4354
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3646
4355
  return Reflect.metadata(metadataKey, metadataValue);
3647
4356
  }
3648
4357
  }
3649
- __name(_ts_metadata12, "_ts_metadata");
3650
- function _ts_param11(paramIndex, decorator) {
4358
+ __name(_ts_metadata13, "_ts_metadata");
4359
+ function _ts_param13(paramIndex, decorator) {
3651
4360
  return function(target, key) {
3652
4361
  decorator(target, key, paramIndex);
3653
4362
  };
3654
4363
  }
3655
- __name(_ts_param11, "_ts_param");
4364
+ __name(_ts_param13, "_ts_param");
3656
4365
  var MemoriesController = class {
3657
4366
  static {
3658
4367
  __name(this, "MemoriesController");
@@ -3686,20 +4395,20 @@ var MemoriesController = class {
3686
4395
  */
3687
4396
  async forget(req, id) {
3688
4397
  if (this.memory === void 0) {
3689
- throw new import_common14.NotFoundException("No memory is configured in this deployment.");
4398
+ throw new import_common16.NotFoundException("No memory is configured in this deployment.");
3690
4399
  }
3691
4400
  const actor = await this.actorResolver.resolve(req);
3692
4401
  const digest = await this.unbounded("", actor);
3693
4402
  const entry = digest.entries.find((candidate) => candidate.id === id);
3694
4403
  if (entry === void 0) {
3695
- throw new import_common14.NotFoundException(`No memory with id "${id}".`);
4404
+ throw new import_common16.NotFoundException(`No memory with id "${id}".`);
3696
4405
  }
3697
- const verdict = (0, import_nestjs_agent_core15.memoryForgetVerdict)({
4406
+ const verdict = (0, import_nestjs_agent_core19.memoryForgetVerdict)({
3698
4407
  record: entry,
3699
4408
  actor
3700
4409
  });
3701
4410
  if (!verdict.allowed) {
3702
- throw new import_common14.ForbiddenException(verdict.reason);
4411
+ throw new import_common16.ForbiddenException(verdict.reason);
3703
4412
  }
3704
4413
  return {
3705
4414
  forgotten: await this.memory.provider.forget({
@@ -3713,7 +4422,7 @@ var MemoriesController = class {
3713
4422
  }
3714
4423
  async unbounded(threadId, actor) {
3715
4424
  const config = this.memory;
3716
- return await (0, import_nestjs_agent_core15.offerMemories)({
4425
+ return await (0, import_nestjs_agent_core19.offerMemories)({
3717
4426
  config: {
3718
4427
  ...config,
3719
4428
  maxMemories: Number.POSITIVE_INFINITY
@@ -3725,44 +4434,44 @@ var MemoriesController = class {
3725
4434
  });
3726
4435
  }
3727
4436
  };
3728
- _ts_decorate13([
3729
- (0, import_common14.Get)(),
3730
- _ts_param11(0, (0, import_common14.Req)()),
3731
- _ts_param11(1, (0, import_common14.Query)("threadId")),
3732
- _ts_metadata12("design:type", Function),
3733
- _ts_metadata12("design:paramtypes", [
4437
+ _ts_decorate15([
4438
+ (0, import_common16.Get)(),
4439
+ _ts_param13(0, (0, import_common16.Req)()),
4440
+ _ts_param13(1, (0, import_common16.Query)("threadId")),
4441
+ _ts_metadata13("design:type", Function),
4442
+ _ts_metadata13("design:paramtypes", [
3734
4443
  typeof Request === "undefined" ? Object : Request,
3735
4444
  String
3736
4445
  ]),
3737
- _ts_metadata12("design:returntype", Promise)
4446
+ _ts_metadata13("design:returntype", Promise)
3738
4447
  ], MemoriesController.prototype, "list", null);
3739
- _ts_decorate13([
3740
- (0, import_common14.Delete)(":id"),
3741
- _ts_param11(0, (0, import_common14.Req)()),
3742
- _ts_param11(1, (0, import_common14.Param)("id")),
3743
- _ts_metadata12("design:type", Function),
3744
- _ts_metadata12("design:paramtypes", [
4448
+ _ts_decorate15([
4449
+ (0, import_common16.Delete)(":id"),
4450
+ _ts_param13(0, (0, import_common16.Req)()),
4451
+ _ts_param13(1, (0, import_common16.Param)("id")),
4452
+ _ts_metadata13("design:type", Function),
4453
+ _ts_metadata13("design:paramtypes", [
3745
4454
  typeof Request === "undefined" ? Object : Request,
3746
4455
  String
3747
4456
  ]),
3748
- _ts_metadata12("design:returntype", Promise)
4457
+ _ts_metadata13("design:returntype", Promise)
3749
4458
  ], MemoriesController.prototype, "forget", null);
3750
- MemoriesController = _ts_decorate13([
3751
- (0, import_common14.Controller)("memories"),
3752
- _ts_param11(0, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_ACTOR_RESOLVER)),
3753
- _ts_param11(1, (0, import_common14.Optional)()),
3754
- _ts_param11(1, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_MEMORY)),
3755
- _ts_metadata12("design:type", Function),
3756
- _ts_metadata12("design:paramtypes", [
4459
+ MemoriesController = _ts_decorate15([
4460
+ (0, import_common16.Controller)("memories"),
4461
+ _ts_param13(0, (0, import_common16.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
4462
+ _ts_param13(1, (0, import_common16.Optional)()),
4463
+ _ts_param13(1, (0, import_common16.Inject)(import_nestjs_agent_core19.AGENT_MEMORY)),
4464
+ _ts_metadata13("design:type", Function),
4465
+ _ts_metadata13("design:paramtypes", [
3757
4466
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
3758
4467
  Object
3759
4468
  ])
3760
4469
  ], MemoriesController);
3761
4470
 
3762
4471
  // src/controller/messages.controller.ts
3763
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
3764
- var import_common15 = require("@nestjs/common");
3765
- function _ts_decorate14(decorators, target, key, desc) {
4472
+ var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4473
+ var import_common17 = require("@nestjs/common");
4474
+ function _ts_decorate16(decorators, target, key, desc) {
3766
4475
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3767
4476
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3768
4477
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3775,19 +4484,19 @@ function _ts_decorate14(decorators, target, key, desc) {
3775
4484
  }
3776
4485
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3777
4486
  }
3778
- __name(_ts_decorate14, "_ts_decorate");
3779
- function _ts_metadata13(metadataKey, metadataValue) {
4487
+ __name(_ts_decorate16, "_ts_decorate");
4488
+ function _ts_metadata14(metadataKey, metadataValue) {
3780
4489
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3781
4490
  return Reflect.metadata(metadataKey, metadataValue);
3782
4491
  }
3783
4492
  }
3784
- __name(_ts_metadata13, "_ts_metadata");
3785
- function _ts_param12(paramIndex, decorator) {
4493
+ __name(_ts_metadata14, "_ts_metadata");
4494
+ function _ts_param14(paramIndex, decorator) {
3786
4495
  return function(target, key) {
3787
4496
  decorator(target, key, paramIndex);
3788
4497
  };
3789
4498
  }
3790
- __name(_ts_param12, "_ts_param");
4499
+ __name(_ts_param14, "_ts_param");
3791
4500
  var MessagesController = class {
3792
4501
  static {
3793
4502
  __name(this, "MessagesController");
@@ -3815,34 +4524,34 @@ var MessagesController = class {
3815
4524
  };
3816
4525
  }
3817
4526
  };
3818
- _ts_decorate14([
3819
- (0, import_common15.Post)(":id/feedback"),
3820
- (0, import_common15.HttpCode)(200),
3821
- _ts_param12(0, (0, import_common15.Req)()),
3822
- _ts_param12(1, (0, import_common15.Param)("id")),
3823
- _ts_param12(2, (0, import_common15.Body)()),
3824
- _ts_metadata13("design:type", Function),
3825
- _ts_metadata13("design:paramtypes", [
4527
+ _ts_decorate16([
4528
+ (0, import_common17.Post)(":id/feedback"),
4529
+ (0, import_common17.HttpCode)(200),
4530
+ _ts_param14(0, (0, import_common17.Req)()),
4531
+ _ts_param14(1, (0, import_common17.Param)("id")),
4532
+ _ts_param14(2, (0, import_common17.Body)()),
4533
+ _ts_metadata14("design:type", Function),
4534
+ _ts_metadata14("design:paramtypes", [
3826
4535
  typeof Request === "undefined" ? Object : Request,
3827
4536
  String,
3828
4537
  typeof FeedbackBody === "undefined" ? Object : FeedbackBody
3829
4538
  ]),
3830
- _ts_metadata13("design:returntype", Promise)
4539
+ _ts_metadata14("design:returntype", Promise)
3831
4540
  ], MessagesController.prototype, "feedback", null);
3832
- MessagesController = _ts_decorate14([
3833
- (0, import_common15.Controller)("messages"),
3834
- _ts_param12(1, (0, import_common15.Inject)(import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER)),
3835
- _ts_metadata13("design:type", Function),
3836
- _ts_metadata13("design:paramtypes", [
4541
+ MessagesController = _ts_decorate16([
4542
+ (0, import_common17.Controller)("messages"),
4543
+ _ts_param14(1, (0, import_common17.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
4544
+ _ts_metadata14("design:type", Function),
4545
+ _ts_metadata14("design:paramtypes", [
3837
4546
  typeof AgentService === "undefined" ? Object : AgentService,
3838
4547
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3839
4548
  ])
3840
4549
  ], MessagesController);
3841
4550
 
3842
4551
  // src/controller/models.controller.ts
3843
- var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
3844
- var import_common16 = require("@nestjs/common");
3845
- function _ts_decorate15(decorators, target, key, desc) {
4552
+ var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4553
+ var import_common18 = require("@nestjs/common");
4554
+ function _ts_decorate17(decorators, target, key, desc) {
3846
4555
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3847
4556
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3848
4557
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3855,19 +4564,19 @@ function _ts_decorate15(decorators, target, key, desc) {
3855
4564
  }
3856
4565
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3857
4566
  }
3858
- __name(_ts_decorate15, "_ts_decorate");
3859
- function _ts_metadata14(metadataKey, metadataValue) {
4567
+ __name(_ts_decorate17, "_ts_decorate");
4568
+ function _ts_metadata15(metadataKey, metadataValue) {
3860
4569
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3861
4570
  return Reflect.metadata(metadataKey, metadataValue);
3862
4571
  }
3863
4572
  }
3864
- __name(_ts_metadata14, "_ts_metadata");
3865
- function _ts_param13(paramIndex, decorator) {
4573
+ __name(_ts_metadata15, "_ts_metadata");
4574
+ function _ts_param15(paramIndex, decorator) {
3866
4575
  return function(target, key) {
3867
4576
  decorator(target, key, paramIndex);
3868
4577
  };
3869
4578
  }
3870
- __name(_ts_param13, "_ts_param");
4579
+ __name(_ts_param15, "_ts_param");
3871
4580
  var ModelsController = class {
3872
4581
  static {
3873
4582
  __name(this, "ModelsController");
@@ -3887,31 +4596,31 @@ var ModelsController = class {
3887
4596
  return this.agent.listModels(actor, agent);
3888
4597
  }
3889
4598
  };
3890
- _ts_decorate15([
3891
- (0, import_common16.Get)(),
3892
- _ts_param13(0, (0, import_common16.Req)()),
3893
- _ts_param13(1, (0, import_common16.Query)("agent")),
3894
- _ts_metadata14("design:type", Function),
3895
- _ts_metadata14("design:paramtypes", [
4599
+ _ts_decorate17([
4600
+ (0, import_common18.Get)(),
4601
+ _ts_param15(0, (0, import_common18.Req)()),
4602
+ _ts_param15(1, (0, import_common18.Query)("agent")),
4603
+ _ts_metadata15("design:type", Function),
4604
+ _ts_metadata15("design:paramtypes", [
3896
4605
  typeof Request === "undefined" ? Object : Request,
3897
4606
  String
3898
4607
  ]),
3899
- _ts_metadata14("design:returntype", Promise)
4608
+ _ts_metadata15("design:returntype", Promise)
3900
4609
  ], ModelsController.prototype, "list", null);
3901
- ModelsController = _ts_decorate15([
3902
- (0, import_common16.Controller)("models"),
3903
- _ts_param13(1, (0, import_common16.Inject)(import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER)),
3904
- _ts_metadata14("design:type", Function),
3905
- _ts_metadata14("design:paramtypes", [
4610
+ ModelsController = _ts_decorate17([
4611
+ (0, import_common18.Controller)("models"),
4612
+ _ts_param15(1, (0, import_common18.Inject)(import_nestjs_agent_core21.AGENT_ACTOR_RESOLVER)),
4613
+ _ts_metadata15("design:type", Function),
4614
+ _ts_metadata15("design:paramtypes", [
3906
4615
  typeof AgentService === "undefined" ? Object : AgentService,
3907
4616
  typeof ActorResolver === "undefined" ? Object : ActorResolver
3908
4617
  ])
3909
4618
  ], ModelsController);
3910
4619
 
3911
4620
  // src/controller/queue.controller.ts
3912
- var import_nestjs_agent_core18 = require("@dudousxd/nestjs-agent-core");
3913
- var import_common17 = require("@nestjs/common");
3914
- function _ts_decorate16(decorators, target, key, desc) {
4621
+ var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4622
+ var import_common19 = require("@nestjs/common");
4623
+ function _ts_decorate18(decorators, target, key, desc) {
3915
4624
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3916
4625
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
3917
4626
  r = Reflect.decorate(decorators, target, key, desc);
@@ -3924,19 +4633,19 @@ function _ts_decorate16(decorators, target, key, desc) {
3924
4633
  }
3925
4634
  return c > 3 && r && Object.defineProperty(target, key, r), r;
3926
4635
  }
3927
- __name(_ts_decorate16, "_ts_decorate");
3928
- function _ts_metadata15(metadataKey, metadataValue) {
4636
+ __name(_ts_decorate18, "_ts_decorate");
4637
+ function _ts_metadata16(metadataKey, metadataValue) {
3929
4638
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
3930
4639
  return Reflect.metadata(metadataKey, metadataValue);
3931
4640
  }
3932
4641
  }
3933
- __name(_ts_metadata15, "_ts_metadata");
3934
- function _ts_param14(paramIndex, decorator) {
4642
+ __name(_ts_metadata16, "_ts_metadata");
4643
+ function _ts_param16(paramIndex, decorator) {
3935
4644
  return function(target, key) {
3936
4645
  decorator(target, key, paramIndex);
3937
4646
  };
3938
4647
  }
3939
- __name(_ts_param14, "_ts_param");
4648
+ __name(_ts_param16, "_ts_param");
3940
4649
  var QueueController = class {
3941
4650
  static {
3942
4651
  __name(this, "QueueController");
@@ -3960,10 +4669,10 @@ var QueueController = class {
3960
4669
  async update(req, messageId, body) {
3961
4670
  const actor = await this.actorResolver.resolve(req);
3962
4671
  if (body.message !== void 0 && typeof body.message !== "string") {
3963
- throw new import_common17.BadRequestException("message must be a string");
4672
+ throw new import_common19.BadRequestException("message must be a string");
3964
4673
  }
3965
4674
  if (body.position !== void 0 && typeof body.position !== "number") {
3966
- throw new import_common17.BadRequestException("position must be a number");
4675
+ throw new import_common19.BadRequestException("position must be a number");
3967
4676
  }
3968
4677
  const attachments = body.attachments === void 0 ? void 0 : body.attachments === null ? null : attachmentRefs(body.attachments);
3969
4678
  return this.agent.updateQueuedMessage(actor, messageId, {
@@ -3990,88 +4699,88 @@ var QueueController = class {
3990
4699
  return this.agent.removeQueuedMessage(await this.actorResolver.resolve(req), messageId);
3991
4700
  }
3992
4701
  };
3993
- _ts_decorate16([
3994
- (0, import_common17.Get)("threads/:id/queue"),
3995
- _ts_param14(0, (0, import_common17.Req)()),
3996
- _ts_param14(1, (0, import_common17.Param)("id")),
3997
- _ts_metadata15("design:type", Function),
3998
- _ts_metadata15("design:paramtypes", [
4702
+ _ts_decorate18([
4703
+ (0, import_common19.Get)("threads/:id/queue"),
4704
+ _ts_param16(0, (0, import_common19.Req)()),
4705
+ _ts_param16(1, (0, import_common19.Param)("id")),
4706
+ _ts_metadata16("design:type", Function),
4707
+ _ts_metadata16("design:paramtypes", [
3999
4708
  typeof Request === "undefined" ? Object : Request,
4000
4709
  String
4001
4710
  ]),
4002
- _ts_metadata15("design:returntype", Promise)
4711
+ _ts_metadata16("design:returntype", Promise)
4003
4712
  ], QueueController.prototype, "list", null);
4004
- _ts_decorate16([
4005
- (0, import_common17.Delete)("threads/:id/queue"),
4006
- _ts_param14(0, (0, import_common17.Req)()),
4007
- _ts_param14(1, (0, import_common17.Param)("id")),
4008
- _ts_metadata15("design:type", Function),
4009
- _ts_metadata15("design:paramtypes", [
4713
+ _ts_decorate18([
4714
+ (0, import_common19.Delete)("threads/:id/queue"),
4715
+ _ts_param16(0, (0, import_common19.Req)()),
4716
+ _ts_param16(1, (0, import_common19.Param)("id")),
4717
+ _ts_metadata16("design:type", Function),
4718
+ _ts_metadata16("design:paramtypes", [
4010
4719
  typeof Request === "undefined" ? Object : Request,
4011
4720
  String
4012
4721
  ]),
4013
- _ts_metadata15("design:returntype", Promise)
4722
+ _ts_metadata16("design:returntype", Promise)
4014
4723
  ], QueueController.prototype, "clear", null);
4015
- _ts_decorate16([
4016
- (0, import_common17.Post)("threads/:id/queue/resume"),
4017
- _ts_param14(0, (0, import_common17.Req)()),
4018
- _ts_param14(1, (0, import_common17.Param)("id")),
4019
- _ts_metadata15("design:type", Function),
4020
- _ts_metadata15("design:paramtypes", [
4724
+ _ts_decorate18([
4725
+ (0, import_common19.Post)("threads/:id/queue/resume"),
4726
+ _ts_param16(0, (0, import_common19.Req)()),
4727
+ _ts_param16(1, (0, import_common19.Param)("id")),
4728
+ _ts_metadata16("design:type", Function),
4729
+ _ts_metadata16("design:paramtypes", [
4021
4730
  typeof Request === "undefined" ? Object : Request,
4022
4731
  String
4023
4732
  ]),
4024
- _ts_metadata15("design:returntype", Promise)
4733
+ _ts_metadata16("design:returntype", Promise)
4025
4734
  ], QueueController.prototype, "resume", null);
4026
- _ts_decorate16([
4027
- (0, import_common17.Patch)("queue/:messageId"),
4028
- _ts_param14(0, (0, import_common17.Req)()),
4029
- _ts_param14(1, (0, import_common17.Param)("messageId")),
4030
- _ts_param14(2, (0, import_common17.Body)()),
4031
- _ts_metadata15("design:type", Function),
4032
- _ts_metadata15("design:paramtypes", [
4735
+ _ts_decorate18([
4736
+ (0, import_common19.Patch)("queue/:messageId"),
4737
+ _ts_param16(0, (0, import_common19.Req)()),
4738
+ _ts_param16(1, (0, import_common19.Param)("messageId")),
4739
+ _ts_param16(2, (0, import_common19.Body)()),
4740
+ _ts_metadata16("design:type", Function),
4741
+ _ts_metadata16("design:paramtypes", [
4033
4742
  typeof Request === "undefined" ? Object : Request,
4034
4743
  String,
4035
4744
  typeof UpdateQueuedMessageBody === "undefined" ? Object : UpdateQueuedMessageBody
4036
4745
  ]),
4037
- _ts_metadata15("design:returntype", Promise)
4746
+ _ts_metadata16("design:returntype", Promise)
4038
4747
  ], QueueController.prototype, "update", null);
4039
- _ts_decorate16([
4040
- (0, import_common17.Post)("queue/:messageId/interrupt"),
4041
- _ts_param14(0, (0, import_common17.Req)()),
4042
- _ts_param14(1, (0, import_common17.Param)("messageId")),
4043
- _ts_metadata15("design:type", Function),
4044
- _ts_metadata15("design:paramtypes", [
4748
+ _ts_decorate18([
4749
+ (0, import_common19.Post)("queue/:messageId/interrupt"),
4750
+ _ts_param16(0, (0, import_common19.Req)()),
4751
+ _ts_param16(1, (0, import_common19.Param)("messageId")),
4752
+ _ts_metadata16("design:type", Function),
4753
+ _ts_metadata16("design:paramtypes", [
4045
4754
  typeof Request === "undefined" ? Object : Request,
4046
4755
  String
4047
4756
  ]),
4048
- _ts_metadata15("design:returntype", Promise)
4757
+ _ts_metadata16("design:returntype", Promise)
4049
4758
  ], QueueController.prototype, "interrupt", null);
4050
- _ts_decorate16([
4051
- (0, import_common17.Delete)("queue/:messageId"),
4052
- _ts_param14(0, (0, import_common17.Req)()),
4053
- _ts_param14(1, (0, import_common17.Param)("messageId")),
4054
- _ts_metadata15("design:type", Function),
4055
- _ts_metadata15("design:paramtypes", [
4759
+ _ts_decorate18([
4760
+ (0, import_common19.Delete)("queue/:messageId"),
4761
+ _ts_param16(0, (0, import_common19.Req)()),
4762
+ _ts_param16(1, (0, import_common19.Param)("messageId")),
4763
+ _ts_metadata16("design:type", Function),
4764
+ _ts_metadata16("design:paramtypes", [
4056
4765
  typeof Request === "undefined" ? Object : Request,
4057
4766
  String
4058
4767
  ]),
4059
- _ts_metadata15("design:returntype", Promise)
4768
+ _ts_metadata16("design:returntype", Promise)
4060
4769
  ], QueueController.prototype, "remove", null);
4061
- QueueController = _ts_decorate16([
4062
- (0, import_common17.Controller)(),
4063
- _ts_param14(1, (0, import_common17.Inject)(import_nestjs_agent_core18.AGENT_ACTOR_RESOLVER)),
4064
- _ts_metadata15("design:type", Function),
4065
- _ts_metadata15("design:paramtypes", [
4770
+ QueueController = _ts_decorate18([
4771
+ (0, import_common19.Controller)(),
4772
+ _ts_param16(1, (0, import_common19.Inject)(import_nestjs_agent_core22.AGENT_ACTOR_RESOLVER)),
4773
+ _ts_metadata16("design:type", Function),
4774
+ _ts_metadata16("design:paramtypes", [
4066
4775
  typeof AgentService === "undefined" ? Object : AgentService,
4067
4776
  typeof ActorResolver === "undefined" ? Object : ActorResolver
4068
4777
  ])
4069
4778
  ], QueueController);
4070
4779
 
4071
4780
  // src/controller/quota.controller.ts
4072
- var import_nestjs_agent_core19 = require("@dudousxd/nestjs-agent-core");
4073
- var import_common18 = require("@nestjs/common");
4074
- function _ts_decorate17(decorators, target, key, desc) {
4781
+ var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4782
+ var import_common20 = require("@nestjs/common");
4783
+ function _ts_decorate19(decorators, target, key, desc) {
4075
4784
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4076
4785
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4077
4786
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4084,19 +4793,19 @@ function _ts_decorate17(decorators, target, key, desc) {
4084
4793
  }
4085
4794
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4086
4795
  }
4087
- __name(_ts_decorate17, "_ts_decorate");
4088
- function _ts_metadata16(metadataKey, metadataValue) {
4796
+ __name(_ts_decorate19, "_ts_decorate");
4797
+ function _ts_metadata17(metadataKey, metadataValue) {
4089
4798
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4090
4799
  return Reflect.metadata(metadataKey, metadataValue);
4091
4800
  }
4092
4801
  }
4093
- __name(_ts_metadata16, "_ts_metadata");
4094
- function _ts_param15(paramIndex, decorator) {
4802
+ __name(_ts_metadata17, "_ts_metadata");
4803
+ function _ts_param17(paramIndex, decorator) {
4095
4804
  return function(target, key) {
4096
4805
  decorator(target, key, paramIndex);
4097
4806
  };
4098
4807
  }
4099
- __name(_ts_param15, "_ts_param");
4808
+ __name(_ts_param17, "_ts_param");
4100
4809
  var QuotaController = class {
4101
4810
  static {
4102
4811
  __name(this, "QuotaController");
@@ -4116,29 +4825,29 @@ var QuotaController = class {
4116
4825
  return this.agent.quotaReport(actor);
4117
4826
  }
4118
4827
  };
4119
- _ts_decorate17([
4120
- (0, import_common18.Get)(),
4121
- _ts_param15(0, (0, import_common18.Req)()),
4122
- _ts_metadata16("design:type", Function),
4123
- _ts_metadata16("design:paramtypes", [
4828
+ _ts_decorate19([
4829
+ (0, import_common20.Get)(),
4830
+ _ts_param17(0, (0, import_common20.Req)()),
4831
+ _ts_metadata17("design:type", Function),
4832
+ _ts_metadata17("design:paramtypes", [
4124
4833
  typeof Request === "undefined" ? Object : Request
4125
4834
  ]),
4126
- _ts_metadata16("design:returntype", Promise)
4835
+ _ts_metadata17("design:returntype", Promise)
4127
4836
  ], QuotaController.prototype, "report", null);
4128
- QuotaController = _ts_decorate17([
4129
- (0, import_common18.Controller)("quota"),
4130
- _ts_param15(1, (0, import_common18.Inject)(import_nestjs_agent_core19.AGENT_ACTOR_RESOLVER)),
4131
- _ts_metadata16("design:type", Function),
4132
- _ts_metadata16("design:paramtypes", [
4837
+ QuotaController = _ts_decorate19([
4838
+ (0, import_common20.Controller)("quota"),
4839
+ _ts_param17(1, (0, import_common20.Inject)(import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER)),
4840
+ _ts_metadata17("design:type", Function),
4841
+ _ts_metadata17("design:paramtypes", [
4133
4842
  typeof AgentService === "undefined" ? Object : AgentService,
4134
4843
  typeof ActorResolver === "undefined" ? Object : ActorResolver
4135
4844
  ])
4136
4845
  ], QuotaController);
4137
4846
 
4138
4847
  // src/controller/skills.controller.ts
4139
- var import_nestjs_agent_core20 = require("@dudousxd/nestjs-agent-core");
4140
- var import_common19 = require("@nestjs/common");
4141
- function _ts_decorate18(decorators, target, key, desc) {
4848
+ var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4849
+ var import_common21 = require("@nestjs/common");
4850
+ function _ts_decorate20(decorators, target, key, desc) {
4142
4851
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4143
4852
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4144
4853
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4151,19 +4860,19 @@ function _ts_decorate18(decorators, target, key, desc) {
4151
4860
  }
4152
4861
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4153
4862
  }
4154
- __name(_ts_decorate18, "_ts_decorate");
4155
- function _ts_metadata17(metadataKey, metadataValue) {
4863
+ __name(_ts_decorate20, "_ts_decorate");
4864
+ function _ts_metadata18(metadataKey, metadataValue) {
4156
4865
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4157
4866
  return Reflect.metadata(metadataKey, metadataValue);
4158
4867
  }
4159
4868
  }
4160
- __name(_ts_metadata17, "_ts_metadata");
4161
- function _ts_param16(paramIndex, decorator) {
4869
+ __name(_ts_metadata18, "_ts_metadata");
4870
+ function _ts_param18(paramIndex, decorator) {
4162
4871
  return function(target, key) {
4163
4872
  decorator(target, key, paramIndex);
4164
4873
  };
4165
4874
  }
4166
- __name(_ts_param16, "_ts_param");
4875
+ __name(_ts_param18, "_ts_param");
4167
4876
  var SkillsController = class {
4168
4877
  static {
4169
4878
  __name(this, "SkillsController");
@@ -4179,40 +4888,40 @@ var SkillsController = class {
4179
4888
  return [];
4180
4889
  }
4181
4890
  const actor = await this.actorResolver.resolve(req);
4182
- const offer = await (0, import_nestjs_agent_core20.offerSkills)(this.skills, {
4891
+ const offer = await (0, import_nestjs_agent_core24.offerSkills)(this.skills, {
4183
4892
  actor,
4184
4893
  threadId: threadId ?? ""
4185
4894
  });
4186
4895
  return offer.entries;
4187
4896
  }
4188
4897
  };
4189
- _ts_decorate18([
4190
- (0, import_common19.Get)(),
4191
- _ts_param16(0, (0, import_common19.Req)()),
4192
- _ts_param16(1, (0, import_common19.Query)("threadId")),
4193
- _ts_metadata17("design:type", Function),
4194
- _ts_metadata17("design:paramtypes", [
4898
+ _ts_decorate20([
4899
+ (0, import_common21.Get)(),
4900
+ _ts_param18(0, (0, import_common21.Req)()),
4901
+ _ts_param18(1, (0, import_common21.Query)("threadId")),
4902
+ _ts_metadata18("design:type", Function),
4903
+ _ts_metadata18("design:paramtypes", [
4195
4904
  typeof Request === "undefined" ? Object : Request,
4196
4905
  String
4197
4906
  ]),
4198
- _ts_metadata17("design:returntype", Promise)
4907
+ _ts_metadata18("design:returntype", Promise)
4199
4908
  ], SkillsController.prototype, "list", null);
4200
- SkillsController = _ts_decorate18([
4201
- (0, import_common19.Controller)("skills"),
4202
- _ts_param16(0, (0, import_common19.Inject)(import_nestjs_agent_core20.AGENT_ACTOR_RESOLVER)),
4203
- _ts_param16(1, (0, import_common19.Optional)()),
4204
- _ts_param16(1, (0, import_common19.Inject)(import_nestjs_agent_core20.AGENT_SKILLS)),
4205
- _ts_metadata17("design:type", Function),
4206
- _ts_metadata17("design:paramtypes", [
4909
+ SkillsController = _ts_decorate20([
4910
+ (0, import_common21.Controller)("skills"),
4911
+ _ts_param18(0, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_ACTOR_RESOLVER)),
4912
+ _ts_param18(1, (0, import_common21.Optional)()),
4913
+ _ts_param18(1, (0, import_common21.Inject)(import_nestjs_agent_core24.AGENT_SKILLS)),
4914
+ _ts_metadata18("design:type", Function),
4915
+ _ts_metadata18("design:paramtypes", [
4207
4916
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
4208
4917
  Object
4209
4918
  ])
4210
4919
  ], SkillsController);
4211
4920
 
4212
4921
  // src/controller/threads.controller.ts
4213
- var import_nestjs_agent_core21 = require("@dudousxd/nestjs-agent-core");
4214
- var import_common20 = require("@nestjs/common");
4215
- function _ts_decorate19(decorators, target, key, desc) {
4922
+ var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4923
+ var import_common22 = require("@nestjs/common");
4924
+ function _ts_decorate21(decorators, target, key, desc) {
4216
4925
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4217
4926
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4218
4927
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4225,19 +4934,19 @@ function _ts_decorate19(decorators, target, key, desc) {
4225
4934
  }
4226
4935
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4227
4936
  }
4228
- __name(_ts_decorate19, "_ts_decorate");
4229
- function _ts_metadata18(metadataKey, metadataValue) {
4937
+ __name(_ts_decorate21, "_ts_decorate");
4938
+ function _ts_metadata19(metadataKey, metadataValue) {
4230
4939
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4231
4940
  return Reflect.metadata(metadataKey, metadataValue);
4232
4941
  }
4233
4942
  }
4234
- __name(_ts_metadata18, "_ts_metadata");
4235
- function _ts_param17(paramIndex, decorator) {
4943
+ __name(_ts_metadata19, "_ts_metadata");
4944
+ function _ts_param19(paramIndex, decorator) {
4236
4945
  return function(target, key) {
4237
4946
  decorator(target, key, paramIndex);
4238
4947
  };
4239
4948
  }
4240
- __name(_ts_param17, "_ts_param");
4949
+ __name(_ts_param19, "_ts_param");
4241
4950
  var ThreadsController = class {
4242
4951
  static {
4243
4952
  __name(this, "ThreadsController");
@@ -4283,6 +4992,9 @@ var ThreadsController = class {
4283
4992
  } : {},
4284
4993
  ..."model" in body ? {
4285
4994
  model: body.model ?? null
4995
+ } : {},
4996
+ ..."persona" in body ? {
4997
+ persona: body.persona ?? null
4286
4998
  } : {}
4287
4999
  });
4288
5000
  return {
@@ -4304,101 +5016,101 @@ var ThreadsController = class {
4304
5016
  };
4305
5017
  }
4306
5018
  };
4307
- _ts_decorate19([
4308
- (0, import_common20.Get)(),
4309
- _ts_param17(0, (0, import_common20.Req)()),
4310
- _ts_metadata18("design:type", Function),
4311
- _ts_metadata18("design:paramtypes", [
5019
+ _ts_decorate21([
5020
+ (0, import_common22.Get)(),
5021
+ _ts_param19(0, (0, import_common22.Req)()),
5022
+ _ts_metadata19("design:type", Function),
5023
+ _ts_metadata19("design:paramtypes", [
4312
5024
  typeof Request === "undefined" ? Object : Request
4313
5025
  ]),
4314
- _ts_metadata18("design:returntype", Promise)
5026
+ _ts_metadata19("design:returntype", Promise)
4315
5027
  ], ThreadsController.prototype, "list", null);
4316
- _ts_decorate19([
4317
- (0, import_common20.Get)(":id"),
4318
- _ts_param17(0, (0, import_common20.Req)()),
4319
- _ts_param17(1, (0, import_common20.Param)("id")),
4320
- _ts_metadata18("design:type", Function),
4321
- _ts_metadata18("design:paramtypes", [
5028
+ _ts_decorate21([
5029
+ (0, import_common22.Get)(":id"),
5030
+ _ts_param19(0, (0, import_common22.Req)()),
5031
+ _ts_param19(1, (0, import_common22.Param)("id")),
5032
+ _ts_metadata19("design:type", Function),
5033
+ _ts_metadata19("design:paramtypes", [
4322
5034
  typeof Request === "undefined" ? Object : Request,
4323
5035
  String
4324
5036
  ]),
4325
- _ts_metadata18("design:returntype", Promise)
5037
+ _ts_metadata19("design:returntype", Promise)
4326
5038
  ], ThreadsController.prototype, "detail", null);
4327
- _ts_decorate19([
4328
- (0, import_common20.Delete)(":id"),
4329
- _ts_param17(0, (0, import_common20.Req)()),
4330
- _ts_param17(1, (0, import_common20.Param)("id")),
4331
- _ts_metadata18("design:type", Function),
4332
- _ts_metadata18("design:paramtypes", [
5039
+ _ts_decorate21([
5040
+ (0, import_common22.Delete)(":id"),
5041
+ _ts_param19(0, (0, import_common22.Req)()),
5042
+ _ts_param19(1, (0, import_common22.Param)("id")),
5043
+ _ts_metadata19("design:type", Function),
5044
+ _ts_metadata19("design:paramtypes", [
4333
5045
  typeof Request === "undefined" ? Object : Request,
4334
5046
  String
4335
5047
  ]),
4336
- _ts_metadata18("design:returntype", Promise)
5048
+ _ts_metadata19("design:returntype", Promise)
4337
5049
  ], ThreadsController.prototype, "remove", null);
4338
- _ts_decorate19([
4339
- (0, import_common20.Post)(":id/fork-from/:messageId"),
4340
- _ts_param17(0, (0, import_common20.Req)()),
4341
- _ts_param17(1, (0, import_common20.Param)("id")),
4342
- _ts_param17(2, (0, import_common20.Param)("messageId")),
4343
- _ts_metadata18("design:type", Function),
4344
- _ts_metadata18("design:paramtypes", [
5050
+ _ts_decorate21([
5051
+ (0, import_common22.Post)(":id/fork-from/:messageId"),
5052
+ _ts_param19(0, (0, import_common22.Req)()),
5053
+ _ts_param19(1, (0, import_common22.Param)("id")),
5054
+ _ts_param19(2, (0, import_common22.Param)("messageId")),
5055
+ _ts_metadata19("design:type", Function),
5056
+ _ts_metadata19("design:paramtypes", [
4345
5057
  typeof Request === "undefined" ? Object : Request,
4346
5058
  String,
4347
5059
  String
4348
5060
  ]),
4349
- _ts_metadata18("design:returntype", Promise)
5061
+ _ts_metadata19("design:returntype", Promise)
4350
5062
  ], ThreadsController.prototype, "fork", null);
4351
- _ts_decorate19([
4352
- (0, import_common20.Patch)(":id"),
4353
- _ts_param17(0, (0, import_common20.Req)()),
4354
- _ts_param17(1, (0, import_common20.Param)("id")),
4355
- _ts_param17(2, (0, import_common20.Body)()),
4356
- _ts_metadata18("design:type", Function),
4357
- _ts_metadata18("design:paramtypes", [
5063
+ _ts_decorate21([
5064
+ (0, import_common22.Patch)(":id"),
5065
+ _ts_param19(0, (0, import_common22.Req)()),
5066
+ _ts_param19(1, (0, import_common22.Param)("id")),
5067
+ _ts_param19(2, (0, import_common22.Body)()),
5068
+ _ts_metadata19("design:type", Function),
5069
+ _ts_metadata19("design:paramtypes", [
4358
5070
  typeof Request === "undefined" ? Object : Request,
4359
5071
  String,
4360
5072
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
4361
5073
  ]),
4362
- _ts_metadata18("design:returntype", Promise)
5074
+ _ts_metadata19("design:returntype", Promise)
4363
5075
  ], ThreadsController.prototype, "update", null);
4364
- _ts_decorate19([
4365
- (0, import_common20.Post)(":id/promote"),
4366
- _ts_param17(0, (0, import_common20.Req)()),
4367
- _ts_param17(1, (0, import_common20.Param)("id")),
4368
- _ts_metadata18("design:type", Function),
4369
- _ts_metadata18("design:paramtypes", [
5076
+ _ts_decorate21([
5077
+ (0, import_common22.Post)(":id/promote"),
5078
+ _ts_param19(0, (0, import_common22.Req)()),
5079
+ _ts_param19(1, (0, import_common22.Param)("id")),
5080
+ _ts_metadata19("design:type", Function),
5081
+ _ts_metadata19("design:paramtypes", [
4370
5082
  typeof Request === "undefined" ? Object : Request,
4371
5083
  String
4372
5084
  ]),
4373
- _ts_metadata18("design:returntype", Promise)
5085
+ _ts_metadata19("design:returntype", Promise)
4374
5086
  ], ThreadsController.prototype, "promote", null);
4375
- _ts_decorate19([
4376
- (0, import_common20.Delete)(":id/from/:messageId"),
4377
- _ts_param17(0, (0, import_common20.Req)()),
4378
- _ts_param17(1, (0, import_common20.Param)("id")),
4379
- _ts_param17(2, (0, import_common20.Param)("messageId")),
4380
- _ts_metadata18("design:type", Function),
4381
- _ts_metadata18("design:paramtypes", [
5087
+ _ts_decorate21([
5088
+ (0, import_common22.Delete)(":id/from/:messageId"),
5089
+ _ts_param19(0, (0, import_common22.Req)()),
5090
+ _ts_param19(1, (0, import_common22.Param)("id")),
5091
+ _ts_param19(2, (0, import_common22.Param)("messageId")),
5092
+ _ts_metadata19("design:type", Function),
5093
+ _ts_metadata19("design:paramtypes", [
4382
5094
  typeof Request === "undefined" ? Object : Request,
4383
5095
  String,
4384
5096
  String
4385
5097
  ]),
4386
- _ts_metadata18("design:returntype", Promise)
5098
+ _ts_metadata19("design:returntype", Promise)
4387
5099
  ], ThreadsController.prototype, "truncateFrom", null);
4388
- ThreadsController = _ts_decorate19([
4389
- (0, import_common20.Controller)("threads"),
4390
- _ts_param17(1, (0, import_common20.Inject)(import_nestjs_agent_core21.AGENT_ACTOR_RESOLVER)),
4391
- _ts_metadata18("design:type", Function),
4392
- _ts_metadata18("design:paramtypes", [
5100
+ ThreadsController = _ts_decorate21([
5101
+ (0, import_common22.Controller)("threads"),
5102
+ _ts_param19(1, (0, import_common22.Inject)(import_nestjs_agent_core25.AGENT_ACTOR_RESOLVER)),
5103
+ _ts_metadata19("design:type", Function),
5104
+ _ts_metadata19("design:paramtypes", [
4393
5105
  typeof AgentService === "undefined" ? Object : AgentService,
4394
5106
  typeof ActorResolver === "undefined" ? Object : ActorResolver
4395
5107
  ])
4396
5108
  ], ThreadsController);
4397
5109
 
4398
5110
  // src/controller/tool-call.controller.ts
4399
- var import_nestjs_agent_core22 = require("@dudousxd/nestjs-agent-core");
4400
- var import_common21 = require("@nestjs/common");
4401
- function _ts_decorate20(decorators, target, key, desc) {
5111
+ var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
5112
+ var import_common23 = require("@nestjs/common");
5113
+ function _ts_decorate22(decorators, target, key, desc) {
4402
5114
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4403
5115
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4404
5116
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4411,19 +5123,19 @@ function _ts_decorate20(decorators, target, key, desc) {
4411
5123
  }
4412
5124
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4413
5125
  }
4414
- __name(_ts_decorate20, "_ts_decorate");
4415
- function _ts_metadata19(metadataKey, metadataValue) {
5126
+ __name(_ts_decorate22, "_ts_decorate");
5127
+ function _ts_metadata20(metadataKey, metadataValue) {
4416
5128
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4417
5129
  return Reflect.metadata(metadataKey, metadataValue);
4418
5130
  }
4419
5131
  }
4420
- __name(_ts_metadata19, "_ts_metadata");
4421
- function _ts_param18(paramIndex, decorator) {
5132
+ __name(_ts_metadata20, "_ts_metadata");
5133
+ function _ts_param20(paramIndex, decorator) {
4422
5134
  return function(target, key) {
4423
5135
  decorator(target, key, paramIndex);
4424
5136
  };
4425
5137
  }
4426
- __name(_ts_param18, "_ts_param");
5138
+ __name(_ts_param20, "_ts_param");
4427
5139
  var MAX_ANSWERED_QUESTIONS = 100;
4428
5140
  var MAX_VALUES_PER_QUESTION = 100;
4429
5141
  var MAX_ANSWER_VALUE_LENGTH = 4096;
@@ -4432,7 +5144,7 @@ var MAX_VIA_LENGTH = 64;
4432
5144
  var DEFAULT_VIA = "web";
4433
5145
  function toolCallId(claimed) {
4434
5146
  if (typeof claimed !== "string" || claimed.length === 0) {
4435
- throw new import_common21.BadRequestException("toolCallId must be a non-empty string");
5147
+ throw new import_common23.BadRequestException("toolCallId must be a non-empty string");
4436
5148
  }
4437
5149
  return claimed;
4438
5150
  }
@@ -4442,10 +5154,10 @@ function rejectReason(claimed) {
4442
5154
  return void 0;
4443
5155
  }
4444
5156
  if (typeof claimed !== "string") {
4445
- throw new import_common21.BadRequestException("reason must be a string");
5157
+ throw new import_common23.BadRequestException("reason must be a string");
4446
5158
  }
4447
5159
  if (claimed.length > MAX_REJECT_REASON_LENGTH) {
4448
- throw new import_common21.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
5160
+ throw new import_common23.BadRequestException(`reason must be at most ${MAX_REJECT_REASON_LENGTH} characters`);
4449
5161
  }
4450
5162
  return claimed;
4451
5163
  }
@@ -4455,7 +5167,7 @@ function remember(claimed) {
4455
5167
  return false;
4456
5168
  }
4457
5169
  if (typeof claimed !== "boolean") {
4458
- throw new import_common21.BadRequestException("remember must be a boolean");
5170
+ throw new import_common23.BadRequestException("remember must be a boolean");
4459
5171
  }
4460
5172
  return claimed;
4461
5173
  }
@@ -4465,7 +5177,7 @@ function via(claimed) {
4465
5177
  return DEFAULT_VIA;
4466
5178
  }
4467
5179
  if (typeof claimed !== "string" || claimed.length === 0 || claimed.length > MAX_VIA_LENGTH) {
4468
- throw new import_common21.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
5180
+ throw new import_common23.BadRequestException(`via must be a string of 1-${MAX_VIA_LENGTH} characters`);
4469
5181
  }
4470
5182
  return claimed;
4471
5183
  }
@@ -4475,26 +5187,26 @@ function answers(claimed) {
4475
5187
  return void 0;
4476
5188
  }
4477
5189
  if (typeof claimed !== "object" || claimed === null || Array.isArray(claimed)) {
4478
- throw new import_common21.BadRequestException("answers must be an object of questionId \u2192 chosen values");
5190
+ throw new import_common23.BadRequestException("answers must be an object of questionId \u2192 chosen values");
4479
5191
  }
4480
5192
  const entries = Object.entries(claimed);
4481
5193
  if (entries.length > MAX_ANSWERED_QUESTIONS) {
4482
- throw new import_common21.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
5194
+ throw new import_common23.BadRequestException(`answers may cover at most ${MAX_ANSWERED_QUESTIONS} questions`);
4483
5195
  }
4484
5196
  const validated = /* @__PURE__ */ Object.create(null);
4485
5197
  for (const [questionId, values] of entries) {
4486
5198
  if (!Array.isArray(values)) {
4487
- throw new import_common21.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
5199
+ throw new import_common23.BadRequestException(`answers["${questionId}"] must be an array of chosen values`);
4488
5200
  }
4489
5201
  if (values.length > MAX_VALUES_PER_QUESTION) {
4490
- throw new import_common21.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
5202
+ throw new import_common23.BadRequestException(`answers["${questionId}"] may carry at most ${MAX_VALUES_PER_QUESTION} values`);
4491
5203
  }
4492
5204
  for (const value of values) {
4493
5205
  if (typeof value !== "string") {
4494
- throw new import_common21.BadRequestException(`answers["${questionId}"] must contain only strings`);
5206
+ throw new import_common23.BadRequestException(`answers["${questionId}"] must contain only strings`);
4495
5207
  }
4496
5208
  if (value.length > MAX_ANSWER_VALUE_LENGTH) {
4497
- throw new import_common21.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
5209
+ throw new import_common23.BadRequestException(`answers["${questionId}"] values must be at most ${MAX_ANSWER_VALUE_LENGTH} characters`);
4498
5210
  }
4499
5211
  }
4500
5212
  validated[questionId] = values;
@@ -4556,64 +5268,64 @@ var ToolCallController = class {
4556
5268
  };
4557
5269
  }
4558
5270
  };
4559
- _ts_decorate20([
4560
- (0, import_common21.Post)("approve"),
4561
- _ts_param18(0, (0, import_common21.Req)()),
4562
- _ts_param18(1, (0, import_common21.Body)()),
4563
- _ts_metadata19("design:type", Function),
4564
- _ts_metadata19("design:paramtypes", [
5271
+ _ts_decorate22([
5272
+ (0, import_common23.Post)("approve"),
5273
+ _ts_param20(0, (0, import_common23.Req)()),
5274
+ _ts_param20(1, (0, import_common23.Body)()),
5275
+ _ts_metadata20("design:type", Function),
5276
+ _ts_metadata20("design:paramtypes", [
4565
5277
  typeof Request === "undefined" ? Object : Request,
4566
5278
  typeof ApproveBody === "undefined" ? Object : ApproveBody
4567
5279
  ]),
4568
- _ts_metadata19("design:returntype", Promise)
5280
+ _ts_metadata20("design:returntype", Promise)
4569
5281
  ], ToolCallController.prototype, "approve", null);
4570
- _ts_decorate20([
4571
- (0, import_common21.Post)("reject"),
4572
- _ts_param18(0, (0, import_common21.Req)()),
4573
- _ts_param18(1, (0, import_common21.Body)()),
4574
- _ts_metadata19("design:type", Function),
4575
- _ts_metadata19("design:paramtypes", [
5282
+ _ts_decorate22([
5283
+ (0, import_common23.Post)("reject"),
5284
+ _ts_param20(0, (0, import_common23.Req)()),
5285
+ _ts_param20(1, (0, import_common23.Body)()),
5286
+ _ts_metadata20("design:type", Function),
5287
+ _ts_metadata20("design:paramtypes", [
4576
5288
  typeof Request === "undefined" ? Object : Request,
4577
5289
  typeof RejectBody === "undefined" ? Object : RejectBody
4578
5290
  ]),
4579
- _ts_metadata19("design:returntype", Promise)
5291
+ _ts_metadata20("design:returntype", Promise)
4580
5292
  ], ToolCallController.prototype, "reject", null);
4581
- _ts_decorate20([
4582
- (0, import_common21.Post)("answer"),
4583
- _ts_param18(0, (0, import_common21.Req)()),
4584
- _ts_param18(1, (0, import_common21.Body)()),
4585
- _ts_metadata19("design:type", Function),
4586
- _ts_metadata19("design:paramtypes", [
5293
+ _ts_decorate22([
5294
+ (0, import_common23.Post)("answer"),
5295
+ _ts_param20(0, (0, import_common23.Req)()),
5296
+ _ts_param20(1, (0, import_common23.Body)()),
5297
+ _ts_metadata20("design:type", Function),
5298
+ _ts_metadata20("design:paramtypes", [
4587
5299
  typeof Request === "undefined" ? Object : Request,
4588
5300
  typeof AnswerBody === "undefined" ? Object : AnswerBody
4589
5301
  ]),
4590
- _ts_metadata19("design:returntype", Promise)
5302
+ _ts_metadata20("design:returntype", Promise)
4591
5303
  ], ToolCallController.prototype, "answer", null);
4592
- _ts_decorate20([
4593
- (0, import_common21.Post)("skip"),
4594
- _ts_param18(0, (0, import_common21.Req)()),
4595
- _ts_param18(1, (0, import_common21.Body)()),
4596
- _ts_metadata19("design:type", Function),
4597
- _ts_metadata19("design:paramtypes", [
5304
+ _ts_decorate22([
5305
+ (0, import_common23.Post)("skip"),
5306
+ _ts_param20(0, (0, import_common23.Req)()),
5307
+ _ts_param20(1, (0, import_common23.Body)()),
5308
+ _ts_metadata20("design:type", Function),
5309
+ _ts_metadata20("design:paramtypes", [
4598
5310
  typeof Request === "undefined" ? Object : Request,
4599
5311
  Object
4600
5312
  ]),
4601
- _ts_metadata19("design:returntype", Promise)
5313
+ _ts_metadata20("design:returntype", Promise)
4602
5314
  ], ToolCallController.prototype, "skip", null);
4603
- ToolCallController = _ts_decorate20([
4604
- (0, import_common21.Controller)("tool-call"),
4605
- _ts_param18(1, (0, import_common21.Inject)(import_nestjs_agent_core22.AGENT_ACTOR_RESOLVER)),
4606
- _ts_metadata19("design:type", Function),
4607
- _ts_metadata19("design:paramtypes", [
5315
+ ToolCallController = _ts_decorate22([
5316
+ (0, import_common23.Controller)("tool-call"),
5317
+ _ts_param20(1, (0, import_common23.Inject)(import_nestjs_agent_core26.AGENT_ACTOR_RESOLVER)),
5318
+ _ts_metadata20("design:type", Function),
5319
+ _ts_metadata20("design:paramtypes", [
4608
5320
  typeof AgentService === "undefined" ? Object : AgentService,
4609
5321
  typeof ActorResolver === "undefined" ? Object : ActorResolver
4610
5322
  ])
4611
5323
  ], ToolCallController);
4612
5324
 
4613
5325
  // src/controller/tools.controller.ts
4614
- var import_nestjs_agent_core23 = require("@dudousxd/nestjs-agent-core");
4615
- var import_common22 = require("@nestjs/common");
4616
- function _ts_decorate21(decorators, target, key, desc) {
5326
+ var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
5327
+ var import_common24 = require("@nestjs/common");
5328
+ function _ts_decorate23(decorators, target, key, desc) {
4617
5329
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4618
5330
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4619
5331
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4626,19 +5338,19 @@ function _ts_decorate21(decorators, target, key, desc) {
4626
5338
  }
4627
5339
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4628
5340
  }
4629
- __name(_ts_decorate21, "_ts_decorate");
4630
- function _ts_metadata20(metadataKey, metadataValue) {
5341
+ __name(_ts_decorate23, "_ts_decorate");
5342
+ function _ts_metadata21(metadataKey, metadataValue) {
4631
5343
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4632
5344
  return Reflect.metadata(metadataKey, metadataValue);
4633
5345
  }
4634
5346
  }
4635
- __name(_ts_metadata20, "_ts_metadata");
4636
- function _ts_param19(paramIndex, decorator) {
5347
+ __name(_ts_metadata21, "_ts_metadata");
5348
+ function _ts_param21(paramIndex, decorator) {
4637
5349
  return function(target, key) {
4638
5350
  decorator(target, key, paramIndex);
4639
5351
  };
4640
5352
  }
4641
- __name(_ts_param19, "_ts_param");
5353
+ __name(_ts_param21, "_ts_param");
4642
5354
  var ToolsController = class {
4643
5355
  static {
4644
5356
  __name(this, "ToolsController");
@@ -4652,11 +5364,11 @@ var ToolsController = class {
4652
5364
  this.agents = agents;
4653
5365
  }
4654
5366
  async list(req, agent) {
4655
- if (agent !== void 0 && agent !== import_nestjs_agent_core23.ALL_AGENTS && this.agents.get(agent) === void 0) {
4656
- throw new import_common22.NotFoundException(`No agent named "${agent}"`);
5367
+ if (agent !== void 0 && agent !== import_nestjs_agent_core27.ALL_AGENTS && this.agents.get(agent) === void 0) {
5368
+ throw new import_common24.NotFoundException(`No agent named "${agent}"`);
4657
5369
  }
4658
5370
  const actor = await this.actorResolver.resolve(req);
4659
- const names = agent === import_nestjs_agent_core23.ALL_AGENTS ? [
5371
+ const names = agent === import_nestjs_agent_core27.ALL_AGENTS ? [
4660
5372
  void 0,
4661
5373
  ...this.agents.list().map((definition) => definition.name)
4662
5374
  ] : [
@@ -4682,33 +5394,33 @@ var ToolsController = class {
4682
5394
  ];
4683
5395
  }
4684
5396
  };
4685
- _ts_decorate21([
4686
- (0, import_common22.Get)(),
4687
- _ts_param19(0, (0, import_common22.Req)()),
4688
- _ts_param19(1, (0, import_common22.Query)("agent")),
4689
- _ts_metadata20("design:type", Function),
4690
- _ts_metadata20("design:paramtypes", [
5397
+ _ts_decorate23([
5398
+ (0, import_common24.Get)(),
5399
+ _ts_param21(0, (0, import_common24.Req)()),
5400
+ _ts_param21(1, (0, import_common24.Query)("agent")),
5401
+ _ts_metadata21("design:type", Function),
5402
+ _ts_metadata21("design:paramtypes", [
4691
5403
  typeof Request === "undefined" ? Object : Request,
4692
5404
  String
4693
5405
  ]),
4694
- _ts_metadata20("design:returntype", Promise)
5406
+ _ts_metadata21("design:returntype", Promise)
4695
5407
  ], ToolsController.prototype, "list", null);
4696
- ToolsController = _ts_decorate21([
4697
- (0, import_common22.Controller)("tools"),
4698
- _ts_param19(0, (0, import_common22.Inject)(import_nestjs_agent_core23.AGENT_ACTOR_RESOLVER)),
4699
- _ts_param19(1, (0, import_common22.Inject)(import_nestjs_agent_core23.AGENT_DEPS_FACTORY)),
4700
- _ts_param19(2, (0, import_common22.Inject)(import_nestjs_agent_core23.AGENT_REGISTRY)),
4701
- _ts_metadata20("design:type", Function),
4702
- _ts_metadata20("design:paramtypes", [
5408
+ ToolsController = _ts_decorate23([
5409
+ (0, import_common24.Controller)("tools"),
5410
+ _ts_param21(0, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_ACTOR_RESOLVER)),
5411
+ _ts_param21(1, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_DEPS_FACTORY)),
5412
+ _ts_param21(2, (0, import_common24.Inject)(import_nestjs_agent_core27.AGENT_REGISTRY)),
5413
+ _ts_metadata21("design:type", Function),
5414
+ _ts_metadata21("design:paramtypes", [
4703
5415
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
4704
5416
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
4705
- typeof import_nestjs_agent_core23.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core23.AgentRegistry
5417
+ typeof import_nestjs_agent_core27.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core27.AgentRegistry
4706
5418
  ])
4707
5419
  ], ToolsController);
4708
5420
 
4709
5421
  // src/discovery/agent-discovery.service.ts
4710
- var import_nestjs_agent_core24 = require("@dudousxd/nestjs-agent-core");
4711
- var import_common23 = require("@nestjs/common");
5422
+ var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
5423
+ var import_common25 = require("@nestjs/common");
4712
5424
  var import_core = require("@nestjs/core");
4713
5425
 
4714
5426
  // src/decorator/agent.decorator.ts
@@ -4725,7 +5437,7 @@ var SYSTEM_PROMPT_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:
4725
5437
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
4726
5438
 
4727
5439
  // src/discovery/agent-discovery.service.ts
4728
- function _ts_decorate22(decorators, target, key, desc) {
5440
+ function _ts_decorate24(decorators, target, key, desc) {
4729
5441
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4730
5442
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4731
5443
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4738,19 +5450,19 @@ function _ts_decorate22(decorators, target, key, desc) {
4738
5450
  }
4739
5451
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4740
5452
  }
4741
- __name(_ts_decorate22, "_ts_decorate");
4742
- function _ts_metadata21(metadataKey, metadataValue) {
5453
+ __name(_ts_decorate24, "_ts_decorate");
5454
+ function _ts_metadata22(metadataKey, metadataValue) {
4743
5455
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4744
5456
  return Reflect.metadata(metadataKey, metadataValue);
4745
5457
  }
4746
5458
  }
4747
- __name(_ts_metadata21, "_ts_metadata");
4748
- function _ts_param20(paramIndex, decorator) {
5459
+ __name(_ts_metadata22, "_ts_metadata");
5460
+ function _ts_param22(paramIndex, decorator) {
4749
5461
  return function(target, key) {
4750
5462
  decorator(target, key, paramIndex);
4751
5463
  };
4752
5464
  }
4753
- __name(_ts_param20, "_ts_param");
5465
+ __name(_ts_param22, "_ts_param");
4754
5466
  var AgentDiscoveryService = class _AgentDiscoveryService {
4755
5467
  static {
4756
5468
  __name(this, "AgentDiscoveryService");
@@ -4759,7 +5471,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4759
5471
  scanner;
4760
5472
  registry;
4761
5473
  contributors;
4762
- logger = new import_common23.Logger(_AgentDiscoveryService.name);
5474
+ logger = new import_common25.Logger(_AgentDiscoveryService.name);
4763
5475
  constructor(discovery, scanner, registry, contributors) {
4764
5476
  this.discovery = discovery;
4765
5477
  this.scanner = scanner;
@@ -4778,6 +5490,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4778
5490
  }
4779
5491
  this.collectContributors(instance);
4780
5492
  }
5493
+ this.assertPersonas(this.registry.list());
4781
5494
  }
4782
5495
  /** Build the internal {@link AgentDefinition} from an `@Agent` instance and its options. */
4783
5496
  definitionFrom(instance, meta) {
@@ -4821,10 +5534,48 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4821
5534
  } : {},
4822
5535
  ...meta.handoff !== void 0 ? {
4823
5536
  delegatesTo: this.handoffEdges(meta)
5537
+ } : {},
5538
+ ...meta.personas !== void 0 ? {
5539
+ personas: meta.personas
5540
+ } : {},
5541
+ ...meta.defaultPersona !== void 0 ? {
5542
+ defaultPersona: meta.defaultPersona
4824
5543
  } : {}
4825
5544
  };
4826
5545
  }
4827
5546
  /**
5547
+ * Refuse to boot on a persona declaration that could only fail later, per request: a default that
5548
+ * names no persona, an id declared twice, an alias two personas claim, or an alias that is a real
5549
+ * agent's name (which would never be reached — a registered agent always wins).
5550
+ */
5551
+ assertPersonas(definitions) {
5552
+ const agentNames = new Set(definitions.map((definition) => definition.name));
5553
+ const aliasOwner = /* @__PURE__ */ new Map();
5554
+ for (const definition of definitions) {
5555
+ const ids = /* @__PURE__ */ new Set();
5556
+ for (const persona of definition.personas ?? []) {
5557
+ if (ids.has(persona.id)) {
5558
+ throw new Error(`Agent "${definition.name}" declares persona "${persona.id}" twice.`);
5559
+ }
5560
+ ids.add(persona.id);
5561
+ for (const alias of persona.aliases ?? []) {
5562
+ const owner = `${definition.name}/${persona.id}`;
5563
+ if (agentNames.has(alias)) {
5564
+ throw new Error(`Persona ${owner} claims the alias "${alias}", which is a registered agent's name.`);
5565
+ }
5566
+ const previous = aliasOwner.get(alias);
5567
+ if (previous !== void 0) {
5568
+ throw new Error(`Personas ${previous} and ${owner} both claim the alias "${alias}".`);
5569
+ }
5570
+ aliasOwner.set(alias, owner);
5571
+ }
5572
+ }
5573
+ if (definition.defaultPersona !== void 0 && !ids.has(definition.defaultPersona)) {
5574
+ throw new Error(`Agent "${definition.name}" names "${definition.defaultPersona}" as its default persona, but declares no persona with that id.`);
5575
+ }
5576
+ }
5577
+ }
5578
+ /**
4828
5579
  * Resolve each handoff entry to an {@link AgentDelegation} — its target's registered name, plus
4829
5580
  * whether that edge detaches (skipping non-agent classes). A bare name is kept for a plain edge
4830
5581
  * rather than an always-object form, so a definition an older host built by hand still reads.
@@ -4877,22 +5628,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
4877
5628
  return (ctx) => candidate.call(instance, ctx);
4878
5629
  }
4879
5630
  };
4880
- AgentDiscoveryService = _ts_decorate22([
4881
- (0, import_common23.Injectable)(),
4882
- _ts_param20(2, (0, import_common23.Inject)(import_nestjs_agent_core24.AGENT_REGISTRY)),
4883
- _ts_param20(3, (0, import_common23.Inject)(import_nestjs_agent_core24.AGENT_PROMPT_CONTRIBUTORS)),
4884
- _ts_metadata21("design:type", Function),
4885
- _ts_metadata21("design:paramtypes", [
5631
+ AgentDiscoveryService = _ts_decorate24([
5632
+ (0, import_common25.Injectable)(),
5633
+ _ts_param22(2, (0, import_common25.Inject)(import_nestjs_agent_core28.AGENT_REGISTRY)),
5634
+ _ts_param22(3, (0, import_common25.Inject)(import_nestjs_agent_core28.AGENT_PROMPT_CONTRIBUTORS)),
5635
+ _ts_metadata22("design:type", Function),
5636
+ _ts_metadata22("design:paramtypes", [
4886
5637
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
4887
5638
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
4888
- typeof import_nestjs_agent_core24.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core24.AgentRegistry,
5639
+ typeof import_nestjs_agent_core28.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core28.AgentRegistry,
4889
5640
  Array
4890
5641
  ])
4891
5642
  ], AgentDiscoveryService);
4892
5643
 
4893
5644
  // src/discovery/ai-tool-discovery.service.ts
4894
- var import_nestjs_agent_core25 = require("@dudousxd/nestjs-agent-core");
4895
- var import_common24 = require("@nestjs/common");
5645
+ var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
5646
+ var import_common26 = require("@nestjs/common");
4896
5647
  var import_core2 = require("@nestjs/core");
4897
5648
  var import_zod = require("zod");
4898
5649
 
@@ -4904,15 +5655,8 @@ function readAiToolMetadata(target) {
4904
5655
  }
4905
5656
  __name(readAiToolMetadata, "readAiToolMetadata");
4906
5657
 
4907
- // src/functional-tool.ts
4908
- var AGENT_TOOL_BRAND = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:functional-tool");
4909
- function isBrandedFunctionalTool(value) {
4910
- return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
4911
- }
4912
- __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
4913
-
4914
5658
  // src/discovery/ai-tool-discovery.service.ts
4915
- function _ts_decorate23(decorators, target, key, desc) {
5659
+ function _ts_decorate25(decorators, target, key, desc) {
4916
5660
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4917
5661
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
4918
5662
  r = Reflect.decorate(decorators, target, key, desc);
@@ -4925,19 +5669,19 @@ function _ts_decorate23(decorators, target, key, desc) {
4925
5669
  }
4926
5670
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4927
5671
  }
4928
- __name(_ts_decorate23, "_ts_decorate");
4929
- function _ts_metadata22(metadataKey, metadataValue) {
5672
+ __name(_ts_decorate25, "_ts_decorate");
5673
+ function _ts_metadata23(metadataKey, metadataValue) {
4930
5674
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
4931
5675
  return Reflect.metadata(metadataKey, metadataValue);
4932
5676
  }
4933
5677
  }
4934
- __name(_ts_metadata22, "_ts_metadata");
4935
- function _ts_param21(paramIndex, decorator) {
5678
+ __name(_ts_metadata23, "_ts_metadata");
5679
+ function _ts_param23(paramIndex, decorator) {
4936
5680
  return function(target, key) {
4937
5681
  decorator(target, key, paramIndex);
4938
5682
  };
4939
5683
  }
4940
- __name(_ts_param21, "_ts_param");
5684
+ __name(_ts_param23, "_ts_param");
4941
5685
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
4942
5686
  static {
4943
5687
  __name(this, "AiToolDiscoveryService");
@@ -4946,7 +5690,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
4946
5690
  registry;
4947
5691
  agents;
4948
5692
  options;
4949
- logger = new import_common24.Logger(_AiToolDiscoveryService.name);
5693
+ logger = new import_common26.Logger(_AiToolDiscoveryService.name);
4950
5694
  constructor(discovery, registry, agents, options) {
4951
5695
  this.discovery = discovery;
4952
5696
  this.registry = registry;
@@ -5005,9 +5749,15 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
5005
5749
  } : {},
5006
5750
  ...meta.terminal === true ? {
5007
5751
  terminal: true
5752
+ } : {},
5753
+ ...meta.replacementKey !== void 0 ? {
5754
+ replacementKey: meta.replacementKey
5008
5755
  } : {}
5009
5756
  }, {
5010
5757
  execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute"),
5758
+ ...typeof handler.preflight === "function" ? {
5759
+ preflight: /* @__PURE__ */ __name((input, ctx, options) => instance.preflight(input, ctx, options), "preflight")
5760
+ } : {},
5011
5761
  // Forwarded, not copied: the registry holds this wrapper rather than the provider, so an
5012
5762
  // `isEnabled()`/`canUse()` left behind here would be a gate that silently never applies.
5013
5763
  // Called through `instance` so each keeps its `this` (and its injected deps).
@@ -5031,7 +5781,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
5031
5781
  let delegates = 0;
5032
5782
  for (const definition of this.agents.list()) {
5033
5783
  for (const edge of definition.delegatesTo ?? []) {
5034
- const { agent: target, detached } = (0, import_nestjs_agent_core25.normalizeDelegation)(edge);
5784
+ const { agent: target, detached } = (0, import_nestjs_agent_core29.normalizeDelegation)(edge);
5035
5785
  const targetDefinition = this.agents.get(target);
5036
5786
  if (targetDefinition === void 0) {
5037
5787
  throw new Error(`Agent "${definition.name}" hands off to "${target}", which is not a registered @Agent. Declare it as an @Agent provider or fix the reference.`);
@@ -5081,13 +5831,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
5081
5831
  return true;
5082
5832
  }
5083
5833
  };
5084
- AiToolDiscoveryService = _ts_decorate23([
5085
- (0, import_common24.Injectable)(),
5086
- _ts_param21(1, (0, import_common24.Inject)(import_nestjs_agent_core25.AGENT_TOOL_REGISTRY)),
5087
- _ts_param21(2, (0, import_common24.Inject)(import_nestjs_agent_core25.AGENT_REGISTRY)),
5088
- _ts_param21(3, (0, import_common24.Inject)(import_nestjs_agent_core25.AGENT_OPTIONS)),
5089
- _ts_metadata22("design:type", Function),
5090
- _ts_metadata22("design:paramtypes", [
5834
+ AiToolDiscoveryService = _ts_decorate25([
5835
+ (0, import_common26.Injectable)(),
5836
+ _ts_param23(1, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_TOOL_REGISTRY)),
5837
+ _ts_param23(2, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_REGISTRY)),
5838
+ _ts_param23(3, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_OPTIONS)),
5839
+ _ts_metadata23("design:type", Function),
5840
+ _ts_metadata23("design:paramtypes", [
5091
5841
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
5092
5842
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
5093
5843
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -5096,25 +5846,25 @@ AiToolDiscoveryService = _ts_decorate23([
5096
5846
  ], AiToolDiscoveryService);
5097
5847
 
5098
5848
  // src/discovery/skill-discovery.service.ts
5099
- var import_nestjs_agent_core27 = require("@dudousxd/nestjs-agent-core");
5100
- var import_common25 = require("@nestjs/common");
5849
+ var import_nestjs_agent_core31 = require("@dudousxd/nestjs-agent-core");
5850
+ var import_common27 = require("@nestjs/common");
5101
5851
  var import_core3 = require("@nestjs/core");
5102
5852
 
5103
5853
  // src/decorator/skill.decorator.ts
5104
5854
  var import_reflect_metadata4 = require("reflect-metadata");
5105
- var import_nestjs_agent_core26 = require("@dudousxd/nestjs-agent-core");
5855
+ var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
5106
5856
  var SKILL_METADATA = /* @__PURE__ */ Symbol.for("@dudousxd/nestjs-agent:skill-metadata");
5107
5857
  function readSkillMetadata(target) {
5108
5858
  return Reflect.getMetadata(SKILL_METADATA, target);
5109
5859
  }
5110
5860
  __name(readSkillMetadata, "readSkillMetadata");
5111
5861
  function skillScope(options) {
5112
- return options.scope ?? import_nestjs_agent_core26.GLOBAL_SCOPE;
5862
+ return options.scope ?? import_nestjs_agent_core30.GLOBAL_SCOPE;
5113
5863
  }
5114
5864
  __name(skillScope, "skillScope");
5115
5865
 
5116
5866
  // src/discovery/skill-discovery.service.ts
5117
- function _ts_decorate24(decorators, target, key, desc) {
5867
+ function _ts_decorate26(decorators, target, key, desc) {
5118
5868
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5119
5869
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5120
5870
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5127,26 +5877,26 @@ function _ts_decorate24(decorators, target, key, desc) {
5127
5877
  }
5128
5878
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5129
5879
  }
5130
- __name(_ts_decorate24, "_ts_decorate");
5131
- function _ts_metadata23(metadataKey, metadataValue) {
5880
+ __name(_ts_decorate26, "_ts_decorate");
5881
+ function _ts_metadata24(metadataKey, metadataValue) {
5132
5882
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5133
5883
  return Reflect.metadata(metadataKey, metadataValue);
5134
5884
  }
5135
5885
  }
5136
- __name(_ts_metadata23, "_ts_metadata");
5137
- function _ts_param22(paramIndex, decorator) {
5886
+ __name(_ts_metadata24, "_ts_metadata");
5887
+ function _ts_param24(paramIndex, decorator) {
5138
5888
  return function(target, key) {
5139
5889
  decorator(target, key, paramIndex);
5140
5890
  };
5141
5891
  }
5142
- __name(_ts_param22, "_ts_param");
5892
+ __name(_ts_param24, "_ts_param");
5143
5893
  var SkillDiscoveryService = class _SkillDiscoveryService {
5144
5894
  static {
5145
5895
  __name(this, "SkillDiscoveryService");
5146
5896
  }
5147
5897
  discovery;
5148
5898
  declared;
5149
- logger = new import_common25.Logger(_SkillDiscoveryService.name);
5899
+ logger = new import_common27.Logger(_SkillDiscoveryService.name);
5150
5900
  constructor(discovery, declared) {
5151
5901
  this.discovery = discovery;
5152
5902
  this.declared = declared;
@@ -5183,18 +5933,18 @@ var SkillDiscoveryService = class _SkillDiscoveryService {
5183
5933
  return flat === void 0 ? void 0 : () => flat;
5184
5934
  }
5185
5935
  };
5186
- SkillDiscoveryService = _ts_decorate24([
5187
- (0, import_common25.Injectable)(),
5188
- _ts_param22(1, (0, import_common25.Inject)(import_nestjs_agent_core27.AGENT_SKILL_SOURCES)),
5189
- _ts_metadata23("design:type", Function),
5190
- _ts_metadata23("design:paramtypes", [
5936
+ SkillDiscoveryService = _ts_decorate26([
5937
+ (0, import_common27.Injectable)(),
5938
+ _ts_param24(1, (0, import_common27.Inject)(import_nestjs_agent_core31.AGENT_SKILL_SOURCES)),
5939
+ _ts_metadata24("design:type", Function),
5940
+ _ts_metadata24("design:paramtypes", [
5191
5941
  typeof import_core3.DiscoveryService === "undefined" ? Object : import_core3.DiscoveryService,
5192
5942
  Array
5193
5943
  ])
5194
5944
  ], SkillDiscoveryService);
5195
5945
 
5196
5946
  // src/ledger-quota-provider.ts
5197
- var import_nestjs_agent_core28 = require("@dudousxd/nestjs-agent-core");
5947
+ var import_nestjs_agent_core32 = require("@dudousxd/nestjs-agent-core");
5198
5948
  var LedgerQuotaProvider = class {
5199
5949
  static {
5200
5950
  __name(this, "LedgerQuotaProvider");
@@ -5214,12 +5964,12 @@ var LedgerQuotaProvider = class {
5214
5964
  await this.dayWindow(actorRef, now)
5215
5965
  ];
5216
5966
  if (this.store.usageBetween !== void 0) {
5217
- const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("month", now);
5967
+ const range = (0, import_nestjs_agent_core32.quotaPeriodRange)("month", now);
5218
5968
  const used = await this.store.usageBetween(actorRef, range.fromDay, range.toDay);
5219
5969
  windows.push(this.window("month", used.usedTokens, used.costUsd, range.resetsAt));
5220
5970
  }
5221
- const blocked = (0, import_nestjs_agent_core28.exhaustedWindow)(windows);
5222
- const warning = (0, import_nestjs_agent_core28.quotaWarning)(windows);
5971
+ const blocked = (0, import_nestjs_agent_core32.exhaustedWindow)(windows);
5972
+ const warning = (0, import_nestjs_agent_core32.quotaWarning)(windows);
5223
5973
  return {
5224
5974
  windows,
5225
5975
  ...blocked !== void 0 ? {
@@ -5231,7 +5981,7 @@ var LedgerQuotaProvider = class {
5231
5981
  };
5232
5982
  }
5233
5983
  async dayWindow(actorRef, now) {
5234
- const range = (0, import_nestjs_agent_core28.quotaPeriodRange)("day", now);
5984
+ const range = (0, import_nestjs_agent_core32.quotaPeriodRange)("day", now);
5235
5985
  const { usedTokens, costUsd } = await this.store.quotaToday(actorRef, range.fromDay);
5236
5986
  return this.window("day", usedTokens, costUsd, range.resetsAt);
5237
5987
  }
@@ -5255,10 +6005,245 @@ var LedgerQuotaProvider = class {
5255
6005
  }
5256
6006
  };
5257
6007
 
6008
+ // src/proposals/action-proposal-worker.service.ts
6009
+ var import_node_crypto3 = require("crypto");
6010
+ var import_nestjs_agent_core33 = require("@dudousxd/nestjs-agent-core");
6011
+ var import_common28 = require("@nestjs/common");
6012
+ function _ts_decorate27(decorators, target, key, desc) {
6013
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6014
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
6015
+ r = Reflect.decorate(decorators, target, key, desc);
6016
+ } else {
6017
+ for (var i = decorators.length - 1; i >= 0; i--) {
6018
+ if (d = decorators[i]) {
6019
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6020
+ }
6021
+ }
6022
+ }
6023
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6024
+ }
6025
+ __name(_ts_decorate27, "_ts_decorate");
6026
+ function _ts_metadata25(metadataKey, metadataValue) {
6027
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
6028
+ return Reflect.metadata(metadataKey, metadataValue);
6029
+ }
6030
+ }
6031
+ __name(_ts_metadata25, "_ts_metadata");
6032
+ function _ts_param25(paramIndex, decorator) {
6033
+ return function(target, key) {
6034
+ decorator(target, key, paramIndex);
6035
+ };
6036
+ }
6037
+ __name(_ts_param25, "_ts_param");
6038
+ var ActionProposalWorkerService = class _ActionProposalWorkerService {
6039
+ static {
6040
+ __name(this, "ActionProposalWorkerService");
6041
+ }
6042
+ store;
6043
+ options;
6044
+ deps;
6045
+ worker;
6046
+ logger = new import_common28.Logger(_ActionProposalWorkerService.name);
6047
+ constructor(store, options, deps) {
6048
+ this.store = store;
6049
+ this.options = options;
6050
+ this.deps = deps;
6051
+ }
6052
+ onModuleInit() {
6053
+ if (this.options.actionApprovalMode !== "independent") return;
6054
+ (0, import_nestjs_agent_core33.assertIndependentActionCapabilities)(this.store, this.options.backgroundActorResolver);
6055
+ if (this.options.surface === "http") return;
6056
+ const resolver = this.options.backgroundActorResolver;
6057
+ if (!resolver) throw new Error("BackgroundActorResolver is required");
6058
+ this.worker = new import_nestjs_agent_core33.ActionProposalWorker({
6059
+ store: this.store,
6060
+ workerId: (0, import_node_crypto3.randomUUID)(),
6061
+ ...this.options.actionProposalWorker,
6062
+ executor: new import_nestjs_agent_core33.ActionProposalExecutor({
6063
+ resolver,
6064
+ resolveExecution: /* @__PURE__ */ __name(async (proposal, actor) => {
6065
+ const deps = this.deps.forProposal(proposal, actor);
6066
+ return {
6067
+ registry: deps.registry,
6068
+ rolesPolicy: deps.rolesPolicy,
6069
+ ...deps.resolveUiCatalog !== void 0 ? {
6070
+ resolveUiCatalog: deps.resolveUiCatalog
6071
+ } : {},
6072
+ ...deps.toolAllowList !== void 0 ? {
6073
+ allowedTools: deps.toolAllowList
6074
+ } : {}
6075
+ };
6076
+ }, "resolveExecution")
6077
+ }),
6078
+ onError: /* @__PURE__ */ __name((error) => this.logger.error(error), "onError")
6079
+ });
6080
+ this.worker.start();
6081
+ }
6082
+ async onModuleDestroy() {
6083
+ await this.worker?.stop();
6084
+ }
6085
+ };
6086
+ ActionProposalWorkerService = _ts_decorate27([
6087
+ (0, import_common28.Injectable)(),
6088
+ _ts_param25(0, (0, import_common28.Inject)(import_nestjs_agent_core33.AGENT_STORE)),
6089
+ _ts_param25(1, (0, import_common28.Inject)(import_nestjs_agent_core33.AGENT_OPTIONS)),
6090
+ _ts_param25(2, (0, import_common28.Inject)(import_nestjs_agent_core33.AGENT_DEPS_FACTORY)),
6091
+ _ts_metadata25("design:type", Function),
6092
+ _ts_metadata25("design:paramtypes", [
6093
+ typeof AgentStore === "undefined" ? Object : AgentStore,
6094
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
6095
+ typeof AgentDepsFactory2 === "undefined" ? Object : AgentDepsFactory2
6096
+ ])
6097
+ ], ActionProposalWorkerService);
6098
+
6099
+ // src/proposals/action-proposal.controller.ts
6100
+ var import_nestjs_agent_core34 = require("@dudousxd/nestjs-agent-core");
6101
+ var import_common29 = require("@nestjs/common");
6102
+ function _ts_decorate28(decorators, target, key, desc) {
6103
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6104
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
6105
+ r = Reflect.decorate(decorators, target, key, desc);
6106
+ } else {
6107
+ for (var i = decorators.length - 1; i >= 0; i--) {
6108
+ if (d = decorators[i]) {
6109
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6110
+ }
6111
+ }
6112
+ }
6113
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6114
+ }
6115
+ __name(_ts_decorate28, "_ts_decorate");
6116
+ function _ts_metadata26(metadataKey, metadataValue) {
6117
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
6118
+ return Reflect.metadata(metadataKey, metadataValue);
6119
+ }
6120
+ }
6121
+ __name(_ts_metadata26, "_ts_metadata");
6122
+ function _ts_param26(paramIndex, decorator) {
6123
+ return function(target, key) {
6124
+ decorator(target, key, paramIndex);
6125
+ };
6126
+ }
6127
+ __name(_ts_param26, "_ts_param");
6128
+ function bodyFields(body, field) {
6129
+ if (body === void 0) return {};
6130
+ if (typeof body !== "object" || body === null || Array.isArray(body) || Object.keys(body).some((key) => key !== field)) throw new import_common29.BadRequestException(`Only ${field} is accepted`);
6131
+ const value = body;
6132
+ if (value[field] !== void 0 && (field === "remember" && typeof value[field] !== "boolean" || field === "reason" && typeof value[field] !== "string")) throw new import_common29.BadRequestException(`Invalid ${field}`);
6133
+ return value;
6134
+ }
6135
+ __name(bodyFields, "bodyFields");
6136
+ var ActionProposalController = class {
6137
+ static {
6138
+ __name(this, "ActionProposalController");
6139
+ }
6140
+ proposals;
6141
+ actors;
6142
+ constructor(proposals, actors) {
6143
+ this.proposals = proposals;
6144
+ this.actors = actors;
6145
+ }
6146
+ async list(threadId, request, cursor, response) {
6147
+ let query = {};
6148
+ if (cursor !== void 0) {
6149
+ try {
6150
+ if (typeof cursor !== "string") throw new Error("Invalid cursor");
6151
+ query = {
6152
+ after: JSON.parse(cursor)
6153
+ };
6154
+ (0, import_nestjs_agent_core34.validateActionProposalListQuery)(query);
6155
+ } catch {
6156
+ throw new import_common29.BadRequestException("Invalid action proposal cursor");
6157
+ }
6158
+ }
6159
+ const page = await this.proposals.listPage(threadId, await this.actors.resolve(request), query);
6160
+ if (page.next) {
6161
+ response.setHeader("X-Action-Proposals-Next", encodeURIComponent(JSON.stringify(page.next)));
6162
+ const exposed = response.getHeader("Access-Control-Expose-Headers");
6163
+ response.setHeader("Access-Control-Expose-Headers", `${exposed === void 0 ? "" : `${String(exposed)}, `}X-Action-Proposals-Next`);
6164
+ }
6165
+ return page.items;
6166
+ }
6167
+ async approve(threadId, proposalId, request, body) {
6168
+ const value = bodyFields(body, "remember");
6169
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
6170
+ decision: "approved",
6171
+ ...typeof value.remember === "boolean" ? {
6172
+ remember: value.remember
6173
+ } : {}
6174
+ });
6175
+ }
6176
+ async reject(threadId, proposalId, request, body) {
6177
+ const value = bodyFields(body, "reason");
6178
+ return this.proposals.decide(threadId, proposalId, await this.actors.resolve(request), {
6179
+ decision: "rejected",
6180
+ ...typeof value.reason === "string" ? {
6181
+ reason: value.reason
6182
+ } : {}
6183
+ });
6184
+ }
6185
+ };
6186
+ _ts_decorate28([
6187
+ (0, import_common29.Get)(),
6188
+ _ts_param26(0, (0, import_common29.Param)("threadId")),
6189
+ _ts_param26(1, (0, import_common29.Req)()),
6190
+ _ts_param26(2, (0, import_common29.Query)("after")),
6191
+ _ts_param26(3, (0, import_common29.Res)({
6192
+ passthrough: true
6193
+ })),
6194
+ _ts_metadata26("design:type", Function),
6195
+ _ts_metadata26("design:paramtypes", [
6196
+ String,
6197
+ typeof Request === "undefined" ? Object : Request,
6198
+ Object,
6199
+ typeof Response === "undefined" ? Object : Response
6200
+ ]),
6201
+ _ts_metadata26("design:returntype", Promise)
6202
+ ], ActionProposalController.prototype, "list", null);
6203
+ _ts_decorate28([
6204
+ (0, import_common29.Post)(":proposalId/approve"),
6205
+ _ts_param26(0, (0, import_common29.Param)("threadId")),
6206
+ _ts_param26(1, (0, import_common29.Param)("proposalId")),
6207
+ _ts_param26(2, (0, import_common29.Req)()),
6208
+ _ts_param26(3, (0, import_common29.Body)()),
6209
+ _ts_metadata26("design:type", Function),
6210
+ _ts_metadata26("design:paramtypes", [
6211
+ String,
6212
+ String,
6213
+ typeof Request === "undefined" ? Object : Request,
6214
+ Object
6215
+ ]),
6216
+ _ts_metadata26("design:returntype", Promise)
6217
+ ], ActionProposalController.prototype, "approve", null);
6218
+ _ts_decorate28([
6219
+ (0, import_common29.Post)(":proposalId/reject"),
6220
+ _ts_param26(0, (0, import_common29.Param)("threadId")),
6221
+ _ts_param26(1, (0, import_common29.Param)("proposalId")),
6222
+ _ts_param26(2, (0, import_common29.Req)()),
6223
+ _ts_param26(3, (0, import_common29.Body)()),
6224
+ _ts_metadata26("design:type", Function),
6225
+ _ts_metadata26("design:paramtypes", [
6226
+ String,
6227
+ String,
6228
+ typeof Request === "undefined" ? Object : Request,
6229
+ Object
6230
+ ]),
6231
+ _ts_metadata26("design:returntype", Promise)
6232
+ ], ActionProposalController.prototype, "reject", null);
6233
+ ActionProposalController = _ts_decorate28([
6234
+ (0, import_common29.Controller)("threads/:threadId/action-proposals"),
6235
+ _ts_param26(1, (0, import_common29.Inject)(import_nestjs_agent_core34.AGENT_ACTOR_RESOLVER)),
6236
+ _ts_metadata26("design:type", Function),
6237
+ _ts_metadata26("design:paramtypes", [
6238
+ typeof ActionProposalService === "undefined" ? Object : ActionProposalService,
6239
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
6240
+ ])
6241
+ ], ActionProposalController);
6242
+
5258
6243
  // src/runner/inline-agent-runner.ts
5259
- var import_nestjs_agent_core29 = require("@dudousxd/nestjs-agent-core");
5260
- var import_common26 = require("@nestjs/common");
5261
- function _ts_decorate25(decorators, target, key, desc) {
6244
+ var import_nestjs_agent_core35 = require("@dudousxd/nestjs-agent-core");
6245
+ var import_common30 = require("@nestjs/common");
6246
+ function _ts_decorate29(decorators, target, key, desc) {
5262
6247
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5263
6248
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5264
6249
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5271,19 +6256,19 @@ function _ts_decorate25(decorators, target, key, desc) {
5271
6256
  }
5272
6257
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5273
6258
  }
5274
- __name(_ts_decorate25, "_ts_decorate");
5275
- function _ts_metadata24(metadataKey, metadataValue) {
6259
+ __name(_ts_decorate29, "_ts_decorate");
6260
+ function _ts_metadata27(metadataKey, metadataValue) {
5276
6261
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") {
5277
6262
  return Reflect.metadata(metadataKey, metadataValue);
5278
6263
  }
5279
6264
  }
5280
- __name(_ts_metadata24, "_ts_metadata");
5281
- function _ts_param23(paramIndex, decorator) {
6265
+ __name(_ts_metadata27, "_ts_metadata");
6266
+ function _ts_param27(paramIndex, decorator) {
5282
6267
  return function(target, key) {
5283
6268
  decorator(target, key, paramIndex);
5284
6269
  };
5285
6270
  }
5286
- __name(_ts_param23, "_ts_param");
6271
+ __name(_ts_param27, "_ts_param");
5287
6272
  var InlineAgentRunner = class _InlineAgentRunner {
5288
6273
  static {
5289
6274
  __name(this, "InlineAgentRunner");
@@ -5291,7 +6276,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5291
6276
  factory;
5292
6277
  store;
5293
6278
  queue;
5294
- logger = new import_common26.Logger(_InlineAgentRunner.name);
6279
+ logger = new import_common30.Logger(_InlineAgentRunner.name);
5295
6280
  pending = /* @__PURE__ */ new Map();
5296
6281
  /**
5297
6282
  * Runs someone has asked to stop. In-process, like `pending`, and for the same reason: this runner
@@ -5340,18 +6325,18 @@ var InlineAgentRunner = class _InlineAgentRunner {
5340
6325
  ],
5341
6326
  input
5342
6327
  });
5343
- void (0, import_nestjs_agent_core29.runAgentLoop)({
6328
+ void (0, import_nestjs_agent_core35.runAgentLoop)({
5344
6329
  ...deps,
5345
6330
  day
5346
- }, input, hooks).then(() => (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
5347
- if (error instanceof import_nestjs_agent_core29.RunCancelledError) {
6331
+ }, input, hooks).then(() => (0, import_nestjs_agent_core35.releaseThreadRun)(this.store, input.threadId, runId)).catch(async (error) => {
6332
+ if (error instanceof import_nestjs_agent_core35.RunCancelledError) {
5348
6333
  await this.settleCancelled(runId, input, deps);
5349
6334
  return;
5350
6335
  }
5351
6336
  const message = error instanceof Error ? error.message : String(error);
5352
- const code = (0, import_nestjs_agent_core29.agentFailureCode)(error);
6337
+ const code = (0, import_nestjs_agent_core35.agentFailureCode)(error);
5353
6338
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
5354
- (0, import_nestjs_agent_core29.publishAgentRunFailed)({
6339
+ (0, import_nestjs_agent_core35.publishAgentRunFailed)({
5355
6340
  runId,
5356
6341
  code,
5357
6342
  message
@@ -5362,11 +6347,11 @@ var InlineAgentRunner = class _InlineAgentRunner {
5362
6347
  errorCode: code,
5363
6348
  errorMessage: message
5364
6349
  });
5365
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
6350
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core35.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5366
6351
  const writer = await deps.sink.open(runId);
5367
6352
  await this.settleQueue(writer, input, runId, "failed", message);
5368
- await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5369
- await writer.fail((0, import_nestjs_agent_core29.streamFailure)(error));
6353
+ await (0, import_nestjs_agent_core35.releaseThreadRun)(this.store, input.threadId, runId);
6354
+ await writer.fail((0, import_nestjs_agent_core35.streamFailure)(error));
5370
6355
  }).finally(() => {
5371
6356
  this.cancelled.delete(runId);
5372
6357
  this.live.delete(runId);
@@ -5402,7 +6387,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5402
6387
  for (const [key, waiter] of this.pending) {
5403
6388
  if (key.startsWith(`${runId}:`)) {
5404
6389
  this.pending.delete(key);
5405
- waiter.reject(new import_nestjs_agent_core29.RunCancelledError());
6390
+ waiter.reject(new import_nestjs_agent_core35.RunCancelledError());
5406
6391
  }
5407
6392
  }
5408
6393
  await Promise.resolve();
@@ -5417,8 +6402,8 @@ var InlineAgentRunner = class _InlineAgentRunner {
5417
6402
  this.logger.log(`agent run ${runId} cancelled`);
5418
6403
  const writer = await deps.sink.open(runId);
5419
6404
  await this.settleQueue(writer, input, runId, "cancelled");
5420
- await (0, import_nestjs_agent_core29.releaseThreadRun)(this.store, input.threadId, runId);
5421
- await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)({
6405
+ await (0, import_nestjs_agent_core35.releaseThreadRun)(this.store, input.threadId, runId);
6406
+ await writer.write((0, import_nestjs_agent_core35.encodeStreamEvent)({
5422
6407
  kind: "cancelled"
5423
6408
  }));
5424
6409
  await writer.end();
@@ -5453,7 +6438,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5453
6438
  runId: nextRunId
5454
6439
  }));
5455
6440
  if (frame !== void 0) {
5456
- await writer.write((0, import_nestjs_agent_core29.encodeStreamEvent)(frame));
6441
+ await writer.write((0, import_nestjs_agent_core35.encodeStreamEvent)(frame));
5457
6442
  }
5458
6443
  } catch (failure) {
5459
6444
  this.logger.error(`could not advance the queue of thread ${input.threadId} after run ${runId}: ${failure instanceof Error ? failure.message : String(failure)}`);
@@ -5524,7 +6509,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5524
6509
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5525
6510
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5526
6511
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5527
- parallel: import_nestjs_agent_core29.settleAll,
6512
+ parallel: import_nestjs_agent_core35.settleAll,
5528
6513
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
5529
6514
  runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested({
5530
6515
  agentName,
@@ -5575,7 +6560,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5575
6560
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5576
6561
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5577
6562
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5578
- parallel: import_nestjs_agent_core29.settleAll,
6563
+ parallel: import_nestjs_agent_core35.settleAll,
5579
6564
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId), "cancelled"),
5580
6565
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested({
5581
6566
  agentName: childName,
@@ -5608,7 +6593,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5608
6593
  }
5609
6594
  }), "startAgent")
5610
6595
  };
5611
- void (0, import_nestjs_agent_core29.runAgentLoop)({
6596
+ void (0, import_nestjs_agent_core35.runAgentLoop)({
5612
6597
  ...deps,
5613
6598
  day
5614
6599
  }, {
@@ -5622,13 +6607,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
5622
6607
  parentRunId,
5623
6608
  deliverTo
5624
6609
  }, hooks).catch(async (error) => {
5625
- const cancelled = error instanceof import_nestjs_agent_core29.RunCancelledError;
6610
+ const cancelled = error instanceof import_nestjs_agent_core35.RunCancelledError;
5626
6611
  const message = error instanceof Error ? error.message : String(error);
5627
6612
  if (!cancelled) {
5628
6613
  this.logger.error(`detached agent run ${runId} failed: ${message}`);
5629
- (0, import_nestjs_agent_core29.publishAgentRunFailed)({
6614
+ (0, import_nestjs_agent_core35.publishAgentRunFailed)({
5630
6615
  runId,
5631
- code: (0, import_nestjs_agent_core29.agentFailureCode)(error),
6616
+ code: (0, import_nestjs_agent_core35.agentFailureCode)(error),
5632
6617
  message
5633
6618
  });
5634
6619
  }
@@ -5636,12 +6621,12 @@ var InlineAgentRunner = class _InlineAgentRunner {
5636
6621
  runId,
5637
6622
  status: cancelled ? "cancelled" : "failed",
5638
6623
  ...cancelled ? {} : {
5639
- errorCode: (0, import_nestjs_agent_core29.agentFailureCode)(error),
6624
+ errorCode: (0, import_nestjs_agent_core35.agentFailureCode)(error),
5640
6625
  errorMessage: message
5641
6626
  }
5642
6627
  });
5643
- await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core29.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
5644
- await (0, import_nestjs_agent_core29.settleUnsettledDelegation)({
6628
+ await Promise.resolve(this.store.failUnsettledToolCalls?.(runId, import_nestjs_agent_core35.RUN_ENDED_BEFORE_TOOL_CALL)).catch(() => 0);
6629
+ await (0, import_nestjs_agent_core35.settleUnsettledDelegation)({
5645
6630
  store: this.store,
5646
6631
  delivery: deliverTo,
5647
6632
  agent: agentName,
@@ -5680,7 +6665,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5680
6665
  awaitApproval: /* @__PURE__ */ __name((call, _ctx, opts) => this.parkApproval(runId, call.id, opts?.timeoutMs), "awaitApproval"),
5681
6666
  awaitAnswers: /* @__PURE__ */ __name((request) => this.park(runId, request.id), "awaitAnswers"),
5682
6667
  step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
5683
- parallel: import_nestjs_agent_core29.settleAll,
6668
+ parallel: import_nestjs_agent_core35.settleAll,
5684
6669
  // A child stops when it is cancelled OR when the run a human is actually watching is: the
5685
6670
  // canceller names the top-level run, which is the only id that ever left the server.
5686
6671
  cancelled: /* @__PURE__ */ __name(async () => this.cancelled.has(runId) || this.cancelled.has(sinkRunId), "cancelled"),
@@ -5715,7 +6700,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
5715
6700
  }), "startAgent")
5716
6701
  };
5717
6702
  try {
5718
- return await (0, import_nestjs_agent_core29.runAgentLoop)({
6703
+ return await (0, import_nestjs_agent_core35.runAgentLoop)({
5719
6704
  ...deps,
5720
6705
  day
5721
6706
  }, {
@@ -5734,13 +6719,13 @@ var InlineAgentRunner = class _InlineAgentRunner {
5734
6719
  }
5735
6720
  }
5736
6721
  };
5737
- InlineAgentRunner = _ts_decorate25([
5738
- (0, import_common26.Injectable)(),
5739
- _ts_param23(0, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_DEPS_FACTORY)),
5740
- _ts_param23(1, (0, import_common26.Inject)(import_nestjs_agent_core29.AGENT_STORE)),
5741
- _ts_param23(2, (0, import_common26.Optional)()),
5742
- _ts_metadata24("design:type", Function),
5743
- _ts_metadata24("design:paramtypes", [
6722
+ InlineAgentRunner = _ts_decorate29([
6723
+ (0, import_common30.Injectable)(),
6724
+ _ts_param27(0, (0, import_common30.Inject)(import_nestjs_agent_core35.AGENT_DEPS_FACTORY)),
6725
+ _ts_param27(1, (0, import_common30.Inject)(import_nestjs_agent_core35.AGENT_STORE)),
6726
+ _ts_param27(2, (0, import_common30.Optional)()),
6727
+ _ts_metadata27("design:type", Function),
6728
+ _ts_metadata27("design:paramtypes", [
5744
6729
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
5745
6730
  typeof AgentStore === "undefined" ? Object : AgentStore,
5746
6731
  typeof ChatQueueService2 === "undefined" ? Object : ChatQueueService2
@@ -5752,7 +6737,7 @@ function isThreadTurn2(input) {
5752
6737
  __name(isThreadTurn2, "isThreadTurn");
5753
6738
 
5754
6739
  // src/skills-config.ts
5755
- var import_nestjs_agent_core30 = require("@dudousxd/nestjs-agent-core");
6740
+ var import_nestjs_agent_core36 = require("@dudousxd/nestjs-agent-core");
5756
6741
  function declaredSkillProvider(declared) {
5757
6742
  return {
5758
6743
  list: /* @__PURE__ */ __name(({ scopes }) => declared.filter((skill) => scopes.includes(skill.scope)).map(({ name, description, scope }) => ({
@@ -5778,7 +6763,7 @@ function resolveSkillsConfig(options, declared) {
5778
6763
  declaredSkillProvider(declared)
5779
6764
  ];
5780
6765
  return {
5781
- provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core30.compositeSkillProvider)(providers),
6766
+ provider: providers.length === 1 ? providers[0] : (0, import_nestjs_agent_core36.compositeSkillProvider)(providers),
5782
6767
  ...options.scopes !== void 0 ? {
5783
6768
  scopes: options.scopes
5784
6769
  } : {},
@@ -5790,7 +6775,7 @@ function resolveSkillsConfig(options, declared) {
5790
6775
  __name(resolveSkillsConfig, "resolveSkillsConfig");
5791
6776
 
5792
6777
  // src/agent.module.ts
5793
- function _ts_decorate26(decorators, target, key, desc) {
6778
+ function _ts_decorate30(decorators, target, key, desc) {
5794
6779
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5795
6780
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
5796
6781
  r = Reflect.decorate(decorators, target, key, desc);
@@ -5803,13 +6788,13 @@ function _ts_decorate26(decorators, target, key, desc) {
5803
6788
  }
5804
6789
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5805
6790
  }
5806
- __name(_ts_decorate26, "_ts_decorate");
6791
+ __name(_ts_decorate30, "_ts_decorate");
5807
6792
  var DEFAULT_PATH = "agent";
5808
- var logger = new import_common27.Logger("AgentModule");
6793
+ var logger = new import_common31.Logger("AgentModule");
5809
6794
  function externalStoreWrapper(modules) {
5810
6795
  for (const module2 of modules.values()) {
5811
6796
  if (module2.metatype === AgentModule) continue;
5812
- const wrapper = module2.providers.get(import_nestjs_agent_core31.AGENT_STORE);
6797
+ const wrapper = module2.providers.get(import_nestjs_agent_core37.AGENT_STORE);
5813
6798
  if (wrapper !== void 0) return wrapper;
5814
6799
  }
5815
6800
  return void 0;
@@ -5840,7 +6825,7 @@ function resolveStore(options, modules) {
5840
6825
  const external = externalStoreWrapper(modules);
5841
6826
  if (external !== void 0) return forwardingStore(external);
5842
6827
  logger.warn("No `store` configured and no store module imported \u2014 using the in-memory store. Threads are lost on restart and not shared between processes: not for production. Pass `store`, or import a store module (e.g. MikroOrmAgentStoreModule.forFeature()).");
5843
- return new import_nestjs_agent_core31.InMemoryAgentStore();
6828
+ return new import_nestjs_agent_core37.InMemoryAgentStore();
5844
6829
  }
5845
6830
  __name(resolveStore, "resolveStore");
5846
6831
  function isQuotaProvider(quota) {
@@ -5856,99 +6841,99 @@ __name(resolveCatalog, "resolveCatalog");
5856
6841
  function sharedProviders(durable) {
5857
6842
  const providers = [
5858
6843
  {
5859
- provide: import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
5860
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.ToolRegistry(), "useFactory")
6844
+ provide: import_nestjs_agent_core37.AGENT_TOOL_REGISTRY,
6845
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core37.ToolRegistry(), "useFactory")
5861
6846
  },
5862
6847
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
5863
6848
  {
5864
- provide: import_nestjs_agent_core31.AGENT_REGISTRY,
5865
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core31.AgentRegistry(), "useFactory")
6849
+ provide: import_nestjs_agent_core37.AGENT_REGISTRY,
6850
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core37.AgentRegistry(), "useFactory")
5866
6851
  },
5867
6852
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
5868
6853
  {
5869
- provide: import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
6854
+ provide: import_nestjs_agent_core37.AGENT_PROMPT_CONTRIBUTORS,
5870
6855
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5871
6856
  },
5872
6857
  // Likewise for `@Skill`-decorated providers — filled by SkillDiscoveryService at onModuleInit,
5873
6858
  // read lazily by the AGENT_SKILLS provider below (which DI builds before discovery has run).
5874
6859
  {
5875
- provide: import_nestjs_agent_core31.AGENT_SKILL_SOURCES,
6860
+ provide: import_nestjs_agent_core37.AGENT_SKILL_SOURCES,
5876
6861
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
5877
6862
  },
5878
6863
  {
5879
6864
  // One resolution, shared by the loop's deps and the listing endpoint: a second one would
5880
6865
  // drift, and a user would be offered a skill the agent cannot reach. `undefined` when the
5881
6866
  // host configured none — which is what keeps the turn's checkpoint sequence unchanged.
5882
- provide: import_nestjs_agent_core31.AGENT_SKILLS,
6867
+ provide: import_nestjs_agent_core37.AGENT_SKILLS,
5883
6868
  useFactory: /* @__PURE__ */ __name((options, declared) => resolveSkillsConfig(options.skills, declared), "useFactory"),
5884
6869
  inject: [
5885
- import_nestjs_agent_core31.AGENT_OPTIONS,
5886
- import_nestjs_agent_core31.AGENT_SKILL_SOURCES
6870
+ import_nestjs_agent_core37.AGENT_OPTIONS,
6871
+ import_nestjs_agent_core37.AGENT_SKILL_SOURCES
5887
6872
  ]
5888
6873
  },
5889
6874
  {
5890
6875
  // One resolution, shared by the loop's deps and the read-back endpoint: a person has to be
5891
6876
  // shown what the model was shown, and two resolutions would eventually disagree about that.
5892
- provide: import_nestjs_agent_core31.AGENT_MEMORY,
6877
+ provide: import_nestjs_agent_core37.AGENT_MEMORY,
5893
6878
  useFactory: /* @__PURE__ */ __name((options) => options.memory, "useFactory"),
5894
6879
  inject: [
5895
- import_nestjs_agent_core31.AGENT_OPTIONS
6880
+ import_nestjs_agent_core37.AGENT_OPTIONS
5896
6881
  ]
5897
6882
  },
5898
6883
  {
5899
- provide: import_nestjs_agent_core31.AGENT_SINK,
6884
+ provide: import_nestjs_agent_core37.AGENT_SINK,
5900
6885
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
5901
6886
  inject: [
5902
- import_nestjs_agent_core31.AGENT_OPTIONS
6887
+ import_nestjs_agent_core37.AGENT_OPTIONS
5903
6888
  ]
5904
6889
  },
5905
6890
  {
5906
- provide: import_nestjs_agent_core31.AGENT_ROLES_POLICY,
5907
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new import_nestjs_agent_core31.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core31.DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
6891
+ provide: import_nestjs_agent_core37.AGENT_ROLES_POLICY,
6892
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? (options.emptyRoles === "deny" ? new import_nestjs_agent_core37.ClosedRolesPolicy(options.defaultRoles) : new import_nestjs_agent_core37.DefaultRolesPolicy(options.defaultRoles)), "useFactory"),
5908
6893
  inject: [
5909
- import_nestjs_agent_core31.AGENT_OPTIONS
6894
+ import_nestjs_agent_core37.AGENT_OPTIONS
5910
6895
  ]
5911
6896
  },
5912
6897
  {
5913
- provide: import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
6898
+ provide: import_nestjs_agent_core37.AGENT_ACTOR_RESOLVER,
5914
6899
  useFactory: /* @__PURE__ */ __name((options) => {
5915
6900
  if (options.actorResolver !== void 0) return options.actorResolver;
5916
6901
  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.");
5917
6902
  return new AnonymousActorResolver();
5918
6903
  }, "useFactory"),
5919
6904
  inject: [
5920
- import_nestjs_agent_core31.AGENT_OPTIONS
6905
+ import_nestjs_agent_core37.AGENT_OPTIONS
5921
6906
  ]
5922
6907
  },
5923
6908
  {
5924
- provide: import_nestjs_agent_core31.AGENT_MODEL,
6909
+ provide: import_nestjs_agent_core37.AGENT_MODEL,
5925
6910
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
5926
6911
  inject: [
5927
- import_nestjs_agent_core31.AGENT_OPTIONS
6912
+ import_nestjs_agent_core37.AGENT_OPTIONS
5928
6913
  ]
5929
6914
  },
5930
6915
  {
5931
6916
  // `quota` is either a provider of the host's own or ceilings for the built-in ledger one;
5932
6917
  // omitted, the ledger provider still reports usage, with no ceiling to block on.
5933
- provide: import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
6918
+ provide: import_nestjs_agent_core37.AGENT_QUOTA_PROVIDER,
5934
6919
  useFactory: /* @__PURE__ */ __name((o, store) => isQuotaProvider(o.quota) ? o.quota : new LedgerQuotaProvider(store, o.quota?.limits, o.quota?.warnAt !== void 0 ? {
5935
6920
  warnAt: o.quota.warnAt
5936
6921
  } : {}), "useFactory"),
5937
6922
  inject: [
5938
- import_nestjs_agent_core31.AGENT_OPTIONS,
5939
- import_nestjs_agent_core31.AGENT_STORE
6923
+ import_nestjs_agent_core37.AGENT_OPTIONS,
6924
+ import_nestjs_agent_core37.AGENT_STORE
5940
6925
  ]
5941
6926
  },
5942
6927
  {
5943
- provide: import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
6928
+ provide: import_nestjs_agent_core37.AGENT_MODEL_CATALOG,
5944
6929
  useFactory: /* @__PURE__ */ __name((o) => resolveCatalog(o), "useFactory"),
5945
6930
  inject: [
5946
- import_nestjs_agent_core31.AGENT_OPTIONS
6931
+ import_nestjs_agent_core37.AGENT_OPTIONS
5947
6932
  ]
5948
6933
  },
5949
6934
  AgentDepsFactory2,
5950
6935
  {
5951
- provide: import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
6936
+ provide: import_nestjs_agent_core37.AGENT_DEPS_FACTORY,
5952
6937
  useExisting: AgentDepsFactory2
5953
6938
  },
5954
6939
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -5965,25 +6950,27 @@ function sharedProviders(durable) {
5965
6950
  },
5966
6951
  InlineAgentRunner,
5967
6952
  AgentService,
6953
+ ActionProposalService,
6954
+ ActionProposalWorkerService,
5968
6955
  // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
5969
6956
  // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
5970
6957
  AgentApprovalPortAdapter,
5971
6958
  {
5972
- provide: import_nestjs_agent_core31.AGENT_APPROVAL_PORT,
6959
+ provide: import_nestjs_agent_core37.AGENT_APPROVAL_PORT,
5973
6960
  useExisting: AgentApprovalPortAdapter
5974
6961
  }
5975
6962
  ];
5976
6963
  providers.push({
5977
- provide: import_nestjs_agent_core31.AGENT_STORE,
6964
+ provide: import_nestjs_agent_core37.AGENT_STORE,
5978
6965
  useFactory: /* @__PURE__ */ __name((o, modules) => resolveStore(o, modules), "useFactory"),
5979
6966
  inject: [
5980
- import_nestjs_agent_core31.AGENT_OPTIONS,
6967
+ import_nestjs_agent_core37.AGENT_OPTIONS,
5981
6968
  import_core4.ModulesContainer
5982
6969
  ]
5983
6970
  });
5984
6971
  if (durable) {
5985
6972
  providers.push({
5986
- provide: import_nestjs_agent_core31.AGENT_RUNNER,
6973
+ provide: import_nestjs_agent_core37.AGENT_RUNNER,
5987
6974
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
5988
6975
  if (durableRunner === void 0) {
5989
6976
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -5992,14 +6979,14 @@ function sharedProviders(durable) {
5992
6979
  }, "useFactory"),
5993
6980
  inject: [
5994
6981
  {
5995
- token: import_nestjs_agent_core31.AGENT_DURABLE_RUNNER,
6982
+ token: import_nestjs_agent_core37.AGENT_DURABLE_RUNNER,
5996
6983
  optional: true
5997
6984
  }
5998
6985
  ]
5999
6986
  });
6000
6987
  } else {
6001
6988
  providers.push({
6002
- provide: import_nestjs_agent_core31.AGENT_RUNNER,
6989
+ provide: import_nestjs_agent_core37.AGENT_RUNNER,
6003
6990
  useExisting: InlineAgentRunner
6004
6991
  });
6005
6992
  }
@@ -6008,30 +6995,33 @@ function sharedProviders(durable) {
6008
6995
  __name(sharedProviders, "sharedProviders");
6009
6996
  function exportsFor() {
6010
6997
  return [
6011
- import_nestjs_agent_core31.AGENT_OPTIONS,
6012
- import_nestjs_agent_core31.AGENT_TOOL_REGISTRY,
6013
- import_nestjs_agent_core31.AGENT_REGISTRY,
6014
- import_nestjs_agent_core31.AGENT_SINK,
6015
- import_nestjs_agent_core31.AGENT_ROLES_POLICY,
6016
- import_nestjs_agent_core31.AGENT_ACTOR_RESOLVER,
6017
- import_nestjs_agent_core31.AGENT_MODEL,
6018
- import_nestjs_agent_core31.AGENT_STORE,
6019
- import_nestjs_agent_core31.AGENT_MODEL_CATALOG,
6020
- import_nestjs_agent_core31.AGENT_QUOTA_PROVIDER,
6021
- import_nestjs_agent_core31.AGENT_PROMPT_CONTRIBUTORS,
6022
- import_nestjs_agent_core31.AGENT_SKILLS,
6023
- import_nestjs_agent_core31.AGENT_MEMORY,
6024
- import_nestjs_agent_core31.AGENT_DEPS_FACTORY,
6998
+ import_nestjs_agent_core37.AGENT_OPTIONS,
6999
+ import_nestjs_agent_core37.AGENT_TOOL_REGISTRY,
7000
+ import_nestjs_agent_core37.AGENT_REGISTRY,
7001
+ import_nestjs_agent_core37.AGENT_SINK,
7002
+ import_nestjs_agent_core37.AGENT_ROLES_POLICY,
7003
+ import_nestjs_agent_core37.AGENT_ACTOR_RESOLVER,
7004
+ import_nestjs_agent_core37.AGENT_MODEL,
7005
+ import_nestjs_agent_core37.AGENT_STORE,
7006
+ import_nestjs_agent_core37.AGENT_MODEL_CATALOG,
7007
+ import_nestjs_agent_core37.AGENT_QUOTA_PROVIDER,
7008
+ import_nestjs_agent_core37.AGENT_PROMPT_CONTRIBUTORS,
7009
+ import_nestjs_agent_core37.AGENT_SKILLS,
7010
+ import_nestjs_agent_core37.AGENT_MEMORY,
7011
+ import_nestjs_agent_core37.AGENT_DEPS_FACTORY,
6025
7012
  AgentDepsFactory2,
6026
7013
  AgentService,
7014
+ ActionProposalService,
7015
+ ActionProposalWorkerService,
6027
7016
  ChatQueueService2,
6028
7017
  AGENT_CHAT_QUEUE,
6029
7018
  InlineAgentRunner,
6030
- import_nestjs_agent_core31.AGENT_APPROVAL_PORT
7019
+ import_nestjs_agent_core37.AGENT_APPROVAL_PORT
6031
7020
  ];
6032
7021
  }
6033
7022
  __name(exportsFor, "exportsFor");
6034
7023
  var BASE_CONTROLLERS = [
7024
+ ActionProposalController,
6035
7025
  ChatController,
6036
7026
  QueueController,
6037
7027
  ThreadsController,
@@ -6104,7 +7094,7 @@ var AgentModule = class _AgentModule {
6104
7094
  controllers: controllersForSurface(options.surface, options.adapters),
6105
7095
  providers: [
6106
7096
  {
6107
- provide: import_nestjs_agent_core31.AGENT_OPTIONS,
7097
+ provide: import_nestjs_agent_core37.AGENT_OPTIONS,
6108
7098
  useValue: options
6109
7099
  },
6110
7100
  ...sharedProviders(options.durable ?? false),
@@ -6128,7 +7118,7 @@ var AgentModule = class _AgentModule {
6128
7118
  controllers: controllersForSurface(options.surface, options.adapters),
6129
7119
  providers: [
6130
7120
  {
6131
- provide: import_nestjs_agent_core31.AGENT_OPTIONS,
7121
+ provide: import_nestjs_agent_core37.AGENT_OPTIONS,
6132
7122
  // Stamp the STATIC wiring flags onto the factory result: `durable`/`surface` are
6133
7123
  // authoritative on the async config object (they decided the actual wiring above), and
6134
7124
  // the durable module reads `durable` back off AGENT_OPTIONS. `surface` isn't read back by
@@ -6150,9 +7140,9 @@ var AgentModule = class _AgentModule {
6150
7140
  };
6151
7141
  }
6152
7142
  };
6153
- AgentModule = _ts_decorate26([
6154
- (0, import_common27.Global)(),
6155
- (0, import_common27.Module)({})
7143
+ AgentModule = _ts_decorate30([
7144
+ (0, import_common31.Global)(),
7145
+ (0, import_common31.Module)({})
6156
7146
  ], AgentModule);
6157
7147
 
6158
7148
  // src/durable/agent-durable.ts