@maxanstey-meridian/tandem 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +60 -0
- package/dist/index.d.ts +346 -0
- package/dist/index.js +1291 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Max Anstey
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @maxanstey-meridian/tandem
|
|
2
|
+
|
|
3
|
+
The TypeScript authoring API for [Tandem](https://github.com/maxanstey-meridian/tandem), a typed
|
|
4
|
+
agentic pipeline SDK running on .NET and Microsoft Agent Framework.
|
|
5
|
+
|
|
6
|
+
## Requirements
|
|
7
|
+
|
|
8
|
+
- macOS on Apple silicon
|
|
9
|
+
- Node.js 22 or newer
|
|
10
|
+
- .NET 10 runtime
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @maxanstey-meridian/tandem zod
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Install only this package in application code. Its runtime packages are selected automatically.
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { output, pipeline, route, run, stage } from "@maxanstey-meridian/tandem";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
|
|
26
|
+
const State = z.object({
|
|
27
|
+
input: z.string(),
|
|
28
|
+
normalized: z.string().nullable(),
|
|
29
|
+
});
|
|
30
|
+
type State = z.infer<typeof State>;
|
|
31
|
+
|
|
32
|
+
const normalize = stage<State>({
|
|
33
|
+
id: "normalize",
|
|
34
|
+
execute: (state) => ({
|
|
35
|
+
...state,
|
|
36
|
+
normalized: state.input.trim().toLowerCase(),
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const done = output<State>({
|
|
41
|
+
id: "done",
|
|
42
|
+
summary: (state) => state.normalized!,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const normalizeInput = pipeline({
|
|
46
|
+
name: "normalize-input",
|
|
47
|
+
state: State,
|
|
48
|
+
nodes: [normalize, done],
|
|
49
|
+
start: normalize,
|
|
50
|
+
routes: [route({ from: normalize, to: done, label: "normalized" })],
|
|
51
|
+
outputs: [done],
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const result = await run(normalizeInput, { input: " Hello ", normalized: null });
|
|
55
|
+
console.log(result.state.normalized);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
State holds application facts, participants perform work, and routes decide what runs next. See the
|
|
59
|
+
[TypeScript guide](https://github.com/maxanstey-meridian/tandem/tree/main/typescript) for agents,
|
|
60
|
+
capabilities, interactions, persistence, and complete examples.
|
|
61
|
+
|
|
62
|
+
Licensed under the [MIT License](./LICENSE).
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Pipeline, type RunOptions, type RunResult } from "./index.js";
|
|
2
|
+
export interface RunCliOptions<TState> extends Omit<RunOptions, "presentation"> {
|
|
3
|
+
readonly formatResult: (result: RunResult<TState>) => string | Promise<string>;
|
|
4
|
+
}
|
|
5
|
+
export declare function runCli<TState>(graph: Pipeline<TState>, initial: unknown, options: RunCliOptions<TState>): Promise<void>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { run } from "./index.js";
|
|
2
|
+
export async function runCli(graph, initial, options) {
|
|
3
|
+
let exitCode = 2;
|
|
4
|
+
let signalExitCode = null;
|
|
5
|
+
let pipelineCompleted = false;
|
|
6
|
+
const shutdown = new AbortController();
|
|
7
|
+
const requestShutdown = (code, signal) => {
|
|
8
|
+
signalExitCode ??= code;
|
|
9
|
+
shutdown.abort(new Error(`Received ${signal}.`));
|
|
10
|
+
};
|
|
11
|
+
const onSigInt = () => requestShutdown(130, "SIGINT");
|
|
12
|
+
const onSigTerm = () => requestShutdown(143, "SIGTERM");
|
|
13
|
+
process.once("SIGINT", onSigInt);
|
|
14
|
+
process.once("SIGTERM", onSigTerm);
|
|
15
|
+
try {
|
|
16
|
+
const { formatResult, signal, ...runOptions } = options;
|
|
17
|
+
const runSignal = signal ? AbortSignal.any([signal, shutdown.signal]) : shutdown.signal;
|
|
18
|
+
const result = await run(graph, initial, {
|
|
19
|
+
...runOptions,
|
|
20
|
+
signal: runSignal,
|
|
21
|
+
presentation: "terminal",
|
|
22
|
+
});
|
|
23
|
+
pipelineCompleted = true;
|
|
24
|
+
const formatted = await formatResult(result);
|
|
25
|
+
await write(process.stdout, `${formatted}\n`);
|
|
26
|
+
exitCode = result.succeeded ? 0 : 1;
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (signalExitCode === null) {
|
|
30
|
+
const prefix = pipelineCompleted ? "Pipeline completed, but result output failed: " : "";
|
|
31
|
+
await write(process.stderr, `${prefix}${formatError(error)}\n`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
process.removeListener("SIGINT", onSigInt);
|
|
36
|
+
process.removeListener("SIGTERM", onSigTerm);
|
|
37
|
+
process.exitCode = signalExitCode ?? exitCode;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function formatError(error, seen = new Set()) {
|
|
41
|
+
if (!(error instanceof Error)) {
|
|
42
|
+
return String(error);
|
|
43
|
+
}
|
|
44
|
+
if (seen.has(error)) {
|
|
45
|
+
return error.stack ?? `${error.name}: ${error.message}`;
|
|
46
|
+
}
|
|
47
|
+
seen.add(error);
|
|
48
|
+
const stack = error.stack;
|
|
49
|
+
const detail = stack?.startsWith(`${error.name}: `)
|
|
50
|
+
? stack.slice(error.name.length + 2)
|
|
51
|
+
: (stack ?? error.message);
|
|
52
|
+
if (error.cause === undefined) {
|
|
53
|
+
return detail;
|
|
54
|
+
}
|
|
55
|
+
const cause = formatError(error.cause, seen);
|
|
56
|
+
return detail.includes(cause) ? detail : `${detail}\nCaused by: ${cause}`;
|
|
57
|
+
}
|
|
58
|
+
function write(stream, value) {
|
|
59
|
+
return new Promise((resolve, reject) => stream.write(value, (error) => (error ? reject(error) : resolve())));
|
|
60
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
type SyncCallback = (state: string, input: string) => string;
|
|
3
|
+
type AsyncCallback = (state: string, input: string, signal: AbortSignal) => Promise<string>;
|
|
4
|
+
declare const participantBrand: unique symbol;
|
|
5
|
+
declare const compileCapabilityBrand: unique symbol;
|
|
6
|
+
declare const interactionHandlersBrand: unique symbol;
|
|
7
|
+
declare const workspaceBrand: unique symbol;
|
|
8
|
+
declare const toolGroupBrand: unique symbol;
|
|
9
|
+
declare const commandSelectionBrand: unique symbol;
|
|
10
|
+
export declare class TandemError extends Error {
|
|
11
|
+
constructor(message: string, options?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
export declare class TandemRuntimeError extends TandemError {
|
|
14
|
+
readonly operation: "run" | "inspect";
|
|
15
|
+
constructor(operation: "run" | "inspect", cause: unknown);
|
|
16
|
+
}
|
|
17
|
+
export declare class TandemCancellationError extends TandemRuntimeError {
|
|
18
|
+
constructor(cause: unknown);
|
|
19
|
+
}
|
|
20
|
+
export declare class ContractValidationError extends TandemError {
|
|
21
|
+
readonly boundary: string;
|
|
22
|
+
readonly problems: readonly ValidationProblem[];
|
|
23
|
+
constructor(boundary: string, problems: readonly ValidationProblem[]);
|
|
24
|
+
}
|
|
25
|
+
export type ValidationProblem = {
|
|
26
|
+
readonly path: string;
|
|
27
|
+
readonly message: string;
|
|
28
|
+
};
|
|
29
|
+
declare class CallbackRegistry {
|
|
30
|
+
#private;
|
|
31
|
+
registerSync(callback: SyncCallback): string;
|
|
32
|
+
registerAsync(callback: AsyncCallback): string;
|
|
33
|
+
invokeSync(id: string, state: string, input: string): string;
|
|
34
|
+
invokeAsync(id: string, state: string, input: string, signal: AbortSignal): Promise<string>;
|
|
35
|
+
dispose(): void;
|
|
36
|
+
}
|
|
37
|
+
interface Participant<TState> {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly [participantBrand]: (state: TState) => TState;
|
|
40
|
+
}
|
|
41
|
+
export interface Stage<TState> extends Participant<TState> {
|
|
42
|
+
readonly kind: "stage";
|
|
43
|
+
}
|
|
44
|
+
export interface Interaction<TState, TRequest, TResponse> extends Participant<TState> {
|
|
45
|
+
readonly kind: "interaction";
|
|
46
|
+
readonly requestType?: TRequest;
|
|
47
|
+
readonly responseType?: TResponse;
|
|
48
|
+
}
|
|
49
|
+
export interface Agent<TState> extends Participant<TState> {
|
|
50
|
+
readonly kind: "agent";
|
|
51
|
+
}
|
|
52
|
+
export interface Parallel<TState> extends Participant<TState> {
|
|
53
|
+
readonly kind: "parallel";
|
|
54
|
+
}
|
|
55
|
+
export interface Terminal<TState> extends Participant<TState> {
|
|
56
|
+
readonly kind: "terminal";
|
|
57
|
+
}
|
|
58
|
+
type Node<TState> = Stage<TState> | Interaction<TState, unknown, unknown> | Agent<TState> | Parallel<TState> | Terminal<TState>;
|
|
59
|
+
export declare function stage<TState>(definition: {
|
|
60
|
+
id: string;
|
|
61
|
+
execute: (state: TState, context: {
|
|
62
|
+
readonly signal: AbortSignal;
|
|
63
|
+
}) => TState | Promise<TState>;
|
|
64
|
+
persist?: boolean;
|
|
65
|
+
}): Stage<TState>;
|
|
66
|
+
export declare function interaction<TState, TRequest, TResponse>(definition: {
|
|
67
|
+
id: string;
|
|
68
|
+
requestSchema: z.ZodType<TRequest>;
|
|
69
|
+
responseSchema: z.ZodType<TResponse>;
|
|
70
|
+
request: (state: TState) => TRequest;
|
|
71
|
+
apply: (state: TState, response: TResponse) => TState;
|
|
72
|
+
persist?: boolean;
|
|
73
|
+
}): Interaction<TState, TRequest, TResponse>;
|
|
74
|
+
type InteractionHandler<TRequest, TResponse> = (request: TRequest, context: {
|
|
75
|
+
readonly signal: AbortSignal;
|
|
76
|
+
}) => TResponse | Promise<TResponse>;
|
|
77
|
+
export interface InteractionHandlers {
|
|
78
|
+
handle<TState, TRequest, TResponse>(interaction: Interaction<TState, TRequest, TResponse>, handler: InteractionHandler<TRequest, TResponse>): InteractionHandlers;
|
|
79
|
+
readonly [interactionHandlersBrand]: true;
|
|
80
|
+
}
|
|
81
|
+
export declare function interactions(): InteractionHandlers;
|
|
82
|
+
interface CapabilityCompileContext<TState> {
|
|
83
|
+
readonly id: string;
|
|
84
|
+
readonly stateSchema: z.ZodType<TState>;
|
|
85
|
+
readonly callbacks: CallbackRegistry;
|
|
86
|
+
}
|
|
87
|
+
export interface Capability<TState> {
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly [compileCapabilityBrand]: (context: CapabilityCompileContext<TState>) => object;
|
|
90
|
+
}
|
|
91
|
+
export declare function capability<TState, TRequest>(definition: {
|
|
92
|
+
readonly name: string;
|
|
93
|
+
readonly instructions: string;
|
|
94
|
+
readonly schema: z.ZodType<TRequest>;
|
|
95
|
+
readonly validateFor?: (state: TState, request: TRequest) => readonly ValidationProblem[];
|
|
96
|
+
readonly apply: (state: TState, request: TRequest) => TState;
|
|
97
|
+
readonly summarize: (request: TRequest) => string;
|
|
98
|
+
}): Capability<TState>;
|
|
99
|
+
export interface OpenAiCompatibleChatClient {
|
|
100
|
+
readonly kind: "openai-compatible";
|
|
101
|
+
readonly version: 1;
|
|
102
|
+
readonly endpoint: string;
|
|
103
|
+
readonly model: string;
|
|
104
|
+
readonly wireApi: "completions" | "responses";
|
|
105
|
+
readonly apiKeyEnvironmentVariable?: string;
|
|
106
|
+
readonly verifyModel?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export type ChatClient = OpenAiCompatibleChatClient;
|
|
109
|
+
export type AgentReasoning = {
|
|
110
|
+
readonly effort: "none" | "low" | "medium" | "high";
|
|
111
|
+
readonly maxTokens?: never;
|
|
112
|
+
} | {
|
|
113
|
+
readonly maxTokens: number;
|
|
114
|
+
readonly effort?: never;
|
|
115
|
+
};
|
|
116
|
+
export interface AgentSkill {
|
|
117
|
+
readonly directory: string;
|
|
118
|
+
}
|
|
119
|
+
export type AgentToolName = "read_file" | "ls" | "grep" | "write_file" | "delete_file" | "replace" | "replace_lines" | "git:ro" | "shell" | "web_search" | "web_fetch";
|
|
120
|
+
interface AgentCommandArgumentBase {
|
|
121
|
+
readonly name: string;
|
|
122
|
+
readonly description: string;
|
|
123
|
+
readonly flag: string;
|
|
124
|
+
readonly maxLength?: number;
|
|
125
|
+
}
|
|
126
|
+
export type AgentCommandArgument = AgentCommandArgumentBase & ({
|
|
127
|
+
readonly pattern: string;
|
|
128
|
+
readonly allowedValues?: never;
|
|
129
|
+
} | {
|
|
130
|
+
readonly allowedValues: readonly string[];
|
|
131
|
+
readonly pattern?: never;
|
|
132
|
+
});
|
|
133
|
+
export interface AgentCommand {
|
|
134
|
+
readonly name: string;
|
|
135
|
+
readonly description: string;
|
|
136
|
+
readonly command: string;
|
|
137
|
+
readonly arguments?: readonly AgentCommandArgument[];
|
|
138
|
+
}
|
|
139
|
+
interface AgentCommandSelection {
|
|
140
|
+
readonly [commandSelectionBrand]: object;
|
|
141
|
+
}
|
|
142
|
+
type AgentToolSelection = AgentToolName | AgentCommandSelection;
|
|
143
|
+
export interface AgentToolGroup<TState> {
|
|
144
|
+
readonly [toolGroupBrand]: (state: TState) => boolean;
|
|
145
|
+
}
|
|
146
|
+
export type AgentToolEffect = "read" | "workspaceMutation" | "processExecution" | "lifecycleTransition" | "unclassified";
|
|
147
|
+
export interface AgentToolInvocation {
|
|
148
|
+
readonly name: string;
|
|
149
|
+
readonly effect: AgentToolEffect;
|
|
150
|
+
readonly arguments: unknown;
|
|
151
|
+
}
|
|
152
|
+
export type AgentToolInterceptor<TState> = (state: TState, invocation: AgentToolInvocation, context: {
|
|
153
|
+
readonly signal: AbortSignal;
|
|
154
|
+
}) => string | null | Promise<string | null>;
|
|
155
|
+
export declare const agentTools: {
|
|
156
|
+
always: (...tools: readonly AgentToolSelection[]) => AgentToolGroup<never>;
|
|
157
|
+
when: <TState>(predicate: (state: TState) => boolean, ...tools: readonly AgentToolSelection[]) => AgentToolGroup<TState>;
|
|
158
|
+
};
|
|
159
|
+
export interface AgentWorkspaceConfiguration<TState> {
|
|
160
|
+
readonly [workspaceBrand]: (state: TState) => TState;
|
|
161
|
+
}
|
|
162
|
+
export interface AgentWorkspace<TState> {
|
|
163
|
+
readonly commands: AgentCommandSelection;
|
|
164
|
+
withTools(groups: readonly (AgentToolGroup<TState> | AgentToolGroup<never>)[], options?: {
|
|
165
|
+
readonly interceptTool?: AgentToolInterceptor<TState>;
|
|
166
|
+
}): AgentWorkspaceConfiguration<TState>;
|
|
167
|
+
}
|
|
168
|
+
export declare function agentWorkspace<TState>(definition: {
|
|
169
|
+
readonly path: (state: TState) => string;
|
|
170
|
+
readonly commands?: readonly AgentCommand[] | ((state: TState) => readonly AgentCommand[]);
|
|
171
|
+
}): AgentWorkspace<TState>;
|
|
172
|
+
export declare function skill(definition: {
|
|
173
|
+
readonly directory: string;
|
|
174
|
+
}): AgentSkill;
|
|
175
|
+
export interface AgentDefinition<TState, TOutput = never> {
|
|
176
|
+
readonly id: string;
|
|
177
|
+
readonly instructions: string;
|
|
178
|
+
readonly client: ChatClient;
|
|
179
|
+
readonly message: (state: TState) => string;
|
|
180
|
+
readonly output?: {
|
|
181
|
+
readonly instructions: string;
|
|
182
|
+
readonly schema: z.ZodType<TOutput>;
|
|
183
|
+
readonly validateFor?: (state: TState, output: TOutput) => readonly ValidationProblem[];
|
|
184
|
+
readonly apply: (state: TState, output: TOutput) => TState;
|
|
185
|
+
};
|
|
186
|
+
readonly capabilities?: readonly Capability<TState>[];
|
|
187
|
+
readonly skills?: readonly AgentSkill[];
|
|
188
|
+
readonly workspace?: AgentWorkspaceConfiguration<TState>;
|
|
189
|
+
readonly temperature?: number;
|
|
190
|
+
readonly maxOutputTokens?: number;
|
|
191
|
+
readonly reasoning?: AgentReasoning;
|
|
192
|
+
readonly continueSession?: boolean;
|
|
193
|
+
readonly checkpoint?: {
|
|
194
|
+
readonly contextWindowTokens: number;
|
|
195
|
+
readonly maxOutputTokens: number;
|
|
196
|
+
readonly checkpointAtPercent: number;
|
|
197
|
+
readonly capability: Capability<TState>;
|
|
198
|
+
readonly instructions: string;
|
|
199
|
+
readonly message: (state: TState, currentContextTokens: number) => string;
|
|
200
|
+
readonly session?: "retain" | "reset";
|
|
201
|
+
readonly disableCompaction?: boolean;
|
|
202
|
+
};
|
|
203
|
+
readonly timeoutMs?: number;
|
|
204
|
+
readonly persist?: boolean;
|
|
205
|
+
}
|
|
206
|
+
export declare function agent<TState, TOutput = never>(definition: AgentDefinition<TState, TOutput>): Agent<TState>;
|
|
207
|
+
type ParallelBranches<TState> = Readonly<Record<string, Stage<TState> | Agent<TState>>>;
|
|
208
|
+
type ParallelDefinition<TState, TBranches extends ParallelBranches<TState>> = {
|
|
209
|
+
readonly id: string;
|
|
210
|
+
readonly branches: TBranches;
|
|
211
|
+
readonly merge: (baseline: TState, results: {
|
|
212
|
+
readonly [K in keyof TBranches]: TState;
|
|
213
|
+
}) => TState;
|
|
214
|
+
readonly persist?: boolean;
|
|
215
|
+
};
|
|
216
|
+
export declare function parallel<TState>(): <const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>) => Parallel<TState>;
|
|
217
|
+
export declare function parallel<TState, const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>): Parallel<TState>;
|
|
218
|
+
export declare function output<TState>(definition: {
|
|
219
|
+
id: string;
|
|
220
|
+
summary: (state: TState) => string;
|
|
221
|
+
failed?: boolean;
|
|
222
|
+
persist?: boolean;
|
|
223
|
+
}): Terminal<TState>;
|
|
224
|
+
export interface OrdinaryRoute<TState> {
|
|
225
|
+
readonly from: Stage<TState> | Interaction<TState, unknown, unknown>;
|
|
226
|
+
readonly to: Node<TState>;
|
|
227
|
+
readonly label: string;
|
|
228
|
+
readonly outcome?: never;
|
|
229
|
+
readonly when?: (state: TState) => boolean;
|
|
230
|
+
}
|
|
231
|
+
export interface StandardOutcomeRoute<TState> {
|
|
232
|
+
readonly from: Agent<TState> | Parallel<TState>;
|
|
233
|
+
readonly to: Node<TState>;
|
|
234
|
+
readonly label: string;
|
|
235
|
+
readonly outcome: "success" | "failed";
|
|
236
|
+
readonly when?: (state: TState) => boolean;
|
|
237
|
+
}
|
|
238
|
+
export type Route<TState> = OrdinaryRoute<TState> | StandardOutcomeRoute<TState>;
|
|
239
|
+
export declare function route<TState>(definition: OrdinaryRoute<TState>): OrdinaryRoute<TState>;
|
|
240
|
+
export declare function route<TState>(definition: StandardOutcomeRoute<TState>): StandardOutcomeRoute<TState>;
|
|
241
|
+
export interface Pipeline<TState> {
|
|
242
|
+
readonly name: string;
|
|
243
|
+
readonly state: z.ZodType<TState>;
|
|
244
|
+
readonly nodes: readonly Node<TState>[];
|
|
245
|
+
readonly start: Exclude<Node<TState>, Terminal<TState>>;
|
|
246
|
+
readonly routes: readonly Route<TState>[];
|
|
247
|
+
readonly outputs: readonly Terminal<TState>[];
|
|
248
|
+
readonly persist: boolean;
|
|
249
|
+
}
|
|
250
|
+
export declare function pipeline<TState>(definition: {
|
|
251
|
+
name: string;
|
|
252
|
+
state: z.ZodType<TState>;
|
|
253
|
+
nodes: readonly Node<NoInfer<TState>>[];
|
|
254
|
+
start: Exclude<Node<NoInfer<TState>>, Terminal<NoInfer<TState>>>;
|
|
255
|
+
routes: readonly Route<NoInfer<TState>>[];
|
|
256
|
+
outputs: readonly Terminal<NoInfer<TState>>[];
|
|
257
|
+
persist?: boolean;
|
|
258
|
+
}): Pipeline<TState>;
|
|
259
|
+
export interface RunResult<TState> {
|
|
260
|
+
readonly runId: string;
|
|
261
|
+
readonly succeeded: boolean;
|
|
262
|
+
readonly state: TState;
|
|
263
|
+
readonly summary: string | null;
|
|
264
|
+
}
|
|
265
|
+
export type RunObservation = {
|
|
266
|
+
readonly version: 1;
|
|
267
|
+
readonly kind: "stepStarted";
|
|
268
|
+
readonly stepId: string;
|
|
269
|
+
} | {
|
|
270
|
+
readonly version: 1;
|
|
271
|
+
readonly kind: "stepCompleted";
|
|
272
|
+
readonly stepId: string;
|
|
273
|
+
} | {
|
|
274
|
+
readonly version: 1;
|
|
275
|
+
readonly kind: "stepCancelled";
|
|
276
|
+
readonly stepId: string;
|
|
277
|
+
} | {
|
|
278
|
+
readonly version: 1;
|
|
279
|
+
readonly kind: "stepFaulted";
|
|
280
|
+
readonly stepId: string;
|
|
281
|
+
readonly error: string;
|
|
282
|
+
} | {
|
|
283
|
+
readonly version: 1;
|
|
284
|
+
readonly kind: "agentText";
|
|
285
|
+
readonly stepId: string;
|
|
286
|
+
readonly text: string;
|
|
287
|
+
} | {
|
|
288
|
+
readonly version: 1;
|
|
289
|
+
readonly kind: "agentReasoning";
|
|
290
|
+
readonly stepId: string;
|
|
291
|
+
readonly text: string;
|
|
292
|
+
} | {
|
|
293
|
+
readonly version: 1;
|
|
294
|
+
readonly kind: "agentModelSelected";
|
|
295
|
+
readonly stepId: string;
|
|
296
|
+
readonly modelId: string;
|
|
297
|
+
} | {
|
|
298
|
+
readonly version: 1;
|
|
299
|
+
readonly kind: "agentUsage";
|
|
300
|
+
readonly stepId: string;
|
|
301
|
+
readonly inputTokens: number;
|
|
302
|
+
readonly outputTokens: number;
|
|
303
|
+
readonly reasoningTokens: number;
|
|
304
|
+
readonly currentContextTokens: number;
|
|
305
|
+
readonly contextWindowTokens: number | null;
|
|
306
|
+
} | {
|
|
307
|
+
readonly version: 1;
|
|
308
|
+
readonly kind: "structuredOutputRejected";
|
|
309
|
+
readonly stepId: string;
|
|
310
|
+
readonly attempt: number;
|
|
311
|
+
readonly problems: readonly {
|
|
312
|
+
readonly field: string;
|
|
313
|
+
readonly message: string;
|
|
314
|
+
}[];
|
|
315
|
+
readonly rawResponse: string;
|
|
316
|
+
};
|
|
317
|
+
export interface TerminalPresentationOptions {
|
|
318
|
+
readonly truncatedToolNames?: readonly string[];
|
|
319
|
+
}
|
|
320
|
+
export interface RunOptions {
|
|
321
|
+
readonly ledgerPath?: string;
|
|
322
|
+
readonly signal?: AbortSignal;
|
|
323
|
+
readonly interactions?: InteractionHandlers;
|
|
324
|
+
readonly presentation?: "terminal";
|
|
325
|
+
readonly terminal?: TerminalPresentationOptions;
|
|
326
|
+
readonly observe?: (event: RunObservation, context: {
|
|
327
|
+
readonly signal: AbortSignal;
|
|
328
|
+
}) => void | Promise<void>;
|
|
329
|
+
}
|
|
330
|
+
declare const acceptedKinds: readonly ["StructuredOutputAccepted", "CapabilityAccepted", "InteractionRequested", "InteractionAnswered", "StepCompleted"];
|
|
331
|
+
type AcceptedKind = (typeof acceptedKinds)[number];
|
|
332
|
+
export type AcceptedValue = {
|
|
333
|
+
[K in AcceptedKind]: {
|
|
334
|
+
readonly version: 1;
|
|
335
|
+
readonly kind: K;
|
|
336
|
+
readonly stepId: string;
|
|
337
|
+
readonly valueType: string | null;
|
|
338
|
+
readonly payload: unknown | null;
|
|
339
|
+
};
|
|
340
|
+
}[AcceptedKind];
|
|
341
|
+
export declare function inspectAccepted(options: {
|
|
342
|
+
ledgerPath: string;
|
|
343
|
+
runId: string;
|
|
344
|
+
}): Promise<readonly AcceptedValue[]>;
|
|
345
|
+
export declare function run<TState>(graph: Pipeline<TState>, initial: unknown, options?: RunOptions): Promise<RunResult<TState>>;
|
|
346
|
+
export {};
|