@abloatai/ablo 0.28.0 → 0.29.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 (96) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/Database.js +9 -6
  3. package/dist/SyncClient.d.ts +2 -2
  4. package/dist/SyncClient.js +22 -10
  5. package/dist/adapters/inMemoryStorage.js +18 -14
  6. package/dist/ai-sdk/coordinatedTool.d.ts +15 -2
  7. package/dist/auth/schemas.d.ts +6 -0
  8. package/dist/auth/schemas.js +7 -0
  9. package/dist/cli.cjs +815 -400
  10. package/dist/client/Ablo.d.ts +29 -23
  11. package/dist/client/Ablo.js +8 -196
  12. package/dist/client/claimHeartbeatLoop.d.ts +1 -1
  13. package/dist/client/claimHeartbeatLoop.js +1 -1
  14. package/dist/client/createInternalComponents.d.ts +4 -2
  15. package/dist/client/createInternalComponents.js +3 -1
  16. package/dist/client/durableWrites.d.ts +21 -0
  17. package/dist/client/durableWrites.js +46 -0
  18. package/dist/client/httpClient.d.ts +19 -45
  19. package/dist/client/httpClient.js +104 -26
  20. package/dist/client/httpTransport.d.ts +8 -0
  21. package/dist/client/{ApiClient.js → httpTransport.js} +78 -291
  22. package/dist/client/options.d.ts +43 -19
  23. package/dist/client/options.js +3 -2
  24. package/dist/client/resourceTypes.d.ts +9 -85
  25. package/dist/client/resourceTypes.js +1 -1
  26. package/dist/client/sessionMint.d.ts +5 -6
  27. package/dist/client/sessionMint.js +4 -5
  28. package/dist/client/validateAbloOptions.js +3 -3
  29. package/dist/coordination/schema.d.ts +30 -0
  30. package/dist/coordination/schema.js +14 -0
  31. package/dist/core/index.d.ts +1 -1
  32. package/dist/errors.d.ts +4 -40
  33. package/dist/errors.js +5 -5
  34. package/dist/index.d.ts +14 -8
  35. package/dist/index.js +7 -5
  36. package/dist/interfaces/index.d.ts +3 -0
  37. package/dist/mutators/defineMutators.d.ts +18 -0
  38. package/dist/mutators/defineMutators.js +4 -8
  39. package/dist/react/index.d.ts +1 -1
  40. package/dist/schema/index.d.ts +1 -1
  41. package/dist/schema/index.js +1 -1
  42. package/dist/schema/select.d.ts +15 -0
  43. package/dist/schema/select.js +27 -3
  44. package/dist/source/connector.d.ts +3 -3
  45. package/dist/source/factory.d.ts +4 -6
  46. package/dist/source/factory.js +4 -7
  47. package/dist/source/index.d.ts +4 -4
  48. package/dist/source/index.js +2 -2
  49. package/dist/source/signing.d.ts +0 -3
  50. package/dist/source/types.d.ts +0 -26
  51. package/dist/stores/ObjectStore.js +8 -8
  52. package/dist/surface.d.ts +1 -1
  53. package/dist/surface.js +1 -0
  54. package/dist/sync/BootstrapFetcher.d.ts +10 -0
  55. package/dist/sync/BootstrapFetcher.js +27 -4
  56. package/dist/sync/createClaimStream.d.ts +11 -2
  57. package/dist/sync/createClaimStream.js +4 -3
  58. package/dist/testing/mocks/FakeDatabase.d.ts +1 -1
  59. package/dist/transactions/TransactionQueue.d.ts +2 -2
  60. package/dist/transactions/TransactionQueue.js +3 -3
  61. package/dist/transactions/commitEnvelope.d.ts +1 -1
  62. package/dist/transactions/commitEnvelope.js +2 -2
  63. package/dist/transactions/commitOutboxStore.d.ts +19 -19
  64. package/dist/transactions/durableWriteStore.d.ts +123 -0
  65. package/dist/transactions/durableWriteStore.js +30 -0
  66. package/dist/transactions/httpCommitEnvelope.d.ts +1 -0
  67. package/dist/transactions/httpCommitEnvelope.js +14 -12
  68. package/dist/transactions/idempotencyKey.d.ts +10 -0
  69. package/dist/transactions/idempotencyKey.js +9 -0
  70. package/dist/types/global.d.ts +10 -29
  71. package/dist/types/global.js +4 -7
  72. package/dist/types/streams.d.ts +2 -28
  73. package/dist/wire/frames.d.ts +6 -257
  74. package/dist/wire/frames.js +4 -25
  75. package/dist/wire/index.d.ts +4 -3
  76. package/dist/wire/index.js +2 -2
  77. package/dist/wire/protocolVersion.d.ts +30 -17
  78. package/dist/wire/protocolVersion.js +34 -18
  79. package/docs/agents.md +8 -3
  80. package/docs/api.md +6 -4
  81. package/docs/client-behavior.md +6 -3
  82. package/docs/coordination.md +2 -3
  83. package/docs/data-sources.md +5 -8
  84. package/docs/guarantees.md +21 -0
  85. package/docs/integration-guide.md +1 -0
  86. package/docs/migration.md +21 -1
  87. package/docs/quickstart.md +11 -0
  88. package/docs/react.md +0 -46
  89. package/examples/README.md +6 -5
  90. package/llms.txt +15 -15
  91. package/package.json +2 -7
  92. package/dist/client/ApiClient.d.ts +0 -177
  93. package/dist/commit/contract.d.ts +0 -493
  94. package/dist/commit/contract.js +0 -187
  95. package/dist/commit/index.d.ts +0 -6
  96. package/dist/commit/index.js +0 -5
@@ -12,52 +12,130 @@
12
12
  * where the credential itself carries identity and the server resolves it on
13
13
  * every request.
14
14
  *
15
- * Under the hood this wraps the schema-agnostic protocol client that
16
- * {@link createProtocolClient} returns in a typed proxy. The protocol client
17
- * commits over `POST /v1/commits` and reads over HTTP, authenticating with the
18
- * bearer token each time; its model access is string-keyed (`api.model('slides')`).
19
- * The proxy gives server code the same typed `client.<model>` surface the
20
- * stateful client offers, over stateless transport.
15
+ * Under the hood this wraps one schema-agnostic protocol client in a typed
16
+ * proxy. That protocol layer keeps transport envelopes and string-keyed model
17
+ * routing private; application code gets the same `client.<model>` surface the
18
+ * stateful client offers.
21
19
  */
22
- import { createProtocolClient, } from './ApiClient.js';
20
+ import { createHttpTransport, } from './httpTransport.js';
21
+ import { AbloConnectionError, AbloValidationError } from '../errors.js';
23
22
  /**
24
- * Names on the underlying protocol client that pass straight through the proxy.
25
- * This set intentionally leaves out names that collide with common schema models
26
- * `tasks`, `claims`, `capabilities`, `agent` — so that `client.tasks` resolves to
27
- * the schema model named `tasks` rather than a protocol resource. Only lifecycle
28
- * methods and the genuinely protocol-level members belong here.
23
+ * Private transport members that pass straight through the facade. Everything
24
+ * else must be a declared schema model; there is no dynamic fallback namespace.
29
25
  */
30
26
  const PROTOCOL_MEMBERS = new Set([
31
27
  'ready',
32
28
  'waitForFlush',
33
29
  'dispose',
34
- 'purge',
35
30
  'commits',
36
- 'model',
37
31
  'getAuthToken',
38
32
  'sessions',
39
33
  ]);
34
+ /** Narrows a bare property name to a transport key so the facade can index it typed. */
35
+ function isProtocolMember(prop) {
36
+ return PROTOCOL_MEMBERS.has(prop);
37
+ }
38
+ /**
39
+ * Adapts one low-level protocol model to the public typed model contract. The
40
+ * protocol deliberately retains `{ data, stamp, claims }` reads and commit
41
+ * receipts because functional updates need them. This is the single boundary
42
+ * that unwraps those transport details for application code.
43
+ */
44
+ function createHttpModelClient(protocol) {
45
+ async function readRow(id) {
46
+ const read = await protocol.retrieve({ id });
47
+ return read.data;
48
+ }
49
+ async function requireUpdatedRow(id) {
50
+ const row = await readRow(id);
51
+ if (row === undefined) {
52
+ throw new AbloConnectionError(`update settled but ${id} could not be read back from the server.`, { code: 'commit_no_result' });
53
+ }
54
+ return row;
55
+ }
56
+ // The protocol resource is schema-agnostic and types claim handles as records.
57
+ // The typed facade carries the same handle with its row type attached; runtime
58
+ // mutation code only reads the handle identity. Normalize that one generic
59
+ // boundary here instead of leaking casts into every model method.
60
+ function mutationOptions(params) {
61
+ const { claim, ...rest } = params;
62
+ return {
63
+ ...rest,
64
+ ...(claim !== undefined ? { claim } : {}),
65
+ };
66
+ }
67
+ async function update(arg, updater, options) {
68
+ if (typeof arg === 'string') {
69
+ if (!updater) {
70
+ throw new AbloValidationError('Functional update requires an updater function.', { code: 'write_options_invalid' });
71
+ }
72
+ const receipt = await protocol.update(arg, updater, options);
73
+ return receipt === undefined ? undefined : requireUpdatedRow(arg);
74
+ }
75
+ await protocol.update({
76
+ ...mutationOptions(arg),
77
+ data: arg.data,
78
+ });
79
+ return requireUpdatedRow(arg.id);
80
+ }
81
+ return {
82
+ async retrieve(params) {
83
+ const read = await protocol.retrieve(params);
84
+ return read.data;
85
+ },
86
+ list: (options) => protocol.list(options),
87
+ async create(params) {
88
+ const row = await protocol.create({
89
+ ...mutationOptions(params),
90
+ data: params.data,
91
+ });
92
+ return row;
93
+ },
94
+ update,
95
+ async delete(params) {
96
+ await protocol.delete(mutationOptions(params));
97
+ },
98
+ claim: protocol.claim,
99
+ };
100
+ }
40
101
  /**
41
102
  * Builds the stateless, typed HTTP client. Each `client.<model>` resolves to the
42
103
  * protocol client's model accessor, while `commits`, `dispose`, and the other
43
104
  * protocol members pass through unchanged. No socket is ever opened; the bearer
44
105
  * credential is the identity.
45
106
  */
107
+ /** @internal Constructed only through the public `Ablo({ transport: 'http' })` factory. */
46
108
  export function createAbloHttpClient(options) {
47
- // The schema is type-level only; the protocol client is schema-agnostic.
48
- const { schema: _schema, ...rest } = options;
49
- const api = createProtocolClient({ ...rest, schema: null });
50
- const facade = new Proxy(api, {
51
- get(target, prop) {
109
+ const { schema, ...rest } = options;
110
+ const modelTypenames = Object.fromEntries(Object.entries(schema.models).map(([key, definition]) => [
111
+ key,
112
+ definition.typename ?? key,
113
+ ]));
114
+ const transport = createHttpTransport({
115
+ ...rest,
116
+ modelTypenames,
117
+ });
118
+ const schemaModels = new Set(Object.keys(schema.models));
119
+ const models = new Map();
120
+ const model = (name) => {
121
+ const cached = models.get(name);
122
+ if (cached)
123
+ return cached;
124
+ const created = createHttpModelClient(transport.model(name));
125
+ models.set(name, created);
126
+ return created;
127
+ };
128
+ const facade = new Proxy({}, {
129
+ get(_target, prop) {
52
130
  if (typeof prop !== 'string')
53
- return Reflect.get(target, prop);
131
+ return undefined;
54
132
  // Real protocol members pass through unchanged.
55
- if (PROTOCOL_MEMBERS.has(prop) && prop in target)
56
- return Reflect.get(target, prop);
57
- // Anything else is a typed model accessor → the string-keyed protocol model
58
- // (which implements retrieve/list/create/update/delete/claim every method
59
- // `HttpModelClient` declares).
60
- return api.model(prop);
133
+ if (isProtocolMember(prop)) {
134
+ return transport[prop];
135
+ }
136
+ // Only schema models become model accessors. A typo or retired top-level
137
+ // member resolves to undefined instead of manufacturing a plausible client.
138
+ return schemaModels.has(prop) ? model(prop) : undefined;
61
139
  },
62
140
  });
63
141
  // A single boundary cast. `AbloHttpClient<S>` declares only what the model
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Private HTTP protocol client behind `Ablo({ schema, transport: 'http' })`.
3
+ * It carries no object pool, local database, or WebSocket and maps Model,
4
+ * Claim, and Commit protocol shapes directly to server routes. The typed
5
+ * facade in `httpClient.ts` is the application boundary; this module owns
6
+ * transport envelopes, watermarks, replay, and route details.
7
+ */
8
+ export {};