@shuind/dsh-codex-harness 0.3.1 → 0.3.3
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/CHANGELOG.md +29 -0
- package/README.md +21 -43
- package/docs/preset-library.md +2 -2
- package/docs/tool-policy.md +1 -1
- package/lib/client.js +1738 -327
- package/lib/compact-command.js +7 -1
- package/lib/compaction.js +7 -1
- package/lib/hybrid-executor.js +23 -12
- package/lib/index.js +1266 -36
- package/lib/preferences.js +21 -2
- package/lib/tool-policy.js +11 -2
- package/lib/typert.js +42 -1
- package/lib/types/client/desktop.d.ts +20 -42
- package/lib/types/client/desktop.js +191 -126
- package/lib/types/client/index.d.ts +104 -28
- package/lib/types/client/index.js +97 -15
- package/lib/types/client/policy-drafts.d.ts +18 -0
- package/lib/types/client/policy-drafts.js +27 -0
- package/lib/types/client/policy-locale.d.ts +80 -20
- package/lib/types/client/policy-locale.js +197 -80
- package/lib/types/client/preset-manager.d.ts +25 -2
- package/lib/types/client/preset-manager.js +89 -5
- package/lib/types/client/preset-requests.d.ts +44 -1
- package/lib/types/client/preset-requests.js +150 -0
- package/lib/types/client/tool-policy.d.ts +7 -2
- package/lib/types/client/tool-policy.js +48 -6
- package/lib/types/contracts/preset-editor-schema.d.ts +35 -0
- package/lib/types/contracts/preset-editor-schema.js +39 -0
- package/lib/types/contracts/settings.d.ts +12 -0
- package/lib/types/contracts/settings.js +10 -1
- package/lib/types/contracts/ui-contracts.d.ts +52 -0
- package/lib/types/contracts/ui-contracts.js +58 -0
- package/lib/types/contracts/update.d.ts +73 -0
- package/lib/types/contracts/update.js +291 -0
- package/lib/types/entries/index.js +20 -2
- package/lib/types/entries/preferences.d.ts +2 -0
- package/lib/types/entries/preferences.js +9 -0
- package/lib/types/hybrid/hybrid-sdk.d.ts +1 -1
- package/lib/types/hybrid/hybrid-sdk.js +27 -13
- package/lib/types/presets/preset-editor.d.ts +13 -1
- package/lib/types/presets/preset-editor.js +24 -1
- package/lib/types/presets/pro-mode-store.d.ts +13 -0
- package/lib/types/presets/pro-mode-store.js +69 -0
- package/lib/types/responses/background-sse-codec.d.ts +23 -0
- package/lib/types/responses/background-sse-codec.js +230 -0
- package/lib/types/responses/background-stream.d.ts +28 -0
- package/lib/types/responses/background-stream.js +351 -0
- package/lib/types/responses/compact-checkpoint.js +3 -10
- package/lib/types/responses/fetch-transport.js +24 -9
- package/lib/types/responses/remote-compact.js +39 -11
- package/lib/types/responses/wire-rewrite.d.ts +4 -0
- package/lib/types/responses/wire-rewrite.js +30 -4
- package/lib/types/tools/codex-subagent.d.ts +14 -0
- package/lib/types/tools/codex-subagent.js +269 -0
- package/lib/types/update/checker.d.ts +14 -0
- package/lib/types/update/checker.js +166 -0
- package/locale/en.json +1 -1
- package/locale/hybrid-executor/en.json +1 -1
- package/locale/hybrid-executor/zh.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +6 -2
- package/src/client/desktop.tsx +370 -153
- package/src/client/index.tsx +122 -22
- package/src/client/policy-drafts.ts +45 -0
- package/src/client/policy-locale.ts +197 -80
- package/src/client/preset-manager.tsx +125 -4
- package/src/client/preset-requests.ts +185 -1
- package/src/client/tool-policy.tsx +63 -9
- package/src/contracts/preset-editor-schema.ts +44 -0
- package/src/contracts/settings.ts +20 -1
- package/src/contracts/ui-contracts.ts +91 -0
- package/src/contracts/update.ts +307 -0
- package/src/entries/index.ts +25 -2
- package/src/entries/preferences.ts +9 -0
- package/src/hybrid/hybrid-sdk.ts +28 -12
- package/src/presets/preset-editor.ts +31 -3
- package/src/presets/pro-mode-store.ts +80 -0
- package/src/responses/background-sse-codec.ts +237 -0
- package/src/responses/background-stream.ts +371 -0
- package/src/responses/compact-checkpoint.ts +2 -8
- package/src/responses/fetch-transport.ts +28 -9
- package/src/responses/remote-compact.ts +41 -11
- package/src/responses/wire-rewrite.ts +34 -3
- package/src/tools/codex-subagent.ts +290 -0
- package/src/update/checker.ts +193 -0
- package/tsdown.config.ts +4 -0
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
nextOpenAICodexOverrides,
|
|
3
|
+
OPENAI_CODEX_SETTINGS_NAMESPACE,
|
|
4
|
+
} from '../contracts/ui-contracts.ts'
|
|
5
|
+
import type {
|
|
6
|
+
CodexConnectScope,
|
|
7
|
+
CodexConnectSnapshot,
|
|
8
|
+
CodexSubagentModelCatalog,
|
|
9
|
+
LlmProvidersMap,
|
|
10
|
+
LlmProvidersScope,
|
|
11
|
+
PresetCatalog,
|
|
12
|
+
} from '../contracts/ui-contracts.ts'
|
|
13
|
+
import type { CodexScope, CodexSettingsSnapshot } from './index.tsx'
|
|
2
14
|
import type { PresetManagerActions } from './preset-manager.tsx'
|
|
3
15
|
import type { PresetPromptCatalog, PresetToolCatalog } from '../contracts/tool-policy-contract.ts'
|
|
4
16
|
|
|
@@ -40,6 +52,10 @@ export function cachedPresetTools(manager: PresetManagerActions, id: string): Pr
|
|
|
40
52
|
return toolCatalogs.get(manager)?.get(id)
|
|
41
53
|
}
|
|
42
54
|
|
|
55
|
+
export function invalidatePresetTools(manager: PresetManagerActions): void {
|
|
56
|
+
toolCatalogs.delete(manager)
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
/** The requested preset owns this snapshot; never substitute current-Agent tools. */
|
|
44
60
|
export function requestPresetTools(manager: PresetManagerActions, id: string, refresh = false): Promise<PresetToolCatalog> {
|
|
45
61
|
const pending = toolRequests.get(manager)?.get(id)
|
|
@@ -111,3 +127,171 @@ export async function readPresetWithRetry<T>(read: () => Promise<T>, active: ()
|
|
|
111
127
|
return read()
|
|
112
128
|
}
|
|
113
129
|
}
|
|
130
|
+
|
|
131
|
+
const subagentModelRequests = new WeakMap<PresetManagerActions, Promise<CodexSubagentModelCatalog>>()
|
|
132
|
+
|
|
133
|
+
export function requestCodexSubagentModels(manager: PresetManagerActions): Promise<CodexSubagentModelCatalog> {
|
|
134
|
+
const pending = subagentModelRequests.get(manager)
|
|
135
|
+
if (pending !== undefined) return pending
|
|
136
|
+
const request = (async (): Promise<CodexSubagentModelCatalog> => {
|
|
137
|
+
await manager.ready
|
|
138
|
+
const remote = manager.remote.codexPresetEditor
|
|
139
|
+
if (typeof remote.codexSubagentModels !== 'function') throw new Error('codex-subagent-models-unavailable')
|
|
140
|
+
const result = await remote.codexSubagentModels()
|
|
141
|
+
if (!result.ok) throw new Error(result.error.message ?? 'codex-subagent-models-unavailable')
|
|
142
|
+
return result.value
|
|
143
|
+
})()
|
|
144
|
+
subagentModelRequests.set(manager, request)
|
|
145
|
+
void request.finally(() => {
|
|
146
|
+
if (subagentModelRequests.get(manager) === request) subagentModelRequests.delete(manager)
|
|
147
|
+
}).catch(() => {})
|
|
148
|
+
return request
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface DesktopConfigForm extends Pick<CodexScope, 'getSnapshot' | 'subscribe'> {
|
|
152
|
+
set(field: string, value: unknown): Promise<boolean>
|
|
153
|
+
unset(field: string): Promise<boolean>
|
|
154
|
+
mutate(ops: Array<{ op: 'set'; path: string[]; value: unknown } | { op: 'unset'; path: string[] }>, expectedRevision?: number | string): Promise<boolean>
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
interface MirrorNamespaceRow {
|
|
158
|
+
readonly ns: string
|
|
159
|
+
readonly value?: unknown
|
|
160
|
+
readonly base?: unknown
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
interface ConfigMirror {
|
|
164
|
+
getSnapshot(): { readonly status?: string; readonly view?: { readonly writable?: boolean; readonly namespaces?: readonly MirrorNamespaceRow[] } }
|
|
165
|
+
subscribe(listener: () => void): () => void
|
|
166
|
+
ensure?(): unknown
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface DesktopSettingsContext {
|
|
170
|
+
configForms: {
|
|
171
|
+
get(entryId: string): DesktopConfigForm
|
|
172
|
+
describe?(): ConfigMirror
|
|
173
|
+
whileServed(namespaces: string[], register: () => () => void): () => void
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
178
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
179
|
+
? value as Record<string, unknown>
|
|
180
|
+
: undefined
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function asOverrides(value: unknown): Record<string, number | null> | undefined {
|
|
184
|
+
const record = asRecord(value)
|
|
185
|
+
if (record === undefined) return undefined
|
|
186
|
+
const out: Record<string, number | null> = {}
|
|
187
|
+
for (const [k, v] of Object.entries(record)) {
|
|
188
|
+
if (v === null || (typeof v === 'number' && Number.isSafeInteger(v) && v > 0)) out[k] = v
|
|
189
|
+
}
|
|
190
|
+
return out
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function projectCodexConnectRecord(
|
|
194
|
+
record: Record<string, unknown>,
|
|
195
|
+
baseRecord: Record<string, unknown> | undefined,
|
|
196
|
+
writable: boolean,
|
|
197
|
+
): CodexConnectSnapshot {
|
|
198
|
+
const searchModel = typeof record.searchModel === 'string' && record.searchModel.trim() ? record.searchModel.trim() : undefined
|
|
199
|
+
const imageModelHint = typeof record.imageModelHint === 'string' ? record.imageModelHint.trim() : undefined
|
|
200
|
+
return {
|
|
201
|
+
status: 'ready',
|
|
202
|
+
writable,
|
|
203
|
+
overrides: asOverrides(record.contextWindowOverrides),
|
|
204
|
+
baseOverrides: asOverrides(baseRecord?.contextWindowOverrides),
|
|
205
|
+
...(typeof record.enableNativeCompaction === 'boolean' ? { nativeCompaction: record.enableNativeCompaction } : {}),
|
|
206
|
+
...(typeof record.enableSearch === 'boolean' ? { searchEnabled: record.enableSearch } : {}),
|
|
207
|
+
...(searchModel !== undefined ? { searchModel } : {}),
|
|
208
|
+
...(typeof record.enableImageGeneration === 'boolean' ? { imageGenerationEnabled: record.enableImageGeneration } : {}),
|
|
209
|
+
...(imageModelHint !== undefined ? { imageModelHint } : {}),
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function bindCodexConnectScope(configForms: DesktopSettingsContext['configForms']): CodexConnectScope {
|
|
214
|
+
const form = configForms.get(OPENAI_CODEX_SETTINGS_NAMESPACE)
|
|
215
|
+
const mirror = configForms.describe?.()
|
|
216
|
+
void Promise.resolve(mirror?.ensure?.()).catch(() => {})
|
|
217
|
+
let lastFormSnap: unknown
|
|
218
|
+
let lastMirrorSnap: unknown
|
|
219
|
+
let projected: CodexConnectSnapshot = { status: 'loading', writable: false }
|
|
220
|
+
const getSnapshot = (): CodexConnectSnapshot => {
|
|
221
|
+
const formSnap = form.getSnapshot() as CodexSettingsSnapshot & { readonly base?: Record<string, unknown> }
|
|
222
|
+
const mirrorSnap = mirror?.getSnapshot()
|
|
223
|
+
if (formSnap === lastFormSnap && mirrorSnap === lastMirrorSnap) return projected
|
|
224
|
+
lastFormSnap = formSnap
|
|
225
|
+
lastMirrorSnap = mirrorSnap
|
|
226
|
+
const formRecord = formSnap.status === 'ready' ? asRecord(formSnap.value) : undefined
|
|
227
|
+
if (formRecord !== undefined) {
|
|
228
|
+
return projected = projectCodexConnectRecord(formRecord, asRecord(formSnap.base), formSnap.writable)
|
|
229
|
+
}
|
|
230
|
+
const view = mirrorSnap?.view
|
|
231
|
+
if (view !== undefined) {
|
|
232
|
+
const row = view.namespaces?.find(candidate => candidate.ns === OPENAI_CODEX_SETTINGS_NAMESPACE)
|
|
233
|
+
const rowRecord = row === undefined ? undefined : asRecord(row.value)
|
|
234
|
+
if (row === undefined || rowRecord === undefined) return projected = { status: 'unavailable', writable: false }
|
|
235
|
+
return projected = projectCodexConnectRecord(rowRecord, asRecord(row.base), view.writable ?? formSnap.writable)
|
|
236
|
+
}
|
|
237
|
+
return projected = { status: formSnap.status, writable: formSnap.writable }
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
getSnapshot,
|
|
241
|
+
subscribe: listener => {
|
|
242
|
+
const stopForm = form.subscribe(listener)
|
|
243
|
+
const stopMirror = mirror?.subscribe(listener)
|
|
244
|
+
return () => { stopForm(); stopMirror?.() }
|
|
245
|
+
},
|
|
246
|
+
setModelOverride: async (modelId, tokens) => {
|
|
247
|
+
const snap = getSnapshot()
|
|
248
|
+
const next = nextOpenAICodexOverrides(snap.overrides, snap.baseOverrides, modelId, tokens)
|
|
249
|
+
const accepted = next === undefined
|
|
250
|
+
? await form.unset('contextWindowOverrides')
|
|
251
|
+
: await form.set('contextWindowOverrides', next)
|
|
252
|
+
if (!accepted) throw new Error('The host did not accept the settings change.')
|
|
253
|
+
},
|
|
254
|
+
setNativeCompaction: async enabled => {
|
|
255
|
+
const accepted = await form.set('enableNativeCompaction', enabled)
|
|
256
|
+
if (!accepted) throw new Error('The host did not accept the settings change.')
|
|
257
|
+
},
|
|
258
|
+
setSearchEnabled: async enabled => {
|
|
259
|
+
const accepted = await form.set('enableSearch', enabled)
|
|
260
|
+
if (!accepted) throw new Error('The host did not accept the settings change.')
|
|
261
|
+
},
|
|
262
|
+
setImageGenerationEnabled: async enabled => {
|
|
263
|
+
const accepted = await form.set('enableImageGeneration', enabled)
|
|
264
|
+
if (!accepted) throw new Error('The host did not accept the settings change.')
|
|
265
|
+
},
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function bindLlmProvidersScope(configForms: DesktopSettingsContext['configForms']): LlmProvidersScope | undefined {
|
|
270
|
+
const mirror = configForms.describe?.()
|
|
271
|
+
if (mirror === undefined) return undefined
|
|
272
|
+
void Promise.resolve(mirror.ensure?.()).catch(() => {})
|
|
273
|
+
let lastMirrorSnap: unknown
|
|
274
|
+
let projected: LlmProvidersMap | undefined
|
|
275
|
+
const getSnapshot = (): LlmProvidersMap | undefined => {
|
|
276
|
+
const mirrorSnap = mirror.getSnapshot()
|
|
277
|
+
if (mirrorSnap === lastMirrorSnap) return projected
|
|
278
|
+
lastMirrorSnap = mirrorSnap
|
|
279
|
+
const row = mirrorSnap?.view?.namespaces?.find(candidate => candidate.ns === 'llm-pi-ai')
|
|
280
|
+
const providers = asRecord(asRecord(row?.value)?.providers)
|
|
281
|
+
return projected = providers as LlmProvidersMap | undefined
|
|
282
|
+
}
|
|
283
|
+
return { getSnapshot, subscribe: listener => mirror.subscribe(listener) }
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export function adaptConfigForm(form: Pick<DesktopConfigForm, 'getSnapshot' | 'subscribe' | 'set' | 'unset'>): CodexScope {
|
|
287
|
+
const accepted = async (result: Promise<boolean>) => { if (!await result) throw new Error('The host did not accept the settings change.') }
|
|
288
|
+
return { getSnapshot: () => form.getSnapshot(), subscribe: listener => form.subscribe(listener),
|
|
289
|
+
set: (field, value) => accepted(form.set(field, value)), unset: field => accepted(form.unset(field)) }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export async function saveDesktopSettings(form: Pick<DesktopConfigForm, 'mutate'>, edits: Record<string, unknown>, expectedRevision?: number | string): Promise<void> {
|
|
293
|
+
const ops = Object.entries(edits).map(([field, value]) => value === undefined ? { op: 'unset' as const, path: [field] } : { op: 'set' as const, path: [field], value })
|
|
294
|
+
if (!ops.length) return
|
|
295
|
+
const accepted = expectedRevision === undefined ? await form.mutate(ops) : await form.mutate(ops, expectedRevision)
|
|
296
|
+
if (!accepted) throw new Error('The host did not accept the settings change.')
|
|
297
|
+
}
|
|
@@ -15,12 +15,13 @@ import type {
|
|
|
15
15
|
PresetToolEntry, ToolAction, ToolActionContext, ToolPolicyRule,
|
|
16
16
|
} from '../contracts/tool-policy-contract.ts'
|
|
17
17
|
import { PRESET_PROMPT_NAMES } from '../contracts/ui-contracts.ts'
|
|
18
|
-
import { acceptPresetSave, editPresetDraft, preparePresetSave, presetRules, sameRules } from './policy-drafts.ts'
|
|
19
|
-
import type { PresetDrafts } from './policy-drafts.ts'
|
|
18
|
+
import { acceptPresetSave, editPresetDraft, formatGptImageBadge, preparePresetSave, presetRules, resolveGptCapabilities, sameRules } from './policy-drafts.ts'
|
|
19
|
+
import type { GptCapabilitiesState, PresetDrafts } from './policy-drafts.ts'
|
|
20
20
|
import { groupOf, humanLabels, policyStyles, toolPolicyEn, toolPolicyZh } from './policy-locale.ts'
|
|
21
21
|
import type { ToolGroupId } from './policy-locale.ts'
|
|
22
22
|
export type { ToolPolicyRule } from '../contracts/tool-policy-contract.ts'
|
|
23
|
-
export {
|
|
23
|
+
export type { GptCapabilitiesState }
|
|
24
|
+
export { formatGptImageBadge, resolveGptCapabilities, toolPolicyEn, toolPolicyZh }
|
|
24
25
|
|
|
25
26
|
export const TOOL_POLICY_NAMESPACE = 'codex-tool-policy'
|
|
26
27
|
export interface ToolPolicySettings { readonly rules: readonly ToolPolicyRule[] }
|
|
@@ -88,12 +89,20 @@ export function saveToolPolicy(form: ToolPolicyForm, rules: readonly ToolPolicyR
|
|
|
88
89
|
|
|
89
90
|
export type ToolPolicySubMode = 'tools' | 'prompts' | 'definition'
|
|
90
91
|
export type ToolPolicyMode = ToolPolicySubMode | 'inactive'
|
|
91
|
-
type PolicyProps = PropsLocale<'codex'> & {
|
|
92
|
+
type PolicyProps = PropsLocale<'codex'> & {
|
|
93
|
+
presetManager?: PresetManagerActions | undefined
|
|
94
|
+
mode?: ToolPolicyMode
|
|
95
|
+
gptCapabilities?: GptCapabilitiesState | undefined
|
|
96
|
+
toolsVersion?: number | undefined
|
|
97
|
+
}
|
|
92
98
|
type ToolsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetToolCatalog }
|
|
93
99
|
type PromptsView = { preset: string; status: 'loading' | 'ready' | 'error'; value?: PresetPromptCatalog }
|
|
94
100
|
const isPromptName = (name: string): name is PresetPromptName => (PRESET_PROMPT_NAMES as readonly string[]).includes(name)
|
|
95
101
|
|
|
96
|
-
const GROUP_META: readonly {
|
|
102
|
+
const GROUP_META: readonly {
|
|
103
|
+
id: ToolGroupId
|
|
104
|
+
labelKey: 'toolPolicyCommandGroup' | 'toolPolicyFileGroup' | 'toolPolicyPlanGroup' | 'toolPolicyCollabGroup' | 'toolPolicyOtherGroup'
|
|
105
|
+
}[] = [
|
|
97
106
|
{ id: 'command', labelKey: 'toolPolicyCommandGroup' },
|
|
98
107
|
{ id: 'file', labelKey: 'toolPolicyFileGroup' },
|
|
99
108
|
{ id: 'plan', labelKey: 'toolPolicyPlanGroup' },
|
|
@@ -106,7 +115,7 @@ export function ToolPolicySection({ binding, ...props }: { binding: ToolPolicyBi
|
|
|
106
115
|
return form === undefined ? null : <ToolPolicySettingsCard form={form} {...props} />
|
|
107
116
|
}
|
|
108
117
|
|
|
109
|
-
export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t }: { form: ToolPolicyForm } & PolicyProps) {
|
|
118
|
+
export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', gptCapabilities, toolsVersion = 0, t }: { form: ToolPolicyForm } & PolicyProps) {
|
|
110
119
|
const snapshot = useSyncExternalStore(listener => form.subscribe(listener), () => form.getSnapshot(), () => form.getSnapshot())
|
|
111
120
|
const [subMode, setSubMode] = useState<ToolPolicySubMode>(mode === 'prompts' || mode === 'definition' ? mode : 'tools')
|
|
112
121
|
const prevMode = useRef(mode)
|
|
@@ -156,6 +165,13 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t
|
|
|
156
165
|
}).catch(() => { if (alive.current && ticket === toolsRequest.current) setToolsView({ preset: selectedId, status: 'error' }) })
|
|
157
166
|
}
|
|
158
167
|
useEffect(() => { loadTools(); return () => { toolsRequest.current++ } }, [presetManager, selectedId])
|
|
168
|
+
const loadedToolsVersion = useRef(toolsVersion)
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (mode !== 'inactive' && loadedToolsVersion.current !== toolsVersion) {
|
|
171
|
+
loadedToolsVersion.current = toolsVersion
|
|
172
|
+
loadTools(true)
|
|
173
|
+
}
|
|
174
|
+
}, [mode, toolsVersion, presetManager, selectedId])
|
|
159
175
|
|
|
160
176
|
const cached = presetManager && selectedId ? cachedPresetTools(presetManager, selectedId) : undefined
|
|
161
177
|
const inventory = toolsView?.preset === selectedId && toolsView.status === 'error' ? undefined : toolsView?.preset === selectedId && toolsView.status === 'ready' ? toolsView.value : cached
|
|
@@ -273,15 +289,48 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t
|
|
|
273
289
|
const changeSummary = summaryParts.join(' · ') || t(currentDraft && !sameRules(beforeTarget, currentDraft.rules) ? 'toolPolicyRuleChanged' : 'toolPolicyNoToolDelta')
|
|
274
290
|
const unavailable = (reason: 'conditional' | 'target-exists' | undefined) => t(reason === 'conditional' ? 'toolPolicyConditional' : reason === 'target-exists' ? 'toolPolicyTargetExists' : 'toolPolicyUnsupported')
|
|
275
291
|
|
|
292
|
+
const gptSearchActive = gptCapabilities?.hostedWebSearch === true || gptCapabilities?.codexSearch === true
|
|
293
|
+
const gptBadgeFor = (tool: PresetToolEntry): { label: string; title: string } | undefined => {
|
|
294
|
+
if (tool.name === 'codex_subagent') {
|
|
295
|
+
const model = gptCapabilities?.codexSubagentModel
|
|
296
|
+
return {
|
|
297
|
+
label: model ? `${t('toolPolicyGptCodexSearch')} · ${model}` : t('toolPolicyGptCodexSearch'),
|
|
298
|
+
title: t('toolPolicyGptSubagentTitle'),
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (tool.name === 'codex_connect_image_generate') {
|
|
302
|
+
return { label: `${t('toolPolicyGptCodexSearch')} · ${formatGptImageBadge(gptCapabilities?.imageModelHint)}`, title: t('toolPolicyGptImageTitle') }
|
|
303
|
+
}
|
|
304
|
+
if (tool.name === 'web_search' && gptSearchActive) {
|
|
305
|
+
const model = gptCapabilities?.codexSearchModel
|
|
306
|
+
if (gptCapabilities?.hostedWebSearch && gptCapabilities?.codexSearch) {
|
|
307
|
+
return {
|
|
308
|
+
label: t('toolPolicyGptDualSearch'),
|
|
309
|
+
title: model ? `${t('toolPolicyGptDualSearchTitle')} (${model})` : t('toolPolicyGptDualSearchTitle'),
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (gptCapabilities?.hostedWebSearch) {
|
|
313
|
+
return { label: t('toolPolicyGptHostedSearch'), title: t('toolPolicyGptHostedSearchTitle') }
|
|
314
|
+
}
|
|
315
|
+
return {
|
|
316
|
+
label: model ? `${t('toolPolicyGptCodexSearch')} · ${model}` : t('toolPolicyGptCodexSearch'),
|
|
317
|
+
title: model ? `${t('toolPolicyGptCodexSearchTitle')} (${model})` : t('toolPolicyGptCodexSearchTitle'),
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return undefined
|
|
321
|
+
}
|
|
322
|
+
|
|
276
323
|
const renderRows = (tools: readonly PresetToolEntry[]) => <div className="codex-tool-policy-table" role="table" aria-label={t('toolPolicyTitle')}>
|
|
277
324
|
{tools.map(tool => {
|
|
278
325
|
const action = chosen(tool); const deferReason = deferUnavailableReason(tool)
|
|
279
326
|
const supported = action === 'keep' || action === 'hide' || action === 'defer' || tool.replacements.some(option => option.action === action)
|
|
280
327
|
const custom = customized(tool); const hasOverride = !!rule?.tools?.some(choice => choice.name === tool.name)
|
|
328
|
+
const gptBadge = gptBadgeFor(tool)
|
|
281
329
|
return <div key={tool.name} role="row" className="codex-tool-policy-tool" data-tool-name={tool.name} data-tool-action={action}>
|
|
282
330
|
<div role="cell" className="codex-tool-policy-name">
|
|
283
331
|
<code className="codex-tool-policy-identifier">{tool.name}</code>
|
|
284
332
|
<span className="codex-tool-policy-description" title={tool.description}>{human(tool)}</span>
|
|
333
|
+
{gptBadge && <span className="codex-badge" data-tone="gpt" title={gptBadge.title}>{gptBadge.label}</span>}
|
|
285
334
|
{tool.defaultDeferred && !custom && <span className="codex-badge" data-tone="blue">{t('toolPolicyDefaultDeferred')}</span>}
|
|
286
335
|
{custom && <span className="codex-badge" data-tone="blue">{t('toolPolicyModified')}</span>}
|
|
287
336
|
{tool.codexTool?.presetEnabled === false && <span className="codex-badge" data-tone="warn">{t('toolPolicyPresetDisabled')}</span>}
|
|
@@ -311,8 +360,12 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t
|
|
|
311
360
|
const isFiltering = text.length > 0 || filter !== 'all'
|
|
312
361
|
const allTools = inventory?.tools ?? []
|
|
313
362
|
const hasReplaceable = allTools.some(tool => tool.replacements.some(option => option.available))
|
|
314
|
-
const shown = allTools.filter(tool =>
|
|
315
|
-
|
|
363
|
+
const shown = allTools.filter(tool => {
|
|
364
|
+
const gptBadge = gptBadgeFor(tool)
|
|
365
|
+
const haystack = `${human(tool)} ${tool.name} ${tool.description} ${gptBadge?.label ?? ''}`.toLowerCase()
|
|
366
|
+
return (!text || haystack.includes(text))
|
|
367
|
+
&& (filter === 'all' || (filter === 'modified' ? customized(tool) : filter === 'deferred' ? chosen(tool) === 'defer' : tool.replacements.some(option => option.available)))
|
|
368
|
+
})
|
|
316
369
|
|
|
317
370
|
return <section className="codex-tool-policy" aria-label={t(activeSub === 'prompts' ? 'settingsPresetPrompts' : 'toolPolicyTitle')}>
|
|
318
371
|
<style>{policyStyles}</style>
|
|
@@ -355,7 +408,8 @@ export function ToolPolicySettingsCard({ form, presetManager, mode = 'tools', t
|
|
|
355
408
|
{inventory && !duplicate && (isFiltering && shown.length === 0
|
|
356
409
|
? <div className="codex-card">{renderRows(shown)}</div>
|
|
357
410
|
: GROUP_META.map(group => {
|
|
358
|
-
const tools = shown.filter(tool => groupOf(tool) === group.id)
|
|
411
|
+
const tools = shown.filter(tool => groupOf(tool) === group.id)
|
|
412
|
+
if (!tools.length) return null
|
|
359
413
|
const changes = tools.filter(customized).length; const key = `${selectedId}/${group.id}`
|
|
360
414
|
return <details key={group.id} className="codex-group" data-tool-group={group.id} open={isFiltering ? true : (groupOpen.get(key) ?? true)}
|
|
361
415
|
onToggle={event => { const open = event.currentTarget.open; setGroupOpen(previous => new Map(previous).set(key, open)) }}>
|
|
@@ -7,6 +7,46 @@ export const PRESET_EDITOR_SERVICE = 'codexPresetEditor'
|
|
|
7
7
|
|
|
8
8
|
export const presetIdSchema = z.string().min(1).max(256)
|
|
9
9
|
|
|
10
|
+
export const proModeSessionIdSchema = z.string().min(1).max(256)
|
|
11
|
+
|
|
12
|
+
export const proModeSetInputSchema = z.object({
|
|
13
|
+
sessionId: proModeSessionIdSchema,
|
|
14
|
+
enabled: z.boolean(),
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const proModeStateSchema = z.object({
|
|
18
|
+
enabled: z.boolean(),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
export const harnessUpdateResultSchema = z.discriminatedUnion('status', [
|
|
22
|
+
z.object({
|
|
23
|
+
status: z.literal('up-to-date'),
|
|
24
|
+
currentVersion: z.string(),
|
|
25
|
+
latestVersion: z.string(),
|
|
26
|
+
}),
|
|
27
|
+
z.object({
|
|
28
|
+
status: z.literal('update-available'),
|
|
29
|
+
currentVersion: z.string(),
|
|
30
|
+
latestVersion: z.string(),
|
|
31
|
+
releaseUrl: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
z.object({
|
|
34
|
+
status: z.literal('unavailable'),
|
|
35
|
+
currentVersion: z.string(),
|
|
36
|
+
reason: z.enum(['invalid-current-version', 'registry-unavailable', 'invalid-registry-response']),
|
|
37
|
+
}),
|
|
38
|
+
])
|
|
39
|
+
|
|
40
|
+
export const codexSubagentModelsSchema = z.object({
|
|
41
|
+
available: z.boolean(),
|
|
42
|
+
models: z.array(z.object({
|
|
43
|
+
id: z.string(),
|
|
44
|
+
name: z.string(),
|
|
45
|
+
efforts: z.array(z.string()),
|
|
46
|
+
defaultEffort: z.string().optional(),
|
|
47
|
+
})),
|
|
48
|
+
})
|
|
49
|
+
|
|
10
50
|
export const presetCatalogSchema = z.object({
|
|
11
51
|
presets: z.array(z.object({
|
|
12
52
|
id: z.string(),
|
|
@@ -99,6 +139,10 @@ export function buildPresetEditorDescriptors(): readonly InvocationDescriptor[]
|
|
|
99
139
|
descriptor('tools', 'id', presetIdSchema, presetToolCatalogSchema),
|
|
100
140
|
descriptor('prompts', 'id', presetIdSchema, presetPromptCatalogSchema),
|
|
101
141
|
descriptor('read', 'id', presetIdSchema, presetDefinitionSchema),
|
|
142
|
+
descriptor('proModeGet', 'sessionId', proModeSessionIdSchema, proModeStateSchema),
|
|
143
|
+
descriptor('proModeSet', 'input', proModeSetInputSchema, proModeStateSchema),
|
|
144
|
+
descriptor('updateCheck', undefined, z.unknown(), harnessUpdateResultSchema),
|
|
145
|
+
descriptor('codexSubagentModels', undefined, z.unknown(), codexSubagentModelsSchema),
|
|
102
146
|
]
|
|
103
147
|
}
|
|
104
148
|
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import type { Context } from '@deepseek-ai/cordis'
|
|
4
4
|
import z from '@deepseek-ai/schemastery'
|
|
5
5
|
import type { SettingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
6
|
-
import { CODEX_CONTEXT_MAX } from './ui-contracts.ts'
|
|
6
|
+
import { CODEX_CONTEXT_MAX, CODEX_SUBAGENT_DEFAULT_PRESET, supportsApiProMode } from './ui-contracts.ts'
|
|
7
|
+
export { supportsApiProMode }
|
|
7
8
|
import {
|
|
8
9
|
DEFAULT_CODEX_PERSONA,
|
|
9
10
|
DEFAULT_CODEX_SYSTEM_PROMPT,
|
|
@@ -19,6 +20,8 @@ export interface CodexSettings {
|
|
|
19
20
|
fast: boolean
|
|
20
21
|
/** Show the Fast mode switch in the conversation composer. */
|
|
21
22
|
fastModeControlEnabled: boolean
|
|
23
|
+
/** Show the ephemeral per-session API Pro mode switch in the conversation composer. */
|
|
24
|
+
proModeControlEnabled: boolean
|
|
22
25
|
/** Show the quick context-window control in the conversation composer. */
|
|
23
26
|
contextWindowControlEnabled: boolean
|
|
24
27
|
/** Optional context capacity override, in tokens. */
|
|
@@ -45,12 +48,21 @@ export interface CodexSettings {
|
|
|
45
48
|
remoteCompactionEnabled: boolean
|
|
46
49
|
/** Show the Codex request/compaction activity indicator. */
|
|
47
50
|
activityIndicatorEnabled: boolean
|
|
51
|
+
/** Globally register codex_subagent backed by the openai-codex subscription provider. */
|
|
52
|
+
codexSubagentEnabled: boolean
|
|
53
|
+
/** Optional openai-codex model id for codex_subagent (blank uses the first enabled model). */
|
|
54
|
+
codexSubagentModel?: string
|
|
55
|
+
/** Optional reasoning effort id for codex_subagent (blank uses the model default). */
|
|
56
|
+
codexSubagentEffort?: string
|
|
57
|
+
/** Preset for codex_subagent children ('codex-hybrid' by default, or 'inherit'). */
|
|
58
|
+
codexSubagentPreset: string
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
/** Default settings exposed even before a Codex session is opened. */
|
|
51
62
|
export const CODEX_SETTINGS_ENTRY: CodexSettings = {
|
|
52
63
|
fast: false,
|
|
53
64
|
fastModeControlEnabled: true,
|
|
65
|
+
proModeControlEnabled: true,
|
|
54
66
|
contextWindowControlEnabled: true,
|
|
55
67
|
persona: DEFAULT_CODEX_PERSONA,
|
|
56
68
|
harnessSourcePrompt: DEFAULT_DSH_CORE_SOURCE_PROMPT,
|
|
@@ -63,11 +75,14 @@ export const CODEX_SETTINGS_ENTRY: CodexSettings = {
|
|
|
63
75
|
hostedWebSearchEnabled: true,
|
|
64
76
|
remoteCompactionEnabled: true,
|
|
65
77
|
activityIndicatorEnabled: true,
|
|
78
|
+
codexSubagentEnabled: false,
|
|
79
|
+
codexSubagentPreset: CODEX_SUBAGENT_DEFAULT_PRESET,
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
export const CODEX_SETTINGS_SCHEMA: z<CodexSettings> = z.object({
|
|
69
83
|
fast: z.boolean().default(false),
|
|
70
84
|
fastModeControlEnabled: z.boolean().default(true),
|
|
85
|
+
proModeControlEnabled: z.boolean().default(true),
|
|
71
86
|
contextWindowControlEnabled: z.boolean().default(true),
|
|
72
87
|
contextWindow: z.number().step(1).min(1).max(CODEX_CONTEXT_MAX).hidden(),
|
|
73
88
|
persona: z.string().default(DEFAULT_CODEX_PERSONA),
|
|
@@ -81,6 +96,10 @@ export const CODEX_SETTINGS_SCHEMA: z<CodexSettings> = z.object({
|
|
|
81
96
|
hostedWebSearchEnabled: z.boolean().default(true),
|
|
82
97
|
remoteCompactionEnabled: z.boolean().default(true),
|
|
83
98
|
activityIndicatorEnabled: z.boolean().default(true),
|
|
99
|
+
codexSubagentEnabled: z.boolean().default(false),
|
|
100
|
+
codexSubagentModel: z.string(),
|
|
101
|
+
codexSubagentEffort: z.string(),
|
|
102
|
+
codexSubagentPreset: z.string().default(CODEX_SUBAGENT_DEFAULT_PRESET),
|
|
84
103
|
})
|
|
85
104
|
|
|
86
105
|
interface SettingsReader {
|
|
@@ -7,6 +7,91 @@ export const CODEX_CONTEXT_MAX = 1_000_000
|
|
|
7
7
|
export const OPENAI_CODEX_PROVIDER = 'openai-codex'
|
|
8
8
|
export const OPENAI_CODEX_SETTINGS_NAMESPACE = 'llm-openai-codex'
|
|
9
9
|
export const OPENAI_CODEX_MODEL_CATALOG_PATH = '/plugins/dsh-codex-connect/models'
|
|
10
|
+
export const CODEX_SUBAGENT_TOOL_NAME = 'codex_subagent'
|
|
11
|
+
export const CODEX_SUBAGENT_DEFAULT_PRESET = 'codex-hybrid'
|
|
12
|
+
export const CODEX_SUBAGENT_PRESET_INHERIT = 'inherit'
|
|
13
|
+
|
|
14
|
+
export interface CodexSubagentModelOption {
|
|
15
|
+
readonly id: string
|
|
16
|
+
readonly name: string
|
|
17
|
+
readonly efforts: readonly string[]
|
|
18
|
+
readonly defaultEffort?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface CodexSubagentModelCatalog {
|
|
22
|
+
readonly available: boolean
|
|
23
|
+
readonly models: readonly CodexSubagentModelOption[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const API_PRO_MODE_MODEL = /^gpt-(?:5\.6|[6-9]|\d{2,})(?:[._-]|$)/i
|
|
27
|
+
const LEGACY_PRO_MODEL_SLUG = /(?:^|[-_.])pro(?:$|[-_.])/i
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Models on the OpenAI Responses API that accept `reasoning.mode = "pro"`.
|
|
31
|
+
* Excludes standalone legacy `*-pro` slugs (e.g. `gpt-5.4-pro`, `gpt-5.5-pro`).
|
|
32
|
+
*/
|
|
33
|
+
export function supportsApiProMode(model: unknown): model is string {
|
|
34
|
+
if (typeof model !== 'string') return false
|
|
35
|
+
const trimmed = model.trim()
|
|
36
|
+
if (trimmed.length === 0) return false
|
|
37
|
+
const base = trimmed.includes('/') ? trimmed.slice(trimmed.lastIndexOf('/') + 1) : trimmed
|
|
38
|
+
return API_PRO_MODE_MODEL.test(base) && !LEGACY_PRO_MODEL_SLUG.test(base)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface LlmProviderRouteProfile {
|
|
42
|
+
readonly api?: string | undefined
|
|
43
|
+
readonly baseURL?: string | undefined
|
|
44
|
+
readonly baseUrl?: string | undefined
|
|
45
|
+
readonly models?: readonly { readonly id?: string; readonly api?: string; readonly baseURL?: string; readonly baseUrl?: string }[] | undefined
|
|
46
|
+
readonly modelOverrides?: Readonly<Record<string, { readonly api?: string; readonly baseURL?: string; readonly baseUrl?: string }>> | undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type LlmProvidersMap = Readonly<Record<string, LlmProviderRouteProfile>>
|
|
50
|
+
|
|
51
|
+
export interface LlmProvidersScope {
|
|
52
|
+
getSnapshot(): LlmProvidersMap | undefined
|
|
53
|
+
subscribe(listener: () => void): () => void
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** True only when `url` is an HTTPS official OpenAI API endpoint (`api.openai.com`). */
|
|
57
|
+
export function isOfficialOpenAiBaseUrl(url: unknown): boolean {
|
|
58
|
+
if (typeof url !== 'string') return false
|
|
59
|
+
const trimmed = url.trim()
|
|
60
|
+
if (trimmed.length === 0) return false
|
|
61
|
+
try {
|
|
62
|
+
const parsed = new URL(trimmed)
|
|
63
|
+
return parsed.protocol === 'https:' && parsed.hostname.toLowerCase() === 'api.openai.com'
|
|
64
|
+
} catch {
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* True only when `(provider, model)` routes to the official OpenAI Responses API
|
|
71
|
+
* (`https://api.openai.com`) on a Pro-capable GPT-5.6 / 6+ model.
|
|
72
|
+
*/
|
|
73
|
+
export function isOfficialOpenAiApiRoute(
|
|
74
|
+
provider: string | undefined,
|
|
75
|
+
model: string | undefined,
|
|
76
|
+
providers?: LlmProvidersMap | undefined,
|
|
77
|
+
): boolean {
|
|
78
|
+
if (typeof provider !== 'string' || provider.length === 0 || provider === OPENAI_CODEX_PROVIDER) return false
|
|
79
|
+
if (!supportsApiProMode(model)) return false
|
|
80
|
+
const profile = providers?.[provider]
|
|
81
|
+
const override = model !== undefined ? profile?.modelOverrides?.[model] : undefined
|
|
82
|
+
const modelEntry = model !== undefined && Array.isArray(profile?.models)
|
|
83
|
+
? profile.models.find(item => item?.id === model)
|
|
84
|
+
: undefined
|
|
85
|
+
const effectiveApi = override?.api ?? modelEntry?.api ?? profile?.api
|
|
86
|
+
if (effectiveApi !== undefined && effectiveApi !== 'openai-responses') return false
|
|
87
|
+
const effectiveBaseUrl = override?.baseURL ?? override?.baseUrl
|
|
88
|
+
?? modelEntry?.baseURL ?? modelEntry?.baseUrl
|
|
89
|
+
?? profile?.baseURL ?? profile?.baseUrl
|
|
90
|
+
if (typeof effectiveBaseUrl === 'string' && effectiveBaseUrl.trim().length > 0) {
|
|
91
|
+
return isOfficialOpenAiBaseUrl(effectiveBaseUrl)
|
|
92
|
+
}
|
|
93
|
+
return provider === 'openai'
|
|
94
|
+
}
|
|
10
95
|
|
|
11
96
|
export interface ContextWindowBounds {
|
|
12
97
|
readonly defaultTokens?: number
|
|
@@ -158,6 +243,10 @@ export interface CodexConnectSnapshot {
|
|
|
158
243
|
readonly overrides?: Readonly<Record<string, number | null>> | undefined
|
|
159
244
|
readonly baseOverrides?: Readonly<Record<string, number | null>> | undefined
|
|
160
245
|
readonly nativeCompaction?: boolean | undefined
|
|
246
|
+
readonly searchEnabled?: boolean | undefined
|
|
247
|
+
readonly searchModel?: string | undefined
|
|
248
|
+
readonly imageGenerationEnabled?: boolean | undefined
|
|
249
|
+
readonly imageModelHint?: string | undefined
|
|
161
250
|
}
|
|
162
251
|
|
|
163
252
|
export interface CodexConnectScope {
|
|
@@ -165,6 +254,8 @@ export interface CodexConnectScope {
|
|
|
165
254
|
subscribe(listener: () => void): () => void
|
|
166
255
|
setModelOverride(modelId: string, tokens: number | undefined): Promise<void>
|
|
167
256
|
setNativeCompaction?(enabled: boolean): Promise<void>
|
|
257
|
+
setSearchEnabled?(enabled: boolean): Promise<void>
|
|
258
|
+
setImageGenerationEnabled?(enabled: boolean): Promise<void>
|
|
168
259
|
}
|
|
169
260
|
|
|
170
261
|
export interface PresetPromptCatalog {
|