@theokit/sdk 2.28.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 +34 -0
- package/dist/a2a/index.cjs +373 -17
- package/dist/a2a/index.cjs.map +1 -1
- package/dist/a2a/index.js +373 -17
- package/dist/a2a/index.js.map +1 -1
- package/dist/{cron-BR1NCSk1.d.cts → cron-BNHJywtl.d.ts} +482 -18
- package/dist/{cron-DgEQCJ2i.d.ts → cron-t4oKI2Is.d.cts} +482 -18
- package/dist/cron.cjs +1143 -692
- 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 +1146 -695
- package/dist/cron.js.map +1 -1
- package/dist/{errors-DLMNb4Ka.d.cts → errors-DZpCGlYv.d.cts} +1 -1
- package/dist/{errors-CbY3pxY7.d.ts → errors-D_Bfo30u.d.ts} +1 -1
- package/dist/errors.d.cts +2 -2
- package/dist/eval.cjs +914 -508
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +915 -509
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +1038 -590
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -135
- package/dist/index.d.ts +13 -135
- package/dist/index.js +1037 -588
- package/dist/index.js.map +1 -1
- package/dist/internal/persistence/conversation-storage-fs.d.cts +4 -0
- package/dist/internal/persistence/conversation-storage-fs.d.ts +4 -0
- package/dist/internal/persistence/conversation-storage-memory.d.cts +4 -0
- package/dist/internal/persistence/conversation-storage-memory.d.ts +4 -0
- package/dist/internal/persistence/objective-coerce.d.cts +9 -0
- package/dist/internal/persistence/objective-coerce.d.ts +9 -0
- package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +30 -0
- package/dist/internal/runtime/local-agent/local-agent-goal-extensions.d.ts +80 -0
- package/dist/internal/runtime/objective/objective-store.d.ts +33 -0
- package/dist/{run-CdWiihyU.d.cts → run-CLXKMRgq.d.cts} +71 -2
- package/dist/{run-CdWiihyU.d.ts → run-CLXKMRgq.d.ts} +71 -2
- package/dist/types/agent.d.ts +32 -1
- package/dist/types/conversation-storage.d.ts +23 -0
- package/dist/types/cron.d.ts +30 -13
- package/dist/types/goal-events.d.ts +7 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/objective.d.ts +45 -0
- package/dist/types/run-events.d.ts +12 -1
- package/dist/types/run.d.ts +58 -0
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { C as CustomTool, M as ModelSelection, a4 as SDKUserMessage, a6 as SendOptions, b as Run, G as GenerateOptions, j as GenerateRunResult, N as RunToCompletionOptions, Q as RunToCompletionResult, S as SDKMessage, ad as StreamToCompletionResult, a as McpServerConfig, P as Processor } from './run-CdWiihyU.cjs';
|
|
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).
|
|
@@ -139,6 +140,13 @@ interface GoalOptions {
|
|
|
139
140
|
judgeApiKey?: string;
|
|
140
141
|
/** Optional subgoals fed to the judge prompt. */
|
|
141
142
|
subgoals?: string[];
|
|
143
|
+
/**
|
|
144
|
+
* SE33 (ADR 0012) — resolve the goal from the durable thread-scoped
|
|
145
|
+
* objective when `runUntil()` is called with NO explicit goal. Also the
|
|
146
|
+
* key the loop writes `runsUsed` / `status` progress back to. Ignored when
|
|
147
|
+
* an explicit goal is passed (that path stays ephemeral).
|
|
148
|
+
*/
|
|
149
|
+
threadId?: string;
|
|
142
150
|
/**
|
|
143
151
|
* Cancel mid-loop via `AbortController.signal`. The generator yields
|
|
144
152
|
* a `status_change: paused` event and returns at the next turn
|
|
@@ -570,6 +578,52 @@ interface BudgetTracker {
|
|
|
570
578
|
nextIteration?(): void;
|
|
571
579
|
}
|
|
572
580
|
|
|
581
|
+
/**
|
|
582
|
+
* SE33 — the durable, thread-scoped objective (Mastra Goals parity, durable half).
|
|
583
|
+
*
|
|
584
|
+
* The SDK's `runUntil` goal loop (ADRs D115-D121) is per-call/transient. SE33
|
|
585
|
+
* persists an objective in conversation storage (via the optional
|
|
586
|
+
* `getObjectiveRecord`/`setObjectiveRecord` adapter methods) so it survives
|
|
587
|
+
* reloads, is managed via `Agent` methods, and is read by `runUntil` when no
|
|
588
|
+
* explicit goal is passed. See ADR 0012.
|
|
589
|
+
*
|
|
590
|
+
* @public
|
|
591
|
+
*/
|
|
592
|
+
/** Lifecycle status of a durable objective (ADR 0012 D2). */
|
|
593
|
+
type ObjectiveStatus = "active" | "done" | "paused";
|
|
594
|
+
/**
|
|
595
|
+
* The per-objective override subset of goal options. Precedence (ADR 0012 D3):
|
|
596
|
+
* these `record.options` → the agent's standing `goal` config → built-in default.
|
|
597
|
+
* The `judgeModel` is the activation switch — with no judge resolved, the
|
|
598
|
+
* standing objective is inert (no scoring, no budget consumed).
|
|
599
|
+
*/
|
|
600
|
+
interface DurableGoalOptions {
|
|
601
|
+
/** Max judge-gated turns before the loop stops (default 20 — the `runUntil` default). */
|
|
602
|
+
readonly maxRuns?: number;
|
|
603
|
+
/** Judge model identifier (e.g. `"openai/gpt-4o-mini"`). Absent ⇒ inherit from agent `goal` config. */
|
|
604
|
+
readonly judgeModel?: string;
|
|
605
|
+
/** Optional extra judge instruction appended to the default judge prompt. */
|
|
606
|
+
readonly prompt?: string;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* A persisted objective record. Stored under the caller's `threadId` (the
|
|
610
|
+
* conversation key). `_schemaVersion` mirrors {@link import("./workflow.js").WorkflowSnapshot}
|
|
611
|
+
* for future migration (ADR 0012 D2).
|
|
612
|
+
*/
|
|
613
|
+
interface ObjectiveRecord {
|
|
614
|
+
readonly _schemaVersion: 1;
|
|
615
|
+
readonly objective: string;
|
|
616
|
+
readonly options?: DurableGoalOptions;
|
|
617
|
+
readonly status: ObjectiveStatus;
|
|
618
|
+
readonly runsUsed: number;
|
|
619
|
+
}
|
|
620
|
+
/** The standing `goal` config on an agent (ADR 0012 D3). Read when a durable objective is set. */
|
|
621
|
+
interface AgentGoalConfig {
|
|
622
|
+
readonly judgeModel?: string;
|
|
623
|
+
readonly maxRuns?: number;
|
|
624
|
+
readonly prompt?: string;
|
|
625
|
+
}
|
|
626
|
+
|
|
573
627
|
/**
|
|
574
628
|
* Pluggable persistence for conversation history (Production-Readiness #1, ADRs D303-D306).
|
|
575
629
|
*
|
|
@@ -581,6 +635,7 @@ interface BudgetTracker {
|
|
|
581
635
|
*
|
|
582
636
|
* @public
|
|
583
637
|
*/
|
|
638
|
+
|
|
584
639
|
/**
|
|
585
640
|
* Persisted message envelope used by {@link ConversationStorageAdapter}.
|
|
586
641
|
*
|
|
@@ -712,6 +767,28 @@ interface ConversationStorageAdapter {
|
|
|
712
767
|
* lazily. Adapters that cannot store side metadata MAY omit this.
|
|
713
768
|
*/
|
|
714
769
|
setSessionMeta?(conversationId: string, patch: SessionMetaPatch): Promise<void>;
|
|
770
|
+
/**
|
|
771
|
+
* SE33 — optional: read the durable {@link ObjectiveRecord} for a conversation
|
|
772
|
+
* (the thread-scoped goal). Absent ⇒ the agent's objective methods no-op
|
|
773
|
+
* (typed degradation, same contract as `getSessionMeta`). ADR 0012 D1.
|
|
774
|
+
*/
|
|
775
|
+
getObjectiveRecord?(conversationId: string): Promise<ObjectiveRecord | undefined>;
|
|
776
|
+
/**
|
|
777
|
+
* SE33 — optional: write (or, with `record: null`, CLEAR) the durable
|
|
778
|
+
* objective for a conversation. MUST create the record lazily. Adapters that
|
|
779
|
+
* cannot store side state MAY omit this. ADR 0012 D1.
|
|
780
|
+
*/
|
|
781
|
+
setObjectiveRecord?(conversationId: string, record: ObjectiveRecord | null): Promise<void>;
|
|
782
|
+
/**
|
|
783
|
+
* SE33 — optional: ATOMIC read-modify-write of the durable objective. `mutate`
|
|
784
|
+
* receives the current record (or `undefined`) and returns the next record, or
|
|
785
|
+
* `null` to clear, or `undefined` to leave it unchanged. The whole get→mutate→set
|
|
786
|
+
* MUST run under the adapter's own concurrency guard (the FS adapter holds its
|
|
787
|
+
* file lock across the read AND the write) so concurrent progress write-backs
|
|
788
|
+
* on one thread cannot drop turns (TOCTOU). Adapters that omit it fall back to a
|
|
789
|
+
* non-atomic `getObjectiveRecord` + `setObjectiveRecord` pair. ADR 0012 D1.
|
|
790
|
+
*/
|
|
791
|
+
updateObjectiveRecord?(conversationId: string, mutate: (current: ObjectiveRecord | undefined) => ObjectiveRecord | null | undefined): Promise<void>;
|
|
715
792
|
/**
|
|
716
793
|
* Optional: dispose underlying handles (close DB pool, etc.).
|
|
717
794
|
* MUST be safe to call multiple times.
|
|
@@ -1502,6 +1579,14 @@ interface AgentOptions {
|
|
|
1502
1579
|
outputProcessors?: readonly Processor[];
|
|
1503
1580
|
/** Memory configuration. Persists durable facts; auto-recalled on send. */
|
|
1504
1581
|
memory?: MemorySettings;
|
|
1582
|
+
/**
|
|
1583
|
+
* SE33 — standing goal config for a DURABLE, thread-scoped objective (Mastra
|
|
1584
|
+
* Goals parity). Read when a durable objective (`setObjective`) is set: the
|
|
1585
|
+
* per-objective values take precedence over this config, which takes
|
|
1586
|
+
* precedence over the built-in defaults. The judge is the activation switch —
|
|
1587
|
+
* with no `judgeModel` resolved, a standing objective is inert. ADR 0012.
|
|
1588
|
+
*/
|
|
1589
|
+
goal?: AgentGoalConfig;
|
|
1505
1590
|
/**
|
|
1506
1591
|
* Inline custom tools. Local runtime only — cloud agents reject any non-empty
|
|
1507
1592
|
* `tools` array. Handlers are not persisted; pass them again on resume.
|
|
@@ -1801,7 +1886,30 @@ interface SDKAgent {
|
|
|
1801
1886
|
*
|
|
1802
1887
|
* @public
|
|
1803
1888
|
*/
|
|
1804
|
-
runUntil?(goal
|
|
1889
|
+
runUntil?(goal?: string, options?: GoalOptions): RunUntilIterator;
|
|
1890
|
+
/**
|
|
1891
|
+
* SE33 — set a DURABLE, thread-scoped objective persisted via the
|
|
1892
|
+
* conversation storage (survives reload). Read by `runUntil()` when no
|
|
1893
|
+
* explicit goal is passed. `threadId` is REQUIRED (the durability key); the
|
|
1894
|
+
* call no-ops when the run is not memory-backed (the storage adapter omits the
|
|
1895
|
+
* optional objective methods). Throws `ConfigurationError` on `maxRuns <= 0`.
|
|
1896
|
+
* ADR 0012.
|
|
1897
|
+
*/
|
|
1898
|
+
setObjective?(objective: string, opts: {
|
|
1899
|
+
threadId: string;
|
|
1900
|
+
} & DurableGoalOptions): Promise<void>;
|
|
1901
|
+
/** SE33 — read the durable objective record for a thread (or `undefined`). */
|
|
1902
|
+
getObjective?(opts: {
|
|
1903
|
+
threadId: string;
|
|
1904
|
+
}): Promise<ObjectiveRecord | undefined>;
|
|
1905
|
+
/** SE33 — merge options into the active objective (only provided fields change; no-op if unset). */
|
|
1906
|
+
updateObjectiveOptions?(opts: {
|
|
1907
|
+
threadId: string;
|
|
1908
|
+
} & DurableGoalOptions): Promise<void>;
|
|
1909
|
+
/** SE33 — drop the durable objective for a thread. */
|
|
1910
|
+
clearObjective?(opts: {
|
|
1911
|
+
threadId: string;
|
|
1912
|
+
}): Promise<void>;
|
|
1805
1913
|
/**
|
|
1806
1914
|
* Fork a short-lived sub-agent with parent's credentials + system
|
|
1807
1915
|
* prompt byte-identical (ADR D112 — cache hit) and a restricted tool
|
|
@@ -2001,6 +2109,345 @@ interface ListResult<T> {
|
|
|
2001
2109
|
nextCursor?: string;
|
|
2002
2110
|
}
|
|
2003
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
|
+
|
|
2004
2451
|
/**
|
|
2005
2452
|
* Runtime hosting a cron job. Mirrors the agent runtime split.
|
|
2006
2453
|
*
|
|
@@ -2019,11 +2466,12 @@ type CronRuntime = "local" | "cloud";
|
|
|
2019
2466
|
*/
|
|
2020
2467
|
type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
|
|
2021
2468
|
/**
|
|
2022
|
-
* Persistent cron-scheduled invocation of the Theo agent.
|
|
2469
|
+
* Persistent cron-scheduled invocation of the Theo agent or a workflow.
|
|
2023
2470
|
*
|
|
2024
|
-
* Exactly one
|
|
2025
|
-
*
|
|
2026
|
-
* 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`.
|
|
2027
2475
|
*
|
|
2028
2476
|
* @public
|
|
2029
2477
|
*/
|
|
@@ -2034,17 +2482,25 @@ interface CronJob {
|
|
|
2034
2482
|
cron: string;
|
|
2035
2483
|
/** IANA timezone identifier. Defaults to `"UTC"`. */
|
|
2036
2484
|
timezone?: string;
|
|
2037
|
-
/** Message sent to the agent on each fire. */
|
|
2038
|
-
message
|
|
2039
|
-
/** 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`. */
|
|
2040
2488
|
agent?: AgentOptions;
|
|
2041
|
-
/** 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`. */
|
|
2042
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;
|
|
2043
2499
|
/** Whether the scheduler will fire this job on schedule. */
|
|
2044
2500
|
enabled: boolean;
|
|
2045
2501
|
/** Current status. */
|
|
2046
2502
|
status: CronJobStatus;
|
|
2047
|
-
/** 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`). */
|
|
2048
2504
|
runtime: CronRuntime;
|
|
2049
2505
|
/** Unix ms of the last successful fire, if any. */
|
|
2050
2506
|
lastRunAt?: number;
|
|
@@ -2056,17 +2512,24 @@ interface CronJob {
|
|
|
2056
2512
|
/**
|
|
2057
2513
|
* Options for `Cron.create()`.
|
|
2058
2514
|
*
|
|
2059
|
-
* Pass `agent`
|
|
2060
|
-
*
|
|
2061
|
-
*
|
|
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`.
|
|
2062
2520
|
*
|
|
2063
2521
|
* @public
|
|
2064
2522
|
*/
|
|
2065
2523
|
interface CronCreateOptions {
|
|
2066
2524
|
cron: string;
|
|
2067
|
-
|
|
2525
|
+
/** Message for an agent target. Required with `agent`/`agentId`; forbidden with `workflow`. */
|
|
2526
|
+
message?: string | SDKUserMessage;
|
|
2068
2527
|
agent?: AgentOptions;
|
|
2069
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;
|
|
2070
2533
|
name?: string;
|
|
2071
2534
|
timezone?: string;
|
|
2072
2535
|
/** Defaults to `true`. */
|
|
@@ -2194,11 +2657,12 @@ declare class Cron {
|
|
|
2194
2657
|
*/
|
|
2195
2658
|
static disable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
|
|
2196
2659
|
/**
|
|
2197
|
-
* 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).
|
|
2198
2662
|
*
|
|
2199
2663
|
* @public
|
|
2200
2664
|
*/
|
|
2201
|
-
static run(jobId: string, _options?: CronRunOptions): Promise<Run>;
|
|
2665
|
+
static run(jobId: string, _options?: CronRunOptions): Promise<Run | WorkflowRun>;
|
|
2202
2666
|
/**
|
|
2203
2667
|
* Activate the in-process scheduler for local cron jobs.
|
|
2204
2668
|
*
|
|
@@ -2219,4 +2683,4 @@ declare class Cron {
|
|
|
2219
2683
|
static status(_options?: CronStartOptions): Promise<CronSchedulerStatus>;
|
|
2220
2684
|
}
|
|
2221
2685
|
|
|
2222
|
-
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 };
|