maskweaver 0.9.4 → 0.9.6
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.ko.md +638 -592
- package/README.md +671 -667
- package/dist/cli/doctor.js +5 -21
- package/dist/cli/install.d.ts +0 -8
- package/dist/cli/install.js +0 -39
- package/dist/context/config.d.ts +0 -22
- package/dist/context/config.js +0 -28
- package/dist/context/feature.d.ts +0 -39
- package/dist/context/feature.js +0 -77
- package/dist/context/files.d.ts +0 -13
- package/dist/context/files.js +1 -24
- package/dist/context/index.d.ts +0 -7
- package/dist/context/index.js +0 -12
- package/dist/context/project.d.ts +0 -21
- package/dist/context/project.js +0 -30
- package/dist/context/types.d.ts +0 -48
- package/dist/context/types.js +0 -12
- package/dist/context/utils.d.ts +0 -18
- package/dist/context/utils.js +0 -27
- package/dist/core/engine/promptBuilder.d.ts +0 -17
- package/dist/core/engine/promptBuilder.js +0 -28
- package/dist/core/index.d.ts +0 -6
- package/dist/core/index.js +0 -9
- package/dist/core/loader/MaskLoader.d.ts +0 -23
- package/dist/core/loader/MaskLoader.js +0 -29
- package/dist/core/schema/types.d.ts +0 -47
- package/dist/core/schema/types.js +0 -6
- package/dist/core/schema/validator.d.ts +0 -14
- package/dist/core/schema/validator.js +0 -18
- package/dist/i18n/index.d.ts +0 -18
- package/dist/i18n/index.js +4 -23
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/lib.d.ts +0 -5
- package/dist/lib.js +0 -12
- package/dist/memory/chunking.d.ts +0 -22
- package/dist/memory/chunking.js +2 -37
- package/dist/memory/core.d.ts +0 -29
- package/dist/memory/core.js +1 -52
- package/dist/memory/index.d.ts +0 -5
- package/dist/memory/index.js +0 -10
- package/dist/memory/indexer.d.ts +0 -21
- package/dist/memory/indexer.js +0 -44
- package/dist/memory/providers/examples.d.ts +0 -5
- package/dist/memory/providers/examples.js +4 -64
- package/dist/memory/providers/factory.d.ts +0 -44
- package/dist/memory/providers/factory.js +0 -46
- package/dist/memory/providers/index.d.ts +0 -26
- package/dist/memory/providers/index.js +0 -28
- package/dist/memory/providers/ollama.d.ts +0 -6
- package/dist/memory/providers/ollama.js +1 -8
- package/dist/memory/providers/openai.d.ts +0 -6
- package/dist/memory/providers/openai.js +1 -8
- package/dist/memory/providers/openrouter.d.ts +0 -6
- package/dist/memory/providers/openrouter.js +0 -8
- package/dist/memory/providers/text-only.d.ts +0 -13
- package/dist/memory/providers/text-only.js +0 -17
- package/dist/memory/providers/types.d.ts +0 -39
- package/dist/memory/providers/types.js +0 -7
- package/dist/memory/providers/voyage.d.ts +0 -22
- package/dist/memory/providers/voyage.js +1 -24
- package/dist/memory/search/hybrid.d.ts +0 -12
- package/dist/memory/search/hybrid.js +1 -22
- package/dist/memory/store/sqlite.d.ts +0 -72
- package/dist/memory/store/sqlite.js +4 -127
- package/dist/plugin/config/index.d.ts +0 -112
- package/dist/plugin/config/index.js +0 -115
- package/dist/plugin/index.d.ts +0 -13
- package/dist/plugin/index.js +1 -123
- package/dist/plugin/tools/command-registry.d.ts +0 -6
- package/dist/plugin/tools/command-registry.js +0 -14
- package/dist/plugin/tools/context.d.ts +0 -12
- package/dist/plugin/tools/context.js +0 -58
- package/dist/plugin/tools/maskSave.d.ts +0 -3
- package/dist/plugin/tools/maskSave.js +0 -3
- package/dist/plugin/tools/memoryGet.d.ts +0 -3
- package/dist/plugin/tools/memoryGet.js +0 -3
- package/dist/plugin/tools/memoryIndexer.d.ts +0 -3
- package/dist/plugin/tools/memoryIndexer.js +0 -10
- package/dist/plugin/tools/memorySearch.d.ts +0 -31
- package/dist/plugin/tools/memorySearch.js +0 -79
- package/dist/plugin/tools/memoryWrite.d.ts +0 -8
- package/dist/plugin/tools/memoryWrite.js +0 -32
- package/dist/plugin/tools/retrospect.d.ts +0 -3
- package/dist/plugin/tools/retrospect.js +0 -3
- package/dist/plugin/tools/slashcommand.d.ts +0 -11
- package/dist/plugin/tools/slashcommand.js +0 -38
- package/dist/plugin/tools/squad.d.ts +0 -12
- package/dist/plugin/tools/squad.js +11 -83
- package/dist/plugin/tools/weave.d.ts +0 -6
- package/dist/plugin/tools/weave.js +0 -78
- package/dist/plugin/types.d.ts +0 -20
- package/dist/plugin/types.js +0 -7
- package/dist/retrospect/index.d.ts +0 -7
- package/dist/retrospect/index.js +0 -9
- package/dist/retrospect/mask-save.d.ts +0 -12
- package/dist/retrospect/mask-save.js +1 -80
- package/dist/retrospect/retrospect.d.ts +0 -18
- package/dist/retrospect/retrospect.js +0 -63
- package/dist/retrospect/strategies/base.d.ts +0 -15
- package/dist/retrospect/strategies/base.js +0 -7
- package/dist/retrospect/strategies/deep.d.ts +0 -12
- package/dist/retrospect/strategies/deep.js +0 -24
- package/dist/retrospect/strategies/index.d.ts +0 -12
- package/dist/retrospect/strategies/index.js +0 -12
- package/dist/retrospect/strategies/quick.d.ts +0 -12
- package/dist/retrospect/strategies/quick.js +0 -19
- package/dist/retrospect/strategies/standard.d.ts +0 -12
- package/dist/retrospect/strategies/standard.js +0 -15
- package/dist/retrospect/types.d.ts +0 -7
- package/dist/retrospect/types.js +0 -7
- package/dist/shared/config.d.ts +0 -105
- package/dist/shared/config.js +0 -33
- package/dist/shared/errors.d.ts +0 -18
- package/dist/shared/errors.js +0 -19
- package/dist/shared/generate-agents.d.ts +0 -69
- package/dist/shared/generate-agents.js +2 -86
- package/dist/shared/image.d.ts +0 -67
- package/dist/shared/image.js +6 -104
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -7
- package/dist/shared/model-registry.d.ts +0 -72
- package/dist/shared/model-registry.js +5 -95
- package/dist/shared/types.d.ts +0 -15
- package/dist/shared/types.js +0 -3
- package/dist/shared-context/dag.d.ts +0 -105
- package/dist/shared-context/dag.js +3 -114
- package/dist/shared-context/index.d.ts +0 -5
- package/dist/shared-context/index.js +0 -15
- package/dist/shared-context/logger.d.ts +0 -37
- package/dist/shared-context/logger.js +0 -41
- package/dist/shared-context/parallel-executor.d.ts +0 -54
- package/dist/shared-context/parallel-executor.js +4 -56
- package/dist/shared-context/session.d.ts +0 -56
- package/dist/shared-context/session.js +0 -47
- package/dist/shared-context/squad.d.ts +0 -68
- package/dist/shared-context/squad.js +0 -63
- package/dist/shared-context/storage.d.ts +0 -132
- package/dist/shared-context/storage.js +0 -116
- package/dist/shared-context/task.d.ts +0 -120
- package/dist/shared-context/task.js +0 -152
- package/dist/shared-context/test/dag.test.js +9 -14
- package/dist/shared-context/test/logger.test.d.ts +0 -8
- package/dist/shared-context/test/logger.test.js +0 -52
- package/dist/shared-context/test/session.test.d.ts +0 -7
- package/dist/shared-context/test/session.test.js +0 -63
- package/dist/shared-context/test/squad.test.d.ts +0 -10
- package/dist/shared-context/test/squad.test.js +2 -68
- package/dist/shared-context/test/storage.test.d.ts +0 -8
- package/dist/shared-context/test/storage.test.js +0 -68
- package/dist/shared-context/test/task.test.d.ts +0 -7
- package/dist/shared-context/test/task.test.js +0 -54
- package/dist/shared-context/test/watchdog.test.d.ts +0 -7
- package/dist/shared-context/test/watchdog.test.js +3 -58
- package/dist/shared-context/types.d.ts +0 -215
- package/dist/shared-context/types.js +0 -125
- package/dist/shared-context/watchdog.d.ts +0 -127
- package/dist/shared-context/watchdog.js +0 -148
- package/dist/shared-context/worktree.d.ts +0 -68
- package/dist/shared-context/worktree.js +2 -34
- package/dist/verify/budget.d.ts +0 -29
- package/dist/verify/budget.js +0 -34
- package/dist/verify/critical-files.d.ts +0 -17
- package/dist/verify/critical-files.js +0 -37
- package/dist/verify/escalation.d.ts +0 -20
- package/dist/verify/escalation.js +0 -22
- package/dist/verify/index.d.ts +0 -5
- package/dist/verify/index.js +0 -11
- package/dist/verify/prompts.d.ts +0 -20
- package/dist/verify/prompts.js +0 -20
- package/dist/verify/types.d.ts +0 -26
- package/dist/verify/types.js +1 -12
- package/dist/verify/verifier.d.ts +0 -29
- package/dist/verify/verifier.js +0 -54
- package/dist/version.d.ts +1 -16
- package/dist/version.js +1 -16
- package/dist/weave/bridge.d.ts +0 -35
- package/dist/weave/bridge.js +0 -51
- package/dist/weave/environment/detector.d.ts +0 -6
- package/dist/weave/environment/detector.js +4 -45
- package/dist/weave/environment/index.d.ts +0 -19
- package/dist/weave/environment/index.js +1 -39
- package/dist/weave/environment/issues.d.ts +0 -35
- package/dist/weave/environment/issues.js +0 -59
- package/dist/weave/git.d.ts +0 -8
- package/dist/weave/git.js +0 -8
- package/dist/weave/index.d.ts +0 -13
- package/dist/weave/index.js +2 -28
- package/dist/weave/knowledge/global.d.ts +0 -39
- package/dist/weave/knowledge/global.js +2 -78
- package/dist/weave/loop.js +0 -3
- package/dist/weave/orchestrator.d.ts +0 -69
- package/dist/weave/orchestrator.js +1 -101
- package/dist/weave/phase-manager.d.ts +0 -64
- package/dist/weave/phase-manager.js +0 -89
- package/dist/weave/security/secret-scan.d.ts +0 -14
- package/dist/weave/security/secret-scan.js +0 -19
- package/dist/weave/stages/build.js +0 -15
- package/dist/weave/stages/execute.d.ts +0 -42
- package/dist/weave/stages/execute.js +4 -86
- package/dist/weave/stages/handoff.d.ts +0 -7
- package/dist/weave/stages/handoff.js +0 -43
- package/dist/weave/stages/index.d.ts +0 -3
- package/dist/weave/stages/index.js +0 -3
- package/dist/weave/stages/intake.d.ts +0 -8
- package/dist/weave/stages/intake.js +5 -65
- package/dist/weave/stages/map.d.ts +0 -1
- package/dist/weave/stages/openspec.d.ts +0 -1
- package/dist/weave/stages/plan.d.ts +0 -11
- package/dist/weave/stages/plan.js +1 -53
- package/dist/weave/stages/refine.d.ts +0 -7
- package/dist/weave/stages/refine.js +0 -7
- package/dist/weave/stages/research.d.ts +0 -6
- package/dist/weave/stages/research.js +0 -6
- package/dist/weave/stages/spec.d.ts +0 -12
- package/dist/weave/stages/spec.js +0 -17
- package/dist/weave/types.d.ts +0 -20
- package/dist/weave/types.js +0 -5
- package/dist/weave/verification/commands.d.ts +0 -12
- package/dist/weave/verification/commands.js +0 -19
- package/dist/weave/verification/index.d.ts +0 -6
- package/dist/weave/verification/index.js +1 -19
- package/dist/weave/verification/playwright.d.ts +0 -47
- package/dist/weave/verification/playwright.js +1 -90
- package/dist/weave/worktree.d.ts +0 -16
- package/dist/weave/worktree.js +0 -23
- package/dist/weave/yaml-repair.d.ts +0 -39
- package/dist/weave/yaml-repair.js +13 -116
- package/package.json +1 -1
package/dist/memory/indexer.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File Indexer - Process markdown files into searchable chunks
|
|
3
|
-
*
|
|
4
|
-
* Read file → Parse sections → Chunk → Hash → Embed → Store
|
|
5
|
-
*/
|
|
6
1
|
import { readFile } from 'fs/promises';
|
|
7
2
|
import { chunkText } from './chunking.js';
|
|
8
3
|
import { initDatabase, upsertChunk, deleteChunksByPath, getChunksByPath } from './store/sqlite.js';
|
|
9
4
|
import { getDbPath } from './core.js';
|
|
10
5
|
const HEADER_REGEX = /^(#{1,6})\s+(.+)$/;
|
|
11
|
-
/**
|
|
12
|
-
* Parse markdown into sections.
|
|
13
|
-
*/
|
|
14
6
|
export function parseMarkdownSections(content) {
|
|
15
7
|
const lines = content.split('\n');
|
|
16
8
|
const sections = [];
|
|
@@ -22,7 +14,6 @@ export function parseMarkdownSections(content) {
|
|
|
22
14
|
const lineNumber = i + 1;
|
|
23
15
|
const headerMatch = line.match(HEADER_REGEX);
|
|
24
16
|
if (headerMatch) {
|
|
25
|
-
// Save previous section
|
|
26
17
|
if (currentSection !== null || currentLines.length > 0) {
|
|
27
18
|
sections.push({
|
|
28
19
|
header: currentSection?.header || '',
|
|
@@ -32,7 +23,6 @@ export function parseMarkdownSections(content) {
|
|
|
32
23
|
endLine: lineNumber - 1
|
|
33
24
|
});
|
|
34
25
|
}
|
|
35
|
-
// Start new section
|
|
36
26
|
currentSection = {
|
|
37
27
|
header: headerMatch[2],
|
|
38
28
|
content: '',
|
|
@@ -47,7 +37,6 @@ export function parseMarkdownSections(content) {
|
|
|
47
37
|
currentLines.push(line);
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
|
-
// Save last section
|
|
51
40
|
if (currentLines.length > 0) {
|
|
52
41
|
sections.push({
|
|
53
42
|
header: currentSection?.header || '',
|
|
@@ -59,9 +48,6 @@ export function parseMarkdownSections(content) {
|
|
|
59
48
|
}
|
|
60
49
|
return sections;
|
|
61
50
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Classify source from file path.
|
|
64
|
-
*/
|
|
65
51
|
export function classifySource(filePath) {
|
|
66
52
|
const normalized = filePath.replace(/\\/g, '/').toLowerCase();
|
|
67
53
|
const fileName = normalized.split('/').pop() || '';
|
|
@@ -77,34 +63,17 @@ export function classifySource(filePath) {
|
|
|
77
63
|
return 'daily';
|
|
78
64
|
return 'memory';
|
|
79
65
|
}
|
|
80
|
-
// ============================================================================
|
|
81
|
-
// File Processing
|
|
82
|
-
// ============================================================================
|
|
83
|
-
/**
|
|
84
|
-
* Process markdown file into chunks.
|
|
85
|
-
*/
|
|
86
66
|
async function processFile(filePath) {
|
|
87
67
|
const content = await readFile(filePath, 'utf-8');
|
|
88
68
|
return chunkText(content, filePath);
|
|
89
69
|
}
|
|
90
|
-
// ============================================================================
|
|
91
|
-
// Indexing
|
|
92
|
-
// ============================================================================
|
|
93
|
-
/**
|
|
94
|
-
* Index a single file.
|
|
95
|
-
* Only re-embeds chunks that changed (based on hash).
|
|
96
|
-
*/
|
|
97
70
|
export async function indexFile(filePath, getEmbedding, basePath) {
|
|
98
71
|
console.log(`[Indexer] Processing: ${filePath}`);
|
|
99
|
-
// Initialize database
|
|
100
72
|
await initDatabase(getDbPath(basePath));
|
|
101
|
-
// Process file
|
|
102
73
|
const chunks = await processFile(filePath);
|
|
103
74
|
console.log(`[Indexer] Generated ${chunks.length} chunks`);
|
|
104
|
-
// Get existing chunks for hash comparison
|
|
105
75
|
const existingChunks = getChunksByPath(filePath);
|
|
106
76
|
const existingHashes = new Set(existingChunks.map(c => c.hash));
|
|
107
|
-
// Process only changed chunks
|
|
108
77
|
let newCount = 0;
|
|
109
78
|
let skippedCount = 0;
|
|
110
79
|
for (const chunk of chunks) {
|
|
@@ -112,22 +81,16 @@ export async function indexFile(filePath, getEmbedding, basePath) {
|
|
|
112
81
|
skippedCount++;
|
|
113
82
|
continue;
|
|
114
83
|
}
|
|
115
|
-
// New or changed chunk - compute embedding
|
|
116
84
|
const embedding = await getEmbedding(chunk.text);
|
|
117
85
|
upsertChunk(chunk, embedding);
|
|
118
86
|
newCount++;
|
|
119
87
|
}
|
|
120
88
|
console.log(`[Indexer] Completed: ${newCount} new, ${skippedCount} unchanged`);
|
|
121
89
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Reindex file (delete all chunks and reindex).
|
|
124
|
-
*/
|
|
125
90
|
export async function reindexFile(filePath, getEmbedding, basePath) {
|
|
126
91
|
console.log(`[Indexer] Reindexing: ${filePath}`);
|
|
127
92
|
await initDatabase(getDbPath(basePath));
|
|
128
|
-
// Delete existing chunks
|
|
129
93
|
deleteChunksByPath(filePath);
|
|
130
|
-
// Process and index all chunks
|
|
131
94
|
const chunks = await processFile(filePath);
|
|
132
95
|
for (const chunk of chunks) {
|
|
133
96
|
const embedding = await getEmbedding(chunk.text);
|
|
@@ -135,13 +98,9 @@ export async function reindexFile(filePath, getEmbedding, basePath) {
|
|
|
135
98
|
}
|
|
136
99
|
console.log(`[Indexer] Reindexed ${chunks.length} chunks`);
|
|
137
100
|
}
|
|
138
|
-
/**
|
|
139
|
-
* Index all memory files in directory.
|
|
140
|
-
*/
|
|
141
101
|
export async function indexAllMemoryFiles(baseDir, getEmbedding, basePath) {
|
|
142
102
|
console.log(`[Indexer] Scanning directory: ${baseDir}`);
|
|
143
103
|
await initDatabase(getDbPath(basePath || baseDir));
|
|
144
|
-
// Main memory files
|
|
145
104
|
const mainFiles = ['MEMORY.md', 'MASKS.md', 'RETROSPECT.md', 'USER.md'];
|
|
146
105
|
let totalFiles = 0;
|
|
147
106
|
for (const fileName of mainFiles) {
|
|
@@ -151,11 +110,8 @@ export async function indexAllMemoryFiles(baseDir, getEmbedding, basePath) {
|
|
|
151
110
|
totalFiles++;
|
|
152
111
|
}
|
|
153
112
|
catch (error) {
|
|
154
|
-
// File doesn't exist or not readable
|
|
155
113
|
console.log(`[Indexer] Skipping ${fileName}: ${error}`);
|
|
156
114
|
}
|
|
157
115
|
}
|
|
158
|
-
// TODO: Scan daily directory
|
|
159
|
-
// This requires glob or fs.readdir
|
|
160
116
|
console.log(`[Indexer] Completed indexing ${totalFiles} files`);
|
|
161
117
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Embedding Provider Usage Examples
|
|
3
|
-
*
|
|
4
|
-
* Practical examples showing how to use the provider system.
|
|
5
|
-
*/
|
|
6
1
|
declare function example1_autoSelection(): Promise<void>;
|
|
7
2
|
declare function example2_manualSelection(): Promise<void>;
|
|
8
3
|
declare function example3_codeEmbedding(): Promise<void>;
|
|
@@ -1,20 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Embedding Provider Usage Examples
|
|
3
|
-
*
|
|
4
|
-
* Practical examples showing how to use the provider system.
|
|
5
|
-
*/
|
|
6
1
|
import { createProvider, selectBestProvider, getDefaultConfigs } from "./index.js";
|
|
7
|
-
// ============================================================================
|
|
8
|
-
// Example 1: Auto-selection (Recommended)
|
|
9
|
-
// ============================================================================
|
|
10
2
|
async function example1_autoSelection() {
|
|
11
3
|
console.log("Example 1: Auto-selection with graceful degradation\n");
|
|
12
|
-
// Let the system choose the best available provider
|
|
13
4
|
const provider = await selectBestProvider(getDefaultConfigs());
|
|
14
5
|
console.log(`✓ Selected: ${provider.name}`);
|
|
15
6
|
console.log(` Type: ${provider.type}`);
|
|
16
7
|
console.log(` Dimensions: ${provider.dimensions}\n`);
|
|
17
|
-
// Use it!
|
|
18
8
|
const embeddings = await provider.embed([
|
|
19
9
|
"Hello, world!",
|
|
20
10
|
"TypeScript is awesome"
|
|
@@ -22,18 +12,13 @@ async function example1_autoSelection() {
|
|
|
22
12
|
console.log(`Generated ${embeddings.length} embeddings`);
|
|
23
13
|
console.log(`Each embedding has ${embeddings[0].length} dimensions\n`);
|
|
24
14
|
}
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Example 2: Manual Provider Selection
|
|
27
|
-
// ============================================================================
|
|
28
15
|
async function example2_manualSelection() {
|
|
29
16
|
console.log("Example 2: Manual provider selection\n");
|
|
30
|
-
// For local development - privacy-first
|
|
31
17
|
const localProvider = createProvider({
|
|
32
18
|
type: "ollama",
|
|
33
19
|
model: "nomic-embed-text"
|
|
34
20
|
});
|
|
35
21
|
console.log(`Using: ${localProvider.name}`);
|
|
36
|
-
// Check health before using
|
|
37
22
|
const health = await localProvider.healthCheck();
|
|
38
23
|
if (!health.ok) {
|
|
39
24
|
console.error(`❌ ${health.reason}`);
|
|
@@ -46,9 +31,6 @@ async function example2_manualSelection() {
|
|
|
46
31
|
const embeddings = await localProvider.embed(["Test document"]);
|
|
47
32
|
console.log(`Generated embedding with ${embeddings[0].length} dimensions\n`);
|
|
48
33
|
}
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// Example 3: Code-Specialized Embedding
|
|
51
|
-
// ============================================================================
|
|
52
34
|
async function example3_codeEmbedding() {
|
|
53
35
|
console.log("Example 3: Code-specialized embedding with Voyage\n");
|
|
54
36
|
const codeProvider = createProvider({
|
|
@@ -57,22 +39,17 @@ async function example3_codeEmbedding() {
|
|
|
57
39
|
dimensions: 1024,
|
|
58
40
|
apiKey: process.env.VOYAGE_API_KEY
|
|
59
41
|
});
|
|
60
|
-
// Code snippets
|
|
61
42
|
const codeSnippets = [
|
|
62
43
|
"function fibonacci(n: number): number { return n < 2 ? n : fibonacci(n-1) + fibonacci(n-2); }",
|
|
63
44
|
"const factorial = (n: number): number => n <= 1 ? 1 : n * factorial(n - 1);",
|
|
64
45
|
"class Stack<T> { private items: T[] = []; push(item: T) { this.items.push(item); } }"
|
|
65
46
|
];
|
|
66
|
-
// Use code-specific embedding
|
|
67
47
|
if (codeProvider.embedCode) {
|
|
68
48
|
const embeddings = await codeProvider.embedCode(codeSnippets);
|
|
69
49
|
console.log(`Generated ${embeddings.length} code embeddings`);
|
|
70
50
|
console.log(`Optimized for code similarity search\n`);
|
|
71
51
|
}
|
|
72
52
|
}
|
|
73
|
-
// ============================================================================
|
|
74
|
-
// Example 4: Asymmetric Search (Query vs Document)
|
|
75
|
-
// ============================================================================
|
|
76
53
|
async function example4_asymmetricSearch() {
|
|
77
54
|
console.log("Example 4: Asymmetric search with Voyage\n");
|
|
78
55
|
const provider = createProvider({
|
|
@@ -80,17 +57,13 @@ async function example4_asymmetricSearch() {
|
|
|
80
57
|
model: "voyage-4-lite",
|
|
81
58
|
apiKey: process.env.VOYAGE_API_KEY
|
|
82
59
|
});
|
|
83
|
-
// Documents (what you're searching through)
|
|
84
60
|
const documents = [
|
|
85
61
|
"TypeScript is a strongly typed programming language that builds on JavaScript.",
|
|
86
62
|
"Python is an interpreted, high-level programming language with dynamic semantics.",
|
|
87
63
|
"Rust is a systems programming language focused on safety and performance."
|
|
88
64
|
];
|
|
89
|
-
// Query (what the user is searching for)
|
|
90
65
|
const query = "What is a type-safe language?";
|
|
91
|
-
// Embed documents
|
|
92
66
|
const docEmbeddings = await provider.embed(documents);
|
|
93
|
-
// Embed query (optimized differently)
|
|
94
67
|
let queryEmbedding;
|
|
95
68
|
if (provider.embedQuery) {
|
|
96
69
|
queryEmbedding = await provider.embedQuery(query);
|
|
@@ -100,14 +73,12 @@ async function example4_asymmetricSearch() {
|
|
|
100
73
|
[queryEmbedding] = await provider.embed([query]);
|
|
101
74
|
console.log("✓ Used standard embedding");
|
|
102
75
|
}
|
|
103
|
-
// Compute cosine similarity (simplified)
|
|
104
76
|
const similarities = docEmbeddings.map((docEmb) => {
|
|
105
77
|
const dotProduct = docEmb.reduce((sum, val, i) => sum + val * queryEmbedding[i], 0);
|
|
106
78
|
const magnitude1 = Math.sqrt(docEmb.reduce((sum, val) => sum + val * val, 0));
|
|
107
79
|
const magnitude2 = Math.sqrt(queryEmbedding.reduce((sum, val) => sum + val * val, 0));
|
|
108
80
|
return dotProduct / (magnitude1 * magnitude2);
|
|
109
81
|
});
|
|
110
|
-
// Show results
|
|
111
82
|
console.log("\nSearch results:");
|
|
112
83
|
similarities
|
|
113
84
|
.map((sim, i) => ({ doc: documents[i], similarity: sim }))
|
|
@@ -117,47 +88,35 @@ async function example4_asymmetricSearch() {
|
|
|
117
88
|
});
|
|
118
89
|
console.log();
|
|
119
90
|
}
|
|
120
|
-
// ============================================================================
|
|
121
|
-
// Example 5: Custom Priority Order
|
|
122
|
-
// ============================================================================
|
|
123
91
|
async function example5_customPriority() {
|
|
124
92
|
console.log("Example 5: Custom priority order\n");
|
|
125
|
-
// Try local first, then cloud
|
|
126
93
|
const customConfigs = [
|
|
127
|
-
{ type: "ollama" },
|
|
128
|
-
{ type: "openai", dimensions: 512 },
|
|
129
|
-
{ type: "text-only" }
|
|
94
|
+
{ type: "ollama" },
|
|
95
|
+
{ type: "openai", dimensions: 512 },
|
|
96
|
+
{ type: "text-only" }
|
|
130
97
|
];
|
|
131
98
|
const provider = await selectBestProvider(customConfigs);
|
|
132
99
|
console.log(`Selected: ${provider.name}`);
|
|
133
100
|
console.log(`Strategy: Try local → Try cheap cloud → Fallback\n`);
|
|
134
101
|
}
|
|
135
|
-
// ============================================================================
|
|
136
|
-
// Example 6: Production Configuration
|
|
137
|
-
// ============================================================================
|
|
138
102
|
async function example6_production() {
|
|
139
103
|
console.log("Example 6: Production-ready configuration\n");
|
|
140
|
-
// Production setup with redundancy
|
|
141
104
|
const productionConfigs = [
|
|
142
|
-
// Primary: High-quality embeddings
|
|
143
105
|
{
|
|
144
106
|
type: "openai",
|
|
145
107
|
model: "text-embedding-3-large",
|
|
146
108
|
dimensions: 3072
|
|
147
109
|
},
|
|
148
|
-
// Fallback 1: Smaller but still good
|
|
149
110
|
{
|
|
150
111
|
type: "openai",
|
|
151
112
|
model: "text-embedding-3-small",
|
|
152
113
|
dimensions: 1536
|
|
153
114
|
},
|
|
154
|
-
// Fallback 2: Alternative provider
|
|
155
115
|
{
|
|
156
116
|
type: "voyage",
|
|
157
117
|
model: "voyage-4-lite",
|
|
158
118
|
dimensions: 1024
|
|
159
119
|
},
|
|
160
|
-
// Fallback 3: Multi-provider gateway
|
|
161
120
|
{
|
|
162
121
|
type: "openrouter",
|
|
163
122
|
model: "openai/text-embedding-3-small"
|
|
@@ -168,13 +127,9 @@ async function example6_production() {
|
|
|
168
127
|
console.log(` Dimensions: ${provider.dimensions}`);
|
|
169
128
|
console.log(` Type: ${provider.type}\n`);
|
|
170
129
|
}
|
|
171
|
-
// ============================================================================
|
|
172
|
-
// Example 7: Batch Processing
|
|
173
|
-
// ============================================================================
|
|
174
130
|
async function example7_batchProcessing() {
|
|
175
131
|
console.log("Example 7: Efficient batch processing\n");
|
|
176
132
|
const provider = await selectBestProvider(getDefaultConfigs());
|
|
177
|
-
// Efficient: Single API call
|
|
178
133
|
const startTime = Date.now();
|
|
179
134
|
const texts = Array.from({ length: 100 }, (_, i) => `Document number ${i + 1} with some content`);
|
|
180
135
|
const embeddings = await provider.embed(texts);
|
|
@@ -182,16 +137,12 @@ async function example7_batchProcessing() {
|
|
|
182
137
|
console.log(`✓ Embedded ${embeddings.length} documents in ${duration}ms`);
|
|
183
138
|
console.log(` Average: ${(duration / embeddings.length).toFixed(2)}ms per document\n`);
|
|
184
139
|
}
|
|
185
|
-
// ============================================================================
|
|
186
|
-
// Example 8: Error Handling
|
|
187
|
-
// ============================================================================
|
|
188
140
|
async function example8_errorHandling() {
|
|
189
141
|
console.log("Example 8: Proper error handling\n");
|
|
190
142
|
try {
|
|
191
|
-
// Invalid configuration
|
|
192
143
|
const provider = createProvider({
|
|
193
144
|
type: "openai",
|
|
194
|
-
dimensions: 999
|
|
145
|
+
dimensions: 999
|
|
195
146
|
});
|
|
196
147
|
await provider.embed(["test"]);
|
|
197
148
|
}
|
|
@@ -200,9 +151,6 @@ async function example8_errorHandling() {
|
|
|
200
151
|
console.log("✓ Errors are clear and actionable\n");
|
|
201
152
|
}
|
|
202
153
|
}
|
|
203
|
-
// ============================================================================
|
|
204
|
-
// Example 9: Health Monitoring
|
|
205
|
-
// ============================================================================
|
|
206
154
|
async function example9_healthMonitoring() {
|
|
207
155
|
console.log("Example 9: Health monitoring\n");
|
|
208
156
|
const providers = [
|
|
@@ -222,12 +170,8 @@ async function example9_healthMonitoring() {
|
|
|
222
170
|
console.log();
|
|
223
171
|
}
|
|
224
172
|
}
|
|
225
|
-
// ============================================================================
|
|
226
|
-
// Example 10: Testing Setup
|
|
227
|
-
// ============================================================================
|
|
228
173
|
async function example10_testing() {
|
|
229
174
|
console.log("Example 10: Testing setup\n");
|
|
230
|
-
// Use text-only provider for fast tests
|
|
231
175
|
const testProvider = createProvider({ type: "text-only" });
|
|
232
176
|
console.log("Test provider setup:");
|
|
233
177
|
console.log(` Name: ${testProvider.name}`);
|
|
@@ -237,9 +181,6 @@ async function example10_testing() {
|
|
|
237
181
|
const embeddings = await testProvider.embed(["test1", "test2", "test3"]);
|
|
238
182
|
console.log(` Generated ${embeddings.length} mock embeddings\n`);
|
|
239
183
|
}
|
|
240
|
-
// ============================================================================
|
|
241
|
-
// Run Examples
|
|
242
|
-
// ============================================================================
|
|
243
184
|
async function runExamples() {
|
|
244
185
|
const examples = [
|
|
245
186
|
example1_autoSelection,
|
|
@@ -263,7 +204,6 @@ async function runExamples() {
|
|
|
263
204
|
console.log("─".repeat(80) + "\n");
|
|
264
205
|
}
|
|
265
206
|
}
|
|
266
|
-
// Run if executed directly
|
|
267
207
|
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
268
208
|
runExamples().catch(console.error);
|
|
269
209
|
}
|
|
@@ -1,48 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider Factory with Graceful Degradation
|
|
3
|
-
*
|
|
4
|
-
* "Make the right things easy and the wrong things hard."
|
|
5
|
-
*
|
|
6
|
-
* This factory implements:
|
|
7
|
-
* 1. Strategy Pattern - swappable providers
|
|
8
|
-
* 2. Factory Pattern - centralized creation
|
|
9
|
-
* 3. Graceful Degradation - automatic fallback to working providers
|
|
10
|
-
*/
|
|
11
1
|
import type { IEmbeddingProvider, ProviderConfig } from "./types.js";
|
|
12
|
-
/**
|
|
13
|
-
* Create a provider from configuration
|
|
14
|
-
*
|
|
15
|
-
* @throws Error if provider type is invalid or required credentials are missing
|
|
16
|
-
*/
|
|
17
2
|
export declare function createProvider(config: ProviderConfig): IEmbeddingProvider;
|
|
18
|
-
/**
|
|
19
|
-
* Select the best working provider from a list
|
|
20
|
-
*
|
|
21
|
-
* Implements graceful degradation:
|
|
22
|
-
* - Tries each provider in order
|
|
23
|
-
* - Returns first healthy provider
|
|
24
|
-
* - Falls back to text-only if all fail
|
|
25
|
-
*
|
|
26
|
-
* @param configs - Array of provider configurations in priority order
|
|
27
|
-
* @returns The first healthy provider or text-only fallback
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const provider = await selectBestProvider([
|
|
32
|
-
* { type: "voyage", model: "voyage-code-3" },
|
|
33
|
-
* { type: "ollama" },
|
|
34
|
-
* { type: "openai" }
|
|
35
|
-
* ]);
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
3
|
export declare function selectBestProvider(configs: ProviderConfig[]): Promise<IEmbeddingProvider>;
|
|
39
|
-
/**
|
|
40
|
-
* Get default provider configurations
|
|
41
|
-
*
|
|
42
|
-
* Priority order:
|
|
43
|
-
* 1. Voyage (code-specialized)
|
|
44
|
-
* 2. Ollama (local, free)
|
|
45
|
-
* 3. OpenAI (reliable)
|
|
46
|
-
* 4. OpenRouter (fallback)
|
|
47
|
-
*/
|
|
48
4
|
export declare function getDefaultConfigs(): ProviderConfig[];
|
|
@@ -1,23 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider Factory with Graceful Degradation
|
|
3
|
-
*
|
|
4
|
-
* "Make the right things easy and the wrong things hard."
|
|
5
|
-
*
|
|
6
|
-
* This factory implements:
|
|
7
|
-
* 1. Strategy Pattern - swappable providers
|
|
8
|
-
* 2. Factory Pattern - centralized creation
|
|
9
|
-
* 3. Graceful Degradation - automatic fallback to working providers
|
|
10
|
-
*/
|
|
11
1
|
import { OllamaProvider } from "./ollama.js";
|
|
12
2
|
import { OpenAIProvider } from "./openai.js";
|
|
13
3
|
import { VoyageProvider } from "./voyage.js";
|
|
14
4
|
import { OpenRouterProvider } from "./openrouter.js";
|
|
15
5
|
import { TextOnlyProvider } from "./text-only.js";
|
|
16
|
-
/**
|
|
17
|
-
* Create a provider from configuration
|
|
18
|
-
*
|
|
19
|
-
* @throws Error if provider type is invalid or required credentials are missing
|
|
20
|
-
*/
|
|
21
6
|
export function createProvider(config) {
|
|
22
7
|
switch (config.type) {
|
|
23
8
|
case "ollama":
|
|
@@ -34,29 +19,8 @@ export function createProvider(config) {
|
|
|
34
19
|
throw new Error(`Unknown provider type: ${config.type}`);
|
|
35
20
|
}
|
|
36
21
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Select the best working provider from a list
|
|
39
|
-
*
|
|
40
|
-
* Implements graceful degradation:
|
|
41
|
-
* - Tries each provider in order
|
|
42
|
-
* - Returns first healthy provider
|
|
43
|
-
* - Falls back to text-only if all fail
|
|
44
|
-
*
|
|
45
|
-
* @param configs - Array of provider configurations in priority order
|
|
46
|
-
* @returns The first healthy provider or text-only fallback
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const provider = await selectBestProvider([
|
|
51
|
-
* { type: "voyage", model: "voyage-code-3" },
|
|
52
|
-
* { type: "ollama" },
|
|
53
|
-
* { type: "openai" }
|
|
54
|
-
* ]);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
22
|
export async function selectBestProvider(configs) {
|
|
58
23
|
const results = [];
|
|
59
|
-
// Try each provider
|
|
60
24
|
for (const config of configs) {
|
|
61
25
|
try {
|
|
62
26
|
const provider = createProvider(config);
|
|
@@ -72,20 +36,10 @@ export async function selectBestProvider(configs) {
|
|
|
72
36
|
console.warn(`✗ Failed to initialize ${config.type}:`, error instanceof Error ? error.message : error);
|
|
73
37
|
}
|
|
74
38
|
}
|
|
75
|
-
// Fallback to text-only
|
|
76
39
|
console.warn("⚠️ All embedding providers failed. Falling back to text-only mode.");
|
|
77
40
|
console.warn(" Semantic search will be limited to keyword matching.");
|
|
78
41
|
return new TextOnlyProvider({ type: "text-only" });
|
|
79
42
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Get default provider configurations
|
|
82
|
-
*
|
|
83
|
-
* Priority order:
|
|
84
|
-
* 1. Voyage (code-specialized)
|
|
85
|
-
* 2. Ollama (local, free)
|
|
86
|
-
* 3. OpenAI (reliable)
|
|
87
|
-
* 4. OpenRouter (fallback)
|
|
88
|
-
*/
|
|
89
43
|
export function getDefaultConfigs() {
|
|
90
44
|
return [
|
|
91
45
|
{
|
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Embedding Providers Module
|
|
3
|
-
*
|
|
4
|
-
* Clean public API following the Dependency Inversion Principle.
|
|
5
|
-
* Clients depend on abstractions (IEmbeddingProvider), not implementations.
|
|
6
|
-
*
|
|
7
|
-
* @example Basic usage
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { createProvider } from "./providers";
|
|
10
|
-
*
|
|
11
|
-
* const provider = createProvider({
|
|
12
|
-
* type: "voyage",
|
|
13
|
-
* model: "voyage-code-3"
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* const embeddings = await provider.embed(["hello world"]);
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example Auto-selection with graceful degradation
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { selectBestProvider, getDefaultConfigs } from "./providers";
|
|
22
|
-
*
|
|
23
|
-
* const provider = await selectBestProvider(getDefaultConfigs());
|
|
24
|
-
* // Will try providers in order and fallback to text-only if needed
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
1
|
export type { Embedding, ProviderType, HealthCheckResult, ProviderConfig, IEmbeddingProvider } from "./types.js";
|
|
28
2
|
export { OllamaProvider } from "./ollama.js";
|
|
29
3
|
export { OpenAIProvider } from "./openai.js";
|
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Embedding Providers Module
|
|
3
|
-
*
|
|
4
|
-
* Clean public API following the Dependency Inversion Principle.
|
|
5
|
-
* Clients depend on abstractions (IEmbeddingProvider), not implementations.
|
|
6
|
-
*
|
|
7
|
-
* @example Basic usage
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { createProvider } from "./providers";
|
|
10
|
-
*
|
|
11
|
-
* const provider = createProvider({
|
|
12
|
-
* type: "voyage",
|
|
13
|
-
* model: "voyage-code-3"
|
|
14
|
-
* });
|
|
15
|
-
*
|
|
16
|
-
* const embeddings = await provider.embed(["hello world"]);
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @example Auto-selection with graceful degradation
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { selectBestProvider, getDefaultConfigs } from "./providers";
|
|
22
|
-
*
|
|
23
|
-
* const provider = await selectBestProvider(getDefaultConfigs());
|
|
24
|
-
* // Will try providers in order and fallback to text-only if needed
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
// Concrete implementations (export for advanced use cases)
|
|
28
1
|
export { OllamaProvider } from "./ollama.js";
|
|
29
2
|
export { OpenAIProvider } from "./openai.js";
|
|
30
3
|
export { VoyageProvider } from "./voyage.js";
|
|
31
4
|
export { OpenRouterProvider } from "./openrouter.js";
|
|
32
5
|
export { TextOnlyProvider } from "./text-only.js";
|
|
33
|
-
// Factory functions (recommended API)
|
|
34
6
|
export { createProvider, selectBestProvider, getDefaultConfigs } from "./factory.js";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ollama Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Local-first embedding using Ollama's API.
|
|
5
|
-
* Prioritizes privacy and zero-cost operation.
|
|
6
|
-
*/
|
|
7
1
|
import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
|
|
8
2
|
export declare class OllamaProvider implements IEmbeddingProvider {
|
|
9
3
|
readonly name = "Ollama";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Ollama Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Local-first embedding using Ollama's API.
|
|
5
|
-
* Prioritizes privacy and zero-cost operation.
|
|
6
|
-
*/
|
|
7
1
|
export class OllamaProvider {
|
|
8
2
|
name = "Ollama";
|
|
9
3
|
type = "ollama";
|
|
@@ -13,7 +7,7 @@ export class OllamaProvider {
|
|
|
13
7
|
constructor(config) {
|
|
14
8
|
this.baseUrl = config.baseUrl || "http://localhost:11434";
|
|
15
9
|
this.model = config.model || "nomic-embed-text";
|
|
16
|
-
this.dimensions = config.dimensions || 768;
|
|
10
|
+
this.dimensions = config.dimensions || 768;
|
|
17
11
|
}
|
|
18
12
|
async healthCheck() {
|
|
19
13
|
try {
|
|
@@ -46,7 +40,6 @@ export class OllamaProvider {
|
|
|
46
40
|
}
|
|
47
41
|
async embed(texts) {
|
|
48
42
|
const embeddings = [];
|
|
49
|
-
// Ollama API processes one text at a time
|
|
50
43
|
for (const text of texts) {
|
|
51
44
|
const response = await fetch(`${this.baseUrl}/api/embeddings`, {
|
|
52
45
|
method: "POST",
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Industry-standard embeddings with flexible dimensionality.
|
|
5
|
-
* Supports text-embedding-3-small and text-embedding-3-large models.
|
|
6
|
-
*/
|
|
7
1
|
import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
|
|
8
2
|
export declare class OpenAIProvider implements IEmbeddingProvider {
|
|
9
3
|
readonly name = "OpenAI";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Industry-standard embeddings with flexible dimensionality.
|
|
5
|
-
* Supports text-embedding-3-small and text-embedding-3-large models.
|
|
6
|
-
*/
|
|
7
1
|
const VALID_DIMENSIONS = [256, 512, 1536, 3072];
|
|
8
2
|
export class OpenAIProvider {
|
|
9
3
|
name = "OpenAI";
|
|
@@ -25,7 +19,7 @@ export class OpenAIProvider {
|
|
|
25
19
|
}
|
|
26
20
|
validateDimensions(dim) {
|
|
27
21
|
if (!dim)
|
|
28
|
-
return 1536;
|
|
22
|
+
return 1536;
|
|
29
23
|
if (!VALID_DIMENSIONS.includes(dim)) {
|
|
30
24
|
throw new Error(`Invalid dimensions ${dim}. Must be one of: ${VALID_DIMENSIONS.join(", ")}`);
|
|
31
25
|
}
|
|
@@ -33,7 +27,6 @@ export class OpenAIProvider {
|
|
|
33
27
|
}
|
|
34
28
|
async healthCheck() {
|
|
35
29
|
try {
|
|
36
|
-
// Lightweight check: list models endpoint
|
|
37
30
|
const response = await fetch(`${this.baseUrl}/models`, {
|
|
38
31
|
headers: {
|
|
39
32
|
"Authorization": `Bearer ${this.apiKey}`,
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenRouter Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Multi-model gateway supporting various embedding providers.
|
|
5
|
-
* Requires HTTP-Referer and X-Title headers for API tracking.
|
|
6
|
-
*/
|
|
7
1
|
import type { Embedding, HealthCheckResult, IEmbeddingProvider, ProviderConfig } from "./types.js";
|
|
8
2
|
export declare class OpenRouterProvider implements IEmbeddingProvider {
|
|
9
3
|
readonly name = "OpenRouter";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenRouter Embedding Provider
|
|
3
|
-
*
|
|
4
|
-
* Multi-model gateway supporting various embedding providers.
|
|
5
|
-
* Requires HTTP-Referer and X-Title headers for API tracking.
|
|
6
|
-
*/
|
|
7
1
|
export class OpenRouterProvider {
|
|
8
2
|
name = "OpenRouter";
|
|
9
3
|
type = "openrouter";
|
|
@@ -22,13 +16,11 @@ export class OpenRouterProvider {
|
|
|
22
16
|
this.model = config.model || "openai/text-embedding-3-small";
|
|
23
17
|
this.baseUrl = config.baseUrl || "https://openrouter.ai/api/v1";
|
|
24
18
|
this.dimensions = config.dimensions || 1536;
|
|
25
|
-
// OpenRouter requires these headers for tracking
|
|
26
19
|
this.referer = process.env.OPENROUTER_REFERER || "https://maskweaver.dev";
|
|
27
20
|
this.title = process.env.OPENROUTER_TITLE || "MaskWeaver";
|
|
28
21
|
}
|
|
29
22
|
async healthCheck() {
|
|
30
23
|
try {
|
|
31
|
-
// Check API key validity
|
|
32
24
|
const response = await fetch(`${this.baseUrl}/auth/key`, {
|
|
33
25
|
headers: {
|
|
34
26
|
"Authorization": `Bearer ${this.apiKey}`,
|