refactor: route channel runtime via plugin api
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { listChannelDocks } from "../channels/dock.js";
|
||||
import { getActivePluginRegistry } from "../plugins/runtime.js";
|
||||
import { listThinkingLevels } from "./thinking.js";
|
||||
import { COMMAND_ARG_FORMATTERS } from "./commands-args.js";
|
||||
import type { ChatCommandDefinition, CommandScope } from "./commands-registry.types.js";
|
||||
@@ -111,7 +112,12 @@ function assertCommandRegistry(commands: ChatCommandDefinition[]): void {
|
||||
}
|
||||
}
|
||||
|
||||
export const CHAT_COMMANDS: ChatCommandDefinition[] = (() => {
|
||||
let cachedCommands: ChatCommandDefinition[] | null = null;
|
||||
let cachedRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
|
||||
let cachedNativeCommandSurfaces: Set<string> | null = null;
|
||||
let cachedNativeRegistry: ReturnType<typeof getActivePluginRegistry> | null = null;
|
||||
|
||||
function buildChatCommands(): ChatCommandDefinition[] {
|
||||
const commands: ChatCommandDefinition[] = [
|
||||
defineChatCommand({
|
||||
key: "help",
|
||||
@@ -454,17 +460,28 @@ export const CHAT_COMMANDS: ChatCommandDefinition[] = (() => {
|
||||
|
||||
assertCommandRegistry(commands);
|
||||
return commands;
|
||||
})();
|
||||
}
|
||||
|
||||
let cachedNativeCommandSurfaces: Set<string> | null = null;
|
||||
export function getChatCommands(): ChatCommandDefinition[] {
|
||||
const registry = getActivePluginRegistry();
|
||||
if (cachedCommands && registry === cachedRegistry) return cachedCommands;
|
||||
const commands = buildChatCommands();
|
||||
cachedCommands = commands;
|
||||
cachedRegistry = registry;
|
||||
cachedNativeCommandSurfaces = null;
|
||||
return commands;
|
||||
}
|
||||
|
||||
export const getNativeCommandSurfaces = (): Set<string> => {
|
||||
if (!cachedNativeCommandSurfaces) {
|
||||
cachedNativeCommandSurfaces = new Set(
|
||||
listChannelDocks()
|
||||
.filter((dock) => dock.capabilities.nativeCommands)
|
||||
.map((dock) => dock.id),
|
||||
);
|
||||
export function getNativeCommandSurfaces(): Set<string> {
|
||||
const registry = getActivePluginRegistry();
|
||||
if (cachedNativeCommandSurfaces && registry === cachedNativeRegistry) {
|
||||
return cachedNativeCommandSurfaces;
|
||||
}
|
||||
cachedNativeCommandSurfaces = new Set(
|
||||
listChannelDocks()
|
||||
.filter((dock) => dock.capabilities.nativeCommands)
|
||||
.map((dock) => dock.id),
|
||||
);
|
||||
cachedNativeRegistry = registry;
|
||||
return cachedNativeCommandSurfaces;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user