@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.
Files changed (46) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/a2a/index.cjs +373 -17
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +373 -17
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/{cron-BR1NCSk1.d.cts → cron-BNHJywtl.d.ts} +482 -18
  7. package/dist/{cron-DgEQCJ2i.d.ts → cron-t4oKI2Is.d.cts} +482 -18
  8. package/dist/cron.cjs +1143 -692
  9. package/dist/cron.cjs.map +1 -1
  10. package/dist/cron.d.cts +2 -2
  11. package/dist/cron.d.ts +2 -2
  12. package/dist/cron.js +1146 -695
  13. package/dist/cron.js.map +1 -1
  14. package/dist/{errors-DLMNb4Ka.d.cts → errors-DZpCGlYv.d.cts} +1 -1
  15. package/dist/{errors-CbY3pxY7.d.ts → errors-D_Bfo30u.d.ts} +1 -1
  16. package/dist/errors.d.cts +2 -2
  17. package/dist/eval.cjs +914 -508
  18. package/dist/eval.cjs.map +1 -1
  19. package/dist/eval.js +915 -509
  20. package/dist/eval.js.map +1 -1
  21. package/dist/index.cjs +1038 -590
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +13 -135
  24. package/dist/index.d.ts +13 -135
  25. package/dist/index.js +1037 -588
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal/persistence/conversation-storage-fs.d.cts +4 -0
  28. package/dist/internal/persistence/conversation-storage-fs.d.ts +4 -0
  29. package/dist/internal/persistence/conversation-storage-memory.d.cts +4 -0
  30. package/dist/internal/persistence/conversation-storage-memory.d.ts +4 -0
  31. package/dist/internal/persistence/objective-coerce.d.cts +9 -0
  32. package/dist/internal/persistence/objective-coerce.d.ts +9 -0
  33. package/dist/internal/runtime/lifecycle/wrap-completion-check-run.d.ts +30 -0
  34. package/dist/internal/runtime/local-agent/local-agent-goal-extensions.d.ts +80 -0
  35. package/dist/internal/runtime/objective/objective-store.d.ts +33 -0
  36. package/dist/{run-CdWiihyU.d.cts → run-CLXKMRgq.d.cts} +71 -2
  37. package/dist/{run-CdWiihyU.d.ts → run-CLXKMRgq.d.ts} +71 -2
  38. package/dist/types/agent.d.ts +32 -1
  39. package/dist/types/conversation-storage.d.ts +23 -0
  40. package/dist/types/cron.d.ts +30 -13
  41. package/dist/types/goal-events.d.ts +7 -0
  42. package/dist/types/index.d.ts +1 -0
  43. package/dist/types/objective.d.ts +45 -0
  44. package/dist/types/run-events.d.ts +12 -1
  45. package/dist/types/run.d.ts +58 -0
  46. package/package.json +3 -3
@@ -86,6 +86,13 @@ export interface GoalOptions {
86
86
  judgeApiKey?: string;
87
87
  /** Optional subgoals fed to the judge prompt. */
88
88
  subgoals?: string[];
89
+ /**
90
+ * SE33 (ADR 0012) — resolve the goal from the durable thread-scoped
91
+ * objective when `runUntil()` is called with NO explicit goal. Also the
92
+ * key the loop writes `runsUsed` / `status` progress back to. Ignored when
93
+ * an explicit goal is passed (that path stays ephemeral).
94
+ */
95
+ threadId?: string;
89
96
  /**
90
97
  * Cancel mid-loop via `AbortController.signal`. The generator yields
91
98
  * a `status_change: paused` event and returns at the next turn
@@ -9,6 +9,7 @@ export type * from "./goal-events.js";
9
9
  export type * from "./mcp.js";
10
10
  export type * from "./memory-adapter.js";
11
11
  export type * from "./messages.js";
12
+ export type * from "./objective.js";
12
13
  export type * from "./processors.js";
13
14
  export type * from "./providers.js";
14
15
  export type * from "./run.js";
@@ -0,0 +1,45 @@
1
+ /**
2
+ * SE33 — the durable, thread-scoped objective (Mastra Goals parity, durable half).
3
+ *
4
+ * The SDK's `runUntil` goal loop (ADRs D115-D121) is per-call/transient. SE33
5
+ * persists an objective in conversation storage (via the optional
6
+ * `getObjectiveRecord`/`setObjectiveRecord` adapter methods) so it survives
7
+ * reloads, is managed via `Agent` methods, and is read by `runUntil` when no
8
+ * explicit goal is passed. See ADR 0012.
9
+ *
10
+ * @public
11
+ */
12
+ /** Lifecycle status of a durable objective (ADR 0012 D2). */
13
+ export type ObjectiveStatus = "active" | "done" | "paused";
14
+ /**
15
+ * The per-objective override subset of goal options. Precedence (ADR 0012 D3):
16
+ * these `record.options` → the agent's standing `goal` config → built-in default.
17
+ * The `judgeModel` is the activation switch — with no judge resolved, the
18
+ * standing objective is inert (no scoring, no budget consumed).
19
+ */
20
+ export interface DurableGoalOptions {
21
+ /** Max judge-gated turns before the loop stops (default 20 — the `runUntil` default). */
22
+ readonly maxRuns?: number;
23
+ /** Judge model identifier (e.g. `"openai/gpt-4o-mini"`). Absent ⇒ inherit from agent `goal` config. */
24
+ readonly judgeModel?: string;
25
+ /** Optional extra judge instruction appended to the default judge prompt. */
26
+ readonly prompt?: string;
27
+ }
28
+ /**
29
+ * A persisted objective record. Stored under the caller's `threadId` (the
30
+ * conversation key). `_schemaVersion` mirrors {@link import("./workflow.js").WorkflowSnapshot}
31
+ * for future migration (ADR 0012 D2).
32
+ */
33
+ export interface ObjectiveRecord {
34
+ readonly _schemaVersion: 1;
35
+ readonly objective: string;
36
+ readonly options?: DurableGoalOptions;
37
+ readonly status: ObjectiveStatus;
38
+ readonly runsUsed: number;
39
+ }
40
+ /** The standing `goal` config on an agent (ADR 0012 D3). Read when a durable objective is set. */
41
+ export interface AgentGoalConfig {
42
+ readonly judgeModel?: string;
43
+ readonly maxRuns?: number;
44
+ readonly prompt?: string;
45
+ }
@@ -16,7 +16,7 @@
16
16
  *
17
17
  * @public
18
18
  */
19
- export type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent | RunTripwireEvent;
19
+ export type RunEvent = RunToolProgressEvent | RunRateLimitEvent | RunPermissionDeniedEvent | RunTaskStartedEvent | RunTaskUpdatedEvent | RunTaskCompletedEvent | RunCompactBoundaryEvent | RunTripwireEvent | RunCompletionCheckEvent;
20
20
  /**
21
21
  * SE24 — a guardrail processor called `abort()`; the run stops with a tripwire.
22
22
  * Delivered via {@link SendOptions.onRunEvent} (mirrors the `RunResult.tripwire`
@@ -73,6 +73,17 @@ export interface RunTaskCompletedEvent {
73
73
  readonly taskId: string;
74
74
  readonly status: "completed" | "failed" | "stopped";
75
75
  }
76
+ /**
77
+ * SE34 — the per-send completion check (`isTaskComplete`) produced a verdict.
78
+ * Emitted once, after a finished run's reply is judged against
79
+ * {@link SendOptions.completionCheck}. Distinct from `task_completed` (which is
80
+ * background-task/subagent lifecycle). Mirrors {@link RunResult.completionCheck}.
81
+ */
82
+ export interface RunCompletionCheckEvent {
83
+ readonly type: "completion_check";
84
+ readonly complete: boolean;
85
+ readonly reason: string;
86
+ }
76
87
  /** The conversation crossed a compaction boundary (history was summarized). */
77
88
  export interface RunCompactBoundaryEvent {
78
89
  readonly type: "compact_boundary";
@@ -155,6 +155,13 @@ export interface RunResult {
155
155
  * @public
156
156
  */
157
157
  stoppedByDoomLoop?: boolean;
158
+ /**
159
+ * SE34 — the per-send completion verdict, populated when
160
+ * {@link SendOptions.completionCheck} was set AND the run finished. Absent on
161
+ * non-finished runs and when no completion check was requested. Reuses the
162
+ * shipped LLM-as-judge (same one `runUntil` drives). @public
163
+ */
164
+ completionCheck?: CompletionCheckResult;
158
165
  }
159
166
  /**
160
167
  * Doom-loop guard thresholds (see {@link SendOptions.doomLoop}). Both are counts of CONSECUTIVE
@@ -427,6 +434,57 @@ export interface SendOptions {
427
434
  * @public
428
435
  */
429
436
  maxIterations?: number;
437
+ /**
438
+ * SE34 — per-send completion check (`isTaskComplete`). After this single
439
+ * `send()` reaches a terminal `finished` state, the shipped LLM-as-judge
440
+ * scores the final reply against `criteria` and surfaces the verdict on
441
+ * {@link RunResult.completionCheck} + a `completion_check` run-event. This is
442
+ * the finer-grained, single-`send()` gate (contrast `runUntil`, which judges
443
+ * the FULL response BETWEEN sends). Opt-in — absent ⇒ the send is byte-identical
444
+ * to today (no extra judge call). Non-finished runs skip the check. The judge
445
+ * runs when `wait()` is called on the returned `Run`; a stream-only consumer
446
+ * must call `wait()` to trigger the verdict + the `completion_check` event.
447
+ *
448
+ * @public
449
+ */
450
+ completionCheck?: CompletionCheck;
451
+ /**
452
+ * SE34 — project the standing durable objective (SE33) for this `threadId`
453
+ * into the model context for this send as `<current-objective>…`, so the
454
+ * model always sees what it is working toward. Opt-in — absent ⇒ the assembled
455
+ * system prompt is byte-identical to today. Only an ACTIVE objective is
456
+ * projected (`done`/`paused` ⇒ nothing injected). Reuses the SE33 objective
457
+ * store + the system-prompt assembly seam (no general signal framework — YAGNI).
458
+ *
459
+ * @public
460
+ */
461
+ objectiveThreadId?: string;
462
+ }
463
+ /**
464
+ * SE34 — the per-send completion criterion (see {@link SendOptions.completionCheck}).
465
+ *
466
+ * @public
467
+ */
468
+ export interface CompletionCheck {
469
+ /** What "complete" means for this send — fed to the judge as the goal. */
470
+ criteria: string;
471
+ /** Judge model identifier. Default `"openai/gpt-4o-mini"`. */
472
+ judgeModel?: string;
473
+ /** Override env for the judge auxiliary agent. Default `OPENROUTER_API_KEY`. */
474
+ apiKey?: string;
475
+ }
476
+ /**
477
+ * SE34 — the resolved per-send completion verdict (see {@link RunResult.completionCheck}).
478
+ *
479
+ * @public
480
+ */
481
+ export interface CompletionCheckResult {
482
+ /** `true` when the judge ruled the send's reply satisfies the criteria. */
483
+ complete: boolean;
484
+ /** The judge's stated reason. */
485
+ reason: string;
486
+ /** `true` when the judge output could not be parsed — fail-safe `complete: false`. */
487
+ parseFailed: boolean;
430
488
  }
431
489
  /**
432
490
  * Handle to a single prompt submission.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theokit/sdk",
3
- "version": "2.28.0",
3
+ "version": "2.30.0",
4
4
  "description": "TypeScript SDK for the Theo agent harness — same surface, local or cloud.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/usetheo/theokit-sdk#readme",
@@ -365,8 +365,8 @@
365
365
  "typedoc": "^0.28.19",
366
366
  "ws": "^8.18.0",
367
367
  "zod": "^4.0.0",
368
- "@theokit/sdk-memory": "0.2.0",
369
- "@theokit/sdk-handoff": "0.1.0"
368
+ "@theokit/sdk-handoff": "0.1.0",
369
+ "@theokit/sdk-memory": "0.2.0"
370
370
  },
371
371
  "scripts": {
372
372
  "build": "tsup && cp src/internal/providers/provider-catalog.json dist/provider-catalog.json",