@shuind/dsh-codex-harness 0.1.34 → 0.1.35

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/README.md CHANGED
@@ -20,7 +20,7 @@
20
20
  ## 安装
21
21
 
22
22
  ```sh
23
- dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.34
23
+ dsh plugin --profile web add @shuind/dsh-codex-harness@0.1.35
24
24
  ```
25
25
 
26
26
  重启 Web,创建新会话,在模式菜单中选择 **Codex 模式**。
package/lib/client.js CHANGED
@@ -284,15 +284,19 @@ window.__ModuleLoader__.load({
284
284
  function elapsedSeconds(startedAt, now) {
285
285
  return Math.max(0, Math.floor((now - startedAt) / 1e3));
286
286
  }
287
- function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }) {
288
- const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
289
- const projectedActivity = useProjection("codexActivity");
290
- const fallbackActivity = useSession(modelActivity, sameModelActivity);
291
- const normalizedProjectedActivity = projectedActivity?.activity === "awaiting-model" ? {
287
+ /** Prefer the session snapshot when an older projection host only exposes null. */
288
+ function resolveActivity(agentPreset, projectedActivity, fallbackActivity) {
289
+ if (!isCodexPresetId(agentPreset)) return null;
290
+ if (projectedActivity?.activity === "awaiting-model") return {
292
291
  activity: fallbackActivity?.activity ?? "requesting-model",
293
292
  startedAt: fallbackActivity?.startedAt ?? projectedActivity.startedAt
294
- } : projectedActivity;
295
- const activity = projectedActivity !== void 0 ? normalizedProjectedActivity : isCodexPresetId(agentPreset) && fallbackActivity !== void 0 ? fallbackActivity : null;
293
+ };
294
+ if (projectedActivity === null) return fallbackActivity ?? null;
295
+ return projectedActivity ?? fallbackActivity ?? null;
296
+ }
297
+ function ActivityLine({ sessionId, useSession, useSessions, useProjection, t, position }) {
298
+ const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
299
+ const activity = resolveActivity(agentPreset, useProjection("codexActivity"), useSession(modelActivity, sameModelActivity));
296
300
  const [now, setNow] = (0, react.useState)(() => Date.now());
297
301
  (0, react.useEffect)(() => {
298
302
  if (!isCodexPresetId(agentPreset) || activity === void 0 || activity === null) return void 0;
@@ -316,12 +320,19 @@ window.__ModuleLoader__.load({
316
320
  alignItems: "center",
317
321
  gap: 7,
318
322
  minHeight: 26,
319
- marginLeft: 10,
323
+ marginLeft: position === void 0 ? 10 : 0,
320
324
  color: "var(--dsw-alias-label-secondary)",
321
325
  fontSize: 12,
322
326
  lineHeight: "20px",
323
327
  whiteSpace: "nowrap",
324
- WebkitTextFillColor: "currentColor"
328
+ WebkitTextFillColor: "currentColor",
329
+ ...position === void 0 ? {} : {
330
+ position: "fixed",
331
+ left: position.left,
332
+ top: position.top,
333
+ zIndex: 100,
334
+ pointerEvents: "none"
335
+ }
325
336
  },
326
337
  children: [
327
338
  (0, react_jsx_runtime.jsx)("span", {
@@ -361,8 +372,48 @@ window.__ModuleLoader__.load({
361
372
  return null;
362
373
  }
363
374
  function findTurnStatus() {
364
- for (const status of document.querySelectorAll("[role=\"status\"]")) if (status.textContent?.includes("Deep diving...") === true && status.closest("[data-chat-flow]") !== null) return status;
365
- return null;
375
+ let fallback = null;
376
+ for (const status of document.querySelectorAll("[role=\"status\"]")) {
377
+ if (status.closest("[data-chat-flow]") === null) continue;
378
+ fallback ??= status;
379
+ if (status.textContent?.includes("Deep diving...") === true || status.className.toString().includes("turnStatus")) return status;
380
+ }
381
+ return fallback;
382
+ }
383
+ function useTurnStatusPosition(target) {
384
+ const [position, setPosition] = (0, react.useState)(null);
385
+ (0, react.useLayoutEffect)(() => {
386
+ if (target === null) {
387
+ setPosition(null);
388
+ return;
389
+ }
390
+ const update = () => {
391
+ if (!target.isConnected) {
392
+ setPosition(null);
393
+ return;
394
+ }
395
+ const rect = target.getBoundingClientRect();
396
+ if (rect.width === 0 && rect.height === 0) {
397
+ setPosition(null);
398
+ return;
399
+ }
400
+ setPosition({
401
+ left: Math.round(rect.right + 10),
402
+ top: Math.round(rect.top + (rect.height - 26) / 2)
403
+ });
404
+ };
405
+ update();
406
+ window.addEventListener("resize", update);
407
+ window.addEventListener("scroll", update, true);
408
+ const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
409
+ observer?.observe(target);
410
+ return () => {
411
+ window.removeEventListener("resize", update);
412
+ window.removeEventListener("scroll", update, true);
413
+ observer?.disconnect();
414
+ };
415
+ }, [target]);
416
+ return position;
366
417
  }
367
418
  function useLegacyHostTargets() {
368
419
  const [targets, setTargets] = (0, react.useState)({
@@ -394,6 +445,7 @@ window.__ModuleLoader__.load({
394
445
  function LegacyOverlay(props) {
395
446
  const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
396
447
  const { contextDialog, turnStatus } = useLegacyHostTargets();
448
+ const turnStatusPosition = useTurnStatusPosition(turnStatus);
397
449
  const contextWindow = contextWindowFromProjection(useProjection);
398
450
  if (!isCodexPresetId(useSessions((state) => state.byId[sessionId]?.agentPreset))) return null;
399
451
  return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
@@ -404,13 +456,14 @@ window.__ModuleLoader__.load({
404
456
  setSetting,
405
457
  unsetSetting,
406
458
  t
407
- }), contextDialog, "codex-context-size"), turnStatus !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ActivityLine, {
459
+ }), contextDialog, "codex-context-size"), turnStatusPosition !== null && typeof document !== "undefined" && document.body !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ActivityLine, {
408
460
  sessionId,
409
461
  useSession,
410
462
  useSessions,
411
463
  useProjection,
412
- t
413
- }), turnStatus, "codex-activity")] });
464
+ t,
465
+ position: turnStatusPosition
466
+ }), document.body, "codex-activity")] });
414
467
  }
415
468
  const inject = [
416
469
  "slots",
@@ -453,6 +506,7 @@ window.__ModuleLoader__.load({
453
506
  exports.apply = apply;
454
507
  exports.default = client_default;
455
508
  exports.inject = inject;
509
+ exports.resolveActivity = resolveActivity;
456
510
  return module.exports;
457
511
  }
458
512
  });
@@ -2,6 +2,8 @@
2
2
  import type { HostObservable, InjectFace, PropsLocale, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
3
3
  import type { Context } from '@deepseek-ai/cordis';
4
4
  import type { SettingsScope } from '@deepseek-ai/dsh-client-runtime/client';
5
+ import type { CodexActivity } from '../activity-types.ts';
6
+ import { modelActivity } from './activity.ts';
5
7
  declare const LEGACY_OVERLAY_SLOT: "conversation.input.overlay";
6
8
  interface CodexSettings {
7
9
  fast: boolean;
@@ -43,7 +45,15 @@ interface InputSettingsControlInjected {
43
45
  }
44
46
  type LegacyOverlayProps = PropsRuntime<typeof LEGACY_OVERLAY_SLOT> & InjectFace<InputSettingsControlInjected> & PropsLocale<'codex'>;
45
47
  type ActivityProps = Pick<LegacyOverlayProps, 'sessionId' | 'useSession' | 'useSessions' | 'useProjection' | 't'>;
46
- export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }: ActivityProps): import("react").JSX.Element | null;
48
+ type ActivityFallback = ReturnType<typeof modelActivity>;
49
+ /** Prefer the session snapshot when an older projection host only exposes null. */
50
+ export declare function resolveActivity(agentPreset: string | undefined, projectedActivity: CodexActivity | null | undefined, fallbackActivity: ActivityFallback): CodexActivity | null;
51
+ export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t, position, }: ActivityProps & {
52
+ position?: {
53
+ left: number;
54
+ top: number;
55
+ };
56
+ }): import("react").JSX.Element | null;
47
57
  export declare const inject: string[];
48
58
  /** Mount all controls through the official composer seats shared by every DSH release. */
49
59
  export declare function apply(ctx: Context): void;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /** Browser controls for the Codex request settings mounted by the Host plugin. */
3
- import { useEffect, useState } from 'react';
3
+ import { useEffect, useLayoutEffect, useState } from 'react';
4
4
  import { createPortal } from 'react-dom';
5
5
  import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
6
6
  import { modelActivity, sameModelActivity } from "./activity.js";
@@ -121,7 +121,21 @@ function ContextSizeControl({ contextWindow, sessionId, useSessions, useSettings
121
121
  function elapsedSeconds(startedAt, now) {
122
122
  return Math.max(0, Math.floor((now - startedAt) / 1_000));
123
123
  }
124
- export function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }) {
124
+ /** Prefer the session snapshot when an older projection host only exposes null. */
125
+ export function resolveActivity(agentPreset, projectedActivity, fallbackActivity) {
126
+ if (!isCodexPresetId(agentPreset))
127
+ return null;
128
+ if (projectedActivity?.activity === 'awaiting-model') {
129
+ return {
130
+ activity: fallbackActivity?.activity ?? 'requesting-model',
131
+ startedAt: fallbackActivity?.startedAt ?? projectedActivity.startedAt,
132
+ };
133
+ }
134
+ if (projectedActivity === null)
135
+ return fallbackActivity ?? null;
136
+ return projectedActivity ?? fallbackActivity ?? null;
137
+ }
138
+ export function ActivityLine({ sessionId, useSession, useSessions, useProjection, t, position, }) {
125
139
  const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
126
140
  // Keep the projection seam optional: this package must still load when the
127
141
  // host has no session-projection registry or has not carried this key.
@@ -130,17 +144,7 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
130
144
  // fallback only covers the short wire gap before the next projection frame;
131
145
  // tool calls intentionally remain silent because their cards own the status.
132
146
  const fallbackActivity = useSession(modelActivity, sameModelActivity);
133
- // `undefined` means the key has not arrived yet; `null` is an authoritative
134
- // clear and must not be resurrected by the local snapshot fallback.
135
- const normalizedProjectedActivity = projectedActivity?.activity === 'awaiting-model'
136
- ? {
137
- activity: fallbackActivity?.activity ?? 'requesting-model',
138
- startedAt: fallbackActivity?.startedAt ?? projectedActivity.startedAt,
139
- }
140
- : projectedActivity;
141
- const activity = projectedActivity !== undefined ? normalizedProjectedActivity : (isCodexPresetId(agentPreset) && fallbackActivity !== undefined
142
- ? fallbackActivity
143
- : null);
147
+ const activity = resolveActivity(agentPreset, projectedActivity, fallbackActivity);
144
148
  const [now, setNow] = useState(() => Date.now());
145
149
  useEffect(() => {
146
150
  if (!isCodexPresetId(agentPreset) || activity === undefined || activity === null)
@@ -161,12 +165,19 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
161
165
  alignItems: 'center',
162
166
  gap: 7,
163
167
  minHeight: 26,
164
- marginLeft: 10,
168
+ marginLeft: position === undefined ? 10 : 0,
165
169
  color: 'var(--dsw-alias-label-secondary)',
166
170
  fontSize: 12,
167
171
  lineHeight: '20px',
168
172
  whiteSpace: 'nowrap',
169
173
  WebkitTextFillColor: 'currentColor',
174
+ ...(position === undefined ? {} : {
175
+ position: 'fixed',
176
+ left: position.left,
177
+ top: position.top,
178
+ zIndex: 100,
179
+ pointerEvents: 'none',
180
+ }),
170
181
  }, children: [_jsx("span", { "aria-hidden": "true", style: {
171
182
  width: 5,
172
183
  height: 5,
@@ -191,12 +202,51 @@ function findContextMeterDialog() {
191
202
  return null;
192
203
  }
193
204
  function findTurnStatus() {
205
+ let fallback = null;
194
206
  for (const status of document.querySelectorAll('[role="status"]')) {
207
+ if (status.closest('[data-chat-flow]') === null)
208
+ continue;
209
+ fallback ??= status;
195
210
  if (status.textContent?.includes('Deep diving...') === true
196
- && status.closest('[data-chat-flow]') !== null)
211
+ || status.className.toString().includes('turnStatus'))
197
212
  return status;
198
213
  }
199
- return null;
214
+ return fallback;
215
+ }
216
+ function useTurnStatusPosition(target) {
217
+ const [position, setPosition] = useState(null);
218
+ useLayoutEffect(() => {
219
+ if (target === null) {
220
+ setPosition(null);
221
+ return undefined;
222
+ }
223
+ const update = () => {
224
+ if (!target.isConnected) {
225
+ setPosition(null);
226
+ return;
227
+ }
228
+ const rect = target.getBoundingClientRect();
229
+ if (rect.width === 0 && rect.height === 0) {
230
+ setPosition(null);
231
+ return;
232
+ }
233
+ setPosition({
234
+ left: Math.round(rect.right + 10),
235
+ top: Math.round(rect.top + (rect.height - 26) / 2),
236
+ });
237
+ };
238
+ update();
239
+ window.addEventListener('resize', update);
240
+ window.addEventListener('scroll', update, true);
241
+ const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(update);
242
+ observer?.observe(target);
243
+ return () => {
244
+ window.removeEventListener('resize', update);
245
+ window.removeEventListener('scroll', update, true);
246
+ observer?.disconnect();
247
+ };
248
+ }, [target]);
249
+ return position;
200
250
  }
201
251
  function useLegacyHostTargets() {
202
252
  const [targets, setTargets] = useState({ contextDialog: null, turnStatus: null });
@@ -227,11 +277,12 @@ function useLegacyHostTargets() {
227
277
  function LegacyOverlay(props) {
228
278
  const { sessionId, useSession, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
229
279
  const { contextDialog, turnStatus } = useLegacyHostTargets();
280
+ const turnStatusPosition = useTurnStatusPosition(turnStatus);
230
281
  const contextWindow = contextWindowFromProjection(useProjection);
231
282
  const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
232
283
  if (!isCodexPresetId(agentPreset))
233
284
  return null;
234
- return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatus !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, t: t }), turnStatus, 'codex-activity')] }));
285
+ return (_jsxs(_Fragment, { children: [contextDialog !== null && createPortal(_jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }), contextDialog, 'codex-context-size'), turnStatusPosition !== null && typeof document !== 'undefined' && document.body !== null && createPortal(_jsx(ActivityLine, { sessionId: sessionId, useSession: useSession, useSessions: useSessions, useProjection: useProjection, t: t, position: turnStatusPosition }), document.body, 'codex-activity')] }));
235
286
  }
236
287
  export const inject = ['slots', 'locale', 'settingsScope'];
237
288
  /** Mount all controls through the official composer seats shared by every DSH release. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuind/dsh-codex-harness",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "A Codex harness with a streamlined system prompt for GPT models that do not fit DSH's native interface, while remaining compatible with the DSH plugin ecosystem.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -45,13 +45,6 @@
45
45
  "README.zh.md",
46
46
  "LICENSE"
47
47
  ],
48
- "scripts": {
49
- "build": "tsc --noCheck -p tsconfig.json && tsdown",
50
- "check": "tsc -p tsconfig.json --noEmit",
51
- "test": "vitest run",
52
- "pack:check": "npm pack --dry-run",
53
- "prepare": "npm run build"
54
- },
55
48
  "repository": {
56
49
  "type": "git",
57
50
  "url": "git+https://github.com/shuind/dsh-codex-harness.git"
@@ -239,5 +232,11 @@
239
232
  "typescript": "^6.0.3",
240
233
  "unrun": "^0.3.1",
241
234
  "vitest": "^4.1.8"
235
+ },
236
+ "scripts": {
237
+ "build": "tsc --noCheck -p tsconfig.json && tsdown",
238
+ "check": "tsc -p tsconfig.json --noEmit",
239
+ "test": "vitest run",
240
+ "pack:check": "npm pack --dry-run"
242
241
  }
243
- }
242
+ }