dsh-fundus 0.1.0 → 0.1.1
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/README.md +1 -1
- package/lib/client.js.map +1 -1
- package/lib/core.mjs +113 -1
- package/lib/core.mjs.map +2 -2
- package/lib/index.js +139 -21
- package/lib/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-fundus
|
|
2
2
|
|
|
3
|
-
> **Status:** `0.1.
|
|
3
|
+
> **Status:** `0.1.1` — Tier-1 Unified Local Studio Archive for **[The Ivory Tower](https://github.com/janpauldahlke/the-ivory-tower)** / [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness)
|
|
4
4
|
|
|
5
5
|
Indexes documents, `dsh-web-missions` receipts, and tagged media in `~/.ivory-tower/fundus/` (`node:sqlite` FTS5 + BM25), verifies primary-source quote provenance via `ctx.galley.registerPreflight('fundus-quotes')`, and exposes a calm read-only **Sources & Media** right-sidebar inspector.
|
|
6
6
|
|
package/lib/client.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/client/index.tsx", "../src/shared/types.ts", "../src/shared/i18n.ts", "../src/client/FundusIcon.tsx", "../src/client/FundusPane.tsx"],
|
|
4
|
-
"sourcesContent": ["/** dsh-fundus \u2014 browser client face (ModuleLoader CJS entry). */\nimport type { Context } from '@deepseek-ai/cordis'\nimport { PLUGIN } from '../shared/types.ts'\nimport { t, type LocaleCode } from '../shared/i18n.ts'\nimport { FundusIcon } from './FundusIcon.tsx'\nimport { FundusPane } from './FundusPane.tsx'\n\nexport const name = PLUGIN\nexport const inject = ['slots', 'sidebarRightTabs']\n\nconst STYLE = `[data-dsh-fundus],.dsh-fundus-pane{--f-paper:var(--ivory-paper,#FAF7F2);--f-desk:var(--ivory-desk,#EFE9DF);--f-ink:var(--ivory-ink,#1C1917);--f-muted:var(--ivory-ink-muted,#57534E);--f-line:var(--ivory-line,#E3DCD0);--f-ok:var(--ivory-verified,#3D6B4F);color:var(--f-ink);font:13px/1.45 ui-sans-serif,system-ui,sans-serif}.dsh-fundus-pane{display:flex;flex-direction:column;gap:8px;height:100%;padding:8px;background:var(--f-paper)}.dsh-fundus-head{display:flex;justify-content:space-between;align-items:center;color:var(--f-muted);font-size:12px}.dsh-fundus-refresh,.dsh-fundus-pills button,.dsh-fundus-id{border:1px solid var(--f-line);background:var(--f-desk);color:var(--f-ink);border-radius:4px;cursor:pointer;padding:2px 8px}.dsh-fundus-search{width:100%;border:1px solid var(--f-line);border-radius:4px;padding:6px 8px;background:#fff;color:var(--f-ink)}.dsh-fundus-pills{display:flex;gap:4px;flex-wrap:wrap}.dsh-fundus-pills button.is-active{background:var(--f-ok);color:#fff;border-color:var(--f-ok)}.dsh-fundus-list{overflow:auto;display:flex;flex-direction:column;gap:8px}.dsh-fundus-card{display:flex;gap:8px;border-top:1px solid var(--f-line);padding-top:8px;cursor:pointer}.dsh-fundus-thumb{width:48px;height:48px;object-fit:cover;background:var(--f-desk);flex:none}.dsh-fundus-card-body{min-width:0;flex:1}.dsh-fundus-card header{display:flex;justify-content:space-between;gap:8px;align-items:baseline}.dsh-fundus-meta,.dsh-fundus-card footer,.dsh-fundus-empty{color:var(--f-muted);font-size:12px}.dsh-fundus-detail{white-space:pre-wrap;background:var(--f-desk);padding:8px;border-radius:4px;font-size:12px}.dsh-fundus-id{font-family:ui-monospace,monospace;font-size:11px}`\n\nfunction resolveLocale(ctx: Context): LocaleCode {\n try {\n const loc =\n typeof ctx.get === 'function' ? (ctx.get('locale') as { lang?: string } | undefined) : undefined\n return loc?.lang === 'de' ? 'de' : 'en'\n } catch {\n return 'en'\n }\n}\n\nfunction label(ctx: Context, key: 'tabTitle' | 'tabDescription') {\n return t(resolveLocale(ctx), key)\n}\n\nexport function apply(ctx: Context): void {\n if (typeof document !== 'undefined' && !document.querySelector('style[data-dsh-fundus]')) {\n const el = document.createElement('style')\n el.setAttribute('data-dsh-fundus', '')\n el.textContent = STYLE\n document.head.appendChild(el)\n ctx.effect(() => () => el.remove(), 'fundus: style')\n }\n const tabs = ctx.sidebarRightTabs as { register: (d: Record<string, unknown>) => () => void }\n const slots = ctx.slots as {\n inject: (n: string, f: () => () => void) => () => void\n register: (s: { name: string; key: string }, c: unknown) => () => void\n }\n const disposeType = tabs.register({\n id: 'fundus',\n kind: 'fundus',\n title: () => label(ctx, 'tabTitle'),\n guide: [\n {\n id: 'fundus',\n order: 290,\n title: () => label(ctx, 'tabTitle'),\n description: () => label(ctx, 'tabDescription'),\n icon: FundusIcon,\n },\n ],\n })\n const disposeBody = slots.inject('sidebar.right.pane.tab', () =>\n slots.register({ name: 'sidebar.right.pane.tab', key: 'fundus' }, FundusPane),\n )\n ctx.effect(\n () => () => {\n disposeBody()\n disposeType()\n },\n 'fundus: rightbar tab',\n )\n}\n", "/**\n * dsh-fundus \u2014 shared constants & public type authority.\n * Mirror of agent/STUDIO_CONTRACTS.d.ts seams needed by this brick (never import agent/).\n */\n\nexport const PLUGIN = 'dsh-fundus'\nexport const VERSION = '0.1.0'\n\nexport interface HealthProbe {\n ok: true\n plugin: typeof PLUGIN\n version: string\n}\n\nexport type StudioToolCategory =\n | 'archive-intake'\n | 'archive-admin'\n | 'planning'\n | 'plates'\n | 'review'\n\nexport interface StudioTailToolPropertySchema {\n readonly type: 'string' | 'number' | 'integer' | 'boolean' | 'array'\n readonly description: string\n readonly enum?: readonly string[]\n readonly items?: {\n readonly type: 'string' | 'number' | 'integer' | 'boolean'\n readonly enum?: readonly string[]\n }\n readonly minimum?: number\n readonly maximum?: number\n}\n\nexport interface StudioTailToolSchema {\n readonly type: 'object'\n readonly properties: Readonly<Record<string, StudioTailToolPropertySchema>>\n readonly required: readonly string[]\n readonly additionalProperties: false\n}\n\nexport interface StudioTailToolExecContext {\n readonly cwd?: string\n readonly sessionId?: string\n readonly signal?: AbortSignal\n}\n\nexport interface StudioTailToolDescriptor {\n readonly name: string\n readonly owner: string\n readonly category: StudioToolCategory\n readonly description: string\n readonly searchTerms: readonly string[]\n readonly parametersSchema: StudioTailToolSchema\n execute(\n args: Record<string, unknown>,\n exec?: StudioTailToolExecContext,\n ): Promise<Record<string, unknown>> | Record<string, unknown>\n}\n\nexport interface StudioTailToolProvider {\n listTailTools(): readonly StudioTailToolDescriptor[]\n executeTailTool(\n name: string,\n args: Record<string, unknown>,\n exec?: StudioTailToolExecContext,\n ): Promise<Record<string, unknown>>\n}\n\nexport interface SourceProvenanceLike {\n readonly sourceId: string\n readonly quoteSha256?: string\n readonly citation?: string\n readonly locator?: string\n}\n\nexport type GalleyInlineLike =\n | { readonly t: 'text'; readonly v: string }\n | { readonly t: 'strong'; readonly c: readonly GalleyInlineLike[] }\n | { readonly t: 'emph'; readonly c: readonly GalleyInlineLike[] }\n | { readonly t: 'code'; readonly v: string }\n | { readonly t: 'cloze'; readonly hint?: string }\n | { readonly t: 'math'; readonly v: string }\n | { readonly t: 'newline' }\n\nexport interface GalleyBlockLike {\n readonly id: string\n readonly type: string\n readonly body?: readonly GalleyInlineLike[]\n readonly provenance?: SourceProvenanceLike\n readonly [key: string]: unknown\n}\n\nexport interface GalleyPacketLike {\n readonly id: string\n readonly sheetOrder: readonly string[]\n readonly sheets: Readonly<\n Record<\n string,\n {\n readonly id: string\n readonly title: string\n readonly blocks: readonly GalleyBlockLike[]\n }\n >\n >\n readonly [key: string]: unknown\n}\n\nexport interface GalleyPreflightWarningLike {\n readonly code: string\n readonly severity: 'info' | 'warn' | 'error'\n readonly sheetId?: string\n readonly blockId?: string\n readonly message: string\n}\n\nexport interface GalleyServiceLike {\n registerPreflight(\n id: string,\n check: (packet: GalleyPacketLike, cwd: string) => GalleyPreflightWarningLike[],\n ): () => void\n getStore(cwd?: string): {\n listAnnotations?(packetId: string): ReadonlyArray<{\n readonly id: string\n readonly blockId: string\n readonly body: readonly GalleyInlineLike[]\n readonly provenance?: SourceProvenanceLike\n readonly resolved: boolean\n }>\n }\n}\n\nexport interface CompanionShelfItemLike {\n readonly id: string\n readonly section: 'sources' | 'unit-plan' | 'custom'\n readonly label: { readonly en: string; readonly de?: string }\n readonly badge?: string | number\n readonly rightTabKind?: string\n readonly starterPrompt?: string\n}\n\nexport interface IvoryShellServiceLike {\n registerShelfItem(item: CompanionShelfItemLike): () => void\n}\n\nexport type FundusSearchKind = 'all' | 'passage' | 'source' | 'media'\nexport type FundusSourceKind = 'markdown' | 'text' | 'json-pack' | 'web-mission' | 'media'\nexport type FundusVisionStatus = 'none' | 'pending' | 'done' | 'failed'\n\nexport interface FundusQuoteVerification {\n readonly ok: boolean\n readonly code:\n | 'VERIFIED_EXACT'\n | 'VERIFIED_EXCERPT'\n | 'NON_FUNDUS_ID'\n | 'FUNDUS_UNKNOWN_SOURCE'\n | 'FUNDUS_QUOTE_DRIFT'\n | 'FUNDUS_HASH_MISMATCH'\n readonly sourceId: string\n readonly canonicalSha256: string\n readonly expectedSha256?: string\n readonly message?: string\n}\n\nexport interface FundusVisionAdapter {\n readonly id: string\n describeMedia(input: {\n readonly bytes: Buffer\n readonly mimeType: string\n readonly filename?: string\n readonly hintTitle?: string\n readonly signal?: AbortSignal\n }): Promise<{\n readonly description: string\n readonly ocrText?: string\n readonly suggestedTags?: readonly string[]\n readonly model: string\n }>\n}\n\nexport interface FundusConfig {\n readonly enabled?: boolean\n readonly vaultDir?: string\n readonly maxPassageChars?: number\n}\n\nexport interface FundusServiceLike extends StudioTailToolProvider {\n getVaultDir(): string\n getStats(): {\n readonly sources: number\n readonly passages: number\n readonly media: number\n readonly blobs: number\n }\n search(input: {\n readonly query: string\n readonly kind?: FundusSearchKind\n readonly tag?: string\n readonly language?: string\n readonly limit?: number\n }): Record<string, unknown>\n read(input: {\n readonly id: string\n readonly includePassages?: boolean\n }): Record<string, unknown>\n verifyQuote(input: {\n readonly text: string\n readonly provenance: SourceProvenanceLike\n }): FundusQuoteVerification\n registerVisionAdapter?(adapter: FundusVisionAdapter): () => void\n}\n\nexport interface WebMissionPageJson {\n readonly artifact_id: string\n readonly mission_id: string\n readonly url: string\n readonly finalUrl: string\n readonly normalized_url: string\n readonly status: number\n readonly contentType: string\n readonly title: string\n readonly content: string\n readonly fetchedAt: string\n readonly stored_at?: string\n readonly quality: 'full' | 'thin' | 'blocked'\n readonly qualitySignals?: readonly string[]\n}\n", "/**\n * EN + DE UI strings with 100% key parity.\n */\n\nexport type LocaleCode = 'en' | 'de'\n\nconst STRINGS = {\n en: {\n tabTitle: 'Sources & Media',\n tabDescription: 'Search and inspect the local Fundus archive of passages, sources, and media.',\n sourcesLabel: 'Sources & Media',\n refresh: 'Refresh',\n searchPlaceholder: 'Search passages, sources, media\u2026',\n filterAll: 'All',\n filterPassages: 'Passages',\n filterSources: 'Sources',\n filterMedia: 'Media',\n empty: 'No results yet. Ingest sources or clear the search box to browse recent entries.',\n copyId: 'Copy ID',\n stats: '{sources} sources \u00B7 {passages} passages \u00B7 {media} media',\n },\n de: {\n tabTitle: 'Quellen & Medien',\n tabDescription: 'Lokales Fundus-Archiv durchsuchen und Passagen, Quellen sowie Medien pr\u00FCfen.',\n sourcesLabel: 'Quellen & Medien',\n refresh: 'Aktualisieren',\n searchPlaceholder: 'Passagen, Quellen, Medien suchen\u2026',\n filterAll: 'Alle',\n filterPassages: 'Passagen',\n filterSources: 'Quellen',\n filterMedia: 'Medien',\n empty: 'Noch keine Treffer. Quellen einspielen oder Suchfeld leeren, um aktuelle Eintr\u00E4ge zu sehen.',\n copyId: 'ID kopieren',\n stats: '{sources} Quellen \u00B7 {passages} Passagen \u00B7 {media} Medien',\n },\n} as const\n\nexport type FundusUiKey = keyof typeof STRINGS.en\n\nexport function t(locale: LocaleCode, key: FundusUiKey): string {\n return STRINGS[locale][key] ?? STRINGS.en[key]\n}\n\nexport function formatStats(\n locale: LocaleCode,\n stats: { sources: number; passages: number; media: number },\n): string {\n return t(locale, 'stats')\n .replace('{sources}', String(stats.sources))\n .replace('{passages}', String(stats.passages))\n .replace('{media}', String(stats.media))\n}\n\nexport { STRINGS }\n", "/** Minimal archive / index-card icon for the Fundus right-sidebar tab. */\nexport function FundusIcon(props: { size?: number; className?: string }) {\n const size = props.size ?? 18\n return (\n <svg\n className={props.className as string | undefined}\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n aria-hidden=\"true\"\n >\n <rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n <path d=\"M7 9h10M7 13h7M7 17h5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n", "import { useCallback, useEffect, useRef, useState } from 'react'\nimport { formatStats, t, type LocaleCode } from '../shared/i18n.ts'\n\ntype Hit = {\n kind: 'passage' | 'source' | 'media'\n id: string\n sourceId: string\n title: string\n locator?: string\n passageCount?: number\n snippet?: string\n license: string\n tags: string[]\n quoteSha256?: string\n mimeType?: string\n widthPx?: number | null\n heightPx?: number | null\n caption?: string\n}\ntype Filter = 'all' | 'passage' | 'source' | 'media'\n\nfunction resolvePaneLocale(ctx?: { get?: (k: string) => unknown }): LocaleCode {\n try {\n const loc =\n typeof ctx?.get === 'function' ? (ctx.get('locale') as { lang?: string } | undefined) : undefined\n return loc?.lang === 'de' ? 'de' : 'en'\n } catch {\n return 'en'\n }\n}\n\nexport function FundusPane(props: { ctx?: { get?: (k: string) => unknown } }) {\n const locale: LocaleCode = resolvePaneLocale(props.ctx)\n const [query, setQuery] = useState('')\n const [filter, setFilter] = useState<Filter>('all')\n const [hits, setHits] = useState<Hit[]>([])\n const [stats, setStats] = useState({ sources: 0, passages: 0, media: 0 })\n const [expanded, setExpanded] = useState<string | null>(null)\n const [detail, setDetail] = useState('')\n const timer = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const load = useCallback(async (q: string, kind: Filter) => {\n try {\n const res = await fetch(`/api/fundus/search?q=${encodeURIComponent(q || '*')}&kind=${kind}&limit=20`)\n const json = (await res.json()) as { hits?: Hit[]; stats?: typeof stats }\n setHits(json.hits ?? [])\n if (json.stats) setStats(json.stats)\n } catch {\n setHits([])\n }\n }, [])\n\n useEffect(() => {\n if (timer.current) clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(query, filter), 150)\n return () => {\n if (timer.current) clearTimeout(timer.current)\n }\n }, [query, filter, load])\n\n const expand = async (hit: Hit) => {\n if (expanded === hit.id) {\n setExpanded(null)\n setDetail('')\n return\n }\n setExpanded(hit.id)\n try {\n const extra = hit.kind === 'source' ? '&includePassages=1' : ''\n const json = (await (await fetch(`/api/fundus/item?id=${encodeURIComponent(hit.id)}${extra}`)).json()) as {\n text?: string\n quoteSha256?: string\n caption?: string\n passages?: Array<{ id: string; locator: string; text: string }>\n }\n if (hit.kind === 'passage') {\n setDetail(`${json.text ?? ''}\\n\\nsha256: ${json.quoteSha256 ?? ''}`)\n } else if (hit.kind === 'source') {\n setDetail((json.passages ?? []).map((p) => `[${p.id} \u00B7 ${p.locator}] ${p.text}`).join('\\n\\n'))\n } else {\n setDetail(String(json.caption ?? hit.caption ?? ''))\n }\n } catch {\n setDetail('')\n }\n }\n\n const pills: Array<[Filter, string]> = [\n ['all', t(locale, 'filterAll')],\n ['passage', t(locale, 'filterPassages')],\n ['source', t(locale, 'filterSources')],\n ['media', t(locale, 'filterMedia')],\n ]\n\n return (\n <div className=\"dsh-fundus-pane\">\n <div className=\"dsh-fundus-head\">\n <span>{formatStats(locale, stats)}</span>\n <button type=\"button\" className=\"dsh-fundus-refresh\" onClick={() => void load(query, filter)}>\n \u21BB\n </button>\n </div>\n <input\n className=\"dsh-fundus-search\"\n value={query}\n placeholder={t(locale, 'searchPlaceholder')}\n onChange={(e: { target: { value: string } }) => setQuery(e.target.value)}\n />\n <div className=\"dsh-fundus-pills\">\n {pills.map(([id, label]) => (\n <button key={id} type=\"button\" className={filter === id ? 'is-active' : ''} onClick={() => setFilter(id)}>\n {label}\n </button>\n ))}\n </div>\n <div className=\"dsh-fundus-list\">\n {!hits.length ? <p className=\"dsh-fundus-empty\">{t(locale, 'empty')}</p> : null}\n {hits.map((hit) => (\n <article key={hit.id} className=\"dsh-fundus-card\" onClick={() => void expand(hit)}>\n {hit.kind === 'media' ? (\n <img className=\"dsh-fundus-thumb\" src={`/api/fundus/blob?sourceId=${hit.sourceId}`} alt=\"\" width={48} height={48} />\n ) : null}\n <div className=\"dsh-fundus-card-body\">\n <header>\n <strong>{hit.title}</strong>\n <button\n type=\"button\"\n className=\"dsh-fundus-id\"\n onClick={(e: { stopPropagation: () => void }) => {\n e.stopPropagation()\n void navigator.clipboard?.writeText(hit.id)\n }}\n >\n {hit.id}\n </button>\n </header>\n <div className=\"dsh-fundus-meta\">\n {hit.kind === 'passage'\n ? hit.locator\n : hit.kind === 'source'\n ? `${hit.passageCount ?? 0} passages`\n : `${hit.widthPx ?? '?'}\u00D7${hit.heightPx ?? '?'} \u00B7 ${hit.mimeType}`}\n </div>\n <p>{hit.kind === 'media' ? hit.caption : hit.snippet}</p>\n <footer>\n {hit.license}\n {hit.tags?.length ? ` \u00B7 ${hit.tags.join(', ')}` : ''}\n </footer>\n {expanded === hit.id && detail ? <pre className=\"dsh-fundus-detail\">{detail}</pre> : null}\n </div>\n </article>\n ))}\n </div>\n </div>\n )\n}\n"],
|
|
4
|
+
"sourcesContent": ["/** dsh-fundus \u2014 browser client face (ModuleLoader CJS entry). */\nimport type { Context } from '@deepseek-ai/cordis'\nimport { PLUGIN } from '../shared/types.ts'\nimport { t, type LocaleCode } from '../shared/i18n.ts'\nimport { FundusIcon } from './FundusIcon.tsx'\nimport { FundusPane } from './FundusPane.tsx'\n\nexport const name = PLUGIN\nexport const inject = ['slots', 'sidebarRightTabs']\n\nconst STYLE = `[data-dsh-fundus],.dsh-fundus-pane{--f-paper:var(--ivory-paper,#FAF7F2);--f-desk:var(--ivory-desk,#EFE9DF);--f-ink:var(--ivory-ink,#1C1917);--f-muted:var(--ivory-ink-muted,#57534E);--f-line:var(--ivory-line,#E3DCD0);--f-ok:var(--ivory-verified,#3D6B4F);color:var(--f-ink);font:13px/1.45 ui-sans-serif,system-ui,sans-serif}.dsh-fundus-pane{display:flex;flex-direction:column;gap:8px;height:100%;padding:8px;background:var(--f-paper)}.dsh-fundus-head{display:flex;justify-content:space-between;align-items:center;color:var(--f-muted);font-size:12px}.dsh-fundus-refresh,.dsh-fundus-pills button,.dsh-fundus-id{border:1px solid var(--f-line);background:var(--f-desk);color:var(--f-ink);border-radius:4px;cursor:pointer;padding:2px 8px}.dsh-fundus-search{width:100%;border:1px solid var(--f-line);border-radius:4px;padding:6px 8px;background:#fff;color:var(--f-ink)}.dsh-fundus-pills{display:flex;gap:4px;flex-wrap:wrap}.dsh-fundus-pills button.is-active{background:var(--f-ok);color:#fff;border-color:var(--f-ok)}.dsh-fundus-list{overflow:auto;display:flex;flex-direction:column;gap:8px}.dsh-fundus-card{display:flex;gap:8px;border-top:1px solid var(--f-line);padding-top:8px;cursor:pointer}.dsh-fundus-thumb{width:48px;height:48px;object-fit:cover;background:var(--f-desk);flex:none}.dsh-fundus-card-body{min-width:0;flex:1}.dsh-fundus-card header{display:flex;justify-content:space-between;gap:8px;align-items:baseline}.dsh-fundus-meta,.dsh-fundus-card footer,.dsh-fundus-empty{color:var(--f-muted);font-size:12px}.dsh-fundus-detail{white-space:pre-wrap;background:var(--f-desk);padding:8px;border-radius:4px;font-size:12px}.dsh-fundus-id{font-family:ui-monospace,monospace;font-size:11px}`\n\nfunction resolveLocale(ctx: Context): LocaleCode {\n try {\n const loc =\n typeof ctx.get === 'function' ? (ctx.get('locale') as { lang?: string } | undefined) : undefined\n return loc?.lang === 'de' ? 'de' : 'en'\n } catch {\n return 'en'\n }\n}\n\nfunction label(ctx: Context, key: 'tabTitle' | 'tabDescription') {\n return t(resolveLocale(ctx), key)\n}\n\nexport function apply(ctx: Context): void {\n if (typeof document !== 'undefined' && !document.querySelector('style[data-dsh-fundus]')) {\n const el = document.createElement('style')\n el.setAttribute('data-dsh-fundus', '')\n el.textContent = STYLE\n document.head.appendChild(el)\n ctx.effect(() => () => el.remove(), 'fundus: style')\n }\n const tabs = ctx.sidebarRightTabs as { register: (d: Record<string, unknown>) => () => void }\n const slots = ctx.slots as {\n inject: (n: string, f: () => () => void) => () => void\n register: (s: { name: string; key: string }, c: unknown) => () => void\n }\n const disposeType = tabs.register({\n id: 'fundus',\n kind: 'fundus',\n title: () => label(ctx, 'tabTitle'),\n guide: [\n {\n id: 'fundus',\n order: 290,\n title: () => label(ctx, 'tabTitle'),\n description: () => label(ctx, 'tabDescription'),\n icon: FundusIcon,\n },\n ],\n })\n const disposeBody = slots.inject('sidebar.right.pane.tab', () =>\n slots.register({ name: 'sidebar.right.pane.tab', key: 'fundus' }, FundusPane),\n )\n ctx.effect(\n () => () => {\n disposeBody()\n disposeType()\n },\n 'fundus: rightbar tab',\n )\n}\n", "/**\n * dsh-fundus \u2014 shared constants & public type authority.\n * Mirror of agent/STUDIO_CONTRACTS.d.ts seams needed by this brick (never import agent/).\n */\n\nexport const PLUGIN = 'dsh-fundus'\nexport const VERSION = '0.1.1'\n\nexport interface HealthProbe {\n ok: true\n plugin: typeof PLUGIN\n version: string\n}\n\nexport type StudioToolCategory =\n | 'archive-intake'\n | 'archive-admin'\n | 'planning'\n | 'plates'\n | 'review'\n\nexport interface StudioTailToolPropertySchema {\n readonly type: 'string' | 'number' | 'integer' | 'boolean' | 'array'\n readonly description: string\n readonly enum?: readonly string[]\n readonly items?: {\n readonly type: 'string' | 'number' | 'integer' | 'boolean'\n readonly enum?: readonly string[]\n }\n readonly minimum?: number\n readonly maximum?: number\n}\n\nexport interface StudioTailToolSchema {\n readonly type: 'object'\n readonly properties: Readonly<Record<string, StudioTailToolPropertySchema>>\n readonly required: readonly string[]\n readonly additionalProperties: false\n}\n\nexport interface StudioTailToolExecContext {\n readonly cwd?: string\n readonly sessionId?: string\n readonly signal?: AbortSignal\n}\n\nexport interface StudioTailToolDescriptor {\n readonly name: string\n readonly owner: string\n readonly category: StudioToolCategory\n readonly description: string\n readonly searchTerms: readonly string[]\n readonly parametersSchema: StudioTailToolSchema\n execute(\n args: Record<string, unknown>,\n exec?: StudioTailToolExecContext,\n ): Promise<Record<string, unknown>> | Record<string, unknown>\n}\n\nexport interface StudioTailToolProvider {\n listTailTools(): readonly StudioTailToolDescriptor[]\n executeTailTool(\n name: string,\n args: Record<string, unknown>,\n exec?: StudioTailToolExecContext,\n ): Promise<Record<string, unknown>>\n}\n\nexport interface SourceProvenanceLike {\n readonly sourceId: string\n readonly quoteSha256?: string\n readonly citation?: string\n readonly locator?: string\n}\n\nexport type GalleyInlineLike =\n | { readonly t: 'text'; readonly v: string }\n | { readonly t: 'strong'; readonly c: readonly GalleyInlineLike[] }\n | { readonly t: 'emph'; readonly c: readonly GalleyInlineLike[] }\n | { readonly t: 'code'; readonly v: string }\n | { readonly t: 'cloze'; readonly hint?: string }\n | { readonly t: 'math'; readonly v: string }\n | { readonly t: 'newline' }\n\nexport interface GalleyBlockLike {\n readonly id: string\n readonly type: string\n readonly body?: readonly GalleyInlineLike[]\n readonly provenance?: SourceProvenanceLike\n readonly [key: string]: unknown\n}\n\nexport interface GalleyPacketLike {\n readonly id: string\n readonly sheetOrder: readonly string[]\n readonly sheets: Readonly<\n Record<\n string,\n {\n readonly id: string\n readonly title: string\n readonly blocks: readonly GalleyBlockLike[]\n }\n >\n >\n readonly [key: string]: unknown\n}\n\nexport interface GalleyPreflightWarningLike {\n readonly code: string\n readonly severity: 'info' | 'warn' | 'error'\n readonly sheetId?: string\n readonly blockId?: string\n readonly message: string\n}\n\nexport interface GalleyServiceLike {\n registerPreflight(\n id: string,\n check: (packet: GalleyPacketLike, cwd: string) => GalleyPreflightWarningLike[],\n ): () => void\n getStore(cwd?: string): {\n listAnnotations?(packetId: string): ReadonlyArray<{\n readonly id: string\n readonly blockId: string\n readonly body: readonly GalleyInlineLike[]\n readonly provenance?: SourceProvenanceLike\n readonly resolved: boolean\n }>\n }\n}\n\nexport interface CompanionShelfItemLike {\n readonly id: string\n readonly section: 'sources' | 'unit-plan' | 'custom'\n readonly label: { readonly en: string; readonly de?: string }\n readonly badge?: string | number\n readonly rightTabKind?: string\n readonly starterPrompt?: string\n}\n\nexport interface IvoryShellServiceLike {\n registerShelfItem(item: CompanionShelfItemLike): () => void\n}\n\nexport type FundusSearchKind = 'all' | 'passage' | 'source' | 'media'\nexport type FundusSourceKind = 'markdown' | 'text' | 'json-pack' | 'web-mission' | 'media'\nexport type FundusVisionStatus = 'none' | 'pending' | 'done' | 'failed'\n\nexport interface FundusQuoteVerification {\n readonly ok: boolean\n readonly code:\n | 'VERIFIED_EXACT'\n | 'VERIFIED_EXCERPT'\n | 'NON_FUNDUS_ID'\n | 'FUNDUS_UNKNOWN_SOURCE'\n | 'FUNDUS_QUOTE_DRIFT'\n | 'FUNDUS_HASH_MISMATCH'\n readonly sourceId: string\n readonly canonicalSha256: string\n readonly expectedSha256?: string\n readonly message?: string\n}\n\nexport interface FundusVisionAdapter {\n readonly id: string\n describeMedia(input: {\n readonly bytes: Buffer\n readonly mimeType: string\n readonly filename?: string\n readonly hintTitle?: string\n readonly signal?: AbortSignal\n }): Promise<{\n readonly description: string\n readonly ocrText?: string\n readonly suggestedTags?: readonly string[]\n readonly model: string\n }>\n}\n\nexport interface FundusConfig {\n readonly enabled?: boolean\n readonly vaultDir?: string\n readonly maxPassageChars?: number\n}\n\nexport interface FundusServiceLike extends StudioTailToolProvider {\n getVaultDir(): string\n getStats(): {\n readonly sources: number\n readonly passages: number\n readonly media: number\n readonly blobs: number\n }\n search(input: {\n readonly query: string\n readonly kind?: FundusSearchKind\n readonly tag?: string\n readonly language?: string\n readonly limit?: number\n }): Record<string, unknown>\n read(input: {\n readonly id: string\n readonly includePassages?: boolean\n }): Record<string, unknown>\n verifyQuote(input: {\n readonly text: string\n readonly provenance: SourceProvenanceLike\n }): FundusQuoteVerification\n registerVisionAdapter?(adapter: FundusVisionAdapter): () => void\n}\n\nexport interface WebMissionPageJson {\n readonly artifact_id: string\n readonly mission_id: string\n readonly url: string\n readonly finalUrl: string\n readonly normalized_url: string\n readonly status: number\n readonly contentType: string\n readonly title: string\n readonly content: string\n readonly fetchedAt: string\n readonly stored_at?: string\n readonly quality: 'full' | 'thin' | 'blocked'\n readonly qualitySignals?: readonly string[]\n}\n", "/**\n * EN + DE UI strings with 100% key parity.\n */\n\nexport type LocaleCode = 'en' | 'de'\n\nconst STRINGS = {\n en: {\n tabTitle: 'Sources & Media',\n tabDescription: 'Search and inspect the local Fundus archive of passages, sources, and media.',\n sourcesLabel: 'Sources & Media',\n refresh: 'Refresh',\n searchPlaceholder: 'Search passages, sources, media\u2026',\n filterAll: 'All',\n filterPassages: 'Passages',\n filterSources: 'Sources',\n filterMedia: 'Media',\n empty: 'No results yet. Ingest sources or clear the search box to browse recent entries.',\n copyId: 'Copy ID',\n stats: '{sources} sources \u00B7 {passages} passages \u00B7 {media} media',\n },\n de: {\n tabTitle: 'Quellen & Medien',\n tabDescription: 'Lokales Fundus-Archiv durchsuchen und Passagen, Quellen sowie Medien pr\u00FCfen.',\n sourcesLabel: 'Quellen & Medien',\n refresh: 'Aktualisieren',\n searchPlaceholder: 'Passagen, Quellen, Medien suchen\u2026',\n filterAll: 'Alle',\n filterPassages: 'Passagen',\n filterSources: 'Quellen',\n filterMedia: 'Medien',\n empty: 'Noch keine Treffer. Quellen einspielen oder Suchfeld leeren, um aktuelle Eintr\u00E4ge zu sehen.',\n copyId: 'ID kopieren',\n stats: '{sources} Quellen \u00B7 {passages} Passagen \u00B7 {media} Medien',\n },\n} as const\n\nexport type FundusUiKey = keyof typeof STRINGS.en\n\nexport function t(locale: LocaleCode, key: FundusUiKey): string {\n return STRINGS[locale][key] ?? STRINGS.en[key]\n}\n\nexport function formatStats(\n locale: LocaleCode,\n stats: { sources: number; passages: number; media: number },\n): string {\n return t(locale, 'stats')\n .replace('{sources}', String(stats.sources))\n .replace('{passages}', String(stats.passages))\n .replace('{media}', String(stats.media))\n}\n\nexport { STRINGS }\n", "/** Minimal archive / index-card icon for the Fundus right-sidebar tab. */\nexport function FundusIcon(props: { size?: number; className?: string }) {\n const size = props.size ?? 18\n return (\n <svg\n className={props.className as string | undefined}\n width={size}\n height={size}\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n aria-hidden=\"true\"\n >\n <rect x=\"3\" y=\"4\" width=\"18\" height=\"16\" rx=\"2\" stroke=\"currentColor\" strokeWidth=\"1.5\" />\n <path d=\"M7 9h10M7 13h7M7 17h5\" stroke=\"currentColor\" strokeWidth=\"1.5\" strokeLinecap=\"round\" />\n </svg>\n )\n}\n", "import { useCallback, useEffect, useRef, useState } from 'react'\nimport { formatStats, t, type LocaleCode } from '../shared/i18n.ts'\n\ntype Hit = {\n kind: 'passage' | 'source' | 'media'\n id: string\n sourceId: string\n title: string\n locator?: string\n passageCount?: number\n snippet?: string\n license: string\n tags: string[]\n quoteSha256?: string\n mimeType?: string\n widthPx?: number | null\n heightPx?: number | null\n caption?: string\n}\ntype Filter = 'all' | 'passage' | 'source' | 'media'\n\nfunction resolvePaneLocale(ctx?: { get?: (k: string) => unknown }): LocaleCode {\n try {\n const loc =\n typeof ctx?.get === 'function' ? (ctx.get('locale') as { lang?: string } | undefined) : undefined\n return loc?.lang === 'de' ? 'de' : 'en'\n } catch {\n return 'en'\n }\n}\n\nexport function FundusPane(props: { ctx?: { get?: (k: string) => unknown } }) {\n const locale: LocaleCode = resolvePaneLocale(props.ctx)\n const [query, setQuery] = useState('')\n const [filter, setFilter] = useState<Filter>('all')\n const [hits, setHits] = useState<Hit[]>([])\n const [stats, setStats] = useState({ sources: 0, passages: 0, media: 0 })\n const [expanded, setExpanded] = useState<string | null>(null)\n const [detail, setDetail] = useState('')\n const timer = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const load = useCallback(async (q: string, kind: Filter) => {\n try {\n const res = await fetch(`/api/fundus/search?q=${encodeURIComponent(q || '*')}&kind=${kind}&limit=20`)\n const json = (await res.json()) as { hits?: Hit[]; stats?: typeof stats }\n setHits(json.hits ?? [])\n if (json.stats) setStats(json.stats)\n } catch {\n setHits([])\n }\n }, [])\n\n useEffect(() => {\n if (timer.current) clearTimeout(timer.current)\n timer.current = setTimeout(() => void load(query, filter), 150)\n return () => {\n if (timer.current) clearTimeout(timer.current)\n }\n }, [query, filter, load])\n\n const expand = async (hit: Hit) => {\n if (expanded === hit.id) {\n setExpanded(null)\n setDetail('')\n return\n }\n setExpanded(hit.id)\n try {\n const extra = hit.kind === 'source' ? '&includePassages=1' : ''\n const json = (await (await fetch(`/api/fundus/item?id=${encodeURIComponent(hit.id)}${extra}`)).json()) as {\n text?: string\n quoteSha256?: string\n caption?: string\n passages?: Array<{ id: string; locator: string; text: string }>\n }\n if (hit.kind === 'passage') {\n setDetail(`${json.text ?? ''}\\n\\nsha256: ${json.quoteSha256 ?? ''}`)\n } else if (hit.kind === 'source') {\n setDetail((json.passages ?? []).map((p) => `[${p.id} \u00B7 ${p.locator}] ${p.text}`).join('\\n\\n'))\n } else {\n setDetail(String(json.caption ?? hit.caption ?? ''))\n }\n } catch {\n setDetail('')\n }\n }\n\n const pills: Array<[Filter, string]> = [\n ['all', t(locale, 'filterAll')],\n ['passage', t(locale, 'filterPassages')],\n ['source', t(locale, 'filterSources')],\n ['media', t(locale, 'filterMedia')],\n ]\n\n return (\n <div className=\"dsh-fundus-pane\">\n <div className=\"dsh-fundus-head\">\n <span>{formatStats(locale, stats)}</span>\n <button type=\"button\" className=\"dsh-fundus-refresh\" onClick={() => void load(query, filter)}>\n \u21BB\n </button>\n </div>\n <input\n className=\"dsh-fundus-search\"\n value={query}\n placeholder={t(locale, 'searchPlaceholder')}\n onChange={(e: { target: { value: string } }) => setQuery(e.target.value)}\n />\n <div className=\"dsh-fundus-pills\">\n {pills.map(([id, label]) => (\n <button key={id} type=\"button\" className={filter === id ? 'is-active' : ''} onClick={() => setFilter(id)}>\n {label}\n </button>\n ))}\n </div>\n <div className=\"dsh-fundus-list\">\n {!hits.length ? <p className=\"dsh-fundus-empty\">{t(locale, 'empty')}</p> : null}\n {hits.map((hit) => (\n <article key={hit.id} className=\"dsh-fundus-card\" onClick={() => void expand(hit)}>\n {hit.kind === 'media' ? (\n <img className=\"dsh-fundus-thumb\" src={`/api/fundus/blob?sourceId=${hit.sourceId}`} alt=\"\" width={48} height={48} />\n ) : null}\n <div className=\"dsh-fundus-card-body\">\n <header>\n <strong>{hit.title}</strong>\n <button\n type=\"button\"\n className=\"dsh-fundus-id\"\n onClick={(e: { stopPropagation: () => void }) => {\n e.stopPropagation()\n void navigator.clipboard?.writeText(hit.id)\n }}\n >\n {hit.id}\n </button>\n </header>\n <div className=\"dsh-fundus-meta\">\n {hit.kind === 'passage'\n ? hit.locator\n : hit.kind === 'source'\n ? `${hit.passageCount ?? 0} passages`\n : `${hit.widthPx ?? '?'}\u00D7${hit.heightPx ?? '?'} \u00B7 ${hit.mimeType}`}\n </div>\n <p>{hit.kind === 'media' ? hit.caption : hit.snippet}</p>\n <footer>\n {hit.license}\n {hit.tags?.length ? ` \u00B7 ${hit.tags.join(', ')}` : ''}\n </footer>\n {expanded === hit.id && detail ? <pre className=\"dsh-fundus-detail\">{detail}</pre> : null}\n </div>\n </article>\n ))}\n </div>\n </div>\n )\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,SAAS;;;ACCtB,IAAM,UAAU;AAAA,EACd,IAAI;AAAA,IACF,UAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,cAAc;AAAA,IACd,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,IACX,gBAAgB;AAAA,IAChB,eAAe;AAAA,IACf,aAAa;AAAA,IACb,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,OAAO;AAAA,EACT;AAAA,EACA,IAAI;AAAA,IACF,UAAU;AAAA,IACV,gBAAgB;AAAA,IA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|
|
6
6
|
"names": ["import_jsx_runtime", "label"]
|
|
7
7
|
}
|
package/lib/core.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/shared/types.ts
|
|
2
2
|
var PLUGIN = "dsh-fundus";
|
|
3
|
-
var VERSION = "0.1.
|
|
3
|
+
var VERSION = "0.1.1";
|
|
4
4
|
|
|
5
5
|
// src/core/config.ts
|
|
6
6
|
import { homedir } from "node:os";
|
|
@@ -582,6 +582,7 @@ function verifyQuote(input, lookup) {
|
|
|
582
582
|
}
|
|
583
583
|
|
|
584
584
|
// src/core/search.ts
|
|
585
|
+
var MIN_SUBSTRING_TOKEN_LEN = 4;
|
|
585
586
|
function sanitizeFts5Query(raw) {
|
|
586
587
|
const tokens = [];
|
|
587
588
|
const re = /[\p{L}\p{N}]{2,}|[0-9]/gu;
|
|
@@ -603,6 +604,15 @@ function isBrowseQuery(query) {
|
|
|
603
604
|
const q = query.trim();
|
|
604
605
|
return q === "" || q === "*";
|
|
605
606
|
}
|
|
607
|
+
function substringFallbackTokens(tokens) {
|
|
608
|
+
return tokens.filter((t) => t.length >= MIN_SUBSTRING_TOKEN_LEN);
|
|
609
|
+
}
|
|
610
|
+
function escapeLikePattern(raw) {
|
|
611
|
+
return raw.replace(/[\\%_]/g, (ch) => `\\${ch}`);
|
|
612
|
+
}
|
|
613
|
+
function likeContainsPattern(token) {
|
|
614
|
+
return `%${escapeLikePattern(token.toLowerCase())}%`;
|
|
615
|
+
}
|
|
606
616
|
|
|
607
617
|
// src/core/vault.ts
|
|
608
618
|
var ID_RE = /^(?:pas|src)-[0-9a-f]{12}$/;
|
|
@@ -1533,6 +1543,37 @@ CREATE VIRTUAL TABLE IF NOT EXISTS fundus_fts USING fts5(
|
|
|
1533
1543
|
if (rows2.length === 0 && tokens2.length > 1) {
|
|
1534
1544
|
rows2 = runSourceMatch(orExpr2);
|
|
1535
1545
|
}
|
|
1546
|
+
if (rows2.length < limit) {
|
|
1547
|
+
const subToks = substringFallbackTokens(tokens2);
|
|
1548
|
+
if (subToks.length) {
|
|
1549
|
+
const seen = new Set(rows2.map((r) => r.source_id));
|
|
1550
|
+
const likePatterns = subToks.map(likeContainsPattern);
|
|
1551
|
+
const likeClauses = likePatterns.map(
|
|
1552
|
+
() => `(lower(s.title) LIKE ? ESCAPE '\\' OR EXISTS (SELECT 1 FROM passages p2 WHERE p2.source_id = s.source_id AND lower(p2.body) LIKE ? ESCAPE '\\'))`
|
|
1553
|
+
).join(" OR ");
|
|
1554
|
+
const likeParams = [];
|
|
1555
|
+
for (const pat of likePatterns) {
|
|
1556
|
+
likeParams.push(pat, pat);
|
|
1557
|
+
}
|
|
1558
|
+
const sql = `
|
|
1559
|
+
SELECT s.source_id AS entry_id, 'source' AS entry_kind, s.source_id, s.title, s.citation,
|
|
1560
|
+
s.license, s.tags_json, s.passage_count,
|
|
1561
|
+
(SELECT substr(p.body, 1, 240) FROM passages p WHERE p.source_id = s.source_id ORDER BY p.ordinal ASC LIMIT 1) AS snippet
|
|
1562
|
+
FROM sources s
|
|
1563
|
+
WHERE 1=1 ${filterSql}
|
|
1564
|
+
AND (${likeClauses})
|
|
1565
|
+
ORDER BY s.source_id ASC
|
|
1566
|
+
LIMIT ?
|
|
1567
|
+
`;
|
|
1568
|
+
const extra = this.db.prepare(sql).all(...params, ...likeParams, limit * 4);
|
|
1569
|
+
for (const r of extra) {
|
|
1570
|
+
if (seen.has(r.source_id)) continue;
|
|
1571
|
+
seen.add(r.source_id);
|
|
1572
|
+
rows2.push(r);
|
|
1573
|
+
if (rows2.length >= limit) break;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1536
1577
|
return { ok: true, query: input.query, totalMatches: rows2.length, hits: mapHits(rows2) };
|
|
1537
1578
|
}
|
|
1538
1579
|
if (isBrowseQuery(input.query)) {
|
|
@@ -1575,6 +1616,73 @@ CREATE VIRTUAL TABLE IF NOT EXISTS fundus_fts USING fts5(
|
|
|
1575
1616
|
if (rows.length === 0 && tokens.length > 1) {
|
|
1576
1617
|
rows = runMatch(orExpr);
|
|
1577
1618
|
}
|
|
1619
|
+
if (rows.length < limit) {
|
|
1620
|
+
const subToks = substringFallbackTokens(tokens);
|
|
1621
|
+
if (subToks.length) {
|
|
1622
|
+
const seen = new Set(rows.map((r) => r.entry_id));
|
|
1623
|
+
const likePatterns = subToks.map(likeContainsPattern);
|
|
1624
|
+
const need = limit - rows.length;
|
|
1625
|
+
const tagLangFilters = [];
|
|
1626
|
+
const tagLangParams = [];
|
|
1627
|
+
if (tag) {
|
|
1628
|
+
tagLangFilters.push(
|
|
1629
|
+
`EXISTS (SELECT 1 FROM json_each(s.tags_json) WHERE lower(json_each.value) = ?)`
|
|
1630
|
+
);
|
|
1631
|
+
tagLangParams.push(tag);
|
|
1632
|
+
}
|
|
1633
|
+
if (language) {
|
|
1634
|
+
tagLangFilters.push(`s.language = ?`);
|
|
1635
|
+
tagLangParams.push(language);
|
|
1636
|
+
}
|
|
1637
|
+
const tagLangSql = tagLangFilters.length ? `AND ${tagLangFilters.join(" AND ")}` : "";
|
|
1638
|
+
const appendExtra = (extra) => {
|
|
1639
|
+
for (const r of extra) {
|
|
1640
|
+
if (seen.has(r.entry_id)) continue;
|
|
1641
|
+
seen.add(r.entry_id);
|
|
1642
|
+
rows.push(r);
|
|
1643
|
+
if (rows.length >= limit) return true;
|
|
1644
|
+
}
|
|
1645
|
+
return false;
|
|
1646
|
+
};
|
|
1647
|
+
if (kind === "all" || kind === "passage") {
|
|
1648
|
+
const bodyClauses = likePatterns.map(() => `(lower(p.body) LIKE ? ESCAPE '\\' OR lower(s.title) LIKE ? ESCAPE '\\')`).join(" OR ");
|
|
1649
|
+
const bodyParams = [];
|
|
1650
|
+
for (const pat of likePatterns) bodyParams.push(pat, pat);
|
|
1651
|
+
const sql = `
|
|
1652
|
+
SELECT p.passage_id AS entry_id, 'passage' AS entry_kind, p.source_id, s.title, s.citation,
|
|
1653
|
+
s.license, s.tags_json, p.locator, p.quote_sha256, substr(p.body, 1, 240) AS snippet
|
|
1654
|
+
FROM passages p
|
|
1655
|
+
JOIN sources s ON s.source_id = p.source_id
|
|
1656
|
+
WHERE (${bodyClauses}) ${tagLangSql}
|
|
1657
|
+
ORDER BY p.passage_id ASC
|
|
1658
|
+
LIMIT ?
|
|
1659
|
+
`;
|
|
1660
|
+
const extra = this.db.prepare(sql).all(...bodyParams, ...tagLangParams, need * 4);
|
|
1661
|
+
if (appendExtra(extra)) {
|
|
1662
|
+
return { ok: true, query: input.query, totalMatches: rows.length, hits: mapHits(rows) };
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
if (kind === "all" || kind === "media") {
|
|
1666
|
+
const mediaClauses = likePatterns.map(
|
|
1667
|
+
() => `(lower(COALESCE(m.caption, '')) LIKE ? ESCAPE '\\' OR lower(s.title) LIKE ? ESCAPE '\\')`
|
|
1668
|
+
).join(" OR ");
|
|
1669
|
+
const mediaParams = [];
|
|
1670
|
+
for (const pat of likePatterns) mediaParams.push(pat, pat);
|
|
1671
|
+
const sql = `
|
|
1672
|
+
SELECT s.source_id AS entry_id, 'media' AS entry_kind, s.source_id, s.title, s.citation,
|
|
1673
|
+
s.license, s.tags_json, m.mime_type, m.width_px, m.height_px, m.caption,
|
|
1674
|
+
substr(COALESCE(m.caption, s.title), 1, 240) AS snippet
|
|
1675
|
+
FROM media_meta m
|
|
1676
|
+
JOIN sources s ON s.source_id = m.source_id
|
|
1677
|
+
WHERE (${mediaClauses}) ${tagLangSql}
|
|
1678
|
+
ORDER BY s.source_id ASC
|
|
1679
|
+
LIMIT ?
|
|
1680
|
+
`;
|
|
1681
|
+
const extra = this.db.prepare(sql).all(...mediaParams, ...tagLangParams, need * 4);
|
|
1682
|
+
appendExtra(extra);
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1578
1686
|
return { ok: true, query: input.query, totalMatches: rows.length, hits: mapHits(rows) };
|
|
1579
1687
|
}
|
|
1580
1688
|
read(input) {
|
|
@@ -1858,14 +1966,17 @@ function createVaultFromEnv(rawConfig, env = process.env) {
|
|
|
1858
1966
|
export {
|
|
1859
1967
|
BlobStore,
|
|
1860
1968
|
FundusVault,
|
|
1969
|
+
MIN_SUBSTRING_TOKEN_LEN,
|
|
1861
1970
|
PLUGIN,
|
|
1862
1971
|
VERSION,
|
|
1863
1972
|
canonicalizeQuote,
|
|
1864
1973
|
chunkTextIntoPassages,
|
|
1865
1974
|
computeQuoteSha256,
|
|
1866
1975
|
createVaultFromEnv,
|
|
1976
|
+
escapeLikePattern,
|
|
1867
1977
|
galleyInlinesToText,
|
|
1868
1978
|
isBrowseQuery,
|
|
1979
|
+
likeContainsPattern,
|
|
1869
1980
|
listMissionIds,
|
|
1870
1981
|
loadMissionPages,
|
|
1871
1982
|
openFundusVault,
|
|
@@ -1876,6 +1987,7 @@ export {
|
|
|
1876
1987
|
sha256Hex,
|
|
1877
1988
|
shouldIngestPage,
|
|
1878
1989
|
sniffMedia,
|
|
1990
|
+
substringFallbackTokens,
|
|
1879
1991
|
verifyQuote
|
|
1880
1992
|
};
|
|
1881
1993
|
//# sourceMappingURL=core.mjs.map
|