@abloatai/ablo 0.18.0 → 0.20.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 (61) hide show
  1. package/CHANGELOG.md +49 -0
  2. package/dist/Model.d.ts +22 -0
  3. package/dist/Model.js +45 -0
  4. package/dist/ObjectPool.d.ts +14 -1
  5. package/dist/ObjectPool.js +8 -1
  6. package/dist/SyncClient.js +7 -1
  7. package/dist/SyncEngineContext.js +2 -0
  8. package/dist/ai-sdk/coordination-context.d.ts +2 -1
  9. package/dist/ai-sdk/coordination-context.js +3 -3
  10. package/dist/ai-sdk/index.d.ts +3 -4
  11. package/dist/ai-sdk/index.js +2 -3
  12. package/dist/ai-sdk/wrap.d.ts +13 -18
  13. package/dist/ai-sdk/wrap.js +2 -6
  14. package/dist/cli.cjs +253 -160
  15. package/dist/client/Ablo.d.ts +83 -22
  16. package/dist/client/Ablo.js +116 -32
  17. package/dist/client/ApiClient.d.ts +2 -2
  18. package/dist/client/ApiClient.js +27 -32
  19. package/dist/client/auth.d.ts +26 -0
  20. package/dist/client/auth.js +208 -0
  21. package/dist/client/createModelProxy.d.ts +16 -11
  22. package/dist/client/createModelProxy.js +15 -15
  23. package/dist/client/sessionMint.d.ts +10 -0
  24. package/dist/client/sessionMint.js +8 -1
  25. package/dist/coordination/schema.d.ts +10 -10
  26. package/dist/coordination/schema.js +7 -8
  27. package/dist/coordination/trace.d.ts +91 -0
  28. package/dist/coordination/trace.js +147 -0
  29. package/dist/errorCodes.d.ts +2 -0
  30. package/dist/errorCodes.js +2 -0
  31. package/dist/errors.d.ts +1 -2
  32. package/dist/errors.js +6 -9
  33. package/dist/index.d.ts +6 -1
  34. package/dist/index.js +13 -0
  35. package/dist/interfaces/index.d.ts +45 -2
  36. package/dist/mutators/undoApply.d.ts +7 -2
  37. package/dist/mutators/undoApply.js +7 -35
  38. package/dist/policy/types.d.ts +18 -9
  39. package/dist/policy/types.js +26 -16
  40. package/dist/react/AbloProvider.d.ts +2 -2
  41. package/dist/react/useAblo.js +12 -2
  42. package/dist/schema/sugar.js +10 -2
  43. package/dist/server/read-config.d.ts +7 -0
  44. package/dist/sync/HydrationCoordinator.js +7 -3
  45. package/dist/sync/SyncWebSocket.d.ts +11 -2
  46. package/dist/sync/SyncWebSocket.js +67 -3
  47. package/dist/sync/createClaimStream.d.ts +9 -2
  48. package/dist/sync/createClaimStream.js +9 -7
  49. package/dist/sync/participants.d.ts +12 -11
  50. package/dist/sync/participants.js +5 -5
  51. package/dist/transactions/TransactionQueue.d.ts +1 -0
  52. package/dist/transactions/TransactionQueue.js +40 -3
  53. package/dist/types/streams.d.ts +57 -135
  54. package/dist/utils/json.d.ts +39 -0
  55. package/dist/utils/json.js +88 -0
  56. package/docs/coordination.md +16 -0
  57. package/docs/debugging.md +194 -0
  58. package/docs/index.md +1 -0
  59. package/package.json +1 -1
  60. package/dist/ai-sdk/claim-broadcast.d.ts +0 -83
  61. package/dist/ai-sdk/claim-broadcast.js +0 -79
@@ -1,83 +0,0 @@
1
- /**
2
- * Claim broadcast middleware — wraps a language model so the agent
3
- * declares "I'm about to edit entity X" over the sync engine's
4
- * claim primitive at stream start, and abandons the claim at
5
- * stream end.
6
- *
7
- * Cross-cutting by design — composes via the AI SDK's
8
- * `wrapLanguageModel`. Same middleware works for every chat
9
- * surface, and for non-chat agent loops that share the AI SDK's
10
- * middleware interface (workers, MCP tools, autonomous loops).
11
- *
12
- * Open-source-clean: depends only on `@ai-sdk/provider` types and
13
- * the package's own `SyncAgent`. No app-specific assumptions —
14
- * Ablo's web app uses this, but so can any consumer of `@abloatai/ablo`.
15
- *
16
- * Cost: one WS frame at stream start (`claim_begin`), one at end
17
- * (`claim_abandon`). No DB I/O, no extra LLM tokens.
18
- */
19
- import type { LanguageModelV3Middleware } from '@ai-sdk/provider';
20
- import type { Ablo } from '../client/Ablo.js';
21
- import type { SchemaRecord } from '../schema/schema.js';
22
- /**
23
- * Target entity for the claim broadcast.
24
- *
25
- * `entityType` is a free-form string — convention is the schema's
26
- * typename (e.g. `'SlideDeck'`, `'Task'`, `'Matter'`) so peers can
27
- * filter consistently. The wire format treats it opaquely.
28
- */
29
- export interface ClaimTarget {
30
- readonly entityType: string;
31
- readonly entityId: string;
32
- /** Optional path for file/document-like targets. */
33
- readonly path?: string;
34
- /** Optional line/column range for partial-entity coordination. */
35
- readonly range?: {
36
- readonly startLine: number;
37
- readonly endLine: number;
38
- readonly startColumn?: number;
39
- readonly endColumn?: number;
40
- };
41
- /**
42
- * Optional sub-field within the entity. Useful when the agent
43
- * knows it's only editing a specific field — peers can filter
44
- * on the field too.
45
- */
46
- readonly field?: string;
47
- /** App-defined structured metadata. Opaque to the core SDK. */
48
- readonly meta?: Record<string, unknown>;
49
- /**
50
- * Hint for the server-side TTL on the claim. Caps at 10 minutes
51
- * server-side; default 60s — typical chat turn.
52
- */
53
- readonly estimatedMs?: number;
54
- }
55
- export interface ClaimBroadcastMiddlewareOptions<R extends SchemaRecord = SchemaRecord> {
56
- /** Connected Ablo. Null disables the middleware (no-op). */
57
- readonly agent: Ablo<R> | null;
58
- /** Target entity. Null skips the broadcast (purely conversational). */
59
- readonly target: ClaimTarget | null;
60
- /**
61
- * Human-readable phase describing what the agent is doing. Convention:
62
- * `'edit'`, `'read'`, `'review'`, `'generate'`. Default `'edit'`. The same
63
- * `reason` field used on every claim surface.
64
- */
65
- readonly reason?: string;
66
- /**
67
- * Peer-visible explanation of the specific work this model call is about to
68
- * perform. Surfaces to other agents through `ActiveClaim.description`.
69
- */
70
- readonly description?: string;
71
- }
72
- /**
73
- * Build the middleware. When `agent` or `target` is null, returns a
74
- * pass-through — keeps call sites unconditional regardless of
75
- * whether the surface has an entity in scope.
76
- *
77
- * Generic over the schema record so callers passing
78
- * `Ablo<typeof schema>` don't have to widen — `Ablo<S>` and
79
- * `Ablo<SchemaRecord>` are structurally non-compatible because the
80
- * widened version collapses model proxies to an index signature
81
- * that clashes with the named methods (`ready`, `dispose`, etc.).
82
- */
83
- export declare function claimBroadcastMiddleware<R extends SchemaRecord = SchemaRecord>(options: ClaimBroadcastMiddlewareOptions<R>): LanguageModelV3Middleware;
@@ -1,79 +0,0 @@
1
- /**
2
- * Claim broadcast middleware — wraps a language model so the agent
3
- * declares "I'm about to edit entity X" over the sync engine's
4
- * claim primitive at stream start, and abandons the claim at
5
- * stream end.
6
- *
7
- * Cross-cutting by design — composes via the AI SDK's
8
- * `wrapLanguageModel`. Same middleware works for every chat
9
- * surface, and for non-chat agent loops that share the AI SDK's
10
- * middleware interface (workers, MCP tools, autonomous loops).
11
- *
12
- * Open-source-clean: depends only on `@ai-sdk/provider` types and
13
- * the package's own `SyncAgent`. No app-specific assumptions —
14
- * Ablo's web app uses this, but so can any consumer of `@abloatai/ablo`.
15
- *
16
- * Cost: one WS frame at stream start (`claim_begin`), one at end
17
- * (`claim_abandon`). No DB I/O, no extra LLM tokens.
18
- */
19
- /**
20
- * Build the middleware. When `agent` or `target` is null, returns a
21
- * pass-through — keeps call sites unconditional regardless of
22
- * whether the surface has an entity in scope.
23
- *
24
- * Generic over the schema record so callers passing
25
- * `Ablo<typeof schema>` don't have to widen — `Ablo<S>` and
26
- * `Ablo<SchemaRecord>` are structurally non-compatible because the
27
- * widened version collapses model proxies to an index signature
28
- * that clashes with the named methods (`ready`, `dispose`, etc.).
29
- */
30
- export function claimBroadcastMiddleware(options) {
31
- const { agent, target } = options;
32
- const reason = options.reason ?? 'edit';
33
- const description = options.description;
34
- const openClaim = () => {
35
- if (!agent || !target)
36
- return null;
37
- return agent.claims.claim({
38
- type: target.entityType,
39
- id: target.entityId,
40
- path: target.path,
41
- range: target.range,
42
- field: target.field,
43
- meta: target.meta,
44
- }, {
45
- reason,
46
- description,
47
- ttl: target.estimatedMs ?? 60_000,
48
- });
49
- };
50
- return {
51
- specificationVersion: 'v3',
52
- // The AI SDK's middleware contract passes a no-arg `doStream` /
53
- // `doGenerate` thunk — params have already been transformed by
54
- // any earlier `transformParams` middleware in the chain. We
55
- // open the claim, call the inner, abandon when the inner
56
- // resolves (or rejects).
57
- async wrapStream({ doStream }) {
58
- const handle = openClaim();
59
- try {
60
- return await doStream();
61
- }
62
- finally {
63
- // Always abandon — even on error. The server's TTL would
64
- // eventually clean up regardless, but explicit release means
65
- // peers see the claim drop the moment generation completes.
66
- handle?.revoke();
67
- }
68
- },
69
- async wrapGenerate({ doGenerate }) {
70
- const handle = openClaim();
71
- try {
72
- return await doGenerate();
73
- }
74
- finally {
75
- handle?.revoke();
76
- }
77
- },
78
- };
79
- }