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/3139-palette-fulltext-search.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The command palette now searches the whole text of a chat's messages, not only the opening the outline preview keeps: a word that appears past the first characters of a long reply lists a **Messages (full text)** group, and choosing a row opens that chat at the turn the line came from ([#3139](https://github.com/ThinkFlowLab/FlyBot/issues/3139)).
59 changes: 58 additions & 1 deletion core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ var ZH = {
"Rejected for {name}": "已拒绝 {name} 的请求",
// Command palette
Messages: "消息",
"Messages (full text)": "消息(全文)",
Commands: "命令",
"Search Bots, chats and messages": "搜索 Bot、对话和消息",
"Clear search": "清除搜索",
Expand Down Expand Up @@ -15879,10 +15880,12 @@ var import_react33 = require("react");
var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
var paletteText = (raw, names) => readableLine(String(raw ?? ""), names);
var PALETTE_EXIT_MS = 160;
var SEARCH_DEBOUNCE_MS = 150;
function CommandPalette({ start, token, roster, actions, useSessions }) {
const [query, setQuery] = (0, import_react33.useState)(start ?? "");
const [cursor, setCursor] = (0, import_react33.useState)(0);
const [leaving, setLeaving] = (0, import_react33.useState)(false);
const [wholeText, setWholeText] = (0, import_react33.useState)(null);
const wanted = query.trim().toLowerCase();
const close = () => {
if (leaving) return;
Expand Down Expand Up @@ -15914,6 +15917,29 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
}
return JSON.stringify(hits);
});
const searchChats = actions.searchChats;
(0, import_react33.useEffect)(() => {
if (wanted.length < 2 || !searchChats) {
setWholeText(null);
return void 0;
}
let current = true;
const controller = new AbortController();
const timer = setTimeout(() => {
void searchChats(wanted, controller.signal).then(
(rows2) => {
if (current) setWholeText(Array.isArray(rows2) ? rows2 : []);
},
() => {
}
);
}, SEARCH_DEBOUNCE_MS);
return () => {
current = false;
clearTimeout(timer);
controller.abort();
};
}, [wanted, searchChats]);
const matchesName = (...fields) => wanted === "" || fields.some((field) => (field ?? "").toLowerCase().includes(wanted));
const sections = [];
const people2 = [
Expand Down Expand Up @@ -15961,6 +15987,19 @@ function CommandPalette({ start, token, roster, actions, useSessions }) {
};
});
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 bot = roster.byId[row.chat];
const room2 = roster.roomsById[row.chat];
return {
key: `${row.chat}:${row.turn}`,
title: bot?.name ?? room2?.name ?? t("Bot"),
subtitle: row.text,
avatar: bot ? (0, import_react33.createElement)(BotAvatar, { bot, size: 24, badge: false, live: false }) : (0, import_react33.createElement)(RoomAvatar, { room: room2, roster, size: 24 }),
run: () => actions.openSession(row.chat, { turn: row.turn })
};
});
if (fullText.length) sections.push([t("Messages (full text)"), fullText]);
const commands = [
{ key: "cmd:new", icon: (0, import_react33.createElement)(PlusIcon), title: t("New chat"), run: () => actions.openNewChat("new") },
{ key: "cmd:bot", icon: (0, import_react33.createElement)(PlusIcon), title: t("Create Bot"), run: () => actions.openNewChat("create") },
Expand Down Expand Up @@ -23229,19 +23268,37 @@ function apply(ctx) {
for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id);
return ids;
};
const seekTurn = (turn) => {
if (!Number.isInteger(turn) || turn < 0 || typeof document === "undefined") return;
let tries = 0;
const seek = () => {
const node = document.querySelector(`[data-chat-turn="${turn}"]`);
if (node !== null) {
node.scrollIntoView({ block: "center" });
return;
}
if ((tries += 1) > 20) return;
setTimeout(seek, 100);
};
seek();
};
const actions = {
// The full-pane overlays sit above the conversation, so opening one must dismiss them
// or the click appears to do nothing.
isAgentSession: (id) => isAgentSessionId(id),
openSession: (id) => {
openSession: (id, { turn } = {}) => {
noteNavigation("openSession", id);
if (isAgentSessionId(id)) return actions.openAgentSession(id);
ui2.set((state) => state.newChat || state.exchange || state.menu || state.palette ? { ...state, newChat: null, exchange: null, menu: null, palette: null } : state);
setPlain(false);
const target = partFor(id);
expected = target;
ctx.uiWorkspace.openSession(target);
seekTurn(turn);
},
// 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 ?? []),
// The conversation replacements withdraw for a plain Session; set the surface
// before the navigation so the Bot skin never flashes.
openAgentSession: (sessionId) => {
Expand Down
1 change: 1 addition & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ const ZH = {
'Rejected for {name}': '已拒绝 {name} 的请求',
// Command palette
Messages: '消息',
'Messages (full text)': '消息(全文)',
Commands: '命令',
'Search Bots, chats and messages': '搜索 Bot、对话和消息',
'Clear search': '清除搜索',
Expand Down
21 changes: 20 additions & 1 deletion core/src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,26 @@ export function apply(ctx) {
for (const [id, owner] of pendingAdopt) if (owner === agentId && !ids.includes(id)) ids.push(id)
return ids
}
// The palette's whole-text rows name the turn the hit belongs to (P-820). DSH opens a
// session by id only, so the turn is found where the message pills already look: the
// flow's own DOM. A turn the host has not loaded lands on the nearest view — the row's
// snippet still shows the words — and the seek gives up rather than spin.
const seekTurn = (turn) => {
if (!Number.isInteger(turn) || turn < 0 || typeof document === 'undefined') return
let tries = 0
const seek = () => {
const node = document.querySelector(`[data-chat-turn="${turn}"]`)
if (node !== null) { node.scrollIntoView({ block: 'center' }); return }
if ((tries += 1) > 20) return
setTimeout(seek, 100)
}
seek()
}
const actions = {
// The full-pane overlays sit above the conversation, so opening one must dismiss them
// or the click appears to do nothing.
isAgentSession: id => isAgentSessionId(id),
openSession: (id) => {
openSession: (id, { turn } = {}) => {
noteNavigation('openSession', id)
// A DSH Agent Session id lands on the plain surface, not the Bot skin.
if (isAgentSessionId(id)) return actions.openAgentSession(id)
Expand All @@ -427,7 +442,11 @@ export function apply(ctx) {
const target = partFor(id)
expected = target
ctx.uiWorkspace.openSession(target)
seekTurn(turn)
},
// 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 ?? []),
// The conversation replacements withdraw for a plain Session; set the surface
// before the navigation so the Bot skin never flashes.
openAgentSession: (sessionId) => {
Expand Down
38 changes: 38 additions & 0 deletions core/src/client/palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import { seatedCount } from './group-settings.js'
// a delegation trace and a fence are routing or data, never the row (#1347).
const paletteText = (raw, names) => readableLine(String(raw ?? ''), names)
const PALETTE_EXIT_MS = 160
// The whole-text search is a round-trip the host answers: a pause, so typing a query does
// not ask once per character.
const SEARCH_DEBOUNCE_MS = 150
export function CommandPalette({ start, token, roster, actions, useSessions }) {
const [query, setQuery] = useState(start ?? '')
const [cursor, setCursor] = useState(0)
const [leaving, setLeaving] = useState(false)
const [wholeText, setWholeText] = useState(null)
const wanted = query.trim().toLowerCase()
const close = () => {
if (leaving) return
Expand Down Expand Up @@ -51,6 +55,26 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
}
return JSON.stringify(hits)
})
// 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
// caller's own chats; an answer that lands for a query the user already changed is
// dropped with the effect that asked for it.
const searchChats = actions.searchChats
useEffect(() => {
if (wanted.length < 2 || !searchChats) {
setWholeText(null)
return undefined
}
let current = true
const controller = new AbortController()
const timer = setTimeout(() => {
void searchChats(wanted, controller.signal).then(
rows => { if (current) setWholeText(Array.isArray(rows) ? rows : []) },
() => {},
)
}, SEARCH_DEBOUNCE_MS)
return () => { current = false; clearTimeout(timer); controller.abort() }
}, [wanted, searchChats])
const matchesName = (...fields) => wanted === '' || fields.some(field => (field ?? '').toLowerCase().includes(wanted))
const sections = []
const people = [
Expand Down Expand Up @@ -82,6 +106,20 @@ export function CommandPalette({ start, token, roster, actions, useSessions }) {
}
})
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 => {
const bot = roster.byId[row.chat]
const room = roster.roomsById[row.chat]
return {
key: `${row.chat}:${row.turn}`, 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 }),
}
})
if (fullText.length) sections.push([t('Messages (full text)'), fullText])
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
5 changes: 5 additions & 0 deletions core/src/host/authz.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ export function install(rt) {
// writes keep their Session and target gates below, unchanged.
if (ep === 'schedules') return ALLOW

// The palette's whole-text search is the same shape (P-820): the ask names no Bot or
// room, and the answer is scoped per actor in the handler (`chats.search` in
// channel.js searches only the sessions the actor's own view holds).
if (ep === 'chats.search') return ALLOW

if (BOT_TARGETED.has(ep)) {
if (ep.startsWith('schedule-')) {
// The create endpoint keys off `body.target` (Bot or room id); `sessionId` is
Expand Down
30 changes: 29 additions & 1 deletion core/src/host/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { readQuietHours } from '../shared/quiet-hours.js'
import { readTurnBudget } from './turn-budget.js'
import { faceMentions } from './face-mentions.js'
import { visibleText } from '../shared/preview.js'
import { excerpt } from './text.js'

const NOTIFY_KINDS = ['approval', 'finished', 'failed']
const LANGUAGES = { zh: 'Chinese (简体中文)', en: 'English' }
Expand Down Expand Up @@ -239,7 +240,7 @@ export function install(rt) {
// `diagnostics-clear` is not a read: it truncates `<home>/logs/diagnostics.jsonl`, the file a bug
// report is meant to carry, so a host that only reads refuses it instead of erasing the evidence
// (#2302). `diagnostics` and `diagnostics-log` stay, because they only read that file.
const READS = new Set(['state', 'models', 'efforts', 'earlier', 'room-progress', 'room-history', 'exchange', 'usage', 'schedules', 'memory-view', 'browser-wait', 'browser-result', 'diagnostics', 'diagnostics-log', 'update-check', 'update-install', 'dsh-update-install', 'repo-stars', 'approval-answer', 'auth-whoami', 'workflows',
const READS = new Set(['state', 'models', 'efforts', 'earlier', 'chats.search', 'room-progress', 'room-history', 'exchange', 'usage', 'schedules', 'memory-view', 'browser-wait', 'browser-result', 'diagnostics', 'diagnostics-log', 'update-check', 'update-install', 'dsh-update-install', 'repo-stars', 'approval-answer', 'auth-whoami', 'workflows',
'tasks', 'projects', 'project-read', 'project-board', 'project-team', 'project-of', 'project-decision', 'project-memory',
'folders', 'folder-list', 'connector-app-status'])

Expand Down Expand Up @@ -356,6 +357,33 @@ export function install(rt) {
case 'earlier':
await rt.load()
return ok(await rt.earlierPage(String(body.sessionId ?? ''), body.cursor ?? undefined))
case 'chats.search': {
// The palette's whole-text rows (P-820). `view(actor)` is the narrowing `state` uses:
// it keeps the actor's own Bots, and also the other-owner Bots a shared room carries so
// the room renders. Those Bots' own chats are not room content, so only the sessions
// the actor owns are searched; a room's own parts stay, because the room is shared.
await rt.load()
const query = String(body.query ?? '')
const scoped = view(actor)
const sessionToChat = new Map()
for (const bot of scoped.bots) for (const part of [bot.sessionId, ...(bot.parts ?? [])]) {
if (rt.authzEnforced?.() && !rt.sessionOwnedBy?.(actor, part)) continue
sessionToChat.set(part, bot.id)
}
for (const room of scoped.rooms) for (const part of room.parts ?? []) if (!sessionToChat.has(part)) sessionToChat.set(part, room.id)
const { rows, more } = await rt.searchHomeChat([...sessionToChat.keys()], query)
const terms = [...new Set(query.toLowerCase().split(/\s+/).filter(Boolean))]
return ok({
rows: rows
.map(row => {
const lower = row.text.toLowerCase()
const wanted = terms.find(term => lower.includes(term)) ?? ''
return { chat: sessionToChat.get(row.session) ?? null, turn: row.turn, text: excerpt(row.text, wanted) }
})
.filter(row => row.chat !== null),
more,
})
}
case 'usage':
await rt.load()
return ok(await rt.usageView({ timeZone: typeof body.timeZone === 'string' ? body.timeZone.slice(0, 64) : undefined }))
Expand Down
Loading
Loading