@anthropic-ai/sdk 0.20.9 → 0.21.1
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 +24 -0
- package/_vendor/partial-json-parser/parser.d.ts +3 -0
- package/_vendor/partial-json-parser/parser.d.ts.map +1 -0
- package/_vendor/partial-json-parser/parser.js +224 -0
- package/_vendor/partial-json-parser/parser.js.map +1 -0
- package/_vendor/partial-json-parser/parser.mjs +221 -0
- package/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/lib/ToolsBetaMessageStream.d.ts +95 -0
- package/lib/ToolsBetaMessageStream.d.ts.map +1 -0
- package/lib/ToolsBetaMessageStream.js +459 -0
- package/lib/ToolsBetaMessageStream.js.map +1 -0
- package/lib/ToolsBetaMessageStream.mjs +455 -0
- package/lib/ToolsBetaMessageStream.mjs.map +1 -0
- package/package.json +2 -2
- package/resources/beta/tools/index.d.ts +1 -1
- package/resources/beta/tools/index.d.ts.map +1 -1
- package/resources/beta/tools/index.js.map +1 -1
- package/resources/beta/tools/index.mjs.map +1 -1
- package/resources/beta/tools/messages.d.ts +351 -20
- package/resources/beta/tools/messages.d.ts.map +1 -1
- package/resources/beta/tools/messages.js +11 -2
- package/resources/beta/tools/messages.js.map +1 -1
- package/resources/beta/tools/messages.mjs +9 -1
- package/resources/beta/tools/messages.mjs.map +1 -1
- package/resources/beta/tools/tools.d.ts +5 -0
- package/resources/beta/tools/tools.d.ts.map +1 -1
- package/resources/beta/tools/tools.js.map +1 -1
- package/resources/beta/tools/tools.mjs.map +1 -1
- package/resources/completions.d.ts +11 -19
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs.map +1 -1
- package/resources/messages.d.ts +24 -24
- package/src/_shims/auto/runtime-bun.ts +1 -1
- package/src/_shims/auto/runtime-node.ts +1 -1
- package/src/_shims/auto/runtime.ts +1 -1
- package/src/_shims/auto/types-node.ts +1 -1
- package/src/_shims/bun-runtime.ts +2 -2
- package/src/_shims/index.d.ts +3 -3
- package/src/_shims/index.mjs +1 -1
- package/src/_shims/node-runtime.ts +3 -3
- package/src/_shims/registry.ts +1 -1
- package/src/_shims/web-runtime.ts +3 -3
- package/src/_vendor/partial-json-parser/README.md +3 -0
- package/src/_vendor/partial-json-parser/parser.ts +262 -0
- package/src/core.ts +6 -6
- package/src/error.ts +1 -1
- package/src/index.ts +5 -5
- package/src/lib/MessageStream.ts +5 -5
- package/src/lib/ToolsBetaMessageStream.ts +561 -0
- package/src/resource.ts +1 -1
- package/src/resources/beta/beta.ts +2 -2
- package/src/resources/beta/index.ts +2 -2
- package/src/resources/beta/tools/index.ts +7 -2
- package/src/resources/beta/tools/messages.ts +405 -29
- package/src/resources/beta/tools/tools.ts +7 -2
- package/src/resources/completions.ts +16 -24
- package/src/resources/index.ts +3 -3
- package/src/resources/messages.ts +31 -31
- package/src/shims/node.ts +3 -3
- package/src/shims/web.ts +3 -3
- package/src/streaming.ts +4 -4
- package/src/uploads.ts +4 -4
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -8,11 +8,10 @@ export declare class Completions extends APIResource {
|
|
|
8
8
|
* [Legacy] Create a Text Completion.
|
|
9
9
|
*
|
|
10
10
|
* The Text Completions API is a legacy API. We recommend using the
|
|
11
|
-
* [Messages API](https://docs.anthropic.com/
|
|
12
|
-
* forward.
|
|
11
|
+
* [Messages API](https://docs.anthropic.com/en/api/messages) going forward.
|
|
13
12
|
*
|
|
14
13
|
* Future models and features will not be compatible with Text Completions. See our
|
|
15
|
-
* [migration guide](https://docs.anthropic.com/
|
|
14
|
+
* [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages)
|
|
16
15
|
* for guidance in migrating from Text Completions to Messages.
|
|
17
16
|
*/
|
|
18
17
|
create(body: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
|
|
@@ -63,8 +62,8 @@ export interface CompletionCreateParamsBase {
|
|
|
63
62
|
/**
|
|
64
63
|
* The model that will complete your prompt.
|
|
65
64
|
*
|
|
66
|
-
* See [models](https://docs.anthropic.com/
|
|
67
|
-
*
|
|
65
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
66
|
+
* details and options.
|
|
68
67
|
*/
|
|
69
68
|
model: (string & {}) | 'claude-2.0' | 'claude-2.1' | 'claude-instant-1.2';
|
|
70
69
|
/**
|
|
@@ -77,11 +76,10 @@ export interface CompletionCreateParamsBase {
|
|
|
77
76
|
* "\n\nHuman: {userQuestion}\n\nAssistant:"
|
|
78
77
|
* ```
|
|
79
78
|
*
|
|
80
|
-
* See
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* for more details.
|
|
79
|
+
* See [prompt validation](https://docs.anthropic.com/en/api/prompt-validation) and
|
|
80
|
+
* our guide to
|
|
81
|
+
* [prompt design](https://docs.anthropic.com/en/docs/intro-to-prompting) for more
|
|
82
|
+
* details.
|
|
85
83
|
*/
|
|
86
84
|
prompt: string;
|
|
87
85
|
/**
|
|
@@ -99,9 +97,7 @@ export interface CompletionCreateParamsBase {
|
|
|
99
97
|
/**
|
|
100
98
|
* Whether to incrementally stream the response using server-sent events.
|
|
101
99
|
*
|
|
102
|
-
* See
|
|
103
|
-
* [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
|
|
104
|
-
* for details.
|
|
100
|
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
105
101
|
*/
|
|
106
102
|
stream?: boolean;
|
|
107
103
|
/**
|
|
@@ -159,9 +155,7 @@ export interface CompletionCreateParamsNonStreaming extends CompletionCreatePara
|
|
|
159
155
|
/**
|
|
160
156
|
* Whether to incrementally stream the response using server-sent events.
|
|
161
157
|
*
|
|
162
|
-
* See
|
|
163
|
-
* [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
|
|
164
|
-
* for details.
|
|
158
|
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
165
159
|
*/
|
|
166
160
|
stream?: false;
|
|
167
161
|
}
|
|
@@ -169,9 +163,7 @@ export interface CompletionCreateParamsStreaming extends CompletionCreateParamsB
|
|
|
169
163
|
/**
|
|
170
164
|
* Whether to incrementally stream the response using server-sent events.
|
|
171
165
|
*
|
|
172
|
-
* See
|
|
173
|
-
* [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
|
|
174
|
-
* for details.
|
|
166
|
+
* See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
|
|
175
167
|
*/
|
|
176
168
|
stream: true;
|
|
177
169
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,qBAAa,WAAY,SAAQ,WAAW;IAC1C
|
|
1
|
+
{"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,qBAAa,WAAY,SAAQ,WAAW;IAC1C;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,kCAAkC,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC;IACvG,MAAM,CACJ,IAAI,EAAE,+BAA+B,EACrC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACjC,MAAM,CACJ,IAAI,EAAE,0BAA0B,EAChC,OAAO,CAAC,EAAE,IAAI,CAAC,cAAc,GAC5B,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;CAY/C;AAED,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;;;OAQG;IACH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAE3B;;;;OAIG;IACH,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,MAAM,MAAM,sBAAsB,GAAG,kCAAkC,GAAG,+BAA+B,CAAC;AAE1G,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAE7B;;;;;OAKG;IACH,KAAK,EAAE,CAAC,MAAM,GAAG,EAAE,CAAC,GAAG,YAAY,GAAG,YAAY,GAAG,oBAAoB,CAAC;IAE1E;;;;;;;;;;;;;;OAcG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,QAAQ,CAAC,EAAE,sBAAsB,CAAC,QAAQ,CAAC;IAE3C;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAE/B;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;;;;;;;OAUG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,yBAAiB,sBAAsB,CAAC;IACtC;;OAEG;IACH,UAAiB,QAAQ;QACvB;;;;;;WAMG;QACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB;IAED,KAAY,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACnG,KAAY,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAC9F;AAED,MAAM,WAAW,kCAAmC,SAAQ,0BAA0B;IACpF;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,WAAW,+BAAgC,SAAQ,0BAA0B;IACjF;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAC;CACd;AAED,yBAAiB,WAAW,CAAC;IAC3B,MAAM,QAAQ,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;IACrD,MAAM,QAAQ,sBAAsB,GAAG,cAAc,CAAC,sBAAsB,CAAC;IAC7E,MAAM,QAAQ,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACrG,MAAM,QAAQ,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAChG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAItF,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;
|
|
1
|
+
{"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAItF,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAoB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AA/BD,kCA+BC;AA0KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAK3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAI/E,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;
|
|
1
|
+
{"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAI/E,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAoB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AA0KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,KAAX,WAAW,QAK3B"}
|
package/resources/messages.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export declare class Messages extends APIResource {
|
|
|
12
12
|
* Send a structured list of input messages with text and/or image content, and the
|
|
13
13
|
* model will generate the next message in the conversation.
|
|
14
14
|
*
|
|
15
|
-
* The Messages API can be used for
|
|
16
|
-
*
|
|
15
|
+
* The Messages API can be used for either single queries or stateless multi-turn
|
|
16
|
+
* conversations.
|
|
17
17
|
*/
|
|
18
18
|
create(body: MessageCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Message>;
|
|
19
19
|
create(body: MessageCreateParamsStreaming, options?: Core.RequestOptions): APIPromise<Stream<MessageStreamEvent>>;
|
|
@@ -217,7 +217,7 @@ export interface MessageCreateParamsBase {
|
|
|
217
217
|
* only specifies the absolute maximum number of tokens to generate.
|
|
218
218
|
*
|
|
219
219
|
* Different models have different maximum values for this parameter. See
|
|
220
|
-
* [models](https://docs.anthropic.com/
|
|
220
|
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for details.
|
|
221
221
|
*/
|
|
222
222
|
max_tokens: number;
|
|
223
223
|
/**
|
|
@@ -299,20 +299,20 @@ export interface MessageCreateParamsBase {
|
|
|
299
299
|
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
|
300
300
|
* `image/png`, `image/gif`, and `image/webp` media types.
|
|
301
301
|
*
|
|
302
|
-
* See [examples](https://docs.anthropic.com/
|
|
303
|
-
*
|
|
302
|
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
|
|
303
|
+
* input examples.
|
|
304
304
|
*
|
|
305
305
|
* Note that if you want to include a
|
|
306
|
-
* [system prompt](https://docs.anthropic.com/
|
|
307
|
-
*
|
|
306
|
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
|
307
|
+
* the top-level `system` parameter — there is no `"system"` role for input
|
|
308
308
|
* messages in the Messages API.
|
|
309
309
|
*/
|
|
310
310
|
messages: Array<MessageParam>;
|
|
311
311
|
/**
|
|
312
312
|
* The model that will complete your prompt.
|
|
313
313
|
*
|
|
314
|
-
* See [models](https://docs.anthropic.com/
|
|
315
|
-
*
|
|
314
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
315
|
+
* details and options.
|
|
316
316
|
*/
|
|
317
317
|
model: (string & {}) | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'claude-2.1' | 'claude-2.0' | 'claude-instant-1.2';
|
|
318
318
|
/**
|
|
@@ -334,8 +334,8 @@ export interface MessageCreateParamsBase {
|
|
|
334
334
|
/**
|
|
335
335
|
* Whether to incrementally stream the response using server-sent events.
|
|
336
336
|
*
|
|
337
|
-
* See [streaming](https://docs.anthropic.com/
|
|
338
|
-
*
|
|
337
|
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
338
|
+
* details.
|
|
339
339
|
*/
|
|
340
340
|
stream?: boolean;
|
|
341
341
|
/**
|
|
@@ -343,7 +343,7 @@ export interface MessageCreateParamsBase {
|
|
|
343
343
|
*
|
|
344
344
|
* A system prompt is a way of providing context and instructions to Claude, such
|
|
345
345
|
* as specifying a particular goal or role. See our
|
|
346
|
-
* [guide to system prompts](https://docs.anthropic.com/
|
|
346
|
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
|
347
347
|
*/
|
|
348
348
|
system?: string;
|
|
349
349
|
/**
|
|
@@ -401,8 +401,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
|
|
|
401
401
|
/**
|
|
402
402
|
* Whether to incrementally stream the response using server-sent events.
|
|
403
403
|
*
|
|
404
|
-
* See [streaming](https://docs.anthropic.com/
|
|
405
|
-
*
|
|
404
|
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
405
|
+
* details.
|
|
406
406
|
*/
|
|
407
407
|
stream?: false;
|
|
408
408
|
}
|
|
@@ -410,8 +410,8 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
|
|
|
410
410
|
/**
|
|
411
411
|
* Whether to incrementally stream the response using server-sent events.
|
|
412
412
|
*
|
|
413
|
-
* See [streaming](https://docs.anthropic.com/
|
|
414
|
-
*
|
|
413
|
+
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
414
|
+
* details.
|
|
415
415
|
*/
|
|
416
416
|
stream: true;
|
|
417
417
|
}
|
|
@@ -423,7 +423,7 @@ export interface MessageStreamParams {
|
|
|
423
423
|
* only specifies the absolute maximum number of tokens to generate.
|
|
424
424
|
*
|
|
425
425
|
* Different models have different maximum values for this parameter. See
|
|
426
|
-
* [models](https://docs.anthropic.com/
|
|
426
|
+
* [models](https://docs.anthropic.com/en/docs/models-overview) for details.
|
|
427
427
|
*/
|
|
428
428
|
max_tokens: number;
|
|
429
429
|
/**
|
|
@@ -505,20 +505,20 @@ export interface MessageStreamParams {
|
|
|
505
505
|
* We currently support the `base64` source type for images, and the `image/jpeg`,
|
|
506
506
|
* `image/png`, `image/gif`, and `image/webp` media types.
|
|
507
507
|
*
|
|
508
|
-
* See [examples](https://docs.anthropic.com/
|
|
509
|
-
*
|
|
508
|
+
* See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
|
|
509
|
+
* input examples.
|
|
510
510
|
*
|
|
511
511
|
* Note that if you want to include a
|
|
512
|
-
* [system prompt](https://docs.anthropic.com/
|
|
513
|
-
*
|
|
512
|
+
* [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
|
|
513
|
+
* the top-level `system` parameter — there is no `"system"` role for input
|
|
514
514
|
* messages in the Messages API.
|
|
515
515
|
*/
|
|
516
516
|
messages: Array<MessageParam>;
|
|
517
517
|
/**
|
|
518
518
|
* The model that will complete your prompt.
|
|
519
519
|
*
|
|
520
|
-
* See [models](https://docs.anthropic.com/
|
|
521
|
-
*
|
|
520
|
+
* See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
521
|
+
* details and options.
|
|
522
522
|
*/
|
|
523
523
|
model: (string & {}) | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'claude-2.1' | 'claude-2.0' | 'claude-instant-1.2';
|
|
524
524
|
/**
|
|
@@ -542,7 +542,7 @@ export interface MessageStreamParams {
|
|
|
542
542
|
*
|
|
543
543
|
* A system prompt is a way of providing context and instructions to Claude, such
|
|
544
544
|
* as specifying a particular goal or role. See our
|
|
545
|
-
* [guide to system prompts](https://docs.anthropic.com/
|
|
545
|
+
* [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
|
|
546
546
|
*/
|
|
547
547
|
system?: string;
|
|
548
548
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { type Shims } from
|
|
5
|
-
import { getRuntime as getWebRuntime } from
|
|
4
|
+
import { type Shims } from "./registry.js";
|
|
5
|
+
import { getRuntime as getWebRuntime } from "./web-runtime.js";
|
|
6
6
|
import { ReadStream as FsReadStream } from 'node:fs';
|
|
7
7
|
|
|
8
8
|
export function getRuntime(): Shims {
|
package/src/_shims/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { manual } from
|
|
5
|
-
import * as auto from "./auto/types";
|
|
6
|
-
import { type RequestOptions } from
|
|
4
|
+
import { manual } from "./manual-types.js";
|
|
5
|
+
import * as auto from "./auto/types.js";
|
|
6
|
+
import { type RequestOptions } from "../core.js";
|
|
7
7
|
|
|
8
8
|
type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
|
|
9
9
|
|
package/src/_shims/index.mjs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
4
|
import * as shims from './registry.mjs';
|
|
5
|
-
import * as auto from "./auto/runtime";
|
|
5
|
+
import * as auto from "./auto/runtime.mjs";
|
|
6
6
|
if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
|
|
7
7
|
export * from './registry.mjs';
|
|
@@ -10,9 +10,9 @@ import { ReadStream as FsReadStream } from 'node:fs';
|
|
|
10
10
|
import { type Agent } from 'node:http';
|
|
11
11
|
import { FormDataEncoder } from 'form-data-encoder';
|
|
12
12
|
import { Readable } from 'node:stream';
|
|
13
|
-
import { type RequestOptions } from
|
|
14
|
-
import { MultipartBody } from
|
|
15
|
-
import { type Shims } from
|
|
13
|
+
import { type RequestOptions } from "../core.js";
|
|
14
|
+
import { MultipartBody } from "./MultipartBody.js";
|
|
15
|
+
import { type Shims } from "./registry.js";
|
|
16
16
|
|
|
17
17
|
// @ts-ignore (this package does not have proper export maps for this export)
|
|
18
18
|
import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.es2018.js';
|
package/src/_shims/registry.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Disclaimer: modules in _shims aren't intended to be imported by SDK users.
|
|
3
3
|
*/
|
|
4
|
-
import { MultipartBody } from
|
|
5
|
-
import { type RequestOptions } from
|
|
6
|
-
import { type Shims } from
|
|
4
|
+
import { MultipartBody } from "./MultipartBody.js";
|
|
5
|
+
import { type RequestOptions } from "../core.js";
|
|
6
|
+
import { type Shims } from "./registry.js";
|
|
7
7
|
|
|
8
8
|
export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims {
|
|
9
9
|
const recommendation =
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
type Token = {
|
|
2
|
+
type: string;
|
|
3
|
+
value: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const tokenize = (input: string) => {
|
|
7
|
+
let current = 0;
|
|
8
|
+
let tokens = [];
|
|
9
|
+
|
|
10
|
+
while (current < input.length) {
|
|
11
|
+
let char = input[current];
|
|
12
|
+
|
|
13
|
+
if (char === '\\') {
|
|
14
|
+
current++;
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (char === '{') {
|
|
19
|
+
tokens.push({
|
|
20
|
+
type: 'brace',
|
|
21
|
+
value: '{',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
current++;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (char === '}') {
|
|
29
|
+
tokens.push({
|
|
30
|
+
type: 'brace',
|
|
31
|
+
value: '}',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
current++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (char === '[') {
|
|
39
|
+
tokens.push({
|
|
40
|
+
type: 'paren',
|
|
41
|
+
value: '[',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
current++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (char === ']') {
|
|
49
|
+
tokens.push({
|
|
50
|
+
type: 'paren',
|
|
51
|
+
value: ']',
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
current++;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (char === ':') {
|
|
59
|
+
tokens.push({
|
|
60
|
+
type: 'separator',
|
|
61
|
+
value: ':',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
current++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (char === ',') {
|
|
69
|
+
tokens.push({
|
|
70
|
+
type: 'delimiter',
|
|
71
|
+
value: ',',
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
current++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (char === '"') {
|
|
79
|
+
let value = '';
|
|
80
|
+
let danglingQuote = false;
|
|
81
|
+
|
|
82
|
+
char = input[++current];
|
|
83
|
+
|
|
84
|
+
while (char !== '"') {
|
|
85
|
+
if (current === input.length) {
|
|
86
|
+
danglingQuote = true;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (char === '\\') {
|
|
91
|
+
current++;
|
|
92
|
+
if (current === input.length) {
|
|
93
|
+
danglingQuote = true;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
value += char + input[current];
|
|
97
|
+
char = input[++current];
|
|
98
|
+
} else {
|
|
99
|
+
value += char;
|
|
100
|
+
char = input[++current];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
char = input[++current];
|
|
105
|
+
|
|
106
|
+
if (!danglingQuote) {
|
|
107
|
+
tokens.push({
|
|
108
|
+
type: 'string',
|
|
109
|
+
value,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let WHITESPACE = /\s/;
|
|
116
|
+
if (char && WHITESPACE.test(char)) {
|
|
117
|
+
current++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let NUMBERS = /[0-9]/;
|
|
122
|
+
if ((char && NUMBERS.test(char)) || char === '-' || char === '.') {
|
|
123
|
+
let value = '';
|
|
124
|
+
|
|
125
|
+
if (char === '-') {
|
|
126
|
+
value += char;
|
|
127
|
+
char = input[++current];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
while ((char && NUMBERS.test(char)) || char === '.') {
|
|
131
|
+
value += char;
|
|
132
|
+
char = input[++current];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
tokens.push({
|
|
136
|
+
type: 'number',
|
|
137
|
+
value,
|
|
138
|
+
});
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let LETTERS = /[a-z]/i;
|
|
143
|
+
if (char && LETTERS.test(char)) {
|
|
144
|
+
let value = '';
|
|
145
|
+
|
|
146
|
+
while (char && LETTERS.test(char)) {
|
|
147
|
+
if (current === input.length) {
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
value += char;
|
|
151
|
+
char = input[++current];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (value == 'true' || value == 'false') {
|
|
155
|
+
tokens.push({
|
|
156
|
+
type: 'name',
|
|
157
|
+
value,
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
throw new Error(`Invalid token: ${value} is not a valid token!`);
|
|
161
|
+
}
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
current++;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return tokens;
|
|
169
|
+
},
|
|
170
|
+
strip = (tokens: Token[]): Token[] => {
|
|
171
|
+
if (tokens.length === 0) {
|
|
172
|
+
return tokens;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
let lastToken = tokens[tokens.length - 1]!;
|
|
176
|
+
|
|
177
|
+
switch (lastToken.type) {
|
|
178
|
+
case 'separator':
|
|
179
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
180
|
+
return strip(tokens);
|
|
181
|
+
break;
|
|
182
|
+
case 'number':
|
|
183
|
+
let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
|
|
184
|
+
if (lastCharacterOfLastToken === '.' || lastCharacterOfLastToken === '-') {
|
|
185
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
186
|
+
return strip(tokens);
|
|
187
|
+
}
|
|
188
|
+
case 'string':
|
|
189
|
+
let tokenBeforeTheLastToken = tokens[tokens.length - 2];
|
|
190
|
+
if (tokenBeforeTheLastToken?.type === 'delimiter') {
|
|
191
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
192
|
+
return strip(tokens);
|
|
193
|
+
} else if (tokenBeforeTheLastToken?.type === 'brace' && tokenBeforeTheLastToken.value === '{') {
|
|
194
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
195
|
+
return strip(tokens);
|
|
196
|
+
}
|
|
197
|
+
break;
|
|
198
|
+
case 'delimiter':
|
|
199
|
+
tokens = tokens.slice(0, tokens.length - 1);
|
|
200
|
+
return strip(tokens);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return tokens;
|
|
205
|
+
},
|
|
206
|
+
unstrip = (tokens: Token[]): Token[] => {
|
|
207
|
+
let tail: string[] = [];
|
|
208
|
+
|
|
209
|
+
tokens.map((token) => {
|
|
210
|
+
if (token.type === 'brace') {
|
|
211
|
+
if (token.value === '{') {
|
|
212
|
+
tail.push('}');
|
|
213
|
+
} else {
|
|
214
|
+
tail.splice(tail.lastIndexOf('}'), 1);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (token.type === 'paren') {
|
|
218
|
+
if (token.value === '[') {
|
|
219
|
+
tail.push(']');
|
|
220
|
+
} else {
|
|
221
|
+
tail.splice(tail.lastIndexOf(']'), 1);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (tail.length > 0) {
|
|
227
|
+
tail.reverse().map((item) => {
|
|
228
|
+
if (item === '}') {
|
|
229
|
+
tokens.push({
|
|
230
|
+
type: 'brace',
|
|
231
|
+
value: '}',
|
|
232
|
+
});
|
|
233
|
+
} else if (item === ']') {
|
|
234
|
+
tokens.push({
|
|
235
|
+
type: 'paren',
|
|
236
|
+
value: ']',
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return tokens;
|
|
243
|
+
},
|
|
244
|
+
generate = (tokens: Token[]): string => {
|
|
245
|
+
let output = '';
|
|
246
|
+
|
|
247
|
+
tokens.map((token) => {
|
|
248
|
+
switch (token.type) {
|
|
249
|
+
case 'string':
|
|
250
|
+
output += '"' + token.value + '"';
|
|
251
|
+
break;
|
|
252
|
+
default:
|
|
253
|
+
output += token.value;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return output;
|
|
259
|
+
},
|
|
260
|
+
partialParse = (input: string): unknown => JSON.parse(generate(unstrip(strip(tokenize(input)))));
|
|
261
|
+
|
|
262
|
+
export { partialParse };
|
package/src/core.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { VERSION } from
|
|
2
|
-
import { Stream } from
|
|
1
|
+
import { VERSION } from "./version.js";
|
|
2
|
+
import { Stream } from "./streaming.js";
|
|
3
3
|
import {
|
|
4
4
|
AnthropicError,
|
|
5
5
|
APIError,
|
|
6
6
|
APIConnectionError,
|
|
7
7
|
APIConnectionTimeoutError,
|
|
8
8
|
APIUserAbortError,
|
|
9
|
-
} from
|
|
9
|
+
} from "./error.js";
|
|
10
10
|
import {
|
|
11
11
|
kind as shimsKind,
|
|
12
12
|
type Readable,
|
|
@@ -17,15 +17,15 @@ import {
|
|
|
17
17
|
type RequestInit,
|
|
18
18
|
type Response,
|
|
19
19
|
type HeadersInit,
|
|
20
|
-
} from
|
|
20
|
+
} from "./_shims/index.js";
|
|
21
21
|
export { type Response };
|
|
22
|
-
import { isMultipartBody } from
|
|
22
|
+
import { isMultipartBody } from "./uploads.js";
|
|
23
23
|
export {
|
|
24
24
|
maybeMultipartFormRequestOptions,
|
|
25
25
|
multipartFormRequestOptions,
|
|
26
26
|
createForm,
|
|
27
27
|
type Uploadable,
|
|
28
|
-
} from
|
|
28
|
+
} from "./uploads.js";
|
|
29
29
|
|
|
30
30
|
export type Fetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
31
31
|
|
package/src/error.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import * as Core from
|
|
4
|
-
import * as Errors from
|
|
5
|
-
import { type Agent } from
|
|
6
|
-
import * as Uploads from
|
|
7
|
-
import * as API from "./resources/index";
|
|
3
|
+
import * as Core from "./core.js";
|
|
4
|
+
import * as Errors from "./error.js";
|
|
5
|
+
import { type Agent } from "./_shims/index.js";
|
|
6
|
+
import * as Uploads from "./uploads.js";
|
|
7
|
+
import * as API from "./resources/index.js";
|
|
8
8
|
|
|
9
9
|
export interface ClientOptions {
|
|
10
10
|
/**
|