@chances-ai/wire 24.0.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/dist/rpc/acp/adapter.d.ts +32 -0
- package/dist/rpc/acp/adapter.d.ts.map +1 -0
- package/dist/rpc/acp/adapter.js +185 -0
- package/dist/rpc/acp/adapter.js.map +1 -0
- package/dist/rpc/acp/engine-driver.d.ts +128 -0
- package/dist/rpc/acp/engine-driver.d.ts.map +1 -0
- package/dist/rpc/acp/engine-driver.js +550 -0
- package/dist/rpc/acp/engine-driver.js.map +1 -0
- package/dist/rpc/acp/event-map.d.ts +22 -0
- package/dist/rpc/acp/event-map.d.ts.map +1 -0
- package/dist/rpc/acp/event-map.js +205 -0
- package/dist/rpc/acp/event-map.js.map +1 -0
- package/dist/rpc/acp/load-sdk.d.ts +3 -0
- package/dist/rpc/acp/load-sdk.d.ts.map +1 -0
- package/dist/rpc/acp/load-sdk.js +24 -0
- package/dist/rpc/acp/load-sdk.js.map +1 -0
- package/dist/rpc/acp/workspace-query.d.ts +41 -0
- package/dist/rpc/acp/workspace-query.d.ts.map +1 -0
- package/dist/rpc/acp/workspace-query.js +89 -0
- package/dist/rpc/acp/workspace-query.js.map +1 -0
- package/dist/rpc/driver.d.ts +42 -0
- package/dist/rpc/driver.d.ts.map +1 -0
- package/dist/rpc/driver.js +7 -0
- package/dist/rpc/driver.js.map +1 -0
- package/dist/rpc/event-map.d.ts +8 -0
- package/dist/rpc/event-map.d.ts.map +1 -0
- package/dist/rpc/event-map.js +91 -0
- package/dist/rpc/event-map.js.map +1 -0
- package/dist/rpc/index.d.ts +13 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +18 -0
- package/dist/rpc/index.js.map +1 -0
- package/dist/rpc/lines.d.ts +2 -0
- package/dist/rpc/lines.d.ts.map +1 -0
- package/dist/rpc/lines.js +24 -0
- package/dist/rpc/lines.js.map +1 -0
- package/dist/rpc/protocol.d.ts +315 -0
- package/dist/rpc/protocol.d.ts.map +1 -0
- package/dist/rpc/protocol.js +70 -0
- package/dist/rpc/protocol.js.map +1 -0
- package/dist/rpc/rpc-server.d.ts +56 -0
- package/dist/rpc/rpc-server.d.ts.map +1 -0
- package/dist/rpc/rpc-server.js +305 -0
- package/dist/rpc/rpc-server.js.map +1 -0
- package/dist/rpc/stdout-guard.d.ts +5 -0
- package/dist/rpc/stdout-guard.d.ts.map +1 -0
- package/dist/rpc/stdout-guard.js +31 -0
- package/dist/rpc/stdout-guard.js.map +1 -0
- package/dist/rpc/writer.d.ts +34 -0
- package/dist/rpc/writer.d.ts.map +1 -0
- package/dist/rpc/writer.js +85 -0
- package/dist/rpc/writer.js.map +1 -0
- package/dist/serve/acp-session-host.d.ts +120 -0
- package/dist/serve/acp-session-host.d.ts.map +1 -0
- package/dist/serve/acp-session-host.js +276 -0
- package/dist/serve/acp-session-host.js.map +1 -0
- package/dist/serve/auth.d.ts +21 -0
- package/dist/serve/auth.d.ts.map +1 -0
- package/dist/serve/auth.js +58 -0
- package/dist/serve/auth.js.map +1 -0
- package/dist/serve/highlight.d.ts +25 -0
- package/dist/serve/highlight.d.ts.map +1 -0
- package/dist/serve/highlight.js +28 -0
- package/dist/serve/highlight.js.map +1 -0
- package/dist/serve/index.d.ts +14 -0
- package/dist/serve/index.d.ts.map +1 -0
- package/dist/serve/index.js +23 -0
- package/dist/serve/index.js.map +1 -0
- package/dist/serve/pairing.d.ts +25 -0
- package/dist/serve/pairing.d.ts.map +1 -0
- package/dist/serve/pairing.js +10 -0
- package/dist/serve/pairing.js.map +1 -0
- package/dist/serve/relay-frames.d.ts +29 -0
- package/dist/serve/relay-frames.d.ts.map +1 -0
- package/dist/serve/relay-frames.js +54 -0
- package/dist/serve/relay-frames.js.map +1 -0
- package/dist/serve/relay.d.ts +146 -0
- package/dist/serve/relay.d.ts.map +1 -0
- package/dist/serve/relay.js +475 -0
- package/dist/serve/relay.js.map +1 -0
- package/dist/serve/replay-hub.d.ts +102 -0
- package/dist/serve/replay-hub.d.ts.map +1 -0
- package/dist/serve/replay-hub.js +176 -0
- package/dist/serve/replay-hub.js.map +1 -0
- package/dist/serve/tls.d.ts +20 -0
- package/dist/serve/tls.d.ts.map +1 -0
- package/dist/serve/tls.js +64 -0
- package/dist/serve/tls.js.map +1 -0
- package/dist/serve/ws-transport.d.ts +64 -0
- package/dist/serve/ws-transport.d.ts.map +1 -0
- package/dist/serve/ws-transport.js +92 -0
- package/dist/serve/ws-transport.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Split a byte/string stream into LF-delimited lines. Splits on "\n" ONLY
|
|
2
|
+
// (stripping a trailing "\r") and never on U+2028/U+2029 — those are valid
|
|
3
|
+
// inside JSON strings, and Node's `readline` would wrongly break on them (pi
|
|
4
|
+
// learned this the hard way: `modes/rpc/jsonl.ts`). `process.stdin` is an
|
|
5
|
+
// AsyncIterable<Buffer>; the bespoke RPC server consumes the yielded lines.
|
|
6
|
+
export async function* linesFromStream(stream) {
|
|
7
|
+
let buf = "";
|
|
8
|
+
for await (const chunk of stream) {
|
|
9
|
+
buf += typeof chunk === "string" ? chunk : Buffer.from(chunk).toString("utf8");
|
|
10
|
+
let nl = buf.indexOf("\n");
|
|
11
|
+
while (nl !== -1) {
|
|
12
|
+
let line = buf.slice(0, nl);
|
|
13
|
+
if (line.endsWith("\r"))
|
|
14
|
+
line = line.slice(0, -1);
|
|
15
|
+
yield line;
|
|
16
|
+
buf = buf.slice(nl + 1);
|
|
17
|
+
nl = buf.indexOf("\n");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const tail = buf.endsWith("\r") ? buf.slice(0, -1) : buf;
|
|
21
|
+
if (tail.length > 0)
|
|
22
|
+
yield tail;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=lines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lines.js","sourceRoot":"","sources":["../../src/rpc/lines.ts"],"names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ai/runtime";
|
|
3
|
+
/** Bumped on any breaking wire change. Carried in the `ready` handshake.
|
|
4
|
+
* v2 (M2 / docs/6.2): additive `rseq` cursor + relay control frames. Old
|
|
5
|
+
* clients ignore the extra field + unknown frames, so v2 is wire-compatible —
|
|
6
|
+
* the bump is a capability signal, not a break. */
|
|
7
|
+
export declare const PROTOCOL_VERSION: 2;
|
|
8
|
+
export declare const PROTOCOL_NAME: "chances-rpc";
|
|
9
|
+
export declare const CommandSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"prompt">;
|
|
11
|
+
id: z.ZodOptional<z.ZodString>;
|
|
12
|
+
text: z.ZodString;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "prompt";
|
|
15
|
+
text: string;
|
|
16
|
+
id?: string | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
type: "prompt";
|
|
19
|
+
text: string;
|
|
20
|
+
id?: string | undefined;
|
|
21
|
+
}>, z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"abort">;
|
|
23
|
+
id: z.ZodOptional<z.ZodString>;
|
|
24
|
+
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
type: "abort";
|
|
26
|
+
id?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
type: "abort";
|
|
29
|
+
id?: string | undefined;
|
|
30
|
+
}>, z.ZodObject<{
|
|
31
|
+
type: z.ZodLiteral<"set_model">;
|
|
32
|
+
id: z.ZodOptional<z.ZodString>;
|
|
33
|
+
provider: z.ZodOptional<z.ZodString>;
|
|
34
|
+
model: z.ZodOptional<z.ZodString>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
type: "set_model";
|
|
37
|
+
id?: string | undefined;
|
|
38
|
+
provider?: string | undefined;
|
|
39
|
+
model?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
type: "set_model";
|
|
42
|
+
id?: string | undefined;
|
|
43
|
+
provider?: string | undefined;
|
|
44
|
+
model?: string | undefined;
|
|
45
|
+
}>, z.ZodObject<{
|
|
46
|
+
type: z.ZodLiteral<"get_state">;
|
|
47
|
+
id: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
type: "get_state";
|
|
50
|
+
id?: string | undefined;
|
|
51
|
+
}, {
|
|
52
|
+
type: "get_state";
|
|
53
|
+
id?: string | undefined;
|
|
54
|
+
}>, z.ZodObject<{
|
|
55
|
+
type: z.ZodLiteral<"get_models">;
|
|
56
|
+
id: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
type: "get_models";
|
|
59
|
+
id?: string | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
type: "get_models";
|
|
62
|
+
id?: string | undefined;
|
|
63
|
+
}>, z.ZodObject<{
|
|
64
|
+
type: z.ZodLiteral<"permission_response">;
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
allow: z.ZodBoolean;
|
|
67
|
+
remember: z.ZodOptional<z.ZodBoolean>;
|
|
68
|
+
}, "strip", z.ZodTypeAny, {
|
|
69
|
+
type: "permission_response";
|
|
70
|
+
id: string;
|
|
71
|
+
allow: boolean;
|
|
72
|
+
remember?: boolean | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
type: "permission_response";
|
|
75
|
+
id: string;
|
|
76
|
+
allow: boolean;
|
|
77
|
+
remember?: boolean | undefined;
|
|
78
|
+
}>, z.ZodObject<{
|
|
79
|
+
type: z.ZodLiteral<"set_options">;
|
|
80
|
+
id: z.ZodOptional<z.ZodString>;
|
|
81
|
+
toolChunks: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
type: "set_options";
|
|
84
|
+
id?: string | undefined;
|
|
85
|
+
toolChunks?: boolean | undefined;
|
|
86
|
+
}, {
|
|
87
|
+
type: "set_options";
|
|
88
|
+
id?: string | undefined;
|
|
89
|
+
toolChunks?: boolean | undefined;
|
|
90
|
+
}>, z.ZodObject<{
|
|
91
|
+
type: z.ZodLiteral<"ping">;
|
|
92
|
+
id: z.ZodOptional<z.ZodString>;
|
|
93
|
+
}, "strip", z.ZodTypeAny, {
|
|
94
|
+
type: "ping";
|
|
95
|
+
id?: string | undefined;
|
|
96
|
+
}, {
|
|
97
|
+
type: "ping";
|
|
98
|
+
id?: string | undefined;
|
|
99
|
+
}>]>;
|
|
100
|
+
export type Command = z.infer<typeof CommandSchema>;
|
|
101
|
+
export type CommandType = Command["type"];
|
|
102
|
+
export type PromptCommand = Extract<Command, {
|
|
103
|
+
type: "prompt";
|
|
104
|
+
}>;
|
|
105
|
+
export type RpcErrorCode = "PARSE_ERROR" | "UNKNOWN_COMMAND" | "AGENT_BUSY" | "BAD_REQUEST" | "INTERNAL";
|
|
106
|
+
export interface RpcError {
|
|
107
|
+
code: RpcErrorCode;
|
|
108
|
+
message: string;
|
|
109
|
+
}
|
|
110
|
+
export interface ModelInfo {
|
|
111
|
+
provider: string;
|
|
112
|
+
model: string;
|
|
113
|
+
}
|
|
114
|
+
export interface ReadyFrame {
|
|
115
|
+
type: "ready";
|
|
116
|
+
protocol: typeof PROTOCOL_NAME;
|
|
117
|
+
version: typeof PROTOCOL_VERSION;
|
|
118
|
+
agent: {
|
|
119
|
+
name: string;
|
|
120
|
+
version: string;
|
|
121
|
+
};
|
|
122
|
+
sessionId: string;
|
|
123
|
+
models: ModelInfo[];
|
|
124
|
+
capabilities: {
|
|
125
|
+
permissionPrompt: true;
|
|
126
|
+
toolChunks: boolean;
|
|
127
|
+
steering: false;
|
|
128
|
+
/** (M2) Relay reconnect/replay available. OPTIONAL: `RpcServer` is consumed
|
|
129
|
+
* UNCHANGED (docs/6.2 §5) and never sets it, so it is absent on the raw
|
|
130
|
+
* engine `ready`. The actual reconnect handshake is the relay's
|
|
131
|
+
* {@link RelayWelcomeFrame}; this field is reserved for a future relay that
|
|
132
|
+
* stamps it + for documentation. */
|
|
133
|
+
reconnect?: boolean;
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/** Reply to a command, correlated by the command's `id` (echoed, may be null
|
|
137
|
+
* for un-attributable transport errors — codex C9). */
|
|
138
|
+
export interface ResponseFrame {
|
|
139
|
+
type: "response";
|
|
140
|
+
id: string | null;
|
|
141
|
+
command: CommandType | "parse";
|
|
142
|
+
ok: boolean;
|
|
143
|
+
data?: JSONValue;
|
|
144
|
+
error?: RpcError;
|
|
145
|
+
}
|
|
146
|
+
export interface RequestPermissionFrame {
|
|
147
|
+
type: "request_permission";
|
|
148
|
+
/** Permission id; the client answers with `permission_response {id}`. */
|
|
149
|
+
id: string;
|
|
150
|
+
/** The originating tool call (codex Round-1 MUST-FIX #3). */
|
|
151
|
+
callId?: string;
|
|
152
|
+
tool: string;
|
|
153
|
+
category: string;
|
|
154
|
+
summary: string;
|
|
155
|
+
args: JSONValue;
|
|
156
|
+
cacheKey?: string;
|
|
157
|
+
}
|
|
158
|
+
export type StopReason = "end" | "cancelled" | "error";
|
|
159
|
+
/** Streamed agent events, mapped from the internal `AppEvent` union. */
|
|
160
|
+
export type EventFrame = {
|
|
161
|
+
type: "turn_start";
|
|
162
|
+
commandId?: string;
|
|
163
|
+
turnId: string;
|
|
164
|
+
prompt: string;
|
|
165
|
+
sessionId?: string;
|
|
166
|
+
} | {
|
|
167
|
+
type: "assistant_delta";
|
|
168
|
+
turnId: string;
|
|
169
|
+
text: string;
|
|
170
|
+
agentId?: string;
|
|
171
|
+
} | {
|
|
172
|
+
type: "tool_call";
|
|
173
|
+
callId: string;
|
|
174
|
+
name: string;
|
|
175
|
+
args: JSONValue;
|
|
176
|
+
agentId?: string;
|
|
177
|
+
} | {
|
|
178
|
+
type: "tool_result";
|
|
179
|
+
callId: string;
|
|
180
|
+
name: string;
|
|
181
|
+
ok: boolean;
|
|
182
|
+
output: string;
|
|
183
|
+
agentId?: string;
|
|
184
|
+
} | {
|
|
185
|
+
type: "tool_chunk";
|
|
186
|
+
callId: string;
|
|
187
|
+
sessionId: string;
|
|
188
|
+
seq: number;
|
|
189
|
+
text: string;
|
|
190
|
+
bytes: number;
|
|
191
|
+
dropped?: number;
|
|
192
|
+
terminal?: true;
|
|
193
|
+
state?: "running" | "exited" | "killed";
|
|
194
|
+
exitCode?: number;
|
|
195
|
+
reason?: "exit" | "signal" | "timeout" | "io-error";
|
|
196
|
+
agentId?: string;
|
|
197
|
+
} | {
|
|
198
|
+
type: "usage";
|
|
199
|
+
model: string;
|
|
200
|
+
inputTokens: number;
|
|
201
|
+
outputTokens: number;
|
|
202
|
+
costUsd: number;
|
|
203
|
+
agentId?: string;
|
|
204
|
+
} | {
|
|
205
|
+
type: "compaction_start";
|
|
206
|
+
reason: string;
|
|
207
|
+
beforeTokens: number;
|
|
208
|
+
} | {
|
|
209
|
+
type: "compaction_end";
|
|
210
|
+
reason: string;
|
|
211
|
+
ok: boolean;
|
|
212
|
+
savedTokens?: number;
|
|
213
|
+
durationMs: number;
|
|
214
|
+
} | {
|
|
215
|
+
type: "subagent_done";
|
|
216
|
+
taskId: string;
|
|
217
|
+
agentName: string;
|
|
218
|
+
status: "completed" | "failed" | "cancelled";
|
|
219
|
+
durationMs: number;
|
|
220
|
+
tokens?: {
|
|
221
|
+
input: number;
|
|
222
|
+
output: number;
|
|
223
|
+
};
|
|
224
|
+
} | {
|
|
225
|
+
type: "error";
|
|
226
|
+
code: string;
|
|
227
|
+
message: string;
|
|
228
|
+
} | {
|
|
229
|
+
type: "result";
|
|
230
|
+
commandId?: string;
|
|
231
|
+
turnId?: string;
|
|
232
|
+
text: string;
|
|
233
|
+
usage: {
|
|
234
|
+
inputTokens: number;
|
|
235
|
+
outputTokens: number;
|
|
236
|
+
costUsd: number;
|
|
237
|
+
};
|
|
238
|
+
stopReason: StopReason;
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Engine→client frames. The optional `rseq` is the **relay-assigned monotonic
|
|
242
|
+
* cursor** (M2 / docs/6.2 §3.2): the serve `ReplayHub` stamps it on every
|
|
243
|
+
* outbound frame at the write boundary; `RpcServer` never sets it (the engine
|
|
244
|
+
* is cursor-agnostic). It is named **`rseq`, not `seq`**, on purpose: the
|
|
245
|
+
* `tool_chunk` variant ALREADY carries a top-level `seq` (its own chunk-ordering
|
|
246
|
+
* counter, protocol line ~128). A relay cursor named `seq` would produce a
|
|
247
|
+
* duplicate JSON key on tool_chunk frames — `JSON.parse` keeps the LAST, so the
|
|
248
|
+
* client would read the chunk's seq as the cursor and corrupt reconnect on any
|
|
249
|
+
* streaming turn. `rseq` is collision-free across every variant. It doubles as
|
|
250
|
+
* the SSE `id:` value in the M5/M6 transports (an SSE field, not a JSON key, so
|
|
251
|
+
* the name is independent there).
|
|
252
|
+
*/
|
|
253
|
+
export type ServerFrame = (ReadyFrame | ResponseFrame | RequestPermissionFrame | EventFrame) & {
|
|
254
|
+
rseq?: number;
|
|
255
|
+
};
|
|
256
|
+
/** Sent once per attach, BEFORE any replayed/live frame. Carries the relay's
|
|
257
|
+
* reconnect snapshot so a fresh OR resuming client knows where it stands
|
|
258
|
+
* without inferring from the stream (goose/OpenHands "subscribe pushes state"). */
|
|
259
|
+
export interface RelayWelcomeFrame {
|
|
260
|
+
type: "relay_welcome";
|
|
261
|
+
/** Per-attach fencing token. Reserved for the M5 stateless POST transport
|
|
262
|
+
* (which echoes `{epoch}` since it has no socket to gate by); NOT enforced on
|
|
263
|
+
* the M2 WebSocket (fan-out has no exclusive lock to fence). */
|
|
264
|
+
epoch: number;
|
|
265
|
+
/** The highest `rseq` the relay has assigned so far (the live head). */
|
|
266
|
+
headSeq: number;
|
|
267
|
+
/** True iff the client's `Last-Event-ID` predates the ring floor — its cursor
|
|
268
|
+
* is unrecoverable, so it must discard its transcript and take the full ring
|
|
269
|
+
* replay that follows (cold reload — never a silent gap). [goose
|
|
270
|
+
* `ClientTooFarBehind`.] */
|
|
271
|
+
reset: boolean;
|
|
272
|
+
/** Whether a turn is in flight right now (snoop-derived: `turn_start` → true,
|
|
273
|
+
* `result` → false), so a reconnecting client can lock its composer. */
|
|
274
|
+
busy: boolean;
|
|
275
|
+
/** Ids of `request_permission` frames still open (unanswered) at attach time,
|
|
276
|
+
* re-sent right after the welcome so a parked turn is answerable. */
|
|
277
|
+
pendingPermissionIds: string[];
|
|
278
|
+
/** (v21 M4 / docs/6.5 §5) Controller-lease snapshot. `lease` = whether the
|
|
279
|
+
* optional single-controller lease is enabled (default false ⇒ fan-out: any
|
|
280
|
+
* paired device drives, the engine serializes turns via AGENT_BUSY). When
|
|
281
|
+
* enabled, `holder` is the clientId currently allowed to drive (null =
|
|
282
|
+
* unclaimed) and `controlEpoch` increments on each handoff. A client compares
|
|
283
|
+
* its own clientId to `holder` to know if it is the controller or a read-only
|
|
284
|
+
* viewer. */
|
|
285
|
+
lease: boolean;
|
|
286
|
+
holder: string | null;
|
|
287
|
+
controlEpoch: number;
|
|
288
|
+
}
|
|
289
|
+
/** Stand-alone cold-reload signal. M2 carries the same intent inside
|
|
290
|
+
* {@link RelayWelcomeFrame.reset}; this variant exists for forward-compat with
|
|
291
|
+
* a mid-stream reset under M3. */
|
|
292
|
+
export interface ResetFrame {
|
|
293
|
+
type: "reset";
|
|
294
|
+
}
|
|
295
|
+
export type RelayFrame = RelayWelcomeFrame | ResetFrame;
|
|
296
|
+
/** Everything a client may receive on the wire: engine frames + relay control. */
|
|
297
|
+
export type ClientInboundFrame = ServerFrame | RelayFrame;
|
|
298
|
+
/** The JSON key the relay cursor is spliced under. Centralised so the splicer,
|
|
299
|
+
* the reader, and the round-trip test agree. */
|
|
300
|
+
export declare const RSEQ_KEY: "rseq";
|
|
301
|
+
/**
|
|
302
|
+
* Splice the relay cursor onto an already-serialized frame line as the FIRST
|
|
303
|
+
* key — an O(1) string op, **payload-agnostic** (it never parses the frame, so
|
|
304
|
+
* it carries unchanged to the M3 ACP wire). Safe because every `ServerFrame`
|
|
305
|
+
* serializes to a non-empty object `{"type":...,...}` (≥1 field ⇒ the byte at
|
|
306
|
+
* index 0 is always `{` and index 1 is `"`), so splicing `"rseq":N,` after the
|
|
307
|
+
* opening brace yields valid JSON with `rseq` first. `line` may or may not end
|
|
308
|
+
* in `\n`; the splice is before the first key, so the trailing newline is
|
|
309
|
+
* untouched.
|
|
310
|
+
*/
|
|
311
|
+
export declare function stampSeq(line: string, seq: number): string;
|
|
312
|
+
/** Read the relay cursor off a parsed inbound frame (`undefined` ⇒ a control
|
|
313
|
+
* frame or a pre-M2 relay). Kept beside {@link stampSeq} so the key never drifts. */
|
|
314
|
+
export declare function readRseq(frame: ClientInboundFrame): number | undefined;
|
|
315
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/rpc/protocol.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;oDAGoD;AACpD,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAC3C,eAAO,MAAM,aAAa,EAAG,aAAsB,CAAC;AAiBpD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAqBxB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC1C,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAAC;AAKjE,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,iBAAiB,GACjB,YAAY,GACZ,aAAa,GACb,UAAU,CAAC;AAEf,MAAM,WAAW,QAAQ;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a,GAAG,sBAAsB,GAAG,UAAU,CAAC,GAAG;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAQF;;oFAEoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,eAAe,CAAC;IACtB;;qEAEiE;IACjE,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,OAAO,EAAE,MAAM,CAAC;IAChB;;;iCAG6B;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf;6EACyE;IACzE,IAAI,EAAE,OAAO,CAAC;IACd;0EACsE;IACtE,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B;;;;;;kBAMc;IACd,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;mCAEmC;AACnC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,MAAM,UAAU,GAAG,iBAAiB,GAAG,UAAU,CAAC;AAExD,kFAAkF;AAClF,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC;AAE1D;iDACiD;AACjD,eAAO,MAAM,QAAQ,EAAG,MAAe,CAAC;AAExC;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED;sFACsF;AACtF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAGtE"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Wire protocol for the bespoke Stable RPC transport (5.2).
|
|
2
|
+
//
|
|
3
|
+
// Schema-first (codex C2): inbound frames — untrusted client input — are
|
|
4
|
+
// validated by zod; outbound frames are typed structurally (the server
|
|
5
|
+
// constructs them, so a schema would only re-state the type). One LF-NDJSON
|
|
6
|
+
// object per line; see docs/5.2-design.md § D3.
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
/** Bumped on any breaking wire change. Carried in the `ready` handshake.
|
|
9
|
+
* v2 (M2 / docs/6.2): additive `rseq` cursor + relay control frames. Old
|
|
10
|
+
* clients ignore the extra field + unknown frames, so v2 is wire-compatible —
|
|
11
|
+
* the bump is a capability signal, not a break. */
|
|
12
|
+
export const PROTOCOL_VERSION = 2;
|
|
13
|
+
export const PROTOCOL_NAME = "chances-rpc";
|
|
14
|
+
// `z.json()`-equivalent for `args` payloads (zod 3 has no built-in json).
|
|
15
|
+
const jsonValue = z.lazy(() => z.union([
|
|
16
|
+
z.string(),
|
|
17
|
+
z.number(),
|
|
18
|
+
z.boolean(),
|
|
19
|
+
z.null(),
|
|
20
|
+
z.array(jsonValue),
|
|
21
|
+
z.record(jsonValue),
|
|
22
|
+
]));
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Inbound commands (stdin → server). Validated.
|
|
25
|
+
export const CommandSchema = z.discriminatedUnion("type", [
|
|
26
|
+
z.object({ type: z.literal("prompt"), id: z.string().optional(), text: z.string() }),
|
|
27
|
+
z.object({ type: z.literal("abort"), id: z.string().optional() }),
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.literal("set_model"),
|
|
30
|
+
id: z.string().optional(),
|
|
31
|
+
provider: z.string().optional(),
|
|
32
|
+
model: z.string().optional(),
|
|
33
|
+
}),
|
|
34
|
+
z.object({ type: z.literal("get_state"), id: z.string().optional() }),
|
|
35
|
+
z.object({ type: z.literal("get_models"), id: z.string().optional() }),
|
|
36
|
+
// `id` here is the permission-request id being answered (NOT a command
|
|
37
|
+
// correlation id — permission_response gets no response of its own).
|
|
38
|
+
z.object({
|
|
39
|
+
type: z.literal("permission_response"),
|
|
40
|
+
id: z.string(),
|
|
41
|
+
allow: z.boolean(),
|
|
42
|
+
remember: z.boolean().optional(),
|
|
43
|
+
}),
|
|
44
|
+
z.object({ type: z.literal("set_options"), id: z.string().optional(), toolChunks: z.boolean().optional() }),
|
|
45
|
+
z.object({ type: z.literal("ping"), id: z.string().optional() }),
|
|
46
|
+
]);
|
|
47
|
+
/** The JSON key the relay cursor is spliced under. Centralised so the splicer,
|
|
48
|
+
* the reader, and the round-trip test agree. */
|
|
49
|
+
export const RSEQ_KEY = "rseq";
|
|
50
|
+
/**
|
|
51
|
+
* Splice the relay cursor onto an already-serialized frame line as the FIRST
|
|
52
|
+
* key — an O(1) string op, **payload-agnostic** (it never parses the frame, so
|
|
53
|
+
* it carries unchanged to the M3 ACP wire). Safe because every `ServerFrame`
|
|
54
|
+
* serializes to a non-empty object `{"type":...,...}` (≥1 field ⇒ the byte at
|
|
55
|
+
* index 0 is always `{` and index 1 is `"`), so splicing `"rseq":N,` after the
|
|
56
|
+
* opening brace yields valid JSON with `rseq` first. `line` may or may not end
|
|
57
|
+
* in `\n`; the splice is before the first key, so the trailing newline is
|
|
58
|
+
* untouched.
|
|
59
|
+
*/
|
|
60
|
+
export function stampSeq(line, seq) {
|
|
61
|
+
// `{"type":...}` → `{"rseq":<seq>,"type":...}`. Slice(1) drops the leading `{`.
|
|
62
|
+
return `{"${RSEQ_KEY}":${seq},${line.slice(1)}`;
|
|
63
|
+
}
|
|
64
|
+
/** Read the relay cursor off a parsed inbound frame (`undefined` ⇒ a control
|
|
65
|
+
* frame or a pre-M2 relay). Kept beside {@link stampSeq} so the key never drifts. */
|
|
66
|
+
export function readRseq(frame) {
|
|
67
|
+
const v = frame[RSEQ_KEY];
|
|
68
|
+
return typeof v === "number" ? v : undefined;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/rpc/protocol.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,EAAE;AACF,yEAAyE;AACzE,uEAAuE;AACvE,4EAA4E;AAC5E,gDAAgD;AAEhD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;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,KAAyB;IAChD,MAAM,CAAC,GAAI,KAAkC,CAAC,QAAQ,CAAC,CAAC;IACxD,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EngineHost } from "./driver.js";
|
|
2
|
+
import { BoundedNdjsonWriter } from "./writer.js";
|
|
3
|
+
export interface RpcServerOptions {
|
|
4
|
+
host: EngineHost;
|
|
5
|
+
writer: BoundedNdjsonWriter;
|
|
6
|
+
agent: {
|
|
7
|
+
name: string;
|
|
8
|
+
version: string;
|
|
9
|
+
};
|
|
10
|
+
/** `--yes`: auto-approve every tool permission (trusted automation). When
|
|
11
|
+
* false (default), each permission is round-tripped to the client. */
|
|
12
|
+
autoApprove?: boolean;
|
|
13
|
+
/** Forward `tool:chunk` (live PTY output) by default (N2). */
|
|
14
|
+
toolChunks?: boolean;
|
|
15
|
+
/** stderr sink for the routed bus `log` event (defaults to process.stderr). */
|
|
16
|
+
logSink?: (line: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class RpcServer {
|
|
19
|
+
private readonly host;
|
|
20
|
+
private readonly writer;
|
|
21
|
+
private readonly agent;
|
|
22
|
+
private readonly autoApprove;
|
|
23
|
+
private toolChunks;
|
|
24
|
+
private readonly logSink;
|
|
25
|
+
private built;
|
|
26
|
+
private unsub;
|
|
27
|
+
private activeTurn;
|
|
28
|
+
/** The in-flight `handlePrompt` promise (fire-and-forget from the read
|
|
29
|
+
* loop). Tracked so shutdown can await its terminal `result` before
|
|
30
|
+
* closing the writer (Round-2 M1). */
|
|
31
|
+
private activePrompt;
|
|
32
|
+
private readonly pending;
|
|
33
|
+
private readonly resolvedIds;
|
|
34
|
+
private readonly resolvedSet;
|
|
35
|
+
private shuttingDown;
|
|
36
|
+
constructor(opts: RpcServerOptions);
|
|
37
|
+
/** Drive the server until `lines` ends, then shut down. Returns an exit code. */
|
|
38
|
+
run(lines: AsyncIterable<string>): Promise<number>;
|
|
39
|
+
/** Idempotent shutdown. Order (Round-1 S4): cancel the turn → deny pending
|
|
40
|
+
* permissions (so a turn blocked in the resolver unwinds — M2) → dispose
|
|
41
|
+
* (disposers may emit their LAST bus frames, still subscribed) → flush →
|
|
42
|
+
* close. */
|
|
43
|
+
shutdown(): Promise<void>;
|
|
44
|
+
private handleLine;
|
|
45
|
+
private dispatch;
|
|
46
|
+
private handlePrompt;
|
|
47
|
+
private makeResolver;
|
|
48
|
+
private resolvePermission;
|
|
49
|
+
/** Resolve every outstanding permission with deny — unblocks a turn parked
|
|
50
|
+
* in the resolver on `abort` / shutdown (Round-1 M2). */
|
|
51
|
+
private denyAllPending;
|
|
52
|
+
private markResolved;
|
|
53
|
+
private respondOk;
|
|
54
|
+
private respondError;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=rpc-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-server.d.ts","sourceRoot":"","sources":["../../src/rpc/rpc-server.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAU3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAkBlD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IACzC;0EACsE;IACtE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,+EAA+E;IAC/E,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OA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