@theokit/sdk 4.28.0 → 4.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.
Files changed (90) hide show
  1. package/dist/agent-7YUGJJTU.js +41 -0
  2. package/dist/agent-7YUGJJTU.js.map +1 -0
  3. package/dist/{cron-BN6JJlDw.d.ts → agent-Bzg2_uGr.d.cts} +56 -577
  4. package/dist/{cron-CoQREV_k.d.cts → agent-Ekv8y7_c.d.ts} +56 -577
  5. package/dist/agent-LD76RI74.cjs +50 -0
  6. package/dist/agent-LD76RI74.cjs.map +1 -0
  7. package/dist/{chunk-AKSBP7OO.js → chunk-5IB2UKSN.js} +5 -41
  8. package/dist/chunk-5IB2UKSN.js.map +1 -0
  9. package/dist/{chunk-PF5Y5BHG.js → chunk-5YCAR23S.js} +3 -3
  10. package/dist/{chunk-PF5Y5BHG.js.map → chunk-5YCAR23S.js.map} +1 -1
  11. package/dist/chunk-BNIFFFH3.js +129 -0
  12. package/dist/chunk-BNIFFFH3.js.map +1 -0
  13. package/dist/{chunk-LSLPF6OI.cjs → chunk-DHLZIMP6.cjs} +5 -43
  14. package/dist/chunk-DHLZIMP6.cjs.map +1 -0
  15. package/dist/chunk-FKCC2MED.js +43 -0
  16. package/dist/chunk-FKCC2MED.js.map +1 -0
  17. package/dist/{chunk-PN53WGEI.cjs → chunk-GWMQ5CS3.cjs} +633 -741
  18. package/dist/chunk-GWMQ5CS3.cjs.map +1 -0
  19. package/dist/{chunk-QUTUJ6P6.cjs → chunk-HK7ZHSAX.cjs} +25 -16
  20. package/dist/chunk-HK7ZHSAX.cjs.map +1 -0
  21. package/dist/{chunk-XW6RXVGB.js → chunk-ISZ3MBUD.js} +610 -718
  22. package/dist/chunk-ISZ3MBUD.js.map +1 -0
  23. package/dist/{chunk-MQLCZ4HJ.cjs → chunk-JLMXKTBX.cjs} +4 -4
  24. package/dist/{chunk-MQLCZ4HJ.cjs.map → chunk-JLMXKTBX.cjs.map} +1 -1
  25. package/dist/chunk-LALRCFSN.cjs +46 -0
  26. package/dist/chunk-LALRCFSN.cjs.map +1 -0
  27. package/dist/{chunk-I53QDJVI.cjs → chunk-NG6B2PMA.cjs} +5 -5
  28. package/dist/{chunk-I53QDJVI.cjs.map → chunk-NG6B2PMA.cjs.map} +1 -1
  29. package/dist/{chunk-DUK5WMKJ.js → chunk-R6ZP6KNB.js} +25 -16
  30. package/dist/chunk-R6ZP6KNB.js.map +1 -0
  31. package/dist/chunk-RZQ6E5YZ.cjs +131 -0
  32. package/dist/chunk-RZQ6E5YZ.cjs.map +1 -0
  33. package/dist/{chunk-G6GO6BXD.js → chunk-XAUBQMQU.js} +3 -3
  34. package/dist/{chunk-G6GO6BXD.js.map → chunk-XAUBQMQU.js.map} +1 -1
  35. package/dist/compact-session-OO2GD76G.js +1 -1
  36. package/dist/compact-session-OO7NVWPB.cjs +1 -1
  37. package/dist/cron-CjzvXGT2.d.cts +579 -0
  38. package/dist/cron-D0Z29gI-.d.ts +579 -0
  39. package/dist/cron.cjs +13 -11
  40. package/dist/cron.d.cts +2 -1
  41. package/dist/cron.d.ts +2 -1
  42. package/dist/cron.js +12 -10
  43. package/dist/eval.cjs +17 -15
  44. package/dist/eval.cjs.map +1 -1
  45. package/dist/eval.js +13 -11
  46. package/dist/eval.js.map +1 -1
  47. package/dist/{index-manager-CB6I7XFQ.cjs → index-manager-H7HUMW52.cjs} +5 -5
  48. package/dist/{index-manager-CB6I7XFQ.cjs.map → index-manager-H7HUMW52.cjs.map} +1 -1
  49. package/dist/{index-manager-L27Q3QAC.js → index-manager-P7ZUX2RG.js} +4 -4
  50. package/dist/{index-manager-L27Q3QAC.js.map → index-manager-P7ZUX2RG.js.map} +1 -1
  51. package/dist/index.cjs +65 -44
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.cts +18 -4
  54. package/dist/index.d.ts +18 -4
  55. package/dist/index.js +41 -20
  56. package/dist/index.js.map +1 -1
  57. package/dist/internal/persistence/index.cjs +10 -10
  58. package/dist/internal/persistence/index.js +2 -2
  59. package/dist/internal/persistence/jsonl.d.cts +7 -0
  60. package/dist/internal/persistence/jsonl.d.ts +7 -0
  61. package/dist/internal/persistence/session-writer.d.cts +56 -0
  62. package/dist/internal/persistence/session-writer.d.ts +56 -0
  63. package/dist/internal/persistence/transcript-ops.d.cts +71 -0
  64. package/dist/internal/persistence/transcript-ops.d.ts +71 -0
  65. package/dist/internal/plugins/types.d.cts +1 -1
  66. package/dist/internal/plugins/types.d.ts +1 -1
  67. package/dist/persistence.cjs +115 -12
  68. package/dist/persistence.cjs.map +1 -1
  69. package/dist/persistence.d.cts +2 -0
  70. package/dist/persistence.d.ts +2 -0
  71. package/dist/persistence.js +105 -3
  72. package/dist/persistence.js.map +1 -1
  73. package/dist/skills.cjs +4 -3
  74. package/dist/skills.js +2 -1
  75. package/dist/subagents-loader.cjs +19 -0
  76. package/dist/subagents-loader.cjs.map +1 -0
  77. package/dist/subagents-loader.d.cts +39 -0
  78. package/dist/subagents-loader.d.ts +39 -0
  79. package/dist/subagents-loader.js +16 -0
  80. package/dist/subagents-loader.js.map +1 -0
  81. package/dist/types/plugin.d.ts +32 -0
  82. package/dist/workflow.cjs +1 -1
  83. package/dist/workflow.js +1 -1
  84. package/package.json +12 -2
  85. package/dist/chunk-AKSBP7OO.js.map +0 -1
  86. package/dist/chunk-DUK5WMKJ.js.map +0 -1
  87. package/dist/chunk-LSLPF6OI.cjs.map +0 -1
  88. package/dist/chunk-PN53WGEI.cjs.map +0 -1
  89. package/dist/chunk-QUTUJ6P6.cjs.map +0 -1
  90. package/dist/chunk-XW6RXVGB.js.map +0 -1
@@ -0,0 +1,41 @@
1
+ export { Agent } from './chunk-ISZ3MBUD.js';
2
+ import './chunk-2SFBB54R.js';
3
+ import './chunk-HRA3CPGG.js';
4
+ import './chunk-SQLZ7ONU.js';
5
+ import './chunk-K2BQQ445.js';
6
+ import './chunk-U6QGZHPN.js';
7
+ import './chunk-NRSH7RJY.js';
8
+ import './chunk-6CLRANZA.js';
9
+ import './chunk-EEZ7CFMM.js';
10
+ import './chunk-XAUBQMQU.js';
11
+ import './chunk-XIG2IE3L.js';
12
+ import './chunk-7GFX45DD.js';
13
+ import './chunk-DGRZNMTU.js';
14
+ import './chunk-FD2UT76F.js';
15
+ import './chunk-U54XCYG3.js';
16
+ import './chunk-FV3YEMQ7.js';
17
+ import './chunk-6X6ID4MO.js';
18
+ import './chunk-UJ7IQJAG.js';
19
+ import './chunk-7AD3ZTZL.js';
20
+ import './chunk-V4XRLPEF.js';
21
+ import './chunk-5PZMMF4H.js';
22
+ import './chunk-HZQEDNF6.js';
23
+ import './chunk-77FOZCOT.js';
24
+ import './chunk-2XLKLVVR.js';
25
+ import './chunk-ZZWTY3RX.js';
26
+ import './chunk-BXV2QUIC.js';
27
+ import './chunk-4VPXM6UU.js';
28
+ import './chunk-S2BBRVQX.js';
29
+ import './chunk-BNIFFFH3.js';
30
+ import './chunk-WA3FO4R7.js';
31
+ import './chunk-X2FR4OIT.js';
32
+ import './chunk-KAP4GJHO.js';
33
+ import './chunk-LU7VALW5.js';
34
+ import './chunk-5NBUH3NO.js';
35
+ import './chunk-5IB2UKSN.js';
36
+ import './chunk-POQT2OIF.js';
37
+ import './chunk-FKCC2MED.js';
38
+ import './chunk-WLKFWQSJ.js';
39
+ import './chunk-JTFYYKDT.js';
40
+ //# sourceMappingURL=agent-7YUGJJTU.js.map
41
+ //# sourceMappingURL=agent-7YUGJJTU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"agent-7YUGJJTU.js"}
@@ -1,6 +1,5 @@
1
+ import { M as ModelSelection, ac as SDKUserMessage, ae as SendOptions, b as Run, G as GenerateOptions, n as GenerateRunResult, _ as RunToCompletionOptions, $ as RunToCompletionResult, S as SDKMessage, al as StreamToCompletionResult, C as CustomTool, c as PermissionMode, a as McpServerConfig, P as Processor } from './run-OJbGyweZ.cjs';
1
2
  import * as zod from 'zod';
2
- import { ZodType } from 'zod';
3
- import { M as ModelSelection, ac as SDKUserMessage, ae as SendOptions, b as Run, G as GenerateOptions, n as GenerateRunResult, _ as RunToCompletionOptions, $ as RunToCompletionResult, S as SDKMessage, al as StreamToCompletionResult, C as CustomTool, c as PermissionMode, a as McpServerConfig, P as Processor, u as MessageOrigin } from './run-OJbGyweZ.js';
4
3
 
5
4
  /**
6
5
  * `SessionRecord` — the native on-disk transcript record shape (SE40).
@@ -1319,6 +1318,60 @@ interface PreToolCallDecision {
1319
1318
  block: true;
1320
1319
  message: string;
1321
1320
  }
1321
+ /** #65 — context for the `post_tool_call` hook (fired after a tool runs). @public */
1322
+ interface PostToolCallContext {
1323
+ name: string;
1324
+ args: Record<string, unknown>;
1325
+ result: {
1326
+ stdout: string;
1327
+ stderr: string;
1328
+ exitCode?: number | null;
1329
+ };
1330
+ agentId: string;
1331
+ runId: string;
1332
+ }
1333
+ /** #65 — context for the `on_session_start` / `on_session_end` hooks. @public */
1334
+ interface SessionLifecycleContext {
1335
+ agentId: string;
1336
+ runId: string;
1337
+ }
1338
+ /** #65 — context for the `transform_tool_result` / `transform_llm_output` hooks. @public */
1339
+ interface TransformContext {
1340
+ agentId: string;
1341
+ runId: string;
1342
+ }
1343
+ /**
1344
+ * M82 — one tool call of the turn, as seen by `transform_tool_result`. `id` is the correlation key
1345
+ * back into the batch: it equals the `toolUseId` of the matching `tool_result` part.
1346
+ *
1347
+ * @public
1348
+ */
1349
+ interface ToolCallSummary {
1350
+ id: string;
1351
+ name: string;
1352
+ args: Record<string, unknown>;
1353
+ }
1354
+ /**
1355
+ * M82 — context for `transform_tool_result`, the only tool-stage hook whose return value the SDK
1356
+ * actually applies (`#runTransform` folds it; `#runFireAndForget` discards `post_tool_call`'s).
1357
+ *
1358
+ * Before M82 this seam knew only `{agentId, runId}`, so a hook could transform results but could not
1359
+ * tell WHICH tool produced which one. A policy scoped to a tool name — the common case — therefore
1360
+ * had to live on `post_tool_call`, whose return is discarded, and silently degraded to observation.
1361
+ *
1362
+ * `toolCalls` is PLURAL because the seam is batch-shaped: `dispatchTools` runs every tool call of the
1363
+ * turn and the hook receives all results together. A singular `name` would have to lie in any
1364
+ * multi-tool turn. Correlate with `LlmToolResultPart.toolUseId === ToolCallSummary.id`.
1365
+ *
1366
+ * Kept separate from {@link TransformContext} on purpose: that type is shared with
1367
+ * `transform_llm_output`, which has no tool call at all, and an optional field there would be
1368
+ * permanently `undefined` for half its consumers.
1369
+ *
1370
+ * @public
1371
+ */
1372
+ interface ToolResultTransformContext extends TransformContext {
1373
+ toolCalls: readonly ToolCallSummary[];
1374
+ }
1322
1375
  /**
1323
1376
  * Context passed to `pre_user_send` hook handlers (ADR D145).
1324
1377
  *
@@ -2060,578 +2113,4 @@ interface ListResult<T> {
2060
2113
  nextCursor?: string;
2061
2114
  }
2062
2115
 
2063
- /**
2064
- * Public type contract for `Workflow.create / .run / .resume` (Adoption
2065
- * Roadmap #5; ADRs D230-D248).
2066
- *
2067
- * Step types form a discriminated union by `kind`. Helper factory functions
2068
- * (`fn()`, `agentStep()`) live in `workflow.ts` and hide the discriminator
2069
- * from end users.
2070
- *
2071
- * @public
2072
- */
2073
-
2074
- type Step = FnStep | AgentStep | ParallelStep | BranchStep | ForeachStep | DowhileStep | SleepStep | SuspendStep;
2075
- /** A pure function step. */
2076
- interface FnStep {
2077
- readonly kind: "fn";
2078
- readonly id: string;
2079
- readonly fn: (input: unknown, ctx: StepContext) => Promise<unknown> | unknown;
2080
- readonly inputSchema?: ZodType;
2081
- readonly outputSchema?: ZodType;
2082
- readonly retry?: RetryPolicy;
2083
- /** D238 — slot reserved; runtime throws if engine not yet implemented. */
2084
- readonly compensate?: (input: unknown, output: unknown, error: Error) => Promise<void> | void;
2085
- }
2086
- /** An agent.send-driven step. */
2087
- interface AgentStep {
2088
- readonly kind: "agent";
2089
- readonly id: string;
2090
- readonly agent: SDKAgent;
2091
- readonly promptTemplate: string | ((input: unknown) => string);
2092
- readonly retry?: RetryPolicy;
2093
- /**
2094
- * SE3 — provenance stamped onto this step's `agent.send()` (forwarded to
2095
- * `RunResult.origin`). Squad sets `{ kind: "peer", from: "agent-<i-1>" }` on
2096
- * every step after the first so a peer-driven turn is attributable.
2097
- */
2098
- readonly origin?: MessageOrigin;
2099
- }
2100
- /** N concurrent branches, each its own mini-step-list. */
2101
- interface ParallelStep {
2102
- readonly kind: "parallel";
2103
- readonly id: string;
2104
- readonly branches: ReadonlyArray<ReadonlyArray<Step>>;
2105
- readonly concurrency?: number;
2106
- readonly errorPolicy?: "fail-fast" | "collect";
2107
- }
2108
- /** First-match-wins predicates + optional fallback. */
2109
- interface BranchStep {
2110
- readonly kind: "branch";
2111
- readonly id: string;
2112
- readonly predicates: ReadonlyArray<readonly [(input: unknown) => boolean | Promise<boolean>, ReadonlyArray<Step>]>;
2113
- readonly fallback?: ReadonlyArray<Step>;
2114
- }
2115
- /** Map a step over an upstream array output. */
2116
- interface ForeachStep {
2117
- readonly kind: "foreach";
2118
- readonly id: string;
2119
- /** ID of an upstream top-level step whose output is iterable. */
2120
- readonly iterableFrom: string;
2121
- readonly step: Step;
2122
- readonly concurrency?: number;
2123
- }
2124
- /** Loop a step until condFn returns false. */
2125
- interface DowhileStep {
2126
- readonly kind: "dowhile";
2127
- readonly id: string;
2128
- readonly step: Step;
2129
- readonly condFn: (output: unknown, iteration: number) => boolean | Promise<boolean>;
2130
- readonly maxIterations?: number;
2131
- }
2132
- /** Pause for a fixed duration. */
2133
- interface SleepStep {
2134
- readonly kind: "sleep";
2135
- readonly id: string;
2136
- readonly durationMs: number;
2137
- }
2138
- /** Standalone explicit suspend point. */
2139
- interface SuspendStep {
2140
- readonly kind: "suspend";
2141
- readonly id: string;
2142
- readonly payloadSchema?: ZodType;
2143
- }
2144
- /** D237 — retry policy applied per fn/agent step. */
2145
- interface RetryPolicy {
2146
- /** Total attempts (MIN 1, MAX 20). `1` = no retry. */
2147
- readonly maxAttempts: number;
2148
- readonly initialBackoffMs?: number;
2149
- readonly backoffCoefficient?: number;
2150
- readonly maximumBackoffMs?: number;
2151
- readonly nonRetryableErrors?: ReadonlyArray<string>;
2152
- }
2153
- /** D247 — context handed to every step.fn. */
2154
- interface StepContext {
2155
- readonly runId: string;
2156
- readonly signal: AbortSignal;
2157
- readonly log: {
2158
- debug: (msg: string, attrs?: Record<string, unknown>) => void;
2159
- info: (msg: string, attrs?: Record<string, unknown>) => void;
2160
- warn: (msg: string, attrs?: Record<string, unknown>) => void;
2161
- };
2162
- /** Pause the workflow; resume via `Workflow.resume({...})`. */
2163
- readonly suspend: (payload?: unknown) => Promise<never>;
2164
- /**
2165
- * SE29 — the workflow's shared state (from `WorkflowOptions.initialState`,
2166
- * mutated by {@link setState}), visible to every subsequent step in the run.
2167
- * `undefined` when no `initialState`/`setState` has run. Persisted across
2168
- * suspend/resume.
2169
- */
2170
- readonly state: unknown;
2171
- /**
2172
- * SE29 — update the shared state for subsequent steps. Validated against
2173
- * `WorkflowOptions.stateSchema` when set (a mismatch throws
2174
- * {@link WorkflowStateError}, which fails the step/run — Rule 8).
2175
- */
2176
- readonly setState: (next: unknown) => void;
2177
- }
2178
- interface StepResult {
2179
- readonly stepId: string;
2180
- readonly kind: Step["kind"];
2181
- readonly status: "completed" | "failed" | "skipped" | "suspended";
2182
- readonly attempts: number;
2183
- readonly durationMs: number;
2184
- readonly output?: unknown;
2185
- readonly error?: {
2186
- name: string;
2187
- message: string;
2188
- };
2189
- }
2190
- interface WorkflowRun<TOutput = unknown> {
2191
- readonly id: string;
2192
- readonly name: string;
2193
- readonly status: "running" | "completed" | "failed" | "suspended" | "cancelled";
2194
- readonly output?: TOutput;
2195
- readonly error?: {
2196
- name: string;
2197
- message: string;
2198
- };
2199
- readonly startedAt: number;
2200
- readonly endedAt?: number;
2201
- readonly stepResults: ReadonlyArray<StepResult>;
2202
- }
2203
- /**
2204
- * SE28 — a step-level workflow event emitted by `Workflow.stream()` as top-level
2205
- * steps run. Coarse-grained (one event per top-level step; nested
2206
- * parallel/branch/foreach emit as their single wrapping step), distinct from the
2207
- * token-delta agent stream. Discriminate on `type`.
2208
- *
2209
- * @public
2210
- */
2211
- type WorkflowEvent = {
2212
- readonly type: "step_started";
2213
- readonly stepId: string;
2214
- } | {
2215
- readonly type: "step_completed";
2216
- readonly stepId: string;
2217
- readonly output: unknown;
2218
- } | {
2219
- readonly type: "step_failed";
2220
- readonly stepId: string;
2221
- readonly error: {
2222
- readonly name: string;
2223
- readonly message: string;
2224
- };
2225
- } | {
2226
- readonly type: "workflow_suspended";
2227
- readonly stepId: string;
2228
- } | {
2229
- readonly type: "workflow_completed";
2230
- };
2231
- /**
2232
- * SE28 — the async iterator returned by `Workflow.stream()`. Yields
2233
- * {@link WorkflowEvent}s in execution order; `result` resolves to the same
2234
- * terminal {@link WorkflowRun} the `run()` path returns (the authoritative
2235
- * outcome — the stream ends when the run terminates).
2236
- *
2237
- * @public
2238
- */
2239
- type WorkflowStream<TOutput = unknown> = AsyncIterableIterator<WorkflowEvent> & {
2240
- readonly result: Promise<WorkflowRun<TOutput>>;
2241
- };
2242
- interface WorkflowPersistenceOptions {
2243
- readonly backend: "memory" | "json";
2244
- /** Required for `backend: "json"`. */
2245
- readonly dir?: string;
2246
- }
2247
- interface WorkflowOptions {
2248
- readonly name: string;
2249
- readonly persistence?: WorkflowPersistenceOptions;
2250
- /**
2251
- * SE27 — Zod schema for the WHOLE workflow's input. When set, `run(input)`
2252
- * validates `input` BEFORE step 1; a mismatch yields `status: "failed"` with a
2253
- * typed {@link WorkflowInputError} in `error` (fail-fast, no step runs, no
2254
- * silent coerce). Absent ⇒ no whole-workflow input validation (unchanged).
2255
- */
2256
- readonly inputSchema?: ZodType;
2257
- /**
2258
- * SE27 — Zod schema for the workflow's final output. When set, the terminal
2259
- * `completed` output is validated before `WorkflowRun.output` is populated; a
2260
- * mismatch yields `status: "failed"` with a typed {@link WorkflowOutputError}.
2261
- * Only validated on the `completed` path (suspended/failed runs skip it).
2262
- */
2263
- readonly outputSchema?: ZodType;
2264
- /**
2265
- * SE29 — Zod schema for the workflow's shared state (see `StepContext.state` /
2266
- * `setState`). When set, `initialState` and every `setState(next)` are
2267
- * validated against it (a mismatch throws {@link WorkflowStateError}). When
2268
- * `initialState` is absent, `state` starts as `undefined` and validation fires
2269
- * on the first `setState` call.
2270
- */
2271
- readonly stateSchema?: ZodType;
2272
- /**
2273
- * SE29 — the initial shared state, seeded onto `StepContext.state` before
2274
- * step 1. Validated against `stateSchema` when both are set. Persisted across
2275
- * suspend/resume.
2276
- */
2277
- readonly initialState?: unknown;
2278
- /** Internal — minted at `.commit()`. Not user-facing. */
2279
- readonly workflowId?: string;
2280
- }
2281
- interface WorkflowRunOptions {
2282
- readonly signal?: AbortSignal;
2283
- /** Override run ID for deterministic resume (advanced; default = mintRunId). */
2284
- readonly runId?: string;
2285
- /**
2286
- * Opt-in Task wrapping (ADRs D363, D374). Registers the workflow run
2287
- * as a `Task` (kind="workflow") with a `wf-` namespaced id (D368,
2288
- * EC-5). The task transitions terminal when `Workflow.run` resolves.
2289
- *
2290
- * Auto-id: `wf-{runId}`.
2291
- *
2292
- * @public
2293
- */
2294
- readonly task?: true | {
2295
- id?: string;
2296
- meta?: Record<string, unknown>;
2297
- };
2298
- }
2299
- interface WorkflowResumeOptions<TI = unknown> {
2300
- readonly runId: string;
2301
- readonly workflow: {
2302
- run: (input: TI, opts?: WorkflowRunOptions) => Promise<WorkflowRun>;
2303
- };
2304
- readonly payload?: unknown;
2305
- readonly signal?: AbortSignal;
2306
- }
2307
-
2308
- /**
2309
- * Public `Workflow` class — declarative multi-step orchestration over
2310
- * `Agent.send`, `Handoff`, `Agent.batch` and friends (Adoption Roadmap #5;
2311
- * ADRs D230-D248).
2312
- *
2313
- * Usage:
2314
- *
2315
- * import { Agent } from "@theokit/sdk";
2316
- * import { Workflow, fn, agentStep } from "@theokit/sdk/workflow";
2317
- *
2318
- * const classifier = await Agent.create({ ... });
2319
- * const wf = Workflow.create({ name: "demo" })
2320
- * .then(fn("validate", (input: { id: string }) => {
2321
- * if (!input.id) throw new Error("missing id");
2322
- * return input;
2323
- * }))
2324
- * .then(agentStep("classify", classifier, (i) => `Classify: ${JSON.stringify(i)}`))
2325
- * .commit();
2326
- *
2327
- * const run = await wf.run({ id: "x" });
2328
- * console.log(run.status, run.output);
2329
- *
2330
- * @public
2331
- */
2332
-
2333
- declare class WorkflowBuilder<TInput = unknown, TOutput = unknown> {
2334
- private readonly options;
2335
- private readonly _steps;
2336
- private _committed;
2337
- then<TO = unknown>(step: Step): WorkflowBuilder<TInput, TO>;
2338
- parallel(branches: ReadonlyArray<ReadonlyArray<Step>>, opts?: {
2339
- id?: string;
2340
- concurrency?: number;
2341
- errorPolicy?: "fail-fast" | "collect";
2342
- }): WorkflowBuilder<TInput, unknown[]>;
2343
- branch(predicates: BranchStep["predicates"], opts?: {
2344
- id?: string;
2345
- fallback?: ReadonlyArray<Step>;
2346
- }): WorkflowBuilder<TInput, unknown>;
2347
- foreach(iterableFrom: string, step: Step, opts?: {
2348
- id?: string;
2349
- concurrency?: number;
2350
- }): WorkflowBuilder<TInput, unknown[]>;
2351
- dowhile(step: Step, condFn: DowhileStep["condFn"], opts?: {
2352
- id?: string;
2353
- maxIterations?: number;
2354
- }): WorkflowBuilder<TInput, unknown>;
2355
- sleep(durationMs: number, id?: string): WorkflowBuilder<TInput, TOutput>;
2356
- suspend(opts?: {
2357
- id?: string;
2358
- payloadSchema?: ZodType;
2359
- }): WorkflowBuilder<TInput, unknown>;
2360
- commit(): Workflow<TInput, TOutput>;
2361
- private validateUniqueIds;
2362
- private assertNotCommitted;
2363
- }
2364
- declare class Workflow<TInput = unknown, TOutput = unknown> {
2365
- private readonly _options;
2366
- private readonly _steps;
2367
- /**
2368
- * Construct a workflow builder. Validate options via Zod and return a
2369
- * `WorkflowBuilder` for fluent chaining. Call `.commit()` to obtain the
2370
- * immutable `Workflow`.
2371
- */
2372
- static create<TI = unknown, TO = unknown>(options: WorkflowOptions): WorkflowBuilder<TI, TO>;
2373
- /**
2374
- * Run this workflow with the given input. Returns a populated
2375
- * `WorkflowRun`. Errors inside a step DO NOT throw — they propagate via
2376
- * `run.status === "failed"`.
2377
- */
2378
- run(input: TInput, opts?: WorkflowRunOptions): Promise<WorkflowRun<TOutput>>;
2379
- /**
2380
- * SE28 — run the workflow and STREAM step-level events as they happen. Returns
2381
- * an async iterator of {@link WorkflowEvent}s (`step_started` / `step_completed`
2382
- * / `step_failed` / `workflow_suspended` / `workflow_completed`, top-level
2383
- * steps) plus a `result` promise resolving to the same terminal
2384
- * {@link WorkflowRun} `run()` returns. Iterate for progress; await `result` for
2385
- * the outcome. The stream ends when the run terminates.
2386
- *
2387
- * `result` is the AUTHORITATIVE terminal status. Not every terminal state has a
2388
- * closing event: a step failure emits `step_failed`, but an `outputSchema`
2389
- * rejection (SE27) or an abort ends the stream WITHOUT `workflow_completed` —
2390
- * always `await result` to read the final `status`. Consuming order is free:
2391
- * awaiting `result` without draining, or draining without awaiting `result`,
2392
- * both work (breaking out of `for await` stops the buffering early).
2393
- */
2394
- stream(input: TInput, opts?: WorkflowRunOptions): WorkflowStream<TOutput>;
2395
- /**
2396
- * Resume a suspended workflow from its snapshot. Throws
2397
- * `WorkflowSnapshotNotFoundError` if `runId` is unknown.
2398
- */
2399
- static resume<TO = unknown>(opts: WorkflowResumeOptions): Promise<WorkflowRun<TO>>;
2400
- }
2401
-
2402
- /**
2403
- * Runtime hosting a cron job. Mirrors the agent runtime split.
2404
- *
2405
- * - `local` — the in-process scheduler activated via `Cron.start()` fires the
2406
- * job while the host process is alive.
2407
- * - `cloud` — Theo PaaS schedules the job server-side; fires independent of
2408
- * any SDK process.
2409
- *
2410
- * @public
2411
- */
2412
- type CronRuntime = "local" | "cloud";
2413
- /**
2414
- * Lifecycle state reported by `Cron.list()` / `Cron.get()`.
2415
- *
2416
- * @public
2417
- */
2418
- type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
2419
- /**
2420
- * Persistent cron-scheduled invocation of the Theo agent or a workflow.
2421
- *
2422
- * Exactly one target is set: {@link CronJob.agent} (ephemeral agent created on
2423
- * each fire), {@link CronJob.agentId} (bound to an existing agent for context
2424
- * continuity), or {@link CronJob.workflow} (a committed workflow run per fire;
2425
- * SE35). Agent targets carry a `message`; a workflow target carries `inputData`.
2426
- *
2427
- * @public
2428
- */
2429
- interface CronJob {
2430
- id: string;
2431
- name?: string;
2432
- /** Standard 5-field POSIX cron expression or shorthand (`@hourly`, `@daily`, ...). */
2433
- cron: string;
2434
- /** IANA timezone identifier. Defaults to `"UTC"`. */
2435
- timezone?: string;
2436
- /** Message sent to the agent on each fire. Present for agent targets; absent for a workflow target. */
2437
- message?: string | SDKUserMessage;
2438
- /** Ephemeral agent options. Mutually exclusive with `agentId`/`workflow`. */
2439
- agent?: AgentOptions;
2440
- /** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`/`workflow`. */
2441
- agentId?: string;
2442
- /**
2443
- * SE35 — a committed {@link Workflow} run on each fire (`workflow.run(inputData)`).
2444
- * Mutually exclusive with `agent`/`agentId`. Held in-memory (local runtime only —
2445
- * a workflow instance cannot cross the cloud process boundary). ADR 0014.
2446
- */
2447
- workflow?: Workflow;
2448
- /** SE35 — input passed to `workflow.run(inputData)` on each fire. Workflow targets only. */
2449
- inputData?: unknown;
2450
- /** Whether the scheduler will fire this job on schedule. */
2451
- enabled: boolean;
2452
- /** Current status. */
2453
- status: CronJobStatus;
2454
- /** Runtime that hosts this job. Inferred from `agent`/`agentId`/`workflow` at create time (a `workflow` target is always `local`). */
2455
- runtime: CronRuntime;
2456
- /** Unix ms of the last successful fire, if any. */
2457
- lastRunAt?: number;
2458
- /** Unix ms of the next scheduled fire, computed by the scheduler. */
2459
- nextRunAt?: number;
2460
- /** Unix ms when the job was created. */
2461
- createdAt: number;
2462
- }
2463
- /**
2464
- * Options for `Cron.create()`.
2465
- *
2466
- * Pass exactly ONE target: `agent` (ephemeral agent fresh per fire), `agentId`
2467
- * (reuse an existing agent — preserves conversation context), or `workflow`
2468
- * (SE35 — run a committed workflow per fire). Agent targets REQUIRE `message`;
2469
- * a workflow target takes `inputData` and MUST NOT set `message`. Violations are
2470
- * a `ConfigurationError`.
2471
- *
2472
- * @public
2473
- */
2474
- interface CronCreateOptions {
2475
- cron: string;
2476
- /** Message for an agent target. Required with `agent`/`agentId`; forbidden with `workflow`. */
2477
- message?: string | SDKUserMessage;
2478
- agent?: AgentOptions;
2479
- agentId?: string;
2480
- /** SE35 — a committed {@link Workflow} to run per fire. Mutually exclusive with `agent`/`agentId`. */
2481
- workflow?: Workflow;
2482
- /** SE35 — input for `workflow.run(inputData)`. Workflow targets only. */
2483
- inputData?: unknown;
2484
- name?: string;
2485
- timezone?: string;
2486
- /** Defaults to `true`. */
2487
- enabled?: boolean;
2488
- /** Falls back to `THEOKIT_API_KEY`. */
2489
- apiKey?: string;
2490
- }
2491
- /**
2492
- * Options for `Cron.list()`.
2493
- *
2494
- * @public
2495
- */
2496
- type CronListOptions = {
2497
- limit?: number;
2498
- cursor?: string;
2499
- } & ({
2500
- runtime?: undefined;
2501
- } | {
2502
- runtime: "local";
2503
- cwd?: string;
2504
- } | {
2505
- runtime: "cloud";
2506
- apiKey?: string;
2507
- });
2508
- /**
2509
- * Options for `Cron.get()`.
2510
- *
2511
- * @public
2512
- */
2513
- interface CronGetOptions {
2514
- cwd?: string;
2515
- apiKey?: string;
2516
- }
2517
- /**
2518
- * Options for `Cron.delete()` / `Cron.enable()` / `Cron.disable()`.
2519
- *
2520
- * @public
2521
- */
2522
- interface CronOperationOptions {
2523
- cwd?: string;
2524
- apiKey?: string;
2525
- }
2526
- /**
2527
- * Options for `Cron.run()` — manually trigger a job off-schedule.
2528
- *
2529
- * @public
2530
- */
2531
- interface CronRunOptions {
2532
- cwd?: string;
2533
- apiKey?: string;
2534
- }
2535
- /**
2536
- * Options for `Cron.start()` — activates the in-process scheduler for local
2537
- * jobs.
2538
- *
2539
- * @public
2540
- */
2541
- interface CronStartOptions {
2542
- /** Local workspace whose `.theokit/cron/jobs.json` to load. Defaults to `process.cwd()`. */
2543
- cwd?: string;
2544
- /** Override the env API key. */
2545
- apiKey?: string;
2546
- }
2547
- /**
2548
- * Snapshot of the local scheduler returned by `Cron.status()`.
2549
- *
2550
- * @public
2551
- */
2552
- interface CronSchedulerStatus {
2553
- /** Whether the in-process scheduler is currently running. */
2554
- running: boolean;
2555
- /** Number of jobs loaded into the scheduler. */
2556
- jobCount: number;
2557
- /** Unix ms of the next scheduled fire across all jobs, if any. */
2558
- nextFireAt?: number;
2559
- /** Last error observed in the scheduler, if any. */
2560
- lastError?: {
2561
- jobId: string;
2562
- message: string;
2563
- at: number;
2564
- };
2565
- }
2566
-
2567
- /**
2568
- * Static façade for scheduling Theo agent runs on a cron expression.
2569
- *
2570
- * @public
2571
- */
2572
- declare class Cron {
2573
- private constructor();
2574
- /**
2575
- * Create and persist a cron job.
2576
- *
2577
- * @public
2578
- */
2579
- static create(options: CronCreateOptions): Promise<CronJob>;
2580
- /**
2581
- * List cron jobs (local, cloud, or both).
2582
- *
2583
- * @public
2584
- */
2585
- static list(options?: CronListOptions): Promise<ListResult<CronJob>>;
2586
- /**
2587
- * Get a single cron job by ID.
2588
- *
2589
- * @public
2590
- */
2591
- static get(jobId: string, _options?: CronGetOptions): Promise<CronJob>;
2592
- /**
2593
- * Delete a cron job permanently.
2594
- *
2595
- * @public
2596
- */
2597
- static delete(jobId: string, _options?: CronOperationOptions): Promise<void>;
2598
- /**
2599
- * Re-enable a paused cron job.
2600
- *
2601
- * @public
2602
- */
2603
- static enable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
2604
- /**
2605
- * Pause a cron job without deleting it.
2606
- *
2607
- * @public
2608
- */
2609
- static disable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
2610
- /**
2611
- * Manually trigger a cron job off-schedule. Returns the resulting `Run`
2612
- * (agent target) or `WorkflowRun` (workflow target — SE35).
2613
- *
2614
- * @public
2615
- */
2616
- static run(jobId: string, _options?: CronRunOptions): Promise<Run | WorkflowRun>;
2617
- /**
2618
- * Activate the in-process scheduler for local cron jobs.
2619
- *
2620
- * @public
2621
- */
2622
- static start(options?: CronStartOptions): Promise<void>;
2623
- /**
2624
- * Stop the in-process scheduler. Jobs are preserved.
2625
- *
2626
- * @public
2627
- */
2628
- static stop(): Promise<void>;
2629
- /**
2630
- * Snapshot of the local scheduler.
2631
- *
2632
- * @public
2633
- */
2634
- static status(_options?: CronStartOptions): Promise<CronSchedulerStatus>;
2635
- }
2636
-
2637
- export { type CronRuntime as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type BudgetUsageEvent as D, type CloudEnv as E, type CloudRepo as F, type GetAgentOptions as G, type ContextBudget as H, type InlineSkill as I, type JudgeResult as J, type ContextManagerKind as K, type LocalOptions as L, type MemorySettings as M, type ContextSnapshot as N, type ContextSource as O, type ProviderRoutingSettings as P, type ContextSourceStatus as Q, type CreateSkillSpec as R, type SystemPromptResolver as S, Cron as T, type CronCreateOptions as U, type CronGetOptions as V, type CronJob as W, type CronJobStatus as X, type CronListOptions as Y, type CronOperationOptions as Z, type CronRunOptions as _, type AgentDefinition as a, type CronSchedulerStatus as a0, type CronStartOptions as a1, type HookName as a2, type InvalidateCacheOptions as a3, type MemoryAdapter as a4, type MemoryAdapterCapabilities as a5, type MemoryContext as a6, type MemoryFact as a7, type MemoryProviderHandle as a8, type MemoryProviderInitOptions as a9, Skill as aA, type SkillsResolver as aB, type SkillsResolverContext as aC, type SystemPromptContext as aD, type SystemPromptMemoryFact as aE, type SystemPromptSkillRef as aF, type TelemetrySettings as aG, type Verdict as aH, type MemoryRevision as aa, type MemoryToolSchema as ab, type MemoryTurnMessage as ac, type PersonalityPreset as ad, type PluginContext as ae, type PostAssistantReplyContext as af, type PreToolCallContext as ag, type PreUserSendContext as ah, type PreUserSendResult as ai, type ProviderCapability as aj, type ProviderRoute as ak, type ProviderTransform as al, type ProviderTransformContext as am, type RecordSessionSummaryArgs as an, type ResolvedProviderRoute as ao, type RunUntilIterator as ap, type SDKAgentPlugins as aq, type SDKAgentSkillDetail as ar, type SDKAgentSkills as as, type SDKArtifact as at, type SDKContextManager as au, type SDKPluginMetadata as av, type SDKProvidersManager as aw, type SessionRecord as ax, type SessionStore as ay, type SettingSource 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 Plugin as l, type ProviderProfile as m, type GoalOptions as n, type GoalEvent as o, type GoalResult as p, type MemoryProvider as q, type MemoryId as r, type PreToolCallDecision as s, type StepResult as t, type SDKProvider as u, type ActiveMemoryPassArgs as v, type ActiveMemoryPassResult as w, type AgentMemory as x, type BudgetCheck as y, type BudgetTotal as z };
2116
+ export { type MemoryToolSchema as $, type AgentOptions as A, type BudgetTracker as B, type CloudOptions as C, type CloudEnv as D, type CloudRepo as E, type ContextBudget as F, type GetAgentOptions as G, type ContextManagerKind as H, type InlineSkill as I, type JudgeResult as J, type ContextSnapshot as K, type LocalOptions as L, type MemorySettings as M, type ContextSource as N, type ContextSourceStatus as O, type ProviderRoutingSettings as P, type CreateSkillSpec as Q, type HookName as R, type SystemPromptResolver as S, type InvalidateCacheOptions as T, type MemoryAdapter as U, type MemoryAdapterCapabilities as V, type MemoryContext as W, type MemoryFact as X, type MemoryProviderHandle as Y, type MemoryProviderInitOptions as Z, type MemoryRevision as _, type AgentDefinition as a, type MemoryTurnMessage as a0, type PersonalityPreset as a1, type PluginContext as a2, type PostAssistantReplyContext as a3, type PostToolCallContext as a4, type PreToolCallContext as a5, type PreUserSendContext as a6, type PreUserSendResult as a7, type ProviderCapability as a8, type ProviderRoute as a9, type Verdict as aA, type ProviderTransform as aa, type ProviderTransformContext as ab, type RecordSessionSummaryArgs as ac, type ResolvedProviderRoute as ad, type RunUntilIterator as ae, type SDKAgentPlugins as af, type SDKAgentSkillDetail as ag, type SDKAgentSkills as ah, type SDKArtifact as ai, type SDKContextManager as aj, type SDKPluginMetadata as ak, type SDKProvidersManager as al, type SessionLifecycleContext as am, type SessionRecord as an, type SessionStore as ao, type SettingSource as ap, Skill as aq, type SkillsResolver as ar, type SkillsResolverContext as as, type SystemPromptContext as at, type SystemPromptMemoryFact as au, type SystemPromptSkillRef as av, type TelemetrySettings as aw, type ToolCallSummary as ax, type ToolResultTransformContext as ay, type TransformContext 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 Plugin as l, type ProviderProfile as m, type GoalOptions as n, type GoalEvent as o, type GoalResult as p, type MemoryProvider as q, type MemoryId as r, type PreToolCallDecision as s, type SDKProvider as t, type ActiveMemoryPassArgs as u, type ActiveMemoryPassResult as v, type AgentMemory as w, type BudgetCheck as x, type BudgetTotal as y, type BudgetUsageEvent as z };