feat: fully dynamic model picker in inline prompt
This commit is contained in:
@@ -5,9 +5,10 @@
|
||||
*
|
||||
* Registered in index.ts via IToolbarWidgetRegistry.addFactory('Cell', ...).
|
||||
*
|
||||
* The frontend does NO semantic processing: it gathers the cell's source /
|
||||
* outputs / error, attaches the user's freeform instruction, and POSTs to
|
||||
* the server. The server (and the LLM it forwards to) decides what to do.
|
||||
* v3-final: the frontend does NO semantic processing. It gathers the cell's
|
||||
* source / outputs / error, attaches the user's freeform instruction, and
|
||||
* POSTs to the server. The chosen provider/model comes from the inline
|
||||
* picker (no settings-based default).
|
||||
*/
|
||||
import type { CodeCell } from '@jupyterlab/cells';
|
||||
import { Notification } from '@jupyterlab/apputils';
|
||||
@@ -19,23 +20,27 @@ import { callOpenCodeEdit } from '../api/opencode_client';
|
||||
import { extractCellContext } from '../context/cell_context';
|
||||
import type {
|
||||
CellContext,
|
||||
OpenCodeProvidersResponse,
|
||||
OpenCodeRequest,
|
||||
OpenCodeResponse,
|
||||
OpenCodeSettings
|
||||
OpenCodeResponse
|
||||
} from '../types';
|
||||
|
||||
import { OpenCodeInlinePrompt } from './opencode_inline_prompt';
|
||||
|
||||
// Module-level runtime injection (set by index.ts after settings load).
|
||||
let _settings: OpenCodeSettings | null = null;
|
||||
// Module-level runtime injection (set by index.ts after activation).
|
||||
let _serverSettings: ServerConnection.ISettings | null = null;
|
||||
let _providers: OpenCodeProvidersResponse | null = null;
|
||||
|
||||
export function setOpenCodeRuntime(args: {
|
||||
settings: OpenCodeSettings;
|
||||
serverSettings: ServerConnection.ISettings;
|
||||
}): void {
|
||||
_settings = args.settings;
|
||||
_serverSettings = args.serverSettings;
|
||||
export function setOpenCodeServerSettings(
|
||||
serverSettings: ServerConnection.ISettings
|
||||
): void {
|
||||
_serverSettings = serverSettings;
|
||||
}
|
||||
|
||||
export function setOpenCodeProviders(
|
||||
p: OpenCodeProvidersResponse | null
|
||||
): void {
|
||||
_providers = p;
|
||||
}
|
||||
|
||||
type Status = 'idle' | 'loading';
|
||||
@@ -108,8 +113,9 @@ export class OpenCodeCellActions extends Widget {
|
||||
}
|
||||
const prompt = new OpenCodeInlinePrompt(this._cell, {
|
||||
disabled: !this._context || this._status === 'loading',
|
||||
onSubmit: (text: string) => {
|
||||
void this._onSubmit(text);
|
||||
providers: _providers,
|
||||
onSubmit: (text: string, providerId?: string, modelId?: string) => {
|
||||
void this._onSubmit(text, providerId, modelId);
|
||||
},
|
||||
onCancel: () => {
|
||||
this._hidePrompt();
|
||||
@@ -126,20 +132,24 @@ export class OpenCodeCellActions extends Widget {
|
||||
}
|
||||
}
|
||||
|
||||
private async _onSubmit(text: string): Promise<void> {
|
||||
private async _onSubmit(
|
||||
text: string,
|
||||
providerId?: string,
|
||||
modelId?: string
|
||||
): Promise<void> {
|
||||
if (!this._context) {
|
||||
return;
|
||||
}
|
||||
if (!_settings || !_serverSettings) {
|
||||
Notification.error('OpenCode 运行时未初始化,请检查 settings');
|
||||
if (!_serverSettings) {
|
||||
Notification.error('OpenCode 运行时未初始化');
|
||||
return;
|
||||
}
|
||||
|
||||
const request: OpenCodeRequest = {
|
||||
prompt: text,
|
||||
context: this._context,
|
||||
providerId: _settings.opencodeProvider || undefined,
|
||||
modelId: _settings.opencodeModel || undefined
|
||||
providerId,
|
||||
modelId
|
||||
};
|
||||
|
||||
this._status = 'loading';
|
||||
|
||||
Reference in New Issue
Block a user