@dsh-plus/web-search-services 0.1.0 → 0.1.2

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.
package/src/provider.ts CHANGED
@@ -5,6 +5,8 @@
5
5
  * @module web-search-services/provider
6
6
  */
7
7
  import { existsSync } from 'node:fs'
8
+ import { fileURLToPath } from 'node:url'
9
+
8
10
  import type { WebSearchProvider, WebSearchRequest, WebSearchResult } from '@deepseek-ai/dsh-web'
9
11
  import { WebError } from '@deepseek-ai/dsh-web'
10
12
 
@@ -16,6 +18,15 @@ import { isAbortError, runProcess, type SpawnFn } from './runner.ts'
16
18
 
17
19
  export const PROVIDER_ID = 'search-services'
18
20
 
21
+ /**
22
+ * scriptPath 解析:空串 = 随包内置脚本副本(tgz 内 scripts/search.py,与 lib/
23
+ * 同级;src 直跑时为包根 scripts/)。非空按 ~ 展开。
24
+ */
25
+ export function resolveScriptPath(scriptPath: string): string {
26
+ if (scriptPath.trim() !== '') return expandHome(scriptPath)
27
+ return fileURLToPath(new URL('../scripts/search.py', import.meta.url))
28
+ }
29
+
19
30
  /** 各后端在合并环境(进程 env ⊕ envFile ⊕ 行级 keys)中的可用性判定变量。 */
20
31
  const BACKEND_KEY_VARS: Readonly<Record<SearchBackend, readonly string[]>> = {
21
32
  tavily: ['TAVILY_API_KEY', 'TAVILY_API_KEYS'],
@@ -60,7 +71,7 @@ export class SearchServicesProvider implements WebSearchProvider {
60
71
  /** 廉价本地检查:脚本存在 + 优先级内至少一个后端有 key;不做网络调用。 */
61
72
  available(): boolean {
62
73
  const cfg = this.current()
63
- if (!existsSync(expandHome(cfg.scriptPath))) return false
74
+ if (!existsSync(resolveScriptPath(cfg.scriptPath))) return false
64
75
  const env = this.childEnv(cfg)
65
76
  return cfg.priority.some((backend) =>
66
77
  BACKEND_KEY_VARS[backend].some((name) => (env[name]?.trim() ?? '') !== ''),
@@ -87,7 +98,7 @@ export class SearchServicesProvider implements WebSearchProvider {
87
98
  try {
88
99
  return await runProcess({
89
100
  command: cfg.python,
90
- args: [expandHome(cfg.scriptPath), ...argv],
101
+ args: [resolveScriptPath(cfg.scriptPath), ...argv],
91
102
  env: this.childEnv(cfg),
92
103
  timeoutMs: cfg.timeoutMs,
93
104
  ...(signal !== undefined ? { signal } : {}),