@dudousxd/nestjs-agent 0.4.1 → 0.6.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.
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/durable/index.ts
22
22
  var durable_exports = {};
23
23
  __export(durable_exports, {
24
+ AGENT_DISPATCHED_STEPS: () => AGENT_DISPATCHED_STEPS,
24
25
  AgentDurableModule: () => AgentDurableModule,
26
+ AgentRunSteps: () => AgentRunSteps,
25
27
  AgentRunWorkflow: () => AgentRunWorkflow,
26
28
  DurableAgentRunner: () => DurableAgentRunner,
27
29
  agentDurable: () => agentDurable
@@ -29,10 +31,10 @@ __export(durable_exports, {
29
31
  module.exports = __toCommonJS(durable_exports);
30
32
 
31
33
  // src/durable/agent-run.workflow.ts
32
- var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
33
- var import_nestjs_durable = require("@dudousxd/nestjs-durable");
34
+ var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
35
+ var import_nestjs_durable2 = require("@dudousxd/nestjs-durable");
34
36
  var import_nestjs_durable_core = require("@dudousxd/nestjs-durable-core");
35
- var import_common = require("@nestjs/common");
37
+ var import_common2 = require("@nestjs/common");
36
38
 
37
39
  // src/agent-deps.ts
38
40
  function utcDay(date = /* @__PURE__ */ new Date()) {
@@ -50,7 +52,10 @@ function childSinkWriter(writer) {
50
52
  }
51
53
  __name(childSinkWriter, "childSinkWriter");
52
54
 
53
- // src/durable/agent-run.workflow.ts
55
+ // src/durable/agent-run.steps.ts
56
+ var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
57
+ var import_nestjs_durable = require("@dudousxd/nestjs-durable");
58
+ var import_common = require("@nestjs/common");
54
59
  function _ts_decorate(decorators, target, key, desc) {
55
60
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
56
61
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -68,15 +73,107 @@ function _ts_param(paramIndex, decorator) {
68
73
  };
69
74
  }
70
75
  __name(_ts_param, "_ts_param");
76
+ var AgentRunSteps = class {
77
+ static {
78
+ __name(this, "AgentRunSteps");
79
+ }
80
+ factory;
81
+ constructor(factory) {
82
+ this.factory = factory;
83
+ }
84
+ /**
85
+ * Retryable: every side effect (persist/quota/stream markers) happens loop-side under
86
+ * `hooks.step`, so a durable retry only re-runs the model call and re-streams its tokens — never
87
+ * double-writes. NEVER call `writer.end()`/`fail()` here: the workflow owns the stream's lifecycle,
88
+ * across however many turns/retries it takes.
89
+ */
90
+ async llm(input) {
91
+ const deps = this.factory.forAgent(input.agentName);
92
+ const tools = await deps.registry.definitionsFor(input.actor, deps.rolesPolicy, deps.toolAllowList);
93
+ const opened = await deps.sink.open(input.sinkRunId);
94
+ const writer = input.childSink ? childSinkWriter(opened) : opened;
95
+ return deps.model.runTurn({
96
+ system: input.system,
97
+ messages: input.messages,
98
+ tools,
99
+ sink: writer
100
+ });
101
+ }
102
+ /**
103
+ * No retries — a tool may not be idempotent (a bare `@Step()` carries none, unlike `llm` above).
104
+ * The timeout is applied HERE, handler-side, via `withToolTimeout` — never as a durable dispatch
105
+ * `timeoutMs`, which bounds engine liveness (retryable) rather than the tool's own business outcome.
106
+ */
107
+ async tool(input) {
108
+ const deps = this.factory.forAgent(input.ctx.agentName);
109
+ const ctx = {
110
+ ...input.ctx
111
+ };
112
+ const invocation = deps.registry.invoke(input.toolName, input.input, ctx, deps.rolesPolicy);
113
+ return input.timeoutMs !== void 0 ? (0, import_nestjs_agent_core.withToolTimeout)(invocation, input.timeoutMs, input.toolName) : invocation;
114
+ }
115
+ };
116
+ _ts_decorate([
117
+ (0, import_nestjs_durable.Step)({
118
+ retries: 3
119
+ }),
120
+ _ts_metadata("design:type", Function),
121
+ _ts_metadata("design:paramtypes", [
122
+ typeof DispatchedLlmInput === "undefined" ? Object : DispatchedLlmInput
123
+ ]),
124
+ _ts_metadata("design:returntype", Promise)
125
+ ], AgentRunSteps.prototype, "llm", null);
126
+ _ts_decorate([
127
+ (0, import_nestjs_durable.Step)(),
128
+ _ts_metadata("design:type", Function),
129
+ _ts_metadata("design:paramtypes", [
130
+ typeof ToolStepEnvelope === "undefined" ? Object : ToolStepEnvelope
131
+ ]),
132
+ _ts_metadata("design:returntype", Promise)
133
+ ], AgentRunSteps.prototype, "tool", null);
134
+ AgentRunSteps = _ts_decorate([
135
+ (0, import_common.Injectable)(),
136
+ _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_DEPS_FACTORY)),
137
+ _ts_metadata("design:type", Function),
138
+ _ts_metadata("design:paramtypes", [
139
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
140
+ ])
141
+ ], AgentRunSteps);
142
+
143
+ // src/durable/dispatched-steps.token.ts
144
+ var AGENT_DISPATCHED_STEPS = Symbol.for("@dudousxd/nestjs-agent:dispatched-steps");
145
+
146
+ // src/durable/agent-run.workflow.ts
147
+ function _ts_decorate2(decorators, target, key, desc) {
148
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
149
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
150
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
151
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
152
+ }
153
+ __name(_ts_decorate2, "_ts_decorate");
154
+ function _ts_metadata2(k, v) {
155
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
156
+ }
157
+ __name(_ts_metadata2, "_ts_metadata");
158
+ function _ts_param2(paramIndex, decorator) {
159
+ return function(target, key) {
160
+ decorator(target, key, paramIndex);
161
+ };
162
+ }
163
+ __name(_ts_param2, "_ts_param");
71
164
  var AgentRunWorkflow = class _AgentRunWorkflow {
72
165
  static {
73
166
  __name(this, "AgentRunWorkflow");
74
167
  }
75
168
  factory;
76
169
  store;
77
- constructor(factory, store) {
170
+ steps;
171
+ dispatchedSteps;
172
+ constructor(factory, store, steps, dispatchedSteps) {
78
173
  this.factory = factory;
79
174
  this.store = store;
175
+ this.steps = steps;
176
+ this.dispatchedSteps = dispatchedSteps;
80
177
  }
81
178
  async run(ctx, input) {
82
179
  const day = input.day ?? utcDay();
@@ -91,6 +188,8 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
91
188
  openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
92
189
  awaitApproval: /* @__PURE__ */ __name((call) => ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`), "awaitApproval"),
93
190
  step: /* @__PURE__ */ __name((name, fn) => ctx.localStep(name, fn), "step"),
191
+ // Dispatched-step suspends must escape the loop's tool catch — control flow, not a tool failure.
192
+ isControlFlowError: /* @__PURE__ */ __name((error) => error instanceof import_nestjs_durable_core.WorkflowSuspended || error instanceof import_nestjs_durable_core.ContinueAsNew, "isControlFlowError"),
94
193
  runAgent: /* @__PURE__ */ __name(async (agentName, task) => {
95
194
  const subThreadId = await ctx.localStep(`subthread:${agentName}`, async () => {
96
195
  const thread = await this.store.createThread({
@@ -108,10 +207,23 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
108
207
  delegationDepth: (input.delegationDepth ?? 0) + 1,
109
208
  sinkRunId
110
209
  });
111
- }, "runAgent")
210
+ }, "runAgent"),
211
+ // Routes the two long steps through AgentRunSteps as engine-dispatched `ctx.step`s instead of
212
+ // `ctx.localStep`s, so a turn isn't pinned to this workflow worker for the model call or a tool
213
+ // execution. `sinkRunId`/`childSink` are sink routing this workflow already resolved above —
214
+ // core's dispatchLlm signature stays sink-topology-agnostic, so we add them here, not in core.
215
+ ...this.dispatchedSteps ? {
216
+ dispatchLlm: /* @__PURE__ */ __name((_index, envelope) => ctx.step(this.steps.llm, {
217
+ ...envelope,
218
+ runId: ctx.runId,
219
+ sinkRunId,
220
+ childSink: input.sinkRunId !== void 0
221
+ }), "dispatchLlm"),
222
+ dispatchTool: /* @__PURE__ */ __name((_call, envelope) => ctx.step(this.steps.tool, envelope), "dispatchTool")
223
+ } : {}
112
224
  };
113
225
  try {
114
- const result = await (0, import_nestjs_agent_core.runAgentLoop)({
226
+ const result = await (0, import_nestjs_agent_core2.runAgentLoop)({
115
227
  ...deps,
116
228
  day
117
229
  }, input, hooks);
@@ -122,12 +234,18 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
122
234
  throw error;
123
235
  }
124
236
  const message = error instanceof Error ? error.message : String(error);
125
- const code = error instanceof import_nestjs_agent_core.QuotaExceededError ? "quota_exceeded" : "run_failed";
126
- (0, import_nestjs_agent_core.publishAgentRunFailed)({
237
+ const code = error instanceof import_nestjs_agent_core2.QuotaExceededError ? "quota_exceeded" : "run_failed";
238
+ (0, import_nestjs_agent_core2.publishAgentRunFailed)({
127
239
  runId: ctx.runId,
128
240
  code,
129
241
  message
130
242
  });
243
+ await ctx.localStep("persist:run:fail", () => this.store.recordRunEnd?.({
244
+ runId: ctx.runId,
245
+ status: "failed",
246
+ errorCode: code,
247
+ errorMessage: message
248
+ }) ?? Promise.resolve());
131
249
  await ctx.localStep("deactivate", () => this.store.setActiveStream(input.threadId, null));
132
250
  const writer = await hooks.openSink();
133
251
  await writer.fail({
@@ -138,37 +256,40 @@ var AgentRunWorkflow = class _AgentRunWorkflow {
138
256
  }
139
257
  }
140
258
  };
141
- AgentRunWorkflow = _ts_decorate([
142
- (0, import_common.Injectable)(),
143
- (0, import_nestjs_durable.Workflow)({
259
+ AgentRunWorkflow = _ts_decorate2([
260
+ (0, import_common2.Injectable)(),
261
+ (0, import_nestjs_durable2.Workflow)({
144
262
  name: "agent.run",
145
263
  version: "1"
146
264
  }),
147
- _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_DEPS_FACTORY)),
148
- _ts_param(1, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_STORE)),
149
- _ts_metadata("design:type", Function),
150
- _ts_metadata("design:paramtypes", [
265
+ _ts_param2(0, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_DEPS_FACTORY)),
266
+ _ts_param2(1, (0, import_common2.Inject)(import_nestjs_agent_core2.AGENT_STORE)),
267
+ _ts_param2(3, (0, import_common2.Inject)(AGENT_DISPATCHED_STEPS)),
268
+ _ts_metadata2("design:type", Function),
269
+ _ts_metadata2("design:paramtypes", [
151
270
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
152
- typeof AgentStore === "undefined" ? Object : AgentStore
271
+ typeof AgentStore === "undefined" ? Object : AgentStore,
272
+ typeof AgentRunSteps === "undefined" ? Object : AgentRunSteps,
273
+ Boolean
153
274
  ])
154
275
  ], AgentRunWorkflow);
155
276
 
156
277
  // src/durable/durable-agent-runner.ts
157
278
  var import_node_crypto = require("crypto");
158
- var import_nestjs_durable2 = require("@dudousxd/nestjs-durable");
279
+ var import_nestjs_durable3 = require("@dudousxd/nestjs-durable");
159
280
  var import_nestjs_durable_core2 = require("@dudousxd/nestjs-durable-core");
160
- var import_common2 = require("@nestjs/common");
161
- function _ts_decorate2(decorators, target, key, desc) {
281
+ var import_common3 = require("@nestjs/common");
282
+ function _ts_decorate3(decorators, target, key, desc) {
162
283
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
163
284
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
164
285
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
165
286
  return c > 3 && r && Object.defineProperty(target, key, r), r;
166
287
  }
167
- __name(_ts_decorate2, "_ts_decorate");
168
- function _ts_metadata2(k, v) {
288
+ __name(_ts_decorate3, "_ts_decorate");
289
+ function _ts_metadata3(k, v) {
169
290
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
170
291
  }
171
- __name(_ts_metadata2, "_ts_metadata");
292
+ __name(_ts_metadata3, "_ts_metadata");
172
293
  var DurableAgentRunner = class {
173
294
  static {
174
295
  __name(this, "DurableAgentRunner");
@@ -201,24 +322,95 @@ var DurableAgentRunner = class {
201
322
  await Promise.resolve();
202
323
  }
203
324
  };
204
- DurableAgentRunner = _ts_decorate2([
205
- (0, import_common2.Injectable)(),
206
- _ts_metadata2("design:type", Function),
207
- _ts_metadata2("design:paramtypes", [
208
- typeof import_nestjs_durable2.WorkflowService === "undefined" ? Object : import_nestjs_durable2.WorkflowService
325
+ DurableAgentRunner = _ts_decorate3([
326
+ (0, import_common3.Injectable)(),
327
+ _ts_metadata3("design:type", Function),
328
+ _ts_metadata3("design:paramtypes", [
329
+ typeof import_nestjs_durable3.WorkflowService === "undefined" ? Object : import_nestjs_durable3.WorkflowService
209
330
  ])
210
331
  ], DurableAgentRunner);
211
332
 
212
333
  // src/durable/agent-durable.module.ts
213
- var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
214
- var import_common3 = require("@nestjs/common");
215
- function _ts_decorate3(decorators, target, key, desc) {
334
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
335
+ var import_common4 = require("@nestjs/common");
336
+
337
+ // src/in-process-sink.ts
338
+ var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
339
+ var InProcessTokenStreamSink = class {
340
+ static {
341
+ __name(this, "InProcessTokenStreamSink");
342
+ }
343
+ runs = /* @__PURE__ */ new Map();
344
+ buffer(runId) {
345
+ let buf = this.runs.get(runId);
346
+ if (buf === void 0) {
347
+ buf = {
348
+ chunks: [],
349
+ ended: false,
350
+ notify: /* @__PURE__ */ new Set()
351
+ };
352
+ this.runs.set(runId, buf);
353
+ }
354
+ return buf;
355
+ }
356
+ wake(buf) {
357
+ for (const resolve of buf.notify) {
358
+ resolve();
359
+ }
360
+ buf.notify.clear();
361
+ }
362
+ open(runId) {
363
+ const buf = this.buffer(runId);
364
+ return {
365
+ write: /* @__PURE__ */ __name((chunk) => {
366
+ buf.chunks.push(chunk);
367
+ this.wake(buf);
368
+ }, "write"),
369
+ end: /* @__PURE__ */ __name(() => {
370
+ buf.ended = true;
371
+ this.wake(buf);
372
+ }, "end"),
373
+ fail: /* @__PURE__ */ __name((error) => {
374
+ buf.failure = error;
375
+ buf.ended = true;
376
+ this.wake(buf);
377
+ }, "fail")
378
+ };
379
+ }
380
+ async *subscribe(runId) {
381
+ const buf = this.buffer(runId);
382
+ let index = 0;
383
+ while (true) {
384
+ while (index < buf.chunks.length) {
385
+ const chunk = buf.chunks[index];
386
+ index += 1;
387
+ if (chunk !== void 0) {
388
+ yield chunk;
389
+ }
390
+ }
391
+ if (buf.ended) {
392
+ if (buf.failure !== void 0) {
393
+ throw new import_nestjs_agent_core3.AgentStreamError(buf.failure);
394
+ }
395
+ return;
396
+ }
397
+ await new Promise((resolve) => buf.notify.add(resolve));
398
+ }
399
+ }
400
+ close(runId) {
401
+ this.runs.delete(runId);
402
+ }
403
+ };
404
+
405
+ // src/durable/agent-durable.module.ts
406
+ function _ts_decorate4(decorators, target, key, desc) {
216
407
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
217
408
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
218
409
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
219
410
  return c > 3 && r && Object.defineProperty(target, key, r), r;
220
411
  }
221
- __name(_ts_decorate3, "_ts_decorate");
412
+ __name(_ts_decorate4, "_ts_decorate");
413
+ var logger = new import_common4.Logger("AgentDurableModule");
222
414
  var AgentDurableModule = class _AgentDurableModule {
223
415
  static {
224
416
  __name(this, "AgentDurableModule");
@@ -235,50 +427,67 @@ var AgentDurableModule = class _AgentDurableModule {
235
427
  };
236
428
  }
237
429
  };
238
- AgentDurableModule = _ts_decorate3([
239
- (0, import_common3.Global)(),
240
- (0, import_common3.Module)({
430
+ AgentDurableModule = _ts_decorate4([
431
+ (0, import_common4.Global)(),
432
+ (0, import_common4.Module)({
241
433
  providers: [
242
434
  AgentRunWorkflow,
435
+ AgentRunSteps,
243
436
  DurableAgentRunner,
244
437
  {
245
- provide: import_nestjs_agent_core2.AGENT_DURABLE_RUNNER,
438
+ provide: import_nestjs_agent_core4.AGENT_DURABLE_RUNNER,
246
439
  useExisting: DurableAgentRunner
440
+ },
441
+ {
442
+ provide: AGENT_DISPATCHED_STEPS,
443
+ useFactory: /* @__PURE__ */ __name((options, sink) => {
444
+ const enabled = options.durable === true && options.dispatchedSteps !== false;
445
+ if (enabled && sink instanceof InProcessTokenStreamSink) {
446
+ logger.warn("Dispatched steps are active (the default under durable: true) with the default InProcessTokenStreamSink, which only buffers tokens in-process. A dispatched `llm` step served by a different worker cannot stream into this buffer. Wire a cross-process TokenStreamSink (e.g. a Redis pub/sub sink) via AgentModule.forRoot({ sink }) before running multi-pod, or set dispatchedSteps: false to keep the turn in-process localSteps.");
447
+ }
448
+ return enabled;
449
+ }, "useFactory"),
450
+ inject: [
451
+ import_nestjs_agent_core4.AGENT_OPTIONS,
452
+ import_nestjs_agent_core4.AGENT_SINK
453
+ ]
247
454
  }
248
455
  ],
249
456
  exports: [
250
- import_nestjs_agent_core2.AGENT_DURABLE_RUNNER,
251
- AgentRunWorkflow
457
+ import_nestjs_agent_core4.AGENT_DURABLE_RUNNER,
458
+ AgentRunWorkflow,
459
+ AgentRunSteps,
460
+ AGENT_DISPATCHED_STEPS
252
461
  ]
253
462
  })
254
463
  ], AgentDurableModule);
255
464
 
256
465
  // src/agent.module.ts
257
- var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
258
- var import_common15 = require("@nestjs/common");
466
+ var import_nestjs_agent_core17 = require("@dudousxd/nestjs-agent-core");
467
+ var import_common17 = require("@nestjs/common");
259
468
  var import_core3 = require("@nestjs/core");
260
469
 
261
470
  // src/agent-deps.factory.ts
262
- var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
263
- var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
264
- var import_common4 = require("@nestjs/common");
265
- function _ts_decorate4(decorators, target, key, desc) {
471
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
472
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
473
+ var import_common5 = require("@nestjs/common");
474
+ function _ts_decorate5(decorators, target, key, desc) {
266
475
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
267
476
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
268
477
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
269
478
  return c > 3 && r && Object.defineProperty(target, key, r), r;
270
479
  }
271
- __name(_ts_decorate4, "_ts_decorate");
272
- function _ts_metadata3(k, v) {
480
+ __name(_ts_decorate5, "_ts_decorate");
481
+ function _ts_metadata4(k, v) {
273
482
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
274
483
  }
275
- __name(_ts_metadata3, "_ts_metadata");
276
- function _ts_param2(paramIndex, decorator) {
484
+ __name(_ts_metadata4, "_ts_metadata");
485
+ function _ts_param3(paramIndex, decorator) {
277
486
  return function(target, key) {
278
487
  decorator(target, key, paramIndex);
279
488
  };
280
489
  }
281
- __name(_ts_param2, "_ts_param");
490
+ __name(_ts_param3, "_ts_param");
282
491
  function delegateToolName(target) {
283
492
  return `ask_${target.replace(/[^a-zA-Z0-9]+/g, "_")}`;
284
493
  }
@@ -386,28 +595,28 @@ var AgentDepsFactory2 = class {
386
595
  return void 0;
387
596
  }
388
597
  };
389
- AgentDepsFactory2 = _ts_decorate4([
390
- (0, import_common4.Injectable)(),
391
- _ts_param2(0, (0, import_common4.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
392
- _ts_param2(1, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_MODEL)),
393
- _ts_param2(2, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
394
- _ts_param2(3, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
395
- _ts_param2(4, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_ROLES_POLICY)),
396
- _ts_param2(5, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_TOOL_REGISTRY)),
397
- _ts_param2(6, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_REGISTRY)),
398
- _ts_param2(7, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_PROMPT_CONTRIBUTORS)),
399
- _ts_param2(8, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_STORE)),
400
- _ts_param2(9, (0, import_common4.Optional)()),
401
- _ts_param2(9, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_PRICING_STORE)),
402
- _ts_metadata3("design:type", Function),
403
- _ts_metadata3("design:paramtypes", [
598
+ AgentDepsFactory2 = _ts_decorate5([
599
+ (0, import_common5.Injectable)(),
600
+ _ts_param3(0, (0, import_common5.Inject)(import_nestjs_agent_core6.AGENT_OPTIONS)),
601
+ _ts_param3(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_MODEL)),
602
+ _ts_param3(2, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
603
+ _ts_param3(3, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_SINK)),
604
+ _ts_param3(4, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_ROLES_POLICY)),
605
+ _ts_param3(5, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_TOOL_REGISTRY)),
606
+ _ts_param3(6, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_REGISTRY)),
607
+ _ts_param3(7, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_PROMPT_CONTRIBUTORS)),
608
+ _ts_param3(8, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_QUOTA_STORE)),
609
+ _ts_param3(9, (0, import_common5.Optional)()),
610
+ _ts_param3(9, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_PRICING_STORE)),
611
+ _ts_metadata4("design:type", Function),
612
+ _ts_metadata4("design:paramtypes", [
404
613
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
405
614
  typeof ModelProvider === "undefined" ? Object : ModelProvider,
406
615
  typeof AgentStore === "undefined" ? Object : AgentStore,
407
616
  typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
408
617
  typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
409
- typeof import_nestjs_agent_core3.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core3.ToolRegistry,
410
- typeof import_nestjs_agent_core3.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core3.AgentRegistry,
618
+ typeof import_nestjs_agent_core5.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core5.ToolRegistry,
619
+ typeof import_nestjs_agent_core5.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core5.AgentRegistry,
411
620
  Array,
412
621
  Object,
413
622
  Object
@@ -415,25 +624,25 @@ AgentDepsFactory2 = _ts_decorate4([
415
624
  ], AgentDepsFactory2);
416
625
 
417
626
  // src/agent.service.ts
418
- var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
419
- var import_common5 = require("@nestjs/common");
420
- function _ts_decorate5(decorators, target, key, desc) {
627
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
628
+ var import_common6 = require("@nestjs/common");
629
+ function _ts_decorate6(decorators, target, key, desc) {
421
630
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
422
631
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
423
632
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
424
633
  return c > 3 && r && Object.defineProperty(target, key, r), r;
425
634
  }
426
- __name(_ts_decorate5, "_ts_decorate");
427
- function _ts_metadata4(k, v) {
635
+ __name(_ts_decorate6, "_ts_decorate");
636
+ function _ts_metadata5(k, v) {
428
637
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
429
638
  }
430
- __name(_ts_metadata4, "_ts_metadata");
431
- function _ts_param3(paramIndex, decorator) {
639
+ __name(_ts_metadata5, "_ts_metadata");
640
+ function _ts_param4(paramIndex, decorator) {
432
641
  return function(target, key) {
433
642
  decorator(target, key, paramIndex);
434
643
  };
435
644
  }
436
- __name(_ts_param3, "_ts_param");
645
+ __name(_ts_param4, "_ts_param");
437
646
  var AgentService = class {
438
647
  static {
439
648
  __name(this, "AgentService");
@@ -453,7 +662,7 @@ var AgentService = class {
453
662
  let threadId = params.threadId;
454
663
  if (threadId === void 0) {
455
664
  if (params.regenerate === true) {
456
- throw new import_common5.BadRequestException("regenerate requires an existing threadId");
665
+ throw new import_common6.BadRequestException("regenerate requires an existing threadId");
457
666
  }
458
667
  const created = await this.store.createThread({
459
668
  actor: params.actor,
@@ -492,20 +701,32 @@ var AgentService = class {
492
701
  return this.deps.forAgent().sink.subscribe(runId);
493
702
  }
494
703
  async approve(actor, toolCallId) {
495
- const runId = await this.runForOwnedToolCall(actor, toolCallId);
496
- return this.runner.signal(runId, toolCallId, {
704
+ await this.assertOwnsToolCall(actor, toolCallId);
705
+ return this.signalToolCall(toolCallId, {
497
706
  approved: true
498
707
  });
499
708
  }
500
709
  async reject(actor, toolCallId, reason) {
501
- const runId = await this.runForOwnedToolCall(actor, toolCallId);
502
- return this.runner.signal(runId, toolCallId, {
710
+ await this.assertOwnsToolCall(actor, toolCallId);
711
+ return this.signalToolCall(toolCallId, {
503
712
  approved: false,
504
713
  ...reason !== void 0 ? {
505
714
  reason
506
715
  } : {}
507
716
  });
508
717
  }
718
+ /**
719
+ * The decision core behind approve/reject, WITHOUT an ownership check: resolves the run
720
+ * currently awaiting `toolCallId` and signals it. `approve`/`reject` above call this after their
721
+ * own `assertOwnsToolCall` gate; the console `AgentApprovalPort` adapter (bound by `AgentModule`)
722
+ * calls it directly — a console caller is already authorized by the dashboard's own guards, and
723
+ * re-deriving thread ownership here would reject a legitimate operator decision (an operator is
724
+ * not the thread's own actor).
725
+ */
726
+ async signalToolCall(toolCallId, decision) {
727
+ const runId = await this.resolveRunForToolCall(toolCallId);
728
+ return this.runner.signal(runId, toolCallId, decision);
729
+ }
509
730
  async cancel(actor, runId) {
510
731
  await this.assertOwnsActiveStream(actor, runId);
511
732
  return this.runner.cancel(runId);
@@ -549,7 +770,7 @@ var AgentService = class {
549
770
  return;
550
771
  }
551
772
  if (this.store.updateThread === void 0) {
552
- throw new import_common5.NotImplementedException("Setting a thread's defaultAgent requires an AgentStore that implements updateThread(); the bound store does not support it.");
773
+ throw new import_common6.NotImplementedException("Setting a thread's defaultAgent requires an AgentStore that implements updateThread(); the bound store does not support it.");
553
774
  }
554
775
  await this.store.updateThread(threadId, {
555
776
  ...title !== void 0 ? {
@@ -561,10 +782,10 @@ var AgentService = class {
561
782
  validateTitle(title) {
562
783
  const trimmed = title.trim();
563
784
  if (trimmed.length === 0) {
564
- throw new import_common5.BadRequestException("title must not be empty");
785
+ throw new import_common6.BadRequestException("title must not be empty");
565
786
  }
566
787
  if (trimmed.length > 200) {
567
- throw new import_common5.BadRequestException("title must be at most 200 characters");
788
+ throw new import_common6.BadRequestException("title must be at most 200 characters");
568
789
  }
569
790
  return trimmed;
570
791
  }
@@ -646,29 +867,35 @@ var AgentService = class {
646
867
  async assertOwnsThread(actor, threadId) {
647
868
  const owner = await this.store.ownerOfThread(threadId);
648
869
  if (owner === null) {
649
- throw new import_common5.NotFoundException(`thread ${threadId} not found`);
870
+ throw new import_common6.NotFoundException(`thread ${threadId} not found`);
650
871
  }
651
872
  if (owner !== actor.id) {
652
- throw new import_common5.ForbiddenException("thread belongs to another actor");
873
+ throw new import_common6.ForbiddenException("thread belongs to another actor");
653
874
  }
654
875
  }
655
876
  /**
656
- * Authorization + routing seam for HITL approve/reject: assert the caller owns the tool call's
657
- * thread, then resolve the run currently awaiting that call (its thread's active stream). That run
658
- * is the sub-agent's own child run when the pending call belongs to a delegated agent — the client
659
- * never knows or supplies a runId; it is derived here from the tool call alone.
877
+ * Authorization seam for HITL approve/reject: the caller must own the tool call's thread. Split
878
+ * out from run resolution (see {@link resolveRunForToolCall}) so the console `AgentApprovalPort`
879
+ * adapter can resolve+signal a decision WITHOUT this check — it is authorized upstream instead.
660
880
  */
661
- async runForOwnedToolCall(actor, toolCallId) {
881
+ async assertOwnsToolCall(actor, toolCallId) {
662
882
  const owner = await this.store.ownerOfToolCall(toolCallId);
663
883
  if (owner === null) {
664
- throw new import_common5.NotFoundException(`tool call ${toolCallId} not found`);
884
+ throw new import_common6.NotFoundException(`tool call ${toolCallId} not found`);
665
885
  }
666
886
  if (owner !== actor.id) {
667
- throw new import_common5.ForbiddenException("tool call belongs to another actor");
887
+ throw new import_common6.ForbiddenException("tool call belongs to another actor");
668
888
  }
889
+ }
890
+ /**
891
+ * Resolve the run currently awaiting `toolCallId` (its thread's active stream). That run is the
892
+ * sub-agent's own child run when the pending call belongs to a delegated agent — the client never
893
+ * knows or supplies a runId; it is derived here from the tool call alone.
894
+ */
895
+ async resolveRunForToolCall(toolCallId) {
669
896
  const runId = await this.store.runForToolCall(toolCallId);
670
897
  if (runId === null) {
671
- throw new import_common5.NotFoundException(`tool call ${toolCallId} has no active run to signal`);
898
+ throw new import_common6.NotFoundException(`tool call ${toolCallId} has no active run to signal`);
672
899
  }
673
900
  return runId;
674
901
  }
@@ -676,21 +903,21 @@ var AgentService = class {
676
903
  async assertOwnsActiveStream(actor, runId) {
677
904
  const owner = await this.store.ownerOfActiveStream(runId);
678
905
  if (owner === null) {
679
- throw new import_common5.NotFoundException(`no active run ${runId}`);
906
+ throw new import_common6.NotFoundException(`no active run ${runId}`);
680
907
  }
681
908
  if (owner !== actor.id) {
682
- throw new import_common5.ForbiddenException("run belongs to another actor");
909
+ throw new import_common6.ForbiddenException("run belongs to another actor");
683
910
  }
684
911
  }
685
912
  };
686
- AgentService = _ts_decorate5([
687
- (0, import_common5.Injectable)(),
688
- _ts_param3(0, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_RUNNER)),
689
- _ts_param3(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
690
- _ts_param3(2, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
691
- _ts_param3(3, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_QUOTA_STORE)),
692
- _ts_metadata4("design:type", Function),
693
- _ts_metadata4("design:paramtypes", [
913
+ AgentService = _ts_decorate6([
914
+ (0, import_common6.Injectable)(),
915
+ _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_RUNNER)),
916
+ _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_STORE)),
917
+ _ts_param4(2, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_DEPS_FACTORY)),
918
+ _ts_param4(3, (0, import_common6.Inject)(import_nestjs_agent_core7.AGENT_QUOTA_STORE)),
919
+ _ts_metadata5("design:type", Function),
920
+ _ts_metadata5("design:paramtypes", [
694
921
  typeof AgentRunner === "undefined" ? Object : AgentRunner,
695
922
  typeof AgentStore === "undefined" ? Object : AgentStore,
696
923
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
@@ -698,26 +925,75 @@ AgentService = _ts_decorate5([
698
925
  ])
699
926
  ], AgentService);
700
927
 
928
+ // src/approval-port.adapter.ts
929
+ var import_common7 = require("@nestjs/common");
930
+ function _ts_decorate7(decorators, target, key, desc) {
931
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
932
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
933
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
934
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
935
+ }
936
+ __name(_ts_decorate7, "_ts_decorate");
937
+ function _ts_metadata6(k, v) {
938
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
939
+ }
940
+ __name(_ts_metadata6, "_ts_metadata");
941
+ var AgentApprovalPortAdapter = class {
942
+ static {
943
+ __name(this, "AgentApprovalPortAdapter");
944
+ }
945
+ agent;
946
+ constructor(agent) {
947
+ this.agent = agent;
948
+ }
949
+ async approve(toolCallId, opts) {
950
+ await this.agent.signalToolCall(toolCallId, {
951
+ approved: true,
952
+ ...opts?.executedByRef !== void 0 ? {
953
+ executedByRef: opts.executedByRef
954
+ } : {}
955
+ });
956
+ }
957
+ async reject(toolCallId, opts) {
958
+ await this.agent.signalToolCall(toolCallId, {
959
+ approved: false,
960
+ ...opts?.executedByRef !== void 0 ? {
961
+ executedByRef: opts.executedByRef
962
+ } : {},
963
+ ...opts?.reason !== void 0 ? {
964
+ reason: opts.reason
965
+ } : {}
966
+ });
967
+ }
968
+ };
969
+ AgentApprovalPortAdapter = _ts_decorate7([
970
+ (0, import_common7.Injectable)(),
971
+ _ts_metadata6("design:type", Function),
972
+ _ts_metadata6("design:paramtypes", [
973
+ typeof AgentService === "undefined" ? Object : AgentService
974
+ ])
975
+ ], AgentApprovalPortAdapter);
976
+
701
977
  // src/controller/agents.controller.ts
702
- var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
703
- var import_common6 = require("@nestjs/common");
704
- function _ts_decorate6(decorators, target, key, desc) {
978
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
979
+ var import_common8 = require("@nestjs/common");
980
+ function _ts_decorate8(decorators, target, key, desc) {
705
981
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
706
982
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
707
983
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
708
984
  return c > 3 && r && Object.defineProperty(target, key, r), r;
709
985
  }
710
- __name(_ts_decorate6, "_ts_decorate");
711
- function _ts_metadata5(k, v) {
986
+ __name(_ts_decorate8, "_ts_decorate");
987
+ function _ts_metadata7(k, v) {
712
988
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
713
989
  }
714
- __name(_ts_metadata5, "_ts_metadata");
715
- function _ts_param4(paramIndex, decorator) {
990
+ __name(_ts_metadata7, "_ts_metadata");
991
+ function _ts_param5(paramIndex, decorator) {
716
992
  return function(target, key) {
717
993
  decorator(target, key, paramIndex);
718
994
  };
719
995
  }
720
- __name(_ts_param4, "_ts_param");
996
+ __name(_ts_param5, "_ts_param");
721
997
  var AgentsController = class {
722
998
  static {
723
999
  __name(this, "AgentsController");
@@ -739,44 +1015,44 @@ var AgentsController = class {
739
1015
  }));
740
1016
  }
741
1017
  };
742
- _ts_decorate6([
743
- (0, import_common6.Get)(),
744
- _ts_metadata5("design:type", Function),
745
- _ts_metadata5("design:paramtypes", []),
746
- _ts_metadata5("design:returntype", Array)
1018
+ _ts_decorate8([
1019
+ (0, import_common8.Get)(),
1020
+ _ts_metadata7("design:type", Function),
1021
+ _ts_metadata7("design:paramtypes", []),
1022
+ _ts_metadata7("design:returntype", Array)
747
1023
  ], AgentsController.prototype, "list", null);
748
- AgentsController = _ts_decorate6([
749
- (0, import_common6.Controller)("agents"),
750
- _ts_param4(0, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_REGISTRY)),
751
- _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_DEPS_FACTORY)),
752
- _ts_metadata5("design:type", Function),
753
- _ts_metadata5("design:paramtypes", [
754
- typeof import_nestjs_agent_core6.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core6.AgentRegistry,
1024
+ AgentsController = _ts_decorate8([
1025
+ (0, import_common8.Controller)("agents"),
1026
+ _ts_param5(0, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_REGISTRY)),
1027
+ _ts_param5(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_DEPS_FACTORY)),
1028
+ _ts_metadata7("design:type", Function),
1029
+ _ts_metadata7("design:paramtypes", [
1030
+ typeof import_nestjs_agent_core8.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core8.AgentRegistry,
755
1031
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
756
1032
  ])
757
1033
  ], AgentsController);
758
1034
 
759
1035
  // src/controller/attachments.controller.ts
760
- var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
761
- var import_common7 = require("@nestjs/common");
1036
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1037
+ var import_common9 = require("@nestjs/common");
762
1038
  var import_platform_express = require("@nestjs/platform-express");
763
- function _ts_decorate7(decorators, target, key, desc) {
1039
+ function _ts_decorate9(decorators, target, key, desc) {
764
1040
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
765
1041
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
766
1042
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
767
1043
  return c > 3 && r && Object.defineProperty(target, key, r), r;
768
1044
  }
769
- __name(_ts_decorate7, "_ts_decorate");
770
- function _ts_metadata6(k, v) {
1045
+ __name(_ts_decorate9, "_ts_decorate");
1046
+ function _ts_metadata8(k, v) {
771
1047
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
772
1048
  }
773
- __name(_ts_metadata6, "_ts_metadata");
774
- function _ts_param5(paramIndex, decorator) {
1049
+ __name(_ts_metadata8, "_ts_metadata");
1050
+ function _ts_param6(paramIndex, decorator) {
775
1051
  return function(target, key) {
776
1052
  decorator(target, key, paramIndex);
777
1053
  };
778
1054
  }
779
- __name(_ts_param5, "_ts_param");
1055
+ __name(_ts_param6, "_ts_param");
780
1056
  var DEFAULT_MAX_ATTACHMENT_BYTES = 20 * 1024 * 1024;
781
1057
  var DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES = [
782
1058
  "image/png",
@@ -812,18 +1088,18 @@ var AttachmentsController = class {
812
1088
  }
813
1089
  async upload(req, file) {
814
1090
  if (this.staging === void 0) {
815
- throw new import_common7.NotImplementedException("Attachment upload is not configured on this server.");
1091
+ throw new import_common9.NotImplementedException("Attachment upload is not configured on this server.");
816
1092
  }
817
1093
  if (file === void 0) {
818
- throw new import_common7.BadRequestException('multipart field "file" is required');
1094
+ throw new import_common9.BadRequestException('multipart field "file" is required');
819
1095
  }
820
1096
  const allowedContentTypes = this.options.attachments?.allowedContentTypes ?? DEFAULT_ALLOWED_ATTACHMENT_CONTENT_TYPES;
821
1097
  if (!allowedContentTypes.includes(file.mimetype)) {
822
- throw new import_common7.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
1098
+ throw new import_common9.UnsupportedMediaTypeException(`content type "${file.mimetype}" is not allowed (allowed: ${allowedContentTypes.join(", ")})`);
823
1099
  }
824
1100
  const maxBytes = this.options.attachments?.maxBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES;
825
1101
  if (file.size > maxBytes) {
826
- throw new import_common7.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
1102
+ throw new import_common9.PayloadTooLargeException(`file exceeds the ${maxBytes}-byte limit`);
827
1103
  }
828
1104
  const actor = await this.actorResolver.resolve(req);
829
1105
  return this.staging.stage({
@@ -835,26 +1111,26 @@ var AttachmentsController = class {
835
1111
  });
836
1112
  }
837
1113
  };
838
- _ts_decorate7([
839
- (0, import_common7.Post)(),
840
- (0, import_common7.UseInterceptors)((0, import_platform_express.FileInterceptor)("file")),
841
- _ts_param5(0, (0, import_common7.Req)()),
842
- _ts_param5(1, (0, import_common7.UploadedFile)()),
843
- _ts_metadata6("design:type", Function),
844
- _ts_metadata6("design:paramtypes", [
1114
+ _ts_decorate9([
1115
+ (0, import_common9.Post)(),
1116
+ (0, import_common9.UseInterceptors)((0, import_platform_express.FileInterceptor)("file")),
1117
+ _ts_param6(0, (0, import_common9.Req)()),
1118
+ _ts_param6(1, (0, import_common9.UploadedFile)()),
1119
+ _ts_metadata8("design:type", Function),
1120
+ _ts_metadata8("design:paramtypes", [
845
1121
  typeof Request === "undefined" ? Object : Request,
846
1122
  Object
847
1123
  ]),
848
- _ts_metadata6("design:returntype", Promise)
1124
+ _ts_metadata8("design:returntype", Promise)
849
1125
  ], AttachmentsController.prototype, "upload", null);
850
- AttachmentsController = _ts_decorate7([
851
- (0, import_common7.Controller)("attachments"),
852
- _ts_param5(0, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_OPTIONS)),
853
- _ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
854
- _ts_param5(2, (0, import_common7.Optional)()),
855
- _ts_param5(2, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ATTACHMENT_STAGING)),
856
- _ts_metadata6("design:type", Function),
857
- _ts_metadata6("design:paramtypes", [
1126
+ AttachmentsController = _ts_decorate9([
1127
+ (0, import_common9.Controller)("attachments"),
1128
+ _ts_param6(0, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_OPTIONS)),
1129
+ _ts_param6(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
1130
+ _ts_param6(2, (0, import_common9.Optional)()),
1131
+ _ts_param6(2, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ATTACHMENT_STAGING)),
1132
+ _ts_metadata8("design:type", Function),
1133
+ _ts_metadata8("design:paramtypes", [
858
1134
  typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
859
1135
  typeof ActorResolver === "undefined" ? Object : ActorResolver,
860
1136
  Object
@@ -862,25 +1138,25 @@ AttachmentsController = _ts_decorate7([
862
1138
  ], AttachmentsController);
863
1139
 
864
1140
  // src/controller/chat.controller.ts
865
- var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
866
- var import_common8 = require("@nestjs/common");
867
- function _ts_decorate8(decorators, target, key, desc) {
1141
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1142
+ var import_common10 = require("@nestjs/common");
1143
+ function _ts_decorate10(decorators, target, key, desc) {
868
1144
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
869
1145
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
870
1146
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
871
1147
  return c > 3 && r && Object.defineProperty(target, key, r), r;
872
1148
  }
873
- __name(_ts_decorate8, "_ts_decorate");
874
- function _ts_metadata7(k, v) {
1149
+ __name(_ts_decorate10, "_ts_decorate");
1150
+ function _ts_metadata9(k, v) {
875
1151
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
876
1152
  }
877
- __name(_ts_metadata7, "_ts_metadata");
878
- function _ts_param6(paramIndex, decorator) {
1153
+ __name(_ts_metadata9, "_ts_metadata");
1154
+ function _ts_param7(paramIndex, decorator) {
879
1155
  return function(target, key) {
880
1156
  decorator(target, key, paramIndex);
881
1157
  };
882
1158
  }
883
- __name(_ts_param6, "_ts_param");
1159
+ __name(_ts_param7, "_ts_param");
884
1160
  var ChatController = class {
885
1161
  static {
886
1162
  __name(this, "ChatController");
@@ -968,7 +1244,7 @@ data: ${JSON.stringify({
968
1244
  }
969
1245
  res.write("event: done\ndata: {}\n\n");
970
1246
  } catch (error) {
971
- const payload = error instanceof import_nestjs_agent_core8.AgentStreamError ? {
1247
+ const payload = error instanceof import_nestjs_agent_core10.AgentStreamError ? {
972
1248
  code: error.code,
973
1249
  message: error.message
974
1250
  } : {
@@ -983,71 +1259,71 @@ data: ${JSON.stringify(payload)}
983
1259
  res.end();
984
1260
  }
985
1261
  };
986
- _ts_decorate8([
987
- (0, import_common8.Post)("chat"),
988
- _ts_param6(0, (0, import_common8.Req)()),
989
- _ts_param6(1, (0, import_common8.Res)()),
990
- _ts_param6(2, (0, import_common8.Body)()),
991
- _ts_metadata7("design:type", Function),
992
- _ts_metadata7("design:paramtypes", [
1262
+ _ts_decorate10([
1263
+ (0, import_common10.Post)("chat"),
1264
+ _ts_param7(0, (0, import_common10.Req)()),
1265
+ _ts_param7(1, (0, import_common10.Res)()),
1266
+ _ts_param7(2, (0, import_common10.Body)()),
1267
+ _ts_metadata9("design:type", Function),
1268
+ _ts_metadata9("design:paramtypes", [
993
1269
  typeof Request === "undefined" ? Object : Request,
994
1270
  typeof Response === "undefined" ? Object : Response,
995
1271
  typeof ChatBody === "undefined" ? Object : ChatBody
996
1272
  ]),
997
- _ts_metadata7("design:returntype", Promise)
1273
+ _ts_metadata9("design:returntype", Promise)
998
1274
  ], ChatController.prototype, "chat", null);
999
- _ts_decorate8([
1000
- (0, import_common8.Get)("chat/:runId/stream"),
1001
- _ts_param6(0, (0, import_common8.Param)("runId")),
1002
- _ts_param6(1, (0, import_common8.Res)()),
1003
- _ts_metadata7("design:type", Function),
1004
- _ts_metadata7("design:paramtypes", [
1275
+ _ts_decorate10([
1276
+ (0, import_common10.Get)("chat/:runId/stream"),
1277
+ _ts_param7(0, (0, import_common10.Param)("runId")),
1278
+ _ts_param7(1, (0, import_common10.Res)()),
1279
+ _ts_metadata9("design:type", Function),
1280
+ _ts_metadata9("design:paramtypes", [
1005
1281
  String,
1006
1282
  typeof Response === "undefined" ? Object : Response
1007
1283
  ]),
1008
- _ts_metadata7("design:returntype", Promise)
1284
+ _ts_metadata9("design:returntype", Promise)
1009
1285
  ], ChatController.prototype, "stream", null);
1010
- _ts_decorate8([
1011
- (0, import_common8.Post)("chat/:runId/cancel"),
1012
- _ts_param6(0, (0, import_common8.Req)()),
1013
- _ts_param6(1, (0, import_common8.Param)("runId")),
1014
- _ts_metadata7("design:type", Function),
1015
- _ts_metadata7("design:paramtypes", [
1286
+ _ts_decorate10([
1287
+ (0, import_common10.Post)("chat/:runId/cancel"),
1288
+ _ts_param7(0, (0, import_common10.Req)()),
1289
+ _ts_param7(1, (0, import_common10.Param)("runId")),
1290
+ _ts_metadata9("design:type", Function),
1291
+ _ts_metadata9("design:paramtypes", [
1016
1292
  typeof Request === "undefined" ? Object : Request,
1017
1293
  String
1018
1294
  ]),
1019
- _ts_metadata7("design:returntype", Promise)
1295
+ _ts_metadata9("design:returntype", Promise)
1020
1296
  ], ChatController.prototype, "cancel", null);
1021
- ChatController = _ts_decorate8([
1022
- (0, import_common8.Controller)(),
1023
- _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
1024
- _ts_metadata7("design:type", Function),
1025
- _ts_metadata7("design:paramtypes", [
1297
+ ChatController = _ts_decorate10([
1298
+ (0, import_common10.Controller)(),
1299
+ _ts_param7(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
1300
+ _ts_metadata9("design:type", Function),
1301
+ _ts_metadata9("design:paramtypes", [
1026
1302
  typeof AgentService === "undefined" ? Object : AgentService,
1027
1303
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1028
1304
  ])
1029
1305
  ], ChatController);
1030
1306
 
1031
1307
  // src/controller/quota.controller.ts
1032
- var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
1033
- var import_common9 = require("@nestjs/common");
1034
- function _ts_decorate9(decorators, target, key, desc) {
1308
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
1309
+ var import_common11 = require("@nestjs/common");
1310
+ function _ts_decorate11(decorators, target, key, desc) {
1035
1311
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1036
1312
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1037
1313
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1038
1314
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1039
1315
  }
1040
- __name(_ts_decorate9, "_ts_decorate");
1041
- function _ts_metadata8(k, v) {
1316
+ __name(_ts_decorate11, "_ts_decorate");
1317
+ function _ts_metadata10(k, v) {
1042
1318
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1043
1319
  }
1044
- __name(_ts_metadata8, "_ts_metadata");
1045
- function _ts_param7(paramIndex, decorator) {
1320
+ __name(_ts_metadata10, "_ts_metadata");
1321
+ function _ts_param8(paramIndex, decorator) {
1046
1322
  return function(target, key) {
1047
1323
  decorator(target, key, paramIndex);
1048
1324
  };
1049
1325
  }
1050
- __name(_ts_param7, "_ts_param");
1326
+ __name(_ts_param8, "_ts_param");
1051
1327
  var QuotaController = class {
1052
1328
  static {
1053
1329
  __name(this, "QuotaController");
@@ -1063,45 +1339,45 @@ var QuotaController = class {
1063
1339
  return this.agent.quotaToday(actor.id);
1064
1340
  }
1065
1341
  };
1066
- _ts_decorate9([
1067
- (0, import_common9.Get)("today"),
1068
- _ts_param7(0, (0, import_common9.Req)()),
1069
- _ts_metadata8("design:type", Function),
1070
- _ts_metadata8("design:paramtypes", [
1342
+ _ts_decorate11([
1343
+ (0, import_common11.Get)("today"),
1344
+ _ts_param8(0, (0, import_common11.Req)()),
1345
+ _ts_metadata10("design:type", Function),
1346
+ _ts_metadata10("design:paramtypes", [
1071
1347
  typeof Request === "undefined" ? Object : Request
1072
1348
  ]),
1073
- _ts_metadata8("design:returntype", Promise)
1349
+ _ts_metadata10("design:returntype", Promise)
1074
1350
  ], QuotaController.prototype, "today", null);
1075
- QuotaController = _ts_decorate9([
1076
- (0, import_common9.Controller)("quota"),
1077
- _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
1078
- _ts_metadata8("design:type", Function),
1079
- _ts_metadata8("design:paramtypes", [
1351
+ QuotaController = _ts_decorate11([
1352
+ (0, import_common11.Controller)("quota"),
1353
+ _ts_param8(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
1354
+ _ts_metadata10("design:type", Function),
1355
+ _ts_metadata10("design:paramtypes", [
1080
1356
  typeof AgentService === "undefined" ? Object : AgentService,
1081
1357
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1082
1358
  ])
1083
1359
  ], QuotaController);
1084
1360
 
1085
1361
  // src/controller/threads.controller.ts
1086
- var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
1087
- var import_common10 = require("@nestjs/common");
1088
- function _ts_decorate10(decorators, target, key, desc) {
1362
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
1363
+ var import_common12 = require("@nestjs/common");
1364
+ function _ts_decorate12(decorators, target, key, desc) {
1089
1365
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1090
1366
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1091
1367
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1092
1368
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1093
1369
  }
1094
- __name(_ts_decorate10, "_ts_decorate");
1095
- function _ts_metadata9(k, v) {
1370
+ __name(_ts_decorate12, "_ts_decorate");
1371
+ function _ts_metadata11(k, v) {
1096
1372
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1097
1373
  }
1098
- __name(_ts_metadata9, "_ts_metadata");
1099
- function _ts_param8(paramIndex, decorator) {
1374
+ __name(_ts_metadata11, "_ts_metadata");
1375
+ function _ts_param9(paramIndex, decorator) {
1100
1376
  return function(target, key) {
1101
1377
  decorator(target, key, paramIndex);
1102
1378
  };
1103
1379
  }
1104
- __name(_ts_param8, "_ts_param");
1380
+ __name(_ts_param9, "_ts_param");
1105
1381
  var ThreadsController = class {
1106
1382
  static {
1107
1383
  __name(this, "ThreadsController");
@@ -1165,117 +1441,117 @@ var ThreadsController = class {
1165
1441
  };
1166
1442
  }
1167
1443
  };
1168
- _ts_decorate10([
1169
- (0, import_common10.Get)(),
1170
- _ts_param8(0, (0, import_common10.Req)()),
1171
- _ts_metadata9("design:type", Function),
1172
- _ts_metadata9("design:paramtypes", [
1444
+ _ts_decorate12([
1445
+ (0, import_common12.Get)(),
1446
+ _ts_param9(0, (0, import_common12.Req)()),
1447
+ _ts_metadata11("design:type", Function),
1448
+ _ts_metadata11("design:paramtypes", [
1173
1449
  typeof Request === "undefined" ? Object : Request
1174
1450
  ]),
1175
- _ts_metadata9("design:returntype", Promise)
1451
+ _ts_metadata11("design:returntype", Promise)
1176
1452
  ], ThreadsController.prototype, "list", null);
1177
- _ts_decorate10([
1178
- (0, import_common10.Get)(":id"),
1179
- _ts_param8(0, (0, import_common10.Req)()),
1180
- _ts_param8(1, (0, import_common10.Param)("id")),
1181
- _ts_metadata9("design:type", Function),
1182
- _ts_metadata9("design:paramtypes", [
1453
+ _ts_decorate12([
1454
+ (0, import_common12.Get)(":id"),
1455
+ _ts_param9(0, (0, import_common12.Req)()),
1456
+ _ts_param9(1, (0, import_common12.Param)("id")),
1457
+ _ts_metadata11("design:type", Function),
1458
+ _ts_metadata11("design:paramtypes", [
1183
1459
  typeof Request === "undefined" ? Object : Request,
1184
1460
  String
1185
1461
  ]),
1186
- _ts_metadata9("design:returntype", Promise)
1462
+ _ts_metadata11("design:returntype", Promise)
1187
1463
  ], ThreadsController.prototype, "detail", null);
1188
- _ts_decorate10([
1189
- (0, import_common10.Delete)(":id"),
1190
- _ts_param8(0, (0, import_common10.Req)()),
1191
- _ts_param8(1, (0, import_common10.Param)("id")),
1192
- _ts_metadata9("design:type", Function),
1193
- _ts_metadata9("design:paramtypes", [
1464
+ _ts_decorate12([
1465
+ (0, import_common12.Delete)(":id"),
1466
+ _ts_param9(0, (0, import_common12.Req)()),
1467
+ _ts_param9(1, (0, import_common12.Param)("id")),
1468
+ _ts_metadata11("design:type", Function),
1469
+ _ts_metadata11("design:paramtypes", [
1194
1470
  typeof Request === "undefined" ? Object : Request,
1195
1471
  String
1196
1472
  ]),
1197
- _ts_metadata9("design:returntype", Promise)
1473
+ _ts_metadata11("design:returntype", Promise)
1198
1474
  ], ThreadsController.prototype, "remove", null);
1199
- _ts_decorate10([
1200
- (0, import_common10.Post)(":id/fork-from/:messageId"),
1201
- _ts_param8(0, (0, import_common10.Req)()),
1202
- _ts_param8(1, (0, import_common10.Param)("id")),
1203
- _ts_param8(2, (0, import_common10.Param)("messageId")),
1204
- _ts_metadata9("design:type", Function),
1205
- _ts_metadata9("design:paramtypes", [
1475
+ _ts_decorate12([
1476
+ (0, import_common12.Post)(":id/fork-from/:messageId"),
1477
+ _ts_param9(0, (0, import_common12.Req)()),
1478
+ _ts_param9(1, (0, import_common12.Param)("id")),
1479
+ _ts_param9(2, (0, import_common12.Param)("messageId")),
1480
+ _ts_metadata11("design:type", Function),
1481
+ _ts_metadata11("design:paramtypes", [
1206
1482
  typeof Request === "undefined" ? Object : Request,
1207
1483
  String,
1208
1484
  String
1209
1485
  ]),
1210
- _ts_metadata9("design:returntype", Promise)
1486
+ _ts_metadata11("design:returntype", Promise)
1211
1487
  ], ThreadsController.prototype, "fork", null);
1212
- _ts_decorate10([
1213
- (0, import_common10.Patch)(":id"),
1214
- _ts_param8(0, (0, import_common10.Req)()),
1215
- _ts_param8(1, (0, import_common10.Param)("id")),
1216
- _ts_param8(2, (0, import_common10.Body)()),
1217
- _ts_metadata9("design:type", Function),
1218
- _ts_metadata9("design:paramtypes", [
1488
+ _ts_decorate12([
1489
+ (0, import_common12.Patch)(":id"),
1490
+ _ts_param9(0, (0, import_common12.Req)()),
1491
+ _ts_param9(1, (0, import_common12.Param)("id")),
1492
+ _ts_param9(2, (0, import_common12.Body)()),
1493
+ _ts_metadata11("design:type", Function),
1494
+ _ts_metadata11("design:paramtypes", [
1219
1495
  typeof Request === "undefined" ? Object : Request,
1220
1496
  String,
1221
1497
  typeof UpdateThreadBody === "undefined" ? Object : UpdateThreadBody
1222
1498
  ]),
1223
- _ts_metadata9("design:returntype", Promise)
1499
+ _ts_metadata11("design:returntype", Promise)
1224
1500
  ], ThreadsController.prototype, "update", null);
1225
- _ts_decorate10([
1226
- (0, import_common10.Post)(":id/promote"),
1227
- _ts_param8(0, (0, import_common10.Req)()),
1228
- _ts_param8(1, (0, import_common10.Param)("id")),
1229
- _ts_metadata9("design:type", Function),
1230
- _ts_metadata9("design:paramtypes", [
1501
+ _ts_decorate12([
1502
+ (0, import_common12.Post)(":id/promote"),
1503
+ _ts_param9(0, (0, import_common12.Req)()),
1504
+ _ts_param9(1, (0, import_common12.Param)("id")),
1505
+ _ts_metadata11("design:type", Function),
1506
+ _ts_metadata11("design:paramtypes", [
1231
1507
  typeof Request === "undefined" ? Object : Request,
1232
1508
  String
1233
1509
  ]),
1234
- _ts_metadata9("design:returntype", Promise)
1510
+ _ts_metadata11("design:returntype", Promise)
1235
1511
  ], ThreadsController.prototype, "promote", null);
1236
- _ts_decorate10([
1237
- (0, import_common10.Delete)(":id/from/:messageId"),
1238
- _ts_param8(0, (0, import_common10.Req)()),
1239
- _ts_param8(1, (0, import_common10.Param)("id")),
1240
- _ts_param8(2, (0, import_common10.Param)("messageId")),
1241
- _ts_metadata9("design:type", Function),
1242
- _ts_metadata9("design:paramtypes", [
1512
+ _ts_decorate12([
1513
+ (0, import_common12.Delete)(":id/from/:messageId"),
1514
+ _ts_param9(0, (0, import_common12.Req)()),
1515
+ _ts_param9(1, (0, import_common12.Param)("id")),
1516
+ _ts_param9(2, (0, import_common12.Param)("messageId")),
1517
+ _ts_metadata11("design:type", Function),
1518
+ _ts_metadata11("design:paramtypes", [
1243
1519
  typeof Request === "undefined" ? Object : Request,
1244
1520
  String,
1245
1521
  String
1246
1522
  ]),
1247
- _ts_metadata9("design:returntype", Promise)
1523
+ _ts_metadata11("design:returntype", Promise)
1248
1524
  ], ThreadsController.prototype, "truncateFrom", null);
1249
- ThreadsController = _ts_decorate10([
1250
- (0, import_common10.Controller)("threads"),
1251
- _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_ACTOR_RESOLVER)),
1252
- _ts_metadata9("design:type", Function),
1253
- _ts_metadata9("design:paramtypes", [
1525
+ ThreadsController = _ts_decorate12([
1526
+ (0, import_common12.Controller)("threads"),
1527
+ _ts_param9(1, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_ACTOR_RESOLVER)),
1528
+ _ts_metadata11("design:type", Function),
1529
+ _ts_metadata11("design:paramtypes", [
1254
1530
  typeof AgentService === "undefined" ? Object : AgentService,
1255
1531
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1256
1532
  ])
1257
1533
  ], ThreadsController);
1258
1534
 
1259
1535
  // src/controller/tool-call.controller.ts
1260
- var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
1261
- var import_common11 = require("@nestjs/common");
1262
- function _ts_decorate11(decorators, target, key, desc) {
1536
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
1537
+ var import_common13 = require("@nestjs/common");
1538
+ function _ts_decorate13(decorators, target, key, desc) {
1263
1539
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1264
1540
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1265
1541
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1266
1542
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1267
1543
  }
1268
- __name(_ts_decorate11, "_ts_decorate");
1269
- function _ts_metadata10(k, v) {
1544
+ __name(_ts_decorate13, "_ts_decorate");
1545
+ function _ts_metadata12(k, v) {
1270
1546
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1271
1547
  }
1272
- __name(_ts_metadata10, "_ts_metadata");
1273
- function _ts_param9(paramIndex, decorator) {
1548
+ __name(_ts_metadata12, "_ts_metadata");
1549
+ function _ts_param10(paramIndex, decorator) {
1274
1550
  return function(target, key) {
1275
1551
  decorator(target, key, paramIndex);
1276
1552
  };
1277
1553
  }
1278
- __name(_ts_param9, "_ts_param");
1554
+ __name(_ts_param10, "_ts_param");
1279
1555
  var ToolCallController = class {
1280
1556
  static {
1281
1557
  __name(this, "ToolCallController");
@@ -1301,41 +1577,41 @@ var ToolCallController = class {
1301
1577
  };
1302
1578
  }
1303
1579
  };
1304
- _ts_decorate11([
1305
- (0, import_common11.Post)("approve"),
1306
- _ts_param9(0, (0, import_common11.Req)()),
1307
- _ts_param9(1, (0, import_common11.Body)()),
1308
- _ts_metadata10("design:type", Function),
1309
- _ts_metadata10("design:paramtypes", [
1580
+ _ts_decorate13([
1581
+ (0, import_common13.Post)("approve"),
1582
+ _ts_param10(0, (0, import_common13.Req)()),
1583
+ _ts_param10(1, (0, import_common13.Body)()),
1584
+ _ts_metadata12("design:type", Function),
1585
+ _ts_metadata12("design:paramtypes", [
1310
1586
  typeof Request === "undefined" ? Object : Request,
1311
1587
  typeof ApproveBody === "undefined" ? Object : ApproveBody
1312
1588
  ]),
1313
- _ts_metadata10("design:returntype", Promise)
1589
+ _ts_metadata12("design:returntype", Promise)
1314
1590
  ], ToolCallController.prototype, "approve", null);
1315
- _ts_decorate11([
1316
- (0, import_common11.Post)("reject"),
1317
- _ts_param9(0, (0, import_common11.Req)()),
1318
- _ts_param9(1, (0, import_common11.Body)()),
1319
- _ts_metadata10("design:type", Function),
1320
- _ts_metadata10("design:paramtypes", [
1591
+ _ts_decorate13([
1592
+ (0, import_common13.Post)("reject"),
1593
+ _ts_param10(0, (0, import_common13.Req)()),
1594
+ _ts_param10(1, (0, import_common13.Body)()),
1595
+ _ts_metadata12("design:type", Function),
1596
+ _ts_metadata12("design:paramtypes", [
1321
1597
  typeof Request === "undefined" ? Object : Request,
1322
1598
  typeof RejectBody === "undefined" ? Object : RejectBody
1323
1599
  ]),
1324
- _ts_metadata10("design:returntype", Promise)
1600
+ _ts_metadata12("design:returntype", Promise)
1325
1601
  ], ToolCallController.prototype, "reject", null);
1326
- ToolCallController = _ts_decorate11([
1327
- (0, import_common11.Controller)("tool-call"),
1328
- _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core11.AGENT_ACTOR_RESOLVER)),
1329
- _ts_metadata10("design:type", Function),
1330
- _ts_metadata10("design:paramtypes", [
1602
+ ToolCallController = _ts_decorate13([
1603
+ (0, import_common13.Controller)("tool-call"),
1604
+ _ts_param10(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER)),
1605
+ _ts_metadata12("design:type", Function),
1606
+ _ts_metadata12("design:paramtypes", [
1331
1607
  typeof AgentService === "undefined" ? Object : AgentService,
1332
1608
  typeof ActorResolver === "undefined" ? Object : ActorResolver
1333
1609
  ])
1334
1610
  ], ToolCallController);
1335
1611
 
1336
1612
  // src/discovery/agent-discovery.service.ts
1337
- var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
1338
- var import_common12 = require("@nestjs/common");
1613
+ var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
1614
+ var import_common14 = require("@nestjs/common");
1339
1615
  var import_core = require("@nestjs/core");
1340
1616
 
1341
1617
  // src/decorator/agent.decorator.ts
@@ -1352,23 +1628,23 @@ var SYSTEM_PROMPT_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt");
1352
1628
  var SYSTEM_PROMPT_CONTRIBUTOR_METADATA = Symbol.for("@dudousxd/nestjs-agent:system-prompt-contributor");
1353
1629
 
1354
1630
  // src/discovery/agent-discovery.service.ts
1355
- function _ts_decorate12(decorators, target, key, desc) {
1631
+ function _ts_decorate14(decorators, target, key, desc) {
1356
1632
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1357
1633
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1358
1634
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1359
1635
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1360
1636
  }
1361
- __name(_ts_decorate12, "_ts_decorate");
1362
- function _ts_metadata11(k, v) {
1637
+ __name(_ts_decorate14, "_ts_decorate");
1638
+ function _ts_metadata13(k, v) {
1363
1639
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1364
1640
  }
1365
- __name(_ts_metadata11, "_ts_metadata");
1366
- function _ts_param10(paramIndex, decorator) {
1641
+ __name(_ts_metadata13, "_ts_metadata");
1642
+ function _ts_param11(paramIndex, decorator) {
1367
1643
  return function(target, key) {
1368
1644
  decorator(target, key, paramIndex);
1369
1645
  };
1370
1646
  }
1371
- __name(_ts_param10, "_ts_param");
1647
+ __name(_ts_param11, "_ts_param");
1372
1648
  var AgentDiscoveryService = class _AgentDiscoveryService {
1373
1649
  static {
1374
1650
  __name(this, "AgentDiscoveryService");
@@ -1377,7 +1653,7 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
1377
1653
  scanner;
1378
1654
  registry;
1379
1655
  contributors;
1380
- logger = new import_common12.Logger(_AgentDiscoveryService.name);
1656
+ logger = new import_common14.Logger(_AgentDiscoveryService.name);
1381
1657
  constructor(discovery, scanner, registry, contributors) {
1382
1658
  this.discovery = discovery;
1383
1659
  this.scanner = scanner;
@@ -1465,22 +1741,22 @@ var AgentDiscoveryService = class _AgentDiscoveryService {
1465
1741
  return (ctx) => candidate.call(instance, ctx);
1466
1742
  }
1467
1743
  };
1468
- AgentDiscoveryService = _ts_decorate12([
1469
- (0, import_common12.Injectable)(),
1470
- _ts_param10(2, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_REGISTRY)),
1471
- _ts_param10(3, (0, import_common12.Inject)(import_nestjs_agent_core12.AGENT_PROMPT_CONTRIBUTORS)),
1472
- _ts_metadata11("design:type", Function),
1473
- _ts_metadata11("design:paramtypes", [
1744
+ AgentDiscoveryService = _ts_decorate14([
1745
+ (0, import_common14.Injectable)(),
1746
+ _ts_param11(2, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_REGISTRY)),
1747
+ _ts_param11(3, (0, import_common14.Inject)(import_nestjs_agent_core14.AGENT_PROMPT_CONTRIBUTORS)),
1748
+ _ts_metadata13("design:type", Function),
1749
+ _ts_metadata13("design:paramtypes", [
1474
1750
  typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
1475
1751
  typeof import_core.MetadataScanner === "undefined" ? Object : import_core.MetadataScanner,
1476
- typeof import_nestjs_agent_core12.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core12.AgentRegistry,
1752
+ typeof import_nestjs_agent_core14.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core14.AgentRegistry,
1477
1753
  Array
1478
1754
  ])
1479
1755
  ], AgentDiscoveryService);
1480
1756
 
1481
1757
  // src/discovery/ai-tool-discovery.service.ts
1482
- var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
1483
- var import_common13 = require("@nestjs/common");
1758
+ var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
1759
+ var import_common15 = require("@nestjs/common");
1484
1760
  var import_core2 = require("@nestjs/core");
1485
1761
  var import_zod = require("zod");
1486
1762
 
@@ -1500,23 +1776,23 @@ function isBrandedFunctionalTool(value) {
1500
1776
  __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
1501
1777
 
1502
1778
  // src/discovery/ai-tool-discovery.service.ts
1503
- function _ts_decorate13(decorators, target, key, desc) {
1779
+ function _ts_decorate15(decorators, target, key, desc) {
1504
1780
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1505
1781
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1506
1782
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1507
1783
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1508
1784
  }
1509
- __name(_ts_decorate13, "_ts_decorate");
1510
- function _ts_metadata12(k, v) {
1785
+ __name(_ts_decorate15, "_ts_decorate");
1786
+ function _ts_metadata14(k, v) {
1511
1787
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1512
1788
  }
1513
- __name(_ts_metadata12, "_ts_metadata");
1514
- function _ts_param11(paramIndex, decorator) {
1789
+ __name(_ts_metadata14, "_ts_metadata");
1790
+ function _ts_param12(paramIndex, decorator) {
1515
1791
  return function(target, key) {
1516
1792
  decorator(target, key, paramIndex);
1517
1793
  };
1518
1794
  }
1519
- __name(_ts_param11, "_ts_param");
1795
+ __name(_ts_param12, "_ts_param");
1520
1796
  var AiToolDiscoveryService = class _AiToolDiscoveryService {
1521
1797
  static {
1522
1798
  __name(this, "AiToolDiscoveryService");
@@ -1525,7 +1801,7 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
1525
1801
  registry;
1526
1802
  agents;
1527
1803
  options;
1528
- logger = new import_common13.Logger(_AiToolDiscoveryService.name);
1804
+ logger = new import_common15.Logger(_AiToolDiscoveryService.name);
1529
1805
  constructor(discovery, registry, agents, options) {
1530
1806
  this.discovery = discovery;
1531
1807
  this.registry = registry;
@@ -1623,13 +1899,13 @@ var AiToolDiscoveryService = class _AiToolDiscoveryService {
1623
1899
  return true;
1624
1900
  }
1625
1901
  };
1626
- AiToolDiscoveryService = _ts_decorate13([
1627
- (0, import_common13.Injectable)(),
1628
- _ts_param11(1, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_TOOL_REGISTRY)),
1629
- _ts_param11(2, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_REGISTRY)),
1630
- _ts_param11(3, (0, import_common13.Inject)(import_nestjs_agent_core13.AGENT_OPTIONS)),
1631
- _ts_metadata12("design:type", Function),
1632
- _ts_metadata12("design:paramtypes", [
1902
+ AiToolDiscoveryService = _ts_decorate15([
1903
+ (0, import_common15.Injectable)(),
1904
+ _ts_param12(1, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_TOOL_REGISTRY)),
1905
+ _ts_param12(2, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_REGISTRY)),
1906
+ _ts_param12(3, (0, import_common15.Inject)(import_nestjs_agent_core15.AGENT_OPTIONS)),
1907
+ _ts_metadata14("design:type", Function),
1908
+ _ts_metadata14("design:paramtypes", [
1633
1909
  typeof import_core2.DiscoveryService === "undefined" ? Object : import_core2.DiscoveryService,
1634
1910
  typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
1635
1911
  typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
@@ -1637,74 +1913,6 @@ AiToolDiscoveryService = _ts_decorate13([
1637
1913
  ])
1638
1914
  ], AiToolDiscoveryService);
1639
1915
 
1640
- // src/in-process-sink.ts
1641
- var import_nestjs_agent_core14 = require("@dudousxd/nestjs-agent-core");
1642
- var InProcessTokenStreamSink = class {
1643
- static {
1644
- __name(this, "InProcessTokenStreamSink");
1645
- }
1646
- runs = /* @__PURE__ */ new Map();
1647
- buffer(runId) {
1648
- let buf = this.runs.get(runId);
1649
- if (buf === void 0) {
1650
- buf = {
1651
- chunks: [],
1652
- ended: false,
1653
- notify: /* @__PURE__ */ new Set()
1654
- };
1655
- this.runs.set(runId, buf);
1656
- }
1657
- return buf;
1658
- }
1659
- wake(buf) {
1660
- for (const resolve of buf.notify) {
1661
- resolve();
1662
- }
1663
- buf.notify.clear();
1664
- }
1665
- open(runId) {
1666
- const buf = this.buffer(runId);
1667
- return {
1668
- write: /* @__PURE__ */ __name((chunk) => {
1669
- buf.chunks.push(chunk);
1670
- this.wake(buf);
1671
- }, "write"),
1672
- end: /* @__PURE__ */ __name(() => {
1673
- buf.ended = true;
1674
- this.wake(buf);
1675
- }, "end"),
1676
- fail: /* @__PURE__ */ __name((error) => {
1677
- buf.failure = error;
1678
- buf.ended = true;
1679
- this.wake(buf);
1680
- }, "fail")
1681
- };
1682
- }
1683
- async *subscribe(runId) {
1684
- const buf = this.buffer(runId);
1685
- let index = 0;
1686
- while (true) {
1687
- while (index < buf.chunks.length) {
1688
- const chunk = buf.chunks[index];
1689
- index += 1;
1690
- if (chunk !== void 0) {
1691
- yield chunk;
1692
- }
1693
- }
1694
- if (buf.ended) {
1695
- if (buf.failure !== void 0) {
1696
- throw new import_nestjs_agent_core14.AgentStreamError(buf.failure);
1697
- }
1698
- return;
1699
- }
1700
- await new Promise((resolve) => buf.notify.add(resolve));
1701
- }
1702
- }
1703
- close(runId) {
1704
- this.runs.delete(runId);
1705
- }
1706
- };
1707
-
1708
1916
  // src/ledger-quota-store.ts
1709
1917
  var LedgerQuotaStore = class {
1710
1918
  static {
@@ -1729,32 +1937,32 @@ var LedgerQuotaStore = class {
1729
1937
  };
1730
1938
 
1731
1939
  // src/runner/inline-agent-runner.ts
1732
- var import_nestjs_agent_core15 = require("@dudousxd/nestjs-agent-core");
1733
- var import_common14 = require("@nestjs/common");
1734
- function _ts_decorate14(decorators, target, key, desc) {
1940
+ var import_nestjs_agent_core16 = require("@dudousxd/nestjs-agent-core");
1941
+ var import_common16 = require("@nestjs/common");
1942
+ function _ts_decorate16(decorators, target, key, desc) {
1735
1943
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1736
1944
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1737
1945
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1738
1946
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1739
1947
  }
1740
- __name(_ts_decorate14, "_ts_decorate");
1741
- function _ts_metadata13(k, v) {
1948
+ __name(_ts_decorate16, "_ts_decorate");
1949
+ function _ts_metadata15(k, v) {
1742
1950
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1743
1951
  }
1744
- __name(_ts_metadata13, "_ts_metadata");
1745
- function _ts_param12(paramIndex, decorator) {
1952
+ __name(_ts_metadata15, "_ts_metadata");
1953
+ function _ts_param13(paramIndex, decorator) {
1746
1954
  return function(target, key) {
1747
1955
  decorator(target, key, paramIndex);
1748
1956
  };
1749
1957
  }
1750
- __name(_ts_param12, "_ts_param");
1958
+ __name(_ts_param13, "_ts_param");
1751
1959
  var InlineAgentRunner = class _InlineAgentRunner {
1752
1960
  static {
1753
1961
  __name(this, "InlineAgentRunner");
1754
1962
  }
1755
1963
  factory;
1756
1964
  store;
1757
- logger = new import_common14.Logger(_InlineAgentRunner.name);
1965
+ logger = new import_common16.Logger(_InlineAgentRunner.name);
1758
1966
  pending = /* @__PURE__ */ new Map();
1759
1967
  constructor(factory, store) {
1760
1968
  this.factory = factory;
@@ -1765,18 +1973,24 @@ var InlineAgentRunner = class _InlineAgentRunner {
1765
1973
  const day = input.day ?? utcDay();
1766
1974
  const deps = this.factory.forAgent(input.agentName);
1767
1975
  const hooks = this.topLevelHooks(runId, deps, input.actor, day);
1768
- void (0, import_nestjs_agent_core15.runAgentLoop)({
1976
+ void (0, import_nestjs_agent_core16.runAgentLoop)({
1769
1977
  ...deps,
1770
1978
  day
1771
1979
  }, input, hooks).then(() => this.store.setActiveStream(input.threadId, null)).catch(async (error) => {
1772
1980
  const message = error instanceof Error ? error.message : String(error);
1773
- const code = error instanceof import_nestjs_agent_core15.QuotaExceededError ? "quota_exceeded" : "run_failed";
1981
+ const code = error instanceof import_nestjs_agent_core16.QuotaExceededError ? "quota_exceeded" : "run_failed";
1774
1982
  this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
1775
- (0, import_nestjs_agent_core15.publishAgentRunFailed)({
1983
+ (0, import_nestjs_agent_core16.publishAgentRunFailed)({
1776
1984
  runId,
1777
1985
  code,
1778
1986
  message
1779
1987
  });
1988
+ await this.store.recordRunEnd?.({
1989
+ runId,
1990
+ status: "failed",
1991
+ errorCode: code,
1992
+ errorMessage: message
1993
+ });
1780
1994
  await this.store.setActiveStream(input.threadId, null);
1781
1995
  const writer = await deps.sink.open(runId);
1782
1996
  await writer.fail({
@@ -1836,7 +2050,7 @@ var InlineAgentRunner = class _InlineAgentRunner {
1836
2050
  runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested(childName, childTask, actor, day, depth + 1, sinkRunId), "runAgent")
1837
2051
  };
1838
2052
  try {
1839
- return await (0, import_nestjs_agent_core15.runAgentLoop)({
2053
+ return await (0, import_nestjs_agent_core16.runAgentLoop)({
1840
2054
  ...deps,
1841
2055
  day
1842
2056
  }, {
@@ -1853,84 +2067,84 @@ var InlineAgentRunner = class _InlineAgentRunner {
1853
2067
  }
1854
2068
  }
1855
2069
  };
1856
- InlineAgentRunner = _ts_decorate14([
1857
- (0, import_common14.Injectable)(),
1858
- _ts_param12(0, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_DEPS_FACTORY)),
1859
- _ts_param12(1, (0, import_common14.Inject)(import_nestjs_agent_core15.AGENT_STORE)),
1860
- _ts_metadata13("design:type", Function),
1861
- _ts_metadata13("design:paramtypes", [
2070
+ InlineAgentRunner = _ts_decorate16([
2071
+ (0, import_common16.Injectable)(),
2072
+ _ts_param13(0, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_DEPS_FACTORY)),
2073
+ _ts_param13(1, (0, import_common16.Inject)(import_nestjs_agent_core16.AGENT_STORE)),
2074
+ _ts_metadata15("design:type", Function),
2075
+ _ts_metadata15("design:paramtypes", [
1862
2076
  typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1863
2077
  typeof AgentStore === "undefined" ? Object : AgentStore
1864
2078
  ])
1865
2079
  ], InlineAgentRunner);
1866
2080
 
1867
2081
  // src/agent.module.ts
1868
- function _ts_decorate15(decorators, target, key, desc) {
2082
+ function _ts_decorate17(decorators, target, key, desc) {
1869
2083
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1870
2084
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1871
2085
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1872
2086
  return c > 3 && r && Object.defineProperty(target, key, r), r;
1873
2087
  }
1874
- __name(_ts_decorate15, "_ts_decorate");
2088
+ __name(_ts_decorate17, "_ts_decorate");
1875
2089
  var DEFAULT_PATH = "agent";
1876
2090
  function sharedProviders(durable, includeStore) {
1877
2091
  const providers = [
1878
2092
  {
1879
- provide: import_nestjs_agent_core16.AGENT_TOOL_REGISTRY,
1880
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core16.ToolRegistry(), "useFactory")
2093
+ provide: import_nestjs_agent_core17.AGENT_TOOL_REGISTRY,
2094
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core17.ToolRegistry(), "useFactory")
1881
2095
  },
1882
2096
  // Starts empty; AgentDiscoveryService populates it from `@Agent`-decorated providers at boot.
1883
2097
  {
1884
- provide: import_nestjs_agent_core16.AGENT_REGISTRY,
1885
- useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core16.AgentRegistry(), "useFactory")
2098
+ provide: import_nestjs_agent_core17.AGENT_REGISTRY,
2099
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core17.AgentRegistry(), "useFactory")
1886
2100
  },
1887
2101
  // A shared, mutable list AgentDiscoveryService fills with `@SystemPromptContributor()` methods.
1888
2102
  {
1889
- provide: import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS,
2103
+ provide: import_nestjs_agent_core17.AGENT_PROMPT_CONTRIBUTORS,
1890
2104
  useFactory: /* @__PURE__ */ __name(() => [], "useFactory")
1891
2105
  },
1892
2106
  {
1893
- provide: import_nestjs_agent_core16.AGENT_SINK,
2107
+ provide: import_nestjs_agent_core17.AGENT_SINK,
1894
2108
  useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
1895
2109
  inject: [
1896
- import_nestjs_agent_core16.AGENT_OPTIONS
2110
+ import_nestjs_agent_core17.AGENT_OPTIONS
1897
2111
  ]
1898
2112
  },
1899
2113
  {
1900
- provide: import_nestjs_agent_core16.AGENT_ROLES_POLICY,
1901
- useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core16.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
2114
+ provide: import_nestjs_agent_core17.AGENT_ROLES_POLICY,
2115
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core17.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
1902
2116
  inject: [
1903
- import_nestjs_agent_core16.AGENT_OPTIONS
2117
+ import_nestjs_agent_core17.AGENT_OPTIONS
1904
2118
  ]
1905
2119
  },
1906
2120
  {
1907
- provide: import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER,
2121
+ provide: import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER,
1908
2122
  useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
1909
2123
  inject: [
1910
- import_nestjs_agent_core16.AGENT_OPTIONS
2124
+ import_nestjs_agent_core17.AGENT_OPTIONS
1911
2125
  ]
1912
2126
  },
1913
2127
  {
1914
- provide: import_nestjs_agent_core16.AGENT_MODEL,
2128
+ provide: import_nestjs_agent_core17.AGENT_MODEL,
1915
2129
  useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
1916
2130
  inject: [
1917
- import_nestjs_agent_core16.AGENT_OPTIONS
2131
+ import_nestjs_agent_core17.AGENT_OPTIONS
1918
2132
  ]
1919
2133
  },
1920
2134
  {
1921
2135
  // An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
1922
2136
  // store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
1923
2137
  // the loop already writes, so enforcement needs no extra shared state across replicas.
1924
- provide: import_nestjs_agent_core16.AGENT_QUOTA_STORE,
2138
+ provide: import_nestjs_agent_core17.AGENT_QUOTA_STORE,
1925
2139
  useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
1926
2140
  inject: [
1927
- import_nestjs_agent_core16.AGENT_OPTIONS,
1928
- import_nestjs_agent_core16.AGENT_STORE
2141
+ import_nestjs_agent_core17.AGENT_OPTIONS,
2142
+ import_nestjs_agent_core17.AGENT_STORE
1929
2143
  ]
1930
2144
  },
1931
2145
  AgentDepsFactory2,
1932
2146
  {
1933
- provide: import_nestjs_agent_core16.AGENT_DEPS_FACTORY,
2147
+ provide: import_nestjs_agent_core17.AGENT_DEPS_FACTORY,
1934
2148
  useExisting: AgentDepsFactory2
1935
2149
  },
1936
2150
  // Populates the registry + contributors (onModuleInit) BEFORE AiToolDiscoveryService synthesizes
@@ -1938,20 +2152,27 @@ function sharedProviders(durable, includeStore) {
1938
2152
  AgentDiscoveryService,
1939
2153
  AiToolDiscoveryService,
1940
2154
  InlineAgentRunner,
1941
- AgentService
2155
+ AgentService,
2156
+ // Bound ALWAYS (durable or inline) — the console's cross-thread approvals inbox routes decisions
2157
+ // through AgentService.signalToolCall, which reaches whichever AGENT_RUNNER is bound above.
2158
+ AgentApprovalPortAdapter,
2159
+ {
2160
+ provide: import_nestjs_agent_core17.AGENT_APPROVAL_PORT,
2161
+ useExisting: AgentApprovalPortAdapter
2162
+ }
1942
2163
  ];
1943
2164
  if (includeStore) {
1944
2165
  providers.push({
1945
- provide: import_nestjs_agent_core16.AGENT_STORE,
2166
+ provide: import_nestjs_agent_core17.AGENT_STORE,
1946
2167
  useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
1947
2168
  inject: [
1948
- import_nestjs_agent_core16.AGENT_OPTIONS
2169
+ import_nestjs_agent_core17.AGENT_OPTIONS
1949
2170
  ]
1950
2171
  });
1951
2172
  }
1952
2173
  if (durable) {
1953
2174
  providers.push({
1954
- provide: import_nestjs_agent_core16.AGENT_RUNNER,
2175
+ provide: import_nestjs_agent_core17.AGENT_RUNNER,
1955
2176
  useFactory: /* @__PURE__ */ __name((durableRunner) => {
1956
2177
  if (durableRunner === void 0) {
1957
2178
  throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
@@ -1960,14 +2181,14 @@ function sharedProviders(durable, includeStore) {
1960
2181
  }, "useFactory"),
1961
2182
  inject: [
1962
2183
  {
1963
- token: import_nestjs_agent_core16.AGENT_DURABLE_RUNNER,
2184
+ token: import_nestjs_agent_core17.AGENT_DURABLE_RUNNER,
1964
2185
  optional: true
1965
2186
  }
1966
2187
  ]
1967
2188
  });
1968
2189
  } else {
1969
2190
  providers.push({
1970
- provide: import_nestjs_agent_core16.AGENT_RUNNER,
2191
+ provide: import_nestjs_agent_core17.AGENT_RUNNER,
1971
2192
  useExisting: InlineAgentRunner
1972
2193
  });
1973
2194
  }
@@ -1976,22 +2197,23 @@ function sharedProviders(durable, includeStore) {
1976
2197
  __name(sharedProviders, "sharedProviders");
1977
2198
  function exportsFor(includeStore) {
1978
2199
  return [
1979
- import_nestjs_agent_core16.AGENT_OPTIONS,
1980
- import_nestjs_agent_core16.AGENT_TOOL_REGISTRY,
1981
- import_nestjs_agent_core16.AGENT_REGISTRY,
1982
- import_nestjs_agent_core16.AGENT_SINK,
1983
- import_nestjs_agent_core16.AGENT_ROLES_POLICY,
1984
- import_nestjs_agent_core16.AGENT_ACTOR_RESOLVER,
1985
- import_nestjs_agent_core16.AGENT_MODEL,
2200
+ import_nestjs_agent_core17.AGENT_OPTIONS,
2201
+ import_nestjs_agent_core17.AGENT_TOOL_REGISTRY,
2202
+ import_nestjs_agent_core17.AGENT_REGISTRY,
2203
+ import_nestjs_agent_core17.AGENT_SINK,
2204
+ import_nestjs_agent_core17.AGENT_ROLES_POLICY,
2205
+ import_nestjs_agent_core17.AGENT_ACTOR_RESOLVER,
2206
+ import_nestjs_agent_core17.AGENT_MODEL,
1986
2207
  ...includeStore ? [
1987
- import_nestjs_agent_core16.AGENT_STORE
2208
+ import_nestjs_agent_core17.AGENT_STORE
1988
2209
  ] : [],
1989
- import_nestjs_agent_core16.AGENT_QUOTA_STORE,
1990
- import_nestjs_agent_core16.AGENT_PROMPT_CONTRIBUTORS,
1991
- import_nestjs_agent_core16.AGENT_DEPS_FACTORY,
2210
+ import_nestjs_agent_core17.AGENT_QUOTA_STORE,
2211
+ import_nestjs_agent_core17.AGENT_PROMPT_CONTRIBUTORS,
2212
+ import_nestjs_agent_core17.AGENT_DEPS_FACTORY,
1992
2213
  AgentDepsFactory2,
1993
2214
  AgentService,
1994
- InlineAgentRunner
2215
+ InlineAgentRunner,
2216
+ import_nestjs_agent_core17.AGENT_APPROVAL_PORT
1995
2217
  ];
1996
2218
  }
1997
2219
  __name(exportsFor, "exportsFor");
@@ -2036,11 +2258,18 @@ function routerFor(path) {
2036
2258
  ]);
2037
2259
  }
2038
2260
  __name(routerFor, "routerFor");
2261
+ function assertDispatchedStepsRequiresDurable(dispatchedSteps, durable) {
2262
+ if (dispatchedSteps && !durable) {
2263
+ throw new Error("AgentModule dispatchedSteps: true requires durable: true \u2014 dispatched steps are routed durable steps (AgentRunSteps.llm/tool) with no in-process equivalent.");
2264
+ }
2265
+ }
2266
+ __name(assertDispatchedStepsRequiresDurable, "assertDispatchedStepsRequiresDurable");
2039
2267
  var AgentModule = class _AgentModule {
2040
2268
  static {
2041
2269
  __name(this, "AgentModule");
2042
2270
  }
2043
2271
  static forRoot(options) {
2272
+ assertDispatchedStepsRequiresDurable(options.dispatchedSteps ?? false, options.durable ?? false);
2044
2273
  const path = options.path ?? DEFAULT_PATH;
2045
2274
  const includeStore = options.store !== void 0;
2046
2275
  applyGuards(options.guards);
@@ -2054,7 +2283,7 @@ var AgentModule = class _AgentModule {
2054
2283
  controllers: controllersFor(options.attachments?.upload === true),
2055
2284
  providers: [
2056
2285
  {
2057
- provide: import_nestjs_agent_core16.AGENT_OPTIONS,
2286
+ provide: import_nestjs_agent_core17.AGENT_OPTIONS,
2058
2287
  useValue: options
2059
2288
  },
2060
2289
  ...sharedProviders(options.durable ?? false, includeStore),
@@ -2064,6 +2293,7 @@ var AgentModule = class _AgentModule {
2064
2293
  };
2065
2294
  }
2066
2295
  static forRootAsync(options) {
2296
+ assertDispatchedStepsRequiresDurable(options.dispatchedSteps ?? false, options.durable ?? false);
2067
2297
  const path = options.path ?? DEFAULT_PATH;
2068
2298
  const includeStore = options.externalStore !== true;
2069
2299
  applyGuards(options.guards);
@@ -2078,8 +2308,18 @@ var AgentModule = class _AgentModule {
2078
2308
  controllers: controllersFor(options.attachmentsUpload === true),
2079
2309
  providers: [
2080
2310
  {
2081
- provide: import_nestjs_agent_core16.AGENT_OPTIONS,
2082
- useFactory: options.useFactory,
2311
+ provide: import_nestjs_agent_core17.AGENT_OPTIONS,
2312
+ // Stamp the STATIC wiring flags onto the factory result: `durable`/`dispatchedSteps` are
2313
+ // authoritative on the async config object (they decided the actual wiring above), and
2314
+ // `AgentDurableModule` derives the effective dispatched-steps value from AGENT_OPTIONS —
2315
+ // without this stamp, an async host would get in-process localSteps despite durable: true.
2316
+ useFactory: /* @__PURE__ */ __name(async (...args) => ({
2317
+ ...await options.useFactory(...args),
2318
+ durable: options.durable ?? false,
2319
+ ...options.dispatchedSteps !== void 0 ? {
2320
+ dispatchedSteps: options.dispatchedSteps
2321
+ } : {}
2322
+ }), "useFactory"),
2083
2323
  inject: options.inject ?? []
2084
2324
  },
2085
2325
  ...sharedProviders(options.durable ?? false, includeStore),
@@ -2089,9 +2329,9 @@ var AgentModule = class _AgentModule {
2089
2329
  };
2090
2330
  }
2091
2331
  };
2092
- AgentModule = _ts_decorate15([
2093
- (0, import_common15.Global)(),
2094
- (0, import_common15.Module)({})
2332
+ AgentModule = _ts_decorate17([
2333
+ (0, import_common17.Global)(),
2334
+ (0, import_common17.Module)({})
2095
2335
  ], AgentModule);
2096
2336
 
2097
2337
  // src/durable/agent-durable.ts
@@ -2107,7 +2347,9 @@ function agentDurable(options) {
2107
2347
  __name(agentDurable, "agentDurable");
2108
2348
  // Annotate the CommonJS export names for ESM import in node:
2109
2349
  0 && (module.exports = {
2350
+ AGENT_DISPATCHED_STEPS,
2110
2351
  AgentDurableModule,
2352
+ AgentRunSteps,
2111
2353
  AgentRunWorkflow,
2112
2354
  DurableAgentRunner,
2113
2355
  agentDurable