@dudousxd/nestjs-agent 0.1.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.
@@ -0,0 +1,1590 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/durable/index.ts
22
+ var durable_exports = {};
23
+ __export(durable_exports, {
24
+ AgentDurableModule: () => AgentDurableModule,
25
+ AgentRunWorkflow: () => AgentRunWorkflow,
26
+ DurableAgentRunner: () => DurableAgentRunner,
27
+ agentDurable: () => agentDurable
28
+ });
29
+ module.exports = __toCommonJS(durable_exports);
30
+
31
+ // 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_durable_core = require("@dudousxd/nestjs-durable-core");
35
+ var import_common = require("@nestjs/common");
36
+
37
+ // src/agent-deps.ts
38
+ function utcDay(date = /* @__PURE__ */ new Date()) {
39
+ return date.toISOString().slice(0, 10);
40
+ }
41
+ __name(utcDay, "utcDay");
42
+ function childSinkWriter(writer) {
43
+ return {
44
+ write: /* @__PURE__ */ __name((chunk) => writer.write(chunk), "write"),
45
+ end: /* @__PURE__ */ __name(async () => {
46
+ }, "end"),
47
+ fail: /* @__PURE__ */ __name(async () => {
48
+ }, "fail")
49
+ };
50
+ }
51
+ __name(childSinkWriter, "childSinkWriter");
52
+
53
+ // src/durable/agent-run.workflow.ts
54
+ function _ts_decorate(decorators, target, key, desc) {
55
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
56
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
57
+ 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;
58
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
59
+ }
60
+ __name(_ts_decorate, "_ts_decorate");
61
+ function _ts_metadata(k, v) {
62
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
63
+ }
64
+ __name(_ts_metadata, "_ts_metadata");
65
+ function _ts_param(paramIndex, decorator) {
66
+ return function(target, key) {
67
+ decorator(target, key, paramIndex);
68
+ };
69
+ }
70
+ __name(_ts_param, "_ts_param");
71
+ var AgentRunWorkflow = class _AgentRunWorkflow {
72
+ static {
73
+ __name(this, "AgentRunWorkflow");
74
+ }
75
+ factory;
76
+ store;
77
+ constructor(factory, store) {
78
+ this.factory = factory;
79
+ this.store = store;
80
+ }
81
+ async run(ctx, input) {
82
+ const day = input.day ?? utcDay();
83
+ const deps = this.factory.forAgent(input.agentName);
84
+ if (input.sinkRunId !== void 0) {
85
+ await ctx.step("activate", () => this.store.setActiveStream(input.threadId, ctx.runId));
86
+ }
87
+ const sinkRunId = input.sinkRunId ?? ctx.runId;
88
+ const hooks = {
89
+ runId: ctx.runId,
90
+ // A child forwards into the top-level sink but must not end/fail it (the top-level run owns it).
91
+ openSink: /* @__PURE__ */ __name(async () => input.sinkRunId !== void 0 ? childSinkWriter(await deps.sink.open(sinkRunId)) : deps.sink.open(ctx.runId), "openSink"),
92
+ awaitApproval: /* @__PURE__ */ __name((call) => ctx.waitForSignal(`tool:${ctx.runId}:${call.id}`), "awaitApproval"),
93
+ step: /* @__PURE__ */ __name((name, fn) => ctx.step(name, fn), "step"),
94
+ runAgent: /* @__PURE__ */ __name(async (agentName, task) => {
95
+ const subThreadId = await ctx.step(`subthread:${agentName}`, async () => {
96
+ const thread = await this.store.createThread({
97
+ actor: input.actor,
98
+ persona: "default",
99
+ transient: true
100
+ });
101
+ return thread.id;
102
+ });
103
+ return ctx.child(_AgentRunWorkflow, {
104
+ agentName,
105
+ threadId: subThreadId,
106
+ actor: input.actor,
107
+ userText: task,
108
+ day,
109
+ delegationDepth: (input.delegationDepth ?? 0) + 1,
110
+ sinkRunId
111
+ });
112
+ }, "runAgent")
113
+ };
114
+ try {
115
+ return await (0, import_nestjs_agent_core.runAgentLoop)({
116
+ ...deps,
117
+ day
118
+ }, input, hooks);
119
+ } catch (error) {
120
+ if (error instanceof import_nestjs_durable_core.WorkflowSuspended || error instanceof import_nestjs_durable_core.ContinueAsNew) {
121
+ throw error;
122
+ }
123
+ const message = error instanceof Error ? error.message : String(error);
124
+ const code = error instanceof import_nestjs_agent_core.QuotaExceededError ? "quota_exceeded" : "run_failed";
125
+ (0, import_nestjs_agent_core.publishAgentRunFailed)({
126
+ runId: ctx.runId,
127
+ code,
128
+ message
129
+ });
130
+ const writer = await hooks.openSink();
131
+ await writer.fail({
132
+ code,
133
+ message
134
+ });
135
+ throw error;
136
+ }
137
+ }
138
+ };
139
+ AgentRunWorkflow = _ts_decorate([
140
+ (0, import_common.Injectable)(),
141
+ (0, import_nestjs_durable.Workflow)({
142
+ name: "agent.run",
143
+ version: "1"
144
+ }),
145
+ _ts_param(0, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_DEPS_FACTORY)),
146
+ _ts_param(1, (0, import_common.Inject)(import_nestjs_agent_core.AGENT_STORE)),
147
+ _ts_metadata("design:type", Function),
148
+ _ts_metadata("design:paramtypes", [
149
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
150
+ typeof AgentStore === "undefined" ? Object : AgentStore
151
+ ])
152
+ ], AgentRunWorkflow);
153
+
154
+ // src/durable/durable-agent-runner.ts
155
+ var import_nestjs_durable2 = require("@dudousxd/nestjs-durable");
156
+ var import_common2 = require("@nestjs/common");
157
+ function _ts_decorate2(decorators, target, key, desc) {
158
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
159
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
160
+ 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;
161
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
162
+ }
163
+ __name(_ts_decorate2, "_ts_decorate");
164
+ function _ts_metadata2(k, v) {
165
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
166
+ }
167
+ __name(_ts_metadata2, "_ts_metadata");
168
+ var DurableAgentRunner = class {
169
+ static {
170
+ __name(this, "DurableAgentRunner");
171
+ }
172
+ workflows;
173
+ constructor(workflows) {
174
+ this.workflows = workflows;
175
+ }
176
+ async start(input) {
177
+ const stamped = {
178
+ ...input,
179
+ day: input.day ?? utcDay()
180
+ };
181
+ const result = await this.workflows.start(AgentRunWorkflow, stamped);
182
+ return {
183
+ runId: result.runId
184
+ };
185
+ }
186
+ async signal(runId, toolCallId, decision) {
187
+ await this.workflows.signal(`tool:${runId}:${toolCallId}`, decision);
188
+ }
189
+ async cancel(_runId) {
190
+ await Promise.resolve();
191
+ }
192
+ };
193
+ DurableAgentRunner = _ts_decorate2([
194
+ (0, import_common2.Injectable)(),
195
+ _ts_metadata2("design:type", Function),
196
+ _ts_metadata2("design:paramtypes", [
197
+ typeof import_nestjs_durable2.WorkflowService === "undefined" ? Object : import_nestjs_durable2.WorkflowService
198
+ ])
199
+ ], DurableAgentRunner);
200
+
201
+ // src/durable/agent-durable.module.ts
202
+ var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
203
+ var import_common3 = require("@nestjs/common");
204
+ function _ts_decorate3(decorators, target, key, desc) {
205
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
206
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
207
+ 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;
208
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
209
+ }
210
+ __name(_ts_decorate3, "_ts_decorate");
211
+ var AgentDurableModule = class _AgentDurableModule {
212
+ static {
213
+ __name(this, "AgentDurableModule");
214
+ }
215
+ /**
216
+ * The dynamic form used by the `agentDurable` helper. The module needs no configuration of its
217
+ * own (its providers come from the decorator above), so this just yields the module reference —
218
+ * importing `AgentDurableModule` directly stays equivalent.
219
+ */
220
+ static forRoot() {
221
+ return {
222
+ module: _AgentDurableModule,
223
+ global: true
224
+ };
225
+ }
226
+ };
227
+ AgentDurableModule = _ts_decorate3([
228
+ (0, import_common3.Global)(),
229
+ (0, import_common3.Module)({
230
+ providers: [
231
+ AgentRunWorkflow,
232
+ DurableAgentRunner,
233
+ {
234
+ provide: import_nestjs_agent_core2.AGENT_DURABLE_RUNNER,
235
+ useExisting: DurableAgentRunner
236
+ }
237
+ ],
238
+ exports: [
239
+ import_nestjs_agent_core2.AGENT_DURABLE_RUNNER,
240
+ AgentRunWorkflow
241
+ ]
242
+ })
243
+ ], AgentDurableModule);
244
+
245
+ // src/agent.module.ts
246
+ var import_nestjs_agent_core13 = require("@dudousxd/nestjs-agent-core");
247
+ var import_common12 = require("@nestjs/common");
248
+ var import_core2 = require("@nestjs/core");
249
+
250
+ // src/agent-deps.factory.ts
251
+ var import_nestjs_agent_core3 = require("@dudousxd/nestjs-agent-core");
252
+ var import_nestjs_agent_core4 = require("@dudousxd/nestjs-agent-core");
253
+ var import_common4 = require("@nestjs/common");
254
+ function _ts_decorate4(decorators, target, key, desc) {
255
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
256
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
257
+ 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;
258
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
259
+ }
260
+ __name(_ts_decorate4, "_ts_decorate");
261
+ function _ts_metadata3(k, v) {
262
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
263
+ }
264
+ __name(_ts_metadata3, "_ts_metadata");
265
+ function _ts_param2(paramIndex, decorator) {
266
+ return function(target, key) {
267
+ decorator(target, key, paramIndex);
268
+ };
269
+ }
270
+ __name(_ts_param2, "_ts_param");
271
+ function delegateToolName(target) {
272
+ return `ask_${target.replace(/[^a-zA-Z0-9]+/g, "_")}`;
273
+ }
274
+ __name(delegateToolName, "delegateToolName");
275
+ var AgentDepsFactory2 = class {
276
+ static {
277
+ __name(this, "AgentDepsFactory");
278
+ }
279
+ options;
280
+ model;
281
+ store;
282
+ sink;
283
+ rolesPolicy;
284
+ registry;
285
+ agents;
286
+ quota;
287
+ constructor(options, model, store, sink, rolesPolicy, registry, agents, quota) {
288
+ this.options = options;
289
+ this.model = model;
290
+ this.store = store;
291
+ this.sink = sink;
292
+ this.rolesPolicy = rolesPolicy;
293
+ this.registry = registry;
294
+ this.agents = agents;
295
+ this.quota = quota;
296
+ }
297
+ defaultAgentName() {
298
+ return this.options.defaultAgent?.name ?? "default";
299
+ }
300
+ effectiveTools(definition) {
301
+ if (definition === void 0) {
302
+ return void 0;
303
+ }
304
+ const delegated = (definition.delegatesTo ?? []).map(delegateToolName);
305
+ if (definition.tools === void 0 && delegated.length === 0) {
306
+ return void 0;
307
+ }
308
+ return [
309
+ ...definition.tools ?? [],
310
+ ...delegated
311
+ ];
312
+ }
313
+ forAgent(agentName) {
314
+ const name = agentName ?? this.defaultAgentName();
315
+ const definition = this.agents.get(name);
316
+ const personas = /* @__PURE__ */ new Map();
317
+ for (const persona of definition?.personas ?? []) {
318
+ personas.set(persona.id, persona);
319
+ }
320
+ const toolAllowList = this.effectiveTools(definition);
321
+ const followUpsCount = this.followUpsCount();
322
+ const retrieval = this.options.retrieval;
323
+ return {
324
+ model: this.model,
325
+ store: this.store,
326
+ sink: this.sink,
327
+ rolesPolicy: this.rolesPolicy,
328
+ registry: this.registry,
329
+ systemPrompt: definition?.systemPrompt ?? "You are a helpful assistant.",
330
+ maxSteps: definition?.maxSteps ?? 8,
331
+ personas,
332
+ defaultPersona: definition?.defaultPersona ?? "default",
333
+ ...definition?.modelId !== void 0 ? {
334
+ modelId: definition.modelId
335
+ } : {},
336
+ ...this.quota !== void 0 ? {
337
+ quota: this.quota
338
+ } : {},
339
+ ...toolAllowList !== void 0 ? {
340
+ toolAllowList
341
+ } : {},
342
+ ...this.options.toolTimeoutMs !== void 0 ? {
343
+ toolTimeoutMs: this.options.toolTimeoutMs
344
+ } : {},
345
+ ...followUpsCount !== void 0 ? {
346
+ followUpsCount
347
+ } : {},
348
+ ...retrieval?.mode === "inject" ? {
349
+ retriever: retrieval.retriever,
350
+ ...retrieval.topK !== void 0 ? {
351
+ retrievalTopK: retrieval.topK
352
+ } : {}
353
+ } : {}
354
+ };
355
+ }
356
+ /** Normalize the `followUps` option (`true` → 3, `{ count }` → count) to a number, or undefined. */
357
+ followUpsCount() {
358
+ const followUps = this.options.followUps;
359
+ if (followUps === true) {
360
+ return 3;
361
+ }
362
+ if (typeof followUps === "object") {
363
+ return followUps.count;
364
+ }
365
+ return void 0;
366
+ }
367
+ };
368
+ AgentDepsFactory2 = _ts_decorate4([
369
+ (0, import_common4.Injectable)(),
370
+ _ts_param2(0, (0, import_common4.Inject)(import_nestjs_agent_core4.AGENT_OPTIONS)),
371
+ _ts_param2(1, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_MODEL)),
372
+ _ts_param2(2, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_STORE)),
373
+ _ts_param2(3, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_SINK)),
374
+ _ts_param2(4, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_ROLES_POLICY)),
375
+ _ts_param2(5, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_TOOL_REGISTRY)),
376
+ _ts_param2(6, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_REGISTRY)),
377
+ _ts_param2(7, (0, import_common4.Inject)(import_nestjs_agent_core3.AGENT_QUOTA_STORE)),
378
+ _ts_metadata3("design:type", Function),
379
+ _ts_metadata3("design:paramtypes", [
380
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions,
381
+ typeof ModelProvider === "undefined" ? Object : ModelProvider,
382
+ typeof AgentStore === "undefined" ? Object : AgentStore,
383
+ typeof TokenStreamSink === "undefined" ? Object : TokenStreamSink,
384
+ typeof RolesPolicy === "undefined" ? Object : RolesPolicy,
385
+ typeof import_nestjs_agent_core3.ToolRegistry === "undefined" ? Object : import_nestjs_agent_core3.ToolRegistry,
386
+ typeof import_nestjs_agent_core3.AgentRegistry === "undefined" ? Object : import_nestjs_agent_core3.AgentRegistry,
387
+ Object
388
+ ])
389
+ ], AgentDepsFactory2);
390
+
391
+ // src/agent.service.ts
392
+ var import_nestjs_agent_core5 = require("@dudousxd/nestjs-agent-core");
393
+ var import_common5 = require("@nestjs/common");
394
+ function _ts_decorate5(decorators, target, key, desc) {
395
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
396
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
397
+ 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;
398
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
399
+ }
400
+ __name(_ts_decorate5, "_ts_decorate");
401
+ function _ts_metadata4(k, v) {
402
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
403
+ }
404
+ __name(_ts_metadata4, "_ts_metadata");
405
+ function _ts_param3(paramIndex, decorator) {
406
+ return function(target, key) {
407
+ decorator(target, key, paramIndex);
408
+ };
409
+ }
410
+ __name(_ts_param3, "_ts_param");
411
+ var AgentService = class {
412
+ static {
413
+ __name(this, "AgentService");
414
+ }
415
+ runner;
416
+ store;
417
+ deps;
418
+ constructor(runner, store, deps) {
419
+ this.runner = runner;
420
+ this.store = store;
421
+ this.deps = deps;
422
+ }
423
+ async chat(params) {
424
+ const agentName = params.agentName ?? this.deps.defaultAgentName();
425
+ let threadId = params.threadId;
426
+ if (threadId === void 0) {
427
+ if (params.regenerate === true) {
428
+ throw new import_common5.BadRequestException("regenerate requires an existing threadId");
429
+ }
430
+ const created = await this.store.createThread({
431
+ actor: params.actor,
432
+ persona: params.personaId ?? this.deps.forAgent(agentName).defaultPersona
433
+ });
434
+ threadId = created.id;
435
+ } else if (params.regenerate === true) {
436
+ await this.assertOwnsThread(params.actor, threadId);
437
+ }
438
+ const persona = this.resolvePersona(agentName, params.personaId);
439
+ const input = {
440
+ threadId,
441
+ actor: params.actor,
442
+ userText: params.message,
443
+ day: utcDay(),
444
+ agentName,
445
+ ...params.regenerate === true ? {
446
+ regenerate: true
447
+ } : {},
448
+ ...persona !== void 0 ? {
449
+ persona
450
+ } : {},
451
+ ...params.pageContext !== void 0 ? {
452
+ pageContext: params.pageContext
453
+ } : {}
454
+ };
455
+ const { runId } = await this.runner.start(input);
456
+ await this.store.setActiveStream(threadId, runId);
457
+ return {
458
+ runId,
459
+ threadId
460
+ };
461
+ }
462
+ subscribe(runId) {
463
+ return this.deps.forAgent().sink.subscribe(runId);
464
+ }
465
+ async approve(actor, toolCallId) {
466
+ const runId = await this.runForOwnedToolCall(actor, toolCallId);
467
+ return this.runner.signal(runId, toolCallId, {
468
+ approved: true
469
+ });
470
+ }
471
+ async reject(actor, toolCallId, reason) {
472
+ const runId = await this.runForOwnedToolCall(actor, toolCallId);
473
+ return this.runner.signal(runId, toolCallId, {
474
+ approved: false,
475
+ ...reason !== void 0 ? {
476
+ reason
477
+ } : {}
478
+ });
479
+ }
480
+ async cancel(actor, runId) {
481
+ await this.assertOwnsActiveStream(actor, runId);
482
+ return this.runner.cancel(runId);
483
+ }
484
+ resolvePersona(agentName, id) {
485
+ const deps = this.deps.forAgent(agentName);
486
+ return deps.personas.get(id ?? deps.defaultPersona);
487
+ }
488
+ personaCatalog(agentName) {
489
+ return [
490
+ ...this.deps.forAgent(agentName).personas.values()
491
+ ].map((persona) => ({
492
+ id: persona.id,
493
+ label: persona.label
494
+ }));
495
+ }
496
+ listThreads(actorRef) {
497
+ return this.store.listThreads(actorRef);
498
+ }
499
+ async getThread(actor, threadId) {
500
+ await this.assertOwnsThread(actor, threadId);
501
+ return this.store.getThread(threadId);
502
+ }
503
+ async deleteThread(actor, threadId) {
504
+ await this.assertOwnsThread(actor, threadId);
505
+ return this.store.softDeleteThread(threadId);
506
+ }
507
+ async forkThread(actor, threadId, fromMessageId) {
508
+ await this.assertOwnsThread(actor, threadId);
509
+ return this.store.forkThread(threadId, fromMessageId);
510
+ }
511
+ async quotaToday(actorRef) {
512
+ return this.store.quotaToday(actorRef, utcDay());
513
+ }
514
+ /**
515
+ * Authorization seam for thread-scoped endpoints: the caller must own the thread. A missing
516
+ * thread is a 404; someone else's thread is a 403 — one actor never touches another's thread.
517
+ */
518
+ async assertOwnsThread(actor, threadId) {
519
+ const owner = await this.store.ownerOfThread(threadId);
520
+ if (owner === null) {
521
+ throw new import_common5.NotFoundException(`thread ${threadId} not found`);
522
+ }
523
+ if (owner !== actor.id) {
524
+ throw new import_common5.ForbiddenException("thread belongs to another actor");
525
+ }
526
+ }
527
+ /**
528
+ * Authorization + routing seam for HITL approve/reject: assert the caller owns the tool call's
529
+ * thread, then resolve the run currently awaiting that call (its thread's active stream). That run
530
+ * is the sub-agent's own child run when the pending call belongs to a delegated agent — the client
531
+ * never knows or supplies a runId; it is derived here from the tool call alone.
532
+ */
533
+ async runForOwnedToolCall(actor, toolCallId) {
534
+ const owner = await this.store.ownerOfToolCall(toolCallId);
535
+ if (owner === null) {
536
+ throw new import_common5.NotFoundException(`tool call ${toolCallId} not found`);
537
+ }
538
+ if (owner !== actor.id) {
539
+ throw new import_common5.ForbiddenException("tool call belongs to another actor");
540
+ }
541
+ const runId = await this.store.runForToolCall(toolCallId);
542
+ if (runId === null) {
543
+ throw new import_common5.NotFoundException(`tool call ${toolCallId} has no active run to signal`);
544
+ }
545
+ return runId;
546
+ }
547
+ /** Authorization seam for `cancel`: the caller must own the thread currently streaming this run. */
548
+ async assertOwnsActiveStream(actor, runId) {
549
+ const owner = await this.store.ownerOfActiveStream(runId);
550
+ if (owner === null) {
551
+ throw new import_common5.NotFoundException(`no active run ${runId}`);
552
+ }
553
+ if (owner !== actor.id) {
554
+ throw new import_common5.ForbiddenException("run belongs to another actor");
555
+ }
556
+ }
557
+ };
558
+ AgentService = _ts_decorate5([
559
+ (0, import_common5.Injectable)(),
560
+ _ts_param3(0, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_RUNNER)),
561
+ _ts_param3(1, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_STORE)),
562
+ _ts_param3(2, (0, import_common5.Inject)(import_nestjs_agent_core5.AGENT_DEPS_FACTORY)),
563
+ _ts_metadata4("design:type", Function),
564
+ _ts_metadata4("design:paramtypes", [
565
+ typeof AgentRunner === "undefined" ? Object : AgentRunner,
566
+ typeof AgentStore === "undefined" ? Object : AgentStore,
567
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory
568
+ ])
569
+ ], AgentService);
570
+
571
+ // src/controller/chat.controller.ts
572
+ var import_nestjs_agent_core6 = require("@dudousxd/nestjs-agent-core");
573
+ var import_common6 = require("@nestjs/common");
574
+ function _ts_decorate6(decorators, target, key, desc) {
575
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
576
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
577
+ 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;
578
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
579
+ }
580
+ __name(_ts_decorate6, "_ts_decorate");
581
+ function _ts_metadata5(k, v) {
582
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
583
+ }
584
+ __name(_ts_metadata5, "_ts_metadata");
585
+ function _ts_param4(paramIndex, decorator) {
586
+ return function(target, key) {
587
+ decorator(target, key, paramIndex);
588
+ };
589
+ }
590
+ __name(_ts_param4, "_ts_param");
591
+ var ChatController = class {
592
+ static {
593
+ __name(this, "ChatController");
594
+ }
595
+ agent;
596
+ actorResolver;
597
+ constructor(agent, actorResolver) {
598
+ this.agent = agent;
599
+ this.actorResolver = actorResolver;
600
+ }
601
+ async chat(req, res, body) {
602
+ const actor = await this.actorResolver.resolve(req);
603
+ const { runId, threadId } = await this.agent.chat({
604
+ actor,
605
+ message: body.message,
606
+ ...body.threadId !== void 0 ? {
607
+ threadId: body.threadId
608
+ } : {},
609
+ ...body.agent !== void 0 ? {
610
+ agentName: body.agent
611
+ } : {},
612
+ ...body.persona !== void 0 ? {
613
+ personaId: body.persona
614
+ } : {},
615
+ ...body.pageContext !== void 0 ? {
616
+ pageContext: body.pageContext
617
+ } : {},
618
+ ...body.regenerate === true ? {
619
+ regenerate: true
620
+ } : {}
621
+ });
622
+ await this.pipe(res, runId, threadId);
623
+ }
624
+ async stream(runId, res) {
625
+ await this.pipe(res, runId);
626
+ }
627
+ async cancel(req, runId) {
628
+ const actor = await this.actorResolver.resolve(req);
629
+ await this.agent.cancel(actor, runId);
630
+ return {
631
+ aborted: true
632
+ };
633
+ }
634
+ async pipe(res, runId, threadId) {
635
+ res.setHeader("Content-Type", "text/event-stream");
636
+ res.setHeader("Cache-Control", "no-cache");
637
+ res.setHeader("Connection", "keep-alive");
638
+ res.setHeader("X-Agent-Run-Id", runId);
639
+ if (threadId !== void 0) {
640
+ res.setHeader("X-Agent-Thread-Id", threadId);
641
+ }
642
+ res.write(`event: meta
643
+ data: ${JSON.stringify({
644
+ runId,
645
+ threadId
646
+ })}
647
+
648
+ `);
649
+ const decoder = new TextDecoder();
650
+ try {
651
+ for await (const chunk of this.agent.subscribe(runId)) {
652
+ res.write(`data: ${JSON.stringify({
653
+ delta: decoder.decode(chunk)
654
+ })}
655
+
656
+ `);
657
+ }
658
+ res.write("event: done\ndata: {}\n\n");
659
+ } catch (error) {
660
+ const payload = error instanceof import_nestjs_agent_core6.AgentStreamError ? {
661
+ code: error.code,
662
+ message: error.message
663
+ } : {
664
+ code: "run_failed",
665
+ message: error instanceof Error ? error.message : "stream error"
666
+ };
667
+ res.write(`event: error
668
+ data: ${JSON.stringify(payload)}
669
+
670
+ `);
671
+ }
672
+ res.end();
673
+ }
674
+ };
675
+ _ts_decorate6([
676
+ (0, import_common6.Post)("chat"),
677
+ _ts_param4(0, (0, import_common6.Req)()),
678
+ _ts_param4(1, (0, import_common6.Res)()),
679
+ _ts_param4(2, (0, import_common6.Body)()),
680
+ _ts_metadata5("design:type", Function),
681
+ _ts_metadata5("design:paramtypes", [
682
+ typeof Request === "undefined" ? Object : Request,
683
+ typeof Response === "undefined" ? Object : Response,
684
+ typeof ChatBody === "undefined" ? Object : ChatBody
685
+ ]),
686
+ _ts_metadata5("design:returntype", Promise)
687
+ ], ChatController.prototype, "chat", null);
688
+ _ts_decorate6([
689
+ (0, import_common6.Get)("chat/:runId/stream"),
690
+ _ts_param4(0, (0, import_common6.Param)("runId")),
691
+ _ts_param4(1, (0, import_common6.Res)()),
692
+ _ts_metadata5("design:type", Function),
693
+ _ts_metadata5("design:paramtypes", [
694
+ String,
695
+ typeof Response === "undefined" ? Object : Response
696
+ ]),
697
+ _ts_metadata5("design:returntype", Promise)
698
+ ], ChatController.prototype, "stream", null);
699
+ _ts_decorate6([
700
+ (0, import_common6.Post)("chat/:runId/cancel"),
701
+ _ts_param4(0, (0, import_common6.Req)()),
702
+ _ts_param4(1, (0, import_common6.Param)("runId")),
703
+ _ts_metadata5("design:type", Function),
704
+ _ts_metadata5("design:paramtypes", [
705
+ typeof Request === "undefined" ? Object : Request,
706
+ String
707
+ ]),
708
+ _ts_metadata5("design:returntype", Promise)
709
+ ], ChatController.prototype, "cancel", null);
710
+ ChatController = _ts_decorate6([
711
+ (0, import_common6.Controller)(),
712
+ _ts_param4(1, (0, import_common6.Inject)(import_nestjs_agent_core6.AGENT_ACTOR_RESOLVER)),
713
+ _ts_metadata5("design:type", Function),
714
+ _ts_metadata5("design:paramtypes", [
715
+ typeof AgentService === "undefined" ? Object : AgentService,
716
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
717
+ ])
718
+ ], ChatController);
719
+
720
+ // src/controller/quota.controller.ts
721
+ var import_nestjs_agent_core7 = require("@dudousxd/nestjs-agent-core");
722
+ var import_common7 = require("@nestjs/common");
723
+ function _ts_decorate7(decorators, target, key, desc) {
724
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
725
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
726
+ 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;
727
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
728
+ }
729
+ __name(_ts_decorate7, "_ts_decorate");
730
+ function _ts_metadata6(k, v) {
731
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
732
+ }
733
+ __name(_ts_metadata6, "_ts_metadata");
734
+ function _ts_param5(paramIndex, decorator) {
735
+ return function(target, key) {
736
+ decorator(target, key, paramIndex);
737
+ };
738
+ }
739
+ __name(_ts_param5, "_ts_param");
740
+ var QuotaController = class {
741
+ static {
742
+ __name(this, "QuotaController");
743
+ }
744
+ agent;
745
+ actorResolver;
746
+ constructor(agent, actorResolver) {
747
+ this.agent = agent;
748
+ this.actorResolver = actorResolver;
749
+ }
750
+ async today(req) {
751
+ const actor = await this.actorResolver.resolve(req);
752
+ return this.agent.quotaToday(actor.id);
753
+ }
754
+ };
755
+ _ts_decorate7([
756
+ (0, import_common7.Get)("today"),
757
+ _ts_param5(0, (0, import_common7.Req)()),
758
+ _ts_metadata6("design:type", Function),
759
+ _ts_metadata6("design:paramtypes", [
760
+ typeof Request === "undefined" ? Object : Request
761
+ ]),
762
+ _ts_metadata6("design:returntype", Promise)
763
+ ], QuotaController.prototype, "today", null);
764
+ QuotaController = _ts_decorate7([
765
+ (0, import_common7.Controller)("quota"),
766
+ _ts_param5(1, (0, import_common7.Inject)(import_nestjs_agent_core7.AGENT_ACTOR_RESOLVER)),
767
+ _ts_metadata6("design:type", Function),
768
+ _ts_metadata6("design:paramtypes", [
769
+ typeof AgentService === "undefined" ? Object : AgentService,
770
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
771
+ ])
772
+ ], QuotaController);
773
+
774
+ // src/controller/threads.controller.ts
775
+ var import_nestjs_agent_core8 = require("@dudousxd/nestjs-agent-core");
776
+ var import_common8 = require("@nestjs/common");
777
+ function _ts_decorate8(decorators, target, key, desc) {
778
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
779
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
780
+ 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;
781
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
782
+ }
783
+ __name(_ts_decorate8, "_ts_decorate");
784
+ function _ts_metadata7(k, v) {
785
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
786
+ }
787
+ __name(_ts_metadata7, "_ts_metadata");
788
+ function _ts_param6(paramIndex, decorator) {
789
+ return function(target, key) {
790
+ decorator(target, key, paramIndex);
791
+ };
792
+ }
793
+ __name(_ts_param6, "_ts_param");
794
+ var ThreadsController = class {
795
+ static {
796
+ __name(this, "ThreadsController");
797
+ }
798
+ agent;
799
+ actorResolver;
800
+ constructor(agent, actorResolver) {
801
+ this.agent = agent;
802
+ this.actorResolver = actorResolver;
803
+ }
804
+ async list(req) {
805
+ const actor = await this.actorResolver.resolve(req);
806
+ return this.agent.listThreads(actor.id);
807
+ }
808
+ personas() {
809
+ return this.agent.personaCatalog();
810
+ }
811
+ async detail(req, id) {
812
+ const actor = await this.actorResolver.resolve(req);
813
+ return this.agent.getThread(actor, id);
814
+ }
815
+ async remove(req, id) {
816
+ const actor = await this.actorResolver.resolve(req);
817
+ await this.agent.deleteThread(actor, id);
818
+ return {
819
+ ok: true
820
+ };
821
+ }
822
+ async fork(req, id, messageId) {
823
+ const actor = await this.actorResolver.resolve(req);
824
+ return this.agent.forkThread(actor, id, messageId);
825
+ }
826
+ };
827
+ _ts_decorate8([
828
+ (0, import_common8.Get)(),
829
+ _ts_param6(0, (0, import_common8.Req)()),
830
+ _ts_metadata7("design:type", Function),
831
+ _ts_metadata7("design:paramtypes", [
832
+ typeof Request === "undefined" ? Object : Request
833
+ ]),
834
+ _ts_metadata7("design:returntype", Promise)
835
+ ], ThreadsController.prototype, "list", null);
836
+ _ts_decorate8([
837
+ (0, import_common8.Get)("personas/catalog"),
838
+ _ts_metadata7("design:type", Function),
839
+ _ts_metadata7("design:paramtypes", []),
840
+ _ts_metadata7("design:returntype", void 0)
841
+ ], ThreadsController.prototype, "personas", null);
842
+ _ts_decorate8([
843
+ (0, import_common8.Get)(":id"),
844
+ _ts_param6(0, (0, import_common8.Req)()),
845
+ _ts_param6(1, (0, import_common8.Param)("id")),
846
+ _ts_metadata7("design:type", Function),
847
+ _ts_metadata7("design:paramtypes", [
848
+ typeof Request === "undefined" ? Object : Request,
849
+ String
850
+ ]),
851
+ _ts_metadata7("design:returntype", Promise)
852
+ ], ThreadsController.prototype, "detail", null);
853
+ _ts_decorate8([
854
+ (0, import_common8.Delete)(":id"),
855
+ _ts_param6(0, (0, import_common8.Req)()),
856
+ _ts_param6(1, (0, import_common8.Param)("id")),
857
+ _ts_metadata7("design:type", Function),
858
+ _ts_metadata7("design:paramtypes", [
859
+ typeof Request === "undefined" ? Object : Request,
860
+ String
861
+ ]),
862
+ _ts_metadata7("design:returntype", Promise)
863
+ ], ThreadsController.prototype, "remove", null);
864
+ _ts_decorate8([
865
+ (0, import_common8.Post)(":id/fork-from/:messageId"),
866
+ _ts_param6(0, (0, import_common8.Req)()),
867
+ _ts_param6(1, (0, import_common8.Param)("id")),
868
+ _ts_param6(2, (0, import_common8.Param)("messageId")),
869
+ _ts_metadata7("design:type", Function),
870
+ _ts_metadata7("design:paramtypes", [
871
+ typeof Request === "undefined" ? Object : Request,
872
+ String,
873
+ String
874
+ ]),
875
+ _ts_metadata7("design:returntype", Promise)
876
+ ], ThreadsController.prototype, "fork", null);
877
+ ThreadsController = _ts_decorate8([
878
+ (0, import_common8.Controller)("threads"),
879
+ _ts_param6(1, (0, import_common8.Inject)(import_nestjs_agent_core8.AGENT_ACTOR_RESOLVER)),
880
+ _ts_metadata7("design:type", Function),
881
+ _ts_metadata7("design:paramtypes", [
882
+ typeof AgentService === "undefined" ? Object : AgentService,
883
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
884
+ ])
885
+ ], ThreadsController);
886
+
887
+ // src/controller/tool-call.controller.ts
888
+ var import_nestjs_agent_core9 = require("@dudousxd/nestjs-agent-core");
889
+ var import_common9 = require("@nestjs/common");
890
+ function _ts_decorate9(decorators, target, key, desc) {
891
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
892
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
893
+ 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;
894
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
895
+ }
896
+ __name(_ts_decorate9, "_ts_decorate");
897
+ function _ts_metadata8(k, v) {
898
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
899
+ }
900
+ __name(_ts_metadata8, "_ts_metadata");
901
+ function _ts_param7(paramIndex, decorator) {
902
+ return function(target, key) {
903
+ decorator(target, key, paramIndex);
904
+ };
905
+ }
906
+ __name(_ts_param7, "_ts_param");
907
+ var ToolCallController = class {
908
+ static {
909
+ __name(this, "ToolCallController");
910
+ }
911
+ agent;
912
+ actorResolver;
913
+ constructor(agent, actorResolver) {
914
+ this.agent = agent;
915
+ this.actorResolver = actorResolver;
916
+ }
917
+ async approve(req, body) {
918
+ const actor = await this.actorResolver.resolve(req);
919
+ await this.agent.approve(actor, body.toolCallId);
920
+ return {
921
+ ok: true
922
+ };
923
+ }
924
+ async reject(req, body) {
925
+ const actor = await this.actorResolver.resolve(req);
926
+ await this.agent.reject(actor, body.toolCallId, body.reason);
927
+ return {
928
+ ok: true
929
+ };
930
+ }
931
+ };
932
+ _ts_decorate9([
933
+ (0, import_common9.Post)("approve"),
934
+ _ts_param7(0, (0, import_common9.Req)()),
935
+ _ts_param7(1, (0, import_common9.Body)()),
936
+ _ts_metadata8("design:type", Function),
937
+ _ts_metadata8("design:paramtypes", [
938
+ typeof Request === "undefined" ? Object : Request,
939
+ typeof ApproveBody === "undefined" ? Object : ApproveBody
940
+ ]),
941
+ _ts_metadata8("design:returntype", Promise)
942
+ ], ToolCallController.prototype, "approve", null);
943
+ _ts_decorate9([
944
+ (0, import_common9.Post)("reject"),
945
+ _ts_param7(0, (0, import_common9.Req)()),
946
+ _ts_param7(1, (0, import_common9.Body)()),
947
+ _ts_metadata8("design:type", Function),
948
+ _ts_metadata8("design:paramtypes", [
949
+ typeof Request === "undefined" ? Object : Request,
950
+ typeof RejectBody === "undefined" ? Object : RejectBody
951
+ ]),
952
+ _ts_metadata8("design:returntype", Promise)
953
+ ], ToolCallController.prototype, "reject", null);
954
+ ToolCallController = _ts_decorate9([
955
+ (0, import_common9.Controller)("tool-call"),
956
+ _ts_param7(1, (0, import_common9.Inject)(import_nestjs_agent_core9.AGENT_ACTOR_RESOLVER)),
957
+ _ts_metadata8("design:type", Function),
958
+ _ts_metadata8("design:paramtypes", [
959
+ typeof AgentService === "undefined" ? Object : AgentService,
960
+ typeof ActorResolver === "undefined" ? Object : ActorResolver
961
+ ])
962
+ ], ToolCallController);
963
+
964
+ // src/discovery/ai-tool-discovery.service.ts
965
+ var import_nestjs_agent_core10 = require("@dudousxd/nestjs-agent-core");
966
+ var import_common10 = require("@nestjs/common");
967
+ var import_core = require("@nestjs/core");
968
+ var import_zod = require("zod");
969
+
970
+ // src/decorator/ai-tool.decorator.ts
971
+ var import_reflect_metadata = require("reflect-metadata");
972
+ var AI_TOOL_METADATA = Symbol("nestjs-agent:ai-tool");
973
+ function readAiToolMetadata(target) {
974
+ return Reflect.getMetadata(AI_TOOL_METADATA, target.constructor);
975
+ }
976
+ __name(readAiToolMetadata, "readAiToolMetadata");
977
+
978
+ // src/functional-tool.ts
979
+ var AGENT_TOOL_BRAND = Symbol.for("@dudousxd/nestjs-agent:functional-tool");
980
+ function isBrandedFunctionalTool(value) {
981
+ return AGENT_TOOL_BRAND in value && "spec" in value && "handler" in value;
982
+ }
983
+ __name(isBrandedFunctionalTool, "isBrandedFunctionalTool");
984
+
985
+ // src/discovery/ai-tool-discovery.service.ts
986
+ function _ts_decorate10(decorators, target, key, desc) {
987
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
988
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
989
+ 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;
990
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
991
+ }
992
+ __name(_ts_decorate10, "_ts_decorate");
993
+ function _ts_metadata9(k, v) {
994
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
995
+ }
996
+ __name(_ts_metadata9, "_ts_metadata");
997
+ function _ts_param8(paramIndex, decorator) {
998
+ return function(target, key) {
999
+ decorator(target, key, paramIndex);
1000
+ };
1001
+ }
1002
+ __name(_ts_param8, "_ts_param");
1003
+ var AiToolDiscoveryService = class _AiToolDiscoveryService {
1004
+ static {
1005
+ __name(this, "AiToolDiscoveryService");
1006
+ }
1007
+ discovery;
1008
+ registry;
1009
+ agents;
1010
+ options;
1011
+ logger = new import_common10.Logger(_AiToolDiscoveryService.name);
1012
+ constructor(discovery, registry, agents, options) {
1013
+ this.discovery = discovery;
1014
+ this.registry = registry;
1015
+ this.agents = agents;
1016
+ this.options = options;
1017
+ }
1018
+ onApplicationBootstrap() {
1019
+ let count = 0;
1020
+ let functional = 0;
1021
+ for (const wrapper of this.discovery.getProviders()) {
1022
+ const instance = wrapper.instance;
1023
+ if (instance === null || instance === void 0 || typeof instance !== "object") {
1024
+ continue;
1025
+ }
1026
+ if (isBrandedFunctionalTool(instance)) {
1027
+ if (this.registerFunctionalTool(instance)) {
1028
+ functional += 1;
1029
+ }
1030
+ continue;
1031
+ }
1032
+ const meta = readAiToolMetadata(instance);
1033
+ if (meta === void 0) {
1034
+ continue;
1035
+ }
1036
+ const handler = instance;
1037
+ if (typeof handler.execute !== "function") {
1038
+ this.logger.warn(`@AiTool "${meta.name}" has no execute() method \u2014 skipped`);
1039
+ continue;
1040
+ }
1041
+ this.registry.register({
1042
+ name: meta.name,
1043
+ kind: meta.kind,
1044
+ description: meta.description,
1045
+ inputSchema: meta.input,
1046
+ // Leave roles unset when the tool didn't declare any — the RolesPolicy owns the default
1047
+ // (its `defaultRoles`). Baking it in here too would leak it into custom policies.
1048
+ ...meta.roles !== void 0 ? {
1049
+ roles: meta.roles
1050
+ } : {},
1051
+ ...meta.ability !== void 0 ? {
1052
+ ability: meta.ability
1053
+ } : {}
1054
+ }, {
1055
+ execute: /* @__PURE__ */ __name((input, ctx) => instance.execute(input, ctx), "execute")
1056
+ });
1057
+ count += 1;
1058
+ }
1059
+ for (const tool of this.options.tools ?? []) {
1060
+ if (this.registerFunctionalTool(tool)) {
1061
+ functional += 1;
1062
+ }
1063
+ }
1064
+ let delegates = 0;
1065
+ for (const definition of this.agents.list()) {
1066
+ for (const target of definition.delegatesTo ?? []) {
1067
+ const targetDefinition = this.agents.get(target);
1068
+ if (targetDefinition === void 0) {
1069
+ throw new Error(`Agent "${definition.name}" delegatesTo "${target}", which is not a registered agent. Register it via AgentModule.forFeature([...]) or fix the name.`);
1070
+ }
1071
+ const name = delegateToolName(target);
1072
+ if (this.registry.has(name)) {
1073
+ continue;
1074
+ }
1075
+ const targetBlurb = typeof targetDefinition.systemPrompt === "string" ? ` It is: ${targetDefinition.systemPrompt}` : "";
1076
+ this.registry.register(
1077
+ {
1078
+ name,
1079
+ kind: "agent",
1080
+ targetAgent: target,
1081
+ description: `Delegate a task to the "${target}" agent and get its answer.${targetBlurb}`,
1082
+ inputSchema: import_zod.z.object({
1083
+ task: import_zod.z.string()
1084
+ })
1085
+ },
1086
+ // Loop-handled (kind 'agent'); the handler is never called.
1087
+ {
1088
+ execute: /* @__PURE__ */ __name(async () => ({}), "execute")
1089
+ }
1090
+ );
1091
+ delegates += 1;
1092
+ }
1093
+ }
1094
+ this.logger.log(`registered ${count} AI tool(s), ${functional} functional tool(s) and ${delegates} delegate tool(s)`);
1095
+ }
1096
+ /**
1097
+ * Registers a functional tool's `{ spec, handler }`, skipping it if a tool of the same name is
1098
+ * already registered. Returns whether it was newly registered.
1099
+ */
1100
+ registerFunctionalTool(tool) {
1101
+ if (this.registry.has(tool.spec.name)) {
1102
+ this.logger.warn(`functional tool "${tool.spec.name}" duplicates a registered name \u2014 skipped`);
1103
+ return false;
1104
+ }
1105
+ this.registry.register(tool.spec, tool.handler);
1106
+ return true;
1107
+ }
1108
+ };
1109
+ AiToolDiscoveryService = _ts_decorate10([
1110
+ (0, import_common10.Injectable)(),
1111
+ _ts_param8(1, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_TOOL_REGISTRY)),
1112
+ _ts_param8(2, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_REGISTRY)),
1113
+ _ts_param8(3, (0, import_common10.Inject)(import_nestjs_agent_core10.AGENT_OPTIONS)),
1114
+ _ts_metadata9("design:type", Function),
1115
+ _ts_metadata9("design:paramtypes", [
1116
+ typeof import_core.DiscoveryService === "undefined" ? Object : import_core.DiscoveryService,
1117
+ typeof ToolRegistry === "undefined" ? Object : ToolRegistry,
1118
+ typeof AgentRegistry === "undefined" ? Object : AgentRegistry,
1119
+ typeof AgentModuleOptions === "undefined" ? Object : AgentModuleOptions
1120
+ ])
1121
+ ], AiToolDiscoveryService);
1122
+
1123
+ // src/in-process-sink.ts
1124
+ var import_nestjs_agent_core11 = require("@dudousxd/nestjs-agent-core");
1125
+ var InProcessTokenStreamSink = class {
1126
+ static {
1127
+ __name(this, "InProcessTokenStreamSink");
1128
+ }
1129
+ runs = /* @__PURE__ */ new Map();
1130
+ buffer(runId) {
1131
+ let buf = this.runs.get(runId);
1132
+ if (buf === void 0) {
1133
+ buf = {
1134
+ chunks: [],
1135
+ ended: false,
1136
+ notify: /* @__PURE__ */ new Set()
1137
+ };
1138
+ this.runs.set(runId, buf);
1139
+ }
1140
+ return buf;
1141
+ }
1142
+ wake(buf) {
1143
+ for (const resolve of buf.notify) {
1144
+ resolve();
1145
+ }
1146
+ buf.notify.clear();
1147
+ }
1148
+ open(runId) {
1149
+ const buf = this.buffer(runId);
1150
+ return {
1151
+ write: /* @__PURE__ */ __name((chunk) => {
1152
+ buf.chunks.push(chunk);
1153
+ this.wake(buf);
1154
+ }, "write"),
1155
+ end: /* @__PURE__ */ __name(() => {
1156
+ buf.ended = true;
1157
+ this.wake(buf);
1158
+ }, "end"),
1159
+ fail: /* @__PURE__ */ __name((error) => {
1160
+ buf.failure = error;
1161
+ buf.ended = true;
1162
+ this.wake(buf);
1163
+ }, "fail")
1164
+ };
1165
+ }
1166
+ async *subscribe(runId) {
1167
+ const buf = this.buffer(runId);
1168
+ let index = 0;
1169
+ while (true) {
1170
+ while (index < buf.chunks.length) {
1171
+ const chunk = buf.chunks[index];
1172
+ index += 1;
1173
+ if (chunk !== void 0) {
1174
+ yield chunk;
1175
+ }
1176
+ }
1177
+ if (buf.ended) {
1178
+ if (buf.failure !== void 0) {
1179
+ throw new import_nestjs_agent_core11.AgentStreamError(buf.failure);
1180
+ }
1181
+ return;
1182
+ }
1183
+ await new Promise((resolve) => buf.notify.add(resolve));
1184
+ }
1185
+ }
1186
+ close(runId) {
1187
+ this.runs.delete(runId);
1188
+ }
1189
+ };
1190
+
1191
+ // src/ledger-quota-store.ts
1192
+ var LedgerQuotaStore = class {
1193
+ static {
1194
+ __name(this, "LedgerQuotaStore");
1195
+ }
1196
+ store;
1197
+ limitTokens;
1198
+ constructor(store, limitTokens) {
1199
+ this.store = store;
1200
+ this.limitTokens = limitTokens;
1201
+ }
1202
+ async check(actorRef, day) {
1203
+ const { usedTokens } = await this.store.quotaToday(actorRef, day);
1204
+ return {
1205
+ usedTokens,
1206
+ limitTokens: this.limitTokens,
1207
+ withinLimit: usedTokens < this.limitTokens
1208
+ };
1209
+ }
1210
+ async bump() {
1211
+ }
1212
+ };
1213
+
1214
+ // src/runner/inline-agent-runner.ts
1215
+ var import_nestjs_agent_core12 = require("@dudousxd/nestjs-agent-core");
1216
+ var import_common11 = require("@nestjs/common");
1217
+ function _ts_decorate11(decorators, target, key, desc) {
1218
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1219
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1220
+ 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;
1221
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1222
+ }
1223
+ __name(_ts_decorate11, "_ts_decorate");
1224
+ function _ts_metadata10(k, v) {
1225
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
1226
+ }
1227
+ __name(_ts_metadata10, "_ts_metadata");
1228
+ function _ts_param9(paramIndex, decorator) {
1229
+ return function(target, key) {
1230
+ decorator(target, key, paramIndex);
1231
+ };
1232
+ }
1233
+ __name(_ts_param9, "_ts_param");
1234
+ var InlineAgentRunner = class _InlineAgentRunner {
1235
+ static {
1236
+ __name(this, "InlineAgentRunner");
1237
+ }
1238
+ factory;
1239
+ store;
1240
+ logger = new import_common11.Logger(_InlineAgentRunner.name);
1241
+ pending = /* @__PURE__ */ new Map();
1242
+ constructor(factory, store) {
1243
+ this.factory = factory;
1244
+ this.store = store;
1245
+ }
1246
+ async start(input) {
1247
+ const runId = crypto.randomUUID();
1248
+ const day = input.day ?? utcDay();
1249
+ const deps = this.factory.forAgent(input.agentName);
1250
+ const hooks = this.topLevelHooks(runId, deps, input.actor, day);
1251
+ void (0, import_nestjs_agent_core12.runAgentLoop)({
1252
+ ...deps,
1253
+ day
1254
+ }, input, hooks).catch(async (error) => {
1255
+ const message = error instanceof Error ? error.message : String(error);
1256
+ const code = error instanceof import_nestjs_agent_core12.QuotaExceededError ? "quota_exceeded" : "run_failed";
1257
+ this.logger.error(`agent run ${runId} failed (${code}): ${message}`);
1258
+ (0, import_nestjs_agent_core12.publishAgentRunFailed)({
1259
+ runId,
1260
+ code,
1261
+ message
1262
+ });
1263
+ const writer = await deps.sink.open(runId);
1264
+ await writer.fail({
1265
+ code,
1266
+ message
1267
+ });
1268
+ });
1269
+ return {
1270
+ runId
1271
+ };
1272
+ }
1273
+ async signal(runId, toolCallId, decision) {
1274
+ const key = `${runId}:${toolCallId}`;
1275
+ const resolve = this.pending.get(key);
1276
+ if (resolve !== void 0) {
1277
+ this.pending.delete(key);
1278
+ resolve(decision);
1279
+ }
1280
+ }
1281
+ async cancel(runId) {
1282
+ const deps = this.factory.forAgent();
1283
+ const writer = await deps.sink.open(runId);
1284
+ await writer.end();
1285
+ }
1286
+ topLevelHooks(runId, deps, actor, day) {
1287
+ return {
1288
+ runId,
1289
+ openSink: /* @__PURE__ */ __name(() => deps.sink.open(runId), "openSink"),
1290
+ awaitApproval: /* @__PURE__ */ __name((call) => new Promise((resolve) => {
1291
+ this.pending.set(`${runId}:${call.id}`, resolve);
1292
+ }), "awaitApproval"),
1293
+ step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
1294
+ runAgent: /* @__PURE__ */ __name((agentName, task) => this.runNested(agentName, task, actor, day, 1, runId), "runAgent")
1295
+ };
1296
+ }
1297
+ /**
1298
+ * Delegate to another agent as a nested in-process run. The sub-agent streams into `sinkRunId`
1299
+ * (the top-level run the human is watching) so its output and any pending action tool are visible,
1300
+ * and its own approvals resolve through the shared pending map keyed by its own runId.
1301
+ */
1302
+ async runNested(agentName, task, actor, day, depth, sinkRunId) {
1303
+ const subThread = await this.store.createThread({
1304
+ actor,
1305
+ persona: "default",
1306
+ transient: true
1307
+ });
1308
+ const runId = crypto.randomUUID();
1309
+ await this.store.setActiveStream(subThread.id, runId);
1310
+ const deps = this.factory.forAgent(agentName);
1311
+ const hooks = {
1312
+ runId,
1313
+ // Forward into the top-level stream; the top-level run owns end/fail on that shared sink.
1314
+ openSink: /* @__PURE__ */ __name(async () => childSinkWriter(await deps.sink.open(sinkRunId)), "openSink"),
1315
+ awaitApproval: /* @__PURE__ */ __name((call) => new Promise((resolve) => {
1316
+ this.pending.set(`${runId}:${call.id}`, resolve);
1317
+ }), "awaitApproval"),
1318
+ step: /* @__PURE__ */ __name((_name, fn) => fn(), "step"),
1319
+ runAgent: /* @__PURE__ */ __name((childName, childTask) => this.runNested(childName, childTask, actor, day, depth + 1, sinkRunId), "runAgent")
1320
+ };
1321
+ return (0, import_nestjs_agent_core12.runAgentLoop)({
1322
+ ...deps,
1323
+ day
1324
+ }, {
1325
+ threadId: subThread.id,
1326
+ actor,
1327
+ userText: task,
1328
+ agentName,
1329
+ day,
1330
+ delegationDepth: depth,
1331
+ sinkRunId
1332
+ }, hooks);
1333
+ }
1334
+ };
1335
+ InlineAgentRunner = _ts_decorate11([
1336
+ (0, import_common11.Injectable)(),
1337
+ _ts_param9(0, (0, import_common11.Inject)(import_nestjs_agent_core12.AGENT_DEPS_FACTORY)),
1338
+ _ts_param9(1, (0, import_common11.Inject)(import_nestjs_agent_core12.AGENT_STORE)),
1339
+ _ts_metadata10("design:type", Function),
1340
+ _ts_metadata10("design:paramtypes", [
1341
+ typeof AgentDepsFactory === "undefined" ? Object : AgentDepsFactory,
1342
+ typeof AgentStore === "undefined" ? Object : AgentStore
1343
+ ])
1344
+ ], InlineAgentRunner);
1345
+
1346
+ // src/agent.module.ts
1347
+ function _ts_decorate12(decorators, target, key, desc) {
1348
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1349
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1350
+ 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;
1351
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1352
+ }
1353
+ __name(_ts_decorate12, "_ts_decorate");
1354
+ var FEATURE_INIT = Symbol("nestjs-agent:feature-init");
1355
+ var DEFAULT_PATH = "agent";
1356
+ function defaultDefinition(options) {
1357
+ return {
1358
+ name: "default",
1359
+ ...options.defaultAgent
1360
+ };
1361
+ }
1362
+ __name(defaultDefinition, "defaultDefinition");
1363
+ function sharedProviders(durable, includeStore) {
1364
+ const providers = [
1365
+ {
1366
+ provide: import_nestjs_agent_core13.AGENT_TOOL_REGISTRY,
1367
+ useFactory: /* @__PURE__ */ __name(() => new import_nestjs_agent_core13.ToolRegistry(), "useFactory")
1368
+ },
1369
+ {
1370
+ provide: import_nestjs_agent_core13.AGENT_REGISTRY,
1371
+ useFactory: /* @__PURE__ */ __name((options) => {
1372
+ const registry = new import_nestjs_agent_core13.AgentRegistry();
1373
+ registry.register(defaultDefinition(options));
1374
+ return registry;
1375
+ }, "useFactory"),
1376
+ inject: [
1377
+ import_nestjs_agent_core13.AGENT_OPTIONS
1378
+ ]
1379
+ },
1380
+ {
1381
+ provide: import_nestjs_agent_core13.AGENT_SINK,
1382
+ useFactory: /* @__PURE__ */ __name((options) => options.sink ?? new InProcessTokenStreamSink(), "useFactory"),
1383
+ inject: [
1384
+ import_nestjs_agent_core13.AGENT_OPTIONS
1385
+ ]
1386
+ },
1387
+ {
1388
+ provide: import_nestjs_agent_core13.AGENT_ROLES_POLICY,
1389
+ useFactory: /* @__PURE__ */ __name((options) => options.rolesPolicy ?? new import_nestjs_agent_core13.DefaultRolesPolicy(options.defaultRoles), "useFactory"),
1390
+ inject: [
1391
+ import_nestjs_agent_core13.AGENT_OPTIONS
1392
+ ]
1393
+ },
1394
+ {
1395
+ provide: import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER,
1396
+ useFactory: /* @__PURE__ */ __name((options) => options.actorResolver, "useFactory"),
1397
+ inject: [
1398
+ import_nestjs_agent_core13.AGENT_OPTIONS
1399
+ ]
1400
+ },
1401
+ {
1402
+ provide: import_nestjs_agent_core13.AGENT_MODEL,
1403
+ useFactory: /* @__PURE__ */ __name((o) => o.model, "useFactory"),
1404
+ inject: [
1405
+ import_nestjs_agent_core13.AGENT_OPTIONS
1406
+ ]
1407
+ },
1408
+ {
1409
+ // An explicit `quota` wins; otherwise `quotaLimitTokens` binds the built-in ledger-backed
1410
+ // store; otherwise quotas are off (undefined). The ledger store reads the same usage rows
1411
+ // the loop already writes, so enforcement needs no extra shared state across replicas.
1412
+ provide: import_nestjs_agent_core13.AGENT_QUOTA_STORE,
1413
+ useFactory: /* @__PURE__ */ __name((o, store) => o.quota ?? (o.quotaLimitTokens !== void 0 ? new LedgerQuotaStore(store, o.quotaLimitTokens) : void 0), "useFactory"),
1414
+ inject: [
1415
+ import_nestjs_agent_core13.AGENT_OPTIONS,
1416
+ import_nestjs_agent_core13.AGENT_STORE
1417
+ ]
1418
+ },
1419
+ AgentDepsFactory2,
1420
+ {
1421
+ provide: import_nestjs_agent_core13.AGENT_DEPS_FACTORY,
1422
+ useExisting: AgentDepsFactory2
1423
+ },
1424
+ AiToolDiscoveryService,
1425
+ InlineAgentRunner,
1426
+ AgentService
1427
+ ];
1428
+ if (includeStore) {
1429
+ providers.push({
1430
+ provide: import_nestjs_agent_core13.AGENT_STORE,
1431
+ useFactory: /* @__PURE__ */ __name((o) => o.store, "useFactory"),
1432
+ inject: [
1433
+ import_nestjs_agent_core13.AGENT_OPTIONS
1434
+ ]
1435
+ });
1436
+ }
1437
+ if (durable) {
1438
+ providers.push({
1439
+ provide: import_nestjs_agent_core13.AGENT_RUNNER,
1440
+ useFactory: /* @__PURE__ */ __name((durableRunner) => {
1441
+ if (durableRunner === void 0) {
1442
+ throw new Error("AgentModule.forRoot({ durable: true }) requires importing AgentDurableModule from '@dudousxd/nestjs-agent/durable' (alongside a configured DurableModule). It was not found.");
1443
+ }
1444
+ return durableRunner;
1445
+ }, "useFactory"),
1446
+ inject: [
1447
+ {
1448
+ token: import_nestjs_agent_core13.AGENT_DURABLE_RUNNER,
1449
+ optional: true
1450
+ }
1451
+ ]
1452
+ });
1453
+ } else {
1454
+ providers.push({
1455
+ provide: import_nestjs_agent_core13.AGENT_RUNNER,
1456
+ useExisting: InlineAgentRunner
1457
+ });
1458
+ }
1459
+ return providers;
1460
+ }
1461
+ __name(sharedProviders, "sharedProviders");
1462
+ function exportsFor(includeStore) {
1463
+ return [
1464
+ import_nestjs_agent_core13.AGENT_OPTIONS,
1465
+ import_nestjs_agent_core13.AGENT_TOOL_REGISTRY,
1466
+ import_nestjs_agent_core13.AGENT_REGISTRY,
1467
+ import_nestjs_agent_core13.AGENT_SINK,
1468
+ import_nestjs_agent_core13.AGENT_ROLES_POLICY,
1469
+ import_nestjs_agent_core13.AGENT_ACTOR_RESOLVER,
1470
+ import_nestjs_agent_core13.AGENT_MODEL,
1471
+ ...includeStore ? [
1472
+ import_nestjs_agent_core13.AGENT_STORE
1473
+ ] : [],
1474
+ import_nestjs_agent_core13.AGENT_QUOTA_STORE,
1475
+ import_nestjs_agent_core13.AGENT_DEPS_FACTORY,
1476
+ AgentDepsFactory2,
1477
+ AgentService,
1478
+ InlineAgentRunner
1479
+ ];
1480
+ }
1481
+ __name(exportsFor, "exportsFor");
1482
+ var CONTROLLERS = [
1483
+ ChatController,
1484
+ ThreadsController,
1485
+ ToolCallController,
1486
+ QuotaController
1487
+ ];
1488
+ function routerFor(path) {
1489
+ return import_core2.RouterModule.register([
1490
+ {
1491
+ path,
1492
+ module: AgentModule
1493
+ }
1494
+ ]);
1495
+ }
1496
+ __name(routerFor, "routerFor");
1497
+ var AgentModule = class _AgentModule {
1498
+ static {
1499
+ __name(this, "AgentModule");
1500
+ }
1501
+ static forRoot(options) {
1502
+ const path = options.path ?? DEFAULT_PATH;
1503
+ const includeStore = options.store !== void 0;
1504
+ return {
1505
+ module: _AgentModule,
1506
+ global: true,
1507
+ imports: [
1508
+ import_core2.DiscoveryModule,
1509
+ routerFor(path)
1510
+ ],
1511
+ controllers: CONTROLLERS,
1512
+ providers: [
1513
+ {
1514
+ provide: import_nestjs_agent_core13.AGENT_OPTIONS,
1515
+ useValue: options
1516
+ },
1517
+ ...sharedProviders(options.durable ?? false, includeStore)
1518
+ ],
1519
+ exports: exportsFor(includeStore)
1520
+ };
1521
+ }
1522
+ static forRootAsync(options) {
1523
+ const path = options.path ?? DEFAULT_PATH;
1524
+ return {
1525
+ module: _AgentModule,
1526
+ global: true,
1527
+ imports: [
1528
+ import_core2.DiscoveryModule,
1529
+ routerFor(path),
1530
+ ...options.imports ?? []
1531
+ ],
1532
+ controllers: CONTROLLERS,
1533
+ providers: [
1534
+ {
1535
+ provide: import_nestjs_agent_core13.AGENT_OPTIONS,
1536
+ useFactory: options.useFactory,
1537
+ inject: options.inject ?? []
1538
+ },
1539
+ // The async factory resolves too late to inspect `store`, so we always bind AGENT_STORE here
1540
+ // (its factory reads the resolved options). Omit-and-import-a-store-module is a `forRoot` path.
1541
+ ...sharedProviders(options.durable ?? false, true)
1542
+ ],
1543
+ exports: exportsFor(true)
1544
+ };
1545
+ }
1546
+ /** Register additional named agents (an orchestrator + its sub-agents). */
1547
+ static forFeature(definitions) {
1548
+ return {
1549
+ module: _AgentModule,
1550
+ providers: [
1551
+ {
1552
+ provide: FEATURE_INIT,
1553
+ useFactory: /* @__PURE__ */ __name((registry) => {
1554
+ for (const definition of definitions) {
1555
+ registry.register(definition);
1556
+ }
1557
+ return true;
1558
+ }, "useFactory"),
1559
+ inject: [
1560
+ import_nestjs_agent_core13.AGENT_REGISTRY
1561
+ ]
1562
+ }
1563
+ ]
1564
+ };
1565
+ }
1566
+ };
1567
+ AgentModule = _ts_decorate12([
1568
+ (0, import_common12.Global)(),
1569
+ (0, import_common12.Module)({})
1570
+ ], AgentModule);
1571
+
1572
+ // src/durable/agent-durable.ts
1573
+ function agentDurable(options) {
1574
+ return [
1575
+ AgentModule.forRoot({
1576
+ ...options,
1577
+ durable: true
1578
+ }),
1579
+ AgentDurableModule.forRoot()
1580
+ ];
1581
+ }
1582
+ __name(agentDurable, "agentDurable");
1583
+ // Annotate the CommonJS export names for ESM import in node:
1584
+ 0 && (module.exports = {
1585
+ AgentDurableModule,
1586
+ AgentRunWorkflow,
1587
+ DurableAgentRunner,
1588
+ agentDurable
1589
+ });
1590
+ //# sourceMappingURL=index.cjs.map