@maxanstey-meridian/tandem 0.1.1 → 0.1.2
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/dist/cli.d.ts +5 -0
- package/dist/cli.js +60 -0
- package/dist/index.d.ts +389 -0
- package/dist/index.js +1346 -0
- package/dist/runtime/FluentValidation.dll +0 -0
- package/dist/runtime/Google.Protobuf.dll +0 -0
- package/dist/runtime/Microsoft.Agents.AI.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Agents.AI.Harness.dll +0 -0
- package/dist/runtime/Microsoft.Agents.AI.Tools.Shell.dll +0 -0
- package/dist/runtime/Microsoft.Agents.AI.Workflows.dll +0 -0
- package/dist/runtime/Microsoft.Agents.AI.dll +0 -0
- package/dist/runtime/Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/dist/runtime/Microsoft.CodeAnalysis.dll +0 -0
- package/dist/runtime/Microsoft.Data.Sqlite.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.AI.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.AI.Evaluation.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.AI.OpenAI.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.AI.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Caching.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Compliance.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Configuration.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.DependencyInjection.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Diagnostics.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.FileProviders.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.FileSystemGlobbing.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Hosting.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Logging.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.ObjectPool.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Options.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.Primitives.dll +0 -0
- package/dist/runtime/Microsoft.Extensions.VectorData.Abstractions.dll +0 -0
- package/dist/runtime/Microsoft.JavaScript.NodeApi.dll +0 -0
- package/dist/runtime/Microsoft.ML.Tokenizers.dll +0 -0
- package/dist/runtime/OpenAI.dll +0 -0
- package/dist/runtime/OpenTelemetry.Api.dll +0 -0
- package/dist/runtime/SQLitePCLRaw.batteries_v2.dll +0 -0
- package/dist/runtime/SQLitePCLRaw.core.dll +0 -0
- package/dist/runtime/SQLitePCLRaw.provider.e_sqlite3.dll +0 -0
- package/dist/runtime/Spectre.Console.Ansi.dll +0 -0
- package/dist/runtime/Spectre.Console.dll +0 -0
- package/dist/runtime/System.ClientModel.dll +0 -0
- package/dist/runtime/System.Memory.Data.dll +0 -0
- package/dist/runtime/System.Numerics.Tensors.dll +0 -0
- package/dist/runtime/System.Reflection.MetadataLoadContext.dll +0 -0
- package/dist/runtime/Tandem.Advanced.dll +0 -0
- package/dist/runtime/Tandem.Ledger.dll +0 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.cjs +26 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.d.ts +23 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.deps.json +1097 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.dll +0 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.mjs +31 -0
- package/dist/runtime/Tandem.NodeApiSpike.Bridge.runtimeconfig.json +13 -0
- package/dist/runtime/Tandem.OpenAICompatible.dll +0 -0
- package/dist/runtime/Tandem.Terminal.dll +0 -0
- package/dist/runtime/Tandem.dll +0 -0
- package/dist/runtime/libe_sqlite3.dylib +0 -0
- package/dist/runtime/loader.d.mts +10 -0
- package/dist/runtime/loader.mjs +35 -0
- package/package.json +4 -3
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,389 @@
|
|
|
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
|
+
/** Per-attempt transport limits; omitted preserves provider defaults. */
|
|
108
|
+
readonly requestTimeoutMs?: number;
|
|
109
|
+
readonly idleTimeoutMs?: number;
|
|
110
|
+
readonly maxAttempts?: number;
|
|
111
|
+
}
|
|
112
|
+
export type ChatClient = OpenAiCompatibleChatClient;
|
|
113
|
+
export type AgentReasoning = {
|
|
114
|
+
readonly effort: "none" | "low" | "medium" | "high";
|
|
115
|
+
readonly maxTokens?: never;
|
|
116
|
+
} | {
|
|
117
|
+
readonly maxTokens: number;
|
|
118
|
+
readonly effort?: never;
|
|
119
|
+
};
|
|
120
|
+
export interface AgentSkill {
|
|
121
|
+
readonly directory: string;
|
|
122
|
+
}
|
|
123
|
+
export type AgentToolName = "read_file" | "ls" | "grep" | "write_file" | "delete_file" | "replace" | "replace_lines" | "git:ro" | "shell" | "web_search" | "web_fetch";
|
|
124
|
+
export interface AgentCommand {
|
|
125
|
+
readonly name: string;
|
|
126
|
+
readonly description: string;
|
|
127
|
+
readonly command: string;
|
|
128
|
+
readonly arguments?: readonly string[];
|
|
129
|
+
}
|
|
130
|
+
interface AgentCommandSelection {
|
|
131
|
+
readonly [commandSelectionBrand]: object;
|
|
132
|
+
}
|
|
133
|
+
type AgentToolSelection = AgentToolName | AgentCommandSelection;
|
|
134
|
+
export interface AgentToolGroup<TState> {
|
|
135
|
+
readonly [toolGroupBrand]: (state: TState) => boolean;
|
|
136
|
+
}
|
|
137
|
+
export type AgentToolEffect = "read" | "workspaceMutation" | "processExecution" | "lifecycleTransition" | "unclassified";
|
|
138
|
+
export interface AgentToolInvocation {
|
|
139
|
+
readonly name: string;
|
|
140
|
+
readonly effect: AgentToolEffect;
|
|
141
|
+
readonly arguments: unknown;
|
|
142
|
+
}
|
|
143
|
+
export type AgentToolInterceptor<TState> = (state: TState, invocation: AgentToolInvocation, context: {
|
|
144
|
+
readonly signal: AbortSignal;
|
|
145
|
+
}) => string | null | Promise<string | null>;
|
|
146
|
+
export declare const agentTools: {
|
|
147
|
+
always: (...tools: readonly AgentToolSelection[]) => AgentToolGroup<never>;
|
|
148
|
+
when: <TState>(predicate: (state: TState) => boolean, ...tools: readonly AgentToolSelection[]) => AgentToolGroup<TState>;
|
|
149
|
+
};
|
|
150
|
+
export interface AgentWorkspaceConfiguration<TState> {
|
|
151
|
+
readonly [workspaceBrand]: (state: TState) => TState;
|
|
152
|
+
}
|
|
153
|
+
export interface AgentWorkspace<TState> {
|
|
154
|
+
readonly commands: AgentCommandSelection;
|
|
155
|
+
withTools(groups: readonly (AgentToolGroup<TState> | AgentToolGroup<never>)[], options?: {
|
|
156
|
+
readonly interceptTool?: AgentToolInterceptor<TState>;
|
|
157
|
+
}): AgentWorkspaceConfiguration<TState>;
|
|
158
|
+
}
|
|
159
|
+
export declare function agentWorkspace<TState>(definition: {
|
|
160
|
+
readonly path: (state: TState) => string;
|
|
161
|
+
readonly commands?: readonly AgentCommand[] | ((state: TState) => readonly AgentCommand[]);
|
|
162
|
+
}): AgentWorkspace<TState>;
|
|
163
|
+
export declare function skill(definition: {
|
|
164
|
+
readonly directory: string;
|
|
165
|
+
}): AgentSkill;
|
|
166
|
+
export interface AgentDefinition<TState, TOutput = never> {
|
|
167
|
+
readonly id: string;
|
|
168
|
+
readonly instructions: string;
|
|
169
|
+
readonly client: ChatClient;
|
|
170
|
+
readonly message: (state: TState) => string;
|
|
171
|
+
readonly output?: {
|
|
172
|
+
readonly instructions: string;
|
|
173
|
+
readonly schema: z.ZodType<TOutput>;
|
|
174
|
+
readonly validateFor?: (state: TState, output: TOutput) => readonly ValidationProblem[];
|
|
175
|
+
readonly apply: (state: TState, output: TOutput) => TState;
|
|
176
|
+
} | {
|
|
177
|
+
readonly instructions: string;
|
|
178
|
+
readonly raw: true;
|
|
179
|
+
readonly parse: (response: string) => TOutput;
|
|
180
|
+
readonly validateFor?: (state: TState, output: TOutput) => readonly ValidationProblem[];
|
|
181
|
+
readonly apply: (state: TState, output: TOutput) => TState;
|
|
182
|
+
};
|
|
183
|
+
readonly capabilities?: readonly Capability<TState>[];
|
|
184
|
+
readonly skills?: readonly AgentSkill[];
|
|
185
|
+
readonly workspace?: AgentWorkspaceConfiguration<TState>;
|
|
186
|
+
readonly temperature?: number;
|
|
187
|
+
readonly maxOutputTokens?: number;
|
|
188
|
+
readonly reasoning?: AgentReasoning;
|
|
189
|
+
readonly continueSession?: boolean;
|
|
190
|
+
readonly checkpoint?: {
|
|
191
|
+
readonly contextWindowTokens: number;
|
|
192
|
+
readonly maxOutputTokens: number;
|
|
193
|
+
readonly checkpointAtPercent: number;
|
|
194
|
+
readonly capability: Capability<TState>;
|
|
195
|
+
readonly instructions: string;
|
|
196
|
+
readonly message: (state: TState, currentContextTokens: number) => string;
|
|
197
|
+
readonly session?: "retain" | "reset";
|
|
198
|
+
readonly disableCompaction?: boolean;
|
|
199
|
+
};
|
|
200
|
+
readonly timeoutMs?: number;
|
|
201
|
+
readonly persist?: boolean;
|
|
202
|
+
}
|
|
203
|
+
export declare function agent<TState, TOutput = never>(definition: AgentDefinition<TState, TOutput>): Agent<TState>;
|
|
204
|
+
type ParallelBranches<TState> = Readonly<Record<string, Stage<TState> | Agent<TState>>>;
|
|
205
|
+
type ParallelDefinition<TState, TBranches extends ParallelBranches<TState>> = {
|
|
206
|
+
readonly id: string;
|
|
207
|
+
readonly branches: TBranches;
|
|
208
|
+
readonly merge: (baseline: TState, results: {
|
|
209
|
+
readonly [K in keyof TBranches]: TState;
|
|
210
|
+
}) => TState;
|
|
211
|
+
/** Maximum active branches per invocation; omitted means all branches. */
|
|
212
|
+
readonly max?: number;
|
|
213
|
+
readonly persist?: boolean;
|
|
214
|
+
};
|
|
215
|
+
export declare function parallel<TState>(): <const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>) => Parallel<TState>;
|
|
216
|
+
export declare function parallel<TState, const TBranches extends ParallelBranches<TState>>(definition: ParallelDefinition<TState, TBranches>): Parallel<TState>;
|
|
217
|
+
export declare function output<TState>(definition: {
|
|
218
|
+
id: string;
|
|
219
|
+
summary: (state: TState) => string;
|
|
220
|
+
failed?: boolean;
|
|
221
|
+
persist?: boolean;
|
|
222
|
+
}): Terminal<TState>;
|
|
223
|
+
export interface OrdinaryRoute<TState> {
|
|
224
|
+
readonly from: Stage<TState> | Interaction<TState, unknown, unknown>;
|
|
225
|
+
readonly to: Node<TState>;
|
|
226
|
+
readonly label: string;
|
|
227
|
+
readonly outcome?: never;
|
|
228
|
+
readonly when?: (state: TState) => boolean;
|
|
229
|
+
}
|
|
230
|
+
export interface StandardOutcomeRoute<TState> {
|
|
231
|
+
readonly from: Agent<TState> | Parallel<TState>;
|
|
232
|
+
readonly to: Node<TState>;
|
|
233
|
+
readonly label: string;
|
|
234
|
+
readonly outcome: "success" | "failed";
|
|
235
|
+
readonly when?: (state: TState) => boolean;
|
|
236
|
+
}
|
|
237
|
+
export type Route<TState> = OrdinaryRoute<TState> | StandardOutcomeRoute<TState>;
|
|
238
|
+
export declare function route<TState>(definition: OrdinaryRoute<TState>): OrdinaryRoute<TState>;
|
|
239
|
+
export declare function route<TState>(definition: StandardOutcomeRoute<TState>): StandardOutcomeRoute<TState>;
|
|
240
|
+
export interface Pipeline<TState> {
|
|
241
|
+
readonly name: string;
|
|
242
|
+
readonly state: z.ZodType<TState>;
|
|
243
|
+
readonly nodes: readonly Node<TState>[];
|
|
244
|
+
readonly start: Exclude<Node<TState>, Terminal<TState>>;
|
|
245
|
+
readonly routes: readonly Route<TState>[];
|
|
246
|
+
readonly outputs: readonly Terminal<TState>[];
|
|
247
|
+
readonly persist: boolean;
|
|
248
|
+
}
|
|
249
|
+
export declare function pipeline<TState>(definition: {
|
|
250
|
+
name: string;
|
|
251
|
+
state: z.ZodType<TState>;
|
|
252
|
+
nodes: readonly Node<NoInfer<TState>>[];
|
|
253
|
+
start: Exclude<Node<NoInfer<TState>>, Terminal<NoInfer<TState>>>;
|
|
254
|
+
routes: readonly Route<NoInfer<TState>>[];
|
|
255
|
+
outputs: readonly Terminal<NoInfer<TState>>[];
|
|
256
|
+
persist?: boolean;
|
|
257
|
+
}): Pipeline<TState>;
|
|
258
|
+
export interface PipelineInspection {
|
|
259
|
+
readonly name: string;
|
|
260
|
+
readonly stateSchema: unknown;
|
|
261
|
+
readonly start: string;
|
|
262
|
+
readonly persist: boolean;
|
|
263
|
+
readonly nodes: readonly InspectedNode[];
|
|
264
|
+
readonly routes: readonly InspectedRoute[];
|
|
265
|
+
readonly outputs: readonly string[];
|
|
266
|
+
}
|
|
267
|
+
export interface InspectedRoute {
|
|
268
|
+
readonly id: string;
|
|
269
|
+
readonly source: string;
|
|
270
|
+
readonly target: string;
|
|
271
|
+
readonly label: string;
|
|
272
|
+
readonly order: number;
|
|
273
|
+
readonly outcome?: "success" | "failed";
|
|
274
|
+
readonly conditional: boolean;
|
|
275
|
+
}
|
|
276
|
+
export interface InspectedNode {
|
|
277
|
+
readonly id: string;
|
|
278
|
+
readonly kind: "stage" | "interaction" | "agent" | "parallel" | "completion" | "failure";
|
|
279
|
+
readonly persist?: boolean;
|
|
280
|
+
readonly interaction?: {
|
|
281
|
+
readonly requestSchema: unknown;
|
|
282
|
+
readonly responseSchema: unknown;
|
|
283
|
+
};
|
|
284
|
+
readonly agent?: {
|
|
285
|
+
readonly capabilities: readonly {
|
|
286
|
+
readonly name: string;
|
|
287
|
+
readonly requestSchema: unknown;
|
|
288
|
+
}[];
|
|
289
|
+
readonly outputSchema?: unknown;
|
|
290
|
+
readonly workspace: boolean;
|
|
291
|
+
};
|
|
292
|
+
readonly max?: number;
|
|
293
|
+
readonly branches?: readonly {
|
|
294
|
+
readonly id: string;
|
|
295
|
+
readonly participant: InspectedNode;
|
|
296
|
+
}[];
|
|
297
|
+
}
|
|
298
|
+
/** Projects an instantiated pipeline without compiling, registering, or invoking callbacks. */
|
|
299
|
+
export declare function inspectPipeline<TState>(graph: Pipeline<TState>): PipelineInspection;
|
|
300
|
+
export interface RunResult<TState> {
|
|
301
|
+
readonly runId: string;
|
|
302
|
+
readonly succeeded: boolean;
|
|
303
|
+
readonly state: TState;
|
|
304
|
+
readonly summary: string | null;
|
|
305
|
+
}
|
|
306
|
+
export type RunObservation = {
|
|
307
|
+
readonly version: 1;
|
|
308
|
+
readonly kind: "stepStarted";
|
|
309
|
+
readonly stepId: string;
|
|
310
|
+
} | {
|
|
311
|
+
readonly version: 1;
|
|
312
|
+
readonly kind: "stepCompleted";
|
|
313
|
+
readonly stepId: string;
|
|
314
|
+
} | {
|
|
315
|
+
readonly version: 1;
|
|
316
|
+
readonly kind: "stepCancelled";
|
|
317
|
+
readonly stepId: string;
|
|
318
|
+
} | {
|
|
319
|
+
readonly version: 1;
|
|
320
|
+
readonly kind: "stepFaulted";
|
|
321
|
+
readonly stepId: string;
|
|
322
|
+
readonly error: string;
|
|
323
|
+
} | {
|
|
324
|
+
readonly version: 1;
|
|
325
|
+
readonly kind: "agentText";
|
|
326
|
+
readonly stepId: string;
|
|
327
|
+
readonly text: string;
|
|
328
|
+
} | {
|
|
329
|
+
readonly version: 1;
|
|
330
|
+
readonly kind: "agentReasoning";
|
|
331
|
+
readonly stepId: string;
|
|
332
|
+
readonly text: string;
|
|
333
|
+
} | {
|
|
334
|
+
readonly version: 1;
|
|
335
|
+
readonly kind: "agentModelSelected";
|
|
336
|
+
readonly stepId: string;
|
|
337
|
+
readonly modelId: string;
|
|
338
|
+
} | {
|
|
339
|
+
readonly version: 1;
|
|
340
|
+
readonly kind: "agentUsage";
|
|
341
|
+
readonly stepId: string;
|
|
342
|
+
readonly inputTokens: number;
|
|
343
|
+
readonly outputTokens: number;
|
|
344
|
+
readonly reasoningTokens: number;
|
|
345
|
+
readonly currentContextTokens: number;
|
|
346
|
+
readonly contextWindowTokens: number | null;
|
|
347
|
+
} | {
|
|
348
|
+
readonly version: 1;
|
|
349
|
+
readonly kind: "structuredOutputRejected";
|
|
350
|
+
readonly stepId: string;
|
|
351
|
+
readonly attempt: number;
|
|
352
|
+
readonly problems: readonly {
|
|
353
|
+
readonly field: string;
|
|
354
|
+
readonly message: string;
|
|
355
|
+
}[];
|
|
356
|
+
readonly rawResponse: string;
|
|
357
|
+
};
|
|
358
|
+
export interface TerminalPresentationOptions {
|
|
359
|
+
readonly truncatedToolNames?: readonly string[];
|
|
360
|
+
}
|
|
361
|
+
export interface RunOptions {
|
|
362
|
+
readonly ledgerPath?: string;
|
|
363
|
+
/** Expose ledger read/search tools to agents. Disabled by default; does not affect logging. */
|
|
364
|
+
readonly enableLedgerTools?: boolean;
|
|
365
|
+
readonly signal?: AbortSignal;
|
|
366
|
+
readonly interactions?: InteractionHandlers;
|
|
367
|
+
readonly presentation?: "terminal";
|
|
368
|
+
readonly terminal?: TerminalPresentationOptions;
|
|
369
|
+
readonly observe?: (event: RunObservation, context: {
|
|
370
|
+
readonly signal: AbortSignal;
|
|
371
|
+
}) => void | Promise<void>;
|
|
372
|
+
}
|
|
373
|
+
declare const acceptedKinds: readonly ["StructuredOutputAccepted", "CapabilityAccepted", "InteractionRequested", "InteractionAnswered", "StepCompleted"];
|
|
374
|
+
type AcceptedKind = (typeof acceptedKinds)[number];
|
|
375
|
+
export type AcceptedValue = {
|
|
376
|
+
[K in AcceptedKind]: {
|
|
377
|
+
readonly version: 1;
|
|
378
|
+
readonly kind: K;
|
|
379
|
+
readonly stepId: string;
|
|
380
|
+
readonly valueType: string | null;
|
|
381
|
+
readonly payload: unknown | null;
|
|
382
|
+
};
|
|
383
|
+
}[AcceptedKind];
|
|
384
|
+
export declare function inspectAccepted(options: {
|
|
385
|
+
ledgerPath: string;
|
|
386
|
+
runId: string;
|
|
387
|
+
}): Promise<readonly AcceptedValue[]>;
|
|
388
|
+
export declare function run<TState>(graph: Pipeline<TState>, initial: unknown, options?: RunOptions): Promise<RunResult<TState>>;
|
|
389
|
+
export {};
|