@revealui/sync 0.2.1 → 0.3.1

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 (52) hide show
  1. package/README.md +82 -112
  2. package/dist/collab/agent-client-factory.d.ts.map +1 -1
  3. package/dist/collab/agent-client.d.ts +1 -0
  4. package/dist/collab/agent-client.d.ts.map +1 -1
  5. package/dist/collab/agent-client.js +16 -7
  6. package/dist/collab/index.d.ts +1 -0
  7. package/dist/collab/index.d.ts.map +1 -1
  8. package/dist/collab/index.js +1 -0
  9. package/dist/collab/protocol-constants.d.ts +5 -0
  10. package/dist/collab/protocol-constants.d.ts.map +1 -0
  11. package/dist/collab/protocol-constants.js +4 -0
  12. package/dist/collab/server-index.d.ts +1 -0
  13. package/dist/collab/server-index.d.ts.map +1 -1
  14. package/dist/collab/server-index.js +1 -0
  15. package/dist/collab/use-collab-document.d.ts +1 -1
  16. package/dist/collab/use-collab-document.d.ts.map +1 -1
  17. package/dist/collab/use-collab-document.js +7 -4
  18. package/dist/collab/use-collaboration.d.ts.map +1 -1
  19. package/dist/collab/yjs-websocket-provider.d.ts.map +1 -1
  20. package/dist/collab/yjs-websocket-provider.js +1 -2
  21. package/dist/fetch-with-timeout.d.ts +7 -0
  22. package/dist/fetch-with-timeout.d.ts.map +1 -0
  23. package/dist/fetch-with-timeout.js +27 -0
  24. package/dist/hooks/useAgentContexts.d.ts +29 -0
  25. package/dist/hooks/useAgentContexts.d.ts.map +1 -0
  26. package/dist/hooks/useAgentContexts.js +22 -0
  27. package/dist/hooks/useAgentMemory.d.ts +34 -0
  28. package/dist/hooks/useAgentMemory.d.ts.map +1 -0
  29. package/dist/hooks/useAgentMemory.js +37 -0
  30. package/dist/hooks/useConversations.d.ts +26 -6
  31. package/dist/hooks/useConversations.d.ts.map +1 -1
  32. package/dist/hooks/useConversations.js +13 -3
  33. package/dist/hooks/useCoordinationSessions.d.ts +35 -0
  34. package/dist/hooks/useCoordinationSessions.d.ts.map +1 -0
  35. package/dist/hooks/useCoordinationSessions.js +22 -0
  36. package/dist/hooks/useCoordinationWorkItems.d.ts +41 -0
  37. package/dist/hooks/useCoordinationWorkItems.d.ts.map +1 -0
  38. package/dist/hooks/useCoordinationWorkItems.js +22 -0
  39. package/dist/index.d.ts +20 -4
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +14 -4
  42. package/dist/mutations.d.ts +14 -0
  43. package/dist/mutations.d.ts.map +1 -0
  44. package/dist/mutations.js +53 -0
  45. package/dist/provider/index.d.ts +29 -5
  46. package/dist/provider/index.d.ts.map +1 -1
  47. package/dist/provider/index.js +25 -7
  48. package/dist/shape-utils.d.ts +11 -0
  49. package/dist/shape-utils.d.ts.map +1 -0
  50. package/dist/shape-utils.js +14 -0
  51. package/dist/test-setup.d.ts.map +1 -1
  52. package/package.json +17 -15
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAgentMemory.d.ts","sourceRoot":"","sources":["../../src/hooks/useAgentMemory.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAOtD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,iBAAiB,EAAE,CAAC;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACrF,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,KAAK,OAAO,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC;IACjG,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;CACvD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAuCpE"}
@@ -0,0 +1,37 @@
1
+ 'use client';
2
+ import { useShape } from '@electric-sql/react';
3
+ import { fetchWithTimeout } from '../fetch-with-timeout.js';
4
+ import { useSyncMutations } from '../mutations.js';
5
+ import { useElectricConfig } from '../provider/index.js';
6
+ import { toRecords } from '../shape-utils.js';
7
+ const AGENT_ID_RE = /^[a-zA-Z0-9_-]+$/;
8
+ export function useAgentMemory(agentId) {
9
+ const { proxyBaseUrl } = useElectricConfig();
10
+ const isValid = agentId.length > 0 && AGENT_ID_RE.test(agentId);
11
+ // Hook must always be called (Rules of Hooks). Pass an impossible WHERE when
12
+ // the ID is invalid so the shape returns no rows but the hook still runs.
13
+ const { data, isLoading, error } = useShape({
14
+ url: `${proxyBaseUrl}/api/shapes/agent-memories`,
15
+ params: { agent_id: isValid ? agentId : '00000000-0000-0000-0000-000000000000' },
16
+ fetchClient: fetchWithTimeout,
17
+ });
18
+ const { create, update, remove } = useSyncMutations('agent-memories');
19
+ if (!isValid) {
20
+ return {
21
+ memories: [],
22
+ isLoading: false,
23
+ error: new Error('Invalid agentId: must be non-empty alphanumeric, hyphens, underscores only'),
24
+ create,
25
+ update,
26
+ remove,
27
+ };
28
+ }
29
+ return {
30
+ memories: toRecords(data),
31
+ isLoading,
32
+ error: error || null,
33
+ create,
34
+ update,
35
+ remove,
36
+ };
37
+ }
@@ -1,11 +1,31 @@
1
- type ConversationRecord = {
2
- id: string | number;
1
+ import type { MutationResult } from '../mutations.js';
2
+ export interface ConversationRecord {
3
+ id: string;
4
+ user_id: string;
5
+ agent_id: string;
3
6
  title?: string | null;
4
- };
5
- export declare function useConversations(_userId: string): {
7
+ status: string;
8
+ device_id?: string | null;
9
+ version: number;
10
+ created_at: string;
11
+ updated_at: string;
12
+ }
13
+ export interface CreateConversationInput {
14
+ agent_id: string;
15
+ title?: string;
16
+ device_id?: string;
17
+ }
18
+ export interface UpdateConversationInput {
19
+ title?: string;
20
+ status?: string;
21
+ }
22
+ export interface UseConversationsResult {
6
23
  conversations: ConversationRecord[];
7
24
  isLoading: boolean;
8
25
  error: Error | null;
9
- };
10
- export {};
26
+ create: (data: CreateConversationInput) => Promise<MutationResult<ConversationRecord>>;
27
+ update: (id: string, data: UpdateConversationInput) => Promise<MutationResult<ConversationRecord>>;
28
+ remove: (id: string) => Promise<MutationResult<void>>;
29
+ }
30
+ export declare function useConversations(_userId: string): UseConversationsResult;
11
31
  //# sourceMappingURL=useConversations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useConversations.d.ts","sourceRoot":"","sources":["../../src/hooks/useConversations.ts"],"names":[],"mappings":"AAIA,KAAK,kBAAkB,GAAG;IACxB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,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,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;CACvD;AAID,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,sBAAsB,CAuBxE"}
@@ -1,16 +1,26 @@
1
1
  'use client';
2
2
  import { useShape } from '@electric-sql/react';
3
+ import { fetchWithTimeout } from '../fetch-with-timeout.js';
4
+ import { useSyncMutations } from '../mutations.js';
5
+ import { useElectricConfig } from '../provider/index.js';
6
+ import { toRecords } from '../shape-utils.js';
3
7
  // _userId kept for API compatibility — filtering is enforced by the server-side
4
8
  // proxy at /api/shapes/conversations, which reads the session cookie directly.
5
9
  export function useConversations(_userId) {
10
+ const { proxyBaseUrl } = useElectricConfig();
6
11
  // The proxy validates the session and enforces row-level filtering server-side.
7
12
  // Client-provided params are not forwarded — the proxy overrides them.
8
13
  const { data, isLoading, error } = useShape({
9
- url: `/api/shapes/conversations`,
14
+ url: `${proxyBaseUrl}/api/shapes/conversations`,
15
+ fetchClient: fetchWithTimeout,
10
16
  });
17
+ const { create, update, remove } = useSyncMutations('conversations');
11
18
  return {
12
- conversations: Array.isArray(data) ? data : [],
19
+ conversations: toRecords(data),
13
20
  isLoading,
14
- error: error,
21
+ error: error || null,
22
+ create,
23
+ update,
24
+ remove,
15
25
  };
16
26
  }
@@ -0,0 +1,35 @@
1
+ import type { MutationResult } from '../mutations.js';
2
+ export interface CoordinationSessionRecord {
3
+ id: string;
4
+ agent_id: string;
5
+ started_at: string;
6
+ ended_at: string | null;
7
+ task: string;
8
+ status: string;
9
+ pid: number | null;
10
+ tools: Record<string, number> | null;
11
+ metadata: Record<string, unknown> | null;
12
+ }
13
+ export interface CreateCoordinationSessionInput {
14
+ agent_id: string;
15
+ task?: string;
16
+ pid?: number;
17
+ metadata?: Record<string, unknown>;
18
+ }
19
+ export interface UpdateCoordinationSessionInput {
20
+ task?: string;
21
+ status?: string;
22
+ ended_at?: string;
23
+ tools?: Record<string, number>;
24
+ metadata?: Record<string, unknown>;
25
+ }
26
+ export interface UseCoordinationSessionsResult {
27
+ sessions: CoordinationSessionRecord[];
28
+ isLoading: boolean;
29
+ error: Error | null;
30
+ create: (data: CreateCoordinationSessionInput) => Promise<MutationResult<CoordinationSessionRecord>>;
31
+ update: (id: string, data: UpdateCoordinationSessionInput) => Promise<MutationResult<CoordinationSessionRecord>>;
32
+ remove: (id: string) => Promise<MutationResult<void>>;
33
+ }
34
+ export declare function useCoordinationSessions(): UseCoordinationSessionsResult;
35
+ //# sourceMappingURL=useCoordinationSessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCoordinationSessions.d.ts","sourceRoot":"","sources":["../../src/hooks/useCoordinationSessions.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKtD,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,8BAA8B;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,yBAAyB,EAAE,CAAC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,MAAM,EAAE,CACN,IAAI,EAAE,8BAA8B,KACjC,OAAO,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC,CAAC;IACxD,MAAM,EAAE,CACN,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,8BAA8B,KACjC,OAAO,CAAC,cAAc,CAAC,yBAAyB,CAAC,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;CACvD;AAED,wBAAgB,uBAAuB,IAAI,6BAA6B,CAqBvE"}
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import { useShape } from '@electric-sql/react';
3
+ import { fetchWithTimeout } from '../fetch-with-timeout.js';
4
+ import { useSyncMutations } from '../mutations.js';
5
+ import { useElectricConfig } from '../provider/index.js';
6
+ import { toRecords } from '../shape-utils.js';
7
+ export function useCoordinationSessions() {
8
+ const { proxyBaseUrl } = useElectricConfig();
9
+ const { data, isLoading, error } = useShape({
10
+ url: `${proxyBaseUrl}/api/shapes/coordination-sessions`,
11
+ fetchClient: fetchWithTimeout,
12
+ });
13
+ const { create, update, remove } = useSyncMutations('coordination-sessions');
14
+ return {
15
+ sessions: toRecords(data),
16
+ isLoading,
17
+ error: error || null,
18
+ create,
19
+ update,
20
+ remove,
21
+ };
22
+ }
@@ -0,0 +1,41 @@
1
+ import type { MutationResult } from '../mutations.js';
2
+ export interface CoordinationWorkItemRecord {
3
+ id: string;
4
+ title: string;
5
+ description: string | null;
6
+ status: string;
7
+ priority: number;
8
+ owner_agent: string | null;
9
+ owner_session: string | null;
10
+ parent_id: string | null;
11
+ metadata: Record<string, unknown> | null;
12
+ created_at: string;
13
+ updated_at: string;
14
+ completed_at: string | null;
15
+ }
16
+ export interface CreateCoordinationWorkItemInput {
17
+ title: string;
18
+ description?: string;
19
+ priority?: number;
20
+ owner_agent?: string;
21
+ parent_id?: string;
22
+ metadata?: Record<string, unknown>;
23
+ }
24
+ export interface UpdateCoordinationWorkItemInput {
25
+ title?: string;
26
+ description?: string;
27
+ status?: string;
28
+ priority?: number;
29
+ owner_agent?: string;
30
+ metadata?: Record<string, unknown>;
31
+ }
32
+ export interface UseCoordinationWorkItemsResult {
33
+ workItems: CoordinationWorkItemRecord[];
34
+ isLoading: boolean;
35
+ error: Error | null;
36
+ create: (data: CreateCoordinationWorkItemInput) => Promise<MutationResult<CoordinationWorkItemRecord>>;
37
+ update: (id: string, data: UpdateCoordinationWorkItemInput) => Promise<MutationResult<CoordinationWorkItemRecord>>;
38
+ remove: (id: string) => Promise<MutationResult<void>>;
39
+ }
40
+ export declare function useCoordinationWorkItems(): UseCoordinationWorkItemsResult;
41
+ //# sourceMappingURL=useCoordinationWorkItems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCoordinationWorkItems.d.ts","sourceRoot":"","sources":["../../src/hooks/useCoordinationWorkItems.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAKtD,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;IAC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;CACvD;AAED,wBAAgB,wBAAwB,IAAI,8BAA8B,CAqBzE"}
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ import { useShape } from '@electric-sql/react';
3
+ import { fetchWithTimeout } from '../fetch-with-timeout.js';
4
+ import { useSyncMutations } from '../mutations.js';
5
+ import { useElectricConfig } from '../provider/index.js';
6
+ import { toRecords } from '../shape-utils.js';
7
+ export function useCoordinationWorkItems() {
8
+ const { proxyBaseUrl } = useElectricConfig();
9
+ const { data, isLoading, error } = useShape({
10
+ url: `${proxyBaseUrl}/api/shapes/coordination-work-items`,
11
+ fetchClient: fetchWithTimeout,
12
+ });
13
+ const { create, update, remove } = useSyncMutations('coordination-work-items');
14
+ return {
15
+ workItems: toRecords(data),
16
+ isLoading,
17
+ error: error || null,
18
+ create,
19
+ update,
20
+ remove,
21
+ };
22
+ }
package/dist/index.d.ts CHANGED
@@ -1,10 +1,26 @@
1
1
  /**
2
- * @experimental ElectricSQL sync is not yet functional.
3
- * The ElectricProvider is currently a passthrough that renders children without
4
- * establishing any sync connection. Do not use in production.
2
+ * @revealui/sync Real-time collaboration and sync primitives.
3
+ *
4
+ * The collab layer (Yjs-based) is fully functional.
5
+ * ElectricProvider provides proxyBaseUrl config to child hooks. All hooks route
6
+ * through the authenticated CMS proxy at /api/shapes/* — no direct Electric client.
7
+ *
8
+ * Reads use ElectricSQL shape subscriptions for real-time updates.
9
+ * Writes use REST mutations via /api/sync/* — changes propagate to all
10
+ * subscribers automatically through ElectricSQL replication.
5
11
  */
6
12
  export type { CollabDocumentState, UseCollaborationOptions, UseCollaborationResult, } from './collab/index.js';
7
13
  export { CollabProvider, useCollabDocument, useCollaboration, } from './collab/index.js';
14
+ export type { AgentContextRecord, CreateAgentContextInput, UpdateAgentContextInput, UseAgentContextsResult, } from './hooks/useAgentContexts.js';
15
+ export { useAgentContexts } from './hooks/useAgentContexts.js';
16
+ export type { AgentMemoryRecord, CreateAgentMemoryInput, UpdateAgentMemoryInput, UseAgentMemoryResult, } from './hooks/useAgentMemory.js';
17
+ export { useAgentMemory } from './hooks/useAgentMemory.js';
18
+ export type { ConversationRecord, CreateConversationInput, UpdateConversationInput, UseConversationsResult, } from './hooks/useConversations.js';
8
19
  export { useConversations } from './hooks/useConversations.js';
9
- export { ElectricProvider } from './provider/index.js';
20
+ export type { CoordinationSessionRecord, CreateCoordinationSessionInput, UpdateCoordinationSessionInput, UseCoordinationSessionsResult, } from './hooks/useCoordinationSessions.js';
21
+ export { useCoordinationSessions } from './hooks/useCoordinationSessions.js';
22
+ export type { CoordinationWorkItemRecord, CreateCoordinationWorkItemInput, UpdateCoordinationWorkItemInput, UseCoordinationWorkItemsResult, } from './hooks/useCoordinationWorkItems.js';
23
+ export { useCoordinationWorkItems } from './hooks/useCoordinationWorkItems.js';
24
+ export type { MutationResult } from './mutations.js';
25
+ export { ElectricProvider, useElectricConfig } from './provider/index.js';
10
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EACV,iBAAiB,EACjB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,GACrB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,YAAY,EACV,yBAAyB,EACzB,8BAA8B,EAC9B,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,YAAY,EACV,0BAA0B,EAC1B,+BAA+B,EAC/B,+BAA+B,EAC/B,8BAA8B,GAC/B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAC/E,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,8 +1,18 @@
1
1
  /**
2
- * @experimental ElectricSQL sync is not yet functional.
3
- * The ElectricProvider is currently a passthrough that renders children without
4
- * establishing any sync connection. Do not use in production.
2
+ * @revealui/sync Real-time collaboration and sync primitives.
3
+ *
4
+ * The collab layer (Yjs-based) is fully functional.
5
+ * ElectricProvider provides proxyBaseUrl config to child hooks. All hooks route
6
+ * through the authenticated CMS proxy at /api/shapes/* — no direct Electric client.
7
+ *
8
+ * Reads use ElectricSQL shape subscriptions for real-time updates.
9
+ * Writes use REST mutations via /api/sync/* — changes propagate to all
10
+ * subscribers automatically through ElectricSQL replication.
5
11
  */
6
12
  export { CollabProvider, useCollabDocument, useCollaboration, } from './collab/index.js';
13
+ export { useAgentContexts } from './hooks/useAgentContexts.js';
14
+ export { useAgentMemory } from './hooks/useAgentMemory.js';
7
15
  export { useConversations } from './hooks/useConversations.js';
8
- export { ElectricProvider } from './provider/index.js';
16
+ export { useCoordinationSessions } from './hooks/useCoordinationSessions.js';
17
+ export { useCoordinationWorkItems } from './hooks/useCoordinationWorkItems.js';
18
+ export { ElectricProvider, useElectricConfig } from './provider/index.js';
@@ -0,0 +1,14 @@
1
+ export interface MutationResult<T = unknown> {
2
+ success: boolean;
3
+ data?: T;
4
+ error?: string;
5
+ }
6
+ /**
7
+ * Hook that returns mutation functions for a given sync API endpoint.
8
+ */
9
+ export declare function useSyncMutations<TCreate, TUpdate, TRecord>(endpoint: string): {
10
+ create: (data: TCreate) => Promise<MutationResult<TRecord>>;
11
+ update: (id: string, data: TUpdate) => Promise<MutationResult<TRecord>>;
12
+ remove: (id: string) => Promise<MutationResult<void>>;
13
+ };
14
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../src/mutations.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0CD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;mBAK3D,OAAO,KAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;iBAO5C,MAAM,QAAQ,OAAO,KAAG,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;iBAOxD,MAAM,KAAG,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;EAOpD"}
@@ -0,0 +1,53 @@
1
+ 'use client';
2
+ import { useCallback } from 'react';
3
+ import { useElectricConfig } from './provider/index.js';
4
+ /** Default timeout for mutation fetch requests (milliseconds). */
5
+ const MUTATION_FETCH_TIMEOUT_MS = 10_000;
6
+ /**
7
+ * Make an authenticated mutation request to the CMS API.
8
+ * Credentials are included so the session cookie is sent cross-origin.
9
+ * Requests are aborted after {@link MUTATION_FETCH_TIMEOUT_MS} (10 s).
10
+ */
11
+ async function mutationFetch(url, method, body) {
12
+ const controller = new AbortController();
13
+ const timeout = setTimeout(() => controller.abort(), MUTATION_FETCH_TIMEOUT_MS);
14
+ let response;
15
+ try {
16
+ response = await fetch(url, {
17
+ method,
18
+ credentials: 'include',
19
+ signal: controller.signal,
20
+ headers: body !== undefined ? { 'Content-Type': 'application/json' } : undefined,
21
+ body: body !== undefined ? JSON.stringify(body) : undefined,
22
+ });
23
+ }
24
+ finally {
25
+ clearTimeout(timeout);
26
+ }
27
+ if (!response.ok) {
28
+ const errorData = (await response.json().catch(() => null));
29
+ return {
30
+ success: false,
31
+ error: errorData?.error ?? `Request failed with status ${response.status}`,
32
+ };
33
+ }
34
+ const data = (await response.json());
35
+ return { success: true, data };
36
+ }
37
+ /**
38
+ * Hook that returns mutation functions for a given sync API endpoint.
39
+ */
40
+ export function useSyncMutations(endpoint) {
41
+ const { proxyBaseUrl } = useElectricConfig();
42
+ const baseUrl = `${proxyBaseUrl}/api/sync/${endpoint}`;
43
+ const create = useCallback(async (data) => {
44
+ return mutationFetch(baseUrl, 'POST', data);
45
+ }, [baseUrl]);
46
+ const update = useCallback(async (id, data) => {
47
+ return mutationFetch(`${baseUrl}/${encodeURIComponent(id)}`, 'PATCH', data);
48
+ }, [baseUrl]);
49
+ const remove = useCallback(async (id) => {
50
+ return mutationFetch(`${baseUrl}/${encodeURIComponent(id)}`, 'DELETE');
51
+ }, [baseUrl]);
52
+ return { create, update, remove };
53
+ }
@@ -1,11 +1,35 @@
1
- import type { ReactNode } from 'react';
1
+ import { type ReactNode } from 'react';
2
+ interface ElectricContextValue {
3
+ /**
4
+ * Direct Electric service URL (e.g. the Railway instance).
5
+ * Stored in context for future use — not consumed by the current proxy-based hooks.
6
+ * All hooks use proxyBaseUrl + /api/shapes/* instead.
7
+ */
8
+ serviceUrl: string | null;
9
+ /**
10
+ * Base URL prefix for authenticated CMS shape proxy routes.
11
+ * Default '' keeps all hook URLs relative (works for same-origin apps).
12
+ * Set to 'https://cms.revealui.com' when consuming from a different origin.
13
+ */
14
+ proxyBaseUrl: string;
15
+ debug: boolean;
16
+ }
2
17
  /**
3
- * @experimental This provider is a passthrough ElectricSQL integration is not yet implemented.
4
- * Children are rendered without any sync functionality.
18
+ * Provides ElectricSQL configuration to child hooks (`useConversations`, `useCollabDocument`).
19
+ *
20
+ * Provides proxyBaseUrl (and optional serviceUrl/debug) to child hooks via context.
21
+ * All hooks use the CMS proxy pattern — no direct Electric connection is established here.
5
22
  */
6
- export declare function ElectricProvider({ children, }: {
23
+ export declare function ElectricProvider(props: {
7
24
  children: ReactNode;
8
25
  serviceUrl?: string;
26
+ proxyBaseUrl?: string;
9
27
  debug?: boolean;
10
- }): import("react/jsx-runtime").JSX.Element;
28
+ }): ReactNode;
29
+ /**
30
+ * Access the ElectricSQL configuration provided by `ElectricProvider`.
31
+ * Returns `{ serviceUrl: null, debug: false }` if no provider is present.
32
+ */
33
+ export declare function useElectricConfig(): ElectricContextValue;
34
+ export {};
11
35
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,2CAIA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/provider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,SAAS,EAAgB,MAAM,OAAO,CAAC;AAEpE,UAAU,oBAAoB;IAC5B;;;;OAIG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,OAAO,CAAC;CAChB;AAQD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,QAAQ,EAAE,SAAS,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,SAAS,CAWZ;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,oBAAoB,CAExD"}
@@ -1,11 +1,29 @@
1
1
  'use client';
2
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, use, useMemo } from 'react';
4
+ const ElectricContext = createContext({
5
+ serviceUrl: null,
6
+ proxyBaseUrl: '',
7
+ debug: false,
8
+ });
3
9
  /**
4
- * @experimental This provider is a passthrough ElectricSQL integration is not yet implemented.
5
- * Children are rendered without any sync functionality.
10
+ * Provides ElectricSQL configuration to child hooks (`useConversations`, `useCollabDocument`).
11
+ *
12
+ * Provides proxyBaseUrl (and optional serviceUrl/debug) to child hooks via context.
13
+ * All hooks use the CMS proxy pattern — no direct Electric connection is established here.
6
14
  */
7
- export function ElectricProvider({ children, }) {
8
- // For now, just pass through children
9
- // useShape hooks work directly with proxy API endpoints
10
- return _jsx(_Fragment, { children: children });
15
+ export function ElectricProvider(props) {
16
+ const value = useMemo(() => ({
17
+ serviceUrl: props.serviceUrl ?? null,
18
+ proxyBaseUrl: props.proxyBaseUrl ?? '',
19
+ debug: props.debug ?? false,
20
+ }), [props.serviceUrl, props.proxyBaseUrl, props.debug]);
21
+ return _jsx(ElectricContext, { value: value, children: props.children });
22
+ }
23
+ /**
24
+ * Access the ElectricSQL configuration provided by `ElectricProvider`.
25
+ * Returns `{ serviceUrl: null, debug: false }` if no provider is present.
26
+ */
27
+ export function useElectricConfig() {
28
+ return use(ElectricContext);
11
29
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Cast ElectricSQL shape data to a typed record array.
3
+ *
4
+ * ElectricSQL's `useShape` returns `Row[]` (i.e. `Record<string, Value>[]`).
5
+ * Our record interfaces describe the exact same shape but lack the index
6
+ * signature that `Row` carries, so TypeScript rejects a direct assignment.
7
+ * This helper encapsulates the boundary cast in one place and returns an
8
+ * empty array when data is falsy.
9
+ */
10
+ export declare function toRecords<T>(data: unknown[] | undefined): T[];
11
+ //# sourceMappingURL=shape-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape-utils.d.ts","sourceRoot":"","sources":["../src/shape-utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,CAAC,EAAE,CAG7D"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Cast ElectricSQL shape data to a typed record array.
3
+ *
4
+ * ElectricSQL's `useShape` returns `Row[]` (i.e. `Record<string, Value>[]`).
5
+ * Our record interfaces describe the exact same shape but lack the index
6
+ * signature that `Row` carries, so TypeScript rejects a direct assignment.
7
+ * This helper encapsulates the boundary cast in one place and returns an
8
+ * empty array when data is falsy.
9
+ */
10
+ export function toRecords(data) {
11
+ if (!Array.isArray(data))
12
+ return [];
13
+ return data;
14
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAA"}
1
+ {"version":3,"file":"test-setup.d.ts","sourceRoot":"","sources":["../src/test-setup.ts"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC"}
package/package.json CHANGED
@@ -1,34 +1,34 @@
1
1
  {
2
2
  "name": "@revealui/sync",
3
- "version": "0.2.1",
4
- "experimental": true,
5
- "license": "MIT",
6
- "files": [
7
- "dist"
8
- ],
3
+ "version": "0.3.1",
9
4
  "description": "ElectricSQL sync utilities for RevealUI",
5
+ "license": "MIT",
10
6
  "dependencies": {
11
7
  "@electric-sql/react": "^1.0.27",
12
8
  "lib0": "^0.2.117",
13
9
  "ws": "^8.18.0",
14
10
  "y-protocols": "^1.0.7",
15
11
  "yjs": "^13.6.29",
16
- "@revealui/contracts": "1.1.0",
17
- "@revealui/db": "0.2.1"
12
+ "@revealui/db": "0.3.1",
13
+ "@revealui/contracts": "1.3.1"
18
14
  },
19
15
  "devDependencies": {
20
16
  "@testing-library/jest-dom": "^6.6.4",
21
- "@types/ws": "^8.5.14",
22
17
  "@testing-library/react": "^16.3.0",
23
18
  "@testing-library/react-hooks": "^8.0.1",
24
- "@vitest/coverage-v8": "^4.0.18",
25
- "jsdom": "^27.4.0",
19
+ "@types/ws": "^8.5.14",
20
+ "@vitest/coverage-v8": "^4.1.0",
21
+ "jsdom": "^29.0.1",
26
22
  "react": "^19.2.3",
27
23
  "react-dom": "^19.2.3",
28
- "typescript": "^5.9.3",
29
- "vitest": "^4.0.18",
24
+ "typescript": "^6.0.2",
25
+ "vitest": "^4.1.0",
30
26
  "dev": "0.0.1"
31
27
  },
28
+ "engines": {
29
+ "node": ">=24.13.0"
30
+ },
31
+ "experimental": true,
32
32
  "exports": {
33
33
  ".": {
34
34
  "types": "./dist/index.d.ts",
@@ -47,6 +47,9 @@
47
47
  "import": "./dist/collab/server-index.js"
48
48
  }
49
49
  },
50
+ "files": [
51
+ "dist"
52
+ ],
50
53
  "main": "./dist/index.js",
51
54
  "publishConfig": {
52
55
  "access": "public",
@@ -59,9 +62,8 @@
59
62
  "clean": "rm -rf dist",
60
63
  "dev": "tsc --watch",
61
64
  "lint": "biome check .",
62
- "lint:eslint": "eslint .",
63
65
  "test": "vitest run",
64
- "test:coverage": "vitest run --coverage",
66
+ "test:coverage": "vitest run --coverage --coverage.reporter=json-summary --coverage.reporter=html --coverage.reporter=text",
65
67
  "test:watch": "vitest",
66
68
  "typecheck": "tsc --noEmit"
67
69
  }