@shuind/dsh-codex-harness 0.1.26 → 0.1.28

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.
@@ -8,7 +8,7 @@ declare const en: {
8
8
  readonly fastStateOn: "On";
9
9
  readonly fastStateOff: "Off";
10
10
  readonly contextSize: "Context size";
11
- readonly contextSizeDescription: "Next request capacity in K tokens. The meter above is current.";
11
+ readonly contextSizeDescription: "Next request capacity in K tokens.";
12
12
  readonly contextRestore: "Restore model default";
13
13
  readonly activityCompacting: "Compacting context...";
14
14
  readonly activityRequestingModel: "Requesting model...";
@@ -19,27 +19,12 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
19
19
  interface LocaleNamespaceMap {
20
20
  codex: CodexKey;
21
21
  }
22
- interface SlotMap {
23
- 'conversation.input.model.settings': {
24
- kind: 'list';
25
- scope: 'session';
26
- };
27
- 'conversation.input.context.settings': {
28
- kind: 'list';
29
- scope: 'session';
30
- owner: {
31
- contextWindow: number;
32
- };
33
- };
34
- }
35
22
  }
36
23
  type ActivityDockProps = PropsRuntime<'conversation.composer.dock'> & PropsLocale<'codex'>;
37
24
  type ActivityProps = ActivityDockProps;
38
25
  export declare function ActivityLine({ sessionId, useSession, useSessions, useProjection, t }: ActivityProps): import("react").JSX.Element | null;
39
26
  export declare const inject: string[];
40
- /** Select a preferred slot when the host declares it, otherwise use a stable legacy composer seat. */
41
- export declare function chooseDeclaredSlot(preferred: string, fallback: string, isDeclared: (slot: string) => boolean): string;
42
- /** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
27
+ /** Mount all controls through the official composer seats shared by every DSH release. */
43
28
  export declare function apply(ctx: Context): void;
44
29
  declare const _default: {
45
30
  inject: string[];
@@ -1,18 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } 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, useRef, useState } from 'react';
4
4
  import { CODEX_CONTEXT_MAX, CODEX_CONTEXT_UNIT, isCodexPresetId } from "../context.js";
5
5
  import { modelActivity, sameModelActivity } from "./activity.js";
6
6
  const NS = 'codex';
7
7
  const SETTINGS_NAMESPACE = 'codex';
8
- const MODEL_SETTINGS_SLOT = 'conversation.input.model.settings';
9
- const CONTEXT_SETTINGS_SLOT = 'conversation.input.context.settings';
10
- // Prefer a dedicated status seat when a newer host declares it; the current
11
- // conversation contract falls back to the ambient composer dock below.
12
- const ACTIVITY_SLOT = 'conversation.chat.status';
13
8
  const ACTIVITY_FALLBACK_SLOT = 'conversation.composer.dock';
14
9
  const FAST_FALLBACK_SLOT = 'conversation.input.right';
15
- const CONTEXT_FALLBACK_SLOT = 'conversation.input.dock';
10
+ const CONTEXT_FALLBACK_SLOT = 'conversation.input.right';
16
11
  const DEFAULT_CONTEXT_WINDOW = 262_144;
17
12
  const en = {
18
13
  fast: 'Fast mode',
@@ -21,7 +16,7 @@ const en = {
21
16
  fastStateOn: 'On',
22
17
  fastStateOff: 'Off',
23
18
  contextSize: 'Context size',
24
- contextSizeDescription: 'Next request capacity in K tokens. The meter above is current.',
19
+ contextSizeDescription: 'Next request capacity in K tokens.',
25
20
  contextRestore: 'Restore model default',
26
21
  activityCompacting: 'Compacting context...',
27
22
  activityRequestingModel: 'Requesting model...',
@@ -34,38 +29,12 @@ const zh = {
34
29
  fastStateOn: '开',
35
30
  fastStateOff: '关',
36
31
  contextSize: '上下文大小',
37
- contextSizeDescription: '设置下次请求的上下文容量,单位为 K tokens;上方是当前请求。',
32
+ contextSizeDescription: '设置下次请求的上下文容量,单位为 K tokens。',
38
33
  contextRestore: '恢复模型默认值',
39
34
  activityCompacting: '正在压缩上下文...',
40
- activityRequestingModel: '请求模型...',
41
- activityModelReply: '模型回复...',
35
+ activityRequestingModel: '请求中...',
36
+ activityModelReply: '回复中...',
42
37
  };
43
- function FastModeButton({ sessionId, useSessions, useSettings, setSetting, t }) {
44
- const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
45
- const snapshot = useSettings(state => state);
46
- const fast = snapshot.value?.fast ?? false;
47
- if (!isCodexPresetId(agentPreset))
48
- return null;
49
- return (_jsxs("button", { type: "button", role: "menuitemcheckbox", disabled: snapshot.writable === false, "aria-pressed": fast, "aria-label": fast ? t('fastOn') : t('fastOff'), title: fast ? t('fastOn') : t('fastOff'), onClick: () => { void setSetting('fast', !fast); }, style: {
50
- boxSizing: 'border-box',
51
- display: 'flex',
52
- alignItems: 'center',
53
- justifyContent: 'space-between',
54
- width: '100%',
55
- height: 40,
56
- border: 0,
57
- borderRadius: 10,
58
- padding: '0 10px',
59
- color: fast ? 'var(--dsw-static-blue-500)' : 'var(--dsw-alias-label-secondary)',
60
- background: fast ? 'var(--dsw-alias-interactive-bg-selected)' : 'transparent',
61
- cursor: snapshot.writable === false ? 'default' : 'pointer',
62
- font: 'inherit',
63
- fontSize: 14,
64
- lineHeight: '22px',
65
- fontWeight: fast ? 600 : 400,
66
- textAlign: 'left',
67
- }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 12 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
68
- }
69
38
  /** The legacy composer seat is a compact inline row, not a menu panel. */
70
39
  function FastModeFallback(props) {
71
40
  const { sessionId, useSessions, useSettings, setSetting, t } = props;
@@ -80,9 +49,9 @@ function FastModeFallback(props) {
80
49
  alignItems: 'center',
81
50
  gap: 5,
82
51
  height: 28,
83
- border: '1px solid var(--dsw-alias-border-primary)',
52
+ border: 0,
84
53
  borderRadius: 7,
85
- padding: '0 8px',
54
+ padding: '0 6px',
86
55
  color: fast ? 'var(--dsw-static-blue-500)' : 'var(--dsw-alias-label-secondary)',
87
56
  background: fast ? 'var(--dsw-alias-interactive-bg-selected)' : 'transparent',
88
57
  cursor: snapshot.writable === false ? 'default' : 'pointer',
@@ -93,7 +62,14 @@ function FastModeFallback(props) {
93
62
  whiteSpace: 'nowrap',
94
63
  }, children: [_jsx("span", { children: t('fast') }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11 }, children: fast ? t('fastStateOn') : t('fastStateOff') })] }));
95
64
  }
96
- function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t }) {
65
+ function contextWindowFromProjection(useProjection) {
66
+ const pressure = useProjection('contextPressure');
67
+ return pressure?.contextWindow !== undefined && pressure.contextWindow > 0
68
+ ? pressure.contextWindow
69
+ : DEFAULT_CONTEXT_WINDOW;
70
+ }
71
+ /** Settings form kept inside the official composer slot's popover. */
72
+ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetting, t, }) {
97
73
  const snapshot = useSettings(state => state);
98
74
  const configured = snapshot.value?.contextWindow;
99
75
  const maxK = CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT;
@@ -108,16 +84,21 @@ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetti
108
84
  else
109
85
  void setSetting('contextWindow', normalized);
110
86
  };
111
- return (_jsxs("div", { style: { marginTop: 10, display: 'grid', gap: 5 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [_jsx("strong", { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 12 }, children: t('contextSize') }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: [valueK, "K"] })] }), _jsx("input", { type: "range", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); } }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 7 }, children: [_jsx("input", { type: "number", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
112
- width: 76,
113
- border: '1px solid var(--dsw-alias-border-primary)',
114
- borderRadius: 5,
115
- padding: '3px 5px',
116
- color: 'var(--dsw-alias-label-primary)',
117
- background: 'var(--dsw-alias-fill-primary)',
118
- font: 'inherit',
119
- fontSize: 11,
120
- } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
87
+ return (_jsxs("div", { style: { marginTop: 0, display: 'grid', gap: 8 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'baseline', justifyContent: 'space-between', gap: 12 }, children: [_jsx("strong", { style: { color: 'var(--dsw-alias-label-primary)', fontSize: 13 }, children: t('contextSize') }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 12, fontVariantNumeric: 'tabular-nums' }, children: [valueK, "K"] })] }), _jsx("input", { type: "range", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
88
+ display: 'block',
89
+ width: '100%',
90
+ accentColor: 'var(--dsw-static-blue-500)',
91
+ } }), _jsxs("div", { style: { display: 'grid', gap: 4 }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 6 }, children: [_jsx("input", { type: "number", min: 1, max: maxK, step: 1, value: valueK, disabled: snapshot.writable === false, "aria-label": t('contextSize'), onChange: event => { setValueK(Number(event.target.value)); }, style: {
92
+ width: 68,
93
+ border: '1px solid var(--dsw-alias-border-primary)',
94
+ borderRadius: 6,
95
+ padding: '4px 6px',
96
+ color: 'var(--dsw-alias-label-primary)',
97
+ background: 'var(--dsw-alias-fill-primary)',
98
+ font: 'inherit',
99
+ fontSize: 12,
100
+ fontVariantNumeric: 'tabular-nums',
101
+ } }), _jsx("span", { style: { color: 'var(--dsw-alias-label-secondary)', fontSize: 11 }, children: "K" })] }), _jsx("span", { style: { color: 'var(--dsw-alias-label-tertiary)', fontSize: 11, lineHeight: '16px' }, children: t('contextSizeDescription') })] }), configured !== undefined && (_jsx("button", { type: "button", onClick: () => { void unsetSetting('contextWindow'); }, style: {
121
102
  justifySelf: 'start',
122
103
  border: 0,
123
104
  padding: 0,
@@ -128,14 +109,70 @@ function ContextSizeControl({ contextWindow, useSettings, setSetting, unsetSetti
128
109
  fontSize: 11,
129
110
  }, children: t('contextRestore') }))] }));
130
111
  }
131
- function contextWindowFromProjection(useProjection) {
132
- const pressure = useProjection('contextPressure');
133
- return pressure?.contextWindow !== undefined && pressure.contextWindow > 0
134
- ? pressure.contextWindow
135
- : DEFAULT_CONTEXT_WINDOW;
136
- }
137
- function LegacyContextSizeControl({ useProjection, ...props }) {
138
- return _jsx(ContextSizeControl, { ...props, contextWindow: contextWindowFromProjection(useProjection) });
112
+ /** Compact trigger used when the host has no ContextMeter settings child slot. */
113
+ function LegacyContextSizeControl({ sessionId, useSessions, useProjection, useSettings, setSetting, unsetSetting, t }) {
114
+ const agentPreset = useSessions(state => state.byId[sessionId]?.agentPreset);
115
+ const contextWindow = contextWindowFromProjection(useProjection);
116
+ const snapshot = useSettings(state => state);
117
+ const configured = snapshot.value?.contextWindow;
118
+ const valueK = Math.min(CODEX_CONTEXT_MAX / CODEX_CONTEXT_UNIT, Math.max(1, Math.round((configured ?? contextWindow) / CODEX_CONTEXT_UNIT)));
119
+ const [open, setOpen] = useState(false);
120
+ const rootRef = useRef(null);
121
+ useEffect(() => {
122
+ if (!open)
123
+ return undefined;
124
+ const onPointerDown = (event) => {
125
+ if (event.target instanceof Node && rootRef.current?.contains(event.target) === true)
126
+ return;
127
+ setOpen(false);
128
+ };
129
+ const onKeyDown = (event) => {
130
+ if (event.key === 'Escape')
131
+ setOpen(false);
132
+ };
133
+ document.addEventListener('pointerdown', onPointerDown);
134
+ document.addEventListener('keydown', onKeyDown);
135
+ return () => {
136
+ document.removeEventListener('pointerdown', onPointerDown);
137
+ document.removeEventListener('keydown', onKeyDown);
138
+ };
139
+ }, [open]);
140
+ if (!isCodexPresetId(agentPreset))
141
+ return null;
142
+ 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: {
143
+ boxSizing: 'border-box',
144
+ display: 'inline-flex',
145
+ alignItems: 'center',
146
+ gap: 3,
147
+ height: 28,
148
+ border: 0,
149
+ borderRadius: 7,
150
+ padding: '0 6px',
151
+ color: configured === undefined
152
+ ? 'var(--dsw-alias-label-secondary)'
153
+ : 'var(--dsw-static-blue-500)',
154
+ background: open ? 'var(--dsw-alias-interactive-bg-hover)' : 'transparent',
155
+ cursor: snapshot.writable === false ? 'default' : 'pointer',
156
+ font: 'inherit',
157
+ fontSize: 12,
158
+ lineHeight: '20px',
159
+ fontWeight: configured === undefined ? 400 : 600,
160
+ whiteSpace: 'nowrap',
161
+ }, 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: {
162
+ position: 'absolute',
163
+ right: 0,
164
+ bottom: 'calc(100% + 8px)',
165
+ zIndex: 20,
166
+ boxSizing: 'border-box',
167
+ width: 300,
168
+ maxWidth: 'calc(100vw - 24px)',
169
+ padding: '10px 12px 12px',
170
+ border: '1px solid var(--dsw-alias-border-l2)',
171
+ borderRadius: 10,
172
+ color: 'var(--dsw-alias-label-primary)',
173
+ background: 'var(--dsw-alias-bg-base)',
174
+ boxShadow: 'var(--dsw-shadow-lv2)',
175
+ }, children: _jsx(ContextSizeControl, { contextWindow: contextWindow, useSettings: useSettings, setSetting: setSetting, unsetSetting: unsetSetting, t: t }) }))] }));
139
176
  }
140
177
  function elapsedSeconds(startedAt, now) {
141
178
  return Math.max(0, Math.floor((now - startedAt) / 1_000));
@@ -185,11 +222,12 @@ export function ActivityLine({ sessionId, useSession, useSessions, useProjection
185
222
  lineHeight: '20px',
186
223
  whiteSpace: 'nowrap',
187
224
  }, children: [_jsx("span", { "aria-hidden": "true", style: {
188
- width: 7,
189
- height: 7,
225
+ width: 5,
226
+ height: 5,
190
227
  flex: '0 0 auto',
191
228
  borderRadius: '50%',
192
229
  background: 'var(--dsw-static-blue-500)',
230
+ opacity: 0.55,
193
231
  } }), _jsx("span", { children: label }), _jsxs("span", { style: { color: 'var(--dsw-alias-label-tertiary)' }, children: ["\u00B7 ", elapsedSeconds(activity.startedAt, now), "s"] })] }));
194
232
  }
195
233
  /** Preserve the old composer-dock footprint for hosts without the chat status seat. */
@@ -197,25 +235,7 @@ function ActivityDock(props) {
197
235
  return (_jsx("div", { style: { display: 'flex', alignItems: 'center', minHeight: 28, padding: '4px 10px' }, children: _jsx(ActivityLine, { ...props }) }));
198
236
  }
199
237
  export const inject = ['slots', 'locale', 'settingsScope'];
200
- /** Select a preferred slot when the host declares it, otherwise use a stable legacy composer seat. */
201
- export function chooseDeclaredSlot(preferred, fallback, isDeclared) {
202
- return isDeclared(preferred) ? preferred : fallback;
203
- }
204
- function slotIsDeclared(ctx, slot) {
205
- const registry = ctx.slots;
206
- return typeof registry.spec === 'function' && registry.spec.call(ctx.slots, slot) !== undefined;
207
- }
208
- /** Register an optional host slot without claiming it in older SlotMap declarations. */
209
- function injectOptionalActivitySlot(ctx, slot) {
210
- const registry = ctx.slots;
211
- registry.inject(slot, () => registry.register({
212
- name: slot,
213
- id: 'codex-activity',
214
- order: 5,
215
- locale: NS,
216
- }, ActivityLine));
217
- }
218
- /** Mount Codex controls in the newest named seats, with legacy composer fallbacks. */
238
+ /** Mount all controls through the official composer seats shared by every DSH release. */
219
239
  export function apply(ctx) {
220
240
  ctx.effect(() => ctx.locale.register(NS, { en, zh }), 'codex client: dictionaries');
221
241
  const settings = ctx.settingsScope.bind({ namespace: SETTINGS_NAMESPACE });
@@ -224,56 +244,26 @@ export function apply(ctx) {
224
244
  setSetting: (field, value) => settings.set(field, value),
225
245
  unsetSetting: (field) => settings.unset(field),
226
246
  });
227
- const fastSlot = chooseDeclaredSlot(MODEL_SETTINGS_SLOT, FAST_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
228
- if (fastSlot === MODEL_SETTINGS_SLOT) {
229
- ctx.slots.inject(MODEL_SETTINGS_SLOT, () => ctx.slots.register({
230
- name: MODEL_SETTINGS_SLOT,
231
- id: 'codex-fast',
232
- order: 0,
233
- locale: NS,
234
- inject: injected,
235
- }, FastModeButton));
236
- }
237
- else {
238
- ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
239
- name: FAST_FALLBACK_SLOT,
240
- id: 'codex-fast-fallback',
241
- order: 0,
242
- locale: NS,
243
- inject: injected,
244
- }, FastModeFallback));
245
- }
246
- const contextSlot = chooseDeclaredSlot(CONTEXT_SETTINGS_SLOT, CONTEXT_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
247
- if (contextSlot === CONTEXT_SETTINGS_SLOT) {
248
- ctx.slots.inject(CONTEXT_SETTINGS_SLOT, () => ctx.slots.register({
249
- name: CONTEXT_SETTINGS_SLOT,
250
- id: 'codex-context-size',
251
- order: 0,
252
- locale: NS,
253
- inject: injected,
254
- }, ContextSizeControl));
255
- }
256
- else {
257
- ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
258
- name: CONTEXT_FALLBACK_SLOT,
259
- id: 'codex-context-size-fallback',
260
- order: 0,
261
- locale: NS,
262
- inject: injected,
263
- }, LegacyContextSizeControl));
264
- }
265
- const activitySlot = chooseDeclaredSlot(ACTIVITY_SLOT, ACTIVITY_FALLBACK_SLOT, slot => slotIsDeclared(ctx, slot));
266
- if (activitySlot === ACTIVITY_SLOT) {
267
- injectOptionalActivitySlot(ctx, ACTIVITY_SLOT);
268
- }
269
- else {
270
- ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
271
- name: ACTIVITY_FALLBACK_SLOT,
272
- id: 'codex-activity',
273
- order: 5,
274
- locale: NS,
275
- }, ActivityDock));
276
- }
247
+ ctx.slots.inject(FAST_FALLBACK_SLOT, () => ctx.slots.register({
248
+ name: FAST_FALLBACK_SLOT,
249
+ id: 'codex-fast',
250
+ order: 0,
251
+ locale: NS,
252
+ inject: injected,
253
+ }, FastModeFallback));
254
+ ctx.slots.inject(CONTEXT_FALLBACK_SLOT, () => ctx.slots.register({
255
+ name: CONTEXT_FALLBACK_SLOT,
256
+ id: 'codex-context-size',
257
+ order: 1,
258
+ locale: NS,
259
+ inject: injected,
260
+ }, LegacyContextSizeControl));
261
+ ctx.slots.inject(ACTIVITY_FALLBACK_SLOT, () => ctx.slots.register({
262
+ name: ACTIVITY_FALLBACK_SLOT,
263
+ id: 'codex-activity',
264
+ order: 5,
265
+ locale: NS,
266
+ }, ActivityDock));
277
267
  }
278
268
  export default { inject, apply };
279
269
  //# sourceMappingURL=index.js.map
@@ -1,21 +1,60 @@
1
1
  /** Codex compaction backend that honors the latest durable request capacity. */
2
2
  import { AsyncLocalStorage } from 'node:async_hooks';
3
3
  import BasicCompactionEngine from '@deepseek-ai/dsh-compaction-basic';
4
+ import { settingsNamespace } from '@deepseek-ai/dsh-settings';
5
+ const CODEX_SETTINGS_NAMESPACE = settingsNamespace('codex');
6
+ /** Codex context overrides apply only to GPT-compatible model routes. */
7
+ function isGptModel(model) {
8
+ return /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
9
+ }
10
+ /** Read the live Codex capacity without requiring a custom LLM service API. */
11
+ function configuredContextWindow(ctx) {
12
+ const settings = ctx.get('settings');
13
+ if (settings?.get === undefined)
14
+ return { available: false };
15
+ const value = settings?.get?.(CODEX_SETTINGS_NAMESPACE);
16
+ return {
17
+ available: true,
18
+ ...value?.contextWindow !== undefined
19
+ && Number.isSafeInteger(value.contextWindow)
20
+ && value.contextWindow > 0
21
+ ? { value: value.contextWindow }
22
+ : {},
23
+ };
24
+ }
25
+ /** Read an explicit capacity persisted in the request header when settings are unavailable. */
26
+ function requestContextWindow(session, provider, model) {
27
+ const config = session.requestHeader()?.config;
28
+ if (config?.provider !== provider || config.model !== model)
29
+ return undefined;
30
+ const value = config.contextWindow;
31
+ return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : undefined;
32
+ }
4
33
  /** Overlay only the capacity lookup used by pressure compaction. */
5
- function withDurableContextCapacity(llm, activeSession) {
34
+ function withDurableContextCapacity(llm, ctx, activeSession) {
6
35
  return new Proxy(llm, {
7
36
  get(target, property) {
8
37
  if (property === 'resolveModelInfo') {
9
38
  return async (provider, model, signal) => {
10
39
  const info = await target.resolveModelInfo(provider, model, signal);
11
40
  const requestContext = activeSession.getStore()?.requestContext();
12
- if (requestContext?.provider !== provider
13
- || requestContext.model !== model
14
- || requestContext.contextWindow === undefined)
41
+ const session = activeSession.getStore();
42
+ const configured = isGptModel(model)
43
+ ? configuredContextWindow(ctx)
44
+ : { available: false };
45
+ // A live setting must win before the old request header: automatic
46
+ // pressure runs before the next request rebuilds that header.
47
+ const contextWindow = configured.available
48
+ ? configured.value
49
+ : (session === undefined ? undefined : requestContextWindow(session, provider, model))
50
+ ?? (requestContext?.provider === provider && requestContext.model === model
51
+ ? requestContext.contextWindow
52
+ : undefined);
53
+ if (contextWindow === undefined)
15
54
  return info;
16
55
  return {
17
56
  ...info,
18
- context: { ...info.context, contextWindow: requestContext.contextWindow },
57
+ context: { ...info.context, contextWindow },
19
58
  };
20
59
  };
21
60
  }
@@ -38,7 +77,7 @@ export default class CodexCompactionEngine extends BasicCompactionEngine {
38
77
  const llm = ctx.get('llm');
39
78
  if (llm === undefined)
40
79
  throw new Error('codex compaction requires ctx.llm');
41
- super(ctx.extend({ llm: withDurableContextCapacity(llm, activeSession) }), config);
80
+ super(ctx.extend({ llm: withDurableContextCapacity(llm, ctx, activeSession) }), config);
42
81
  this.activeSession = activeSession;
43
82
  }
44
83
  compactIfNeeded(agent, trigger, signal) {
@@ -3,14 +3,6 @@ import type { Context } from '@deepseek-ai/cordis';
3
3
  import z from '@deepseek-ai/schemastery';
4
4
  import type { LlmCallConfig } from '@deepseek-ai/dsh-llm';
5
5
  import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
6
- declare module '@deepseek-ai/dsh-llm' {
7
- interface LlmCallConfig {
8
- /** Codex request context capacity override, in tokens. */
9
- contextWindow?: number;
10
- /** Provider-facing service tier, for example Responses `priority`. */
11
- serviceTier?: string;
12
- }
13
- }
14
6
  export declare const name = "codex";
15
7
  export declare const inject: string[];
16
8
  /** Configuration for the Codex shell result bridge. */
@@ -40,6 +32,13 @@ export interface CodexSettings {
40
32
  /** Optional context capacity override, in tokens. */
41
33
  contextWindow?: number;
42
34
  }
35
+ /** Plugin-owned extension envelope; official DSH can carry these as unknown fields. */
36
+ export interface CodexRequestConfig extends LlmCallConfig {
37
+ /** Codex request context capacity override, in tokens. */
38
+ contextWindow?: number;
39
+ /** Provider-facing service tier, for example Responses `priority`. */
40
+ serviceTier?: string;
41
+ }
43
42
  export declare const CODEX_SETTINGS_SCHEMA: z<CodexSettings>;
44
43
  export interface CodexModelProfile {
45
44
  id: string;
@@ -50,7 +49,7 @@ export interface CodexModelProfile {
50
49
  /** Add Codex defaults without overwriting explicit user capabilities. */
51
50
  export declare function enrichCodexModel(model: CodexModelProfile): CodexModelProfile;
52
51
  /** Apply the live Codex controls to one agent request without leaking them to other routes. */
53
- export declare function applyCodexRequestSettings(request: LlmCallConfig, settings: CodexSettings): LlmCallConfig;
52
+ export declare function applyCodexRequestSettings(request: CodexRequestConfig, settings: CodexSettings): CodexRequestConfig;
54
53
  /** Put the agent persona first and omit the generic Harness identity opener. */
55
54
  export declare function normalizeCodexPromptAssembly(assembly: PromptAssembly): PromptAssembly;
56
55
  /** Build the Codex operating prompt with optional, user-enabled collaboration guidance. */
@@ -166,17 +166,16 @@ const CODEX_BASE_PROMPT = String.raw `## General
166
166
  ## Presenting your work
167
167
 
168
168
  - Be concise, direct, friendly, and actionable.
169
- - For substantial work, explain what changed and why, then mention relevant verification and next steps.
169
+ - For substantial work, explain what changed and why, then briefly note how the work was verified and what comes next.
170
170
  - Do not dump large files into the conversation; refer to their paths.
171
171
  - Use plain text with short sections only when they improve scanability.
172
172
  `;
173
173
  const CODEX_COLLABORATION_PROMPT = String.raw `## Collaboration
174
174
 
175
- - Ask, align, and clarify first. Try your best to understand the user's full picture.
175
+ - Gather enough context from the user then achieve the user's goal through the clearest, most effective path.
176
176
  - Keep only the essential logic and core actions. There's no need to explain or test what was removed or why something wasn't done.
177
177
  - Convey enough valuable information with as few words as possible. Stay focused on the end goal.
178
178
  - Solve problems by thinking from first principles and at a higher level.
179
- - Make things as effortless as possible for the user.
180
179
  `;
181
180
  /** Put the agent persona first and omit the generic Harness identity opener. */
182
181
  export function normalizeCodexPromptAssembly(assembly) {
@@ -485,7 +484,7 @@ export function apply(ctx, config = {}) {
485
484
  // scope so apply_patch can use the same wire bridge even when hosted search
486
485
  // and remote compaction are disabled.
487
486
  if (options.purpose === undefined && isGptModel(options.model)) {
488
- return hostedWebSearchStream(next);
487
+ return hostedWebSearchStream(next, { serviceTier: options.serviceTier });
489
488
  }
490
489
  return next();
491
490
  }));
@@ -7,6 +7,10 @@ export interface RemoteCodexConfig {
7
7
  interface JsonObject {
8
8
  [key: string]: unknown;
9
9
  }
10
+ interface CodexRequestWireOptions {
11
+ /** Provider-facing request option preserved by older DSH LLM adapters. */
12
+ serviceTier?: string;
13
+ }
10
14
  /** Replace DSH's JSON function declaration with the Responses custom grammar tool. */
11
15
  export declare function addCodexApplyPatch(body: JsonObject): JsonObject;
12
16
  /** Replay apply_patch calls as custom tool items after pi-ai's generic conversion. */
@@ -20,7 +24,7 @@ export declare function replaceRemoteCompactions(body: JsonObject): JsonObject;
20
24
  /** Enable the transport patch for this Codex plugin scope only. */
21
25
  export declare function installHostedWebSearch(): () => void;
22
26
  /** Iterate an existing DSH stream with the hosted-request context installed. */
23
- export declare function hostedWebSearchStream(next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
27
+ export declare function hostedWebSearchStream(next: () => AsyncIterable<StreamChunk>, options?: CodexRequestWireOptions): AsyncIterable<StreamChunk>;
24
28
  /** Remote-first compaction waterfall with the existing DSH path as fallback. */
25
29
  export declare function remoteCompactStream(ctx: Context, options: GenerateOptions, next: () => AsyncIterable<StreamChunk>): AsyncIterable<StreamChunk>;
26
30
  export {};
@@ -7,6 +7,10 @@ const REMOTE_COMPACTION_CLOSE = '</codex-remote-compaction>';
7
7
  const HOSTED_REQUESTS = new AsyncLocalStorage();
8
8
  let hostedPatchUsers = 0;
9
9
  let hostedPatchRestore;
10
+ function serviceTierOf(options) {
11
+ const value = options.serviceTier;
12
+ return typeof value === 'string' ? value : undefined;
13
+ }
10
14
  function isGptModel(model) {
11
15
  return typeof model === 'string' && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
12
16
  }
@@ -268,6 +272,12 @@ function canPatchBody(body) {
268
272
  || hasRemoteCompaction(body)
269
273
  || (hasFunctionApplyPatchTool(body) && canRewriteApplyPatchHistory(body)));
270
274
  }
275
+ /** Add provider options that older pi-ai adapters do not copy themselves. */
276
+ function applyRequestWireOptions(body, options) {
277
+ if (options.serviceTier === undefined || !isGptModel(body.model))
278
+ return body;
279
+ return { ...body, service_tier: options.serviceTier };
280
+ }
271
281
  /**
272
282
  * Install a scoped fetch shim for pi-ai's already-built Responses request.
273
283
  * The generic DSH adapter remains the owner of auth, streaming, replay, and
@@ -277,7 +287,8 @@ function canPatchBody(body) {
277
287
  function installGlobalHostedWebSearchPatch() {
278
288
  const original = globalThis.fetch;
279
289
  const patched = async (input, init) => {
280
- if (!HOSTED_REQUESTS.getStore())
290
+ const options = HOSTED_REQUESTS.getStore();
291
+ if (options === undefined)
281
292
  return original(input, init);
282
293
  const request = new Request(input, init);
283
294
  if (!isResponsesRequest(request.url))
@@ -289,13 +300,29 @@ function installGlobalHostedWebSearchPatch() {
289
300
  catch {
290
301
  return original(input, init);
291
302
  }
292
- if (!canPatchBody(body))
293
- return original(input, init);
294
- const fallbackRequest = request.clone();
303
+ const requestBody = applyRequestWireOptions(body, options);
304
+ if (!canPatchBody(requestBody)) {
305
+ if (requestBody === body)
306
+ return original(input, init);
307
+ const headers = new Headers(request.headers);
308
+ headers.delete('content-length');
309
+ return original(new Request(request, {
310
+ body: JSON.stringify(requestBody),
311
+ headers,
312
+ }));
313
+ }
314
+ const fallbackHeaders = new Headers(request.headers);
315
+ fallbackHeaders.delete('content-length');
316
+ const fallbackRequest = requestBody === body
317
+ ? request.clone()
318
+ : new Request(request, {
319
+ body: JSON.stringify(requestBody),
320
+ headers: fallbackHeaders,
321
+ });
295
322
  const headers = new Headers(request.headers);
296
323
  headers.delete('content-length');
297
324
  const hostedRequest = new Request(request, {
298
- body: JSON.stringify(rewriteCodexResponsesBody(body)),
325
+ body: JSON.stringify(rewriteCodexResponsesBody(requestBody)),
299
326
  headers,
300
327
  });
301
328
  try {
@@ -331,13 +358,13 @@ export function installHostedWebSearch() {
331
358
  };
332
359
  }
333
360
  /** Iterate an existing DSH stream with the hosted-request context installed. */
334
- export function hostedWebSearchStream(next) {
361
+ export function hostedWebSearchStream(next, options = {}) {
335
362
  return (async function* () {
336
363
  const iterator = next()[Symbol.asyncIterator]();
337
364
  let completed = false;
338
365
  try {
339
366
  while (true) {
340
- const item = await HOSTED_REQUESTS.run(true, () => iterator.next());
367
+ const item = await HOSTED_REQUESTS.run(options, () => iterator.next());
341
368
  if (item.done) {
342
369
  completed = true;
343
370
  return;
@@ -509,7 +536,8 @@ export function remoteCompactStream(ctx, options, next) {
509
536
  ctx.logger.warn(error);
510
537
  // The local fallback still replays the marker through a later GPT
511
538
  // Responses request, so it needs the same scoped wire context.
512
- yield* hostedWebSearchStream(next);
539
+ const serviceTier = serviceTierOf(options);
540
+ yield* hostedWebSearchStream(next, serviceTier === undefined ? {} : { serviceTier });
513
541
  }
514
542
  })();
515
543
  }