@botiverse/oar 0.0.11 → 0.1.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 +2 -2
- package/dist/contracts/model-catalog.d.ts +1 -1
- package/dist/contracts/model-catalog.js +1 -1
- package/dist/contracts/provider-auth.d.ts +2 -2
- package/dist/contracts/provider-auth.js +2 -2
- package/dist/contracts/records.d.ts +205 -0
- package/dist/contracts/records.d.ts.map +1 -0
- package/dist/contracts/records.js +8 -0
- package/dist/contracts/records.js.map +1 -0
- package/dist/contracts/session.d.ts +83 -144
- package/dist/contracts/session.d.ts.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/observe/agent-status.d.ts +32 -18
- package/dist/observe/agent-status.d.ts.map +1 -1
- package/dist/observe/agent-status.js +66 -14
- package/dist/observe/agent-status.js.map +1 -1
- package/dist/observe/aggregate-events.d.ts +7 -6
- package/dist/observe/aggregate-events.d.ts.map +1 -1
- package/dist/observe/aggregate-events.js +38 -28
- package/dist/observe/aggregate-events.js.map +1 -1
- package/dist/observe/index.d.ts +4 -1
- package/dist/observe/index.d.ts.map +1 -1
- package/dist/observe/index.js +3 -1
- package/dist/observe/index.js.map +1 -1
- package/dist/observe/observe-agent.d.ts +4 -4
- package/dist/observe/observe-agent.d.ts.map +1 -1
- package/dist/observe/observe-agent.js +3 -3
- package/dist/observe/observe-agent.js.map +1 -1
- package/dist/observe/stall-observer.d.ts +7 -6
- package/dist/observe/stall-observer.d.ts.map +1 -1
- package/dist/observe/stall-observer.js +6 -5
- package/dist/observe/stall-observer.js.map +1 -1
- package/dist/observe/tool-activity.d.ts +2 -2
- package/dist/observe/tool-activity.d.ts.map +1 -1
- package/dist/observe/tool-activity.js +1 -1
- package/dist/observe/tool-activity.js.map +1 -1
- package/dist/observe/turns.d.ts +37 -0
- package/dist/observe/turns.d.ts.map +1 -0
- package/dist/observe/turns.js +70 -0
- package/dist/observe/turns.js.map +1 -0
- package/dist/observe/usage.d.ts +15 -0
- package/dist/observe/usage.d.ts.map +1 -0
- package/dist/observe/usage.js +79 -0
- package/dist/observe/usage.js.map +1 -0
- package/dist/runtimes/claude/account-usage.js +1 -1
- package/dist/runtimes/claude/context-usage.d.ts +1 -1
- package/dist/runtimes/claude/context-usage.js +1 -1
- package/dist/runtimes/claude/projection.d.ts +40 -27
- package/dist/runtimes/claude/projection.d.ts.map +1 -1
- package/dist/runtimes/claude/projection.js +107 -21
- package/dist/runtimes/claude/projection.js.map +1 -1
- package/dist/runtimes/claude/session.d.ts.map +1 -1
- package/dist/runtimes/claude/session.js +119 -87
- package/dist/runtimes/claude/session.js.map +1 -1
- package/dist/runtimes/codex/app-server-client.d.ts +38 -3
- package/dist/runtimes/codex/app-server-client.d.ts.map +1 -1
- package/dist/runtimes/codex/app-server-client.js +62 -15
- package/dist/runtimes/codex/app-server-client.js.map +1 -1
- package/dist/runtimes/codex/projection.d.ts +12 -12
- package/dist/runtimes/codex/projection.d.ts.map +1 -1
- package/dist/runtimes/codex/projection.js +101 -38
- package/dist/runtimes/codex/projection.js.map +1 -1
- package/dist/runtimes/codex/rpc-control.d.ts +31 -0
- package/dist/runtimes/codex/rpc-control.d.ts.map +1 -0
- package/dist/runtimes/codex/rpc-control.js +51 -0
- package/dist/runtimes/codex/rpc-control.js.map +1 -0
- package/dist/runtimes/codex/session.d.ts.map +1 -1
- package/dist/runtimes/codex/session.js +199 -149
- package/dist/runtimes/codex/session.js.map +1 -1
- package/dist/runtimes/grok/session.d.ts +37 -1
- package/dist/runtimes/grok/session.d.ts.map +1 -1
- package/dist/runtimes/grok/session.js +74 -0
- package/dist/runtimes/grok/session.js.map +1 -1
- package/dist/runtimes/kimi/session.d.ts.map +1 -1
- package/dist/runtimes/kimi/session.js +5 -0
- package/dist/runtimes/kimi/session.js.map +1 -1
- package/dist/runtimes/pi/auth.d.ts.map +1 -1
- package/dist/runtimes/pi/auth.js +6 -1
- package/dist/runtimes/pi/auth.js.map +1 -1
- package/dist/runtimes/pi/catalog.d.ts.map +1 -1
- package/dist/runtimes/pi/catalog.js +6 -1
- package/dist/runtimes/pi/catalog.js.map +1 -1
- package/dist/runtimes/pi/http.d.ts +34 -0
- package/dist/runtimes/pi/http.d.ts.map +1 -0
- package/dist/runtimes/pi/http.js +95 -0
- package/dist/runtimes/pi/http.js.map +1 -0
- package/dist/runtimes/pi/list-models.d.ts.map +1 -1
- package/dist/runtimes/pi/list-models.js +10 -3
- package/dist/runtimes/pi/list-models.js.map +1 -1
- package/dist/runtimes/pi/open.d.ts +32 -0
- package/dist/runtimes/pi/open.d.ts.map +1 -0
- package/dist/runtimes/pi/open.js +106 -0
- package/dist/runtimes/pi/open.js.map +1 -0
- package/dist/runtimes/pi/projection.d.ts +27 -25
- package/dist/runtimes/pi/projection.d.ts.map +1 -1
- package/dist/runtimes/pi/projection.js +85 -50
- package/dist/runtimes/pi/projection.js.map +1 -1
- package/dist/runtimes/pi/session.d.ts +1 -22
- package/dist/runtimes/pi/session.d.ts.map +1 -1
- package/dist/runtimes/pi/session.js +178 -184
- package/dist/runtimes/pi/session.js.map +1 -1
- package/dist/shared/acp/client-app.d.ts +23 -0
- package/dist/shared/acp/client-app.d.ts.map +1 -0
- package/dist/shared/acp/client-app.js +55 -0
- package/dist/shared/acp/client-app.js.map +1 -0
- package/dist/shared/acp/model.d.ts +3 -17
- package/dist/shared/acp/model.d.ts.map +1 -1
- package/dist/shared/acp/model.js +3 -14
- package/dist/shared/acp/model.js.map +1 -1
- package/dist/shared/acp/profile.d.ts +32 -7
- package/dist/shared/acp/profile.d.ts.map +1 -1
- package/dist/shared/acp/profile.js +17 -8
- package/dist/shared/acp/profile.js.map +1 -1
- package/dist/shared/acp/projection.d.ts +16 -8
- package/dist/shared/acp/projection.d.ts.map +1 -1
- package/dist/shared/acp/projection.js +51 -32
- package/dist/shared/acp/projection.js.map +1 -1
- package/dist/shared/acp/records.d.ts +46 -0
- package/dist/shared/acp/records.d.ts.map +1 -0
- package/dist/shared/acp/records.js +125 -0
- package/dist/shared/acp/records.js.map +1 -0
- package/dist/shared/acp/session.d.ts.map +1 -1
- package/dist/shared/acp/session.js +98 -224
- package/dist/shared/acp/session.js.map +1 -1
- package/dist/shared/acp/terminal.d.ts +1 -3
- package/dist/shared/acp/terminal.d.ts.map +1 -1
- package/dist/shared/acp/terminal.js +1 -21
- package/dist/shared/acp/terminal.js.map +1 -1
- package/dist/shared/acp/turns.d.ts +45 -0
- package/dist/shared/acp/turns.d.ts.map +1 -0
- package/dist/shared/acp/turns.js +160 -0
- package/dist/shared/acp/turns.js.map +1 -0
- package/dist/shared/acp/usage-wait.d.ts +6 -6
- package/dist/shared/acp/usage-wait.d.ts.map +1 -1
- package/dist/shared/acp/usage-wait.js +2 -2
- package/dist/shared/acp/usage-wait.js.map +1 -1
- package/dist/shared/failure-class.d.ts +1 -1
- package/dist/shared/failure-class.js +2 -2
- package/dist/shared/failure-class.js.map +1 -1
- package/dist/shared/seal-session.d.ts +5 -3
- package/dist/shared/seal-session.d.ts.map +1 -1
- package/dist/shared/seal-session.js +24 -16
- package/dist/shared/seal-session.js.map +1 -1
- package/dist/shared/session-kernel.d.ts +68 -18
- package/dist/shared/session-kernel.d.ts.map +1 -1
- package/dist/shared/session-kernel.js +82 -42
- package/dist/shared/session-kernel.js.map +1 -1
- package/dist/voyage.d.ts +4 -7
- package/dist/voyage.d.ts.map +1 -1
- package/dist/voyage.js +14 -19
- package/dist/voyage.js.map +1 -1
- package/package.json +4 -3
- package/dist/runtimes/codex/context-usage.d.ts +0 -10
- package/dist/runtimes/codex/context-usage.d.ts.map +0 -1
- package/dist/runtimes/codex/context-usage.js +0 -16
- package/dist/runtimes/codex/context-usage.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { spawnLineProcess } from "../../shared/executable/index.js";
|
|
3
3
|
import { asRecord, parseJson } from "../../shared/json.js";
|
|
4
|
-
import { claudeContextUsageFromResult } from "./context-usage.js";
|
|
5
4
|
import { sealSession } from "../../shared/seal-session.js";
|
|
6
5
|
import { createSessionKernel } from "../../shared/session-kernel.js";
|
|
7
6
|
import { claudeAbortRequested, claudePrompted, foldClaudeStdout, initialClaudeProjection, } from "./projection.js";
|
|
@@ -10,12 +9,14 @@ import { claudeAbortRequested, claudePrompted, foldClaudeStdout, initialClaudePr
|
|
|
10
9
|
* - stdin accepts writes at every phase; a mid-turn write is delivered into
|
|
11
10
|
* the ACTIVE turn at the next model-step boundary (steer), or becomes the
|
|
12
11
|
* next turn when no step remains. Landing shows up in the event stream.
|
|
13
|
-
* - each turn is framed by its own system/init … result pair
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* - each turn is framed by its own system/init … result pair; the `result`
|
|
13
|
+
* frame is claude's own turn end and becomes the turn_ended view.
|
|
14
|
+
* - `control_request {subtype:"interrupt"}` is acked with control_response
|
|
15
|
+
* (the abort request's response record) and claude settles the turn with
|
|
16
|
+
* an error-subtype result.
|
|
17
|
+
* - steer/prompt `accepted` here means: the user message was written to
|
|
18
|
+
* stdin. Landing (same turn vs auto-queued next turn) is claude's timing and
|
|
19
|
+
* shows up only in the stream. Live probe: claude-session-adapter.ts.
|
|
19
20
|
*/
|
|
20
21
|
function userMessage(text) {
|
|
21
22
|
return `${JSON.stringify({
|
|
@@ -37,7 +38,7 @@ export const claudeSession = async (installation, options) => {
|
|
|
37
38
|
"--output-format", "stream-json",
|
|
38
39
|
"--verbose",
|
|
39
40
|
// YOLO by default (repo policy, 2026-08-24): in embedded/SDK use there is
|
|
40
|
-
// no human at an approval prompt
|
|
41
|
+
// no human at an approval prompt: a permission gate is a hang, not
|
|
41
42
|
// safety. Isolation is the sandbox's job, not the approval flow's.
|
|
42
43
|
"--dangerously-skip-permissions",
|
|
43
44
|
...(options.resume === undefined ? ["--session-id", sessionId] : ["--resume", sessionId]),
|
|
@@ -50,124 +51,155 @@ export const claudeSession = async (installation, options) => {
|
|
|
50
51
|
});
|
|
51
52
|
await child.spawned;
|
|
52
53
|
const kernel = createSessionKernel(sessionId);
|
|
53
|
-
const state = {
|
|
54
|
-
|
|
54
|
+
const state = {
|
|
55
|
+
child,
|
|
56
|
+
active: null,
|
|
57
|
+
spontaneous: false,
|
|
58
|
+
projection: initialClaudeProjection,
|
|
59
|
+
disposed: false,
|
|
60
|
+
};
|
|
55
61
|
// claude cannot hold input for a LATER turn natively (an active-turn write
|
|
56
62
|
// steers), so queueing is adapter-held: drained one message per turn end.
|
|
57
63
|
const heldQueue = [];
|
|
58
|
-
|
|
59
|
-
let
|
|
60
|
-
// Model claude reports as in effect: the `model` field of each turn's
|
|
61
|
-
// system/init frame (claude 2.1.261 print.ts writes `model: P.model` there;
|
|
62
|
-
// `resolvedModel` exists only in list_models rows). Nothing says it before
|
|
63
|
-
// the first turn, so this stays null until then.
|
|
64
|
-
let latestModel = null;
|
|
64
|
+
const busy = () => state.active !== null || state.spontaneous;
|
|
65
|
+
let disposeRequest = null;
|
|
65
66
|
// Drive the pure projection fold, applying its commands to the kernel. The
|
|
66
|
-
// fold owns
|
|
67
|
+
// fold owns event translation and attribution; this owns only transport
|
|
68
|
+
// and the control decisions (busy, queue drain).
|
|
67
69
|
child.onLine((line) => {
|
|
68
70
|
const message = asRecord(parseJson(line));
|
|
69
71
|
if (message === null) {
|
|
70
72
|
return;
|
|
71
73
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
latestModel = message.model;
|
|
74
|
+
// A system/init while nothing is active is claude starting a turn on its
|
|
75
|
+
// own (a queued or late-steered message): a spontaneous turn.
|
|
76
|
+
if (message.type === "system" && message.subtype === "init" && !busy()) {
|
|
77
|
+
state.spontaneous = true;
|
|
77
78
|
}
|
|
78
79
|
const { state: nextProjection, commands } = foldClaudeStdout(state.projection, message);
|
|
79
80
|
state.projection = nextProjection;
|
|
80
|
-
let
|
|
81
|
+
let ended = false;
|
|
81
82
|
for (const command of commands) {
|
|
82
83
|
switch (command.kind) {
|
|
83
|
-
case "
|
|
84
|
-
|
|
84
|
+
case "event": {
|
|
85
|
+
const record = kernel.event(command.body, { agentPath: command.agentPath });
|
|
86
|
+
if (record.agentPath.length === 0 && command.body.views.some((view) => view.kind === "turn_ended")) {
|
|
87
|
+
ended = true;
|
|
88
|
+
}
|
|
85
89
|
break;
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
}
|
|
91
|
+
case "respond":
|
|
92
|
+
kernel.respond(command.requestId, command.body);
|
|
88
93
|
break;
|
|
89
|
-
case "
|
|
90
|
-
|
|
91
|
-
state.turn = null;
|
|
92
|
-
settled = true;
|
|
94
|
+
case "toApp":
|
|
95
|
+
kernel.request("toApp", { kind: "native", type: command.type, native: command.native }, { id: command.id });
|
|
93
96
|
break;
|
|
94
97
|
default:
|
|
95
98
|
break;
|
|
96
99
|
}
|
|
97
100
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
if (ended) {
|
|
102
|
+
state.active = null;
|
|
103
|
+
state.spontaneous = false;
|
|
104
|
+
if (!state.disposed) {
|
|
105
|
+
const next = heldQueue.shift();
|
|
106
|
+
if (next !== undefined) {
|
|
107
|
+
child.write(userMessage(next));
|
|
108
|
+
}
|
|
102
109
|
}
|
|
103
110
|
}
|
|
104
111
|
});
|
|
105
|
-
child.onExit(() => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
child.onExit((code) => {
|
|
113
|
+
// The exit is an outcome only oar observes: it answers our dispose when
|
|
114
|
+
// we caused it, and stands alone when claude died on its own.
|
|
115
|
+
kernel.respond(disposeRequest?.id ?? "", { kind: "exited", code });
|
|
116
|
+
state.active = null;
|
|
117
|
+
state.spontaneous = false;
|
|
110
118
|
});
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
let interruptCounter = 0;
|
|
120
|
+
const session = sealSession({
|
|
121
|
+
id: kernel.sessionId,
|
|
122
|
+
capabilities: { steer: true, queue: { durable: false }, attribution: "attributed" },
|
|
123
|
+
prompt: async (input) => {
|
|
124
|
+
const result = await kernel.control({ kind: "prompt", input }, (request) => {
|
|
125
|
+
if (busy()) {
|
|
126
|
+
return { kind: "rejected", reason: "busy" };
|
|
127
|
+
}
|
|
128
|
+
state.active = request;
|
|
129
|
+
state.projection = claudePrompted(state.projection);
|
|
130
|
+
child.write(userMessage(input));
|
|
131
|
+
return { kind: "accepted" };
|
|
132
|
+
});
|
|
133
|
+
return result;
|
|
134
|
+
},
|
|
135
|
+
steer: async (input) => {
|
|
136
|
+
const result = await kernel.control({ kind: "steer", input }, () => {
|
|
137
|
+
if (!busy()) {
|
|
138
|
+
return { kind: "rejected", reason: "not_steerable: no active turn" };
|
|
139
|
+
}
|
|
140
|
+
child.write(userMessage(input));
|
|
141
|
+
return { kind: "accepted" };
|
|
142
|
+
});
|
|
143
|
+
return result;
|
|
144
|
+
},
|
|
145
|
+
queue: async (input) => {
|
|
146
|
+
const result = await kernel.control({ kind: "queue", input }, () => {
|
|
147
|
+
if (busy()) {
|
|
148
|
+
heldQueue.push(input);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
child.write(userMessage(input));
|
|
152
|
+
}
|
|
153
|
+
return { kind: "accepted" };
|
|
154
|
+
});
|
|
155
|
+
return result;
|
|
156
|
+
},
|
|
114
157
|
abort: async () => {
|
|
115
|
-
|
|
116
|
-
|
|
158
|
+
// The interrupt's outcome is claude's control_response, which the fold
|
|
159
|
+
// routes to THIS request id; the turn's end is claude's result frame.
|
|
160
|
+
interruptCounter += 1;
|
|
161
|
+
const requestId = `interrupt-${interruptCounter}`;
|
|
162
|
+
// Recorded by hand (not kernel.control) because claude's control_response
|
|
163
|
+
// is the answer, routed to this id by the fold, so the reachability gate
|
|
164
|
+
// is applied here explicitly.
|
|
165
|
+
const blocked = kernel.unreachable();
|
|
166
|
+
const request = kernel.request("toRuntime", { kind: "abort" }, { id: requestId });
|
|
167
|
+
if (blocked !== null || !busy()) {
|
|
168
|
+
return { request, response: kernel.respond(request.id, blocked ?? { kind: "rejected", reason: "no active turn" }) };
|
|
117
169
|
}
|
|
118
170
|
state.projection = claudeAbortRequested(state.projection);
|
|
119
|
-
|
|
171
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
172
|
+
const unsubscribe = kernel.subscribe((record) => {
|
|
173
|
+
if (record.kind === "response" && record.requestId === requestId) {
|
|
174
|
+
resolve({ request, response: record });
|
|
175
|
+
}
|
|
176
|
+
});
|
|
120
177
|
child.write(`${JSON.stringify({
|
|
121
178
|
type: "control_request",
|
|
122
|
-
request_id:
|
|
179
|
+
request_id: requestId,
|
|
123
180
|
request: { subtype: "interrupt" },
|
|
124
181
|
})}\n`);
|
|
125
|
-
await
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
await Promise.resolve();
|
|
129
|
-
if (turn.settled()) {
|
|
130
|
-
return { kind: "not_steerable", reason: "turn already ended" };
|
|
131
|
-
}
|
|
132
|
-
child.write(userMessage(input));
|
|
133
|
-
return { kind: "accepted" };
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
const session = sealSession({
|
|
137
|
-
id: kernel.sessionId,
|
|
138
|
-
prompt(input) {
|
|
139
|
-
const turn = kernel.begin();
|
|
140
|
-
if (turn === null) {
|
|
141
|
-
return { kind: "busy" };
|
|
142
|
-
}
|
|
143
|
-
state.turn = turn;
|
|
144
|
-
state.projection = claudePrompted();
|
|
145
|
-
child.write(userMessage(input));
|
|
146
|
-
return { kind: "turn", turn: makeTurn(turn) };
|
|
147
|
-
},
|
|
148
|
-
subscribe: (observer) => kernel.subscribe(observer),
|
|
149
|
-
model: () => latestModel,
|
|
150
|
-
contextUsage: () => latestContextUsage,
|
|
151
|
-
queue: {
|
|
152
|
-
durable: false,
|
|
153
|
-
add: async (input) => {
|
|
154
|
-
await Promise.resolve();
|
|
155
|
-
if (kernel.active() === null) {
|
|
156
|
-
child.write(userMessage(input));
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
heldQueue.push(input);
|
|
160
|
-
}
|
|
161
|
-
},
|
|
182
|
+
const result = await promise;
|
|
183
|
+
unsubscribe();
|
|
184
|
+
return result;
|
|
162
185
|
},
|
|
186
|
+
subscribe: (observer, cursor) => kernel.subscribe(observer, cursor),
|
|
187
|
+
records: () => kernel.records(),
|
|
188
|
+
graph: () => kernel.graph(),
|
|
163
189
|
dispose: async () => {
|
|
164
190
|
if (state.disposed) {
|
|
165
191
|
return;
|
|
166
192
|
}
|
|
167
193
|
state.disposed = true;
|
|
168
|
-
kernel.
|
|
194
|
+
const gone = kernel.unreachable() !== null; // only an observed exit can say so before this dispose is recorded
|
|
195
|
+
disposeRequest = kernel.request("toRuntime", { kind: "dispose" });
|
|
196
|
+
if (gone) {
|
|
197
|
+
// The exit is already recorded; nothing is left to release.
|
|
198
|
+
kernel.respond(disposeRequest.id, { kind: "accepted" });
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
169
201
|
child.kill();
|
|
170
|
-
await child.exited; // release point for anything the process held
|
|
202
|
+
await child.exited; // release point for anything the process held; the exit response is recorded by onExit
|
|
171
203
|
},
|
|
172
204
|
});
|
|
173
205
|
return session;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/runtimes/claude/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/runtimes/claude/session.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAoB,MAAM,kCAAkC,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC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,CAAC;YACR,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;YAC7B,WAAW,EAAE,CAAC;YACd,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC;QACnE,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;QAC/B,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE;QAC3B,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACnB,OAAO;YACT,CAAC;YACD,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;YACtB,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,CAAC,mEAAmE;YAC/G,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAClE,IAAI,IAAI,EAAE,CAAC;gBACT,4DAA4D;gBAC5D,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;gBACxD,OAAO;YACT,CAAC;YACD,KAAK,CAAC,IAAI,EAAE,CAAC;YACb,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,uFAAuF;QAC7G,CAAC;KACF,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
|
@@ -4,13 +4,48 @@ import { type JsonRecord } from "../../shared/json.js";
|
|
|
4
4
|
* transport. Local to the codex runtime until a second consumer earns a
|
|
5
5
|
* shared promotion; process mechanics live in shared/executable.
|
|
6
6
|
*/
|
|
7
|
+
/** How a request settled, delivered synchronously as the reply line is read. */
|
|
8
|
+
export type RpcOutcome = {
|
|
9
|
+
readonly kind: "result";
|
|
10
|
+
readonly result: JsonRecord;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: "error";
|
|
13
|
+
readonly error: Error;
|
|
14
|
+
};
|
|
15
|
+
export interface AppServerHandlers {
|
|
16
|
+
readonly onNotification: (method: string, params: JsonRecord) => void;
|
|
17
|
+
readonly onServerRequest: (id: string, method: string, params: JsonRecord) => void;
|
|
18
|
+
}
|
|
7
19
|
export interface AppServerClient {
|
|
8
20
|
readonly spawned: Promise<void>;
|
|
9
21
|
readonly exited: Promise<number | null>;
|
|
10
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Send a request. `onSettled`, when given, runs SYNCHRONOUSLY at the moment
|
|
24
|
+
* the reply line (or the exit) is processed, before any later line in the
|
|
25
|
+
* same chunk, so a caller can record the reply in stream order; the
|
|
26
|
+
* returned promise settles afterwards, on the microtask queue.
|
|
27
|
+
*/
|
|
28
|
+
request(method: string, params: JsonRecord, onSettled?: (outcome: RpcOutcome) => void): Promise<JsonRecord>;
|
|
11
29
|
notify(method: string, params: JsonRecord): void;
|
|
12
|
-
|
|
13
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Register the inbound handlers, once. Notifications and server-initiated
|
|
32
|
+
* requests (frames with both `id` and `method`: approvals, user input,
|
|
33
|
+
* dynamic tools; the client does not answer them) that arrive before this
|
|
34
|
+
* call (the app-server talks right after `initialize`, before the thread
|
|
35
|
+
* exists) are held in ONE queue and delivered here synchronously, in wire
|
|
36
|
+
* order across both kinds: nothing the server said is lost or reordered
|
|
37
|
+
* by registration timing.
|
|
38
|
+
*/
|
|
39
|
+
handle(handlers: AppServerHandlers): void;
|
|
40
|
+
/**
|
|
41
|
+
* Place a callback in wire order: while frames are still being held (before
|
|
42
|
+
* `handle`) it joins the held queue and runs at flush, after every frame
|
|
43
|
+
* read before it and before every frame read after; once released it runs
|
|
44
|
+
* immediately. Called from a request's synchronous `onSettled`, it pins a
|
|
45
|
+
* record exactly where the reply sat on the wire.
|
|
46
|
+
*/
|
|
47
|
+
mark(callback: () => void): void;
|
|
48
|
+
onExit(handler: (code: number | null) => void): void;
|
|
14
49
|
kill(): void;
|
|
15
50
|
}
|
|
16
51
|
export declare function startAppServerClient(command: string, env?: Readonly<Record<string, string>>, configOverrides?: Readonly<Record<string, string>>): AppServerClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-server-client.d.ts","sourceRoot":"","sources":["../../../src/runtimes/codex/app-server-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"app-server-client.d.ts","sourceRoot":"","sources":["../../../src/runtimes/codex/app-server-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;;;GAIG;AACH,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;CAAE,GACxD;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACtE,QAAQ,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACpF;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5G,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACjD;;;;;;;;OAQG;IACH,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAC1C;;;;;;OAMG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;IACjC,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,CAAC;IACrD,IAAI,IAAI,IAAI,CAAC;CACd;AAQD,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,eAAe,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GACrD,eAAe,CAkHjB"}
|
|
@@ -3,50 +3,86 @@ import { asRecord, parseJson } from "../../shared/json.js";
|
|
|
3
3
|
export function startAppServerClient(command, env, configOverrides = {}) {
|
|
4
4
|
// -c KEY=VALUE injects config at launch. This is the ONLY seam that reaches
|
|
5
5
|
// codex's exec tool: thread/start.sandboxMode does not (pinned on a real
|
|
6
|
-
// login
|
|
6
|
+
// login: thread param honored for its own turns but exec follows config).
|
|
7
7
|
const overrideArgs = Object.entries(configOverrides).flatMap(([key, value]) => ["-c", `${key}=${value}`]);
|
|
8
8
|
const child = spawnLineProcess(command, ["app-server", ...overrideArgs, "--listen", "stdio://"], env === undefined ? {} : { env: { ...process.env, ...env } });
|
|
9
9
|
const pending = new Map();
|
|
10
|
-
|
|
10
|
+
// Inbound frames and marks share one queue until `handle` registers the
|
|
11
|
+
// handlers, so their relative order is the wire's whatever kind they are.
|
|
12
|
+
const held = [];
|
|
13
|
+
let handlers = null;
|
|
14
|
+
const deliver = (delivery) => {
|
|
15
|
+
if (handlers === null) {
|
|
16
|
+
held.push(delivery);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
delivery(handlers);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
11
22
|
let nextId = 1;
|
|
23
|
+
let exited = false;
|
|
12
24
|
child.onLine((line) => {
|
|
13
25
|
const message = asRecord(parseJson(line));
|
|
14
26
|
if (message === null) {
|
|
15
27
|
return;
|
|
16
28
|
}
|
|
29
|
+
const hasId = typeof message.id === "number" || typeof message.id === "string";
|
|
30
|
+
if (typeof message.method === "string") {
|
|
31
|
+
const params = asRecord(message.params) ?? {};
|
|
32
|
+
const { method } = message;
|
|
33
|
+
if (hasId) {
|
|
34
|
+
const id = String(message.id);
|
|
35
|
+
deliver((target) => {
|
|
36
|
+
target.onServerRequest(id, method, params);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
deliver((target) => {
|
|
41
|
+
target.onNotification(method, params);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
17
46
|
if (typeof message.id === "number" && pending.has(message.id)) {
|
|
18
47
|
const waiter = pending.get(message.id);
|
|
19
48
|
pending.delete(message.id);
|
|
20
49
|
const error = asRecord(message.error);
|
|
21
50
|
if (error !== null) {
|
|
22
|
-
|
|
51
|
+
const failure = new Error(typeof error.message === "string" ? error.message : "app-server error");
|
|
52
|
+
waiter?.settled({ kind: "error", error: failure });
|
|
53
|
+
waiter?.reject(failure);
|
|
23
54
|
}
|
|
24
55
|
else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else if (typeof message.method === "string") {
|
|
29
|
-
const params = asRecord(message.params) ?? {};
|
|
30
|
-
for (const handler of notificationHandlers) {
|
|
31
|
-
handler(message.method, params);
|
|
56
|
+
const result = asRecord(message.result) ?? {};
|
|
57
|
+
waiter?.settled({ kind: "result", result });
|
|
58
|
+
waiter?.resolve(result);
|
|
32
59
|
}
|
|
33
60
|
}
|
|
34
61
|
});
|
|
35
62
|
child.onExit(() => {
|
|
63
|
+
exited = true;
|
|
36
64
|
for (const waiter of pending.values()) {
|
|
37
|
-
|
|
65
|
+
const error = new Error("app-server exited");
|
|
66
|
+
waiter.settled({ kind: "error", error });
|
|
67
|
+
waiter.reject(error);
|
|
38
68
|
}
|
|
39
69
|
pending.clear();
|
|
40
70
|
});
|
|
41
71
|
return {
|
|
42
72
|
spawned: child.spawned,
|
|
43
73
|
exited: child.exited,
|
|
44
|
-
async request(method, params) {
|
|
74
|
+
async request(method, params, onSettled) {
|
|
75
|
+
const settled = onSettled ?? (() => { });
|
|
76
|
+
if (exited) {
|
|
77
|
+
const error = new Error("app-server exited");
|
|
78
|
+
settled({ kind: "error", error });
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
45
81
|
const id = nextId;
|
|
46
82
|
nextId += 1;
|
|
47
83
|
// oxlint-disable-next-line promise/avoid-new -- settlement is driven by the response pump
|
|
48
84
|
const result = await new Promise((resolve, reject) => {
|
|
49
|
-
pending.set(id, { resolve, reject });
|
|
85
|
+
pending.set(id, { resolve, reject, settled });
|
|
50
86
|
child.write(`${JSON.stringify({ id, method, params })}\n`);
|
|
51
87
|
});
|
|
52
88
|
return result;
|
|
@@ -54,8 +90,19 @@ export function startAppServerClient(command, env, configOverrides = {}) {
|
|
|
54
90
|
notify(method, params) {
|
|
55
91
|
child.write(`${JSON.stringify({ method, params })}\n`);
|
|
56
92
|
},
|
|
57
|
-
|
|
58
|
-
|
|
93
|
+
handle(registered) {
|
|
94
|
+
if (handlers !== null) {
|
|
95
|
+
throw new Error("app-server handlers are already registered");
|
|
96
|
+
}
|
|
97
|
+
handlers = registered;
|
|
98
|
+
for (const delivery of held.splice(0)) {
|
|
99
|
+
delivery(registered);
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
mark(callback) {
|
|
103
|
+
deliver(() => {
|
|
104
|
+
callback();
|
|
105
|
+
});
|
|
59
106
|
},
|
|
60
107
|
onExit(handler) {
|
|
61
108
|
child.onExit(handler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-server-client.js","sourceRoot":"","sources":["../../../src/runtimes/codex/app-server-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAmB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"app-server-client.js","sourceRoot":"","sources":["../../../src/runtimes/codex/app-server-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAmB,MAAM,sBAAsB,CAAC;AAwD5E,MAAM,UAAU,oBAAoB,CAClC,OAAe,EACf,GAAsC,EACtC,kBAAoD,EAAE;IAEtD,4EAA4E;IAC5E,yEAAyE;IACzE,0EAA0E;IAC1E,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC;IAC1G,MAAM,KAAK,GAAG,gBAAgB,CAC5B,OAAO,EACP,CAAC,YAAY,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,UAAU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,EAAE,CAAC,IAAI,CAAC,CAAC;YAC7D,CAAC,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,CAAC,MAAM,EAAE,MAAM;YACnB,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,CAAC,UAAU;YACf,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,CAAC;YACD,QAAQ,GAAG,UAAU,CAAC;YACtB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ;YACX,OAAO,CAAC,GAAG,EAAE;gBACX,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,OAAO;YACZ,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,IAAI;YACF,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EventBody, SessionEdge } from "../../contracts/session.js";
|
|
2
2
|
import { type JsonRecord } from "../../shared/json.js";
|
|
3
3
|
export type ProjectionCommand = {
|
|
4
|
-
readonly kind: "
|
|
4
|
+
readonly kind: "event";
|
|
5
|
+
readonly body: EventBody;
|
|
6
|
+
/** Runtime-native turn id when the notification carries one. */
|
|
7
|
+
readonly spanId?: string;
|
|
8
|
+
/** Set when the notification belongs to another thread: a derived child session. */
|
|
9
|
+
readonly sessionId?: string;
|
|
5
10
|
} | {
|
|
6
|
-
readonly kind: "
|
|
7
|
-
readonly
|
|
8
|
-
} | {
|
|
9
|
-
readonly kind: "settle";
|
|
10
|
-
readonly outcome: TurnOutcome;
|
|
11
|
+
readonly kind: "link";
|
|
12
|
+
readonly edge: SessionEdge;
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* `lastErrorDetail` carries codex's structured `error` notification (which its
|
|
14
|
-
* terminal turn status does NOT include) into the failed
|
|
16
|
+
* terminal turn status does NOT include) into the failed turn_ended reason.
|
|
15
17
|
*/
|
|
16
18
|
export interface CodexProjectionState {
|
|
17
|
-
readonly
|
|
19
|
+
readonly rootThreadId: string;
|
|
18
20
|
readonly lastErrorDetail: string | null;
|
|
19
21
|
}
|
|
20
|
-
export declare
|
|
21
|
-
/** Control plane → state: a prompt (or resume) opens a turn. */
|
|
22
|
-
export declare function codexPrompted(state: CodexProjectionState): CodexProjectionState;
|
|
22
|
+
export declare function initialCodexProjection(rootThreadId: string): CodexProjectionState;
|
|
23
23
|
/** Fold one codex notification into the next state plus commands. */
|
|
24
24
|
export declare function foldCodexNotification(state: CodexProjectionState, method: string, params: JsonRecord): {
|
|
25
25
|
readonly state: CodexProjectionState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/runtimes/codex/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"projection.d.ts","sourceRoot":"","sources":["../../../src/runtimes/codex/projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EAET,WAAW,EAEZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAmB3E,MAAM,MAAM,iBAAiB,GACzB;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,gEAAgE;IAChE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,oFAAoF;IACpF,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CACzC;AAED,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,oBAAoB,CAEjF;AAyHD,qEAAqE;AACrE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,oBAAoB,EAC3B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,GACjB;IAAE,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;CAAE,CA0B3F"}
|