/** Attach to an existing editor session; this package never launches one. */ import { EditorClient } from './client.js'; import { LiveEditor } from './editor.js'; import { lazyChainProxy } from './lazy-proxy.js'; import { resolveSession, type ResolvedSession, type SessionResolutionDeps } from './session.js'; import { createLazySession } from './singleton.js'; import { editorMemberHint } from './member-hints.js'; export { LiveEditor, inferAssetKind, type PanelName } from './editor.js'; export { LiveEditorDocument } from './editor-document.js'; export type { AssetDownloadRequest, AssetDownloadResult, AssetFileOption, AssetSearchQuery, OnlineAsset } from './asset-library.js'; export type { DocumentGestureOptions, DocumentKeyOptions, DocumentPasteOptions } from './editor-document.js'; export { editorMemberHint, withEditorMemberHints } from './member-hints.js'; export { resolveSession, findProjectRootFrom, NO_SESSION_FOR_PROJECT, SESSION_MANIFEST_UNREADABLE } from './session.js'; export type { ResolvedSession, SessionResolutionDeps, SessionListingTransport } from './session.js'; export type { ActiveDocumentCapture, EditorView, PresentedEditorView } from '@volter/sdk'; export interface LiveBindings { editor: LiveEditor; } export interface LiveSession extends LiveBindings { session: ResolvedSession; } function bindTo(port: number): LiveBindings { const client = new EditorClient({ url: `http://127.0.0.1:${port}` }); return { editor: new LiveEditor(client) }; } /** Inspect the callable surface without connecting; calls fail on port zero. */ export function unconnectedBindings(): LiveBindings { return bindTo(0); } /** Attach only to the session serving the requested project's canonical path. */ export async function connect(projectDir?: string, deps?: SessionResolutionDeps): Promise { const session = await resolveSession(projectDir, deps); return { ...bindTo(session.port), session }; } const lazySession = createLazySession(() => connect()); export const editor: LiveEditor = lazyChainProxy(() => lazySession.ensure().then(s => s.editor), [], editorMemberHint);