@anthropic-ai/claude-agent-sdk 0.3.224 → 0.3.226

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/bridge.d.ts CHANGED
@@ -212,18 +212,47 @@ export type RemoteCredentials = {
212
212
  * enroll) or `"session_stale_relogin"` (OAuth session older than the
213
213
  * freshness window — re-authenticate). `"invalid_session_id"` is
214
214
  * client-minted: the session id failed validation (`/^[a-zA-Z0-9_-]+$/`)
215
- * before any request was sent.
215
+ * before any request was sent. `"request_rejected"` is any other
216
+ * authoritative non-retryable 4xx (the server answered; neither time nor a
217
+ * new credential changes the request). `"malformed_response"` is a 2xx this
218
+ * client could not parse — the mint SUCCEEDED server-side (each call bumps
219
+ * `worker_epoch`), so retrying epoch-bumps per attempt; not transient, not
220
+ * an authoritative denial.
216
221
  * @alpha
217
222
  */
218
223
  export type CredentialsFailure = {
219
224
  terminal: true;
220
225
  reason: 'untrusted_device' | 'session_stale_relogin' | 'invalid_session_id';
226
+ } | {
227
+ terminal: true;
228
+ reason: 'request_rejected' | 'malformed_response';
229
+ /** HTTP status, for the debug trail and user-facing hints. */
230
+ status: number;
231
+ };
232
+ /**
233
+ * Non-terminal classified rejection: the OAuth bearer itself was rejected
234
+ * (401). Retrying with the SAME credential is pointless, but a DIFFERENT
235
+ * credential can succeed (post-re-authentication) — distinct from
236
+ * `CredentialsFailure` (`terminal: true`) and from null, which is reserved
237
+ * for transient transport-shaped failures (network error / timeout / 5xx).
238
+ * @alpha
239
+ */
240
+ export type CredentialsRejection = {
241
+ terminal: false;
242
+ reason: 'oauth_rejected';
221
243
  };
222
244
  /**
223
245
  * Type guard for `fetchRemoteCredentials` results.
224
246
  * @alpha
225
247
  */
226
- export declare function isCredentialsFailure(r: RemoteCredentials | CredentialsFailure | null): r is CredentialsFailure;
248
+ export declare function isCredentialsFailure(r: RemoteCredentials | CredentialsFailure | CredentialsRejection | null): r is CredentialsFailure;
249
+ /**
250
+ * Type guard for the non-terminal classified 401 rejection. Accepts
251
+ * `unknown`: callers hand it unions whose success arm is a plain string
252
+ * (session ids), and it narrows structurally.
253
+ * @alpha
254
+ */
255
+ export declare function isCredentialsRejection(r: unknown): r is CredentialsRejection;
227
256
  /**
228
257
  * Git source/outcome context attached to a v2 code session on create.
229
258
  * @alpha
@@ -254,13 +283,18 @@ export declare type BranchDropLogDedup = {
254
283
  lastKey?: string | null;
255
284
  };
256
285
  /**
257
- * Terminal 4xx from `POST /v1/code/sessions` for a recognized
258
- * `session_grouping_id` rejection retrying with the same inputs fails
259
- * identically.
286
+ * Terminal failure from `POST /v1/code/sessions` retrying with the same
287
+ * inputs fails identically. `reason` distinguishes the recognized
288
+ * `session_grouping_id` rejection family (`"grouping_rejected"` — the
289
+ * caller may retry without the grouping) from any other authoritative
290
+ * non-retryable 4xx (`"request_rejected"`) and from a 2xx this client
291
+ * could not parse (`"malformed_response"` — the create SUCCEEDED
292
+ * server-side, so a retry would orphan one session per attempt).
260
293
  * @alpha
261
294
  */
262
295
  export type CreateSessionFailure = {
263
296
  terminal: true;
297
+ reason: 'grouping_rejected' | 'request_rejected' | 'malformed_response';
264
298
  status: number;
265
299
  detail: string | undefined;
266
300
  };
@@ -268,23 +302,25 @@ export type CreateSessionFailure = {
268
302
  * Type guard for `createCodeSession` results.
269
303
  * @alpha
270
304
  */
271
- export declare function isCreateSessionFailure(r: string | CreateSessionFailure | null): r is CreateSessionFailure;
305
+ export declare function isCreateSessionFailure(r: string | CreateSessionFailure | CredentialsRejection | null): r is CreateSessionFailure;
272
306
  /**
273
307
  * `POST /v1/code/sessions` — create a fresh CCR session. Returns the `cse_*`
274
- * session id on success, a `CreateSessionFailure` for a recognized
275
- * `session_grouping_id` rejection (terminal — don't retry), or null on any
276
- * other failure (HTTP error, malformed response).
308
+ * session id on success, a classified `CreateSessionFailure` (terminal
309
+ * don't retry; see its `reason`), a `CredentialsRejection` when the OAuth
310
+ * bearer was rejected (retry only with a NEW credential), or null on
311
+ * transient transport-shaped failures (network error / timeout / 5xx).
277
312
  *
278
313
  * Callers supply their own OAuth token — this is a thin HTTP wrapper with no
279
314
  * implicit auth, so it works from any process (not just the CLI).
280
315
  * @alpha
281
316
  */
282
- 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 | null>;
317
+ 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>;
283
318
  /**
284
319
  * `POST /v1/code/sessions/{id}/bridge` — mint a worker JWT for the session.
285
- * Returns credentials, a `CredentialsFailure` for terminal authz failures
286
- * (don't retry — see `CredentialsFailure.reason` for remediation), or null
287
- * on transient failure. The call IS the worker register (bumps epoch
320
+ * Returns credentials, a `CredentialsFailure` for terminal failures (don't
321
+ * retry — see `CredentialsFailure.reason` for remediation), a
322
+ * `CredentialsRejection` when the OAuth bearer was rejected (retry only
323
+ * with a NEW credential), or null on transient transport-shaped failure. The call IS the worker register (bumps epoch
288
324
  * server-side), so pass `epoch: creds.worker_epoch` to `attachBridgeSession`
289
325
  * to skip a redundant register.
290
326
  *
@@ -293,4 +329,4 @@ export declare function createCodeSession(baseUrl: string, accessToken: string,
293
329
  * (bridge sessions are SecurityTier=ELEVATED). See anthropics/anthropic#274559.
294
330
  * @alpha
295
331
  */
296
- export declare function fetchRemoteCredentials(sessionId: string, baseUrl: string, accessToken: string, timeoutMs: number, trustedDeviceToken?: string): Promise<RemoteCredentials | CredentialsFailure | null>;
332
+ export declare function fetchRemoteCredentials(sessionId: string, baseUrl: string, accessToken: string, timeoutMs: number, trustedDeviceToken?: string): Promise<RemoteCredentials | CredentialsFailure | CredentialsRejection | null>;