@dudousxd/nestjs-agent 1.39.1 → 2.0.1
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 +14 -7
- package/dist/a2ui/index.cjs +1 -0
- package/dist/a2ui/index.cjs.map +1 -1
- package/dist/a2ui/index.d.cts +3 -2
- package/dist/a2ui/index.d.ts +3 -2
- package/dist/a2ui/index.js +2 -1
- package/dist/a2ui/index.js.map +1 -1
- package/dist/{chat-queue.service-YjiKVTKE.d.ts → chat-queue.service-BjPCw4Pf.d.ts} +104 -43
- package/dist/{chat-queue.service-fopUN313.d.cts → chat-queue.service-C49HIuEV.d.cts} +104 -43
- package/dist/durable/index.cjs +13572 -1754
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +6 -6
- package/dist/durable/index.d.ts +6 -6
- package/dist/durable/index.js +12228 -390
- package/dist/durable/index.js.map +1 -1
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.d.cts +4 -6
- package/dist/genui/index.d.ts +4 -6
- package/dist/genui/index.js.map +1 -1
- package/dist/{index-BJFM1tG8.d.cts → index-BBkyvNUi.d.cts} +1 -1
- package/dist/{index-De98CGXa.d.ts → index-CRCbsO6E.d.ts} +1 -1
- package/dist/index.cjs +12408 -450
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +318 -18
- package/dist/index.d.ts +318 -18
- package/dist/index.js +12313 -346
- package/dist/index.js.map +1 -1
- package/dist/media/index.cjs +4 -9
- package/dist/media/index.cjs.map +1 -1
- package/dist/media/index.d.cts +14 -3
- package/dist/media/index.d.ts +14 -3
- package/dist/media/index.js +6 -11
- package/dist/media/index.js.map +1 -1
- package/dist/workflows/index.cjs +1496 -0
- package/dist/workflows/index.cjs.map +1 -0
- package/dist/workflows/index.d.cts +158 -0
- package/dist/workflows/index.d.ts +158 -0
- package/dist/workflows/index.js +1464 -0
- package/dist/workflows/index.js.map +1 -0
- package/package.json +39 -8
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { HumanReply, AgentRunner, AgentStore, TokenStreamSink, AgentRunInput, AgentRunStartOptions, AgentLoopResult } from '@dudousxd/nestjs-agent-core';
|
|
2
|
+
import { WorkflowSignal, WorkflowClient, WorkflowInstanceDetails, WorkflowsModuleOptions, WorkflowContext, WorkflowRunner } from '@nestjs/workflows';
|
|
3
|
+
import { C as ChatQueueService, A as AgentDepsFactory, b as AgentModuleOptions } from '../chat-queue.service-BjPCw4Pf.js';
|
|
4
|
+
import '@dudousxd/nestjs-agent-core/genui';
|
|
5
|
+
import '@standard-schema/spec';
|
|
6
|
+
import '@nestjs/common';
|
|
7
|
+
import '@nestjs/ai';
|
|
8
|
+
import '../genui/index.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Agent turns on NestJS's `@nestjs/workflows`. Import it next to `WorkflowsModule.forRoot()` and
|
|
12
|
+
* `AgentModule.forRoot({ durable: true })`:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* imports: [
|
|
16
|
+
* WorkflowsModule.forRoot(),
|
|
17
|
+
* AgentModule.forRoot({ model, store, durable: true }),
|
|
18
|
+
* AgentWorkflowsModule,
|
|
19
|
+
* ]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* It registers the `aviary.agent.run` workflow (and the one a long turn goes on in) and provides the
|
|
23
|
+
* runner `AgentModule` binds `AGENT_RUNNER` to. Every process registers them, so any process can
|
|
24
|
+
* start a turn; which processes RUN turns is `WorkflowsModule`'s `worker` option: on an API pod
|
|
25
|
+
* that must not, `WorkflowsModule.forRoot({ worker: false })`.
|
|
26
|
+
*/
|
|
27
|
+
declare class AgentWorkflowsModule {
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A person's reply to a call a turn is parked on: a `Decision` on an action tool, or the answers to
|
|
32
|
+
* a question set. Keyed by {@link replyKey}, so a reply reaches only the call it answers.
|
|
33
|
+
*/
|
|
34
|
+
declare const AGENT_REPLY: WorkflowSignal<HumanReply>;
|
|
35
|
+
/** The key a reply to call `toolCallId` of run `runId` is sent and awaited under. */
|
|
36
|
+
declare function replyKey(runId: string, toolCallId: string): string;
|
|
37
|
+
/** A call waiting for a person, as `WorkflowsAgentRunner.pendingReplies()` lists it. */
|
|
38
|
+
interface PendingReply {
|
|
39
|
+
/** What the reply is signalled under ({@link replyKey}). */
|
|
40
|
+
key: string;
|
|
41
|
+
/** The turn's run id. */
|
|
42
|
+
runId: string;
|
|
43
|
+
toolCallId: string;
|
|
44
|
+
/** The tool, or `'ask'` / `'intake'` for a question set. */
|
|
45
|
+
toolName: string;
|
|
46
|
+
kind: 'approval' | 'elicitation';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Runs agent turns on NestJS's `@nestjs/workflows` (`durable: true`). `start` creates the
|
|
51
|
+
* `aviary.agent.run` instance under the run id and returns; whichever worker claims it runs the turn
|
|
52
|
+
* and streams to the sink. A person's reply to a parked call is the `AGENT_REPLY` signal keyed by
|
|
53
|
+
* `<runId>:<toolCallId>`; a Stop is `WorkflowClient.cancel`.
|
|
54
|
+
*/
|
|
55
|
+
declare class WorkflowsAgentRunner implements AgentRunner {
|
|
56
|
+
private readonly store;
|
|
57
|
+
private readonly sink;
|
|
58
|
+
private readonly queue?;
|
|
59
|
+
private readonly logger;
|
|
60
|
+
private readonly client;
|
|
61
|
+
constructor(store: AgentStore, sink: TokenStreamSink, client?: WorkflowClient, queue?: ChatQueueService | undefined);
|
|
62
|
+
start(input: AgentRunInput, options?: AgentRunStartOptions): Promise<{
|
|
63
|
+
runId: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** Not ended as far as the engine knows. An unknown run counts as running, and so does one it can't be asked about. */
|
|
66
|
+
isRunActive(runId: string): Promise<boolean>;
|
|
67
|
+
signal(runId: string, toolCallId: string, reply: HumanReply): Promise<void>;
|
|
68
|
+
/** The engine's view of a run: status, custom status, waits, children. `null` for an unknown id. */
|
|
69
|
+
getStatus(runId: string): Promise<WorkflowInstanceDetails | null>;
|
|
70
|
+
/**
|
|
71
|
+
* The calls of run `runId` waiting for a person now, in the instance it started in, in the
|
|
72
|
+
* instances it went on in, and in the sub-agent runs it delegated to.
|
|
73
|
+
*/
|
|
74
|
+
pendingReplies(runId: string): Promise<PendingReply[]>;
|
|
75
|
+
/**
|
|
76
|
+
* Stop a run: the engine stops the turn at its next `ctx` call (a parked turn at once), and
|
|
77
|
+
* cancels the sub-agent runs it is waiting on. What the engine knows nothing about is settled
|
|
78
|
+
* here, as on the `aviary` engine: the delegation a detached run answers, the thread's queue and
|
|
79
|
+
* live stream, the subscriber's stream (a `cancelled` frame and a normal end), the run's row.
|
|
80
|
+
*/
|
|
81
|
+
cancel(runId: string): Promise<void>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** An error as JSON: its name, its message and its own JSON-safe fields (a `code`, a `status`). */
|
|
85
|
+
interface SerializedTurnError {
|
|
86
|
+
name: string;
|
|
87
|
+
message: string;
|
|
88
|
+
props?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
/** What one journaled operation came to: its value, or the error it threw. */
|
|
91
|
+
type TurnOutcome = {
|
|
92
|
+
v?: unknown;
|
|
93
|
+
} | {
|
|
94
|
+
e: SerializedTurnError;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** The workflow a turn runs as. */
|
|
98
|
+
declare const AGENT_RUN_WORKFLOW = "aviary.agent.run";
|
|
99
|
+
/** The workflow a turn goes on in after `stepsPerInstance` model calls. */
|
|
100
|
+
declare const AGENT_RUN_SEGMENT_WORKFLOW = "aviary.agent.run.segment";
|
|
101
|
+
/** What a segment instance starts from: the turn, its run id, and what the instances before it settled. */
|
|
102
|
+
interface AgentRunSegmentInput {
|
|
103
|
+
input: AgentRunInput;
|
|
104
|
+
/** The turn's run id: the id of the instance it started in. */
|
|
105
|
+
runId: string;
|
|
106
|
+
/** 1 for the first child instance. */
|
|
107
|
+
segment: number;
|
|
108
|
+
carried: Record<string, TurnOutcome>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The agent turn on `@nestjs/workflows`: what `AgentRunFlow` (`aviary.agent.run`) and
|
|
112
|
+
* `AgentRunSegmentFlow` run. Each model call and each tool call is a `ctx.step`, the loop's
|
|
113
|
+
* checkpoints are `ctx.step`s too, a human's reply is a `ctx.waitForSignal(AGENT_REPLY, { key })`,
|
|
114
|
+
* a delegation is `ctx.executeChild`, a detached delegation and the thread's next queued message are
|
|
115
|
+
* `ctx.startChild(..., { parentClose: 'abandon' })`. A cancel is the engine's: `WorkflowClient.cancel`
|
|
116
|
+
* stops the turn at its next `ctx` call, and `WorkflowsAgentRunner.cancel` settles the agent's own
|
|
117
|
+
* state, as it does on the `aviary` engine.
|
|
118
|
+
*/
|
|
119
|
+
declare class AgentTurnExecutor {
|
|
120
|
+
private readonly factory;
|
|
121
|
+
private readonly store;
|
|
122
|
+
private readonly queue?;
|
|
123
|
+
private readonly client?;
|
|
124
|
+
private readonly workflowsOptions?;
|
|
125
|
+
private readonly logger;
|
|
126
|
+
private readonly stepsPerInstance;
|
|
127
|
+
constructor(factory: AgentDepsFactory, store: AgentStore, options?: AgentModuleOptions, queue?: ChatQueueService | undefined, client?: WorkflowClient | undefined, workflowsOptions?: WorkflowsModuleOptions | undefined);
|
|
128
|
+
/** A turn from its first instance. */
|
|
129
|
+
run(ctx: WorkflowContext, input: AgentRunInput): Promise<AgentLoopResult>;
|
|
130
|
+
execute(ctx: WorkflowContext, segment: AgentRunSegmentInput): Promise<AgentLoopResult>;
|
|
131
|
+
/** The turn goes on in a child instance, from what this one (and those before it) settled. */
|
|
132
|
+
private continueInSegment;
|
|
133
|
+
/**
|
|
134
|
+
* Hand the thread on past this settling turn, as the `aviary` engine does: the decision is one
|
|
135
|
+
* checkpoint, and the next message starts as an abandoned child under its own id, so the turn
|
|
136
|
+
* ending doesn't cancel it.
|
|
137
|
+
*/
|
|
138
|
+
private advanceQueue;
|
|
139
|
+
private isCancelled;
|
|
140
|
+
private settleDetachedParent;
|
|
141
|
+
/** A `ctx` call whose interrupt carries core's control-flow marker. */
|
|
142
|
+
private ctxCall;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** An agent turn, as a `@nestjs/workflows` workflow (`aviary.agent.run`). The run id is its instance id. */
|
|
146
|
+
declare class AgentRunFlow implements WorkflowRunner<AgentRunInput, AgentLoopResult> {
|
|
147
|
+
private readonly turns;
|
|
148
|
+
constructor(turns: AgentTurnExecutor);
|
|
149
|
+
run(ctx: WorkflowContext, input: AgentRunInput): Promise<AgentLoopResult>;
|
|
150
|
+
}
|
|
151
|
+
/** A turn going on in a child instance after `stepsPerInstance` model calls. Internal. */
|
|
152
|
+
declare class AgentRunSegmentFlow implements WorkflowRunner<AgentRunSegmentInput, AgentLoopResult> {
|
|
153
|
+
private readonly turns;
|
|
154
|
+
constructor(turns: AgentTurnExecutor);
|
|
155
|
+
run(ctx: WorkflowContext, segment: AgentRunSegmentInput): Promise<AgentLoopResult>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export { AGENT_REPLY, AGENT_RUN_SEGMENT_WORKFLOW, AGENT_RUN_WORKFLOW, AgentRunFlow, AgentRunSegmentFlow, type AgentRunSegmentInput, AgentWorkflowsModule, type PendingReply, WorkflowsAgentRunner, replyKey };
|