@anthropic-ai/sdk 0.28.0 → 0.29.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 +35 -0
- package/README.md +76 -0
- package/core.d.ts +1 -1
- package/core.d.ts.map +1 -1
- package/core.js +1 -1
- package/core.js.map +1 -1
- package/core.mjs +1 -1
- package/core.mjs.map +1 -1
- package/index.d.mts +19 -0
- package/index.d.ts +19 -0
- package/index.d.ts.map +1 -1
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/index.mjs +2 -0
- package/index.mjs.map +1 -1
- package/internal/decoders/jsonl.d.ts +12 -0
- package/internal/decoders/jsonl.d.ts.map +1 -0
- package/internal/decoders/jsonl.js +35 -0
- package/internal/decoders/jsonl.js.map +1 -0
- package/internal/decoders/jsonl.mjs +31 -0
- package/internal/decoders/jsonl.mjs.map +1 -0
- package/internal/decoders/line.d.ts +20 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +88 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +84 -0
- package/internal/decoders/line.mjs.map +1 -0
- package/package.json +1 -1
- package/pagination.d.ts +26 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +54 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +50 -0
- package/pagination.mjs.map +1 -0
- package/resources/beta/beta.d.ts +79 -0
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +3 -0
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +3 -0
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.ts +2 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js +5 -3
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +2 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/batches.d.ts +242 -0
- package/resources/beta/messages/batches.d.ts.map +1 -0
- package/resources/beta/messages/batches.js +120 -0
- package/resources/beta/messages/batches.js.map +1 -0
- package/resources/beta/messages/batches.mjs +92 -0
- package/resources/beta/messages/batches.mjs.map +1 -0
- package/resources/beta/messages/index.d.ts +3 -0
- package/resources/beta/messages/index.d.ts.map +1 -0
- package/resources/beta/messages/index.js +10 -0
- package/resources/beta/messages/index.js.map +1 -0
- package/resources/beta/messages/index.mjs +4 -0
- package/resources/beta/messages/index.mjs.map +1 -0
- package/resources/beta/messages/messages.d.ts +663 -0
- package/resources/beta/messages/messages.d.ts.map +1 -0
- package/resources/beta/messages/messages.js +54 -0
- package/resources/beta/messages/messages.js.map +1 -0
- package/resources/beta/messages/messages.mjs +27 -0
- package/resources/beta/messages/messages.mjs.map +1 -0
- package/resources/beta/prompt-caching/messages.d.ts +40 -74
- package/resources/beta/prompt-caching/messages.d.ts.map +1 -1
- package/resources/beta/prompt-caching/messages.js +7 -3
- package/resources/beta/prompt-caching/messages.js.map +1 -1
- package/resources/beta/prompt-caching/messages.mjs +7 -3
- package/resources/beta/prompt-caching/messages.mjs.map +1 -1
- package/resources/completions.d.ts +3 -12
- package/resources/completions.d.ts.map +1 -1
- package/resources/completions.js.map +1 -1
- package/resources/completions.mjs.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/messages.d.ts +76 -55
- package/resources/messages.d.ts.map +1 -1
- package/resources/messages.js.map +1 -1
- package/resources/messages.mjs.map +1 -1
- package/src/core.ts +4 -2
- package/src/index.ts +20 -0
- package/src/internal/decoders/jsonl.ts +41 -0
- package/src/internal/decoders/line.ts +114 -0
- package/src/pagination.ts +84 -0
- package/src/resources/beta/beta.ts +104 -0
- package/src/resources/beta/index.ts +47 -1
- package/src/resources/beta/messages/batches.ts +393 -0
- package/src/resources/beta/messages/index.ts +53 -0
- package/src/resources/beta/messages/messages.ts +795 -0
- package/src/resources/beta/prompt-caching/messages.ts +45 -81
- package/src/resources/completions.ts +3 -12
- package/src/resources/index.ts +18 -1
- package/src/resources/messages.ts +82 -59
- package/src/streaming.ts +1 -111
- package/src/version.ts +1 -1
- package/streaming.d.ts.map +1 -1
- package/streaming.js +4 -85
- package/streaming.js.map +1 -1
- package/streaming.mjs +1 -82
- package/streaming.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -5,13 +5,12 @@ import { APIPromise } from "../../../core.js";
|
|
|
5
5
|
import * as Core from "../../../core.js";
|
|
6
6
|
import * as PromptCachingMessagesAPI from "./messages.js";
|
|
7
7
|
import * as MessagesAPI from "../../messages.js";
|
|
8
|
+
import * as BetaAPI from "../beta.js";
|
|
8
9
|
import { Stream } from "../../../streaming.js";
|
|
9
10
|
import { PromptCachingBetaMessageStream } from "../../../lib/PromptCachingBetaMessageStream.js";
|
|
10
11
|
|
|
11
12
|
export class Messages extends APIResource {
|
|
12
13
|
/**
|
|
13
|
-
* Create a Message.
|
|
14
|
-
*
|
|
15
14
|
* Send a structured list of input messages with text and/or image content, and the
|
|
16
15
|
* model will generate the next message in the conversation.
|
|
17
16
|
*
|
|
@@ -19,27 +18,31 @@ export class Messages extends APIResource {
|
|
|
19
18
|
* conversations.
|
|
20
19
|
*/
|
|
21
20
|
create(
|
|
22
|
-
|
|
21
|
+
params: MessageCreateParamsNonStreaming,
|
|
23
22
|
options?: Core.RequestOptions,
|
|
24
23
|
): APIPromise<PromptCachingBetaMessage>;
|
|
25
24
|
create(
|
|
26
|
-
|
|
25
|
+
params: MessageCreateParamsStreaming,
|
|
27
26
|
options?: Core.RequestOptions,
|
|
28
27
|
): APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>>;
|
|
29
28
|
create(
|
|
30
|
-
|
|
29
|
+
params: MessageCreateParamsBase,
|
|
31
30
|
options?: Core.RequestOptions,
|
|
32
31
|
): APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent> | PromptCachingBetaMessage>;
|
|
33
32
|
create(
|
|
34
|
-
|
|
33
|
+
params: MessageCreateParams,
|
|
35
34
|
options?: Core.RequestOptions,
|
|
36
35
|
): APIPromise<PromptCachingBetaMessage> | APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>> {
|
|
36
|
+
const { betas, ...body } = params;
|
|
37
37
|
return this._client.post('/v1/messages?beta=prompt_caching', {
|
|
38
38
|
body,
|
|
39
39
|
timeout: (this._client as any)._options.timeout ?? 600000,
|
|
40
40
|
...options,
|
|
41
|
-
headers: {
|
|
42
|
-
|
|
41
|
+
headers: {
|
|
42
|
+
'anthropic-beta': [...(betas ?? []), 'prompt-caching-2024-07-31'].toString(),
|
|
43
|
+
...options?.headers,
|
|
44
|
+
},
|
|
45
|
+
stream: params.stream ?? false,
|
|
43
46
|
}) as APIPromise<PromptCachingBetaMessage> | APIPromise<Stream<RawPromptCachingBetaMessageStreamEvent>>;
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -304,7 +307,7 @@ export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreat
|
|
|
304
307
|
|
|
305
308
|
export interface MessageCreateParamsBase {
|
|
306
309
|
/**
|
|
307
|
-
* The maximum number of tokens to generate before stopping.
|
|
310
|
+
* Body param: The maximum number of tokens to generate before stopping.
|
|
308
311
|
*
|
|
309
312
|
* Note that our models may stop _before_ reaching this maximum. This parameter
|
|
310
313
|
* only specifies the absolute maximum number of tokens to generate.
|
|
@@ -315,7 +318,7 @@ export interface MessageCreateParamsBase {
|
|
|
315
318
|
max_tokens: number;
|
|
316
319
|
|
|
317
320
|
/**
|
|
318
|
-
* Input messages.
|
|
321
|
+
* Body param: Input messages.
|
|
319
322
|
*
|
|
320
323
|
* Our models are trained to operate on alternating `user` and `assistant`
|
|
321
324
|
* conversational turns. When creating a new `Message`, you specify the prior
|
|
@@ -404,19 +407,19 @@ export interface MessageCreateParamsBase {
|
|
|
404
407
|
messages: Array<PromptCachingBetaMessageParam>;
|
|
405
408
|
|
|
406
409
|
/**
|
|
407
|
-
* The model that will complete your prompt.\n\nSee
|
|
410
|
+
* Body param: The model that will complete your prompt.\n\nSee
|
|
408
411
|
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
409
412
|
* details and options.
|
|
410
413
|
*/
|
|
411
414
|
model: MessagesAPI.Model;
|
|
412
415
|
|
|
413
416
|
/**
|
|
414
|
-
* An object describing metadata about the request.
|
|
417
|
+
* Body param: An object describing metadata about the request.
|
|
415
418
|
*/
|
|
416
|
-
metadata?:
|
|
419
|
+
metadata?: MessagesAPI.Metadata;
|
|
417
420
|
|
|
418
421
|
/**
|
|
419
|
-
* Custom text sequences that will cause the model to stop generating.
|
|
422
|
+
* Body param: Custom text sequences that will cause the model to stop generating.
|
|
420
423
|
*
|
|
421
424
|
* Our models will normally stop when they have naturally completed their turn,
|
|
422
425
|
* which will result in a response `stop_reason` of `"end_turn"`.
|
|
@@ -429,7 +432,8 @@ export interface MessageCreateParamsBase {
|
|
|
429
432
|
stop_sequences?: Array<string>;
|
|
430
433
|
|
|
431
434
|
/**
|
|
432
|
-
* Whether to incrementally stream the response using server-sent
|
|
435
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
436
|
+
* events.
|
|
433
437
|
*
|
|
434
438
|
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
435
439
|
* details.
|
|
@@ -437,7 +441,7 @@ export interface MessageCreateParamsBase {
|
|
|
437
441
|
stream?: boolean;
|
|
438
442
|
|
|
439
443
|
/**
|
|
440
|
-
* System prompt.
|
|
444
|
+
* Body param: System prompt.
|
|
441
445
|
*
|
|
442
446
|
* A system prompt is a way of providing context and instructions to Claude, such
|
|
443
447
|
* as specifying a particular goal or role. See our
|
|
@@ -446,7 +450,7 @@ export interface MessageCreateParamsBase {
|
|
|
446
450
|
system?: string | Array<PromptCachingBetaTextBlockParam>;
|
|
447
451
|
|
|
448
452
|
/**
|
|
449
|
-
* Amount of randomness injected into the response.
|
|
453
|
+
* Body param: Amount of randomness injected into the response.
|
|
450
454
|
*
|
|
451
455
|
* Defaults to `1.0`. Ranges from `0.0` to `1.0`. Use `temperature` closer to `0.0`
|
|
452
456
|
* for analytical / multiple choice, and closer to `1.0` for creative and
|
|
@@ -458,16 +462,13 @@ export interface MessageCreateParamsBase {
|
|
|
458
462
|
temperature?: number;
|
|
459
463
|
|
|
460
464
|
/**
|
|
461
|
-
* How the model should use the provided tools. The model can use a
|
|
462
|
-
* any available tool, or decide by itself.
|
|
465
|
+
* Body param: How the model should use the provided tools. The model can use a
|
|
466
|
+
* specific tool, any available tool, or decide by itself.
|
|
463
467
|
*/
|
|
464
|
-
tool_choice?:
|
|
465
|
-
| MessageCreateParams.ToolChoiceAuto
|
|
466
|
-
| MessageCreateParams.ToolChoiceAny
|
|
467
|
-
| MessageCreateParams.ToolChoiceTool;
|
|
468
|
+
tool_choice?: MessagesAPI.ToolChoice;
|
|
468
469
|
|
|
469
470
|
/**
|
|
470
|
-
* Definitions of tools that the model may use.
|
|
471
|
+
* Body param: Definitions of tools that the model may use.
|
|
471
472
|
*
|
|
472
473
|
* If you include `tools` in your API request, the model may return `tool_use`
|
|
473
474
|
* content blocks that represent the model's use of those tools. You can then run
|
|
@@ -539,7 +540,7 @@ export interface MessageCreateParamsBase {
|
|
|
539
540
|
tools?: Array<PromptCachingBetaTool>;
|
|
540
541
|
|
|
541
542
|
/**
|
|
542
|
-
* Only sample from the top K options for each subsequent token.
|
|
543
|
+
* Body param: Only sample from the top K options for each subsequent token.
|
|
543
544
|
*
|
|
544
545
|
* Used to remove "long tail" low probability responses.
|
|
545
546
|
* [Learn more technical details here](https://towardsdatascience.com/how-to-sample-from-language-models-682bceb97277).
|
|
@@ -550,7 +551,7 @@ export interface MessageCreateParamsBase {
|
|
|
550
551
|
top_k?: number;
|
|
551
552
|
|
|
552
553
|
/**
|
|
553
|
-
* Use nucleus sampling.
|
|
554
|
+
* Body param: Use nucleus sampling.
|
|
554
555
|
*
|
|
555
556
|
* In nucleus sampling, we compute the cumulative distribution over all the options
|
|
556
557
|
* for each subsequent token in decreasing probability order and cut it off once it
|
|
@@ -561,72 +562,33 @@ export interface MessageCreateParamsBase {
|
|
|
561
562
|
* `temperature`.
|
|
562
563
|
*/
|
|
563
564
|
top_p?: number;
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Header param: Optional header to specify the beta version(s) you want to use.
|
|
568
|
+
*/
|
|
569
|
+
betas?: Array<BetaAPI.AnthropicBeta>;
|
|
564
570
|
}
|
|
565
571
|
|
|
566
572
|
export namespace MessageCreateParams {
|
|
567
573
|
/**
|
|
568
|
-
*
|
|
569
|
-
*/
|
|
570
|
-
export
|
|
571
|
-
/**
|
|
572
|
-
* An external identifier for the user who is associated with the request.
|
|
573
|
-
*
|
|
574
|
-
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
|
575
|
-
* this id to help detect abuse. Do not include any identifying information such as
|
|
576
|
-
* name, email address, or phone number.
|
|
577
|
-
*/
|
|
578
|
-
user_id?: string | null;
|
|
579
|
-
}
|
|
574
|
+
* @deprecated use `Anthropic.Messages.Metadata` instead
|
|
575
|
+
*/
|
|
576
|
+
export type Metadata = MessagesAPI.Metadata;
|
|
580
577
|
|
|
581
578
|
/**
|
|
582
|
-
*
|
|
579
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
|
|
583
580
|
*/
|
|
584
|
-
export
|
|
585
|
-
type: 'auto';
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* Whether to disable parallel tool use.
|
|
589
|
-
*
|
|
590
|
-
* Defaults to `false`. If set to `true`, the model will output at most one tool
|
|
591
|
-
* use.
|
|
592
|
-
*/
|
|
593
|
-
disable_parallel_tool_use?: boolean;
|
|
594
|
-
}
|
|
581
|
+
export type ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;
|
|
595
582
|
|
|
596
583
|
/**
|
|
597
|
-
*
|
|
584
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceAny` instead
|
|
598
585
|
*/
|
|
599
|
-
export
|
|
600
|
-
type: 'any';
|
|
601
|
-
|
|
602
|
-
/**
|
|
603
|
-
* Whether to disable parallel tool use.
|
|
604
|
-
*
|
|
605
|
-
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
606
|
-
* use.
|
|
607
|
-
*/
|
|
608
|
-
disable_parallel_tool_use?: boolean;
|
|
609
|
-
}
|
|
586
|
+
export type ToolChoiceAny = MessagesAPI.ToolChoiceAny;
|
|
610
587
|
|
|
611
588
|
/**
|
|
612
|
-
*
|
|
589
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceTool` instead
|
|
613
590
|
*/
|
|
614
|
-
export
|
|
615
|
-
/**
|
|
616
|
-
* The name of the tool to use.
|
|
617
|
-
*/
|
|
618
|
-
name: string;
|
|
619
|
-
|
|
620
|
-
type: 'tool';
|
|
621
|
-
|
|
622
|
-
/**
|
|
623
|
-
* Whether to disable parallel tool use.
|
|
624
|
-
*
|
|
625
|
-
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
626
|
-
* use.
|
|
627
|
-
*/
|
|
628
|
-
disable_parallel_tool_use?: boolean;
|
|
629
|
-
}
|
|
591
|
+
export type ToolChoiceTool = MessagesAPI.ToolChoiceTool;
|
|
630
592
|
|
|
631
593
|
export type MessageCreateParamsNonStreaming = PromptCachingMessagesAPI.MessageCreateParamsNonStreaming;
|
|
632
594
|
export type MessageCreateParamsStreaming = PromptCachingMessagesAPI.MessageCreateParamsStreaming;
|
|
@@ -634,7 +596,8 @@ export namespace MessageCreateParams {
|
|
|
634
596
|
|
|
635
597
|
export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase {
|
|
636
598
|
/**
|
|
637
|
-
* Whether to incrementally stream the response using server-sent
|
|
599
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
600
|
+
* events.
|
|
638
601
|
*
|
|
639
602
|
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
640
603
|
* details.
|
|
@@ -644,7 +607,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
|
|
|
644
607
|
|
|
645
608
|
export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
|
|
646
609
|
/**
|
|
647
|
-
* Whether to incrementally stream the response using server-sent
|
|
610
|
+
* Body param: Whether to incrementally stream the response using server-sent
|
|
611
|
+
* events.
|
|
648
612
|
*
|
|
649
613
|
* See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
|
|
650
614
|
* details.
|
|
@@ -117,7 +117,7 @@ export interface CompletionCreateParamsBase {
|
|
|
117
117
|
/**
|
|
118
118
|
* An object describing metadata about the request.
|
|
119
119
|
*/
|
|
120
|
-
metadata?:
|
|
120
|
+
metadata?: MessagesAPI.Metadata;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
123
|
* Sequences that will cause the model to stop generating.
|
|
@@ -174,18 +174,9 @@ export interface CompletionCreateParamsBase {
|
|
|
174
174
|
|
|
175
175
|
export namespace CompletionCreateParams {
|
|
176
176
|
/**
|
|
177
|
-
*
|
|
177
|
+
* @deprecated use `Anthropic.Messages.Metadata` instead
|
|
178
178
|
*/
|
|
179
|
-
export
|
|
180
|
-
/**
|
|
181
|
-
* An external identifier for the user who is associated with the request.
|
|
182
|
-
*
|
|
183
|
-
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
|
184
|
-
* this id to help detect abuse. Do not include any identifying information such as
|
|
185
|
-
* name, email address, or phone number.
|
|
186
|
-
*/
|
|
187
|
-
user_id?: string | null;
|
|
188
|
-
}
|
|
179
|
+
export type Metadata = MessagesAPI.Metadata;
|
|
189
180
|
|
|
190
181
|
export type CompletionCreateParamsNonStreaming = CompletionsAPI.CompletionCreateParamsNonStreaming;
|
|
191
182
|
export type CompletionCreateParamsStreaming = CompletionsAPI.CompletionCreateParamsStreaming;
|
package/src/resources/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
AnthropicBeta,
|
|
5
|
+
BetaAPIError,
|
|
6
|
+
BetaAuthenticationError,
|
|
7
|
+
BetaError,
|
|
8
|
+
BetaErrorResponse,
|
|
9
|
+
BetaInvalidRequestError,
|
|
10
|
+
BetaNotFoundError,
|
|
11
|
+
BetaOverloadedError,
|
|
12
|
+
BetaPermissionError,
|
|
13
|
+
BetaRateLimitError,
|
|
14
|
+
Beta,
|
|
15
|
+
} from "./beta/beta.js";
|
|
4
16
|
export {
|
|
5
17
|
Completion,
|
|
6
18
|
CompletionCreateParams,
|
|
@@ -23,6 +35,7 @@ export {
|
|
|
23
35
|
MessageStartEvent,
|
|
24
36
|
MessageStopEvent,
|
|
25
37
|
MessageStreamEvent,
|
|
38
|
+
Metadata,
|
|
26
39
|
Model,
|
|
27
40
|
RawContentBlockDeltaEvent,
|
|
28
41
|
RawContentBlockStartEvent,
|
|
@@ -35,6 +48,10 @@ export {
|
|
|
35
48
|
TextBlockParam,
|
|
36
49
|
TextDelta,
|
|
37
50
|
Tool,
|
|
51
|
+
ToolChoice,
|
|
52
|
+
ToolChoiceAny,
|
|
53
|
+
ToolChoiceAuto,
|
|
54
|
+
ToolChoiceTool,
|
|
38
55
|
ToolResultBlockParam,
|
|
39
56
|
ToolUseBlock,
|
|
40
57
|
ToolUseBlockParam,
|
|
@@ -11,8 +11,6 @@ export { MessageStream } from "../lib/MessageStream.js";
|
|
|
11
11
|
|
|
12
12
|
export class Messages extends APIResource {
|
|
13
13
|
/**
|
|
14
|
-
* Create a Message.
|
|
15
|
-
*
|
|
16
14
|
* Send a structured list of input messages with text and/or image content, and the
|
|
17
15
|
* model will generate the next message in the conversation.
|
|
18
16
|
*
|
|
@@ -213,6 +211,17 @@ export type MessageStopEvent = RawMessageStopEvent;
|
|
|
213
211
|
|
|
214
212
|
export type MessageStreamEvent = RawMessageStreamEvent;
|
|
215
213
|
|
|
214
|
+
export interface Metadata {
|
|
215
|
+
/**
|
|
216
|
+
* An external identifier for the user who is associated with the request.
|
|
217
|
+
*
|
|
218
|
+
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
|
219
|
+
* this id to help detect abuse. Do not include any identifying information such as
|
|
220
|
+
* name, email address, or phone number.
|
|
221
|
+
*/
|
|
222
|
+
user_id?: string | null;
|
|
223
|
+
}
|
|
224
|
+
|
|
216
225
|
/**
|
|
217
226
|
* The model that will complete your prompt.\n\nSee
|
|
218
227
|
* [models](https://docs.anthropic.com/en/docs/models-overview) for additional
|
|
@@ -365,6 +374,62 @@ export namespace Tool {
|
|
|
365
374
|
}
|
|
366
375
|
}
|
|
367
376
|
|
|
377
|
+
/**
|
|
378
|
+
* How the model should use the provided tools. The model can use a specific tool,
|
|
379
|
+
* any available tool, or decide by itself.
|
|
380
|
+
*/
|
|
381
|
+
export type ToolChoice = ToolChoiceAuto | ToolChoiceAny | ToolChoiceTool;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* The model will use any available tools.
|
|
385
|
+
*/
|
|
386
|
+
export interface ToolChoiceAny {
|
|
387
|
+
type: 'any';
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Whether to disable parallel tool use.
|
|
391
|
+
*
|
|
392
|
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
393
|
+
* use.
|
|
394
|
+
*/
|
|
395
|
+
disable_parallel_tool_use?: boolean;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* The model will automatically decide whether to use tools.
|
|
400
|
+
*/
|
|
401
|
+
export interface ToolChoiceAuto {
|
|
402
|
+
type: 'auto';
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Whether to disable parallel tool use.
|
|
406
|
+
*
|
|
407
|
+
* Defaults to `false`. If set to `true`, the model will output at most one tool
|
|
408
|
+
* use.
|
|
409
|
+
*/
|
|
410
|
+
disable_parallel_tool_use?: boolean;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* The model will use the specified tool with `tool_choice.name`.
|
|
415
|
+
*/
|
|
416
|
+
export interface ToolChoiceTool {
|
|
417
|
+
/**
|
|
418
|
+
* The name of the tool to use.
|
|
419
|
+
*/
|
|
420
|
+
name: string;
|
|
421
|
+
|
|
422
|
+
type: 'tool';
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Whether to disable parallel tool use.
|
|
426
|
+
*
|
|
427
|
+
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
428
|
+
* use.
|
|
429
|
+
*/
|
|
430
|
+
disable_parallel_tool_use?: boolean;
|
|
431
|
+
}
|
|
432
|
+
|
|
368
433
|
export interface ToolResultBlockParam {
|
|
369
434
|
tool_use_id: string;
|
|
370
435
|
|
|
@@ -520,7 +585,7 @@ export interface MessageCreateParamsBase {
|
|
|
520
585
|
/**
|
|
521
586
|
* An object describing metadata about the request.
|
|
522
587
|
*/
|
|
523
|
-
metadata?:
|
|
588
|
+
metadata?: Metadata;
|
|
524
589
|
|
|
525
590
|
/**
|
|
526
591
|
* Custom text sequences that will cause the model to stop generating.
|
|
@@ -568,10 +633,7 @@ export interface MessageCreateParamsBase {
|
|
|
568
633
|
* How the model should use the provided tools. The model can use a specific tool,
|
|
569
634
|
* any available tool, or decide by itself.
|
|
570
635
|
*/
|
|
571
|
-
tool_choice?:
|
|
572
|
-
| MessageCreateParams.ToolChoiceAuto
|
|
573
|
-
| MessageCreateParams.ToolChoiceAny
|
|
574
|
-
| MessageCreateParams.ToolChoiceTool;
|
|
636
|
+
tool_choice?: ToolChoice;
|
|
575
637
|
|
|
576
638
|
/**
|
|
577
639
|
* Definitions of tools that the model may use.
|
|
@@ -672,68 +734,24 @@ export interface MessageCreateParamsBase {
|
|
|
672
734
|
|
|
673
735
|
export namespace MessageCreateParams {
|
|
674
736
|
/**
|
|
675
|
-
*
|
|
737
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
|
|
676
738
|
*/
|
|
677
|
-
export
|
|
678
|
-
/**
|
|
679
|
-
* An external identifier for the user who is associated with the request.
|
|
680
|
-
*
|
|
681
|
-
* This should be a uuid, hash value, or other opaque identifier. Anthropic may use
|
|
682
|
-
* this id to help detect abuse. Do not include any identifying information such as
|
|
683
|
-
* name, email address, or phone number.
|
|
684
|
-
*/
|
|
685
|
-
user_id?: string | null;
|
|
686
|
-
}
|
|
739
|
+
export type Metadata = MessagesAPI.Metadata;
|
|
687
740
|
|
|
688
741
|
/**
|
|
689
|
-
*
|
|
742
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceAuto` instead
|
|
690
743
|
*/
|
|
691
|
-
export
|
|
692
|
-
type: 'auto';
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Whether to disable parallel tool use.
|
|
696
|
-
*
|
|
697
|
-
* Defaults to `false`. If set to `true`, the model will output at most one tool
|
|
698
|
-
* use.
|
|
699
|
-
*/
|
|
700
|
-
disable_parallel_tool_use?: boolean;
|
|
701
|
-
}
|
|
744
|
+
export type ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;
|
|
702
745
|
|
|
703
746
|
/**
|
|
704
|
-
*
|
|
747
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceAny` instead
|
|
705
748
|
*/
|
|
706
|
-
export
|
|
707
|
-
type: 'any';
|
|
708
|
-
|
|
709
|
-
/**
|
|
710
|
-
* Whether to disable parallel tool use.
|
|
711
|
-
*
|
|
712
|
-
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
713
|
-
* use.
|
|
714
|
-
*/
|
|
715
|
-
disable_parallel_tool_use?: boolean;
|
|
716
|
-
}
|
|
749
|
+
export type ToolChoiceAny = MessagesAPI.ToolChoiceAny;
|
|
717
750
|
|
|
718
751
|
/**
|
|
719
|
-
*
|
|
752
|
+
* @deprecated use `Anthropic.Messages.ToolChoiceTool` instead
|
|
720
753
|
*/
|
|
721
|
-
export
|
|
722
|
-
/**
|
|
723
|
-
* The name of the tool to use.
|
|
724
|
-
*/
|
|
725
|
-
name: string;
|
|
726
|
-
|
|
727
|
-
type: 'tool';
|
|
728
|
-
|
|
729
|
-
/**
|
|
730
|
-
* Whether to disable parallel tool use.
|
|
731
|
-
*
|
|
732
|
-
* Defaults to `false`. If set to `true`, the model will output exactly one tool
|
|
733
|
-
* use.
|
|
734
|
-
*/
|
|
735
|
-
disable_parallel_tool_use?: boolean;
|
|
736
|
-
}
|
|
754
|
+
export type ToolChoiceTool = MessagesAPI.ToolChoiceTool;
|
|
737
755
|
|
|
738
756
|
export type MessageCreateParamsNonStreaming = MessagesAPI.MessageCreateParamsNonStreaming;
|
|
739
757
|
export type MessageCreateParamsStreaming = MessagesAPI.MessageCreateParamsStreaming;
|
|
@@ -776,6 +794,7 @@ export namespace Messages {
|
|
|
776
794
|
export import MessageStartEvent = MessagesAPI.MessageStartEvent;
|
|
777
795
|
export import MessageStopEvent = MessagesAPI.MessageStopEvent;
|
|
778
796
|
export import MessageStreamEvent = MessagesAPI.MessageStreamEvent;
|
|
797
|
+
export import Metadata = MessagesAPI.Metadata;
|
|
779
798
|
export import Model = MessagesAPI.Model;
|
|
780
799
|
export import RawContentBlockDeltaEvent = MessagesAPI.RawContentBlockDeltaEvent;
|
|
781
800
|
export import RawContentBlockStartEvent = MessagesAPI.RawContentBlockStartEvent;
|
|
@@ -788,6 +807,10 @@ export namespace Messages {
|
|
|
788
807
|
export import TextBlockParam = MessagesAPI.TextBlockParam;
|
|
789
808
|
export import TextDelta = MessagesAPI.TextDelta;
|
|
790
809
|
export import Tool = MessagesAPI.Tool;
|
|
810
|
+
export import ToolChoice = MessagesAPI.ToolChoice;
|
|
811
|
+
export import ToolChoiceAny = MessagesAPI.ToolChoiceAny;
|
|
812
|
+
export import ToolChoiceAuto = MessagesAPI.ToolChoiceAuto;
|
|
813
|
+
export import ToolChoiceTool = MessagesAPI.ToolChoiceTool;
|
|
791
814
|
export import ToolResultBlockParam = MessagesAPI.ToolResultBlockParam;
|
|
792
815
|
export import ToolUseBlock = MessagesAPI.ToolUseBlock;
|
|
793
816
|
export import ToolUseBlockParam = MessagesAPI.ToolUseBlockParam;
|
package/src/streaming.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReadableStream, type Response } from "./_shims/index.js";
|
|
2
2
|
import { AnthropicError } from "./error.js";
|
|
3
|
+
import { LineDecoder } from "./internal/decoders/line.js";
|
|
3
4
|
|
|
4
5
|
import { createResponseHeaders } from "./core.js";
|
|
5
6
|
import { APIError } from "./error.js";
|
|
@@ -345,117 +346,6 @@ class SSEDecoder {
|
|
|
345
346
|
}
|
|
346
347
|
}
|
|
347
348
|
|
|
348
|
-
/**
|
|
349
|
-
* A re-implementation of httpx's `LineDecoder` in Python that handles incrementally
|
|
350
|
-
* reading lines from text.
|
|
351
|
-
*
|
|
352
|
-
* https://github.com/encode/httpx/blob/920333ea98118e9cf617f246905d7b202510941c/httpx/_decoders.py#L258
|
|
353
|
-
*/
|
|
354
|
-
class LineDecoder {
|
|
355
|
-
// prettier-ignore
|
|
356
|
-
static NEWLINE_CHARS = new Set(['\n', '\r']);
|
|
357
|
-
static NEWLINE_REGEXP = /\r\n|[\n\r]/g;
|
|
358
|
-
|
|
359
|
-
buffer: string[];
|
|
360
|
-
trailingCR: boolean;
|
|
361
|
-
textDecoder: any; // TextDecoder found in browsers; not typed to avoid pulling in either "dom" or "node" types.
|
|
362
|
-
|
|
363
|
-
constructor() {
|
|
364
|
-
this.buffer = [];
|
|
365
|
-
this.trailingCR = false;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
decode(chunk: Bytes): string[] {
|
|
369
|
-
let text = this.decodeText(chunk);
|
|
370
|
-
|
|
371
|
-
if (this.trailingCR) {
|
|
372
|
-
text = '\r' + text;
|
|
373
|
-
this.trailingCR = false;
|
|
374
|
-
}
|
|
375
|
-
if (text.endsWith('\r')) {
|
|
376
|
-
this.trailingCR = true;
|
|
377
|
-
text = text.slice(0, -1);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
if (!text) {
|
|
381
|
-
return [];
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const trailingNewline = LineDecoder.NEWLINE_CHARS.has(text[text.length - 1] || '');
|
|
385
|
-
let lines = text.split(LineDecoder.NEWLINE_REGEXP);
|
|
386
|
-
|
|
387
|
-
// if there is a trailing new line then the last entry will be an empty
|
|
388
|
-
// string which we don't care about
|
|
389
|
-
if (trailingNewline) {
|
|
390
|
-
lines.pop();
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
if (lines.length === 1 && !trailingNewline) {
|
|
394
|
-
this.buffer.push(lines[0]!);
|
|
395
|
-
return [];
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (this.buffer.length > 0) {
|
|
399
|
-
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
400
|
-
this.buffer = [];
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (!trailingNewline) {
|
|
404
|
-
this.buffer = [lines.pop() || ''];
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return lines;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
decodeText(bytes: Bytes): string {
|
|
411
|
-
if (bytes == null) return '';
|
|
412
|
-
if (typeof bytes === 'string') return bytes;
|
|
413
|
-
|
|
414
|
-
// Node:
|
|
415
|
-
if (typeof Buffer !== 'undefined') {
|
|
416
|
-
if (bytes instanceof Buffer) {
|
|
417
|
-
return bytes.toString();
|
|
418
|
-
}
|
|
419
|
-
if (bytes instanceof Uint8Array) {
|
|
420
|
-
return Buffer.from(bytes).toString();
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
throw new AnthropicError(
|
|
424
|
-
`Unexpected: received non-Uint8Array (${bytes.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`,
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Browser
|
|
429
|
-
if (typeof TextDecoder !== 'undefined') {
|
|
430
|
-
if (bytes instanceof Uint8Array || bytes instanceof ArrayBuffer) {
|
|
431
|
-
this.textDecoder ??= new TextDecoder('utf8');
|
|
432
|
-
return this.textDecoder.decode(bytes);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
throw new AnthropicError(
|
|
436
|
-
`Unexpected: received non-Uint8Array/ArrayBuffer (${
|
|
437
|
-
(bytes as any).constructor.name
|
|
438
|
-
}) in a web platform. Please report this error.`,
|
|
439
|
-
);
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
throw new AnthropicError(
|
|
443
|
-
`Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.`,
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
flush(): string[] {
|
|
448
|
-
if (!this.buffer.length && !this.trailingCR) {
|
|
449
|
-
return [];
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const lines = [this.buffer.join('')];
|
|
453
|
-
this.buffer = [];
|
|
454
|
-
this.trailingCR = false;
|
|
455
|
-
return lines;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
349
|
/** This is an internal helper function that's just used for testing */
|
|
460
350
|
export function _decodeChunks(chunks: string[]): string[] {
|
|
461
351
|
const decoder = new LineDecoder();
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.29.1'; // x-release-please-version
|
package/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["src/streaming.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAS/D,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACf,CAAC;AAEF,qBAAa,MAAM,CAAC,IAAI,CAAE,YAAW,aAAa,CAAC,IAAI,CAAC;IAIpD,OAAO,CAAC,QAAQ;IAHlB,UAAU,EAAE,eAAe,CAAC;gBAGlB,QAAQ,EAAE,MAAM,aAAa,CAAC,IAAI,CAAC,EAC3C,UAAU,EAAE,eAAe;IAK7B,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,eAAe;IAiE5E;;;OAGG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,eAAe;IA2C3F,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,IAAI,CAAC;IAI7C;;;OAGG;IACH,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IAwBnC;;;;OAIG;IACH,gBAAgB,IAAI,cAAc;CA0BnC;AAED,wBAAuB,gBAAgB,CACrC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,eAAe,GAC1B,cAAc,CAAC,eAAe,EAAE,IAAI,EAAE,OAAO,CAAC,CAqBhD;AA0HD,uEAAuE;AACvE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAQxD;AAWD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAyBpF"}
|