import { JupyterFrontEnd, JupyterFrontEndPlugin } from '@jupyterlab/application'; import { Widget } from '@lumino/widgets'; import { OpenCodeFloatingPanel } from './components/opencode_floating_panel'; import { requestAPI } from './request'; import { callOpenCodeProviders } from './api/opencode_client'; /** * Initialization data for the opencode_bridge extension. * * v5-floating: the per-cell AI button is gone. A single * OpenCodeFloatingPanel is attached to document.body and operates * against the JupyterLab shell's currently-active notebook. The model * is picked dynamically in the inline prompt. */ const plugin: JupyterFrontEndPlugin = { id: 'opencode_bridge:plugin', description: 'A JupyterLab extension bridging the UI to OpenCode Serve.', autoStart: true, activate: (app: JupyterFrontEnd) => { console.log('JupyterLab extension opencode_bridge is activated!'); // Mount the floating AI button on the body. The panel itself is // hidden until the user clicks the button. const floating = new OpenCodeFloatingPanel({ app, serverSettings: app.serviceManager.serverSettings, providers: null }); Widget.attach(floating, document.body); // Fetch available providers once at activation and cache them for // the inline prompt's model picker. Failure is non-fatal (the // picker hides). Also push the payload into the floating panel so // the prompt can render selects without an extra round trip. void callOpenCodeProviders(app.serviceManager.serverSettings) .then(data => { floating.setProviders(data); const lines: string[] = [ '[opencode_bridge] Available OpenCode providers:' ]; for (const p of data.providers) { const models = Object.values(p.models) .map(m => m.id) .join(', '); lines.push(` - ${p.id}: ${models || '(no models)'}`); } console.log(lines.join('\n')); }) .catch(reason => { console.warn( '[opencode_bridge] Could not fetch providers (is the opencode-bridge server extension enabled and opencode serve running?):', reason ); }); requestAPI('hello', app.serviceManager.serverSettings) .then(data => { console.log('hello endpoint:', data); }) .catch(reason => { console.error( `The opencode_bridge server extension appears to be missing.\n${reason}` ); }); } }; export default plugin;