mino-connector-wechat 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 (2) hide show
  1. package/hostdeps.mjs +30 -65
  2. 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mino-connector-wechat",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "微信本地语料连接器:定位 WeChat 数据目录/进程,封装导出引擎(wechat-dump-rs/PyWxDump)做内存取钥+库解密,明文落 chat.db 检索。特区解封,用户自己的数据。",
5
5
  "keywords": [
6
6
  "dsh",
@@ -42,4 +42,4 @@
42
42
  "bugs": {
43
43
  "url": "https://github.com/694410194/mino-plugins/issues"
44
44
  }
45
- }
45
+ }