UNPKG

consortium

Version:

Remote control and session sharing CLI for AI coding agents

66 lines (62 loc) 1.7 kB
import { s as startOfflineReconnection, c as configuration } from './types-DETLaopx.mjs'; function createOfflineSessionStub(sessionTag) { return { sessionId: `offline-${sessionTag}`, sendCodexMessage: () => { }, sendAgentMessage: () => { }, sendClaudeSessionMessage: () => { }, keepAlive: () => { }, sendSessionEvent: () => { }, sendSessionDeath: () => { }, updateLifecycleState: () => { }, requestControlTransfer: async () => { }, flush: async () => { }, close: async () => { }, updateMetadata: () => { }, updateAgentState: () => { }, onUserMessage: () => { }, rpcHandlerManager: { registerHandler: () => { } } }; } function setupOfflineReconnection(opts) { const { api, sessionTag, metadata, state, response, onSessionSwap } = opts; let session; let reconnectionHandle = null; if (!response) { session = createOfflineSessionStub(sessionTag); reconnectionHandle = startOfflineReconnection({ serverUrl: configuration.serverUrl, onReconnected: async () => { const resp = await api.getOrCreateSession({ tag: sessionTag, metadata, state }); if (!resp) throw new Error("Server unavailable"); const realSession = api.sessionSyncClient(resp); onSessionSwap(realSession); return realSession; }, onNotify: (msg) => { console.log(msg); } }); return { session, reconnectionHandle, isOffline: true }; } else { session = api.sessionSyncClient(response); return { session, reconnectionHandle: null, isOffline: false }; } } export { setupOfflineReconnection as s };