consortium
Version:
Remote control and session sharing CLI for AI coding agents
68 lines (63 loc) • 1.72 kB
JavaScript
;
var persistence = require('./types-B_i6lpTn.cjs');
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 = persistence.startOfflineReconnection({
serverUrl: persistence.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 };
}
}
exports.setupOfflineReconnection = setupOfflineReconnection;