@demlik/tea 0.17.0 → 0.19.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 (119) hide show
  1. package/README.md +4 -3
  2. package/dist/agent/index.d.ts +182 -35
  3. package/dist/agent/index.js +11 -11
  4. package/dist/{chunk-KWNCM6XM.js → chunk-AHW2CLPT.js} +65 -18
  5. package/dist/chunk-AHW2CLPT.js.map +1 -0
  6. package/dist/{chunk-K4ETBNKS.js → chunk-AIIXV4XB.js} +38 -9
  7. package/dist/chunk-AIIXV4XB.js.map +1 -0
  8. package/dist/{chunk-LYVOGOBC.js → chunk-BRX3243I.js} +3 -3
  9. package/dist/{chunk-LYVOGOBC.js.map → chunk-BRX3243I.js.map} +1 -1
  10. package/dist/{chunk-GWWCCSDH.js → chunk-C3G2QFEZ.js} +4 -4
  11. package/dist/{chunk-GWWCCSDH.js.map → chunk-C3G2QFEZ.js.map} +1 -1
  12. package/dist/{chunk-C4U5D5HP.js → chunk-FNGZMVIT.js} +3 -3
  13. package/dist/chunk-FNGZMVIT.js.map +1 -0
  14. package/dist/{chunk-QWIPH4YH.js → chunk-H2ELKHI6.js} +16 -6
  15. package/dist/chunk-H2ELKHI6.js.map +1 -0
  16. package/dist/chunk-H3MWNH7A.js +119 -0
  17. package/dist/chunk-H3MWNH7A.js.map +1 -0
  18. package/dist/chunk-I7E7AD2S.js +213 -0
  19. package/dist/chunk-I7E7AD2S.js.map +1 -0
  20. package/dist/{chunk-OYR7ENKU.js → chunk-IHUNKHDX.js} +3 -3
  21. package/dist/{chunk-OYR7ENKU.js.map → chunk-IHUNKHDX.js.map} +1 -1
  22. package/dist/chunk-JVE2LBFJ.js +21 -0
  23. package/dist/chunk-JVE2LBFJ.js.map +1 -0
  24. package/dist/chunk-JVKU2UQC.js +34 -0
  25. package/dist/chunk-JVKU2UQC.js.map +1 -0
  26. package/dist/{chunk-OPH6Y4UT.js → chunk-JYNYG5SF.js} +4 -4
  27. package/dist/{chunk-OPH6Y4UT.js.map → chunk-JYNYG5SF.js.map} +1 -1
  28. package/dist/{chunk-XBZQT2TD.js → chunk-PCJA2HTZ.js} +437 -162
  29. package/dist/chunk-PCJA2HTZ.js.map +1 -0
  30. package/dist/{chunk-DFUEAA6L.js → chunk-PQSDUX6B.js} +3 -3
  31. package/dist/{chunk-DFUEAA6L.js.map → chunk-PQSDUX6B.js.map} +1 -1
  32. package/dist/{chunk-6XBEYZME.js → chunk-WTSOW2MD.js} +5 -5
  33. package/dist/{chunk-6XBEYZME.js.map → chunk-WTSOW2MD.js.map} +1 -1
  34. package/dist/{chunk-4PXNZ5UY.js → chunk-XVIKSRCK.js} +4 -4
  35. package/dist/{chunk-4PXNZ5UY.js.map → chunk-XVIKSRCK.js.map} +1 -1
  36. package/dist/{chunk-4NTCPTNQ.js → chunk-YIMOFXST.js} +3 -3
  37. package/dist/{chunk-4NTCPTNQ.js.map → chunk-YIMOFXST.js.map} +1 -1
  38. package/dist/{core-rDbOaJTN.d.ts → core-Ce9ncpuv.d.ts} +5 -4
  39. package/dist/do/index.d.ts +140 -64
  40. package/dist/do/index.js +17 -18
  41. package/dist/do/index.js.map +1 -1
  42. package/dist/drive-loop-CsUsW3Wo.d.ts +127 -0
  43. package/dist/{durable-effects-CNaw97Be.d.ts → durable-effects-BmUrRA-h.d.ts} +1 -1
  44. package/dist/effect/index.d.ts +6 -150
  45. package/dist/effect/index.js +4 -96
  46. package/dist/effect/index.js.map +1 -1
  47. package/dist/extension/index.d.ts +7 -5
  48. package/dist/extension/index.js +2 -3
  49. package/dist/extension/index.js.map +1 -1
  50. package/dist/flow/index.d.ts +13 -13
  51. package/dist/flow/index.js +13 -12
  52. package/dist/flow/index.js.map +1 -1
  53. package/dist/idempotency/index.d.ts +3 -3
  54. package/dist/idempotency/index.js +4 -4
  55. package/dist/{index-q1PoukOZ.d.ts → index-2kNxy6az.d.ts} +2 -2
  56. package/dist/{index-B_BxplWi.d.ts → index-B1Wzarkl.d.ts} +1 -1
  57. package/dist/{index-Cberb5Rr.d.ts → index-Bf9_bNql.d.ts} +2 -2
  58. package/dist/index-BnsAqn0-.d.ts +286 -0
  59. package/dist/{index-Cx0F2M34.d.ts → index-Ce5GYAuI.d.ts} +2 -2
  60. package/dist/{index-CWmsXNdX.d.ts → index-D8sYVzCI.d.ts} +1 -1
  61. package/dist/{index-CcrKLtse.d.ts → index-DWdg7R1l.d.ts} +1 -1
  62. package/dist/{index-BOrsbdAf.d.ts → index-Dy3379ve.d.ts} +5 -5
  63. package/dist/{index-DaX_P35Q.d.ts → index-e36uEyl4.d.ts} +3 -3
  64. package/dist/index.d.ts +109 -36
  65. package/dist/index.js +2 -2
  66. package/dist/jev/index.d.ts +8 -8
  67. package/dist/jev/index.js +6 -7
  68. package/dist/jev/index.js.map +1 -1
  69. package/dist/{machine-BcfCFMYF.d.ts → machine-CuojfZup.d.ts} +353 -57
  70. package/dist/machine-viz/index.d.ts +1 -1
  71. package/dist/machine-viz/index.js +2 -2
  72. package/dist/mem/index.d.ts +6 -6
  73. package/dist/mem/index.js +6 -2
  74. package/dist/mem/index.js.map +1 -1
  75. package/dist/node/index.d.ts +16 -10
  76. package/dist/node/index.js +22 -3
  77. package/dist/node/index.js.map +1 -1
  78. package/dist/otel/index.d.ts +161 -0
  79. package/dist/otel/index.js +403 -0
  80. package/dist/otel/index.js.map +1 -0
  81. package/dist/paginate/index.d.ts +4 -4
  82. package/dist/paginate/index.js +5 -5
  83. package/dist/parity/index.d.ts +3 -3
  84. package/dist/parity/index.js +3 -3
  85. package/dist/pbt/index.d.ts +166 -53
  86. package/dist/pbt/index.js +2 -2
  87. package/dist/pbt/index.js.map +1 -1
  88. package/dist/persistence/index.d.ts +5 -5
  89. package/dist/persistence/index.js +5 -5
  90. package/dist/promise/index.d.ts +2 -2
  91. package/dist/promise/index.js +4 -3
  92. package/dist/react/index.d.ts +2 -2
  93. package/dist/resilience/index.d.ts +13 -9
  94. package/dist/resilience/index.js +5 -5
  95. package/dist/resilience/index.js.map +1 -1
  96. package/dist/{runtime-types-B62Ucnxr.d.ts → runtime-types-BKg2CGMx.d.ts} +88 -14
  97. package/dist/testing/effect/index.d.ts +65 -0
  98. package/dist/testing/effect/index.js +148 -0
  99. package/dist/testing/effect/index.js.map +1 -0
  100. package/dist/testing/index.d.ts +12 -158
  101. package/dist/testing/index.js +4 -130
  102. package/dist/testing/index.js.map +1 -1
  103. package/dist/testing/promise/index.d.ts +41 -0
  104. package/dist/testing/promise/index.js +37 -0
  105. package/dist/testing/promise/index.js.map +1 -0
  106. package/dist/timing/index.d.ts +4 -4
  107. package/dist/timing/index.js +4 -4
  108. package/dist/{types-DPm5YCDQ.d.ts → types-SzNSHKlV.d.ts} +1 -1
  109. package/dist/work-queue/index.d.ts +4 -4
  110. package/dist/work-queue/index.js +4 -3
  111. package/dist/work-queue/index.js.map +1 -1
  112. package/package.json +26 -14
  113. package/dist/chunk-C4U5D5HP.js.map +0 -1
  114. package/dist/chunk-G5E74IJB.js +0 -8
  115. package/dist/chunk-G5E74IJB.js.map +0 -1
  116. package/dist/chunk-K4ETBNKS.js.map +0 -1
  117. package/dist/chunk-KWNCM6XM.js.map +0 -1
  118. package/dist/chunk-QWIPH4YH.js.map +0 -1
  119. package/dist/chunk-XBZQT2TD.js.map +0 -1
@@ -1,18 +1,18 @@
1
- import { S as Store, b as BootedRunHandle, E as EngineRun, c as RunHandle, F as FencedStore } from '../runtime-types-B62Ucnxr.js';
2
- import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-CNaw97Be.js';
3
- export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, c as PendingEffectsLedger, d as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-CNaw97Be.js';
1
+ import { S as Store, b as BootedRunHandle, E as EngineRun, c as RunHandle, M as Migrated, F as FencedStore, D as DeletableStore } from '../runtime-types-BKg2CGMx.js';
2
+ import { P as PendingEffectsRecorder, b as EffectOwed, a as EffectConfirmed } from '../durable-effects-BmUrRA-h.js';
3
+ export { D as DeliveryId, E as EffectLedgerEvent, O as OwedEffect, c as PendingEffectsLedger, d as applyEffectEvent, e as emptyLedger, f as foldLedger, i as isOwed, p as pendingEffectsLedger, s as survivingEffects } from '../durable-effects-BmUrRA-h.js';
4
4
  import { RetryPolicy, Rng } from '../retry-backoff/index.js';
5
- import { C as Cmd, S as Sub, M as Machine, W as Wired } from '../core-rDbOaJTN.js';
6
- import { g as AgentEvent, b as AgentTurn, c as AgentState, i as AgentMachineMsg, B as AgentStatus } from '../machine-BcfCFMYF.js';
5
+ import { C as Cmd, c as Sub, M as Machine, W as Wired } from '../core-Ce9ncpuv.js';
6
+ import { A as AgentEvent, f as AgentTurn, e as AgentState, i as AgentMachineMsg, K as AgentStatus } from '../machine-CuojfZup.js';
7
7
  import '@standard-schema/spec';
8
- import '../index-BOrsbdAf.js';
9
- import '../index-CWmsXNdX.js';
10
- import '../index-DaX_P35Q.js';
11
- import '../types-DPm5YCDQ.js';
12
- import '../index-CcrKLtse.js';
13
- import '../index-q1PoukOZ.js';
8
+ import '../index-Dy3379ve.js';
9
+ import '../index-D8sYVzCI.js';
10
+ import '../index-e36uEyl4.js';
11
+ import '../types-SzNSHKlV.js';
12
+ import '../index-DWdg7R1l.js';
13
+ import '../index-2kNxy6az.js';
14
14
  import '../protocol-ClRZBhHQ.js';
15
- import '../index-Cx0F2M34.js';
15
+ import '../index-Ce5GYAuI.js';
16
16
 
17
17
  /**
18
18
  * @demlik/tea/do — `stepHost`, the HTTP-PULL control carrier (#92).
@@ -580,10 +580,11 @@ interface EventSourcedOptions<S, M> {
580
580
  */
581
581
  readonly snapshotEvery?: number;
582
582
  /**
583
- * Boundary parse for the persisted SNAPSHOT cell (the `S` blob). Same
584
- * contract as `doStore`'s `parse`: returns `S` on a recognized shape, `null`
585
- * on an unrecognized one (boot fresh), and must NOT throw. Default accepts
586
- * any non-null, non-array object as `S`.
583
+ * Boundary parse for the persisted SNAPSHOT cell (the `S` blob). Returns `S`
584
+ * on a recognized shape, `null` on an unrecognized one, and must NOT throw.
585
+ * Unlike `doStore`'s `parse`, `null` loses nothing: the snapshot is only a
586
+ * shortcut, so a `null` discards it and replays the whole event log from
587
+ * seq 0. Default accepts any non-null, non-array object as `S`.
587
588
  */
588
589
  readonly parse?: (raw: unknown) => S | null;
589
590
  /**
@@ -995,14 +996,29 @@ declare function sseHub<E>(): SseHub<E>;
995
996
  * - `name`/`key` default to `"sse"`/`"main"`; override for a second SSE view.
996
997
  *
997
998
  * @example
998
- * const hub = sseHub<MyEvent>();
999
- * const registry = projectionRegistry<MyState, MyMsg>();
1000
- * registry.register(sseProjection(hub, (msg) =>
1001
- * msg?.type === "turn_done" ? { kind: "turn", ... } : null,
1002
- * ));
1003
- * driveProjections(registry, runtime); // SSE is now one projection
1004
- * // /sse route unchanged:
1005
- * return hub.open();
999
+ * ```ts
1000
+ * import type { Runtime } from "@demlik/tea";
1001
+ * import {
1002
+ * driveProjections,
1003
+ * projectionRegistry,
1004
+ * sseHub,
1005
+ * sseProjection,
1006
+ * } from "@demlik/tea/do";
1007
+ *
1008
+ * type MyState = { readonly turns: number };
1009
+ * type MyMsg = { type: "turn_done"; turn: number } | { type: "tick" };
1010
+ * type MyEvent = { kind: "turn"; turn: number };
1011
+ * declare const runtime: Runtime<MyState, MyMsg>;
1012
+ *
1013
+ * const hub = sseHub<MyEvent>();
1014
+ * const registry = projectionRegistry<MyState, MyMsg>();
1015
+ * registry.register(sseProjection(hub, (msg: MyMsg | null) =>
1016
+ * msg?.type === "turn_done" ? { kind: "turn", turn: msg.turn } : null,
1017
+ * ));
1018
+ * driveProjections(registry, runtime); // SSE is now one projection
1019
+ * // /sse route unchanged:
1020
+ * const sseRoute = (): Response => hub.open();
1021
+ * ```
1006
1022
  */
1007
1023
  declare function sseProjection<Model, Msg extends {
1008
1024
  type: string;
@@ -1024,13 +1040,22 @@ declare function sseProjection<Model, Msg extends {
1024
1040
  * hand-rolled Msg switch to `on`.
1025
1041
  *
1026
1042
  * @example
1027
- * const hub = sseHub<MyFrame>();
1028
- * const runtime = await run(machine, { ctx, events: agentEvents() }).ready;
1029
- * const off = sseFromAgentEvents(runtime, hub, (e) =>
1030
- * e.type === "RunDone" ? { kind: "done", output: e.output } : null,
1031
- * );
1032
- * // /sse route unchanged:
1033
- * return hub.open();
1043
+ * ```ts
1044
+ * import type { Runtime } from "@demlik/tea";
1045
+ * import type { AgentEndedStatus, AgentEvent } from "@demlik/tea/agent";
1046
+ * import { sseFromAgentEvents, sseHub } from "@demlik/tea/do";
1047
+ *
1048
+ * type MyFrame = { kind: "ended"; status: AgentEndedStatus };
1049
+ * // Built with `run(machine, { ctx, events: agentEvents() }).ready`.
1050
+ * declare const runtime: Runtime<unknown, { type: string }, AgentEvent<string>>;
1051
+ *
1052
+ * const hub = sseHub<MyFrame>();
1053
+ * const off = sseFromAgentEvents(runtime, hub, (e) =>
1054
+ * e.type === "RunDone" ? { kind: "ended", status: e.status } : null,
1055
+ * );
1056
+ * // /sse route unchanged:
1057
+ * const sseRoute = (): Response => hub.open();
1058
+ * ```
1034
1059
  */
1035
1060
  declare function sseFromAgentEvents<R, Frame>(runtime: {
1036
1061
  on<K extends AgentEvent<R>["type"]>(type: K, handler: (event: Extract<AgentEvent<R>, {
@@ -1140,20 +1165,55 @@ interface AgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R,
1140
1165
  * issue #53 had every consumer re-write.
1141
1166
  *
1142
1167
  * @example
1143
- * const host = createAgentHost<Stage, Purpose, Outputs, ClientResult, SseEvent>({
1144
- * run, // from `@demlik/tea/promise`
1145
- * buildMachine: () => agent.toMachine<Ctx>({ toolInterpret }),
1146
- * store: doStore(storage, parse),
1147
- * ctx,
1148
- * toSseFrame: (e) =>
1149
- * e.type === "ToolSettled" ? { kind: "result", ...} :
1150
- * e.type === "TurnSettled" && e.turn.toolCalls.length === 0
1151
- * ? { kind: "verdict", verdict: e.turn.content } :
1152
- * e.type === "RunDone" ? { kind: "phase", phase: "done" } : null,
1153
- * });
1154
- * // route: return host.sse.open();
1155
- * // start: await (await host.runtime()).dispatch({ type: "agent_start", ... });
1156
- * // test: (await host.status()).kind === "suspended"
1168
+ * ```ts
1169
+ * import type { Interpret, Migrated } from "@demlik/tea";
1170
+ * import type {
1171
+ * AgentKnob,
1172
+ * AgentMachineMsg,
1173
+ * AgentState,
1174
+ * AgentTurn,
1175
+ * ToolCall,
1176
+ * } from "@demlik/tea/agent";
1177
+ * import { createAgentHost, doStore } from "@demlik/tea/do";
1178
+ * import { run } from "@demlik/tea/promise";
1179
+ *
1180
+ * type Stage = "plan" | "act";
1181
+ * type Purpose = "plan_turn" | "act_turn";
1182
+ * type Outputs = Record<Purpose, AgentTurn>;
1183
+ * type ClientResult = string;
1184
+ * type ToolCmd = { readonly type: "run_tool" } & ToolCall;
1185
+ * type SseEvent =
1186
+ * | { kind: "result"; callId: string; result: ClientResult }
1187
+ * | { kind: "verdict"; verdict: string }
1188
+ * | { kind: "phase"; phase: string };
1189
+ * interface Ctx { readonly apiKey: string }
1190
+ * type S = AgentState<Stage, Purpose, Outputs, ClientResult>;
1191
+ *
1192
+ * // From `createAgent(...)`, and the interpret for its tool Cmd.
1193
+ * declare const agent: AgentKnob<Stage, Purpose, Outputs, ClientResult, ToolCmd, false, false>;
1194
+ * declare const toolInterpret: Interpret<AgentMachineMsg<Purpose, Outputs, ClientResult>, ToolCmd, Ctx>;
1195
+ * declare const storage: DurableObjectStorage;
1196
+ * declare const parse: (raw: unknown) => Migrated<S>;
1197
+ * declare const ctx: Ctx;
1198
+ *
1199
+ * const host = createAgentHost({
1200
+ * run,
1201
+ * buildMachine: () => agent.toMachine<Ctx>({ toolInterpret }),
1202
+ * store: doStore(storage, parse),
1203
+ * ctx,
1204
+ * toSseFrame: (e): SseEvent | null =>
1205
+ * e.type === "ToolSettled" ? { kind: "result", callId: e.callId, result: e.result } :
1206
+ * e.type === "TurnSettled" && e.turn.toolCalls.length === 0
1207
+ * ? { kind: "verdict", verdict: e.turn.content } :
1208
+ * e.type === "RunDone" ? { kind: "phase", phase: e.status.kind } : null,
1209
+ * });
1210
+ * // route:
1211
+ * const sseRoute = (): Response => host.sse.open();
1212
+ * // start:
1213
+ * await (await host.runtime()).dispatch({ type: "agent_start", runId: "run-1", at: Date.now() });
1214
+ * // test:
1215
+ * const suspended = (await host.status()).kind === "suspended";
1216
+ * ```
1157
1217
  */
1158
1218
  declare function createAgentHost<Stage, P extends string, O extends Record<P, AgentTurn>, R, Frame, C extends Cmd = Cmd, U extends Sub = Sub, Ctx = unknown>(config: AgentHostConfig<Stage, P, O, R, Frame, C, U, Ctx>): AgentHost<Stage, P, O, R, Frame>;
1159
1219
 
@@ -1799,10 +1859,20 @@ interface PresenceUpgrade {
1799
1859
  * via {@link registerHibernatableSocket}.
1800
1860
  *
1801
1861
  * @example
1862
+ * ```ts
1863
+ * import { acceptPresenceSocket, type PresenceCtx } from "@demlik/tea/do";
1864
+ *
1865
+ * declare const room: { snapshot(): unknown };
1866
+ *
1867
+ * class Lobby {
1868
+ * constructor(readonly ctx: PresenceCtx) {}
1869
+ *
1802
1870
  * async fetch(request: Request): Promise<Response> {
1803
1871
  * if (request.headers.get("Upgrade") !== "websocket") {
1804
1872
  * return new Response("expected a websocket upgrade", { status: 426 });
1805
1873
  * }
1874
+ * const playerId = new URL(request.url).searchParams.get("player");
1875
+ * const welcome = { type: "welcome", playerId };
1806
1876
  * const { server, response } = acceptPresenceSocket(this.ctx, {
1807
1877
  * attachment: { playerId },
1808
1878
  * });
@@ -1810,6 +1880,8 @@ interface PresenceUpgrade {
1810
1880
  * server.send(JSON.stringify(room.snapshot()));
1811
1881
  * return response;
1812
1882
  * }
1883
+ * }
1884
+ * ```
1813
1885
  */
1814
1886
  declare function acceptPresenceSocket<A>(ctx: PresenceCtx, options?: RegisterOptions<A>): PresenceUpgrade;
1815
1887
  /**
@@ -1829,12 +1901,11 @@ declare function presenceCount(ctx: PresenceCtx, tag?: string): number;
1829
1901
  * 1. `doStore<S>(storage, parse, key?)` — `Store<S>` impl backed by
1830
1902
  * `DurableObjectStorage`. JSON-stringifies on save, JSON-parses on load
1831
1903
  * and returns `unknown` (invariant-8 boundary); the substrate then calls
1832
- * `migrate(raw)` (which forwards to `parse`) to turn it into `S | null`.
1833
- * Returns `null` (typed as `unknown`) when the key is absent. Structural
1834
- * JSON malformation throws at load — `run()`'s boot path surfaces that
1835
- * (PRD throw-semantics table: "store.load throw at boot → run() throws
1836
- * synchronously"). Shape mismatch is NOT a throw — `parse` returns
1837
- * `null` and the substrate boots fresh.
1904
+ * `migrate(raw)` (which forwards to `parse`) to turn it into `S`, `null`
1905
+ * or a refusal. Returns `null` (typed as `unknown`) when the key is
1906
+ * absent. Structural JSON malformation throws at load, and `run()`'s boot
1907
+ * path turns that into a `StoreRefusedError` on `ready`. A shape
1908
+ * mismatch is `parse`'s to answer with `refuse(reason)` (#316).
1838
1909
  *
1839
1910
  * 2. `deferredGateway` + `createAgentHost` (from `./host`) — THE transport for
1840
1911
  * a DO-hosted agent. A `createAgent().toMachine()` machine owns exactly one
@@ -1892,22 +1963,23 @@ interface DoStoreOptions<S> {
1892
1963
  * `parse` is REQUIRED because DO storage is a real serialization boundary —
1893
1964
  * the bytes that come back through `JSON.parse` are structurally `unknown`,
1894
1965
  * and the caller (the DO that owns `S`) is the only party with enough
1895
- * information to validate the shape. Returning `null` from `parse` means
1896
- * "no usable persisted state" — the substrate boots `init` with `loaded =
1897
- * null`, a known-good fresh-boot path. `parse` must NOT throw per the
1898
- * `Store<S>.migrate` contract; shape mismatch is a value (null), not a
1899
- * panic.
1966
+ * information to validate the shape. `parse` returns `S` for a shape it
1967
+ * recognizes, `null` when nothing was saved (the substrate boots `init` with
1968
+ * `loaded = null`), and `refuse(reason)` for saved bytes it cannot read.
1969
+ * `parse` must NOT throw per the `Store<S>.migrate` contract; a shape
1970
+ * mismatch is a value (a refusal), not a panic.
1900
1971
  *
1901
1972
  * Structural malformations (the stored cell isn't even JSON) still throw at
1902
1973
  * `load()` — that's an infrastructure error, distinct from a schema
1903
- * mismatch. The substrate surfaces it via `runtime.ready` rejection.
1974
+ * mismatch. Either way `runtime.ready` rejects with `StoreRefusedError`
1975
+ * before `init` runs, so nothing is saved over the old bytes.
1904
1976
  *
1905
1977
  * Concrete bite this closes: when a `State` variant is renamed between
1906
1978
  * deploys, the DO's new code previously received a value typed as the new
1907
1979
  * `S` that held a runtime string from the old `S` — silent undefined
1908
- * behavior in `init`/`update`. After this, the boundary parse rejects the
1909
- * old shape (returns null) and the DO boots fresh, picking up its new
1910
- * schema from the next dispatch onward.
1980
+ * behavior in `init`/`update`. After this, the boundary parse refuses the
1981
+ * old shape and the DO fails to start instead of running on it or saving
1982
+ * a fresh state over it.
1911
1983
  *
1912
1984
  * Serialization sharp edge (#182): `save` JSON-serializes the Model, and
1913
1985
  * `JSON.stringify` does NOT survive a `Map`/`Set`/`Date` (a `Map` stringifies
@@ -1920,14 +1992,18 @@ interface DoStoreOptions<S> {
1920
1992
  * value equal to `state`. Omit `serialize` and the Model must stay plain-JSON
1921
1993
  * (the `Record`-not-`Map` constraint the default imposes, unchanged).
1922
1994
  *
1923
- * @param parse - boundary parse, the deserialize half (`unknown -> S | null`).
1995
+ * @param parse - boundary parse, the deserialize half (`unknown -> S | null`,
1996
+ * or `refuse(reason)` for bytes it cannot read).
1924
1997
  * @param keyOrOptions - either the storage key (legacy positional form,
1925
1998
  * defaults to `@@state`) or a {@link DoStoreOptions} bag carrying `key`
1926
1999
  * and/or the `serialize` hook. A bare string is treated as `{ key }`.
2000
+ *
2001
+ * Either form is a `DeletableStore<S>`: `delete()` removes the state cell and
2002
+ * its `<key>@@version` cell in one `storage.delete` call.
1927
2003
  */
1928
- declare function doStore<S>(storage: DurableObjectStorage, parse: (raw: unknown) => S | null, keyOrOptions: DoStoreOptions<S> & {
2004
+ declare function doStore<S>(storage: DurableObjectStorage, parse: (raw: unknown) => Migrated<S>, keyOrOptions: DoStoreOptions<S> & {
1929
2005
  readonly fenced: true;
1930
- }): FencedStore<S>;
1931
- declare function doStore<S>(storage: DurableObjectStorage, parse: (raw: unknown) => S | null, keyOrOptions?: string | DoStoreOptions<S>): Store<S>;
2006
+ }): FencedStore<S> & DeletableStore<S>;
2007
+ declare function doStore<S>(storage: DurableObjectStorage, parse: (raw: unknown) => Migrated<S>, keyOrOptions?: string | DoStoreOptions<S>): DeletableStore<S>;
1932
2008
 
1933
2009
  export { type AgentHost, type AgentHostConfig, type AlarmStorage, type AppliedEffects, type AppliedEffectsEvent, type AppliedEffectsGuard, type AttachableSocket, type BroadcastOptions, type BroadcastReport, type DeferResumeHook, type DeferStepHostConfig, type DeferredGateway, type DeferredStepOutcome, type DeferredStepResponse, type DoStoreOptions, type DurableCommandCarrier, type DurableTimer, type DurableTimerConfig, type EffectApplied, EffectConfirmed, type EffectForgotten, type EffectKey, EffectOwed, type EventLogRange, type EventSourcedOptions, type EventSourcedStore, type ExecuteStep, type HibernatableCtx, type IdempotentEffect, type IdempotentOutcome, type NextStep, PendingEffectsRecorder, type PersistedEvent, type PresenceCtx, type PresenceSocket, type PresenceUpgrade, type Projection, type ProjectionErrorContext, type ProjectionId, type ProjectionOnError, type ProjectionRegistry, type ProjectionRunner, type ProjectionUpdate, type RegisterOptions, type ResumePort, type RunStepLoopConfig, type SseHub, type StepCtx, type StepEngine, type StepHostConfig, type StepLoopOutcome, type StepOutcome, type StepRequest, type StepResponse, type StepResult, type StepTransport, type StepWorking, WS_READY_STATE_OPEN, acceptCommandSocket, acceptDurableCommandSocket, acceptPresenceSocket, agentIsResumable, appliedEffects, applyAppliedEvent, autoBoot, bootResume, broadcast, broadcastFrame, broadcastHibernatable, constantTimeEqual, createAgentHost, deferredGateway, doEventSourcedStore, doStore, driveProjections, durableCommandCarrier, durableDeferredGateway, durableTimer, emptyApplied, foldApplied, idempotentEffect, isApplied, mintRunToken, presenceCount, projectionIdString, projectionRegistry, rebuildProjection, registerHibernatableSocket, reissueSurvivingEffects, runProjection, runStepLoop, sseFromAgentEvents, sseHub, sseProjection, stepHost };
package/dist/do/index.js CHANGED
@@ -1,20 +1,20 @@
1
- import { status, agentBootMsg, agentEvents } from '../chunk-XBZQT2TD.js';
2
- import '../chunk-G5E74IJB.js';
3
- import { createIntake } from '../chunk-OPH6Y4UT.js';
1
+ import { status, agentBootMsg, AGENT_EVENT_TYPES, agentEvents } from '../chunk-PCJA2HTZ.js';
2
+ import { createIntake } from '../chunk-JYNYG5SF.js';
4
3
  export { applyEffectEvent, emptyLedger, foldLedger, isOwed, pendingEffectsLedger, survivingEffects } from '../chunk-6IQPODUF.js';
5
- import '../chunk-4PXNZ5UY.js';
6
- import '../chunk-4NTCPTNQ.js';
4
+ import '../chunk-XVIKSRCK.js';
5
+ import '../chunk-YIMOFXST.js';
7
6
  import '../chunk-QNGYQMZB.js';
8
- import '../chunk-PR6TB3BL.js';
9
- import '../chunk-TXN2KFHF.js';
10
- import '../chunk-6XBEYZME.js';
7
+ import '../chunk-WTSOW2MD.js';
8
+ import '../chunk-C3G2QFEZ.js';
11
9
  import { defaultRetryPolicy, initRetry, recordFailure, shouldRetry, nextDelayMs } from '../chunk-VBDU4JL6.js';
10
+ import '../chunk-PR6TB3BL.js';
12
11
  import '../chunk-4LPY67E4.js';
13
- import '../chunk-GWWCCSDH.js';
14
- import '../chunk-QWIPH4YH.js';
15
- import '../chunk-KWNCM6XM.js';
16
- import '../chunk-C4U5D5HP.js';
17
- import { StoreConflictError, replay } from '../chunk-K4ETBNKS.js';
12
+ import '../chunk-TXN2KFHF.js';
13
+ import '../chunk-H2ELKHI6.js';
14
+ import '../chunk-AHW2CLPT.js';
15
+ import '../chunk-JVE2LBFJ.js';
16
+ import '../chunk-FNGZMVIT.js';
17
+ import { StoreConflictError, replay } from '../chunk-AIIXV4XB.js';
18
18
 
19
19
  // src/do/durable-timer.ts
20
20
  function durableTimer(config) {
@@ -234,11 +234,7 @@ function sseFromAgentEvents(runtime, hub, toFrame) {
234
234
  const frame = toFrame(event);
235
235
  if (frame !== null) hub.emit(frame);
236
236
  };
237
- const offs = [
238
- runtime.on("TurnSettled", push),
239
- runtime.on("ToolSettled", push),
240
- runtime.on("RunDone", push)
241
- ];
237
+ const offs = AGENT_EVENT_TYPES.map((type) => runtime.on(type, push));
242
238
  return () => {
243
239
  for (const off of offs) off();
244
240
  };
@@ -714,6 +710,9 @@ function doStore(storage, parse, keyOrOptions = DEFAULT_STATE_KEY) {
714
710
  },
715
711
  migrate(raw) {
716
712
  return parse(raw);
713
+ },
714
+ async delete() {
715
+ await storage.delete([key, versionKey]);
717
716
  }
718
717
  };
719
718
  if (options.fenced !== true) return base;