@dsh-plus/llm-pi 0.1.28 → 0.1.30

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/client.js CHANGED
@@ -72,6 +72,35 @@ window.__ModuleLoader__.load({
72
72
  });
73
73
  }
74
74
  //#endregion
75
+ //#region ../shared/src/client/config-slots.ts
76
+ /** dsh-plus 聚合 bundle 的包名(各插件 row 均经其补丁层插入 profile)。 */
77
+ const DSH_PLUS_BUNDLE = "@dsh-plus/bundle-main";
78
+ /**
79
+ * 把一张配置卡片同时注册进 legacy 与新版三个槽位。
80
+ * 任一槽位在当前 dsh 版本未声明时对应 inject 挂起等待,版本不命中即 no-op。
81
+ */
82
+ function injectPluginConfigCard(slots, reg) {
83
+ const base = {
84
+ locale: reg.ns,
85
+ inject: reg.inject
86
+ };
87
+ slots.inject("settings.plugin.item", () => slots.register({
88
+ name: "settings.plugin.item",
89
+ key: reg.ns,
90
+ ...base
91
+ }, reg.component));
92
+ slots.inject("plugins.row.config", () => slots.register({
93
+ name: "plugins.row.config",
94
+ key: `${DSH_PLUS_BUNDLE}#${reg.rowId}`,
95
+ ...base
96
+ }, reg.component));
97
+ slots.inject("plugins.bundle.config", () => slots.register({
98
+ name: "plugins.bundle.config",
99
+ key: reg.pkg,
100
+ ...base
101
+ }, reg.component));
102
+ }
103
+ //#endregion
75
104
  //#region ../shared/src/client/fields.tsx
76
105
  function TextField$1(props) {
77
106
  const p = props.prefix ?? "dshp";
@@ -371,10 +400,10 @@ ${extra}
371
400
  /**
372
401
  * settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
373
402
  * 服务端直接以字面量注册(0.1.2-alpha.2 起 dsh-settings 对命名空间做编译期
374
- * 语法校验,见 config.ts),浏览器半将其作为 settings.plugin.item keyed 槽位的
375
- * key —— 同一字面量两处共用,防止漂移。
376
- * 契约:该槽位按「卡片编辑的 settings 命名空间」作 key 分发,
377
- * 官方配置页只渲染 key 命中 Host 已注册命名空间的卡片。
403
+ * 语法校验,见 config.ts);浏览器半把它作为配置卡片的注册键
404
+ * (legacy settings.plugin.item keyed 槽位按「卡片编辑的 settings 命名空间」
405
+ * 分发;0.1.6-alpha.2 起改挂插件页 row/bundle config,见 shared/config-slots),
406
+ * 同一字面量两处共用,防止漂移。
378
407
  * @module llm-pi/ns
379
408
  */
380
409
  const SETTINGS_NS = "dsh-plus-llm-pi";
@@ -1725,7 +1754,9 @@ ${extra}
1725
1754
  //#endregion
1726
1755
  //#region src/client/card.tsx
1727
1756
  /**
1728
- * 「LLM 路由」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
1757
+ * 「LLM 路由」配置卡片:经 injectPluginConfigCard 注册(legacy settings.plugin.item
1758
+ * 与 0.1.6-alpha.2 插件页 plugins.row.config / plugins.bundle.config,view 分发
1759
+ * summary/page)。
1729
1760
  * 顶部:enabled / catalogUrl / catalogRefreshHours / 只读状态行(kitSource、
1730
1761
  * modelsDevStatus,来自模型目录端点)+ 保存(settings.update 全量深合并)与
1731
1762
  * 错误/成功提示;下方为 providers 路由列表(新增/删除/字段编辑/compat/模型
@@ -1742,7 +1773,7 @@ ${extra}
1742
1773
  const { t, scope, api } = props;
1743
1774
  const snapshot = (0, react.useSyncExternalStore)((listener) => scope.subscribe(listener), () => scope.getSnapshot());
1744
1775
  const value = snapshot.value;
1745
- const [open, setOpen] = (0, react.useState)(false);
1776
+ const [open, setOpen] = (0, react.useState)(props.view === "page");
1746
1777
  const [draft, setDraft] = (0, react.useState)(null);
1747
1778
  const [epoch, setEpoch] = (0, react.useState)(0);
1748
1779
  const [kitSource, setKitSource] = (0, react.useState)(null);
@@ -1771,6 +1802,7 @@ ${extra}
1771
1802
  if (draft === null) return false;
1772
1803
  return !numTextOk(draft.catalogRefreshHours) || Object.values(draft.providers).some((provider) => provider.models.some((model) => model.id.trim() === ""));
1773
1804
  }, [draft]);
1805
+ if (props.view === "summary") return t("summaryLine");
1774
1806
  if (value === void 0 || draft === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
1775
1807
  className: "lpc-card",
1776
1808
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
@@ -1990,6 +2022,7 @@ ${extra}
1990
2022
  const ownZh = {
1991
2023
  title: "LLM 路由(llm-pi)",
1992
2024
  description: "自定义 LLM 路由:协议、compat、模型目录与 models.dev 目录兜底。",
2025
+ summaryLine: "自定义 LLM 路由:协议、compat、模型目录与 models.dev 目录兜底。",
1993
2026
  enabled: "启用插件",
1994
2027
  catalogUrl: "models.dev 目录数据端点",
1995
2028
  catalogUrlHint: "快照数据源;一般无需修改。",
@@ -2071,6 +2104,7 @@ ${extra}
2071
2104
  const ownEn = {
2072
2105
  title: "LLM routes (llm-pi)",
2073
2106
  description: "Custom LLM routes: protocol, compat, model catalog and models.dev fallback.",
2107
+ summaryLine: "Custom LLM routes: protocol, compat, model catalog and models.dev fallback.",
2074
2108
  enabled: "Enable plugin",
2075
2109
  catalogUrl: "models.dev catalog endpoint",
2076
2110
  catalogUrlHint: "Snapshot data source; usually no change needed.",
@@ -2237,16 +2271,17 @@ ${extra}
2237
2271
  }), "llm-pi: locale");
2238
2272
  const scope = createSettingsScope(c, SETTINGS_NS, "llm-pi: settings scope");
2239
2273
  const api = createNamespaceApi(c.get("remote").settings, SETTINGS_NS);
2240
- c.slots.inject("settings.plugin.item", () => c.slots.register({
2241
- name: "settings.plugin.item",
2242
- key: SETTINGS_NS,
2243
- locale: NS,
2274
+ injectPluginConfigCard(c.slots, {
2275
+ ns: SETTINGS_NS,
2276
+ rowId: "dsh-plus-llm-pi",
2277
+ pkg: "@dsh-plus/llm-pi",
2278
+ component: LlmPiCard,
2244
2279
  inject: () => ({
2245
2280
  t: c.locale.bind(NS),
2246
2281
  scope,
2247
2282
  api
2248
2283
  })
2249
- }, LlmPiCard));
2284
+ });
2250
2285
  }
2251
2286
  //#endregion
2252
2287
  exports.apply = apply;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-plus/llm-pi",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "dsh-plus service+ui plugin: 基于 PiAiAdapter 的自定义 LLM 路由(全量 compat、模型继承、models.dev 目录兜底)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -32,40 +32,40 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "https-proxy-agent": "^9.1.0",
35
- "@dsh-plus/shared": "0.1.17"
35
+ "@dsh-plus/shared": "0.1.19"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@deepseek-ai/cordis": "^4.0.2",
39
- "@deepseek-ai/dsh-anonymous-user-id": "^0.1.5-rc.2",
40
- "@deepseek-ai/dsh-credentials": "^0.1.5-rc.2",
41
- "@deepseek-ai/dsh-home-paths": "^0.1.5-rc.2",
42
- "@deepseek-ai/dsh-host-webserver": "^0.1.5-rc.2",
43
- "@deepseek-ai/dsh-launch-environment": "^0.1.5-rc.2",
44
- "@deepseek-ai/dsh-llm": "^0.1.5-rc.2",
45
- "@deepseek-ai/dsh-llm-deepseek": "^0.1.5-rc.2",
46
- "@deepseek-ai/dsh-llm-pi-ai": "^0.1.5-rc.2",
47
- "@deepseek-ai/dsh-settings": "^0.1.5-rc.2",
48
- "@deepseek-ai/dsh-util-values": "^0.1.5-rc.2",
39
+ "@deepseek-ai/dsh-anonymous-user-id": "^0.1.6-alpha.2",
40
+ "@deepseek-ai/dsh-credentials": "^0.1.6-alpha.2",
41
+ "@deepseek-ai/dsh-home-paths": "^0.1.6-alpha.2",
42
+ "@deepseek-ai/dsh-host-webserver": "^0.1.6-alpha.2",
43
+ "@deepseek-ai/dsh-launch-environment": "^0.1.6-alpha.2",
44
+ "@deepseek-ai/dsh-llm": "^0.1.6-alpha.2",
45
+ "@deepseek-ai/dsh-llm-deepseek": "^0.1.6-alpha.2",
46
+ "@deepseek-ai/dsh-llm-pi-ai": "^0.1.6-alpha.2",
47
+ "@deepseek-ai/dsh-settings": "^0.1.6-alpha.2",
48
+ "@deepseek-ai/dsh-util-values": "^0.1.6-alpha.2",
49
49
  "@deepseek-ai/schemastery": "^3.18.2",
50
50
  "@earendil-works/pi-ai": "^0.85.1"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@deepseek-ai/cordis": "4.0.2",
54
- "@deepseek-ai/dsh-anonymous-user-id": "0.1.5-rc.2",
55
- "@deepseek-ai/dsh-atomic-write": "0.1.5-rc.2",
56
- "@deepseek-ai/dsh-attachment": "0.1.5-rc.2",
57
- "@deepseek-ai/dsh-credentials": "0.1.5-rc.2",
58
- "@deepseek-ai/dsh-home-paths": "0.1.5-rc.2",
59
- "@deepseek-ai/dsh-host-webserver": "0.1.5-rc.2",
60
- "@deepseek-ai/dsh-launch-environment": "0.1.5-rc.2",
61
- "@deepseek-ai/dsh-llm": "0.1.5-rc.2",
62
- "@deepseek-ai/dsh-llm-deepseek": "0.1.5-rc.2",
63
- "@deepseek-ai/dsh-llm-pi-ai": "0.1.5-rc.2",
64
- "@deepseek-ai/dsh-settings": "0.1.5-rc.2",
65
- "@deepseek-ai/dsh-timeout": "0.1.5-rc.2",
66
- "@deepseek-ai/dsh-typert-protocol": "0.1.5-rc.2",
67
- "@deepseek-ai/dsh-util-crypto": "0.1.5-rc.2",
68
- "@deepseek-ai/dsh-util-values": "0.1.5-rc.2",
54
+ "@deepseek-ai/dsh-anonymous-user-id": "0.1.6-alpha.2",
55
+ "@deepseek-ai/dsh-atomic-write": "0.1.6-alpha.2",
56
+ "@deepseek-ai/dsh-attachment": "0.1.6-alpha.2",
57
+ "@deepseek-ai/dsh-credentials": "0.1.6-alpha.2",
58
+ "@deepseek-ai/dsh-home-paths": "0.1.6-alpha.2",
59
+ "@deepseek-ai/dsh-host-webserver": "0.1.6-alpha.2",
60
+ "@deepseek-ai/dsh-launch-environment": "0.1.6-alpha.2",
61
+ "@deepseek-ai/dsh-llm": "0.1.6-alpha.2",
62
+ "@deepseek-ai/dsh-llm-deepseek": "0.1.6-alpha.2",
63
+ "@deepseek-ai/dsh-llm-pi-ai": "0.1.6-alpha.2",
64
+ "@deepseek-ai/dsh-settings": "0.1.6-alpha.2",
65
+ "@deepseek-ai/dsh-timeout": "0.1.6-alpha.2",
66
+ "@deepseek-ai/dsh-typert-protocol": "0.1.6-alpha.2",
67
+ "@deepseek-ai/dsh-util-crypto": "0.1.6-alpha.2",
68
+ "@deepseek-ai/dsh-util-values": "0.1.6-alpha.2",
69
69
  "@deepseek-ai/schemastery": "3.18.2",
70
70
  "@earendil-works/pi-ai": "0.85.1",
71
71
  "@types/react": "~18.3.31",
@@ -1,5 +1,7 @@
1
1
  /**
2
- * 「LLM 路由」配置卡片:注册进 settings.plugin.item 插槽(官方插件配置页)。
2
+ * 「LLM 路由」配置卡片:经 injectPluginConfigCard 注册(legacy settings.plugin.item
3
+ * 与 0.1.6-alpha.2 插件页 plugins.row.config / plugins.bundle.config,view 分发
4
+ * summary/page)。
3
5
  * 顶部:enabled / catalogUrl / catalogRefreshHours / 只读状态行(kitSource、
4
6
  * modelsDevStatus,来自模型目录端点)+ 保存(settings.update 全量深合并)与
5
7
  * 错误/成功提示;下方为 providers 路由列表(新增/删除/字段编辑/compat/模型
@@ -13,6 +15,7 @@ import {
13
15
  CheckRow,
14
16
  IDLE_STATUS,
15
17
  type NamespaceSettingsApi,
18
+ type PluginConfigViewProps,
16
19
  type Scope,
17
20
  TextField,
18
21
  } from '@dsh-plus/shared/client'
@@ -30,7 +33,7 @@ import {
30
33
  import type { Translate } from './i18n.ts'
31
34
  import { ProvidersSection } from './views/providers.tsx'
32
35
 
33
- export interface CardProps {
36
+ export interface CardProps extends PluginConfigViewProps {
34
37
  t: Translate
35
38
  scope: Scope
36
39
  api: NamespaceSettingsApi
@@ -43,14 +46,15 @@ function modelsDevText(status: WireModelsDevStatus | null, t: Translate): string
43
46
  return `${t('modelsDevStatusLine')}:${status.providers} 个 provider,快照 ${status.fetchedAt}`
44
47
  }
45
48
 
46
- export function LlmPiCard(props: CardProps): ReactElement | null {
49
+ export function LlmPiCard(props: CardProps): ReactElement | string | null {
47
50
  const { t, scope, api } = props
48
51
  const snapshot = useSyncExternalStore(
49
52
  (listener: () => void) => scope.subscribe(listener),
50
53
  () => scope.getSnapshot(),
51
54
  )
52
55
  const value = snapshot.value as ConfigValue | undefined
53
- const [open, setOpen] = useState(false)
56
+ // 0.1.6-alpha.2 插件页 page 视图为表单落地页,默认展开;旧槽位无 view,保持折叠。
57
+ const [open, setOpen] = useState(props.view === 'page')
54
58
  const [draft, setDraft] = useState<Draft | null>(null)
55
59
  const [epoch, setEpoch] = useState(0)
56
60
  const [kitSource, setKitSource] = useState<string | null>(null)
@@ -99,6 +103,9 @@ export function LlmPiCard(props: CardProps): ReactElement | null {
99
103
  )
100
104
  }, [draft])
101
105
 
106
+ // 插件页 summary 视图只出一行简介(hooks 已全部落定,可安全提前返回)。
107
+ if (props.view === 'summary') return t('summaryLine')
108
+
102
109
  if (value === undefined || draft === null) {
103
110
  return (
104
111
  <li className="lpc-card">
@@ -1,23 +1,24 @@
1
1
  /**
2
- * 浏览器半入口:注册 locale 字典 + 向 settings.plugin.item 插槽注册「LLM 路由」卡片。
2
+ * 浏览器半入口:注册 locale 字典 + 注册「LLM 路由」卡片
3
+ * (injectPluginConfigCard 三槽位:legacy settings.plugin.item 与 0.1.6-alpha.2
4
+ * 独立插件页的 plugins.row.config / plugins.bundle.config)。
3
5
  * 构建产物为 window.__ModuleLoader__.load({id, factory}) 形式的 CJS factory
4
6
  * (包装见 tsdown.config.ts);样式沿用官方 data-plugin-css 约定,HMR 据此卸载。
5
7
  *
6
8
  * 类型说明:浏览器半只用到 slots/locale/remote 的很窄一面,
7
9
  * scope 与基础控件走 @dsh-plus/shared/client 套件(收编自本插件原实现)。
8
- * 该插槽为 keyed 槽位:key 必须是卡片编辑的 settings 命名空间
9
- * (即服务端注册的同一字面量,见 ../ns.ts),
10
- * 官方配置页按此 key 与 Host 已注册命名空间配对分发。
11
10
  * 配置读写经 ctx.remote.settings 直连(0.1.2-alpha.1 起 connection.api.settings
12
11
  * 已移除;不复用 settingsScope 服务——非 loopback 页面下它固定 memory 模式无数据,
13
12
  * 见 @dsh-plus/shared/client scope.ts);自定义端点仅剩「模型目录」
14
13
  * (api.ts,含 kitSource/models-dev 运行期诊断)。
14
+ * 卡片 key/rowId 约定见 @dsh-plus/shared/client/config-slots。
15
15
  * @module @dsh-plus/llm-pi/client
16
16
  */
17
17
  import type { Context } from '@deepseek-ai/cordis'
18
18
  import {
19
19
  createNamespaceApi,
20
20
  createSettingsScope,
21
+ injectPluginConfigCard,
21
22
  type PluginClientContext,
22
23
  } from '@dsh-plus/shared/client'
23
24
  import { SETTINGS_NS } from '../ns.ts'
@@ -45,15 +46,11 @@ export function apply(ctx: Context): void {
45
46
  c.effect(() => c.locale.register(NS, { zh, en }), 'llm-pi: locale')
46
47
  const scope = createSettingsScope(c, SETTINGS_NS, 'llm-pi: settings scope')
47
48
  const api = createNamespaceApi(c.get('remote').settings, SETTINGS_NS)
48
- c.slots.inject('settings.plugin.item', () =>
49
- c.slots.register(
50
- {
51
- name: 'settings.plugin.item',
52
- key: SETTINGS_NS,
53
- locale: NS,
54
- inject: () => ({ t: c.locale.bind(NS), scope, api }),
55
- },
56
- LlmPiCard,
57
- ),
58
- )
49
+ injectPluginConfigCard(c.slots, {
50
+ ns: SETTINGS_NS,
51
+ rowId: 'dsh-plus-llm-pi',
52
+ pkg: '@dsh-plus/llm-pi',
53
+ component: LlmPiCard,
54
+ inject: () => ({ t: c.locale.bind(NS), scope, api }),
55
+ })
59
56
  }
@@ -10,6 +10,7 @@ export const NS = 'dsh-plus-llm-pi'
10
10
  const ownZh = {
11
11
  title: 'LLM 路由(llm-pi)',
12
12
  description: '自定义 LLM 路由:协议、compat、模型目录与 models.dev 目录兜底。',
13
+ summaryLine: '自定义 LLM 路由:协议、compat、模型目录与 models.dev 目录兜底。',
13
14
  enabled: '启用插件',
14
15
  catalogUrl: 'models.dev 目录数据端点',
15
16
  catalogUrlHint: '快照数据源;一般无需修改。',
@@ -92,6 +93,7 @@ const ownZh = {
92
93
  const ownEn = {
93
94
  title: 'LLM routes (llm-pi)',
94
95
  description: 'Custom LLM routes: protocol, compat, model catalog and models.dev fallback.',
96
+ summaryLine: 'Custom LLM routes: protocol, compat, model catalog and models.dev fallback.',
95
97
  enabled: 'Enable plugin',
96
98
  catalogUrl: 'models.dev catalog endpoint',
97
99
  catalogUrlHint: 'Snapshot data source; usually no change needed.',
package/src/ns.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * settings 命名空间字面量(纯常量,零依赖,浏览器半可安全引入)。
3
3
  * 服务端直接以字面量注册(0.1.2-alpha.2 起 dsh-settings 对命名空间做编译期
4
- * 语法校验,见 config.ts),浏览器半将其作为 settings.plugin.item keyed 槽位的
5
- * key —— 同一字面量两处共用,防止漂移。
6
- * 契约:该槽位按「卡片编辑的 settings 命名空间」作 key 分发,
7
- * 官方配置页只渲染 key 命中 Host 已注册命名空间的卡片。
4
+ * 语法校验,见 config.ts);浏览器半把它作为配置卡片的注册键
5
+ * (legacy settings.plugin.item keyed 槽位按「卡片编辑的 settings 命名空间」
6
+ * 分发;0.1.6-alpha.2 起改挂插件页 row/bundle config,见 shared/config-slots),
7
+ * 同一字面量两处共用,防止漂移。
8
8
  * @module llm-pi/ns
9
9
  */
10
10
  export const SETTINGS_NS = 'dsh-plus-llm-pi'