@shuind/dsh-codex-harness 0.2.11 → 0.2.12
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 +171 -60
- package/lib/types/client/index.js +117 -51
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -14,6 +14,11 @@ window.__ModuleLoader__.load({
|
|
|
14
14
|
/** User-selectable Codex context controls use whole K-token units. */
|
|
15
15
|
const CODEX_CONTEXT_UNIT = 1e3;
|
|
16
16
|
const CODEX_CONTEXT_MAX = 1e6;
|
|
17
|
+
const CODEX_PRESET_IDS = /* @__PURE__ */ new Set(["codex", "codex-collaboration"]);
|
|
18
|
+
/** The bundled preset and legacy Codex sessions share the same Web controls. */
|
|
19
|
+
function isCodexPresetId(value) {
|
|
20
|
+
return value !== void 0 && CODEX_PRESET_IDS.has(value);
|
|
21
|
+
}
|
|
17
22
|
//#endregion
|
|
18
23
|
//#region lib/types/prompt.js
|
|
19
24
|
/** Default plugin-owned Codex operating prompt. */
|
|
@@ -979,6 +984,139 @@ window.__ModuleLoader__.load({
|
|
|
979
984
|
]
|
|
980
985
|
});
|
|
981
986
|
}
|
|
987
|
+
/** Detect the host meter so the fallback does not duplicate its ring button. */
|
|
988
|
+
function hasHostContextMeter() {
|
|
989
|
+
if (typeof document === "undefined") return false;
|
|
990
|
+
return [...document.querySelectorAll("button[aria-haspopup=\"dialog\"]")].some((button) => button.querySelectorAll("circle").length >= 2);
|
|
991
|
+
}
|
|
992
|
+
function useHostContextMeter() {
|
|
993
|
+
const [available, setAvailable] = (0, react.useState)(false);
|
|
994
|
+
(0, react.useEffect)(() => {
|
|
995
|
+
if (typeof document === "undefined" || document.body === null) return void 0;
|
|
996
|
+
const refresh = () => {
|
|
997
|
+
setAvailable(hasHostContextMeter());
|
|
998
|
+
};
|
|
999
|
+
refresh();
|
|
1000
|
+
const observer = new MutationObserver(refresh);
|
|
1001
|
+
observer.observe(document.body, {
|
|
1002
|
+
subtree: true,
|
|
1003
|
+
childList: true,
|
|
1004
|
+
attributes: true,
|
|
1005
|
+
attributeFilter: ["aria-expanded"]
|
|
1006
|
+
});
|
|
1007
|
+
return () => observer.disconnect();
|
|
1008
|
+
}, []);
|
|
1009
|
+
return available;
|
|
1010
|
+
}
|
|
1011
|
+
/** Keep context configuration reachable before the host has a pressure meter. */
|
|
1012
|
+
function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
|
|
1013
|
+
const agentPreset = useSessions((state) => state.byId[sessionId]?.agentPreset);
|
|
1014
|
+
const hostMeter = useHostContextMeter();
|
|
1015
|
+
const contextWindow = contextWindowFromProjection(useProjection);
|
|
1016
|
+
const snapshot = useSettings((state) => state);
|
|
1017
|
+
const configured = snapshot.value?.contextWindow;
|
|
1018
|
+
const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
|
|
1019
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
1020
|
+
const rootRef = (0, react.useRef)(null);
|
|
1021
|
+
(0, react.useEffect)(() => {
|
|
1022
|
+
if (!open) return void 0;
|
|
1023
|
+
const onPointerDown = (event) => {
|
|
1024
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true) return;
|
|
1025
|
+
setOpen(false);
|
|
1026
|
+
};
|
|
1027
|
+
const onKeyDown = (event) => {
|
|
1028
|
+
if (event.key === "Escape") setOpen(false);
|
|
1029
|
+
};
|
|
1030
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
1031
|
+
document.addEventListener("keydown", onKeyDown);
|
|
1032
|
+
return () => {
|
|
1033
|
+
document.removeEventListener("pointerdown", onPointerDown);
|
|
1034
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
1035
|
+
};
|
|
1036
|
+
}, [open]);
|
|
1037
|
+
if (!isCodexPresetId(agentPreset) || hostMeter) return null;
|
|
1038
|
+
return (0, react_jsx_runtime.jsxs)("span", {
|
|
1039
|
+
ref: rootRef,
|
|
1040
|
+
style: {
|
|
1041
|
+
position: "relative",
|
|
1042
|
+
display: "inline-flex",
|
|
1043
|
+
alignItems: "center"
|
|
1044
|
+
},
|
|
1045
|
+
children: [(0, react_jsx_runtime.jsxs)("button", {
|
|
1046
|
+
type: "button",
|
|
1047
|
+
"aria-label": `${t("contextSize")}: ${valueK}K`,
|
|
1048
|
+
"aria-haspopup": "dialog",
|
|
1049
|
+
"aria-expanded": open,
|
|
1050
|
+
disabled: snapshot.writable === false,
|
|
1051
|
+
title: t("contextSize"),
|
|
1052
|
+
onMouseDown: (event) => {
|
|
1053
|
+
event.preventDefault();
|
|
1054
|
+
},
|
|
1055
|
+
onClick: () => {
|
|
1056
|
+
setOpen((value) => !value);
|
|
1057
|
+
},
|
|
1058
|
+
style: {
|
|
1059
|
+
boxSizing: "border-box",
|
|
1060
|
+
display: "inline-flex",
|
|
1061
|
+
alignItems: "center",
|
|
1062
|
+
gap: 3,
|
|
1063
|
+
height: 28,
|
|
1064
|
+
border: 0,
|
|
1065
|
+
borderRadius: 7,
|
|
1066
|
+
padding: "0 6px",
|
|
1067
|
+
color: configured === void 0 ? "var(--dsw-alias-label-secondary)" : "var(--dsw-static-blue-500)",
|
|
1068
|
+
background: open ? "var(--dsw-alias-interactive-bg-hover)" : "transparent",
|
|
1069
|
+
cursor: snapshot.writable === false ? "default" : "pointer",
|
|
1070
|
+
font: "inherit",
|
|
1071
|
+
fontSize: 12,
|
|
1072
|
+
lineHeight: "20px",
|
|
1073
|
+
fontWeight: configured === void 0 ? 400 : 600,
|
|
1074
|
+
whiteSpace: "nowrap"
|
|
1075
|
+
},
|
|
1076
|
+
children: [(0, react_jsx_runtime.jsxs)("span", { children: [valueK, "K"] }), (0, react_jsx_runtime.jsx)("svg", {
|
|
1077
|
+
viewBox: "0 0 12 12",
|
|
1078
|
+
width: "12",
|
|
1079
|
+
height: "12",
|
|
1080
|
+
"aria-hidden": true,
|
|
1081
|
+
children: (0, react_jsx_runtime.jsx)("path", {
|
|
1082
|
+
d: "M3 4.5 6 7.5 9 4.5",
|
|
1083
|
+
fill: "none",
|
|
1084
|
+
stroke: "currentColor",
|
|
1085
|
+
strokeWidth: "1.25",
|
|
1086
|
+
strokeLinecap: "round",
|
|
1087
|
+
strokeLinejoin: "round"
|
|
1088
|
+
})
|
|
1089
|
+
})]
|
|
1090
|
+
}), open && (0, react_jsx_runtime.jsx)("div", {
|
|
1091
|
+
role: "dialog",
|
|
1092
|
+
"aria-label": t("contextSize"),
|
|
1093
|
+
style: {
|
|
1094
|
+
position: "absolute",
|
|
1095
|
+
right: 0,
|
|
1096
|
+
bottom: "calc(100% + 8px)",
|
|
1097
|
+
zIndex: 20,
|
|
1098
|
+
boxSizing: "border-box",
|
|
1099
|
+
width: 300,
|
|
1100
|
+
maxWidth: "calc(100vw - 24px)",
|
|
1101
|
+
padding: "10px 12px 12px",
|
|
1102
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
1103
|
+
borderRadius: 10,
|
|
1104
|
+
color: "var(--dsw-alias-label-primary)",
|
|
1105
|
+
background: "var(--dsw-alias-bg-base)",
|
|
1106
|
+
boxShadow: "var(--dsw-shadow-lv2)"
|
|
1107
|
+
},
|
|
1108
|
+
children: (0, react_jsx_runtime.jsx)(ContextSizeControl, {
|
|
1109
|
+
contextWindow,
|
|
1110
|
+
sessionId,
|
|
1111
|
+
useSessions,
|
|
1112
|
+
useSettings,
|
|
1113
|
+
setSetting,
|
|
1114
|
+
unsetSetting,
|
|
1115
|
+
t
|
|
1116
|
+
})
|
|
1117
|
+
})]
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
982
1120
|
function elapsedSeconds(startedAt, now) {
|
|
983
1121
|
return Math.max(0, Math.floor((now - startedAt) / 1e3));
|
|
984
1122
|
}
|
|
@@ -1080,57 +1218,13 @@ window.__ModuleLoader__.load({
|
|
|
1080
1218
|
const preferred = statuses.filter(isTurnStatus);
|
|
1081
1219
|
return preferred.findLast(hasLayout) ?? preferred.at(-1) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).findLast(hasLayout) ?? statuses.filter((status) => status.closest("[data-chat-flow]") !== null).at(-1) ?? null;
|
|
1082
1220
|
}
|
|
1083
|
-
function findTurnStatus() {
|
|
1084
|
-
return selectTurnStatus([...document.querySelectorAll("[role=\"status\"]")]);
|
|
1085
|
-
}
|
|
1086
|
-
function useTurnStatusPosition(target) {
|
|
1087
|
-
const [position, setPosition] = (0, react.useState)(null);
|
|
1088
|
-
(0, react.useLayoutEffect)(() => {
|
|
1089
|
-
if (target === null) {
|
|
1090
|
-
setPosition(null);
|
|
1091
|
-
return;
|
|
1092
|
-
}
|
|
1093
|
-
const update = () => {
|
|
1094
|
-
if (!target.isConnected) {
|
|
1095
|
-
setPosition(null);
|
|
1096
|
-
return;
|
|
1097
|
-
}
|
|
1098
|
-
const rect = target.getBoundingClientRect();
|
|
1099
|
-
if (rect.width === 0 && rect.height === 0) {
|
|
1100
|
-
setPosition(null);
|
|
1101
|
-
return;
|
|
1102
|
-
}
|
|
1103
|
-
setPosition({
|
|
1104
|
-
left: Math.round(rect.right + 10),
|
|
1105
|
-
top: Math.round(rect.top + (rect.height - 26) / 2)
|
|
1106
|
-
});
|
|
1107
|
-
};
|
|
1108
|
-
update();
|
|
1109
|
-
window.addEventListener("resize", update);
|
|
1110
|
-
window.addEventListener("scroll", update, true);
|
|
1111
|
-
const observer = typeof ResizeObserver === "undefined" ? void 0 : new ResizeObserver(update);
|
|
1112
|
-
observer?.observe(target);
|
|
1113
|
-
return () => {
|
|
1114
|
-
window.removeEventListener("resize", update);
|
|
1115
|
-
window.removeEventListener("scroll", update, true);
|
|
1116
|
-
observer?.disconnect();
|
|
1117
|
-
};
|
|
1118
|
-
}, [target]);
|
|
1119
|
-
return position;
|
|
1120
|
-
}
|
|
1121
1221
|
function useLegacyHostTargets() {
|
|
1122
|
-
const [targets, setTargets] = (0, react.useState)({
|
|
1123
|
-
contextDialog: null,
|
|
1124
|
-
turnStatus: null
|
|
1125
|
-
});
|
|
1222
|
+
const [targets, setTargets] = (0, react.useState)({ contextDialog: null });
|
|
1126
1223
|
(0, react.useEffect)(() => {
|
|
1127
1224
|
if (typeof document === "undefined" || document.body === null) return void 0;
|
|
1128
1225
|
const refresh = () => {
|
|
1129
|
-
const next = {
|
|
1130
|
-
|
|
1131
|
-
turnStatus: findTurnStatus()
|
|
1132
|
-
};
|
|
1133
|
-
setTargets((current) => current.contextDialog === next.contextDialog && current.turnStatus === next.turnStatus ? current : next);
|
|
1226
|
+
const next = { contextDialog: findContextMeterDialog() };
|
|
1227
|
+
setTargets((current) => current.contextDialog === next.contextDialog ? current : next);
|
|
1134
1228
|
};
|
|
1135
1229
|
refresh();
|
|
1136
1230
|
const observer = new MutationObserver(refresh);
|
|
@@ -1146,11 +1240,10 @@ window.__ModuleLoader__.load({
|
|
|
1146
1240
|
}
|
|
1147
1241
|
/** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
|
|
1148
1242
|
function LegacyOverlay(props) {
|
|
1149
|
-
const { sessionId,
|
|
1150
|
-
const { contextDialog
|
|
1151
|
-
const turnStatusPosition = useTurnStatusPosition(turnStatus);
|
|
1243
|
+
const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t } = props;
|
|
1244
|
+
const { contextDialog } = useLegacyHostTargets();
|
|
1152
1245
|
const contextWindow = contextWindowFromProjection(useProjection);
|
|
1153
|
-
return (0, react_jsx_runtime.
|
|
1246
|
+
return (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: contextDialog !== null && (0, react_dom.createPortal)((0, react_jsx_runtime.jsx)(ContextSizeControl, {
|
|
1154
1247
|
contextWindow,
|
|
1155
1248
|
sessionId,
|
|
1156
1249
|
useSessions,
|
|
@@ -1158,15 +1251,19 @@ window.__ModuleLoader__.load({
|
|
|
1158
1251
|
setSetting,
|
|
1159
1252
|
unsetSetting,
|
|
1160
1253
|
t
|
|
1161
|
-
}), contextDialog, "codex-context-size")
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1254
|
+
}), contextDialog, "codex-context-size") });
|
|
1255
|
+
}
|
|
1256
|
+
/** Stable composer fallback for hosts whose transient turn-status node is absent. */
|
|
1257
|
+
function ActivityDock(props) {
|
|
1258
|
+
return (0, react_jsx_runtime.jsx)("div", {
|
|
1259
|
+
style: {
|
|
1260
|
+
display: "flex",
|
|
1261
|
+
alignItems: "center",
|
|
1262
|
+
minHeight: 28,
|
|
1263
|
+
padding: "4px 10px"
|
|
1264
|
+
},
|
|
1265
|
+
children: (0, react_jsx_runtime.jsx)(ActivityLine, { ...props })
|
|
1266
|
+
});
|
|
1170
1267
|
}
|
|
1171
1268
|
const inject = [
|
|
1172
1269
|
"commandUi",
|
|
@@ -1221,6 +1318,20 @@ window.__ModuleLoader__.load({
|
|
|
1221
1318
|
locale: NS,
|
|
1222
1319
|
inject: injected
|
|
1223
1320
|
}, FastModeFallback));
|
|
1321
|
+
ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
|
|
1322
|
+
name: FAST_FALLBACK_SLOT,
|
|
1323
|
+
id: "codex-context-size-fallback",
|
|
1324
|
+
order: 1,
|
|
1325
|
+
locale: NS,
|
|
1326
|
+
inject: injected
|
|
1327
|
+
}, ContextSizeFallback));
|
|
1328
|
+
ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
|
|
1329
|
+
name: "conversation.composer.dock",
|
|
1330
|
+
id: "codex-activity-fallback",
|
|
1331
|
+
order: 5,
|
|
1332
|
+
locale: NS,
|
|
1333
|
+
inject: injected
|
|
1334
|
+
}, ActivityDock));
|
|
1224
1335
|
ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
|
|
1225
1336
|
name: LEGACY_OVERLAY_SLOT,
|
|
1226
1337
|
id: "codex-legacy-overlay",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/** Browser controls for Codex requests and the editable operating prompt. */
|
|
3
|
-
import { useEffect,
|
|
3
|
+
import { useEffect, useRef, useState } from 'react';
|
|
4
4
|
import { createPortal } from 'react-dom';
|
|
5
|
-
import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT } from "../context.js";
|
|
5
|
+
import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
|
|
6
6
|
import { DEFAULT_CODEX_PERSONA, DEFAULT_CODEX_SYSTEM_PROMPT, DEFAULT_DSH_CORE_SOURCE_PROMPT, DEFAULT_DSH_CORE_WEB_PROMPT, } from "../prompt.js";
|
|
7
7
|
import { modelActivity, sameModelActivity } from "./activity.js";
|
|
8
8
|
const NS = 'codex';
|
|
@@ -412,6 +412,97 @@ function ContextSizeControl({ contextWindow, sessionId: _sessionId, useSessions:
|
|
|
412
412
|
fontSize: 11,
|
|
413
413
|
}, children: t('contextRestore') }))] }));
|
|
414
414
|
}
|
|
415
|
+
/** Detect the host meter so the fallback does not duplicate its ring button. */
|
|
416
|
+
function hasHostContextMeter() {
|
|
417
|
+
if (typeof document === 'undefined')
|
|
418
|
+
return false;
|
|
419
|
+
return [...document.querySelectorAll('button[aria-haspopup="dialog"]')]
|
|
420
|
+
.some(button => button.querySelectorAll('circle').length >= 2);
|
|
421
|
+
}
|
|
422
|
+
function useHostContextMeter() {
|
|
423
|
+
const [available, setAvailable] = useState(false);
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
if (typeof document === 'undefined' || document.body === null)
|
|
426
|
+
return undefined;
|
|
427
|
+
const refresh = () => { setAvailable(hasHostContextMeter()); };
|
|
428
|
+
refresh();
|
|
429
|
+
const observer = new MutationObserver(refresh);
|
|
430
|
+
observer.observe(document.body, {
|
|
431
|
+
subtree: true,
|
|
432
|
+
childList: true,
|
|
433
|
+
attributes: true,
|
|
434
|
+
attributeFilter: ['aria-expanded'],
|
|
435
|
+
});
|
|
436
|
+
return () => observer.disconnect();
|
|
437
|
+
}, []);
|
|
438
|
+
return available;
|
|
439
|
+
}
|
|
440
|
+
/** Keep context configuration reachable before the host has a pressure meter. */
|
|
441
|
+
function ContextSizeFallback({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, }) {
|
|
442
|
+
const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
|
|
443
|
+
const hostMeter = useHostContextMeter();
|
|
444
|
+
const contextWindow = contextWindowFromProjection(useProjection);
|
|
445
|
+
const snapshot = useSettings(state => state);
|
|
446
|
+
const configured = snapshot.value?.contextWindow;
|
|
447
|
+
const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
|
|
448
|
+
const [open, setOpen] = useState(false);
|
|
449
|
+
const rootRef = useRef(null);
|
|
450
|
+
useEffect(() => {
|
|
451
|
+
if (!open)
|
|
452
|
+
return undefined;
|
|
453
|
+
const onPointerDown = (event) => {
|
|
454
|
+
if (event.target instanceof Node && rootRef.current?.contains(event.target) === true)
|
|
455
|
+
return;
|
|
456
|
+
setOpen(false);
|
|
457
|
+
};
|
|
458
|
+
const onKeyDown = (event) => {
|
|
459
|
+
if (event.key === 'Escape')
|
|
460
|
+
setOpen(false);
|
|
461
|
+
};
|
|
462
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
463
|
+
document.addEventListener('keydown', onKeyDown);
|
|
464
|
+
return () => {
|
|
465
|
+
document.removeEventListener('pointerdown', onPointerDown);
|
|
466
|
+
document.removeEventListener('keydown', onKeyDown);
|
|
467
|
+
};
|
|
468
|
+
}, [open]);
|
|
469
|
+
if (!isCodexPresetId(agentPreset) || hostMeter)
|
|
470
|
+
return null;
|
|
471
|
+
return (_jsxs("span", { ref: rootRef, style: { position: 'relative', display: 'inline-flex', alignItems: 'center' }, children: [_jsxs("button", { type: "button", "aria-label": `${t('contextSize')}: ${valueK}K`, "aria-haspopup": "dialog", "aria-expanded": open, disabled: snapshot.writable === false, title: t('contextSize'), onMouseDown: event => { event.preventDefault(); }, onClick: () => { setOpen(value => !value); }, style: {
|
|
472
|
+
boxSizing: 'border-box',
|
|
473
|
+
display: 'inline-flex',
|
|
474
|
+
alignItems: 'center',
|
|
475
|
+
gap: 3,
|
|
476
|
+
height: 28,
|
|
477
|
+
border: 0,
|
|
478
|
+
borderRadius: 7,
|
|
479
|
+
padding: '0 6px',
|
|
480
|
+
color: configured === undefined
|
|
481
|
+
? 'var(--dsw-alias-label-secondary)'
|
|
482
|
+
: 'var(--dsw-static-blue-500)',
|
|
483
|
+
background: open ? 'var(--dsw-alias-interactive-bg-hover)' : 'transparent',
|
|
484
|
+
cursor: snapshot.writable === false ? 'default' : 'pointer',
|
|
485
|
+
font: 'inherit',
|
|
486
|
+
fontSize: 12,
|
|
487
|
+
lineHeight: '20px',
|
|
488
|
+
fontWeight: configured === undefined ? 400 : 600,
|
|
489
|
+
whiteSpace: 'nowrap',
|
|
490
|
+
}, children: [_jsxs("span", { children: [valueK, "K"] }), _jsx("svg", { viewBox: "0 0 12 12", width: "12", height: "12", "aria-hidden": true, children: _jsx("path", { d: "M3 4.5 6 7.5 9 4.5", fill: "none", stroke: "currentColor", strokeWidth: "1.25", strokeLinecap: "round", strokeLinejoin: "round" }) })] }), open && (_jsx("div", { role: "dialog", "aria-label": t('contextSize'), style: {
|
|
491
|
+
position: 'absolute',
|
|
492
|
+
right: 0,
|
|
493
|
+
bottom: 'calc(100% + 8px)',
|
|
494
|
+
zIndex: 20,
|
|
495
|
+
boxSizing: 'border-box',
|
|
496
|
+
width: 300,
|
|
497
|
+
maxWidth: 'calc(100vw - 24px)',
|
|
498
|
+
padding: '10px 12px 12px',
|
|
499
|
+
border: '1px solid var(--dsw-alias-border-l2)',
|
|
500
|
+
borderRadius: 10,
|
|
501
|
+
color: 'var(--dsw-alias-label-primary)',
|
|
502
|
+
background: 'var(--dsw-alias-bg-base)',
|
|
503
|
+
boxShadow: 'var(--dsw-shadow-lv2)',
|
|
504
|
+
}, children: _jsx(ContextSizeControl, { contextWindow: contextWindow, sessionId: sessionId, useSessions: useSessions, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }) }))] }));
|
|
505
|
+
}
|
|
415
506
|
function elapsedSeconds(startedAt, now) {
|
|
416
507
|
return Math.max(0, Math.floor((now - startedAt) / 1_000));
|
|
417
508
|
}
|
|
@@ -511,56 +602,14 @@ export function selectTurnStatus(statuses) {
|
|
|
511
602
|
?? statuses.filter(status => status.closest('[data-chat-flow]') !== null).at(-1)
|
|
512
603
|
?? null;
|
|
513
604
|
}
|
|
514
|
-
function findTurnStatus() {
|
|
515
|
-
return selectTurnStatus([...document.querySelectorAll('[role="status"]')]);
|
|
516
|
-
}
|
|
517
|
-
function useTurnStatusPosition(target) {
|
|
518
|
-
const [position, setPosition] = useState(null);
|
|
519
|
-
useLayoutEffect(() => {
|
|
520
|
-
if (target === null) {
|
|
521
|
-
setPosition(null);
|
|
522
|
-
return undefined;
|
|
523
|
-
}
|
|
524
|
-
const update = () => {
|
|
525
|
-
if (!target.isConnected) {
|
|
526
|
-
setPosition(null);
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const rect = target.getBoundingClientRect();
|
|
530
|
-
if (rect.width === 0 && rect.height === 0) {
|
|
531
|
-
setPosition(null);
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
setPosition({
|
|
535
|
-
left: Math.round(rect.right + 10),
|
|
536
|
-
top: Math.round(rect.top + (rect.height - 26) / 2),
|
|
537
|
-
});
|
|
538
|
-
};
|
|
539
|
-
update();
|
|
540
|
-
window.addEventListener('resize', update);
|
|
541
|
-
window.addEventListener('scroll', update, true);
|
|
542
|
-
const observer = typeof ResizeObserver === 'undefined' ? undefined : new ResizeObserver(update);
|
|
543
|
-
observer?.observe(target);
|
|
544
|
-
return () => {
|
|
545
|
-
window.removeEventListener('resize', update);
|
|
546
|
-
window.removeEventListener('scroll', update, true);
|
|
547
|
-
observer?.disconnect();
|
|
548
|
-
};
|
|
549
|
-
}, [target]);
|
|
550
|
-
return position;
|
|
551
|
-
}
|
|
552
605
|
function useLegacyHostTargets() {
|
|
553
|
-
const [targets, setTargets] = useState({ contextDialog: null
|
|
606
|
+
const [targets, setTargets] = useState({ contextDialog: null });
|
|
554
607
|
useEffect(() => {
|
|
555
608
|
if (typeof document === 'undefined' || document.body === null)
|
|
556
609
|
return undefined;
|
|
557
610
|
const refresh = () => {
|
|
558
|
-
const next = {
|
|
559
|
-
|
|
560
|
-
turnStatus: findTurnStatus(),
|
|
561
|
-
};
|
|
562
|
-
setTargets(current => current.contextDialog === next.contextDialog
|
|
563
|
-
&& current.turnStatus === next.turnStatus ? current : next);
|
|
611
|
+
const next = { contextDialog: findContextMeterDialog() };
|
|
612
|
+
setTargets(current => current.contextDialog === next.contextDialog ? current : next);
|
|
564
613
|
};
|
|
565
614
|
refresh();
|
|
566
615
|
const observer = new MutationObserver(refresh);
|
|
@@ -576,11 +625,14 @@ function useLegacyHostTargets() {
|
|
|
576
625
|
}
|
|
577
626
|
/** Bridges plugin UI into DOM sites rendered by the legacy conversation host. */
|
|
578
627
|
function LegacyOverlay(props) {
|
|
579
|
-
const { sessionId,
|
|
580
|
-
const { contextDialog
|
|
581
|
-
const turnStatusPosition = useTurnStatusPosition(turnStatus);
|
|
628
|
+
const { sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t, } = props;
|
|
629
|
+
const { contextDialog } = useLegacyHostTargets();
|
|
582
630
|
const contextWindow = contextWindowFromProjection(useProjection);
|
|
583
|
-
return (
|
|
631
|
+
return (_jsx(_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') }));
|
|
632
|
+
}
|
|
633
|
+
/** Stable composer fallback for hosts whose transient turn-status node is absent. */
|
|
634
|
+
function ActivityDock(props) {
|
|
635
|
+
return (_jsx("div", { style: { display: 'flex', alignItems: 'center', minHeight: 28, padding: '4px 10px' }, children: _jsx(ActivityLine, { ...props }) }));
|
|
584
636
|
}
|
|
585
637
|
export const inject = ['commandUi', 'sessions', 'slots', 'locale', 'settingsScope'];
|
|
586
638
|
/** Mount request controls and the plugin settings card through shared slots. */
|
|
@@ -624,6 +676,20 @@ export function apply(ctx) {
|
|
|
624
676
|
locale: NS,
|
|
625
677
|
inject: injected,
|
|
626
678
|
}, FastModeFallback));
|
|
679
|
+
ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
|
|
680
|
+
name: FAST_FALLBACK_SLOT,
|
|
681
|
+
id: 'codex-context-size-fallback',
|
|
682
|
+
order: 1,
|
|
683
|
+
locale: NS,
|
|
684
|
+
inject: injected,
|
|
685
|
+
}, ContextSizeFallback));
|
|
686
|
+
ctx.slots.inject('conversation.composer.dock', () => ctx.slots.register({
|
|
687
|
+
name: 'conversation.composer.dock',
|
|
688
|
+
id: 'codex-activity-fallback',
|
|
689
|
+
order: 5,
|
|
690
|
+
locale: NS,
|
|
691
|
+
inject: injected,
|
|
692
|
+
}, ActivityDock));
|
|
627
693
|
ctx.slots.inject(LEGACY_OVERLAY_SLOT, () => ctx.slots.register({
|
|
628
694
|
name: LEGACY_OVERLAY_SLOT,
|
|
629
695
|
id: 'codex-legacy-overlay',
|