@abloatai/ablo 0.24.0 → 0.26.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 (246) hide show
  1. package/AGENTS.md +5 -3
  2. package/CHANGELOG.md +33 -0
  3. package/README.md +45 -36
  4. package/dist/BaseSyncedStore.d.ts +72 -195
  5. package/dist/BaseSyncedStore.js +240 -625
  6. package/dist/Database.d.ts +8 -9
  7. package/dist/Database.js +9 -14
  8. package/dist/LazyReferenceCollection.js +5 -0
  9. package/dist/Model.js +6 -8
  10. package/dist/ModelRegistry.d.ts +25 -6
  11. package/dist/ModelRegistry.js +12 -6
  12. package/dist/NetworkMonitor.js +1 -1
  13. package/dist/ObjectPool.js +9 -3
  14. package/dist/SyncClient.d.ts +15 -5
  15. package/dist/SyncClient.js +152 -66
  16. package/dist/SyncEngineContext.d.ts +1 -3
  17. package/dist/SyncEngineContext.js +1 -2
  18. package/dist/agent/Agent.d.ts +21 -8
  19. package/dist/agent/Agent.js +26 -13
  20. package/dist/ai-sdk/coordination-context.js +9 -3
  21. package/dist/ai-sdk/wrap.d.ts +1 -1
  22. package/dist/ai-sdk/wrap.js +1 -1
  23. package/dist/auth/credentialPolicy.d.ts +10 -2
  24. package/dist/auth/credentialSource.d.ts +1 -13
  25. package/dist/auth/credentialSource.js +6 -13
  26. package/dist/auth/index.js +3 -3
  27. package/dist/cli.cjs +583 -287
  28. package/dist/client/Ablo.d.ts +35 -764
  29. package/dist/client/Ablo.js +64 -688
  30. package/dist/client/ApiClient.d.ts +14 -1
  31. package/dist/client/ApiClient.js +63 -9
  32. package/dist/client/auth.d.ts +8 -17
  33. package/dist/client/auth.js +42 -6
  34. package/dist/client/consoleLogger.d.ts +36 -0
  35. package/dist/client/consoleLogger.js +45 -0
  36. package/dist/client/createInternalComponents.js +1 -1
  37. package/dist/client/createModelProxy.js +10 -6
  38. package/dist/client/credentialEndpoint.d.ts +63 -0
  39. package/dist/client/credentialEndpoint.js +87 -0
  40. package/dist/client/hostedEndpoints.d.ts +24 -0
  41. package/dist/client/hostedEndpoints.js +24 -0
  42. package/dist/client/httpClient.d.ts +1 -1
  43. package/dist/client/identity.js +2 -1
  44. package/dist/client/modelRegistration.d.ts +14 -0
  45. package/dist/client/modelRegistration.js +321 -0
  46. package/dist/client/options.d.ts +396 -0
  47. package/dist/client/options.js +10 -0
  48. package/dist/client/resourceTypes.d.ts +344 -0
  49. package/dist/client/resourceTypes.js +13 -0
  50. package/dist/client/schemaConfig.d.ts +56 -0
  51. package/dist/client/schemaConfig.js +188 -0
  52. package/dist/client/sessionMint.d.ts +1 -1
  53. package/dist/client/validateAbloOptions.js +1 -1
  54. package/dist/client/wsMutationExecutor.d.ts +33 -0
  55. package/dist/client/wsMutationExecutor.js +77 -0
  56. package/dist/context.js +0 -3
  57. package/dist/coordination/index.d.ts +8 -1
  58. package/dist/coordination/index.js +24 -1
  59. package/dist/coordination/trace.d.ts +0 -1
  60. package/dist/coordination/trace.js +0 -1
  61. package/dist/core/DatabaseManager.d.ts +0 -1
  62. package/dist/core/DatabaseManager.js +26 -24
  63. package/dist/core/QueryProcessor.js +7 -8
  64. package/dist/core/QueryView.d.ts +14 -2
  65. package/dist/core/QueryView.js +4 -5
  66. package/dist/core/StoreManager.d.ts +2 -2
  67. package/dist/core/StoreManager.js +5 -1
  68. package/dist/core/index.d.ts +1 -1
  69. package/dist/core/openIDBWithTimeout.js +15 -11
  70. package/dist/core/query-utils.js +1 -1
  71. package/dist/core/storeContract.d.ts +143 -0
  72. package/dist/core/storeContract.js +16 -0
  73. package/dist/errorCodes.d.ts +11 -2
  74. package/dist/errorCodes.js +155 -137
  75. package/dist/errors.d.ts +18 -7
  76. package/dist/errors.js +14 -1
  77. package/dist/index.js +5 -0
  78. package/dist/interfaces/index.d.ts +6 -20
  79. package/dist/keys/index.js +18 -9
  80. package/dist/mutators/UndoManager.js +6 -1
  81. package/dist/mutators/defineMutators.d.ts +1 -3
  82. package/dist/policy/types.d.ts +1 -1
  83. package/dist/query/client.d.ts +11 -0
  84. package/dist/query/client.js +81 -52
  85. package/dist/react/AbloProvider.d.ts +6 -10
  86. package/dist/react/AbloProvider.js +22 -15
  87. package/dist/react/context.d.ts +2 -118
  88. package/dist/react/useAblo.js +1 -1
  89. package/dist/react/useErrorListener.js +1 -1
  90. package/dist/react/useMutationFailureListener.js +1 -1
  91. package/dist/react/useMutators.js +7 -1
  92. package/dist/react/useReactive.js +0 -1
  93. package/dist/react/useUndoScope.js +2 -2
  94. package/dist/schema/ddlLock.d.ts +39 -0
  95. package/dist/schema/ddlLock.js +51 -0
  96. package/dist/schema/field.js +1 -1
  97. package/dist/schema/index.d.ts +4 -3
  98. package/dist/schema/index.js +15 -5
  99. package/dist/schema/model.d.ts +3 -3
  100. package/dist/schema/model.js +2 -2
  101. package/dist/schema/openapi.js +5 -1
  102. package/dist/schema/queries.d.ts +1 -1
  103. package/dist/schema/queries.js +1 -0
  104. package/dist/schema/residency.d.ts +35 -0
  105. package/dist/schema/residency.js +27 -0
  106. package/dist/schema/roles.d.ts +25 -0
  107. package/dist/schema/roles.js +37 -0
  108. package/dist/schema/schema.d.ts +3 -3
  109. package/dist/schema/schema.js +11 -7
  110. package/dist/schema/serialize.d.ts +8 -8
  111. package/dist/schema/sync-delta-row.d.ts +2 -2
  112. package/dist/schema/sync-delta-row.js +2 -2
  113. package/dist/server/storage-mode.d.ts +8 -1
  114. package/dist/server/storage-mode.js +14 -4
  115. package/dist/source/adapter.d.ts +1 -1
  116. package/dist/source/adapters/drizzle.js +4 -3
  117. package/dist/source/adapters/kysely.js +4 -3
  118. package/dist/source/adapters/memory.js +1 -1
  119. package/dist/source/adapters/prisma.js +5 -4
  120. package/dist/source/conformance.js +10 -8
  121. package/dist/source/connector.js +4 -2
  122. package/dist/source/factory.d.ts +106 -0
  123. package/dist/source/factory.js +273 -0
  124. package/dist/source/index.d.ts +11 -461
  125. package/dist/source/index.js +14 -416
  126. package/dist/source/next.d.ts +1 -1
  127. package/dist/source/next.js +1 -1
  128. package/dist/source/pushQueue.d.ts +1 -1
  129. package/dist/source/pushQueue.js +6 -3
  130. package/dist/source/signing.d.ts +59 -0
  131. package/dist/source/signing.js +142 -0
  132. package/dist/source/types.d.ts +334 -0
  133. package/dist/source/types.js +44 -0
  134. package/dist/stores/ObjectStore.d.ts +1 -1
  135. package/dist/stores/ObjectStore.js +23 -23
  136. package/dist/stores/SyncActionStore.d.ts +1 -1
  137. package/dist/stores/SyncActionStore.js +70 -35
  138. package/dist/surface.d.ts +1 -1
  139. package/dist/surface.js +1 -0
  140. package/dist/sync/AreaOfInterestManager.d.ts +2 -2
  141. package/dist/sync/AreaOfInterestManager.js +1 -1
  142. package/dist/sync/BootstrapHelper.d.ts +1 -3
  143. package/dist/sync/BootstrapHelper.js +29 -8
  144. package/dist/sync/ConnectionManager.d.ts +8 -0
  145. package/dist/sync/ConnectionManager.js +19 -4
  146. package/dist/sync/HydrationCoordinator.d.ts +12 -0
  147. package/dist/sync/HydrationCoordinator.js +25 -5
  148. package/dist/sync/NetworkProbe.d.ts +3 -2
  149. package/dist/sync/NetworkProbe.js +7 -6
  150. package/dist/sync/SyncWebSocket.d.ts +71 -120
  151. package/dist/sync/SyncWebSocket.js +324 -630
  152. package/dist/sync/awaitClaimGrant.js +27 -19
  153. package/dist/sync/bootstrapApply.d.ts +60 -0
  154. package/dist/sync/bootstrapApply.js +65 -0
  155. package/dist/sync/commitFrames.d.ts +43 -0
  156. package/dist/sync/commitFrames.js +94 -0
  157. package/dist/sync/createClaimStream.js +3 -2
  158. package/dist/sync/createSnapshot.d.ts +1 -3
  159. package/dist/sync/credentialLifecycle.d.ts +175 -0
  160. package/dist/sync/credentialLifecycle.js +329 -0
  161. package/dist/sync/deltaPipeline.d.ts +111 -0
  162. package/dist/sync/deltaPipeline.js +262 -0
  163. package/dist/sync/groupChange.d.ts +111 -0
  164. package/dist/sync/groupChange.js +246 -0
  165. package/dist/sync/heartbeat.d.ts +62 -0
  166. package/dist/sync/heartbeat.js +91 -0
  167. package/dist/sync/participants.d.ts +8 -8
  168. package/dist/sync/syncCursor.d.ts +44 -0
  169. package/dist/sync/syncCursor.js +59 -0
  170. package/dist/sync/syncPlan.d.ts +62 -0
  171. package/dist/sync/syncPlan.js +51 -0
  172. package/dist/sync/wsFrameHandlers.d.ts +117 -0
  173. package/dist/sync/wsFrameHandlers.js +378 -0
  174. package/dist/testing/fixtures/bootstrap.d.ts +9 -11
  175. package/dist/testing/fixtures/deltas.d.ts +1 -1
  176. package/dist/testing/fixtures/models.js +1 -0
  177. package/dist/testing/helpers/sync-engine-harness.d.ts +0 -3
  178. package/dist/testing/helpers/sync-engine-harness.js +2 -1
  179. package/dist/testing/index.d.ts +1 -1
  180. package/dist/testing/index.js +1 -1
  181. package/dist/testing/mocks/MockSyncContext.d.ts +1 -17
  182. package/dist/testing/mocks/MockSyncContext.js +1 -32
  183. package/dist/testing/mocks/MockSyncStore.d.ts +4 -4
  184. package/dist/testing/mocks/MockWebSocket.d.ts +2 -2
  185. package/dist/transactions/TransactionQueue.d.ts +20 -56
  186. package/dist/transactions/TransactionQueue.js +101 -487
  187. package/dist/transactions/TransactionStore.d.ts +18 -0
  188. package/dist/transactions/TransactionStore.js +51 -0
  189. package/dist/transactions/coalesceRules.d.ts +34 -0
  190. package/dist/transactions/coalesceRules.js +117 -0
  191. package/dist/transactions/commitPayload.d.ts +134 -0
  192. package/dist/transactions/commitPayload.js +152 -0
  193. package/dist/transactions/deltaConfirmation.d.ts +60 -0
  194. package/dist/transactions/deltaConfirmation.js +223 -0
  195. package/dist/transactions/optimistic.d.ts +24 -0
  196. package/dist/transactions/optimistic.js +45 -0
  197. package/dist/transactions/persistedReplay.d.ts +93 -0
  198. package/dist/transactions/persistedReplay.js +105 -0
  199. package/dist/types/index.d.ts +3 -3
  200. package/dist/types/index.js +0 -5
  201. package/dist/types/modelData.d.ts +12 -0
  202. package/dist/types/modelData.js +11 -0
  203. package/dist/types/participant.d.ts +21 -0
  204. package/dist/types/participant.js +12 -0
  205. package/dist/types/streams.d.ts +8 -14
  206. package/dist/utils/mobx-setup.d.ts +1 -1
  207. package/dist/utils/mobx-setup.js +2 -2
  208. package/dist/wire/errorEnvelope.d.ts +11 -2
  209. package/dist/wire/errorEnvelope.js +14 -2
  210. package/dist/wire/frames.d.ts +90 -0
  211. package/dist/wire/frames.js +55 -1
  212. package/dist/wire/index.d.ts +4 -1
  213. package/dist/wire/index.js +20 -1
  214. package/dist/wire/protocol.d.ts +45 -0
  215. package/dist/wire/protocol.js +45 -0
  216. package/dist/wire/protocolVersion.d.ts +56 -0
  217. package/dist/wire/protocolVersion.js +63 -0
  218. package/docs/api-keys.md +4 -3
  219. package/docs/data-sources.md +12 -5
  220. package/docs/examples/existing-python-backend.md +3 -3
  221. package/docs/identity.md +4 -4
  222. package/docs/integration-guide.md +1 -1
  223. package/docs/react.md +1 -1
  224. package/docs/sessions.md +5 -7
  225. package/llms.txt +4 -2
  226. package/package.json +15 -13
  227. package/dist/client/index.d.ts +0 -36
  228. package/dist/client/index.js +0 -33
  229. package/dist/config/index.d.ts +0 -10
  230. package/dist/config/index.js +0 -12
  231. package/dist/interfaces/headless.d.ts +0 -95
  232. package/dist/interfaces/headless.js +0 -41
  233. package/dist/query/index.d.ts +0 -6
  234. package/dist/query/index.js +0 -5
  235. package/dist/realtime/index.d.ts +0 -10
  236. package/dist/realtime/index.js +0 -9
  237. package/dist/schema/plane.d.ts +0 -23
  238. package/dist/schema/plane.js +0 -19
  239. package/dist/server/next.d.ts +0 -51
  240. package/dist/server/next.js +0 -47
  241. package/dist/sync/OfflineFlush.d.ts +0 -9
  242. package/dist/sync/OfflineFlush.js +0 -22
  243. package/dist/sync/OfflineTransactionStore.d.ts +0 -37
  244. package/dist/sync/OfflineTransactionStore.js +0 -263
  245. package/dist/transactions/index.d.ts +0 -16
  246. package/dist/transactions/index.js +0 -7
@@ -0,0 +1,396 @@
1
+ /**
2
+ * Option types for the `Ablo({...})` factory — the public `AbloOptions` bag
3
+ * and the full internal construction surface (`InternalAbloOptions`).
4
+ *
5
+ * Extracted from `Ablo.ts` so the option types can be referenced without
6
+ * pulling in the factory's runtime graph. This module is type-only — ZERO
7
+ * runtime imports — so importing it can never create a cycle. `Ablo.ts`
8
+ * re-exports everything here, so existing import paths keep resolving.
9
+ */
10
+ import type { Schema, SchemaRecord } from '../schema/schema.js';
11
+ import type { SyncEngineConfig, SyncLogger, MutationExecutor, SyncObservabilityProvider, SyncAnalytics, SessionErrorDetector, OnlineStatusProvider } from '../interfaces/index.js';
12
+ import type { AbloPersistence } from './persistence.js';
13
+ /**
14
+ * Async function that resolves an apiKey at request time. Use for
15
+ * credential rotation — rotate from a vault, refresh from session
16
+ * storage, or pull from a Better Auth session. Mirrors Anthropic's
17
+ * `ApiKeySetter` exactly so any rotation pattern that works with
18
+ * `@anthropic-ai/sdk` works here.
19
+ *
20
+ * Re-exported from `./auth` so existing import paths (`@abloatai/ablo`)
21
+ * keep resolving; the canonical definition lives there alongside the
22
+ * resolvers that consume it.
23
+ */
24
+ export type { ApiKeySetter } from './auth.js';
25
+ import type { ApiKeySetter } from './auth.js';
26
+ /**
27
+ * Options for `Ablo({...})`.
28
+ *
29
+ * The only required field is `schema`. The default path is one line:
30
+ *
31
+ * ```ts
32
+ * const ablo = Ablo({ schema, apiKey: process.env.ABLO_API_KEY });
33
+ * ```
34
+ *
35
+ * `apiKey` itself defaults to `process.env.ABLO_API_KEY`, so in most
36
+ * server setups `Ablo({ schema })` is enough. Every other field is
37
+ * optional tuning (timeouts, retries, custom fetch, persistence) —
38
+ * if you're not sure whether you need one, you don't. Reach for them
39
+ * the way you'd reach for the equivalent option on the Stripe / OpenAI
40
+ * / Anthropic clients: rarely, and deliberately.
41
+ *
42
+ * @see https://docs.abloatai.com — full option reference
43
+ */
44
+ export interface AbloOptions<S extends SchemaRecord = SchemaRecord> {
45
+ /**
46
+ * TypeScript schema defined with `defineSchema()`. Required — it's what
47
+ * makes `ablo.weatherReports.update(...)` typed. This is the one field you must
48
+ * pass; start here.
49
+ */
50
+ schema: Schema<S>;
51
+ /**
52
+ * API key — **the one auth field most apps set.** Three shapes, one option:
53
+ *
54
+ * - **A key string** (server): your secret `sk_` — defaults to
55
+ * `process.env['ABLO_API_KEY']`, so you usually pass nothing. A
56
+ * long-lived key needs no refresh; the client uses it as-is.
57
+ *
58
+ * - **An endpoint path/URL** — `apiKey: '/api/ablo-session'` (the route
59
+ * `ablo init` scaffolds). The SDK owns the whole exchange: it POSTs the
60
+ * endpoint (same-origin, cookies included), reads the minted short-lived
61
+ * token, and keeps it fresh — a refresh timer ahead of expiry plus
62
+ * re-mint on OS-wake and a reactive re-mint when the server reports the
63
+ * key stale. You never call a refresh method (the Ably `authUrl` /
64
+ * Liveblocks `authEndpoint` model). Detection is by prefix (`/`,
65
+ * `http://`, `https://`) — key strings are `sk_`/`ek_`/`rk_`-prefixed so
66
+ * the shapes can't collide. Long-lived server clients should pass the
67
+ * ABSOLUTE URL: it enables pre-expiry renewal on windowless hosts too.
68
+ *
69
+ * - **An async resolver** `() => Promise<string | null>` — the escape
70
+ * hatch when the exchange needs custom headers, a body, or a non-HTTP
71
+ * mint (vault rotation, AWS STS, a Better Auth session). Same renewal
72
+ * machinery as the endpoint form.
73
+ *
74
+ * Endpoint/resolver contract: produce a token; produce `null` when the login
75
+ * itself is gone (terminal → the client signs out / fails `ready()` with
76
+ * `session_expired`); or THROW on a transient failure (→ back off and retry,
77
+ * never sign out). The endpoint form maps HTTP onto this for you: 401/403 →
78
+ * signed out, any other failure → transient.
79
+ */
80
+ apiKey?: string | ApiKeySetter | null | undefined;
81
+ /**
82
+ * Session-mint endpoint — **the browser auth field**, and the named twin of
83
+ * `apiKey`'s endpoint-string shape (Liveblocks `authEndpoint` / Ably
84
+ * `authUrl`). Point it at the route that mints the signed-in user's
85
+ * short-lived token (`ablo init` scaffolds `/api/ablo-session`):
86
+ *
87
+ * ```ts
88
+ * const ablo = Ablo({ schema, authEndpoint: '/api/ablo-session' });
89
+ * ```
90
+ *
91
+ * The SDK owns the whole exchange — POSTs the route (same-origin, cookies
92
+ * included), reads `{ token }`, keeps it fresh ahead of expiry, re-mints
93
+ * when the server reports it stale. 401/403 from the route = signed out;
94
+ * any other failure is retried, never a sign-out. Also accepts an async
95
+ * resolver `() => Promise<string | null>` when the exchange needs custom
96
+ * headers or a body (same contract as the `apiKey` resolver form).
97
+ *
98
+ * Mutually exclusive with `apiKey` — servers hold a key, browsers hold a
99
+ * mint route; passing both is a validation error.
100
+ */
101
+ authEndpoint?: string | ApiKeySetter | null | undefined;
102
+ /**
103
+ * @deprecated The direct connector lets Ablo dial INTO your Postgres and write to
104
+ * it — the operate-their-database posture we are moving off. Ablo is Stripe-shaped:
105
+ * it hosts only the transaction log (the ordered sync_deltas) + coordination, never
106
+ * your data; your rows always live in your own database. Use the signed Data Source
107
+ * endpoint instead — keep `DATABASE_URL` in your app, expose `dataSource(...)`, and
108
+ * let your server own the write while Ablo coordinates the sync stream. To keep the
109
+ * log in your infra too, self-host the engine. See
110
+ * docs/plans/stripe-shaped-storage-posture.md.
111
+ *
112
+ * Still honored at runtime for back-compat. SERVER-ONLY: it carries credentials, so
113
+ * it is never sent from the browser — constructing a client with `databaseUrl` and
114
+ * `dangerouslyAllowBrowser` throws. If you use it, provide a NON-superuser,
115
+ * non-`BYPASSRLS` role; the connector rejects privileged roles that cannot enforce RLS.
116
+ */
117
+ databaseUrl?: string | null | undefined;
118
+ /**
119
+ * Local persistence mode. Pass `indexeddb` only when you want offline
120
+ * queueing and a reload-surviving browser cache.
121
+ *
122
+ * @default 'memory'
123
+ */
124
+ persistence?: AbloPersistence;
125
+ /**
126
+ * Transport selector. `'websocket'` (default) is the live client —
127
+ * persistent socket, local synced pool, `onChange` subscriptions. `'http'`
128
+ * returns the STATELESS client for server-side actors (agents, workers,
129
+ * serverless): same `ablo.<model>` surface and coordination plane, but each
130
+ * call is one HTTP round-trip, identity rides the Bearer credential, and no
131
+ * socket is ever opened. With `'http'` the return type narrows to
132
+ * `AbloHttpClient<S>`, so stateful-only capabilities (`get`/`getAll`,
133
+ * `onChange`) are compile errors rather than latent runtime gaps.
134
+ *
135
+ * Note: session/credential minting (`sessions.create`) currently runs on the
136
+ * stateful (default) client, not the http client.
137
+ *
138
+ * @default 'websocket'
139
+ */
140
+ transport?: 'websocket' | 'http' | undefined;
141
+ /**
142
+ * Turn Ablo's diagnostic logging on/off. `true` surfaces the `[Ablo]`
143
+ * coordination trace — claims requested / queued / granted / released, agent
144
+ * handovers, connection state — so you can SEE the human+agent coordination
145
+ * you built while debugging. Omitted/`false` keeps the quiet default (only
146
+ * warnings + errors). For a middle ground use {@link logLevel}. Env override:
147
+ * `ABLO_LOG_LEVEL`. Ignored if a custom logger is supplied.
148
+ */
149
+ debug?: boolean | undefined;
150
+ /**
151
+ * Log threshold for the default `[Ablo]` logger (takes precedence over
152
+ * {@link debug}). `'info'` = coordination + connection events without the
153
+ * per-model registration firehose; `'debug'` = everything; `'warn'` (default)
154
+ * = warnings + errors only; `'silent'` = nothing. Env override: `ABLO_LOG_LEVEL`.
155
+ */
156
+ logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent' | undefined;
157
+ /**
158
+ * Bearer auth token. Hosted-cloud consumers pass `apiKey`; self-hosted
159
+ * deployments may pass a bearer token minted by their own auth layer.
160
+ */
161
+ authToken?: string | null | undefined;
162
+ /**
163
+ * Override the Ablo API base URL. Defaults to hosted production.
164
+ */
165
+ baseURL?: string | null | undefined;
166
+ /** Custom fetch implementation for tests, proxies, or non-standard runtimes. */
167
+ fetch?: typeof fetch | undefined;
168
+ /** Default headers sent with every API request. */
169
+ defaultHeaders?: Record<string, string | null | undefined> | undefined;
170
+ /** Default query parameters sent with every API request. */
171
+ defaultQuery?: Record<string, string | undefined> | undefined;
172
+ /**
173
+ * Client-side use is disabled by default because private API keys should
174
+ * not ship to browsers. Set this only when the browser holds a minted
175
+ * session token (`ek_`/`rk_`) or you route through a controlled server proxy.
176
+ */
177
+ dangerouslyAllowBrowser?: boolean | undefined;
178
+ }
179
+ export interface InternalAbloOptions<S extends SchemaRecord = SchemaRecord> {
180
+ /**
181
+ * API key used for authentication.
182
+ *
183
+ * Accepts a static string (`sk_live_...`) or an async function that
184
+ * resolves to one. Defaults to `process.env['ABLO_API_KEY']`.
185
+ *
186
+ * When a function is provided, it's invoked before each request so
187
+ * you can rotate or refresh credentials at runtime. The function
188
+ * must return a non-empty string; otherwise an `AbloAuthenticationError`
189
+ * is thrown. If the function throws, the error is wrapped with the
190
+ * original available as `cause`.
191
+ *
192
+ * Mirrors Anthropic / OpenAI / Stripe SDK shape exactly.
193
+ */
194
+ apiKey?: string | ApiKeySetter | null | undefined;
195
+ /**
196
+ * Session-mint endpoint (string or async resolver) — see
197
+ * {@link AbloOptions.authEndpoint}. Mutually exclusive with `apiKey`.
198
+ */
199
+ authEndpoint?: string | ApiKeySetter | null | undefined;
200
+ /**
201
+ * Bearer auth token. Sent as `Authorization: Bearer <token>` on
202
+ * every request.
203
+ *
204
+ * Use this for self-hosted deployments where your auth layer mints
205
+ * cap tokens directly. Hosted-cloud consumers pass `apiKey` instead;
206
+ * the server handles cap-mint internally.
207
+ */
208
+ authToken?: string | null | undefined;
209
+ /**
210
+ * Override the default base URL. Defaults to
211
+ * `wss://api.abloatai.com` for hosted production; pass an explicit
212
+ * URL for self-hosted or private deployments.
213
+ */
214
+ baseURL?: string | null | undefined;
215
+ /**
216
+ * Custom `fetch` implementation. Defaults to `globalThis.fetch`.
217
+ * Override for testing, custom transports, or runtime shims.
218
+ */
219
+ fetch?: typeof fetch | undefined;
220
+ /**
221
+ * Default headers to include with every request to the API.
222
+ * Removed per-request by setting the header to `null` in request
223
+ * options.
224
+ */
225
+ defaultHeaders?: Record<string, string | null | undefined> | undefined;
226
+ /**
227
+ * Default query parameters to include with every request.
228
+ * Removed per-request by setting the param to `undefined`.
229
+ */
230
+ defaultQuery?: Record<string, string | undefined> | undefined;
231
+ /**
232
+ * Client-side use of this SDK is disabled by default — your apiKey
233
+ * would ship to every visitor's network tab. Only set this to
234
+ * `true` if you've understood the risk and have appropriate
235
+ * mitigations (a minted session token, a server-side proxy, etc).
236
+ */
237
+ dangerouslyAllowBrowser?: boolean | undefined;
238
+ /**
239
+ * TypeScript schema defined with `defineSchema()`.
240
+ *
241
+ * The root `Ablo(...)` client is schema-first so consumers get typed
242
+ * model clients such as `ablo.weatherReports.update(...)`. Omit `schema`
243
+ * only for the advanced Model / Claim / Commit client.
244
+ */
245
+ schema: Schema<S>;
246
+ /**
247
+ * @deprecated Server derives participant kind from the apiKey's
248
+ * scope. Pass apiKey only; this option will be removed once the
249
+ * server-internal cap-mint flow lands.
250
+ */
251
+ kind?: 'user' | 'agent' | 'system';
252
+ /**
253
+ * @deprecated Server derives user identity from the apiKey's
254
+ * scope (or from `Ablo-Acting-User` request header for B2B2C).
255
+ * Removed once Phase 3 ships.
256
+ */
257
+ user?: {
258
+ id: string;
259
+ teamIds?: string[];
260
+ };
261
+ /**
262
+ * @deprecated Server derives agent identity from the apiKey's
263
+ * scope. Removed once Phase 3 ships.
264
+ */
265
+ agentId?: string;
266
+ /**
267
+ * @deprecated Cap-mint moves server-internal in Phase 3. Pass
268
+ * `apiKey` only; the server handles capability issuance.
269
+ */
270
+ capabilityToken?: string;
271
+ /** Custom logger (default: console). Supplying one bypasses {@link debug}/{@link logLevel}. */
272
+ logger?: SyncLogger;
273
+ /**
274
+ * Turn Ablo's diagnostic logging on/off. `true` surfaces the `[Ablo]`
275
+ * coordination trace — claims acquired / queued / granted / released, agent
276
+ * handovers, connection state — plus internal lifecycle, so you can SEE the
277
+ * human+agent coordination you built. Omitted/`false` keeps the quiet default
278
+ * (only warnings + errors). For a middle ground use {@link logLevel}.
279
+ * Env override: `ABLO_LOG_LEVEL`. Ignored if a custom {@link logger} is passed.
280
+ */
281
+ debug?: boolean;
282
+ /**
283
+ * Log threshold for the default `[Ablo]` logger (takes precedence over
284
+ * {@link debug}). `'info'` = coordination + connection events without the
285
+ * per-model registration firehose; `'debug'` = everything; `'warn'` (default)
286
+ * = warnings + errors only; `'silent'` = nothing. Env override: `ABLO_LOG_LEVEL`.
287
+ */
288
+ logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
289
+ /** ObjectPool size limit (default: 10000) */
290
+ maxPoolSize?: number;
291
+ /**
292
+ * Local persistence mode. Defaults to `memory` so Ablo behaves like a
293
+ * point solution for shared state instead of silently bolting IndexedDB
294
+ * durability onto every browser consumer.
295
+ *
296
+ * Pass `persistence: 'indexeddb'` only when you want offline queueing
297
+ * and a reload-surviving local cache in a browser.
298
+ */
299
+ persistence?: AbloPersistence;
300
+ /** @deprecated Use `persistence: 'indexeddb'` for durable browser storage. */
301
+ offline?: boolean;
302
+ /**
303
+ * @deprecated Internal/testing escape hatch. Use `persistence` in
304
+ * production code. `true` maps to `memory`; `false` maps to
305
+ * `indexeddb` in browsers.
306
+ */
307
+ inMemory?: boolean;
308
+ /**
309
+ * If true, initialization starts immediately in the background so
310
+ * `sync.reports.findMany()` works after `await sync.ready()`.
311
+ *
312
+ * If false (default), the consumer MUST call `await sync.ready()` before
313
+ * using the engine — any query before that returns empty results.
314
+ *
315
+ * Default: false (explicit is better — prevents silent init failures).
316
+ */
317
+ autoStart?: boolean;
318
+ /**
319
+ * How aggressively this client should pull baseline state at
320
+ * startup.
321
+ *
322
+ * - `'full'`: pull every delta in the configured sync groups before
323
+ * `ready()` resolves. Default for `kind: 'user'`.
324
+ * - `'none'`: open the WS and process live deltas only — no baseline
325
+ * fetch. Reads round-trip via `model.retrieve()`; subscriptions
326
+ * populate the pool lazily via covering deltas. Default for
327
+ * `kind: 'agent'` because agent-worker / routine runners don't
328
+ * need (or want) a local replica of the org's tenant plane.
329
+ */
330
+ bootstrapMode?: 'full' | 'none';
331
+ /**
332
+ * Custom observability provider (Sentry, Honeycomb, OTel, etc.).
333
+ * Default: a noop implementation that drops all breadcrumbs and spans.
334
+ */
335
+ observability?: SyncObservabilityProvider;
336
+ /**
337
+ * Custom analytics provider (PostHog, Amplitude, Segment, etc.).
338
+ * Default: a noop implementation that drops all events.
339
+ */
340
+ analytics?: SyncAnalytics;
341
+ /**
342
+ * Detect whether an error from a mutation/bootstrap response means the
343
+ * user's session has expired. Used to surface re-auth prompts. Default:
344
+ * heuristic that matches `401 Unauthorized` and a few common error shapes.
345
+ */
346
+ sessionErrorDetector?: SessionErrorDetector;
347
+ /**
348
+ * Detect whether the browser is currently online. Default: reads
349
+ * `navigator.onLine` and listens to the `online`/`offline` events.
350
+ */
351
+ onlineStatus?: OnlineStatusProvider;
352
+ /**
353
+ * Replace the built-in `MutationExecutor` (which posts a hardcoded
354
+ * `commit` method against `${url}/graphql`) with one that uses your own
355
+ * GraphQL client, auth headers, retry policy, and observability hooks.
356
+ *
357
+ * Default: a fetch-based executor that targets `${url}/graphql` and sends
358
+ * the configured bearer (`apiKey` / backend-minted token) as `Authorization`.
359
+ */
360
+ mutationExecutor?: MutationExecutor;
361
+ /**
362
+ * Partial overrides for the auto-derived `SyncEngineConfig`. Merged on
363
+ * top of `deriveConfigFromSchema(schema)`. Use this when you need
364
+ * specific `modelCreatePriority`, `batchableModels`, or
365
+ * `essentialFields` settings that the schema cannot express.
366
+ */
367
+ configOverrides?: Partial<SyncEngineConfig>;
368
+ /**
369
+ * Sync groups (entity scopes) this client subscribes to. **Provisional, not
370
+ * deprecated** — pick the right lane: normally the server derives these from
371
+ * the apiKey's scope, but passing them is still REQUIRED today in any config
372
+ * where the key doesn't resolve them (omitting yields a `degenerate
373
+ * syncGroups` warning and a zero-fan-out client). Keep passing it explicitly
374
+ * until the server-derived path ships in Phase 3, at which point it becomes a
375
+ * true no-op and is removed. Build values with `syncGroup(kind, id)` from
376
+ * `@abloatai/ablo/schema`.
377
+ */
378
+ syncGroups?: string[];
379
+ /**
380
+ * Override the bootstrap endpoint base URL. Use this when your sync
381
+ * server's HTTP API lives on a different host than the WebSocket URL.
382
+ *
383
+ * Must include the `/api` prefix — `BootstrapHelper` appends
384
+ * `/sync/bootstrap` directly. Example:
385
+ * `'http://api.example.com/api'` → `http://api.example.com/api/sync/bootstrap`.
386
+ *
387
+ * Default: `${url.replace(/^ws/, 'http')}/api`.
388
+ */
389
+ bootstrapBaseUrl?: string;
390
+ /**
391
+ * Ablo-owned account scope. Required for Branch 3 identity resolution
392
+ * in `identity.ts` — without it the SDK falls through to the
393
+ * `/api/identity` HTTP-derived path (Branch 2).
394
+ */
395
+ organizationId?: string;
396
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Option types for the `Ablo({...})` factory — the public `AbloOptions` bag
3
+ * and the full internal construction surface (`InternalAbloOptions`).
4
+ *
5
+ * Extracted from `Ablo.ts` so the option types can be referenced without
6
+ * pulling in the factory's runtime graph. This module is type-only — ZERO
7
+ * runtime imports — so importing it can never create a cycle. `Ablo.ts`
8
+ * re-exports everything here, so existing import paths keep resolving.
9
+ */
10
+ export {};