mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-08-28 06:43:51 +03:00
feat(webui): add tabbed pane workbench (#5322)
This commit is contained in:
@@ -73,6 +73,7 @@ type SessionUpdateHandler = (
|
||||
scope?: SessionUpdateScope,
|
||||
workspaceScope?: WorkspaceScopePayload,
|
||||
) => void;
|
||||
type SidebarStateUpdateHandler = (state: SidebarStatePayload) => void;
|
||||
type RunStatusHandler = (chatId: string, startedAt: number | null) => void;
|
||||
|
||||
/** Structured errors surfaced to the UI.
|
||||
@@ -178,6 +179,7 @@ export class NanobotClient {
|
||||
private statusHandlers = new Set<StatusHandler>();
|
||||
private runtimeModelHandlers = new Set<RuntimeModelHandler>();
|
||||
private sessionUpdateHandlers = new Set<SessionUpdateHandler>();
|
||||
private sidebarStateUpdateHandlers = new Set<SidebarStateUpdateHandler>();
|
||||
private runStatusHandlers = new Set<RunStatusHandler>();
|
||||
private errorHandlers = new Set<ErrorHandler>();
|
||||
// chat_id -> handlers listening on it
|
||||
@@ -275,6 +277,13 @@ export class NanobotClient {
|
||||
};
|
||||
}
|
||||
|
||||
onSidebarStateUpdate(handler: SidebarStateUpdateHandler): Unsubscribe {
|
||||
this.sidebarStateUpdateHandlers.add(handler);
|
||||
return () => {
|
||||
this.sidebarStateUpdateHandlers.delete(handler);
|
||||
};
|
||||
}
|
||||
|
||||
onRunStatus(handler: RunStatusHandler): Unsubscribe {
|
||||
this.runStatusHandlers.add(handler);
|
||||
for (const [chatId, startedAt] of this.runStartedAtByChatId) {
|
||||
@@ -1149,6 +1158,11 @@ export class NanobotClient {
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed.event === "sidebar_state_updated") {
|
||||
this.emitSidebarStateUpdate(parsed.state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed.event === "error" && parsed.detail === "workspace_scope_rejected") {
|
||||
this.emitError({
|
||||
kind: "workspace_scope_rejected",
|
||||
@@ -1198,6 +1212,12 @@ export class NanobotClient {
|
||||
}
|
||||
}
|
||||
|
||||
private emitSidebarStateUpdate(state: SidebarStatePayload): void {
|
||||
for (const handler of this.sidebarStateUpdateHandlers) {
|
||||
handler(state);
|
||||
}
|
||||
}
|
||||
|
||||
private emitRunStatus(chatId: string, startedAt: number | null): void {
|
||||
for (const handler of this.runStatusHandlers) {
|
||||
handler(chatId, startedAt);
|
||||
|
||||
Reference in New Issue
Block a user