























@@ -29,7 +29,6 @@ import {
2929import { getSlashCommands } from "./commands.js";
3030import { ChatLog } from "./components/chat-log.js";
3131import { CustomEditor } from "./components/custom-editor.js";
32-import { GatewayChatClient } from "./gateway-chat.js";
3332import { resolveLocalRunShutdownGraceMs } from "./local-run-shutdown.js";
3433import { editorTheme, theme } from "./theme/theme.js";
3534import type { TuiBackend } from "./tui-backend.js";
@@ -522,6 +521,8 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
522521let dynamicSlashCommandsKey: string | null = null;
523522let dynamicSlashCommandsInFlightKey: string | null = null;
524523let dynamicSlashCommandsRequestId = 0;
524+let dynamicSlashCommandsReady = false;
525+let dynamicSlashCommandsRefreshTimer: ReturnType<typeof setTimeout> | null = null;
525526let lastCtrlCAt = 0;
526527let exitRequested = false;
527528let exitResult: TuiResult = { exitReason: "exit" };
@@ -714,6 +715,7 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
714715const { EmbeddedTuiBackend } = await import("./embedded-backend.js");
715716client = new EmbeddedTuiBackend();
716717} else {
718+const { GatewayChatClient } = await import("./gateway-chat.js");
717719client = await GatewayChatClient.connect({
718720url: opts.url,
719721token: opts.token,
@@ -769,9 +771,19 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
769771);
770772};
771773774+const clearDynamicSlashCommandsRefreshTimer = () => {
775+if (!dynamicSlashCommandsRefreshTimer) {
776+return;
777+}
778+clearTimeout(dynamicSlashCommandsRefreshTimer);
779+dynamicSlashCommandsRefreshTimer = null;
780+};
781+772782const refreshDynamicSlashCommands = () => {
783+clearDynamicSlashCommandsRefreshTimer();
773784const key = resolveDynamicSlashCommandsKey();
774785if (
786+!dynamicSlashCommandsReady ||
775787!isConnected ||
776788!client.listCommands ||
777789dynamicSlashCommandsKey === key ||
@@ -807,9 +819,21 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
807819});
808820};
809821822+const scheduleDynamicSlashCommandsRefresh = () => {
823+if (
824+!dynamicSlashCommandsReady ||
825+dynamicSlashCommandsRefreshTimer ||
826+dynamicSlashCommandsKey === resolveDynamicSlashCommandsKey()
827+) {
828+return;
829+}
830+dynamicSlashCommandsRefreshTimer = setTimeout(refreshDynamicSlashCommands, 0);
831+dynamicSlashCommandsRefreshTimer.unref?.();
832+};
833+810834const updateAutocompleteProvider = () => {
811835applyAutocompleteProvider();
812-refreshDynamicSlashCommands();
836+scheduleDynamicSlashCommandsRefresh();
813837};
814838815839tui.addChild(root);
@@ -1474,6 +1498,8 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
147414984000,
14751499);
14761500tui.requestRender();
1501+dynamicSlashCommandsReady = true;
1502+scheduleDynamicSlashCommandsRefresh();
14771503if (!autoMessageSent && autoMessage) {
14781504autoMessageSent = true;
14791505await sendMessage(autoMessage);
@@ -1494,6 +1520,8 @@ export async function runTui(opts: RunTuiOptions): Promise<TuiResult> {
14941520dynamicSlashCommands = [];
14951521dynamicSlashCommandsKey = null;
14961522dynamicSlashCommandsInFlightKey = null;
1523+dynamicSlashCommandsReady = false;
1524+clearDynamicSlashCommandsRefreshTimer();
14971525dynamicSlashCommandsRequestId += 1;
14981526updateAutocompleteProvider();
14991527pauseStreamingWatchdog();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。