diff --git a/api.md b/api.md index 29f593ea..c4fa2a0b 100644 --- a/api.md +++ b/api.md @@ -14,6 +14,13 @@ Types: - MessageStartEvent - MessageStopEvent - MessageStreamEvent +- RawContentBlockDeltaEvent +- RawContentBlockStartEvent +- RawContentBlockStopEvent +- RawMessageDeltaEvent +- RawMessageStartEvent +- RawMessageStopEvent +- RawMessageStreamEvent - TextBlock - TextBlockParam - TextDelta @@ -32,6 +39,9 @@ Methods: Types: - InputJsonDelta +- RawToolsBetaContentBlockDeltaEvent +- RawToolsBetaContentBlockStartEvent +- RawToolsBetaMessageStreamEvent - Tool - ToolResultBlockParam - ToolUseBlock diff --git a/src/index.ts b/src/index.ts index 998717b7..b1631503 100644 --- a/src/index.ts +++ b/src/index.ts @@ -249,6 +249,13 @@ export namespace Anthropic { export import MessageStartEvent = API.MessageStartEvent; export import MessageStopEvent = API.MessageStopEvent; export import MessageStreamEvent = API.MessageStreamEvent; + export import RawContentBlockDeltaEvent = API.RawContentBlockDeltaEvent; + export import RawContentBlockStartEvent = API.RawContentBlockStartEvent; + export import RawContentBlockStopEvent = API.RawContentBlockStopEvent; + export import RawMessageDeltaEvent = API.RawMessageDeltaEvent; + export import RawMessageStartEvent = API.RawMessageStartEvent; + export import RawMessageStopEvent = API.RawMessageStopEvent; + export import RawMessageStreamEvent = API.RawMessageStreamEvent; export import TextBlock = API.TextBlock; export import TextBlockParam = API.TextBlockParam; export import TextDelta = API.TextDelta; diff --git a/src/resources/beta/tools/index.ts b/src/resources/beta/tools/index.ts index cc7d73f8..cb40336c 100644 --- a/src/resources/beta/tools/index.ts +++ b/src/resources/beta/tools/index.ts @@ -2,6 +2,9 @@ export { InputJsonDelta, + RawToolsBetaContentBlockDeltaEvent, + RawToolsBetaContentBlockStartEvent, + RawToolsBetaMessageStreamEvent, Tool, ToolResultBlockParam, ToolUseBlock, diff --git a/src/resources/beta/tools/messages.ts b/src/resources/beta/tools/messages.ts index ca5ff95b..d6a73a84 100644 --- a/src/resources/beta/tools/messages.ts +++ b/src/resources/beta/tools/messages.ts @@ -21,22 +21,22 @@ export class Messages extends APIResource { create( body: MessageCreateParamsStreaming, options?: Core.RequestOptions, - ): APIPromise>; + ): APIPromise>; create( body: MessageCreateParamsBase, options?: Core.RequestOptions, - ): APIPromise | ToolsBetaMessage>; + ): APIPromise | ToolsBetaMessage>; create( body: MessageCreateParams, options?: Core.RequestOptions, - ): APIPromise | APIPromise> { + ): APIPromise | APIPromise> { return this._client.post('/v1/messages?beta=tools', { body, timeout: 600000, ...options, headers: { 'anthropic-beta': 'tools-2024-05-16', ...options?.headers }, stream: body.stream ?? false, - }) as APIPromise | APIPromise>; + }) as APIPromise | APIPromise>; } } @@ -46,6 +46,30 @@ export interface InputJsonDelta { type: 'input_json_delta'; } +export interface RawToolsBetaContentBlockDeltaEvent { + delta: MessagesAPI.TextDelta | InputJsonDelta; + + index: number; + + type: 'content_block_delta'; +} + +export interface RawToolsBetaContentBlockStartEvent { + content_block: MessagesAPI.TextBlock | ToolUseBlock; + + index: number; + + type: 'content_block_start'; +} + +export type RawToolsBetaMessageStreamEvent = + | MessagesAPI.RawMessageStartEvent + | MessagesAPI.RawMessageDeltaEvent + | MessagesAPI.RawMessageStopEvent + | RawToolsBetaContentBlockStartEvent + | RawToolsBetaContentBlockDeltaEvent + | MessagesAPI.RawContentBlockStopEvent; + export interface Tool { /** * [JSON schema](https://json-schema.org/) for this tool's input. @@ -115,21 +139,9 @@ export interface ToolUseBlockParam { export type ToolsBetaContentBlock = MessagesAPI.TextBlock | ToolUseBlock; -export interface ToolsBetaContentBlockDeltaEvent { - delta: MessagesAPI.TextDelta | InputJsonDelta; - - index: number; - - type: 'content_block_delta'; -} +export type ToolsBetaContentBlockDeltaEvent = RawToolsBetaContentBlockDeltaEvent; -export interface ToolsBetaContentBlockStartEvent { - content_block: MessagesAPI.TextBlock | ToolUseBlock; - - index: number; - - type: 'content_block_start'; -} +export type ToolsBetaContentBlockStartEvent = RawToolsBetaContentBlockStartEvent; export interface ToolsBetaMessage { /** @@ -244,13 +256,7 @@ export interface ToolsBetaMessageParam { role: 'user' | 'assistant'; } -export type ToolsBetaMessageStreamEvent = - | MessagesAPI.MessageStartEvent - | MessagesAPI.MessageDeltaEvent - | MessagesAPI.MessageStopEvent - | ToolsBetaContentBlockStartEvent - | ToolsBetaContentBlockDeltaEvent - | MessagesAPI.ContentBlockStopEvent; +export type ToolsBetaMessageStreamEvent = RawToolsBetaMessageStreamEvent; export type MessageCreateParams = MessageCreateParamsNonStreaming | MessageCreateParamsStreaming; @@ -584,6 +590,9 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase { export namespace Messages { export import InputJsonDelta = ToolsMessagesAPI.InputJsonDelta; + export import RawToolsBetaContentBlockDeltaEvent = ToolsMessagesAPI.RawToolsBetaContentBlockDeltaEvent; + export import RawToolsBetaContentBlockStartEvent = ToolsMessagesAPI.RawToolsBetaContentBlockStartEvent; + export import RawToolsBetaMessageStreamEvent = ToolsMessagesAPI.RawToolsBetaMessageStreamEvent; export import Tool = ToolsMessagesAPI.Tool; export import ToolResultBlockParam = ToolsMessagesAPI.ToolResultBlockParam; export import ToolUseBlock = ToolsMessagesAPI.ToolUseBlock; diff --git a/src/resources/beta/tools/tools.ts b/src/resources/beta/tools/tools.ts index 31b47788..b64f6214 100644 --- a/src/resources/beta/tools/tools.ts +++ b/src/resources/beta/tools/tools.ts @@ -10,6 +10,9 @@ export class Tools extends APIResource { export namespace Tools { export import Messages = MessagesAPI.Messages; export import InputJsonDelta = MessagesAPI.InputJsonDelta; + export import RawToolsBetaContentBlockDeltaEvent = MessagesAPI.RawToolsBetaContentBlockDeltaEvent; + export import RawToolsBetaContentBlockStartEvent = MessagesAPI.RawToolsBetaContentBlockStartEvent; + export import RawToolsBetaMessageStreamEvent = MessagesAPI.RawToolsBetaMessageStreamEvent; export import Tool = MessagesAPI.Tool; export import ToolResultBlockParam = MessagesAPI.ToolResultBlockParam; export import ToolUseBlock = MessagesAPI.ToolUseBlock; diff --git a/src/resources/index.ts b/src/resources/index.ts index e9463f7a..5b9fb01f 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -21,6 +21,13 @@ export { MessageStartEvent, MessageStopEvent, MessageStreamEvent, + RawContentBlockDeltaEvent, + RawContentBlockStartEvent, + RawContentBlockStopEvent, + RawMessageDeltaEvent, + RawMessageStartEvent, + RawMessageStopEvent, + RawMessageStreamEvent, TextBlock, TextBlockParam, TextDelta, diff --git a/src/resources/messages.ts b/src/resources/messages.ts index b716ec46..9e475081 100644 --- a/src/resources/messages.ts +++ b/src/resources/messages.ts @@ -20,47 +20,31 @@ export class Messages extends APIResource { create( body: MessageCreateParamsStreaming, options?: Core.RequestOptions, - ): APIPromise>; + ): APIPromise>; create( body: MessageCreateParamsBase, options?: Core.RequestOptions, - ): APIPromise | Message>; + ): APIPromise | Message>; create( body: MessageCreateParams, options?: Core.RequestOptions, - ): APIPromise | APIPromise> { + ): APIPromise | APIPromise> { return this._client.post('/v1/messages', { body, timeout: 600000, ...options, stream: body.stream ?? false, - }) as APIPromise | APIPromise>; + }) as APIPromise | APIPromise>; } } export type ContentBlock = TextBlock; -export interface ContentBlockDeltaEvent { - delta: TextDelta; +export type ContentBlockDeltaEvent = RawContentBlockDeltaEvent; - index: number; +export type ContentBlockStartEvent = RawContentBlockStartEvent; - type: 'content_block_delta'; -} - -export interface ContentBlockStartEvent { - content_block: TextBlock; - - index: number; - - type: 'content_block_start'; -} - -export interface ContentBlockStopEvent { - index: number; - - type: 'content_block_stop'; -} +export type ContentBlockStopEvent = RawContentBlockStopEvent; export interface ImageBlockParam { source: ImageBlockParam.Source; @@ -180,8 +164,51 @@ export interface Message { usage: Usage; } -export interface MessageDeltaEvent { - delta: MessageDeltaEvent.Delta; +export type MessageDeltaEvent = RawMessageDeltaEvent; + +export interface MessageDeltaUsage { + /** + * The cumulative number of output tokens which were used. + */ + output_tokens: number; +} + +export interface MessageParam { + content: string | Array; + + role: 'user' | 'assistant'; +} + +export type MessageStartEvent = RawMessageStartEvent; + +export type MessageStopEvent = RawMessageStopEvent; + +export type MessageStreamEvent = RawMessageStreamEvent; + +export interface RawContentBlockDeltaEvent { + delta: TextDelta; + + index: number; + + type: 'content_block_delta'; +} + +export interface RawContentBlockStartEvent { + content_block: TextBlock; + + index: number; + + type: 'content_block_start'; +} + +export interface RawContentBlockStopEvent { + index: number; + + type: 'content_block_stop'; +} + +export interface RawMessageDeltaEvent { + delta: RawMessageDeltaEvent.Delta; type: 'message_delta'; @@ -202,7 +229,7 @@ export interface MessageDeltaEvent { usage: MessageDeltaUsage; } -export namespace MessageDeltaEvent { +export namespace RawMessageDeltaEvent { export interface Delta { stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | null; @@ -210,36 +237,23 @@ export namespace MessageDeltaEvent { } } -export interface MessageDeltaUsage { - /** - * The cumulative number of output tokens which were used. - */ - output_tokens: number; -} - -export interface MessageParam { - content: string | Array; - - role: 'user' | 'assistant'; -} - -export interface MessageStartEvent { +export interface RawMessageStartEvent { message: Message; type: 'message_start'; } -export interface MessageStopEvent { +export interface RawMessageStopEvent { type: 'message_stop'; } -export type MessageStreamEvent = - | MessageStartEvent - | MessageDeltaEvent - | MessageStopEvent - | ContentBlockStartEvent - | ContentBlockDeltaEvent - | ContentBlockStopEvent; +export type RawMessageStreamEvent = + | RawMessageStartEvent + | RawMessageDeltaEvent + | RawMessageStopEvent + | RawContentBlockStartEvent + | RawContentBlockDeltaEvent + | RawContentBlockStopEvent; export interface TextBlock { text: string; @@ -513,6 +527,13 @@ export namespace Messages { export import MessageStartEvent = MessagesAPI.MessageStartEvent; export import MessageStopEvent = MessagesAPI.MessageStopEvent; export import MessageStreamEvent = MessagesAPI.MessageStreamEvent; + export import RawContentBlockDeltaEvent = MessagesAPI.RawContentBlockDeltaEvent; + export import RawContentBlockStartEvent = MessagesAPI.RawContentBlockStartEvent; + export import RawContentBlockStopEvent = MessagesAPI.RawContentBlockStopEvent; + export import RawMessageDeltaEvent = MessagesAPI.RawMessageDeltaEvent; + export import RawMessageStartEvent = MessagesAPI.RawMessageStartEvent; + export import RawMessageStopEvent = MessagesAPI.RawMessageStopEvent; + export import RawMessageStreamEvent = MessagesAPI.RawMessageStreamEvent; export import TextBlock = MessagesAPI.TextBlock; export import TextBlockParam = MessagesAPI.TextBlockParam; export import TextDelta = MessagesAPI.TextDelta;