@gmickel/gno 0.7.0 → 0.8.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/LICENSE +21 -0
- package/README.md +90 -50
- package/THIRD_PARTY_NOTICES.md +22 -0
- package/assets/screenshots/webui-ask-answer.png +0 -0
- package/assets/screenshots/webui-collections.png +0 -0
- package/assets/screenshots/webui-editor.png +0 -0
- package/assets/screenshots/webui-home.png +0 -0
- package/assets/skill/SKILL.md +12 -12
- package/assets/skill/cli-reference.md +59 -57
- package/assets/skill/examples.md +8 -7
- package/assets/skill/mcp-reference.md +8 -4
- package/package.json +31 -24
- package/src/app/constants.ts +43 -42
- package/src/cli/colors.ts +1 -1
- package/src/cli/commands/ask.ts +44 -43
- package/src/cli/commands/cleanup.ts +9 -8
- package/src/cli/commands/collection/add.ts +12 -12
- package/src/cli/commands/collection/index.ts +4 -4
- package/src/cli/commands/collection/list.ts +26 -25
- package/src/cli/commands/collection/remove.ts +10 -10
- package/src/cli/commands/collection/rename.ts +10 -10
- package/src/cli/commands/context/add.ts +1 -1
- package/src/cli/commands/context/check.ts +17 -17
- package/src/cli/commands/context/index.ts +4 -4
- package/src/cli/commands/context/list.ts +11 -11
- package/src/cli/commands/context/rm.ts +1 -1
- package/src/cli/commands/doctor.ts +86 -84
- package/src/cli/commands/embed.ts +30 -28
- package/src/cli/commands/get.ts +27 -26
- package/src/cli/commands/index-cmd.ts +9 -9
- package/src/cli/commands/index.ts +16 -16
- package/src/cli/commands/init.ts +13 -12
- package/src/cli/commands/ls.ts +20 -19
- package/src/cli/commands/mcp/config.ts +30 -28
- package/src/cli/commands/mcp/index.ts +4 -4
- package/src/cli/commands/mcp/install.ts +17 -17
- package/src/cli/commands/mcp/paths.ts +133 -133
- package/src/cli/commands/mcp/status.ts +21 -21
- package/src/cli/commands/mcp/uninstall.ts +13 -13
- package/src/cli/commands/mcp.ts +2 -2
- package/src/cli/commands/models/clear.ts +12 -11
- package/src/cli/commands/models/index.ts +5 -5
- package/src/cli/commands/models/list.ts +31 -30
- package/src/cli/commands/models/path.ts +1 -1
- package/src/cli/commands/models/pull.ts +19 -18
- package/src/cli/commands/models/use.ts +4 -4
- package/src/cli/commands/multi-get.ts +38 -36
- package/src/cli/commands/query.ts +21 -20
- package/src/cli/commands/ref-parser.ts +10 -10
- package/src/cli/commands/reset.ts +40 -39
- package/src/cli/commands/search.ts +14 -13
- package/src/cli/commands/serve.ts +4 -4
- package/src/cli/commands/shared.ts +11 -10
- package/src/cli/commands/skill/index.ts +5 -5
- package/src/cli/commands/skill/install.ts +18 -17
- package/src/cli/commands/skill/paths-cmd.ts +11 -10
- package/src/cli/commands/skill/paths.ts +23 -23
- package/src/cli/commands/skill/show.ts +13 -12
- package/src/cli/commands/skill/uninstall.ts +16 -15
- package/src/cli/commands/status.ts +25 -24
- package/src/cli/commands/update.ts +3 -3
- package/src/cli/commands/vsearch.ts +17 -16
- package/src/cli/context.ts +5 -5
- package/src/cli/errors.ts +3 -3
- package/src/cli/format/search-results.ts +37 -37
- package/src/cli/options.ts +43 -43
- package/src/cli/program.ts +455 -459
- package/src/cli/progress.ts +1 -1
- package/src/cli/run.ts +24 -23
- package/src/collection/add.ts +9 -8
- package/src/collection/index.ts +3 -3
- package/src/collection/remove.ts +7 -6
- package/src/collection/types.ts +6 -6
- package/src/config/defaults.ts +1 -1
- package/src/config/index.ts +5 -5
- package/src/config/loader.ts +19 -18
- package/src/config/paths.ts +9 -8
- package/src/config/saver.ts +14 -13
- package/src/config/types.ts +53 -52
- package/src/converters/adapters/markitdownTs/adapter.ts +21 -19
- package/src/converters/adapters/officeparser/adapter.ts +18 -16
- package/src/converters/canonicalize.ts +12 -12
- package/src/converters/errors.ts +26 -22
- package/src/converters/index.ts +8 -8
- package/src/converters/mime.ts +25 -25
- package/src/converters/native/markdown.ts +10 -9
- package/src/converters/native/plaintext.ts +8 -7
- package/src/converters/path.ts +2 -2
- package/src/converters/pipeline.ts +11 -10
- package/src/converters/registry.ts +8 -8
- package/src/converters/types.ts +14 -14
- package/src/converters/versions.ts +4 -4
- package/src/index.ts +4 -4
- package/src/ingestion/chunker.ts +10 -9
- package/src/ingestion/index.ts +6 -6
- package/src/ingestion/language.ts +62 -62
- package/src/ingestion/sync.ts +50 -49
- package/src/ingestion/types.ts +10 -10
- package/src/ingestion/walker.ts +14 -13
- package/src/llm/cache.ts +51 -49
- package/src/llm/errors.ts +40 -36
- package/src/llm/index.ts +9 -9
- package/src/llm/lockfile.ts +6 -6
- package/src/llm/nodeLlamaCpp/adapter.ts +13 -12
- package/src/llm/nodeLlamaCpp/embedding.ts +9 -8
- package/src/llm/nodeLlamaCpp/generation.ts +7 -6
- package/src/llm/nodeLlamaCpp/lifecycle.ts +11 -10
- package/src/llm/nodeLlamaCpp/rerank.ts +6 -5
- package/src/llm/policy.ts +5 -5
- package/src/llm/registry.ts +6 -5
- package/src/llm/types.ts +2 -2
- package/src/mcp/resources/index.ts +15 -13
- package/src/mcp/server.ts +25 -23
- package/src/mcp/tools/get.ts +25 -23
- package/src/mcp/tools/index.ts +32 -29
- package/src/mcp/tools/multi-get.ts +34 -32
- package/src/mcp/tools/query.ts +29 -27
- package/src/mcp/tools/search.ts +14 -12
- package/src/mcp/tools/status.ts +12 -11
- package/src/mcp/tools/vsearch.ts +26 -24
- package/src/pipeline/answer.ts +9 -9
- package/src/pipeline/chunk-lookup.ts +1 -1
- package/src/pipeline/contextual.ts +4 -4
- package/src/pipeline/expansion.ts +23 -21
- package/src/pipeline/explain.ts +21 -21
- package/src/pipeline/fusion.ts +9 -9
- package/src/pipeline/hybrid.ts +41 -42
- package/src/pipeline/index.ts +10 -10
- package/src/pipeline/query-language.ts +39 -39
- package/src/pipeline/rerank.ts +8 -7
- package/src/pipeline/search.ts +22 -22
- package/src/pipeline/types.ts +8 -8
- package/src/pipeline/vsearch.ts +21 -24
- package/src/serve/CLAUDE.md +21 -15
- package/src/serve/config-sync.ts +9 -8
- package/src/serve/context.ts +19 -18
- package/src/serve/index.ts +1 -1
- package/src/serve/jobs.ts +7 -7
- package/src/serve/public/app.tsx +79 -25
- package/src/serve/public/components/AddCollectionDialog.tsx +382 -0
- package/src/serve/public/components/CaptureButton.tsx +60 -0
- package/src/serve/public/components/CaptureModal.tsx +365 -0
- package/src/serve/public/components/IndexingProgress.tsx +333 -0
- package/src/serve/public/components/ShortcutHelpModal.tsx +106 -0
- package/src/serve/public/components/ai-elements/code-block.tsx +42 -32
- package/src/serve/public/components/ai-elements/conversation.tsx +16 -14
- package/src/serve/public/components/ai-elements/inline-citation.tsx +33 -32
- package/src/serve/public/components/ai-elements/loader.tsx +5 -4
- package/src/serve/public/components/ai-elements/message.tsx +39 -37
- package/src/serve/public/components/ai-elements/prompt-input.tsx +97 -95
- package/src/serve/public/components/ai-elements/sources.tsx +12 -10
- package/src/serve/public/components/ai-elements/suggestion.tsx +10 -9
- package/src/serve/public/components/editor/CodeMirrorEditor.tsx +142 -0
- package/src/serve/public/components/editor/MarkdownPreview.tsx +311 -0
- package/src/serve/public/components/editor/index.ts +6 -0
- package/src/serve/public/components/preset-selector.tsx +29 -28
- package/src/serve/public/components/ui/badge.tsx +13 -12
- package/src/serve/public/components/ui/button-group.tsx +13 -12
- package/src/serve/public/components/ui/button.tsx +23 -22
- package/src/serve/public/components/ui/card.tsx +16 -16
- package/src/serve/public/components/ui/carousel.tsx +36 -35
- package/src/serve/public/components/ui/collapsible.tsx +1 -1
- package/src/serve/public/components/ui/command.tsx +17 -15
- package/src/serve/public/components/ui/dialog.tsx +13 -12
- package/src/serve/public/components/ui/dropdown-menu.tsx +13 -12
- package/src/serve/public/components/ui/hover-card.tsx +6 -5
- package/src/serve/public/components/ui/input-group.tsx +45 -43
- package/src/serve/public/components/ui/input.tsx +6 -6
- package/src/serve/public/components/ui/progress.tsx +5 -4
- package/src/serve/public/components/ui/scroll-area.tsx +11 -10
- package/src/serve/public/components/ui/select.tsx +19 -18
- package/src/serve/public/components/ui/separator.tsx +6 -5
- package/src/serve/public/components/ui/table.tsx +18 -18
- package/src/serve/public/components/ui/textarea.tsx +4 -4
- package/src/serve/public/components/ui/tooltip.tsx +5 -4
- package/src/serve/public/globals.css +27 -4
- package/src/serve/public/hooks/use-api.ts +8 -8
- package/src/serve/public/hooks/useCaptureModal.tsx +83 -0
- package/src/serve/public/hooks/useKeyboardShortcuts.ts +85 -0
- package/src/serve/public/index.html +4 -4
- package/src/serve/public/lib/utils.ts +6 -0
- package/src/serve/public/pages/Ask.tsx +27 -26
- package/src/serve/public/pages/Browse.tsx +28 -27
- package/src/serve/public/pages/Collections.tsx +439 -0
- package/src/serve/public/pages/Dashboard.tsx +166 -40
- package/src/serve/public/pages/DocView.tsx +258 -73
- package/src/serve/public/pages/DocumentEditor.tsx +510 -0
- package/src/serve/public/pages/Search.tsx +80 -58
- package/src/serve/routes/api.ts +272 -155
- package/src/serve/security.ts +4 -4
- package/src/serve/server.ts +66 -48
- package/src/store/index.ts +5 -5
- package/src/store/migrations/001-initial.ts +24 -23
- package/src/store/migrations/002-documents-fts.ts +7 -6
- package/src/store/migrations/index.ts +4 -4
- package/src/store/migrations/runner.ts +17 -15
- package/src/store/sqlite/adapter.ts +123 -121
- package/src/store/sqlite/fts5-snowball.ts +24 -23
- package/src/store/sqlite/index.ts +1 -1
- package/src/store/sqlite/setup.ts +12 -12
- package/src/store/sqlite/types.ts +4 -4
- package/src/store/types.ts +19 -19
- package/src/store/vector/index.ts +3 -3
- package/src/store/vector/sqlite-vec.ts +23 -20
- package/src/store/vector/stats.ts +10 -8
- package/src/store/vector/types.ts +2 -2
- package/vendor/fts5-snowball/README.md +6 -6
- package/assets/screenshots/webui-ask-answer.jpg +0 -0
- package/assets/screenshots/webui-home.jpg +0 -0
|
@@ -7,14 +7,15 @@
|
|
|
7
7
|
* @module src/store/sqlite/fts5-snowball
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { Database } from
|
|
10
|
+
import type { Database } from "bun:sqlite";
|
|
11
|
+
|
|
11
12
|
// node:fs: existsSync for sync file checks at load time
|
|
12
|
-
import { existsSync } from
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
13
14
|
// node:path: join for cross-platform paths
|
|
14
|
-
import { join } from
|
|
15
|
+
import { join } from "node:path";
|
|
15
16
|
// node:process: arch/platform detection (no Bun equivalent)
|
|
16
|
-
import { arch, platform } from
|
|
17
|
-
import { fileURLToPath } from
|
|
17
|
+
import { arch, platform } from "node:process";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
18
19
|
|
|
19
20
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
20
21
|
// Types
|
|
@@ -34,30 +35,30 @@ export interface Fts5SnowballLoadResult {
|
|
|
34
35
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
35
36
|
|
|
36
37
|
function getPlatformDir(): string | null {
|
|
37
|
-
const os = platform ===
|
|
38
|
-
const archName = arch ===
|
|
38
|
+
const os = platform === "win32" ? "windows" : platform;
|
|
39
|
+
const archName = arch === "arm64" ? "arm64" : "x64";
|
|
39
40
|
|
|
40
|
-
if (os ===
|
|
41
|
+
if (os === "darwin") {
|
|
41
42
|
return `darwin-${archName}`;
|
|
42
43
|
}
|
|
43
|
-
if (os ===
|
|
44
|
-
return
|
|
44
|
+
if (os === "linux" && archName === "x64") {
|
|
45
|
+
return "linux-x64";
|
|
45
46
|
}
|
|
46
|
-
if (os ===
|
|
47
|
-
return
|
|
47
|
+
if (os === "windows" && archName === "x64") {
|
|
48
|
+
return "windows-x64";
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
return null;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
function getExtensionSuffix(): string {
|
|
54
|
-
if (platform ===
|
|
55
|
-
return
|
|
55
|
+
if (platform === "win32") {
|
|
56
|
+
return "dll";
|
|
56
57
|
}
|
|
57
|
-
if (platform ===
|
|
58
|
-
return
|
|
58
|
+
if (platform === "darwin") {
|
|
59
|
+
return "dylib";
|
|
59
60
|
}
|
|
60
|
-
return
|
|
61
|
+
return "so";
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -78,14 +79,14 @@ export function getExtensionPath(): string | null {
|
|
|
78
79
|
const filename = `fts5stemmer.${suffix}`;
|
|
79
80
|
|
|
80
81
|
// Resolve relative to this module (ESM-safe)
|
|
81
|
-
const thisDir = fileURLToPath(new URL(
|
|
82
|
+
const thisDir = fileURLToPath(new URL(".", import.meta.url));
|
|
82
83
|
const vendorPath = join(
|
|
83
84
|
thisDir,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
"..",
|
|
86
|
+
"..",
|
|
87
|
+
"..",
|
|
88
|
+
"vendor",
|
|
89
|
+
"fts5-snowball",
|
|
89
90
|
platformDir,
|
|
90
91
|
filename
|
|
91
92
|
);
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* @module src/store/sqlite/setup
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { Database } from
|
|
13
|
+
import { Database } from "bun:sqlite";
|
|
14
14
|
// node:fs: existsSync for checking file existence (no async needed at module load)
|
|
15
|
-
import { existsSync } from
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
16
|
// node:os: platform detection (no Bun equivalent)
|
|
17
|
-
import { platform } from
|
|
17
|
+
import { platform } from "node:os";
|
|
18
18
|
|
|
19
19
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
20
20
|
// Types
|
|
@@ -26,7 +26,7 @@ import { platform } from 'node:os';
|
|
|
26
26
|
* - 'custom': Custom SQLite library loaded successfully (macOS with Homebrew)
|
|
27
27
|
* - 'unavailable': Extension loading not possible
|
|
28
28
|
*/
|
|
29
|
-
export type ExtensionLoadingMode =
|
|
29
|
+
export type ExtensionLoadingMode = "native" | "custom" | "unavailable";
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Record of a SQLite load attempt for diagnostics.
|
|
@@ -42,8 +42,8 @@ export interface LoadAttempt {
|
|
|
42
42
|
|
|
43
43
|
// Possible paths to Homebrew SQLite with extension support
|
|
44
44
|
const SQLITE_PATHS = [
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
"/opt/homebrew/opt/sqlite3/lib/libsqlite3.dylib", // macOS Apple Silicon
|
|
46
|
+
"/usr/local/opt/sqlite3/lib/libsqlite3.dylib", // macOS Intel
|
|
47
47
|
];
|
|
48
48
|
|
|
49
49
|
let setupCompleted = false;
|
|
@@ -64,7 +64,7 @@ function setupCustomSqlite(): void {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// Linux/Windows: bundled SQLite supports extensions natively
|
|
67
|
-
if (platform() !==
|
|
67
|
+
if (platform() !== "darwin") {
|
|
68
68
|
setupCompleted = true;
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
@@ -72,7 +72,7 @@ function setupCustomSqlite(): void {
|
|
|
72
72
|
// macOS: try Homebrew paths
|
|
73
73
|
for (const path of SQLITE_PATHS) {
|
|
74
74
|
if (!existsSync(path)) {
|
|
75
|
-
loadAttempts.push({ path, error:
|
|
75
|
+
loadAttempts.push({ path, error: "file not found" });
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
78
|
try {
|
|
@@ -100,10 +100,10 @@ setupCustomSqlite();
|
|
|
100
100
|
* Get the extension loading mode for this platform.
|
|
101
101
|
*/
|
|
102
102
|
export function getExtensionLoadingMode(): ExtensionLoadingMode {
|
|
103
|
-
if (platform() !==
|
|
104
|
-
return
|
|
103
|
+
if (platform() !== "darwin") {
|
|
104
|
+
return "native"; // Linux/Windows: bundled SQLite supports extensions
|
|
105
105
|
}
|
|
106
|
-
return customSqlitePath ?
|
|
106
|
+
return customSqlitePath ? "custom" : "unavailable";
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
/**
|
|
@@ -125,5 +125,5 @@ export function getLoadAttempts(): LoadAttempt[] {
|
|
|
125
125
|
* @deprecated Use getExtensionLoadingMode() !== 'unavailable' instead
|
|
126
126
|
*/
|
|
127
127
|
export function hasExtensionSupport(): boolean {
|
|
128
|
-
return getExtensionLoadingMode() !==
|
|
128
|
+
return getExtensionLoadingMode() !== "unavailable";
|
|
129
129
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module src/store/sqlite/types
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Database } from
|
|
8
|
+
import type { Database } from "bun:sqlite";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Type guard interface for accessing raw SQLite DB.
|
|
@@ -21,8 +21,8 @@ export interface SqliteDbProvider {
|
|
|
21
21
|
export function isSqliteDbProvider(store: unknown): store is SqliteDbProvider {
|
|
22
22
|
return (
|
|
23
23
|
store !== null &&
|
|
24
|
-
typeof store ===
|
|
25
|
-
|
|
26
|
-
typeof (store as SqliteDbProvider).getRawDb ===
|
|
24
|
+
typeof store === "object" &&
|
|
25
|
+
"getRawDb" in store &&
|
|
26
|
+
typeof (store as SqliteDbProvider).getRawDb === "function"
|
|
27
27
|
);
|
|
28
28
|
}
|
package/src/store/types.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module src/store/types
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Collection, Context, FtsTokenizer } from
|
|
8
|
+
import type { Collection, Context, FtsTokenizer } from "../config/types";
|
|
9
9
|
|
|
10
10
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
11
|
// Error Types
|
|
@@ -13,24 +13,24 @@ import type { Collection, Context, FtsTokenizer } from '../config/types';
|
|
|
13
13
|
|
|
14
14
|
/** Store error codes */
|
|
15
15
|
export type StoreErrorCode =
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
16
|
+
| "NOT_FOUND"
|
|
17
|
+
| "ALREADY_EXISTS"
|
|
18
|
+
| "CONSTRAINT_VIOLATION"
|
|
19
|
+
| "MIGRATION_FAILED"
|
|
20
|
+
| "CONNECTION_FAILED"
|
|
21
|
+
| "EXTENSION_LOAD_FAILED"
|
|
22
|
+
| "QUERY_FAILED"
|
|
23
|
+
| "TRANSACTION_FAILED"
|
|
24
|
+
| "INVALID_INPUT"
|
|
25
|
+
| "IO_ERROR"
|
|
26
|
+
| "INTERNAL"
|
|
27
27
|
// Vector-specific error codes (EPIC 7)
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
33
|
-
|
|
|
28
|
+
| "VECTOR_WRITE_FAILED"
|
|
29
|
+
| "VECTOR_DELETE_FAILED"
|
|
30
|
+
| "VEC_SEARCH_UNAVAILABLE"
|
|
31
|
+
| "VEC_SEARCH_FAILED"
|
|
32
|
+
| "VEC_REBUILD_FAILED"
|
|
33
|
+
| "VEC_SYNC_FAILED";
|
|
34
34
|
|
|
35
35
|
/** Store error with structured details */
|
|
36
36
|
export interface StoreError {
|
|
@@ -77,7 +77,7 @@ export interface CollectionRow {
|
|
|
77
77
|
|
|
78
78
|
/** Context row from DB (mirrors config) */
|
|
79
79
|
export interface ContextRow {
|
|
80
|
-
scopeType:
|
|
80
|
+
scopeType: "global" | "collection" | "prefix";
|
|
81
81
|
scopeKey: string;
|
|
82
82
|
text: string;
|
|
83
83
|
syncedAt: string;
|
|
@@ -8,6 +8,6 @@ export {
|
|
|
8
8
|
createVectorIndexPort,
|
|
9
9
|
decodeEmbedding,
|
|
10
10
|
encodeEmbedding,
|
|
11
|
-
} from
|
|
12
|
-
export { createVectorStatsPort } from
|
|
13
|
-
export * from
|
|
11
|
+
} from "./sqlite-vec";
|
|
12
|
+
export { createVectorStatsPort } from "./stats";
|
|
13
|
+
export * from "./types";
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
* @module src/store/vector/sqliteVec
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Database } from
|
|
9
|
-
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import type {
|
|
8
|
+
import type { Database } from "bun:sqlite";
|
|
9
|
+
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
|
|
12
|
+
import type { StoreResult } from "../types";
|
|
13
|
+
import type { VectorIndexPort, VectorRow, VectorSearchResult } from "./types";
|
|
14
|
+
|
|
15
|
+
import { err, ok } from "../types";
|
|
13
16
|
|
|
14
17
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
15
18
|
// BLOB Encoding Helpers (avoid Buffer.buffer footgun)
|
|
@@ -49,7 +52,7 @@ export function decodeEmbedding(blob: Uint8Array): Float32Array {
|
|
|
49
52
|
* First 8 chars of SHA256 hash.
|
|
50
53
|
*/
|
|
51
54
|
function modelTableName(modelUri: string): string {
|
|
52
|
-
const hash = createHash(
|
|
55
|
+
const hash = createHash("sha256").update(modelUri).digest("hex").slice(0, 8);
|
|
53
56
|
return `vec_${hash}`;
|
|
54
57
|
}
|
|
55
58
|
|
|
@@ -60,7 +63,7 @@ function modelTableName(modelUri: string): string {
|
|
|
60
63
|
export interface VectorIndexOptions {
|
|
61
64
|
model: string;
|
|
62
65
|
dimensions: number;
|
|
63
|
-
distanceMetric?:
|
|
66
|
+
distanceMetric?: "cosine" | "l2";
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
/**
|
|
@@ -71,14 +74,14 @@ export async function createVectorIndexPort(
|
|
|
71
74
|
db: Database,
|
|
72
75
|
options: VectorIndexOptions
|
|
73
76
|
): Promise<StoreResult<VectorIndexPort>> {
|
|
74
|
-
const { model, dimensions, distanceMetric =
|
|
77
|
+
const { model, dimensions, distanceMetric = "cosine" } = options;
|
|
75
78
|
const tableName = modelTableName(model);
|
|
76
79
|
|
|
77
80
|
// Try loading sqlite-vec extension (ESM dynamic import)
|
|
78
81
|
let searchAvailable = false;
|
|
79
82
|
let loadError: string | undefined;
|
|
80
83
|
try {
|
|
81
|
-
const sqliteVec = await import(
|
|
84
|
+
const sqliteVec = await import("sqlite-vec");
|
|
82
85
|
sqliteVec.load(db);
|
|
83
86
|
searchAvailable = true;
|
|
84
87
|
} catch (e) {
|
|
@@ -155,7 +158,7 @@ export async function createVectorIndexPort(
|
|
|
155
158
|
} catch (e) {
|
|
156
159
|
return Promise.resolve(
|
|
157
160
|
err(
|
|
158
|
-
|
|
161
|
+
"VECTOR_WRITE_FAILED",
|
|
159
162
|
`Vector write failed: ${e instanceof Error ? e.message : String(e)}`
|
|
160
163
|
)
|
|
161
164
|
);
|
|
@@ -186,7 +189,7 @@ export async function createVectorIndexPort(
|
|
|
186
189
|
} catch (e) {
|
|
187
190
|
return Promise.resolve(
|
|
188
191
|
err(
|
|
189
|
-
|
|
192
|
+
"VECTOR_DELETE_FAILED",
|
|
190
193
|
`Vector delete failed: ${e instanceof Error ? e.message : String(e)}`
|
|
191
194
|
)
|
|
192
195
|
);
|
|
@@ -212,8 +215,8 @@ export async function createVectorIndexPort(
|
|
|
212
215
|
if (!(searchAvailable && searchStmt)) {
|
|
213
216
|
return Promise.resolve(
|
|
214
217
|
err(
|
|
215
|
-
|
|
216
|
-
|
|
218
|
+
"VEC_SEARCH_UNAVAILABLE",
|
|
219
|
+
"Vector search requires sqlite-vec. Embeddings stored but KNN search disabled."
|
|
217
220
|
)
|
|
218
221
|
);
|
|
219
222
|
}
|
|
@@ -235,9 +238,9 @@ export async function createVectorIndexPort(
|
|
|
235
238
|
return Promise.resolve(
|
|
236
239
|
ok(
|
|
237
240
|
filtered.map((r) => {
|
|
238
|
-
const parts = r.chunk_id.split(
|
|
239
|
-
const mirrorHash = parts[0] ??
|
|
240
|
-
const seqStr = parts[1] ??
|
|
241
|
+
const parts = r.chunk_id.split(":");
|
|
242
|
+
const mirrorHash = parts[0] ?? "";
|
|
243
|
+
const seqStr = parts[1] ?? "0";
|
|
241
244
|
return {
|
|
242
245
|
mirrorHash,
|
|
243
246
|
seq: Number.parseInt(seqStr, 10),
|
|
@@ -249,7 +252,7 @@ export async function createVectorIndexPort(
|
|
|
249
252
|
} catch (e) {
|
|
250
253
|
return Promise.resolve(
|
|
251
254
|
err(
|
|
252
|
-
|
|
255
|
+
"VEC_SEARCH_FAILED",
|
|
253
256
|
`Vector search failed: ${e instanceof Error ? e.message : String(e)}`
|
|
254
257
|
)
|
|
255
258
|
);
|
|
@@ -274,7 +277,7 @@ export async function createVectorIndexPort(
|
|
|
274
277
|
// Repopulate from content_vectors
|
|
275
278
|
const rows = db
|
|
276
279
|
.prepare(
|
|
277
|
-
|
|
280
|
+
"SELECT mirror_hash, seq, embedding FROM content_vectors WHERE model = ?"
|
|
278
281
|
)
|
|
279
282
|
.all(model) as {
|
|
280
283
|
mirror_hash: string;
|
|
@@ -297,7 +300,7 @@ export async function createVectorIndexPort(
|
|
|
297
300
|
} catch (e) {
|
|
298
301
|
return Promise.resolve(
|
|
299
302
|
err(
|
|
300
|
-
|
|
303
|
+
"VEC_REBUILD_FAILED",
|
|
301
304
|
`Vec rebuild failed: ${e instanceof Error ? e.message : String(e)}`
|
|
302
305
|
)
|
|
303
306
|
);
|
|
@@ -363,7 +366,7 @@ export async function createVectorIndexPort(
|
|
|
363
366
|
} catch (e) {
|
|
364
367
|
return Promise.resolve(
|
|
365
368
|
err(
|
|
366
|
-
|
|
369
|
+
"VEC_SYNC_FAILED",
|
|
367
370
|
`Vec sync failed: ${e instanceof Error ? e.message : String(e)}`
|
|
368
371
|
)
|
|
369
372
|
);
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* @module src/store/vector/stats
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { Database } from
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import type { BacklogItem, VectorStatsPort } from
|
|
8
|
+
import type { Database } from "bun:sqlite";
|
|
9
|
+
|
|
10
|
+
import type { StoreResult } from "../types";
|
|
11
|
+
import type { BacklogItem, VectorStatsPort } from "./types";
|
|
12
|
+
|
|
13
|
+
import { err, ok } from "../types";
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Create a VectorStatsPort for backlog detection and vector stats.
|
|
@@ -20,14 +22,14 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
20
22
|
try {
|
|
21
23
|
const result = db
|
|
22
24
|
.prepare(
|
|
23
|
-
|
|
25
|
+
"SELECT COUNT(*) as count FROM content_vectors WHERE model = ?"
|
|
24
26
|
)
|
|
25
27
|
.get(model) as { count: number };
|
|
26
28
|
return Promise.resolve(ok(result.count));
|
|
27
29
|
} catch (e) {
|
|
28
30
|
return Promise.resolve(
|
|
29
31
|
err(
|
|
30
|
-
|
|
32
|
+
"QUERY_FAILED",
|
|
31
33
|
`Failed to count vectors: ${e instanceof Error ? e.message : String(e)}`
|
|
32
34
|
)
|
|
33
35
|
);
|
|
@@ -61,7 +63,7 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
61
63
|
} catch (e) {
|
|
62
64
|
return Promise.resolve(
|
|
63
65
|
err(
|
|
64
|
-
|
|
66
|
+
"QUERY_FAILED",
|
|
65
67
|
`Failed to count backlog: ${e instanceof Error ? e.message : String(e)}`
|
|
66
68
|
)
|
|
67
69
|
);
|
|
@@ -145,7 +147,7 @@ export function createVectorStatsPort(db: Database): VectorStatsPort {
|
|
|
145
147
|
} catch (e) {
|
|
146
148
|
return Promise.resolve(
|
|
147
149
|
err(
|
|
148
|
-
|
|
150
|
+
"QUERY_FAILED",
|
|
149
151
|
`Failed to get backlog: ${e instanceof Error ? e.message : String(e)}`
|
|
150
152
|
)
|
|
151
153
|
);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* @module src/store/vector/types
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import type { StoreResult } from
|
|
8
|
+
import type { StoreResult } from "../types";
|
|
9
9
|
|
|
10
10
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
11
|
// Row Types
|
|
@@ -39,7 +39,7 @@ export interface BacklogItem {
|
|
|
39
39
|
seq: number;
|
|
40
40
|
text: string;
|
|
41
41
|
title: string | null;
|
|
42
|
-
reason:
|
|
42
|
+
reason: "new" | "changed" | "force";
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -4,12 +4,12 @@ Prebuilt [fts5-snowball](https://github.com/abiliojr/fts5-snowball) SQLite exten
|
|
|
4
4
|
|
|
5
5
|
## Supported Platforms
|
|
6
6
|
|
|
7
|
-
| Platform | File
|
|
8
|
-
|
|
9
|
-
| Linux
|
|
10
|
-
| macOS
|
|
11
|
-
| macOS
|
|
12
|
-
| Windows
|
|
7
|
+
| Platform | File | Architecture |
|
|
8
|
+
| -------- | -------------------------------- | --------------------- |
|
|
9
|
+
| Linux | `linux-x64/fts5stemmer.so` | x86_64 |
|
|
10
|
+
| macOS | `darwin-arm64/fts5stemmer.dylib` | ARM64 (Apple Silicon) |
|
|
11
|
+
| macOS | `darwin-x64/fts5stemmer.dylib` | x86_64 (Intel) |
|
|
12
|
+
| Windows | `windows-x64/fts5stemmer.dll` | x86_64 |
|
|
13
13
|
|
|
14
14
|
## Build Provenance
|
|
15
15
|
|
|
Binary file
|
|
Binary file
|