@shuind/dsh-codex-harness 0.2.21 → 0.3.0
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 +185 -0
- package/README.md +38 -50
- package/RELEASE.md +61 -0
- package/assets/codex.svg +5 -0
- package/cordis.patch.yml +181 -6
- package/docs/preset-library.md +33 -23
- package/docs/tool-policy-benchmark.json +310 -0
- package/docs/tool-policy.md +148 -0
- package/lib/client.js +4774 -2416
- package/lib/compact-command.js +416 -0
- package/lib/compaction.js +141 -12
- package/lib/hybrid-executor.js +1196 -0
- package/lib/index.js +3658 -2334
- package/lib/preferences.js +117 -0
- package/lib/tool-policy.js +2422 -0
- package/lib/typert.js +86 -79
- package/lib/types/client/activity.d.ts +33 -9
- package/lib/types/client/activity.js +4 -3
- package/lib/types/client/desktop.d.ts +67 -0
- package/lib/types/client/desktop.js +229 -0
- package/lib/types/client/index.d.ts +207 -110
- package/lib/types/client/index.js +99 -492
- package/lib/types/client/policy-drafts.d.ts +25 -0
- package/lib/types/client/policy-drafts.js +47 -0
- package/lib/types/client/policy-locale.d.ts +260 -0
- package/lib/types/client/policy-locale.js +357 -0
- package/lib/types/client/preset-manager.d.ts +38 -10
- package/lib/types/client/preset-manager.js +235 -185
- package/lib/types/client/preset-requests.d.ts +12 -0
- package/lib/types/client/preset-requests.js +101 -0
- package/lib/types/client/tool-policy.d.ts +33 -0
- package/lib/types/client/tool-policy.js +336 -0
- package/lib/types/contracts/preset-editor-schema.d.ts +78 -0
- package/lib/types/contracts/preset-editor-schema.js +95 -0
- package/lib/types/{prompt.js → contracts/prompt.js} +13 -7
- package/lib/types/{settings.d.ts → contracts/settings.d.ts} +11 -4
- package/lib/types/{settings.js → contracts/settings.js} +22 -6
- package/lib/types/contracts/tool-policy-contract.d.ts +63 -0
- package/lib/types/contracts/tool-policy-contract.js +33 -0
- package/lib/types/contracts/ui-contracts.d.ts +92 -0
- package/lib/types/contracts/ui-contracts.js +83 -0
- package/lib/types/entries/client.d.ts +10 -0
- package/lib/types/entries/client.js +10 -0
- package/lib/types/{compact-command.d.ts → entries/compact-command.d.ts} +2 -0
- package/lib/types/entries/compact-command.js +176 -0
- package/lib/types/{compaction.d.ts → entries/compaction.d.ts} +15 -3
- package/lib/types/{compaction.js → entries/compaction.js} +47 -11
- package/lib/types/entries/hybrid-executor.d.ts +19 -0
- package/lib/types/entries/hybrid-executor.js +57 -0
- package/lib/types/entries/index.d.ts +66 -0
- package/lib/types/entries/index.js +192 -0
- package/lib/types/entries/preferences.d.ts +11 -0
- package/lib/types/entries/preferences.js +16 -0
- package/lib/types/entries/tool-policy.d.ts +97 -0
- package/lib/types/entries/tool-policy.js +158 -0
- package/lib/types/entries/typert.host.d.ts +23 -0
- package/lib/types/entries/typert.host.js +24 -0
- package/lib/types/hybrid/codex-hybrid-executor.d.ts +44 -0
- package/lib/types/hybrid/codex-hybrid-executor.js +257 -0
- package/lib/types/hybrid/hybrid-sdk.d.ts +13 -0
- package/lib/types/hybrid/hybrid-sdk.js +196 -0
- package/lib/types/hybrid/program-calls.d.ts +28 -0
- package/lib/types/hybrid/program-calls.js +193 -0
- package/lib/types/hybrid/subcall-scheduler.d.ts +90 -0
- package/lib/types/hybrid/subcall-scheduler.js +343 -0
- package/lib/types/policy/deferred-tools.d.ts +42 -0
- package/lib/types/policy/deferred-tools.js +264 -0
- package/lib/types/policy/overlay-installer.d.ts +12 -0
- package/lib/types/policy/overlay-installer.js +179 -0
- package/lib/types/policy/rule-resolver.d.ts +94 -0
- package/lib/types/policy/rule-resolver.js +114 -0
- package/lib/types/policy/tool-capabilities.d.ts +33 -0
- package/lib/types/policy/tool-capabilities.js +46 -0
- package/lib/types/{activity.d.ts → presets/activity.d.ts} +3 -5
- package/lib/types/{activity.js → presets/activity.js} +51 -27
- package/lib/types/presets/desktop-preset.d.ts +22 -0
- package/lib/types/presets/desktop-preset.js +43 -0
- package/lib/types/presets/preset-editor.d.ts +47 -0
- package/lib/types/presets/preset-editor.js +81 -0
- package/lib/types/presets/preset-prompt-catalog.d.ts +23 -0
- package/lib/types/presets/preset-prompt-catalog.js +215 -0
- package/lib/types/presets/preset-tool-catalog.d.ts +5 -0
- package/lib/types/presets/preset-tool-catalog.js +58 -0
- package/lib/types/presets/runtime-enhancements.d.ts +45 -0
- package/lib/types/presets/runtime-enhancements.js +349 -0
- package/lib/types/presets/small-window-compaction.d.ts +15 -0
- package/lib/types/presets/small-window-compaction.js +121 -0
- package/lib/types/responses/compact-checkpoint.d.ts +27 -0
- package/lib/types/responses/compact-checkpoint.js +257 -0
- package/lib/types/responses/fetch-transport.d.ts +16 -0
- package/lib/types/responses/fetch-transport.js +257 -0
- package/lib/types/responses/remote-compact.d.ts +13 -0
- package/lib/types/responses/remote-compact.js +319 -0
- package/lib/types/responses/sse-diagnostics.d.ts +9 -0
- package/lib/types/responses/sse-diagnostics.js +157 -0
- package/lib/types/responses/wire-rewrite.d.ts +35 -0
- package/lib/types/responses/wire-rewrite.js +237 -0
- package/lib/types/tools/exec-output.d.ts +58 -0
- package/lib/types/tools/exec-output.js +173 -0
- package/lib/types/tools/exec-plan-tools.d.ts +37 -0
- package/lib/types/tools/exec-plan-tools.js +265 -0
- package/lib/types/tools/exec-runner.d.ts +21 -0
- package/lib/types/tools/exec-runner.js +385 -0
- package/lib/types/tools/patch-tool.d.ts +16 -0
- package/lib/types/tools/patch-tool.js +258 -0
- package/lib/types/{patch.d.ts → tools/patch.d.ts} +1 -1
- package/lib/types/{patch.js → tools/patch.js} +96 -21
- package/locale/en.json +6 -0
- package/locale/hybrid-executor/en.json +6 -0
- package/locale/hybrid-executor/zh.json +6 -0
- package/locale/tool-policy/en.json +6 -0
- package/locale/tool-policy/zh.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +297 -299
- package/presets/{codex-collaboration → codex-hybrid}/agent.cordis.yml +45 -48
- package/presets/codex-hybrid/preset.yml +3 -0
- package/scripts/benchmark-tool-policy.mjs +186 -0
- package/scripts/build-preset.mjs +19 -0
- package/scripts/clean-build.mjs +11 -0
- package/src/client/activity.ts +83 -0
- package/src/client/desktop.tsx +276 -0
- package/src/client/index.tsx +391 -0
- package/src/client/policy-drafts.ts +56 -0
- package/src/client/policy-locale.ts +362 -0
- package/src/client/preset-manager.tsx +376 -0
- package/src/client/preset-requests.ts +113 -0
- package/src/client/tool-policy.tsx +402 -0
- package/src/contracts/preset-editor-schema.ts +110 -0
- package/src/contracts/prompt.ts +66 -0
- package/src/contracts/settings.ts +103 -0
- package/src/contracts/tool-policy-contract.ts +93 -0
- package/src/contracts/ui-contracts.ts +173 -0
- package/src/entries/client.tsx +14 -0
- package/src/entries/compact-command.ts +256 -0
- package/src/entries/compaction.ts +218 -0
- package/src/entries/hybrid-executor.ts +76 -0
- package/src/entries/index.ts +298 -0
- package/src/entries/preferences.ts +17 -0
- package/src/entries/tool-policy.ts +162 -0
- package/src/entries/typert.host.ts +29 -0
- package/src/hybrid/codex-hybrid-executor.ts +310 -0
- package/src/hybrid/hybrid-sdk.ts +217 -0
- package/src/hybrid/program-calls.ts +202 -0
- package/src/hybrid/subcall-scheduler.ts +446 -0
- package/src/policy/deferred-tools.ts +331 -0
- package/src/policy/overlay-installer.ts +191 -0
- package/src/policy/rule-resolver.ts +128 -0
- package/src/policy/tool-capabilities.ts +88 -0
- package/src/presets/activity.ts +146 -0
- package/src/presets/desktop-preset.ts +60 -0
- package/src/presets/preset-editor.ts +101 -0
- package/src/presets/preset-prompt-catalog.ts +221 -0
- package/src/presets/preset-tool-catalog.ts +58 -0
- package/src/presets/runtime-enhancements.ts +415 -0
- package/src/presets/small-window-compaction.ts +166 -0
- package/src/responses/compact-checkpoint.ts +264 -0
- package/src/responses/fetch-transport.ts +290 -0
- package/src/responses/remote-compact.ts +393 -0
- package/src/responses/sse-diagnostics.ts +156 -0
- package/src/responses/wire-rewrite.ts +261 -0
- package/src/tools/exec-output.ts +211 -0
- package/src/tools/exec-plan-tools.ts +307 -0
- package/src/tools/exec-runner.ts +445 -0
- package/src/tools/patch-tool.ts +331 -0
- package/src/tools/patch.ts +328 -0
- package/tsconfig.json +29 -0
- package/tsdown.config.ts +110 -0
- package/lib/installer.js +0 -237
- package/lib/invariant.js +0 -23
- package/lib/types/activity-types.d.ts +0 -6
- package/lib/types/activity-types.js +0 -3
- package/lib/types/client/preset-copy.d.ts +0 -42
- package/lib/types/client/preset-copy.js +0 -81
- package/lib/types/compact-command.js +0 -79
- package/lib/types/context.d.ts +0 -8
- package/lib/types/context.js +0 -14
- package/lib/types/exec.d.ts +0 -46
- package/lib/types/exec.js +0 -365
- package/lib/types/index.d.ts +0 -95
- package/lib/types/index.js +0 -738
- package/lib/types/installer.d.ts +0 -27
- package/lib/types/installer.js +0 -146
- package/lib/types/invariant.d.ts +0 -16
- package/lib/types/invariant.js +0 -22
- package/lib/types/preset-contract.d.ts +0 -69
- package/lib/types/preset-contract.js +0 -22
- package/lib/types/preset-editor-remote.d.ts +0 -30
- package/lib/types/preset-editor-remote.js +0 -37
- package/lib/types/preset-editor.d.ts +0 -69
- package/lib/types/preset-editor.js +0 -557
- package/lib/types/preset-templates.d.ts +0 -36
- package/lib/types/preset-templates.js +0 -12
- package/lib/types/prompt-sections.d.ts +0 -15
- package/lib/types/prompt-sections.js +0 -23
- package/lib/types/remote.d.ts +0 -40
- package/lib/types/remote.js +0 -683
- package/lib/types/typert.host.d.ts +0 -47
- package/lib/types/typert.host.js +0 -99
- package/presets/codex-collaboration/preset.yml +0 -3
- /package/lib/types/{prompt.d.ts → contracts/prompt.d.ts} +0 -0
|
@@ -1,217 +1,267 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Read-only preset definition viewer and composer context-window control for Harness 0.2.2+. */
|
|
3
|
+
import { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { createPortal } from 'react-dom';
|
|
5
|
+
import { contextPresetsForBounds, formatCompactTokens, OPENAI_CODEX_MODEL_CATALOG_PATH, OPENAI_CODEX_MODEL_LIMITS, OPENAI_CODEX_PROVIDER, parseCustomContextInput, resolveContextWindowBounds, } from "../contracts/ui-contracts.js";
|
|
6
|
+
import { readPresetWithRetry } from "./preset-requests.js";
|
|
6
7
|
const documentCache = new WeakMap();
|
|
7
|
-
const CODEX_DEFAULT_ID = 'codex-collaboration';
|
|
8
8
|
function unwrap(result) {
|
|
9
9
|
if (result.ok)
|
|
10
10
|
return result.value;
|
|
11
11
|
throw new Error(result.error.message ?? 'remote-request-failed');
|
|
12
12
|
}
|
|
13
|
-
function equalEditorState(a, b) {
|
|
14
|
-
if (!a || !b)
|
|
15
|
-
return a === b;
|
|
16
|
-
return a.name === b.name && a.description === b.description && a.systemPrompt === b.systemPrompt
|
|
17
|
-
&& a.inheritPrompt === b.inheritPrompt && a.codex === b.codex
|
|
18
|
-
&& JSON.stringify(a.codexOptions) === JSON.stringify(b.codexOptions)
|
|
19
|
-
&& JSON.stringify(a.promptSections) === JSON.stringify(b.promptSections);
|
|
20
|
-
}
|
|
21
13
|
const styles = `
|
|
22
|
-
.codex-preset-editor { display:grid; gap:
|
|
23
|
-
.codex-preset-editor
|
|
24
|
-
.codex-preset-editor
|
|
25
|
-
.codex-preset-editor input:not([type=checkbox]), .codex-preset-editor textarea, .codex-preset-editor select { box-sizing:border-box; width:100%; padding:8px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; font:inherit; }
|
|
26
|
-
.codex-preset-editor textarea { resize:vertical; line-height:1.5; }
|
|
27
|
-
.codex-preset-editor button { font:inherit; padding:6px 12px; border:1px solid var(--dsw-alias-border-l2); border-radius:6px; background:var(--dsw-alias-bg-layer-3); color:inherit; cursor:pointer; }
|
|
14
|
+
.codex-preset-editor { display:grid; gap:10px; min-width:0; font-size:13px; border:0.5px solid var(--dsw-alias-settings-card-stroke, var(--dsw-alias-border-l2)); border-radius:var(--dsw-radius-xl, 12px); background:var(--dsw-alias-settings-card-fill, var(--dsw-alias-bg-layer-1)); padding:12px 14px; }
|
|
15
|
+
.codex-preset-editor .codex-preset-editor-head { display:flex; align-items:center; justify-content:space-between; gap:8px; }
|
|
16
|
+
.codex-preset-editor button { font:inherit; font-size:12px; height:30px; padding:0 11px; border:0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); border-radius:var(--dsw-radius-md, 8px); background:var(--dsw-alias-bg-layer-2); color:inherit; cursor:pointer; }
|
|
28
17
|
.codex-preset-editor button:disabled { opacity:.5; cursor:default; }
|
|
29
|
-
.codex-preset-editor
|
|
30
|
-
.codex-preset-editor
|
|
31
|
-
.codex-preset-editor .pe-toggle { display:flex; align-items:flex-start; gap:9px; }
|
|
32
|
-
.codex-preset-editor .pe-toggle span { display:grid; gap:2px; }
|
|
33
|
-
.codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-tertiary); }
|
|
18
|
+
.codex-preset-editor p { margin:0; font-size:12px; line-height:1.55; color:var(--dsw-alias-label-secondary); }
|
|
19
|
+
.codex-preset-editor pre { white-space:pre-wrap; overflow-wrap:anywhere; margin:0; padding:10px 12px; border-radius:var(--dsw-radius-md, 8px); background:var(--dsw-alias-bg-layer-2); font-size:12px; line-height:1.5; max-height:480px; overflow:auto; }
|
|
34
20
|
`;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export function PresetManagerCard({ presetManager, t }) {
|
|
40
|
-
const [catalog, setCatalog] = useState(() => catalogCache.get(presetManager));
|
|
41
|
-
const [selectedId, setSelectedId] = useState('');
|
|
42
|
-
const [original, setOriginal] = useState();
|
|
43
|
-
const [draft, setDraft] = useState();
|
|
44
|
-
const [sourceId, setSourceId] = useState('');
|
|
45
|
-
const [copyMode, setCopyMode] = useState(false);
|
|
46
|
-
const [codexEnabled, setCodexEnabled] = useState(false);
|
|
47
|
-
const [busy, setBusy] = useState(false);
|
|
21
|
+
/** A fixed-ID declaration viewer: no second picker and no write/copy actions. */
|
|
22
|
+
export function PresetDefinitionCard({ presetManager, id, t, }) {
|
|
23
|
+
const [value, setValue] = useState();
|
|
24
|
+
const [loading, setLoading] = useState(true);
|
|
48
25
|
const [error, setError] = useState('');
|
|
49
|
-
const [errorAction, setErrorAction] = useState('read');
|
|
50
|
-
const [notice, setNotice] = useState('');
|
|
51
|
-
const alive = useRef(true);
|
|
52
26
|
const request = useRef(0);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const cache = documentCache.get(presetManager);
|
|
56
|
-
const remote = presetManager.remote.codexPresetEditor;
|
|
57
|
-
const dirty = !!draft && (!original || !equalEditorState(draft, original) || codexEnabled !== draft.codex);
|
|
58
|
-
async function run(work) {
|
|
59
|
-
setBusy(true);
|
|
60
|
-
setError('');
|
|
61
|
-
setNotice('');
|
|
62
|
-
try {
|
|
63
|
-
await presetManager.ready;
|
|
64
|
-
if (alive.current)
|
|
65
|
-
await work();
|
|
66
|
-
}
|
|
67
|
-
catch (cause) {
|
|
68
|
-
if (alive.current)
|
|
69
|
-
setError(cause instanceof Error ? cause.message : String(cause));
|
|
70
|
-
}
|
|
71
|
-
finally {
|
|
72
|
-
if (alive.current)
|
|
73
|
-
setBusy(false);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
async function load(id, confirmDirty = true) {
|
|
77
|
-
if (!id)
|
|
78
|
-
return;
|
|
79
|
-
if (confirmDirty && dirty && !window.confirm(t('pmDiscard')))
|
|
80
|
-
return;
|
|
27
|
+
const alive = useRef(true);
|
|
28
|
+
async function load(refresh = false) {
|
|
81
29
|
const ticket = ++request.current;
|
|
82
|
-
|
|
30
|
+
setLoading(true);
|
|
83
31
|
setError('');
|
|
84
|
-
setNotice('');
|
|
85
|
-
setErrorAction('read');
|
|
86
|
-
const accept = (value) => {
|
|
87
|
-
if (!alive.current || ticket !== request.current)
|
|
88
|
-
return;
|
|
89
|
-
setSelectedId(id);
|
|
90
|
-
setSourceId(id);
|
|
91
|
-
setOriginal(value);
|
|
92
|
-
setDraft(value);
|
|
93
|
-
setCopyMode(false);
|
|
94
|
-
setCodexEnabled(value.codex);
|
|
95
|
-
};
|
|
96
|
-
const cached = cache.get(id);
|
|
97
|
-
if (cached && Date.now() - cached.time < 60_000) {
|
|
98
|
-
accept(cached.value);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
setDraft(undefined);
|
|
102
|
-
setOriginal(undefined);
|
|
103
|
-
setBusy(true);
|
|
104
32
|
try {
|
|
105
33
|
await presetManager.ready;
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
34
|
+
const cache = documentCache.get(presetManager) ?? new Map();
|
|
35
|
+
documentCache.set(presetManager, cache);
|
|
36
|
+
const cached = cache.get(id);
|
|
37
|
+
const document = !refresh && cached && Date.now() - cached.time < 60_000
|
|
38
|
+
? cached.value
|
|
39
|
+
: await readPresetWithRetry(() => presetManager.remote.codexPresetEditor.read(id).then(unwrap), () => alive.current && ticket === request.current);
|
|
40
|
+
if (document.id !== id)
|
|
41
|
+
throw new Error('preset-document-mismatch');
|
|
42
|
+
cache.set(id, { value: document, time: Date.now() });
|
|
43
|
+
if (alive.current && ticket === request.current)
|
|
44
|
+
setValue(document);
|
|
109
45
|
}
|
|
110
46
|
catch (cause) {
|
|
111
|
-
if (alive.current && ticket === request.current)
|
|
112
|
-
setError(String(cause));
|
|
47
|
+
if (alive.current && ticket === request.current) {
|
|
48
|
+
setError(cause instanceof Error ? cause.message : String(cause));
|
|
49
|
+
}
|
|
113
50
|
}
|
|
114
51
|
finally {
|
|
115
52
|
if (alive.current && ticket === request.current)
|
|
116
|
-
|
|
53
|
+
setLoading(false);
|
|
117
54
|
}
|
|
118
55
|
}
|
|
119
|
-
async function refresh() {
|
|
120
|
-
setErrorAction('read');
|
|
121
|
-
const value = await readPresetWithRetry(() => remote.catalog().then(unwrap), () => alive.current);
|
|
122
|
-
if (!alive.current)
|
|
123
|
-
return;
|
|
124
|
-
catalogCache.set(presetManager, value);
|
|
125
|
-
setCatalog(value);
|
|
126
|
-
const current = selectedId || (value.presets.some(row => row.id === CODEX_DEFAULT_ID) ? CODEX_DEFAULT_ID : value.presets[0]?.id ?? '');
|
|
127
|
-
if (current && current !== selectedId)
|
|
128
|
-
await load(current, false);
|
|
129
|
-
}
|
|
130
56
|
useEffect(() => {
|
|
131
57
|
alive.current = true;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}, [presetManager]);
|
|
58
|
+
void load();
|
|
59
|
+
return () => {
|
|
60
|
+
alive.current = false;
|
|
61
|
+
request.current++;
|
|
62
|
+
};
|
|
63
|
+
}, [presetManager, id]);
|
|
64
|
+
const shown = value?.id === id ? value : undefined;
|
|
65
|
+
return _jsxs("section", { className: "codex-preset-editor", "aria-label": t('settingsDefinition'), "aria-busy": loading, children: [_jsx("style", { children: styles }), _jsx("h3", { children: t('settingsDefinition') }), _jsx("code", { children: id }), _jsx("button", { type: "button", disabled: loading, onClick: () => { void load(true); }, children: t('pmRefresh') }), loading && !shown && _jsx("p", { role: "status", children: t('peLoading') }), error && _jsx("p", { role: "alert", children: t('peReadError') }), shown && _jsxs(_Fragment, { children: [_jsx("strong", { children: shown.name }), _jsx("p", { children: shown.description }), _jsx("pre", { style: { whiteSpace: 'pre-wrap', overflowWrap: 'anywhere', margin: 0 }, children: shown.composition })] })] });
|
|
66
|
+
}
|
|
67
|
+
const NOOP_SUBSCRIBE = () => () => { };
|
|
68
|
+
export const isGptModelName = (model) => typeof model === 'string' && /(?:^|\/)(?:gpt|chatgpt)(?:[-_.]|\d|$)/i.test(model);
|
|
69
|
+
export function useModelDirectory(modelDirectory) {
|
|
70
|
+
const subscribe = useCallback((listener) => modelDirectory !== undefined ? modelDirectory.subscribe(listener) : NOOP_SUBSCRIBE(), [modelDirectory]);
|
|
71
|
+
const getSnapshot = useCallback(() => modelDirectory?.getSnapshot(), [modelDirectory]);
|
|
72
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
73
|
+
}
|
|
74
|
+
export function pillStyle(active, writable) {
|
|
75
|
+
return {
|
|
76
|
+
boxSizing: 'border-box',
|
|
77
|
+
display: 'inline-flex',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
gap: 5,
|
|
80
|
+
height: 28,
|
|
81
|
+
border: 0,
|
|
82
|
+
borderRadius: 7,
|
|
83
|
+
padding: '0 6px',
|
|
84
|
+
font: 'inherit',
|
|
85
|
+
fontSize: 12,
|
|
86
|
+
lineHeight: '20px',
|
|
87
|
+
whiteSpace: 'nowrap',
|
|
88
|
+
color: active ? 'var(--dsw-static-blue-500)' : 'var(--dsw-alias-label-secondary)',
|
|
89
|
+
background: active ? 'var(--dsw-alias-interactive-bg-selected)' : 'transparent',
|
|
90
|
+
cursor: writable ? 'pointer' : 'default',
|
|
91
|
+
fontWeight: active ? 600 : 400,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
let cachedConnectCatalog;
|
|
95
|
+
let catalogFetchPromise;
|
|
96
|
+
async function loadConnectCatalog() {
|
|
97
|
+
if (cachedConnectCatalog !== undefined)
|
|
98
|
+
return cachedConnectCatalog;
|
|
99
|
+
if (typeof fetch !== 'function')
|
|
100
|
+
return undefined;
|
|
101
|
+
return catalogFetchPromise ??= fetch(OPENAI_CODEX_MODEL_CATALOG_PATH, {
|
|
102
|
+
headers: { accept: 'application/json' },
|
|
103
|
+
credentials: 'same-origin',
|
|
104
|
+
}).then(async (res) => {
|
|
105
|
+
if (!res.ok)
|
|
106
|
+
return undefined;
|
|
107
|
+
const rows = await res.json();
|
|
108
|
+
if (!Array.isArray(rows))
|
|
109
|
+
return undefined;
|
|
110
|
+
const map = {};
|
|
111
|
+
for (const row of rows) {
|
|
112
|
+
const rec = typeof row === 'object' && row !== null ? row : undefined;
|
|
113
|
+
if (rec !== undefined && typeof rec.id === 'string' && typeof rec.contextWindow === 'number' && typeof rec.maxContextWindow === 'number') {
|
|
114
|
+
map[rec.id] = { defaultTokens: rec.contextWindow, maxTokens: rec.maxContextWindow };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return cachedConnectCatalog = map;
|
|
118
|
+
}).catch(() => undefined).finally(() => { catalogFetchPromise = undefined; });
|
|
119
|
+
}
|
|
120
|
+
const contextMenuCss = `
|
|
121
|
+
.codex-ctx-menu { position:fixed; z-index:1200; width:196px; padding:6px; border-radius:10px; font-size:12px; color:var(--dsw-alias-label-primary); background:var(--dsw-alias-bg-layer-1, #1f2329); border:0.5px solid var(--dsw-alias-border-l2); box-shadow:var(--dsw-shadow-lv2, 0 6px 20px rgb(0 0 0 / 16%)); box-sizing:border-box; }
|
|
122
|
+
.codex-ctx-head { padding:4px 8px 6px; font-size:11px; color:var(--dsw-alias-label-secondary); border-bottom:0.5px solid var(--dsw-alias-border-l2); margin-bottom:4px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
123
|
+
.codex-ctx-item { display:flex; align-items:center; gap:6px; width:100%; border:0; border-radius:6px; padding:5px 8px; background:transparent; color:inherit; font:inherit; text-align:left; cursor:pointer; }
|
|
124
|
+
.codex-ctx-item:hover:not(:disabled) { background:var(--dsw-alias-interactive-bg-hover, rgb(128 128 128 / 12%)); }
|
|
125
|
+
.codex-ctx-item[aria-checked=true] { color:var(--dsw-static-blue-500); font-weight:600; }
|
|
126
|
+
.codex-ctx-item:disabled { opacity:.5; cursor:default; }
|
|
127
|
+
.codex-ctx-form { display:flex; gap:4px; margin-top:4px; padding-top:6px; border-top:0.5px solid var(--dsw-alias-border-l2); }
|
|
128
|
+
.codex-ctx-form input { flex:1; min-width:0; height:26px; padding:0 7px; border-radius:6px; border:0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); background:var(--dsw-alias-bg-layer-2); color:inherit; font:inherit; font-variant-numeric:tabular-nums; }
|
|
129
|
+
.codex-ctx-form input[aria-invalid=true] { border-color:var(--dsw-alias-state-error-primary, #e5484d); }
|
|
130
|
+
.codex-ctx-form button { height:26px; padding:0 9px; border-radius:6px; border:0.5px solid var(--dsw-alias-border-l3, var(--dsw-alias-border-l2)); background:var(--dsw-alias-bg-layer-2); color:inherit; font:inherit; cursor:pointer; }
|
|
131
|
+
`;
|
|
132
|
+
export function ContextWindowControl(props) {
|
|
133
|
+
const { useSettings, setSetting, unsetSetting, modelDirectory, getCodexConnectScope, t } = props;
|
|
134
|
+
const dirSnapshot = useModelDirectory(modelDirectory);
|
|
135
|
+
const settings = useSettings(state => state);
|
|
136
|
+
const hasDirectory = modelDirectory !== undefined;
|
|
137
|
+
const provider = dirSnapshot?.current?.provider;
|
|
138
|
+
const currentModel = dirSnapshot?.current?.model;
|
|
139
|
+
const eligible = hasDirectory ? dirSnapshot?.status === 'ready' && isGptModelName(currentModel) : true;
|
|
140
|
+
const isCodexConnect = hasDirectory && eligible && provider === OPENAI_CODEX_PROVIDER;
|
|
141
|
+
const connectScope = isCodexConnect ? getCodexConnectScope?.() : undefined;
|
|
142
|
+
const subscribeConnect = useCallback((listener) => connectScope !== undefined ? connectScope.subscribe(listener) : NOOP_SUBSCRIBE(), [connectScope]);
|
|
143
|
+
const getConnectSnapshot = useCallback(() => connectScope?.getSnapshot(), [connectScope]);
|
|
144
|
+
const connectSnap = useSyncExternalStore(subscribeConnect, getConnectSnapshot, getConnectSnapshot);
|
|
145
|
+
const [open, setOpen] = useState(false);
|
|
146
|
+
const [customInput, setCustomInput] = useState('');
|
|
147
|
+
const [customInvalid, setCustomInvalid] = useState(false);
|
|
148
|
+
const [anchorRect, setAnchorRect] = useState();
|
|
149
|
+
const [dynamicCatalog, setDynamicCatalog] = useState(() => cachedConnectCatalog);
|
|
150
|
+
const fetchedModelsRef = useRef(new Set());
|
|
151
|
+
const buttonRef = useRef(null);
|
|
152
|
+
const menuRef = useRef(null);
|
|
153
|
+
const menuId = useId();
|
|
138
154
|
useEffect(() => {
|
|
139
|
-
if (!
|
|
155
|
+
if (!isCodexConnect || currentModel === undefined)
|
|
140
156
|
return;
|
|
141
|
-
|
|
142
|
-
window.addEventListener('beforeunload', guard);
|
|
143
|
-
return () => window.removeEventListener('beforeunload', guard);
|
|
144
|
-
}, [dirty]);
|
|
145
|
-
function patch(value) { if (draft)
|
|
146
|
-
setDraft({ ...draft, ...value }); }
|
|
147
|
-
function beginCopy() {
|
|
148
|
-
if (!draft || !sourceId)
|
|
157
|
+
if (OPENAI_CODEX_MODEL_LIMITS[currentModel] !== undefined || dynamicCatalog?.[currentModel] !== undefined)
|
|
149
158
|
return;
|
|
150
|
-
|
|
151
|
-
setCodexEnabled(draft.codex);
|
|
152
|
-
setOriginal({ ...draft });
|
|
153
|
-
setDraft({ ...draft, id: '', revision: '', editable: true, name: `${draft.name} · ${t('pmCustom')}` });
|
|
154
|
-
}
|
|
155
|
-
function save() {
|
|
156
|
-
if (!draft || busy || !draft.name.trim())
|
|
159
|
+
if (fetchedModelsRef.current.has(currentModel))
|
|
157
160
|
return;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
fetchedModelsRef.current.add(currentModel);
|
|
162
|
+
let cancelled = false;
|
|
163
|
+
void loadConnectCatalog().then(catalog => {
|
|
164
|
+
if (!cancelled && catalog !== undefined)
|
|
165
|
+
setDynamicCatalog(catalog);
|
|
166
|
+
});
|
|
167
|
+
return () => { cancelled = true; };
|
|
168
|
+
}, [isCodexConnect, currentModel, dynamicCatalog]);
|
|
169
|
+
useEffect(() => { setOpen(false); setCustomInvalid(false); setCustomInput(''); }, [provider, currentModel]);
|
|
170
|
+
useEffect(() => {
|
|
171
|
+
if (!open)
|
|
172
|
+
return undefined;
|
|
173
|
+
const updateAnchor = () => {
|
|
174
|
+
const rect = buttonRef.current?.getBoundingClientRect();
|
|
175
|
+
if (rect === undefined)
|
|
168
176
|
return;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
177
|
+
setAnchorRect({
|
|
178
|
+
bottom: Math.max(8, window.innerHeight - rect.top + 6),
|
|
179
|
+
right: Math.max(8, window.innerWidth - rect.right),
|
|
180
|
+
});
|
|
181
|
+
};
|
|
182
|
+
const onKeyDown = (event) => {
|
|
183
|
+
if (event.key !== 'Escape')
|
|
184
|
+
return;
|
|
185
|
+
setOpen(false);
|
|
186
|
+
setCustomInvalid(false);
|
|
187
|
+
buttonRef.current?.focus();
|
|
188
|
+
};
|
|
189
|
+
const onPointerDown = (event) => {
|
|
190
|
+
const target = event.target;
|
|
191
|
+
if (target !== null && (buttonRef.current?.contains(target) || menuRef.current?.contains(target)))
|
|
192
|
+
return;
|
|
193
|
+
setOpen(false);
|
|
194
|
+
setCustomInvalid(false);
|
|
195
|
+
};
|
|
196
|
+
updateAnchor();
|
|
197
|
+
window.addEventListener('resize', updateAnchor);
|
|
198
|
+
window.addEventListener('scroll', updateAnchor, true);
|
|
199
|
+
window.addEventListener('keydown', onKeyDown);
|
|
200
|
+
document.addEventListener('pointerdown', onPointerDown);
|
|
201
|
+
return () => {
|
|
202
|
+
window.removeEventListener('resize', updateAnchor);
|
|
203
|
+
window.removeEventListener('scroll', updateAnchor, true);
|
|
204
|
+
window.removeEventListener('keydown', onKeyDown);
|
|
205
|
+
document.removeEventListener('pointerdown', onPointerDown);
|
|
206
|
+
};
|
|
207
|
+
}, [open]);
|
|
208
|
+
if (!(settings.value?.contextWindowControlEnabled ?? true) || !eligible)
|
|
209
|
+
return null;
|
|
210
|
+
if (isCodexConnect && connectSnap?.status === 'unavailable')
|
|
211
|
+
return null;
|
|
212
|
+
const bounds = resolveContextWindowBounds(provider, currentModel, dynamicCatalog);
|
|
213
|
+
const rawConnectOverride = isCodexConnect && typeof currentModel === 'string'
|
|
214
|
+
? connectSnap?.overrides?.[currentModel]
|
|
215
|
+
: undefined;
|
|
216
|
+
const overrideTokens = isCodexConnect
|
|
217
|
+
? (typeof rawConnectOverride === 'number' && rawConnectOverride > 0 ? rawConnectOverride : undefined)
|
|
218
|
+
: settings.value?.contextWindow;
|
|
219
|
+
const effectiveTokens = overrideTokens ?? bounds.defaultTokens;
|
|
220
|
+
const writable = isCodexConnect ? connectSnap?.writable !== false : settings.writable !== false;
|
|
221
|
+
const label = effectiveTokens !== undefined ? formatCompactTokens(effectiveTokens) : t('contextShortDefault');
|
|
222
|
+
const fullLabel = `${t('contextSize')}: ${effectiveTokens !== undefined ? `${effectiveTokens.toLocaleString()} tokens` : t('contextDefaultOption')}`;
|
|
223
|
+
const applyBudget = (tokens) => {
|
|
224
|
+
if (!writable)
|
|
225
|
+
return;
|
|
226
|
+
if (isCodexConnect) {
|
|
227
|
+
if (connectScope !== undefined && typeof currentModel === 'string') {
|
|
228
|
+
void connectScope.setModelOverride(currentModel, tokens).catch(() => { });
|
|
184
229
|
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
}
|
|
231
|
+
else if (tokens === undefined) {
|
|
232
|
+
void unsetSetting('contextWindow').catch(() => { });
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
void setSetting('contextWindow', tokens).catch(() => { });
|
|
236
|
+
}
|
|
237
|
+
setOpen(false);
|
|
238
|
+
setCustomInvalid(false);
|
|
239
|
+
setCustomInput('');
|
|
240
|
+
buttonRef.current?.focus();
|
|
241
|
+
};
|
|
242
|
+
return _jsxs(_Fragment, { children: [_jsx("button", { ref: buttonRef, type: "button", "data-codex-context-control": overrideTokens !== undefined ? 'override' : 'default', "aria-haspopup": "menu", "aria-expanded": open, "aria-controls": open ? menuId : undefined, "aria-label": fullLabel, title: fullLabel, disabled: !writable, onClick: () => {
|
|
243
|
+
if (!writable)
|
|
244
|
+
return;
|
|
245
|
+
if (!open && typeof window !== 'undefined') {
|
|
246
|
+
const rect = buttonRef.current?.getBoundingClientRect();
|
|
247
|
+
if (rect !== undefined) {
|
|
248
|
+
setAnchorRect({
|
|
249
|
+
bottom: Math.max(8, window.innerHeight - rect.top + 6),
|
|
250
|
+
right: Math.max(8, window.innerWidth - rect.right),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
setOpen(current => !current);
|
|
255
|
+
setCustomInvalid(false);
|
|
256
|
+
}, style: { ...pillStyle(overrideTokens !== undefined, writable), fontVariantNumeric: 'tabular-nums' }, children: label }), open && typeof document !== 'undefined' ? createPortal(_jsxs("div", { id: menuId, ref: menuRef, role: "menu", "aria-label": t('contextSize'), "data-codex-context-menu": true, className: "codex-ctx-menu", style: { bottom: anchorRect?.bottom ?? 48, right: anchorRect?.right ?? 16 }, children: [_jsx("style", { children: contextMenuCss }), _jsx("div", { className: "codex-ctx-head", children: `${currentModel ?? 'GPT'} · ≤${formatCompactTokens(bounds.maxTokens)}` }), _jsxs("button", { type: "button", role: "menuitemradio", className: "codex-ctx-item", "aria-checked": overrideTokens === undefined, disabled: !writable, onClick: () => applyBudget(undefined), children: [_jsx("span", { "aria-hidden": "true", style: { width: 14, textAlign: 'center' }, children: overrideTokens === undefined ? '✓' : '' }), _jsx("span", { children: bounds.defaultTokens !== undefined ? `${t('contextDefaultOption')} (${formatCompactTokens(bounds.defaultTokens)})` : t('contextDefaultOption') })] }), contextPresetsForBounds(bounds).map(tier => _jsxs("button", { type: "button", role: "menuitemradio", className: "codex-ctx-item", "aria-checked": overrideTokens === tier, disabled: !writable, onClick: () => applyBudget(tier), style: { fontVariantNumeric: 'tabular-nums' }, children: [_jsx("span", { "aria-hidden": "true", style: { width: 14, textAlign: 'center' }, children: overrideTokens === tier ? '✓' : '' }), _jsx("span", { children: formatCompactTokens(tier) })] }, tier)), _jsxs("form", { className: "codex-ctx-form", onSubmit: event => {
|
|
257
|
+
event.preventDefault();
|
|
258
|
+
const parsed = parseCustomContextInput(customInput, bounds.maxTokens);
|
|
259
|
+
if (parsed === undefined) {
|
|
260
|
+
setCustomInvalid(true);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
applyBudget(parsed);
|
|
264
|
+
}, children: [_jsx("input", { type: "text", inputMode: "numeric", placeholder: t('contextCustomPlaceholder'), "aria-label": t('contextCustomPlaceholder'), "aria-invalid": customInvalid, value: customInput, onChange: event => { setCustomInput(event.currentTarget.value); if (customInvalid)
|
|
265
|
+
setCustomInvalid(false); } }), _jsx("button", { type: "submit", disabled: !writable, children: t('contextApply') })] })] }), document.body) : null] });
|
|
215
266
|
}
|
|
216
|
-
export default PresetManagerCard;
|
|
217
267
|
//# sourceMappingURL=preset-manager.js.map
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import type { PresetCatalog } from '../contracts/ui-contracts.ts';
|
|
2
|
+
import type { PresetManagerActions } from './preset-manager.tsx';
|
|
3
|
+
import type { PresetPromptCatalog, PresetToolCatalog } from '../contracts/tool-policy-contract.ts';
|
|
4
|
+
export declare function cachedPresetCatalog(manager: PresetManagerActions): PresetCatalog | undefined;
|
|
5
|
+
export declare function cachePresetCatalog(manager: PresetManagerActions, catalog: PresetCatalog): void;
|
|
6
|
+
/** One cache and one in-flight catalog read for every surface using this manager. */
|
|
7
|
+
export declare function requestPresetCatalog(manager: PresetManagerActions, refresh?: boolean): Promise<PresetCatalog>;
|
|
8
|
+
export declare function cachedPresetTools(manager: PresetManagerActions, id: string): PresetToolCatalog | undefined;
|
|
9
|
+
/** The requested preset owns this snapshot; never substitute current-Agent tools. */
|
|
10
|
+
export declare function requestPresetTools(manager: PresetManagerActions, id: string, refresh?: boolean): Promise<PresetToolCatalog>;
|
|
11
|
+
export declare function cachedPresetPrompts(manager: PresetManagerActions, id: string): PresetPromptCatalog | undefined;
|
|
12
|
+
export declare function requestPresetPrompts(manager: PresetManagerActions, id: string, refresh?: boolean): Promise<PresetPromptCatalog>;
|
|
1
13
|
/** Only transport failures from a read can be retried without duplicating writes. */
|
|
2
14
|
export declare function isPresetConnectionError(error: unknown): boolean;
|
|
3
15
|
export declare function readPresetWithRetry<T>(read: () => Promise<T>, active: () => boolean): Promise<T>;
|
|
@@ -1,3 +1,104 @@
|
|
|
1
|
+
const catalogs = new WeakMap();
|
|
2
|
+
const catalogRequests = new WeakMap();
|
|
3
|
+
export function cachedPresetCatalog(manager) {
|
|
4
|
+
return catalogs.get(manager);
|
|
5
|
+
}
|
|
6
|
+
export function cachePresetCatalog(manager, catalog) {
|
|
7
|
+
catalogs.set(manager, catalog);
|
|
8
|
+
}
|
|
9
|
+
/** One cache and one in-flight catalog read for every surface using this manager. */
|
|
10
|
+
export function requestPresetCatalog(manager, refresh = false) {
|
|
11
|
+
const pending = catalogRequests.get(manager);
|
|
12
|
+
if (pending !== undefined)
|
|
13
|
+
return pending;
|
|
14
|
+
const cached = catalogs.get(manager);
|
|
15
|
+
if (!refresh && cached !== undefined)
|
|
16
|
+
return Promise.resolve(cached);
|
|
17
|
+
const request = (async () => {
|
|
18
|
+
await manager.ready;
|
|
19
|
+
const result = await manager.remote.codexPresetEditor.catalog();
|
|
20
|
+
if (!result.ok)
|
|
21
|
+
throw new Error(result.error.message ?? 'preset-catalog-unavailable');
|
|
22
|
+
catalogs.set(manager, result.value);
|
|
23
|
+
return result.value;
|
|
24
|
+
})();
|
|
25
|
+
catalogRequests.set(manager, request);
|
|
26
|
+
void request.finally(() => {
|
|
27
|
+
if (catalogRequests.get(manager) === request)
|
|
28
|
+
catalogRequests.delete(manager);
|
|
29
|
+
}).catch(() => { });
|
|
30
|
+
return request;
|
|
31
|
+
}
|
|
32
|
+
const toolCatalogs = new WeakMap();
|
|
33
|
+
const toolRequests = new WeakMap();
|
|
34
|
+
export function cachedPresetTools(manager, id) {
|
|
35
|
+
return toolCatalogs.get(manager)?.get(id);
|
|
36
|
+
}
|
|
37
|
+
/** The requested preset owns this snapshot; never substitute current-Agent tools. */
|
|
38
|
+
export function requestPresetTools(manager, id, refresh = false) {
|
|
39
|
+
const pending = toolRequests.get(manager)?.get(id);
|
|
40
|
+
if (pending !== undefined)
|
|
41
|
+
return pending;
|
|
42
|
+
const cached = cachedPresetTools(manager, id);
|
|
43
|
+
if (!refresh && cached !== undefined)
|
|
44
|
+
return Promise.resolve(cached);
|
|
45
|
+
const requests = toolRequests.get(manager) ?? new Map();
|
|
46
|
+
toolRequests.set(manager, requests);
|
|
47
|
+
const request = (async () => {
|
|
48
|
+
await manager.ready;
|
|
49
|
+
const remote = manager.remote.codexPresetEditor;
|
|
50
|
+
if (typeof remote.tools !== 'function')
|
|
51
|
+
throw new Error('preset-tools-unavailable');
|
|
52
|
+
const result = await remote.tools(id);
|
|
53
|
+
if (!result.ok)
|
|
54
|
+
throw new Error(result.error.message ?? 'preset-tools-unavailable');
|
|
55
|
+
if (result.value.preset !== id || result.value.registeredOnly !== true || !Array.isArray(result.value.tools)) {
|
|
56
|
+
throw new Error('preset-tools-mismatched-snapshot');
|
|
57
|
+
}
|
|
58
|
+
const catalogs = toolCatalogs.get(manager) ?? new Map();
|
|
59
|
+
catalogs.set(id, result.value);
|
|
60
|
+
toolCatalogs.set(manager, catalogs);
|
|
61
|
+
return result.value;
|
|
62
|
+
})();
|
|
63
|
+
requests.set(id, request);
|
|
64
|
+
void request.finally(() => { if (requests.get(id) === request)
|
|
65
|
+
requests.delete(id); }).catch(() => { });
|
|
66
|
+
return request;
|
|
67
|
+
}
|
|
68
|
+
const promptCatalogs = new WeakMap();
|
|
69
|
+
const promptRequests = new WeakMap();
|
|
70
|
+
export function cachedPresetPrompts(manager, id) {
|
|
71
|
+
return promptCatalogs.get(manager)?.get(id);
|
|
72
|
+
}
|
|
73
|
+
export function requestPresetPrompts(manager, id, refresh = false) {
|
|
74
|
+
const pending = promptRequests.get(manager)?.get(id);
|
|
75
|
+
if (pending !== undefined)
|
|
76
|
+
return pending;
|
|
77
|
+
const cached = cachedPresetPrompts(manager, id);
|
|
78
|
+
if (!refresh && cached !== undefined)
|
|
79
|
+
return Promise.resolve(cached);
|
|
80
|
+
const requests = promptRequests.get(manager) ?? new Map();
|
|
81
|
+
promptRequests.set(manager, requests);
|
|
82
|
+
const request = (async () => {
|
|
83
|
+
await manager.ready;
|
|
84
|
+
const remote = manager.remote.codexPresetEditor;
|
|
85
|
+
if (typeof remote.prompts !== 'function')
|
|
86
|
+
throw new Error('preset-prompts-unavailable');
|
|
87
|
+
const result = await remote.prompts(id);
|
|
88
|
+
if (!result.ok)
|
|
89
|
+
throw new Error(result.error.message ?? 'preset-prompts-unavailable');
|
|
90
|
+
if (result.value.preset !== id || !Array.isArray(result.value.sections))
|
|
91
|
+
throw new Error('preset-prompts-mismatched-snapshot');
|
|
92
|
+
const catalogs = promptCatalogs.get(manager) ?? new Map();
|
|
93
|
+
catalogs.set(id, result.value);
|
|
94
|
+
promptCatalogs.set(manager, catalogs);
|
|
95
|
+
return result.value;
|
|
96
|
+
})();
|
|
97
|
+
requests.set(id, request);
|
|
98
|
+
void request.finally(() => { if (requests.get(id) === request)
|
|
99
|
+
requests.delete(id); }).catch(() => { });
|
|
100
|
+
return request;
|
|
101
|
+
}
|
|
1
102
|
/** Only transport failures from a read can be retried without duplicating writes. */
|
|
2
103
|
export function isPresetConnectionError(error) {
|
|
3
104
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { HostObservable, PropsLocale } from '@deepseek-ai/dsh-client-ui-slots';
|
|
3
|
+
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
4
|
+
import type { PresetManagerActions } from './preset-manager.tsx';
|
|
5
|
+
import type { ToolAction, ToolActionContext, ToolPolicyRule } from '../contracts/tool-policy-contract.ts';
|
|
6
|
+
import { toolPolicyEn, toolPolicyZh } from './policy-locale.ts';
|
|
7
|
+
export type { ToolPolicyRule } from '../contracts/tool-policy-contract.ts';
|
|
8
|
+
export { toolPolicyEn, toolPolicyZh };
|
|
9
|
+
export declare const TOOL_POLICY_NAMESPACE = "codex-tool-policy";
|
|
10
|
+
export interface ToolPolicySettings {
|
|
11
|
+
readonly rules: readonly ToolPolicyRule[];
|
|
12
|
+
}
|
|
13
|
+
export type ObservableConfigForm<T> = Pick<ConfigForm<T>, 'getSnapshot' | 'subscribe' | 'mutate'>;
|
|
14
|
+
export type ToolPolicyForm = ObservableConfigForm<ToolPolicySettings>;
|
|
15
|
+
export type ToolPolicyBinding = HostObservable<ToolPolicyForm | undefined>;
|
|
16
|
+
type PolicyForms = Pick<Context['configForms'], 'get' | 'whileServed'>;
|
|
17
|
+
export declare function bindToolPolicy(ctx: Pick<Context, 'effect'>, forms: PolicyForms): ToolPolicyBinding;
|
|
18
|
+
export declare function validateToolPolicyRules(rules: readonly ToolPolicyRule[]): 'toolPolicyInvalidPreset' | 'toolPolicyDuplicatePreset' | undefined;
|
|
19
|
+
export declare function withToolAction(rule: ToolPolicyRule, name: string, action: ToolAction, context?: ToolActionContext): ToolPolicyRule;
|
|
20
|
+
export declare function saveToolPolicy(form: ToolPolicyForm, rules: readonly ToolPolicyRule[], revision: number | undefined): Promise<boolean>;
|
|
21
|
+
export type ToolPolicySubMode = 'tools' | 'prompts' | 'definition';
|
|
22
|
+
export type ToolPolicyMode = ToolPolicySubMode | 'inactive';
|
|
23
|
+
type PolicyProps = PropsLocale<'codex'> & {
|
|
24
|
+
presetManager?: PresetManagerActions | undefined;
|
|
25
|
+
mode?: ToolPolicyMode;
|
|
26
|
+
};
|
|
27
|
+
export declare function ToolPolicySection({ binding, ...props }: {
|
|
28
|
+
binding: ToolPolicyBinding;
|
|
29
|
+
} & PolicyProps): import("react").JSX.Element | null;
|
|
30
|
+
export declare function ToolPolicySettingsCard({ form, presetManager, mode, t }: {
|
|
31
|
+
form: ToolPolicyForm;
|
|
32
|
+
} & PolicyProps): import("react").JSX.Element | null;
|
|
33
|
+
//# sourceMappingURL=tool-policy.d.ts.map
|