Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3114-history-hit-rows.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
History search in the command palette now lands on what each row names: a message row opens the chat at its own turn, two hits in one turn are two rows, and a hit the current part does not hold is marked `Earlier part` instead of trying to scroll somewhere it cannot reach. When the 20-row cap hides more matches the group says how many and asks for one more word, and a Bot whose current part is a Session of its own no longer lists the same message twice ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)).
52 changes: 36 additions & 16 deletions core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ var ZH = {
Results: "结果",
"No results": "没有结果",
"Try a Bot name or words from a message": "试试 Bot 名字或消息里的词",
"Earlier part": "更早的 part",
"{count} more matches · add a word to narrow it": "还有 {count} 条 · 加一个词缩小范围",
// Bot exchange
"Bot exchange": "Bot 间对话",
"Bot exchange transcript": "Bot 间对话记录",
Expand Down Expand Up @@ -5813,6 +5815,7 @@ button:hover .bt-you{background:color-mix(in srgb,var(--bt-ink) 9%,var(--bt-side
:is(.bt-palette-row,.bt-palette-section,.bt-drop-list>.bt-option){position:relative;z-index:1}
.bt-palette-section{padding:8px 8px 4px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
.bt-palette-section:first-of-type{padding-top:0}
.bt-palette-note{padding:2px 8px 8px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
.bt-palette-row{flex:none;display:flex;align-items:center;gap:8px;height:49px;padding:6px 10px 6px 8px;border:0;border-radius:8px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer;box-sizing:border-box;width:100%}
.bt-palette-row[aria-selected=true]{background:var(--bt-active)}
.bt-palette-lead{flex:none;width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center}
Expand Down Expand Up @@ -16553,16 +16556,19 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
useEscape(close);
const ids = [...roster.bots.map(currentPart), ...roster.rooms.map((item) => item.id)];
const names = botNames(roster);
const chatOf2 = (id) => roster.byId[id]?.id ?? id;
const found = useSessions((list) => {
if (wanted.length < 2) return "[]";
if (wanted.length < 2) return '{"hits":[],"turns":{}}';
const hits = [];
const turns = {};
for (const id of ids) {
const outline = list.projectionsBySession?.[id]?.values?.turnOutline ?? list.byId[id]?.projectionValues?.turnOutline;
if (!Array.isArray(outline)) continue;
const hidden = roster.exchangeTurns[id] ?? [];
turns[chatOf2(id)] ??= outline.map((entry) => entry.turn);
const hidden2 = roster.exchangeTurns[id] ?? [];
for (let index2 = outline.length - 1; index2 >= 0 && hits.length < 30; index2 -= 1) {
const entry = outline[index2];
if (hidden.includes(entry.turn)) continue;
if (hidden2.includes(entry.turn)) continue;
for (const raw of [entry.response, entry.prompt]) {
const text2 = paletteText(raw, names);
const at = text2.toLowerCase().indexOf(wanted);
Expand All @@ -16573,7 +16579,7 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
}
}
}
return JSON.stringify(hits);
return JSON.stringify({ hits, turns });
});
const searchChats = actions.searchChats;
(0, import_react35.useEffect)(() => {
Expand All @@ -16585,8 +16591,8 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
const controller = new AbortController();
const timer = setTimeout(() => {
void searchChats(wanted, controller.signal).then(
(rows2) => {
if (current) setWholeText(Array.isArray(rows2) ? rows2 : []);
(value) => {
if (current) setWholeText({ rows: value?.rows ?? [], more: value?.more ?? 0 });
},
() => {
}
Expand Down Expand Up @@ -16633,31 +16639,44 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
run: () => actions.openAgent(agent.id)
}));
if (agents.length) sections.push(["DSH Agent", agents]);
const messages = JSON.parse(found).map(([id, turn, snippet]) => {
const outlineRead = JSON.parse(found);
const messages = outlineRead.hits.map(([id, turn, snippet]) => {
const bot = roster.byId[id];
const room2 = roster.roomsById[id];
return {
key: `${id}:${turn}`,
key: `${chatOf2(id)}:${turn}`,
title: bot?.name ?? room2?.name ?? t("Bot"),
subtitle: snippet,
avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }),
run: () => actions.openSession(id)
run: () => actions.openSession(id, { turn })
};
});
if (messages.length) sections.push([t("Messages"), messages]);
const outlined = new Set(messages.map((row) => row.key));
const fullText = (wholeText ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => {
const inPart = (chat, turn) => {
const held = outlineRead.turns?.[chat];
return Array.isArray(held) && held.length > 0 ? held.includes(turn) : void 0;
};
const keyCounts = /* @__PURE__ */ new Map();
const fullText = (wholeText?.rows ?? []).filter((row) => row?.chat !== void 0 && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map((row) => {
const bot = roster.byId[row.chat];
const room2 = roster.roomsById[row.chat];
const here = inPart(row.chat, row.turn);
const at = `${row.chat}:${row.turn}`;
const count = (keyCounts.get(at) ?? 0) + 1;
keyCounts.set(at, count);
return {
key: `${row.chat}:${row.turn}`,
key: count > 1 ? `${at}:${count}` : at,
title: bot?.name ?? room2?.name ?? t("Bot"),
subtitle: row.text,
avatar: bot ? (0, import_react35.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react35.createElement)(RoomAvatar, { room: room2, roster, size: 24 }),
run: () => actions.openSession(row.chat, { turn: row.turn })
badge: here === false ? t("Earlier part") : void 0,
run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn })
};
});
if (fullText.length) sections.push([t("Messages (full text)"), fullText]);
const hidden = wholeText?.more ?? 0;
const note = hidden > 0 ? t("{count} more matches · add a word to narrow it", { count: hidden }) : null;
if (fullText.length) sections.push([t("Messages (full text)"), fullText, note]);
const commands = [
{ key: "cmd:new", icon: (0, import_react35.createElement)(PlusIcon), title: t("New chat"), run: () => actions.openNewChat("new") },
{ key: "cmd:bot", icon: (0, import_react35.createElement)(PlusIcon), title: t("Create Bot"), run: () => actions.openNewChat("create") },
Expand Down Expand Up @@ -16733,7 +16752,7 @@ ${shown}`, { axis: "y", ...QUICK_EDGES });
(0, import_react35.createElement)("span", { className: "bt-palette-empty-icon", "aria-hidden": true }, (0, import_react35.createElement)(SearchIcon)),
(0, import_react35.createElement)("span", { className: "bt-palette-empty-label" }, t("No results")),
(0, import_react35.createElement)("span", { className: "bt-palette-empty-hint" }, t("Try a Bot name or words from a message"))
) : sections.map(([title, items]) => (0, import_react35.createElement)(
) : sections.map(([title, items, note2]) => (0, import_react35.createElement)(
import_react35.Fragment,
{ key: title },
(0, import_react35.createElement)("div", { className: "bt-palette-section", role: "presentation", "data-flip": `section:${title}` }, title),
Expand Down Expand Up @@ -16763,7 +16782,8 @@ ${shown}`, { axis: "y", ...QUICK_EDGES });
),
row.badge ? (0, import_react35.createElement)("span", { className: "bt-palette-badge" }, row.badge) : null
);
})
}),
note2 ? (0, import_react35.createElement)("div", { className: "bt-palette-note", role: "status" }, note2) : null
))
)
)
Expand Down Expand Up @@ -24014,7 +24034,7 @@ function apply(ctx) {
},
// The palette's whole-text message search (P-820): the host answers with the
// caller's own chats, whole lines with the turn they belong to.
searchChats: (query, signal) => call("chats.search", { query }, signal).then((value) => value?.rows ?? []),
searchChats: (query, signal) => call("chats.search", { query }, signal).then((value) => ({ rows: value?.rows ?? [], more: value?.more ?? 0 })),
// The conversation replacements withdraw for a plain Session; set the surface
// before the navigation so the Bot skin never flashes.
openAgentSession: (sessionId) => {
Expand Down
2 changes: 2 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ const ZH = {
Results: '结果',
'No results': '没有结果',
'Try a Bot name or words from a message': '试试 Bot 名字或消息里的词',
'Earlier part': '更早的 part',
'{count} more matches · add a word to narrow it': '还有 {count} 条 · 加一个词缩小范围',

// Bot exchange
'Bot exchange': 'Bot 间对话',
Expand Down
2 changes: 1 addition & 1 deletion core/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export function apply(ctx) {
},
// The palette's whole-text message search (P-820): the host answers with the
// caller's own chats, whole lines with the turn they belong to.
searchChats: (query, signal) => call('chats.search', { query }, signal).then(value => value?.rows ?? []),
searchChats: (query, signal) => call('chats.search', { query }, signal).then(value => ({ rows: value?.rows ?? [], more: value?.more ?? 0 })),
// The conversation replacements withdraw for a plain Session; set the surface
// before the navigation so the Bot skin never flashes.
openAgentSession: (sessionId) => {
Expand Down
43 changes: 31 additions & 12 deletions core/src/client/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
useEscape(close)
const ids = [...roster.bots.map(currentPart), ...roster.rooms.map(item => item.id)]
const names = botNames(roster)
const chatOf = (id) => roster.byId[id]?.id ?? id
const found = useSessions((list) => {
if (wanted.length < 2) return '[]'
if (wanted.length < 2) return '{"hits":[],"turns":{}}'
const hits = []
const turns = {}
for (const id of ids) {
const outline = list.projectionsBySession?.[id]?.values?.turnOutline ?? list.byId[id]?.projectionValues?.turnOutline
if (!Array.isArray(outline)) continue
turns[chatOf(id)] ??= outline.map(entry => entry.turn)
const hidden = roster.exchangeTurns[id] ?? []
for (let index = outline.length - 1; index >= 0 && hits.length < 30; index -= 1) {
const entry = outline[index]
Expand All @@ -53,7 +56,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
}
}
}
return JSON.stringify(hits)
return JSON.stringify({ hits, turns })
})
// The outline previews stop at 50/120 characters, so any hit past that budget is
// invisible to the read above (P-820). The host searches the whole text over the
Expand All @@ -69,7 +72,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
const controller = new AbortController()
const timer = setTimeout(() => {
void searchChats(wanted, controller.signal).then(
rows => { if (current) setWholeText(Array.isArray(rows) ? rows : []) },
value => { if (current) setWholeText({ rows: value?.rows ?? [], more: value?.more ?? 0 }) },
() => {},
)
}, SEARCH_DEBOUNCE_MS)
Expand All @@ -96,30 +99,45 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
run: () => actions.openAgent(agent.id),
}))
if (agents.length) sections.push(['DSH Agent', agents])
const messages = JSON.parse(found).map(([id, turn, snippet]) => {
const outlineRead = JSON.parse(found)
const messages = outlineRead.hits.map(([id, turn, snippet]) => {
const bot = roster.byId[id]
const room = roster.roomsById[id]
return {
key: `${id}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet,
key: `${chatOf(id)}:${turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: snippet,
avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }),
run: () => actions.openSession(id),
run: () => actions.openSession(id, { turn }),
}
})
if (messages.length) sections.push([t('Messages'), messages])
// The host's whole-text rows, newest first (P-820). A row the outline already found for
// the same chat and turn is the same message, so it is not shown twice; a row whose chat
// the roster does not hold is not the caller's to open.
const outlined = new Set(messages.map(row => row.key))
const fullText = (wholeText ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => {
// The current part's own turn numbers are the only proof the client has of what it holds; a
// chat whose outline has not loaded proves nothing, and is left unmarked.
const inPart = (chat, turn) => {
const held = outlineRead.turns?.[chat]
return Array.isArray(held) && held.length > 0 ? held.includes(turn) : undefined
}
const keyCounts = new Map()
const fullText = (wholeText?.rows ?? []).filter(row => row?.chat !== undefined && (roster.byId[row.chat] || roster.roomsById[row.chat]) && !outlined.has(`${row.chat}:${row.turn}`)).map(row => {
const bot = roster.byId[row.chat]
const room = roster.roomsById[row.chat]
const here = inPart(row.chat, row.turn)
const at = `${row.chat}:${row.turn}`
const count = (keyCounts.get(at) ?? 0) + 1
keyCounts.set(at, count)
return {
key: `${row.chat}:${row.turn}`, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text,
key: count > 1 ? `${at}:${count}` : at, title: bot?.name ?? room?.name ?? t('Bot'), subtitle: row.text,
avatar: bot ? h(BotAvatar, { bot, size: 24, badge: false, live: false }) : h(RoomAvatar, { room, roster, size: 24 }),
run: () => actions.openSession(row.chat, { turn: row.turn }),
badge: here === false ? t('Earlier part') : undefined,
run: here === false ? () => actions.openSession(row.chat) : () => actions.openSession(row.chat, { turn: row.turn }),
}
})
if (fullText.length) sections.push([t('Messages (full text)'), fullText])
const hidden = wholeText?.more ?? 0
const note = hidden > 0 ? t('{count} more matches · add a word to narrow it', { count: hidden }) : null
if (fullText.length) sections.push([t('Messages (full text)'), fullText, note])
const commands = [
{ key: 'cmd:new', icon: h(PlusIcon), title: t('New chat'), run: () => actions.openNewChat('new') },
{ key: 'cmd:bot', icon: h(PlusIcon), title: t('Create Bot'), run: () => actions.openNewChat('create') },
Expand Down Expand Up @@ -166,7 +184,7 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
h('span', { className: 'bt-palette-empty-icon', 'aria-hidden': true }, h(SearchIcon)),
h('span', { className: 'bt-palette-empty-label' }, t('No results')),
h('span', { className: 'bt-palette-empty-hint' }, t('Try a Bot name or words from a message')))
: sections.map(([title, items]) => h(Fragment, { key: title },
: sections.map(([title, items, note]) => h(Fragment, { key: title },
h('div', { className: 'bt-palette-section', role: 'presentation', 'data-flip': `section:${title}` }, title),
items.map((row) => {
index += 1
Expand All @@ -180,5 +198,6 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
h('span', { className: 'bt-palette-title' }, row.title),
row.subtitle ? h('span', { className: 'bt-palette-sub' }, row.subtitle) : null),
row.badge ? h('span', { className: 'bt-palette-badge' }, row.badge) : null)
}))))))
}),
note ? h('div', { className: 'bt-palette-note', role: 'status' }, note) : null)))))
}
1 change: 1 addition & 0 deletions core/src/client/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ button:hover .bt-you{background:color-mix(in srgb,var(--bt-ink) 9%,var(--bt-side
:is(.bt-palette-row,.bt-palette-section,.bt-drop-list>.bt-option){position:relative;z-index:1}
.bt-palette-section{padding:8px 8px 4px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
.bt-palette-section:first-of-type{padding-top:0}
.bt-palette-note{padding:2px 8px 8px;font-size:12px;line-height:16px;color:var(--bt-ink-3);flex:none}
.bt-palette-row{flex:none;display:flex;align-items:center;gap:8px;height:49px;padding:6px 10px 6px 8px;border:0;border-radius:8px;background:none;color:inherit;font:inherit;text-align:left;cursor:pointer;box-sizing:border-box;width:100%}
.bt-palette-row[aria-selected=true]{background:var(--bt-active)}
.bt-palette-lead{flex:none;width:24px;height:24px;display:inline-flex;align-items:center;justify-content:center}
Expand Down
Loading
Loading