chart data loading
This commit is contained in:
86
gateway/src/workspace/index.ts
Normal file
86
gateway/src/workspace/index.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Workspace Module
|
||||
*
|
||||
* Provides two-way state synchronization between web clients, gateway, and user containers.
|
||||
*
|
||||
* Key components:
|
||||
* - WorkspaceManager: Per-session state manager with channel-agnostic interface
|
||||
* - SyncRegistry: Handles JSON patch sync protocol
|
||||
* - ContainerSync: Persists state to user containers via MCP
|
||||
*
|
||||
* Usage:
|
||||
* ```typescript
|
||||
* import { WorkspaceManager, ContainerSync, DEFAULT_STORES } from './workspace/index.js';
|
||||
*
|
||||
* // Create container sync (optional, for persistent stores)
|
||||
* const containerSync = new ContainerSync(mcpClient, logger);
|
||||
*
|
||||
* // Create workspace manager for session
|
||||
* const workspace = new WorkspaceManager({
|
||||
* userId: 'user-123',
|
||||
* sessionId: 'session-456',
|
||||
* stores: DEFAULT_STORES,
|
||||
* containerSync,
|
||||
* logger,
|
||||
* });
|
||||
*
|
||||
* // Initialize (loads persistent stores from container)
|
||||
* await workspace.initialize();
|
||||
*
|
||||
* // Attach channel adapter
|
||||
* workspace.setAdapter({
|
||||
* sendSnapshot: (msg) => socket.send(JSON.stringify(msg)),
|
||||
* sendPatch: (msg) => socket.send(JSON.stringify(msg)),
|
||||
* getCapabilities: () => ({ supportsSync: true, ... }),
|
||||
* });
|
||||
*
|
||||
* // Handle sync messages from client
|
||||
* workspace.handleHello(clientSeqs);
|
||||
* workspace.handlePatch(storeName, seq, patch);
|
||||
*
|
||||
* // Access state
|
||||
* const chartState = workspace.getState('chartState');
|
||||
* await workspace.setState('chartState', newState);
|
||||
*
|
||||
* // Register triggers (future use)
|
||||
* const unsub = workspace.onPathChange('/chartState/symbol', (old, new, ctx) => {
|
||||
* console.log('Symbol changed:', old, '->', new);
|
||||
* });
|
||||
*
|
||||
* // Cleanup
|
||||
* await workspace.shutdown();
|
||||
* ```
|
||||
*/
|
||||
|
||||
// Types
|
||||
export type {
|
||||
SnapshotMessage,
|
||||
PatchMessage,
|
||||
HelloMessage,
|
||||
InboundSyncMessage,
|
||||
OutboundSyncMessage,
|
||||
StoreConfig,
|
||||
ChannelAdapter,
|
||||
ChannelCapabilities,
|
||||
PathTrigger,
|
||||
PathTriggerHandler,
|
||||
PathTriggerContext,
|
||||
ChartState,
|
||||
ChartStore,
|
||||
ChannelState,
|
||||
ChannelInfo,
|
||||
WorkspaceStores,
|
||||
} from './types.js';
|
||||
|
||||
export { DEFAULT_STORES } from './types.js';
|
||||
|
||||
// Sync registry
|
||||
export { SyncRegistry } from './sync-registry.js';
|
||||
|
||||
// Container sync
|
||||
export { ContainerSync } from './container-sync.js';
|
||||
export type { LoadResult, SaveResult, PatchResult } from './container-sync.js';
|
||||
|
||||
// Workspace manager
|
||||
export { WorkspaceManager } from './workspace-manager.js';
|
||||
export type { WorkspaceManagerConfig } from './workspace-manager.js';
|
||||
Reference in New Issue
Block a user