refactor: register AI actions in native Cell toolbar; remove cell footer chain

This commit is contained in:
tao.chen
2026-07-23 10:30:15 +08:00
parent bb846d64fe
commit 0a05424b29
5 changed files with 26 additions and 415 deletions
+26 -10
View File
@@ -3,11 +3,15 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { INotebookTracker } from '@jupyterlab/notebook';
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
import { Cell, CodeCell } from '@jupyterlab/cells';
import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { Widget } from '@lumino/widgets';
import { installOpenCodeEverywhere } from './components/opencode_installer';
import { setOpenCodeRuntime } from './components/opencode_cell_footer';
import {
OpenCodeCellActions,
setOpenCodeRuntime
} from './components/opencode_cell_actions';
import { requestAPI } from './request';
import { readOpenCodeSettings } from './types';
import { callOpenCodeProviders } from './api/opencode_client';
@@ -19,19 +23,31 @@ const plugin: JupyterFrontEndPlugin<void> = {
id: 'opencode_bridge:plugin',
description: 'A JupyterLab extension bridging the UI to OpenCode Serve.',
autoStart: true,
optional: [ISettingRegistry],
requires: [INotebookTracker],
optional: [ISettingRegistry, IToolbarWidgetRegistry],
activate: (
app: JupyterFrontEnd,
tracker: INotebookTracker,
settingRegistry: ISettingRegistry | null
settingRegistry: ISettingRegistry | null,
toolbarRegistry: IToolbarWidgetRegistry | null
) => {
console.log('JupyterLab extension opencode_bridge is activated!');
// Install the per-cell footer factory on every notebook.
installOpenCodeEverywhere(tracker);
// Register the per-cell AI actions into the native Cell toolbar
// (top-right of the active cell, next to move up/down). Non-code
// cells get an empty widget so they show no AI buttons.
if (toolbarRegistry) {
toolbarRegistry.addFactory<Cell>(
'Cell',
'opencode-cell-actions',
(cell: Cell) => {
if (cell instanceof CodeCell) {
return new OpenCodeCellActions(cell);
}
return new Widget();
}
);
}
// Load settings + push into toolbar module.
// Load settings + push into the actions module.
if (settingRegistry) {
void settingRegistry
.load(plugin.id)