@ou6235/dsh-modelpicker 0.0.0-stage → 1.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-modelpicker contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,201 @@
1
- # Temporary Holding Version
1
+ # dsh-modelpicker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ DeepSeek Harness(DSH)Web 界面的增强版模型选择器。顶替 composer 工具行里那颗内置的模型按钮,把单列长滚动列表换成**左侧提供商栏 + 右侧模型列表**的双栏面板,两侧独立滚动,并支持跨提供商搜索。
4
+
5
+ A drop-in replacement for the composer's model seat in the DeepSeek Harness web GUI: the single long scrolling list becomes a **provider rail plus an independently scrolling model list**, with cross-provider search on top.
6
+
7
+ ---
8
+
9
+ ## 它解决什么 What it solves
10
+
11
+ 内置选择器把所有模型压在一列里,提供商一多就要滚很久,找一个模型得先记住它属于哪家。本插件:
12
+
13
+ - 左栏列出全部提供商(带模型数量徽章),点击即切换右栏
14
+ - 右栏只显示当前提供商的模型,两栏各自滚动,互不影响
15
+ - 顶部搜索框跨提供商匹配「提供商名 / 模型名 / 描述」,命中项带提供商名,点选即切换
16
+ - 下拉面板 **portal 到 `<body>`** 并按实测尺寸定位,窗口再小也不会被裁掉或跑出屏幕
17
+
18
+ The stock picker flattens every model into one column: with many providers you scroll a lot and must remember which provider a model belongs to. This panel puts a provider rail beside the model list, keeps the two scrolls independent, adds cross-provider search, and portals the popup out of the composer so small windows cannot clip it.
19
+
20
+ ---
21
+
22
+ ## 功能 Features
23
+
24
+ - **双栏布局**:左栏提供商(独立滚动、数量徽章),右栏当前提供商的模型(独立滚动)
25
+ - **默认选中**当前模型所属的提供商;点击任意提供商即切换
26
+ - **跨提供商搜索**:大小写不敏感,匹配提供商名、模型名与描述;结果行标注来源提供商;清空后回到原列表
27
+ - **推理档位**:当前模型支持时,菜单底部出现档位按钮(含「提供方默认」),点击即生效
28
+ - **完整状态**:加载中、加载失败(带重试)、单个提供商加载失败告警、空列表提示
29
+ - **小窗口自适应**:面板宽度 `min(560px, 100vw − 16px)`、高度 `min(460px, 100vh − 16px, 该侧可用空间)`;上方放不下就翻到下方;两侧都不够时整块夹在窗口内并内部滚动
30
+ - **跟随变化重排**:窗口 resize、任意祖先滚动、触发按钮自身尺寸变化都会重新定位
31
+ - **主题跟随**:沿用 DSH 的 `--dsw-*` 设计令牌,深浅色自动适配
32
+ - **中英文文案**:按浏览器语言自动切换
33
+
34
+ ---
35
+
36
+ ## 安装 Install
37
+
38
+ 插件是标准的 DSH profile bundle,通过 `dsh plugin add` 装入当前 profile:
39
+
40
+ ```sh
41
+ # 方式一:从 npm registry 安装(推荐,无 git 克隆步骤)
42
+ dsh plugin --profile desktop add @ou6235/dsh-modelpicker
43
+
44
+ # 方式二:从 git 源安装
45
+ dsh plugin --profile desktop add github:ou6235/dsh-modelpicker
46
+
47
+ # 方式三:从本地克隆安装(把 <路径> 换成仓库实际所在目录)
48
+ dsh plugin --profile desktop add link:<路径>
49
+ ```
50
+
51
+ > 仓库名 `dsh-modelpicker` 与 npm 包名 `@ou6235/dsh-modelpicker` 指向同一个插件:DSH 以 `package.json` 的 `name` 作为插件身份。
52
+ >
53
+ > **关于包名**:npm 上无 scope 的 `dsh-modelpicker` 因与已存在的 `dsh-model-picker`(另一个包)过于相似而被 npm 名称策略拒绝,故发布于 scope 下。安装时请使用带 scope 的完整名称。
54
+
55
+ 装入后**刷新页面即可生效**,不需要重启 DSH。插件在 `cordis.patch.yml` 里插入一行:
56
+
57
+ ```yaml
58
+ - insert:
59
+ - id: dsh-modelpicker
60
+ name: 'dsh-modelpicker'
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 使用 Usage
66
+
67
+ 点开 composer 工具行右端(发送按钮左侧)的模型按钮:
68
+
69
+ | 操作 | 结果 |
70
+ |---|---|
71
+ | 点击左栏提供商 | 右栏切换到该提供商的模型 |
72
+ | 点击右栏模型 | 选中并关闭面板(当前项带 ✓) |
73
+ | 在搜索框输入 | 右栏变为跨提供商搜索结果 |
74
+ | 点击左栏任意提供商 | 退出搜索,回到该提供商的完整列表 |
75
+ | 点击底部档位按钮 | 切换推理档位(仅当前模型支持时显示) |
76
+ | `Esc` / 点击面板外 | 关闭面板 |
77
+
78
+ ---
79
+
80
+ ## 实现原理 How it works
81
+
82
+ ### 双半结构 Two halves
83
+
84
+ - **Client 半**(`lib/client.js`):通过 `exports["./client"]` + `dsh.client.platform = "web"` 被前端加载,注册到插槽 `conversation.input.model`,`priority: -1` 顶替内置实现
85
+ - **Host 半**(`lib/host.js`):空实现。Node 侧 loader 以包根入口导入它,因此必须 Node 安全(模块顶层不碰 `window` / `document`);浏览器专属代码只经 `./client` 导出,不会被 Node 端加载
86
+
87
+ ### 数据来源 Data source
88
+
89
+ 复用内置 `ui-model-selection` 的**每会话模型目录**(`ctx.modelDirectories`),不引入第二份状态:
90
+
91
+ ```js
92
+ const directory = models.directoryFor(sessionId)
93
+ // directory.store —— 当前选择 / 提供商分组 / 加载状态的快照存储
94
+ // directory.load() —— 拉起模型目录
95
+ // directory.select(...) —— 提交 provider + model + reasoningEffort
96
+ ```
97
+
98
+ 因此在内置 `/model` 弹层里切换、或在本面板里切换,另一处立即同步。
99
+
100
+ ### 注册时序 Registration
101
+
102
+ 两个前置条件都必须满足,否则座位要么注册不上、要么渲染即崩:
103
+
104
+ 1. **`conversation.input.model` 必须已被声明**。它由 `ui-conversation` 声明,晚于本插件 boot;未声明时 `register()` 抛 `slot "..." is not declared`。因此注册包在:
105
+
106
+ ```js
107
+ scope.slots.inject('conversation.input.model', () => scope.slots.register({ ... }))
108
+ ```
109
+
110
+ 该门回调可能因声明世代变化而重跑,所以每次回调只持有一个注册,并在返回的 disposer 中释放,避免重复入表。
111
+
112
+ 2. **模块级 `inject` 必须声明 `slots`、`sessions`、`remote`、`remote.session`**。`directoryFor()` 会通过**调用方**的 fiber 解析 `ctx.remote.session`,少声明一个就会在渲染期抛 `cannot get property "remote.session" without inject`,座位崩溃并静默回落到内置选择器。`modelDirectories` 则由运行时 `ctx.inject` 解析,因为它可能随 `ui-model-selection` 缺席——缺席时本插件不注册座位,内置选择器保持可用。
113
+
114
+ ### 子插槽:刻意不声明 Child slot: deliberately not declared
115
+
116
+ `conversation.input.model.options` 这个子插槽**全局只允许一个声明者**,内置 `ui-model-selection` 已占用。若本插件也列出同名 `children`,`SlotCore.register` 会抛:
117
+
118
+ ```
119
+ slot "conversation.input.model.options" is already declared (by ...)
120
+ ```
121
+
122
+ 且抛错发生在**条目入表之前**——后果是连锁的:
123
+
124
+ 1. 先注册方正常渲染,后注册方被拒;
125
+ 2. 卸载插件时 `releaseChildren` 释放子插槽声明,但内置座位**不会重跑注册**;
126
+ 3. composer 里两个座位都没有,必须刷新页面才能恢复。
127
+
128
+ 因此本插件**不声明任何子插槽**。代价是:内置的「启用智能体团队协作」开关仍留在内置 `/model` 面板里,不会出现在本面板底部。这是该冲突的唯一安全解——子插槽只能有一个声明者,而内置座位持有它。
129
+
130
+ ### 浮层与层级 Overlay and stacking
131
+
132
+ - 面板用 `createPortal` 挂到 `<body>`,composer 的 `overflow:auto` 滚动容器与 `overflow:hidden` 中栏都无法裁切它(`react-dom` 缺席时回退内联渲染,不会让座位崩掉)
133
+ - 定位为 `position: fixed`,坐标由 `getBoundingClientRect()` 实测得出(见 `measureLayout()`)
134
+ - `z-index: 1099`,**必须低于** primitives 浮层 tooltip 层(`._bubble_*[data-portal]{z-index:1100}`),否则宿主在面板内弹出的 tooltip 会被卡片盖住
135
+ - 未用 `scrollIntoView` 定位已选行,而是直接调整列表 `scrollTop`——fixed 卡片下前者可能连带滚动文档,把 composer 顶出视口
136
+
137
+ ---
138
+
139
+ ## 布局参数 Layout constants
140
+
141
+ | 常量 | 值 | 含义 |
142
+ |---|---|---|
143
+ | `EDGE` | 8px | 面板与窗口边缘的最小间距 |
144
+ | `GAP` | 8px | 面板与触发按钮的间距 |
145
+ | `PREFERRED_WIDTH` | 560px | 首选宽度上限 |
146
+ | `PREFERRED_HEIGHT` | 460px | 首选高度上限 |
147
+ | `MIN_HEIGHT` | 180px | 可用空间不足时的最小高度 |
148
+ | `WIDE_RAIL` | 150px | 宽面板下的左栏宽度 |
149
+ | `NARROW_RAIL` | 96px | 窄面板下的左栏宽度(此时隐藏数量徽章) |
150
+
151
+ 窄于 `PREFERRED_WIDTH` 时左栏自动收窄,把空间让给模型列表。
152
+
153
+ ---
154
+
155
+ ## 要求与限制 Requirements
156
+
157
+ - 需要 web profile 已装载 `@deepseek-ai/dsh-client-ui-model-selection`(web-app 内置,通常已存在);缺席时本插件不注册座位,内置选择器保持可用
158
+ - 仅影响 composer 的模型选择座位;内置 `/model` 弹层保持原样,但两者共享同一份当前选择
159
+ - 启用 / 禁用后**刷新页面**即可互换座位,无需重启 DSH
160
+ - 子插槽 `conversation.input.model.options` 不由本插件声明,因此面板底部没有第三方贡献的会话选项行(详见上节)
161
+
162
+ ---
163
+
164
+ ## 开发 Development
165
+
166
+ ```sh
167
+ # 跑测试(零依赖,纯 Node)
168
+ node --test tests/*.test.mjs
169
+ ```
170
+
171
+ 测试覆盖:
172
+
173
+ - 模块形状、`priority: -1` 座位注册、注入面(face)字段
174
+ - 座位**不声明**任何子插槽;即便插槽看似空闲也不去占
175
+ - 注册门回调重跑三次既不叠加也不泄漏注册
176
+ - 小窗口下 rendered tree 结构、portal 到 `document.body`
177
+ - `.dsh-mp-menu` 的 `z-index` 必须落在 `[100, 1100)`
178
+ - `modelDirectories` / `sessions` 缺席时的回退路径
179
+ - `directoryFor()` 抛错时必须把异常抛出去,便于宿主回退内置座位
180
+
181
+ ### 目录结构
182
+
183
+ ```
184
+ dsh-modelpicker/ # 仓库名
185
+ ├── package.json # bundle 清单:main / exports / dsh.bundle / dsh.client(name 为 dsh-modelpicker)
186
+ ├── cordis.patch.yml # 插入一行 plugin entry
187
+ ├── lib/
188
+ │ ├── host.js # Node 端空实现(必须 Node 安全)
189
+ │ └── client.js # 浏览器端全部逻辑:组件、CSS、注册
190
+ ├── tests/
191
+ │ ├── client.test.mjs # 假 __ModuleLoader__ + react stub 的冒烟与回归
192
+ │ └── host.test.mjs # Node 端模块形状
193
+ ├── LICENSE
194
+ └── README.md
195
+ ```
196
+
197
+ ---
198
+
199
+ ## License
200
+
201
+ MIT
@@ -0,0 +1,10 @@
1
+ # @ou6235/dsh-modelpicker bundle patch: mounts the enhanced model picker over
2
+ # the composer's model seat in the dsh web GUI.
3
+ #
4
+ # `name` must be the EXACT npm package name — the loader resolves this specifier
5
+ # from the profile's node_modules, so a scoped package needs its scope here even
6
+ # though `id` is an arbitrary local row label.
7
+
8
+ - insert:
9
+ - id: dsh-modelpicker
10
+ name: '@ou6235/dsh-modelpicker'
package/lib/client.js ADDED
@@ -0,0 +1,682 @@
1
+ // Browser half of @ou6235/dsh-modelpicker. Loaded through the web plugin loader
2
+ // (window.__ModuleLoader__); React comes from the platform module table.
3
+ // Replaces the shipped composer model seat (conversation.input.model) with a
4
+ // left provider column / right model list layout — both independently
5
+ // scrollable — plus a cross-provider search box. Data rides the SAME
6
+ // per-session ModelDirectory as the /model popup (ctx.modelDirectories), so
7
+ // a switch made in either surface is what the other shows next.
8
+ window.__ModuleLoader__.load({ id: '@ou6235/dsh-modelpicker', factory: (require) => {
9
+ var module = { exports: {} }; var exports = module.exports;
10
+
11
+ const React = require('react')
12
+ const { useState, useEffect, useLayoutEffect, useRef, useMemo, useSyncExternalStore, Fragment } = React
13
+ const h = React.createElement
14
+
15
+ // The menu is portaled to <body> so the composer's own overflow (the scroll
16
+ // body and the hidden center column) cannot crop it. createPortal ships in
17
+ // the platform's react-dom entry; if that entry is ever missing the menu
18
+ // falls back to inline rendering instead of failing the whole seat.
19
+ let createPortal = null
20
+ try {
21
+ const reactDom = require('react-dom')
22
+ if (reactDom !== null && typeof reactDom.createPortal === 'function') createPortal = reactDom.createPortal
23
+ } catch (error) { createPortal = null }
24
+
25
+ let LOCALE = 'en'
26
+ try {
27
+ const nl = String(navigator.language || navigator.userLanguage || '')
28
+ if (nl.toLowerCase().startsWith('zh')) LOCALE = 'zh'
29
+ } catch (e) {}
30
+
31
+ const STR = {
32
+ zh: {
33
+ triggerFallback: '选择模型', search: '搜索模型或提供商', loading: '加载中…', retry: '重试',
34
+ noModels: '暂无可用模型', providerEmpty: '该提供商暂无模型', noMatch: '没有匹配的模型',
35
+ effort: '推理档位', providerDefault: '提供方默认', selectFailed: '选择失败,请重试',
36
+ selectFailedMsg: '选择失败:', providers: '提供商',
37
+ },
38
+ en: {
39
+ triggerFallback: 'Select model', search: 'Search model or provider', loading: 'Loading…', retry: 'Retry',
40
+ noModels: 'No models available', providerEmpty: 'No models for this provider', noMatch: 'No matching models',
41
+ effort: 'Reasoning', providerDefault: 'Provider default', selectFailed: 'Selection failed, retry',
42
+ selectFailedMsg: 'Selection failed: ', providers: 'Providers',
43
+ },
44
+ }
45
+ const t = (key) => STR[LOCALE][key] ?? STR.en[key]
46
+
47
+ // Module-level fallback snapshot. useSyncExternalStore compares snapshots by
48
+ // identity, so building this literal inside the component makes an
49
+ // unavailable seat re-render forever instead of settling.
50
+ const EMPTY_STATE = { current: null, routable: null, groups: [], failures: [], status: 'idle', pending: null, error: null }
51
+
52
+ // Layout constants shared by measure() and the CSS fallback. GAP keeps the
53
+ // card clear of the trigger; EDGE keeps it off the window frame; the height
54
+ // window is what a 720p-class window can show without clipping.
55
+ const GAP = 8
56
+ const EDGE = 8
57
+ const MIN_HEIGHT = 180
58
+ const PREFERRED_HEIGHT = 460
59
+ const PREFERRED_WIDTH = 560
60
+ const NARROW_RAIL = 96
61
+ const WIDE_RAIL = 150
62
+ // Below this width the provider rail gives its space back to the model list.
63
+ const RAIL_BREAKPOINT = PREFERRED_WIDTH
64
+
65
+ // First-paint stand-in used until the layout effect measures the trigger.
66
+ const DEFAULT_LAYOUT = { left: EDGE, width: PREFERRED_WIDTH, maxHeight: 360, up: true, rail: WIDE_RAIL, top: EDGE }
67
+
68
+ const CSS = `
69
+ .dsh-mp-root{position:relative;min-width:0}
70
+ .dsh-mp-trigger{display:flex;align-items:center;gap:4px;min-width:0;max-width:220px;height:28px;padding:0 4px 0 8px;border:none;border-radius:24px;outline:none;background:transparent;color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px;font-weight:500;cursor:pointer}
71
+ .dsh-mp-trigger:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover)}
72
+ .dsh-mp-trigger:focus-visible{box-shadow:0 0 0 2px var(--dsw-alias-border-l3)}
73
+ .dsh-mp-trigger:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}
74
+ .dsh-mp-triggerLabel{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
75
+ .dsh-mp-triggerEffort{flex:0 0 auto;color:var(--dsw-alias-label-caption)}
76
+ .dsh-mp-chevron{flex:0 0 auto;color:var(--dsw-alias-label-caption);font-size:10px;transition:transform 120ms ease}
77
+ .dsh-mp-chevronOpen{transform:rotate(180deg)}
78
+ /* Portaled card: fixed so no scrolling ancestor can crop it, and sized by the
79
+ inline layout the component measures against the trigger and viewport.
80
+ z-index stays BELOW the primitives tooltip layer (1100 for a portaled
81
+ Tooltip bubble): the contributed session options use a Tooltip, and the
82
+ bubble is portaled to <body> at a fixed z-index we cannot raise, so a card
83
+ above it would paint the tooltip behind the menu — it would exist, be
84
+ visible in the DOM, and still be unreadable. 1099 keeps the card above page
85
+ content while letting every tooltip it hosts land on top deterministically,
86
+ without relying on same-z-index paint order. */
87
+ .dsh-mp-menu{position:fixed;z-index:1099;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;padding:4px;border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background-color:var(--dsw-alias-bg-layer-2);background-image:linear-gradient(var(--dsw-specific-menu),var(--dsw-specific-menu));box-shadow:var(--dsw-shadow-lv3);color:var(--dsw-alias-label-primary);overscroll-behavior:contain}
88
+ .dsh-mp-search{flex:0 0 auto;margin:2px 2px 6px;padding:6px 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;outline:none;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font-size:13px;line-height:20px}
89
+ .dsh-mp-search::placeholder{color:var(--dsw-alias-label-tertiary)}
90
+ .dsh-mp-search:focus{border-color:var(--dsw-alias-brand-primary)}
91
+ .dsh-mp-body{display:flex;flex:1;min-height:0;gap:4px}
92
+ .dsh-mp-providers{flex:0 0 var(--dsh-mp-rail,150px);min-width:0;min-height:0;overflow-y:auto;overscroll-behavior:contain;display:flex;flex-direction:column;gap:2px;padding:2px}
93
+ .dsh-mp-provider{display:flex;align-items:center;gap:6px;width:100%;min-height:30px;padding:0 8px;border:none;border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;text-align:left;cursor:pointer}
94
+ .dsh-mp-provider:hover{background:var(--dsw-alias-interactive-bg-hover)}
95
+ .dsh-mp-providerActive{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 14%,transparent);color:var(--dsw-alias-brand-primary);font-weight:600}
96
+ .dsh-mp-providerName{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
97
+ .dsh-mp-providerCount{flex:0 0 auto;padding:0 6px;border-radius:8px;background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
98
+ .dsh-mp-menu[data-narrow="true"] .dsh-mp-providerCount{display:none}
99
+ .dsh-mp-menu[data-narrow="true"] .dsh-mp-provider{padding:0 8px}
100
+ .dsh-mp-list{flex:1;min-width:0;min-height:0;overflow-y:auto;overscroll-behavior:contain;border-left:1px solid var(--dsw-alias-border-l1);padding:2px 0 2px 2px}
101
+ .dsh-mp-status,.dsh-mp-empty{padding:10px;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:20px}
102
+ .dsh-mp-error,.dsh-mp-warning{display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin:4px 2px;padding:7px 8px;border-radius:8px;background:var(--dsw-alias-interactive-bg-hover-danger);color:var(--dsw-alias-state-error-primary);font-size:12px;line-height:18px}
103
+ .dsh-mp-warning{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-state-warn-label)}
104
+ .dsh-mp-retry{flex:0 0 auto;padding:0;border:none;background:transparent;color:inherit;font:inherit;font-weight:600;cursor:pointer}
105
+ .dsh-mp-option{display:flex;align-items:center;gap:8px;width:100%;min-height:38px;padding:6px 8px;border:none;border-radius:10px;outline:none;background:transparent;color:inherit;text-align:left;cursor:pointer}
106
+ .dsh-mp-option:hover:not(:disabled),.dsh-mp-option:focus-visible{background:var(--dsw-alias-interactive-bg-hover)}
107
+ .dsh-mp-option:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}
108
+ .dsh-mp-optionCopy{display:flex;flex:1;flex-direction:column;min-width:0}
109
+ .dsh-mp-selected{background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}
110
+ .dsh-mp-modelName{overflow:hidden;color:inherit;font-size:14px;line-height:20px;font-weight:500;text-overflow:ellipsis;white-space:nowrap}
111
+ .dsh-mp-description{overflow:hidden;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;text-overflow:ellipsis;white-space:nowrap}
112
+ .dsh-mp-check{flex:0 0 18px;color:var(--dsw-alias-brand-primary);font-size:13px;text-align:center}
113
+ .dsh-mp-effort{display:flex;align-items:center;gap:4px;flex-wrap:wrap;flex:0 0 auto;padding:8px 6px 4px;border-top:1px solid var(--dsw-alias-border-l1)}
114
+ .dsh-mp-effortLabel{flex:0 0 auto;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px}
115
+ .dsh-mp-effortBtn{flex:0 0 auto;height:24px;padding:0 10px;border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:transparent;color:var(--dsw-alias-label-secondary);font-size:12px;line-height:22px;cursor:pointer}
116
+ .dsh-mp-effortBtn:hover{background:var(--dsw-alias-interactive-bg-hover)}
117
+ .dsh-mp-effortActive{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}
118
+ /* Contributed session options (e.g. the agent-team collaboration toggle) sit
119
+ below the effort chips, separated by the same hairline the effort row uses. */
120
+ .dsh-mp-options{flex:0 0 auto;display:flex;flex-direction:column;gap:2px;padding:4px 2px 2px;border-top:1px solid var(--dsw-alias-border-l1)}
121
+ .dsh-mp-options:empty{display:none}
122
+ .dsh-mp-options button{font:inherit}
123
+ `
124
+
125
+ // Measure the trigger and the viewport, then decide where the portaled card
126
+ // can live: above the trigger when that side holds the room, otherwise
127
+ // below; width never exceeds the window minus both edges, and the provider
128
+ // rail narrows so the model list keeps a usable column on small windows.
129
+ // `top` is clamped last so a window shorter than MIN_HEIGHT still keeps the
130
+ // whole card on screen (it scrolls internally) instead of running off the
131
+ // frame — the exact failure a `bottom` anchor alone cannot prevent.
132
+ function measureLayout(trigger) {
133
+ if (trigger === null) return DEFAULT_LAYOUT
134
+ const rect = trigger.getBoundingClientRect()
135
+ const vw = window.innerWidth || document.documentElement.clientWidth || 0
136
+ const vh = window.innerHeight || document.documentElement.clientHeight || 0
137
+ if (vw <= 0 || vh <= 0) return DEFAULT_LAYOUT
138
+ // Fit the viewport first, then cap at the preferred size: a window narrower
139
+ // than PREFERRED_WIDTH must still get a card that fits rather than one that
140
+ // hangs off the frame.
141
+ const width = Math.max(0, Math.min(PREFERRED_WIDTH, vw - EDGE * 2))
142
+ let left = rect.right - width
143
+ left = Math.min(Math.max(EDGE, left), Math.max(EDGE, vw - width - EDGE))
144
+ const heightCap = Math.max(0, vh - EDGE * 2)
145
+ const spaceAbove = rect.top - GAP - EDGE
146
+ const spaceBelow = vh - rect.bottom - GAP - EDGE
147
+ const up = spaceAbove >= spaceBelow
148
+ const room = Math.max(0, up ? spaceAbove : spaceBelow)
149
+ const maxHeight = Math.min(PREFERRED_HEIGHT, heightCap, Math.max(room, Math.min(MIN_HEIGHT, heightCap)))
150
+ const preferredTop = up ? rect.top - GAP - maxHeight : rect.bottom + GAP
151
+ const top = Math.min(Math.max(EDGE, preferredTop), Math.max(EDGE, vh - EDGE - maxHeight))
152
+ return {
153
+ left,
154
+ width,
155
+ maxHeight,
156
+ up,
157
+ rail: width < RAIL_BREAKPOINT ? NARROW_RAIL : WIDE_RAIL,
158
+ top,
159
+ }
160
+ }
161
+
162
+ function ModelPicker(props) {
163
+ const locked = props.locked
164
+ const available = props.available
165
+ const directory = props.directory
166
+ const load = props.load
167
+ const select = props.select
168
+
169
+ const state = useSyncExternalStore(
170
+ (fn) => directory === null ? (() => {}) : directory.subscribe(fn),
171
+ () => directory === null ? EMPTY_STATE : directory.getSnapshot(),
172
+ )
173
+ const [open, setOpen] = useState(false)
174
+ const [query, setQuery] = useState('')
175
+ const [activeProvider, setActiveProvider] = useState(null)
176
+ const [notice, setNotice] = useState(null)
177
+ const [layout, setLayout] = useState(null)
178
+ const lastActionRef = useRef('load')
179
+ const rootRef = useRef(null)
180
+ const menuRef = useRef(null)
181
+ const triggerRef = useRef(null)
182
+ const searchRef = useRef(null)
183
+
184
+ const q = query.trim().toLowerCase()
185
+ const current = state.current
186
+
187
+ const currentChoice = useMemo(() => {
188
+ if (current === null) return null
189
+ for (const group of state.groups) {
190
+ if (group.id !== current.provider) continue
191
+ for (const model of group.models) {
192
+ if (model.id === current.model) return { group, model }
193
+ }
194
+ }
195
+ return null
196
+ }, [state.groups, current])
197
+
198
+ const reasoning = currentChoice === null ? undefined : currentChoice.model.reasoning
199
+ const effectiveEffort = current === null ? undefined : (current.reasoningEffort ?? reasoning?.defaultEffort)
200
+ const effortLabel = reasoning === undefined ? undefined
201
+ : effectiveEffort === undefined ? t('providerDefault')
202
+ : (reasoning.efforts.find((level) => level.id === effectiveEffort)?.name ?? String(effectiveEffort))
203
+ const effortChoices = useMemo(() => {
204
+ if (reasoning === undefined) return []
205
+ const rows = []
206
+ if (reasoning.defaultEffort === undefined) {
207
+ rows.push({ key: 'provider-default', effort: undefined, label: t('providerDefault') })
208
+ }
209
+ for (const level of reasoning.efforts) {
210
+ rows.push({ key: level.id, effort: level.id, label: level.name, description: level.description })
211
+ }
212
+ return rows
213
+ }, [reasoning])
214
+
215
+ const searching = q !== ''
216
+ const results = useMemo(() => {
217
+ if (!searching) return []
218
+ const out = []
219
+ for (const group of state.groups) {
220
+ const providerMatch = group.name.toLowerCase().includes(q)
221
+ for (const model of group.models) {
222
+ const modelMatch = model.name.toLowerCase().includes(q)
223
+ || (model.description !== undefined && model.description.toLowerCase().includes(q))
224
+ if (providerMatch || modelMatch) out.push({ group, model })
225
+ }
226
+ }
227
+ return out
228
+ }, [searching, q, state.groups])
229
+
230
+ const activeTab = (activeProvider !== null && state.groups.some((g) => g.id === activeProvider))
231
+ ? activeProvider
232
+ : (current !== null && state.groups.some((g) => g.id === current.provider))
233
+ ? current.provider
234
+ : (state.groups.length > 0 ? state.groups[0].id : null)
235
+ const activeGroup = state.groups.find((g) => g.id === activeTab) ?? null
236
+
237
+ const busy = state.status === 'selecting'
238
+ const modelLabel = currentChoice === null ? t('triggerFallback') : currentChoice.model.name
239
+ const triggerLabel = effortLabel === undefined ? modelLabel : modelLabel + ' · ' + effortLabel
240
+
241
+ const reload = () => {
242
+ lastActionRef.current = 'load'
243
+ load()
244
+ }
245
+
246
+ useEffect(() => {
247
+ if (!available) return
248
+ lastActionRef.current = 'load'
249
+ load()
250
+ }, [available, load])
251
+
252
+ useEffect(() => {
253
+ if (open) searchRef.current?.focus()
254
+ }, [open])
255
+
256
+ const close = (restoreFocus) => {
257
+ setOpen(false)
258
+ setNotice(null)
259
+ setActiveProvider(null)
260
+ setLayout(null)
261
+ if (restoreFocus && triggerRef.current !== null) triggerRef.current.focus()
262
+ }
263
+
264
+ const show = () => {
265
+ setNotice(null)
266
+ setQuery('')
267
+ lastActionRef.current = 'load'
268
+ setOpen(true)
269
+ reload()
270
+ }
271
+
272
+ // `directory.select` resolves with the host result envelope
273
+ // ({ ok: true } on success, or the Remote failure relayed verbatim), so a
274
+ // rejected transport and a declined selection are told apart here instead
275
+ // of collapsing both into one boolean at the face.
276
+ const settle = (result) => {
277
+ if (result !== null && typeof result === 'object' && result.ok === true) {
278
+ close(true)
279
+ return
280
+ }
281
+ const relayed = result !== null && typeof result === 'object' && result.error !== undefined
282
+ ? String(result.error.message ?? result.error.code ?? '')
283
+ : ''
284
+ const message = directory === null ? null : directory.getSnapshot().error
285
+ setNotice(message === null
286
+ ? (relayed === '' ? t('selectFailed') : t('selectFailedMsg') + relayed)
287
+ : t('selectFailedMsg') + message)
288
+ }
289
+
290
+ const choose = (group, model) => {
291
+ if (current !== null && current.provider === group.id && current.model === model.id) {
292
+ close(true)
293
+ return
294
+ }
295
+ lastActionRef.current = 'select'
296
+ const selection = {
297
+ provider: group.id,
298
+ model: model.id,
299
+ ...(model.reasoning !== undefined && model.reasoning.defaultEffort !== undefined
300
+ ? { reasoningEffort: model.reasoning.defaultEffort }
301
+ : {}),
302
+ }
303
+ void Promise.resolve(select(selection)).then(settle, () => { settle(null) })
304
+ }
305
+
306
+ const chooseEffort = (effort) => {
307
+ if (current === null) return
308
+ if (effectiveEffort === effort) {
309
+ close(true)
310
+ return
311
+ }
312
+ lastActionRef.current = 'select'
313
+ const selection = {
314
+ provider: current.provider,
315
+ model: current.model,
316
+ ...(effort === undefined ? {} : { reasoningEffort: effort }),
317
+ }
318
+ void Promise.resolve(select(selection)).then(settle, () => { settle(null) })
319
+ }
320
+
321
+ // Place the card before the browser paints an open menu, then keep it
322
+ // pinned while the window resizes, the page scrolls (any ancestor, hence
323
+ // capture) or the composer itself reflows around the trigger.
324
+ useLayoutEffect(() => {
325
+ if (!open) return
326
+ const sync = () => { setLayout(measureLayout(triggerRef.current)) }
327
+ sync()
328
+ window.addEventListener('resize', sync)
329
+ document.addEventListener('scroll', sync, true)
330
+ let observer = null
331
+ if (typeof ResizeObserver === 'function' && triggerRef.current !== null) {
332
+ observer = new ResizeObserver(sync)
333
+ observer.observe(triggerRef.current)
334
+ }
335
+ return () => {
336
+ window.removeEventListener('resize', sync)
337
+ document.removeEventListener('scroll', sync, true)
338
+ if (observer !== null) observer.disconnect()
339
+ }
340
+ }, [open])
341
+
342
+ // Keep the active row visible without moving the page: scroll the list
343
+ // element itself. `scrollIntoView` is deliberately not used — with a fixed
344
+ // card it can still scroll the document in some engines, which would drag
345
+ // the composer out from under the pointer on a short window.
346
+ useLayoutEffect(() => {
347
+ if (!open) return
348
+ const menu = menuRef.current
349
+ if (menu === null) return
350
+ const row = menu.querySelector('.dsh-mp-selected')
351
+ if (row === null) return
352
+ const list = menu.querySelector('.dsh-mp-list')
353
+ if (list === null) return
354
+ const rowBox = row.getBoundingClientRect()
355
+ const listBox = list.getBoundingClientRect()
356
+ if (rowBox.top < listBox.top) list.scrollTop -= listBox.top - rowBox.top
357
+ else if (rowBox.bottom > listBox.bottom) list.scrollTop += rowBox.bottom - listBox.bottom
358
+ }, [open, activeTab, searching])
359
+
360
+ // Close on an outside pointer press. Focus-based closing is deliberately
361
+ // NOT used: opening the menu moves focus into the search field, which
362
+ // makes the root fire a bubbling blur whose relatedTarget can still be the
363
+ // previously focused outside element, so a focus listener closes the menu
364
+ // in the same tick that opened it. A document-level pointerdown that
365
+ // ignores presses inside the root OR the portaled card has no such
366
+ // ordering hazard.
367
+ useEffect(() => {
368
+ if (!open) return
369
+ const onPointerDown = (event) => {
370
+ const target = event.target
371
+ if (!(target instanceof Node)) return
372
+ if (rootRef.current !== null && rootRef.current.contains(target)) return
373
+ if (menuRef.current !== null && menuRef.current.contains(target)) return
374
+ close()
375
+ }
376
+ const onKeyDown = (event) => {
377
+ if (event.key !== 'Escape') return
378
+ event.preventDefault()
379
+ close(true)
380
+ }
381
+ document.addEventListener('pointerdown', onPointerDown, true)
382
+ document.addEventListener('keydown', onKeyDown, true)
383
+ return () => {
384
+ document.removeEventListener('pointerdown', onPointerDown, true)
385
+ document.removeEventListener('keydown', onKeyDown, true)
386
+ }
387
+ }, [open])
388
+
389
+ const renderOption = (group, model) => {
390
+ const selected = current !== null && current.provider === group.id && current.model === model.id
391
+ const detail = searching
392
+ ? (group.name + (model.description !== undefined ? ' · ' + model.description : ''))
393
+ : (model.description ?? '')
394
+ return h('button', {
395
+ key: group.id + '/' + model.id,
396
+ type: 'button',
397
+ role: 'menuitemradio',
398
+ 'aria-checked': selected,
399
+ className: 'dsh-mp-option' + (selected ? ' dsh-mp-selected' : ''),
400
+ disabled: busy,
401
+ onClick: () => { choose(group, model) },
402
+ },
403
+ h('span', { className: 'dsh-mp-optionCopy' },
404
+ h('span', { className: 'dsh-mp-modelName' }, model.name),
405
+ detail !== '' && h('span', { className: 'dsh-mp-description' }, detail),
406
+ ),
407
+ h('span', { className: 'dsh-mp-check' }, selected ? '✓' : ''),
408
+ )
409
+ }
410
+
411
+ if (!available || directory === null) return null
412
+
413
+ const place = layout !== null && layout !== undefined ? layout : DEFAULT_LAYOUT
414
+ const menuStyle = {
415
+ left: place.left + 'px',
416
+ top: place.top + 'px',
417
+ width: place.width + 'px',
418
+ maxHeight: place.maxHeight + 'px',
419
+ }
420
+ const railStyle = { '--dsh-mp-rail': place.rail + 'px' }
421
+
422
+ // No contributed options: this seat declares no child slot (see apply()), so
423
+ // the framework never supplies a renderer for them. Keeping the variable
424
+ // explicit makes the footer branch below a no-op rather than a latent
425
+ // ownership error.
426
+ const optionsSlot = null
427
+
428
+ const menu = open && h('div', {
429
+ ref: menuRef,
430
+ className: 'dsh-mp-menu',
431
+ role: 'menu',
432
+ tabIndex: -1,
433
+ style: { ...menuStyle, ...railStyle },
434
+ // Marks the narrowed rail so its count badges collapse instead of
435
+ // squeezing the provider name to two characters.
436
+ 'data-narrow': place.rail === NARROW_RAIL ? 'true' : undefined,
437
+ onMouseDown: (event) => { event.preventDefault() },
438
+ 'aria-busy': state.status === 'loading' || busy,
439
+ },
440
+ h('input', {
441
+ ref: searchRef,
442
+ type: 'text',
443
+ className: 'dsh-mp-search',
444
+ placeholder: t('search'),
445
+ value: query,
446
+ onChange: (event) => { setQuery(event.target.value) },
447
+ }),
448
+ h('div', { className: 'dsh-mp-body' },
449
+ h('div', { className: 'dsh-mp-providers', role: 'tablist', 'aria-label': t('providers') },
450
+ state.groups.map((group) => {
451
+ const active = !searching && group.id === activeTab
452
+ return h('button', {
453
+ key: group.id,
454
+ type: 'button',
455
+ role: 'tab',
456
+ 'aria-selected': active,
457
+ className: 'dsh-mp-provider' + (active ? ' dsh-mp-providerActive' : ''),
458
+ onClick: () => { setQuery(''); setActiveProvider(group.id) },
459
+ },
460
+ h('span', { className: 'dsh-mp-providerName' }, group.name),
461
+ h('span', { className: 'dsh-mp-providerCount' }, String(group.models.length)),
462
+ )
463
+ }),
464
+ ),
465
+ h('div', { className: 'dsh-mp-list' },
466
+ state.status === 'loading'
467
+ ? h('div', { className: 'dsh-mp-status' }, t('loading'))
468
+ : h(Fragment, null,
469
+ state.error !== null && lastActionRef.current === 'load'
470
+ && h('div', { className: 'dsh-mp-error' },
471
+ h('span', null, String(state.error)),
472
+ h('button', { type: 'button', className: 'dsh-mp-retry', onClick: reload }, t('retry')),
473
+ ),
474
+ notice !== null
475
+ && h('div', { className: 'dsh-mp-error' },
476
+ h('span', null, notice),
477
+ ),
478
+ !searching && state.failures.map((failure) =>
479
+ h('div', { className: 'dsh-mp-warning', key: failure.id },
480
+ h('span', null, failure.name + ' 加载失败:' + failure.message),
481
+ h('button', { type: 'button', className: 'dsh-mp-retry', onClick: reload }, t('retry')),
482
+ ),
483
+ ),
484
+ searching
485
+ ? (results.length === 0
486
+ ? h('div', { className: 'dsh-mp-empty' }, t('noMatch'))
487
+ : results.map((row) => renderOption(row.group, row.model)))
488
+ : activeGroup === null
489
+ ? (state.status === 'ready' && state.groups.length === 0
490
+ ? h('div', { className: 'dsh-mp-empty' }, t('noModels'))
491
+ : null)
492
+ : activeGroup.models.length === 0
493
+ ? h('div', { className: 'dsh-mp-empty' }, t('providerEmpty'))
494
+ : activeGroup.models.map((model) => renderOption(activeGroup, model)),
495
+ ),
496
+ ),
497
+ ),
498
+ reasoning !== undefined && effortChoices.length > 0 && !searching
499
+ && h('div', { className: 'dsh-mp-effort' },
500
+ h('span', { className: 'dsh-mp-effortLabel' }, t('effort')),
501
+ effortChoices.map((level) => h('button', {
502
+ key: level.key,
503
+ type: 'button',
504
+ className: 'dsh-mp-effortBtn' + (effectiveEffort === level.effort ? ' dsh-mp-effortActive' : ''),
505
+ title: level.description,
506
+ onClick: () => { chooseEffort(level.effort) },
507
+ }, level.label)),
508
+ ),
509
+ optionsSlot !== null && optionsSlot !== undefined
510
+ && h('div', { className: 'dsh-mp-options' }, optionsSlot),
511
+ )
512
+
513
+ return h('div', { ref: rootRef, className: 'dsh-mp-root' },
514
+ h('button', {
515
+ ref: triggerRef,
516
+ type: 'button',
517
+ className: 'dsh-mp-trigger',
518
+ title: triggerLabel,
519
+ 'aria-label': modelLabel,
520
+ 'aria-haspopup': 'menu',
521
+ 'aria-expanded': open,
522
+ disabled: locked,
523
+ onClick: () => { if (open) { close() } else { show() } },
524
+ },
525
+ h('span', { className: 'dsh-mp-triggerLabel' }, modelLabel),
526
+ effortLabel !== undefined && h('span', { className: 'dsh-mp-triggerEffort' }, effortLabel),
527
+ h('span', { className: 'dsh-mp-chevron' + (open ? ' dsh-mp-chevronOpen' : '') }, '▾'),
528
+ ),
529
+ menu !== null && menu !== undefined && menu !== false
530
+ ? (createPortal !== null && typeof document !== 'undefined'
531
+ ? createPortal(menu, document.body)
532
+ : menu)
533
+ : null,
534
+ )
535
+ }
536
+
537
+ // `slots` plus the dependency surface `modelDirectories.directoryFor()` needs
538
+ // from its CALLER: the service resolves `this.ctx.remote.session` (and
539
+ // `sessions`) against the caller's fiber, so a plugin that calls directoryFor
540
+ // without declaring these throws "cannot get property "remote.session"
541
+ // without inject" at render time — which the seat reports as a crash and
542
+ // silently falls back to the stock picker. The shipped ui-model-selection
543
+ // seat declares exactly this set, and it is mirrored here.
544
+ //
545
+ // These are declared at MODULE level rather than through a runtime
546
+ // ctx.inject: the web boot audits every top-level entry and throws
547
+ // "N entries did not activate: ... pending (waiting for service: ...)" when a
548
+ // declared dependency never arrives, so listing services the web profile may
549
+ // legitimately omit would blank the whole GUI. `remote`/`remote.session` ship
550
+ // with every web roster; `modelDirectories` (owned by the optional
551
+ // ui-model-selection plugin) is still resolved through the runtime inject
552
+ // below so its absence only skips this plugin's seat.
553
+ const inject = ['slots', 'sessions', 'remote', 'remote.session']
554
+
555
+ function apply(ctx) {
556
+ const slots = ctx.get('slots')
557
+ if (slots === undefined) return
558
+ ctx.effect(() => {
559
+ const id = 'dsh-modelpicker-style'
560
+ if (!document.getElementById(id)) {
561
+ const s = document.createElement('style')
562
+ s.id = id
563
+ s.textContent = CSS
564
+ document.head.appendChild(s)
565
+ }
566
+ return () => { const el = document.getElementById(id); if (el) el.remove() }
567
+ }, 'model-picker-style')
568
+ // Register from inside a RUNTIME inject, exactly like the shipped
569
+ // ui-model-selection seat does. The seat face is cached per (entry x
570
+ // session) for the registration's lifetime, so a face minted while
571
+ // `modelDirectories` is still unresolved would be cached as unusable —
572
+ // and because it then renders nothing rather than throwing, the slot error
573
+ // boundary never abdicates the entry and the priority:-1 shadow silently
574
+ // removes the model picker from the composer. Deferring registration until
575
+ // the catalog service is live means the face can only ever be minted
576
+ // against a working directory; if the service never arrives, this plugin
577
+ // simply never shadows the stock picker and the built-in list stays.
578
+ // Runtime gate on the OPTIONAL catalog service only. `slots`, `sessions`,
579
+ // `remote` and `remote.session` come from the module-level declaration
580
+ // above; a child fiber inherits them, so the face can resolve everything
581
+ // directoryFor() needs.
582
+ //
583
+ // ── the child slot, and why it is OPTIONAL here ─────────────────────────
584
+ // Contributed session options (the shipped agent-team collaboration toggle)
585
+ // reach a model seat through the child slot
586
+ // 'conversation.input.model.options'. Rendering them requires the seat's own
587
+ // entry to have declared that name — `renderSlot` throws
588
+ // slot '<key>' is not declared by this entry's children
589
+ // otherwise — and `ctx.slots.renderSlot` cannot stand in, because the
590
+ // service-level method only renders 'root'.
591
+ //
592
+ // A slot name, however, has exactly ONE declarer: SlotCore.register throws
593
+ // slot '<name>' is already declared (by '<declarer>')
594
+ // for a second entry that lists the same child. The shipped seat declares
595
+ // this name at module scope, so it always wins the race; declaring it here
596
+ // unconditionally would make OUR registration throw, the composer would lose
597
+ // the enhanced picker, AND hot-disabling the bundle would release the
598
+ // declaration without the stock seat ever re-registering — leaving no model
599
+ // seat at all until a page reload. That is the reported bug.
600
+ //
601
+ // The resolution: register WITHOUT the child slot first. If the public name
602
+ // turns out to be free, swap to a registration that declares it, so the
603
+ // contributed toggle appears. If the stock seat owns it, keep the plain
604
+ // registration — the enhanced picker works and the footer simply has no
605
+ // contributed rows. Preferences are set through the plugin's own surfaces
606
+ // instead, and nothing is ever double-declared.
607
+ const OPTIONS_SLOT = 'conversation.input.model.options'
608
+
609
+ ctx.inject(['slots', 'modelDirectories', 'sessions'], (scope) => {
610
+ const models = scope.modelDirectories
611
+ const sessions = scope.sessions
612
+
613
+ const seatFace = (sessionId) => {
614
+ const directory = models.directoryFor(sessionId)
615
+ const available = sessions.subagentAddress(sessionId) === undefined
616
+ return {
617
+ available,
618
+ directory: directory.store,
619
+ load: () => { if (available) directory.load().catch(() => { /* surfaced on the store */ }) },
620
+ select: (selection) => available
621
+ ? directory.select(selection)
622
+ : Promise.resolve({ ok: false, error: { code: 'unavailable', message: 'model selection is unavailable' } }),
623
+ }
624
+ }
625
+
626
+ const registerPlain = () => scope.slots.register({
627
+ name: 'conversation.input.model',
628
+ priority: -1,
629
+ registrant: 'dsh-modelpicker',
630
+ inject: seatFace,
631
+ }, ModelPicker)
632
+
633
+ // Is the public options slot still unclaimed? `slots.inject` fires exactly
634
+ // when a name IS declared, so an immediate callback answers "taken".
635
+ // Retained for diagnostics: a future DSH release may let a plugin declare
636
+ // the name without colliding with the shipped seat.
637
+ const optionsTaken = () => {
638
+ let taken = false
639
+ const stop = scope.slots.inject(OPTIONS_SLOT, () => { taken = true })
640
+ if (typeof stop === 'function') stop()
641
+ return taken
642
+ }
643
+ void optionsTaken
644
+
645
+ // The seat only becomes registerable once 'conversation.input.model' is
646
+ // DECLARED — `register` throws "not declared (a parent entry's children
647
+ // table must declare it)" otherwise, and ui-conversation declares it later
648
+ // than this plugin boots. `slots.inject` is the declaration gate.
649
+ //
650
+ // That callback can run MORE THAN ONCE: cordis re-runs it whenever the
651
+ // declaration epoch changes (the shipped seat re-registering, a hot reload,
652
+ // another entry arriving). Registering inside it unconditionally therefore
653
+ // stacks entries and — with a child slot — trips "slot ... is already
654
+ // declared (by an entry in 'conversation.input.model' (dsh-modelpicker))"
655
+ // against OUR OWN previous registration, which then blanks the seat. Each
656
+ // callback therefore owns exactly one registration and releases it through
657
+ // the disposer cordis takes from us.
658
+ return scope.slots.inject('conversation.input.model', () => {
659
+ let release = null
660
+ let disposed = false
661
+
662
+ // Never declare 'conversation.input.model.options'. The shipped
663
+ // ui-model-selection seat claims that name, and it re-registers on the
664
+ // same declaration epoch we watch: whichever side declares second throws
665
+ // "slot ... is already declared", and the throw blanks whichever seat
666
+ // registered. Declaring nothing keeps both seats healthy; this picker
667
+ // simply renders no contributed footer rows.
668
+ release = registerPlain()
669
+
670
+ return () => {
671
+ if (disposed) return
672
+ disposed = true
673
+ if (typeof release === 'function') release()
674
+ release = null
675
+ }
676
+ })
677
+ })
678
+ }
679
+
680
+ module.exports = { inject, apply }
681
+ return module.exports;
682
+ } })
package/lib/host.js ADDED
@@ -0,0 +1,12 @@
1
+ // Host half of dsh-modelpicker: a no-op plugin. All behavior lives in the
2
+ // browser client half (lib/client.js, served through the ./client export).
3
+ // The Node-side loader imports this file as the package root entry, so it
4
+ // must stay Node-safe: no window/document access at module scope.
5
+ export const name = 'dsh-modelpicker'
6
+
7
+ export const inject = []
8
+
9
+ export function apply() {
10
+ // Intentionally empty: the composer model seat is contributed by the
11
+ // client half over the web plugin loader.
12
+ }
package/package.json CHANGED
@@ -1,6 +1,74 @@
1
1
  {
2
2
  "name": "@ou6235/dsh-modelpicker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Enhanced model picker for the DeepSeek Harness web GUI: a provider rail with an independently scrolling model list, cross-provider search, and a portaled popup that stays fully usable in small windows",
4
+ "version": "1.3.1",
5
+ "type": "module",
6
+ "main": "lib/host.js",
7
+ "exports": {
8
+ ".": "./lib/host.js",
9
+ "./client": "./lib/client.js",
10
+ "./cordis.patch.yml": "./cordis.patch.yml",
11
+ "./package.json": "./package.json"
12
+ },
13
+ "files": [
14
+ "lib/",
15
+ "cordis.patch.yml",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "keywords": [
20
+ "dsh",
21
+ "agent-harness",
22
+ "plugin",
23
+ "model",
24
+ "picker",
25
+ "web",
26
+ "ui"
27
+ ],
28
+ "license": "MIT",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/ou6235/dsh-modelpicker.git"
35
+ },
36
+ "homepage": "https://github.com/ou6235/dsh-modelpicker#readme",
37
+ "bugs": {
38
+ "url": "https://github.com/ou6235/dsh-modelpicker/issues"
39
+ },
40
+ "engines": {
41
+ "node": "^22.19.0 || >=24.0.0"
42
+ },
43
+ "dsh": {
44
+ "bundle": {
45
+ "patch": "./cordis.patch.yml"
46
+ },
47
+ "client": {
48
+ "platform": "web"
49
+ }
50
+ },
51
+ "peerDependencies": {
52
+ "react": "^18.2.0",
53
+ "@deepseek-ai/cordis": "*",
54
+ "@deepseek-ai/dsh-client-runtime": "*",
55
+ "@deepseek-ai/dsh-client-ui-slots": "*"
56
+ },
57
+ "peerDependenciesMeta": {
58
+ "react": {
59
+ "optional": true
60
+ },
61
+ "@deepseek-ai/cordis": {
62
+ "optional": true
63
+ },
64
+ "@deepseek-ai/dsh-client-runtime": {
65
+ "optional": true
66
+ },
67
+ "@deepseek-ai/dsh-client-ui-slots": {
68
+ "optional": true
69
+ }
70
+ },
71
+ "scripts": {
72
+ "test": "node --test tests/*.test.mjs"
73
+ }
6
74
  }