iterate 0.3.0 → 0.4.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 (241) hide show
  1. package/README.md +164 -82
  2. package/dist/{next/api.d.ts → api.d.ts} +197 -33
  3. package/dist/{next/app-server.d.ts → app-server.d.ts} +7 -0
  4. package/dist/{next/app-server.mjs → app-server.mjs} +17 -15
  5. package/dist/app-server.mjs.map +1 -0
  6. package/dist/{next/app-session.mjs → app-session.mjs} +12 -15
  7. package/dist/app-session.mjs.map +1 -0
  8. package/dist/{next/app.mjs → app.mjs} +53 -14
  9. package/dist/app.mjs.map +1 -0
  10. package/dist/{next/client → client}/live-state.d.ts +11 -11
  11. package/dist/client/oauth.d.ts +17 -0
  12. package/dist/{next/client → client}/react.d.ts +10 -42
  13. package/dist/{next/client → client}/socket.d.ts +1 -0
  14. package/dist/client.mjs +156 -4
  15. package/dist/client.mjs.map +1 -0
  16. package/dist/{next/expression.d.ts → expression.d.ts} +11 -69
  17. package/dist/{next/expression.mjs → expression.mjs} +11 -109
  18. package/dist/expression.mjs.map +1 -0
  19. package/dist/lib-BWr-5mFO.mjs +36 -0
  20. package/dist/lib-BWr-5mFO.mjs.map +1 -0
  21. package/dist/{next/lib.d.ts → lib.d.ts} +16 -2
  22. package/dist/{next/lib.mjs → lib.mjs} +32 -3
  23. package/dist/lib.mjs.map +1 -0
  24. package/dist/node.d.ts +15 -3
  25. package/dist/node.mjs +36 -174
  26. package/dist/node.mjs.map +1 -1
  27. package/dist/{next/oauth-scopes.mjs → oauth-scopes.mjs} +1 -1
  28. package/dist/oauth-scopes.mjs.map +1 -0
  29. package/dist/{next/oauth.mjs → oauth.mjs} +14 -2
  30. package/dist/oauth.mjs.map +1 -0
  31. package/dist/principal.d.ts +8 -0
  32. package/dist/principal.mjs +8 -0
  33. package/dist/principal.mjs.map +1 -0
  34. package/dist/project-ingress.d.ts +58 -0
  35. package/dist/project-ingress.mjs +104 -0
  36. package/dist/project-ingress.mjs.map +1 -0
  37. package/dist/{next/react.mjs → react.mjs} +12 -12
  38. package/dist/react.mjs.map +1 -0
  39. package/dist/sdk/auth.d.ts +25 -0
  40. package/dist/sdk/index.d.ts +155 -0
  41. package/dist/sdk/record-pipelined-steps.d.ts +19 -0
  42. package/dist/sdk.mjs +245 -2
  43. package/dist/sdk.mjs.map +1 -0
  44. package/dist/{next/stream → stream}/processor.d.ts +28 -23
  45. package/dist/{next/stream → stream}/processor.mjs +48 -25
  46. package/dist/stream/processor.mjs.map +1 -0
  47. package/dist/{next/stream → stream}/run.d.ts +9 -6
  48. package/dist/{next/stream → stream}/run.mjs +13 -8
  49. package/dist/stream/run.mjs.map +1 -0
  50. package/dist/stream/test-support.d.ts +45 -0
  51. package/dist/stream/test-support.mjs +196 -0
  52. package/dist/stream/test-support.mjs.map +1 -0
  53. package/package.json +65 -219
  54. package/THIRD_PARTY_NOTICES.md +0 -55
  55. package/bin/iterate.js +0 -94
  56. package/dist/api-url-B6404M82.mjs +0 -17
  57. package/dist/api-url-B6404M82.mjs.map +0 -1
  58. package/dist/app-ref-BipL0feU.mjs +0 -35
  59. package/dist/app-ref-BipL0feU.mjs.map +0 -1
  60. package/dist/app-ref-C1CrgXqX.mjs +0 -7
  61. package/dist/app-ref-C1CrgXqX.mjs.map +0 -1
  62. package/dist/app-ref-DYai_om1.mjs +0 -7
  63. package/dist/app-ref-DYai_om1.mjs.map +0 -1
  64. package/dist/cli-D0c-pDL_.mjs +0 -1010
  65. package/dist/cli-D0c-pDL_.mjs.map +0 -1
  66. package/dist/client.d.ts +0 -3
  67. package/dist/cloudflare-BTm90gQ4.mjs +0 -951
  68. package/dist/cloudflare-BTm90gQ4.mjs.map +0 -1
  69. package/dist/contract-s4FW4eES.mjs +0 -309
  70. package/dist/contract-s4FW4eES.mjs.map +0 -1
  71. package/dist/document-review/index.d.ts +0 -5
  72. package/dist/document-review/types.d.ts +0 -107
  73. package/dist/document-review.mjs +0 -7015
  74. package/dist/document-review.mjs.map +0 -1
  75. package/dist/durable-object-processor-durability-CNsTjAJS.mjs +0 -205
  76. package/dist/durable-object-processor-durability-CNsTjAJS.mjs.map +0 -1
  77. package/dist/idempotency-DleloJNt.mjs +0 -28
  78. package/dist/idempotency-DleloJNt.mjs.map +0 -1
  79. package/dist/index.d.mts +0 -5
  80. package/dist/index.mjs +0 -8
  81. package/dist/index.mjs.map +0 -1
  82. package/dist/itx/api-url.d.ts +0 -6
  83. package/dist/itx/itx-node-client.d.ts +0 -65
  84. package/dist/itx/itx-session.d.ts +0 -215
  85. package/dist/itx/owned-rpc-session.d.ts +0 -14
  86. package/dist/itx/query-client.d.ts +0 -10
  87. package/dist/itx-api.generated.d.ts +0 -6195
  88. package/dist/itx-session-sjud8GiT.mjs +0 -534
  89. package/dist/itx-session-sjud8GiT.mjs.map +0 -1
  90. package/dist/live-state-BJNqOwFw.mjs +0 -299
  91. package/dist/live-state-BJNqOwFw.mjs.map +0 -1
  92. package/dist/next/app-server.mjs.map +0 -1
  93. package/dist/next/app-session.mjs.map +0 -1
  94. package/dist/next/app.mjs.map +0 -1
  95. package/dist/next/client/oauth.d.ts +0 -12
  96. package/dist/next/client.mjs +0 -156
  97. package/dist/next/client.mjs.map +0 -1
  98. package/dist/next/expression.mjs.map +0 -1
  99. package/dist/next/lib.mjs.map +0 -1
  100. package/dist/next/oauth-scopes.mjs.map +0 -1
  101. package/dist/next/oauth.mjs.map +0 -1
  102. package/dist/next/principal.d.ts +0 -64
  103. package/dist/next/principal.mjs +0 -98
  104. package/dist/next/principal.mjs.map +0 -1
  105. package/dist/next/project-ingress.d.ts +0 -37
  106. package/dist/next/project-ingress.mjs +0 -75
  107. package/dist/next/project-ingress.mjs.map +0 -1
  108. package/dist/next/react.mjs.map +0 -1
  109. package/dist/next/sdk/auth.d.ts +0 -5
  110. package/dist/next/sdk/index.d.ts +0 -112
  111. package/dist/next/sdk.mjs +0 -139
  112. package/dist/next/sdk.mjs.map +0 -1
  113. package/dist/next/stream/processor.mjs.map +0 -1
  114. package/dist/next/stream/run.mjs.map +0 -1
  115. package/dist/next-node.d.ts +0 -15
  116. package/dist/next-node.mjs +0 -51
  117. package/dist/next-node.mjs.map +0 -1
  118. package/dist/processor-host-capabilities-BMFH3KTM.mjs +0 -56
  119. package/dist/processor-host-capabilities-BMFH3KTM.mjs.map +0 -1
  120. package/dist/processors/cloudflare.d.ts +0 -3
  121. package/dist/processors/durable-object-processor-durability.d.ts +0 -79
  122. package/dist/processors/event-consumption-metrics.d.ts +0 -82
  123. package/dist/processors/idempotency.d.ts +0 -13
  124. package/dist/processors/index.d.ts +0 -12
  125. package/dist/processors/processor-contracts.d.ts +0 -342
  126. package/dist/processors/processor-facet.d.ts +0 -186
  127. package/dist/processors/processor-host-capabilities.d.ts +0 -60
  128. package/dist/processors/prompt-sections.d.ts +0 -17
  129. package/dist/processors/rpc-types.d.ts +0 -515
  130. package/dist/processors/schemas.d.ts +0 -102
  131. package/dist/processors/stream-handle.d.ts +0 -45
  132. package/dist/processors/stream-processor-keepalive.d.ts +0 -95
  133. package/dist/processors/stream-processor-registry.d.ts +0 -233
  134. package/dist/processors/stream-processor-runner.d.ts +0 -289
  135. package/dist/processors/stream-processor.d.ts +0 -339
  136. package/dist/processors/stream-runtime-metrics.d.ts +0 -107
  137. package/dist/processors/testing.d.ts +0 -302
  138. package/dist/processors-BoNyeBfQ.mjs +0 -10
  139. package/dist/processors-BoNyeBfQ.mjs.map +0 -1
  140. package/dist/processors-cloudflare.mjs +0 -3
  141. package/dist/processors-testing.mjs +0 -435
  142. package/dist/processors-testing.mjs.map +0 -1
  143. package/dist/processors.mjs +0 -52
  144. package/dist/processors.mjs.map +0 -1
  145. package/dist/protocol-DnK_f2m6.mjs +0 -251
  146. package/dist/protocol-DnK_f2m6.mjs.map +0 -1
  147. package/dist/sdk/capnweb/index.d.ts +0 -2
  148. package/dist/sdk/capnweb/live-state/compact.d.ts +0 -5
  149. package/dist/sdk/capnweb/live-state/diff.d.ts +0 -41
  150. package/dist/sdk/capnweb/live-state/engine.d.ts +0 -44
  151. package/dist/sdk/capnweb/live-state/index.d.ts +0 -41
  152. package/dist/sdk/capnweb/live-state/protocol.d.ts +0 -87
  153. package/dist/sdk/capnweb/live-state/retain.d.ts +0 -23
  154. package/dist/sdk/capnweb/live-state/store.d.ts +0 -20
  155. package/dist/sdk/capnweb/live-state/types.d.ts +0 -11
  156. package/dist/sdk/capnweb/react.d.ts +0 -45
  157. package/dist/sdk/capnweb/react.mjs +0 -316
  158. package/dist/sdk/capnweb/react.mjs.map +0 -1
  159. package/dist/sdk/capnweb.mjs +0 -4
  160. package/dist/sdk/itx/react.d.ts +0 -191
  161. package/dist/sdk/itx/react.mjs +0 -383
  162. package/dist/sdk/itx/react.mjs.map +0 -1
  163. package/dist/sdk-DMB-IM11.mjs +0 -933
  164. package/dist/sdk-DMB-IM11.mjs.map +0 -1
  165. package/dist/sdk.d.ts +0 -339
  166. package/dist/serve-itx.d.ts +0 -46
  167. package/dist/starter-apps/flake-dashboard/app-ref.d.ts +0 -31
  168. package/dist/starter-apps/flake-dashboard/configured-worker.mjs +0 -1055
  169. package/dist/starter-apps/flake-dashboard/configured-worker.mjs.map +0 -1
  170. package/dist/starter-apps/flake-dashboard/contract.d.ts +0 -4839
  171. package/dist/starter-apps/flake-dashboard/contract.mjs +0 -2
  172. package/dist/starter-apps/flake-dashboard/index.d.ts +0 -17
  173. package/dist/starter-apps/flake-dashboard/index.mjs +0 -56
  174. package/dist/starter-apps/flake-dashboard/index.mjs.map +0 -1
  175. package/dist/starter-apps/flake-dashboard/worker.d.ts +0 -4607
  176. package/dist/starter-apps/github-ai-linter/ai-linter.d.ts +0 -8914
  177. package/dist/starter-apps/github-ai-linter/configured-worker.mjs +0 -17987
  178. package/dist/starter-apps/github-ai-linter/configured-worker.mjs.map +0 -1
  179. package/dist/starter-apps/github-ai-linter/contract.d.ts +0 -9193
  180. package/dist/starter-apps/github-ai-linter/index.d.ts +0 -10
  181. package/dist/starter-apps/github-ai-linter/index.mjs +0 -36
  182. package/dist/starter-apps/github-ai-linter/index.mjs.map +0 -1
  183. package/dist/starter-apps/github-ai-linter/prompt.d.ts +0 -13
  184. package/dist/starter-apps/github-ai-linter/review-bot.d.ts +0 -808
  185. package/dist/starter-apps/github-ai-linter/rules.d.ts +0 -34
  186. package/dist/starter-apps/github-ai-linter/worker-ref.d.ts +0 -19
  187. package/dist/starter-apps/github-ai-linter/worker.d.ts +0 -19
  188. package/dist/starter-apps/github-ai-linter/worker.mjs +0 -947
  189. package/dist/starter-apps/github-ai-linter/worker.mjs.map +0 -1
  190. package/dist/starter-apps/guestbook/app-ref.d.ts +0 -27
  191. package/dist/starter-apps/guestbook/client.d.ts +0 -7
  192. package/dist/starter-apps/guestbook/client.mjs +0 -59
  193. package/dist/starter-apps/guestbook/configured-worker.mjs +0 -205
  194. package/dist/starter-apps/guestbook/configured-worker.mjs.map +0 -1
  195. package/dist/starter-apps/guestbook/index.d.ts +0 -9
  196. package/dist/starter-apps/guestbook/index.mjs +0 -31
  197. package/dist/starter-apps/guestbook/index.mjs.map +0 -1
  198. package/dist/starter-apps/guestbook/processor.d.ts +0 -2267
  199. package/dist/starter-apps/guestbook/worker.d.ts +0 -26
  200. package/dist/starter-apps/guestbook/worker.mjs +0 -191
  201. package/dist/starter-apps/guestbook/worker.mjs.map +0 -1
  202. package/dist/starter-apps/media/configured-worker.mjs +0 -577
  203. package/dist/starter-apps/media/configured-worker.mjs.map +0 -1
  204. package/dist/starter-apps/media/index.mjs +0 -36
  205. package/dist/starter-apps/media/index.mjs.map +0 -1
  206. package/dist/starter-apps/media/ref.mjs +0 -20
  207. package/dist/starter-apps/media/ref.mjs.map +0 -1
  208. package/dist/starter-apps/media/worker.mjs +0 -579
  209. package/dist/starter-apps/media/worker.mjs.map +0 -1
  210. package/dist/starter-apps/notes/configured-worker.mjs +0 -6134
  211. package/dist/starter-apps/notes/configured-worker.mjs.map +0 -1
  212. package/dist/starter-apps/notes/index.mjs +0 -23
  213. package/dist/starter-apps/notes/index.mjs.map +0 -1
  214. package/dist/starter-apps/notes/ref.mjs +0 -21
  215. package/dist/starter-apps/notes/ref.mjs.map +0 -1
  216. package/dist/starter-apps/notes/worker.mjs +0 -427
  217. package/dist/starter-apps/notes/worker.mjs.map +0 -1
  218. package/dist/starter-apps/todo/client.mjs +0 -59
  219. package/dist/starter-apps/todo/configured-worker.mjs +0 -2864
  220. package/dist/starter-apps/todo/configured-worker.mjs.map +0 -1
  221. package/dist/starter-apps/todo/index.d.ts +0 -8
  222. package/dist/starter-apps/todo/index.mjs +0 -29
  223. package/dist/starter-apps/todo/index.mjs.map +0 -1
  224. package/dist/stream-processor-keepalive-DAQTP6m3.mjs +0 -2082
  225. package/dist/stream-processor-keepalive-DAQTP6m3.mjs.map +0 -1
  226. package/dist/usingCtx-mZx5nsAW.mjs +0 -11800
  227. package/dist/usingCtx-mZx5nsAW.mjs.map +0 -1
  228. package/dist/worker-ref-DZxPDmb_.mjs +0 -390
  229. package/dist/worker-ref-DZxPDmb_.mjs.map +0 -1
  230. package/dist/worker.d.mts +0 -33
  231. package/dist/worker.mjs +0 -18
  232. package/dist/worker.mjs.map +0 -1
  233. package/menubar/Iterate.entitlements +0 -12
  234. package/menubar/Iterate.swift +0 -914
  235. package/menubar/IterateIcon.swift +0 -145
  236. package/menubar/README.md +0 -28
  237. package/menubar/build-menubar-app.sh +0 -59
  238. /package/dist/{next/api.mjs → api.mjs} +0 -0
  239. /package/dist/{next/app-session.d.ts → app-session.d.ts} +0 -0
  240. /package/dist/{next/app.d.ts → app.d.ts} +0 -0
  241. /package/dist/{next/oauth-scopes.d.ts → oauth-scopes.d.ts} +0 -0
@@ -1,515 +0,0 @@
1
- /**
2
- * The stream + processor RPC surface: stored subscriptions, live connections, the
3
- * processor state-push contract, and the batch envelope sent to callbacks.
4
- * These are hand-authored shapes (generics preserved) that both the public itx
5
- * contract and the server-side processor and connection code build against.
6
- */
7
- import type { StatefulDynamicWorkerRef } from "../itx-api.generated.ts";
8
- import type { StreamEvent } from "./schemas.ts";
9
- /** Maximum serialized durable-event bytes one Stream read may return. */
10
- export declare const MAX_STREAM_EVENT_READ_BYTE_LIMIT: number;
11
- /** Source-local identity for one durable subscription that sends matching stream events. */
12
- export type SubscriptionName = string;
13
- /** Stable identity for one live connection to a processEventBatch callback. */
14
- export type ConnectionKey = string;
15
- /** The read window accepted by `Stream.getEvents` / `Stream.readEvents`. */
16
- export type StreamEventReadInput = {
17
- /** Exclusive lower bound. Defaults to 0. */
18
- afterOffset?: number;
19
- /** Exclusive upper bound. Omit/null to read through the latest offset. */
20
- beforeOffset?: number | null;
21
- /** Event types to include. Omit or include "*" for all; [] matches none. */
22
- eventTypes?: readonly string[];
23
- /** Page size, 1-500. Defaults to 500. */
24
- limit?: number;
25
- /**
26
- * Maximum serialized durable-event bytes in one page, from 1 through 8 MiB.
27
- * It cannot be used with `includeEphemeral`. A shorter nonempty page may
28
- * still have more matching events; advance from its last offset until an
29
- * empty page confirms the current head. The first matching event is returned
30
- * even when it alone exceeds this cap, so the cursor can make progress.
31
- */
32
- byteLimit?: number;
33
- /**
34
- * Include ephemeral events (default false). The Durable Object incarnation
35
- * keeps their bodies in a bounded memory buffer;
36
- * this opt-in merges the events still buffered into the durable page.
37
- * Restart and FIFO eviction leave permanent offset gaps, so never derive
38
- * durable state from an ephemeral event.
39
- */
40
- includeEphemeral?: boolean;
41
- };
42
- /** One consistent read of a processor (what `snapshot()` returns): the folded
43
- * state pinned to the offset of the last event folded into it. */
44
- export type ProcessorSnapshot<State> = {
45
- offset: number;
46
- state: State;
47
- };
48
- /**
49
- * The internal extension used when stream delivery calls a hosted processor.
50
- * Public processor properties expose only {@link StreamProcessorRpc}; a stored
51
- * subscription persists an ITX expression that continues one
52
- * step past that public property to this trusted-only method:
53
- * `["agents", ["get", path], "processor", "wakeStreamProcessor"]`.
54
- *
55
- * `wakeStreamProcessor` is called by trusted stream delivery only
56
- * (trusted-internal): its processEventBatch callback drives the host's durable
57
- * checkpoint, so an ordinary session poking it could feed fabricated batches
58
- * and fast-forward the checkpoint past real events. Multi-processor hosts (an
59
- * agent stream hosts agent + slack-agent + more) resolve WHICH processor
60
- * wakes from the request's `name` (which equals the contract slug). Each
61
- * public domain surface selects that same named processor for inspection,
62
- * while deliberately omitting this method from its public TypeScript
63
- * contract, so `agent.processor`, `agent.slack.processor`, and other siblings
64
- * expose their own snapshots and checkpoints.
65
- */
66
- export type WakeableStreamProcessorRpc<State = unknown> = StreamProcessorRpc<State> & {
67
- wakeStreamProcessor(request: StreamProcessorWakeRequest): Promise<StreamProcessorWakeResponse>;
68
- };
69
- /**
70
- * The read-side RPC surface every stream processor node exposes: inspect
71
- * runtime state (snapshot plus a processor-specific runtime bag), take an
72
- * offset-pinned `snapshot()` of the folded state, and `waitUntilProcessed` to
73
- * block until the processor has durably folded through a given offset.
74
- */
75
- export interface StreamProcessorRpc<State = unknown> {
76
- getRuntimeState(): Promise<ProcessorRuntimeState<State>>;
77
- snapshot(): Promise<ProcessorSnapshot<State>>;
78
- waitUntilProcessed(input: {
79
- offset: number;
80
- timeoutMs?: number;
81
- }): Promise<void>;
82
- }
83
- /**
84
- * Live handle for one live-state subscription. `ping()` reports liveness (and
85
- * the call rejects when the hosting incarnation is gone); `unsubscribe()` closes it.
86
- */
87
- export type { LiveStateRpc, LiveStateSubscriptionHandle } from "../sdk/capnweb/live-state/types.ts";
88
- /**
89
- * A node's live state — a source-agnostic reactive value. `get()` reads it once;
90
- * `subscribe()` opens a channel that pushes a full snapshot then minimal diffs
91
- * (see `lib/live-state`), which the React `useLiveState` hook reassembles so
92
- * components pick only the slice they render. ANY RpcTarget can expose one: a
93
- * Durable Object over its folded state, or a stateless worker over state it
94
- * computes or fetches.
95
- *
96
- * Deliberately READ-ONLY over the wire: the server DERIVES this state (a DO
97
- * reassembles it from its fold), so writes go through the node's own verbs —
98
- * events appended, mutations called — never a generic `set`. A wire-level
99
- * `set`/`assign` would let any principal that can reach the node broadcast
100
- * fabricated state to every live-state listener.
101
- */
102
- /**
103
- * Batch delivered to stream processors and live connections.
104
- *
105
- * Kept named because callback retention, processor hosts, and tests all depend
106
- * on the same cross-RPC batch envelope.
107
- */
108
- export type StreamEventBatch = {
109
- projectId: string | null;
110
- path: string;
111
- /** Random identity of this event log; changes when the stream is recreated. */
112
- streamId: string;
113
- events: StreamEvent[];
114
- /** Exclusive raw-log cursor from which this delivery scan began. */
115
- scannedAfterOffset: number;
116
- /** Inclusive raw-log cursor through which this delivery scan completed. */
117
- scannedThroughOffset: number;
118
- streamMaxOffset: number;
119
- /** Reduced core state, or null when the connection opts out with `state: false`. */
120
- state: unknown;
121
- };
122
- /**
123
- * One atomic stream read: the matching events plus the identity and raw-log
124
- * head they were read from. Consumers that persist offsets must use this
125
- * envelope instead of pairing `getEvents()` with a separate state read — a
126
- * reset between those calls would make equal offsets name a different log.
127
- */
128
- export type StreamEventPage = {
129
- /** Random identity of the event log that served this page. */
130
- streamId: string;
131
- /** Highest assigned raw-log offset when this page was read. */
132
- streamMaxOffset: number;
133
- events: StreamEvent[];
134
- };
135
- /**
136
- * Callback invoked by the stream send loop for each delivered batch.
137
- *
138
- * It stays as a named type because Workers RPC callback lifecycle helpers need
139
- * to duplicate, retain, and dispose exactly this callback shape.
140
- */
141
- export type ProcessEventBatch = (batch: StreamEventBatch) => unknown;
142
- /**
143
- * Serializable failure reported after a durable wake delivery finishes.
144
- *
145
- * The result crosses an independent one-way RPC hop, so preserve the lifecycle
146
- * flags and ITX call correlation that distinguish and locate failures. Error
147
- * prototypes and arbitrary properties do not survive that hop reliably.
148
- */
149
- export type StreamWakeDeliveryError = {
150
- name: string;
151
- message: string;
152
- /** Wide-log ID of the failed ITX call, when the failure crossed that boundary. */
153
- itxCallId?: string;
154
- durableObjectReset?: true;
155
- overloaded?: true;
156
- retryable?: true;
157
- };
158
- /** The hosted processor's final result for one durable wake delivery. */
159
- export type StreamWakeDeliveryResult = {
160
- outcome: "ok";
161
- } | {
162
- outcome: "error";
163
- error: StreamWakeDeliveryError;
164
- };
165
- /**
166
- * One-shot acknowledgement capability owned by a single durable wake batch.
167
- *
168
- * It is deliberately independent of the callback call's return value. A
169
- * processor may append back to the stream that delivered the batch; making
170
- * the stream await that return value can make two Durable Objects wait for
171
- * each other forever.
172
- */
173
- export type ReportStreamWakeDeliveryResult = (result: StreamWakeDeliveryResult) => unknown;
174
- /** Internal hosted-processor frame: an ordinary batch plus its one-shot completion callback. */
175
- export type StreamWakeEventBatch = StreamEventBatch & {
176
- reportDeliveryResult: ReportStreamWakeDeliveryResult;
177
- };
178
- /** Hosted processor callback. Its call result is always disposed without being awaited. */
179
- export type ProcessStreamWakeEventBatch = (batch: StreamWakeEventBatch) => unknown;
180
- /**
181
- * The committed subscription fields carried with a delivery whose cursor the
182
- * source stream stores. This deliberately omits metadata, provenance, and
183
- * idempotency bookkeeping that the core reducer does not retain. A receiver
184
- * uses the included event coordinates and payload to verify the delivery
185
- * against the subscription it recorded.
186
- */
187
- export type SubscriptionConfigurationForDelivery = {
188
- type: "events.iterate.com/stream/subscription-configured";
189
- offset: number;
190
- createdAt: string;
191
- path: string;
192
- payload: {
193
- /** The subscription's caller-chosen name; omitted when the effective name
194
- * is derived from this event's offset (`subscription:<offset>`). */
195
- name?: string;
196
- description?: string;
197
- filter?: {
198
- eventTypes?: string[];
199
- jsonataCondition?: string;
200
- };
201
- receiver: {
202
- /** The processor runs as a facet of the stream's own Durable Object:
203
- * the subscription NAME is the facet name and the registered-contract
204
- * selector; delivery is an in-process parent→facet dial (no wake
205
- * lane). `source` chooses the class — `builtin` (resolved by the
206
- * stream's path-family registration) or `userspace` (the DurableObject
207
- * class is loaded from `worker` and hosted as a facet). */
208
- action: "facet-processor";
209
- source: {
210
- kind: "builtin";
211
- } | {
212
- kind: "userspace";
213
- worker: StatefulDynamicWorkerRef;
214
- };
215
- } | {
216
- /** The processor runs in ANOTHER Durable Object, woken by dialing this
217
- * itx expression (own-DO or userspace-worker placement). */
218
- action: "wake-processor";
219
- expression: Array<string | [method: string, ...args: unknown[]]>;
220
- } | {
221
- action: "copy-to-stream";
222
- receivingStreamPath: string;
223
- jsonataTransform?: string;
224
- delivery: {
225
- start: "beginning" | "now";
226
- onFailingEvent: "halt";
227
- };
228
- } | {
229
- action: "itx-call";
230
- expression: Array<string | [method: string, ...args: unknown[]]>;
231
- jsonataTransform?: string;
232
- delivery: {
233
- start: "beginning" | "now";
234
- onFailingEvent: "halt" | "skip";
235
- };
236
- } | {
237
- action: "webhook-post";
238
- url: string;
239
- jsonataTransform?: string;
240
- delivery: {
241
- start: "beginning" | "now";
242
- onFailingEvent: "halt" | "skip";
243
- };
244
- };
245
- };
246
- };
247
- /**
248
- * The batch sent to a durable receiver for a subscription whose cursor the
249
- * source stream stores: delivery coordinates and events plus the fields an
250
- * at-least-once receiver needs to deduplicate and self-configure. Deliberately
251
- * not the state-carrying callback batch
252
- * {@link StreamEventBatch}: ITX calls and copy destinations do not get
253
- * folded core state, because other subscriptions' configuration, halt errors,
254
- * and the presence roster are deployment-internal. Webhooks use a narrower
255
- * per-event envelope for the same reason. Session callbacks and hosted
256
- * processors still get state-carrying batches because they paint or reduce
257
- * from stream state.
258
- */
259
- export type StreamDeliveryBatch = {
260
- projectId: string | null;
261
- path: string;
262
- /** Random identity assigned when this source stream's storage was created. */
263
- streamId: string;
264
- /** Creation time of this source stream; orders recreated streams whose offsets restarted. */
265
- streamCreatedAt: string;
266
- /**
267
- * For an ITX-call subscription with a `jsonataTransform`, each event's
268
- * `type`/`payload`/`metadata` are the transform's output while the
269
- * coordinates keep naming the source rows. Copy batches always carry the
270
- * untransformed source events: the receiving stream applies its transform
271
- * before committing.
272
- */
273
- events: StreamEvent[];
274
- streamMaxOffset: number;
275
- /** The source stream's subscription this delivery serves, by NAME. */
276
- name: SubscriptionName;
277
- /**
278
- * Offset of the configure or cursor-set event that started this delivery run.
279
- * It stays stable across network retries, but changes after an explicit seek
280
- * or same-key reconfiguration so those deliberate replays are not deduped as
281
- * old transport attempts.
282
- */
283
- cursorChangedAtSourceOffset: number;
284
- /**
285
- * Stable across retries of the same batch and cursor-control event,
286
- * so receivers can dedupe redeliveries even without per-event bookkeeping.
287
- * (`${event.path}@${event.offset}` remains the per-event idempotency idiom.)
288
- */
289
- deliveryId: string;
290
- /** 1-based consecutive attempt count for this batch. */
291
- attempt: number;
292
- /**
293
- * The committed `subscription-configured` event this delivery serves — so a
294
- * receiver can configure itself from committed stream state without a
295
- * side-channel registry for the source stream, filter, and receiver settings.
296
- * Narrowed to the fields the fold stores; an honest shape instead of a
297
- * `StreamEvent` cast that pretends metadata/source survived.
298
- */
299
- configuredEvent: SubscriptionConfigurationForDelivery;
300
- };
301
- /** What a receiving stream durably did with one delivered source batch. */
302
- export type CopyReceipt = {
303
- /**
304
- * Events the receiver terminally acknowledged: appended now, already
305
- * present under the same source-coordinate idempotency key, or dropped
306
- * because their stream-copy path cannot safely continue (cycle/hop limit —
307
- * audited by an `error-occurred` event on the receiving stream). The sender
308
- * advances its cursor past every event in an acked batch. The count itself
309
- * is observability-only wire decoration: the sender never reads it — the
310
- * awaited call resolving is the whole acknowledgement.
311
- */
312
- acknowledged: number;
313
- };
314
- /**
315
- * A durable receiver's declaration that it cannot accept ANY batch right now —
316
- * part of the delivery contract, not an implementation detail. The subscription's cursor row
317
- * treats a rejection carrying this name as "the receiver is down/not ready"
318
- * and backs off or halts even under `onFailingEvent: "skip"`,
319
- * because failing-event confirmation is a verdict about ONE event and an unavailable
320
- * receiver fails every event: confirming skips during an outage window steps
321
- * over healthy events forever (the bootstrap incarnation: the project-worker
322
- * feed called its receiver before the config repo seeded, and permanently skipped the
323
- * events that raced the seed).
324
- *
325
- * Matched by NAME, not instanceof: the rejection crosses Workers RPC hops
326
- * (loopback itx roots, DO bindings), which preserve `error.name` but not
327
- * class identity.
328
- */
329
- export declare class StreamReceiverUnavailableError extends Error {
330
- static readonly NAME = "StreamReceiverUnavailableError";
331
- readonly name = "StreamReceiverUnavailableError";
332
- }
333
- /** A compare-and-append assertion lost to another committed stream event. */
334
- export declare class StreamOffsetConflictError extends Error {
335
- static readonly NAME = "StreamOffsetConflictError";
336
- readonly name = "StreamOffsetConflictError";
337
- }
338
- /** An operation was bound to a stream lifetime that this path no longer names. */
339
- export declare class StreamIdMismatchError extends Error {
340
- static readonly NAME = "StreamIdMismatchError";
341
- readonly name = "StreamIdMismatchError";
342
- }
343
- /** Canonical guarded-append rejection text, including across RPC hops that
344
- * normalize the custom error name to `Error`. */
345
- export declare function streamIdMismatchMessage(expectedStreamId: string, actualStreamId: unknown): string;
346
- /**
347
- * Match a guarded append rejected because its source stream was recreated.
348
- * Durable Object RPC preserves the custom name; CapnWeb can reduce it to a
349
- * plain Error, so the exact canonical message remains a narrow fallback.
350
- */
351
- export declare function isStreamIdMismatchError(error: unknown): boolean;
352
- /** Canonical compare-and-append conflict text, including across RPC hops that
353
- * normalize the custom error name to `Error`. */
354
- export declare function streamOffsetConflictMessage(expectedOffset: number, actualOffset: number): string;
355
- /**
356
- * Match by name because Durable Object RPC preserves names, not prototypes.
357
- * CapnWeb's public itx boundary currently normalizes custom error names to
358
- * `Error`, so retain an exact message fallback for that hop. Keep this
359
- * deliberately narrow: callers use the result to retry a compare-and-append.
360
- */
361
- export declare function isStreamOffsetConflictError(error: unknown): boolean;
362
- export declare function isStreamReceiverUnavailableError(error: unknown): boolean;
363
- /**
364
- * One webhook delivery: a single committed event POSTed as JSON to the
365
- * subscription's URL. Deliberately per-EVENT (external webhook consumers
366
- * expect individual events, and per-event acking gives mid-batch
367
- * resumability) and deliberately WITHOUT the `state` batch callbacks receive — core
368
- * reduced state is internal and has no business leaving the deployment.
369
- *
370
- * Webhook delivery is at-least-once: a remote processor must deduplicate by
371
- * (streamId, event.offset).
372
- */
373
- export type StreamWebhookDelivery = {
374
- /** Never null: webhooks require a project-scoped stream (egress attribution). */
375
- projectId: string;
376
- path: string;
377
- /** Random identity assigned when this source stream's storage was created. */
378
- streamId: string;
379
- /** Creation time of this source stream; orders recreated streams whose offsets restarted. */
380
- streamCreatedAt: string;
381
- /**
382
- * The committed event. When the subscription configures a `jsonataTransform`, its
383
- * `type`/`payload`/`metadata` are the transform's output while the
384
- * coordinates (`offset`, `createdAt`, `path`) keep naming the source row.
385
- */
386
- event: StreamEvent;
387
- /** The source stream's subscription this delivery serves, by NAME. */
388
- name: SubscriptionName;
389
- /** See {@link StreamDeliveryBatch.cursorChangedAtSourceOffset}. */
390
- cursorChangedAtSourceOffset: number;
391
- /** Stable across retries of this event within one delivery run. */
392
- deliveryId: string;
393
- /** 1-based consecutive attempt count for this event. */
394
- attempt: number;
395
- /** The committed subscription event this delivery serves (see {@link StreamDeliveryBatch}). */
396
- configuredEvent: SubscriptionConfigurationForDelivery;
397
- };
398
- /**
399
- * What the stream sends when waking a hosted processor through
400
- * `wakeStreamProcessor`: serializable coordinates only.
401
- */
402
- export type StreamProcessorWakeRequest = {
403
- stream: {
404
- projectId: string | null;
405
- path: string;
406
- /** Random identity of this event log; fences persisted processor checkpoints. */
407
- streamId: string;
408
- streamMaxOffset: number;
409
- };
410
- /**
411
- * The subscription's NAME — the caller-chosen per-stream binding this wake
412
- * serves. Processor-wake names EQUAL their contract slug, so it is also the
413
- * registered processor name (and, under facet placement, the facet name):
414
- * hosts route on this one identity, and a name matching no registered
415
- * processor fails loudly here with the registry's unknown-name error.
416
- */
417
- name: SubscriptionName;
418
- };
419
- /**
420
- * What the woken processor hands back in one response. The stream retains
421
- * `processEventBatch` (ownership of a returned stub transfers to
422
- * the caller) and streams one-way batches into it from `checkpointOffset + 1`;
423
- * there is no callback registration call in the other direction.
424
- */
425
- export type StreamProcessorWakeResponse = {
426
- /** Stream identity to which `checkpointOffset` and the returned callback are bound. */
427
- streamId: string;
428
- /** The processor's durable checkpoint offset — replay resumes after it. */
429
- checkpointOffset: number;
430
- /**
431
- * The live delivery callback the stream retains and invokes per batch.
432
- * Calls are one-way; each batch reports completion through its independent
433
- * `reportDeliveryResult` callback.
434
- */
435
- processEventBatch: ProcessStreamWakeEventBatch;
436
- /**
437
- * Serializable callback-owner identity (validated against
438
- * `ConnectionOpenerDescriptor` by the stream) appended as the
439
- * connection-opened presence fact; carries the processor's contract
440
- * announcement for the stream's `processorsBySlug` registry.
441
- */
442
- openedBy?: unknown;
443
- /** Live runtime-state capability, retained for the connection lifetime. */
444
- getRuntimeState?: GetProcessorRuntimeState;
445
- /** Optional ping capability, retained for the connection lifetime (see {@link StreamConnectionPing}). */
446
- ping?: StreamConnectionPing;
447
- };
448
- /**
449
- * The mutual ping's request half (NTP-style, for real latency measurement
450
- * between a stream and its callback owners): the requester stamps `t0` on its own
451
- * clock and observes `t3` when the reply lands.
452
- */
453
- export type StreamPingInput = {
454
- t0: number;
455
- };
456
- /**
457
- * The mutual ping's reply half: the responder echoes `t0` and reports when it
458
- * received the request (`t1`) and sent the reply (`t2`) on ITS clock.
459
- * `rtt = (t3 - t0) - (t2 - t1)` excludes responder processing time, and
460
- * `((t1 - t0) + (t2 - t3)) / 2` estimates the responder−requester clock
461
- * offset (see stream-runtime-metrics.pingRoundTrip). Purely observational:
462
- * ping failures drop the sample and never affect delivery or liveness.
463
- */
464
- export type StreamPingReply = {
465
- t0: number;
466
- t1: number;
467
- t2: number;
468
- };
469
- /**
470
- * Optional ping capability a connection owner hands the stream (session
471
- * `openConnection()` argument or processor wake-response field).
472
- */
473
- export type StreamConnectionPing = (input: StreamPingInput) => StreamPingReply | Promise<StreamPingReply>;
474
- /** Serializable snapshot plus optional live runtime debug state for a processor. */
475
- export type ProcessorRuntimeState<State = unknown> = {
476
- snapshot: {
477
- offset: number;
478
- state: State;
479
- };
480
- runtime?: Record<string, unknown>;
481
- };
482
- /**
483
- * Optional runtime-state callback exposed by a hosted processor.
484
- *
485
- * It accepts sync or async implementations because local processors can return
486
- * immediately, while RPC-backed processors may need an async round trip.
487
- */
488
- export type GetProcessorRuntimeState = () => ProcessorRuntimeState | Promise<ProcessorRuntimeState>;
489
- /**
490
- * Live handle returned by `Stream.openConnection`.
491
- *
492
- * `ping()` reports liveness: `true` while
493
- * the connection is still open on the live stream, `false` after it closed
494
- * (replaced, delivery failure, or explicit close); it rejects when the stream's
495
- * Durable Object incarnation is gone. Either non-`true` outcome means the
496
- * owner should open another connection.
497
- *
498
- * CAUTION ON THE DATA PROPERTIES BELOW. A handle obtained across the worker
499
- * relay was measured NOT to materialize `streamMaxOffset` as a number — it is
500
- * present inside the Stream DO and can arrive undefined to a remote consumer.
501
- * Prefer the delivery batches for offsets: every connection receives an initial
502
- * (possibly empty) batch immediately on open, carrying `streamMaxOffset` and
503
- * `scannedThroughOffset`, and those are the values to seed a resume cursor
504
- * from. A consumer that advances its cursor from the handle can silently
505
- * resume at zero.
506
- */
507
- export type StreamConnectionHandle = Disposable & {
508
- /** Stable identity of this live connection. */
509
- connectionKey: ConnectionKey;
510
- /** The stream's max offset when the connection opened. See the caution above. */
511
- streamMaxOffset: number;
512
- ping(): boolean | Promise<boolean>;
513
- /** Close this connection; safe to call more than once. */
514
- close(): void;
515
- };
@@ -1,102 +0,0 @@
1
- import { z } from "zod";
2
- /**
3
- * Maximum number of stream-to-stream copies retained in one event's provenance.
4
- * Cycles normally stop a chain earlier; this bounds acyclic graphs and the
5
- * serialized event growth they can produce.
6
- */
7
- export declare const MAX_COPIED_FROM_HOPS = 32;
8
- /** Append input before the stream assigns offset and timestamp. */
9
- export declare const StreamEventInput: z.ZodObject<{
10
- type: z.ZodString;
11
- payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
12
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
13
- source: z.ZodOptional<z.ZodObject<{
14
- processor: z.ZodOptional<z.ZodObject<{
15
- slug: z.ZodString;
16
- version: z.ZodString;
17
- stream: z.ZodObject<{
18
- path: z.ZodString;
19
- projectId: z.ZodNullable<z.ZodString>;
20
- streamId: z.ZodUUID;
21
- }, z.core.$strict>;
22
- whileProcessing: z.ZodOptional<z.ZodObject<{
23
- offset: z.ZodNumber;
24
- type: z.ZodString;
25
- }, z.core.$strict>>;
26
- }, z.core.$strict>>;
27
- copiedFrom: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
- name: z.ZodString;
29
- streamId: z.ZodUUID;
30
- streamCreatedAt: z.ZodString;
31
- cursorChangedAtSourceOffset: z.ZodNumber;
32
- createdAt: z.ZodString;
33
- offset: z.ZodNumber;
34
- path: z.ZodString;
35
- projectId: z.ZodNullable<z.ZodString>;
36
- type: z.ZodString;
37
- }, z.core.$strict>>>;
38
- }, z.core.$strict>>;
39
- idempotencyKey: z.ZodOptional<z.ZodString>;
40
- ephemeral: z.ZodOptional<z.ZodLiteral<true>>;
41
- }, z.core.$strict>;
42
- /** Offset-assigned stream event after commit. */
43
- export declare const StreamEvent: z.ZodObject<{
44
- type: z.ZodString;
45
- payload: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
46
- metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
47
- source: z.ZodOptional<z.ZodObject<{
48
- processor: z.ZodOptional<z.ZodObject<{
49
- slug: z.ZodString;
50
- version: z.ZodString;
51
- stream: z.ZodObject<{
52
- path: z.ZodString;
53
- projectId: z.ZodNullable<z.ZodString>;
54
- streamId: z.ZodUUID;
55
- }, z.core.$strict>;
56
- whileProcessing: z.ZodOptional<z.ZodObject<{
57
- offset: z.ZodNumber;
58
- type: z.ZodString;
59
- }, z.core.$strict>>;
60
- }, z.core.$strict>>;
61
- copiedFrom: z.ZodOptional<z.ZodArray<z.ZodObject<{
62
- name: z.ZodString;
63
- streamId: z.ZodUUID;
64
- streamCreatedAt: z.ZodString;
65
- cursorChangedAtSourceOffset: z.ZodNumber;
66
- createdAt: z.ZodString;
67
- offset: z.ZodNumber;
68
- path: z.ZodString;
69
- projectId: z.ZodNullable<z.ZodString>;
70
- type: z.ZodString;
71
- }, z.core.$strict>>>;
72
- }, z.core.$strict>>;
73
- idempotencyKey: z.ZodOptional<z.ZodString>;
74
- ephemeral: z.ZodOptional<z.ZodLiteral<true>>;
75
- offset: z.ZodNumber;
76
- createdAt: z.ZodString;
77
- path: z.ZodString;
78
- }, z.core.$strict>;
79
- /**
80
- * One known stream in a project's reduced state — what the project processor
81
- * records per agent/repo/secret/stream and what the collection `list()`
82
- * methods return.
83
- */
84
- export declare const StreamListItem: z.ZodObject<{
85
- createdAt: z.ZodString;
86
- path: z.ZodString;
87
- }, z.core.$strip>;
88
- /** Append input for `Stream.append`: event type, JSON payload, optional
89
- * metadata, provenance source, and idempotency key — everything before the
90
- * stream assigns offset and timestamp at commit. `ephemeral: true` assigns a
91
- * real offset but keeps the event body only in the Stream Durable Object's
92
- * bounded memory until eviction or restart; it cannot be combined with an
93
- * idempotency key. */
94
- export type StreamEventInput = z.infer<typeof StreamEventInput>;
95
- /** One offset-assigned stream event: type, JSON payload, offset, provenance
96
- * (processor stamp / source-stream chain), plus the commit-time `createdAt`
97
- * and stream `path`. Durable events may have an idempotency key;
98
- * `ephemeral: true` marks a memory-only event (see `StreamEventInput`). */
99
- export type StreamEvent = z.infer<typeof StreamEvent>;
100
- /** One known stream in a project's reduced state — the entry shape the
101
- * collection `list()` methods return: stream path plus creation time. */
102
- export type StreamListItem = z.infer<typeof StreamListItem>;
@@ -1,45 +0,0 @@
1
- import type { StreamEvent, StreamEventInput } from "./schemas.ts";
2
- import type { StreamEventPage, StreamEventReadInput } from "./rpc-types.ts";
3
- /**
4
- * Resolve the path accepted by `stream.at(path)`. Absolute paths start at the
5
- * stream root; relative paths start at `basePath`; `..` may climb only as far
6
- * as the root. Keeping this next to {@link ProcessorStream} lets processor
7
- * appends decide whether a resolved destination is their own stream without
8
- * relying on RPC-target object identity.
9
- */
10
- export declare function resolveStreamPath(basePath: string, streamPath: string): string;
11
- /** One open journal read — page with `next()`, dispose when done
12
- * (`using pager = stream.readEvents(...)`). */
13
- export interface ProcessorStreamPager {
14
- /** Returns [] when no newer matching page is currently available. */
15
- next(): Promise<StreamEvent[]>;
16
- [Symbol.dispose](): void;
17
- }
18
- /** The stream capabilities a processor host must supply — see module doc. */
19
- export interface ProcessorStream {
20
- append(...events: StreamEventInput[]): Promise<StreamEvent[]>;
21
- /**
22
- * Append only if this path still names the observed stream lifetime. The
23
- * identity check and append happen in one stream turn, so a delete/recreate
24
- * cannot slip between them.
25
- */
26
- appendIfStreamId(args: {
27
- streamId: string;
28
- events: StreamEventInput[];
29
- }): Promise<StreamEvent[]>;
30
- /**
31
- * Read events together with the stream lifetime that owns their offsets.
32
- * Processor cursors must never consume a bare event array.
33
- */
34
- getEventPage(args?: StreamEventReadInput): Promise<StreamEventPage>;
35
- readEvents(args?: StreamEventReadInput): ProcessorStreamPager;
36
- getEvent(args: {
37
- offset: number;
38
- idempotencyKey?: never;
39
- } | {
40
- idempotencyKey: string;
41
- offset?: never;
42
- }): Promise<StreamEvent | undefined>;
43
- getEvents(args?: StreamEventReadInput): Promise<StreamEvent[]>;
44
- at(path: string): ProcessorStream;
45
- }