@neta-art/cohub-cli 10.17.1 → 10.18.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/README.md +6 -0
- package/dist/board-export-resources.d.ts +2 -0
- package/dist/board-export-resources.js +1 -0
- package/dist/board-export.d.ts +4 -1
- package/dist/board-export.js +109 -23
- package/dist/board-gpu/index.d.ts +32 -0
- package/dist/board-gpu/index.js +188 -0
- package/dist/board-gpu/page.js +70178 -0
- package/dist/board-gpu/protocol.d.ts +37 -0
- package/dist/board-gpu/protocol.js +1 -0
- package/dist/board-kernel/{getPo2TextureFromSource.js → FilterPipe.js} +251 -1
- package/dist/board-kernel/browserAll.js +1 -1
- package/dist/board-kernel/init.js +1 -251
- package/dist/board-kernel/webworkerAll.js +1 -1
- package/dist/board-kernel.d.ts +3 -3
- package/dist/board-kernel.js +6624 -1462
- package/dist/board-simulate.d.ts +4 -0
- package/dist/board-simulate.js +34 -4
- package/dist/client.d.ts +1 -0
- package/dist/client.js +4 -1
- package/dist/commands/apps.js +25 -3
- package/dist/commands/boards/examples.js +21 -5
- package/dist/commands/boards.js +10 -2
- package/dist/commands/space-displays.js +301 -82
- package/dist/commands/spaces.js +11 -2
- package/dist/host/runtime.d.ts +12 -2
- package/dist/host/runtime.js +155 -10
- package/dist/host/serve.js +49 -11
- package/dist/host/workspaces.d.ts +2 -0
- package/dist/host/workspaces.js +18 -0
- package/dist/index.js +1 -0
- package/dist/runtime/cli-path.d.ts +5 -0
- package/dist/runtime/cli-path.js +27 -0
- package/dist/runtime/connection.d.ts +22 -4
- package/dist/runtime/connection.js +13 -3
- package/dist/runtime/harnesses/claude-approval.d.ts +31 -0
- package/dist/runtime/harnesses/claude-approval.js +119 -0
- package/dist/runtime/harnesses/claude.js +42 -3
- package/dist/runtime/harnesses/codex-approval.d.ts +25 -0
- package/dist/runtime/harnesses/codex-approval.js +69 -0
- package/dist/runtime/harnesses/codex.js +36 -5
- package/dist/runtime/harnesses/index.js +12 -3
- package/dist/runtime/harnesses/stream-json.d.ts +16 -2
- package/dist/runtime/harnesses/stream-json.js +26 -6
- package/dist/runtime/harnesses/types.d.ts +3 -1
- package/dist/runtime/instance.d.ts +1 -0
- package/dist/runtime/instance.js +1 -0
- package/dist/runtime/launch.js +2 -4
- package/dist/runtime/local-workspace.d.ts +15 -0
- package/dist/runtime/local-workspace.js +52 -0
- package/dist/runtime/model-catalog.js +7 -4
- package/dist/runtime/native/approvals.d.ts +18 -0
- package/dist/runtime/native/approvals.js +54 -0
- package/dist/runtime/native/codex-link.d.ts +7 -0
- package/dist/runtime/native/codex-link.js +40 -5
- package/dist/runtime/native/daemon.d.ts +5 -1
- package/dist/runtime/native/daemon.js +6 -1
- package/dist/runtime/native/execution.d.ts +2 -0
- package/dist/runtime/preferences.d.ts +7 -0
- package/dist/runtime/preferences.js +22 -0
- package/dist/runtime/presentation.d.ts +3 -0
- package/dist/runtime/presentation.js +2 -1
- package/dist/runtime/supervisor.js +92 -9
- package/dist/space-files/transfer.js +3 -2
- package/dist/space-files/upload.d.ts +5 -2
- package/dist/space-files/upload.js +41 -1
- package/package.json +2 -2
|
@@ -5,9 +5,10 @@ import { JsonRpcProcess, record } from "../json-rpc.js";
|
|
|
5
5
|
import { copyNativeArchive } from "../native/archive.js";
|
|
6
6
|
import { projectChainedSession, projectionMeta, projectionToolId, rebindSessionId } from "./chained-projection.js";
|
|
7
7
|
import { chainedSessionHeader, projectDirectory, projectTranscript } from "./chained-transcript.js";
|
|
8
|
+
import { answerClaudeApproval, claudeApprovalMode, claudeApprovalModes, claudePermissionMode, SessionGrants } from "./claude-approval.js";
|
|
8
9
|
import { CLAUDE_REPLY_ENDED, readClaudeTranscript } from "./claude-transcript.js";
|
|
9
10
|
import { array, harnessCommand, text } from "./process.js";
|
|
10
|
-
import { DEFAULT_MODEL, runStreamJson, streamJsonHelp, streamJsonModel } from "./stream-json.js";
|
|
11
|
+
import { DEFAULT_MODEL, READ_ONLY_ARGS, runStreamJson, streamJsonHelp, streamJsonModel } from "./stream-json.js";
|
|
11
12
|
const MAX_PROJECT_NAME = 200;
|
|
12
13
|
const INITIALIZE_TIMEOUT_MS = 30_000;
|
|
13
14
|
const dataRoot = () => process.env.CLAUDE_CONFIG_DIR?.trim() || join(homedir(), ".claude");
|
|
@@ -28,6 +29,31 @@ export const claudeProjectDirectory = (cwd) => join(dataRoot(), "projects", clau
|
|
|
28
29
|
const projectsRoot = () => join(dataRoot(), "projects");
|
|
29
30
|
/** Every subdirectory's project name starts with this; a hashed long name keeps its first 200 units. */
|
|
30
31
|
const projectPrefix = (cwd) => cwd.replace(/[^a-zA-Z0-9]/g, "-").slice(0, MAX_PROJECT_NAME);
|
|
32
|
+
const grants = new SessionGrants();
|
|
33
|
+
/** Probed once per executable and again with each catalog refresh; a failed probe is retried. */
|
|
34
|
+
const supportedModes = new Map();
|
|
35
|
+
/**
|
|
36
|
+
* `--permission-prompt-tool` is hidden from `--help`, so the CLI must accept it to answer `initialize`.
|
|
37
|
+
* A CLI that rejects it offers no modes; any other failure is retried.
|
|
38
|
+
*/
|
|
39
|
+
function probeApprovalModes(executable, cwd) {
|
|
40
|
+
const probe = (async () => {
|
|
41
|
+
const help = await streamJsonHelp(profile, executable, cwd);
|
|
42
|
+
try {
|
|
43
|
+
await claudeInitialize(executable, cwd, ["--permission-prompt-tool", "stdio"]);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
if (error instanceof Error && /unknown option '--permission-prompt-tool'/.test(error.message))
|
|
47
|
+
return [];
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
50
|
+
return claudeApprovalModes(help);
|
|
51
|
+
})();
|
|
52
|
+
supportedModes.set(executable, probe);
|
|
53
|
+
probe.catch(() => { if (supportedModes.get(executable) === probe)
|
|
54
|
+
supportedModes.delete(executable); });
|
|
55
|
+
return probe;
|
|
56
|
+
}
|
|
31
57
|
const profile = {
|
|
32
58
|
harness: "claude",
|
|
33
59
|
label: "Claude Code",
|
|
@@ -37,6 +63,18 @@ const profile = {
|
|
|
37
63
|
projectDirectory: claudeProjectDirectory,
|
|
38
64
|
effortLevels: ["low", "medium", "high", "xhigh", "max"],
|
|
39
65
|
promptUuid: true,
|
|
66
|
+
async approvals(executor, input) {
|
|
67
|
+
const executable = executor.executables.claude || profile.binary;
|
|
68
|
+
const modes = await (supportedModes.get(executable) ?? probeApprovalModes(executable, executor.cwd)).catch(() => []);
|
|
69
|
+
const mode = claudeApprovalMode(input, modes);
|
|
70
|
+
if (mode === "read_only")
|
|
71
|
+
return { args: READ_ONLY_ARGS };
|
|
72
|
+
const permission = claudePermissionMode(mode);
|
|
73
|
+
return {
|
|
74
|
+
args: [...(modes.length ? ["--permission-prompt-tool", "stdio"] : []), ...(permission ? ["--permission-mode", permission] : [])],
|
|
75
|
+
...(modes.length ? { answer: (request, signal) => answerClaudeApproval(request, input, executor.approvals, grants, signal) } : {}),
|
|
76
|
+
};
|
|
77
|
+
},
|
|
40
78
|
};
|
|
41
79
|
function anthropicBlock(block) {
|
|
42
80
|
if (block.type === "text")
|
|
@@ -58,8 +96,8 @@ function withAssistantIds(projection) {
|
|
|
58
96
|
}) };
|
|
59
97
|
}
|
|
60
98
|
/** Claude Code's own `/model` list (what the SDK's `supportedModels()` reads), gateway-discovered models included. */
|
|
61
|
-
async function claudeInitialize(executable, cwd) {
|
|
62
|
-
const args = ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", "--no-session-persistence", "--strict-mcp-config"];
|
|
99
|
+
async function claudeInitialize(executable, cwd, extra = []) {
|
|
100
|
+
const args = ["-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", "--no-session-persistence", "--strict-mcp-config", ...extra];
|
|
63
101
|
const host = new JsonRpcProcess(...harnessCommand(executable, args, cwd), cwd, "stream");
|
|
64
102
|
const requestId = randomUUID();
|
|
65
103
|
let timer;
|
|
@@ -131,6 +169,7 @@ export const claudeHarness = {
|
|
|
131
169
|
streamJsonModel(profile, "haiku", "Claude Haiku", { reasoning: false }),
|
|
132
170
|
];
|
|
133
171
|
},
|
|
172
|
+
approvalModes: probeApprovalModes,
|
|
134
173
|
run: (executor, turn) => runStreamJson(profile, executor, turn),
|
|
135
174
|
session: {
|
|
136
175
|
path: (nativeSessionId, cwd) => join(claudeProjectDirectory(cwd), `${nativeSessionId}.jsonl`),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ApprovalDecision, type ApprovalMode, type RuntimeTurnInput } from "@neta-art/cohub";
|
|
2
|
+
import type { ApprovalRequest } from "../native/approvals.js";
|
|
3
|
+
import { type JsonRecord } from "../json-rpc.js";
|
|
4
|
+
import type { CodexChannel } from "../native/codex-link.js";
|
|
5
|
+
import { type Version } from "../native/version.js";
|
|
6
|
+
/** First app-server whose thread and Turn approval overrides Cohub has verified. */
|
|
7
|
+
export declare const CODEX_APPROVAL_MIN_VERSION: Version;
|
|
8
|
+
export declare const codexApprovalModes: (version: Version | null) => ApprovalMode[];
|
|
9
|
+
/** The platform's read-only access always wins; `null` keeps the legacy behaviour. */
|
|
10
|
+
export declare function codexApprovalMode(input: RuntimeTurnInput, version: Version | null): ApprovalMode | null;
|
|
11
|
+
/** Overrides for opening the thread and for `turn/start`, which a loaded thread keeps for later Turns. */
|
|
12
|
+
export type CodexApproval = {
|
|
13
|
+
thread: JsonRecord;
|
|
14
|
+
turn: JsonRecord;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `inherit` sends the machine's own settings, so an existing thread drops what an earlier mode set;
|
|
18
|
+
* a new thread starts with them anyway. Only Codex resolves them (profiles, requirements).
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveCodexApproval(mode: ApprovalMode, codex: CodexChannel, cwd: string, existing: boolean): Promise<CodexApproval>;
|
|
21
|
+
export declare const codexDecision: (decision: ApprovalDecision) => {
|
|
22
|
+
decision: string;
|
|
23
|
+
};
|
|
24
|
+
/** A Codex request a person can answer on a card; others are refused as before. */
|
|
25
|
+
export declare function codexApprovalRequest(method: string, params: JsonRecord, paths: string[] | undefined): ApprovalRequest | null;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { APPROVAL_DECISIONS, APPROVAL_MODES } from "@neta-art/cohub";
|
|
2
|
+
import { record } from "../json-rpc.js";
|
|
3
|
+
import { atLeast } from "../native/version.js";
|
|
4
|
+
/** First app-server whose thread and Turn approval overrides Cohub has verified. */
|
|
5
|
+
export const CODEX_APPROVAL_MIN_VERSION = [0, 162, 1];
|
|
6
|
+
export const codexApprovalModes = (version) => atLeast(version, CODEX_APPROVAL_MIN_VERSION) ? [...APPROVAL_MODES] : [];
|
|
7
|
+
/** The platform's read-only access always wins; `null` keeps the legacy behaviour. */
|
|
8
|
+
export function codexApprovalMode(input, version) {
|
|
9
|
+
if (input.accessMode === "read_only" && input.approvalMode && input.approvalMode !== "read_only") {
|
|
10
|
+
throw new Error("The approval mode conflicts with read-only access");
|
|
11
|
+
}
|
|
12
|
+
const mode = input.accessMode === "read_only" ? "read_only" : input.approvalMode;
|
|
13
|
+
if (!mode || codexApprovalModes(version).includes(mode))
|
|
14
|
+
return mode ?? null;
|
|
15
|
+
if (!input.approvalMode)
|
|
16
|
+
return null;
|
|
17
|
+
throw new Error(`Codex approval modes need app-server ${CODEX_APPROVAL_MIN_VERSION.join(".")} or newer; update Codex and restart its app-server`);
|
|
18
|
+
}
|
|
19
|
+
const PRESETS = {
|
|
20
|
+
// Like Codex's own Read Only; Cohub refuses the approvals it would ask for.
|
|
21
|
+
read_only: { sandbox: "read-only", sandboxPolicy: { type: "readOnly", networkAccess: false }, approvalPolicy: "on-request", approvalsReviewer: "user" },
|
|
22
|
+
auto: {
|
|
23
|
+
sandbox: "workspace-write", approvalPolicy: "on-request", approvalsReviewer: "auto_review",
|
|
24
|
+
sandboxPolicy: { type: "workspaceWrite", writableRoots: [], networkAccess: false, excludeTmpdirEnvVar: false, excludeSlashTmp: false },
|
|
25
|
+
},
|
|
26
|
+
full_access: { sandbox: "danger-full-access", sandboxPolicy: { type: "dangerFullAccess" }, approvalPolicy: "never", approvalsReviewer: "user" },
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* `inherit` sends the machine's own settings, so an existing thread drops what an earlier mode set;
|
|
30
|
+
* a new thread starts with them anyway. Only Codex resolves them (profiles, requirements).
|
|
31
|
+
*/
|
|
32
|
+
export async function resolveCodexApproval(mode, codex, cwd, existing) {
|
|
33
|
+
if (mode !== "inherit") {
|
|
34
|
+
const { sandbox, sandboxPolicy, ...approval } = PRESETS[mode];
|
|
35
|
+
return { thread: { sandbox, ...approval }, turn: { sandboxPolicy, ...approval } };
|
|
36
|
+
}
|
|
37
|
+
if (!existing)
|
|
38
|
+
return { thread: {}, turn: {} };
|
|
39
|
+
const probe = await codex.request("thread/start", { cwd, ephemeral: true, config: { "features.hooks": false } });
|
|
40
|
+
const probeId = record(probe.thread).id;
|
|
41
|
+
if (typeof probeId === "string" && probeId)
|
|
42
|
+
await codex.request("thread/unsubscribe", { threadId: probeId }).catch(() => undefined);
|
|
43
|
+
const sandbox = record(probe.sandbox);
|
|
44
|
+
if (probe.approvalPolicy == null || typeof probe.approvalsReviewer !== "string" || !sandbox.type)
|
|
45
|
+
throw new Error("Codex did not report its local approval settings");
|
|
46
|
+
const approval = { approvalPolicy: probe.approvalPolicy, approvalsReviewer: probe.approvalsReviewer };
|
|
47
|
+
const profile = record(probe.activePermissionProfile).id;
|
|
48
|
+
// A named profile carries more than its sandbox policy; built-in ones are exactly it.
|
|
49
|
+
return { thread: {}, turn: typeof profile === "string" && profile && !profile.startsWith(":") ? { ...approval, permissions: profile } : { ...approval, sandboxPolicy: probe.sandbox } };
|
|
50
|
+
}
|
|
51
|
+
const CODEX_DECISIONS = { accept: "accept", accept_for_session: "acceptForSession", decline: "decline" };
|
|
52
|
+
export const codexDecision = (decision) => ({ decision: CODEX_DECISIONS[decision] });
|
|
53
|
+
const clip = (value, max) => typeof value === "string" && value ? value.slice(0, max) : undefined;
|
|
54
|
+
/** A Codex request a person can answer on a card; others are refused as before. */
|
|
55
|
+
export function codexApprovalRequest(method, params, paths) {
|
|
56
|
+
if (method !== "item/commandExecution/requestApproval" && method !== "item/fileChange/requestApproval")
|
|
57
|
+
return null;
|
|
58
|
+
// Codex may leave `decline` out of its list but accepts it; a card can always say no.
|
|
59
|
+
const offered = Array.isArray(params.availableDecisions) ? params.availableDecisions : null;
|
|
60
|
+
const decisions = APPROVAL_DECISIONS.filter((decision) => decision === "decline" || !offered || offered.includes(CODEX_DECISIONS[decision]));
|
|
61
|
+
const reason = clip(params.reason, 4096);
|
|
62
|
+
if (method === "item/fileChange/requestApproval") {
|
|
63
|
+
const changed = [...paths ?? [], ...typeof params.grantRoot === "string" ? [params.grantRoot] : []].slice(0, 100).map((path) => path.slice(0, 4096));
|
|
64
|
+
return { kind: "file_change", decisions, ...(reason ? { reason } : {}), ...(changed.length ? { paths: changed } : {}) };
|
|
65
|
+
}
|
|
66
|
+
const command = clip(params.command, 16_384);
|
|
67
|
+
const cwd = clip(params.cwd, 4096);
|
|
68
|
+
return { kind: "command", decisions, ...(command ? { command } : {}), ...(cwd ? { cwd } : {}), ...(reason ? { reason } : {}) };
|
|
69
|
+
}
|
|
@@ -4,10 +4,12 @@ import { projectNativeSession } from "@neta-art/cohub";
|
|
|
4
4
|
import { JsonRpcProcess, record } from "../json-rpc.js";
|
|
5
5
|
import { codexModelCatalog } from "../model-catalog.js";
|
|
6
6
|
import { describeError } from "../../network-error.js";
|
|
7
|
-
import { CODEX_UNLOAD_DELAY_SECS, openPrivateServer, resumeThread } from "../native/codex-link.js";
|
|
7
|
+
import { CODEX_UNLOAD_DELAY_SECS, openPrivateServer, resumeThread, runningSharedVersion } from "../native/codex-link.js";
|
|
8
8
|
import { ArchiveNotRestorableError, copyNativeArchive } from "../native/archive.js";
|
|
9
9
|
import { codexArchivedSessionsDirectory, codexRolloutBytes, codexRolloutIdOf, codexSessionsDirectory, ensurePlainCodexRollout, readFirstRecord, readNativeTranscript, } from "../native/transcript.js";
|
|
10
10
|
import { codexTranslator } from "../native/translate.js";
|
|
11
|
+
import { atLeast, harnessVersion } from "../native/version.js";
|
|
12
|
+
import { codexApprovalMode, codexApprovalModes, codexApprovalRequest, codexDecision, resolveCodexApproval } from "./codex-approval.js";
|
|
11
13
|
import { array, closeHost, harnessCommand, inlineImage, text, turnEnvironment, watchHost } from "./process.js";
|
|
12
14
|
/** A stop request that the harness does not honour within this long ends its private process. */
|
|
13
15
|
const ABORT_ESCALATION_MS = 5_000;
|
|
@@ -49,11 +51,13 @@ async function runCodex(executor, turn) {
|
|
|
49
51
|
channel = await openPrivateServer(host);
|
|
50
52
|
}
|
|
51
53
|
const codex = channel;
|
|
54
|
+
const mode = codexApprovalMode(input, codex.version);
|
|
55
|
+
const approval = mode ? await resolveCodexApproval(mode, codex, executor.cwd, prepared.resume !== "new") : null;
|
|
52
56
|
const threadOptions = {
|
|
53
57
|
cwd: executor.cwd,
|
|
54
58
|
...(input.model ? { model: input.model } : {}),
|
|
55
59
|
...(input.provider && input.provider !== "codex" ? { modelProvider: input.provider } : {}),
|
|
56
|
-
...(input.accessMode === "read_only" ? { sandbox: "read-only" } : {}),
|
|
60
|
+
...(approval ? approval.thread : input.accessMode === "read_only" ? { sandbox: "read-only" } : {}),
|
|
57
61
|
// Tools of a shared server otherwise see the environment of whoever started that server.
|
|
58
62
|
config: {
|
|
59
63
|
"shell_environment_policy.set.COHUB_SPACE_ID": input.spaceId, "shell_environment_policy.set.COHUB_SESSION_ID": input.sessionId,
|
|
@@ -79,6 +83,7 @@ async function runCodex(executor, turn) {
|
|
|
79
83
|
await turn.started(session);
|
|
80
84
|
begun = true;
|
|
81
85
|
let nativeTurnId = null;
|
|
86
|
+
const changedPaths = new Map();
|
|
82
87
|
executor.codex.driving.add(threadId);
|
|
83
88
|
await new Promise((resolve, reject) => {
|
|
84
89
|
let escalation;
|
|
@@ -101,13 +106,24 @@ async function runCodex(executor, turn) {
|
|
|
101
106
|
const off = codex.onEvent((event) => {
|
|
102
107
|
const params = event.params;
|
|
103
108
|
if (event.id != null) {
|
|
104
|
-
//
|
|
105
|
-
if (
|
|
109
|
+
// A terminal user's requests on the shared server are theirs to answer.
|
|
110
|
+
if (codex.shared && (params.threadId !== threadId || nativeTurnId && params.turnId !== nativeTurnId))
|
|
111
|
+
return;
|
|
112
|
+
const request = codexApprovalRequest(event.method, params, changedPaths.get(text(params.itemId)));
|
|
113
|
+
// A platform read-only Turn is never widened, whoever approves.
|
|
114
|
+
if (!request || input.accessMode === "read_only" || !executor.approvals.available) {
|
|
106
115
|
codex.refuse(event.id, "Approval requires an interactive local client");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const requestId = event.id;
|
|
119
|
+
void executor.approvals.request(input.sessionId, input.turnId, request, signal).then((decision) => codex.respond(requestId, codexDecision(decision)));
|
|
107
120
|
return;
|
|
108
121
|
}
|
|
109
122
|
if (params.threadId !== threadId)
|
|
110
123
|
return;
|
|
124
|
+
const item = record(params.item);
|
|
125
|
+
if (item.type === "fileChange" && Array.isArray(item.changes))
|
|
126
|
+
changedPaths.set(text(item.id), item.changes.map((change) => text(record(change).path)).filter(Boolean));
|
|
111
127
|
// A resumed thread replays its last usage; only this Turn's counts belong to it.
|
|
112
128
|
if (event.method === "thread/tokenUsage/updated" && params.turnId !== nativeTurnId)
|
|
113
129
|
return;
|
|
@@ -133,7 +149,14 @@ async function runCodex(executor, turn) {
|
|
|
133
149
|
escalation = setTimeout(() => void host?.close().catch(() => undefined), ABORT_ESCALATION_MS);
|
|
134
150
|
};
|
|
135
151
|
signal.addEventListener("abort", abort, { once: true });
|
|
136
|
-
codex.request("turn/start", {
|
|
152
|
+
codex.request("turn/start", {
|
|
153
|
+
threadId, clientUserMessageId: input.turnId, input: content,
|
|
154
|
+
// A loaded thread ignores open-time overrides and keeps these for later Turns.
|
|
155
|
+
...approval?.turn,
|
|
156
|
+
...(input.thinkingLevel ? { effort: input.thinkingLevel === "off" ? "none" : input.thinkingLevel } : {}),
|
|
157
|
+
// Only this Turn: the thread's own tier, and so a terminal user's, stays as it was.
|
|
158
|
+
...(input.serviceTier ? { serviceTierForTurn: input.serviceTier } : {}),
|
|
159
|
+
})
|
|
137
160
|
.then((result) => { nativeTurnId ??= text(record(result.turn).id) || null; if (signal.aborted)
|
|
138
161
|
interrupt(); })
|
|
139
162
|
.catch(finish);
|
|
@@ -189,6 +212,14 @@ export const codexHarness = {
|
|
|
189
212
|
await rpc.close();
|
|
190
213
|
}
|
|
191
214
|
},
|
|
215
|
+
async approvalModes(executable) {
|
|
216
|
+
const [binary, running] = await Promise.all([harnessVersion(executable), runningSharedVersion()]);
|
|
217
|
+
// A failed probe keeps the previous modes; Turns still check the server they run on.
|
|
218
|
+
if (!binary)
|
|
219
|
+
throw new Error("Codex did not report its version");
|
|
220
|
+
// Turns use the binary or, when sharing, a server already running: offer only what both support.
|
|
221
|
+
return codexApprovalModes(running && !atLeast(running, binary) ? running : binary);
|
|
222
|
+
},
|
|
192
223
|
run: runCodex,
|
|
193
224
|
session: {
|
|
194
225
|
path: (nativeSessionId) => codexSessionPath(nativeSessionId),
|
|
@@ -30,6 +30,15 @@ export async function installedHarnesses(cwd, executables, path = process.env.PA
|
|
|
30
30
|
}));
|
|
31
31
|
return found.filter((harness) => harness !== null);
|
|
32
32
|
}
|
|
33
|
+
/** Whatever a harness offers beyond its models. A failed probe keeps `previous`, never failing discovery. */
|
|
34
|
+
async function harnessFeatures(harnesses, executables, cwd, previous) {
|
|
35
|
+
const entries = await Promise.all(harnesses.map(async (harness) => {
|
|
36
|
+
const modes = await adapters()[harness].approvalModes?.(harnessExecutable(harness, executables), cwd).catch(() => previous?.approvalModes?.[harness] ?? []);
|
|
37
|
+
return modes?.length ? [[harness, modes]] : [];
|
|
38
|
+
}));
|
|
39
|
+
const approvalModes = Object.fromEntries(entries.flat());
|
|
40
|
+
return Object.keys(approvalModes).length ? { approvalModes } : {};
|
|
41
|
+
}
|
|
33
42
|
/**
|
|
34
43
|
* Explicitly requested harnesses must all work. With `onUnavailable`, a failing harness is reported
|
|
35
44
|
* and left out instead, so auto-discovery still starts with the ones that work.
|
|
@@ -46,8 +55,8 @@ export async function discoverHarnesses(harnesses, executables, cwd, onUnavailab
|
|
|
46
55
|
return null;
|
|
47
56
|
}
|
|
48
57
|
}));
|
|
49
|
-
const available = catalogs.filter((catalog) => catalog !== null);
|
|
50
|
-
return { harnesses: available
|
|
58
|
+
const available = catalogs.filter((catalog) => catalog !== null).map((catalog) => catalog.harness);
|
|
59
|
+
return { harnesses: available, models: catalogs.flatMap((catalog) => catalog?.models ?? []), ...await harnessFeatures(available, executables, cwd) };
|
|
51
60
|
}
|
|
52
61
|
/** Rediscover the running harnesses' models; a harness that fails keeps its previous models. */
|
|
53
62
|
export async function refreshHarnesses(current, executables, cwd, onUnavailable) {
|
|
@@ -60,5 +69,5 @@ export async function refreshHarnesses(current, executables, cwd, onUnavailable)
|
|
|
60
69
|
return current.models.filter((model) => model.harness === harness);
|
|
61
70
|
}
|
|
62
71
|
}));
|
|
63
|
-
return { harnesses: current.harnesses, models: catalogs.flat() };
|
|
72
|
+
return { harnesses: current.harnesses, models: catalogs.flat(), ...await harnessFeatures(current.harnesses, executables, cwd, current) };
|
|
64
73
|
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { type ContentBlock, type RuntimeMessage, type RuntimeTurnInput } from "@neta-art/cohub";
|
|
2
|
+
import { type JsonRecord } from "../json-rpc.js";
|
|
2
3
|
import type { Executor } from "../native/execution.js";
|
|
3
4
|
import type { HarnessModel, HarnessRun, HarnessTurn } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Plan mode still honours the user's allow rules, so a read-only Turn also gets only these
|
|
7
|
+
* built-in tools and no configured MCP servers.
|
|
8
|
+
*/
|
|
9
|
+
export declare const READ_ONLY_ARGS: string[];
|
|
4
10
|
/** Runs without `--model`, so the CLI's own configuration and account default apply. */
|
|
5
11
|
export declare const DEFAULT_MODEL = "default";
|
|
6
12
|
/** A Claude Code–compatible CLI (`-p --input-format stream-json --output-format stream-json`). */
|
|
@@ -16,6 +22,14 @@ export type StreamJsonProfile = {
|
|
|
16
22
|
effortLevels: readonly string[];
|
|
17
23
|
/** The CLI keeps a stream-json prompt's `uuid` as its record id, so the file names the Cohub Turn. */
|
|
18
24
|
promptUuid: boolean;
|
|
25
|
+
/** Without it, a Turn with full access runs `acceptEdits` and every permission prompt is denied. */
|
|
26
|
+
approvals?(executor: Executor, input: RuntimeTurnInput): Promise<StreamJsonApprovals | null>;
|
|
27
|
+
};
|
|
28
|
+
export type StreamJsonApprovals = {
|
|
29
|
+
/** Replaces `--permission-mode acceptEdits`. */
|
|
30
|
+
args: string[];
|
|
31
|
+
/** Answers a `can_use_tool` request; absent, it is denied. */
|
|
32
|
+
answer?(request: JsonRecord, signal: AbortSignal): Promise<JsonRecord>;
|
|
19
33
|
};
|
|
20
34
|
/** The CLI's help, after checking it offers every flag a Turn uses. */
|
|
21
35
|
export declare function streamJsonHelp(profile: StreamJsonProfile, executable: string, cwd: string): Promise<string>;
|
|
@@ -28,7 +42,7 @@ export declare function streamJsonModel(profile: StreamJsonProfile, id: string,
|
|
|
28
42
|
export declare function streamContent(value: unknown): ContentBlock[];
|
|
29
43
|
export declare function streamUsage(value: unknown, cost: unknown): RuntimeMessage["usage"];
|
|
30
44
|
/**
|
|
31
|
-
* One Turn per process.
|
|
32
|
-
* `acceptEdits` and every other tool
|
|
45
|
+
* One Turn per process. Cohub grants a permission prompt only through the profile's approvals;
|
|
46
|
+
* otherwise workspace edits follow `acceptEdits` and every other tool the user's own rules.
|
|
33
47
|
*/
|
|
34
48
|
export declare function runStreamJson(profile: StreamJsonProfile, executor: Executor, turn: HarnessTurn): Promise<HarnessRun>;
|
|
@@ -16,7 +16,7 @@ const FLUSH_TIMEOUT_MS = 10_000;
|
|
|
16
16
|
* Plan mode still honours the user's allow rules, so a read-only Turn also gets only these
|
|
17
17
|
* built-in tools and no configured MCP servers.
|
|
18
18
|
*/
|
|
19
|
-
const
|
|
19
|
+
export const READ_ONLY_ARGS = ["--permission-mode", "plan", "--tools", "Read,Glob,Grep", "--strict-mcp-config"];
|
|
20
20
|
/** Flags every Turn relies on; an executable whose help lacks one is an older or unrelated CLI. */
|
|
21
21
|
const REQUIRED_FLAGS = ["--input-format", "--output-format", "--include-partial-messages", "--session-id", "--resume", "--permission-mode", "--tools", "--strict-mcp-config", "--model", "--effort"];
|
|
22
22
|
/** Runs without `--model`, so the CLI's own configuration and account default apply. */
|
|
@@ -205,8 +205,8 @@ function streamJsonTranslator(emit, identity) {
|
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
207
|
/**
|
|
208
|
-
* One Turn per process.
|
|
209
|
-
* `acceptEdits` and every other tool
|
|
208
|
+
* One Turn per process. Cohub grants a permission prompt only through the profile's approvals;
|
|
209
|
+
* otherwise workspace edits follow `acceptEdits` and every other tool the user's own rules.
|
|
210
210
|
*/
|
|
211
211
|
export async function runStreamJson(profile, executor, turn) {
|
|
212
212
|
const { input, signal, context } = turn;
|
|
@@ -220,12 +220,13 @@ export async function runStreamJson(profile, executor, turn) {
|
|
|
220
220
|
if (profile.promptUuid && prepared.resume === "native" && await holdsPrompt(prepared.session.path, input.turnId, signal))
|
|
221
221
|
prepared = await prepare(() => false);
|
|
222
222
|
let session = prepared.session;
|
|
223
|
+
const approvals = await profile.approvals?.(executor, input) ?? null;
|
|
223
224
|
// Cohub has already fitted the level to the levels the model declares; these CLIs have no `off` effort.
|
|
224
225
|
const effort = isModelThinkingLevel(input.thinkingLevel) && input.thinkingLevel !== "off" ? input.thinkingLevel : null;
|
|
225
226
|
const args = [
|
|
226
227
|
"-p", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose", "--include-partial-messages",
|
|
227
228
|
...(prepared.resume === "new" ? ["--session-id", session.nativeSessionId] : ["--resume", session.nativeSessionId]),
|
|
228
|
-
...(input.accessMode === "read_only" ?
|
|
229
|
+
...(input.accessMode === "read_only" ? READ_ONLY_ARGS : approvals?.args ?? ["--permission-mode", "acceptEdits"]),
|
|
229
230
|
...(input.model && input.model !== DEFAULT_MODEL ? ["--model", input.model] : []),
|
|
230
231
|
...(effort ? ["--effort", effort] : []),
|
|
231
232
|
];
|
|
@@ -236,6 +237,8 @@ export async function runStreamJson(profile, executor, turn) {
|
|
|
236
237
|
const translator = streamJsonTranslator(turn.emit, { provider: input.provider || profile.provider, model: input.model && input.model !== DEFAULT_MODEL ? input.model : null });
|
|
237
238
|
let message = { ordinal: 0, content: [] };
|
|
238
239
|
let begun = false;
|
|
240
|
+
// Open approvals close with the process, not only when the Turn is stopped.
|
|
241
|
+
const approvalScope = new AbortController();
|
|
239
242
|
try {
|
|
240
243
|
await turn.started(session);
|
|
241
244
|
begun = true;
|
|
@@ -250,6 +253,7 @@ export async function runStreamJson(profile, executor, turn) {
|
|
|
250
253
|
offFailure();
|
|
251
254
|
signal.removeEventListener("abort", abort);
|
|
252
255
|
clearTimeout(escalation);
|
|
256
|
+
approvalScope.abort();
|
|
253
257
|
if (error)
|
|
254
258
|
reject(error);
|
|
255
259
|
else
|
|
@@ -257,10 +261,26 @@ export async function runStreamJson(profile, executor, turn) {
|
|
|
257
261
|
};
|
|
258
262
|
const offFailure = host.onFailure((error) => finish(error));
|
|
259
263
|
const off = host.onEvent((event) => {
|
|
260
|
-
// An unattended Cohub Turn never grants a permission request.
|
|
261
264
|
if (event.type === "control_request") {
|
|
265
|
+
const respond = (response) => host.write({ type: "control_response", response: { subtype: "success", request_id: event.request_id, response } });
|
|
266
|
+
const request = record(event.request);
|
|
267
|
+
if (approvals?.answer && request.subtype === "can_use_tool" && input.accessMode !== "read_only") {
|
|
268
|
+
void approvals.answer(request, AbortSignal.any([signal, approvalScope.signal]))
|
|
269
|
+
.catch(() => ({ behavior: "deny", message: "Approval failed" }))
|
|
270
|
+
.then((response) => {
|
|
271
|
+
if (done)
|
|
272
|
+
return;
|
|
273
|
+
try {
|
|
274
|
+
respond(response);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
finish(error);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
262
282
|
try {
|
|
263
|
-
|
|
283
|
+
respond({ behavior: "deny", message: "Approval requires an interactive local client" });
|
|
264
284
|
}
|
|
265
285
|
catch (error) {
|
|
266
286
|
finish(error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LocalHarness, NativeProjection, ProjectionInput, ProjectionRecord, RuntimeCapabilities, RuntimeExecutionEvent, RuntimeMessage, RuntimeTurnInput } from "@neta-art/cohub";
|
|
1
|
+
import type { ApprovalMode, LocalHarness, NativeProjection, ProjectionInput, ProjectionRecord, RuntimeCapabilities, RuntimeExecutionEvent, RuntimeMessage, RuntimeTurnInput } from "@neta-art/cohub";
|
|
2
2
|
import type { JsonRpcProcess } from "../json-rpc.js";
|
|
3
3
|
import type { RuntimeDiagnosticContext } from "../diagnostics.js";
|
|
4
4
|
import type { Executor } from "../native/execution.js";
|
|
@@ -108,6 +108,8 @@ export type LocalHarnessAdapter = {
|
|
|
108
108
|
models(executable: string, cwd: string, options?: {
|
|
109
109
|
strict?: boolean;
|
|
110
110
|
}): Promise<HarnessModel[]>;
|
|
111
|
+
/** Approval modes this installation enforces; absent or empty hides the choice. */
|
|
112
|
+
approvalModes?(executable: string, cwd: string): Promise<ApprovalMode[]>;
|
|
111
113
|
run(executor: Executor, turn: HarnessTurn): Promise<HarnessRun>;
|
|
112
114
|
session: NativeSessionFormat;
|
|
113
115
|
/** Every harness reads its own transcripts, so terminal conversations sync to the Space. */
|
|
@@ -8,6 +8,7 @@ type Response = {
|
|
|
8
8
|
export declare function requestRuntimeInstance(directory: string, action?: "status" | "stop", force?: boolean): Promise<RuntimeSummary | null>;
|
|
9
9
|
/** Send a control action to the running Runtime; `null` when none runs. */
|
|
10
10
|
export declare function controlRuntimeInstance(directory: string, action: string, payload?: Record<string, unknown>, timeoutMs?: number): Promise<Response | null>;
|
|
11
|
+
export declare const UNCONFIRMED_WORK = "Unconfirmed executions remain";
|
|
11
12
|
export declare function stopRuntimeInstance(directory: string, force?: boolean): Promise<RuntimeSummary | null>;
|
|
12
13
|
export declare function watchRuntimeInstance(directory: string, onStatus: (status: RuntimeSummary) => void, signal?: AbortSignal): Promise<boolean>;
|
|
13
14
|
export type RuntimeInstanceHandle = {
|
package/dist/runtime/instance.js
CHANGED
|
@@ -99,6 +99,7 @@ export async function controlRuntimeInstance(directory, action, payload = {}, ti
|
|
|
99
99
|
throw error;
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
+
export const UNCONFIRMED_WORK = "Unconfirmed executions remain";
|
|
102
103
|
export async function stopRuntimeInstance(directory, force = false) {
|
|
103
104
|
const local = await requestRuntimeInstance(directory, "stop", force);
|
|
104
105
|
const until = Date.now() + 15_000;
|
package/dist/runtime/launch.js
CHANGED
|
@@ -155,8 +155,6 @@ export async function runtimeUp(program, dir, options) {
|
|
|
155
155
|
display = parseRuntimeDisplay(options.display);
|
|
156
156
|
if (!options.harness.length)
|
|
157
157
|
harnesses = await installedHarnesses(root, executables);
|
|
158
|
-
if (!harnesses.length)
|
|
159
|
-
throw new Error(`Install and sign in to ${LOCAL_HARNESSES.map((harness) => LOCAL_HARNESS_SPECS[harness].label).join(", ")}, or pass --harness`);
|
|
160
158
|
let createNew = Boolean(options.new);
|
|
161
159
|
let name = resolveLocalSpaceName(root, options.name);
|
|
162
160
|
if (!options.yes) {
|
|
@@ -205,9 +203,9 @@ export async function runtimeUp(program, dir, options) {
|
|
|
205
203
|
const capabilities = await discoverHarnesses(harnesses, executables, root, options.harness.length ? undefined : (harness, error) => {
|
|
206
204
|
process.stderr.write(`Skipping ${LOCAL_HARNESS_SPECS[harness].label}: ${serializeDiagnosticError(error).message.split("\n")[0]}\n`);
|
|
207
205
|
});
|
|
208
|
-
if (!capabilities.harnesses.length)
|
|
209
|
-
throw new Error("No installed harness could start; fix the warnings above or pass --harness");
|
|
210
206
|
harnesses = capabilities.harnesses;
|
|
207
|
+
if (!harnesses.length)
|
|
208
|
+
process.stderr.write(`No local Harness found (${LOCAL_HARNESSES.map((harness) => LOCAL_HARNESS_SPECS[harness].label).join(", ")}); Turns run on Cohub. Reconnect after installing one\n`);
|
|
211
209
|
const client = createClient();
|
|
212
210
|
const { spaceId, source } = await resolveRuntimeSpace({
|
|
213
211
|
root, identityKey: identity, explicitSpaceId: requested,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type LocalWorkspaceResolver, type LocalWorkspaceTransport } from "@neta-art/cohub";
|
|
2
|
+
export declare const connectLocalWorkspace: (endpoint: Endpoint) => LocalWorkspaceTransport;
|
|
3
|
+
type Endpoint = {
|
|
4
|
+
url: string;
|
|
5
|
+
token: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function findLocalWorkspace(spaceId: string): Promise<Endpoint | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Files and displays of a Space this machine serves go straight to its Runtime,
|
|
10
|
+
* looked up once per account and process. Only the signed-in owner goes direct: a scoped
|
|
11
|
+
* execution token stays on the API that enforces its scope, as does
|
|
12
|
+
* `COHUB_NO_DIRECT=1`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveLocalWorkspace: LocalWorkspaceResolver;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Agent, request } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
import { loopbackWorkspace } from "@neta-art/cohub";
|
|
4
|
+
import { currentIdentityKey } from "../space.js";
|
|
5
|
+
import { controlRuntimeInstance, runtimeInstanceDirectory } from "./instance.js";
|
|
6
|
+
const DISCOVERY_TIMEOUT_MS = 1_500;
|
|
7
|
+
const NULL_BODY_STATUS = new Set([204, 304]);
|
|
8
|
+
/** Its own agent keeps requests off the proxy `--use-env-proxy` gives global fetch and http: they carry the Runtime's token. */
|
|
9
|
+
const direct = new Agent({ keepAlive: true });
|
|
10
|
+
const loopbackFetch = (input, init = {}) => new Promise((resolve, reject) => {
|
|
11
|
+
const client = request(String(input), { agent: direct, method: init.method ?? "GET", headers: Object.fromEntries(new Headers(init.headers)), signal: init.signal ?? undefined }, (response) => {
|
|
12
|
+
const headers = new Headers(Object.entries(response.headers).flatMap(([name, value]) => [value ?? []].flat().map((item) => [name, item])));
|
|
13
|
+
const status = response.statusCode ?? 502;
|
|
14
|
+
resolve(new Response(NULL_BODY_STATUS.has(status) ? null : Readable.toWeb(response), { status, headers }));
|
|
15
|
+
});
|
|
16
|
+
client.on("error", (cause) => reject(new TypeError("fetch failed", { cause })));
|
|
17
|
+
const { body } = init;
|
|
18
|
+
if (body instanceof Blob)
|
|
19
|
+
Readable.from(body.stream()).on("error", (error) => client.destroy(error)).pipe(client);
|
|
20
|
+
else
|
|
21
|
+
client.end(typeof body === "string" ? body : undefined);
|
|
22
|
+
});
|
|
23
|
+
export const connectLocalWorkspace = (endpoint) => loopbackWorkspace(endpoint, loopbackFetch);
|
|
24
|
+
const isEndpoint = (value) => {
|
|
25
|
+
const endpoint = value;
|
|
26
|
+
return typeof endpoint?.token === "string" && typeof endpoint.url === "string" && /^http:\/\/127\.0\.0\.1:\d+$/.test(endpoint.url);
|
|
27
|
+
};
|
|
28
|
+
export async function findLocalWorkspace(spaceId) {
|
|
29
|
+
const identity = currentIdentityKey();
|
|
30
|
+
if (!identity)
|
|
31
|
+
return null;
|
|
32
|
+
const response = await controlRuntimeInstance(runtimeInstanceDirectory(identity, spaceId), "workspace", {}, DISCOVERY_TIMEOUT_MS).catch(() => null);
|
|
33
|
+
return isEndpoint(response?.result) ? response.result : null;
|
|
34
|
+
}
|
|
35
|
+
const found = new Map();
|
|
36
|
+
/**
|
|
37
|
+
* Files and displays of a Space this machine serves go straight to its Runtime,
|
|
38
|
+
* looked up once per account and process. Only the signed-in owner goes direct: a scoped
|
|
39
|
+
* execution token stays on the API that enforces its scope, as does
|
|
40
|
+
* `COHUB_NO_DIRECT=1`.
|
|
41
|
+
*/
|
|
42
|
+
export const resolveLocalWorkspace = (spaceId) => {
|
|
43
|
+
if (process.env.COHUB_NO_DIRECT === "1" || process.env.COHUB_EXECUTION_TOKEN?.trim())
|
|
44
|
+
return null;
|
|
45
|
+
const key = `${currentIdentityKey()}\0${spaceId}`;
|
|
46
|
+
let workspace = found.get(key);
|
|
47
|
+
if (!workspace) {
|
|
48
|
+
workspace = findLocalWorkspace(spaceId).then((endpoint) => (endpoint ? connectLocalWorkspace(endpoint) : null));
|
|
49
|
+
found.set(key, workspace);
|
|
50
|
+
}
|
|
51
|
+
return workspace;
|
|
52
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isModelThinkingLevel, MODEL_THINKING_LEVELS as thinkingLevels, RUNTIME_MAX_SERVICE_TIERS, runtimeServiceTierSchema, thinkingLevelMapFor } from "@neta-art/cohub";
|
|
1
|
+
import { isModelThinkingLevel, MODEL_THINKING_LEVELS as thinkingLevels, RUNTIME_MAX_SERVICE_TIERS, runtimeServiceTierSchema, STANDARD_SERVICE_TIER, thinkingLevelMapFor } from "@neta-art/cohub";
|
|
2
2
|
import { record } from "./json-rpc.js";
|
|
3
3
|
const thinkingLevel = (value) => isModelThinkingLevel(value) ? value : undefined;
|
|
4
4
|
/**
|
|
@@ -46,7 +46,7 @@ function codexThinking(model, configuredEffort) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
/** `serviceTiers` supersedes the deprecated `additionalSpeedTiers`, which only names tier ids. */
|
|
49
|
-
function codexServiceTiers(model) {
|
|
49
|
+
function codexServiceTiers(model, configuredTier) {
|
|
50
50
|
const candidates = Array.isArray(model.serviceTiers)
|
|
51
51
|
? model.serviceTiers.map((entry) => {
|
|
52
52
|
const tier = record(entry);
|
|
@@ -58,7 +58,10 @@ function codexServiceTiers(model) {
|
|
|
58
58
|
const parsed = runtimeServiceTierSchema.safeParse(tier);
|
|
59
59
|
return parsed.success ? [parsed.data] : [];
|
|
60
60
|
}).slice(0, RUNTIME_MAX_SERVICE_TIERS);
|
|
61
|
-
|
|
61
|
+
// A configured `service_tier` replaces the catalog default; `fast` is its legacy name for `priority`.
|
|
62
|
+
const configured = configuredTier === "fast" ? "priority" : configuredTier;
|
|
63
|
+
const preferred = configured === STANDARD_SERVICE_TIER ? undefined : typeof configured === "string" && configured ? configured : model.defaultServiceTier;
|
|
64
|
+
const defaultServiceTier = typeof preferred === "string" && tiers.some((tier) => tier.id === preferred) ? preferred : undefined;
|
|
62
65
|
return { ...(tiers.length ? { serviceTiers: tiers } : {}), ...(defaultServiceTier ? { defaultServiceTier } : {}) };
|
|
63
66
|
}
|
|
64
67
|
/** Use Codex's picker-visible model/list for every provider, including custom providers. */
|
|
@@ -73,7 +76,7 @@ export function codexModelCatalog(configResponse, entries) {
|
|
|
73
76
|
return [];
|
|
74
77
|
// A configured model replaces the catalog's own default.
|
|
75
78
|
const isDefault = configuredModel ? id === configuredModel : model.isDefault === true;
|
|
76
|
-
return [{ harness: "codex", provider, id, name: typeof model.displayName === "string" ? model.displayName : id, ...(isDefault ? { isDefault } : {}), ...codexThinking(model, config.model_reasoning_effort), ...codexServiceTiers(model) }];
|
|
79
|
+
return [{ harness: "codex", provider, id, name: typeof model.displayName === "string" ? model.displayName : id, ...(isDefault ? { isDefault } : {}), ...codexThinking(model, config.model_reasoning_effort), ...codexServiceTiers(model, config.service_tier) }];
|
|
77
80
|
});
|
|
78
81
|
if (configuredModel && !models.some((model) => model.id === configuredModel))
|
|
79
82
|
models.unshift({ harness: "codex", provider, id: configuredModel, name: configuredModel, isDefault: true });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ApprovalDecision, NativeRuntimeEvent, RuntimeApproval, RuntimeApprovalDecision } from "@neta-art/cohub";
|
|
2
|
+
/** How long a card waits for a person; unanswered, the request is declined. */
|
|
3
|
+
export declare const APPROVAL_TIMEOUT_MS: number;
|
|
4
|
+
type Send = (event: NativeRuntimeEvent) => Promise<unknown>;
|
|
5
|
+
export type ApprovalRequest = Omit<RuntimeApproval, "id" | "requestedAt" | "expiresAt">;
|
|
6
|
+
/** Asks the web for a decision over the control connection; without one, it declines. */
|
|
7
|
+
export declare class ApprovalBroker {
|
|
8
|
+
private readonly timeoutMs;
|
|
9
|
+
private send;
|
|
10
|
+
private readonly pending;
|
|
11
|
+
constructor(timeoutMs?: number);
|
|
12
|
+
/** `null` when the Gateway cannot relay decisions; open cards are then declined. */
|
|
13
|
+
connect(send: Send | null): void;
|
|
14
|
+
get available(): boolean;
|
|
15
|
+
request(sessionId: string, turnId: string, request: ApprovalRequest, signal: AbortSignal): Promise<ApprovalDecision>;
|
|
16
|
+
decide(input: Pick<RuntimeApprovalDecision, "sessionId" | "turnId" | "approvalId" | "decision">): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|