@dudousxd/nestjs-agent 0.12.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.
- package/README.md +34 -0
- package/dist/{agent-deps.factory-EROMcBNh.d.cts → agent-deps.factory-OjrLyAZo.d.cts} +13 -25
- package/dist/{agent-deps.factory-EROMcBNh.d.ts → agent-deps.factory-OjrLyAZo.d.ts} +13 -25
- package/dist/durable/index.cjs +133 -132
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +42 -34
- package/dist/durable/index.d.ts +42 -34
- package/dist/durable/index.js +161 -159
- package/dist/durable/index.js.map +1 -1
- package/dist/index.cjs +7 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -19
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/durable/index.d.cts
CHANGED
|
@@ -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-
|
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* replay-safe, observable child run (it shows up as
|
|
17
|
-
* streams into its top-level ancestor's sink
|
|
18
|
-
*
|
|
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,
|
|
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
|
|
89
|
-
* `AgentRunSteps.tool`)
|
|
90
|
-
* in-process 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
|
|
93
|
-
*
|
|
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
|
|
147
|
-
*
|
|
148
|
-
*
|
|
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
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
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
|
-
* false` — default ON under durable); `AgentRunWorkflow` injects it. Kept in its own file —
|
|
225
|
-
* `AgentDurableModule` provides `AgentRunWorkflow` and `AgentRunWorkflow` injects this token, so
|
|
226
|
-
* declaring it in either of those 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 };
|
package/dist/durable/index.d.ts
CHANGED
|
@@ -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-
|
|
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
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* replay-safe, observable child run (it shows up as
|
|
17
|
-
* streams into its top-level ancestor's sink
|
|
18
|
-
*
|
|
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,
|
|
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
|
|
89
|
-
* `AgentRunSteps.tool`)
|
|
90
|
-
* in-process 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
|
|
93
|
-
*
|
|
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
|
|
147
|
-
*
|
|
148
|
-
*
|
|
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
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
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
|
-
* false` — default ON under durable); `AgentRunWorkflow` injects it. Kept in its own file —
|
|
225
|
-
* `AgentDurableModule` provides `AgentRunWorkflow` and `AgentRunWorkflow` injects this token, so
|
|
226
|
-
* declaring it in either of those 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 };
|