dsh-per-message-model 0.1.5 → 0.1.6

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/lib/client.js +32 -21
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -118,26 +118,37 @@ window.__ModuleLoader__.load({
118
118
  * existing chip behavior (color change + title); a single click rolls the
119
119
  * model name out from left to right like a scroll (icon rotates by a random
120
120
  * angle); clicking again rolls it back (icon rotates back).
121
+ *
122
+ * Implemented WITHOUT React state on purpose: the DSH slot renderer mounts
123
+ * registrants through an error boundary and some hosts do not tolerate
124
+ * hook-based state in dock seats; the unfold/collapse is a pure DOM class
125
+ * toggle plus an inline transform on the icon, so it works in any host.
121
126
  */
122
127
  function FooterModelBadge({ useProjection, t }) {
123
- const [open, setOpen] = React.useState(false);
124
- const [rot, setRot] = React.useState(0);
125
- const value = useProjection("perMessageModel");
126
- const current = value === void 0 || value === null || typeof value !== "object" || value.current === void 0
127
- ? void 0
128
- : value.current;
129
- const known = current !== void 0 && typeof current === "object";
130
- const provider = known && typeof current.provider === "string" ? current.provider : null;
131
- const model = known && typeof current.model === "string" ? current.model : null;
132
- const label = provider !== null && model !== null
133
- ? provider + " / " + model
134
- : t("badge.unknown");
135
- const toggle = () => {
136
- if (open) {
137
- setOpen(false);
128
+ let value = null;
129
+ try { value = useProjection("perMessageModel"); } catch (err) { value = null; }
130
+ const hasValue = value !== null && value !== void 0 && typeof value === "object";
131
+ const current = hasValue && typeof value.current === "object" && value.current !== null ? value.current : null;
132
+ const provider = current !== null && typeof current.provider === "string" ? current.provider : null;
133
+ const model = current !== null && typeof current.model === "string" ? current.model : null;
134
+ let label;
135
+ try { label = provider !== null && model !== null ? provider + " / " + model : (typeof t === "function" ? t("badge.unknown") : "model unknown"); }
136
+ catch (err) { label = provider !== null && model !== null ? provider + " / " + model : "model unknown"; }
137
+ const toggle = (event) => {
138
+ const btn = event && event.currentTarget ? event.currentTarget : null;
139
+ if (btn === null) return;
140
+ const labelEl = btn.querySelector('[class*="footer-label"]');
141
+ const iconEl = btn.querySelector('[class*="footer-icon"]');
142
+ const isOpen = btn.getAttribute("aria-expanded") === "true";
143
+ if (isOpen) {
144
+ btn.setAttribute("aria-expanded", "false");
145
+ if (labelEl !== null) labelEl.setAttribute("data-open", "false");
146
+ if (iconEl !== null) iconEl.style.transform = "rotate(0deg)";
138
147
  } else {
139
- setRot(Math.round(90 + Math.random() * 180));
140
- setOpen(true);
148
+ const deg = Math.round(90 + Math.random() * 180);
149
+ btn.setAttribute("aria-expanded", "true");
150
+ if (labelEl !== null) labelEl.setAttribute("data-open", "true");
151
+ if (iconEl !== null) iconEl.style.transform = "rotate(" + deg + "deg)";
141
152
  }
142
153
  };
143
154
  return createElement("button", {
@@ -146,22 +157,22 @@ window.__ModuleLoader__.load({
146
157
  "data-dsh-per-message-model-footer": "true",
147
158
  "aria-label": label,
148
159
  title: label,
149
- "aria-expanded": open ? "true" : "false",
160
+ "aria-expanded": "false",
150
161
  onClick: toggle
151
162
  }, [
152
163
  createElement("span", {
153
164
  key: "icon",
154
165
  className: BADGE_PREFIX + "footer-icon",
155
- style: { transform: open ? "rotate(" + rot + "deg)" : "rotate(0deg)" }
166
+ style: { transform: "rotate(0deg)" }
156
167
  }, chipIcon()),
157
168
  createElement("span", {
158
169
  key: "label",
159
170
  className: BADGE_PREFIX + "footer-label",
160
- "data-open": open ? "true" : "false"
171
+ "data-open": "false"
161
172
  }, label)
162
173
  ]);
163
174
  }
164
- //#endregion
175
+ //#endregion //#endregion
165
176
  //#region client divider
166
177
  /** Fixed Chinese copy for the model-switch divider (user-required). */
167
178
  const SWITCH_COPY = "模型切换:";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-per-message-model",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "在 DSH 主对话每条 assistant 回复旁展示该条回复实际使用的 provider / model 徽章(可选附带 reasoning effort)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",