





















@@ -205,6 +205,9 @@ function openChatSessionPicker(state: AppViewState, surface: ChatSessionSelectSu
205205state.chatSessionPickerOpen = true;
206206state.chatSessionPickerSurface = surface;
207207state.chatSessionPickerError = null;
208+if (!state.chatSessionPickerResult && !state.chatSessionPickerAppliedQuery) {
209+void loadChatSessionPickerPage(state);
210+}
208211requestHostUpdate(state);
209212focusChatSessionPickerSearch(state);
210213}
@@ -216,6 +219,18 @@ function closeChatSessionPicker(state: AppViewState) {
216219requestHostUpdate(state);
217220}
218221222+export function resetChatSessionPickerState(state: AppViewState) {
223+clearChatSessionPickerSearchTimer(state);
224+invalidateChatSessionPickerSearchRequests(state);
225+state.chatSessionPickerOpen = false;
226+state.chatSessionPickerSurface = null;
227+state.chatSessionPickerQuery = "";
228+state.chatSessionPickerAppliedQuery = "";
229+state.chatSessionPickerLoading = false;
230+state.chatSessionPickerError = null;
231+state.chatSessionPickerResult = null;
232+}
233+219234function toggleChatSessionPicker(state: AppViewState, surface: ChatSessionSelectSurface) {
220235if (state.chatSessionPickerOpen && state.chatSessionPickerSurface === surface) {
221236closeChatSessionPicker(state);
@@ -238,6 +253,20 @@ function createChatSessionPickerRequestParams(
238253configuredAgentsOnly: overrides.configuredAgentsOnly,
239254limit: overrides.limit,
240255};
256+const activeAgentSession = parseAgentSessionKey(state.sessionKey);
257+const activeSessionRow = state.sessionsResult?.sessions.find(
258+(row) => row.key === state.sessionKey,
259+);
260+const isGlobalScopeSession =
261+activeSessionRow?.kind === "global" ||
262+activeSessionRow?.kind === "unknown" ||
263+state.sessionKey === "global" ||
264+state.sessionKey === "unknown";
265+if (activeAgentSession || !isGlobalScopeSession) {
266+params.agentId = normalizeAgentId(
267+activeAgentSession?.agentId ?? state.agentsList?.defaultId ?? "main",
268+);
269+}
241270const offset =
242271typeof overrides.offset === "number" && Number.isFinite(overrides.offset)
243272 ? Math.max(0, Math.floor(overrides.offset))
@@ -361,6 +390,9 @@ function clearChatSessionPickerSearch(state: AppViewState, options: { focus?: bo
361390state.chatSessionPickerResult = null;
362391state.chatSessionPickerLoading = false;
363392requestHostUpdate(state);
393+if (state.chatSessionPickerOpen) {
394+void loadChatSessionPickerPage(state);
395+}
364396if (options.focus ?? true) {
365397focusChatSessionPickerSearch(state);
366398}
@@ -394,7 +426,7 @@ function updateChatSessionPickerSearchQuery(state: AppViewState, nextQuery: stri
394426}
395427396428async function loadMoreChatSessionPickerResults(state: AppViewState) {
397-const result = resolveChatSessionPickerResult(state);
429+const result = state.chatSessionPickerResult;
398430const offset = resolveNextChatSessionOffset(result);
399431if (offset === null) {
400432return;
@@ -417,12 +449,30 @@ function resolveChatSessionRow(
417449}
418450419451function resolveChatSessionPickerResult(state: AppViewState): SessionsListResult | null {
420-if (state.chatSessionPickerResult || state.chatSessionPickerAppliedQuery) {
452+if (
453+state.chatSessionPickerResult ||
454+state.chatSessionPickerAppliedQuery ||
455+state.chatSessionPickerOpen
456+) {
421457return state.chatSessionPickerResult;
422458}
423459return state.sessionsResult;
424460}
425461462+function resolveChatSessionPickerRows(
463+state: AppViewState,
464+result: SessionsListResult | null,
465+): { row: SessionsListResult["sessions"][number]; label: string }[] {
466+const rowsByKey = new Map((result?.sessions ?? []).map((row) => [row.key, row] as const));
467+return resolveSessionOptionGroups(state, state.sessionKey, result)
468+.flatMap((group) => group.options)
469+.filter((option) => rowsByKey.has(option.key))
470+.map((option) => ({
471+row: rowsByKey.get(option.key)!,
472+label: option.label,
473+}));
474+}
475+426476function resolveSelectedChatSessionLabel(
427477state: AppViewState,
428478sessionGroups: SessionOptionGroup[],
@@ -497,15 +547,15 @@ function renderChatSessionPickerPopover(
497547pickerId: string,
498548) {
499549const result = resolveChatSessionPickerResult(state);
500-const rows = result?.sessions ?? [];
550+const pickerRows = resolveChatSessionPickerRows(state, result);
501551const controlsDisabled = !state.connected || !state.client;
502552const normalizedQuery = normalizeOptionalString(state.chatSessionPickerQuery) ?? "";
503553const searchPending = normalizedQuery !== state.chatSessionPickerAppliedQuery;
504554const loadMoreDisabled = controlsDisabled || state.chatSessionPickerLoading || searchPending;
505555const hasQuery =
506556state.chatSessionPickerQuery.trim() !== "" || state.chatSessionPickerAppliedQuery.trim() !== "";
507557const loadMoreOffset = resolveNextChatSessionOffset(result);
508-const shownCount = rows.length;
558+const shownCount = pickerRows.length;
509559const totalCount = result?.totalCount;
510560const countLabel =
511561typeof totalCount === "number" && Number.isFinite(totalCount)
@@ -578,17 +628,17 @@ function renderChatSessionPickerPopover(
578628 </div>`
579629 : ""}
580630 <div class="chat-session-picker__list" role="listbox">
581- ${state.chatSessionPickerLoading && rows.length === 0
631+ ${state.chatSessionPickerLoading && pickerRows.length === 0
582632 ? html`<div class="chat-session-picker__status">${t("common.loading")}</div>`
583633 : ""}
584- ${!state.chatSessionPickerLoading && rows.length === 0
634+ ${!state.chatSessionPickerLoading && pickerRows.length === 0
585635 ? html`<div class="chat-session-picker__status">${t("sessionsView.noSessions")}</div>`
586636 : ""}
587637 ${repeat(
588- rows,
589- (row) => row.key,
590- (row) => {
591- const label = resolveSessionDisplayName(row.key, row);
638+ pickerRows,
639+ (entry) => entry.row.key,
640+ (entry) => {
641+ const { row, label } = entry;
592642 const meta = formatChatSessionPickerMeta(row);
593643 const selected = row.key === state.sessionKey;
594644 return html`
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。