@theokit/sdk 2.29.0 → 2.30.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/CHANGELOG.md +10 -0
- package/dist/{cron-COSAehOL.d.ts → cron-BNHJywtl.d.ts} +374 -17
- package/dist/{cron-yJoNUZxe.d.cts → cron-t4oKI2Is.d.cts} +374 -17
- package/dist/cron.cjs +89 -44
- package/dist/cron.cjs.map +1 -1
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +89 -44
- package/dist/cron.js.map +1 -1
- package/dist/{errors-tP-8O-hR.d.cts → errors-DZpCGlYv.d.cts} +1 -1
- package/dist/{errors-BxMIlgLP.d.ts → errors-D_Bfo30u.d.ts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/index.cjs +89 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -135
- package/dist/index.d.ts +7 -135
- package/dist/index.js +89 -44
- package/dist/index.js.map +1 -1
- package/dist/{run-q_P0vHlY.d.cts → run-CLXKMRgq.d.cts} +1 -1
- package/dist/{run-q_P0vHlY.d.ts → run-CLXKMRgq.d.ts} +1 -1
- package/dist/types/cron.d.ts +30 -13
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 2.30.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ea3cd14: **SE35 — schedule a workflow on the `Cron` primitive (`workflow` + `inputData`).**
|
|
8
|
+
|
|
9
|
+
A `Cron` job may now target a committed `Workflow` (SE27–30) instead of an agent — the runtime-legitimate slice of Mastra's Schedules. `Cron.create({ cron, workflow, inputData })` runs `workflow.run(inputData)` on each fire, reusing the shipped in-process scheduler + Task-registry observability. Mutually exclusive with agent targets: exactly one of `agent` | `agentId` | `workflow`; `message` is required for agent targets and forbidden with a workflow (typed `ConfigurationError`s: `cron_ambiguous_target` / `cron_no_target` / `cron_workflow_message` / `cron_missing_message`). `Cron.run(jobId)` returns `Run | WorkflowRun`; the fire handler records the correct terminal status for either shape.
|
|
10
|
+
|
|
11
|
+
Per ADR 0014, the job holds the `Workflow` **instance** (not a `workflowId` + resolver registry) — the cron store is in-memory, so there is no serialization problem to solve and a registry would be YAGNI; workflow cron jobs are local-runtime only (an instance can't cross the cloud boundary). Fire lifecycle hooks (`prepare`/`onFinish`/`onError`/`onAbort`) are deferred with a named re-eval trigger. Back-compat: agent-target jobs are byte-identical. From the Mastra Schedules comparison (SDK Evolution roadmap SE35).
|
|
12
|
+
|
|
3
13
|
## 2.29.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, l as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor } from './run-q_P0vHlY.js';
|
|
2
1
|
import * as zod from 'zod';
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
|
+
import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, k as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor, r as MessageOrigin } from './run-CLXKMRgq.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Fork primitive public type contracts (T1.2, ADRs D110-D114).
|
|
@@ -2108,6 +2109,345 @@ interface ListResult<T> {
|
|
|
2108
2109
|
nextCursor?: string;
|
|
2109
2110
|
}
|
|
2110
2111
|
|
|
2112
|
+
/**
|
|
2113
|
+
* Public type contract for `Workflow.create / .run / .resume` (Adoption
|
|
2114
|
+
* Roadmap #5; ADRs D230-D248).
|
|
2115
|
+
*
|
|
2116
|
+
* Step types form a discriminated union by `kind`. Helper factory functions
|
|
2117
|
+
* (`fn()`, `agentStep()`) live in `workflow.ts` and hide the discriminator
|
|
2118
|
+
* from end users.
|
|
2119
|
+
*
|
|
2120
|
+
* @public
|
|
2121
|
+
*/
|
|
2122
|
+
|
|
2123
|
+
type Step = FnStep | AgentStep | ParallelStep | BranchStep | ForeachStep | DowhileStep | SleepStep | SuspendStep;
|
|
2124
|
+
/** A pure function step. */
|
|
2125
|
+
interface FnStep {
|
|
2126
|
+
readonly kind: "fn";
|
|
2127
|
+
readonly id: string;
|
|
2128
|
+
readonly fn: (input: unknown, ctx: StepContext) => Promise<unknown> | unknown;
|
|
2129
|
+
readonly inputSchema?: ZodType;
|
|
2130
|
+
readonly outputSchema?: ZodType;
|
|
2131
|
+
readonly retry?: RetryPolicy;
|
|
2132
|
+
/** D238 — slot reserved; runtime throws if engine not yet implemented. */
|
|
2133
|
+
readonly compensate?: (input: unknown, output: unknown, error: Error) => Promise<void> | void;
|
|
2134
|
+
}
|
|
2135
|
+
/** An agent.send-driven step. */
|
|
2136
|
+
interface AgentStep {
|
|
2137
|
+
readonly kind: "agent";
|
|
2138
|
+
readonly id: string;
|
|
2139
|
+
readonly agent: SDKAgent;
|
|
2140
|
+
readonly promptTemplate: string | ((input: unknown) => string);
|
|
2141
|
+
readonly retry?: RetryPolicy;
|
|
2142
|
+
/**
|
|
2143
|
+
* SE3 — provenance stamped onto this step's `agent.send()` (forwarded to
|
|
2144
|
+
* `RunResult.origin`). Squad sets `{ kind: "peer", from: "agent-<i-1>" }` on
|
|
2145
|
+
* every step after the first so a peer-driven turn is attributable.
|
|
2146
|
+
*/
|
|
2147
|
+
readonly origin?: MessageOrigin;
|
|
2148
|
+
}
|
|
2149
|
+
/** N concurrent branches, each its own mini-step-list. */
|
|
2150
|
+
interface ParallelStep {
|
|
2151
|
+
readonly kind: "parallel";
|
|
2152
|
+
readonly id: string;
|
|
2153
|
+
readonly branches: ReadonlyArray<ReadonlyArray<Step>>;
|
|
2154
|
+
readonly concurrency?: number;
|
|
2155
|
+
readonly errorPolicy?: "fail-fast" | "collect";
|
|
2156
|
+
}
|
|
2157
|
+
/** First-match-wins predicates + optional fallback. */
|
|
2158
|
+
interface BranchStep {
|
|
2159
|
+
readonly kind: "branch";
|
|
2160
|
+
readonly id: string;
|
|
2161
|
+
readonly predicates: ReadonlyArray<readonly [(input: unknown) => boolean | Promise<boolean>, ReadonlyArray<Step>]>;
|
|
2162
|
+
readonly fallback?: ReadonlyArray<Step>;
|
|
2163
|
+
}
|
|
2164
|
+
/** Map a step over an upstream array output. */
|
|
2165
|
+
interface ForeachStep {
|
|
2166
|
+
readonly kind: "foreach";
|
|
2167
|
+
readonly id: string;
|
|
2168
|
+
/** ID of an upstream top-level step whose output is iterable. */
|
|
2169
|
+
readonly iterableFrom: string;
|
|
2170
|
+
readonly step: Step;
|
|
2171
|
+
readonly concurrency?: number;
|
|
2172
|
+
}
|
|
2173
|
+
/** Loop a step until condFn returns false. */
|
|
2174
|
+
interface DowhileStep {
|
|
2175
|
+
readonly kind: "dowhile";
|
|
2176
|
+
readonly id: string;
|
|
2177
|
+
readonly step: Step;
|
|
2178
|
+
readonly condFn: (output: unknown, iteration: number) => boolean | Promise<boolean>;
|
|
2179
|
+
readonly maxIterations?: number;
|
|
2180
|
+
}
|
|
2181
|
+
/** Pause for a fixed duration. */
|
|
2182
|
+
interface SleepStep {
|
|
2183
|
+
readonly kind: "sleep";
|
|
2184
|
+
readonly id: string;
|
|
2185
|
+
readonly durationMs: number;
|
|
2186
|
+
}
|
|
2187
|
+
/** Standalone explicit suspend point. */
|
|
2188
|
+
interface SuspendStep {
|
|
2189
|
+
readonly kind: "suspend";
|
|
2190
|
+
readonly id: string;
|
|
2191
|
+
readonly payloadSchema?: ZodType;
|
|
2192
|
+
}
|
|
2193
|
+
/** D237 — retry policy applied per fn/agent step. */
|
|
2194
|
+
interface RetryPolicy {
|
|
2195
|
+
/** Total attempts (MIN 1, MAX 20). `1` = no retry. */
|
|
2196
|
+
readonly maxAttempts: number;
|
|
2197
|
+
readonly initialBackoffMs?: number;
|
|
2198
|
+
readonly backoffCoefficient?: number;
|
|
2199
|
+
readonly maximumBackoffMs?: number;
|
|
2200
|
+
readonly nonRetryableErrors?: ReadonlyArray<string>;
|
|
2201
|
+
}
|
|
2202
|
+
/** D247 — context handed to every step.fn. */
|
|
2203
|
+
interface StepContext {
|
|
2204
|
+
readonly runId: string;
|
|
2205
|
+
readonly signal: AbortSignal;
|
|
2206
|
+
readonly log: {
|
|
2207
|
+
debug: (msg: string, attrs?: Record<string, unknown>) => void;
|
|
2208
|
+
info: (msg: string, attrs?: Record<string, unknown>) => void;
|
|
2209
|
+
warn: (msg: string, attrs?: Record<string, unknown>) => void;
|
|
2210
|
+
};
|
|
2211
|
+
/** Pause the workflow; resume via `Workflow.resume({...})`. */
|
|
2212
|
+
readonly suspend: (payload?: unknown) => Promise<never>;
|
|
2213
|
+
/**
|
|
2214
|
+
* SE29 — the workflow's shared state (from `WorkflowOptions.initialState`,
|
|
2215
|
+
* mutated by {@link setState}), visible to every subsequent step in the run.
|
|
2216
|
+
* `undefined` when no `initialState`/`setState` has run. Persisted across
|
|
2217
|
+
* suspend/resume.
|
|
2218
|
+
*/
|
|
2219
|
+
readonly state: unknown;
|
|
2220
|
+
/**
|
|
2221
|
+
* SE29 — update the shared state for subsequent steps. Validated against
|
|
2222
|
+
* `WorkflowOptions.stateSchema` when set (a mismatch throws
|
|
2223
|
+
* {@link WorkflowStateError}, which fails the step/run — Rule 8).
|
|
2224
|
+
*/
|
|
2225
|
+
readonly setState: (next: unknown) => void;
|
|
2226
|
+
}
|
|
2227
|
+
interface StepResult {
|
|
2228
|
+
readonly stepId: string;
|
|
2229
|
+
readonly kind: Step["kind"];
|
|
2230
|
+
readonly status: "completed" | "failed" | "skipped" | "suspended";
|
|
2231
|
+
readonly attempts: number;
|
|
2232
|
+
readonly durationMs: number;
|
|
2233
|
+
readonly output?: unknown;
|
|
2234
|
+
readonly error?: {
|
|
2235
|
+
name: string;
|
|
2236
|
+
message: string;
|
|
2237
|
+
};
|
|
2238
|
+
}
|
|
2239
|
+
interface WorkflowRun<TOutput = unknown> {
|
|
2240
|
+
readonly id: string;
|
|
2241
|
+
readonly name: string;
|
|
2242
|
+
readonly status: "running" | "completed" | "failed" | "suspended" | "cancelled";
|
|
2243
|
+
readonly output?: TOutput;
|
|
2244
|
+
readonly error?: {
|
|
2245
|
+
name: string;
|
|
2246
|
+
message: string;
|
|
2247
|
+
};
|
|
2248
|
+
readonly startedAt: number;
|
|
2249
|
+
readonly endedAt?: number;
|
|
2250
|
+
readonly stepResults: ReadonlyArray<StepResult>;
|
|
2251
|
+
}
|
|
2252
|
+
/**
|
|
2253
|
+
* SE28 — a step-level workflow event emitted by `Workflow.stream()` as top-level
|
|
2254
|
+
* steps run. Coarse-grained (one event per top-level step; nested
|
|
2255
|
+
* parallel/branch/foreach emit as their single wrapping step), distinct from the
|
|
2256
|
+
* token-delta agent stream. Discriminate on `type`.
|
|
2257
|
+
*
|
|
2258
|
+
* @public
|
|
2259
|
+
*/
|
|
2260
|
+
type WorkflowEvent = {
|
|
2261
|
+
readonly type: "step_started";
|
|
2262
|
+
readonly stepId: string;
|
|
2263
|
+
} | {
|
|
2264
|
+
readonly type: "step_completed";
|
|
2265
|
+
readonly stepId: string;
|
|
2266
|
+
readonly output: unknown;
|
|
2267
|
+
} | {
|
|
2268
|
+
readonly type: "step_failed";
|
|
2269
|
+
readonly stepId: string;
|
|
2270
|
+
readonly error: {
|
|
2271
|
+
readonly name: string;
|
|
2272
|
+
readonly message: string;
|
|
2273
|
+
};
|
|
2274
|
+
} | {
|
|
2275
|
+
readonly type: "workflow_suspended";
|
|
2276
|
+
readonly stepId: string;
|
|
2277
|
+
} | {
|
|
2278
|
+
readonly type: "workflow_completed";
|
|
2279
|
+
};
|
|
2280
|
+
/**
|
|
2281
|
+
* SE28 — the async iterator returned by `Workflow.stream()`. Yields
|
|
2282
|
+
* {@link WorkflowEvent}s in execution order; `result` resolves to the same
|
|
2283
|
+
* terminal {@link WorkflowRun} the `run()` path returns (the authoritative
|
|
2284
|
+
* outcome — the stream ends when the run terminates).
|
|
2285
|
+
*
|
|
2286
|
+
* @public
|
|
2287
|
+
*/
|
|
2288
|
+
type WorkflowStream<TOutput = unknown> = AsyncIterableIterator<WorkflowEvent> & {
|
|
2289
|
+
readonly result: Promise<WorkflowRun<TOutput>>;
|
|
2290
|
+
};
|
|
2291
|
+
interface WorkflowPersistenceOptions {
|
|
2292
|
+
readonly backend: "memory" | "json";
|
|
2293
|
+
/** Required for `backend: "json"`. */
|
|
2294
|
+
readonly dir?: string;
|
|
2295
|
+
}
|
|
2296
|
+
interface WorkflowOptions {
|
|
2297
|
+
readonly name: string;
|
|
2298
|
+
readonly persistence?: WorkflowPersistenceOptions;
|
|
2299
|
+
/**
|
|
2300
|
+
* SE27 — Zod schema for the WHOLE workflow's input. When set, `run(input)`
|
|
2301
|
+
* validates `input` BEFORE step 1; a mismatch yields `status: "failed"` with a
|
|
2302
|
+
* typed {@link WorkflowInputError} in `error` (fail-fast, no step runs, no
|
|
2303
|
+
* silent coerce). Absent ⇒ no whole-workflow input validation (unchanged).
|
|
2304
|
+
*/
|
|
2305
|
+
readonly inputSchema?: ZodType;
|
|
2306
|
+
/**
|
|
2307
|
+
* SE27 — Zod schema for the workflow's final output. When set, the terminal
|
|
2308
|
+
* `completed` output is validated before `WorkflowRun.output` is populated; a
|
|
2309
|
+
* mismatch yields `status: "failed"` with a typed {@link WorkflowOutputError}.
|
|
2310
|
+
* Only validated on the `completed` path (suspended/failed runs skip it).
|
|
2311
|
+
*/
|
|
2312
|
+
readonly outputSchema?: ZodType;
|
|
2313
|
+
/**
|
|
2314
|
+
* SE29 — Zod schema for the workflow's shared state (see `StepContext.state` /
|
|
2315
|
+
* `setState`). When set, `initialState` and every `setState(next)` are
|
|
2316
|
+
* validated against it (a mismatch throws {@link WorkflowStateError}). When
|
|
2317
|
+
* `initialState` is absent, `state` starts as `undefined` and validation fires
|
|
2318
|
+
* on the first `setState` call.
|
|
2319
|
+
*/
|
|
2320
|
+
readonly stateSchema?: ZodType;
|
|
2321
|
+
/**
|
|
2322
|
+
* SE29 — the initial shared state, seeded onto `StepContext.state` before
|
|
2323
|
+
* step 1. Validated against `stateSchema` when both are set. Persisted across
|
|
2324
|
+
* suspend/resume.
|
|
2325
|
+
*/
|
|
2326
|
+
readonly initialState?: unknown;
|
|
2327
|
+
/** Internal — minted at `.commit()`. Not user-facing. */
|
|
2328
|
+
readonly workflowId?: string;
|
|
2329
|
+
}
|
|
2330
|
+
interface WorkflowRunOptions {
|
|
2331
|
+
readonly signal?: AbortSignal;
|
|
2332
|
+
/** Override run ID for deterministic resume (advanced; default = mintRunId). */
|
|
2333
|
+
readonly runId?: string;
|
|
2334
|
+
/**
|
|
2335
|
+
* Opt-in Task wrapping (ADRs D363, D374). Registers the workflow run
|
|
2336
|
+
* as a `Task` (kind="workflow") with a `wf-` namespaced id (D368,
|
|
2337
|
+
* EC-5). The task transitions terminal when `Workflow.run` resolves.
|
|
2338
|
+
*
|
|
2339
|
+
* Auto-id: `wf-{runId}`.
|
|
2340
|
+
*
|
|
2341
|
+
* @public
|
|
2342
|
+
*/
|
|
2343
|
+
readonly task?: true | {
|
|
2344
|
+
id?: string;
|
|
2345
|
+
meta?: Record<string, unknown>;
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
interface WorkflowResumeOptions<TI = unknown> {
|
|
2349
|
+
readonly runId: string;
|
|
2350
|
+
readonly workflow: {
|
|
2351
|
+
run: (input: TI, opts?: WorkflowRunOptions) => Promise<WorkflowRun>;
|
|
2352
|
+
};
|
|
2353
|
+
readonly payload?: unknown;
|
|
2354
|
+
readonly signal?: AbortSignal;
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
/**
|
|
2358
|
+
* Public `Workflow` class — declarative multi-step orchestration over
|
|
2359
|
+
* `Agent.send`, `Handoff`, `Agent.batch` and friends (Adoption Roadmap #5;
|
|
2360
|
+
* ADRs D230-D248).
|
|
2361
|
+
*
|
|
2362
|
+
* Usage:
|
|
2363
|
+
*
|
|
2364
|
+
* import { Agent } from "@theokit/sdk";
|
|
2365
|
+
* import { Workflow, fn, agentStep } from "@theokit/sdk/workflow";
|
|
2366
|
+
*
|
|
2367
|
+
* const classifier = await Agent.create({ ... });
|
|
2368
|
+
* const wf = Workflow.create({ name: "demo" })
|
|
2369
|
+
* .then(fn("validate", (input: { id: string }) => {
|
|
2370
|
+
* if (!input.id) throw new Error("missing id");
|
|
2371
|
+
* return input;
|
|
2372
|
+
* }))
|
|
2373
|
+
* .then(agentStep("classify", classifier, (i) => `Classify: ${JSON.stringify(i)}`))
|
|
2374
|
+
* .commit();
|
|
2375
|
+
*
|
|
2376
|
+
* const run = await wf.run({ id: "x" });
|
|
2377
|
+
* console.log(run.status, run.output);
|
|
2378
|
+
*
|
|
2379
|
+
* @public
|
|
2380
|
+
*/
|
|
2381
|
+
|
|
2382
|
+
declare class WorkflowBuilder<TInput = unknown, TOutput = unknown> {
|
|
2383
|
+
private readonly options;
|
|
2384
|
+
private readonly _steps;
|
|
2385
|
+
private _committed;
|
|
2386
|
+
then<TO = unknown>(step: Step): WorkflowBuilder<TInput, TO>;
|
|
2387
|
+
parallel(branches: ReadonlyArray<ReadonlyArray<Step>>, opts?: {
|
|
2388
|
+
id?: string;
|
|
2389
|
+
concurrency?: number;
|
|
2390
|
+
errorPolicy?: "fail-fast" | "collect";
|
|
2391
|
+
}): WorkflowBuilder<TInput, unknown[]>;
|
|
2392
|
+
branch(predicates: BranchStep["predicates"], opts?: {
|
|
2393
|
+
id?: string;
|
|
2394
|
+
fallback?: ReadonlyArray<Step>;
|
|
2395
|
+
}): WorkflowBuilder<TInput, unknown>;
|
|
2396
|
+
foreach(iterableFrom: string, step: Step, opts?: {
|
|
2397
|
+
id?: string;
|
|
2398
|
+
concurrency?: number;
|
|
2399
|
+
}): WorkflowBuilder<TInput, unknown[]>;
|
|
2400
|
+
dowhile(step: Step, condFn: DowhileStep["condFn"], opts?: {
|
|
2401
|
+
id?: string;
|
|
2402
|
+
maxIterations?: number;
|
|
2403
|
+
}): WorkflowBuilder<TInput, unknown>;
|
|
2404
|
+
sleep(durationMs: number, id?: string): WorkflowBuilder<TInput, TOutput>;
|
|
2405
|
+
suspend(opts?: {
|
|
2406
|
+
id?: string;
|
|
2407
|
+
payloadSchema?: ZodType;
|
|
2408
|
+
}): WorkflowBuilder<TInput, unknown>;
|
|
2409
|
+
commit(): Workflow<TInput, TOutput>;
|
|
2410
|
+
private validateUniqueIds;
|
|
2411
|
+
private assertNotCommitted;
|
|
2412
|
+
}
|
|
2413
|
+
declare class Workflow<TInput = unknown, TOutput = unknown> {
|
|
2414
|
+
private readonly _options;
|
|
2415
|
+
private readonly _steps;
|
|
2416
|
+
/**
|
|
2417
|
+
* Construct a workflow builder. Validate options via Zod and return a
|
|
2418
|
+
* `WorkflowBuilder` for fluent chaining. Call `.commit()` to obtain the
|
|
2419
|
+
* immutable `Workflow`.
|
|
2420
|
+
*/
|
|
2421
|
+
static create<TI = unknown, TO = unknown>(options: WorkflowOptions): WorkflowBuilder<TI, TO>;
|
|
2422
|
+
/**
|
|
2423
|
+
* Run this workflow with the given input. Returns a populated
|
|
2424
|
+
* `WorkflowRun`. Errors inside a step DO NOT throw — they propagate via
|
|
2425
|
+
* `run.status === "failed"`.
|
|
2426
|
+
*/
|
|
2427
|
+
run(input: TInput, opts?: WorkflowRunOptions): Promise<WorkflowRun<TOutput>>;
|
|
2428
|
+
/**
|
|
2429
|
+
* SE28 — run the workflow and STREAM step-level events as they happen. Returns
|
|
2430
|
+
* an async iterator of {@link WorkflowEvent}s (`step_started` / `step_completed`
|
|
2431
|
+
* / `step_failed` / `workflow_suspended` / `workflow_completed`, top-level
|
|
2432
|
+
* steps) plus a `result` promise resolving to the same terminal
|
|
2433
|
+
* {@link WorkflowRun} `run()` returns. Iterate for progress; await `result` for
|
|
2434
|
+
* the outcome. The stream ends when the run terminates.
|
|
2435
|
+
*
|
|
2436
|
+
* `result` is the AUTHORITATIVE terminal status. Not every terminal state has a
|
|
2437
|
+
* closing event: a step failure emits `step_failed`, but an `outputSchema`
|
|
2438
|
+
* rejection (SE27) or an abort ends the stream WITHOUT `workflow_completed` —
|
|
2439
|
+
* always `await result` to read the final `status`. Consuming order is free:
|
|
2440
|
+
* awaiting `result` without draining, or draining without awaiting `result`,
|
|
2441
|
+
* both work (breaking out of `for await` stops the buffering early).
|
|
2442
|
+
*/
|
|
2443
|
+
stream(input: TInput, opts?: WorkflowRunOptions): WorkflowStream<TOutput>;
|
|
2444
|
+
/**
|
|
2445
|
+
* Resume a suspended workflow from its snapshot. Throws
|
|
2446
|
+
* `WorkflowSnapshotNotFoundError` if `runId` is unknown.
|
|
2447
|
+
*/
|
|
2448
|
+
static resume<TO = unknown>(opts: WorkflowResumeOptions): Promise<WorkflowRun<TO>>;
|
|
2449
|
+
}
|
|
2450
|
+
|
|
2111
2451
|
/**
|
|
2112
2452
|
* Runtime hosting a cron job. Mirrors the agent runtime split.
|
|
2113
2453
|
*
|
|
@@ -2126,11 +2466,12 @@ type CronRuntime = "local" | "cloud";
|
|
|
2126
2466
|
*/
|
|
2127
2467
|
type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
|
|
2128
2468
|
/**
|
|
2129
|
-
* Persistent cron-scheduled invocation of the Theo agent.
|
|
2469
|
+
* Persistent cron-scheduled invocation of the Theo agent or a workflow.
|
|
2130
2470
|
*
|
|
2131
|
-
* Exactly one
|
|
2132
|
-
*
|
|
2133
|
-
* continuity)
|
|
2471
|
+
* Exactly one target is set: {@link CronJob.agent} (ephemeral agent created on
|
|
2472
|
+
* each fire), {@link CronJob.agentId} (bound to an existing agent for context
|
|
2473
|
+
* continuity), or {@link CronJob.workflow} (a committed workflow run per fire;
|
|
2474
|
+
* SE35). Agent targets carry a `message`; a workflow target carries `inputData`.
|
|
2134
2475
|
*
|
|
2135
2476
|
* @public
|
|
2136
2477
|
*/
|
|
@@ -2141,17 +2482,25 @@ interface CronJob {
|
|
|
2141
2482
|
cron: string;
|
|
2142
2483
|
/** IANA timezone identifier. Defaults to `"UTC"`. */
|
|
2143
2484
|
timezone?: string;
|
|
2144
|
-
/** Message sent to the agent on each fire. */
|
|
2145
|
-
message
|
|
2146
|
-
/** Ephemeral agent options. Mutually exclusive with `agentId`. */
|
|
2485
|
+
/** Message sent to the agent on each fire. Present for agent targets; absent for a workflow target. */
|
|
2486
|
+
message?: string | SDKUserMessage;
|
|
2487
|
+
/** Ephemeral agent options. Mutually exclusive with `agentId`/`workflow`. */
|
|
2147
2488
|
agent?: AgentOptions;
|
|
2148
|
-
/** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`. */
|
|
2489
|
+
/** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`/`workflow`. */
|
|
2149
2490
|
agentId?: string;
|
|
2491
|
+
/**
|
|
2492
|
+
* SE35 — a committed {@link Workflow} run on each fire (`workflow.run(inputData)`).
|
|
2493
|
+
* Mutually exclusive with `agent`/`agentId`. Held in-memory (local runtime only —
|
|
2494
|
+
* a workflow instance cannot cross the cloud process boundary). ADR 0014.
|
|
2495
|
+
*/
|
|
2496
|
+
workflow?: Workflow;
|
|
2497
|
+
/** SE35 — input passed to `workflow.run(inputData)` on each fire. Workflow targets only. */
|
|
2498
|
+
inputData?: unknown;
|
|
2150
2499
|
/** Whether the scheduler will fire this job on schedule. */
|
|
2151
2500
|
enabled: boolean;
|
|
2152
2501
|
/** Current status. */
|
|
2153
2502
|
status: CronJobStatus;
|
|
2154
|
-
/** Runtime that hosts this job. Inferred from `agent`/`agentId` at create time. */
|
|
2503
|
+
/** Runtime that hosts this job. Inferred from `agent`/`agentId`/`workflow` at create time (a `workflow` target is always `local`). */
|
|
2155
2504
|
runtime: CronRuntime;
|
|
2156
2505
|
/** Unix ms of the last successful fire, if any. */
|
|
2157
2506
|
lastRunAt?: number;
|
|
@@ -2163,17 +2512,24 @@ interface CronJob {
|
|
|
2163
2512
|
/**
|
|
2164
2513
|
* Options for `Cron.create()`.
|
|
2165
2514
|
*
|
|
2166
|
-
* Pass `agent`
|
|
2167
|
-
*
|
|
2168
|
-
*
|
|
2515
|
+
* Pass exactly ONE target: `agent` (ephemeral agent fresh per fire), `agentId`
|
|
2516
|
+
* (reuse an existing agent — preserves conversation context), or `workflow`
|
|
2517
|
+
* (SE35 — run a committed workflow per fire). Agent targets REQUIRE `message`;
|
|
2518
|
+
* a workflow target takes `inputData` and MUST NOT set `message`. Violations are
|
|
2519
|
+
* a `ConfigurationError`.
|
|
2169
2520
|
*
|
|
2170
2521
|
* @public
|
|
2171
2522
|
*/
|
|
2172
2523
|
interface CronCreateOptions {
|
|
2173
2524
|
cron: string;
|
|
2174
|
-
|
|
2525
|
+
/** Message for an agent target. Required with `agent`/`agentId`; forbidden with `workflow`. */
|
|
2526
|
+
message?: string | SDKUserMessage;
|
|
2175
2527
|
agent?: AgentOptions;
|
|
2176
2528
|
agentId?: string;
|
|
2529
|
+
/** SE35 — a committed {@link Workflow} to run per fire. Mutually exclusive with `agent`/`agentId`. */
|
|
2530
|
+
workflow?: Workflow;
|
|
2531
|
+
/** SE35 — input for `workflow.run(inputData)`. Workflow targets only. */
|
|
2532
|
+
inputData?: unknown;
|
|
2177
2533
|
name?: string;
|
|
2178
2534
|
timezone?: string;
|
|
2179
2535
|
/** Defaults to `true`. */
|
|
@@ -2301,11 +2657,12 @@ declare class Cron {
|
|
|
2301
2657
|
*/
|
|
2302
2658
|
static disable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
|
|
2303
2659
|
/**
|
|
2304
|
-
* Manually trigger a cron job off-schedule. Returns the resulting `Run
|
|
2660
|
+
* Manually trigger a cron job off-schedule. Returns the resulting `Run`
|
|
2661
|
+
* (agent target) or `WorkflowRun` (workflow target — SE35).
|
|
2305
2662
|
*
|
|
2306
2663
|
* @public
|
|
2307
2664
|
*/
|
|
2308
|
-
static run(jobId: string, _options?: CronRunOptions): Promise<Run>;
|
|
2665
|
+
static run(jobId: string, _options?: CronRunOptions): Promise<Run | WorkflowRun>;
|
|
2309
2666
|
/**
|
|
2310
2667
|
* Activate the in-process scheduler for local cron jobs.
|
|
2311
2668
|
*
|
|
@@ -2326,4 +2683,4 @@ declare class Cron {
|
|
|
2326
2683
|
static status(_options?: CronStartOptions): Promise<CronSchedulerStatus>;
|
|
2327
2684
|
}
|
|
2328
2685
|
|
|
2329
|
-
export { type
|
|
2686
|
+
export { type CronOperationOptions as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type BudgetCheck as D, type BudgetTotal as E, type BudgetUsageEvent as F, type GetAgentOptions as G, type CloudEnv as H, type InlineSkill as I, type CloudRepo as J, type ContextBudget as K, type LocalOptions as L, type MemorySettings as M, type ContextManagerKind as N, type ObjectiveRecord as O, type ProviderRoutingSettings as P, type ContextSnapshot as Q, type ContextSource as R, type SystemPromptResolver as S, type ContextSourceStatus as T, type CreateSkillSpec as U, Cron as V, type CronCreateOptions as W, type CronGetOptions as X, type CronJob as Y, type CronJobStatus as Z, type CronListOptions as _, type AgentDefinition as a, type CronRunOptions as a0, type CronRuntime as a1, type CronSchedulerStatus as a2, type CronStartOptions as a3, type DurableGoalOptions as a4, type GoalEvent as a5, type GoalOptions as a6, type GoalResult as a7, type HookName as a8, type InvalidateCacheOptions as a9, type SDKPluginMetadata as aA, type SDKProvidersManager as aB, type SettingSource as aC, type SkillsResolver as aD, type SkillsResolverContext as aE, type SystemPromptContext as aF, type SystemPromptMemoryFact as aG, type SystemPromptSkillRef as aH, type TelemetrySettings as aI, createSkill as aJ, definePlugin as aK, type MemoryAdapter as aa, type MemoryAdapterCapabilities as ab, type MemoryContext as ac, type MemoryFact as ad, type MemoryProviderHandle as ae, type MemoryProviderInitOptions as af, type MemoryRevision as ag, type MemoryToolSchema as ah, type MemoryTurnMessage as ai, type ObjectiveStatus as aj, type PersonalityPreset as ak, type PluginContext as al, type PostAssistantReplyContext as am, type PreToolCallContext as an, type PreUserSendContext as ao, type PreUserSendResult as ap, type ProviderCapability as aq, type ProviderRoute as ar, type RecordSessionSummaryArgs as as, type ResolvedProviderRoute as at, type RunUntilIterator as au, type SDKAgentPlugins as av, type SDKAgentSkillDetail as aw, type SDKAgentSkills as ax, type SDKArtifact as ay, type SDKContextManager as az, type ContextSettings as b, type PluginsSettings as c, type SkillsSettings as d, type SDKAgent as e, type ListAgentsOptions as f, type ListResult as g, type SDKAgentInfo as h, type ListRunsOptions as i, type GetRunOptions as j, type AgentOperationOptions as k, type ProviderProfile as l, type Plugin as m, type ConversationStorageAdapter as n, type StoredMessage as o, type SessionMeta as p, type SessionMetaPatch as q, type MemoryProvider as r, type MemoryId as s, type PreToolCallDecision as t, type StepResult as u, type SDKProvider as v, type ActiveMemoryPassArgs as w, type ActiveMemoryPassResult as x, type AgentGoalConfig as y, type AgentMemory as z };
|