@anthropic-ai/sdk
Advanced tools
Comparing version 0.12.3 to 0.12.4
# Changelog | ||
## 0.12.4 (2024-01-23) | ||
Full Changelog: [sdk-v0.12.3...sdk-v0.12.4](https://github.com/anthropics/anthropic-sdk-typescript/compare/sdk-v0.12.3...sdk-v0.12.4) | ||
### Chores | ||
* **internal:** add internal helpers & improve build scripts ([#261](https://github.com/anthropics/anthropic-sdk-typescript/issues/261)) ([4c1504a](https://github.com/anthropics/anthropic-sdk-typescript/commit/4c1504abc7eb8685a8409c4a19dc46d83ea26392)) | ||
* **internal:** minor streaming updates ([#264](https://github.com/anthropics/anthropic-sdk-typescript/issues/264)) ([d4414ff](https://github.com/anthropics/anthropic-sdk-typescript/commit/d4414ffeafbc47769b91c4b2681f130b46d1a7c1)) | ||
* **internal:** update resource client type ([#263](https://github.com/anthropics/anthropic-sdk-typescript/issues/263)) ([bc4f115](https://github.com/anthropics/anthropic-sdk-typescript/commit/bc4f115900cbeba1ff09d6f3cec79e639a8fda5e)) | ||
## 0.12.3 (2024-01-19) | ||
@@ -4,0 +14,0 @@ |
import { Stream } from "./streaming.js"; | ||
import { APIError } from "./error.js"; | ||
@@ -106,2 +107,6 @@ import { type Readable, type Agent, type RequestInfo, type RequestInit, type Response, type HeadersInit } from "./_shims/index.js"; | ||
/** | ||
* Used as a callback for mutating the given `FinalRequestOptions` object. | ||
*/ | ||
protected prepareOptions(options: FinalRequestOptions): Promise<void>; | ||
/** | ||
* Used as a callback for mutating the given `RequestInit` object. | ||
@@ -195,2 +200,3 @@ * | ||
__binaryResponse?: boolean | undefined; | ||
__streamClass?: typeof Stream; | ||
}; | ||
@@ -234,2 +240,3 @@ export declare const isRequestOptions: (obj: unknown) => obj is RequestOptions<unknown>; | ||
export declare const toBase64: (str: string | null | undefined) => string; | ||
export declare function isObj(obj: unknown): obj is Record<string, unknown>; | ||
//# sourceMappingURL=core.d.ts.map |
15
core.js
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.toBase64 = exports.getRequiredHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0; | ||
exports.isObj = exports.toBase64 = exports.getRequiredHeader = exports.isHeadersProtocol = exports.isRunningInBrowser = exports.debug = exports.hasOwn = exports.isEmptyObj = exports.maybeCoerceBoolean = exports.maybeCoerceFloat = exports.maybeCoerceInteger = exports.coerceBoolean = exports.coerceFloat = exports.coerceInteger = exports.readEnv = exports.ensurePresent = exports.castToError = exports.sleep = exports.safeJSON = exports.isRequestOptions = exports.createResponseHeaders = exports.PagePromise = exports.AbstractPage = exports.APIClient = exports.APIPromise = exports.createForm = exports.multipartFormRequestOptions = exports.maybeMultipartFormRequestOptions = void 0; | ||
const version_1 = require("./version.js"); | ||
@@ -32,2 +32,5 @@ const streaming_1 = require("./streaming.js"); | ||
// that if you set `stream: true` the response type must also be `Stream<T>` | ||
if (props.options.__streamClass) { | ||
return props.options.__streamClass.fromSSEResponse(response, props.controller); | ||
} | ||
return streaming_1.Stream.fromSSEResponse(response, props.controller); | ||
@@ -244,2 +247,6 @@ } | ||
/** | ||
* Used as a callback for mutating the given `FinalRequestOptions` object. | ||
*/ | ||
async prepareOptions(options) { } | ||
/** | ||
* Used as a callback for mutating the given `RequestInit` object. | ||
@@ -268,2 +275,3 @@ * | ||
} | ||
await this.prepareOptions(options); | ||
const { req, url, timeout } = this.buildRequest(options); | ||
@@ -525,2 +533,3 @@ await this.prepareRequest(req, { url, options }); | ||
__binaryResponse: true, | ||
__streamClass: true, | ||
}; | ||
@@ -870,2 +879,6 @@ const isRequestOptions = (obj) => { | ||
exports.toBase64 = toBase64; | ||
function isObj(obj) { | ||
return obj != null && typeof obj === 'object' && !Array.isArray(obj); | ||
} | ||
exports.isObj = isObj; | ||
//# sourceMappingURL=core.js.map |
{ | ||
"name": "@anthropic-ai/sdk", | ||
"version": "0.12.3", | ||
"version": "0.12.4", | ||
"description": "The official TypeScript library for the Anthropic API", | ||
@@ -5,0 +5,0 @@ "author": "Anthropic <support@anthropic.com>", |
@@ -1,6 +0,6 @@ | ||
import type { Anthropic } from "./index.js"; | ||
import * as Core from '@anthropic-ai/sdk/core'; | ||
export declare class APIResource { | ||
protected _client: Anthropic; | ||
constructor(client: Anthropic); | ||
protected _client: Core.APIClient; | ||
constructor(client: Core.APIClient); | ||
} | ||
//# sourceMappingURL=resource.d.ts.map |
@@ -23,3 +23,3 @@ "use strict"; | ||
stream(body, options) { | ||
return MessageStream_1.MessageStream.createMessage(this._client.beta.messages, body, options); | ||
return MessageStream_1.MessageStream.createMessage(this, body, options); | ||
} | ||
@@ -26,0 +26,0 @@ } |
@@ -47,2 +47,7 @@ import { VERSION } from './version'; | ||
// that if you set `stream: true` the response type must also be `Stream<T>` | ||
if (props.options.__streamClass) { | ||
return props.options.__streamClass.fromSSEResponse(response, props.controller) as any; | ||
} | ||
return Stream.fromSSEResponse(response, props.controller) as any; | ||
@@ -347,2 +352,7 @@ } | ||
/** | ||
* Used as a callback for mutating the given `FinalRequestOptions` object. | ||
*/ | ||
protected async prepareOptions(options: FinalRequestOptions): Promise<void> {} | ||
/** | ||
* Used as a callback for mutating the given `RequestInit` object. | ||
@@ -392,2 +402,4 @@ * | ||
await this.prepareOptions(options); | ||
const { req, url, timeout } = this.buildRequest(options); | ||
@@ -742,2 +754,3 @@ | ||
__binaryResponse?: boolean | undefined; | ||
__streamClass?: typeof Stream; | ||
}; | ||
@@ -763,2 +776,3 @@ | ||
__binaryResponse: true, | ||
__streamClass: true, | ||
}; | ||
@@ -1147,1 +1161,5 @@ | ||
}; | ||
export function isObj(obj: unknown): obj is Record<string, unknown> { | ||
return obj != null && typeof obj === 'object' && !Array.isArray(obj); | ||
} |
// File generated from our OpenAPI spec by Stainless. | ||
import type { Anthropic } from './index'; | ||
import * as Core from "./core"; | ||
export class APIResource { | ||
protected _client: Anthropic; | ||
protected _client: Core.APIClient; | ||
constructor(client: Anthropic) { | ||
constructor(client: Core.APIClient) { | ||
this._client = client; | ||
} | ||
} |
@@ -43,3 +43,3 @@ // File generated from our OpenAPI spec by Stainless. | ||
stream(body: MessageStreamParams, options?: Core.RequestOptions): MessageStream { | ||
return MessageStream.createMessage(this._client.beta.messages, body, options); | ||
return MessageStream.createMessage(this, body, options); | ||
} | ||
@@ -46,0 +46,0 @@ } |
@@ -7,5 +7,5 @@ import { ReadableStream, type Response } from './_shims/index'; | ||
type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; | ||
export type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; | ||
type ServerSentEvent = { | ||
export type ServerSentEvent = { | ||
event: string | null; | ||
@@ -400,3 +400,3 @@ data: string; | ||
*/ | ||
function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T> { | ||
export function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T> { | ||
if (stream[Symbol.asyncIterator]) return stream; | ||
@@ -403,0 +403,0 @@ |
@@ -1,1 +0,1 @@ | ||
export const VERSION = '0.12.3'; // x-release-please-version | ||
export const VERSION = '0.12.4'; // x-release-please-version |
import { ReadableStream, type Response } from "./_shims/index.js"; | ||
export type Bytes = string | ArrayBuffer | Uint8Array | Buffer | null | undefined; | ||
export type ServerSentEvent = { | ||
event: string | null; | ||
data: string; | ||
raw: string[]; | ||
}; | ||
export declare class Stream<Item> implements AsyncIterable<Item> { | ||
@@ -26,2 +33,9 @@ private iterator; | ||
} | ||
/** | ||
* Most browsers don't yet have async iterable support for ReadableStream, | ||
* and Node has a very different way of reading bytes from its "ReadableStream". | ||
* | ||
* This polyfill was pulled from https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490 | ||
*/ | ||
export declare function readableStreamAsyncIterable<T>(stream: any): AsyncIterableIterator<T>; | ||
//# sourceMappingURL=streaming.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Stream = void 0; | ||
exports.readableStreamAsyncIterable = exports.Stream = void 0; | ||
const index_1 = require("./_shims/index.js"); | ||
@@ -361,2 +361,3 @@ const error_1 = require("./error.js"); | ||
} | ||
exports.readableStreamAsyncIterable = readableStreamAsyncIterable; | ||
//# sourceMappingURL=streaming.js.map |
@@ -1,2 +0,2 @@ | ||
export declare const VERSION = "0.12.3"; | ||
export declare const VERSION = "0.12.4"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.VERSION = void 0; | ||
exports.VERSION = '0.12.3'; // x-release-please-version | ||
exports.VERSION = '0.12.4'; // x-release-please-version | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
655490
10421