@trailstep/core 0.1.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/LICENSE +176 -0
- package/README.md +15 -0
- package/dist/index.d.ts +629 -0
- package/dist/index.js +4654 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import { JSONSchemaType } from 'ajv/dist/ajv.js';
|
|
2
|
+
|
|
3
|
+
type WorkflowAgentSize = "default" | "tiny" | "small" | "medium" | "large" | "xl";
|
|
4
|
+
/** Provider-neutral effort/thinking level threaded into built-in provider adapters. */
|
|
5
|
+
type WorkflowAgentThinking = "low" | "medium" | "high" | "xhigh" | "max";
|
|
6
|
+
interface WorkflowAgentRole {
|
|
7
|
+
readonly description?: string;
|
|
8
|
+
readonly size: WorkflowAgentSize;
|
|
9
|
+
readonly thinking?: WorkflowAgentThinking;
|
|
10
|
+
readonly name?: string;
|
|
11
|
+
}
|
|
12
|
+
interface AgentModelTarget {
|
|
13
|
+
readonly adapterKey: string;
|
|
14
|
+
readonly model: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface RetryPolicy {
|
|
18
|
+
readonly maxAttempts: number;
|
|
19
|
+
}
|
|
20
|
+
interface RetryPolicyInput {
|
|
21
|
+
readonly maxAttempts?: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface ResolveRetryPolicyOptions {
|
|
24
|
+
readonly global?: RetryPolicyInput;
|
|
25
|
+
readonly workflow?: RetryPolicyInput;
|
|
26
|
+
readonly step?: RetryPolicyInput;
|
|
27
|
+
}
|
|
28
|
+
declare function resolveRetryPolicy(options: ResolveRetryPolicyOptions): RetryPolicy;
|
|
29
|
+
declare function validateRetryPolicy(input: RetryPolicyInput): RetryPolicy;
|
|
30
|
+
|
|
31
|
+
interface TimeoutPolicy {
|
|
32
|
+
readonly timeoutMs?: number;
|
|
33
|
+
}
|
|
34
|
+
type TimeoutPolicyInput = number;
|
|
35
|
+
interface ResolveTimeoutPolicyOptions {
|
|
36
|
+
readonly global?: TimeoutPolicyInput;
|
|
37
|
+
readonly workflow?: TimeoutPolicyInput;
|
|
38
|
+
readonly step?: TimeoutPolicyInput;
|
|
39
|
+
}
|
|
40
|
+
declare function resolveTimeoutPolicy(options: ResolveTimeoutPolicyOptions): TimeoutPolicy;
|
|
41
|
+
declare function validateTimeoutPolicy(input: unknown): TimeoutPolicy;
|
|
42
|
+
|
|
43
|
+
interface TrailStepCustomProviderConfig {
|
|
44
|
+
readonly binary: string;
|
|
45
|
+
readonly args?: readonly string[];
|
|
46
|
+
readonly interactiveArgs?: readonly string[];
|
|
47
|
+
readonly cwd?: string;
|
|
48
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
49
|
+
}
|
|
50
|
+
interface TrailStepAgentTarget {
|
|
51
|
+
/**
|
|
52
|
+
* Either a key declared in the top-level `customProviders` object, or a
|
|
53
|
+
* built-in provider registry id (e.g. `"claude"`). The registry is checked
|
|
54
|
+
* first; `customProviders` is the fallback/escape hatch.
|
|
55
|
+
*/
|
|
56
|
+
readonly provider: string;
|
|
57
|
+
readonly model?: string;
|
|
58
|
+
readonly thinking?: WorkflowAgentThinking;
|
|
59
|
+
readonly args?: readonly string[];
|
|
60
|
+
/** Undefined means bypass (per-tool confirmation is skipped by default). */
|
|
61
|
+
readonly permissionMode?: "bypass" | "prompt";
|
|
62
|
+
}
|
|
63
|
+
type TrailStepAgentMappings = Readonly<Record<string, readonly TrailStepAgentTarget[]>>;
|
|
64
|
+
interface TrailStepSettings {
|
|
65
|
+
readonly retry?: RetryPolicyInput;
|
|
66
|
+
readonly timeout?: TimeoutPolicyInput;
|
|
67
|
+
readonly [key: string]: unknown;
|
|
68
|
+
}
|
|
69
|
+
interface TrailStepWorkflowConfig {
|
|
70
|
+
readonly agents?: TrailStepAgentMappings;
|
|
71
|
+
readonly settings?: TrailStepSettings;
|
|
72
|
+
}
|
|
73
|
+
interface TrailStepConfig {
|
|
74
|
+
readonly version: 1;
|
|
75
|
+
readonly customProviders: Readonly<Record<string, TrailStepCustomProviderConfig>>;
|
|
76
|
+
readonly agents: TrailStepAgentMappings;
|
|
77
|
+
readonly settings?: TrailStepSettings;
|
|
78
|
+
readonly workflows?: Readonly<Record<string, TrailStepWorkflowConfig>>;
|
|
79
|
+
}
|
|
80
|
+
interface ResolveAgentTargetsOptions {
|
|
81
|
+
readonly config: TrailStepConfig;
|
|
82
|
+
readonly workflowId: string;
|
|
83
|
+
readonly roleName: string;
|
|
84
|
+
readonly roleSize: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
declare function parseTrailStepConfig(value: unknown): TrailStepConfig;
|
|
88
|
+
|
|
89
|
+
declare function resolveAgentTargets(options: ResolveAgentTargetsOptions): readonly TrailStepAgentTarget[];
|
|
90
|
+
|
|
91
|
+
type PlainObject = Record<string, unknown>;
|
|
92
|
+
interface ValidationDiagnostic {
|
|
93
|
+
readonly path: string;
|
|
94
|
+
readonly message: string;
|
|
95
|
+
}
|
|
96
|
+
interface Schema<T extends PlainObject = PlainObject> {
|
|
97
|
+
readonly validate: (value: unknown) => value is T;
|
|
98
|
+
readonly diagnostics: (value: unknown) => readonly ValidationDiagnostic[];
|
|
99
|
+
readonly assert: (value: unknown, label?: string) => T;
|
|
100
|
+
readonly jsonSchema: Record<string, unknown>;
|
|
101
|
+
readonly captureMode?: "json" | "raw-text";
|
|
102
|
+
}
|
|
103
|
+
type ShapePrimitive = "string" | "number" | "boolean";
|
|
104
|
+
type ShapeObject = Readonly<Record<string, ShapePrimitive>>;
|
|
105
|
+
type ShapeInput<T extends PlainObject = PlainObject> = Schema<T> | ShapeObject;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A captured document artifact. `Document` doubles as its own
|
|
109
|
+
* `Schema<Document>`: `validate`/`diagnostics`/`assert`/`jsonSchema`/
|
|
110
|
+
* `captureMode` are static members, so passing the class itself as
|
|
111
|
+
* `.prompt(source, { output: Document })` gives both the TypeScript output
|
|
112
|
+
* type and the runtime validator from one symbol -- no separate schema
|
|
113
|
+
* constant to import or keep in sync.
|
|
114
|
+
*/
|
|
115
|
+
declare class Document {
|
|
116
|
+
readonly content: string;
|
|
117
|
+
readonly path: string;
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
static readonly captureMode: "raw-text";
|
|
120
|
+
static readonly jsonSchema: Record<string, unknown>;
|
|
121
|
+
static validate(value: unknown): value is Document;
|
|
122
|
+
static diagnostics(value: unknown): readonly ValidationDiagnostic[];
|
|
123
|
+
/**
|
|
124
|
+
* Deliberately duck-types instead of checking `instanceof Document`: on
|
|
125
|
+
* resume, a completed step's recorded output is replayed from
|
|
126
|
+
* `events.jsonl` via `JSON.parse`, producing a plain deserialized object —
|
|
127
|
+
* never a live `Document` instance — before `assert` is called on it. An
|
|
128
|
+
* `instanceof` check would fail every such replay. `assert` reconstructs a
|
|
129
|
+
* genuine `Document` from any content/path-shaped value, so every
|
|
130
|
+
* consumer downstream — a live capture or a replayed value alike — always
|
|
131
|
+
* receives a real `Document` instance with working prototype methods.
|
|
132
|
+
*/
|
|
133
|
+
static assert(value: unknown, label?: string): Document;
|
|
134
|
+
constructor(content: string, path: string);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Captures `content` as a durable document artifact for the currently
|
|
138
|
+
* executing step. Must be called from within a step's `.do()` callback —
|
|
139
|
+
* it reads the step-scoped ambient context (`RunContext.currentStep`, set
|
|
140
|
+
* by `withStepContext` for the duration of the step) to determine both the
|
|
141
|
+
* directory to write into and this call's 1-based index within the step, so
|
|
142
|
+
* that a step calling `document(...)` more than once gets
|
|
143
|
+
* `document-1.md`, `document-2.md`, etc.
|
|
144
|
+
*/
|
|
145
|
+
declare function document(content: string): Promise<Document>;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Synchronously reads each named file relative to `dir` and returns its
|
|
149
|
+
* trimmed content keyed the same way, so a step's `prompt.ts` can load all
|
|
150
|
+
* of its shared markdown fragments in one call:
|
|
151
|
+
* `loadFragments(import.meta.dirname, { methodology: "../shared/methodology.md" })`.
|
|
152
|
+
*/
|
|
153
|
+
declare function loadFragments<TKey extends string>(dir: string, files: Record<TKey, string>): Record<TKey, string>;
|
|
154
|
+
/**
|
|
155
|
+
* Renders `body` as a `## title` markdown section, or `undefined` when
|
|
156
|
+
* `body` is falsy -- so a conditional section can be inlined directly as a
|
|
157
|
+
* `promptSections(...)` argument instead of built up separately.
|
|
158
|
+
*/
|
|
159
|
+
declare function section(title: string, body: string | false | null | undefined): string | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Joins prompt fragments and `section(...)` results with a blank line
|
|
162
|
+
* between each, dropping any falsy (conditionally-omitted) part.
|
|
163
|
+
*/
|
|
164
|
+
declare function promptSections(...parts: ReadonlyArray<string | false | null | undefined>): string;
|
|
165
|
+
/** Renders `items` as a markdown bullet list, one `- item` per line. */
|
|
166
|
+
declare function list(items: readonly string[]): string;
|
|
167
|
+
|
|
168
|
+
interface AgentStepRequestConfig<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
169
|
+
readonly kind?: "agent";
|
|
170
|
+
readonly id: string;
|
|
171
|
+
readonly output: Schema<TOutput>;
|
|
172
|
+
readonly prompt: AgentPrompt<TInput>;
|
|
173
|
+
readonly requirements: WorkflowAgentRole;
|
|
174
|
+
readonly adapter?: AgentAdapterSelection<TInput, TOutput>;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
interface AgentMessage {
|
|
178
|
+
readonly role: "user" | "assistant" | "system";
|
|
179
|
+
readonly content: string;
|
|
180
|
+
}
|
|
181
|
+
type AgentPromptRenderer<TInput extends PlainObject = PlainObject> = {
|
|
182
|
+
bivarianceHack(context: {
|
|
183
|
+
readonly input: TInput;
|
|
184
|
+
}): string;
|
|
185
|
+
}["bivarianceHack"];
|
|
186
|
+
type AgentPrompt<TInput extends PlainObject = PlainObject> = string | AgentPromptRenderer<TInput>;
|
|
187
|
+
interface AgentTool<TInput extends PlainObject = PlainObject> {
|
|
188
|
+
readonly name: string;
|
|
189
|
+
readonly description?: string;
|
|
190
|
+
readonly schema: Schema<TInput>;
|
|
191
|
+
call(input: TInput): void | Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface AgentAdapterRequest<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
195
|
+
readonly messages: readonly AgentMessage[];
|
|
196
|
+
readonly tools: readonly AgentTool<TOutput>[];
|
|
197
|
+
readonly requirements: WorkflowAgentRole;
|
|
198
|
+
readonly model: AgentModelTarget;
|
|
199
|
+
readonly step: AgentStepRequestConfig<TInput, TOutput>;
|
|
200
|
+
readonly input: TInput;
|
|
201
|
+
}
|
|
202
|
+
type AgentAdapter<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = {
|
|
203
|
+
bivarianceHack(request: AgentAdapterRequest<TInput, TOutput>): void | Promise<void>;
|
|
204
|
+
}["bivarianceHack"];
|
|
205
|
+
interface AgentAdapterObject<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
206
|
+
runAgentStep(request: AgentAdapterRequest<TInput, TOutput>): void | Promise<void>;
|
|
207
|
+
}
|
|
208
|
+
type AgentAdapterSelection<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = AgentAdapter<TInput, TOutput> | AgentAdapterObject<TInput, TOutput>;
|
|
209
|
+
|
|
210
|
+
interface Failure {
|
|
211
|
+
readonly code: string;
|
|
212
|
+
readonly message: string;
|
|
213
|
+
readonly details?: unknown;
|
|
214
|
+
}
|
|
215
|
+
declare class TrailStepFailureError extends Error {
|
|
216
|
+
readonly failure: Failure;
|
|
217
|
+
constructor(failure: Failure);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** A local text file to load a prompt's content from, resolved relative to the workflow's `cwd` at dispatch time. */
|
|
221
|
+
interface PromptTemplateSource {
|
|
222
|
+
readonly kind: "promptTemplate";
|
|
223
|
+
readonly path: string;
|
|
224
|
+
}
|
|
225
|
+
/** The object passed to `step(...)`. Always relevant, regardless of whether `.prompt(...)` is called. */
|
|
226
|
+
interface StepConfig {
|
|
227
|
+
readonly id: string;
|
|
228
|
+
readonly retry?: RetryPolicyInput;
|
|
229
|
+
readonly timeout?: TimeoutPolicyInput;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The object passed as `.prompt(...)`'s second argument -- config that only
|
|
233
|
+
* matters when a step dispatches to an agent, so it lives here instead of
|
|
234
|
+
* on `StepConfig` where a no-prompt step could set it and have it silently
|
|
235
|
+
* ignored. `output` constrains the agent's structured-output tool.
|
|
236
|
+
*/
|
|
237
|
+
interface PromptOptions<TOutput extends PlainObject = PlainObject> {
|
|
238
|
+
readonly output?: ShapeInput<TOutput>;
|
|
239
|
+
readonly agent?: string;
|
|
240
|
+
readonly mode?: "working" | "interactive";
|
|
241
|
+
readonly adapter?: AgentAdapterSelection<PlainObject, TOutput>;
|
|
242
|
+
readonly maxSubPrompts?: number;
|
|
243
|
+
}
|
|
244
|
+
interface SubPromptOptions<TOutput extends PlainObject = PlainObject> {
|
|
245
|
+
readonly output?: ShapeInput<TOutput>;
|
|
246
|
+
readonly agent?: string;
|
|
247
|
+
readonly adapter?: AgentAdapterSelection<PlainObject, TOutput>;
|
|
248
|
+
readonly maxSubPrompts?: number;
|
|
249
|
+
}
|
|
250
|
+
/** The runtime shape stored in `StepNode.config` -- `StepConfig` plus `PromptOptions` (when a prompt was given) plus the resolved `input` and `prompt` source. */
|
|
251
|
+
interface ContinuationStepConfig<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
252
|
+
readonly id: string;
|
|
253
|
+
readonly input: TInput;
|
|
254
|
+
readonly output?: ShapeInput<TOutput>;
|
|
255
|
+
readonly prompt?: AgentPrompt<TInput> | PromptTemplateSource;
|
|
256
|
+
readonly agent?: string;
|
|
257
|
+
readonly mode?: "working" | "interactive";
|
|
258
|
+
readonly adapter?: AgentAdapterSelection<TInput, TOutput>;
|
|
259
|
+
readonly maxSubPrompts?: number;
|
|
260
|
+
readonly retry?: RetryPolicyInput;
|
|
261
|
+
readonly timeout?: TimeoutPolicyInput;
|
|
262
|
+
}
|
|
263
|
+
type StepContinuation<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = {
|
|
264
|
+
bivarianceHack(output: TOutput, input: TInput): ContinuationResult | Promise<ContinuationResult>;
|
|
265
|
+
}["bivarianceHack"];
|
|
266
|
+
type StepErrorContinuation = {
|
|
267
|
+
bivarianceHack(error: Failure): ContinuationResult;
|
|
268
|
+
}["bivarianceHack"];
|
|
269
|
+
interface StepNode<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
270
|
+
readonly kind: "step";
|
|
271
|
+
readonly config: ContinuationStepConfig<TInput, TOutput>;
|
|
272
|
+
/** Receives the step's own input as the second argument, alongside its output as the first. */
|
|
273
|
+
readonly onOutput: StepContinuation<TInput, TOutput>;
|
|
274
|
+
readonly onError?: StepErrorContinuation;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Returned by `step(...).prompt(...)?.do(...)`: a reusable step definition,
|
|
278
|
+
* called with a live input value to produce an actual `StepNode`
|
|
279
|
+
* (`stepA(input)`). Chain `.catch(...)` to add an error continuation before
|
|
280
|
+
* calling it. When `TInput` has no required keys (e.g. a step that ignores
|
|
281
|
+
* its input), the call is `stepA()` -- the input argument is optional.
|
|
282
|
+
*/
|
|
283
|
+
type StepFactory<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = ({} extends TInput ? (input?: TInput) => StepNode<TInput, TOutput> : (input: TInput) => StepNode<TInput, TOutput>) & {
|
|
284
|
+
catch(onError: StepErrorContinuation): StepFactory<TInput, TOutput>;
|
|
285
|
+
};
|
|
286
|
+
type SubPromptFactory<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = {} extends TInput ? (input?: TInput) => Promise<TOutput> : (input: TInput) => Promise<TOutput>;
|
|
287
|
+
interface DoneNode<TOutput extends PlainObject = PlainObject> {
|
|
288
|
+
readonly kind: "done";
|
|
289
|
+
readonly output: TOutput;
|
|
290
|
+
}
|
|
291
|
+
/** Terminates the workflow as a failure without dispatching a step -- no step.* events, just workflow.failed. */
|
|
292
|
+
interface FailNode {
|
|
293
|
+
readonly kind: "fail";
|
|
294
|
+
readonly failure: Failure;
|
|
295
|
+
}
|
|
296
|
+
type ContinuationResult<TOutput extends PlainObject = PlainObject> = StepNode<PlainObject, PlainObject> | DoneNode<TOutput> | FailNode;
|
|
297
|
+
|
|
298
|
+
/** Loads a step's prompt from a local text file, resolved relative to the workflow's `cwd` at dispatch time. */
|
|
299
|
+
declare function promptTemplate(path: string): PromptTemplateSource;
|
|
300
|
+
|
|
301
|
+
type JsonSchemaObject = JSONSchemaType<PlainObject> | Record<string, unknown>;
|
|
302
|
+
declare function normalizeShape<T extends PlainObject>(shapeInput: ShapeInput<T>): Schema<T>;
|
|
303
|
+
declare function shape<T extends PlainObject>(shapeObject: ShapeObject): Schema<T>;
|
|
304
|
+
declare function jsonSchema<T extends PlainObject>(schema: JsonSchemaObject): Schema<T>;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Ambient handle onto the active run's identity and durable key-value store.
|
|
308
|
+
* Backed by AsyncLocalStorage, set once per run by `runWorkflow`; step
|
|
309
|
+
* continuations import this directly rather than receiving it as an argument.
|
|
310
|
+
*/
|
|
311
|
+
declare const state: {
|
|
312
|
+
get<T = unknown>(key: string): Promise<T | undefined>;
|
|
313
|
+
set(key: string, value: unknown): Promise<void>;
|
|
314
|
+
readonly id: string;
|
|
315
|
+
readonly name: string;
|
|
316
|
+
readonly path: string;
|
|
317
|
+
readonly cwd: string | undefined;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* The only step-authoring primitive. `.prompt(...)` is optional; when present,
|
|
322
|
+
* the step dispatches to an agent and `.do(...)` receives its structured
|
|
323
|
+
* output. When absent, nothing is dispatched -- `.do(...)` receives the
|
|
324
|
+
* step's input directly and is responsible for the work and the continuation
|
|
325
|
+
* in one function. Either way, `.do(...)` produces a reusable `StepFactory`
|
|
326
|
+
* -- call it with a live input value (`stepA(input)`) to get a `StepNode`.
|
|
327
|
+
* When the inferred input type has no required keys, the argument is
|
|
328
|
+
* optional (`stepA()`) and defaults to `{}`.
|
|
329
|
+
*/
|
|
330
|
+
declare function step(config: StepConfig): {
|
|
331
|
+
prompt<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject>(source: AgentPrompt<TInput> | PromptTemplateSource, options?: PromptOptions<TOutput>): {
|
|
332
|
+
do(onOutput: StepContinuation<TInput, TOutput>): StepFactory<TInput, TOutput>;
|
|
333
|
+
};
|
|
334
|
+
do<TInput extends PlainObject = PlainObject>(onOutput: StepContinuation<TInput, TInput>): StepFactory<TInput, TInput>;
|
|
335
|
+
};
|
|
336
|
+
declare function done<TOutput extends PlainObject = PlainObject>(output?: TOutput): DoneNode<TOutput>;
|
|
337
|
+
declare function fail(failure: Failure): FailNode;
|
|
338
|
+
declare function isStepNode(value: unknown): value is StepNode;
|
|
339
|
+
declare function isDoneNode(value: unknown): value is DoneNode;
|
|
340
|
+
declare function isFailNode(value: unknown): value is FailNode;
|
|
341
|
+
|
|
342
|
+
declare function subPrompt<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject>(source: AgentPrompt<TInput> | PromptTemplateSource, options: SubPromptOptions<TOutput>): SubPromptFactory<TInput, TOutput>;
|
|
343
|
+
|
|
344
|
+
interface Workflow<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> {
|
|
345
|
+
readonly id: string;
|
|
346
|
+
readonly input?: Schema<TInput>;
|
|
347
|
+
readonly output?: Schema<TOutput>;
|
|
348
|
+
readonly inputShape?: ShapeInput<TInput>;
|
|
349
|
+
readonly outputShape?: ShapeInput<TOutput>;
|
|
350
|
+
readonly agents?: Readonly<Record<string, WorkflowAgentRole>>;
|
|
351
|
+
readonly retry?: RetryPolicyInput;
|
|
352
|
+
readonly timeout?: TimeoutPolicyInput;
|
|
353
|
+
readonly start: (input: TInput) => ContinuationResult<TOutput>;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
type DeprecationTargetPackage = "@trailstep/core" | "@trailstep/authoring";
|
|
357
|
+
interface DeprecationEntry {
|
|
358
|
+
/** Which published package exports this symbol. A symbol re-exported by both (like `step`,
|
|
359
|
+
* which authoring re-exports from core) needs one entry per package it's importable from, since a
|
|
360
|
+
* workflow author might import it from either. */
|
|
361
|
+
readonly package: DeprecationTargetPackage;
|
|
362
|
+
/** The exact named export identifier, e.g. "step". Matched literally against import statement
|
|
363
|
+
* text by the scanner. */
|
|
364
|
+
readonly symbol: string;
|
|
365
|
+
/** Semver version at/after which this symbol is considered deprecated (still works, warns). */
|
|
366
|
+
readonly deprecatedSince: string;
|
|
367
|
+
/** Semver version at/after which this symbol is actually removed (no longer works). Omit if the
|
|
368
|
+
* symbol is deprecated but has no planned removal. */
|
|
369
|
+
readonly removedIn?: string;
|
|
370
|
+
/** Human-readable explanation, shown verbatim in doctor/update output. */
|
|
371
|
+
readonly message: string;
|
|
372
|
+
/** Optional suggested replacement API, shown as "Suggested replacement: <this>." */
|
|
373
|
+
readonly replacement?: string;
|
|
374
|
+
}
|
|
375
|
+
type DeprecationManifest = readonly DeprecationEntry[];
|
|
376
|
+
interface DeprecationStatus extends DeprecationEntry {
|
|
377
|
+
readonly severity: "warning" | "blocking";
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
declare const deprecationManifest: DeprecationManifest;
|
|
381
|
+
interface FindDeprecationsAsOfQuery {
|
|
382
|
+
readonly package: DeprecationTargetPackage;
|
|
383
|
+
readonly version: string;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Returns every manifest entry for query.package whose deprecatedSince is at or before
|
|
387
|
+
* query.version, tagged with a severity. Calling this once with version set to a target
|
|
388
|
+
* version naturally captures every entry between the installed version and the target, no matter
|
|
389
|
+
* how many majors are being skipped in one update.
|
|
390
|
+
*/
|
|
391
|
+
declare function findDeprecationsAsOf(manifest: DeprecationManifest, query: FindDeprecationsAsOfQuery): readonly DeprecationStatus[];
|
|
392
|
+
|
|
393
|
+
type TrailStepConfigInput = TrailStepConfig | Readonly<Record<string, unknown>>;
|
|
394
|
+
interface InteractiveProcessRequest {
|
|
395
|
+
readonly command: string;
|
|
396
|
+
readonly args: readonly string[];
|
|
397
|
+
readonly cwd: string;
|
|
398
|
+
readonly shell: false;
|
|
399
|
+
readonly stdio: "inherit";
|
|
400
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
401
|
+
readonly signal?: AbortSignal;
|
|
402
|
+
}
|
|
403
|
+
interface InteractiveProcessResult {
|
|
404
|
+
readonly exitCode: number;
|
|
405
|
+
}
|
|
406
|
+
type InteractiveProcessRunner = (request: InteractiveProcessRequest) => InteractiveProcessResult | Promise<InteractiveProcessResult>;
|
|
407
|
+
interface WorkingAgentProcessRequest {
|
|
408
|
+
readonly command: string;
|
|
409
|
+
readonly args: readonly string[];
|
|
410
|
+
readonly cwd: string;
|
|
411
|
+
readonly shell: false;
|
|
412
|
+
readonly stdio: "inherit";
|
|
413
|
+
readonly promptFile: string;
|
|
414
|
+
readonly outputFile: string;
|
|
415
|
+
readonly model?: string;
|
|
416
|
+
readonly signal?: AbortSignal;
|
|
417
|
+
}
|
|
418
|
+
interface WorkingAgentProcessResult {
|
|
419
|
+
readonly exitCode: number;
|
|
420
|
+
}
|
|
421
|
+
type WorkingAgentProcessRunner = (request: WorkingAgentProcessRequest) => WorkingAgentProcessResult | Promise<WorkingAgentProcessResult>;
|
|
422
|
+
interface Event<TPayload extends PlainObject = PlainObject> {
|
|
423
|
+
readonly id: string;
|
|
424
|
+
readonly runId: string;
|
|
425
|
+
readonly workflowId: string;
|
|
426
|
+
readonly stepId?: string;
|
|
427
|
+
readonly type: "workflow.started" | "workflow.resumed" | "workflow.retryStarted" | "workflow.failed" | "step.started" | "step.completed" | "step.failed" | "subPrompt.started" | "subPrompt.completed" | "subPrompt.failed" | "interactive.sessionStarted" | "interactive.sessionCompleted" | "agent.toolCall" | "workflow.completed";
|
|
428
|
+
readonly timestamp: string;
|
|
429
|
+
readonly schemaVersion: "v0";
|
|
430
|
+
readonly payload: TPayload;
|
|
431
|
+
}
|
|
432
|
+
type Result<TOutput extends PlainObject = PlainObject> = {
|
|
433
|
+
readonly status: "success";
|
|
434
|
+
readonly runId: string;
|
|
435
|
+
readonly runDir: string;
|
|
436
|
+
readonly output: TOutput;
|
|
437
|
+
readonly events: readonly Event[];
|
|
438
|
+
} | {
|
|
439
|
+
readonly status: "failure";
|
|
440
|
+
readonly runId: string;
|
|
441
|
+
readonly runDir: string;
|
|
442
|
+
readonly failure: Failure;
|
|
443
|
+
readonly events: readonly Event[];
|
|
444
|
+
};
|
|
445
|
+
interface RunWorkflowBaseOptions<TInput extends PlainObject, TOutput extends PlainObject> {
|
|
446
|
+
readonly workflow: Workflow<TInput, TOutput>;
|
|
447
|
+
readonly cwd?: string;
|
|
448
|
+
readonly runsRoot?: string;
|
|
449
|
+
readonly eventSink?: (event: Event) => void | Promise<void>;
|
|
450
|
+
readonly processRunner?: InteractiveProcessRunner;
|
|
451
|
+
readonly trailstepConfig?: TrailStepConfigInput;
|
|
452
|
+
readonly workingAgentProcessRunner?: WorkingAgentProcessRunner;
|
|
453
|
+
/** Injectable stdout-capturing runner for built-in registry provider adapters (e.g. Claude). Test-only seam. */
|
|
454
|
+
readonly providerWorkingRunner?: ProviderWorkingRunner;
|
|
455
|
+
readonly maxSteps?: number;
|
|
456
|
+
}
|
|
457
|
+
type RunWorkflowOptions<TInput extends PlainObject = PlainObject, TOutput extends PlainObject = PlainObject> = RunWorkflowBaseOptions<TInput, TOutput> & ({
|
|
458
|
+
readonly input: TInput;
|
|
459
|
+
readonly runName: string;
|
|
460
|
+
readonly resume?: undefined;
|
|
461
|
+
readonly retry?: undefined;
|
|
462
|
+
} | {
|
|
463
|
+
readonly resume: {
|
|
464
|
+
readonly runDir: string;
|
|
465
|
+
};
|
|
466
|
+
readonly input?: undefined;
|
|
467
|
+
readonly runName?: undefined;
|
|
468
|
+
readonly retry?: undefined;
|
|
469
|
+
} | {
|
|
470
|
+
readonly retry: {
|
|
471
|
+
readonly runDir: string;
|
|
472
|
+
readonly kind: "manual" | "automatic";
|
|
473
|
+
};
|
|
474
|
+
readonly input?: undefined;
|
|
475
|
+
readonly runName?: undefined;
|
|
476
|
+
readonly resume?: undefined;
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Request shape for a built-in provider's non-interactive ("working") invocation.
|
|
481
|
+
* The runtime has already written `promptFile`; the adapter is responsible for
|
|
482
|
+
* invoking its vendor CLI and writing a single JSON object to `outputFile`.
|
|
483
|
+
*/
|
|
484
|
+
interface ProviderWorkingRequest {
|
|
485
|
+
readonly promptFile: string;
|
|
486
|
+
readonly outputFile: string;
|
|
487
|
+
readonly usageFile?: string;
|
|
488
|
+
readonly cwd: string;
|
|
489
|
+
readonly model?: string;
|
|
490
|
+
readonly thinking?: WorkflowAgentThinking;
|
|
491
|
+
readonly captureMode?: "json" | "raw-text";
|
|
492
|
+
readonly signal?: AbortSignal;
|
|
493
|
+
}
|
|
494
|
+
/** Low-level process request for a provider's stdout-capturing runner. */
|
|
495
|
+
interface ProviderWorkingProcessRequest {
|
|
496
|
+
readonly command: string;
|
|
497
|
+
readonly args: readonly string[];
|
|
498
|
+
readonly cwd: string;
|
|
499
|
+
/**
|
|
500
|
+
* Prompt text to write to the child's stdin and close, rather than appending
|
|
501
|
+
* it to `args`. Windows' `CreateProcess` concatenates argv into a single
|
|
502
|
+
* command-line string capped around 32,767 characters, so large rendered
|
|
503
|
+
* prompts must use either a tiny @prompt-file argv reference or stdin.
|
|
504
|
+
* Providers only set this for CLI flows that cannot use an existing prompt
|
|
505
|
+
* file artifact (for example, Claude's output-repair prompt).
|
|
506
|
+
*/
|
|
507
|
+
readonly stdin?: string;
|
|
508
|
+
readonly signal?: AbortSignal;
|
|
509
|
+
}
|
|
510
|
+
interface ProviderWorkingProcessResult {
|
|
511
|
+
readonly exitCode: number;
|
|
512
|
+
readonly stdout: string;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Spawns a provider's CLI, collecting stdout for envelope parsing instead of
|
|
516
|
+
* inheriting it. Runners may ignore stdin or pipe it depending on whether
|
|
517
|
+
* `stdin` is set. Injectable for tests.
|
|
518
|
+
*/
|
|
519
|
+
type ProviderWorkingRunner = (request: ProviderWorkingProcessRequest) => ProviderWorkingProcessResult | Promise<ProviderWorkingProcessResult>;
|
|
520
|
+
/** Request shape for a built-in provider's interactive (human-in-the-loop) invocation. */
|
|
521
|
+
interface ProviderInteractiveRequest {
|
|
522
|
+
readonly prompt: string;
|
|
523
|
+
/**
|
|
524
|
+
* Path to a file containing the full interactive prompt, for adapters that
|
|
525
|
+
* support a system-prompt-file flag instead of a positional prompt argument.
|
|
526
|
+
*/
|
|
527
|
+
readonly systemPromptFile?: string;
|
|
528
|
+
readonly cwd: string;
|
|
529
|
+
readonly model?: string;
|
|
530
|
+
/** Undefined means bypass (per-tool confirmation is skipped by default). */
|
|
531
|
+
readonly permissionMode?: "bypass" | "prompt";
|
|
532
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
533
|
+
readonly signal?: AbortSignal;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Request shape for a one-shot repair of a working-agent turn whose final
|
|
537
|
+
* answer failed JSON extraction. `sessionId` and `rawResultText` are the
|
|
538
|
+
* malformed turn's own session id and (best-effort) raw final-answer text, as
|
|
539
|
+
* surfaced by the failed `runWorking` call.
|
|
540
|
+
*/
|
|
541
|
+
interface ProviderWorkingRepairRequest {
|
|
542
|
+
readonly sessionId: string;
|
|
543
|
+
readonly rawResultText: string;
|
|
544
|
+
readonly outputFile: string;
|
|
545
|
+
readonly usageFile?: string;
|
|
546
|
+
readonly cwd: string;
|
|
547
|
+
readonly model?: string;
|
|
548
|
+
readonly thinking?: WorkflowAgentThinking;
|
|
549
|
+
readonly outputSchema: Record<string, unknown>;
|
|
550
|
+
readonly captureMode?: "json" | "raw-text";
|
|
551
|
+
readonly signal?: AbortSignal;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* A built-in, core-owned known-CLI adapter for a single named vendor.
|
|
555
|
+
* This is CLI print-mode invocation knowledge, not an in-process vendor SDK
|
|
556
|
+
* adapter: adapters spawn a real CLI process and never import a vendor SDK
|
|
557
|
+
* library.
|
|
558
|
+
*/
|
|
559
|
+
interface ProviderAdapter {
|
|
560
|
+
readonly id: string;
|
|
561
|
+
/** Non-interactive invocation: writes `request.outputFile` itself before resolving. */
|
|
562
|
+
runWorking(request: ProviderWorkingRequest, runner?: ProviderWorkingRunner): Promise<void>;
|
|
563
|
+
/**
|
|
564
|
+
* Optional one-shot repair of a malformed final answer, for providers whose
|
|
565
|
+
* CLI can resume a prior session (currently only `claude`). Malformed JSON
|
|
566
|
+
* after a real agentic turn should not trigger a full re-run of the task —
|
|
567
|
+
* the agent may have already made real file edits, and redoing the task
|
|
568
|
+
* from scratch risks duplicating or conflicting with them — so this asks
|
|
569
|
+
* the *same* session to reformat its last answer only. Providers without a
|
|
570
|
+
* resumable session omit this entirely and keep today's immediate-failure
|
|
571
|
+
* behavior.
|
|
572
|
+
*/
|
|
573
|
+
repairOutput?(request: ProviderWorkingRepairRequest, runner?: ProviderWorkingRunner): Promise<void>;
|
|
574
|
+
/** Interactive invocation: inherited stdio, a human is present. */
|
|
575
|
+
runInteractive(request: ProviderInteractiveRequest, runner?: InteractiveProcessRunner): Promise<InteractiveProcessResult>;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Core's built-in known-CLI provider registry. Each entry maps a provider id
|
|
580
|
+
* (matched against a `.trailstep/config.json` target's `provider` field) to a
|
|
581
|
+
* core-owned CLI print-mode invocation for a single named vendor.
|
|
582
|
+
*
|
|
583
|
+
* This is the full four-provider set. Unlike Claude/Codex/Pi, `gemini`'s
|
|
584
|
+
* adapter is structurally verified only (an injected fake stdout-capturing
|
|
585
|
+
* runner in `agent.test.ts`/`gemini.test.ts`) — the real `gemini` CLI is not
|
|
586
|
+
* installed in this environment, so its argv/envelope shape has not been
|
|
587
|
+
* confirmed against a live process.
|
|
588
|
+
*/
|
|
589
|
+
declare const providerRegistry: Record<"claude" | "codex" | "pi" | "gemini", ProviderAdapter>;
|
|
590
|
+
type ProviderRegistryKey = keyof typeof providerRegistry;
|
|
591
|
+
|
|
592
|
+
type RunState = Record<string, unknown>;
|
|
593
|
+
declare function defaultRunsRoot(cwd: string): string;
|
|
594
|
+
declare function readRunEvents(runDir: string): Promise<Event[]>;
|
|
595
|
+
declare function readRunState(runDir: string): Promise<RunState>;
|
|
596
|
+
declare function writeRunState(runDir: string, state: RunState): Promise<void>;
|
|
597
|
+
|
|
598
|
+
interface LatestUnresolvedFailure {
|
|
599
|
+
readonly event: Event;
|
|
600
|
+
readonly replayPosition: number;
|
|
601
|
+
readonly sourceFailureEventId?: string;
|
|
602
|
+
readonly workflowId: string;
|
|
603
|
+
readonly workflowInput?: PlainObject;
|
|
604
|
+
readonly stepId?: string;
|
|
605
|
+
}
|
|
606
|
+
declare function selectLatestUnresolvedFailure(events: readonly Event[]): LatestUnresolvedFailure | undefined;
|
|
607
|
+
|
|
608
|
+
declare function runWorkflow<TInput extends PlainObject, TOutput extends PlainObject>(options: RunWorkflowOptions<TInput, TOutput>): Promise<Result<TOutput>>;
|
|
609
|
+
|
|
610
|
+
type RunSummaryStatus = "active" | "completed" | "failed" | "unknown";
|
|
611
|
+
interface RunSummary {
|
|
612
|
+
readonly runId: string;
|
|
613
|
+
readonly runDir: string;
|
|
614
|
+
readonly status: RunSummaryStatus;
|
|
615
|
+
readonly workflowId?: string;
|
|
616
|
+
readonly lastTimestamp?: string;
|
|
617
|
+
readonly latestFailure?: LatestUnresolvedFailure;
|
|
618
|
+
readonly warning?: string;
|
|
619
|
+
}
|
|
620
|
+
declare function listRunSummaries(options: {
|
|
621
|
+
readonly cwd: string;
|
|
622
|
+
readonly runsRoot?: string;
|
|
623
|
+
}): Promise<RunSummary[]>;
|
|
624
|
+
declare function selectRecentFailedRunSummaries(summaries: readonly RunSummary[], options?: {
|
|
625
|
+
readonly now?: Date;
|
|
626
|
+
}): RunSummary[];
|
|
627
|
+
declare function newestFirst(left: RunSummary, right: RunSummary): number;
|
|
628
|
+
|
|
629
|
+
export { type AgentAdapter, type AgentAdapterObject, type AgentAdapterRequest, type AgentAdapterSelection, type AgentMessage, type AgentModelTarget, type AgentPrompt, type AgentTool, type ContinuationResult, type ContinuationStepConfig, type DeprecationEntry, type DeprecationManifest, type DeprecationStatus, type DeprecationTargetPackage, Document, type DoneNode, type Event, type FailNode, type Failure, type FindDeprecationsAsOfQuery, type InteractiveProcessRequest, type InteractiveProcessResult, type InteractiveProcessRunner, type JsonSchemaObject, type LatestUnresolvedFailure, type PlainObject, type PromptOptions, type PromptTemplateSource, type ProviderAdapter, type ProviderInteractiveRequest, type ProviderRegistryKey, type ProviderWorkingProcessRequest, type ProviderWorkingProcessResult, type ProviderWorkingRequest, type ProviderWorkingRunner, type ResolveAgentTargetsOptions, type ResolveRetryPolicyOptions, type ResolveTimeoutPolicyOptions, type Result, type RetryPolicy, type RetryPolicyInput, type RunSummary, type RunSummaryStatus, type RunWorkflowOptions, type Schema, type ShapeInput, type ShapeObject, type ShapePrimitive, type StepConfig, type StepContinuation, type StepErrorContinuation, type StepFactory, type StepNode, type SubPromptFactory, type SubPromptOptions, type TimeoutPolicy, type TimeoutPolicyInput, type TrailStepAgentMappings, type TrailStepAgentTarget, type TrailStepConfig, type TrailStepCustomProviderConfig, TrailStepFailureError, type TrailStepSettings, type TrailStepWorkflowConfig, type Workflow, type WorkflowAgentRole, type WorkflowAgentSize, type WorkflowAgentThinking, type WorkingAgentProcessRequest, type WorkingAgentProcessResult, type WorkingAgentProcessRunner, defaultRunsRoot, deprecationManifest, document, done, fail, findDeprecationsAsOf, isDoneNode, isFailNode, isStepNode, jsonSchema, list, listRunSummaries, loadFragments, newestFirst, normalizeShape, parseTrailStepConfig, promptSections, promptTemplate, providerRegistry, readRunEvents, readRunState, resolveAgentTargets, resolveRetryPolicy, resolveTimeoutPolicy, runWorkflow, section, selectLatestUnresolvedFailure, selectRecentFailedRunSummaries, shape, state, step, subPrompt, validateRetryPolicy, validateTimeoutPolicy, writeRunState };
|