@dudousxd/nestjs-agent 0.13.0 → 1.0.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.
@@ -1,6 +1,6 @@
1
1
  import { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, HumanReply } from '@dudousxd/nestjs-agent-core';
2
2
  import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
3
- import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-y2hvoQ6U.cjs';
3
+ import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-OjrLyAZo.cjs';
4
4
  import { WorkflowService } from '@dudousxd/nestjs-durable';
5
5
  import { DynamicModule } from '@nestjs/common';
6
6
  import '@standard-schema/spec';
@@ -9,20 +9,20 @@ import '@standard-schema/spec';
9
9
  * The agent turn AS a durable workflow. Persist/stream checkpoints are `ctx.localStep`s — the
10
10
  * in-process primitive, NOT the always-dispatched `ctx.step`: their names are dynamic checkpoint
11
11
  * identities (`persist:toolcall:<id>`), not routable worker groups, and their deps (store, sink)
12
- * live in THIS workflow worker's DI. The two LONG steps (model call, tool execution) are dispatched
13
- * through `AgentRunSteps` where the deployment asked for it (`AGENT_DISPATCHED_STEPS`, from
14
- * `dispatchedSteps: true`) so the run isn't pinned to this pod while they execute; without that
15
- * flag they are localSteps too. HITL is `ctx.waitForSignal`, and sub-agent delegation is
16
- * `ctx.child(AgentRunWorkflow)` — a replay-safe, observable child run (it shows up as a node in the durable dashboard). A child
17
- * streams into its top-level ancestor's sink (`sinkRunId`) so the human watching the parent sees it
18
- * and can approve its action tools; the approval routes to the child's own run via `runForToolCall`.
12
+ * live in THIS workflow worker's DI. The two LONG steps (model call, tool execution) are `ctx.step`s
13
+ * routed to `AgentRunSteps`, so the run is never pinned to this pod while they execute — the same
14
+ * thing `ctx.step` means anywhere in this ecosystem, and the reason a `@AiTool` handler must
15
+ * establish whatever execution context it needs itself. HITL is `ctx.waitForSignal`, and sub-agent
16
+ * delegation is `ctx.child(AgentRunWorkflow)` — a replay-safe, observable child run (it shows up as
17
+ * a node in the durable dashboard). A child streams into its top-level ancestor's sink
18
+ * (`sinkRunId`) so the human watching the parent sees it and can approve its action tools; the
19
+ * approval routes to the child's own run via `runForToolCall`.
19
20
  */
20
21
  declare class AgentRunWorkflow {
21
22
  private readonly factory;
22
23
  private readonly store;
23
- private readonly dispatchedSteps;
24
24
  private readonly runs?;
25
- constructor(factory: AgentDepsFactory, store: AgentStore, dispatchedSteps: boolean, runs?: RunGateway | undefined);
25
+ constructor(factory: AgentDepsFactory, store: AgentStore, runs?: RunGateway | undefined);
26
26
  /**
27
27
  * Has someone asked this run to stop? Read from the runtime's own run status, which is where
28
28
  * `DurableAgentRunner.cancel` puts it — `cancelling` while a compensating cancel is in flight,
@@ -85,12 +85,13 @@ interface DispatchedToolInput extends ToolStepEnvelope {
85
85
  toolType: 'read' | 'action';
86
86
  }
87
87
  /**
88
- * The two long steps `AgentRunWorkflow` dispatches as routed remote steps (`AgentRunSteps.llm` /
89
- * `AgentRunSteps.tool`) under `dispatchedSteps: true`; omitting that flag runs them in-process
90
- * under `ctx.localStep` instead. Both re-resolve their deps from THIS worker's own DI via
88
+ * The two long steps every turn dispatches as routed remote steps (`AgentRunSteps.llm` /
89
+ * `AgentRunSteps.tool`). Both re-resolve their deps from THIS worker's own DI via
91
90
  * `AGENT_DEPS_FACTORY.forAgent` — a step can be served by any worker in the fleet, not just the one
92
- * that started the run. Always provided by `AgentDurableModule` regardless of `dispatchedSteps`, so
93
- * the worker group is never orphaned.
91
+ * that started the run, which is also why a host's `@AiTool` handler has to establish whatever
92
+ * execution context it needs (a request-scoped ORM EntityManager, a CLS transaction) rather than
93
+ * inherit one. Provided by `AgentDurableModule` under every surface but `'http'`, so the routed
94
+ * groups are served wherever a run may be driven.
94
95
  */
95
96
  declare class AgentRunSteps {
96
97
  private readonly factory;
@@ -143,13 +144,31 @@ declare class DurableAgentRunner implements AgentRunner {
143
144
  * settles the run `cancelled` regardless. The cascade to child runs comes with it.
144
145
  *
145
146
  * Neither of those settles the agent's own state, so this does: the run row gets its own terminal,
146
- * and the subscriber gets a `cancelled` frame followed by a normal end. Both are keyed by runId
147
- * alone, which is why they belong here rather than in the body — the body is the only place that
148
- * knows which THREAD was streaming, so releasing that stays there (see `AgentRunWorkflow`).
147
+ * the thread stops reporting a live stream, and the subscriber gets a `cancelled` frame followed
148
+ * by a normal end.
149
+ *
150
+ * The thread is released HERE rather than left to the body, because a cancelled turn is usually
151
+ * suspended — parked on a human, or on one of the dispatched steps a turn spends most of its life
152
+ * in — and a suspended body never reaches its own catch: the runtime settles the run from outside
153
+ * it. The body still releases the thread on the paths where it does unwind (see
154
+ * `AgentRunWorkflow`); both write the same `null`, and whichever gets there first is right. The
155
+ * thread id comes off the run's own recorded input, so this holds for a sub-agent's subthread too
156
+ * — read best-effort, because a gateway that cannot name the thread must not stop the cancel.
149
157
  *
150
158
  * A tool already executing is not interrupted, here or anywhere: see `haltIfCancelled` in core.
151
159
  */
152
160
  cancel(runId: string): Promise<void>;
161
+ /**
162
+ * Which thread a run was streaming, or `undefined` where the gateway cannot say.
163
+ *
164
+ * A read failure answers `undefined` instead of propagating, the same posture `AgentRunWorkflow`
165
+ * takes for its own cancel observation: failing to ask is not an answer worth failing a cancel
166
+ * over. This id is only needed to clear the thread's active stream, and a stream still marked live
167
+ * is a far smaller fault than the one a throw here would cause — a run nobody ever told to stop,
168
+ * with a subscriber holding a stream that never settles, from the one call whose entire job is to
169
+ * make a run stop.
170
+ */
171
+ private threadOf;
153
172
  }
154
173
 
155
174
  /**
@@ -183,11 +202,10 @@ interface AgentDurableModuleOptions {
183
202
  * and exposes the durable runner via `AGENT_DURABLE_RUNNER`, which AgentModule binds to
184
203
  * `AGENT_RUNNER`. Forgetting this import makes AgentModule throw a clear error at boot.
185
204
  *
186
- * Always provides `AgentRunSteps` regardless of `dispatchedSteps` — the worker group it serves
187
- * (`AgentRunSteps.llm`/`.tool`) must never be orphaned by a config flag the durable step registrar
188
- * can't see ahead of time. This is the FULL ('both'/'engine'-equivalent) wiring: bare-importing this
189
- * class (no `forRoot()` call) always gets it, unconditionally — `forRoot({ surface: 'http' })` is
190
- * the only form that diverges (see `AgentDurableHttpModule` above).
205
+ * Provides `AgentRunSteps`, whose two groups (`AgentRunSteps.llm`/`.tool`) every turn dispatches to.
206
+ * This is the FULL ('both'/'engine'-equivalent) wiring: bare-importing this class (no `forRoot()`
207
+ * call) always gets it, unconditionally — `forRoot({ surface: 'http' })` is the only form that
208
+ * diverges (see `AgentDurableHttpModule` above).
191
209
  */
192
210
  declare class AgentDurableModule {
193
211
  /**
@@ -217,14 +235,4 @@ declare class AgentDurableModule {
217
235
  */
218
236
  declare function agentDurable(options: AgentModuleOptions): DynamicModule[];
219
237
 
220
- /**
221
- * DI flag carrying the EFFECTIVE `dispatchedSteps` value: whether `AgentRunWorkflow` dispatches its
222
- * `llm`/`tool` steps as routed remote steps (`AgentRunSteps`) instead of in-process `ctx.localStep`s.
223
- * `AgentDurableModule` derives it from `AGENT_OPTIONS` (`durable === true && dispatchedSteps ===
224
- * true`); `AgentRunWorkflow` injects it. Kept in its own file — `AgentDurableModule` provides
225
- * `AgentRunWorkflow` and `AgentRunWorkflow` injects this token, so declaring it in either of those
226
- * two files would make them import each other.
227
- */
228
- declare const AGENT_DISPATCHED_STEPS: unique symbol;
229
-
230
- export { AGENT_DISPATCHED_STEPS, AgentDurableModule, type AgentDurableModuleOptions, AgentRunSteps, AgentRunWorkflow, type DispatchedLlmInput, type DispatchedToolInput, DurableAgentRunner, agentDurable };
238
+ export { AgentDurableModule, type AgentDurableModuleOptions, AgentRunSteps, AgentRunWorkflow, type DispatchedLlmInput, type DispatchedToolInput, DurableAgentRunner, agentDurable };
@@ -1,6 +1,6 @@
1
1
  import { AgentStore, AgentRunInput, AgentLoopResult, LlmStepEnvelope, BufferedModelTurnResult, ToolStepEnvelope, AgentRunner, TokenStreamSink, HumanReply } from '@dudousxd/nestjs-agent-core';
2
2
  import { RunGateway, WorkflowCtx } from '@dudousxd/nestjs-durable-core';
3
- import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-y2hvoQ6U.js';
3
+ import { A as AgentDepsFactory, a as AgentSurface, b as AgentModuleOptions } from '../agent-deps.factory-OjrLyAZo.js';
4
4
  import { WorkflowService } from '@dudousxd/nestjs-durable';
5
5
  import { DynamicModule } from '@nestjs/common';
6
6
  import '@standard-schema/spec';
@@ -9,20 +9,20 @@ import '@standard-schema/spec';
9
9
  * The agent turn AS a durable workflow. Persist/stream checkpoints are `ctx.localStep`s — the
10
10
  * in-process primitive, NOT the always-dispatched `ctx.step`: their names are dynamic checkpoint
11
11
  * identities (`persist:toolcall:<id>`), not routable worker groups, and their deps (store, sink)
12
- * live in THIS workflow worker's DI. The two LONG steps (model call, tool execution) are dispatched
13
- * through `AgentRunSteps` where the deployment asked for it (`AGENT_DISPATCHED_STEPS`, from
14
- * `dispatchedSteps: true`) so the run isn't pinned to this pod while they execute; without that
15
- * flag they are localSteps too. HITL is `ctx.waitForSignal`, and sub-agent delegation is
16
- * `ctx.child(AgentRunWorkflow)` — a replay-safe, observable child run (it shows up as a node in the durable dashboard). A child
17
- * streams into its top-level ancestor's sink (`sinkRunId`) so the human watching the parent sees it
18
- * and can approve its action tools; the approval routes to the child's own run via `runForToolCall`.
12
+ * live in THIS workflow worker's DI. The two LONG steps (model call, tool execution) are `ctx.step`s
13
+ * routed to `AgentRunSteps`, so the run is never pinned to this pod while they execute — the same
14
+ * thing `ctx.step` means anywhere in this ecosystem, and the reason a `@AiTool` handler must
15
+ * establish whatever execution context it needs itself. HITL is `ctx.waitForSignal`, and sub-agent
16
+ * delegation is `ctx.child(AgentRunWorkflow)` — a replay-safe, observable child run (it shows up as
17
+ * a node in the durable dashboard). A child streams into its top-level ancestor's sink
18
+ * (`sinkRunId`) so the human watching the parent sees it and can approve its action tools; the
19
+ * approval routes to the child's own run via `runForToolCall`.
19
20
  */
20
21
  declare class AgentRunWorkflow {
21
22
  private readonly factory;
22
23
  private readonly store;
23
- private readonly dispatchedSteps;
24
24
  private readonly runs?;
25
- constructor(factory: AgentDepsFactory, store: AgentStore, dispatchedSteps: boolean, runs?: RunGateway | undefined);
25
+ constructor(factory: AgentDepsFactory, store: AgentStore, runs?: RunGateway | undefined);
26
26
  /**
27
27
  * Has someone asked this run to stop? Read from the runtime's own run status, which is where
28
28
  * `DurableAgentRunner.cancel` puts it — `cancelling` while a compensating cancel is in flight,
@@ -85,12 +85,13 @@ interface DispatchedToolInput extends ToolStepEnvelope {
85
85
  toolType: 'read' | 'action';
86
86
  }
87
87
  /**
88
- * The two long steps `AgentRunWorkflow` dispatches as routed remote steps (`AgentRunSteps.llm` /
89
- * `AgentRunSteps.tool`) under `dispatchedSteps: true`; omitting that flag runs them in-process
90
- * under `ctx.localStep` instead. Both re-resolve their deps from THIS worker's own DI via
88
+ * The two long steps every turn dispatches as routed remote steps (`AgentRunSteps.llm` /
89
+ * `AgentRunSteps.tool`). Both re-resolve their deps from THIS worker's own DI via
91
90
  * `AGENT_DEPS_FACTORY.forAgent` — a step can be served by any worker in the fleet, not just the one
92
- * that started the run. Always provided by `AgentDurableModule` regardless of `dispatchedSteps`, so
93
- * the worker group is never orphaned.
91
+ * that started the run, which is also why a host's `@AiTool` handler has to establish whatever
92
+ * execution context it needs (a request-scoped ORM EntityManager, a CLS transaction) rather than
93
+ * inherit one. Provided by `AgentDurableModule` under every surface but `'http'`, so the routed
94
+ * groups are served wherever a run may be driven.
94
95
  */
95
96
  declare class AgentRunSteps {
96
97
  private readonly factory;
@@ -143,13 +144,31 @@ declare class DurableAgentRunner implements AgentRunner {
143
144
  * settles the run `cancelled` regardless. The cascade to child runs comes with it.
144
145
  *
145
146
  * Neither of those settles the agent's own state, so this does: the run row gets its own terminal,
146
- * and the subscriber gets a `cancelled` frame followed by a normal end. Both are keyed by runId
147
- * alone, which is why they belong here rather than in the body — the body is the only place that
148
- * knows which THREAD was streaming, so releasing that stays there (see `AgentRunWorkflow`).
147
+ * the thread stops reporting a live stream, and the subscriber gets a `cancelled` frame followed
148
+ * by a normal end.
149
+ *
150
+ * The thread is released HERE rather than left to the body, because a cancelled turn is usually
151
+ * suspended — parked on a human, or on one of the dispatched steps a turn spends most of its life
152
+ * in — and a suspended body never reaches its own catch: the runtime settles the run from outside
153
+ * it. The body still releases the thread on the paths where it does unwind (see
154
+ * `AgentRunWorkflow`); both write the same `null`, and whichever gets there first is right. The
155
+ * thread id comes off the run's own recorded input, so this holds for a sub-agent's subthread too
156
+ * — read best-effort, because a gateway that cannot name the thread must not stop the cancel.
149
157
  *
150
158
  * A tool already executing is not interrupted, here or anywhere: see `haltIfCancelled` in core.
151
159
  */
152
160
  cancel(runId: string): Promise<void>;
161
+ /**
162
+ * Which thread a run was streaming, or `undefined` where the gateway cannot say.
163
+ *
164
+ * A read failure answers `undefined` instead of propagating, the same posture `AgentRunWorkflow`
165
+ * takes for its own cancel observation: failing to ask is not an answer worth failing a cancel
166
+ * over. This id is only needed to clear the thread's active stream, and a stream still marked live
167
+ * is a far smaller fault than the one a throw here would cause — a run nobody ever told to stop,
168
+ * with a subscriber holding a stream that never settles, from the one call whose entire job is to
169
+ * make a run stop.
170
+ */
171
+ private threadOf;
153
172
  }
154
173
 
155
174
  /**
@@ -183,11 +202,10 @@ interface AgentDurableModuleOptions {
183
202
  * and exposes the durable runner via `AGENT_DURABLE_RUNNER`, which AgentModule binds to
184
203
  * `AGENT_RUNNER`. Forgetting this import makes AgentModule throw a clear error at boot.
185
204
  *
186
- * Always provides `AgentRunSteps` regardless of `dispatchedSteps` — the worker group it serves
187
- * (`AgentRunSteps.llm`/`.tool`) must never be orphaned by a config flag the durable step registrar
188
- * can't see ahead of time. This is the FULL ('both'/'engine'-equivalent) wiring: bare-importing this
189
- * class (no `forRoot()` call) always gets it, unconditionally — `forRoot({ surface: 'http' })` is
190
- * the only form that diverges (see `AgentDurableHttpModule` above).
205
+ * Provides `AgentRunSteps`, whose two groups (`AgentRunSteps.llm`/`.tool`) every turn dispatches to.
206
+ * This is the FULL ('both'/'engine'-equivalent) wiring: bare-importing this class (no `forRoot()`
207
+ * call) always gets it, unconditionally — `forRoot({ surface: 'http' })` is the only form that
208
+ * diverges (see `AgentDurableHttpModule` above).
191
209
  */
192
210
  declare class AgentDurableModule {
193
211
  /**
@@ -217,14 +235,4 @@ declare class AgentDurableModule {
217
235
  */
218
236
  declare function agentDurable(options: AgentModuleOptions): DynamicModule[];
219
237
 
220
- /**
221
- * DI flag carrying the EFFECTIVE `dispatchedSteps` value: whether `AgentRunWorkflow` dispatches its
222
- * `llm`/`tool` steps as routed remote steps (`AgentRunSteps`) instead of in-process `ctx.localStep`s.
223
- * `AgentDurableModule` derives it from `AGENT_OPTIONS` (`durable === true && dispatchedSteps ===
224
- * true`); `AgentRunWorkflow` injects it. Kept in its own file — `AgentDurableModule` provides
225
- * `AgentRunWorkflow` and `AgentRunWorkflow` injects this token, so declaring it in either of those
226
- * two files would make them import each other.
227
- */
228
- declare const AGENT_DISPATCHED_STEPS: unique symbol;
229
-
230
- export { AGENT_DISPATCHED_STEPS, AgentDurableModule, type AgentDurableModuleOptions, AgentRunSteps, AgentRunWorkflow, type DispatchedLlmInput, type DispatchedToolInput, DurableAgentRunner, agentDurable };
238
+ export { AgentDurableModule, type AgentDurableModuleOptions, AgentRunSteps, AgentRunWorkflow, type DispatchedLlmInput, type DispatchedToolInput, DurableAgentRunner, agentDurable };