Skip to content

chore: release main #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
".": "0.36.2",
".": "0.36.3",
"packages/vertex-sdk": "0.6.4",
"packages/bedrock-sdk": "0.12.4"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-7270ee0a79d885681ee507414608229f61c27f47c40f355dcd210b38aa7cddf1.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-f5276eeef7512112e802c85530c51e0a971ee521eebe3a0db309621587b4973d.yml
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## 0.36.3 (2025-01-27)

Full Changelog: [sdk-v0.36.2...sdk-v0.36.3](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.36.2...sdk-v0.36.3)

### Bug Fixes

* **streaming:** accumulate citations ([#675](https://github.com/anthropics/anthropic-sdk-typescript/issues/675)) ([522118f](https://github.com/anthropics/anthropic-sdk-typescript/commit/522118ffeab327e8476f12d9b9fa1f19042ed714))


### Chores

* **docs:** updates ([#673](https://github.com/anthropics/anthropic-sdk-typescript/issues/673)) ([751ecd0](https://github.com/anthropics/anthropic-sdk-typescript/commit/751ecd0d44707b21ccb390c81716937fae3d8e35))

## 0.36.2 (2025-01-23)

Full Changelog: [sdk-v0.36.1...sdk-v0.36.2](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.36.1...sdk-v0.36.2)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anthropic-ai/sdk",
"version": "0.36.2",
"version": "0.36.3",
"description": "The official TypeScript library for the Anthropic API",
"author": "Anthropic <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/bedrock-sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

"@anthropic-ai/sdk@file:../../dist":
# x-release-please-start-version
version "0.36.2"
version "0.36.3"
# x-release-please-end-version
dependencies:
"@types/node" "^18.11.18"
Expand Down
2 changes: 1 addition & 1 deletion packages/vertex-sdk/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

"@anthropic-ai/sdk@file:../../dist":
# x-release-please-start-version
version "0.36.2"
version "0.36.3"
# x-release-please-end-version
dependencies:
"@types/node" "^18.11.18"
Expand Down
83 changes: 61 additions & 22 deletions src/lib/BetaMessageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type MessageCreateParams as BetaMessageCreateParams,
type MessageCreateParamsBase as BetaMessageCreateParamsBase,
type BetaTextBlock,
type BetaTextCitation,
} from '@anthropic-ai/sdk/resources/beta/messages/messages';
import { type ReadableStream, type Response } from '@anthropic-ai/sdk/_shims/index';
import { Stream } from '@anthropic-ai/sdk/streaming';
Expand All @@ -18,6 +19,7 @@ export interface MessageStreamEvents {
connect: () => void;
streamEvent: (event: BetaMessageStreamEvent, snapshot: BetaMessage) => void;
text: (textDelta: string, textSnapshot: string) => void;
citation: (citation: BetaTextCitation, citationsSnapshot: BetaTextCitation[]) => void;
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
message: (message: BetaMessage) => void;
contentBlock: (content: BetaContentBlock) => void;
Expand Down Expand Up @@ -413,12 +415,27 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
switch (event.type) {
case 'content_block_delta': {
const content = messageSnapshot.content.at(-1)!;
if (event.delta.type === 'text_delta' && content.type === 'text') {
this._emit('text', event.delta.text, content.text || '');
} else if (event.delta.type === 'input_json_delta' && content.type === 'tool_use') {
if (content.input) {
this._emit('inputJson', event.delta.partial_json, content.input);
switch (event.delta.type) {
case 'text_delta': {
if (content.type === 'text') {
this._emit('text', event.delta.text, content.text || '');
}
break;
}
case 'citations_delta': {
if (content.type === 'text') {
this._emit('citation', event.delta.citation, content.citations ?? []);
}
break;
}
case 'input_json_delta': {
if (content.type === 'tool_use' && content.input) {
this._emit('inputJson', event.delta.partial_json, content.input);
}
break;
}
default:
checkNever(event.delta);
}
break;
}
Expand Down Expand Up @@ -505,24 +522,43 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
return snapshot;
case 'content_block_delta': {
const snapshotContent = snapshot.content.at(event.index);
if (snapshotContent?.type === 'text' && event.delta.type === 'text_delta') {
snapshotContent.text += event.delta.text;
} else if (snapshotContent?.type === 'tool_use' && event.delta.type === 'input_json_delta') {
// we need to keep track of the raw JSON string as well so that we can
// re-parse it for each delta, for now we just store it as an untyped
// non-enumerable property on the snapshot
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
jsonBuf += event.delta.partial_json;

Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
value: jsonBuf,
enumerable: false,
writable: true,
});

if (jsonBuf) {
snapshotContent.input = partialParse(jsonBuf);

switch (event.delta.type) {
case 'text_delta': {
if (snapshotContent?.type === 'text') {
snapshotContent.text += event.delta.text;
}
break;
}
case 'citations_delta': {
if (snapshotContent?.type === 'text') {
snapshotContent.citations ??= [];
snapshotContent.citations.push(event.delta.citation);
}
break;
}
case 'input_json_delta': {
if (snapshotContent?.type === 'tool_use') {
// we need to keep track of the raw JSON string as well so that we can
// re-parse it for each delta, for now we just store it as an untyped
// non-enumerable property on the snapshot
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
jsonBuf += event.delta.partial_json;

Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
value: jsonBuf,
enumerable: false,
writable: true,
});

if (jsonBuf) {
snapshotContent.input = partialParse(jsonBuf);
}
}
break;
}
default:
checkNever(event.delta);
}
return snapshot;
}
Expand Down Expand Up @@ -597,3 +633,6 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
return stream.toReadableStream();
}
}

// used to ensure exhaustive case matching without throwing a runtime error
function checkNever(x: never) {}
84 changes: 62 additions & 22 deletions src/lib/MessageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
type MessageCreateParams,
type MessageCreateParamsBase,
type TextBlock,
type TextCitation,
} from '@anthropic-ai/sdk/resources/messages';
import { type ReadableStream, type Response } from '@anthropic-ai/sdk/_shims/index';
import { Stream } from '@anthropic-ai/sdk/streaming';
Expand All @@ -18,6 +19,7 @@ export interface MessageStreamEvents {
connect: () => void;
streamEvent: (event: MessageStreamEvent, snapshot: Message) => void;
text: (textDelta: string, textSnapshot: string) => void;
citation: (citation: TextCitation, citationsSnapshot: TextCitation[]) => void;
inputJson: (partialJson: string, jsonSnapshot: unknown) => void;
message: (message: Message) => void;
contentBlock: (content: ContentBlock) => void;
Expand Down Expand Up @@ -413,12 +415,27 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
switch (event.type) {
case 'content_block_delta': {
const content = messageSnapshot.content.at(-1)!;
if (event.delta.type === 'text_delta' && content.type === 'text') {
this._emit('text', event.delta.text, content.text || '');
} else if (event.delta.type === 'input_json_delta' && content.type === 'tool_use') {
if (content.input) {
this._emit('inputJson', event.delta.partial_json, content.input);
switch (event.delta.type) {
case 'text_delta': {
if (content.type === 'text') {
this._emit('text', event.delta.text, content.text || '');
}
break;
}
case 'citations_delta': {
if (content.type === 'text') {
this._emit('citation', event.delta.citation, content.citations ?? []);
}
break;
}
case 'input_json_delta': {
if (content.type === 'tool_use' && content.input) {
this._emit('inputJson', event.delta.partial_json, content.input);
}
break;
}
default:
checkNever(event.delta);
}
break;
}
Expand Down Expand Up @@ -505,25 +522,45 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
return snapshot;
case 'content_block_delta': {
const snapshotContent = snapshot.content.at(event.index);
if (snapshotContent?.type === 'text' && event.delta.type === 'text_delta') {
snapshotContent.text += event.delta.text;
} else if (snapshotContent?.type === 'tool_use' && event.delta.type === 'input_json_delta') {
// we need to keep track of the raw JSON string as well so that we can
// re-parse it for each delta, for now we just store it as an untyped
// non-enumerable property on the snapshot
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
jsonBuf += event.delta.partial_json;

Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
value: jsonBuf,
enumerable: false,
writable: true,
});

if (jsonBuf) {
snapshotContent.input = partialParse(jsonBuf);

switch (event.delta.type) {
case 'text_delta': {
if (snapshotContent?.type === 'text') {
snapshotContent.text += event.delta.text;
}
break;
}
case 'citations_delta': {
if (snapshotContent?.type === 'text') {
snapshotContent.citations ??= [];
snapshotContent.citations.push(event.delta.citation);
}
break;
}
case 'input_json_delta': {
if (snapshotContent?.type === 'tool_use') {
// we need to keep track of the raw JSON string as well so that we can
// re-parse it for each delta, for now we just store it as an untyped
// non-enumerable property on the snapshot
let jsonBuf = (snapshotContent as any)[JSON_BUF_PROPERTY] || '';
jsonBuf += event.delta.partial_json;

Object.defineProperty(snapshotContent, JSON_BUF_PROPERTY, {
value: jsonBuf,
enumerable: false,
writable: true,
});

if (jsonBuf) {
snapshotContent.input = partialParse(jsonBuf);
}
}
break;
}
default:
checkNever(event.delta);
}

return snapshot;
}
case 'content_block_stop':
Expand Down Expand Up @@ -597,3 +634,6 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
return stream.toReadableStream();
}
}

// used to ensure exhaustive case matching without throwing a runtime error
function checkNever(x: never) {}
4 changes: 4 additions & 0 deletions src/resources/beta/messages/batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export interface BetaMessageBatchExpiredResult {
type: 'expired';
}

/**
* This is a single line in the response `.jsonl` file and does not represent the
* response as a whole.
*/
export interface BetaMessageBatchIndividualResponse {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
Expand Down
4 changes: 4 additions & 0 deletions src/resources/messages/batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ export interface MessageBatchExpiredResult {
type: 'expired';
}

/**
* This is a single line in the response `.jsonl` file and does not represent the
* response as a whole.
*/
export interface MessageBatchIndividualResponse {
/**
* Developer-provided ID created for each request in a Message Batch. Useful for
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.36.2'; // x-release-please-version
export const VERSION = '0.36.3'; // x-release-please-version
Loading