sensemaking 0.18.2 → 0.18.4

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 (179) hide show
  1. package/dist/cjs/cli/status.js +32 -31
  2. package/dist/cjs/cli/status.js.map +1 -1
  3. package/dist/cjs/commands/map.js +50 -67
  4. package/dist/cjs/commands/map.js.map +1 -1
  5. package/dist/cjs/config/access.d.cts +2 -2
  6. package/dist/cjs/config/access.d.ts +2 -2
  7. package/dist/cjs/config/access.js.map +1 -1
  8. package/dist/cjs/config/index.d.cts +1 -1
  9. package/dist/cjs/config/index.d.ts +1 -1
  10. package/dist/cjs/config/index.js.map +1 -1
  11. package/dist/cjs/config/load.js +3 -2
  12. package/dist/cjs/config/load.js.map +1 -1
  13. package/dist/cjs/config/types.d.cts +2 -1
  14. package/dist/cjs/config/types.d.ts +2 -1
  15. package/dist/cjs/config/types.js.map +1 -1
  16. package/dist/cjs/config/validate.js +3 -0
  17. package/dist/cjs/config/validate.js.map +1 -1
  18. package/dist/cjs/embed/identity.js +3 -2
  19. package/dist/cjs/embed/identity.js.map +1 -1
  20. package/dist/cjs/embed/store.js +3 -3
  21. package/dist/cjs/embed/store.js.map +1 -1
  22. package/dist/cjs/index.d.cts +2 -2
  23. package/dist/cjs/index.d.ts +2 -2
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/lib/atomic-write.d.cts +1 -0
  26. package/dist/cjs/lib/atomic-write.d.ts +1 -0
  27. package/dist/cjs/lib/atomic-write.js +26 -0
  28. package/dist/cjs/lib/atomic-write.js.map +1 -0
  29. package/dist/cjs/store/duckdb/batch.js +3 -2
  30. package/dist/cjs/store/duckdb/batch.js.map +1 -1
  31. package/dist/cjs/store/duckdb/connection.js +12 -0
  32. package/dist/cjs/store/duckdb/connection.js.map +1 -1
  33. package/dist/cjs/store/duckdb/fieldStats.d.cts +2 -0
  34. package/dist/cjs/store/duckdb/fieldStats.d.ts +2 -0
  35. package/dist/cjs/store/duckdb/fieldStats.js +219 -0
  36. package/dist/cjs/store/duckdb/fieldStats.js.map +1 -0
  37. package/dist/cjs/store/duckdb/lexical.js +16 -9
  38. package/dist/cjs/store/duckdb/lexical.js.map +1 -1
  39. package/dist/cjs/store/duckdb/native.d.cts +0 -1
  40. package/dist/cjs/store/duckdb/native.d.ts +0 -1
  41. package/dist/cjs/store/duckdb/native.js +7 -336
  42. package/dist/cjs/store/duckdb/native.js.map +1 -1
  43. package/dist/cjs/store/duckdb/sql-functions.js +1 -1
  44. package/dist/cjs/store/duckdb/sql-functions.js.map +1 -1
  45. package/dist/cjs/store/duckdb/store.js +16 -1
  46. package/dist/cjs/store/duckdb/store.js.map +1 -1
  47. package/dist/cjs/store/duckdb/vectors.js +5 -17
  48. package/dist/cjs/store/duckdb/vectors.js.map +1 -1
  49. package/dist/cjs/store/index.js +6 -0
  50. package/dist/cjs/store/index.js.map +1 -1
  51. package/dist/cjs/store/native.d.cts +7 -0
  52. package/dist/cjs/store/native.d.ts +7 -0
  53. package/dist/cjs/store/native.js +350 -0
  54. package/dist/cjs/store/native.js.map +1 -0
  55. package/dist/cjs/store/sqlite/fieldStats.d.cts +2 -0
  56. package/dist/cjs/store/sqlite/fieldStats.d.ts +2 -0
  57. package/dist/cjs/store/sqlite/fieldStats.js +201 -0
  58. package/dist/cjs/store/sqlite/fieldStats.js.map +1 -0
  59. package/dist/cjs/store/sqlite/open.js +82 -29
  60. package/dist/cjs/store/sqlite/open.js.map +1 -1
  61. package/dist/cjs/store/sqlite/store.js +32 -4
  62. package/dist/cjs/store/sqlite/store.js.map +1 -1
  63. package/dist/cjs/store/sqlite/vectors.d.cts +0 -5
  64. package/dist/cjs/store/sqlite/vectors.d.ts +0 -5
  65. package/dist/cjs/store/sqlite/vectors.js +5 -71
  66. package/dist/cjs/store/sqlite/vectors.js.map +1 -1
  67. package/dist/cjs/store/turso/connection.d.cts +3 -0
  68. package/dist/cjs/store/turso/connection.d.ts +3 -0
  69. package/dist/cjs/store/turso/connection.js +529 -0
  70. package/dist/cjs/store/turso/connection.js.map +1 -0
  71. package/dist/cjs/store/turso/fieldStats.d.cts +2 -0
  72. package/dist/cjs/store/turso/fieldStats.d.ts +2 -0
  73. package/dist/cjs/store/turso/fieldStats.js +201 -0
  74. package/dist/cjs/store/turso/fieldStats.js.map +1 -0
  75. package/dist/cjs/store/turso/native.d.cts +2 -0
  76. package/dist/cjs/store/turso/native.d.ts +2 -0
  77. package/dist/cjs/store/turso/native.js +31 -0
  78. package/dist/cjs/store/turso/native.js.map +1 -0
  79. package/dist/cjs/store/turso/open.d.cts +12 -0
  80. package/dist/cjs/store/turso/open.d.ts +12 -0
  81. package/dist/cjs/store/turso/open.js +500 -0
  82. package/dist/cjs/store/turso/open.js.map +1 -0
  83. package/dist/cjs/store/turso/reconcile.d.cts +6 -0
  84. package/dist/cjs/store/turso/reconcile.d.ts +6 -0
  85. package/dist/cjs/store/turso/reconcile.js +793 -0
  86. package/dist/cjs/store/turso/reconcile.js.map +1 -0
  87. package/dist/cjs/store/turso/store.d.cts +5 -0
  88. package/dist/cjs/store/turso/store.d.ts +5 -0
  89. package/dist/cjs/store/turso/store.js +609 -0
  90. package/dist/cjs/store/turso/store.js.map +1 -0
  91. package/dist/cjs/store/types.d.cts +9 -1
  92. package/dist/cjs/store/types.d.ts +9 -1
  93. package/dist/cjs/store/types.js +0 -7
  94. package/dist/cjs/store/types.js.map +1 -1
  95. package/dist/cjs/store/vectors.d.cts +9 -0
  96. package/dist/cjs/store/vectors.d.ts +9 -0
  97. package/dist/cjs/store/vectors.js +215 -0
  98. package/dist/cjs/store/vectors.js.map +1 -0
  99. package/dist/esm/cli/status.js +5 -7
  100. package/dist/esm/cli/status.js.map +1 -1
  101. package/dist/esm/commands/map.js +7 -19
  102. package/dist/esm/commands/map.js.map +1 -1
  103. package/dist/esm/config/access.d.ts +2 -2
  104. package/dist/esm/config/access.js.map +1 -1
  105. package/dist/esm/config/index.d.ts +1 -1
  106. package/dist/esm/config/index.js.map +1 -1
  107. package/dist/esm/config/load.js +4 -3
  108. package/dist/esm/config/load.js.map +1 -1
  109. package/dist/esm/config/types.d.ts +2 -1
  110. package/dist/esm/config/types.js.map +1 -1
  111. package/dist/esm/config/validate.js +3 -0
  112. package/dist/esm/config/validate.js.map +1 -1
  113. package/dist/esm/embed/identity.js +4 -3
  114. package/dist/esm/embed/identity.js.map +1 -1
  115. package/dist/esm/embed/store.js +3 -3
  116. package/dist/esm/embed/store.js.map +1 -1
  117. package/dist/esm/index.d.ts +2 -2
  118. package/dist/esm/index.js.map +1 -1
  119. package/dist/esm/lib/atomic-write.d.ts +1 -0
  120. package/dist/esm/lib/atomic-write.js +17 -0
  121. package/dist/esm/lib/atomic-write.js.map +1 -0
  122. package/dist/esm/store/duckdb/batch.js +3 -2
  123. package/dist/esm/store/duckdb/batch.js.map +1 -1
  124. package/dist/esm/store/duckdb/connection.js +12 -0
  125. package/dist/esm/store/duckdb/connection.js.map +1 -1
  126. package/dist/esm/store/duckdb/fieldStats.d.ts +2 -0
  127. package/dist/esm/store/duckdb/fieldStats.js +39 -0
  128. package/dist/esm/store/duckdb/fieldStats.js.map +1 -0
  129. package/dist/esm/store/duckdb/lexical.js +19 -9
  130. package/dist/esm/store/duckdb/lexical.js.map +1 -1
  131. package/dist/esm/store/duckdb/native.d.ts +0 -1
  132. package/dist/esm/store/duckdb/native.js +7 -84
  133. package/dist/esm/store/duckdb/native.js.map +1 -1
  134. package/dist/esm/store/duckdb/sql-functions.js +1 -1
  135. package/dist/esm/store/duckdb/sql-functions.js.map +1 -1
  136. package/dist/esm/store/duckdb/store.js +8 -5
  137. package/dist/esm/store/duckdb/store.js.map +1 -1
  138. package/dist/esm/store/duckdb/vectors.js +2 -12
  139. package/dist/esm/store/duckdb/vectors.js.map +1 -1
  140. package/dist/esm/store/index.js +6 -0
  141. package/dist/esm/store/index.js.map +1 -1
  142. package/dist/esm/store/native.d.ts +7 -0
  143. package/dist/esm/store/native.js +83 -0
  144. package/dist/esm/store/native.js.map +1 -0
  145. package/dist/esm/store/sqlite/fieldStats.d.ts +2 -0
  146. package/dist/esm/store/sqlite/fieldStats.js +25 -0
  147. package/dist/esm/store/sqlite/fieldStats.js.map +1 -0
  148. package/dist/esm/store/sqlite/open.js +21 -8
  149. package/dist/esm/store/sqlite/open.js.map +1 -1
  150. package/dist/esm/store/sqlite/store.js +14 -1
  151. package/dist/esm/store/sqlite/store.js.map +1 -1
  152. package/dist/esm/store/sqlite/vectors.d.ts +0 -5
  153. package/dist/esm/store/sqlite/vectors.js +2 -22
  154. package/dist/esm/store/sqlite/vectors.js.map +1 -1
  155. package/dist/esm/store/turso/connection.d.ts +3 -0
  156. package/dist/esm/store/turso/connection.js +52 -0
  157. package/dist/esm/store/turso/connection.js.map +1 -0
  158. package/dist/esm/store/turso/fieldStats.d.ts +2 -0
  159. package/dist/esm/store/turso/fieldStats.js +24 -0
  160. package/dist/esm/store/turso/fieldStats.js.map +1 -0
  161. package/dist/esm/store/turso/native.d.ts +2 -0
  162. package/dist/esm/store/turso/native.js +19 -0
  163. package/dist/esm/store/turso/native.js.map +1 -0
  164. package/dist/esm/store/turso/open.d.ts +12 -0
  165. package/dist/esm/store/turso/open.js +113 -0
  166. package/dist/esm/store/turso/open.js.map +1 -0
  167. package/dist/esm/store/turso/reconcile.d.ts +6 -0
  168. package/dist/esm/store/turso/reconcile.js +158 -0
  169. package/dist/esm/store/turso/reconcile.js.map +1 -0
  170. package/dist/esm/store/turso/store.d.ts +5 -0
  171. package/dist/esm/store/turso/store.js +93 -0
  172. package/dist/esm/store/turso/store.js.map +1 -0
  173. package/dist/esm/store/types.d.ts +9 -1
  174. package/dist/esm/store/types.js +0 -7
  175. package/dist/esm/store/types.js.map +1 -1
  176. package/dist/esm/store/vectors.d.ts +9 -0
  177. package/dist/esm/store/vectors.js +26 -0
  178. package/dist/esm/store/vectors.js.map +1 -0
  179. package/package.json +2 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/vectors.ts"],"sourcesContent":["import type { DuckDBConnection, DuckDBType, DuckDBValue } from '@duckdb/node-api';\nimport { withTransaction } from '../transaction.ts';\nimport type { Connection, VectorCandidate, VectorSimilar, VectorWriteRow } from '../types.ts';\nimport { rewriteUpdate } from './batch.ts';\nimport { duckdbApi } from './native.ts';\n\n// This store keeps vectors as native FLOAT[dims] arrays (dims fixed at DDL time by\n// duckdb/open.ts's ensureSchema, from embed/types.ts's STORE_DIMS) and scans them with\n// array_cosine_similarity, pushing top-k into SQL instead of pulling every row into JS --\n// sqlite's int8+scale BLOB scan (src/store/sqlite/vectors.ts) is the other store's own\n// representation and stays as it is. Every function here takes `dims` as a parameter rather\n// than importing STORE_DIMS directly, so it is testable at any width (store.ts wires the real\n// constant at the call site).\n//\n// A value import of '@duckdb/node-api' must never sit at module top level, or a sqlite-only\n// tree would resolve this optional dependency just by importing store/index.ts -- native.ts's\n// shared duckdbApi() (not a bare import of its own) is what keeps that lazy and reuses whatever\n// open.ts already resolved, including via an on-demand install (see native.ts).\n\n// A bind position whose type is left to auto-inference (safe for plain strings/numbers; only\n// the vector ARRAY positions below need an explicit type -- see writeVectorBatch's comment).\nconst untyped = undefined as unknown as DuckDBType;\n\n// Seed chunks that participate in a `related` scan; must match sqlite/vectors.ts's\n// TARGET_CHUNK_CAP for identical sampling behavior (see that file for the measurement it's\n// based on -- 12.7s at 201 chunks/note without sampling).\nconst TARGET_CHUNK_CAP = 16;\n\n// array_cosine_similarity is already a true cosine (no int8 accumulation to push slightly\n// outside [-1, 1]), but rounded the same way sqlite's scores are so both stores print the\n// same bounded number rather than one having more decimal noise than the other.\nfunction asCosine(score: number): number {\n return Math.round(Math.min(1, Math.max(-1, score)) * 1000) / 1000;\n}\n\n// The DDL-fixed array width can exceed a vector's actual length (a hypothetical model sliced\n// under the column's width); zero-padding leaves cosine scores unchanged since the added\n// dimensions contribute nothing to either vector's dot product or norm.\nfunction padded(values: ArrayLike<number>, dims: number): number[] {\n const out = new Array<number>(dims).fill(0);\n for (let d = 0; d < Math.min(values.length, dims); d++) out[d] = values[d];\n return out;\n}\n\nfunction inClause(column: string, count: number): string {\n return `${column} IN (${Array.from({ length: count }, () => '?').join(', ')})`;\n}\n\n// Rows arrive int8-quantized with a per-vector scale (the wire format embed/query.ts produces\n// for every store, see toStore); dequantizing into a plain float array is this store's own\n// representation choice, so both stores are handed the same vectors and diverge only here.\nfunction dequantize(row: VectorWriteRow, dims: number): number[] {\n const q = new Int8Array(row.vector.buffer, row.vector.byteOffset, row.vector.byteLength);\n return padded(\n Array.from(q, (v) => v * row.scale),\n dims\n );\n}\n\n// One runBatch-equivalent call per provider batch: a single multi-row UPDATE (batch.ts's\n// rewriteUpdate, the same rewrite Connection.runBatch uses), bound directly against the native\n// connection because the vector column needs an explicit ARRAY(DOUBLE, dims) bind type --\n// automatic type inference on the raw values misreads an all-integer first component (a real\n// vector's exact 0.0 is common) as an INTEGER array and silently truncates the rest of the row\n// (verified against a live connection: an untyped bind of [0, 0.35, 0.1, -0.2] stores [0,0,0,0]).\nexport async function writeVectorBatch(duckdb: DuckDBConnection, conn: Connection, dims: number, rows: VectorWriteRow[]): Promise<void> {\n if (rows.length === 0) return;\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const rewritten = rewriteUpdate('UPDATE embeddings SET vector = ? WHERE \"path\" = ? AND chunk = ?', rows.length);\n if (!rewritten) throw new Error('duckdb: writeVectorBatch SQL shape not recognized by rewriteUpdate');\n\n await withTransaction(conn, async () => {\n const stmt = await duckdb.prepare(rewritten.sql);\n try {\n const values: DuckDBValue[] = [];\n const types: DuckDBType[] = [];\n for (const row of rows) {\n values.push(arrayValue(dequantize(row, dims)), row.path, row.chunk);\n types.push(ARRAY(DOUBLE, dims), untyped, untyped);\n }\n stmt.bind(values, types);\n await stmt.run();\n } finally {\n stmt.destroySync();\n }\n });\n}\n\n// Best chunk per file by cosine, its line range riding along, entirely in SQL: arg_max picks\n// the winning chunk's line range from the same row max(score) came from, per path. An empty\n// `allowed` set matches sqlite's scan (every row filtered out) without touching the table.\nexport async function scanCandidates(duckdb: DuckDBConnection, qv: Float32Array, dims: number, fetch: number, allowed?: Set<string>): Promise<VectorCandidate[]> {\n if (allowed && allowed.size === 0) return [];\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const allowedList = allowed ? [...allowed] : [];\n const sql = `SELECT \"path\", arg_max(start_line, score) AS start_line, arg_max(end_line, score) AS end_line, max(score) AS score\n FROM (\n SELECT \"path\", start_line, end_line, array_cosine_similarity(vector, ?) AS score\n FROM embeddings\n WHERE vector IS NOT NULL ${allowed ? `AND ${inClause('\"path\"', allowedList.length)}` : ''}\n ) sub\n GROUP BY \"path\"\n ORDER BY score DESC\n LIMIT ?`;\n const stmt = await duckdb.prepare(sql);\n try {\n const values: DuckDBValue[] = [arrayValue(padded(qv, dims)), ...allowedList, fetch];\n const types: DuckDBType[] = [ARRAY(DOUBLE, dims), ...allowedList.map(() => untyped), untyped];\n stmt.bind(values, types);\n const reader = await stmt.runAndReadAll();\n const rows = reader.getRowObjectsJS() as Array<{ path: string; start_line: number; end_line: number; score: number }>;\n return rows.map((r) => ({ path: r.path, lines: `L${r.start_line}-${r.end_line}`, similarity: asCosine(r.score) }));\n } finally {\n stmt.destroySync();\n }\n}\n\n// Note-to-note similarity is the max cosine over (target chunk, other chunk) pairs, pushed\n// into one native scan: the sampled target vectors become a small VALUES list, cross-joined\n// against every stored vector and reduced with max()/GROUP BY, so the O(target x stored) cost\n// the plan measures (12.7s at 201 chunks/note in JS) runs vectorized instead of scalar.\nexport async function scanSimilar(duckdb: DuckDBConnection, conn: Connection, dims: number, path: string, opts: { exclude: Set<string>; allowed?: Set<string>; k: number }): Promise<VectorSimilar[]> {\n if (opts.allowed && opts.allowed.size === 0) return [];\n const targetStmt = await conn.prepare('SELECT vector FROM embeddings WHERE \"path\" = ? AND vector IS NOT NULL ORDER BY chunk');\n const targetRows = (await targetStmt.all(path)) as Array<{ vector: number[] }>;\n if (targetRows.length === 0) return [];\n const step = Math.max(1, Math.ceil(targetRows.length / TARGET_CHUNK_CAP));\n const targets = targetRows.filter((_, i) => i % step === 0).map((row) => row.vector);\n\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const excludeList = [...opts.exclude];\n const allowedList = opts.allowed ? [...opts.allowed] : [];\n const sql = `WITH targets(tv) AS (VALUES ${targets.map(() => '(?)').join(', ')})\n SELECT e.\"path\" AS path, max(array_cosine_similarity(e.vector, t.tv)) AS score\n FROM embeddings e, targets t\n WHERE e.vector IS NOT NULL AND e.\"path\" != ?\n ${excludeList.length > 0 ? `AND NOT ${inClause('e.\"path\"', excludeList.length)}` : ''}\n ${opts.allowed ? `AND ${inClause('e.\"path\"', allowedList.length)}` : ''}\n GROUP BY e.\"path\"\n ORDER BY score DESC\n LIMIT ?`;\n const stmt = await duckdb.prepare(sql);\n try {\n const values: DuckDBValue[] = [...targets.map((t) => arrayValue(padded(t, dims))), path, ...excludeList, ...allowedList, opts.k];\n const types: DuckDBType[] = [...targets.map(() => ARRAY(DOUBLE, dims)), untyped, ...excludeList.map(() => untyped), ...allowedList.map(() => untyped), untyped];\n stmt.bind(values, types);\n const reader = await stmt.runAndReadAll();\n const rows = reader.getRowObjectsJS() as Array<{ path: string; score: number }>;\n return rows.map((r) => ({ path: r.path, similarity: asCosine(r.score) }));\n } finally {\n stmt.destroySync();\n }\n}\n"],"names":["scanCandidates","scanSimilar","writeVectorBatch","untyped","undefined","TARGET_CHUNK_CAP","asCosine","score","Math","round","min","max","padded","values","dims","out","Array","fill","d","length","inClause","column","count","from","join","dequantize","row","q","Int8Array","vector","buffer","byteOffset","byteLength","v","scale","duckdb","conn","rows","arrayValue","ARRAY","DOUBLE","rewritten","duckdbApi","rewriteUpdate","Error","withTransaction","stmt","types","prepare","sql","push","path","chunk","bind","run","destroySync","qv","fetch","allowed","allowedList","reader","size","map","runAndReadAll","getRowObjectsJS","r","lines","start_line","end_line","similarity","opts","targetStmt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G;oBAI/D;;wBAAMgB,OAAOa,OAAO,CAACC;;;oBAA5BH,OAAO;;;;;;;;;oBAELjC,SAAwB,AAAC,qBAAG6D,QAAQZ,GAAG,CAAC,SAACoB;+BAAM5C,WAAW1B,OAAOsE,GAAGpE;;wBAASqC;uBAAM,qBAAGwB,cAAa,qBAAGhB;wBAAaW,KAAKa,CAAC;;oBACzHpC,QAAsB,AAAC,qBAAG2B,QAAQZ,GAAG,CAAC;+BAAMvB,MAAMC,QAAQ1B;;wBAAQX;uBAAS,qBAAGwE,YAAYb,GAAG,CAAC;+BAAM3D;yBAAU,qBAAGwD,YAAYG,GAAG,CAAC;+BAAM3D;;wBAAUA;;oBACvJ2C,KAAKO,IAAI,CAACxC,QAAQkC;oBACH;;wBAAMD,KAAKiB,aAAa;;;oBAAjCH,SAAS;oBACTvB,OAAOuB,OAAOI,eAAe;oBACnC;;wBAAO3B,KAAKyB,GAAG,CAAC,SAACG;mCAAO;gCAAEd,MAAMc,EAAEd,IAAI;gCAAEkB,YAAY/D,SAAS2D,EAAE1D,KAAK;4BAAE;;;;oBAEtEuC,KAAKS,WAAW;;;;;;;;;;IAEpB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/duckdb/vectors.ts"],"sourcesContent":["import type { DuckDBConnection, DuckDBType, DuckDBValue } from '@duckdb/node-api';\nimport { withTransaction } from '../transaction.ts';\nimport type { Connection, VectorCandidate, VectorSimilar, VectorWriteRow } from '../types.ts';\nimport { asCosine, sampleEvenly } from '../vectors.ts';\nimport { rewriteUpdate } from './batch.ts';\nimport { duckdbApi } from './native.ts';\n\n// This store keeps vectors as native FLOAT[dims] arrays (dims fixed at DDL time by\n// duckdb/open.ts's ensureSchema, from embed/types.ts's STORE_DIMS) and scans them with\n// array_cosine_similarity, pushing top-k into SQL instead of pulling every row into JS --\n// sqlite's int8+scale BLOB scan (src/store/sqlite/vectors.ts) is the other store's own\n// representation and stays as it is. Every function here takes `dims` as a parameter rather\n// than importing STORE_DIMS directly, so it is testable at any width (store.ts wires the real\n// constant at the call site).\n//\n// A value import of '@duckdb/node-api' must never sit at module top level, or a sqlite-only\n// tree would resolve this optional dependency just by importing store/index.ts -- native.ts's\n// shared duckdbApi() (not a bare import of its own) is what keeps that lazy and reuses whatever\n// open.ts already resolved, including via an on-demand install (see native.ts).\n\n// A bind position whose type is left to auto-inference (safe for plain strings/numbers; only\n// the vector ARRAY positions below need an explicit type -- see writeVectorBatch's comment).\nconst untyped = undefined as unknown as DuckDBType;\n\n// The DDL-fixed array width can exceed a vector's actual length (a hypothetical model sliced\n// under the column's width); zero-padding leaves cosine scores unchanged since the added\n// dimensions contribute nothing to either vector's dot product or norm.\nfunction padded(values: ArrayLike<number>, dims: number): number[] {\n const out = new Array<number>(dims).fill(0);\n for (let d = 0; d < Math.min(values.length, dims); d++) out[d] = values[d];\n return out;\n}\n\nfunction inClause(column: string, count: number): string {\n return `${column} IN (${Array.from({ length: count }, () => '?').join(', ')})`;\n}\n\n// Rows arrive int8-quantized with a per-vector scale (the wire format embed/query.ts produces\n// for every store, see toStore); dequantizing into a plain float array is this store's own\n// representation choice, so both stores are handed the same vectors and diverge only here.\nfunction dequantize(row: VectorWriteRow, dims: number): number[] {\n const q = new Int8Array(row.vector.buffer, row.vector.byteOffset, row.vector.byteLength);\n return padded(\n Array.from(q, (v) => v * row.scale),\n dims\n );\n}\n\n// One runBatch-equivalent call per provider batch: a single multi-row UPDATE (batch.ts's\n// rewriteUpdate, the same rewrite Connection.runBatch uses), bound directly against the native\n// connection because the vector column needs an explicit ARRAY(DOUBLE, dims) bind type --\n// automatic type inference on the raw values misreads an all-integer first component (a real\n// vector's exact 0.0 is common) as an INTEGER array and silently truncates the rest of the row\n// (verified against a live connection: an untyped bind of [0, 0.35, 0.1, -0.2] stores [0,0,0,0]).\nexport async function writeVectorBatch(duckdb: DuckDBConnection, conn: Connection, dims: number, rows: VectorWriteRow[]): Promise<void> {\n if (rows.length === 0) return;\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const rewritten = rewriteUpdate('UPDATE embeddings SET vector = ? WHERE \"path\" = ? AND chunk = ?', rows.length);\n if (!rewritten) throw new Error('duckdb: writeVectorBatch SQL shape not recognized by rewriteUpdate');\n\n await withTransaction(conn, async () => {\n const stmt = await duckdb.prepare(rewritten.sql);\n try {\n const values: DuckDBValue[] = [];\n const types: DuckDBType[] = [];\n for (const row of rows) {\n values.push(arrayValue(dequantize(row, dims)), row.path, row.chunk);\n types.push(ARRAY(DOUBLE, dims), untyped, untyped);\n }\n stmt.bind(values, types);\n await stmt.run();\n } finally {\n stmt.destroySync();\n }\n });\n}\n\n// Best chunk per file by cosine, its line range riding along, entirely in SQL: arg_max picks\n// the winning chunk's line range from the same row max(score) came from, per path. An empty\n// `allowed` set matches sqlite's scan (every row filtered out) without touching the table.\nexport async function scanCandidates(duckdb: DuckDBConnection, qv: Float32Array, dims: number, fetch: number, allowed?: Set<string>): Promise<VectorCandidate[]> {\n if (allowed && allowed.size === 0) return [];\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const allowedList = allowed ? [...allowed] : [];\n const sql = `SELECT \"path\", arg_max(start_line, score) AS start_line, arg_max(end_line, score) AS end_line, max(score) AS score\n FROM (\n SELECT \"path\", start_line, end_line, array_cosine_similarity(vector, ?) AS score\n FROM embeddings\n WHERE vector IS NOT NULL ${allowed ? `AND ${inClause('\"path\"', allowedList.length)}` : ''}\n ) sub\n GROUP BY \"path\"\n ORDER BY score DESC\n LIMIT ?`;\n const stmt = await duckdb.prepare(sql);\n try {\n const values: DuckDBValue[] = [arrayValue(padded(qv, dims)), ...allowedList, fetch];\n const types: DuckDBType[] = [ARRAY(DOUBLE, dims), ...allowedList.map(() => untyped), untyped];\n stmt.bind(values, types);\n const reader = await stmt.runAndReadAll();\n const rows = reader.getRowObjectsJS() as Array<{ path: string; start_line: number; end_line: number; score: number }>;\n return rows.map((r) => ({ path: r.path, lines: `L${r.start_line}-${r.end_line}`, similarity: asCosine(r.score) }));\n } finally {\n stmt.destroySync();\n }\n}\n\n// Note-to-note similarity is the max cosine over (target chunk, other chunk) pairs, pushed\n// into one native scan: the sampled target vectors become a small VALUES list, cross-joined\n// against every stored vector and reduced with max()/GROUP BY, so the O(target x stored) cost\n// the plan measures (12.7s at 201 chunks/note in JS) runs vectorized instead of scalar.\nexport async function scanSimilar(duckdb: DuckDBConnection, conn: Connection, dims: number, path: string, opts: { exclude: Set<string>; allowed?: Set<string>; k: number }): Promise<VectorSimilar[]> {\n if (opts.allowed && opts.allowed.size === 0) return [];\n const targetStmt = await conn.prepare('SELECT vector FROM embeddings WHERE \"path\" = ? AND vector IS NOT NULL ORDER BY chunk');\n const targetRows = (await targetStmt.all(path)) as Array<{ vector: number[] }>;\n if (targetRows.length === 0) return [];\n const targets = sampleEvenly(targetRows).map((row) => row.vector);\n\n const { arrayValue, ARRAY, DOUBLE } = await duckdbApi();\n const excludeList = [...opts.exclude];\n const allowedList = opts.allowed ? [...opts.allowed] : [];\n const sql = `WITH targets(tv) AS (VALUES ${targets.map(() => '(?)').join(', ')})\n SELECT e.\"path\" AS path, max(array_cosine_similarity(e.vector, t.tv)) AS score\n FROM embeddings e, targets t\n WHERE e.vector IS NOT NULL AND e.\"path\" != ?\n ${excludeList.length > 0 ? `AND NOT ${inClause('e.\"path\"', excludeList.length)}` : ''}\n ${opts.allowed ? `AND ${inClause('e.\"path\"', allowedList.length)}` : ''}\n GROUP BY e.\"path\"\n ORDER BY score DESC\n LIMIT ?`;\n const stmt = await duckdb.prepare(sql);\n try {\n const values: DuckDBValue[] = [...targets.map((t) => arrayValue(padded(t, dims))), path, ...excludeList, ...allowedList, opts.k];\n const types: DuckDBType[] = [...targets.map(() => ARRAY(DOUBLE, dims)), untyped, ...excludeList.map(() => untyped), ...allowedList.map(() => untyped), untyped];\n stmt.bind(values, types);\n const reader = await stmt.runAndReadAll();\n const rows = reader.getRowObjectsJS() as Array<{ path: string; score: number }>;\n return rows.map((r) => ({ path: r.path, similarity: asCosine(r.score) }));\n } finally {\n stmt.destroySync();\n }\n}\n"],"names":["scanCandidates","scanSimilar","writeVectorBatch","untyped","undefined","padded","values","dims","out","Array","fill","d","Math","min","length","inClause","column","count","from","join","dequantize","row","q","Int8Array","vector","buffer","byteOffset","byteLength","v","scale","duckdb","conn","rows","arrayValue","ARRAY","DOUBLE","rewritten","duckdbApi","rewriteUpdate","Error","withTransaction","stmt","types","prepare","sql","push","path","chunk","bind","run","destroySync","qv","fetch","allowed","allowedList","reader","size","map","runAndReadAll","getRowObjectsJS","r","lines","start_line","end_line","similarity","asCosine","score","opts","targetStmt","targetRows","targets","excludeList","all","sampleEvenly","exclude","t","k"],"mappings":";;;;;;;;;;;QAgFsBA;eAAAA;;QA8BAC;eAAAA;;QAxDAC;eAAAA;;;6BArDU;yBAEO;uBACT;wBACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,mFAAmF;AACnF,uFAAuF;AACvF,0FAA0F;AAC1F,uFAAuF;AACvF,4FAA4F;AAC5F,8FAA8F;AAC9F,8BAA8B;AAC9B,EAAE;AACF,4FAA4F;AAC5F,8FAA8F;AAC9F,gGAAgG;AAChG,gFAAgF;AAEhF,6FAA6F;AAC7F,6FAA6F;AAC7F,IAAMC,UAAUC;AAEhB,6FAA6F;AAC7F,yFAAyF;AACzF,wEAAwE;AACxE,SAASC,OAAOC,MAAyB,EAAEC,IAAY;IACrD,IAAMC,MAAM,IAAIC,MAAcF,MAAMG,IAAI,CAAC;IACzC,IAAK,IAAIC,IAAI,GAAGA,IAAIC,KAAKC,GAAG,CAACP,OAAOQ,MAAM,EAAEP,OAAOI,IAAKH,GAAG,CAACG,EAAE,GAAGL,MAAM,CAACK,EAAE;IAC1E,OAAOH;AACT;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AM,IAAG;oBAI/D;;wBAAMgB,OAAOa,OAAO,CAACC;;;oBAA5BH,OAAO;;;;;;;;;oBAELnC,SAAwB,AAAC,qBAAGgE,QAAQb,GAAG,CAAC,SAACkB;+BAAM1C,WAAW5B,OAAOsE,GAAGpE;;wBAASuC;uBAAM,qBAAGyB,cAAa,qBAAGjB;wBAAaa,KAAKS,CAAC;;oBACzHlC,QAAsB,AAAC,qBAAG4B,QAAQb,GAAG,CAAC;+BAAMvB,MAAMC,QAAQ5B;;wBAAQJ;uBAAS,qBAAGoE,YAAYd,GAAG,CAAC;+BAAMtD;yBAAU,qBAAGmD,YAAYG,GAAG,CAAC;+BAAMtD;;wBAAUA;;oBACvJsC,KAAKO,IAAI,CAAC1C,QAAQoC;oBACH;;wBAAMD,KAAKiB,aAAa;;;oBAAjCH,SAAS;oBACTvB,OAAOuB,OAAOI,eAAe;oBACnC;;wBAAO3B,KAAKyB,GAAG,CAAC,SAACG;mCAAO;gCAAEd,MAAMc,EAAEd,IAAI;gCAAEkB,YAAYC,IAAAA,mBAAQ,EAACL,EAAEM,KAAK;4BAAE;;;;oBAEtEzB,KAAKS,WAAW;;;;;;;;;;IAEpB"}
@@ -42,6 +42,8 @@ var _opents = require("./duckdb/open.js");
42
42
  var _storets = require("./duckdb/store.js");
43
43
  var _opents1 = require("./sqlite/open.js");
44
44
  var _storets1 = require("./sqlite/store.js");
45
+ var _opents2 = require("./turso/open.js");
46
+ var _storets2 = require("./turso/store.js");
45
47
  var _metats = require("./meta.js");
46
48
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
47
49
  try {
@@ -178,6 +180,10 @@ var REGISTRY = {
178
180
  duckdb: {
179
181
  capabilities: _storets.CAPABILITIES,
180
182
  open: _opents.openDuckdb
183
+ },
184
+ turso: {
185
+ capabilities: _storets2.CAPABILITIES,
186
+ open: _opents2.openTurso
181
187
  }
182
188
  };
183
189
  function entryFor(name) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/index.ts"],"sourcesContent":["// Rows -> a backing store: registry + openStore(cfg). Parsing lives in scan.ts; everything\n// beyond frontmatter + content lives in src/features/.\n\nimport type { ResolvedConfig } from '../config/index.ts';\nimport { anyPresetEmbeds, storeName } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { openDuckdb } from './duckdb/open.ts';\nimport { CAPABILITIES as DUCKDB_CAPABILITIES } from './duckdb/store.ts';\nimport type { OpenResult } from './sqlite/open.ts';\nimport { openSqlite } from './sqlite/open.ts';\nimport { CAPABILITIES as SQLITE_CAPABILITIES } from './sqlite/store.ts';\nimport type { Capability } from './types.ts';\n\ntype StoreName = 'sqlite' | 'duckdb';\n\ninterface StoreEntry {\n capabilities: ReadonlySet<Capability>;\n open: (cfg: ResolvedConfig) => Promise<OpenResult>;\n}\n\n// Capabilities are checked against the registry entry before opening (no wasted connect/reconcile\n// work for a config that cannot be satisfied), then the store itself opens.\nconst REGISTRY: Record<StoreName, StoreEntry> = {\n sqlite: { capabilities: SQLITE_CAPABILITIES, open: openSqlite },\n duckdb: { capabilities: DUCKDB_CAPABILITIES, open: openDuckdb },\n};\n\nfunction entryFor(name: StoreName): StoreEntry {\n const entry = REGISTRY[name];\n if (!entry) throw new SenseError('STORE_UNKNOWN', `unknown backing store \"${name}\"; available: ${Object.keys(REGISTRY).join(', ')}`);\n return entry;\n}\n\nexport async function openStore(cfg: ResolvedConfig): Promise<OpenResult> {\n const name = storeName(cfg);\n const entry = entryFor(name);\n\n // The one unambiguous, config-level capability need: an embed block some preset actually\n // uses for vectors. Word/lexical search has no equivalent unambiguous signal at this level\n // (every preset defaults to wanting \"words\"), so a store lacking 'lexical' fails loudly at\n // first use instead (see duckdb/store.ts's lexical.query()).\n if (anyPresetEmbeds(cfg) && !entry.capabilities.has('vectors')) {\n throw new SenseError('STORE_CAPABILITY_MISSING', `store \"${name}\" does not implement \"vectors\" in this build, but this config's \"embed\" block is in use by at least one preset; remove or narrow it, or set \"store\" to a store that supports vectors (sqlite)`);\n }\n\n return entry.open(cfg);\n}\n\n// watch keeps its connection open for the run, so a file-locking store would fail every\n// other command on the tree; check before open, as openStore does for \"vectors\".\nexport function requireWatchConcurrency(cfg: ResolvedConfig): void {\n const name = storeName(cfg);\n if (!entryFor(name).capabilities.has('watch-concurrency')) {\n throw new SenseError('STORE_CAPABILITY_MISSING', `store \"${name}\" does not implement \"watch-concurrency\" in this build; sense watch holds the store open for its whole run, and this store locks the cache file, so every other command on this tree would fail to open; set \"store\" to \"sqlite\" in sense.config.json`);\n }\n}\n\nexport { getMeta, setMeta } from './meta.ts';\nexport type { OpenResult } from './sqlite/open.ts';\nexport { clearCache, DB_FILENAME, docCount, SCHEMA_VERSION } from './sqlite/open.ts';\nexport type { Capability, Connection, DocumentStore, LexicalHit, LexicalIndex, LexicalQueryOptions, RawStatement, RunResult, SqlSession, Statement, Store, VectorCandidate, VectorSimilar, VectorStore, VectorWriteRow } from './types.ts';\n"],"names":["DB_FILENAME","SCHEMA_VERSION","clearCache","docCount","getMeta","openStore","requireWatchConcurrency","setMeta","REGISTRY","sqlite","capabilities","SQLITE_CAPABILITIES","open","openSqlite","duckdb","DUCKDB_CAPABILITIES","openDuckdb","entryFor","name","entry","SenseError","Object","keys","join","cfg","storeName","anyPresetEmbeds","has"],"mappings":"AAAA,2FAA2F;AAC3F,uDAAuD;;;;;;;;;;;;QA0DlCA;eAAAA,oBAAW;;QAAYC;eAAAA,uBAAc;;QAAjDC;eAAAA,mBAAU;;QAAeC;eAAAA,iBAAQ;;QAFjCC;eAAAA,eAAO;;QAxBMC;eAAAA;;QAiBNC;eAAAA;;QAOEC;eAAAA,eAAO;;;uBArDkB;wBAChB;sBACA;uBACyB;uBAEzB;wBACyB;sBA+CnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AArCjC,kGAAkG;AAClG,4EAA4E;AAC5E,IAAMC,WAA0C;IAC9CC,QAAQ;QAAEC,cAAcC,sBAAmB;QAAEC,MAAMC,mBAAU;IAAC;IAC9DC,QAAQ;QAAEJ,cAAcK,qBAAmB;QAAEH,MAAMI,kBAAU;IAAC;AAChE;AAEA,SAASC,SAASC,IAAe;IAC/B,IAAMC,QAAQX,QAAQ,CAACU,KAAK;IAC5B,IAAI,CAACC,OAAO,MAAM,IAAIC,oBAAU,CAAC,iBAAiB,AAAC,0BAA8CC,OAArBH,MAAK,kBAAiD,OAAjCG,OAAOC,IAAI,CAACd,UAAUe,IAAI,CAAC;IAC5H,OAAOJ;AACT;AAEO,SAAed,UAAUmB,GAAmB;;YAC3CN,MACAC;;YADAD,OAAOO,IAAAA,kBAAS,EAACD;YACjBL,QAAQF,SAASC;YAEvB,yFAAyF;YACzF,2FAA2F;YAC3F,2FAA2F;YAC3F,6DAA6D;YAC7D,IAAIQ,IAAAA,wBAAe,EAACF,QAAQ,CAACL,MAAMT,YAAY,CAACiB,GAAG,CAAC,YAAY;gBAC9D,MAAM,IAAIP,oBAAU,CAAC,4BAA4B,AAAC,UAAc,OAALF,MAAK;YAClE;YAEA;;gBAAOC,MAAMP,IAAI,CAACY;;;IACpB;;AAIO,SAASlB,wBAAwBkB,GAAmB;IACzD,IAAMN,OAAOO,IAAAA,kBAAS,EAACD;IACvB,IAAI,CAACP,SAASC,MAAMR,YAAY,CAACiB,GAAG,CAAC,sBAAsB;QACzD,MAAM,IAAIP,oBAAU,CAAC,4BAA4B,AAAC,UAAc,OAALF,MAAK;IAClE;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/index.ts"],"sourcesContent":["// Rows -> a backing store: registry + openStore(cfg). Parsing lives in scan.ts; everything\n// beyond frontmatter + content lives in src/features/.\n\nimport type { ResolvedConfig, StoreName } from '../config/index.ts';\nimport { anyPresetEmbeds, storeName } from '../config/index.ts';\nimport { SenseError } from '../errors.ts';\nimport { openDuckdb } from './duckdb/open.ts';\nimport { CAPABILITIES as DUCKDB_CAPABILITIES } from './duckdb/store.ts';\nimport type { OpenResult } from './sqlite/open.ts';\nimport { openSqlite } from './sqlite/open.ts';\nimport { CAPABILITIES as SQLITE_CAPABILITIES } from './sqlite/store.ts';\nimport { openTurso } from './turso/open.ts';\nimport { CAPABILITIES as TURSO_CAPABILITIES } from './turso/store.ts';\nimport type { Capability } from './types.ts';\n\ninterface StoreEntry {\n capabilities: ReadonlySet<Capability>;\n open: (cfg: ResolvedConfig) => Promise<OpenResult>;\n}\n\n// Capabilities are checked against the registry entry before opening (no wasted connect/reconcile\n// work for a config that cannot be satisfied), then the store itself opens.\nconst REGISTRY: Record<StoreName, StoreEntry> = {\n sqlite: { capabilities: SQLITE_CAPABILITIES, open: openSqlite },\n duckdb: { capabilities: DUCKDB_CAPABILITIES, open: openDuckdb },\n turso: { capabilities: TURSO_CAPABILITIES, open: openTurso },\n};\n\nfunction entryFor(name: StoreName): StoreEntry {\n const entry = REGISTRY[name];\n if (!entry) throw new SenseError('STORE_UNKNOWN', `unknown backing store \"${name}\"; available: ${Object.keys(REGISTRY).join(', ')}`);\n return entry;\n}\n\nexport async function openStore(cfg: ResolvedConfig): Promise<OpenResult> {\n const name = storeName(cfg);\n const entry = entryFor(name);\n\n // The one unambiguous, config-level capability need: an embed block some preset actually\n // uses for vectors. Word/lexical search has no equivalent unambiguous signal at this level\n // (every preset defaults to wanting \"words\"), so a store lacking 'lexical' fails loudly at\n // first use instead (see duckdb/store.ts's lexical.query()).\n if (anyPresetEmbeds(cfg) && !entry.capabilities.has('vectors')) {\n throw new SenseError('STORE_CAPABILITY_MISSING', `store \"${name}\" does not implement \"vectors\" in this build, but this config's \"embed\" block is in use by at least one preset; remove or narrow it, or set \"store\" to a store that supports vectors (sqlite)`);\n }\n\n return entry.open(cfg);\n}\n\n// watch keeps its connection open for the run, so a file-locking store would fail every\n// other command on the tree; check before open, as openStore does for \"vectors\".\nexport function requireWatchConcurrency(cfg: ResolvedConfig): void {\n const name = storeName(cfg);\n if (!entryFor(name).capabilities.has('watch-concurrency')) {\n throw new SenseError('STORE_CAPABILITY_MISSING', `store \"${name}\" does not implement \"watch-concurrency\" in this build; sense watch holds the store open for its whole run, and this store locks the cache file, so every other command on this tree would fail to open; set \"store\" to \"sqlite\" in sense.config.json`);\n }\n}\n\nexport { getMeta, setMeta } from './meta.ts';\nexport type { OpenResult } from './sqlite/open.ts';\nexport { clearCache, DB_FILENAME, docCount, SCHEMA_VERSION } from './sqlite/open.ts';\nexport type { Capability, Connection, DocumentStore, LexicalHit, LexicalIndex, LexicalQueryOptions, RawStatement, RunResult, SqlSession, Statement, Store, VectorCandidate, VectorSimilar, VectorStore, VectorWriteRow } from './types.ts';\n"],"names":["DB_FILENAME","SCHEMA_VERSION","clearCache","docCount","getMeta","openStore","requireWatchConcurrency","setMeta","REGISTRY","sqlite","capabilities","SQLITE_CAPABILITIES","open","openSqlite","duckdb","DUCKDB_CAPABILITIES","openDuckdb","turso","TURSO_CAPABILITIES","openTurso","entryFor","name","entry","SenseError","Object","keys","join","cfg","storeName","anyPresetEmbeds","has"],"mappings":"AAAA,2FAA2F;AAC3F,uDAAuD;;;;;;;;;;;;QA2DlCA;eAAAA,oBAAW;;QAAYC;eAAAA,uBAAc;;QAAjDC;eAAAA,mBAAU;;QAAeC;eAAAA,iBAAQ;;QAFjCC;eAAAA,eAAO;;QAxBMC;eAAAA;;QAiBNC;eAAAA;;QAOEC;eAAAA,eAAO;;;uBAtDkB;wBAChB;sBACA;uBACyB;uBAEzB;wBACyB;uBAC1B;wBACyB;sBA8ClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAtCjC,kGAAkG;AAClG,4EAA4E;AAC5E,IAAMC,WAA0C;IAC9CC,QAAQ;QAAEC,cAAcC,sBAAmB;QAAEC,MAAMC,mBAAU;IAAC;IAC9DC,QAAQ;QAAEJ,cAAcK,qBAAmB;QAAEH,MAAMI,kBAAU;IAAC;IAC9DC,OAAO;QAAEP,cAAcQ,sBAAkB;QAAEN,MAAMO,kBAAS;IAAC;AAC7D;AAEA,SAASC,SAASC,IAAe;IAC/B,IAAMC,QAAQd,QAAQ,CAACa,KAAK;IAC5B,IAAI,CAACC,OAAO,MAAM,IAAIC,oBAAU,CAAC,iBAAiB,AAAC,0BAA8CC,OAArBH,MAAK,kBAAiD,OAAjCG,OAAOC,IAAI,CAACjB,UAAUkB,IAAI,CAAC;IAC5H,OAAOJ;AACT;AAEO,SAAejB,UAAUsB,GAAmB;;YAC3CN,MACAC;;YADAD,OAAOO,IAAAA,kBAAS,EAACD;YACjBL,QAAQF,SAASC;YAEvB,yFAAyF;YACzF,2FAA2F;YAC3F,2FAA2F;YAC3F,6DAA6D;YAC7D,IAAIQ,IAAAA,wBAAe,EAACF,QAAQ,CAACL,MAAMZ,YAAY,CAACoB,GAAG,CAAC,YAAY;gBAC9D,MAAM,IAAIP,oBAAU,CAAC,4BAA4B,AAAC,UAAc,OAALF,MAAK;YAClE;YAEA;;gBAAOC,MAAMV,IAAI,CAACe;;;IACpB;;AAIO,SAASrB,wBAAwBqB,GAAmB;IACzD,IAAMN,OAAOO,IAAAA,kBAAS,EAACD;IACvB,IAAI,CAACP,SAASC,MAAMX,YAAY,CAACoB,GAAG,CAAC,sBAAsB;QACzD,MAAM,IAAIP,oBAAU,CAAC,4BAA4B,AAAC,UAAc,OAALF,MAAK;IAClE;AACF"}
@@ -0,0 +1,7 @@
1
+ export interface NativeDescriptor {
2
+ store: string;
3
+ pkg: string;
4
+ sizeHint: string;
5
+ }
6
+ export declare function packageNodeModules(): string;
7
+ export declare function loadOrInstall<T>(descriptor: NativeDescriptor, nodeModulesPath: string, importName?: string): Promise<T>;
@@ -0,0 +1,7 @@
1
+ export interface NativeDescriptor {
2
+ store: string;
3
+ pkg: string;
4
+ sizeHint: string;
5
+ }
6
+ export declare function packageNodeModules(): string;
7
+ export declare function loadOrInstall<T>(descriptor: NativeDescriptor, nodeModulesPath: string, importName?: string): Promise<T>;
@@ -0,0 +1,350 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get loadOrInstall () {
13
+ return loadOrInstall;
14
+ },
15
+ get packageNodeModules () {
16
+ return packageNodeModules;
17
+ }
18
+ });
19
+ var _nodefs = require("node:fs");
20
+ var _nodemodule = /*#__PURE__*/ _interop_require_default(require("node:module"));
21
+ var _nodepath = require("node:path");
22
+ var _nodeurl = require("node:url");
23
+ var _errorsts = require("../errors.js");
24
+ function _array_like_to_array(arr, len) {
25
+ if (len == null || len > arr.length) len = arr.length;
26
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
27
+ return arr2;
28
+ }
29
+ function _array_without_holes(arr) {
30
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
31
+ }
32
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
33
+ try {
34
+ var info = gen[key](arg);
35
+ var value = info.value;
36
+ } catch (error) {
37
+ reject(error);
38
+ return;
39
+ }
40
+ if (info.done) resolve(value);
41
+ else Promise.resolve(value).then(_next, _throw);
42
+ }
43
+ function _async_to_generator(fn) {
44
+ return function() {
45
+ var self = this, args = arguments;
46
+ return new Promise(function(resolve, reject) {
47
+ var gen = fn.apply(self, args);
48
+ function _next(value) {
49
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
50
+ }
51
+ function _throw(err) {
52
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
53
+ }
54
+ _next(undefined);
55
+ });
56
+ };
57
+ }
58
+ function _interop_require_default(obj) {
59
+ return obj && obj.__esModule ? obj : {
60
+ default: obj
61
+ };
62
+ }
63
+ function _getRequireWildcardCache(nodeInterop) {
64
+ if (typeof WeakMap !== "function") return null;
65
+ var cacheBabelInterop = new WeakMap();
66
+ var cacheNodeInterop = new WeakMap();
67
+ return (_getRequireWildcardCache = function(nodeInterop) {
68
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
69
+ })(nodeInterop);
70
+ }
71
+ function _interop_require_wildcard(obj, nodeInterop) {
72
+ if (!nodeInterop && obj && obj.__esModule) return obj;
73
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
74
+ default: obj
75
+ };
76
+ var cache = _getRequireWildcardCache(nodeInterop);
77
+ if (cache && cache.has(obj)) return cache.get(obj);
78
+ var newObj = {
79
+ __proto__: null
80
+ };
81
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
82
+ for(var key in obj){
83
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
84
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
85
+ if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
86
+ else newObj[key] = obj[key];
87
+ }
88
+ }
89
+ newObj.default = obj;
90
+ if (cache) cache.set(obj, newObj);
91
+ return newObj;
92
+ }
93
+ function _iterable_to_array(iter) {
94
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
95
+ return Array.from(iter);
96
+ }
97
+ }
98
+ function _non_iterable_spread() {
99
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
100
+ }
101
+ function _to_consumable_array(arr) {
102
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
103
+ }
104
+ function _ts_generator(thisArg, body) {
105
+ var f, y, t, _ = {
106
+ label: 0,
107
+ sent: function() {
108
+ if (t[0] & 1) throw t[1];
109
+ return t[1];
110
+ },
111
+ trys: [],
112
+ ops: []
113
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
114
+ return d(g, "next", {
115
+ value: verb(0)
116
+ }), d(g, "throw", {
117
+ value: verb(1)
118
+ }), d(g, "return", {
119
+ value: verb(2)
120
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
121
+ value: function() {
122
+ return this;
123
+ }
124
+ }), g;
125
+ function verb(n) {
126
+ return function(v) {
127
+ return step([
128
+ n,
129
+ v
130
+ ]);
131
+ };
132
+ }
133
+ function step(op) {
134
+ if (f) throw new TypeError("Generator is already executing.");
135
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
136
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
137
+ if (y = 0, t) op = [
138
+ op[0] & 2,
139
+ t.value
140
+ ];
141
+ switch(op[0]){
142
+ case 0:
143
+ case 1:
144
+ t = op;
145
+ break;
146
+ case 4:
147
+ _.label++;
148
+ return {
149
+ value: op[1],
150
+ done: false
151
+ };
152
+ case 5:
153
+ _.label++;
154
+ y = op[1];
155
+ op = [
156
+ 0
157
+ ];
158
+ continue;
159
+ case 7:
160
+ op = _.ops.pop();
161
+ _.trys.pop();
162
+ continue;
163
+ default:
164
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
165
+ _ = 0;
166
+ continue;
167
+ }
168
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
169
+ _.label = op[1];
170
+ break;
171
+ }
172
+ if (op[0] === 6 && _.label < t[1]) {
173
+ _.label = t[1];
174
+ t = op;
175
+ break;
176
+ }
177
+ if (t && _.label < t[2]) {
178
+ _.label = t[2];
179
+ _.ops.push(op);
180
+ break;
181
+ }
182
+ if (t[2]) _.ops.pop();
183
+ _.trys.pop();
184
+ continue;
185
+ }
186
+ op = body.call(thisArg, _);
187
+ } catch (e) {
188
+ op = [
189
+ 6,
190
+ e
191
+ ];
192
+ y = 0;
193
+ } finally{
194
+ f = t = 0;
195
+ }
196
+ if (op[0] & 5) throw op[1];
197
+ return {
198
+ value: op[0] ? op[1] : void 0,
199
+ done: true
200
+ };
201
+ }
202
+ }
203
+ function _unsupported_iterable_to_array(o, minLen) {
204
+ if (!o) return;
205
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
206
+ var n = Object.prototype.toString.call(o).slice(8, -1);
207
+ if (n === "Object" && o.constructor) n = o.constructor.name;
208
+ if (n === "Map" || n === "Set") return Array.from(n);
209
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
210
+ }
211
+ // install-module-linked itself is small, but a target native package can be large (@duckdb/node-
212
+ // api's ~110MB is the current instance): deferred the same way embed/static.ts defers
213
+ // @huggingface/tokenizers, so requiring it stays inside the already-gated branch below rather
214
+ // than running for every store/index.ts load.
215
+ var _require = typeof require === 'undefined' ? _nodemodule.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
216
+ var _dirname = (0, _nodepath.dirname)(typeof __filename !== 'undefined' ? __filename : (0, _nodeurl.fileURLToPath)(require("url").pathToFileURL(__filename).toString()));
217
+ function packageNodeModules() {
218
+ var dir = _dirname;
219
+ for(;;){
220
+ var candidate = (0, _nodepath.join)(dir, 'package.json');
221
+ if ((0, _nodefs.existsSync)(candidate)) {
222
+ var pkg = JSON.parse((0, _nodefs.readFileSync)(candidate, 'utf8'));
223
+ if (pkg.name === 'sensemaking') return (0, _nodepath.join)(dir, 'node_modules');
224
+ }
225
+ var parent = (0, _nodepath.dirname)(dir);
226
+ if (parent === dir) throw new Error('could not locate the sensemaking package root to install a native dependency into');
227
+ dir = parent;
228
+ }
229
+ }
230
+ var installing = new Map();
231
+ // De-dupes concurrent installs within this process (see spawn-term's loadInk for the shape).
232
+ // The install here is async -- the load site already awaits a dynamic import -- so a bare
233
+ // attempted flag (xz-compat's `installationAttempted`, enough for its synchronous single-target
234
+ // install) isn't enough on its own; concurrent callers instead await the same in-flight promise,
235
+ // keyed by specifier and target so tests exercising several installs in one process don't share
236
+ // one slot. A failed install is not cached, so a later call retries.
237
+ function installOnce(specifier, nodeModulesPath) {
238
+ var key = "".concat(specifier, "\n").concat(nodeModulesPath);
239
+ var promise = installing.get(key);
240
+ if (!promise) {
241
+ var installModuleLinked = _require('install-module-linked').default;
242
+ promise = installModuleLinked(specifier, nodeModulesPath).then(function() {}, function(err) {
243
+ installing.delete(key);
244
+ throw err;
245
+ });
246
+ installing.set(key, promise);
247
+ }
248
+ return promise;
249
+ }
250
+ // Node caches a bare specifier's package resolution -- including a "not found" miss -- for the
251
+ // life of the process, so retrying `import(importName)` right after installing sees the same
252
+ // stale miss and falls through to a bogus index.js guess instead of the package's real entry
253
+ // (verified against a real global install: the plain-specifier retry failed there, this did
254
+ // not). Reading the freshly-installed package's own package.json and importing its entry file
255
+ // by an absolute file: URL sidesteps that stale cache instead of re-resolving the bare name.
256
+ function resolveEntryUrl(importName, nodeModulesPath) {
257
+ var _pkg_main;
258
+ var pkgDir = _nodepath.join.apply(void 0, [
259
+ nodeModulesPath
260
+ ].concat(_to_consumable_array(importName.split('/'))));
261
+ var pkg = JSON.parse((0, _nodefs.readFileSync)((0, _nodepath.join)(pkgDir, 'package.json'), 'utf8'));
262
+ var entry = typeof pkg.exports === 'string' ? pkg.exports : (_pkg_main = pkg.main) !== null && _pkg_main !== void 0 ? _pkg_main : 'index.js';
263
+ return (0, _nodeurl.pathToFileURL)((0, _nodepath.join)(pkgDir, entry)).href;
264
+ }
265
+ function loadOrInstall(_0, _1) {
266
+ return _async_to_generator(function(descriptor, nodeModulesPath) {
267
+ var importName, unused, installErr, loadErr;
268
+ var _arguments = arguments;
269
+ return _ts_generator(this, function(_state) {
270
+ switch(_state.label){
271
+ case 0:
272
+ importName = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : descriptor.pkg;
273
+ _state.label = 1;
274
+ case 1:
275
+ _state.trys.push([
276
+ 1,
277
+ 3,
278
+ ,
279
+ 11
280
+ ]);
281
+ return [
282
+ 4,
283
+ Promise.resolve(importName).then(function(p) {
284
+ return /*#__PURE__*/ _interop_require_wildcard(require(p));
285
+ })
286
+ ];
287
+ case 2:
288
+ return [
289
+ 2,
290
+ _state.sent()
291
+ ];
292
+ case 3:
293
+ unused = _state.sent();
294
+ console.error('sense: store "'.concat(descriptor.store, '" needs ').concat(descriptor.pkg, "; installing it now (one-time download, ").concat(descriptor.sizeHint, ")..."));
295
+ _state.label = 4;
296
+ case 4:
297
+ _state.trys.push([
298
+ 4,
299
+ 6,
300
+ ,
301
+ 7
302
+ ]);
303
+ return [
304
+ 4,
305
+ installOnce(importName, nodeModulesPath)
306
+ ];
307
+ case 5:
308
+ _state.sent();
309
+ return [
310
+ 3,
311
+ 7
312
+ ];
313
+ case 6:
314
+ installErr = _state.sent();
315
+ throw new _errorsts.SenseError('STORE_DEPENDENCY_MISSING', 'store "'.concat(descriptor.store, '" needs ').concat(descriptor.pkg, ", and installing it automatically failed (").concat(installErr.message, "); this can happen offline, in a sandboxed environment, or when node_modules is read-only or owned by another user (e.g. under a global install) -- run `npm install ").concat(descriptor.pkg, "` yourself and try again"));
316
+ case 7:
317
+ _state.trys.push([
318
+ 7,
319
+ 9,
320
+ ,
321
+ 10
322
+ ]);
323
+ return [
324
+ 4,
325
+ Promise.resolve(resolveEntryUrl(importName, nodeModulesPath)).then(function(p) {
326
+ return /*#__PURE__*/ _interop_require_wildcard(require(p));
327
+ })
328
+ ];
329
+ case 8:
330
+ return [
331
+ 2,
332
+ _state.sent()
333
+ ];
334
+ case 9:
335
+ loadErr = _state.sent();
336
+ throw new _errorsts.SenseError('STORE_DEPENDENCY_MISSING', 'store "'.concat(descriptor.store, '" installed ').concat(descriptor.pkg, " but it could not be loaded (").concat(loadErr.message, "); it may not be available for this platform (").concat(process.platform, "-").concat(process.arch, ") -- run `npm install ").concat(descriptor.pkg, "` to see the underlying error"));
337
+ case 10:
338
+ return [
339
+ 3,
340
+ 11
341
+ ];
342
+ case 11:
343
+ return [
344
+ 2
345
+ ];
346
+ }
347
+ });
348
+ }).apply(this, arguments);
349
+ }
350
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/sensemaking/src/store/native.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport Module from 'node:module';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport { SenseError } from '../errors.ts';\n\n// A store's optional native package, and the strings its error messages and install notice name.\nexport interface NativeDescriptor {\n store: string;\n pkg: string;\n sizeHint: string;\n}\n\n// install-module-linked itself is small, but a target native package can be large (@duckdb/node-\n// api's ~110MB is the current instance): deferred the same way embed/static.ts defers\n// @huggingface/tokenizers, so requiring it stays inside the already-gated branch below rather\n// than running for every store/index.ts load.\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst _dirname = dirname(typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url));\n\n// Walks up from this file's own directory to find the real package.json, rather than a fixed\n// dot-count from __dirname (xz-compat's `../../node_modules`): this file sits at a different\n// depth under src/ during `tsds test:node` than under the built dist/{cjs,esm}/store output, so a\n// hardcoded depth is right for one and wrong for the other. Works the same way for a\n// globally-installed `sense`, whose node_modules this resolves to -- never the caller's cwd.\nexport function packageNodeModules(): string {\n let dir = _dirname;\n for (;;) {\n const candidate = join(dir, 'package.json');\n if (existsSync(candidate)) {\n const pkg = JSON.parse(readFileSync(candidate, 'utf8')) as { name?: string };\n if (pkg.name === 'sensemaking') return join(dir, 'node_modules');\n }\n const parent = dirname(dir);\n if (parent === dir) throw new Error('could not locate the sensemaking package root to install a native dependency into');\n dir = parent;\n }\n}\n\nconst installing = new Map<string, Promise<void>>();\n\n// De-dupes concurrent installs within this process (see spawn-term's loadInk for the shape).\n// The install here is async -- the load site already awaits a dynamic import -- so a bare\n// attempted flag (xz-compat's `installationAttempted`, enough for its synchronous single-target\n// install) isn't enough on its own; concurrent callers instead await the same in-flight promise,\n// keyed by specifier and target so tests exercising several installs in one process don't share\n// one slot. A failed install is not cached, so a later call retries.\nfunction installOnce(specifier: string, nodeModulesPath: string): Promise<void> {\n const key = `${specifier}\\n${nodeModulesPath}`;\n let promise = installing.get(key);\n if (!promise) {\n const installModuleLinked = (_require('install-module-linked') as { default: (specifier: string, nodeModulesPath: string) => Promise<string> }).default;\n promise = installModuleLinked(specifier, nodeModulesPath).then(\n () => {},\n (err) => {\n installing.delete(key);\n throw err;\n }\n );\n installing.set(key, promise);\n }\n return promise;\n}\n\n// Node caches a bare specifier's package resolution -- including a \"not found\" miss -- for the\n// life of the process, so retrying `import(importName)` right after installing sees the same\n// stale miss and falls through to a bogus index.js guess instead of the package's real entry\n// (verified against a real global install: the plain-specifier retry failed there, this did\n// not). Reading the freshly-installed package's own package.json and importing its entry file\n// by an absolute file: URL sidesteps that stale cache instead of re-resolving the bare name.\nfunction resolveEntryUrl(importName: string, nodeModulesPath: string): string {\n const pkgDir = join(nodeModulesPath, ...importName.split('/'));\n const pkg = JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8')) as { main?: string; exports?: string };\n const entry = typeof pkg.exports === 'string' ? pkg.exports : (pkg.main ?? 'index.js');\n return pathToFileURL(join(pkgDir, entry)).href;\n}\n\n// Import-then-install-then-retry, over an injectable importName so the failure path (import AND\n// install both fail) can be exercised for real in tests without downloading a real store's native\n// binding. importName defaults to descriptor.pkg, which is what production always wants; the\n// thrown errors name descriptor.pkg regardless, since that is what a real user needs to install.\nexport async function loadOrInstall<T>(descriptor: NativeDescriptor, nodeModulesPath: string, importName: string = descriptor.pkg): Promise<T> {\n try {\n return (await import(importName)) as T;\n } catch {\n console.error(`sense: store \"${descriptor.store}\" needs ${descriptor.pkg}; installing it now (one-time download, ${descriptor.sizeHint})...`);\n try {\n await installOnce(importName, nodeModulesPath);\n } catch (installErr) {\n throw new SenseError(\n 'STORE_DEPENDENCY_MISSING',\n `store \"${descriptor.store}\" needs ${descriptor.pkg}, and installing it automatically failed (${(installErr as Error).message}); this can happen offline, in a sandboxed environment, or when node_modules is read-only or owned by another user (e.g. under a global install) -- run \\`npm install ${descriptor.pkg}\\` yourself and try again`\n );\n }\n try {\n return (await import(resolveEntryUrl(importName, nodeModulesPath))) as T;\n } catch (loadErr) {\n throw new SenseError(\n 'STORE_DEPENDENCY_MISSING',\n `store \"${descriptor.store}\" installed ${descriptor.pkg} but it could not be loaded (${(loadErr as Error).message}); it may not be available for this platform (${process.platform}-${process.arch}) -- run \\`npm install ${descriptor.pkg}\\` to see the underlying error`\n );\n }\n }\n}\n"],"names":["loadOrInstall","packageNodeModules","_require","require","Module","createRequire","_dirname","dirname","__filename","fileURLToPath","dir","candidate","join","existsSync","pkg","JSON","parse","readFileSync","name","parent","Error","installing","Map","installOnce","specifier","nodeModulesPath","key","promise","get","installModuleLinked","default","then","err","delete","set","resolveEntryUrl","importName","pkgDir","split","entry","exports","main","pathToFileURL","href","descriptor","installErr","loadErr","console","error","store","sizeHint","SenseError","message","process","platform","arch"],"mappings":";;;;;;;;;;;QAiFsBA;eAAAA;;QAxDNC;eAAAA;;;sBAzByB;iEACtB;wBACW;uBACe;wBAClB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAS3B,iGAAiG;AACj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,iCAA0GuC,OAA3E,AAACP,QAAkBM,OAAO,EAAC,kDAAoEC,OAApBA,QAAQC,QAAQ,EAAC,KAAyCV,OAAtCS,QAAQE,IAAI,EAAC,0BAAwC,OAAfX,WAAW9B,GAAG,EAAC;;;;;;;;;;;;IAInP"}
@@ -0,0 +1,2 @@
1
+ import type { Connection, FieldStat } from '../types.js';
2
+ export declare function fieldStats(conn: Connection, columns: string[], scopeWhere: string): Promise<FieldStat[]>;
@@ -0,0 +1,2 @@
1
+ import type { Connection, FieldStat } from '../types.js';
2
+ export declare function fieldStats(conn: Connection, columns: string[], scopeWhere: string): Promise<FieldStat[]>;