@dsh-plus/llm-pi 0.1.10 → 0.1.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.
package/lib/index.js CHANGED
@@ -276,6 +276,12 @@ function fetchJson(url, proxy, timeoutMs) {
276
276
  }, (response) => {
277
277
  const chunks = [];
278
278
  let size = 0;
279
+ let settled = false;
280
+ const fail = (error) => {
281
+ if (settled) return;
282
+ settled = true;
283
+ reject(error);
284
+ };
279
285
  response.on("data", (chunk) => {
280
286
  size += chunk.length;
281
287
  if (size > MAX_RESPONSE_BYTES$1) {
@@ -285,11 +291,14 @@ function fetchJson(url, proxy, timeoutMs) {
285
291
  chunks.push(chunk);
286
292
  });
287
293
  response.on("end", () => {
294
+ if (settled) return;
295
+ settled = true;
288
296
  resolve({
289
297
  status: response.statusCode ?? 0,
290
298
  body: Buffer.concat(chunks).toString("utf8")
291
299
  });
292
300
  });
301
+ response.on("error", fail);
293
302
  });
294
303
  req.on("timeout", () => req.destroy(/* @__PURE__ */ new Error(`请求超时(${timeoutMs}ms)`)));
295
304
  req.on("error", reject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plus/llm-pi",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "dsh-plus service+ui plugin: 基于 PiAiAdapter 的自定义 LLM 路由(全量 compat、模型继承、models.dev 目录兜底)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -82,6 +82,12 @@ function fetchJson(url: string, proxy: string, timeoutMs: number): Promise<JsonR
82
82
  (response) => {
83
83
  const chunks: Buffer[] = []
84
84
  let size = 0
85
+ let settled = false
86
+ const fail = (error: Error): void => {
87
+ if (settled) return
88
+ settled = true
89
+ reject(error)
90
+ }
85
91
  response.on('data', (chunk: Buffer) => {
86
92
  size += chunk.length
87
93
  if (size > MAX_RESPONSE_BYTES) {
@@ -91,11 +97,16 @@ function fetchJson(url: string, proxy: string, timeoutMs: number): Promise<JsonR
91
97
  chunks.push(chunk)
92
98
  })
93
99
  response.on('end', () => {
100
+ if (settled) return
101
+ settled = true
94
102
  resolve({
95
103
  status: response.statusCode ?? 0,
96
104
  body: Buffer.concat(chunks).toString('utf8'),
97
105
  })
98
106
  })
107
+ // 响应流自身出错(中途截断的 aborted 等)不经请求转发:缺此监听时
108
+ // Promise 永不 settle(req timeout 只覆盖建连/空闲等待),refresh 永久挂起。
109
+ response.on('error', fail)
99
110
  },
100
111
  )
101
112
  req.on('timeout', () => req.destroy(new Error(`请求超时(${timeoutMs}ms)`)))
@@ -21,7 +21,7 @@ import type { Context } from '@deepseek-ai/cordis'
21
21
  import { SETTINGS_NS } from '../ns.ts'
22
22
  import { LlmPiCard } from './card.tsx'
23
23
  import { en, NS, zh } from './i18n.ts'
24
- import type { Scope, SettingsApi } from './scope.ts'
24
+ import type { Scope, ScopeSnapshot, SettingsApi } from './scope.ts'
25
25
  import { injectStyle } from './styles.ts'
26
26
 
27
27
  export const name = 'dsh-plus-llm-pi'
@@ -35,8 +35,11 @@ export interface SettingsApi {
35
35
  result: {
36
36
  ok: boolean
37
37
  value?: {
38
+ writable: boolean
38
39
  namespaces: Array<{
39
40
  ns: string
41
+ value: unknown
42
+ revision: number
40
43
  secrets: Array<{ path: string[]; set: boolean }>
41
44
  }>
42
45
  }