@luziyang2026/dsh-question-nav 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +176 -340
- package/lib/client.js.map +1 -1
- package/lib/index.js +93 -3
- package/lib/types/client/QuestionNavStrip.d.ts +9 -3
- package/lib/types/client/index.d.ts +9 -8
- package/lib/types/client/locales.d.ts +0 -6
- package/lib/types/core/nodes.d.ts +0 -7
- package/lib/types/core/question-entry.d.ts +17 -0
- package/lib/types/core/turn-dots.d.ts +48 -0
- package/lib/types/index.d.ts +17 -6
- package/lib/types/projection.d.ts +38 -0
- package/package.json +8 -4
- package/src/client/QuestionNavStrip.tsx +76 -118
- package/src/client/index.ts +20 -46
- package/src/client/locales.ts +0 -6
- package/src/client/question-nav.module.css +15 -24
- package/src/core/nodes.ts +0 -14
- package/src/core/question-entry.ts +17 -0
- package/src/core/turn-dots.ts +98 -0
- package/src/index.ts +23 -6
- package/src/projection.ts +98 -0
- package/src/core/history-index.ts +0 -176
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["useState","useRef","styles","createPortal","DEFAULTS","kind"],"sources":["../src/core/nodes.ts","../src/client/QuestionNavStrip.tsx","../src/client/locales.ts","../src/core/jump.ts","../src/core/history-index.ts","../src/client/index.ts"],"sourcesContent":["/**\n * Pure node-indexing logic for the question-nav plugin. No React, no DOM, no\n * Cordis — every function here is a pure transform over chat-node data so it\n * can be unit-tested in isolation (and reused by the browser half).\n */\n\n/** One user question as shown in the strip and targeted by a jump. */\nexport interface QuestionNode {\n /** Chat anchor key, matches a `[data-chat-anchor-key]` row in the scrollport. */\n key: string\n /** Monotone anchor sequence for ordering and window-min detection. */\n anchorSeq: number\n /** Event seq of the user message. */\n seq: number\n /** Unix ms timestamp. */\n time: number\n /** Full question text — shown in the hover tooltip (not truncated). */\n text: string\n}\n\n/** Minimal shape a chat node must expose for indexing (structural, not SDK-bound). */\nexport interface ChatNodeLike {\n key: string\n anchorSeq: number\n visibility?: string\n kind?: string\n /** Kind-specific payload (a UserMessageNode for `user`/`steering`). */\n data?: unknown\n}\n\n/** Kinds counted as a user question (turn-opening and steering admissions). */\nexport const QUESTION_KINDS = ['user', 'steering'] as const\n\n/** Narrow `node.data` to the user-message payload we read. */\ninterface UserDataLike {\n content?: readonly { type?: string; text?: string }[]\n seq?: number\n time?: number\n}\n\nfunction userData(data: unknown): UserDataLike | undefined {\n if (typeof data !== 'object' || data === null) return undefined\n return data as UserDataLike\n}\n\n/** First text block of a user message; falls back to the raw first block. */\nexport function messageText(content: readonly { type?: string; text?: string }[] | undefined): string {\n if (content === undefined || content.length === 0) return ''\n const first = content[0]\n if (typeof first?.text === 'string') return first.text\n return ''\n}\n\n/** Extract the user questions from a chat-node window, ordered by anchorSeq. */\nexport function extractQuestions(nodes: Iterable<ChatNodeLike>): QuestionNode[] {\n const out: QuestionNode[] = []\n for (const node of nodes) {\n if (!QUESTION_KINDS.includes(node.kind as (typeof QUESTION_KINDS)[number])) continue\n const payload = userData(node.data)\n out.push({\n key: node.key,\n anchorSeq: node.anchorSeq,\n seq: payload?.seq ?? -1,\n time: payload?.time ?? 0,\n // Full question text: shown in the hover tooltip (not truncated).\n text: messageText(payload?.content),\n })\n }\n out.sort((a, b) => a.anchorSeq - b.anchorSeq)\n return out\n}\n\n/** Whether a node is actually rendered (visible rows only are scroll targets). */\nexport function isRenderable(node: ChatNodeLike): boolean {\n return node.visibility !== 'hidden'\n}\n\n/** The row of the window that renders the given key (exact match). */\nexport function findQuestionRow(nodes: Iterable<ChatNodeLike>, key: string): ChatNodeLike | null {\n for (const node of nodes) {\n if (node.key === key) return node\n }\n return null\n}\n\n/** Nearest renderable row for a key that is absent or hidden (compaction, windowing). */\nexport function nearestRenderable(\n nodes: Iterable<{ key: string; anchorSeq: number; visibility?: string }>,\n excludeKey: string | undefined,\n): { key: string; anchorSeq: number } | null {\n let best: { key: string; anchorSeq: number } | null = null\n for (const node of nodes) {\n if (node.visibility === 'hidden') continue\n if (node.key === excludeKey) continue\n if (best === null || node.anchorSeq < best.anchorSeq) best = { key: node.key, anchorSeq: node.anchorSeq }\n }\n return best\n}\n\n/**\n * Merge two question sets (full-history index + live loaded window) into one\n * deduplicated, anchorSeq-ascending list. The window may hold questions that\n * arrived after the index was built; the index may hold questions the window\n * has not loaded yet — union on `key`, newest live copy wins per key.\n */\nexport function mergeQuestions(...sources: readonly (readonly QuestionNode[])[]): QuestionNode[] {\n const byKey = new Map<string, QuestionNode>()\n for (const source of sources) {\n for (const node of source) byKey.set(node.key, node)\n }\n return [...byKey.values()].sort((a, b) => a.anchorSeq - b.anchorSeq)\n}\n","/**\n * Question-nav minimap. Renders a vertical column of small round dots overlaid\n * on the LEFT edge of the conversation column (via the frame-wide\n * `shell.overlay` floating layer), vertically centered: one dot per user\n * question, enlarge on hover. The instant tooltip (a portal-rendered overlay,\n * no native-title delay) shows the question's full text; clicking a dot scrolls\n * the chat to that question.\n *\n * Index strategy (no render-window expansion): the dots cover the WHOLE\n * session history. The index is built from the raw `session.history` RPC via\n * the injected `fetchQuestionIndex` — the conversation's paged window is\n * untouched, so DSH's memory economy is preserved. The loaded window's live\n * questions are merged on top (for new messages arriving after the index was\n * built). Clicking a dot jumps through the existing paging loop, which calls\n * `loadOlder()` only until that specific page is in the window. If the index\n * safety budget is exhausted, a dimmed dashed \"load earlier\" dot appears above\n * the oldest question and continues the index on click.\n *\n * Data arrives through the four props shares: the framework `useSessions`\n * hook (current session), the registrant inject face (read/subscribe/jump/\n * fetch-index), and the bound locale translator.\n */\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { SessionId } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: pulls the ui-layout SlotMap merge ('shell.overlay').\nimport type {} from '@deepseek-ai/dsh-client-ui-layout/client'\nimport type { QuestionNode } from '../core/nodes.ts'\nimport { mergeQuestions } from '../core/nodes.ts'\nimport type { JumpFailureCode } from '../core/jump.ts'\nimport type { HistoryIndexOptions, HistoryIndexResult } from '../core/history-index.ts'\nimport type { QuestionNavKey } from './locales.ts'\nimport styles from './question-nav.module.css'\n\n/** Values the registrant inject face supplies (wired in src/client/index.ts). */\nexport interface QuestionNavInjected {\n /** Extract the user questions of a session's currently loaded window. */\n readQuestions: (sessionId: SessionId) => QuestionNode[]\n /** Subscribe to the session list; returns an unsubscribe. */\n subscribeList: (cb: () => void) => () => void\n /** Subscribe to a session's content; returns an unsubscribe. */\n subscribeContent: (sessionId: SessionId, cb: () => void) => () => void\n /** Jump the chat to a question row (pages the window on demand). */\n jump: (sessionId: SessionId, key: string) => void\n /** Build the full-session question index from the raw history RPC. */\n fetchQuestionIndex: (sessionId: SessionId, options?: HistoryIndexOptions) => Promise<HistoryIndexResult>\n}\n\ntype ComponentProps = PropsRuntime<'shell.overlay'> & QuestionNavInjected & PropsLocale<'question-nav'>\n\nconst FAILURE_HINTS: Record<JumpFailureCode, QuestionNavKey> = {\n VIEW_INACTIVE: 'jump.inactive',\n TARGET_HIDDEN: 'jump.hidden',\n NOT_FOUND: 'jump.notfound',\n TIMEOUT: 'jump.timeout',\n}\n\n/** Live position of the instant hover tooltip. */\ninterface TooltipState {\n text: string\n left: number\n top: number\n}\n\nfunction findConvRoot(): HTMLElement | null {\n return document.querySelector<HTMLElement>('[data-slot=\"conversation\"] > div[data-phase]')\n}\n\nexport function QuestionNavStrip(props: ComponentProps): React.JSX.Element | null {\n const current = props.useSessions((s) => s.current)\n const summary = props.useSessions((s) => (s.current === undefined ? undefined : s.byId[s.current]))\n const visible = current !== undefined && summary !== undefined && summary.blank !== true\n\n const [questions, setQuestions] = useState<QuestionNode[]>([])\n const [jumpingKey, setJumpingKey] = useState<string | null>(null)\n const [hint, setHint] = useState<string | null>(null)\n const [tooltip, setTooltip] = useState<TooltipState | null>(null)\n const [loadingIndex, setLoadingIndex] = useState(false)\n const [moreAvailable, setMoreAvailable] = useState(false)\n const panelRef = useRef<HTMLDivElement | null>(null)\n const hintTimerRef = useRef<number | null>(null)\n /** Full-history index from the raw RPC (per current session). */\n const indexRef = useRef<QuestionNode[]>([])\n /** Next beforeSeq to resume from when the index budget was exhausted. */\n const nextBeforeSeqRef = useRef<number | undefined>(undefined)\n /** Abort controller for the in-flight index build. */\n const indexAbortRef = useRef<AbortController | null>(null)\n /** Session whose index build is in flight, to avoid duplicate loops. */\n const buildingSessionRef = useRef<SessionId | null>(null)\n\n const showHint = (message: string): void => {\n setHint(message)\n if (hintTimerRef.current !== null) window.clearTimeout(hintTimerRef.current)\n hintTimerRef.current = window.setTimeout(() => setHint(null), 1800)\n }\n\n // Build the full-history index on show; refresh the live window on content\n // change and merge both into the dot list.\n useEffect(() => {\n if (!visible || current === undefined) {\n indexRef.current = []\n nextBeforeSeqRef.current = undefined\n indexAbortRef.current?.abort()\n indexAbortRef.current = null\n buildingSessionRef.current = null\n setQuestions([])\n setLoadingIndex(false)\n setMoreAvailable(false)\n return\n }\n const sessionId = current\n // Reset the per-session index: this effect re-runs on session change.\n indexRef.current = []\n nextBeforeSeqRef.current = undefined\n const refresh = (): void => {\n const windowQuestions = props.readQuestions(sessionId)\n setQuestions(mergeQuestions(indexRef.current, windowQuestions))\n }\n const startBuild = (options?: HistoryIndexOptions): void => {\n buildingSessionRef.current = sessionId\n const controller = new AbortController()\n indexAbortRef.current = controller\n setLoadingIndex(true)\n setMoreAvailable(false)\n props.fetchQuestionIndex(sessionId, { ...options, signal: controller.signal })\n .then((result) => {\n if (buildingSessionRef.current !== sessionId) return\n indexRef.current = mergeQuestions(result.questions, indexRef.current)\n nextBeforeSeqRef.current = result.nextBeforeSeq\n setMoreAvailable(result.code === 'BUDGET' && result.nextBeforeSeq !== undefined)\n refresh()\n })\n .finally(() => {\n if (buildingSessionRef.current === sessionId) {\n setLoadingIndex(false)\n if (indexAbortRef.current === controller) indexAbortRef.current = null\n buildingSessionRef.current = null\n }\n })\n }\n refresh()\n startBuild()\n const unsubContent = props.subscribeContent(sessionId, refresh)\n const unsubList = props.subscribeList(refresh)\n return () => {\n indexAbortRef.current?.abort()\n indexAbortRef.current = null\n unsubContent()\n unsubList()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [visible, current, props])\n\n // Listen for jump-failure events and surface the hint.\n useEffect(() => {\n const onJumpFailed = (event: Event): void => {\n const code = (event as CustomEvent<JumpFailureCode>).detail\n showHint(props.t(FAILURE_HINTS[code] ?? 'jump.timeout'))\n }\n window.addEventListener('question-nav:jump-failed', onJumpFailed)\n return () => window.removeEventListener('question-nav:jump-failed', onJumpFailed)\n }, [props])\n\n // Anchor the minimap to the conversation column: position it at the left\n // edge of the conversation root and reserve a thin rail with padding-left.\n useLayoutEffect(() => {\n if (!visible) return\n let raf = 0\n let retries = 0\n const applyLayout = (): void => {\n const panel = panelRef.current\n if (panel === null) return\n const frame = panel.closest('[data-shell-overlay]')?.parentElement ?? null\n const convRoot = findConvRoot()\n if (frame === null || convRoot === null) return\n const frameRect = frame.getBoundingClientRect()\n const convRect = convRoot.getBoundingClientRect()\n if (convRect.height <= 0) {\n if (retries < 20) {\n retries += 1\n raf = requestAnimationFrame(applyLayout)\n }\n return\n }\n retries = 0\n panel.style.top = `${convRect.top - frameRect.top}px`\n panel.style.height = `${convRect.height}px`\n panel.style.left = `${convRect.left - frameRect.left}px`\n }\n applyLayout()\n raf = requestAnimationFrame(applyLayout)\n const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(applyLayout)\n const convRoot = findConvRoot()\n observer?.observe(convRoot ?? document.body, { box: 'border-box' })\n window.addEventListener('resize', applyLayout)\n return () => {\n if (raf !== 0) cancelAnimationFrame(raf)\n observer?.disconnect()\n window.removeEventListener('resize', applyLayout)\n }\n }, [visible])\n\n // Clear any pending hint timer on unmount.\n useEffect(() => () => {\n if (hintTimerRef.current !== null) window.clearTimeout(hintTimerRef.current)\n }, [])\n\n if (!visible) return null\n\n const onJump = (node: QuestionNode): void => {\n if (current === undefined) return\n setJumpingKey(node.key)\n props.jump(current, node.key)\n window.setTimeout(() => setJumpingKey((k) => (k === node.key ? null : k)), 600)\n }\n\n const onLoadMore = (): void => {\n if (current === undefined || nextBeforeSeqRef.current === undefined) return\n setMoreAvailable(false)\n setLoadingIndex(true)\n props.fetchQuestionIndex(current, { startBeforeSeq: nextBeforeSeqRef.current })\n .then((result) => {\n if (current === undefined) return\n indexRef.current = mergeQuestions(result.questions, indexRef.current)\n nextBeforeSeqRef.current = result.nextBeforeSeq\n setMoreAvailable(result.code === 'BUDGET' && result.nextBeforeSeq !== undefined)\n setQuestions(mergeQuestions(indexRef.current, props.readQuestions(current)))\n })\n .finally(() => setLoadingIndex(false))\n }\n\n const t = props.t\n\n return (\n <div ref={panelRef} className={styles.rail} data-question-nav=\"rail\">\n {hint !== null ? <div className={styles.hint} role=\"status\">{hint}</div> : null}\n <div className={styles.list}>\n {questions.length === 0 ? (\n <div className={styles.empty}>{loadingIndex ? t('strip.loadingAll') : t('strip.empty')}</div>\n ) : (\n <div className={styles.dots}>\n <span className={styles.count}>\n {questions.length}\n {loadingIndex ? <span className={styles.countLoading}>{t('strip.loadingSuffix')}</span> : null}\n </span>\n {moreAvailable && !loadingIndex ? (\n <button\n className={`${styles.dot} ${styles.moreDot}`}\n aria-label={t('strip.loadEarlier')}\n title={t('strip.loadEarlier')}\n onMouseEnter={(e) => {\n const r = e.currentTarget.getBoundingClientRect()\n setTooltip({ text: t('strip.loadEarlier'), left: r.right + 10, top: r.top })\n }}\n onMouseLeave={() => setTooltip(null)}\n onClick={onLoadMore}\n />\n ) : null}\n {questions.map((node) => (\n <button\n key={node.key}\n className={jumpingKey === node.key ? `${styles.dot} ${styles.active}` : styles.dot}\n aria-label={node.text}\n onMouseEnter={(e) => {\n const r = e.currentTarget.getBoundingClientRect()\n setTooltip({ text: node.text, left: r.right + 10, top: r.top })\n }}\n onMouseLeave={() => setTooltip(null)}\n onClick={() => onJump(node)}\n />\n ))}\n </div>\n )}\n </div>\n {tooltip !== null\n ? createPortal(\n <div className={styles.tooltip} style={{ left: tooltip.left, top: tooltip.top }}>\n {tooltip.text}\n </div>,\n document.body,\n )\n : null}\n </div>\n )\n}\n","/**\n * Locale dictionaries for the question-nav surface (zh/en). Registered under\n * the `question-nav` namespace; keys are consumed through the bound translator.\n */\nexport const zh = {\n 'strip.empty': '本会话还没有提问',\n 'strip.loadingAll': '正在加载全部历史…',\n 'strip.loadingSuffix': '…',\n 'strip.loadEarlier': '加载更早的问题',\n 'jump.inactive': '聊天视图未激活',\n 'jump.hidden': '目标无独立气泡,已定位到邻近内容',\n 'jump.notfound': '目标未加载或不存在(可能已压缩)',\n 'jump.timeout': '加载历史超时,可重试',\n} as const\n\nexport const en = {\n 'strip.empty': 'No questions in this session yet',\n 'strip.loadingAll': 'Loading full history…',\n 'strip.loadingSuffix': '…',\n 'strip.loadEarlier': 'Load earlier questions',\n 'jump.inactive': 'Chat view is not active',\n 'jump.hidden': 'No dedicated bubble; landed on nearby content',\n 'jump.notfound': 'Target not loaded or missing (maybe compacted)',\n 'jump.timeout': 'Timed out loading history; retry',\n} as const\n\nexport type QuestionNavKey = keyof typeof zh\n","/**\n * Jump-to-question orchestration. Pure-ish: takes injected ports (snapshot\n * read, loadOlder, DOM row lookup, view liveness, scroll, timers) so the\n * paging/timeout/fallback loop is unit-testable without a real browser or\n * session. The browser half wires these ports to ctx.sessions + the DOM.\n */\n\nimport { nearestRenderable } from './nodes.ts'\n\n/** The bits of a session snapshot the jump loop needs. */\nexport interface JumpSnapshot {\n openState: string\n hasMore: boolean\n loadingOlder: boolean\n /** Renderable chat rows as a key->renderable map (or iterable of rows). */\n rows: Iterable<{ key: string; anchorSeq: number; visibility?: string }>\n}\n\nexport interface JumpPorts {\n /** Read the current snapshot; undefined when the session/view is unavailable. */\n snapshot: () => JumpSnapshot | undefined\n /** Expand the window backwards; rejects/throws on failure. */\n loadOlder: () => Promise<void>\n /** True while the chat view is active (a `[data-chat-flow]` is mounted). */\n isViewActive: () => boolean\n /** Find the DOM row for a chat anchor key; null when not rendered. */\n findRow: (key: string) => HTMLElement | null\n /** Scroll a row into view at the top. */\n scrollIntoView: (row: HTMLElement) => void\n /** Monotonic ms clock. */\n now: () => number\n /** Async sleep. */\n sleep: (ms: number) => Promise<void>\n /** Report a terminal failure to the caller (for a hint). */\n report?: (code: JumpFailureCode, fallback?: boolean) => void\n}\n\nexport type JumpFailureCode = 'VIEW_INACTIVE' | 'TARGET_HIDDEN' | 'NOT_FOUND' | 'TIMEOUT'\n\nexport interface JumpResult {\n ok: boolean\n code?: JumpFailureCode\n /** True when we landed on a fallback row rather than the exact target. */\n fallback?: boolean\n}\n\nexport interface JumpOptions {\n /** Total wall-clock budget for loadOlder paging. */\n totalTimeoutMs?: number\n /** Max loadOlder pages before giving up. */\n maxPages?: number\n /** Poll interval for the row to render after it is known to be in the window. */\n rowWaitMs?: number\n /** Poll interval for state transitions (loadingOlder / openState). */\n pollMs?: number\n}\n\nconst DEFAULTS = {\n totalTimeoutMs: 15_000,\n maxPages: 100,\n rowWaitMs: 8_000,\n pollMs: 60,\n}\n\nfunction minAnchorSeq(rows: Iterable<{ anchorSeq: number }>): number | null {\n let min: number | null = null\n for (const row of rows) {\n if (min === null || row.anchorSeq < min) min = row.anchorSeq\n }\n return min\n}\n\nfunction renderable(rows: Iterable<{ key: string; anchorSeq: number; visibility?: string }>): { key: string; anchorSeq: number }[] {\n const out: { key: string; anchorSeq: number }[] = []\n for (const row of rows) {\n if (row.visibility === 'hidden') continue\n out.push({ key: row.key, anchorSeq: row.anchorSeq })\n }\n return out\n}\n\n/**\n * Jump to the row for `key`, paging older content until it is rendered (or the\n * budget is exhausted). Falls back to the nearest renderable row when the\n * exact row is hidden/absent.\n */\nexport async function jumpToQuestion(ports: JumpPorts, key: string, options: JumpOptions = {}): Promise<JumpResult> {\n const cfg = { ...DEFAULTS, ...options }\n const fail = (code: JumpFailureCode, fallback = false): JumpResult => {\n ports.report?.(code, fallback)\n return fallback ? { ok: false, code, fallback: true } : { ok: false, code }\n }\n\n if (!ports.isViewActive()) return fail('VIEW_INACTIVE')\n\n const deadline = ports.now() + cfg.totalTimeoutMs\n let pages = 0\n\n // Phase 1: page older until the key appears in the loaded window.\n while (true) {\n const snap = ports.snapshot()\n if (snap === undefined) return fail('VIEW_INACTIVE')\n const rows = renderable(snap.rows)\n if (rows.some((r) => r.key === key)) break\n if (snap.openState !== 'open') {\n if (snap.openState === 'error' || ports.now() > deadline) {\n return fail(snap.openState === 'error' ? 'VIEW_INACTIVE' : 'TIMEOUT')\n }\n await ports.sleep(cfg.pollMs)\n continue\n }\n if (snap.hasMore !== true) return fail('NOT_FOUND')\n if (pages >= cfg.maxPages || ports.now() > deadline) return fail('TIMEOUT')\n if (snap.loadingOlder) {\n await ports.sleep(cfg.pollMs)\n continue\n }\n const before = minAnchorSeq(rows)\n await ports.loadOlder()\n pages += 1\n const afterSnap = ports.snapshot()\n const after = minAnchorSeq(afterSnap === undefined ? [] : afterSnap.rows)\n if (after === null || (before !== null && after >= before)) return fail('NOT_FOUND')\n }\n\n // Phase 2: wait for the row to render, then scroll. Fall back if hidden.\n const waitedFor = async (rowKey: string): Promise<HTMLElement | null> => {\n for (let waited = 0; waited <= cfg.rowWaitMs; waited += cfg.pollMs) {\n if (!ports.isViewActive()) return null\n const row = ports.findRow(rowKey)\n if (row !== null) return row\n await ports.sleep(cfg.pollMs)\n }\n return null\n }\n\n const row = await waitedFor(key)\n if (row !== null) {\n ports.scrollIntoView(row)\n return { ok: true }\n }\n\n const snap = ports.snapshot()\n const fallback = nearestRenderable(snap === undefined ? [] : snap.rows, key)\n if (fallback !== null) {\n const fbRow = await waitedFor(fallback.key)\n if (fbRow !== null) {\n ports.scrollIntoView(fbRow)\n return fail('TARGET_HIDDEN', true)\n }\n }\n return fail('TARGET_HIDDEN', false)\n}\n","/**\n * Question-index builder over the raw session history RPC.\n *\n * DSH pages the rendered conversation window on purpose (memory economy):\n * `chat.nodes` only ever holds the loaded window, and force-expanding it\n * (repeated `loadOlder()`) materializes + renders the whole log — the exact\n * cost DSH's paging exists to avoid. This module instead builds a lightweight\n * index of every user question by paging the RAW history RPC (`session.history`\n * with `beforeSeq`), which reads the host log without touching the render\n * window at all. Only `{key, seq, time, text}` per question is retained.\n *\n * The chat anchor key is derived deterministically from the event — it equals\n * `conversationContextKey('input-message', String(event.data.id))` — so the\n * dots can target rows that are not loaded yet, and a click then pages the\n * window on demand (see `jump.ts`).\n *\n * Pure-ish: takes injected ports (one raw history page read, clocks) so it is\n * unit-testable without a browser or a live session.\n */\n\nimport type { QuestionNode } from './nodes.ts'\nimport { messageText } from './nodes.ts'\n\n/** Minimal shape of a raw history event (structural, not SDK-bound). */\nexport interface RawEventLike {\n type: string\n seq: number\n time: number\n surfaceOp?: unknown\n data?: {\n id?: unknown\n source?: { kind?: string; plugin?: string }\n content?: readonly { type?: string; text?: string }[]\n }\n}\n\n/** The conversation Definition kind whose key a user question node uses. */\nexport const MESSAGE_DEFINITION_KIND = 'input-message'\n\n/**\n * The engine-owned stable chat key for a user question event — mirrors\n * `conversationContextKey('input-message', String(id))` from the DSH runtime\n * (verified against it in the unit test).\n */\nexport function questionKey(id: unknown): string {\n const kind = MESSAGE_DEFINITION_KIND\n return `${kind.length}:${kind}${String(id)}`\n}\n\n/**\n * Whether a raw event is one user question the strip should index.\n * Mirrors the DSH `messageDefinition` match + `start` classification:\n * an append-origin `user/message` with a human (`user`) source. Replacement\n * copies (compaction checkpoints, `source.kind === 'plugin'`) and injected\n * context (`source.kind !== 'user'`) are excluded.\n */\nexport function isQuestionEvent(event: RawEventLike): boolean {\n if (event.type !== 'user/message') return false\n if (event.surfaceOp !== 'append') return false\n return event.data?.source?.kind === 'user'\n}\n\n/** Map one raw question event to a strip question node, or null when not one. */\nexport function questionFromEvent(event: RawEventLike): QuestionNode | null {\n if (!isQuestionEvent(event)) return null\n return {\n key: questionKey(event.data?.id),\n anchorSeq: event.seq,\n seq: event.seq,\n time: event.time,\n text: messageText(event.data?.content),\n }\n}\n\nexport interface HistoryIndexPorts {\n /**\n * Read one raw history page. `beforeSeq` is exclusive (events with seq <\n * beforeSeq); `undefined` reads the newest page. Resolves undefined when\n * the page is unavailable (session gone / transport error).\n */\n history: (\n beforeSeq: number | undefined,\n maxMessages: number,\n ) => Promise<{ events: readonly { event: RawEventLike }[]; hasMore: boolean } | undefined>\n /** Monotonic ms clock. */\n now: () => number\n}\n\nexport interface HistoryIndexOptions {\n /** Raw messages per page (default 100). */\n maxMessages?: number\n /** Max pages before giving up (default 200 => 20k messages). */\n maxPages?: number\n /** Total wall-clock budget (default 30s). */\n totalTimeoutMs?: number\n /** Abort the build; checked every iteration. */\n signal?: AbortSignal\n /** Resume from a previous `nextBeforeSeq` instead of the newest page. */\n startBeforeSeq?: number\n}\n\nexport type HistoryIndexCode = 'COMPLETE' | 'BUDGET' | 'TIMEOUT' | 'UNAVAILABLE' | 'CANCELLED'\n\nexport interface HistoryIndexResult {\n ok: boolean\n code: HistoryIndexCode\n /** Questions collected so far, ascending by anchorSeq. */\n questions: QuestionNode[]\n /** Page count actually read. */\n pages: number\n /** Where to continue (exclusive) when stopped early; undefined when COMPLETE. */\n nextBeforeSeq: number | undefined\n}\n\nconst DEFAULTS = {\n maxMessages: 100,\n maxPages: 200,\n totalTimeoutMs: 30_000,\n}\n\nfunction minSeq(events: readonly { event: RawEventLike }[]): number | undefined {\n let min: number | undefined\n for (const { event } of events) {\n if (min === undefined || event.seq < min) min = event.seq\n }\n return min\n}\n\n/**\n * Page the raw session history backward, collecting every user question into a\n * lightweight index. Never touches the render window.\n */\nexport async function buildQuestionIndex(\n ports: HistoryIndexPorts,\n options: HistoryIndexOptions = {},\n): Promise<HistoryIndexResult> {\n const cfg = { ...DEFAULTS, ...options }\n const deadline = ports.now() + cfg.totalTimeoutMs\n const questions: QuestionNode[] = []\n let beforeSeq: number | undefined = cfg.startBeforeSeq\n let pages = 0\n\n const cancelled = (): boolean => cfg.signal?.aborted === true\n\n while (true) {\n if (cancelled()) return { ok: false, code: 'CANCELLED', questions, pages, nextBeforeSeq: beforeSeq }\n if (ports.now() > deadline) return { ok: false, code: 'TIMEOUT', questions, pages, nextBeforeSeq: beforeSeq }\n if (pages >= cfg.maxPages) return { ok: false, code: 'BUDGET', questions, pages, nextBeforeSeq: beforeSeq }\n\n const page = await ports.history(beforeSeq, cfg.maxMessages)\n if (page === undefined) {\n // Transient: retry a little, then give up with what we have.\n if (pages === 0) return { ok: false, code: 'UNAVAILABLE', questions, pages, nextBeforeSeq: beforeSeq }\n return { ok: true, code: 'COMPLETE', questions, pages, nextBeforeSeq: undefined }\n }\n\n for (const { event } of page.events) {\n const question = questionFromEvent(event)\n if (question !== null) questions.push(question)\n }\n\n if (!page.hasMore) {\n questions.sort((a, b) => a.anchorSeq - b.anchorSeq)\n return { ok: true, code: 'COMPLETE', questions, pages, nextBeforeSeq: undefined }\n }\n\n const next = minSeq(page.events)\n if (next === undefined) {\n // Empty page with hasMore true is anomalous; stop cleanly.\n questions.sort((a, b) => a.anchorSeq - b.anchorSeq)\n return { ok: true, code: 'COMPLETE', questions, pages, nextBeforeSeq: undefined }\n }\n beforeSeq = next\n pages += 1\n }\n}\n","/**\n * Browser-half entry for the dsh-question-nav plugin.\n *\n * Registers one surface into the frame-wide floating layer (`shell.overlay`):\n * a vertical strip on the LEFT edge of the conversation column listing every\n * user question in the current session as a small button. Clicking a button\n * scrolls the chat to that question.\n *\n * The strip indexes the WHOLE session history WITHOUT expanding DSH's paged\n * render window: it pages the raw `session.history` RPC (read-only, no render\n * cost) and derives each question's chat anchor key from the event. Only when\n * a dot is clicked does the jump loop call `loadOlder()` to bring that\n * specific page into the window — so the conversation's memory economy is\n * preserved.\n *\n * Failure policy: nothing here throws at apply time — an external plugin must\n * never take the GUI down.\n */\nimport type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'\nimport type { SessionId } from '@deepseek-ai/dsh-client-connection/client'\nimport type { ConnectionHandle } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: pulls ui-layout's SlotMap merge ('shell.overlay').\nimport type {} from '@deepseek-ai/dsh-client-ui-layout/client'\n// Type-only: pulls the locale plugin's Context merge (ctx.locale).\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\nimport { QuestionNavStrip, type QuestionNavInjected } from './QuestionNavStrip.tsx'\nimport { en, zh, type QuestionNavKey } from './locales.ts'\nimport { extractQuestions } from '../core/nodes.ts'\nimport { jumpToQuestion, type JumpFailureCode, type JumpPorts } from '../core/jump.ts'\nimport { buildQuestionIndex, type HistoryIndexOptions, type HistoryIndexResult, type RawEventLike } from '../core/history-index.ts'\n\n/** Locale namespace this plugin owns. */\nconst NS = 'question-nav'\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface LocaleNamespaceMap {\n /** question-nav surface copy. */\n 'question-nav': QuestionNavKey\n }\n}\n\n/** Services required by this plugin. */\nexport const inject = ['slots', 'locale', 'sessions', 'connection']\n\n/** Single-instance guard: a duplicated client injection must not mount twice. */\ndeclare global {\n // eslint-disable-next-line no-var\n var __dshQuestionNavApplied: boolean | undefined\n}\n\nfunction claimApply(): boolean {\n if (globalThis.__dshQuestionNavApplied === true) return false\n globalThis.__dshQuestionNavApplied = true\n return true\n}\n\nfunction releaseApply(): void {\n globalThis.__dshQuestionNavApplied = undefined\n}\n\n/** Map the session snapshot to the jump-loop port surface. */\nfunction jumpPortsFor(ctx: ClientContext, sessionId: SessionId): JumpPorts {\n return {\n snapshot: () => {\n const binding = ctx.sessions.binding(sessionId)\n const snap = binding?.session.getSnapshot()\n if (snap === undefined) return undefined\n return {\n openState: snap.openState,\n hasMore: snap.hasMore,\n loadingOlder: snap.loadingOlder,\n rows: snap.chat.nodes.values(),\n }\n },\n loadOlder: async () => {\n const binding = ctx.sessions.binding(sessionId)\n if (binding === undefined) throw new Error('session unavailable')\n await binding.session.loadOlder()\n },\n isViewActive: () => document.querySelector('[data-chat-flow]') !== null,\n findRow: (key: string) => {\n for (const candidate of Array.from(document.querySelectorAll<HTMLElement>('[data-chat-anchor-key]'))) {\n if (candidate.dataset.chatAnchorKey === key) return candidate\n }\n return null\n },\n scrollIntoView: (row) => row.scrollIntoView({ block: 'start' }),\n now: () => Date.now(),\n sleep: (ms) => new Promise((resolve) => window.setTimeout(resolve, ms)),\n }\n}\n\n/** Resolve the connection handle (shared API client) as other DSH plugins do. */\nfunction connectionOf(ctx: ClientContext): ConnectionHandle {\n return ctx.get('connection') as ConnectionHandle\n}\n\n/**\n * One raw history page, mapped to the pure `buildQuestionIndex` port shape.\n * `beforeSeq` is exclusive; `undefined` reads the newest page. Returns\n * undefined when the page is unavailable so the builder stops cleanly. The\n * SDK's `SessionEvent` is cast to the structural `RawEventLike` at this\n * boundary (the index reader only touches type/seq/time/surfaceOp/data).\n */\nasync function rawHistoryPage(\n ctx: ClientContext,\n sessionId: SessionId,\n beforeSeq: number | undefined,\n maxMessages: number,\n): Promise<{ events: readonly { event: RawEventLike }[]; hasMore: boolean } | undefined> {\n const { api } = connectionOf(ctx)\n const { result } = await api.sessions.history({ sessionId, beforeSeq, maxMessages })\n if (!result.ok) return undefined\n return {\n events: result.value.events.map((entry) => ({ event: entry.event as unknown as RawEventLike })),\n hasMore: result.value.hasMore,\n }\n}\n\n/** Build the full-session question index from the raw history RPC (no render). */\nfunction buildIndexFor(\n ctx: ClientContext,\n sessionId: SessionId,\n options: HistoryIndexOptions = {},\n): Promise<HistoryIndexResult> {\n return buildQuestionIndex({\n history: (beforeSeq, maxMessages) => rawHistoryPage(ctx, sessionId, beforeSeq, maxMessages),\n now: () => Date.now(),\n }, options)\n}\n\nfunction createInject(ctx: ClientContext): QuestionNavInjected {\n return {\n readQuestions: (sessionId) => {\n const snap = ctx.sessions.binding(sessionId)?.session.getSnapshot()\n if (snap === undefined) return []\n return extractQuestions(snap.chat.nodes.values())\n },\n subscribeList: (cb) => ctx.sessions.list.subscribe(cb),\n subscribeContent: (sessionId, cb) => {\n const binding = ctx.sessions.binding(sessionId)\n if (binding === undefined) return () => {}\n return binding.session.subscribe(cb)\n },\n jump: (sessionId, key) => {\n const ports = jumpPortsFor(ctx, sessionId)\n ports.report = (code: JumpFailureCode) => {\n // Surface the failure through the component via a DOM event the\n // strip listens for; simplest reliable cross-boundary channel here.\n window.dispatchEvent(new CustomEvent('question-nav:jump-failed', { detail: code }))\n }\n void jumpToQuestion(ports, key)\n },\n fetchQuestionIndex: (sessionId, options) => buildIndexFor(ctx, sessionId, options),\n }\n}\n\n/**\n * Register the question-nav surface.\n * @param ctx - client root context.\n */\nexport function apply(ctx: ClientContext): void {\n if (!claimApply()) return\n ctx.effect(() => releaseApply, 'question-nav: apply claim')\n\n ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'question-nav: dictionaries')\n\n const injected = createInject(ctx)\n\n ctx.slots.inject('shell.overlay', () => ctx.slots.register({\n name: 'shell.overlay',\n id: 'question-nav',\n order: 900,\n locale: NS,\n inject: () => injected,\n }, QuestionNavStrip))\n}\n"],"mappings":";;;;;;;;;;;EA+BA,MAAa,iBAAiB,CAAC,QAAQ,UAAU;EASjD,SAAS,SAAS,MAAyC;GACzD,IAAI,OAAO,SAAS,YAAY,SAAS,MAAM,OAAO,KAAA;GACtD,OAAO;EACT;;EAGA,SAAgB,YAAY,SAA0E;GACpG,IAAI,YAAY,KAAA,KAAa,QAAQ,WAAW,GAAG,OAAO;GAC1D,MAAM,QAAQ,QAAQ;GACtB,IAAI,OAAO,OAAO,SAAS,UAAU,OAAO,MAAM;GAClD,OAAO;EACT;;EAGA,SAAgB,iBAAiB,OAA+C;GAC9E,MAAM,MAAsB,CAAC;GAC7B,KAAK,MAAM,QAAQ,OAAO;IACxB,IAAI,CAAC,eAAe,SAAS,KAAK,IAAuC,GAAG;IAC5E,MAAM,UAAU,SAAS,KAAK,IAAI;IAClC,IAAI,KAAK;KACP,KAAK,KAAK;KACV,WAAW,KAAK;KAChB,KAAK,SAAS,OAAO;KACrB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ACrD,mBAAmB,WAAW,OAAO;KACnC,MAAM,UAAU,IAAI,SAAS,QAAQ,SAAS;KAC9C,IAAI,YAAY,KAAA,GAAW,aAAa,CAAC;KACzC,OAAO,QAAQ,QAAQ,UAAU,EAAE;IACrC;IACA,OAAO,WAAW,QAAQ;KACxB,MAAM,QAAQ,aAAa,KAAK,SAAS;KACzC,MAAM,UAAU,SAA0B;MAGxC,OAAO,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,KAAK,CAAC,CAAC;KACpF;KACA,eAAoB,OAAO,GAAG;IAChC;IACA,qBAAqB,WAAW,YAAY,cAAc,KAAK,WAAW,OAAO;GACnF;EACF;;;;;EAMA,SAAgB,MAAM,KAA0B;GAC9C,IAAI,CAAC,WAAW,GAAG;GACnB,IAAI,aAAa,cAAc,2BAA2B;GAE1D,IAAI,aAAa,IAAI,OAAO,SAAS,IAAI;IAAE;IAAI;GAAG,CAAC,GAAG,4BAA4B;GAElF,MAAM,WAAW,aAAa,GAAG;GAEjC,IAAI,MAAM,OAAO,uBAAuB,IAAI,MAAM,SAAS;IACzD,MAAM;IACN,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,cAAc;GAChB,GAAG,gBAAgB,CAAC;EACtB"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["kind","useState","useRef","styles","createPortal"],"sources":["../src/core/turn-dots.ts","../src/client/QuestionNavStrip.tsx","../src/client/locales.ts","../src/core/nodes.ts","../src/core/jump.ts","../src/client/index.ts"],"sourcesContent":["/**\n * Turn-aligned dot model for the question-nav strip. Pure transforms over the\n * `questionIndex` projection value plus the live chat window — no React, no\n * DOM — so the grouping and merging rules are unit-testable in isolation.\n *\n * One dot per turn that claimed at least one user question; turns without a\n * question (retry, goal continuation, cancelled empty turns) produce no dot,\n * so dot turn labels may skip numbers but always match the Trajectory view.\n */\n\nimport type { QuestionEntry } from './question-entry.ts'\nimport type { QuestionNode } from './nodes.ts'\n\n/** The conversation Definition kind whose key a user question node uses. */\nexport const MESSAGE_DEFINITION_KIND = 'input-message'\n\n/**\n * The engine-owned stable chat key for a user question — mirrors\n * `conversationContextKey('input-message', String(id))` from the DSH runtime\n * (verified against that formula in the unit test).\n */\nexport function questionKey(id: unknown): string {\n const kind = MESSAGE_DEFINITION_KIND\n return `${kind.length}:${kind}${String(id)}`\n}\n\n/** One strip dot: a turn's questions (grouped) or one ungrouped live question. */\nexport interface TurnDot {\n /** Owning turn number; null for live questions the projection has not seen. */\n readonly turn: number | null\n /** Jump anchor: the chat key of the turn's FIRST question. */\n readonly key: string\n /** Anchor seq of the first question (ordering + jump target). */\n readonly anchorSeq: number\n /** Unix ms of the first question. */\n readonly time: number\n /** Every question text of this dot, in order (tooltip lists them all). */\n readonly texts: readonly string[]\n /** Chat keys of every question folded into this dot (live-merge dedupe). */\n readonly memberKeys: readonly string[]\n}\n\n/**\n * Fold the projection's question list into one dot per turn. Entries arrive\n * in event order; consecutive same-turn entries merge into a single dot whose\n * anchor is the turn's first question.\n */\nexport function groupQuestionsByTurn(entries: readonly QuestionEntry[]): TurnDot[] {\n const sorted = [...entries].sort((a, b) => a.seq - b.seq)\n const dots: TurnDot[] = []\n for (const entry of sorted) {\n const key = questionKey(entry.id)\n const last = dots.at(-1)\n if (last !== undefined && last.turn === entry.turn) {\n dots[dots.length - 1] = {\n ...last,\n texts: [...last.texts, entry.text],\n memberKeys: [...last.memberKeys, key],\n }\n continue\n }\n dots.push({\n turn: entry.turn,\n key,\n anchorSeq: entry.seq,\n time: entry.time,\n texts: [entry.text],\n memberKeys: [key],\n })\n }\n return dots\n}\n\n/**\n * Merge live-window questions the projection has not recorded yet (the brief\n * window before the session/projection push frame lands). A live question\n * whose key is already folded into a dot is dropped (the projected copy\n * wins); the rest become single-question dots with `turn: null`, inserted in\n * anchor-seq order so the strip stays strictly chronological.\n */\nexport function mergeLiveQuestions(\n dots: readonly TurnDot[],\n live: readonly QuestionNode[],\n): TurnDot[] {\n const known = new Set(dots.flatMap(dot => dot.memberKeys))\n const extras: TurnDot[] = live\n .filter(question => !known.has(question.key))\n .map(question => ({\n turn: null,\n key: question.key,\n anchorSeq: question.anchorSeq,\n time: question.time,\n texts: [question.text],\n memberKeys: [question.key],\n }))\n if (extras.length === 0) return [...dots]\n return [...dots, ...extras].sort((a, b) => a.anchorSeq - b.anchorSeq)\n}\n","/**\n * Question-nav minimap. Renders a vertical column of small round dots overlaid\n * on the LEFT edge of the conversation column (via the frame-wide\n * `shell.overlay` floating layer), vertically centered: one dot per turn that\n * claimed at least one user question — strictly aligned with the Trajectory\n * view's turn numbering (turns without a question produce no dot). Hover\n * enlarges a dot and shows an instant tooltip (portal-rendered, no native\n * delay) with the turn label and the turn's question text(s); clicking jumps\n * the chat to that turn's first question.\n *\n * Data source: the host-folded `questionIndex` session projection (whole\n * history, persisted host-side, pushed live through session/projection\n * frames) read through the injected `questionProjection` face, plus the live\n * chat window's questions merged on top for the brief window before a\n * just-sent question lands in the projection. No render-window expansion, no\n * client-side history paging.\n *\n * Data arrives through the props shares: the framework `useSessions` hook\n * (current session), the registrant inject face (read/subscribe/project/\n * jump), and the bound locale translator.\n */\nimport { useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots'\nimport type { SessionId } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: pulls the ui-layout SlotMap merge ('shell.overlay').\nimport type {} from '@deepseek-ai/dsh-client-ui-layout/client'\nimport type { QuestionNode } from '../core/nodes.ts'\nimport type { QuestionEntry } from '../core/question-entry.ts'\nimport { groupQuestionsByTurn, mergeLiveQuestions, type TurnDot } from '../core/turn-dots.ts'\nimport type { JumpFailureCode } from '../core/jump.ts'\nimport type { QuestionNavKey } from './locales.ts'\nimport styles from './question-nav.module.css'\n\n/** Minimal observable shape of a session projection face. */\nexport interface ObservableFace {\n /** Current projection value (unknown — validated structurally at read). */\n getSnapshot: () => unknown\n /** Subscribe to value changes; returns an unsubscribe. */\n subscribe: (listener: () => void) => () => void\n}\n\n/** Values the registrant inject face supplies (wired in src/client/index.ts). */\nexport interface QuestionNavInjected {\n /** Extract the user questions of a session's currently loaded window. */\n readQuestions: (sessionId: SessionId) => QuestionNode[]\n /** Subscribe to the session list; returns an unsubscribe. */\n subscribeList: (cb: () => void) => () => void\n /** Subscribe to a session's content; returns an unsubscribe. */\n subscribeContent: (sessionId: SessionId, cb: () => void) => () => void\n /** The session's `questionIndex` projection face, when the host unit is registered. */\n questionProjection: (sessionId: SessionId) => ObservableFace | undefined\n /** Jump the chat to a question row (pages the window on demand). */\n jump: (sessionId: SessionId, key: string) => void\n}\n\ntype ComponentProps = PropsRuntime<'shell.overlay'> & QuestionNavInjected & PropsLocale<'question-nav'>\n\nconst FAILURE_HINTS: Record<JumpFailureCode, QuestionNavKey> = {\n VIEW_INACTIVE: 'jump.inactive',\n TARGET_HIDDEN: 'jump.hidden',\n NOT_FOUND: 'jump.notfound',\n TIMEOUT: 'jump.timeout',\n}\n\n/** Live position of the instant hover tooltip. */\ninterface TooltipState {\n /** Turn label line (e.g. \"Turn 32\"); null for ungrouped live questions. */\n title: string | null\n /** Question text lines (one per question folded into the dot). */\n lines: readonly string[]\n left: number\n top: number\n}\n\n/** Read the projection face value as a question-entry list (structural guard). */\nfunction projectionEntries(face: ObservableFace | undefined): QuestionEntry[] {\n const value = face?.getSnapshot()\n if (!Array.isArray(value)) return []\n return value.filter((item): item is QuestionEntry =>\n typeof item === 'object' && item !== null\n && typeof (item as QuestionEntry).id === 'string'\n && typeof (item as QuestionEntry).seq === 'number'\n && typeof (item as QuestionEntry).turn === 'number')\n}\n\nfunction findConvRoot(): HTMLElement | null {\n return document.querySelector<HTMLElement>('[data-slot=\"conversation\"] > div[data-phase]')\n}\n\nexport function QuestionNavStrip(props: ComponentProps): React.JSX.Element | null {\n const current = props.useSessions((s) => s.current)\n const summary = props.useSessions((s) => (s.current === undefined ? undefined : s.byId[s.current]))\n const visible = current !== undefined && summary !== undefined && summary.blank !== true\n\n const [dots, setDots] = useState<TurnDot[]>([])\n const [jumpingKey, setJumpingKey] = useState<string | null>(null)\n const [hint, setHint] = useState<string | null>(null)\n const [tooltip, setTooltip] = useState<TooltipState | null>(null)\n const panelRef = useRef<HTMLDivElement | null>(null)\n const hintTimerRef = useRef<number | null>(null)\n\n const showHint = (message: string): void => {\n setHint(message)\n if (hintTimerRef.current !== null) window.clearTimeout(hintTimerRef.current)\n hintTimerRef.current = window.setTimeout(() => setHint(null), 1800)\n }\n\n // Recompute the dot list from the projection + live window; subscribe to\n // the projection push frames, session content, and the session list.\n useEffect(() => {\n if (!visible || current === undefined) {\n setDots([])\n return\n }\n const sessionId = current\n const face = props.questionProjection(sessionId)\n const refresh = (): void => {\n const grouped = groupQuestionsByTurn(projectionEntries(face))\n setDots(mergeLiveQuestions(grouped, props.readQuestions(sessionId)))\n }\n refresh()\n const unsubProjection = face?.subscribe(refresh) ?? (() => {})\n const unsubContent = props.subscribeContent(sessionId, refresh)\n const unsubList = props.subscribeList(refresh)\n return () => {\n unsubProjection()\n unsubContent()\n unsubList()\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [visible, current, props])\n\n // Listen for jump-failure events and surface the hint.\n useEffect(() => {\n const onJumpFailed = (event: Event): void => {\n const code = (event as CustomEvent<JumpFailureCode>).detail\n showHint(props.t(FAILURE_HINTS[code] ?? 'jump.timeout'))\n }\n window.addEventListener('question-nav:jump-failed', onJumpFailed)\n return () => window.removeEventListener('question-nav:jump-failed', onJumpFailed)\n }, [props])\n\n // Anchor the minimap to the conversation column: position it at the left\n // edge of the conversation root and reserve a thin rail with padding-left.\n useLayoutEffect(() => {\n if (!visible) return\n let raf = 0\n let retries = 0\n const applyLayout = (): void => {\n const panel = panelRef.current\n if (panel === null) return\n const frame = panel.closest('[data-shell-overlay]')?.parentElement ?? null\n const convRoot = findConvRoot()\n if (frame === null || convRoot === null) return\n const frameRect = frame.getBoundingClientRect()\n const convRect = convRoot.getBoundingClientRect()\n if (convRect.height <= 0) {\n if (retries < 20) {\n retries += 1\n raf = requestAnimationFrame(applyLayout)\n }\n return\n }\n retries = 0\n panel.style.top = `${convRect.top - frameRect.top}px`\n panel.style.height = `${convRect.height}px`\n panel.style.left = `${convRect.left - frameRect.left}px`\n }\n applyLayout()\n raf = requestAnimationFrame(applyLayout)\n const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(applyLayout)\n const convRoot = findConvRoot()\n observer?.observe(convRoot ?? document.body, { box: 'border-box' })\n window.addEventListener('resize', applyLayout)\n return () => {\n if (raf !== 0) cancelAnimationFrame(raf)\n observer?.disconnect()\n window.removeEventListener('resize', applyLayout)\n }\n }, [visible])\n\n // Clear any pending hint timer on unmount.\n useEffect(() => () => {\n if (hintTimerRef.current !== null) window.clearTimeout(hintTimerRef.current)\n }, [])\n\n if (!visible) return null\n\n const onJump = (dot: TurnDot): void => {\n if (current === undefined) return\n setJumpingKey(dot.key)\n props.jump(current, dot.key)\n window.setTimeout(() => setJumpingKey((k) => (k === dot.key ? null : k)), 600)\n }\n\n const openTooltip = (dot: TurnDot, target: HTMLElement): void => {\n const r = target.getBoundingClientRect()\n setTooltip({\n title: dot.turn === null ? null : `Turn ${dot.turn}`,\n lines: dot.texts,\n left: r.right + 10,\n top: r.top,\n })\n }\n\n const t = props.t\n\n return (\n <div ref={panelRef} className={styles.rail} data-question-nav=\"rail\">\n {hint !== null ? <div className={styles.hint} role=\"status\">{hint}</div> : null}\n <div className={styles.list}>\n {dots.length === 0 ? (\n <div className={styles.empty}>{t('strip.empty')}</div>\n ) : (\n <div className={styles.dots}>\n <span className={styles.count}>{dots.length}</span>\n {dots.map((dot) => (\n <button\n key={dot.key}\n className={jumpingKey === dot.key ? `${styles.dot} ${styles.active}` : styles.dot}\n aria-label={dot.texts[0] ?? ''}\n onMouseEnter={(e) => openTooltip(dot, e.currentTarget)}\n onMouseLeave={() => setTooltip(null)}\n onClick={() => onJump(dot)}\n />\n ))}\n </div>\n )}\n </div>\n {tooltip !== null\n ? createPortal(\n <div className={styles.tooltip} style={{ left: tooltip.left, top: tooltip.top }}>\n {tooltip.title !== null ? <div className={styles.tooltipTitle}>{tooltip.title}</div> : null}\n {tooltip.lines.map((line, index) => (\n <div key={index} className={styles.tooltipLine}>{line}</div>\n ))}\n </div>,\n document.body,\n )\n : null}\n </div>\n )\n}\n","/**\n * Locale dictionaries for the question-nav surface (zh/en). Registered under\n * the `question-nav` namespace; keys are consumed through the bound translator.\n */\nexport const zh = {\n 'strip.empty': '本会话还没有提问',\n 'jump.inactive': '聊天视图未激活',\n 'jump.hidden': '目标无独立气泡,已定位到邻近内容',\n 'jump.notfound': '目标未加载或不存在(可能已压缩)',\n 'jump.timeout': '加载历史超时,可重试',\n} as const\n\nexport const en = {\n 'strip.empty': 'No questions in this session yet',\n 'jump.inactive': 'Chat view is not active',\n 'jump.hidden': 'No dedicated bubble; landed on nearby content',\n 'jump.notfound': 'Target not loaded or missing (maybe compacted)',\n 'jump.timeout': 'Timed out loading history; retry',\n} as const\n\nexport type QuestionNavKey = keyof typeof zh\n","/**\n * Pure node-indexing logic for the question-nav plugin. No React, no DOM, no\n * Cordis — every function here is a pure transform over chat-node data so it\n * can be unit-tested in isolation (and reused by the browser half).\n */\n\n/** One user question as shown in the strip and targeted by a jump. */\nexport interface QuestionNode {\n /** Chat anchor key, matches a `[data-chat-anchor-key]` row in the scrollport. */\n key: string\n /** Monotone anchor sequence for ordering and window-min detection. */\n anchorSeq: number\n /** Event seq of the user message. */\n seq: number\n /** Unix ms timestamp. */\n time: number\n /** Full question text — shown in the hover tooltip (not truncated). */\n text: string\n}\n\n/** Minimal shape a chat node must expose for indexing (structural, not SDK-bound). */\nexport interface ChatNodeLike {\n key: string\n anchorSeq: number\n visibility?: string\n kind?: string\n /** Kind-specific payload (a UserMessageNode for `user`/`steering`). */\n data?: unknown\n}\n\n/** Kinds counted as a user question (turn-opening and steering admissions). */\nexport const QUESTION_KINDS = ['user', 'steering'] as const\n\n/** Narrow `node.data` to the user-message payload we read. */\ninterface UserDataLike {\n content?: readonly { type?: string; text?: string }[]\n seq?: number\n time?: number\n}\n\nfunction userData(data: unknown): UserDataLike | undefined {\n if (typeof data !== 'object' || data === null) return undefined\n return data as UserDataLike\n}\n\n/** First text block of a user message; falls back to the raw first block. */\nexport function messageText(content: readonly { type?: string; text?: string }[] | undefined): string {\n if (content === undefined || content.length === 0) return ''\n const first = content[0]\n if (typeof first?.text === 'string') return first.text\n return ''\n}\n\n/** Extract the user questions from a chat-node window, ordered by anchorSeq. */\nexport function extractQuestions(nodes: Iterable<ChatNodeLike>): QuestionNode[] {\n const out: QuestionNode[] = []\n for (const node of nodes) {\n if (!QUESTION_KINDS.includes(node.kind as (typeof QUESTION_KINDS)[number])) continue\n const payload = userData(node.data)\n out.push({\n key: node.key,\n anchorSeq: node.anchorSeq,\n seq: payload?.seq ?? -1,\n time: payload?.time ?? 0,\n // Full question text: shown in the hover tooltip (not truncated).\n text: messageText(payload?.content),\n })\n }\n out.sort((a, b) => a.anchorSeq - b.anchorSeq)\n return out\n}\n\n/** Whether a node is actually rendered (visible rows only are scroll targets). */\nexport function isRenderable(node: ChatNodeLike): boolean {\n return node.visibility !== 'hidden'\n}\n\n/** The row of the window that renders the given key (exact match). */\nexport function findQuestionRow(nodes: Iterable<ChatNodeLike>, key: string): ChatNodeLike | null {\n for (const node of nodes) {\n if (node.key === key) return node\n }\n return null\n}\n\n/** Nearest renderable row for a key that is absent or hidden (compaction, windowing). */\nexport function nearestRenderable(\n nodes: Iterable<{ key: string; anchorSeq: number; visibility?: string }>,\n excludeKey: string | undefined,\n): { key: string; anchorSeq: number } | null {\n let best: { key: string; anchorSeq: number } | null = null\n for (const node of nodes) {\n if (node.visibility === 'hidden') continue\n if (node.key === excludeKey) continue\n if (best === null || node.anchorSeq < best.anchorSeq) best = { key: node.key, anchorSeq: node.anchorSeq }\n }\n return best\n}\n","/**\n * Jump-to-question orchestration. Pure-ish: takes injected ports (snapshot\n * read, loadOlder, DOM row lookup, view liveness, scroll, timers) so the\n * paging/timeout/fallback loop is unit-testable without a real browser or\n * session. The browser half wires these ports to ctx.sessions + the DOM.\n */\n\nimport { nearestRenderable } from './nodes.ts'\n\n/** The bits of a session snapshot the jump loop needs. */\nexport interface JumpSnapshot {\n openState: string\n hasMore: boolean\n loadingOlder: boolean\n /** Renderable chat rows as a key->renderable map (or iterable of rows). */\n rows: Iterable<{ key: string; anchorSeq: number; visibility?: string }>\n}\n\nexport interface JumpPorts {\n /** Read the current snapshot; undefined when the session/view is unavailable. */\n snapshot: () => JumpSnapshot | undefined\n /** Expand the window backwards; rejects/throws on failure. */\n loadOlder: () => Promise<void>\n /** True while the chat view is active (a `[data-chat-flow]` is mounted). */\n isViewActive: () => boolean\n /** Find the DOM row for a chat anchor key; null when not rendered. */\n findRow: (key: string) => HTMLElement | null\n /** Scroll a row into view at the top. */\n scrollIntoView: (row: HTMLElement) => void\n /** Monotonic ms clock. */\n now: () => number\n /** Async sleep. */\n sleep: (ms: number) => Promise<void>\n /** Report a terminal failure to the caller (for a hint). */\n report?: (code: JumpFailureCode, fallback?: boolean) => void\n}\n\nexport type JumpFailureCode = 'VIEW_INACTIVE' | 'TARGET_HIDDEN' | 'NOT_FOUND' | 'TIMEOUT'\n\nexport interface JumpResult {\n ok: boolean\n code?: JumpFailureCode\n /** True when we landed on a fallback row rather than the exact target. */\n fallback?: boolean\n}\n\nexport interface JumpOptions {\n /** Total wall-clock budget for loadOlder paging. */\n totalTimeoutMs?: number\n /** Max loadOlder pages before giving up. */\n maxPages?: number\n /** Poll interval for the row to render after it is known to be in the window. */\n rowWaitMs?: number\n /** Poll interval for state transitions (loadingOlder / openState). */\n pollMs?: number\n}\n\nconst DEFAULTS = {\n totalTimeoutMs: 15_000,\n maxPages: 100,\n rowWaitMs: 8_000,\n pollMs: 60,\n}\n\nfunction minAnchorSeq(rows: Iterable<{ anchorSeq: number }>): number | null {\n let min: number | null = null\n for (const row of rows) {\n if (min === null || row.anchorSeq < min) min = row.anchorSeq\n }\n return min\n}\n\nfunction renderable(rows: Iterable<{ key: string; anchorSeq: number; visibility?: string }>): { key: string; anchorSeq: number }[] {\n const out: { key: string; anchorSeq: number }[] = []\n for (const row of rows) {\n if (row.visibility === 'hidden') continue\n out.push({ key: row.key, anchorSeq: row.anchorSeq })\n }\n return out\n}\n\n/**\n * Jump to the row for `key`, paging older content until it is rendered (or the\n * budget is exhausted). Falls back to the nearest renderable row when the\n * exact row is hidden/absent.\n */\nexport async function jumpToQuestion(ports: JumpPorts, key: string, options: JumpOptions = {}): Promise<JumpResult> {\n const cfg = { ...DEFAULTS, ...options }\n const fail = (code: JumpFailureCode, fallback = false): JumpResult => {\n ports.report?.(code, fallback)\n return fallback ? { ok: false, code, fallback: true } : { ok: false, code }\n }\n\n if (!ports.isViewActive()) return fail('VIEW_INACTIVE')\n\n const deadline = ports.now() + cfg.totalTimeoutMs\n let pages = 0\n\n // Phase 1: page older until the key appears in the loaded window.\n while (true) {\n const snap = ports.snapshot()\n if (snap === undefined) return fail('VIEW_INACTIVE')\n const rows = renderable(snap.rows)\n if (rows.some((r) => r.key === key)) break\n if (snap.openState !== 'open') {\n if (snap.openState === 'error' || ports.now() > deadline) {\n return fail(snap.openState === 'error' ? 'VIEW_INACTIVE' : 'TIMEOUT')\n }\n await ports.sleep(cfg.pollMs)\n continue\n }\n if (snap.hasMore !== true) return fail('NOT_FOUND')\n if (pages >= cfg.maxPages || ports.now() > deadline) return fail('TIMEOUT')\n if (snap.loadingOlder) {\n await ports.sleep(cfg.pollMs)\n continue\n }\n const before = minAnchorSeq(rows)\n await ports.loadOlder()\n pages += 1\n const afterSnap = ports.snapshot()\n const after = minAnchorSeq(afterSnap === undefined ? [] : afterSnap.rows)\n if (after === null || (before !== null && after >= before)) return fail('NOT_FOUND')\n }\n\n // Phase 2: wait for the row to render, then scroll. Fall back if hidden.\n const waitedFor = async (rowKey: string): Promise<HTMLElement | null> => {\n for (let waited = 0; waited <= cfg.rowWaitMs; waited += cfg.pollMs) {\n if (!ports.isViewActive()) return null\n const row = ports.findRow(rowKey)\n if (row !== null) return row\n await ports.sleep(cfg.pollMs)\n }\n return null\n }\n\n const row = await waitedFor(key)\n if (row !== null) {\n ports.scrollIntoView(row)\n return { ok: true }\n }\n\n const snap = ports.snapshot()\n const fallback = nearestRenderable(snap === undefined ? [] : snap.rows, key)\n if (fallback !== null) {\n const fbRow = await waitedFor(fallback.key)\n if (fbRow !== null) {\n ports.scrollIntoView(fbRow)\n return fail('TARGET_HIDDEN', true)\n }\n }\n return fail('TARGET_HIDDEN', false)\n}\n","/**\n * Browser-half entry for the dsh-question-nav plugin.\n *\n * Registers one surface into the frame-wide floating layer (`shell.overlay`):\n * a vertical strip on the LEFT edge of the conversation column listing every\n * user question in the current session as a small button, one dot per turn.\n * Clicking a button scrolls the chat to that turn's first question.\n *\n * The dots are driven by the host-folded `questionIndex` session projection\n * (registered by the plugin's host half): the projection registry folds the\n * WHOLE event log without touching the chat's paged render window, the\n * projection cache persists it, and the standard carriers (history tail-page\n * baseline + session/projection push frames) keep it live. Live-window\n * questions not yet recorded by the projection are merged on top so a\n * just-sent question appears immediately.\n *\n * Failure policy: nothing here throws at apply time — an external plugin must\n * never take the GUI down.\n */\nimport type { ClientContext } from '@deepseek-ai/dsh-client-runtime/client'\nimport type { SessionId } from '@deepseek-ai/dsh-client-connection/client'\n// Type-only: pulls ui-layout's SlotMap merge ('shell.overlay').\nimport type {} from '@deepseek-ai/dsh-client-ui-layout/client'\n// Type-only: pulls the locale plugin's Context merge (ctx.locale).\nimport type {} from '@deepseek-ai/dsh-client-locale/client'\nimport { QuestionNavStrip, type ObservableFace, type QuestionNavInjected } from './QuestionNavStrip.tsx'\nimport { en, zh, type QuestionNavKey } from './locales.ts'\nimport { extractQuestions } from '../core/nodes.ts'\nimport { jumpToQuestion, type JumpFailureCode, type JumpPorts } from '../core/jump.ts'\n\n/** Locale namespace this plugin owns. */\nconst NS = 'question-nav'\n\ndeclare module '@deepseek-ai/dsh-client-ui-slots' {\n interface LocaleNamespaceMap {\n /** question-nav surface copy. */\n 'question-nav': QuestionNavKey\n }\n}\n\n/** Services required by this plugin. */\nexport const inject = ['slots', 'locale', 'sessions']\n\n/** Single-instance guard: a duplicated client injection must not mount twice. */\ndeclare global {\n // eslint-disable-next-line no-var\n var __dshQuestionNavApplied: boolean | undefined\n}\n\nfunction claimApply(): boolean {\n if (globalThis.__dshQuestionNavApplied === true) return false\n globalThis.__dshQuestionNavApplied = true\n return true\n}\n\nfunction releaseApply(): void {\n globalThis.__dshQuestionNavApplied = undefined\n}\n\n/** Map the session snapshot to the jump-loop port surface. */\nfunction jumpPortsFor(ctx: ClientContext, sessionId: SessionId): JumpPorts {\n return {\n snapshot: () => {\n const binding = ctx.sessions.binding(sessionId)\n const snap = binding?.session.getSnapshot()\n if (snap === undefined) return undefined\n return {\n openState: snap.openState,\n hasMore: snap.hasMore,\n loadingOlder: snap.loadingOlder,\n rows: snap.chat.nodes.values(),\n }\n },\n loadOlder: async () => {\n const binding = ctx.sessions.binding(sessionId)\n if (binding === undefined) throw new Error('session unavailable')\n await binding.session.loadOlder()\n },\n isViewActive: () => document.querySelector('[data-chat-flow]') !== null,\n findRow: (key: string) => {\n for (const candidate of Array.from(document.querySelectorAll<HTMLElement>('[data-chat-anchor-key]'))) {\n if (candidate.dataset.chatAnchorKey === key) return candidate\n }\n return null\n },\n scrollIntoView: (row) => row.scrollIntoView({ block: 'start' }),\n now: () => Date.now(),\n sleep: (ms) => new Promise((resolve) => window.setTimeout(resolve, ms)),\n }\n}\n\n/**\n * The session's `questionIndex` projection face (getSnapshot + subscribe).\n * Undefined when the session is not bound or the host unit is not registered\n * (e.g. a headless composition) — the strip then shows live-window dots only.\n */\nfunction questionProjectionOf(ctx: ClientContext, sessionId: SessionId): ObservableFace | undefined {\n const face = ctx.sessions.binding(sessionId)?.session.projections.faceOf('questionIndex')\n if (face === undefined) return undefined\n return {\n getSnapshot: () => face.getSnapshot(),\n subscribe: (listener) => face.subscribe(listener),\n }\n}\n\nfunction createInject(ctx: ClientContext): QuestionNavInjected {\n return {\n readQuestions: (sessionId) => {\n const snap = ctx.sessions.binding(sessionId)?.session.getSnapshot()\n if (snap === undefined) return []\n return extractQuestions(snap.chat.nodes.values())\n },\n subscribeList: (cb) => ctx.sessions.list.subscribe(cb),\n subscribeContent: (sessionId, cb) => {\n const binding = ctx.sessions.binding(sessionId)\n if (binding === undefined) return () => {}\n return binding.session.subscribe(cb)\n },\n questionProjection: (sessionId) => questionProjectionOf(ctx, sessionId),\n jump: (sessionId, key) => {\n const ports = jumpPortsFor(ctx, sessionId)\n ports.report = (code: JumpFailureCode) => {\n // Surface the failure through the component via a DOM event the\n // strip listens for; simplest reliable cross-boundary channel here.\n window.dispatchEvent(new CustomEvent('question-nav:jump-failed', { detail: code }))\n }\n void jumpToQuestion(ports, key)\n },\n }\n}\n\n/**\n * Register the question-nav surface.\n * @param ctx - client root context.\n */\nexport function apply(ctx: ClientContext): void {\n if (!claimApply()) return\n ctx.effect(() => releaseApply, 'question-nav: apply claim')\n\n ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'question-nav: dictionaries')\n\n const injected = createInject(ctx)\n\n ctx.slots.inject('shell.overlay', () => ctx.slots.register({\n name: 'shell.overlay',\n id: 'question-nav',\n order: 900,\n locale: NS,\n inject: () => injected,\n }, QuestionNavStrip))\n}\n"],"mappings":";;;;;;;;;;;EAcA,MAAa,0BAA0B;;;;;;EAOvC,SAAgB,YAAY,IAAqB;GAE/C,OAAO,MAAkBA,0BAAO,OAAO,EAAE;EAC3C;;;;;;EAuBA,SAAgB,qBAAqB,SAA8C;GACjF,MAAM,SAAS,CAAC,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG;GACxD,MAAM,OAAkB,CAAC;GACzB,KAAK,MAAM,SAAS,QAAQ;IAC1B,MAAM,MAAM,YAAY,MAAM,EAAE;IAChC,MAAM,OAAO,KAAK,GAAG,EAAE;IACvB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SAAS;KACzC,MAAM,UAAU,SAA0B;MAGxC,OAAO,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,KAAK,CAAC,CAAC;KACpF;KACA,eAAoB,OAAO,GAAG;IAChC;GACF;EACF;;;;;EAMA,SAAgB,MAAM,KAA0B;GAC9C,IAAI,CAAC,WAAW,GAAG;GACnB,IAAI,aAAa,cAAc,2BAA2B;GAE1D,IAAI,aAAa,IAAI,OAAO,SAAS,IAAI;IAAE;IAAI;GAAG,CAAC,GAAG,4BAA4B;GAElF,MAAM,WAAW,aAAa,GAAG;GAEjC,IAAI,MAAM,OAAO,uBAAuB,IAAI,MAAM,SAAS;IACzD,MAAM;IACN,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,cAAc;GAChB,GAAG,gBAAgB,CAAC;EACtB"}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,95 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/projection.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `questionIndex` session projection unit: a pure fold of the session
|
|
5
|
+
* event log into the ordered list of user questions, each tagged with the
|
|
6
|
+
* turn that claimed it. Registered on `ctx.sessionProjections` by the host
|
|
7
|
+
* half (src/index.ts); persistence, replay, and client delivery are the
|
|
8
|
+
* projection seam's (session-projection-cache checkpoints the state, the
|
|
9
|
+
* api-proxy carriers seed + push the wire view).
|
|
10
|
+
*
|
|
11
|
+
* Fold rules mirror the chat messageDefinition classification: an
|
|
12
|
+
* append-origin `user/message` with a human (`user`) source is a question;
|
|
13
|
+
* replacement copies (compaction checkpoints) and injected context are not.
|
|
14
|
+
* Turns come from `turn/start` boundaries, so retry/goal-continuation turns
|
|
15
|
+
* without a question simply produce no entry — dots may skip turn numbers,
|
|
16
|
+
* staying exactly aligned with the Trajectory view's turn labels.
|
|
17
|
+
*
|
|
18
|
+
* @module dsh-question-nav/projection
|
|
19
|
+
*/
|
|
20
|
+
const questionEntrySchema = z.object({
|
|
21
|
+
turn: z.number().int().nonnegative(),
|
|
22
|
+
id: z.string(),
|
|
23
|
+
seq: z.number().int().nonnegative(),
|
|
24
|
+
time: z.number().nonnegative(),
|
|
25
|
+
text: z.string()
|
|
26
|
+
}).strict();
|
|
27
|
+
/** Validates persisted rows after their `ver` gate (the unit's input boundary). */
|
|
28
|
+
const questionIndexStateSchema = z.object({
|
|
29
|
+
turn: z.number().int().nonnegative(),
|
|
30
|
+
questions: z.array(questionEntrySchema)
|
|
31
|
+
}).strict();
|
|
32
|
+
/** Validates the wire payload before it leaves the host. */
|
|
33
|
+
const questionIndexViewSchema = z.array(questionEntrySchema);
|
|
34
|
+
/** First text block of a user message; empty string when absent. */
|
|
35
|
+
function messageText(content) {
|
|
36
|
+
if (content === void 0 || content.length === 0) return "";
|
|
37
|
+
const first = content[0];
|
|
38
|
+
return typeof first?.text === "string" ? first.text : "";
|
|
39
|
+
}
|
|
40
|
+
/** The `questionIndex` unit registered on `ctx.sessionProjections`. */
|
|
41
|
+
const questionIndexProjectionDefinition = {
|
|
42
|
+
key: "questionIndex",
|
|
43
|
+
stateVersion: 1,
|
|
44
|
+
stateSchema: questionIndexStateSchema,
|
|
45
|
+
init: () => ({
|
|
46
|
+
turn: 0,
|
|
47
|
+
questions: []
|
|
48
|
+
}),
|
|
49
|
+
apply: (state, event) => {
|
|
50
|
+
switch (event.type) {
|
|
51
|
+
case "turn/start": return event.data.turn === state.turn ? state : {
|
|
52
|
+
...state,
|
|
53
|
+
turn: event.data.turn
|
|
54
|
+
};
|
|
55
|
+
case "user/message": {
|
|
56
|
+
if (event.surfaceOp !== "append") return state;
|
|
57
|
+
if (event.data.source?.kind !== "user") return state;
|
|
58
|
+
const entry = {
|
|
59
|
+
turn: state.turn,
|
|
60
|
+
id: String(event.data.id),
|
|
61
|
+
seq: event.seq,
|
|
62
|
+
time: event.time,
|
|
63
|
+
text: messageText(event.data.content)
|
|
64
|
+
};
|
|
65
|
+
return {
|
|
66
|
+
...state,
|
|
67
|
+
questions: [...state.questions, entry]
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
default: return state;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
wire: {
|
|
74
|
+
viewSchema: questionIndexViewSchema,
|
|
75
|
+
view: (state) => state.questions
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
1
79
|
//#region src/index.ts
|
|
2
|
-
/**
|
|
3
|
-
|
|
80
|
+
/** Cordis plugin name. */
|
|
81
|
+
const name = "dsh-question-nav";
|
|
82
|
+
/**
|
|
83
|
+
* Register the `questionIndex` unit. The registry is an optional capability
|
|
84
|
+
* (absent in headless compositions), so registration rides `ctx.inject`:
|
|
85
|
+
* without it the host half simply contributes nothing and the browser strip
|
|
86
|
+
* falls back to live-window questions.
|
|
87
|
+
* @param ctx - plugin context.
|
|
88
|
+
*/
|
|
89
|
+
function apply(ctx) {
|
|
90
|
+
ctx.inject(["sessionProjections"], (inner) => {
|
|
91
|
+
inner.sessionProjections.register(questionIndexProjectionDefinition);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
4
94
|
//#endregion
|
|
5
|
-
export { apply };
|
|
95
|
+
export { apply, name };
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
2
2
|
import type { SessionId } from '@deepseek-ai/dsh-client-connection/client';
|
|
3
3
|
import type { QuestionNode } from '../core/nodes.ts';
|
|
4
|
-
|
|
4
|
+
/** Minimal observable shape of a session projection face. */
|
|
5
|
+
export interface ObservableFace {
|
|
6
|
+
/** Current projection value (unknown — validated structurally at read). */
|
|
7
|
+
getSnapshot: () => unknown;
|
|
8
|
+
/** Subscribe to value changes; returns an unsubscribe. */
|
|
9
|
+
subscribe: (listener: () => void) => () => void;
|
|
10
|
+
}
|
|
5
11
|
/** Values the registrant inject face supplies (wired in src/client/index.ts). */
|
|
6
12
|
export interface QuestionNavInjected {
|
|
7
13
|
/** Extract the user questions of a session's currently loaded window. */
|
|
@@ -10,10 +16,10 @@ export interface QuestionNavInjected {
|
|
|
10
16
|
subscribeList: (cb: () => void) => () => void;
|
|
11
17
|
/** Subscribe to a session's content; returns an unsubscribe. */
|
|
12
18
|
subscribeContent: (sessionId: SessionId, cb: () => void) => () => void;
|
|
19
|
+
/** The session's `questionIndex` projection face, when the host unit is registered. */
|
|
20
|
+
questionProjection: (sessionId: SessionId) => ObservableFace | undefined;
|
|
13
21
|
/** Jump the chat to a question row (pages the window on demand). */
|
|
14
22
|
jump: (sessionId: SessionId, key: string) => void;
|
|
15
|
-
/** Build the full-session question index from the raw history RPC. */
|
|
16
|
-
fetchQuestionIndex: (sessionId: SessionId, options?: HistoryIndexOptions) => Promise<HistoryIndexResult>;
|
|
17
23
|
}
|
|
18
24
|
type ComponentProps = PropsRuntime<'shell.overlay'> & QuestionNavInjected & PropsLocale<'question-nav'>;
|
|
19
25
|
export declare function QuestionNavStrip(props: ComponentProps): React.JSX.Element | null;
|
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Registers one surface into the frame-wide floating layer (`shell.overlay`):
|
|
5
5
|
* a vertical strip on the LEFT edge of the conversation column listing every
|
|
6
|
-
* user question in the current session as a small button
|
|
7
|
-
* scrolls the chat to that question.
|
|
6
|
+
* user question in the current session as a small button, one dot per turn.
|
|
7
|
+
* Clicking a button scrolls the chat to that turn's first question.
|
|
8
8
|
*
|
|
9
|
-
* The
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* The dots are driven by the host-folded `questionIndex` session projection
|
|
10
|
+
* (registered by the plugin's host half): the projection registry folds the
|
|
11
|
+
* WHOLE event log without touching the chat's paged render window, the
|
|
12
|
+
* projection cache persists it, and the standard carriers (history tail-page
|
|
13
|
+
* baseline + session/projection push frames) keep it live. Live-window
|
|
14
|
+
* questions not yet recorded by the projection are merged on top so a
|
|
15
|
+
* just-sent question appears immediately.
|
|
15
16
|
*
|
|
16
17
|
* Failure policy: nothing here throws at apply time — an external plugin must
|
|
17
18
|
* never take the GUI down.
|
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const zh: {
|
|
6
6
|
readonly 'strip.empty': "本会话还没有提问";
|
|
7
|
-
readonly 'strip.loadingAll': "正在加载全部历史…";
|
|
8
|
-
readonly 'strip.loadingSuffix': "…";
|
|
9
|
-
readonly 'strip.loadEarlier': "加载更早的问题";
|
|
10
7
|
readonly 'jump.inactive': "聊天视图未激活";
|
|
11
8
|
readonly 'jump.hidden': "目标无独立气泡,已定位到邻近内容";
|
|
12
9
|
readonly 'jump.notfound': "目标未加载或不存在(可能已压缩)";
|
|
@@ -14,9 +11,6 @@ export declare const zh: {
|
|
|
14
11
|
};
|
|
15
12
|
export declare const en: {
|
|
16
13
|
readonly 'strip.empty': "No questions in this session yet";
|
|
17
|
-
readonly 'strip.loadingAll': "Loading full history…";
|
|
18
|
-
readonly 'strip.loadingSuffix': "…";
|
|
19
|
-
readonly 'strip.loadEarlier': "Load earlier questions";
|
|
20
14
|
readonly 'jump.inactive': "Chat view is not active";
|
|
21
15
|
readonly 'jump.hidden': "No dedicated bubble; landed on nearby content";
|
|
22
16
|
readonly 'jump.notfound': "Target not loaded or missing (maybe compacted)";
|
|
@@ -47,10 +47,3 @@ export declare function nearestRenderable(nodes: Iterable<{
|
|
|
47
47
|
key: string;
|
|
48
48
|
anchorSeq: number;
|
|
49
49
|
} | null;
|
|
50
|
-
/**
|
|
51
|
-
* Merge two question sets (full-history index + live loaded window) into one
|
|
52
|
-
* deduplicated, anchorSeq-ascending list. The window may hold questions that
|
|
53
|
-
* arrived after the index was built; the index may hold questions the window
|
|
54
|
-
* has not loaded yet — union on `key`, newest live copy wins per key.
|
|
55
|
-
*/
|
|
56
|
-
export declare function mergeQuestions(...sources: readonly (readonly QuestionNode[])[]): QuestionNode[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One user question recorded by the `questionIndex` session projection.
|
|
3
|
+
* Shared by the host fold (src/projection.ts) and the browser strip — the
|
|
4
|
+
* wire value is an array of these entries, in seq order.
|
|
5
|
+
*/
|
|
6
|
+
export interface QuestionEntry {
|
|
7
|
+
/** Turn that claimed this question (turn/start the event followed). */
|
|
8
|
+
turn: number;
|
|
9
|
+
/** UserMessage id; the client derives the chat anchor key from it. */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Event seq of the user/message event (ordering + jump anchor seq). */
|
|
12
|
+
seq: number;
|
|
13
|
+
/** Unix ms timestamp of the question. */
|
|
14
|
+
time: number;
|
|
15
|
+
/** First text block of the question (hover tooltip body). */
|
|
16
|
+
text: string;
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn-aligned dot model for the question-nav strip. Pure transforms over the
|
|
3
|
+
* `questionIndex` projection value plus the live chat window — no React, no
|
|
4
|
+
* DOM — so the grouping and merging rules are unit-testable in isolation.
|
|
5
|
+
*
|
|
6
|
+
* One dot per turn that claimed at least one user question; turns without a
|
|
7
|
+
* question (retry, goal continuation, cancelled empty turns) produce no dot,
|
|
8
|
+
* so dot turn labels may skip numbers but always match the Trajectory view.
|
|
9
|
+
*/
|
|
10
|
+
import type { QuestionEntry } from './question-entry.ts';
|
|
11
|
+
import type { QuestionNode } from './nodes.ts';
|
|
12
|
+
/** The conversation Definition kind whose key a user question node uses. */
|
|
13
|
+
export declare const MESSAGE_DEFINITION_KIND = "input-message";
|
|
14
|
+
/**
|
|
15
|
+
* The engine-owned stable chat key for a user question — mirrors
|
|
16
|
+
* `conversationContextKey('input-message', String(id))` from the DSH runtime
|
|
17
|
+
* (verified against that formula in the unit test).
|
|
18
|
+
*/
|
|
19
|
+
export declare function questionKey(id: unknown): string;
|
|
20
|
+
/** One strip dot: a turn's questions (grouped) or one ungrouped live question. */
|
|
21
|
+
export interface TurnDot {
|
|
22
|
+
/** Owning turn number; null for live questions the projection has not seen. */
|
|
23
|
+
readonly turn: number | null;
|
|
24
|
+
/** Jump anchor: the chat key of the turn's FIRST question. */
|
|
25
|
+
readonly key: string;
|
|
26
|
+
/** Anchor seq of the first question (ordering + jump target). */
|
|
27
|
+
readonly anchorSeq: number;
|
|
28
|
+
/** Unix ms of the first question. */
|
|
29
|
+
readonly time: number;
|
|
30
|
+
/** Every question text of this dot, in order (tooltip lists them all). */
|
|
31
|
+
readonly texts: readonly string[];
|
|
32
|
+
/** Chat keys of every question folded into this dot (live-merge dedupe). */
|
|
33
|
+
readonly memberKeys: readonly string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Fold the projection's question list into one dot per turn. Entries arrive
|
|
37
|
+
* in event order; consecutive same-turn entries merge into a single dot whose
|
|
38
|
+
* anchor is the turn's first question.
|
|
39
|
+
*/
|
|
40
|
+
export declare function groupQuestionsByTurn(entries: readonly QuestionEntry[]): TurnDot[];
|
|
41
|
+
/**
|
|
42
|
+
* Merge live-window questions the projection has not recorded yet (the brief
|
|
43
|
+
* window before the session/projection push frame lands). A live question
|
|
44
|
+
* whose key is already folded into a dot is dropped (the projected copy
|
|
45
|
+
* wins); the rest become single-question dots with `turn: null`, inserted in
|
|
46
|
+
* anchor-seq order so the strip stays strictly chronological.
|
|
47
|
+
*/
|
|
48
|
+
export declare function mergeLiveQuestions(dots: readonly TurnDot[], live: readonly QuestionNode[]): TurnDot[];
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Host
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Host half of the dsh-question-nav plugin — runs in the DSH host process.
|
|
3
|
+
* Registers the `questionIndex` session projection unit: the ordered list of
|
|
4
|
+
* user questions (each tagged with its turn), folded from the session event
|
|
5
|
+
* log by the projection registry, persisted by the projection cache, and
|
|
6
|
+
* delivered to the browser through the standard projection carriers (history
|
|
7
|
+
* tail-page baseline + session/projection push frames). The navigation UI
|
|
8
|
+
* itself lives in the browser half (src/client).
|
|
6
9
|
*/
|
|
7
10
|
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
-
/**
|
|
9
|
-
export declare
|
|
11
|
+
/** Cordis plugin name. */
|
|
12
|
+
export declare const name = "dsh-question-nav";
|
|
13
|
+
/**
|
|
14
|
+
* Register the `questionIndex` unit. The registry is an optional capability
|
|
15
|
+
* (absent in headless compositions), so registration rides `ctx.inject`:
|
|
16
|
+
* without it the host half simply contributes nothing and the browser strip
|
|
17
|
+
* falls back to live-window questions.
|
|
18
|
+
* @param ctx - plugin context.
|
|
19
|
+
*/
|
|
20
|
+
export declare function apply(ctx: Context): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `questionIndex` session projection unit: a pure fold of the session
|
|
3
|
+
* event log into the ordered list of user questions, each tagged with the
|
|
4
|
+
* turn that claimed it. Registered on `ctx.sessionProjections` by the host
|
|
5
|
+
* half (src/index.ts); persistence, replay, and client delivery are the
|
|
6
|
+
* projection seam's (session-projection-cache checkpoints the state, the
|
|
7
|
+
* api-proxy carriers seed + push the wire view).
|
|
8
|
+
*
|
|
9
|
+
* Fold rules mirror the chat messageDefinition classification: an
|
|
10
|
+
* append-origin `user/message` with a human (`user`) source is a question;
|
|
11
|
+
* replacement copies (compaction checkpoints) and injected context are not.
|
|
12
|
+
* Turns come from `turn/start` boundaries, so retry/goal-continuation turns
|
|
13
|
+
* without a question simply produce no entry — dots may skip turn numbers,
|
|
14
|
+
* staying exactly aligned with the Trajectory view's turn labels.
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-question-nav/projection
|
|
17
|
+
*/
|
|
18
|
+
import type { ProjectionDefinition } from '@deepseek-ai/dsh-session-projection';
|
|
19
|
+
import type { QuestionEntry } from './core/question-entry.ts';
|
|
20
|
+
/** Fold state: the last opened turn plus every question recorded so far. */
|
|
21
|
+
export interface QuestionIndexState {
|
|
22
|
+
/** Turn of the last `turn/start` (0 before any; turns are 1-based). */
|
|
23
|
+
turn: number;
|
|
24
|
+
/** Every recorded question, in event order. */
|
|
25
|
+
questions: QuestionEntry[];
|
|
26
|
+
}
|
|
27
|
+
declare module '@deepseek-ai/dsh-session-projection/types' {
|
|
28
|
+
interface SessionProjectionMap {
|
|
29
|
+
questionIndex: QuestionEntry[];
|
|
30
|
+
}
|
|
31
|
+
interface SessionProjectionStateMap {
|
|
32
|
+
questionIndex: QuestionIndexState;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** The `questionIndex` unit registered on `ctx.sessionProjections`. */
|
|
36
|
+
export declare const questionIndexProjectionDefinition: Omit<ProjectionDefinition<'questionIndex', QuestionIndexState>, 'wire'> & {
|
|
37
|
+
wire: NonNullable<ProjectionDefinition<'questionIndex', QuestionIndexState>['wire']>;
|
|
38
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luziyang2026/dsh-question-nav",
|
|
3
3
|
"description": "In-session question navigator for the DSH web GUI: a vertical minimap of round dots overlaid on the left edge of the conversation column, one dot per user question — hover enlarges and shows the full question text, click jumps to that message.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"packageManager": "pnpm@11.7.0",
|
|
7
7
|
"engines": {
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
"client": {
|
|
29
29
|
"inject": [
|
|
30
30
|
"@deepseek-ai/dsh-client-runtime",
|
|
31
|
-
"@deepseek-ai/dsh-client-connection",
|
|
32
31
|
"@deepseek-ai/dsh-client-ui-slots",
|
|
33
32
|
"@deepseek-ai/dsh-client-ui-layout",
|
|
34
33
|
"@deepseek-ai/dsh-client-ui-conversation",
|
|
@@ -38,12 +37,12 @@
|
|
|
38
37
|
}
|
|
39
38
|
},
|
|
40
39
|
"scripts": {
|
|
41
|
-
"build": "tsc -p tsconfig.build.json && tsdown",
|
|
40
|
+
"build": "tsc -p tsconfig.build.json && tsc -p tsconfig.build-client.json && tsdown",
|
|
42
41
|
"prepare": "tsdown",
|
|
43
42
|
"prepublishOnly": "pnpm typecheck && pnpm test && pnpm build",
|
|
44
43
|
"watch": "tsdown --watch",
|
|
45
44
|
"test": "vitest run",
|
|
46
|
-
"typecheck": "tsc --noEmit"
|
|
45
|
+
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.host.json"
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
49
48
|
"react": "^18.2.0",
|
|
@@ -57,6 +56,8 @@
|
|
|
57
56
|
"@deepseek-ai/dsh-client-ui-conversation": "^0.1.1-rc.1",
|
|
58
57
|
"@deepseek-ai/dsh-client-ui-layout": "^0.1.1-rc.1",
|
|
59
58
|
"@deepseek-ai/dsh-client-ui-slots": "^0.1.1-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-session": "0.1.1-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-session-projection": "0.1.1-rc.1",
|
|
60
61
|
"@testing-library/dom": "^10.4.1",
|
|
61
62
|
"@testing-library/react": "^16.3.2",
|
|
62
63
|
"@types/node": "^22.20.0",
|
|
@@ -84,5 +85,8 @@
|
|
|
84
85
|
"repository": {
|
|
85
86
|
"type": "git",
|
|
86
87
|
"url": "https://github.com/AbelKeithsun/dsh-question-nav.git"
|
|
88
|
+
},
|
|
89
|
+
"dependencies": {
|
|
90
|
+
"zod": "^4.4.3"
|
|
87
91
|
}
|
|
88
92
|
}
|