mino-connector-webwatch 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/hostdeps.mjs +30 -65
  2. package/index.js +7 -3
  3. package/package.json +2 -2
package/hostdeps.mjs CHANGED
@@ -1,74 +1,39 @@
1
- /**
2
- * hostdeps.mjs —— 从宿主那棵树里取 `defineTool`(拿不到就退到自己的依赖,再不行用本地等价实现)。
3
- * 与 fish-memory/lib/hostdeps.mjs 同一策略:桌面版 profile `autoInstallPeers: false`
4
- * 时裸 import `@deepseek-ai/dsh-tools` 会让整条插件不激活,所以优先从宿主树解析。
5
- * 本包只需要 defineTool 一个件。
6
- */
7
- import { existsSync, readFileSync, readdirSync } from 'node:fs'
8
- import { join, dirname } from 'node:path'
9
- import { homedir } from 'node:os'
10
- import { fileURLToPath, pathToFileURL } from 'node:url'
1
+ // Canonical host API loader. Generate packaged copies with scripts/sync-hostdeps.mjs.
2
+ import { createRequire } from 'node:module'
3
+ import { join, resolve } from 'node:path'
4
+ import { pathToFileURL } from 'node:url'
11
5
 
12
- const SELF_MODULES = join(dirname(fileURLToPath(import.meta.url)), 'node_modules', '@deepseek-ai')
6
+ function resolverOrigins(name) {
7
+ const origins = []
8
+ // An explicit development host and the current Electron installation own these APIs.
9
+ if (process.env.DSH_HOST_MODULES) origins.push(join(process.env.DSH_HOST_MODULES, name, 'package.json'))
10
+ if (process.resourcesPath) origins.push(join(process.resourcesPath, 'app.asar', 'dsh', 'node_modules', '@deepseek-ai', name, 'package.json'))
11
+ if (process.argv[1]) origins.push(resolve(process.argv[1]))
12
+ origins.push(import.meta.url)
13
+ return [...new Set(origins)]
14
+ }
13
15
 
14
- function candidateRoots() {
15
- const out = []
16
- const push = (p) => { if (p && !out.includes(p)) out.push(p) }
17
- push(process.env.DSH_HOST_MODULES)
18
- const appdata = process.env.APPDATA
19
- if (appdata) {
20
- const npm = join(appdata, 'npm', 'node_modules')
21
- push(join(npm, '@deepseek-ai'))
16
+ async function loadLibrary(name, notes) {
17
+ const failures = []
18
+ for (const origin of resolverOrigins(name)) {
22
19
  try {
23
- for (const n of readdirSync(join(npm, '@deepseek-ai'))) {
24
- push(join(npm, '@deepseek-ai', n, 'node_modules', '@deepseek-ai'))
25
- }
26
- } catch { /* 没有就算了 */ }
20
+ const entry = createRequire(origin).resolve(`@deepseek-ai/${name}`)
21
+ const module = await import(pathToFileURL(entry).href)
22
+ notes.push(`${name}: ${entry}`)
23
+ return module
24
+ } catch (error) { failures.push(error) }
27
25
  }
28
- try {
29
- const dshHome = process.env.DSH_HOME || join(homedir(), '.dsh')
30
- for (const p of readdirSync(join(dshHome, 'profiles'))) {
31
- push(join(dshHome, 'profiles', p, 'node_modules', '@deepseek-ai'))
32
- }
33
- } catch { /* 没有就算了 */ }
34
- push(SELF_MODULES)
35
- return out
36
- }
37
-
38
- function entryUrlFor(root, name) {
39
- try {
40
- const dir = join(root, name)
41
- const pkgFile = join(dir, 'package.json')
42
- if (!existsSync(pkgFile)) return null
43
- const pkg = JSON.parse(readFileSync(pkgFile, 'utf8'))
44
- const dot = pkg.exports?.['.']
45
- const rel = typeof dot === 'string' ? dot : (dot?.import || dot?.default || pkg.module || pkg.main)
46
- if (!rel) return null
47
- const file = join(dir, String(rel).replace(/^\.\//, ''))
48
- return existsSync(file) ? pathToFileURL(file).href : null
49
- } catch { return null }
50
- }
51
-
52
- function localDefineTool(options) {
53
- return options
26
+ throw new AggregateError(failures, `Host API @deepseek-ai/${name} is unavailable`)
54
27
  }
55
28
 
56
29
  export async function loadHostDeps() {
57
30
  const notes = []
58
- const log = (m) => notes.push(m)
59
- let defineTool = null
60
- let dtMod = null
61
- for (const root of candidateRoots()) {
62
- if (root === SELF_MODULES) continue
63
- const url = entryUrlFor(root, 'dsh-tools')
64
- if (!url) continue
65
- try { dtMod = await import(url); log(`dsh-tools:宿主树取到(${url})`); break }
66
- catch { /* try next root */ }
67
- }
68
- if (!dtMod) {
69
- try { dtMod = await import('@deepseek-ai/dsh-tools'); log('dsh-tools:用自己依赖里那份') }
70
- catch (e) { log(`dsh-tools 拿不到(${e?.code || ''})—— 用本地等价实现顶上`); dtMod = null }
71
- }
72
- defineTool = dtMod?.defineTool || ((options) => localDefineTool(options))
73
- return { defineTool, notes }
31
+ const tools = await loadLibrary('dsh-tools', notes)
32
+ if (typeof tools.defineTool !== 'function') throw new Error('Required host API @deepseek-ai/dsh-tools.defineTool is unavailable')
33
+ let z = null
34
+ try {
35
+ const schema = await loadLibrary('schemastery', notes)
36
+ z = schema.default ?? schema
37
+ } catch (error) { notes.push(error.message) }
38
+ return { z, defineTool: tools.defineTool, notes }
74
39
  }
package/index.js CHANGED
@@ -73,10 +73,14 @@ async function readChromium(dbPath, days) {
73
73
  try {
74
74
  const db = new DatabaseSync(tmp, { readOnly: true })
75
75
  const cutoff = (Date.now() / 1000 - days * 86400 + CHROME_EPOCH) * 1e6
76
- const rows = db.prepare(
77
- `SELECT url, title, last_visit_time t FROM urls WHERE last_visit_time > ? ORDER BY last_visit_time DESC LIMIT 200000`).all(cutoff)
76
+ // Chromium last_visit_time ≈1.3e16 µs 超过 Number.MAX_SAFE_INTEGER:node:sqlite 对不安全
77
+ // 整数默认抛 RangeError——必须按 BigInt 读,先除到秒再转 Number。
78
+ const stmt = db.prepare(
79
+ `SELECT url, title, last_visit_time t FROM urls WHERE last_visit_time > ? ORDER BY last_visit_time DESC LIMIT 200000`)
80
+ stmt.setReadBigInts(true)
81
+ const rows = stmt.all(cutoff)
78
82
  db.close()
79
- return rows.map(r => ({ url: r.url, title: r.title || '', ts: (r.t / 1e6 - CHROME_EPOCH) * 1000 }))
83
+ return rows.map(r => ({ url: r.url, title: r.title || '', ts: (Number(r.t / 1_000_000n) - CHROME_EPOCH) * 1000 }))
80
84
  } finally { try { const { unlinkSync } = await import('node:fs'); unlinkSync(tmp) } catch { } }
81
85
  }
82
86
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mino-connector-webwatch",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "被动观察 v0:扫浏览器历史里的订单/行程页访问,提示可用的导入通道(复制/OCR/导出)。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -34,4 +34,4 @@
34
34
  "engines": {
35
35
  "dsh": ">=0.2.2-alpha.1 <0.3.0"
36
36
  }
37
- }
37
+ }