@anthropic-ai/sdk 0.35.0 → 0.36.3
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 +47 -0
- package/index.d.mts +2 -2
- package/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js.map +1 -1
- package/index.mjs.map +1 -1
- package/internal/decoders/jsonl.js +2 -2
- package/internal/decoders/jsonl.js.map +1 -1
- package/internal/decoders/jsonl.mjs +2 -2
- package/internal/decoders/jsonl.mjs.map +1 -1
- package/internal/stream-utils.d.ts +8 -0
- package/internal/stream-utils.d.ts.map +1 -0
- package/internal/stream-utils.js +39 -0
- package/internal/stream-utils.js.map +1 -0
- package/internal/stream-utils.mjs +35 -0
- package/internal/stream-utils.mjs.map +1 -0
- package/lib/BetaMessageStream.d.ts +3 -1
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +62 -24
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +62 -24
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.ts +3 -1
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +62 -24
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +62 -24
- package/lib/MessageStream.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/beta/beta.d.ts +2 -2
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/messages/batches.d.ts +8 -3
- package/resources/beta/messages/batches.d.ts.map +1 -1
- package/resources/beta/messages/batches.js.map +1 -1
- package/resources/beta/messages/batches.mjs.map +1 -1
- package/resources/beta/messages/index.d.ts +1 -1
- package/resources/beta/messages/index.d.ts.map +1 -1
- package/resources/beta/messages/index.js.map +1 -1
- package/resources/beta/messages/index.mjs.map +1 -1
- package/resources/beta/messages/messages.d.ts +82 -3
- package/resources/beta/messages/messages.d.ts.map +1 -1
- package/resources/beta/messages/messages.js.map +1 -1
- package/resources/beta/messages/messages.mjs.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/messages/batches.d.ts +8 -3
- package/resources/messages/batches.d.ts.map +1 -1
- package/resources/messages/batches.js +4 -3
- package/resources/messages/batches.js.map +1 -1
- package/resources/messages/batches.mjs +4 -3
- package/resources/messages/batches.mjs.map +1 -1
- package/resources/messages/index.d.ts +1 -1
- package/resources/messages/index.d.ts.map +1 -1
- package/resources/messages/index.js.map +1 -1
- package/resources/messages/index.mjs.map +1 -1
- package/resources/messages/messages.d.ts +82 -3
- package/resources/messages/messages.d.ts.map +1 -1
- package/resources/messages/messages.js.map +1 -1
- package/resources/messages/messages.mjs.map +1 -1
- package/src/index.ts +26 -0
- package/src/internal/decoders/jsonl.ts +2 -2
- package/src/internal/stream-utils.ts +32 -0
- package/src/lib/BetaMessageStream.ts +67 -22
- package/src/lib/MessageStream.ts +68 -22
- package/src/resources/beta/beta.ts +26 -0
- package/src/resources/beta/index.ts +13 -0
- package/src/resources/beta/messages/batches.ts +8 -3
- package/src/resources/beta/messages/index.ts +13 -0
- package/src/resources/beta/messages/messages.ts +152 -2
- package/src/resources/index.ts +13 -0
- package/src/resources/messages/batches.ts +8 -3
- package/src/resources/messages/index.ts +13 -0
- package/src/resources/messages/messages.ts +149 -2
- package/src/streaming.ts +3 -35
- package/src/version.ts +1 -1
- package/streaming.d.ts +0 -7
- package/streaming.d.ts.map +1 -1
- package/streaming.js +4 -38
- package/streaming.js.map +1 -1
- package/streaming.mjs +3 -36
- package/streaming.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/lib/MessageStream.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type MessageCreateParams,
|
|
10
10
|
type MessageCreateParamsBase,
|
|
11
11
|
type TextBlock,
|
|
12
|
+
type TextCitation,
|
|
12
13
|
} from "../resources/messages.js";
|
|
13
14
|
import { type ReadableStream, type Response } from "../_shims/index.js";
|
|
14
15
|
import { Stream } from "../streaming.js";
|
|
@@ -18,6 +19,7 @@ export interface MessageStreamEvents {
|
|
|
18
19
|
connect: () => void;
|
|
19
20
|
streamEvent: (event: MessageStreamEvent, snapshot: Message) => void;
|
|
20
21
|
text: (textDelta: string, textSnapshot: string) => void;
|
|
22
|
+
citation: (citation: TextCitation, citationsSnapshot: TextCitation[]) => void;
|
|
21
23
|
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
|
|
22
24
|
message: (message: Message) => void;
|
|
23
25
|
contentBlock: (content: ContentBlock) => void;
|
|
@@ -55,6 +57,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
55
57
|
#errored = false;
|
|
56
58
|
#aborted = false;
|
|
57
59
|
#catchingPromiseCreated = false;
|
|
60
|
+
#response: Response | null | undefined;
|
|
58
61
|
#request_id: string | null | undefined;
|
|
59
62
|
|
|
60
63
|
constructor() {
|
|
@@ -76,6 +79,10 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
76
79
|
this.#endPromise.catch(() => {});
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
get response(): Response | null | undefined {
|
|
83
|
+
return this.#response;
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
get request_id(): string | null | undefined {
|
|
80
87
|
return this.#request_id;
|
|
81
88
|
}
|
|
@@ -183,6 +190,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
183
190
|
|
|
184
191
|
protected _connected(response: Response | null) {
|
|
185
192
|
if (this.ended) return;
|
|
193
|
+
this.#response = response;
|
|
186
194
|
this.#request_id = response?.headers.get('request-id');
|
|
187
195
|
this.#resolveConnectedPromise(response);
|
|
188
196
|
this._emit('connect');
|
|
@@ -407,12 +415,27 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
407
415
|
switch (event.type) {
|
|
408
416
|
case 'content_block_delta': {
|
|
409
417
|
const content = messageSnapshot.content.at(-1)!;
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
418
|
+
switch (event.delta.type) {
|
|
419
|
+
case 'text_delta': {
|
|
420
|
+
if (content.type === 'text') {
|
|
421
|
+
this._emit('text', event.delta.text, content.text || '');
|
|
422
|
+
}
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
case 'citations_delta': {
|
|
426
|
+
if (content.type === 'text') {
|
|
427
|
+
this._emit('citation', event.delta.citation, content.citations ?? []);
|
|
428
|
+
}
|
|
429
|
+
break;
|
|
415
430
|
}
|
|
431
|
+
case 'input_json_delta': {
|
|
432
|
+
if (content.type === 'tool_use' && content.input) {
|
|
433
|
+
this._emit('inputJson', event.delta.partial_json, content.input);
|
|
434
|
+
}
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
default:
|
|
438
|
+
checkNever(event.delta);
|
|
416
439
|
}
|
|
417
440
|
break;
|
|
418
441
|
}
|
|
@@ -499,25 +522,45 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
499
522
|
return snapshot;
|
|
500
523
|
case 'content_block_delta': {
|
|
501
524
|
const snapshotContent = snapshot.content.at(event.index);
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
jsonBuf += event.delta.partial_json;
|
|
510
|
-
|
|
511
|
-
Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
|
|
512
|
-
value: jsonBuf,
|
|
513
|
-
enumerable: false,
|
|
514
|
-
writable: true,
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
if (jsonBuf) {
|
|
518
|
-
snapshotContent.input = partialParse(jsonBuf);
|
|
525
|
+
|
|
526
|
+
switch (event.delta.type) {
|
|
527
|
+
case 'text_delta': {
|
|
528
|
+
if (snapshotContent?.type === 'text') {
|
|
529
|
+
snapshotContent.text += event.delta.text;
|
|
530
|
+
}
|
|
531
|
+
break;
|
|
519
532
|
}
|
|
533
|
+
case 'citations_delta': {
|
|
534
|
+
if (snapshotContent?.type === 'text') {
|
|
535
|
+
snapshotContent.citations ??= [];
|
|
536
|
+
snapshotContent.citations.push(event.delta.citation);
|
|
537
|
+
}
|
|
538
|
+
break;
|
|
539
|
+
}
|
|
540
|
+
case 'input_json_delta': {
|
|
541
|
+
if (snapshotContent?.type === 'tool_use') {
|
|
542
|
+
// we need to keep track of the raw JSON string as well so that we can
|
|
543
|
+
// re-parse it for each delta, for now we just store it as an untyped
|
|
544
|
+
// non-enumerable property on the snapshot
|
|
545
|
+
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
|
|
546
|
+
jsonBuf += event.delta.partial_json;
|
|
547
|
+
|
|
548
|
+
Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
|
|
549
|
+
value: jsonBuf,
|
|
550
|
+
enumerable: false,
|
|
551
|
+
writable: true,
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
if (jsonBuf) {
|
|
555
|
+
snapshotContent.input = partialParse(jsonBuf);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
default:
|
|
561
|
+
checkNever(event.delta);
|
|
520
562
|
}
|
|
563
|
+
|
|
521
564
|
return snapshot;
|
|
522
565
|
}
|
|
523
566
|
case 'content_block_stop':
|
|
@@ -591,3 +634,6 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
591
634
|
return stream.toReadableStream();
|
|
592
635
|
}
|
|
593
636
|
}
|
|
637
|
+
|
|
638
|
+
// used to ensure exhaustive case matching without throwing a runtime error
|
|
639
|
+
function checkNever(x: never) {}
|
|
@@ -8,8 +8,18 @@ import {
|
|
|
8
8
|
BetaBase64PDFBlock,
|
|
9
9
|
BetaBase64PDFSource,
|
|
10
10
|
BetaCacheControlEphemeral,
|
|
11
|
+
BetaCitationCharLocation,
|
|
12
|
+
BetaCitationCharLocationParam,
|
|
13
|
+
BetaCitationContentBlockLocation,
|
|
14
|
+
BetaCitationContentBlockLocationParam,
|
|
15
|
+
BetaCitationPageLocation,
|
|
16
|
+
BetaCitationPageLocationParam,
|
|
17
|
+
BetaCitationsConfigParam,
|
|
18
|
+
BetaCitationsDelta,
|
|
11
19
|
BetaContentBlock,
|
|
12
20
|
BetaContentBlockParam,
|
|
21
|
+
BetaContentBlockSource,
|
|
22
|
+
BetaContentBlockSourceContent,
|
|
13
23
|
BetaImageBlockParam,
|
|
14
24
|
BetaInputJSONDelta,
|
|
15
25
|
BetaMessage,
|
|
@@ -17,6 +27,7 @@ import {
|
|
|
17
27
|
BetaMessageParam,
|
|
18
28
|
BetaMessageTokensCount,
|
|
19
29
|
BetaMetadata,
|
|
30
|
+
BetaPlainTextSource,
|
|
20
31
|
BetaRawContentBlockDeltaEvent,
|
|
21
32
|
BetaRawContentBlockStartEvent,
|
|
22
33
|
BetaRawContentBlockStopEvent,
|
|
@@ -26,6 +37,8 @@ import {
|
|
|
26
37
|
BetaRawMessageStreamEvent,
|
|
27
38
|
BetaTextBlock,
|
|
28
39
|
BetaTextBlockParam,
|
|
40
|
+
BetaTextCitation,
|
|
41
|
+
BetaTextCitationParam,
|
|
29
42
|
BetaTextDelta,
|
|
30
43
|
BetaTool,
|
|
31
44
|
BetaToolBash20241022,
|
|
@@ -163,8 +176,18 @@ export declare namespace Beta {
|
|
|
163
176
|
type BetaBase64PDFBlock as BetaBase64PDFBlock,
|
|
164
177
|
type BetaBase64PDFSource as BetaBase64PDFSource,
|
|
165
178
|
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
|
|
179
|
+
type BetaCitationCharLocation as BetaCitationCharLocation,
|
|
180
|
+
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
|
|
181
|
+
type BetaCitationContentBlockLocation as BetaCitationContentBlockLocation,
|
|
182
|
+
type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
|
|
183
|
+
type BetaCitationPageLocation as BetaCitationPageLocation,
|
|
184
|
+
type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
|
|
185
|
+
type BetaCitationsConfigParam as BetaCitationsConfigParam,
|
|
186
|
+
type BetaCitationsDelta as BetaCitationsDelta,
|
|
166
187
|
type BetaContentBlock as BetaContentBlock,
|
|
167
188
|
type BetaContentBlockParam as BetaContentBlockParam,
|
|
189
|
+
type BetaContentBlockSource as BetaContentBlockSource,
|
|
190
|
+
type BetaContentBlockSourceContent as BetaContentBlockSourceContent,
|
|
168
191
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
169
192
|
type BetaInputJSONDelta as BetaInputJSONDelta,
|
|
170
193
|
type BetaMessage as BetaMessage,
|
|
@@ -172,6 +195,7 @@ export declare namespace Beta {
|
|
|
172
195
|
type BetaMessageParam as BetaMessageParam,
|
|
173
196
|
type BetaMessageTokensCount as BetaMessageTokensCount,
|
|
174
197
|
type BetaMetadata as BetaMetadata,
|
|
198
|
+
type BetaPlainTextSource as BetaPlainTextSource,
|
|
175
199
|
type BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent,
|
|
176
200
|
type BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent,
|
|
177
201
|
type BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent,
|
|
@@ -181,6 +205,8 @@ export declare namespace Beta {
|
|
|
181
205
|
type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
|
|
182
206
|
type BetaTextBlock as BetaTextBlock,
|
|
183
207
|
type BetaTextBlockParam as BetaTextBlockParam,
|
|
208
|
+
type BetaTextCitation as BetaTextCitation,
|
|
209
|
+
type BetaTextCitationParam as BetaTextCitationParam,
|
|
184
210
|
type BetaTextDelta as BetaTextDelta,
|
|
185
211
|
type BetaTool as BetaTool,
|
|
186
212
|
type BetaToolBash20241022 as BetaToolBash20241022,
|
|
@@ -21,8 +21,18 @@ export {
|
|
|
21
21
|
type BetaBase64PDFBlock,
|
|
22
22
|
type BetaBase64PDFSource,
|
|
23
23
|
type BetaCacheControlEphemeral,
|
|
24
|
+
type BetaCitationCharLocation,
|
|
25
|
+
type BetaCitationCharLocationParam,
|
|
26
|
+
type BetaCitationContentBlockLocation,
|
|
27
|
+
type BetaCitationContentBlockLocationParam,
|
|
28
|
+
type BetaCitationPageLocation,
|
|
29
|
+
type BetaCitationPageLocationParam,
|
|
30
|
+
type BetaCitationsConfigParam,
|
|
31
|
+
type BetaCitationsDelta,
|
|
24
32
|
type BetaContentBlock,
|
|
25
33
|
type BetaContentBlockParam,
|
|
34
|
+
type BetaContentBlockSource,
|
|
35
|
+
type BetaContentBlockSourceContent,
|
|
26
36
|
type BetaImageBlockParam,
|
|
27
37
|
type BetaInputJSONDelta,
|
|
28
38
|
type BetaMessage,
|
|
@@ -30,6 +40,7 @@ export {
|
|
|
30
40
|
type BetaMessageParam,
|
|
31
41
|
type BetaMessageTokensCount,
|
|
32
42
|
type BetaMetadata,
|
|
43
|
+
type BetaPlainTextSource,
|
|
33
44
|
type BetaRawContentBlockDeltaEvent,
|
|
34
45
|
type BetaRawContentBlockStartEvent,
|
|
35
46
|
type BetaRawContentBlockStopEvent,
|
|
@@ -39,6 +50,8 @@ export {
|
|
|
39
50
|
type BetaRawMessageStreamEvent,
|
|
40
51
|
type BetaTextBlock,
|
|
41
52
|
type BetaTextBlockParam,
|
|
53
|
+
type BetaTextCitation,
|
|
54
|
+
type BetaTextCitationParam,
|
|
42
55
|
type BetaTextDelta,
|
|
43
56
|
type BetaTool,
|
|
44
57
|
type BetaToolBash20241022,
|
|
@@ -86,9 +86,10 @@ export class Batches extends APIResource {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
89
|
+
* Delete a Message Batch.
|
|
90
|
+
*
|
|
91
|
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
|
92
|
+
* like to delete an in-progress batch, you must first cancel it.
|
|
92
93
|
*/
|
|
93
94
|
delete(
|
|
94
95
|
messageBatchId: string,
|
|
@@ -298,6 +299,10 @@ export interface BetaMessageBatchExpiredResult {
|
|
|
298
299
|
type: 'expired';
|
|
299
300
|
}
|
|
300
301
|
|
|
302
|
+
/**
|
|
303
|
+
* This is a single line in the response `.jsonl` file and does not represent the
|
|
304
|
+
* response as a whole.
|
|
305
|
+
*/
|
|
301
306
|
export interface BetaMessageBatchIndividualResponse {
|
|
302
307
|
/**
|
|
303
308
|
* Developer-provided ID created for each request in a Message Batch. Useful for
|
|
@@ -24,8 +24,18 @@ export {
|
|
|
24
24
|
type BetaBase64PDFBlock,
|
|
25
25
|
type BetaBase64PDFSource,
|
|
26
26
|
type BetaCacheControlEphemeral,
|
|
27
|
+
type BetaCitationCharLocation,
|
|
28
|
+
type BetaCitationCharLocationParam,
|
|
29
|
+
type BetaCitationContentBlockLocation,
|
|
30
|
+
type BetaCitationContentBlockLocationParam,
|
|
31
|
+
type BetaCitationPageLocation,
|
|
32
|
+
type BetaCitationPageLocationParam,
|
|
33
|
+
type BetaCitationsConfigParam,
|
|
34
|
+
type BetaCitationsDelta,
|
|
27
35
|
type BetaContentBlock,
|
|
28
36
|
type BetaContentBlockParam,
|
|
37
|
+
type BetaContentBlockSource,
|
|
38
|
+
type BetaContentBlockSourceContent,
|
|
29
39
|
type BetaImageBlockParam,
|
|
30
40
|
type BetaInputJSONDelta,
|
|
31
41
|
type BetaMessage,
|
|
@@ -33,6 +43,7 @@ export {
|
|
|
33
43
|
type BetaMessageParam,
|
|
34
44
|
type BetaMessageTokensCount,
|
|
35
45
|
type BetaMetadata,
|
|
46
|
+
type BetaPlainTextSource,
|
|
36
47
|
type BetaRawContentBlockDeltaEvent,
|
|
37
48
|
type BetaRawContentBlockStartEvent,
|
|
38
49
|
type BetaRawContentBlockStopEvent,
|
|
@@ -42,6 +53,8 @@ export {
|
|
|
42
53
|
type BetaRawMessageStreamEvent,
|
|
43
54
|
type BetaTextBlock,
|
|
44
55
|
type BetaTextBlockParam,
|
|
56
|
+
type BetaTextCitation,
|
|
57
|
+
type BetaTextCitationParam,
|
|
45
58
|
type BetaTextDelta,
|
|
46
59
|
type BetaTool,
|
|
47
60
|
type BetaToolBash20241022,
|
|
@@ -120,11 +120,17 @@ export class Messages extends APIResource {
|
|
|
120
120
|
export type BetaMessageStreamParams = MessageCreateParamsBase;
|
|
121
121
|
|
|
122
122
|
export interface BetaBase64PDFBlock {
|
|
123
|
-
source: BetaBase64PDFSource;
|
|
123
|
+
source: BetaBase64PDFSource | BetaPlainTextSource | BetaContentBlockSource;
|
|
124
124
|
|
|
125
125
|
type: 'document';
|
|
126
126
|
|
|
127
127
|
cache_control?: BetaCacheControlEphemeral | null;
|
|
128
|
+
|
|
129
|
+
citations?: BetaCitationsConfigParam;
|
|
130
|
+
|
|
131
|
+
context?: string | null;
|
|
132
|
+
|
|
133
|
+
title?: string | null;
|
|
128
134
|
}
|
|
129
135
|
|
|
130
136
|
export interface BetaBase64PDFSource {
|
|
@@ -139,6 +145,100 @@ export interface BetaCacheControlEphemeral {
|
|
|
139
145
|
type: 'ephemeral';
|
|
140
146
|
}
|
|
141
147
|
|
|
148
|
+
export interface BetaCitationCharLocation {
|
|
149
|
+
cited_text: string;
|
|
150
|
+
|
|
151
|
+
document_index: number;
|
|
152
|
+
|
|
153
|
+
document_title: string | null;
|
|
154
|
+
|
|
155
|
+
end_char_index: number;
|
|
156
|
+
|
|
157
|
+
start_char_index: number;
|
|
158
|
+
|
|
159
|
+
type: 'char_location';
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface BetaCitationCharLocationParam {
|
|
163
|
+
cited_text: string;
|
|
164
|
+
|
|
165
|
+
document_index: number;
|
|
166
|
+
|
|
167
|
+
document_title: string | null;
|
|
168
|
+
|
|
169
|
+
end_char_index: number;
|
|
170
|
+
|
|
171
|
+
start_char_index: number;
|
|
172
|
+
|
|
173
|
+
type: 'char_location';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface BetaCitationContentBlockLocation {
|
|
177
|
+
cited_text: string;
|
|
178
|
+
|
|
179
|
+
document_index: number;
|
|
180
|
+
|
|
181
|
+
document_title: string | null;
|
|
182
|
+
|
|
183
|
+
end_block_index: number;
|
|
184
|
+
|
|
185
|
+
start_block_index: number;
|
|
186
|
+
|
|
187
|
+
type: 'content_block_location';
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface BetaCitationContentBlockLocationParam {
|
|
191
|
+
cited_text: string;
|
|
192
|
+
|
|
193
|
+
document_index: number;
|
|
194
|
+
|
|
195
|
+
document_title: string | null;
|
|
196
|
+
|
|
197
|
+
end_block_index: number;
|
|
198
|
+
|
|
199
|
+
start_block_index: number;
|
|
200
|
+
|
|
201
|
+
type: 'content_block_location';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface BetaCitationPageLocation {
|
|
205
|
+
cited_text: string;
|
|
206
|
+
|
|
207
|
+
document_index: number;
|
|
208
|
+
|
|
209
|
+
document_title: string | null;
|
|
210
|
+
|
|
211
|
+
end_page_number: number;
|
|
212
|
+
|
|
213
|
+
start_page_number: number;
|
|
214
|
+
|
|
215
|
+
type: 'page_location';
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface BetaCitationPageLocationParam {
|
|
219
|
+
cited_text: string;
|
|
220
|
+
|
|
221
|
+
document_index: number;
|
|
222
|
+
|
|
223
|
+
document_title: string | null;
|
|
224
|
+
|
|
225
|
+
end_page_number: number;
|
|
226
|
+
|
|
227
|
+
start_page_number: number;
|
|
228
|
+
|
|
229
|
+
type: 'page_location';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface BetaCitationsConfigParam {
|
|
233
|
+
enabled?: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface BetaCitationsDelta {
|
|
237
|
+
citation: BetaCitationCharLocation | BetaCitationPageLocation | BetaCitationContentBlockLocation;
|
|
238
|
+
|
|
239
|
+
type: 'citations_delta';
|
|
240
|
+
}
|
|
241
|
+
|
|
142
242
|
export type BetaContentBlock = BetaTextBlock | BetaToolUseBlock;
|
|
143
243
|
|
|
144
244
|
export type BetaContentBlockParam =
|
|
@@ -148,6 +248,14 @@ export type BetaContentBlockParam =
|
|
|
148
248
|
| BetaToolResultBlockParam
|
|
149
249
|
| BetaBase64PDFBlock;
|
|
150
250
|
|
|
251
|
+
export interface BetaContentBlockSource {
|
|
252
|
+
content: string | Array<BetaContentBlockSourceContent>;
|
|
253
|
+
|
|
254
|
+
type: 'content';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export type BetaContentBlockSourceContent = BetaTextBlockParam | BetaImageBlockParam;
|
|
258
|
+
|
|
151
259
|
export interface BetaImageBlockParam {
|
|
152
260
|
source: BetaImageBlockParam.Source;
|
|
153
261
|
|
|
@@ -309,8 +417,16 @@ export interface BetaMetadata {
|
|
|
309
417
|
user_id?: string | null;
|
|
310
418
|
}
|
|
311
419
|
|
|
420
|
+
export interface BetaPlainTextSource {
|
|
421
|
+
data: string;
|
|
422
|
+
|
|
423
|
+
media_type: 'text/plain';
|
|
424
|
+
|
|
425
|
+
type: 'text';
|
|
426
|
+
}
|
|
427
|
+
|
|
312
428
|
export interface BetaRawContentBlockDeltaEvent {
|
|
313
|
-
delta: BetaTextDelta | BetaInputJSONDelta;
|
|
429
|
+
delta: BetaTextDelta | BetaInputJSONDelta | BetaCitationsDelta;
|
|
314
430
|
|
|
315
431
|
index: number;
|
|
316
432
|
|
|
@@ -380,6 +496,15 @@ export type BetaRawMessageStreamEvent =
|
|
|
380
496
|
| BetaRawContentBlockStopEvent;
|
|
381
497
|
|
|
382
498
|
export interface BetaTextBlock {
|
|
499
|
+
/**
|
|
500
|
+
* Citations supporting the text block.
|
|
501
|
+
*
|
|
502
|
+
* The type of citation returned will depend on the type of document being cited.
|
|
503
|
+
* Citing a PDF results in `page_location`, plain text results in `char_location`,
|
|
504
|
+
* and content document results in `content_block_location`.
|
|
505
|
+
*/
|
|
506
|
+
citations: Array<BetaTextCitation> | null;
|
|
507
|
+
|
|
383
508
|
text: string;
|
|
384
509
|
|
|
385
510
|
type: 'text';
|
|
@@ -391,8 +516,20 @@ export interface BetaTextBlockParam {
|
|
|
391
516
|
type: 'text';
|
|
392
517
|
|
|
393
518
|
cache_control?: BetaCacheControlEphemeral | null;
|
|
519
|
+
|
|
520
|
+
citations?: Array<BetaTextCitationParam> | null;
|
|
394
521
|
}
|
|
395
522
|
|
|
523
|
+
export type BetaTextCitation =
|
|
524
|
+
| BetaCitationCharLocation
|
|
525
|
+
| BetaCitationPageLocation
|
|
526
|
+
| BetaCitationContentBlockLocation;
|
|
527
|
+
|
|
528
|
+
export type BetaTextCitationParam =
|
|
529
|
+
| BetaCitationCharLocationParam
|
|
530
|
+
| BetaCitationPageLocationParam
|
|
531
|
+
| BetaCitationContentBlockLocationParam;
|
|
532
|
+
|
|
396
533
|
export interface BetaTextDelta {
|
|
397
534
|
text: string;
|
|
398
535
|
|
|
@@ -1110,8 +1247,18 @@ export declare namespace Messages {
|
|
|
1110
1247
|
type BetaBase64PDFBlock as BetaBase64PDFBlock,
|
|
1111
1248
|
type BetaBase64PDFSource as BetaBase64PDFSource,
|
|
1112
1249
|
type BetaCacheControlEphemeral as BetaCacheControlEphemeral,
|
|
1250
|
+
type BetaCitationCharLocation as BetaCitationCharLocation,
|
|
1251
|
+
type BetaCitationCharLocationParam as BetaCitationCharLocationParam,
|
|
1252
|
+
type BetaCitationContentBlockLocation as BetaCitationContentBlockLocation,
|
|
1253
|
+
type BetaCitationContentBlockLocationParam as BetaCitationContentBlockLocationParam,
|
|
1254
|
+
type BetaCitationPageLocation as BetaCitationPageLocation,
|
|
1255
|
+
type BetaCitationPageLocationParam as BetaCitationPageLocationParam,
|
|
1256
|
+
type BetaCitationsConfigParam as BetaCitationsConfigParam,
|
|
1257
|
+
type BetaCitationsDelta as BetaCitationsDelta,
|
|
1113
1258
|
type BetaContentBlock as BetaContentBlock,
|
|
1114
1259
|
type BetaContentBlockParam as BetaContentBlockParam,
|
|
1260
|
+
type BetaContentBlockSource as BetaContentBlockSource,
|
|
1261
|
+
type BetaContentBlockSourceContent as BetaContentBlockSourceContent,
|
|
1115
1262
|
type BetaImageBlockParam as BetaImageBlockParam,
|
|
1116
1263
|
type BetaInputJSONDelta as BetaInputJSONDelta,
|
|
1117
1264
|
type BetaMessage as BetaMessage,
|
|
@@ -1119,6 +1266,7 @@ export declare namespace Messages {
|
|
|
1119
1266
|
type BetaMessageParam as BetaMessageParam,
|
|
1120
1267
|
type BetaMessageTokensCount as BetaMessageTokensCount,
|
|
1121
1268
|
type BetaMetadata as BetaMetadata,
|
|
1269
|
+
type BetaPlainTextSource as BetaPlainTextSource,
|
|
1122
1270
|
type BetaRawContentBlockDeltaEvent as BetaRawContentBlockDeltaEvent,
|
|
1123
1271
|
type BetaRawContentBlockStartEvent as BetaRawContentBlockStartEvent,
|
|
1124
1272
|
type BetaRawContentBlockStopEvent as BetaRawContentBlockStopEvent,
|
|
@@ -1128,6 +1276,8 @@ export declare namespace Messages {
|
|
|
1128
1276
|
type BetaRawMessageStreamEvent as BetaRawMessageStreamEvent,
|
|
1129
1277
|
type BetaTextBlock as BetaTextBlock,
|
|
1130
1278
|
type BetaTextBlockParam as BetaTextBlockParam,
|
|
1279
|
+
type BetaTextCitation as BetaTextCitation,
|
|
1280
|
+
type BetaTextCitationParam as BetaTextCitationParam,
|
|
1131
1281
|
type BetaTextDelta as BetaTextDelta,
|
|
1132
1282
|
type BetaTool as BetaTool,
|
|
1133
1283
|
type BetaToolBash20241022 as BetaToolBash20241022,
|
package/src/resources/index.ts
CHANGED
|
@@ -27,9 +27,19 @@ export {
|
|
|
27
27
|
Messages,
|
|
28
28
|
type Base64PDFSource,
|
|
29
29
|
type CacheControlEphemeral,
|
|
30
|
+
type CitationCharLocation,
|
|
31
|
+
type CitationCharLocationParam,
|
|
32
|
+
type CitationContentBlockLocation,
|
|
33
|
+
type CitationContentBlockLocationParam,
|
|
34
|
+
type CitationPageLocation,
|
|
35
|
+
type CitationPageLocationParam,
|
|
36
|
+
type CitationsConfigParam,
|
|
37
|
+
type CitationsDelta,
|
|
30
38
|
type ContentBlock,
|
|
31
39
|
type ContentBlockDeltaEvent,
|
|
32
40
|
type ContentBlockParam,
|
|
41
|
+
type ContentBlockSource,
|
|
42
|
+
type ContentBlockSourceContent,
|
|
33
43
|
type ContentBlockStartEvent,
|
|
34
44
|
type ContentBlockStopEvent,
|
|
35
45
|
type DocumentBlockParam,
|
|
@@ -47,6 +57,7 @@ export {
|
|
|
47
57
|
type MessageTokensCount,
|
|
48
58
|
type Metadata,
|
|
49
59
|
type Model,
|
|
60
|
+
type PlainTextSource,
|
|
50
61
|
type RawContentBlockDeltaEvent,
|
|
51
62
|
type RawContentBlockStartEvent,
|
|
52
63
|
type RawContentBlockStopEvent,
|
|
@@ -56,6 +67,8 @@ export {
|
|
|
56
67
|
type RawMessageStreamEvent,
|
|
57
68
|
type TextBlock,
|
|
58
69
|
type TextBlockParam,
|
|
70
|
+
type TextCitation,
|
|
71
|
+
type TextCitationParam,
|
|
59
72
|
type TextDelta,
|
|
60
73
|
type Tool,
|
|
61
74
|
type ToolChoice,
|
|
@@ -50,9 +50,10 @@ export class Batches extends APIResource {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
53
|
+
* Delete a Message Batch.
|
|
54
|
+
*
|
|
55
|
+
* Message Batches can only be deleted once they've finished processing. If you'd
|
|
56
|
+
* like to delete an in-progress batch, you must first cancel it.
|
|
56
57
|
*/
|
|
57
58
|
delete(messageBatchId: string, options?: Core.RequestOptions): Core.APIPromise<DeletedMessageBatch> {
|
|
58
59
|
return this._client.delete(`/v1/messages/batches/${messageBatchId}`, options);
|
|
@@ -206,6 +207,10 @@ export interface MessageBatchExpiredResult {
|
|
|
206
207
|
type: 'expired';
|
|
207
208
|
}
|
|
208
209
|
|
|
210
|
+
/**
|
|
211
|
+
* This is a single line in the response `.jsonl` file and does not represent the
|
|
212
|
+
* response as a whole.
|
|
213
|
+
*/
|
|
209
214
|
export interface MessageBatchIndividualResponse {
|
|
210
215
|
/**
|
|
211
216
|
* Developer-provided ID created for each request in a Message Batch. Useful for
|
|
@@ -19,9 +19,19 @@ export {
|
|
|
19
19
|
Messages,
|
|
20
20
|
type Base64PDFSource,
|
|
21
21
|
type CacheControlEphemeral,
|
|
22
|
+
type CitationCharLocation,
|
|
23
|
+
type CitationCharLocationParam,
|
|
24
|
+
type CitationContentBlockLocation,
|
|
25
|
+
type CitationContentBlockLocationParam,
|
|
26
|
+
type CitationPageLocation,
|
|
27
|
+
type CitationPageLocationParam,
|
|
28
|
+
type CitationsConfigParam,
|
|
29
|
+
type CitationsDelta,
|
|
22
30
|
type ContentBlock,
|
|
23
31
|
type ContentBlockDeltaEvent,
|
|
24
32
|
type ContentBlockParam,
|
|
33
|
+
type ContentBlockSource,
|
|
34
|
+
type ContentBlockSourceContent,
|
|
25
35
|
type ContentBlockStartEvent,
|
|
26
36
|
type ContentBlockStopEvent,
|
|
27
37
|
type DocumentBlockParam,
|
|
@@ -37,6 +47,7 @@ export {
|
|
|
37
47
|
type MessageTokensCount,
|
|
38
48
|
type Metadata,
|
|
39
49
|
type Model,
|
|
50
|
+
type PlainTextSource,
|
|
40
51
|
type RawContentBlockDeltaEvent,
|
|
41
52
|
type RawContentBlockStartEvent,
|
|
42
53
|
type RawContentBlockStopEvent,
|
|
@@ -46,6 +57,8 @@ export {
|
|
|
46
57
|
type RawMessageStreamEvent,
|
|
47
58
|
type TextBlock,
|
|
48
59
|
type TextBlockParam,
|
|
60
|
+
type TextCitation,
|
|
61
|
+
type TextCitationParam,
|
|
49
62
|
type TextDelta,
|
|
50
63
|
type Tool,
|
|
51
64
|
type ToolChoice,
|