brainbank 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1059 -0
  3. package/assets/architecture.png +0 -0
  4. package/bin/brainbank +11 -0
  5. package/dist/chunk-2P3EGY6S.js +37 -0
  6. package/dist/chunk-2P3EGY6S.js.map +1 -0
  7. package/dist/chunk-3GAIDXRW.js +105 -0
  8. package/dist/chunk-3GAIDXRW.js.map +1 -0
  9. package/dist/chunk-4ZKBQ33J.js +56 -0
  10. package/dist/chunk-4ZKBQ33J.js.map +1 -0
  11. package/dist/chunk-7QVYU63E.js +7 -0
  12. package/dist/chunk-7QVYU63E.js.map +1 -0
  13. package/dist/chunk-EDKSKLX4.js +490 -0
  14. package/dist/chunk-EDKSKLX4.js.map +1 -0
  15. package/dist/chunk-GOUBW7UA.js +373 -0
  16. package/dist/chunk-GOUBW7UA.js.map +1 -0
  17. package/dist/chunk-MJ3Y24H6.js +185 -0
  18. package/dist/chunk-MJ3Y24H6.js.map +1 -0
  19. package/dist/chunk-N6ZMBFDE.js +224 -0
  20. package/dist/chunk-N6ZMBFDE.js.map +1 -0
  21. package/dist/chunk-YGSEUWLV.js +2053 -0
  22. package/dist/chunk-YGSEUWLV.js.map +1 -0
  23. package/dist/chunk-Z5SU54HP.js +171 -0
  24. package/dist/chunk-Z5SU54HP.js.map +1 -0
  25. package/dist/cli.d.ts +1 -0
  26. package/dist/cli.js +731 -0
  27. package/dist/cli.js.map +1 -0
  28. package/dist/code.d.ts +31 -0
  29. package/dist/code.js +8 -0
  30. package/dist/code.js.map +1 -0
  31. package/dist/docs.d.ts +19 -0
  32. package/dist/docs.js +8 -0
  33. package/dist/docs.js.map +1 -0
  34. package/dist/git.d.ts +31 -0
  35. package/dist/git.js +8 -0
  36. package/dist/git.js.map +1 -0
  37. package/dist/index.d.ts +845 -0
  38. package/dist/index.js +80 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/memory.d.ts +19 -0
  41. package/dist/memory.js +146 -0
  42. package/dist/memory.js.map +1 -0
  43. package/dist/notes.d.ts +19 -0
  44. package/dist/notes.js +57 -0
  45. package/dist/notes.js.map +1 -0
  46. package/dist/openai-PCTYLOWI.js +8 -0
  47. package/dist/openai-PCTYLOWI.js.map +1 -0
  48. package/dist/types-Da_zLLOl.d.ts +474 -0
  49. package/package.json +91 -0
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ import {
2
+ NoteStore
3
+ } from "./chunk-MJ3Y24H6.js";
4
+ import {
5
+ Consolidator,
6
+ PatternStore
7
+ } from "./chunk-Z5SU54HP.js";
8
+ import {
9
+ BM25Search,
10
+ BrainBank,
11
+ Collection,
12
+ ContextBuilder,
13
+ DEFAULTS,
14
+ HNSWIndex,
15
+ LocalEmbedding,
16
+ UnifiedSearch,
17
+ resolveConfig,
18
+ searchMMR
19
+ } from "./chunk-YGSEUWLV.js";
20
+ import {
21
+ CodeChunker,
22
+ CodeIndexer,
23
+ IGNORE_DIRS,
24
+ SUPPORTED_EXTENSIONS,
25
+ code,
26
+ getLanguage,
27
+ isSupported
28
+ } from "./chunk-EDKSKLX4.js";
29
+ import {
30
+ CoEditAnalyzer,
31
+ GitIndexer,
32
+ git
33
+ } from "./chunk-N6ZMBFDE.js";
34
+ import {
35
+ DocIndexer,
36
+ docs
37
+ } from "./chunk-GOUBW7UA.js";
38
+ import {
39
+ reciprocalRankFusion
40
+ } from "./chunk-4ZKBQ33J.js";
41
+ import {
42
+ cosineSimilarity,
43
+ normalize
44
+ } from "./chunk-2P3EGY6S.js";
45
+ import {
46
+ OpenAIEmbedding
47
+ } from "./chunk-3GAIDXRW.js";
48
+ import "./chunk-7QVYU63E.js";
49
+ export {
50
+ BM25Search,
51
+ BrainBank,
52
+ CoEditAnalyzer,
53
+ CodeChunker,
54
+ CodeIndexer,
55
+ Collection,
56
+ Consolidator,
57
+ ContextBuilder,
58
+ DEFAULTS,
59
+ DocIndexer,
60
+ GitIndexer,
61
+ HNSWIndex,
62
+ IGNORE_DIRS,
63
+ LocalEmbedding,
64
+ NoteStore,
65
+ OpenAIEmbedding,
66
+ PatternStore,
67
+ SUPPORTED_EXTENSIONS,
68
+ UnifiedSearch,
69
+ code,
70
+ cosineSimilarity,
71
+ docs,
72
+ getLanguage,
73
+ git,
74
+ isSupported,
75
+ normalize,
76
+ reciprocalRankFusion,
77
+ resolveConfig,
78
+ searchMMR
79
+ };
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,19 @@
1
+ import { B as BrainBankModule } from './types-Da_zLLOl.js';
2
+ import 'better-sqlite3';
3
+
4
+ /**
5
+ * BrainBank — Memory Module
6
+ *
7
+ * Agent learns from completed tasks — stores patterns,
8
+ * consolidates failures, distills strategies.
9
+ *
10
+ * import { memory } from 'brainbank/memory';
11
+ * brain.use(memory());
12
+ */
13
+
14
+ interface MemoryModuleOptions {
15
+ }
16
+ /** Create an agent memory (learning) module. */
17
+ declare function memory(opts?: MemoryModuleOptions): BrainBankModule;
18
+
19
+ export { type MemoryModuleOptions, memory };
package/dist/memory.js ADDED
@@ -0,0 +1,146 @@
1
+ import {
2
+ Consolidator,
3
+ PatternStore
4
+ } from "./chunk-Z5SU54HP.js";
5
+ import "./chunk-2P3EGY6S.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-7QVYU63E.js";
9
+
10
+ // src/memory/strategy-distiller.ts
11
+ var StrategyDistiller = class {
12
+ constructor(_db) {
13
+ this._db = _db;
14
+ }
15
+ static {
16
+ __name(this, "StrategyDistiller");
17
+ }
18
+ /**
19
+ * Distill top patterns for a task type into a strategy.
20
+ * Updates the distilled_strategies table.
21
+ */
22
+ distill(taskType, topK = 10) {
23
+ const patterns = this._db.prepare(`
24
+ SELECT task, approach, outcome, critique, success_rate
25
+ FROM memory_patterns
26
+ WHERE task_type = ? AND success_rate >= 0.7
27
+ ORDER BY success_rate DESC, created_at DESC
28
+ LIMIT ?
29
+ `).all(taskType, topK);
30
+ if (patterns.length === 0) return null;
31
+ const lines = [];
32
+ const avgSuccess = patterns.reduce((sum, p) => sum + p.success_rate, 0) / patterns.length;
33
+ lines.push(`Strategy for "${taskType}" (${patterns.length} patterns, avg success ${Math.round(avgSuccess * 100)}%):`);
34
+ lines.push("");
35
+ for (const p of patterns) {
36
+ lines.push(`\u2022 ${p.approach} (${Math.round(p.success_rate * 100)}%)`);
37
+ if (p.critique) lines.push(` \u2514 ${p.critique}`);
38
+ }
39
+ const strategy = lines.join("\n");
40
+ const confidence = avgSuccess;
41
+ const now = Math.floor(Date.now() / 1e3);
42
+ this._db.prepare(`
43
+ INSERT INTO distilled_strategies (task_type, strategy, confidence, updated_at)
44
+ VALUES (?, ?, ?, ?)
45
+ ON CONFLICT(task_type) DO UPDATE SET
46
+ strategy = excluded.strategy,
47
+ confidence = excluded.confidence,
48
+ updated_at = excluded.updated_at
49
+ `).run(taskType, strategy, confidence, now);
50
+ return { taskType, strategy, confidence, updatedAt: now };
51
+ }
52
+ /**
53
+ * Get a distilled strategy for a task type.
54
+ */
55
+ get(taskType) {
56
+ const row = this._db.prepare(
57
+ "SELECT * FROM distilled_strategies WHERE task_type = ?"
58
+ ).get(taskType);
59
+ if (!row) return null;
60
+ return {
61
+ taskType: row.task_type,
62
+ strategy: row.strategy,
63
+ confidence: row.confidence,
64
+ updatedAt: row.updated_at
65
+ };
66
+ }
67
+ /**
68
+ * List all distilled strategies.
69
+ */
70
+ list() {
71
+ const rows = this._db.prepare(
72
+ "SELECT * FROM distilled_strategies ORDER BY confidence DESC"
73
+ ).all();
74
+ return rows.map((r) => ({
75
+ taskType: r.task_type,
76
+ strategy: r.strategy,
77
+ confidence: r.confidence,
78
+ updatedAt: r.updated_at
79
+ }));
80
+ }
81
+ };
82
+
83
+ // src/plugins/memory.ts
84
+ var MemoryModuleImpl = class {
85
+ constructor(opts = {}) {
86
+ this.opts = opts;
87
+ }
88
+ static {
89
+ __name(this, "MemoryModuleImpl");
90
+ }
91
+ name = "memory";
92
+ hnsw;
93
+ patternStore;
94
+ consolidator;
95
+ distiller;
96
+ vecCache = /* @__PURE__ */ new Map();
97
+ _db;
98
+ async initialize(ctx) {
99
+ this._db = ctx.db;
100
+ this.hnsw = await ctx.createHnsw(1e5);
101
+ ctx.loadVectors("memory_vectors", "pattern_id", this.hnsw, this.vecCache);
102
+ this.patternStore = new PatternStore({
103
+ db: ctx.db,
104
+ hnsw: this.hnsw,
105
+ vectorCache: this.vecCache,
106
+ embedding: ctx.embedding
107
+ });
108
+ this.consolidator = new Consolidator(ctx.db, this.vecCache);
109
+ this.distiller = new StrategyDistiller(ctx.db);
110
+ }
111
+ /** Store a learned pattern. */
112
+ async learn(pattern) {
113
+ const id = await this.patternStore.learn(pattern);
114
+ if (this.patternStore.count % 50 === 0) {
115
+ this.consolidator.consolidate();
116
+ }
117
+ return id;
118
+ }
119
+ /** Search for similar patterns. */
120
+ async search(query, k = 4) {
121
+ return this.patternStore.search(query, k);
122
+ }
123
+ /** Consolidate: prune old failures + deduplicate. */
124
+ consolidate() {
125
+ return this.consolidator.consolidate();
126
+ }
127
+ /** Distill patterns into a strategy. */
128
+ distill(taskType) {
129
+ return this.distiller.distill(taskType);
130
+ }
131
+ stats() {
132
+ return {
133
+ patterns: this.patternStore.count,
134
+ avgSuccess: this._db.prepare("SELECT AVG(success_rate) as a FROM memory_patterns").get().a ?? 0,
135
+ hnswSize: this.hnsw.size
136
+ };
137
+ }
138
+ };
139
+ function memory(opts) {
140
+ return new MemoryModuleImpl(opts);
141
+ }
142
+ __name(memory, "memory");
143
+ export {
144
+ memory
145
+ };
146
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/memory/strategy-distiller.ts","../src/plugins/memory.ts"],"sourcesContent":["/**\n * BrainBank — Strategy Distiller\n * \n * Aggregates top patterns for a task type into a single strategy text.\n * Analogous to SONA's Deep Loop — periodic knowledge distillation.\n */\n\nimport type { Database } from '../storage/database.ts';\nimport type { DistilledStrategy } from '../types.ts';\n\nexport class StrategyDistiller {\n constructor(private _db: Database) {}\n\n /**\n * Distill top patterns for a task type into a strategy.\n * Updates the distilled_strategies table.\n */\n distill(taskType: string, topK: number = 10): DistilledStrategy | null {\n const patterns = this._db.prepare(`\n SELECT task, approach, outcome, critique, success_rate\n FROM memory_patterns\n WHERE task_type = ? AND success_rate >= 0.7\n ORDER BY success_rate DESC, created_at DESC\n LIMIT ?\n `).all(taskType, topK) as any[];\n\n if (patterns.length === 0) return null;\n\n // Build strategy text from top patterns\n const lines: string[] = [];\n const avgSuccess = patterns.reduce((sum: number, p: any) => sum + p.success_rate, 0) / patterns.length;\n\n lines.push(`Strategy for \"${taskType}\" (${patterns.length} patterns, avg success ${Math.round(avgSuccess * 100)}%):`);\n lines.push('');\n\n for (const p of patterns) {\n lines.push(`• ${p.approach} (${Math.round(p.success_rate * 100)}%)`);\n if (p.critique) lines.push(` └ ${p.critique}`);\n }\n\n const strategy = lines.join('\\n');\n const confidence = avgSuccess;\n const now = Math.floor(Date.now() / 1000);\n\n this._db.prepare(`\n INSERT INTO distilled_strategies (task_type, strategy, confidence, updated_at)\n VALUES (?, ?, ?, ?)\n ON CONFLICT(task_type) DO UPDATE SET\n strategy = excluded.strategy,\n confidence = excluded.confidence,\n updated_at = excluded.updated_at\n `).run(taskType, strategy, confidence, now);\n\n return { taskType, strategy, confidence, updatedAt: now };\n }\n\n /**\n * Get a distilled strategy for a task type.\n */\n get(taskType: string): DistilledStrategy | null {\n const row = this._db.prepare(\n 'SELECT * FROM distilled_strategies WHERE task_type = ?'\n ).get(taskType) as any;\n\n if (!row) return null;\n return {\n taskType: row.task_type,\n strategy: row.strategy,\n confidence: row.confidence,\n updatedAt: row.updated_at,\n };\n }\n\n /**\n * List all distilled strategies.\n */\n list(): DistilledStrategy[] {\n const rows = this._db.prepare(\n 'SELECT * FROM distilled_strategies ORDER BY confidence DESC'\n ).all() as any[];\n\n return rows.map(r => ({\n taskType: r.task_type,\n strategy: r.strategy,\n confidence: r.confidence,\n updatedAt: r.updated_at,\n }));\n }\n}\n","/**\n * BrainBank — Memory Module\n * \n * Agent learns from completed tasks — stores patterns,\n * consolidates failures, distills strategies.\n * \n * import { memory } from 'brainbank/memory';\n * brain.use(memory());\n */\n\nimport type { BrainBankModule, ModuleContext } from './types.ts';\nimport type { HNSWIndex } from '../vector/hnsw.ts';\nimport type { Database } from '../storage/database.ts';\nimport { PatternStore } from '../memory/pattern-store.ts';\nimport { Consolidator } from '../memory/consolidator.ts';\nimport { StrategyDistiller } from '../memory/strategy-distiller.ts';\nimport type { MemoryPattern, DistilledStrategy } from '../types.ts';\n\nexport interface MemoryModuleOptions {}\n\nclass MemoryModuleImpl implements BrainBankModule {\n readonly name = 'memory';\n hnsw!: HNSWIndex;\n patternStore!: PatternStore;\n consolidator!: Consolidator;\n distiller!: StrategyDistiller;\n vecCache = new Map<number, Float32Array>();\n private _db!: Database;\n\n constructor(private opts: MemoryModuleOptions = {}) {}\n\n async initialize(ctx: ModuleContext): Promise<void> {\n this._db = ctx.db;\n this.hnsw = await ctx.createHnsw(100_000);\n ctx.loadVectors('memory_vectors', 'pattern_id', this.hnsw, this.vecCache);\n\n this.patternStore = new PatternStore({\n db: ctx.db,\n hnsw: this.hnsw,\n vectorCache: this.vecCache,\n embedding: ctx.embedding,\n });\n\n this.consolidator = new Consolidator(ctx.db, this.vecCache);\n this.distiller = new StrategyDistiller(ctx.db);\n }\n\n /** Store a learned pattern. */\n async learn(pattern: MemoryPattern): Promise<number> {\n const id = await this.patternStore.learn(pattern);\n\n // Auto-consolidate every 50 patterns\n if (this.patternStore.count % 50 === 0) {\n this.consolidator.consolidate();\n }\n\n return id;\n }\n\n /** Search for similar patterns. */\n async search(query: string, k: number = 4): Promise<(MemoryPattern & { score: number })[]> {\n return this.patternStore.search(query, k);\n }\n\n /** Consolidate: prune old failures + deduplicate. */\n consolidate(): { pruned: number; deduped: number } {\n return this.consolidator.consolidate();\n }\n\n /** Distill patterns into a strategy. */\n distill(taskType: string): DistilledStrategy | null {\n return this.distiller.distill(taskType);\n }\n\n stats(): Record<string, any> {\n return {\n patterns: this.patternStore.count,\n avgSuccess: (this._db.prepare('SELECT AVG(success_rate) as a FROM memory_patterns').get() as any).a ?? 0,\n hnswSize: this.hnsw.size,\n };\n }\n}\n\n/** Create an agent memory (learning) module. */\nexport function memory(opts?: MemoryModuleOptions): BrainBankModule {\n return new MemoryModuleImpl(opts);\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,19 @@
1
+ import { B as BrainBankModule } from './types-Da_zLLOl.js';
2
+ import 'better-sqlite3';
3
+
4
+ /**
5
+ * BrainBank — Notes Module
6
+ *
7
+ * Store structured conversation digests so the agent
8
+ * remembers past discussions.
9
+ *
10
+ * import { notes } from 'brainbank/notes';
11
+ * brain.use(notes());
12
+ */
13
+
14
+ interface NotesModuleOptions {
15
+ }
16
+ /** Create a notes memory module. */
17
+ declare function notes(opts?: NotesModuleOptions): BrainBankModule;
18
+
19
+ export { type NotesModuleOptions, notes };
package/dist/notes.js ADDED
@@ -0,0 +1,57 @@
1
+ import {
2
+ NoteStore
3
+ } from "./chunk-MJ3Y24H6.js";
4
+ import "./chunk-4ZKBQ33J.js";
5
+ import {
6
+ __name
7
+ } from "./chunk-7QVYU63E.js";
8
+
9
+ // src/plugins/notes.ts
10
+ var NotesModuleImpl = class {
11
+ constructor(opts = {}) {
12
+ this.opts = opts;
13
+ }
14
+ static {
15
+ __name(this, "NotesModuleImpl");
16
+ }
17
+ name = "notes";
18
+ hnsw;
19
+ store;
20
+ vecCache = /* @__PURE__ */ new Map();
21
+ async initialize(ctx) {
22
+ this.hnsw = await ctx.createHnsw(1e5);
23
+ ctx.loadVectors("note_vectors", "note_id", this.hnsw, this.vecCache);
24
+ this.store = new NoteStore(ctx.db, ctx.embedding, this.hnsw, this.vecCache);
25
+ }
26
+ /** Store a note digest. */
27
+ async remember(digest) {
28
+ return this.store.remember(digest);
29
+ }
30
+ /** Recall relevant notes (hybrid search). */
31
+ async recall(query, options) {
32
+ return this.store.recall(query, options);
33
+ }
34
+ /** List recent notes. */
35
+ list(limit, tier) {
36
+ return this.store.list(limit, tier);
37
+ }
38
+ /** Consolidate old short-term → long-term. */
39
+ consolidate(keepRecent) {
40
+ return this.store.consolidate(keepRecent);
41
+ }
42
+ /** Count notes by tier. */
43
+ count() {
44
+ return this.store.count();
45
+ }
46
+ stats() {
47
+ return this.store.count();
48
+ }
49
+ };
50
+ function notes(opts) {
51
+ return new NotesModuleImpl(opts);
52
+ }
53
+ __name(notes, "notes");
54
+ export {
55
+ notes
56
+ };
57
+ //# sourceMappingURL=notes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugins/notes.ts"],"sourcesContent":["/**\n * BrainBank — Notes Module\n * \n * Store structured conversation digests so the agent\n * remembers past discussions.\n * \n * import { notes } from 'brainbank/notes';\n * brain.use(notes());\n */\n\nimport type { BrainBankModule, ModuleContext } from './types.ts';\nimport type { HNSWIndex } from '../vector/hnsw.ts';\nimport { NoteStore } from '../memory/note-store.ts';\nimport type { NoteDigest, StoredNote, RecallOptions } from '../memory/note-store.ts';\n\nexport interface NotesModuleOptions {}\n\nclass NotesModuleImpl implements BrainBankModule {\n readonly name = 'notes';\n hnsw!: HNSWIndex;\n store!: NoteStore;\n vecCache = new Map<number, Float32Array>();\n\n constructor(private opts: NotesModuleOptions = {}) {}\n\n async initialize(ctx: ModuleContext): Promise<void> {\n this.hnsw = await ctx.createHnsw(100_000);\n ctx.loadVectors('note_vectors', 'note_id', this.hnsw, this.vecCache);\n this.store = new NoteStore(ctx.db, ctx.embedding, this.hnsw, this.vecCache);\n }\n\n /** Store a note digest. */\n async remember(digest: NoteDigest): Promise<number> {\n return this.store.remember(digest);\n }\n\n /** Recall relevant notes (hybrid search). */\n async recall(query: string, options?: RecallOptions): Promise<StoredNote[]> {\n return this.store.recall(query, options);\n }\n\n /** List recent notes. */\n list(limit?: number, tier?: 'short' | 'long'): StoredNote[] {\n return this.store.list(limit, tier);\n }\n\n /** Consolidate old short-term → long-term. */\n consolidate(keepRecent?: number): { promoted: number } {\n return this.store.consolidate(keepRecent);\n }\n\n /** Count notes by tier. */\n count(): { total: number; short: number; long: number } {\n return this.store.count();\n }\n\n stats(): Record<string, any> {\n return this.store.count();\n }\n}\n\n/** Create a notes memory module. */\nexport function notes(opts?: NotesModuleOptions): BrainBankModule {\n return new NotesModuleImpl(opts);\n}\n"],"mappings":";;;;;;;;;AAiBA,IAAM,kBAAN,MAAiD;AAAA,EAM7C,YAAoB,OAA2B,CAAC,GAAG;AAA/B;AAAA,EAAgC;AAAA,EAvBxD,OAiBiD;AAAA;AAAA;AAAA,EACpC,OAAO;AAAA,EAChB;AAAA,EACA;AAAA,EACA,WAAW,oBAAI,IAA0B;AAAA,EAIzC,MAAM,WAAW,KAAmC;AAChD,SAAK,OAAO,MAAM,IAAI,WAAW,GAAO;AACxC,QAAI,YAAY,gBAAgB,WAAW,KAAK,MAAM,KAAK,QAAQ;AACnE,SAAK,QAAQ,IAAI,UAAU,IAAI,IAAI,IAAI,WAAW,KAAK,MAAM,KAAK,QAAQ;AAAA,EAC9E;AAAA;AAAA,EAGA,MAAM,SAAS,QAAqC;AAChD,WAAO,KAAK,MAAM,SAAS,MAAM;AAAA,EACrC;AAAA;AAAA,EAGA,MAAM,OAAO,OAAe,SAAgD;AACxE,WAAO,KAAK,MAAM,OAAO,OAAO,OAAO;AAAA,EAC3C;AAAA;AAAA,EAGA,KAAK,OAAgB,MAAuC;AACxD,WAAO,KAAK,MAAM,KAAK,OAAO,IAAI;AAAA,EACtC;AAAA;AAAA,EAGA,YAAY,YAA2C;AACnD,WAAO,KAAK,MAAM,YAAY,UAAU;AAAA,EAC5C;AAAA;AAAA,EAGA,QAAwD;AACpD,WAAO,KAAK,MAAM,MAAM;AAAA,EAC5B;AAAA,EAEA,QAA6B;AACzB,WAAO,KAAK,MAAM,MAAM;AAAA,EAC5B;AACJ;AAGO,SAAS,MAAM,MAA4C;AAC9D,SAAO,IAAI,gBAAgB,IAAI;AACnC;AAFgB;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ OpenAIEmbedding
3
+ } from "./chunk-3GAIDXRW.js";
4
+ import "./chunk-7QVYU63E.js";
5
+ export {
6
+ OpenAIEmbedding
7
+ };
8
+ //# sourceMappingURL=openai-PCTYLOWI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}