hyacinth-ai 0.9.10 → 0.9.11

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.
@@ -4,11 +4,22 @@
4
4
  * 使用 better-sqlite3 存储文档 + FTS5 虚拟表做 BM25 关键词检索。
5
5
  * 对 CJK 文本自动追加 bigram 到索引内容中,以支持中文搜索。
6
6
  */
7
- import Database from 'better-sqlite3';
7
+ import { createRequire } from 'node:module';
8
8
  import path from 'node:path';
9
9
  import fs from 'node:fs';
10
10
  import crypto from 'node:crypto';
11
11
  import { preprocessQuery } from './query-preprocessor.js';
12
+ // ── 懒加载 better-sqlite3(可选依赖) ────────────────────────────
13
+ const _require = createRequire(import.meta.url);
14
+ function getDatabase() {
15
+ try {
16
+ return _require('better-sqlite3');
17
+ }
18
+ catch {
19
+ throw new Error('better-sqlite3 未安装。FTS5 知识库功能需要此可选依赖。\n' +
20
+ '请运行: npm install better-sqlite3 或 pnpm add better-sqlite3');
21
+ }
22
+ }
12
23
  // ── CJK bigram 分词 ────────────────────────────────────────────────
13
24
  const CJK_RE = /[一-鿿㐀-䶿]/;
14
25
  /** 将 CJK 文本转为空格分隔的二元组,追加到原文后面供 FTS5 索引 */
@@ -43,6 +54,7 @@ export class Fts5Retriever {
43
54
  name = 'fts5';
44
55
  db;
45
56
  constructor(dbPath) {
57
+ const Database = getDatabase();
46
58
  const dir = path.dirname(dbPath);
47
59
  fs.mkdirSync(dir, { recursive: true });
48
60
  this.db = new Database(dbPath);
@@ -6,14 +6,26 @@
6
6
  * tag 子串匹配为主检索(用户输入.includes(tag))
7
7
  * FTS5 全文索引为兜底
8
8
  */
9
- import Database from 'better-sqlite3';
9
+ import { createRequire } from 'node:module';
10
10
  import path from 'node:path';
11
11
  import fs from 'node:fs';
12
12
  import crypto from 'node:crypto';
13
+ // ── 懒加载 better-sqlite3(可选依赖) ────────────────────────────
14
+ const _require = createRequire(import.meta.url);
15
+ function getDatabase() {
16
+ try {
17
+ return _require('better-sqlite3');
18
+ }
19
+ catch {
20
+ throw new Error('better-sqlite3 未安装。结构化知识库需要此可选依赖。\n' +
21
+ '请运行: npm install better-sqlite3 或 pnpm add better-sqlite3');
22
+ }
23
+ }
13
24
  // ── Store ───────────────────────────────────────────────────────────
14
25
  export class StructuredStore {
15
26
  db;
16
27
  constructor(dbPath) {
28
+ const Database = getDatabase();
17
29
  const dir = path.dirname(dbPath);
18
30
  fs.mkdirSync(dir, { recursive: true });
19
31
  this.db = new Database(dbPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyacinth-ai",
3
- "version": "0.9.10",
3
+ "version": "0.9.11",
4
4
  "description": "Hyacinth 🪻 — multi-provider AI agent with tool system and context management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",