@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,579 @@
1
+ import { ZodType } from 'zod';
2
+ import { e as SDKAgent, A as AgentOptions, g as ListResult } from './agent-Bzg2_uGr.cjs';
3
+ import { u as MessageOrigin, ac as SDKUserMessage, b as Run } from './run-OJbGyweZ.cjs';
4
+
5
+ /**
6
+ * Public type contract for `Workflow.create / .run / .resume` (Adoption
7
+ * Roadmap #5; ADRs D230-D248).
8
+ *
9
+ * Step types form a discriminated union by `kind`. Helper factory functions
10
+ * (`fn()`, `agentStep()`) live in `workflow.ts` and hide the discriminator
11
+ * from end users.
12
+ *
13
+ * @public
14
+ */
15
+
16
+ type Step = FnStep | AgentStep | ParallelStep | BranchStep | ForeachStep | DowhileStep | SleepStep | SuspendStep;
17
+ /** A pure function step. */
18
+ interface FnStep {
19
+ readonly kind: "fn";
20
+ readonly id: string;
21
+ readonly fn: (input: unknown, ctx: StepContext) => Promise<unknown> | unknown;
22
+ readonly inputSchema?: ZodType;
23
+ readonly outputSchema?: ZodType;
24
+ readonly retry?: RetryPolicy;
25
+ /** D238 — slot reserved; runtime throws if engine not yet implemented. */
26
+ readonly compensate?: (input: unknown, output: unknown, error: Error) => Promise<void> | void;
27
+ }
28
+ /** An agent.send-driven step. */
29
+ interface AgentStep {
30
+ readonly kind: "agent";
31
+ readonly id: string;
32
+ readonly agent: SDKAgent;
33
+ readonly promptTemplate: string | ((input: unknown) => string);
34
+ readonly retry?: RetryPolicy;
35
+ /**
36
+ * SE3 — provenance stamped onto this step's `agent.send()` (forwarded to
37
+ * `RunResult.origin`). Squad sets `{ kind: "peer", from: "agent-<i-1>" }` on
38
+ * every step after the first so a peer-driven turn is attributable.
39
+ */
40
+ readonly origin?: MessageOrigin;
41
+ }
42
+ /** N concurrent branches, each its own mini-step-list. */
43
+ interface ParallelStep {
44
+ readonly kind: "parallel";
45
+ readonly id: string;
46
+ readonly branches: ReadonlyArray<ReadonlyArray<Step>>;
47
+ readonly concurrency?: number;
48
+ readonly errorPolicy?: "fail-fast" | "collect";
49
+ }
50
+ /** First-match-wins predicates + optional fallback. */
51
+ interface BranchStep {
52
+ readonly kind: "branch";
53
+ readonly id: string;
54
+ readonly predicates: ReadonlyArray<readonly [(input: unknown) => boolean | Promise<boolean>, ReadonlyArray<Step>]>;
55
+ readonly fallback?: ReadonlyArray<Step>;
56
+ }
57
+ /** Map a step over an upstream array output. */
58
+ interface ForeachStep {
59
+ readonly kind: "foreach";
60
+ readonly id: string;
61
+ /** ID of an upstream top-level step whose output is iterable. */
62
+ readonly iterableFrom: string;
63
+ readonly step: Step;
64
+ readonly concurrency?: number;
65
+ }
66
+ /** Loop a step until condFn returns false. */
67
+ interface DowhileStep {
68
+ readonly kind: "dowhile";
69
+ readonly id: string;
70
+ readonly step: Step;
71
+ readonly condFn: (output: unknown, iteration: number) => boolean | Promise<boolean>;
72
+ readonly maxIterations?: number;
73
+ }
74
+ /** Pause for a fixed duration. */
75
+ interface SleepStep {
76
+ readonly kind: "sleep";
77
+ readonly id: string;
78
+ readonly durationMs: number;
79
+ }
80
+ /** Standalone explicit suspend point. */
81
+ interface SuspendStep {
82
+ readonly kind: "suspend";
83
+ readonly id: string;
84
+ readonly payloadSchema?: ZodType;
85
+ }
86
+ /** D237 — retry policy applied per fn/agent step. */
87
+ interface RetryPolicy {
88
+ /** Total attempts (MIN 1, MAX 20). `1` = no retry. */
89
+ readonly maxAttempts: number;
90
+ readonly initialBackoffMs?: number;
91
+ readonly backoffCoefficient?: number;
92
+ readonly maximumBackoffMs?: number;
93
+ readonly nonRetryableErrors?: ReadonlyArray<string>;
94
+ }
95
+ /** D247 — context handed to every step.fn. */
96
+ interface StepContext {
97
+ readonly runId: string;
98
+ readonly signal: AbortSignal;
99
+ readonly log: {
100
+ debug: (msg: string, attrs?: Record<string, unknown>) => void;
101
+ info: (msg: string, attrs?: Record<string, unknown>) => void;
102
+ warn: (msg: string, attrs?: Record<string, unknown>) => void;
103
+ };
104
+ /** Pause the workflow; resume via `Workflow.resume({...})`. */
105
+ readonly suspend: (payload?: unknown) => Promise<never>;
106
+ /**
107
+ * SE29 — the workflow's shared state (from `WorkflowOptions.initialState`,
108
+ * mutated by {@link setState}), visible to every subsequent step in the run.
109
+ * `undefined` when no `initialState`/`setState` has run. Persisted across
110
+ * suspend/resume.
111
+ */
112
+ readonly state: unknown;
113
+ /**
114
+ * SE29 — update the shared state for subsequent steps. Validated against
115
+ * `WorkflowOptions.stateSchema` when set (a mismatch throws
116
+ * {@link WorkflowStateError}, which fails the step/run — Rule 8).
117
+ */
118
+ readonly setState: (next: unknown) => void;
119
+ }
120
+ interface StepResult {
121
+ readonly stepId: string;
122
+ readonly kind: Step["kind"];
123
+ readonly status: "completed" | "failed" | "skipped" | "suspended";
124
+ readonly attempts: number;
125
+ readonly durationMs: number;
126
+ readonly output?: unknown;
127
+ readonly error?: {
128
+ name: string;
129
+ message: string;
130
+ };
131
+ }
132
+ interface WorkflowRun<TOutput = unknown> {
133
+ readonly id: string;
134
+ readonly name: string;
135
+ readonly status: "running" | "completed" | "failed" | "suspended" | "cancelled";
136
+ readonly output?: TOutput;
137
+ readonly error?: {
138
+ name: string;
139
+ message: string;
140
+ };
141
+ readonly startedAt: number;
142
+ readonly endedAt?: number;
143
+ readonly stepResults: ReadonlyArray<StepResult>;
144
+ }
145
+ /**
146
+ * SE28 — a step-level workflow event emitted by `Workflow.stream()` as top-level
147
+ * steps run. Coarse-grained (one event per top-level step; nested
148
+ * parallel/branch/foreach emit as their single wrapping step), distinct from the
149
+ * token-delta agent stream. Discriminate on `type`.
150
+ *
151
+ * @public
152
+ */
153
+ type WorkflowEvent = {
154
+ readonly type: "step_started";
155
+ readonly stepId: string;
156
+ } | {
157
+ readonly type: "step_completed";
158
+ readonly stepId: string;
159
+ readonly output: unknown;
160
+ } | {
161
+ readonly type: "step_failed";
162
+ readonly stepId: string;
163
+ readonly error: {
164
+ readonly name: string;
165
+ readonly message: string;
166
+ };
167
+ } | {
168
+ readonly type: "workflow_suspended";
169
+ readonly stepId: string;
170
+ } | {
171
+ readonly type: "workflow_completed";
172
+ };
173
+ /**
174
+ * SE28 — the async iterator returned by `Workflow.stream()`. Yields
175
+ * {@link WorkflowEvent}s in execution order; `result` resolves to the same
176
+ * terminal {@link WorkflowRun} the `run()` path returns (the authoritative
177
+ * outcome — the stream ends when the run terminates).
178
+ *
179
+ * @public
180
+ */
181
+ type WorkflowStream<TOutput = unknown> = AsyncIterableIterator<WorkflowEvent> & {
182
+ readonly result: Promise<WorkflowRun<TOutput>>;
183
+ };
184
+ interface WorkflowPersistenceOptions {
185
+ readonly backend: "memory" | "json";
186
+ /** Required for `backend: "json"`. */
187
+ readonly dir?: string;
188
+ }
189
+ interface WorkflowOptions {
190
+ readonly name: string;
191
+ readonly persistence?: WorkflowPersistenceOptions;
192
+ /**
193
+ * SE27 — Zod schema for the WHOLE workflow's input. When set, `run(input)`
194
+ * validates `input` BEFORE step 1; a mismatch yields `status: "failed"` with a
195
+ * typed {@link WorkflowInputError} in `error` (fail-fast, no step runs, no
196
+ * silent coerce). Absent ⇒ no whole-workflow input validation (unchanged).
197
+ */
198
+ readonly inputSchema?: ZodType;
199
+ /**
200
+ * SE27 — Zod schema for the workflow's final output. When set, the terminal
201
+ * `completed` output is validated before `WorkflowRun.output` is populated; a
202
+ * mismatch yields `status: "failed"` with a typed {@link WorkflowOutputError}.
203
+ * Only validated on the `completed` path (suspended/failed runs skip it).
204
+ */
205
+ readonly outputSchema?: ZodType;
206
+ /**
207
+ * SE29 — Zod schema for the workflow's shared state (see `StepContext.state` /
208
+ * `setState`). When set, `initialState` and every `setState(next)` are
209
+ * validated against it (a mismatch throws {@link WorkflowStateError}). When
210
+ * `initialState` is absent, `state` starts as `undefined` and validation fires
211
+ * on the first `setState` call.
212
+ */
213
+ readonly stateSchema?: ZodType;
214
+ /**
215
+ * SE29 — the initial shared state, seeded onto `StepContext.state` before
216
+ * step 1. Validated against `stateSchema` when both are set. Persisted across
217
+ * suspend/resume.
218
+ */
219
+ readonly initialState?: unknown;
220
+ /** Internal — minted at `.commit()`. Not user-facing. */
221
+ readonly workflowId?: string;
222
+ }
223
+ interface WorkflowRunOptions {
224
+ readonly signal?: AbortSignal;
225
+ /** Override run ID for deterministic resume (advanced; default = mintRunId). */
226
+ readonly runId?: string;
227
+ /**
228
+ * Opt-in Task wrapping (ADRs D363, D374). Registers the workflow run
229
+ * as a `Task` (kind="workflow") with a `wf-` namespaced id (D368,
230
+ * EC-5). The task transitions terminal when `Workflow.run` resolves.
231
+ *
232
+ * Auto-id: `wf-{runId}`.
233
+ *
234
+ * @public
235
+ */
236
+ readonly task?: true | {
237
+ id?: string;
238
+ meta?: Record<string, unknown>;
239
+ };
240
+ }
241
+ interface WorkflowResumeOptions<TI = unknown> {
242
+ readonly runId: string;
243
+ readonly workflow: {
244
+ run: (input: TI, opts?: WorkflowRunOptions) => Promise<WorkflowRun>;
245
+ };
246
+ readonly payload?: unknown;
247
+ readonly signal?: AbortSignal;
248
+ }
249
+
250
+ /**
251
+ * Public `Workflow` class — declarative multi-step orchestration over
252
+ * `Agent.send`, `Handoff`, `Agent.batch` and friends (Adoption Roadmap #5;
253
+ * ADRs D230-D248).
254
+ *
255
+ * Usage:
256
+ *
257
+ * import { Agent } from "@theokit/sdk";
258
+ * import { Workflow, fn, agentStep } from "@theokit/sdk/workflow";
259
+ *
260
+ * const classifier = await Agent.create({ ... });
261
+ * const wf = Workflow.create({ name: "demo" })
262
+ * .then(fn("validate", (input: { id: string }) => {
263
+ * if (!input.id) throw new Error("missing id");
264
+ * return input;
265
+ * }))
266
+ * .then(agentStep("classify", classifier, (i) => `Classify: ${JSON.stringify(i)}`))
267
+ * .commit();
268
+ *
269
+ * const run = await wf.run({ id: "x" });
270
+ * console.log(run.status, run.output);
271
+ *
272
+ * @public
273
+ */
274
+
275
+ declare class WorkflowBuilder<TInput = unknown, TOutput = unknown> {
276
+ private readonly options;
277
+ private readonly _steps;
278
+ private _committed;
279
+ then<TO = unknown>(step: Step): WorkflowBuilder<TInput, TO>;
280
+ parallel(branches: ReadonlyArray<ReadonlyArray<Step>>, opts?: {
281
+ id?: string;
282
+ concurrency?: number;
283
+ errorPolicy?: "fail-fast" | "collect";
284
+ }): WorkflowBuilder<TInput, unknown[]>;
285
+ branch(predicates: BranchStep["predicates"], opts?: {
286
+ id?: string;
287
+ fallback?: ReadonlyArray<Step>;
288
+ }): WorkflowBuilder<TInput, unknown>;
289
+ foreach(iterableFrom: string, step: Step, opts?: {
290
+ id?: string;
291
+ concurrency?: number;
292
+ }): WorkflowBuilder<TInput, unknown[]>;
293
+ dowhile(step: Step, condFn: DowhileStep["condFn"], opts?: {
294
+ id?: string;
295
+ maxIterations?: number;
296
+ }): WorkflowBuilder<TInput, unknown>;
297
+ sleep(durationMs: number, id?: string): WorkflowBuilder<TInput, TOutput>;
298
+ suspend(opts?: {
299
+ id?: string;
300
+ payloadSchema?: ZodType;
301
+ }): WorkflowBuilder<TInput, unknown>;
302
+ commit(): Workflow<TInput, TOutput>;
303
+ private validateUniqueIds;
304
+ private assertNotCommitted;
305
+ }
306
+ declare class Workflow<TInput = unknown, TOutput = unknown> {
307
+ private readonly _options;
308
+ private readonly _steps;
309
+ /**
310
+ * Construct a workflow builder. Validate options via Zod and return a
311
+ * `WorkflowBuilder` for fluent chaining. Call `.commit()` to obtain the
312
+ * immutable `Workflow`.
313
+ */
314
+ static create<TI = unknown, TO = unknown>(options: WorkflowOptions): WorkflowBuilder<TI, TO>;
315
+ /**
316
+ * Run this workflow with the given input. Returns a populated
317
+ * `WorkflowRun`. Errors inside a step DO NOT throw — they propagate via
318
+ * `run.status === "failed"`.
319
+ */
320
+ run(input: TInput, opts?: WorkflowRunOptions): Promise<WorkflowRun<TOutput>>;
321
+ /**
322
+ * SE28 — run the workflow and STREAM step-level events as they happen. Returns
323
+ * an async iterator of {@link WorkflowEvent}s (`step_started` / `step_completed`
324
+ * / `step_failed` / `workflow_suspended` / `workflow_completed`, top-level
325
+ * steps) plus a `result` promise resolving to the same terminal
326
+ * {@link WorkflowRun} `run()` returns. Iterate for progress; await `result` for
327
+ * the outcome. The stream ends when the run terminates.
328
+ *
329
+ * `result` is the AUTHORITATIVE terminal status. Not every terminal state has a
330
+ * closing event: a step failure emits `step_failed`, but an `outputSchema`
331
+ * rejection (SE27) or an abort ends the stream WITHOUT `workflow_completed` —
332
+ * always `await result` to read the final `status`. Consuming order is free:
333
+ * awaiting `result` without draining, or draining without awaiting `result`,
334
+ * both work (breaking out of `for await` stops the buffering early).
335
+ */
336
+ stream(input: TInput, opts?: WorkflowRunOptions): WorkflowStream<TOutput>;
337
+ /**
338
+ * Resume a suspended workflow from its snapshot. Throws
339
+ * `WorkflowSnapshotNotFoundError` if `runId` is unknown.
340
+ */
341
+ static resume<TO = unknown>(opts: WorkflowResumeOptions): Promise<WorkflowRun<TO>>;
342
+ }
343
+
344
+ /**
345
+ * Runtime hosting a cron job. Mirrors the agent runtime split.
346
+ *
347
+ * - `local` — the in-process scheduler activated via `Cron.start()` fires the
348
+ * job while the host process is alive.
349
+ * - `cloud` — Theo PaaS schedules the job server-side; fires independent of
350
+ * any SDK process.
351
+ *
352
+ * @public
353
+ */
354
+ type CronRuntime = "local" | "cloud";
355
+ /**
356
+ * Lifecycle state reported by `Cron.list()` / `Cron.get()`.
357
+ *
358
+ * @public
359
+ */
360
+ type CronJobStatus = "scheduled" | "running" | "paused" | "errored";
361
+ /**
362
+ * Persistent cron-scheduled invocation of the Theo agent or a workflow.
363
+ *
364
+ * Exactly one target is set: {@link CronJob.agent} (ephemeral agent created on
365
+ * each fire), {@link CronJob.agentId} (bound to an existing agent for context
366
+ * continuity), or {@link CronJob.workflow} (a committed workflow run per fire;
367
+ * SE35). Agent targets carry a `message`; a workflow target carries `inputData`.
368
+ *
369
+ * @public
370
+ */
371
+ interface CronJob {
372
+ id: string;
373
+ name?: string;
374
+ /** Standard 5-field POSIX cron expression or shorthand (`@hourly`, `@daily`, ...). */
375
+ cron: string;
376
+ /** IANA timezone identifier. Defaults to `"UTC"`. */
377
+ timezone?: string;
378
+ /** Message sent to the agent on each fire. Present for agent targets; absent for a workflow target. */
379
+ message?: string | SDKUserMessage;
380
+ /** Ephemeral agent options. Mutually exclusive with `agentId`/`workflow`. */
381
+ agent?: AgentOptions;
382
+ /** ID of an existing agent to reuse for context continuity. Mutually exclusive with `agent`/`workflow`. */
383
+ agentId?: string;
384
+ /**
385
+ * SE35 — a committed {@link Workflow} run on each fire (`workflow.run(inputData)`).
386
+ * Mutually exclusive with `agent`/`agentId`. Held in-memory (local runtime only —
387
+ * a workflow instance cannot cross the cloud process boundary). ADR 0014.
388
+ */
389
+ workflow?: Workflow;
390
+ /** SE35 — input passed to `workflow.run(inputData)` on each fire. Workflow targets only. */
391
+ inputData?: unknown;
392
+ /** Whether the scheduler will fire this job on schedule. */
393
+ enabled: boolean;
394
+ /** Current status. */
395
+ status: CronJobStatus;
396
+ /** Runtime that hosts this job. Inferred from `agent`/`agentId`/`workflow` at create time (a `workflow` target is always `local`). */
397
+ runtime: CronRuntime;
398
+ /** Unix ms of the last successful fire, if any. */
399
+ lastRunAt?: number;
400
+ /** Unix ms of the next scheduled fire, computed by the scheduler. */
401
+ nextRunAt?: number;
402
+ /** Unix ms when the job was created. */
403
+ createdAt: number;
404
+ }
405
+ /**
406
+ * Options for `Cron.create()`.
407
+ *
408
+ * Pass exactly ONE target: `agent` (ephemeral agent fresh per fire), `agentId`
409
+ * (reuse an existing agent — preserves conversation context), or `workflow`
410
+ * (SE35 — run a committed workflow per fire). Agent targets REQUIRE `message`;
411
+ * a workflow target takes `inputData` and MUST NOT set `message`. Violations are
412
+ * a `ConfigurationError`.
413
+ *
414
+ * @public
415
+ */
416
+ interface CronCreateOptions {
417
+ cron: string;
418
+ /** Message for an agent target. Required with `agent`/`agentId`; forbidden with `workflow`. */
419
+ message?: string | SDKUserMessage;
420
+ agent?: AgentOptions;
421
+ agentId?: string;
422
+ /** SE35 — a committed {@link Workflow} to run per fire. Mutually exclusive with `agent`/`agentId`. */
423
+ workflow?: Workflow;
424
+ /** SE35 — input for `workflow.run(inputData)`. Workflow targets only. */
425
+ inputData?: unknown;
426
+ name?: string;
427
+ timezone?: string;
428
+ /** Defaults to `true`. */
429
+ enabled?: boolean;
430
+ /** Falls back to `THEOKIT_API_KEY`. */
431
+ apiKey?: string;
432
+ }
433
+ /**
434
+ * Options for `Cron.list()`.
435
+ *
436
+ * @public
437
+ */
438
+ type CronListOptions = {
439
+ limit?: number;
440
+ cursor?: string;
441
+ } & ({
442
+ runtime?: undefined;
443
+ } | {
444
+ runtime: "local";
445
+ cwd?: string;
446
+ } | {
447
+ runtime: "cloud";
448
+ apiKey?: string;
449
+ });
450
+ /**
451
+ * Options for `Cron.get()`.
452
+ *
453
+ * @public
454
+ */
455
+ interface CronGetOptions {
456
+ cwd?: string;
457
+ apiKey?: string;
458
+ }
459
+ /**
460
+ * Options for `Cron.delete()` / `Cron.enable()` / `Cron.disable()`.
461
+ *
462
+ * @public
463
+ */
464
+ interface CronOperationOptions {
465
+ cwd?: string;
466
+ apiKey?: string;
467
+ }
468
+ /**
469
+ * Options for `Cron.run()` — manually trigger a job off-schedule.
470
+ *
471
+ * @public
472
+ */
473
+ interface CronRunOptions {
474
+ cwd?: string;
475
+ apiKey?: string;
476
+ }
477
+ /**
478
+ * Options for `Cron.start()` — activates the in-process scheduler for local
479
+ * jobs.
480
+ *
481
+ * @public
482
+ */
483
+ interface CronStartOptions {
484
+ /** Local workspace whose `.theokit/cron/jobs.json` to load. Defaults to `process.cwd()`. */
485
+ cwd?: string;
486
+ /** Override the env API key. */
487
+ apiKey?: string;
488
+ }
489
+ /**
490
+ * Snapshot of the local scheduler returned by `Cron.status()`.
491
+ *
492
+ * @public
493
+ */
494
+ interface CronSchedulerStatus {
495
+ /** Whether the in-process scheduler is currently running. */
496
+ running: boolean;
497
+ /** Number of jobs loaded into the scheduler. */
498
+ jobCount: number;
499
+ /** Unix ms of the next scheduled fire across all jobs, if any. */
500
+ nextFireAt?: number;
501
+ /** Last error observed in the scheduler, if any. */
502
+ lastError?: {
503
+ jobId: string;
504
+ message: string;
505
+ at: number;
506
+ };
507
+ }
508
+
509
+ /**
510
+ * Static façade for scheduling Theo agent runs on a cron expression.
511
+ *
512
+ * @public
513
+ */
514
+ declare class Cron {
515
+ private constructor();
516
+ /**
517
+ * Create and persist a cron job.
518
+ *
519
+ * @public
520
+ */
521
+ static create(options: CronCreateOptions): Promise<CronJob>;
522
+ /**
523
+ * List cron jobs (local, cloud, or both).
524
+ *
525
+ * @public
526
+ */
527
+ static list(options?: CronListOptions): Promise<ListResult<CronJob>>;
528
+ /**
529
+ * Get a single cron job by ID.
530
+ *
531
+ * @public
532
+ */
533
+ static get(jobId: string, _options?: CronGetOptions): Promise<CronJob>;
534
+ /**
535
+ * Delete a cron job permanently.
536
+ *
537
+ * @public
538
+ */
539
+ static delete(jobId: string, _options?: CronOperationOptions): Promise<void>;
540
+ /**
541
+ * Re-enable a paused cron job.
542
+ *
543
+ * @public
544
+ */
545
+ static enable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
546
+ /**
547
+ * Pause a cron job without deleting it.
548
+ *
549
+ * @public
550
+ */
551
+ static disable(jobId: string, _options?: CronOperationOptions): Promise<CronJob>;
552
+ /**
553
+ * Manually trigger a cron job off-schedule. Returns the resulting `Run`
554
+ * (agent target) or `WorkflowRun` (workflow target — SE35).
555
+ *
556
+ * @public
557
+ */
558
+ static run(jobId: string, _options?: CronRunOptions): Promise<Run | WorkflowRun>;
559
+ /**
560
+ * Activate the in-process scheduler for local cron jobs.
561
+ *
562
+ * @public
563
+ */
564
+ static start(options?: CronStartOptions): Promise<void>;
565
+ /**
566
+ * Stop the in-process scheduler. Jobs are preserved.
567
+ *
568
+ * @public
569
+ */
570
+ static stop(): Promise<void>;
571
+ /**
572
+ * Snapshot of the local scheduler.
573
+ *
574
+ * @public
575
+ */
576
+ static status(_options?: CronStartOptions): Promise<CronSchedulerStatus>;
577
+ }
578
+
579
+ export { Cron as C, type StepResult as S, type CronCreateOptions as a, type CronGetOptions as b, type CronJob as c, type CronJobStatus as d, type CronListOptions as e, type CronOperationOptions as f, type CronRunOptions as g, type CronRuntime as h, type CronSchedulerStatus as i, type CronStartOptions as j };