@anthropic-ai/sdk 0.35.0 → 0.36.2
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 +34 -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 +1 -0
- package/lib/BetaMessageStream.d.ts.map +1 -1
- package/lib/BetaMessageStream.js +7 -2
- package/lib/BetaMessageStream.js.map +1 -1
- package/lib/BetaMessageStream.mjs +7 -2
- package/lib/BetaMessageStream.mjs.map +1 -1
- package/lib/MessageStream.d.ts +1 -0
- package/lib/MessageStream.d.ts.map +1 -1
- package/lib/MessageStream.js +7 -2
- package/lib/MessageStream.js.map +1 -1
- package/lib/MessageStream.mjs +7 -2
- 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 +4 -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 +4 -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 +6 -0
- package/src/lib/MessageStream.ts +6 -0
- package/src/resources/beta/beta.ts +26 -0
- package/src/resources/beta/index.ts +13 -0
- package/src/resources/beta/messages/batches.ts +4 -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 +4 -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/index.ts
CHANGED
|
@@ -33,9 +33,19 @@ import {
|
|
|
33
33
|
import {
|
|
34
34
|
Base64PDFSource,
|
|
35
35
|
CacheControlEphemeral,
|
|
36
|
+
CitationCharLocation,
|
|
37
|
+
CitationCharLocationParam,
|
|
38
|
+
CitationContentBlockLocation,
|
|
39
|
+
CitationContentBlockLocationParam,
|
|
40
|
+
CitationPageLocation,
|
|
41
|
+
CitationPageLocationParam,
|
|
42
|
+
CitationsConfigParam,
|
|
43
|
+
CitationsDelta,
|
|
36
44
|
ContentBlock,
|
|
37
45
|
ContentBlockDeltaEvent,
|
|
38
46
|
ContentBlockParam,
|
|
47
|
+
ContentBlockSource,
|
|
48
|
+
ContentBlockSourceContent,
|
|
39
49
|
ContentBlockStartEvent,
|
|
40
50
|
ContentBlockStopEvent,
|
|
41
51
|
DocumentBlockParam,
|
|
@@ -57,6 +67,7 @@ import {
|
|
|
57
67
|
Messages,
|
|
58
68
|
Metadata,
|
|
59
69
|
Model,
|
|
70
|
+
PlainTextSource,
|
|
60
71
|
RawContentBlockDeltaEvent,
|
|
61
72
|
RawContentBlockStartEvent,
|
|
62
73
|
RawContentBlockStopEvent,
|
|
@@ -66,6 +77,8 @@ import {
|
|
|
66
77
|
RawMessageStreamEvent,
|
|
67
78
|
TextBlock,
|
|
68
79
|
TextBlockParam,
|
|
80
|
+
TextCitation,
|
|
81
|
+
TextCitationParam,
|
|
69
82
|
TextDelta,
|
|
70
83
|
Tool,
|
|
71
84
|
ToolChoice,
|
|
@@ -322,9 +335,19 @@ export declare namespace Anthropic {
|
|
|
322
335
|
Messages as Messages,
|
|
323
336
|
type Base64PDFSource as Base64PDFSource,
|
|
324
337
|
type CacheControlEphemeral as CacheControlEphemeral,
|
|
338
|
+
type CitationCharLocation as CitationCharLocation,
|
|
339
|
+
type CitationCharLocationParam as CitationCharLocationParam,
|
|
340
|
+
type CitationContentBlockLocation as CitationContentBlockLocation,
|
|
341
|
+
type CitationContentBlockLocationParam as CitationContentBlockLocationParam,
|
|
342
|
+
type CitationPageLocation as CitationPageLocation,
|
|
343
|
+
type CitationPageLocationParam as CitationPageLocationParam,
|
|
344
|
+
type CitationsConfigParam as CitationsConfigParam,
|
|
345
|
+
type CitationsDelta as CitationsDelta,
|
|
325
346
|
type ContentBlock as ContentBlock,
|
|
326
347
|
type ContentBlockDeltaEvent as ContentBlockDeltaEvent,
|
|
327
348
|
type ContentBlockParam as ContentBlockParam,
|
|
349
|
+
type ContentBlockSource as ContentBlockSource,
|
|
350
|
+
type ContentBlockSourceContent as ContentBlockSourceContent,
|
|
328
351
|
type ContentBlockStartEvent as ContentBlockStartEvent,
|
|
329
352
|
type ContentBlockStopEvent as ContentBlockStopEvent,
|
|
330
353
|
type DocumentBlockParam as DocumentBlockParam,
|
|
@@ -340,6 +363,7 @@ export declare namespace Anthropic {
|
|
|
340
363
|
type MessageTokensCount as MessageTokensCount,
|
|
341
364
|
type Metadata as Metadata,
|
|
342
365
|
type Model as Model,
|
|
366
|
+
type PlainTextSource as PlainTextSource,
|
|
343
367
|
type RawContentBlockDeltaEvent as RawContentBlockDeltaEvent,
|
|
344
368
|
type RawContentBlockStartEvent as RawContentBlockStartEvent,
|
|
345
369
|
type RawContentBlockStopEvent as RawContentBlockStopEvent,
|
|
@@ -349,6 +373,8 @@ export declare namespace Anthropic {
|
|
|
349
373
|
type RawMessageStreamEvent as RawMessageStreamEvent,
|
|
350
374
|
type TextBlock as TextBlock,
|
|
351
375
|
type TextBlockParam as TextBlockParam,
|
|
376
|
+
type TextCitation as TextCitation,
|
|
377
|
+
type TextCitationParam as TextCitationParam,
|
|
352
378
|
type TextDelta as TextDelta,
|
|
353
379
|
type Tool as Tool,
|
|
354
380
|
type ToolChoice as ToolChoice,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnthropicError } from "../../error.js";
|
|
2
|
-
import {
|
|
2
|
+
import { ReadableStreamToAsyncIterable } from "../stream-utils.js";
|
|
3
3
|
import { type Response } from "../../_shims/index.js";
|
|
4
4
|
import { LineDecoder, type Bytes } from "./line.js";
|
|
5
5
|
|
|
@@ -36,6 +36,6 @@ export class JSONLDecoder<T> {
|
|
|
36
36
|
throw new AnthropicError(`Attempted to iterate over a response with no body`);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
return new JSONLDecoder(
|
|
39
|
+
return new JSONLDecoder(ReadableStreamToAsyncIterable<Bytes>(response.body), controller);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Most browsers don't yet have async iterable support for ReadableStream,
|
|
3
|
+
* and Node has a very different way of reading bytes from its "ReadableStream".
|
|
4
|
+
*
|
|
5
|
+
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
6
|
+
*/
|
|
7
|
+
export function ReadableStreamToAsyncIterable<T>(stream: any): AsyncIterableIterator<T> {
|
|
8
|
+
if (stream[Symbol.asyncIterator]) return stream;
|
|
9
|
+
|
|
10
|
+
const reader = stream.getReader();
|
|
11
|
+
return {
|
|
12
|
+
async next() {
|
|
13
|
+
try {
|
|
14
|
+
const result = await reader.read();
|
|
15
|
+
if (result?.done) reader.releaseLock(); // release lock when stream becomes closed
|
|
16
|
+
return result;
|
|
17
|
+
} catch (e) {
|
|
18
|
+
reader.releaseLock(); // release lock when stream becomes errored
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async return() {
|
|
23
|
+
const cancelPromise = reader.cancel();
|
|
24
|
+
reader.releaseLock();
|
|
25
|
+
await cancelPromise;
|
|
26
|
+
return { done: true, value: undefined };
|
|
27
|
+
},
|
|
28
|
+
[Symbol.asyncIterator]() {
|
|
29
|
+
return this;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -55,6 +55,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
55
55
|
#errored = false;
|
|
56
56
|
#aborted = false;
|
|
57
57
|
#catchingPromiseCreated = false;
|
|
58
|
+
#response: Response | null | undefined;
|
|
58
59
|
#request_id: string | null | undefined;
|
|
59
60
|
|
|
60
61
|
constructor() {
|
|
@@ -76,6 +77,10 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
76
77
|
this.#endPromise.catch(() => {});
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
get response(): Response | null | undefined {
|
|
81
|
+
return this.#response;
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
get request_id(): string | null | undefined {
|
|
80
85
|
return this.#request_id;
|
|
81
86
|
}
|
|
@@ -183,6 +188,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
|
|
|
183
188
|
|
|
184
189
|
protected _connected(response: Response | null) {
|
|
185
190
|
if (this.ended) return;
|
|
191
|
+
this.#response = response;
|
|
186
192
|
this.#request_id = response?.headers.get('request-id');
|
|
187
193
|
this.#resolveConnectedPromise(response);
|
|
188
194
|
this._emit('connect');
|
package/src/lib/MessageStream.ts
CHANGED
|
@@ -55,6 +55,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
55
55
|
#errored = false;
|
|
56
56
|
#aborted = false;
|
|
57
57
|
#catchingPromiseCreated = false;
|
|
58
|
+
#response: Response | null | undefined;
|
|
58
59
|
#request_id: string | null | undefined;
|
|
59
60
|
|
|
60
61
|
constructor() {
|
|
@@ -76,6 +77,10 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
76
77
|
this.#endPromise.catch(() => {});
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
get response(): Response | null | undefined {
|
|
81
|
+
return this.#response;
|
|
82
|
+
}
|
|
83
|
+
|
|
79
84
|
get request_id(): string | null | undefined {
|
|
80
85
|
return this.#request_id;
|
|
81
86
|
}
|
|
@@ -183,6 +188,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
|
|
|
183
188
|
|
|
184
189
|
protected _connected(response: Response | null) {
|
|
185
190
|
if (this.ended) return;
|
|
191
|
+
this.#response = response;
|
|
186
192
|
this.#request_id = response?.headers.get('request-id');
|
|
187
193
|
this.#resolveConnectedPromise(response);
|
|
188
194
|
this._emit('connect');
|
|
@@ -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,
|
|
@@ -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);
|
|
@@ -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,
|