@tormentalabs/claude-code-wire-compat 0.1.0-rc.16 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +132 -1
- package/README.md +53 -1
- package/dist/build-request.d.ts.map +1 -1
- package/dist/build-request.js +164 -26
- package/dist/build-request.js.map +1 -1
- package/dist/contracts.d.ts +103 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js.map +1 -1
- package/dist/redaction.d.ts +11 -0
- package/dist/redaction.d.ts.map +1 -1
- package/dist/redaction.js +11 -0
- package/dist/redaction.js.map +1 -1
- package/dist/request-body.d.ts.map +1 -1
- package/dist/request-body.js +74 -19
- package/dist/request-body.js.map +1 -1
- package/dist/system-prompt.d.ts +12 -5
- package/dist/system-prompt.d.ts.map +1 -1
- package/dist/system-prompt.js +29 -13
- package/dist/system-prompt.js.map +1 -1
- package/package.json +2 -1
- package/src/anti-verbosity.ts +219 -0
- package/src/beta-registry.ts +140 -0
- package/src/betas.ts +219 -0
- package/src/build-request.ts +1655 -0
- package/src/contracts.ts +1233 -0
- package/src/count-tokens.ts +84 -0
- package/src/fingerprint.ts +85 -0
- package/src/headers.ts +442 -0
- package/src/index.ts +62 -0
- package/src/metadata.ts +331 -0
- package/src/model-capabilities.ts +295 -0
- package/src/model-identity.ts +45 -0
- package/src/models.ts +46 -0
- package/src/profiles/claude-code-2.1.195.ts +154 -0
- package/src/redaction.ts +521 -0
- package/src/request-body.ts +1924 -0
- package/src/sha256.ts +114 -0
- package/src/system-prompt.ts +222 -0
- package/src/thinking.ts +266 -0
- package/src/unicode.ts +24 -0
package/src/contracts.ts
ADDED
|
@@ -0,0 +1,1233 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
|
|
3
|
+
import type { ThinkingDisplay } from "./thinking.js";
|
|
4
|
+
export type { ThinkingDisplay } from "./thinking.js";
|
|
5
|
+
|
|
6
|
+
/** Model families used only in redacted evidence, never on the wire. */
|
|
7
|
+
export type ClaudeCodeModelFamily =
|
|
8
|
+
"haiku" | "sonnet" | "opus" | "fable" | "mythos" | "unknown";
|
|
9
|
+
|
|
10
|
+
export type ClaudeCodeEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
11
|
+
|
|
12
|
+
/** Identifies which branch of the client's anti-verbosity selector applies. */
|
|
13
|
+
export type AntiVerbositySection =
|
|
14
|
+
"communicating-with-the-user" | "lean" | "text-output";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Host state the package cannot observe, mirrored from the upstream gates so a
|
|
18
|
+
* caller that does know it can reproduce the client exactly.
|
|
19
|
+
*/
|
|
20
|
+
export interface AntiVerbosityPolicy {
|
|
21
|
+
/** Upstream `oqo.isBriefEnabled()`. */
|
|
22
|
+
readonly briefModeEnabled: boolean;
|
|
23
|
+
/** Upstream `Jxe()`, the pewter-owl tool flag. */
|
|
24
|
+
readonly pewterOwlToolEnabled: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ClaudeCodeCatalogueEntry {
|
|
28
|
+
readonly family: ClaudeCodeModelFamily;
|
|
29
|
+
readonly context?: Readonly<{
|
|
30
|
+
readonly window: number;
|
|
31
|
+
readonly native1m?: boolean;
|
|
32
|
+
readonly supports1mBeta?: boolean;
|
|
33
|
+
}>;
|
|
34
|
+
/** Verbatim upstream capability keys; compared by the ported predicates. */
|
|
35
|
+
readonly capabilities: readonly string[];
|
|
36
|
+
readonly defaultEffort?: ClaudeCodeEffort;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type HeaderPair = readonly [name: string, value: string];
|
|
40
|
+
|
|
41
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
42
|
+
export type JsonValue =
|
|
43
|
+
JsonPrimitive | readonly JsonValue[] | { readonly [key: string]: JsonValue };
|
|
44
|
+
|
|
45
|
+
export interface CacheControlEphemeral {
|
|
46
|
+
readonly type: "ephemeral";
|
|
47
|
+
readonly ttl?: "5m" | "1h";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Pre-RC3 package compatibility extension; SDK-derived block types do not use it. */
|
|
51
|
+
export interface TextBlockCacheControl extends CacheControlEphemeral {
|
|
52
|
+
readonly scope?: "global";
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface CitationsConfigParam {
|
|
56
|
+
readonly enabled?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface CitationCharLocationParam {
|
|
60
|
+
readonly cited_text: string;
|
|
61
|
+
readonly document_index: number;
|
|
62
|
+
readonly document_title: string | null;
|
|
63
|
+
readonly end_char_index: number;
|
|
64
|
+
readonly start_char_index: number;
|
|
65
|
+
readonly type: "char_location";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface CitationContentBlockLocationParam {
|
|
69
|
+
readonly cited_text: string;
|
|
70
|
+
readonly document_index: number;
|
|
71
|
+
readonly document_title: string | null;
|
|
72
|
+
readonly end_block_index: number;
|
|
73
|
+
readonly start_block_index: number;
|
|
74
|
+
readonly type: "content_block_location";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface CitationPageLocationParam {
|
|
78
|
+
readonly cited_text: string;
|
|
79
|
+
readonly document_index: number;
|
|
80
|
+
readonly document_title: string | null;
|
|
81
|
+
readonly end_page_number: number;
|
|
82
|
+
readonly start_page_number: number;
|
|
83
|
+
readonly type: "page_location";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface CitationSearchResultLocationParam {
|
|
87
|
+
readonly cited_text: string;
|
|
88
|
+
readonly end_block_index: number;
|
|
89
|
+
readonly search_result_index: number;
|
|
90
|
+
readonly source: string;
|
|
91
|
+
readonly start_block_index: number;
|
|
92
|
+
readonly title: string | null;
|
|
93
|
+
readonly type: "search_result_location";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface CitationWebSearchResultLocationParam {
|
|
97
|
+
readonly cited_text: string;
|
|
98
|
+
readonly encrypted_index: string;
|
|
99
|
+
readonly title: string | null;
|
|
100
|
+
readonly type: "web_search_result_location";
|
|
101
|
+
readonly url: string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export type TextCitationParam =
|
|
105
|
+
| CitationCharLocationParam
|
|
106
|
+
| CitationPageLocationParam
|
|
107
|
+
| CitationContentBlockLocationParam
|
|
108
|
+
| CitationWebSearchResultLocationParam
|
|
109
|
+
| CitationSearchResultLocationParam;
|
|
110
|
+
|
|
111
|
+
export interface TextBlock {
|
|
112
|
+
readonly text: string;
|
|
113
|
+
readonly type: "text";
|
|
114
|
+
readonly cache_control?: TextBlockCacheControl | null;
|
|
115
|
+
readonly citations?: readonly TextCitationParam[] | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface Base64ImageSource {
|
|
119
|
+
readonly data: string;
|
|
120
|
+
readonly media_type: "image/jpeg" | "image/png" | "image/gif" | "image/webp";
|
|
121
|
+
readonly type: "base64";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface FileImageSource {
|
|
125
|
+
readonly file_id: string;
|
|
126
|
+
readonly type: "file";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface URLImageSource {
|
|
130
|
+
readonly type: "url";
|
|
131
|
+
readonly url: string;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface ImageBlock {
|
|
135
|
+
readonly source: Base64ImageSource | URLImageSource | FileImageSource;
|
|
136
|
+
readonly type: "image";
|
|
137
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface Base64PDFSource {
|
|
141
|
+
readonly data: string;
|
|
142
|
+
readonly media_type: "application/pdf";
|
|
143
|
+
readonly type: "base64";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface ContentBlockSource {
|
|
147
|
+
readonly content: string | readonly (TextBlock | ImageBlock)[];
|
|
148
|
+
readonly type: "content";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface FileDocumentSource {
|
|
152
|
+
readonly file_id: string;
|
|
153
|
+
readonly type: "file";
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface PlainTextSource {
|
|
157
|
+
readonly data: string;
|
|
158
|
+
readonly media_type: "text/plain";
|
|
159
|
+
readonly type: "text";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface URLPDFSource {
|
|
163
|
+
readonly type: "url";
|
|
164
|
+
readonly url: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface DocumentBlock {
|
|
168
|
+
readonly source:
|
|
169
|
+
| Base64PDFSource
|
|
170
|
+
| PlainTextSource
|
|
171
|
+
| ContentBlockSource
|
|
172
|
+
| URLPDFSource
|
|
173
|
+
| FileDocumentSource;
|
|
174
|
+
readonly type: "document";
|
|
175
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
176
|
+
readonly citations?: CitationsConfigParam | null;
|
|
177
|
+
readonly context?: string | null;
|
|
178
|
+
readonly title?: string | null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface ThinkingBlock {
|
|
182
|
+
readonly signature: string;
|
|
183
|
+
readonly thinking: string;
|
|
184
|
+
readonly type: "thinking";
|
|
185
|
+
/**
|
|
186
|
+
* Accepted ONLY when `ClaudeCodeRequestInput.preserveThinkingBlockCacheControl`
|
|
187
|
+
* is `true`; otherwise the key is rejected with `INVALID_INPUT`. When
|
|
188
|
+
* accepted it is copied to the body verbatim. See that field's JSDoc for the
|
|
189
|
+
* 400 this exists to avoid.
|
|
190
|
+
*/
|
|
191
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface RedactedThinkingBlock {
|
|
195
|
+
readonly data: string;
|
|
196
|
+
readonly type: "redacted_thinking";
|
|
197
|
+
/** Same seam-gated key as `ThinkingBlock.cache_control`. */
|
|
198
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface SearchResultBlock {
|
|
202
|
+
readonly content: readonly TextBlock[];
|
|
203
|
+
readonly source: string;
|
|
204
|
+
readonly title: string;
|
|
205
|
+
readonly type: "search_result";
|
|
206
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
207
|
+
readonly citations?: CitationsConfigParam;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface ToolReferenceBlock {
|
|
211
|
+
readonly tool_name: string;
|
|
212
|
+
readonly type: "tool_reference";
|
|
213
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface DirectCaller {
|
|
217
|
+
readonly type: "direct";
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export interface ServerToolCaller {
|
|
221
|
+
readonly tool_id: string;
|
|
222
|
+
readonly type: "code_execution_20250825";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface ServerToolCaller20260120 {
|
|
226
|
+
readonly tool_id: string;
|
|
227
|
+
readonly type: "code_execution_20260120";
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface ToolUseBlock {
|
|
231
|
+
readonly id: string;
|
|
232
|
+
readonly input: JsonValue;
|
|
233
|
+
readonly name: string;
|
|
234
|
+
readonly type: "tool_use";
|
|
235
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
236
|
+
readonly caller?: DirectCaller | ServerToolCaller | ServerToolCaller20260120;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export type ToolResultContentBlock =
|
|
240
|
+
| TextBlock
|
|
241
|
+
| ImageBlock
|
|
242
|
+
| SearchResultBlock
|
|
243
|
+
| DocumentBlock
|
|
244
|
+
| ToolReferenceBlock;
|
|
245
|
+
|
|
246
|
+
export interface ToolResultBlock {
|
|
247
|
+
readonly tool_use_id: string;
|
|
248
|
+
readonly type: "tool_result";
|
|
249
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
250
|
+
readonly content?: string | readonly ToolResultContentBlock[];
|
|
251
|
+
readonly is_error?: boolean;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export type MessageContentBlock =
|
|
255
|
+
| TextBlock
|
|
256
|
+
| ImageBlock
|
|
257
|
+
| DocumentBlock
|
|
258
|
+
| SearchResultBlock
|
|
259
|
+
| ThinkingBlock
|
|
260
|
+
| RedactedThinkingBlock
|
|
261
|
+
| ToolUseBlock
|
|
262
|
+
| ToolResultBlock;
|
|
263
|
+
|
|
264
|
+
export type MessageContent = string | readonly MessageContentBlock[];
|
|
265
|
+
export interface Message {
|
|
266
|
+
readonly role: "user" | "assistant";
|
|
267
|
+
readonly content: MessageContent;
|
|
268
|
+
}
|
|
269
|
+
export type SystemInput = string | TextBlock;
|
|
270
|
+
|
|
271
|
+
export interface ToolInputSchema {
|
|
272
|
+
readonly type: "object";
|
|
273
|
+
readonly properties?: JsonValue | null;
|
|
274
|
+
readonly required?: readonly string[] | null;
|
|
275
|
+
readonly [key: string]: JsonValue | undefined;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type ToolAllowedCaller =
|
|
279
|
+
"direct" | "code_execution_20250825" | "code_execution_20260120";
|
|
280
|
+
|
|
281
|
+
export type ToolInputExample = Readonly<Record<string, JsonValue>>;
|
|
282
|
+
|
|
283
|
+
export interface CustomToolDefinition {
|
|
284
|
+
readonly input_schema: ToolInputSchema;
|
|
285
|
+
readonly name: string;
|
|
286
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
287
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
288
|
+
readonly defer_loading?: boolean;
|
|
289
|
+
readonly description?: string;
|
|
290
|
+
readonly eager_input_streaming?: boolean | null;
|
|
291
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
292
|
+
readonly strict?: boolean;
|
|
293
|
+
readonly type?: never;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface ToolBash20241022 {
|
|
297
|
+
readonly name: "bash";
|
|
298
|
+
readonly type: "bash_20241022";
|
|
299
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
300
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
301
|
+
readonly defer_loading?: boolean;
|
|
302
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
303
|
+
readonly strict?: boolean;
|
|
304
|
+
}
|
|
305
|
+
export interface ToolBash20250124 {
|
|
306
|
+
readonly name: "bash";
|
|
307
|
+
readonly type: "bash_20250124";
|
|
308
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
309
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
310
|
+
readonly defer_loading?: boolean;
|
|
311
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
312
|
+
readonly strict?: boolean;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface CodeExecutionTool20250522 {
|
|
316
|
+
readonly name: "code_execution";
|
|
317
|
+
readonly type: "code_execution_20250522";
|
|
318
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
319
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
320
|
+
readonly defer_loading?: boolean;
|
|
321
|
+
readonly strict?: boolean;
|
|
322
|
+
}
|
|
323
|
+
export interface CodeExecutionTool20250825 {
|
|
324
|
+
readonly name: "code_execution";
|
|
325
|
+
readonly type: "code_execution_20250825";
|
|
326
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
327
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
328
|
+
readonly defer_loading?: boolean;
|
|
329
|
+
readonly strict?: boolean;
|
|
330
|
+
}
|
|
331
|
+
export interface CodeExecutionTool20260120 {
|
|
332
|
+
readonly name: "code_execution";
|
|
333
|
+
readonly type: "code_execution_20260120";
|
|
334
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
335
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
336
|
+
readonly defer_loading?: boolean;
|
|
337
|
+
readonly strict?: boolean;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface ToolComputerUse20241022 {
|
|
341
|
+
readonly display_height_px: number;
|
|
342
|
+
readonly display_width_px: number;
|
|
343
|
+
readonly name: "computer";
|
|
344
|
+
readonly type: "computer_20241022";
|
|
345
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
346
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
347
|
+
readonly defer_loading?: boolean;
|
|
348
|
+
readonly display_number?: number | null;
|
|
349
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
350
|
+
readonly strict?: boolean;
|
|
351
|
+
}
|
|
352
|
+
export interface ToolComputerUse20250124 {
|
|
353
|
+
readonly display_height_px: number;
|
|
354
|
+
readonly display_width_px: number;
|
|
355
|
+
readonly name: "computer";
|
|
356
|
+
readonly type: "computer_20250124";
|
|
357
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
358
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
359
|
+
readonly defer_loading?: boolean;
|
|
360
|
+
readonly display_number?: number | null;
|
|
361
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
362
|
+
readonly strict?: boolean;
|
|
363
|
+
}
|
|
364
|
+
export interface ToolComputerUse20251124 {
|
|
365
|
+
readonly display_height_px: number;
|
|
366
|
+
readonly display_width_px: number;
|
|
367
|
+
readonly name: "computer";
|
|
368
|
+
readonly type: "computer_20251124";
|
|
369
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
370
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
371
|
+
readonly defer_loading?: boolean;
|
|
372
|
+
readonly display_number?: number | null;
|
|
373
|
+
readonly enable_zoom?: boolean;
|
|
374
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
375
|
+
readonly strict?: boolean;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export interface MemoryTool20250818 {
|
|
379
|
+
readonly name: "memory";
|
|
380
|
+
readonly type: "memory_20250818";
|
|
381
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
382
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
383
|
+
readonly defer_loading?: boolean;
|
|
384
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
385
|
+
readonly strict?: boolean;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export interface ToolTextEditor20241022 {
|
|
389
|
+
readonly name: "str_replace_editor";
|
|
390
|
+
readonly type: "text_editor_20241022";
|
|
391
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
392
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
393
|
+
readonly defer_loading?: boolean;
|
|
394
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
395
|
+
readonly strict?: boolean;
|
|
396
|
+
}
|
|
397
|
+
export interface ToolTextEditor20250124 {
|
|
398
|
+
readonly name: "str_replace_editor";
|
|
399
|
+
readonly type: "text_editor_20250124";
|
|
400
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
401
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
402
|
+
readonly defer_loading?: boolean;
|
|
403
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
404
|
+
readonly strict?: boolean;
|
|
405
|
+
}
|
|
406
|
+
export interface ToolTextEditor20250429 {
|
|
407
|
+
readonly name: "str_replace_based_edit_tool";
|
|
408
|
+
readonly type: "text_editor_20250429";
|
|
409
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
410
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
411
|
+
readonly defer_loading?: boolean;
|
|
412
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
413
|
+
readonly strict?: boolean;
|
|
414
|
+
}
|
|
415
|
+
export interface ToolTextEditor20250728 {
|
|
416
|
+
readonly name: "str_replace_based_edit_tool";
|
|
417
|
+
readonly type: "text_editor_20250728";
|
|
418
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
419
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
420
|
+
readonly defer_loading?: boolean;
|
|
421
|
+
readonly input_examples?: readonly ToolInputExample[];
|
|
422
|
+
readonly max_characters?: number | null;
|
|
423
|
+
readonly strict?: boolean;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export interface UserLocation {
|
|
427
|
+
readonly type: "approximate";
|
|
428
|
+
readonly city?: string | null;
|
|
429
|
+
readonly country?: string | null;
|
|
430
|
+
readonly region?: string | null;
|
|
431
|
+
readonly timezone?: string | null;
|
|
432
|
+
}
|
|
433
|
+
export interface WebSearchTool20250305 {
|
|
434
|
+
readonly name: "web_search";
|
|
435
|
+
readonly type: "web_search_20250305";
|
|
436
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
437
|
+
readonly allowed_domains?: readonly string[] | null;
|
|
438
|
+
readonly blocked_domains?: readonly string[] | null;
|
|
439
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
440
|
+
readonly defer_loading?: boolean;
|
|
441
|
+
readonly max_uses?: number | null;
|
|
442
|
+
readonly strict?: boolean;
|
|
443
|
+
readonly user_location?: UserLocation | null;
|
|
444
|
+
}
|
|
445
|
+
export interface WebSearchTool20260209 {
|
|
446
|
+
readonly name: "web_search";
|
|
447
|
+
readonly type: "web_search_20260209";
|
|
448
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
449
|
+
readonly allowed_domains?: readonly string[] | null;
|
|
450
|
+
readonly blocked_domains?: readonly string[] | null;
|
|
451
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
452
|
+
readonly defer_loading?: boolean;
|
|
453
|
+
readonly max_uses?: number | null;
|
|
454
|
+
readonly strict?: boolean;
|
|
455
|
+
readonly user_location?: UserLocation | null;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface WebFetchTool20250910 {
|
|
459
|
+
readonly name: "web_fetch";
|
|
460
|
+
readonly type: "web_fetch_20250910";
|
|
461
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
462
|
+
readonly allowed_domains?: readonly string[] | null;
|
|
463
|
+
readonly blocked_domains?: readonly string[] | null;
|
|
464
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
465
|
+
readonly citations?: CitationsConfigParam | null;
|
|
466
|
+
readonly defer_loading?: boolean;
|
|
467
|
+
readonly max_content_tokens?: number | null;
|
|
468
|
+
readonly max_uses?: number | null;
|
|
469
|
+
readonly strict?: boolean;
|
|
470
|
+
}
|
|
471
|
+
export interface WebFetchTool20260209 {
|
|
472
|
+
readonly name: "web_fetch";
|
|
473
|
+
readonly type: "web_fetch_20260209";
|
|
474
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
475
|
+
readonly allowed_domains?: readonly string[] | null;
|
|
476
|
+
readonly blocked_domains?: readonly string[] | null;
|
|
477
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
478
|
+
readonly citations?: CitationsConfigParam | null;
|
|
479
|
+
readonly defer_loading?: boolean;
|
|
480
|
+
readonly max_content_tokens?: number | null;
|
|
481
|
+
readonly max_uses?: number | null;
|
|
482
|
+
readonly strict?: boolean;
|
|
483
|
+
}
|
|
484
|
+
export interface WebFetchTool20260309 {
|
|
485
|
+
readonly name: "web_fetch";
|
|
486
|
+
readonly type: "web_fetch_20260309";
|
|
487
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
488
|
+
readonly allowed_domains?: readonly string[] | null;
|
|
489
|
+
readonly blocked_domains?: readonly string[] | null;
|
|
490
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
491
|
+
readonly citations?: CitationsConfigParam | null;
|
|
492
|
+
readonly defer_loading?: boolean;
|
|
493
|
+
readonly max_content_tokens?: number | null;
|
|
494
|
+
readonly max_uses?: number | null;
|
|
495
|
+
readonly strict?: boolean;
|
|
496
|
+
readonly use_cache?: boolean;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface AdvisorTool20260301 {
|
|
500
|
+
readonly model: string;
|
|
501
|
+
readonly name: "advisor";
|
|
502
|
+
readonly type: "advisor_20260301";
|
|
503
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
504
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
505
|
+
readonly caching?: CacheControlEphemeral | null;
|
|
506
|
+
readonly defer_loading?: boolean;
|
|
507
|
+
readonly max_uses?: number | null;
|
|
508
|
+
readonly strict?: boolean;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
export interface ToolSearchToolBm25_20251119 {
|
|
512
|
+
readonly name: "tool_search_tool_bm25";
|
|
513
|
+
readonly type: "tool_search_tool_bm25_20251119" | "tool_search_tool_bm25";
|
|
514
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
515
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
516
|
+
readonly defer_loading?: boolean;
|
|
517
|
+
readonly strict?: boolean;
|
|
518
|
+
}
|
|
519
|
+
export interface ToolSearchToolRegex20251119 {
|
|
520
|
+
readonly name: "tool_search_tool_regex";
|
|
521
|
+
readonly type: "tool_search_tool_regex_20251119" | "tool_search_tool_regex";
|
|
522
|
+
readonly allowed_callers?: readonly ToolAllowedCaller[];
|
|
523
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
524
|
+
readonly defer_loading?: boolean;
|
|
525
|
+
readonly strict?: boolean;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export interface MCPToolConfig {
|
|
529
|
+
readonly defer_loading?: boolean;
|
|
530
|
+
readonly enabled?: boolean;
|
|
531
|
+
}
|
|
532
|
+
export interface MCPToolDefaultConfig {
|
|
533
|
+
readonly defer_loading?: boolean;
|
|
534
|
+
readonly enabled?: boolean;
|
|
535
|
+
}
|
|
536
|
+
export interface MCPToolset {
|
|
537
|
+
readonly mcp_server_name: string;
|
|
538
|
+
readonly type: "mcp_toolset";
|
|
539
|
+
readonly cache_control?: CacheControlEphemeral | null;
|
|
540
|
+
readonly configs?: Readonly<Record<string, MCPToolConfig>> | null;
|
|
541
|
+
readonly default_config?: MCPToolDefaultConfig;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export type ToolDefinition =
|
|
545
|
+
| CustomToolDefinition
|
|
546
|
+
| ToolBash20241022
|
|
547
|
+
| ToolBash20250124
|
|
548
|
+
| CodeExecutionTool20250522
|
|
549
|
+
| CodeExecutionTool20250825
|
|
550
|
+
| CodeExecutionTool20260120
|
|
551
|
+
| ToolComputerUse20241022
|
|
552
|
+
| ToolComputerUse20250124
|
|
553
|
+
| ToolComputerUse20251124
|
|
554
|
+
| MemoryTool20250818
|
|
555
|
+
| ToolTextEditor20241022
|
|
556
|
+
| ToolTextEditor20250124
|
|
557
|
+
| ToolTextEditor20250429
|
|
558
|
+
| ToolTextEditor20250728
|
|
559
|
+
| WebSearchTool20250305
|
|
560
|
+
| WebSearchTool20260209
|
|
561
|
+
| WebFetchTool20250910
|
|
562
|
+
| WebFetchTool20260209
|
|
563
|
+
| WebFetchTool20260309
|
|
564
|
+
| AdvisorTool20260301
|
|
565
|
+
| ToolSearchToolBm25_20251119
|
|
566
|
+
| ToolSearchToolRegex20251119
|
|
567
|
+
| MCPToolset;
|
|
568
|
+
|
|
569
|
+
export interface AllThinkingTurns {
|
|
570
|
+
readonly type: "all";
|
|
571
|
+
}
|
|
572
|
+
export interface ThinkingTurns {
|
|
573
|
+
readonly type: "thinking_turns";
|
|
574
|
+
readonly value: number;
|
|
575
|
+
}
|
|
576
|
+
export interface ClearThinking20251015Edit {
|
|
577
|
+
readonly type: "clear_thinking_20251015";
|
|
578
|
+
readonly keep?: ThinkingTurns | AllThinkingTurns | "all";
|
|
579
|
+
}
|
|
580
|
+
export interface InputTokensClearAtLeast {
|
|
581
|
+
readonly type: "input_tokens";
|
|
582
|
+
readonly value: number;
|
|
583
|
+
}
|
|
584
|
+
export interface InputTokensTrigger {
|
|
585
|
+
readonly type: "input_tokens";
|
|
586
|
+
readonly value: number;
|
|
587
|
+
}
|
|
588
|
+
export interface ToolUsesKeep {
|
|
589
|
+
readonly type: "tool_uses";
|
|
590
|
+
readonly value: number;
|
|
591
|
+
}
|
|
592
|
+
export interface ToolUsesTrigger {
|
|
593
|
+
readonly type: "tool_uses";
|
|
594
|
+
readonly value: number;
|
|
595
|
+
}
|
|
596
|
+
export interface ClearToolUses20250919Edit {
|
|
597
|
+
readonly type: "clear_tool_uses_20250919";
|
|
598
|
+
readonly clear_at_least?: InputTokensClearAtLeast | null;
|
|
599
|
+
readonly clear_tool_inputs?: boolean | readonly string[] | null;
|
|
600
|
+
readonly exclude_tools?: readonly string[] | null;
|
|
601
|
+
readonly keep?: ToolUsesKeep;
|
|
602
|
+
readonly trigger?: InputTokensTrigger | ToolUsesTrigger;
|
|
603
|
+
}
|
|
604
|
+
export interface Compact20260112Edit {
|
|
605
|
+
readonly type: "compact_20260112";
|
|
606
|
+
readonly instructions?: string | null;
|
|
607
|
+
readonly pause_after_compaction?: boolean;
|
|
608
|
+
readonly trigger?: InputTokensTrigger | null;
|
|
609
|
+
}
|
|
610
|
+
export interface ContextManagementConfig {
|
|
611
|
+
readonly edits?: readonly (
|
|
612
|
+
ClearToolUses20250919Edit | ClearThinking20251015Edit | Compact20260112Edit
|
|
613
|
+
)[];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export interface JSONOutputFormat {
|
|
617
|
+
readonly schema: Readonly<Record<string, JsonValue>>;
|
|
618
|
+
readonly type: "json_schema";
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
export interface OutputConfigInput {
|
|
622
|
+
readonly effort?: ClaudeCodeEffort | null;
|
|
623
|
+
/** Beta-only: requires `task-budgets-2026-03-13`; absent from SDK 0.94.0. */
|
|
624
|
+
readonly maxOutputTokens?: number | null;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
export interface ToolChoiceAny {
|
|
628
|
+
readonly type: "any";
|
|
629
|
+
readonly disable_parallel_tool_use?: boolean;
|
|
630
|
+
}
|
|
631
|
+
export interface ToolChoiceAuto {
|
|
632
|
+
readonly type: "auto";
|
|
633
|
+
readonly disable_parallel_tool_use?: boolean;
|
|
634
|
+
}
|
|
635
|
+
export interface ToolChoiceNone {
|
|
636
|
+
readonly type: "none";
|
|
637
|
+
}
|
|
638
|
+
export interface ToolChoiceTool {
|
|
639
|
+
readonly name: string;
|
|
640
|
+
readonly type: "tool";
|
|
641
|
+
readonly disable_parallel_tool_use?: boolean;
|
|
642
|
+
}
|
|
643
|
+
export type ToolChoice =
|
|
644
|
+
ToolChoiceAuto | ToolChoiceAny | ToolChoiceTool | ToolChoiceNone;
|
|
645
|
+
|
|
646
|
+
export interface ClaudeCodeCapabilities {
|
|
647
|
+
readonly thinking: boolean;
|
|
648
|
+
readonly adaptiveThinking: boolean;
|
|
649
|
+
readonly interleavedThinking: boolean;
|
|
650
|
+
readonly effort: boolean;
|
|
651
|
+
readonly maxEffort: boolean;
|
|
652
|
+
readonly xhighEffort: boolean;
|
|
653
|
+
readonly contextManagement: boolean;
|
|
654
|
+
readonly temperature: boolean;
|
|
655
|
+
readonly rejectsDisabledThinking: boolean;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/** Host-state beta gates pinned for a default first-party environment. */
|
|
659
|
+
export interface ClaudeCodeBetaPolicy {
|
|
660
|
+
readonly oauthAuthenticated: boolean;
|
|
661
|
+
readonly experimentalBetasEnabled: boolean;
|
|
662
|
+
readonly oneMillionContextEnabled: boolean;
|
|
663
|
+
readonly interleavedThinkingEnabled: boolean;
|
|
664
|
+
readonly interactive: boolean;
|
|
665
|
+
readonly thinkingSummariesShown: boolean;
|
|
666
|
+
readonly thinkingTokenCountEnabled: boolean;
|
|
667
|
+
readonly narrationSummariesEnabled: boolean;
|
|
668
|
+
readonly structuredOutputsEnabled: boolean;
|
|
669
|
+
readonly afkModeEnabled: boolean;
|
|
670
|
+
readonly cacheDiagnosisEnabled: boolean;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Substitutes protocol-identity fields of the pinned profile.
|
|
675
|
+
*
|
|
676
|
+
* The destination (`endpoint`), `provider` and `anthropicVersion` are the
|
|
677
|
+
* immutable security core and cannot be expressed here. Supplying any key
|
|
678
|
+
* outside this contract fails with `INVALID_INPUT` rather than being ignored.
|
|
679
|
+
*
|
|
680
|
+
* Each supplied field REPLACES the pinned field wholesale. There is no deep
|
|
681
|
+
* merge, because a merged model table or beta list would describe no real
|
|
682
|
+
* client version.
|
|
683
|
+
*/
|
|
684
|
+
export interface ClaudeCodeProfileOverride {
|
|
685
|
+
readonly id?: string;
|
|
686
|
+
readonly cliVersion?: string;
|
|
687
|
+
readonly sdkVersion?: string;
|
|
688
|
+
readonly entrypoint?: string;
|
|
689
|
+
readonly userAgent?: string;
|
|
690
|
+
readonly buildTime?: string;
|
|
691
|
+
readonly gitSha?: string;
|
|
692
|
+
readonly attributionHeaderEnabled?: boolean;
|
|
693
|
+
readonly contextHintEnabled?: boolean;
|
|
694
|
+
readonly betaPolicy?: ClaudeCodeBetaPolicy;
|
|
695
|
+
readonly supportedModels?: ClaudeCodeProtocolProfile["supportedModels"];
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export interface ClaudeCodeRuntimeIdentity {
|
|
699
|
+
readonly sessionId: string;
|
|
700
|
+
readonly deviceId: string;
|
|
701
|
+
readonly accountUuid: string;
|
|
702
|
+
readonly runtime: "node" | "bun" | "workerd";
|
|
703
|
+
readonly runtimeVersion: string;
|
|
704
|
+
readonly os: "Windows" | "Linux" | "macOS";
|
|
705
|
+
readonly arch: string;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/** Directs where the package places cache breakpoints. */
|
|
709
|
+
export interface ClaudeCodeCacheControlInput {
|
|
710
|
+
readonly enabled?: boolean | null;
|
|
711
|
+
readonly ttl?: "5m" | "1h" | null;
|
|
712
|
+
readonly systemBreakpoint?: boolean | null;
|
|
713
|
+
readonly toolBreakpoint?: boolean | null;
|
|
714
|
+
readonly messageBreakpoint?: boolean | null;
|
|
715
|
+
/**
|
|
716
|
+
* Emits the canonical identity system block (index 1) WITHOUT a
|
|
717
|
+
* `cache_control` marker. The block itself is still emitted, text intact.
|
|
718
|
+
*
|
|
719
|
+
* NOT the same field as the root `suppressIdentityBlock` of
|
|
720
|
+
* `ClaudeCodeRequestInput`, which removes the identity BLOCK from the
|
|
721
|
+
* emitted `system` array. This one only drops the block's marker. When the
|
|
722
|
+
* root seam removed the block there is nothing left to mark, so this field
|
|
723
|
+
* has no effect.
|
|
724
|
+
*
|
|
725
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour: the genuine client
|
|
726
|
+
* always marks that block. Defaults to `false`, which reproduces the
|
|
727
|
+
* unconditional marker byte-for-byte.
|
|
728
|
+
*/
|
|
729
|
+
readonly suppressIdentityBlock?: boolean | null;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Per-request substitutes for beta gates the genuine client reads from host
|
|
734
|
+
* state.
|
|
735
|
+
*
|
|
736
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. Every member is a
|
|
737
|
+
* tri-state: `true` forces the beta, `false` suppresses it, and omission keeps
|
|
738
|
+
* the upstream-derived decision. Recorded in
|
|
739
|
+
* `RedactedRequestEvidence.capabilityDecisions` only when supplied.
|
|
740
|
+
*/
|
|
741
|
+
export interface ClaudeCodeBetaOverrides {
|
|
742
|
+
/**
|
|
743
|
+
* Replaces the `[1m]` model-marker gate for `context-1m-2025-08-07`. The
|
|
744
|
+
* profile gate `betaPolicy.oneMillionContextEnabled` still applies, so an
|
|
745
|
+
* override cannot enable a beta the pinned profile declares unavailable.
|
|
746
|
+
*/
|
|
747
|
+
readonly use1MContext?: boolean;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Per-request substitutes for the `metadata.user_id` value the genuine client
|
|
752
|
+
* derives from host state.
|
|
753
|
+
*
|
|
754
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. The genuine client
|
|
755
|
+
* always emits `user_id` as the JSON encoding of the runtime correlation
|
|
756
|
+
* triple; this seam exists so a consumer can carry a host identifier the
|
|
757
|
+
* runtime-neutral core cannot observe, without forking metadata composition.
|
|
758
|
+
*
|
|
759
|
+
* The two members are MUTUALLY EXCLUSIVE, because they express different
|
|
760
|
+
* intents: `userId` abandons the derived value entirely, while `userIdFields`
|
|
761
|
+
* keeps it and adds to it. Supplying both fails with `INVALID_INPUT` rather
|
|
762
|
+
* than silently resolving the ambiguity.
|
|
763
|
+
*
|
|
764
|
+
* Omitting the field, or omitting both members, leaves the emitted request
|
|
765
|
+
* byte-identical.
|
|
766
|
+
*/
|
|
767
|
+
export interface ClaudeCodeMetadataOverrides {
|
|
768
|
+
/**
|
|
769
|
+
* Replaces the derived `metadata.user_id` verbatim.
|
|
770
|
+
*
|
|
771
|
+
* The correlation guarantee is the caller's from here on: the package no
|
|
772
|
+
* longer proves that `user_id` carries the session, device and account the
|
|
773
|
+
* headers and the identity system block declare. A built request whose
|
|
774
|
+
* `user_id` is not JSON carrying the session identifier is REJECTED by
|
|
775
|
+
* `parseBuiltClaudeCodeRequest`, which keeps that correlation invariant.
|
|
776
|
+
*
|
|
777
|
+
* Must be a non-blank string of at most 8192 characters with no control
|
|
778
|
+
* characters and no lone surrogates.
|
|
779
|
+
*/
|
|
780
|
+
readonly userId?: string;
|
|
781
|
+
/**
|
|
782
|
+
* Adds members to the derived `metadata.user_id` JSON object.
|
|
783
|
+
*
|
|
784
|
+
* Caller members are written FIRST and the correlation triple
|
|
785
|
+
* (`device_id`, `account_uuid`, `session_id`) LAST, so correlation always
|
|
786
|
+
* wins. Supplying any of those three keys fails with `INVALID_INPUT` rather
|
|
787
|
+
* than being silently overwritten.
|
|
788
|
+
*/
|
|
789
|
+
readonly userIdFields?: Readonly<Record<string, JsonValue>>;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* Decides what happens when `extraHeaders` collides with a header this package
|
|
794
|
+
* owns — a canonical name, or a name on the forbidden denylist.
|
|
795
|
+
*
|
|
796
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. The genuine client
|
|
797
|
+
* composes its own headers and never merges a foreign header map.
|
|
798
|
+
*
|
|
799
|
+
* - `strict` (the default) throws `DUPLICATE_HEADER` for a canonical name and
|
|
800
|
+
* `FORBIDDEN_HEADER` for a denylisted one. This is the behaviour that existed
|
|
801
|
+
* before the field, byte for byte.
|
|
802
|
+
* - `dropConflicting` discards the offending pair instead of throwing and
|
|
803
|
+
* records its lowercased name in `evidence.droppedExtraHeaderNames`, so a
|
|
804
|
+
* consumer can forward a heterogeneous host header map without a single
|
|
805
|
+
* inbound `anthropic-beta` destroying the request, and still audit the loss.
|
|
806
|
+
*
|
|
807
|
+
* NEITHER policy relaxes header syntax: a control character in a name or a
|
|
808
|
+
* value raises `HEADER_INJECTION` in both. Header smuggling is never silently
|
|
809
|
+
* tolerated. A caller that duplicates one of its OWN extra headers also keeps
|
|
810
|
+
* getting `DUPLICATE_HEADER` in both, because that collision is a caller bug
|
|
811
|
+
* rather than a conflict with a header this package owns.
|
|
812
|
+
*/
|
|
813
|
+
export type ClaudeCodeExtraHeaderPolicy = "strict" | "dropConflicting";
|
|
814
|
+
|
|
815
|
+
export interface ClaudeCodeRequestInput {
|
|
816
|
+
readonly accessToken: string;
|
|
817
|
+
readonly model: string;
|
|
818
|
+
readonly maxTokens: number;
|
|
819
|
+
readonly messages: readonly Message[];
|
|
820
|
+
readonly system?: readonly SystemInput[];
|
|
821
|
+
readonly tools?: readonly ToolDefinition[];
|
|
822
|
+
readonly cacheControl?: ClaudeCodeCacheControlInput | null;
|
|
823
|
+
readonly runtime: ClaudeCodeRuntimeIdentity;
|
|
824
|
+
readonly capabilities?: Partial<ClaudeCodeCapabilities>;
|
|
825
|
+
/** Substitutes protocol-identity fields of the pinned profile. */
|
|
826
|
+
readonly profileOverride?: ClaudeCodeProfileOverride;
|
|
827
|
+
readonly thinking?: {
|
|
828
|
+
readonly type: "enabled" | "adaptive" | "disabled";
|
|
829
|
+
readonly budgetTokens?: number;
|
|
830
|
+
readonly display?: ThinkingDisplay;
|
|
831
|
+
};
|
|
832
|
+
readonly effort?: ClaudeCodeEffort;
|
|
833
|
+
/** Supplies validated JSON metadata values in caller insertion order. */
|
|
834
|
+
readonly metadata?: Readonly<Record<string, JsonValue>>;
|
|
835
|
+
/** Appends validated, collision-safe beta fields to the request body. */
|
|
836
|
+
readonly experimentalBodyFields?: Readonly<Record<string, JsonValue>>;
|
|
837
|
+
readonly contextManagement?: ContextManagementConfig | null;
|
|
838
|
+
readonly outputConfig?: OutputConfigInput;
|
|
839
|
+
readonly speed?: "standard" | "fast" | null;
|
|
840
|
+
readonly serviceTier?: "auto" | "standard_only";
|
|
841
|
+
readonly outputFormat?: JSONOutputFormat | null;
|
|
842
|
+
readonly toolChoice?: ToolChoice;
|
|
843
|
+
readonly topP?: number;
|
|
844
|
+
readonly topK?: number;
|
|
845
|
+
readonly stopSequences?: readonly string[];
|
|
846
|
+
readonly stream?: boolean;
|
|
847
|
+
readonly temperature?: number;
|
|
848
|
+
/** Supplies the `x-client-request-id` header. */
|
|
849
|
+
readonly clientRequestId: string;
|
|
850
|
+
/** Selects the foreground or background Claude Code entrypoint header. */
|
|
851
|
+
readonly app?: "cli" | "cli-bg";
|
|
852
|
+
/** Supplies the Stainless retry-count header. */
|
|
853
|
+
readonly stainlessRetryCount?: number;
|
|
854
|
+
/** Supplies the Stainless helper header. */
|
|
855
|
+
readonly stainlessHelper?: string;
|
|
856
|
+
/** Supplies the Claude remote-container identifier header. */
|
|
857
|
+
readonly claudeRemoteContainerId?: string;
|
|
858
|
+
/** Supplies the Claude remote-session identifier header. */
|
|
859
|
+
readonly claudeRemoteSessionId?: string;
|
|
860
|
+
/** Supplies the client-application header. */
|
|
861
|
+
readonly clientApp?: string;
|
|
862
|
+
/** Supplies the Anthropic additional-protection header. */
|
|
863
|
+
readonly anthropicAdditionalProtection?: string;
|
|
864
|
+
/**
|
|
865
|
+
* Appends caller-supplied beta identifiers to the `anthropic-beta` header.
|
|
866
|
+
*
|
|
867
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. The genuine client
|
|
868
|
+
* derives its beta set entirely from the profile and the model; this seam
|
|
869
|
+
* exists so a consumer can carry user-configured betas without forking the
|
|
870
|
+
* composer. Entries are appended AFTER the derived canonical set, in caller
|
|
871
|
+
* order, and an entry equal to an already-emitted identifier is dropped.
|
|
872
|
+
*
|
|
873
|
+
* Each entry must match `/^[A-Za-z0-9][A-Za-z0-9._-]*$/` and be at most 128
|
|
874
|
+
* characters; at most 32 entries are accepted. Anything else fails with
|
|
875
|
+
* `INVALID_INPUT`, because the header is a single comma-joined field.
|
|
876
|
+
*
|
|
877
|
+
* Omitting the field leaves the emitted request byte-identical.
|
|
878
|
+
*/
|
|
879
|
+
readonly additionalBetas?: readonly string[];
|
|
880
|
+
/**
|
|
881
|
+
* Removes beta identifiers from the `anthropic-beta` header.
|
|
882
|
+
*
|
|
883
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. This package
|
|
884
|
+
* composes the beta set on its own, from the pinned profile and the model
|
|
885
|
+
* capabilities, so a consumer whose users can switch a beta OFF has no other
|
|
886
|
+
* way to honour that switch.
|
|
887
|
+
*
|
|
888
|
+
* The filter is applied LAST — after composition and after the
|
|
889
|
+
* `additionalBetas` merge — so suppression beats addition: an identifier
|
|
890
|
+
* named by both seams does not reach the wire. An identifier that is not in
|
|
891
|
+
* the composed set is a SILENT no-op, not an error, because the consumer
|
|
892
|
+
* cannot know which betas this package derives for a given model.
|
|
893
|
+
*
|
|
894
|
+
* Entries share the `additionalBetas` grammar exactly: each must match
|
|
895
|
+
* `/^[A-Za-z0-9][A-Za-z0-9._-]*$/` and be at most 128 characters, with at
|
|
896
|
+
* most 32 entries. Anything else fails with `INVALID_INPUT`.
|
|
897
|
+
*
|
|
898
|
+
* NOT guarded: this package does not protect load-bearing identifiers.
|
|
899
|
+
* Suppressing `oauth-2025-04-20` produces a request the API rejects with 401.
|
|
900
|
+
*
|
|
901
|
+
* Omitting the field, or supplying a list that removes nothing, leaves the
|
|
902
|
+
* emitted request byte-identical.
|
|
903
|
+
*/
|
|
904
|
+
readonly suppressBetas?: readonly string[];
|
|
905
|
+
/**
|
|
906
|
+
* Omits the canonical billing block (system index 0) from the emitted
|
|
907
|
+
* request, promoting the identity block to index 0.
|
|
908
|
+
*
|
|
909
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour: the genuine client
|
|
910
|
+
* always emits that block. It exists so a consumer that exposes an
|
|
911
|
+
* attribution switch to its users can honour it, instead of the switch being
|
|
912
|
+
* a silent no-op.
|
|
913
|
+
*
|
|
914
|
+
* Defaults to `false`. Omitting the field, or passing `false`, leaves the
|
|
915
|
+
* emitted request byte-identical. Any non-boolean value fails with
|
|
916
|
+
* `INVALID_INPUT`.
|
|
917
|
+
*/
|
|
918
|
+
readonly suppressBillingBlock?: boolean;
|
|
919
|
+
/**
|
|
920
|
+
* Omits the canonical identity block — the whole block, text included — from
|
|
921
|
+
* the emitted request.
|
|
922
|
+
*
|
|
923
|
+
* NOT the same field as `cacheControl.suppressIdentityBlock`, which KEEPS the
|
|
924
|
+
* identity block and only emits it WITHOUT its `cache_control` marker. This
|
|
925
|
+
* root field removes the block entirely; the two are independent and may be
|
|
926
|
+
* combined, in which case this one wins because there is no block left to
|
|
927
|
+
* mark. With `suppressBillingBlock` also set, the canonical prefix is empty
|
|
928
|
+
* and the emitted `system` array carries caller blocks only.
|
|
929
|
+
*
|
|
930
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour: the genuine client
|
|
931
|
+
* always emits that block. It exists so a consumer that exposes a lean-system
|
|
932
|
+
* switch to its users can honour it, instead of the switch being a silent
|
|
933
|
+
* no-op.
|
|
934
|
+
*
|
|
935
|
+
* Defaults to `false`. Omitting the field, or passing `false`, leaves the
|
|
936
|
+
* emitted request byte-identical. Any non-boolean value fails with
|
|
937
|
+
* `INVALID_INPUT`.
|
|
938
|
+
*/
|
|
939
|
+
readonly suppressIdentityBlock?: boolean;
|
|
940
|
+
/**
|
|
941
|
+
* Accepts `cache_control` on `thinking` and `redacted_thinking` blocks and
|
|
942
|
+
* copies it to the body VERBATIM.
|
|
943
|
+
*
|
|
944
|
+
* WHY THIS EXISTS. The Anthropic API rejects a request whose latest assistant
|
|
945
|
+
* message carries a MUTATED reasoning block:
|
|
946
|
+
*
|
|
947
|
+
* > `400 ... thinking or redacted_thinking blocks in the latest assistant
|
|
948
|
+
* > message cannot be modified. These blocks must remain as they were in the
|
|
949
|
+
* > original response.`
|
|
950
|
+
*
|
|
951
|
+
* A consumer that receives such a block with `cache_control` attached cannot
|
|
952
|
+
* strip the key before handing the message to this package — `delete
|
|
953
|
+
* block.cache_control` IS a modification and triggers that very 400. Without
|
|
954
|
+
* this seam the strict thinking-block allowlist rejected the whole request
|
|
955
|
+
* with `INVALID_INPUT`, leaving the consumer no legal move. That is a
|
|
956
|
+
* production failure, not a test artefact.
|
|
957
|
+
*
|
|
958
|
+
* SCOPE. The allowlist grows by `cache_control` and by nothing else: an
|
|
959
|
+
* unknown key on a thinking block is still `INVALID_INPUT` with the seam
|
|
960
|
+
* active. The value is validated by the same `cache_control` validator every
|
|
961
|
+
* other block uses — `{ type: "ephemeral" }` with an optional `ttl` — so a
|
|
962
|
+
* malformed marker still fails closed. The `scope` key that `text` blocks
|
|
963
|
+
* tolerate for legacy reasons is NOT accepted here; the API never returns it
|
|
964
|
+
* on a reasoning block.
|
|
965
|
+
*
|
|
966
|
+
* PASSTHROUGH, not participation. The preserved marker takes no part in this
|
|
967
|
+
* package's cache-control machinery: no TTL is applied to it, no message or
|
|
968
|
+
* system breakpoint is moved onto or off a thinking block, and
|
|
969
|
+
* `cacheControl.*` is unaffected.
|
|
970
|
+
*
|
|
971
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. Defaults to `false`.
|
|
972
|
+
* Omitting the field, or passing `false`, leaves the emitted request
|
|
973
|
+
* byte-identical and keeps `cache_control` on a reasoning block an
|
|
974
|
+
* `INVALID_INPUT`. The strict default is deliberate: accepting the key
|
|
975
|
+
* unconditionally would silently widen a wire contract this package exists to
|
|
976
|
+
* reproduce exactly. Any non-boolean value fails with `INVALID_INPUT`.
|
|
977
|
+
*/
|
|
978
|
+
readonly preserveThinkingBlockCacheControl?: boolean;
|
|
979
|
+
/**
|
|
980
|
+
* Overrides beta-header gates that the genuine client resolves from host
|
|
981
|
+
* state this package cannot observe.
|
|
982
|
+
*
|
|
983
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. Omitting the field,
|
|
984
|
+
* or omitting any member, leaves the emitted request byte-identical.
|
|
985
|
+
*/
|
|
986
|
+
readonly betaOverrides?: ClaudeCodeBetaOverrides;
|
|
987
|
+
/**
|
|
988
|
+
* Overrides the `metadata.user_id` value the genuine client derives from
|
|
989
|
+
* host state this package cannot observe.
|
|
990
|
+
*
|
|
991
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. Opt-in: with the
|
|
992
|
+
* field omitted, a supplied `metadata.user_id` that diverges from the
|
|
993
|
+
* derived value keeps failing with `INVALID_INPUT`. Omitting the field, or
|
|
994
|
+
* omitting both members, leaves the emitted request byte-identical.
|
|
995
|
+
*/
|
|
996
|
+
readonly metadataOverrides?: ClaudeCodeMetadataOverrides;
|
|
997
|
+
/** Appends validated non-canonical headers in caller order. */
|
|
998
|
+
readonly extraHeaders?: readonly HeaderPair[];
|
|
999
|
+
/**
|
|
1000
|
+
* Decides how a collision between `extraHeaders` and a header this package
|
|
1001
|
+
* owns is resolved. Defaults to `strict`, the pre-existing behaviour.
|
|
1002
|
+
*
|
|
1003
|
+
* PACKAGE EXTENSION, not observed Claude Code behaviour. Omitting the field,
|
|
1004
|
+
* or passing `"strict"`, leaves the emitted request byte-identical, evidence
|
|
1005
|
+
* included: `droppedExtraHeaderNames` is emitted only under
|
|
1006
|
+
* `"dropConflicting"`.
|
|
1007
|
+
*/
|
|
1008
|
+
readonly extraHeaderPolicy?: ClaudeCodeExtraHeaderPolicy;
|
|
1009
|
+
/** Injects the Web Crypto provider used to hash the request body. */
|
|
1010
|
+
readonly crypto?: Pick<Crypto, "subtle">;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Narrower than `ClaudeCodeRequestInput` by design. Upstream `P5e` derives the
|
|
1015
|
+
* beta set from the model alone, so there is deliberately no `capabilities`
|
|
1016
|
+
* field, and the count-tokens body carries no `system`, `metadata`, or
|
|
1017
|
+
* `maxTokens`.
|
|
1018
|
+
*/
|
|
1019
|
+
export type ClaudeCodeCountTokensInput = Pick<
|
|
1020
|
+
ClaudeCodeRequestInput,
|
|
1021
|
+
| "accessToken"
|
|
1022
|
+
| "model"
|
|
1023
|
+
| "messages"
|
|
1024
|
+
| "tools"
|
|
1025
|
+
| "runtime"
|
|
1026
|
+
| "clientRequestId"
|
|
1027
|
+
| "profileOverride"
|
|
1028
|
+
| "crypto"
|
|
1029
|
+
| "app"
|
|
1030
|
+
| "stainlessRetryCount"
|
|
1031
|
+
| "stainlessHelper"
|
|
1032
|
+
| "claudeRemoteContainerId"
|
|
1033
|
+
| "claudeRemoteSessionId"
|
|
1034
|
+
| "clientApp"
|
|
1035
|
+
| "anthropicAdditionalProtection"
|
|
1036
|
+
| "extraHeaders"
|
|
1037
|
+
>;
|
|
1038
|
+
|
|
1039
|
+
export interface BuiltClaudeCodeCountTokensRequest extends Omit<
|
|
1040
|
+
BuiltClaudeCodeRequest,
|
|
1041
|
+
"url"
|
|
1042
|
+
> {
|
|
1043
|
+
readonly url: "https://api.anthropic.com/v1/messages/count_tokens?beta=true";
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
export interface ClaudeCodeProtocolProfile {
|
|
1047
|
+
readonly countTokensEndpoint: "https://api.anthropic.com/v1/messages/count_tokens?beta=true";
|
|
1048
|
+
readonly id: string;
|
|
1049
|
+
readonly cliVersion: string;
|
|
1050
|
+
readonly sdkVersion: string;
|
|
1051
|
+
readonly endpoint: "https://api.anthropic.com/v1/messages?beta=true";
|
|
1052
|
+
/** Replaces upstream `CLAUDE_CODE_ENTRYPOINT`. */
|
|
1053
|
+
readonly entrypoint: string;
|
|
1054
|
+
/** Replaces upstream `buildExtendedUserAgent` (`lib/request-headers.mjs:288-295`). */
|
|
1055
|
+
readonly userAgent: string;
|
|
1056
|
+
/** Replaces upstream `CLAUDE_CODE_BUILD_TIME`. */
|
|
1057
|
+
readonly buildTime: string;
|
|
1058
|
+
/** Replaces upstream `CLAUDE_CODE_GIT_SHA`. */
|
|
1059
|
+
readonly gitSha: string;
|
|
1060
|
+
/** Replaces upstream `CLAUDE_CODE_ATTRIBUTION_HEADER`. */
|
|
1061
|
+
readonly attributionHeaderEnabled: boolean;
|
|
1062
|
+
/**
|
|
1063
|
+
* Replaces the upstream `provider` parameter of
|
|
1064
|
+
* `buildAnthropicBillingHeader` (`lib/mimicry/system-prompt.mjs:134-159`),
|
|
1065
|
+
* where `bedrock`, `anthropicAws`, and `mantle` suppress the `cch` and
|
|
1066
|
+
* workload parts.
|
|
1067
|
+
*/
|
|
1068
|
+
readonly provider: "anthropic";
|
|
1069
|
+
/** Pins the upstream `anthropic-version` request header. */
|
|
1070
|
+
readonly anthropicVersion: "2023-06-01";
|
|
1071
|
+
readonly contextHintEnabled: boolean;
|
|
1072
|
+
readonly betaPolicy: ClaudeCodeBetaPolicy;
|
|
1073
|
+
readonly supportedModels: Readonly<Record<string, ClaudeCodeCatalogueEntry>>;
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
export type ClaudeCodeWireErrorCode =
|
|
1077
|
+
| "INVALID_INPUT"
|
|
1078
|
+
| "INVALID_IDENTITY"
|
|
1079
|
+
| "UNSUPPORTED_CAPABILITY"
|
|
1080
|
+
| "INVALID_THINKING"
|
|
1081
|
+
| "INVALID_EFFORT"
|
|
1082
|
+
| "FORBIDDEN_HEADER"
|
|
1083
|
+
| "DUPLICATE_HEADER"
|
|
1084
|
+
| "HEADER_INJECTION"
|
|
1085
|
+
| "INVALID_UNICODE"
|
|
1086
|
+
| "INPUT_TOO_DEEP"
|
|
1087
|
+
| "INPUT_TOO_LARGE"
|
|
1088
|
+
| "CYCLIC_INPUT"
|
|
1089
|
+
| "CRYPTO_UNAVAILABLE"
|
|
1090
|
+
| "REDACTION_FAILURE";
|
|
1091
|
+
|
|
1092
|
+
export interface RedactedRequestEvidence {
|
|
1093
|
+
/** Reports the effective profile id, which differs when overridden. */
|
|
1094
|
+
readonly profileId: string;
|
|
1095
|
+
readonly url: ClaudeCodeProtocolProfile["endpoint"];
|
|
1096
|
+
readonly method: "POST";
|
|
1097
|
+
readonly modelFamily: ClaudeCodeModelFamily;
|
|
1098
|
+
readonly logicalHeaderNames: readonly string[];
|
|
1099
|
+
readonly betaFeatures: readonly string[];
|
|
1100
|
+
readonly bodySha256: string;
|
|
1101
|
+
readonly bodyByteLength: number;
|
|
1102
|
+
readonly messageCount: number;
|
|
1103
|
+
readonly systemBlockCount: number;
|
|
1104
|
+
readonly capabilityDecisions: ClaudeCodeCapabilityDecisions;
|
|
1105
|
+
/**
|
|
1106
|
+
* Audits the extra headers `extraHeaderPolicy: "dropConflicting"` discarded,
|
|
1107
|
+
* lowercased and in caller order.
|
|
1108
|
+
*
|
|
1109
|
+
* Emitted ONLY under that policy. Under `strict`, and for every request built
|
|
1110
|
+
* before the seam existed, the key is ABSENT rather than present and empty,
|
|
1111
|
+
* so existing evidence stays byte-identical.
|
|
1112
|
+
*/
|
|
1113
|
+
readonly droppedExtraHeaderNames?: readonly string[];
|
|
1114
|
+
/**
|
|
1115
|
+
* Audits the beta identifiers `suppressBetas` actually removed, in the order
|
|
1116
|
+
* the composed set held them.
|
|
1117
|
+
*
|
|
1118
|
+
* Emitted ONLY when at least one identifier was removed. When the seam is
|
|
1119
|
+
* omitted, empty, or matches nothing, the key is ABSENT rather than present
|
|
1120
|
+
* and empty, so existing evidence stays byte-identical.
|
|
1121
|
+
*/
|
|
1122
|
+
readonly suppressedBetaNames?: readonly string[];
|
|
1123
|
+
/**
|
|
1124
|
+
* Records that `suppressBillingBlock` removed the canonical billing block,
|
|
1125
|
+
* which shortens the canonical system prefix from two blocks to one.
|
|
1126
|
+
*
|
|
1127
|
+
* Emitted ONLY when the seam was active. When it is omitted or `false`, the
|
|
1128
|
+
* key is ABSENT rather than present and `false`, so existing evidence stays
|
|
1129
|
+
* byte-identical.
|
|
1130
|
+
*/
|
|
1131
|
+
readonly billingBlockSuppressed?: boolean;
|
|
1132
|
+
/**
|
|
1133
|
+
* Records that the root `suppressIdentityBlock` removed the canonical
|
|
1134
|
+
* identity block. Together with `billingBlockSuppressed` it states the length
|
|
1135
|
+
* of the canonical system prefix — two, one or zero blocks — which the parser
|
|
1136
|
+
* then verifies block by block.
|
|
1137
|
+
*
|
|
1138
|
+
* Refers to the ROOT seam, not `cacheControl.suppressIdentityBlock`: the
|
|
1139
|
+
* latter only drops the identity block's `cache_control` marker and is never
|
|
1140
|
+
* recorded here, because the block itself still ships.
|
|
1141
|
+
*
|
|
1142
|
+
* Emitted ONLY when the seam was active. When it is omitted or `false`, the
|
|
1143
|
+
* key is ABSENT rather than present and `false`, so existing evidence stays
|
|
1144
|
+
* byte-identical.
|
|
1145
|
+
*/
|
|
1146
|
+
readonly identityBlockSuppressed?: boolean;
|
|
1147
|
+
/**
|
|
1148
|
+
* Records that `preserveThinkingBlockCacheControl` was active AND that at
|
|
1149
|
+
* least one emitted `thinking` or `redacted_thinking` block actually carried
|
|
1150
|
+
* a `cache_control` key.
|
|
1151
|
+
*
|
|
1152
|
+
* Emitted ONLY when both hold. A request that opts into the seam without
|
|
1153
|
+
* using it leaves the key ABSENT rather than present and `false`, on the same
|
|
1154
|
+
* discipline as `billingBlockSuppressed`: evidence records what the seam DID,
|
|
1155
|
+
* not what it was allowed to do. `parseBuiltClaudeCodeRequest` verifies the
|
|
1156
|
+
* claim structurally against the body rather than trusting it.
|
|
1157
|
+
*/
|
|
1158
|
+
readonly thinkingBlockCacheControlPreserved?: boolean;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Records the nine model capability decisions, plus any package-extension beta
|
|
1163
|
+
* override the caller supplied.
|
|
1164
|
+
*
|
|
1165
|
+
* The override keys are OPTIONAL and are emitted only when the corresponding
|
|
1166
|
+
* member of `betaOverrides` is present, so evidence for a request that omits
|
|
1167
|
+
* `betaOverrides` is byte-identical to evidence produced before the seam
|
|
1168
|
+
* existed.
|
|
1169
|
+
*/
|
|
1170
|
+
export type ClaudeCodeCapabilityDecisions = Readonly<
|
|
1171
|
+
Record<keyof ClaudeCodeCapabilities, boolean>
|
|
1172
|
+
> & {
|
|
1173
|
+
/** Mirrors `betaOverrides.use1MContext`; absent when it was not supplied. */
|
|
1174
|
+
readonly use1MContext?: boolean;
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
export interface BuiltClaudeCodeRequest {
|
|
1178
|
+
readonly url: "https://api.anthropic.com/v1/messages?beta=true";
|
|
1179
|
+
readonly method: "POST";
|
|
1180
|
+
readonly headers: readonly HeaderPair[];
|
|
1181
|
+
readonly body: string;
|
|
1182
|
+
readonly evidence: RedactedRequestEvidence;
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
export class ClaudeCodeWireError extends Error {
|
|
1186
|
+
override readonly name = "ClaudeCodeWireError";
|
|
1187
|
+
readonly code: ClaudeCodeWireErrorCode;
|
|
1188
|
+
readonly safeDetails: Readonly<Record<string, string | number | boolean>>;
|
|
1189
|
+
|
|
1190
|
+
constructor(
|
|
1191
|
+
code: ClaudeCodeWireErrorCode,
|
|
1192
|
+
safeDetails: Readonly<Record<string, string | number | boolean>> = {},
|
|
1193
|
+
) {
|
|
1194
|
+
super(code);
|
|
1195
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
1196
|
+
|
|
1197
|
+
const entries: [string, string | number | boolean][] = [];
|
|
1198
|
+
for (const key of Reflect.ownKeys(safeDetails)) {
|
|
1199
|
+
if (
|
|
1200
|
+
typeof key !== "string" ||
|
|
1201
|
+
key === "__proto__" ||
|
|
1202
|
+
key === "prototype" ||
|
|
1203
|
+
key === "constructor"
|
|
1204
|
+
) {
|
|
1205
|
+
throw new TypeError("safeDetails contains a forbidden key.");
|
|
1206
|
+
}
|
|
1207
|
+
const value = safeDetails[key];
|
|
1208
|
+
if (
|
|
1209
|
+
typeof value !== "string" &&
|
|
1210
|
+
typeof value !== "number" &&
|
|
1211
|
+
typeof value !== "boolean"
|
|
1212
|
+
) {
|
|
1213
|
+
throw new TypeError("safeDetails values must be primitive-safe.");
|
|
1214
|
+
}
|
|
1215
|
+
entries.push([key, value]);
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
this.code = code;
|
|
1219
|
+
this.safeDetails = Object.freeze(Object.fromEntries(entries));
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
toJSON(): {
|
|
1223
|
+
readonly name: "ClaudeCodeWireError";
|
|
1224
|
+
readonly code: ClaudeCodeWireErrorCode;
|
|
1225
|
+
readonly safeDetails: Readonly<Record<string, string | number | boolean>>;
|
|
1226
|
+
} {
|
|
1227
|
+
return {
|
|
1228
|
+
name: this.name,
|
|
1229
|
+
code: this.code,
|
|
1230
|
+
safeDetails: this.safeDetails,
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
}
|