@chances-ai/client 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.
Files changed (121) hide show
  1. package/dist/client-core/client.d.ts +145 -0
  2. package/dist/client-core/client.d.ts.map +1 -0
  3. package/dist/client-core/client.js +533 -0
  4. package/dist/client-core/client.js.map +1 -0
  5. package/dist/client-core/index.d.ts +16 -0
  6. package/dist/client-core/index.d.ts.map +1 -0
  7. package/dist/client-core/index.js +15 -0
  8. package/dist/client-core/index.js.map +1 -0
  9. package/dist/client-core/reverse-map.d.ts +66 -0
  10. package/dist/client-core/reverse-map.d.ts.map +1 -0
  11. package/dist/client-core/reverse-map.js +86 -0
  12. package/dist/client-core/reverse-map.js.map +1 -0
  13. package/dist/client-core/store.d.ts +144 -0
  14. package/dist/client-core/store.d.ts.map +1 -0
  15. package/dist/client-core/store.js +36 -0
  16. package/dist/client-core/store.js.map +1 -0
  17. package/dist/client-core/transport.d.ts +53 -0
  18. package/dist/client-core/transport.d.ts.map +1 -0
  19. package/dist/client-core/transport.js +103 -0
  20. package/dist/client-core/transport.js.map +1 -0
  21. package/dist/web-ui/approval-badge.d.ts +17 -0
  22. package/dist/web-ui/approval-badge.d.ts.map +1 -0
  23. package/dist/web-ui/approval-badge.js +24 -0
  24. package/dist/web-ui/approval-badge.js.map +1 -0
  25. package/dist/web-ui/button.d.ts +10 -0
  26. package/dist/web-ui/button.d.ts.map +1 -0
  27. package/dist/web-ui/button.js +16 -0
  28. package/dist/web-ui/button.js.map +1 -0
  29. package/dist/web-ui/code-view.d.ts +6 -0
  30. package/dist/web-ui/code-view.d.ts.map +1 -0
  31. package/dist/web-ui/code-view.js +14 -0
  32. package/dist/web-ui/code-view.js.map +1 -0
  33. package/dist/web-ui/code-viewer.d.ts +11 -0
  34. package/dist/web-ui/code-viewer.d.ts.map +1 -0
  35. package/dist/web-ui/code-viewer.js +55 -0
  36. package/dist/web-ui/code-viewer.js.map +1 -0
  37. package/dist/web-ui/commands.d.ts +23 -0
  38. package/dist/web-ui/commands.d.ts.map +1 -0
  39. package/dist/web-ui/commands.js +26 -0
  40. package/dist/web-ui/commands.js.map +1 -0
  41. package/dist/web-ui/control-panel.d.ts +9 -0
  42. package/dist/web-ui/control-panel.d.ts.map +1 -0
  43. package/dist/web-ui/control-panel.js +70 -0
  44. package/dist/web-ui/control-panel.js.map +1 -0
  45. package/dist/web-ui/diff-view.d.ts +8 -0
  46. package/dist/web-ui/diff-view.d.ts.map +1 -0
  47. package/dist/web-ui/diff-view.js +28 -0
  48. package/dist/web-ui/diff-view.js.map +1 -0
  49. package/dist/web-ui/environment-panel.d.ts +9 -0
  50. package/dist/web-ui/environment-panel.d.ts.map +1 -0
  51. package/dist/web-ui/environment-panel.js +38 -0
  52. package/dist/web-ui/environment-panel.js.map +1 -0
  53. package/dist/web-ui/file-tree.d.ts +9 -0
  54. package/dist/web-ui/file-tree.d.ts.map +1 -0
  55. package/dist/web-ui/file-tree.js +77 -0
  56. package/dist/web-ui/file-tree.js.map +1 -0
  57. package/dist/web-ui/help-view.d.ts +13 -0
  58. package/dist/web-ui/help-view.d.ts.map +1 -0
  59. package/dist/web-ui/help-view.js +15 -0
  60. package/dist/web-ui/help-view.js.map +1 -0
  61. package/dist/web-ui/helpers.d.ts +77 -0
  62. package/dist/web-ui/helpers.d.ts.map +1 -0
  63. package/dist/web-ui/helpers.js +176 -0
  64. package/dist/web-ui/helpers.js.map +1 -0
  65. package/dist/web-ui/hooks.d.ts +7 -0
  66. package/dist/web-ui/hooks.d.ts.map +1 -0
  67. package/dist/web-ui/hooks.js +26 -0
  68. package/dist/web-ui/hooks.js.map +1 -0
  69. package/dist/web-ui/index.d.ts +32 -0
  70. package/dist/web-ui/index.d.ts.map +1 -0
  71. package/dist/web-ui/index.js +38 -0
  72. package/dist/web-ui/index.js.map +1 -0
  73. package/dist/web-ui/markdown.d.ts +12 -0
  74. package/dist/web-ui/markdown.d.ts.map +1 -0
  75. package/dist/web-ui/markdown.js +55 -0
  76. package/dist/web-ui/markdown.js.map +1 -0
  77. package/dist/web-ui/model-picker.d.ts +9 -0
  78. package/dist/web-ui/model-picker.d.ts.map +1 -0
  79. package/dist/web-ui/model-picker.js +119 -0
  80. package/dist/web-ui/model-picker.js.map +1 -0
  81. package/dist/web-ui/permission.d.ts +7 -0
  82. package/dist/web-ui/permission.d.ts.map +1 -0
  83. package/dist/web-ui/permission.js +25 -0
  84. package/dist/web-ui/permission.js.map +1 -0
  85. package/dist/web-ui/primitives.d.ts +59 -0
  86. package/dist/web-ui/primitives.d.ts.map +1 -0
  87. package/dist/web-ui/primitives.js +38 -0
  88. package/dist/web-ui/primitives.js.map +1 -0
  89. package/dist/web-ui/progress.d.ts +28 -0
  90. package/dist/web-ui/progress.d.ts.map +1 -0
  91. package/dist/web-ui/progress.js +45 -0
  92. package/dist/web-ui/progress.js.map +1 -0
  93. package/dist/web-ui/prompt-input.d.ts +15 -0
  94. package/dist/web-ui/prompt-input.d.ts.map +1 -0
  95. package/dist/web-ui/prompt-input.js +129 -0
  96. package/dist/web-ui/prompt-input.js.map +1 -0
  97. package/dist/web-ui/question-view.d.ts +7 -0
  98. package/dist/web-ui/question-view.d.ts.map +1 -0
  99. package/dist/web-ui/question-view.js +60 -0
  100. package/dist/web-ui/question-view.js.map +1 -0
  101. package/dist/web-ui/segments.d.ts +8 -0
  102. package/dist/web-ui/segments.d.ts.map +1 -0
  103. package/dist/web-ui/segments.js +19 -0
  104. package/dist/web-ui/segments.js.map +1 -0
  105. package/dist/web-ui/session-sidebar.d.ts +15 -0
  106. package/dist/web-ui/session-sidebar.d.ts.map +1 -0
  107. package/dist/web-ui/session-sidebar.js +10 -0
  108. package/dist/web-ui/session-sidebar.js.map +1 -0
  109. package/dist/web-ui/status-bar.d.ts +10 -0
  110. package/dist/web-ui/status-bar.d.ts.map +1 -0
  111. package/dist/web-ui/status-bar.js +10 -0
  112. package/dist/web-ui/status-bar.js.map +1 -0
  113. package/dist/web-ui/theme-context.d.ts +13 -0
  114. package/dist/web-ui/theme-context.d.ts.map +1 -0
  115. package/dist/web-ui/theme-context.js +31 -0
  116. package/dist/web-ui/theme-context.js.map +1 -0
  117. package/dist/web-ui/transcript.d.ts +27 -0
  118. package/dist/web-ui/transcript.d.ts.map +1 -0
  119. package/dist/web-ui/transcript.js +56 -0
  120. package/dist/web-ui/transcript.js.map +1 -0
  121. package/package.json +56 -0
@@ -0,0 +1,533 @@
1
+ /**
2
+ * (v17 M1 / v19 M2 / v20 M3) `RpcClient` — the pure-TS ACP client state machine.
3
+ * It owns the transport, a browser-safe `LocalEventBus`, the reused
4
+ * `ChatViewModel` (transcript), and a vanilla-zustand control store. Inbound ACP
5
+ * `session/update` notifications are reverse-mapped to `AppEvent`s on the bus
6
+ * that drives the ChatViewModel; the `session/prompt` response, the
7
+ * `session/request_permission` request, and the chances extension event/responses
8
+ * drive the control store. Outbound commands are ACP JSON-RPC. No DOM/React/Ink
9
+ * here — that is web-ui's job.
10
+ *
11
+ * **Self-rolled ACP, not the SDK runtime (docs/6.4a §3).** The relay fans one
12
+ * session out to many sockets, so the SDK's point-to-point `ClientSideConnection`
13
+ * (which owns JSON-RPC id correlation for one socket) doesn't fit. We frame ACP
14
+ * ourselves on the same transport seam, keeping the M2 reconnect machinery: ids
15
+ * are prefixed per client so a fan-out response can't cross-talk between tabs
16
+ * (`ownsId`); a re-received `session/request_permission` for an already-pending
17
+ * id is idempotent; permission answers are ACP responses to the agent's request.
18
+ *
19
+ * Handshake: on the first (or a cold-reloaded) `relay_welcome`, the client sends
20
+ * ACP `initialize` then `session/new` to learn its capabilities/models +
21
+ * sessionId; a RESUMING reconnect skips the handshake (it already has them) and
22
+ * just replays the gap. The wire is real ACP — a plain ACP client/Zed speaks the
23
+ * same `initialize`/`session/*` it does (proven by the c6 SDK-interop test).
24
+ */
25
+ import { ChatViewModel, LocalEventBus } from "@chances-ai/ui-core";
26
+ /** Shift+Tab cycle order (the value-import of runtime's `APPROVAL_CYCLE` would
27
+ * drag the engine into the browser bundle, so mirror the 4-mode order here). */
28
+ const APPROVAL_CYCLE = ["default", "auto-edit", "plan", "yolo"];
29
+ import { acpPermissionToAppEvent, sessionUpdateToAppEvent } from "./reverse-map.js";
30
+ import { createClientStore, } from "./store.js";
31
+ const DEFAULT_BASE_DELAY_MS = 500;
32
+ const DEFAULT_MAX_DELAY_MS = 10_000;
33
+ const DEFAULT_STALE_MS = 5 * 60_000;
34
+ const defaultSchedule = (delayMs, run) => {
35
+ const t = setTimeout(run, delayMs);
36
+ return () => clearTimeout(t);
37
+ };
38
+ /** ACP method names + chances extensions (mirror the agent driver's table). */
39
+ const ACP_PROTOCOL_VERSION = 1;
40
+ /** JSON-RPC error code the relay returns when a viewer sends a privileged command
41
+ * while another client holds the controller lease (§5). */
42
+ const NOT_CONTROLLER = -32010;
43
+ export class RpcClient {
44
+ view;
45
+ store = createClientStore();
46
+ bus = new LocalEventBus();
47
+ factory;
48
+ handlers;
49
+ transport;
50
+ seq = 0;
51
+ clientId;
52
+ /** In-flight request/response waiters (initialize/session.new/ping/set_model). */
53
+ waiters = new Map();
54
+ // -- reconnect state (M2; protocol-agnostic, kept verbatim) --
55
+ userClosed = false;
56
+ transportDown = false;
57
+ reconnectAttempt = 0;
58
+ reconnectBudgetMs = 0;
59
+ cancelReconnect = null;
60
+ schedule;
61
+ baseDelayMs;
62
+ maxDelayMs;
63
+ staleAfterMs;
64
+ constructor(factory, opts = {}) {
65
+ this.view = new ChatViewModel(undefined, {
66
+ ...(opts.scheduler ? { scheduler: opts.scheduler } : {}),
67
+ ...(opts.home !== undefined ? { home: opts.home } : {}),
68
+ });
69
+ this.view.attach(this.bus);
70
+ this.factory = factory;
71
+ this.clientId = opts.clientId ?? randomClientId();
72
+ this.schedule = opts.reconnect?.schedule ?? defaultSchedule;
73
+ this.baseDelayMs = opts.reconnect?.baseDelayMs ?? DEFAULT_BASE_DELAY_MS;
74
+ this.maxDelayMs = opts.reconnect?.maxDelayMs ?? DEFAULT_MAX_DELAY_MS;
75
+ this.staleAfterMs = opts.reconnect?.staleAfterMs ?? DEFAULT_STALE_MS;
76
+ this.handlers = {
77
+ onOpen: () => {
78
+ /* status stays connecting/reconnecting until relay_welcome + handshake */
79
+ },
80
+ onMessage: (data) => this.handleMessage(data),
81
+ onClose: () => this.onTransportDown("closed"),
82
+ onError: () => this.onTransportDown("error"),
83
+ };
84
+ this.transport = this.connect();
85
+ }
86
+ connect() {
87
+ this.transportDown = false;
88
+ return this.factory(this.handlers, this.store.getState().lastSeq, this.clientId);
89
+ }
90
+ // -- commands (outbound ACP) ------------------------------------------------
91
+ /** Submit a prompt (ACP `session/prompt`). Echoes a user line + optimistically
92
+ * marks busy; a rejected response (AGENT_BUSY) clears it. */
93
+ prompt(text) {
94
+ const id = this.nextId();
95
+ this.view.pushUser(text);
96
+ // ACP has no `turn_start` notification (the turn is the request lifetime), so
97
+ // synthesize one locally to open the ChatViewModel's assistant block — same
98
+ // role the bespoke wire's `turn_start` frame played (pushUser stays the user
99
+ // line; turn:start does NOT re-echo it).
100
+ this.bus.emit({ type: "turn:start", turnId: "", prompt: text });
101
+ this.store.setState({ busy: true, lastError: null });
102
+ this.sendRaw({
103
+ jsonrpc: "2.0",
104
+ id,
105
+ method: "session/prompt",
106
+ params: { sessionId: this.sessionId(), prompt: [{ type: "text", text }] },
107
+ });
108
+ }
109
+ /** Cancel the running turn (ACP `session/cancel` notification). */
110
+ abort() {
111
+ this.sendRaw({ jsonrpc: "2.0", method: "session/cancel", params: { sessionId: this.sessionId() } });
112
+ }
113
+ /** Claim the controller lease — a handoff (no effect when the lease is disabled,
114
+ * since everyone already drives). The relay broadcasts the new holder/epoch as
115
+ * a `_chances/unstable/control` notification that recomputes `isController`. */
116
+ takeControl() {
117
+ this.sendRaw({ jsonrpc: "2.0", id: this.nextId(), method: "_chances/unstable/take_control", params: {} });
118
+ }
119
+ /** Switch model (chances extension). Resolves with the ack result. */
120
+ setModel(selection) {
121
+ const id = this.nextId();
122
+ const done = this.expectResponse(id);
123
+ this.sendRaw({ jsonrpc: "2.0", id, method: "_chances/unstable/set_model", params: selection });
124
+ return done.then((r) => {
125
+ const d = r;
126
+ if (d?.provider && d?.model)
127
+ this.store.setState({ selected: { provider: d.provider, model: d.model } });
128
+ return r;
129
+ });
130
+ }
131
+ /** (v22) Set the session approval mode (chances extension `set_approval`), the
132
+ * GUI twin of the TUI Shift+Tab. Allowed mid-turn (applies to the next
133
+ * permission check). Optimistically updates the store, then reconciles with
134
+ * the ack (the engine echoes the mode it actually applied). */
135
+ setApprovalMode(mode) {
136
+ this.store.setState({ approvalMode: mode });
137
+ const id = this.nextId();
138
+ const done = this.expectResponse(id);
139
+ this.sendRaw({ jsonrpc: "2.0", id, method: "_chances/unstable/set_approval", params: { mode } });
140
+ return done.then((r) => {
141
+ const m = r?.approvalMode;
142
+ if (m)
143
+ this.store.setState({ approvalMode: m });
144
+ return r;
145
+ });
146
+ }
147
+ /** (v22) Advance the approval mode one step in the Shift+Tab cycle. */
148
+ cycleApprovalMode() {
149
+ const cur = this.store.getState().approvalMode;
150
+ const next = APPROVAL_CYCLE[(APPROVAL_CYCLE.indexOf(cur) + 1) % APPROVAL_CYCLE.length];
151
+ return this.setApprovalMode(next);
152
+ }
153
+ /** Answer the open permission ask — an ACP RESPONSE to the agent's
154
+ * `session/request_permission` request (id = the ask id). No-op when none. */
155
+ answerPermission(allow, remember) {
156
+ const pending = this.store.getState().pendingPermission;
157
+ if (!pending)
158
+ return;
159
+ const optionId = allow ? (remember ? "allow_always" : "allow_once") : "reject_once";
160
+ this.sendRaw({ jsonrpc: "2.0", id: pending.id, result: { outcome: { outcome: "selected", optionId } } });
161
+ this.store.setState({ pendingPermission: null });
162
+ }
163
+ /** (v22) Answer the open `ask_user_question` — an ACP RESPONSE to the agent's
164
+ * `_chances/unstable/request_question` request (id = the ask id). `declined`
165
+ * cancels. No-op when none pending. */
166
+ answerQuestion(answer) {
167
+ const pending = this.store.getState().pendingQuestion;
168
+ if (!pending)
169
+ return;
170
+ this.sendRaw({ jsonrpc: "2.0", id: pending.id, result: answer });
171
+ this.store.setState({ pendingQuestion: null });
172
+ }
173
+ /** Liveness probe (chances extension `_chances/unstable/ping`). */
174
+ ping() {
175
+ const id = this.nextId();
176
+ const done = this.expectResponse(id);
177
+ this.sendRaw({ jsonrpc: "2.0", id, method: "_chances/unstable/ping", params: {} });
178
+ return done;
179
+ }
180
+ // -- (v23 M5) read-only workspace queries (the 3-pane IDE) ------------------
181
+ // Each follows the `setModel`/`ping` request/response template: a per-client
182
+ // prefixed id parks a waiter, the relay answers it targeted (off-ring), and
183
+ // `ownsId` keeps this client's response. The method-name strings are inlined
184
+ // (a value import of `@chances-ai/rpc` would drag the engine into the bundle).
185
+ /** List the immediate children of `dir` (one level, lazy). The file tree calls
186
+ * this per-expand; results stay component-local (not in the store). */
187
+ listFiles(dir) {
188
+ return this.query("_chances/unstable/list_files", { dir });
189
+ }
190
+ /** Read a workspace file (capped + binary-guarded) and set it as the open file
191
+ * in the store so the code viewer renders it. */
192
+ async openFileInViewer(path) {
193
+ const res = await this.query("_chances/unstable/read_file", { path });
194
+ this.store.setState({ openFile: res });
195
+ return res;
196
+ }
197
+ /** Refresh `git_status` into the store (shared by the environment panel + the
198
+ * file tree change badges). */
199
+ async refreshGitStatus() {
200
+ const res = await this.query("_chances/unstable/git_status", {});
201
+ this.store.setState({ gitStatus: res });
202
+ return res;
203
+ }
204
+ /** `git diff [path]` — the code viewer fetches this on demand (component-local). */
205
+ gitDiff(path) {
206
+ return this.query("_chances/unstable/git_diff", path ? { path } : {});
207
+ }
208
+ /** Shared request/response helper for the read-only queries. */
209
+ query(method, params) {
210
+ const id = this.nextId();
211
+ const done = this.expectResponse(id);
212
+ this.sendRaw({ jsonrpc: "2.0", id, method, params });
213
+ return done;
214
+ }
215
+ /** Close the transport for good — a USER close, so NO reconnect follows. */
216
+ close() {
217
+ this.userClosed = true;
218
+ this.cancelReconnect?.();
219
+ this.cancelReconnect = null;
220
+ this.transport.close();
221
+ }
222
+ // -- inbound dispatch -------------------------------------------------------
223
+ handleMessage(data) {
224
+ let msg;
225
+ try {
226
+ msg = JSON.parse(data);
227
+ }
228
+ catch {
229
+ return; // ignore non-JSON noise
230
+ }
231
+ if (typeof msg !== "object" || msg === null)
232
+ return;
233
+ // Relay control frames (carry `type`, never `jsonrpc`/`rseq`).
234
+ if (msg.type === "relay_welcome") {
235
+ this.onWelcome(msg);
236
+ return;
237
+ }
238
+ if (msg.type === "reset") {
239
+ this.coldReload();
240
+ return;
241
+ }
242
+ // Advance the reconnect cursor on every relay-stamped frame.
243
+ const rseq = readCursor(msg);
244
+ if (rseq !== undefined && rseq > this.store.getState().lastSeq) {
245
+ this.store.setState({ lastSeq: rseq });
246
+ }
247
+ // ACP JSON-RPC.
248
+ if (typeof msg.method === "string") {
249
+ if (msg.method === "session/update")
250
+ this.onSessionUpdate(msg.params);
251
+ else if (msg.method === "session/request_permission")
252
+ this.onPermissionRequest(msg.id, msg.params);
253
+ else if (msg.method === "_chances/unstable/request_question")
254
+ this.onQuestionRequest(msg.id, msg.params);
255
+ else if (msg.method === "_chances/unstable/event")
256
+ this.onExtEvent(msg.params);
257
+ else if (msg.method === "_chances/unstable/control")
258
+ this.onControlState(msg.params);
259
+ return; // unknown notification → ignore
260
+ }
261
+ if (msg.id !== undefined && ("result" in msg || "error" in msg)) {
262
+ this.onResponse(msg.id, msg.result, msg.error ?? null);
263
+ }
264
+ }
265
+ /** A `relay_welcome`: adopt the snapshot, clear backoff, cold-reload if stale,
266
+ * and (re)handshake if this is a fresh/cold session. */
267
+ onWelcome(frame) {
268
+ this.reconnectAttempt = 0;
269
+ this.reconnectBudgetMs = 0;
270
+ if (frame.reset)
271
+ this.coldReload();
272
+ this.store.setState({ epoch: frame.epoch, busy: frame.busy, ...this.leaseStateFrom(frame.lease, frame.holder, frame.controlEpoch) });
273
+ if (!this.store.getState().sessionId) {
274
+ // Fresh OR cold-reloaded → ACP handshake to (re)learn caps/models + sessionId.
275
+ this.store.setState({ status: "connecting" });
276
+ void this.doHandshake();
277
+ }
278
+ else {
279
+ // Resuming an existing session — already initialized; just resume.
280
+ this.store.setState({ status: "ready" });
281
+ }
282
+ }
283
+ async doHandshake() {
284
+ try {
285
+ const initId = this.nextId();
286
+ const init = this.expectResponse(initId);
287
+ this.sendRaw({ jsonrpc: "2.0", id: initId, method: "initialize", params: { protocolVersion: ACP_PROTOCOL_VERSION, clientCapabilities: {} } });
288
+ const initRes = (await init);
289
+ const caps = initRes?._meta?.chances?.capabilities;
290
+ const models = caps?.models ?? [];
291
+ // (v22) Approval mode rides the initialize `_meta.chances` — no extra
292
+ // round-trip, and a plain ACP server (no chances meta) just keeps "default".
293
+ const approvalMode = initRes?._meta?.chances?.approvalMode ?? "default";
294
+ const approvalSupported = caps?.approvalSelection === true;
295
+ // (v23 M5) Show the 3-pane IDE's file/code/git panes only when the agent
296
+ // advertises read-only workspace queries (a plain ACP server reports false).
297
+ const workspaceQueriesSupported = caps?.workspaceQueries === true;
298
+ const nsId = this.nextId();
299
+ const ns = this.expectResponse(nsId);
300
+ this.sendRaw({ jsonrpc: "2.0", id: nsId, method: "session/new", params: { cwd: "", mcpServers: [] } });
301
+ const nsRes = (await ns);
302
+ this.store.setState({
303
+ status: "ready",
304
+ models,
305
+ selected: models[0] ?? null,
306
+ sessionId: nsRes?.sessionId ?? null,
307
+ approvalMode,
308
+ approvalSupported,
309
+ workspaceQueriesSupported,
310
+ });
311
+ }
312
+ catch {
313
+ // Transport died mid-handshake — the reconnect machinery retries.
314
+ }
315
+ }
316
+ coldReload() {
317
+ this.view.clearLines();
318
+ this.store.setState({ lastSeq: 0, pendingPermission: null, pendingQuestion: null, sessionId: null });
319
+ }
320
+ onSessionUpdate(params) {
321
+ const update = params?.update;
322
+ if (!update)
323
+ return;
324
+ if (update.sessionUpdate === "usage_update") {
325
+ const uu = update;
326
+ this.store.setState({
327
+ lastUsage: {
328
+ inputTokens: uu._meta?.chances?.usage?.inputTokens ?? 0,
329
+ outputTokens: uu._meta?.chances?.usage?.outputTokens ?? 0,
330
+ costUsd: uu.cost?.amount ?? 0,
331
+ },
332
+ });
333
+ return;
334
+ }
335
+ const event = sessionUpdateToAppEvent(update);
336
+ if (event)
337
+ this.bus.emit(event);
338
+ }
339
+ onPermissionRequest(id, params) {
340
+ if (id === undefined)
341
+ return;
342
+ const idStr = String(id);
343
+ // Idempotent re-send (M2): the relay re-sends an open ask on every attach.
344
+ if (this.store.getState().pendingPermission?.id === idStr)
345
+ return;
346
+ const tc = (params?.toolCall ?? {});
347
+ const meta = tc._meta?.chances ?? {};
348
+ const tool = meta.tool ?? tc.title ?? "tool";
349
+ const summary = tc.title ?? "";
350
+ this.store.setState({
351
+ pendingPermission: {
352
+ id: idStr,
353
+ ...(tc.toolCallId !== undefined ? { callId: tc.toolCallId } : {}),
354
+ tool,
355
+ category: meta.category ?? "",
356
+ summary,
357
+ args: (tc.rawInput ?? {}),
358
+ },
359
+ });
360
+ this.bus.emit(acpPermissionToAppEvent({ toolCallId: tc.toolCallId, name: tool, summary }));
361
+ }
362
+ /** (v22) An incoming `_chances/unstable/request_question` — park it for the UI.
363
+ * Idempotent on re-send (M2), mirroring the permission ask. */
364
+ onQuestionRequest(id, params) {
365
+ if (id === undefined)
366
+ return;
367
+ const idStr = String(id);
368
+ if (this.store.getState().pendingQuestion?.id === idStr)
369
+ return;
370
+ const questions = (params?.questions ?? []);
371
+ this.store.setState({ pendingQuestion: { id: idStr, questions } });
372
+ }
373
+ onExtEvent(params) {
374
+ const chances = params?._meta?.chances;
375
+ if (!chances)
376
+ return;
377
+ const err = chances.error;
378
+ if (err?.message) {
379
+ this.store.setState({ lastError: err.message });
380
+ // Surface the engine error as an inline transcript line too, matching the
381
+ // TUI: the status bar reads `lastError`, but the transcript needs the
382
+ // `error` AppEvent. M1's `EventFrame → AppEvent` emitted it; M3 routed
383
+ // `error` onto the `_chances/unstable/event` notification, so re-emit here
384
+ // (else web/desktop transcripts silently drop engine errors the TUI shows).
385
+ this.bus.emit({ type: "error", code: (err.code ?? "UNKNOWN"), message: err.message });
386
+ }
387
+ // (6.5b review) A retry is about to restream this turn; drop the partial
388
+ // assistant line so the web/desktop transcript doesn't append-duplicate it,
389
+ // exactly as the TUI does (the engine routed reset onto this extension
390
+ // event — there is no standard ACP SessionUpdate to undo a chunk).
391
+ const reset = chances.reset;
392
+ if (reset) {
393
+ this.bus.emit({ type: "assistant:reset", turnId: reset.turnId ?? "" });
394
+ }
395
+ // compaction/subagent carry no store action.
396
+ }
397
+ /** A `_chances/unstable/control` notification (a lease handoff / state change):
398
+ * recompute whether THIS client may drive. */
399
+ onControlState(params) {
400
+ const p = (params ?? {});
401
+ this.store.setState(this.leaseStateFrom(p.lease ?? false, p.holder ?? null, p.controlEpoch ?? 0));
402
+ }
403
+ /** Derive lease UI state: this client may drive when the lease is OFF (everyone
404
+ * drives) OR it holds the lease (`holder === clientId`). */
405
+ leaseStateFrom(lease, holder, controlEpoch) {
406
+ return { leaseEnabled: lease, isController: !lease || holder === this.clientId, controlEpoch };
407
+ }
408
+ onResponse(id, result, error) {
409
+ // A controller-lease rejection (not_controller) is targeted to THIS client,
410
+ // but its id is the SERVER's permission id (not ours), so handle it BEFORE the
411
+ // ownsId fan-out filter would drop it — else a viewer's rejected permission
412
+ // answer fails silently (codex M4-review SHOULD).
413
+ if (error && error.code === NOT_CONTROLLER) {
414
+ this.store.setState({ busy: false, lastError: error.message ?? "not the controller" });
415
+ return;
416
+ }
417
+ const idStr = String(id);
418
+ if (!this.ownsId(idStr))
419
+ return; // fan-out: another tab's response
420
+ const waiter = this.waiters.get(idStr);
421
+ if (waiter) {
422
+ this.waiters.delete(idStr);
423
+ if (error)
424
+ waiter.reject(new Error(error.message ?? "request failed"));
425
+ else
426
+ waiter.resolve(result);
427
+ return;
428
+ }
429
+ // No waiter → a fire-and-forget `session/prompt`'s terminal response (or its
430
+ // rejection). A rejected prompt (AGENT_BUSY) releases the optimistic busy.
431
+ if (error) {
432
+ this.store.setState({ busy: false, lastError: error.message ?? "prompt rejected" });
433
+ return;
434
+ }
435
+ if (result && typeof result.stopReason === "string") {
436
+ this.onTurnEnd(result);
437
+ }
438
+ }
439
+ /** The `session/prompt` response folds the turn end (chances `result` frame):
440
+ * clear busy + any pending permission, record stopReason/usage, commit the VM. */
441
+ onTurnEnd(result) {
442
+ const r = result;
443
+ this.store.setState({
444
+ busy: false,
445
+ pendingPermission: null,
446
+ pendingQuestion: null, // (codex v22 MUST) no zombie QuestionView past turn end
447
+ lastStopReason: r.stopReason,
448
+ lastUsage: { inputTokens: r.usage?.inputTokens ?? 0, outputTokens: r.usage?.outputTokens ?? 0, costUsd: r._meta?.chances?.costUsd ?? 0 },
449
+ });
450
+ this.bus.emit({ type: "turn:end", turnId: "" });
451
+ }
452
+ // -- transport lifecycle (M2 reconnect; kept verbatim) ----------------------
453
+ onTransportDown(kind) {
454
+ if (this.transportDown)
455
+ return;
456
+ this.transportDown = true;
457
+ const message = kind === "error" ? "connection error" : "connection closed";
458
+ this.rejectWaiters(new Error(message));
459
+ if (this.userClosed) {
460
+ this.toTerminal(kind, kind === "error" ? message : undefined);
461
+ return;
462
+ }
463
+ this.store.setState({
464
+ status: "reconnecting",
465
+ ...(kind === "error" ? { lastError: message } : {}),
466
+ });
467
+ this.scheduleReconnect();
468
+ }
469
+ scheduleReconnect() {
470
+ const delay = Math.min(this.baseDelayMs * 2 ** this.reconnectAttempt, this.maxDelayMs);
471
+ this.reconnectAttempt++;
472
+ if (this.reconnectBudgetMs + delay > this.staleAfterMs) {
473
+ this.toTerminal("error", "reconnect timed out");
474
+ return;
475
+ }
476
+ this.reconnectBudgetMs += delay;
477
+ this.cancelReconnect = this.schedule(delay, () => {
478
+ this.cancelReconnect = null;
479
+ if (this.userClosed)
480
+ return;
481
+ this.store.setState({ status: "connecting" });
482
+ this.transport = this.connect();
483
+ });
484
+ }
485
+ toTerminal(status, errorMessage) {
486
+ this.userClosed = true;
487
+ this.cancelReconnect?.();
488
+ this.cancelReconnect = null;
489
+ this.store.setState({
490
+ status,
491
+ busy: false,
492
+ pendingPermission: null,
493
+ pendingQuestion: null,
494
+ sessionId: null,
495
+ models: [],
496
+ selected: null,
497
+ epoch: null,
498
+ ...(errorMessage !== undefined ? { lastError: errorMessage } : {}),
499
+ });
500
+ }
501
+ rejectWaiters(err) {
502
+ for (const waiter of this.waiters.values())
503
+ waiter.reject(err);
504
+ this.waiters.clear();
505
+ }
506
+ // -- helpers ----------------------------------------------------------------
507
+ sessionId() {
508
+ return this.store.getState().sessionId ?? "";
509
+ }
510
+ nextId() {
511
+ return `${this.clientId}-${++this.seq}`;
512
+ }
513
+ ownsId(id) {
514
+ return id.startsWith(`${this.clientId}-`);
515
+ }
516
+ sendRaw(message) {
517
+ this.transport.send(JSON.stringify(message));
518
+ }
519
+ expectResponse(id) {
520
+ return new Promise((resolve, reject) => this.waiters.set(id, { resolve, reject }));
521
+ }
522
+ }
523
+ /** Read the relay cursor (`rseq`) off a parsed inbound frame, inline (NOT via a
524
+ * `@chances-ai/rpc` value import — that edge would pull the engine runtime into
525
+ * the browser bundle). */
526
+ function readCursor(frame) {
527
+ const v = frame.rseq;
528
+ return typeof v === "number" ? v : undefined;
529
+ }
530
+ function randomClientId() {
531
+ return `c${Math.random().toString(36).slice(2, 8)}`;
532
+ }
533
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client-core/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,aAAa,EAAE,aAAa,EAA6B,MAAM,qBAAqB,CAAC;AAQ9F;iFACiF;AACjF,MAAM,cAAc,GAA4B,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAkB,MAAM,kBAAkB,CAAC;AACpG,OAAO,EACL,iBAAiB,GAQlB,MAAM,YA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IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACtD,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `@chances-ai/client-core` — the surface-agnostic, **browser-safe** ACP
3
+ * client (docs/6.1 §3.2 / 6.4a M3). A pure-TS state machine over a pluggable transport:
4
+ * it reuses the `@chances-ai/ui-core` `ChatViewModel` for the transcript
5
+ * (no forked view logic), exposes connection/permission/model state through a
6
+ * vanilla-zustand store, and owns the permission round-trip. Consumed by
7
+ * `web-ui` (React) now and React-Native (M5) later; the WS transport works in
8
+ * both browsers and Bun. Type-only imports of `@chances-ai/rpc` /
9
+ * `@chances-ai/runtime` keep the engine out of the browser bundle.
10
+ */
11
+ export { RpcClient, type RpcClientOptions } from "./client.js";
12
+ export { type Transport, type TransportFactory, type TransportHandlers, webSocketTransport, withPairingToken, } from "./transport.js";
13
+ export { type ClientState, type ClientStore, type ConnectionStatus, type PendingPermission, type PendingQuestion, type QuestionSpec, type QuestionOption, type QuestionAnswer, type Usage, type FileEntry, type ListFilesResult, type ReadFileResult, type GitFileStatus, type GitStatusResult, type GitDiffResult, createClientStore, initialClientState, } from "./store.js";
14
+ export { sessionUpdateToAppEvent, acpPermissionToAppEvent, type AcpUpdate } from "./reverse-map.js";
15
+ export type { ModelInfo } from "@chances-ai/wire/rpc";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAIpG,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * `@chances-ai/client-core` — the surface-agnostic, **browser-safe** ACP
3
+ * client (docs/6.1 §3.2 / 6.4a M3). A pure-TS state machine over a pluggable transport:
4
+ * it reuses the `@chances-ai/ui-core` `ChatViewModel` for the transcript
5
+ * (no forked view logic), exposes connection/permission/model state through a
6
+ * vanilla-zustand store, and owns the permission round-trip. Consumed by
7
+ * `web-ui` (React) now and React-Native (M5) later; the WS transport works in
8
+ * both browsers and Bun. Type-only imports of `@chances-ai/rpc` /
9
+ * `@chances-ai/runtime` keep the engine out of the browser bundle.
10
+ */
11
+ export { RpcClient } from "./client.js";
12
+ export { webSocketTransport, withPairingToken, } from "./transport.js";
13
+ export { createClientStore, initialClientState, } from "./store.js";
14
+ export { sessionUpdateToAppEvent, acpPermissionToAppEvent } from "./reverse-map.js";
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client-core/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,aAAa,CAAC;AAC/D,OAAO,EAIL,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAgBL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAkB,MAAM,kBAAkB,CAAC"}