viberoom 0.3.1 → 0.4.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/NOTICE +12 -0
- package/README.md +119 -96
- package/dist/hub.js +18 -0
- package/dist/launcher.js +22 -0
- package/dist/main.js +4 -3
- package/dist/persona.js +1 -1
- package/dist/recipes.js +37 -14
- package/dist/room.js +3 -2
- package/dist/server.js +5 -0
- package/package.json +8 -5
- package/scripts/vendor-acp.mjs +85 -0
- package/ui/app.css +7 -0
- package/ui/app.js +47 -2
- package/ui/index.html +2 -0
- package/vendor/acp/claude-agent-acp/LICENSE +191 -0
- package/vendor/acp/claude-agent-acp/dist/acp-agent.js +7694 -0
- package/vendor/acp/claude-agent-acp/dist/acp-subagents.js +13 -0
- package/vendor/acp/claude-agent-acp/dist/air-extension.js +63 -0
- package/vendor/acp/claude-agent-acp/dist/async-tasks.js +613 -0
- package/vendor/acp/claude-agent-acp/dist/clear-context-coordinator.js +80 -0
- package/vendor/acp/claude-agent-acp/dist/elicitation.js +304 -0
- package/vendor/acp/claude-agent-acp/dist/exit-plan.js +154 -0
- package/vendor/acp/claude-agent-acp/dist/file-change-audit.js +350 -0
- package/vendor/acp/claude-agent-acp/dist/fork-session.js +41 -0
- package/vendor/acp/claude-agent-acp/dist/goal-extension.js +50 -0
- package/vendor/acp/claude-agent-acp/dist/index.js +98 -0
- package/vendor/acp/claude-agent-acp/dist/lib.js +5 -0
- package/vendor/acp/claude-agent-acp/dist/native-subagents.js +422 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/effects.js +166 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/modes.js +41 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/normalization.js +100 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/options/filesystem.js +124 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/options/shared.js +64 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/options/shell.js +100 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/options/tools.js +135 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/options.js +60 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/presentation.js +83 -0
- package/vendor/acp/claude-agent-acp/dist/permissions/response.js +19 -0
- package/vendor/acp/claude-agent-acp/dist/session-config-ids.js +4 -0
- package/vendor/acp/claude-agent-acp/dist/session-failure-extension.js +324 -0
- package/vendor/acp/claude-agent-acp/dist/session-mode.js +234 -0
- package/vendor/acp/claude-agent-acp/dist/session-titles.js +199 -0
- package/vendor/acp/claude-agent-acp/dist/settings.js +185 -0
- package/vendor/acp/claude-agent-acp/dist/tool-result-meta.js +19 -0
- package/vendor/acp/claude-agent-acp/dist/tools.js +1235 -0
- package/vendor/acp/claude-agent-acp/dist/utils.js +81 -0
- package/vendor/acp/claude-agent-acp/package.json +7 -0
- package/vendor/acp/claude-agent-sdk/LICENSE.md +1 -0
- package/vendor/acp/claude-agent-sdk/agentSdkTypes.d.ts +1 -0
- package/vendor/acp/claude-agent-sdk/bridge.d.ts +378 -0
- package/vendor/acp/claude-agent-sdk/bridge.mjs +221 -0
- package/vendor/acp/claude-agent-sdk/browser-sdk.d.ts +107 -0
- package/vendor/acp/claude-agent-sdk/browser-sdk.js +185 -0
- package/vendor/acp/claude-agent-sdk/extractFromBunfs.d.ts +1 -0
- package/vendor/acp/claude-agent-sdk/extractFromBunfs.js +156 -0
- package/vendor/acp/claude-agent-sdk/manifest.json +65 -0
- package/vendor/acp/claude-agent-sdk/manifest.zst.json +73 -0
- package/vendor/acp/claude-agent-sdk/package.json +7 -0
- package/vendor/acp/claude-agent-sdk/sdk-tools.d.ts +4129 -0
- package/vendor/acp/claude-agent-sdk/sdk.d.ts +8687 -0
- package/vendor/acp/claude-agent-sdk/sdk.mjs +204 -0
- package/vendor/acp/codex-acp/LICENSE +190 -0
- package/vendor/acp/codex-acp/dist/index.js +34238 -0
- package/vendor/acp/codex-acp/package.json +7 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// A pushable async iterable: allows you to push items and consume them with for-await.
|
|
2
|
+
import { WritableStream, ReadableStream } from "node:stream/web";
|
|
3
|
+
// Useful for bridging push-based and async-iterator-based code.
|
|
4
|
+
export class Pushable {
|
|
5
|
+
queue = [];
|
|
6
|
+
resolvers = [];
|
|
7
|
+
done = false;
|
|
8
|
+
push(item) {
|
|
9
|
+
if (this.resolvers.length > 0) {
|
|
10
|
+
const resolve = this.resolvers.shift();
|
|
11
|
+
resolve({ value: item, done: false });
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
this.queue.push(item);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
end() {
|
|
18
|
+
this.done = true;
|
|
19
|
+
while (this.resolvers.length > 0) {
|
|
20
|
+
const resolve = this.resolvers.shift();
|
|
21
|
+
resolve({ value: undefined, done: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
[Symbol.asyncIterator]() {
|
|
25
|
+
return {
|
|
26
|
+
next: () => {
|
|
27
|
+
if (this.queue.length > 0) {
|
|
28
|
+
const value = this.queue.shift();
|
|
29
|
+
return Promise.resolve({ value, done: false });
|
|
30
|
+
}
|
|
31
|
+
if (this.done) {
|
|
32
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
33
|
+
}
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
this.resolvers.push(resolve);
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Helper to convert Node.js streams to Web Streams
|
|
42
|
+
export function nodeToWebWritable(nodeStream) {
|
|
43
|
+
return new WritableStream({
|
|
44
|
+
write(chunk) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
nodeStream.write(Buffer.from(chunk), (err) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
reject(err);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
resolve();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function nodeToWebReadable(nodeStream) {
|
|
59
|
+
return new ReadableStream({
|
|
60
|
+
start(controller) {
|
|
61
|
+
nodeStream.on("data", (chunk) => {
|
|
62
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
63
|
+
});
|
|
64
|
+
nodeStream.on("end", () => controller.close());
|
|
65
|
+
nodeStream.on("error", (err) => controller.error(err));
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export function unreachable(value, logger = console) {
|
|
70
|
+
let valueAsString;
|
|
71
|
+
try {
|
|
72
|
+
valueAsString = JSON.stringify(value);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
valueAsString = value;
|
|
76
|
+
}
|
|
77
|
+
logger.error(`Unexpected case: ${valueAsString}`);
|
|
78
|
+
}
|
|
79
|
+
export function sleep(time) {
|
|
80
|
+
return new Promise((resolve) => setTimeout(resolve, time));
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
© Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://code.claude.com/docs/en/legal-and-compliance.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sdk.js'
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API surface definition for @anthropic-ai/claude-agent-sdk/bridge.
|
|
3
|
+
*
|
|
4
|
+
* This file is the source of truth for the /bridge export's public types.
|
|
5
|
+
* It imports ONLY from agentSdkTypes.ts so the compiled .d.ts has exactly
|
|
6
|
+
* one import to rewrite (./agentSdkTypes → ./sdk) for the flat package layout.
|
|
7
|
+
*
|
|
8
|
+
* Compiled by scripts/build-ant-sdk-typings.sh; see build-agent-sdk.sh for the
|
|
9
|
+
* copy into the package. Runtime code is in agentSdkBridge.ts (separate file,
|
|
10
|
+
* bun-built to bridge.mjs).
|
|
11
|
+
*
|
|
12
|
+
* The two type definitions below are copied from src/bridge/sessionHandle.ts.
|
|
13
|
+
* Keep in sync — sessionHandle.ts is the implementation source of truth;
|
|
14
|
+
* this file exists to produce a clean .d.ts without walking the implementation
|
|
15
|
+
* import graph.
|
|
16
|
+
*/
|
|
17
|
+
import type { PermissionMode, SDKControlRequest, SDKControlResponse, SDKMessage } from './agentSdkTypes.js';
|
|
18
|
+
/**
|
|
19
|
+
* Session state reported to the CCR /worker endpoint.
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export type SessionState = 'idle' | 'running' | 'requires_action';
|
|
23
|
+
/**
|
|
24
|
+
* Per-session bridge transport handle.
|
|
25
|
+
*
|
|
26
|
+
* Auth is instance-scoped — the JWT lives in this handle's closure, not a
|
|
27
|
+
* process-wide env var, so multiple handles can coexist without stomping
|
|
28
|
+
* each other.
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export type BridgeSessionHandle = {
|
|
32
|
+
readonly sessionId: string;
|
|
33
|
+
/**
|
|
34
|
+
* Live SSE event-stream high-water mark. Updates as the underlying
|
|
35
|
+
* transport receives frames. Persist this and pass back as
|
|
36
|
+
* `initialSequenceNum` on re-attach so the server resumes instead of
|
|
37
|
+
* replaying full history.
|
|
38
|
+
*/
|
|
39
|
+
getSequenceNum(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Worker epoch the current transport is writing as. Callers that
|
|
42
|
+
* reconnect for a token refresh (not a cold re-attach) pass this back
|
|
43
|
+
* via `reconnectTransport({epoch})` so the handle reuses the epoch
|
|
44
|
+
* instead of calling registerWorker again.
|
|
45
|
+
*/
|
|
46
|
+
getEpoch(): number | undefined;
|
|
47
|
+
/** True once the write path (CCRClient initialize) is ready. */
|
|
48
|
+
isConnected(): boolean;
|
|
49
|
+
/** Write a single SDKMessage. `session_id` is injected automatically. */
|
|
50
|
+
write(msg: SDKMessage): void;
|
|
51
|
+
/** Signal turn boundary — claude.ai stops the "working" spinner. */
|
|
52
|
+
sendResult(): void;
|
|
53
|
+
/** Forward a permission request (`can_use_tool`) to claude.ai. */
|
|
54
|
+
sendControlRequest(req: SDKControlRequest): void;
|
|
55
|
+
/** Forward a permission response back through the bridge. */
|
|
56
|
+
sendControlResponse(res: SDKControlResponse): void;
|
|
57
|
+
/**
|
|
58
|
+
* Tell claude.ai to dismiss a pending permission prompt (e.g. caller
|
|
59
|
+
* aborted the turn locally before the user answered).
|
|
60
|
+
*/
|
|
61
|
+
sendControlCancelRequest(requestId: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Swap the underlying transport in place with a fresh JWT (and epoch).
|
|
64
|
+
* Carries the SSE sequence number so the server resumes the stream.
|
|
65
|
+
* Call this when the poll loop re-dispatches work for the same session
|
|
66
|
+
* with a fresh secret (JWT is 4h; backend mints a new one every dispatch).
|
|
67
|
+
*
|
|
68
|
+
* Throws if `createV2ReplTransport` fails (registerWorker error, etc).
|
|
69
|
+
* Caller should treat that as a close and drop this handle.
|
|
70
|
+
*/
|
|
71
|
+
reconnectTransport(opts: {
|
|
72
|
+
ingressToken: string;
|
|
73
|
+
apiBaseUrl: string;
|
|
74
|
+
/** Omit to reuse the current transport's epoch (token-refresh reconnect); provide to override. */
|
|
75
|
+
epoch?: number;
|
|
76
|
+
}): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* PUT /worker state. Multi-session workers: `running` on turn start,
|
|
79
|
+
* `requires_action` on permission prompt, `idle` on turn end. Daemon
|
|
80
|
+
* callers don't need this — user watches the REPL locally.
|
|
81
|
+
*/
|
|
82
|
+
reportState(state: SessionState): void;
|
|
83
|
+
/** PUT /worker external_metadata (branch, dir shown on claude.ai). */
|
|
84
|
+
reportMetadata(metadata: Record<string, unknown>): void;
|
|
85
|
+
/**
|
|
86
|
+
* POST /worker/events/{id}/delivery. Populates CCR's processing_at /
|
|
87
|
+
* processed_at columns. `received` is auto-fired internally; this
|
|
88
|
+
* surfaces `processing` (turn start) and `processed` (turn end).
|
|
89
|
+
*/
|
|
90
|
+
reportDelivery(eventId: string, status: 'processing' | 'processed'): void;
|
|
91
|
+
/** Drain the write queue. Call before close() when delivery matters. */
|
|
92
|
+
flush(): Promise<void>;
|
|
93
|
+
close(): void;
|
|
94
|
+
};
|
|
95
|
+
/** @alpha */
|
|
96
|
+
export type AttachBridgeSessionOptions = {
|
|
97
|
+
/**
|
|
98
|
+
* Session ID (`cse_*` form). Comes from `WorkResponse.data.id` in the
|
|
99
|
+
* poll-loop path, or from whatever created the session.
|
|
100
|
+
*/
|
|
101
|
+
sessionId: string;
|
|
102
|
+
/** Worker JWT. Comes from `decodeWorkSecret(work.secret).session_ingress_token`. */
|
|
103
|
+
ingressToken: string;
|
|
104
|
+
/** `WorkSecret.api_base_url` or wherever the session ingress lives. */
|
|
105
|
+
apiBaseUrl: string;
|
|
106
|
+
/**
|
|
107
|
+
* Worker epoch if already known (e.g. from a `/bridge` call that bumps
|
|
108
|
+
* epoch server-side). Omit to have `createV2ReplTransport` call
|
|
109
|
+
* `registerWorker` itself — correct for poll-loop callers where the
|
|
110
|
+
* work secret doesn't carry epoch.
|
|
111
|
+
*/
|
|
112
|
+
epoch?: number;
|
|
113
|
+
/**
|
|
114
|
+
* SSE sequence-number high-water mark from a prior handle or persisted
|
|
115
|
+
* state. Seeds the first SSE connect's `from_sequence_num` so the server
|
|
116
|
+
* resumes instead of replaying full history. Omit (→ 0) for genuinely
|
|
117
|
+
* fresh attach.
|
|
118
|
+
*/
|
|
119
|
+
initialSequenceNum?: number;
|
|
120
|
+
/**
|
|
121
|
+
* CCRClient heartbeat interval seed. Defaults to 20s. The server-advised
|
|
122
|
+
* interval (ccr_heartbeat_policy) overrides this after the first heartbeat.
|
|
123
|
+
*/
|
|
124
|
+
heartbeatIntervalMs?: number;
|
|
125
|
+
/**
|
|
126
|
+
* When true, the bridge only forwards events outbound (local → CCR). The
|
|
127
|
+
* SSE read stream is not opened — no inbound events are received. Control
|
|
128
|
+
* requests that arrive via the write-path ACK channel reply with an error
|
|
129
|
+
* instead of false-success. onInboundMessage is never called. Use for
|
|
130
|
+
* mirror-mode attachments where the remote UI should see the session but
|
|
131
|
+
* not be able to drive it.
|
|
132
|
+
*/
|
|
133
|
+
outboundOnly?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* User message typed on claude.ai. Echoes of outbound writes and
|
|
136
|
+
* re-deliveries of prompts already forwarded are filtered before this
|
|
137
|
+
* fires. May be async (e.g. attachment resolution).
|
|
138
|
+
*/
|
|
139
|
+
onInboundMessage?: (msg: SDKMessage) => void | Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* `control_response` from claude.ai — the user answered a `can_use_tool`
|
|
142
|
+
* prompt sent via `sendControlRequest`. Caller correlates by `request_id`.
|
|
143
|
+
* Return `false` when the response is rejected (malformed/forged) so the
|
|
144
|
+
* prompt stays eligible for initialize re-delivery; void = accepted.
|
|
145
|
+
*/
|
|
146
|
+
onPermissionResponse?: (res: SDKControlResponse) => boolean | void;
|
|
147
|
+
/** `interrupt` control_request from claude.ai. Already auto-replied-to. */
|
|
148
|
+
onInterrupt?: () => void;
|
|
149
|
+
/**
|
|
150
|
+
* `stop_task` control_request from claude.ai — per-task Stop from the
|
|
151
|
+
* client's tasks panel. Resolve = stopped (hosts should treat a task the
|
|
152
|
+
* process no longer tracks or that already finished as stopped and
|
|
153
|
+
* resolve, so the client prunes the stale row — but NOT a live paused or
|
|
154
|
+
* pending task, nor an ambiguous name matching several live tasks: those
|
|
155
|
+
* should reject so the user sees an accurate
|
|
156
|
+
* refusal); reject = error control_response with the
|
|
157
|
+
* rejection's message. Omit if the host has no task registry — the CLI
|
|
158
|
+
* then answers with a "not supported in this context" error.
|
|
159
|
+
*/
|
|
160
|
+
onStopTask?: (taskId: string) => Promise<void>;
|
|
161
|
+
/**
|
|
162
|
+
* `background_tasks` from claude.ai — the client's Ctrl+B. With a
|
|
163
|
+
* toolUseId, background the single foreground task that tool_use block
|
|
164
|
+
* started and return whether one was found; without, background every
|
|
165
|
+
* foreground task and return true. May answer asynchronously (e.g. by
|
|
166
|
+
* delegating to `Query.backgroundTasks()`); a rejection is sent as an
|
|
167
|
+
* error reply. Omit if the host has no task registry — the CLI then
|
|
168
|
+
* answers with a "not supported in this context" error.
|
|
169
|
+
*/
|
|
170
|
+
onBackgroundTasks?: (toolUseId: string | undefined) => boolean | Promise<boolean>;
|
|
171
|
+
onSetModel?: (model: string | undefined) => {
|
|
172
|
+
ok: true;
|
|
173
|
+
notices?: string[];
|
|
174
|
+
} | {
|
|
175
|
+
ok: false;
|
|
176
|
+
error: string;
|
|
177
|
+
} | void | Promise<{
|
|
178
|
+
ok: true;
|
|
179
|
+
notices?: string[];
|
|
180
|
+
} | {
|
|
181
|
+
ok: false;
|
|
182
|
+
error: string;
|
|
183
|
+
}>;
|
|
184
|
+
onSetMaxThinkingTokens?: (tokens: number | null | undefined, thinkingDisplay?: 'summarized' | 'omitted' | null) => void;
|
|
185
|
+
/**
|
|
186
|
+
* `set_permission_mode` from claude.ai. Return an error verdict to send
|
|
187
|
+
* an error control_response (vs silently false-succeeding). Omit if
|
|
188
|
+
* the caller doesn't support permission modes — the shared handler
|
|
189
|
+
* returns a "not supported in this context" error.
|
|
190
|
+
*/
|
|
191
|
+
onSetPermissionMode?: (mode: PermissionMode) => {
|
|
192
|
+
ok: true;
|
|
193
|
+
} | {
|
|
194
|
+
ok: false;
|
|
195
|
+
error: string;
|
|
196
|
+
};
|
|
197
|
+
/** `rename_session` from claude.ai. Return an error verdict to reject. */
|
|
198
|
+
onRenameSession?: (title: string) => {
|
|
199
|
+
ok: true;
|
|
200
|
+
} | {
|
|
201
|
+
ok: false;
|
|
202
|
+
error: string;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Transport died permanently. 401 = JWT expired (re-attach with fresh
|
|
206
|
+
* secret), 4090 = epoch superseded (no longer the active worker),
|
|
207
|
+
* 4091 = CCRClient init failed, 4092 = codeless close (defensive
|
|
208
|
+
* fallback — cause unknown), 4093 = presence heartbeats kept failing
|
|
209
|
+
* while the SSE stream stayed healthy (transport self-heal candidate),
|
|
210
|
+
* 4094 = worker credential expired or rejected on the request path
|
|
211
|
+
* (heartbeat/write auth exhaustion — re-attach with a fresh secret,
|
|
212
|
+
* like 401), 403/404 = permanent SSE HTTP rejection. Transient
|
|
213
|
+
* disconnects (503, network blips) retry indefinitely inside
|
|
214
|
+
* SSETransport and do NOT fire this.
|
|
215
|
+
*/
|
|
216
|
+
onClose?: (code?: number) => void;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Attach to an existing bridge session. Creates the v2 transport
|
|
220
|
+
* (SSETransport + CCRClient), wires ingress routing and control dispatch,
|
|
221
|
+
* returns a handle scoped to this one session.
|
|
222
|
+
*
|
|
223
|
+
* Throws if `createV2ReplTransport` fails (registerWorker error, etc).
|
|
224
|
+
*
|
|
225
|
+
* ALPHA STABILITY. This is a separate versioning universe from the main
|
|
226
|
+
* `query()` surface: breaking changes here do NOT bump the package major.
|
|
227
|
+
* @alpha
|
|
228
|
+
*/
|
|
229
|
+
export declare function attachBridgeSession(opts: AttachBridgeSessionOptions): Promise<BridgeSessionHandle>;
|
|
230
|
+
/**
|
|
231
|
+
* Worker credentials from `POST /v1/code/sessions/{id}/bridge`.
|
|
232
|
+
* Each call bumps `worker_epoch` server-side — the call IS the worker register.
|
|
233
|
+
* @alpha
|
|
234
|
+
*/
|
|
235
|
+
export type RemoteCredentials = {
|
|
236
|
+
worker_jwt: string;
|
|
237
|
+
api_base_url: string;
|
|
238
|
+
expires_in: number;
|
|
239
|
+
worker_epoch: number;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* Terminal failure from `fetchRemoteCredentials` — retrying with the same
|
|
243
|
+
* inputs is guaranteed to fail. Server-minted reasons arrive as 403 with
|
|
244
|
+
* `error.resource` set to `"untrusted_device"` (token missing/revoked —
|
|
245
|
+
* enroll) or `"session_stale_relogin"` (OAuth session older than the
|
|
246
|
+
* freshness window — re-authenticate). `"invalid_session_id"` is
|
|
247
|
+
* client-minted: the session id failed validation (`/^[a-zA-Z0-9_-]+$/`)
|
|
248
|
+
* before any request was sent. `"request_rejected"` is any other
|
|
249
|
+
* authoritative non-retryable 4xx (the server answered; neither time nor a
|
|
250
|
+
* new credential changes the request). `"malformed_response"` is a 2xx this
|
|
251
|
+
* client could not parse — the mint SUCCEEDED server-side (each call bumps
|
|
252
|
+
* `worker_epoch`), so retrying epoch-bumps per attempt; not transient, not
|
|
253
|
+
* an authoritative denial.
|
|
254
|
+
* @alpha
|
|
255
|
+
*/
|
|
256
|
+
export type CredentialsFailure = {
|
|
257
|
+
terminal: true;
|
|
258
|
+
reason: 'untrusted_device' | 'session_stale_relogin' | 'invalid_session_id';
|
|
259
|
+
} | {
|
|
260
|
+
terminal: true;
|
|
261
|
+
reason: 'request_rejected';
|
|
262
|
+
/** HTTP status, for the debug trail and user-facing hints. */
|
|
263
|
+
status: number;
|
|
264
|
+
/**
|
|
265
|
+
* 403 only: who wrote the rejection, from response headers — the
|
|
266
|
+
* origin (`request-id: req_…`), a Cloudflare edge before it, or a hop
|
|
267
|
+
* that never reached Anthropic. Attribution for telemetry/copy; not a
|
|
268
|
+
* verdict on ownership.
|
|
269
|
+
*/
|
|
270
|
+
source?: 'origin' | 'nonorigin_cf' | 'nonorigin_other';
|
|
271
|
+
} | {
|
|
272
|
+
terminal: true;
|
|
273
|
+
reason: 'malformed_response';
|
|
274
|
+
/** HTTP status, for the debug trail and user-facing hints. */
|
|
275
|
+
status: number;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Non-terminal classified rejection: the OAuth bearer itself was rejected
|
|
279
|
+
* (401). Retrying with the SAME credential is pointless, but a DIFFERENT
|
|
280
|
+
* credential can succeed (post-re-authentication) — distinct from
|
|
281
|
+
* `CredentialsFailure` (`terminal: true`) and from null, which is reserved
|
|
282
|
+
* for transient transport-shaped failures (network error / timeout / 5xx).
|
|
283
|
+
* @alpha
|
|
284
|
+
*/
|
|
285
|
+
export type CredentialsRejection = {
|
|
286
|
+
terminal: false;
|
|
287
|
+
reason: 'oauth_rejected';
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Type guard for `fetchRemoteCredentials` results.
|
|
291
|
+
* @alpha
|
|
292
|
+
*/
|
|
293
|
+
export declare function isCredentialsFailure(r: RemoteCredentials | CredentialsFailure | CredentialsRejection | null): r is CredentialsFailure;
|
|
294
|
+
/**
|
|
295
|
+
* Type guard for the non-terminal classified 401 rejection. Accepts
|
|
296
|
+
* `unknown`: callers hand it unions whose success arm is a plain string
|
|
297
|
+
* (session ids), and it narrows structurally.
|
|
298
|
+
* @alpha
|
|
299
|
+
*/
|
|
300
|
+
export declare function isCredentialsRejection(r: unknown): r is CredentialsRejection;
|
|
301
|
+
/**
|
|
302
|
+
* Git source/outcome context attached to a v2 code session on create.
|
|
303
|
+
* @alpha
|
|
304
|
+
*/
|
|
305
|
+
export type CodeSessionGitContext = {
|
|
306
|
+
gitRepoUrl: string;
|
|
307
|
+
branch: string;
|
|
308
|
+
/**
|
|
309
|
+
* The repo's default branch, when authoritatively known. LOAD-BEARING
|
|
310
|
+
* for branch continuity: when absent, `branch` is omitted from
|
|
311
|
+
* `outcomes.branches` entirely (the classification never acts on a
|
|
312
|
+
* guess), so the remote session works on a runner-generated branch
|
|
313
|
+
* instead of `branch`, with only a debug-level signal. Callers that
|
|
314
|
+
* want the session to check out AND push to `branch` must supply
|
|
315
|
+
* this — read `git symbolic-ref refs/remotes/origin/HEAD`, or run
|
|
316
|
+
* `git remote set-head origin -a` to repair a missing symref.
|
|
317
|
+
*/
|
|
318
|
+
defaultBranch?: string;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* Caller-owned dedupe state for createCodeSession's branch-drop debug
|
|
322
|
+
* signal: create one object per logical create (outside your retry
|
|
323
|
+
* loop) and pass it to every attempt so the drop logs once per
|
|
324
|
+
* decision. Omit it to log on every attempt.
|
|
325
|
+
* @alpha
|
|
326
|
+
*/
|
|
327
|
+
export declare type BranchDropLogDedup = {
|
|
328
|
+
lastKey?: string | null;
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* Terminal failure from `POST /v1/code/sessions` — retrying with the same
|
|
332
|
+
* inputs fails identically. `reason` distinguishes the recognized
|
|
333
|
+
* `session_grouping_id` rejection family (`"grouping_rejected"` — the
|
|
334
|
+
* caller may retry without the grouping) from any other authoritative
|
|
335
|
+
* non-retryable 4xx (`"request_rejected"`) and from a 2xx this client
|
|
336
|
+
* could not parse (`"malformed_response"` — the create SUCCEEDED
|
|
337
|
+
* server-side, so a retry would orphan one session per attempt).
|
|
338
|
+
* @alpha
|
|
339
|
+
*/
|
|
340
|
+
export type CreateSessionFailure = {
|
|
341
|
+
terminal: true;
|
|
342
|
+
reason: 'grouping_rejected' | 'request_rejected' | 'malformed_response';
|
|
343
|
+
status: number;
|
|
344
|
+
detail: string | undefined;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Type guard for `createCodeSession` results. Matches only `terminal: true`
|
|
348
|
+
* failures — a `CredentialsRejection` (`terminal: false`) does not match.
|
|
349
|
+
* @alpha
|
|
350
|
+
*/
|
|
351
|
+
export declare function isCreateSessionFailure(r: string | CreateSessionFailure | CredentialsRejection | null): r is CreateSessionFailure;
|
|
352
|
+
/**
|
|
353
|
+
* `POST /v1/code/sessions` — create a fresh CCR session. Returns the `cse_*`
|
|
354
|
+
* session id on success, a classified `CreateSessionFailure` (terminal —
|
|
355
|
+
* don't retry; see its `reason`), a `CredentialsRejection` when the OAuth
|
|
356
|
+
* bearer was rejected (retry only with a NEW credential), or null on
|
|
357
|
+
* transient transport-shaped failures (network error / timeout / 5xx).
|
|
358
|
+
*
|
|
359
|
+
* Callers supply their own OAuth token — this is a thin HTTP wrapper with no
|
|
360
|
+
* implicit auth, so it works from any process (not just the CLI).
|
|
361
|
+
* @alpha
|
|
362
|
+
*/
|
|
363
|
+
export declare function createCodeSession(baseUrl: string, accessToken: string, title: string, timeoutMs: number, tags?: string[], gitContext?: CodeSessionGitContext, cwd?: string, model?: string, sessionGroupingId?: string, dropLogDedup?: BranchDropLogDedup): Promise<string | CreateSessionFailure | CredentialsRejection | null>;
|
|
364
|
+
/**
|
|
365
|
+
* `POST /v1/code/sessions/{id}/bridge` — mint a worker JWT for the session.
|
|
366
|
+
* Returns credentials, a `CredentialsFailure` for terminal failures (don't
|
|
367
|
+
* retry — see `CredentialsFailure.reason` for remediation), a
|
|
368
|
+
* `CredentialsRejection` when the OAuth bearer was rejected (retry only
|
|
369
|
+
* with a NEW credential), or null on transient transport-shaped failure. The call IS the worker register (bumps epoch
|
|
370
|
+
* server-side), so pass `epoch: creds.worker_epoch` to `attachBridgeSession`
|
|
371
|
+
* to skip a redundant register.
|
|
372
|
+
*
|
|
373
|
+
* `trustedDeviceToken` sets the `X-Trusted-Device-Token` header. Required
|
|
374
|
+
* when the server's `sessions_elevated_auth_enforcement` flag is on
|
|
375
|
+
* (bridge sessions are SecurityTier=ELEVATED). See anthropics/anthropic#274559.
|
|
376
|
+
* @alpha
|
|
377
|
+
*/
|
|
378
|
+
export declare function fetchRemoteCredentials(sessionId: string, baseUrl: string, accessToken: string, timeoutMs: number, trustedDeviceToken?: string): Promise<RemoteCredentials | CredentialsFailure | CredentialsRejection | null>;
|