Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@anthropic-ai/sdk

Package Overview
Dependencies
Maintainers
6
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@anthropic-ai/sdk - npm Package Compare versions

Comparing version 0.5.8 to 0.5.9

19

CHANGELOG.md
# Changelog
## [0.5.9](https://github.com/anthropics/anthropic-sdk-typescript/compare/v0.5.8...v0.5.9) (2023-07-29)
### Bug Fixes
* **client:** handle undefined process in more places ([#87](https://github.com/anthropics/anthropic-sdk-typescript/issues/87)) ([d950c25](https://github.com/anthropics/anthropic-sdk-typescript/commit/d950c25469a6c6b0dd3cfecd282db078826366ba))
* **examples:** avoid swallowing errors in example scripts ([#82](https://github.com/anthropics/anthropic-sdk-typescript/issues/82)) ([b27cfe9](https://github.com/anthropics/anthropic-sdk-typescript/commit/b27cfe9323bce983bb49f57dece98f1d9e507034))
* fix undefined message in errors ([#86](https://github.com/anthropics/anthropic-sdk-typescript/issues/86)) ([5714a14](https://github.com/anthropics/anthropic-sdk-typescript/commit/5714a14d9af282a3d308b8694e6e03309d4b5642))
### Chores
* **internal:** minor refactoring of client instantiation ([#88](https://github.com/anthropics/anthropic-sdk-typescript/issues/88)) ([2c53e1c](https://github.com/anthropics/anthropic-sdk-typescript/commit/2c53e1ca28a444a48e5f1041d9eb9077608b3fc7))
### Refactors
* use destructuring arguments in client constructor and respect false values ([#89](https://github.com/anthropics/anthropic-sdk-typescript/issues/89)) ([8d4c686](https://github.com/anthropics/anthropic-sdk-typescript/commit/8d4c6860273bbd16027023700d521a5e48db76f7))
## [0.5.8](https://github.com/anthropics/anthropic-sdk-typescript/compare/v0.5.7...v0.5.8) (2023-07-22)

@@ -4,0 +23,0 @@

@@ -210,5 +210,14 @@ import { APIError } from './error.js';

export declare const ensurePresent: <T>(value: T | null | undefined) => T;
/**
* Read an environment variable.
*
* Will return an empty string if the environment variable doesn't exist or cannot be accessed.
*/
export declare const readEnv: (env: string) => string | undefined;
export declare const coerceInteger: (value: unknown) => number;
export declare const coerceFloat: (value: unknown) => number;
export declare const coerceBoolean: (value: unknown) => boolean;
export declare const maybeCoerceInteger: (value: unknown) => number | undefined;
export declare const maybeCoerceFloat: (value: unknown) => number | undefined;
export declare const maybeCoerceBoolean: (value: unknown) => boolean | undefined;
export declare function isEmptyObj(obj: Object | null | undefined): boolean;

@@ -215,0 +224,0 @@ export declare function hasOwn(obj: Object, key: string): boolean;

@@ -36,5 +36,9 @@ 'use strict';

exports.isEmptyObj =
exports.maybeCoerceBoolean =
exports.maybeCoerceFloat =
exports.maybeCoerceInteger =
exports.coerceBoolean =
exports.coerceFloat =
exports.coerceInteger =
exports.readEnv =
exports.ensurePresent =

@@ -632,2 +636,15 @@ exports.castToError =

exports.ensurePresent = ensurePresent;
/**
* Read an environment variable.
*
* Will return an empty string if the environment variable doesn't exist or cannot be accessed.
*/
const readEnv = (env) => {
var _a;
if (typeof process === 'undefined') {
return undefined;
}
return (_a = process.env[env]) !== null && _a !== void 0 ? _a : undefined;
};
exports.readEnv = readEnv;
const coerceInteger = (value) => {

@@ -651,2 +668,23 @@ if (typeof value === 'number') return Math.round(value);

exports.coerceBoolean = coerceBoolean;
const maybeCoerceInteger = (value) => {
if (value === undefined) {
return undefined;
}
return (0, exports.coerceInteger)(value);
};
exports.maybeCoerceInteger = maybeCoerceInteger;
const maybeCoerceFloat = (value) => {
if (value === undefined) {
return undefined;
}
return (0, exports.coerceFloat)(value);
};
exports.maybeCoerceFloat = maybeCoerceFloat;
const maybeCoerceBoolean = (value) => {
if (value === undefined) {
return undefined;
}
return (0, exports.coerceBoolean)(value);
};
exports.maybeCoerceBoolean = maybeCoerceBoolean;
// https://stackoverflow.com/a/34491287

@@ -653,0 +691,0 @@ function isEmptyObj(obj) {

1

error.d.ts

@@ -12,2 +12,3 @@ import { Headers } from './core.js';

);
private static makeMessage;
static generate(

@@ -14,0 +15,0 @@ status: number | undefined,

15

error.js

@@ -20,5 +20,3 @@ 'use strict';

constructor(status, error, message, headers) {
super(
message || (error === null || error === void 0 ? void 0 : error.message) || 'Unknown error occurred.',
);
super(APIError.makeMessage(error, message));
this.status = status;

@@ -28,2 +26,13 @@ this.headers = headers;

}
static makeMessage(error, message) {
return (
(
error === null || error === void 0 ? void 0 : error.message
) ?
typeof error.message === 'string' ? error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message || 'Unknown error occurred'
);
}
static generate(status, errorResponse, message, headers) {

@@ -30,0 +39,0 @@ if (!status) {

@@ -65,3 +65,3 @@ import * as Core from './core.js';

private _options;
constructor(opts?: ClientOptions);
constructor({ apiKey, authToken, ...opts }?: ClientOptions);
completions: API.Completions;

@@ -68,0 +68,0 @@ protected defaultQuery(): Core.DefaultQuery | undefined;

@@ -69,6 +69,14 @@ 'use strict';

class Anthropic extends Core.APIClient {
constructor(opts) {
constructor(_b) {
var _c, _d;
var {
apiKey = (_c = Core.readEnv('ANTHROPIC_API_KEY')) !== null && _c !== void 0 ? _c : null,
authToken = (_d = Core.readEnv('ANTHROPIC_AUTH_TOKEN')) !== null && _d !== void 0 ? _d : null,
...opts
} = _b === void 0 ? {} : _b;
undefined;
const options = {
apiKey: typeof process === 'undefined' ? '' : process.env['ANTHROPIC_API_KEY'] || '',
baseURL: 'https://api.anthropic.com',
apiKey,
authToken,
baseURL: `https://api.anthropic.com`,
...opts,

@@ -84,8 +92,5 @@ };

this.completions = new API.Completions(this);
this.apiKey = options.apiKey || null;
this._options = options;
this.authToken =
(opts === null || opts === void 0 ? void 0 : opts.authToken) ||
process.env['ANTHROPIC_AUTH_TOKEN'] ||
null;
this.apiKey = apiKey;
this.authToken = authToken;
}

@@ -92,0 +97,0 @@ defaultQuery() {

{
"name": "@anthropic-ai/sdk",
"version": "0.5.8",
"version": "0.5.9",
"description": "Client library for the Anthropic API",

@@ -5,0 +5,0 @@ "author": "Anthropic <support@anthropic.com>",

@@ -110,3 +110,4 @@ # Anthropic TypeScript API Library

}
main().catch(console.error);
main();
```

@@ -157,3 +158,4 @@

}
main().catch(console.error);
main();
```

@@ -182,6 +184,9 @@

console.log(err.headers); // {server: 'nginx', ...}
} else {
throw err;
}
});
}
main().catch(console.error);
main();
```

@@ -188,0 +193,0 @@

@@ -767,2 +767,15 @@ import { VERSION } from './version';

/**
* Read an environment variable.
*
* Will return an empty string if the environment variable doesn't exist or cannot be accessed.
*/
export const readEnv = (env: string): string | undefined => {
if (typeof process === 'undefined') {
return undefined;
}
return process.env[env] ?? undefined;
};
export const coerceInteger = (value: unknown): number => {

@@ -788,2 +801,23 @@ if (typeof value === 'number') return Math.round(value);

export const maybeCoerceInteger = (value: unknown): number | undefined => {
if (value === undefined) {
return undefined;
}
return coerceInteger(value);
};
export const maybeCoerceFloat = (value: unknown): number | undefined => {
if (value === undefined) {
return undefined;
}
return coerceFloat(value);
};
export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
if (value === undefined) {
return undefined;
}
return coerceBoolean(value);
};
// https://stackoverflow.com/a/34491287

@@ -790,0 +824,0 @@ export function isEmptyObj(obj: Object | null | undefined): boolean {

@@ -16,3 +16,3 @@ // File generated from our OpenAPI spec by Stainless.

) {
super(message || (error as any)?.message || 'Unknown error occurred.');
super(APIError.makeMessage(error, message));
this.status = status;

@@ -23,2 +23,12 @@ this.headers = headers;

private static makeMessage(error: any, message: string | undefined) {
return (
error?.message ?
typeof error.message === 'string' ? error.message
: JSON.stringify(error.message)
: error ? JSON.stringify(error)
: message || 'Unknown error occurred'
);
}
static generate(

@@ -25,0 +35,0 @@ status: number | undefined,

@@ -79,6 +79,13 @@ // File generated from our OpenAPI spec by Stainless.

constructor(opts?: ClientOptions) {
constructor({
apiKey = Core.readEnv('ANTHROPIC_API_KEY') ?? null,
authToken = Core.readEnv('ANTHROPIC_AUTH_TOKEN') ?? null,
...opts
}: ClientOptions = {}) {
undefined;
const options: ClientOptions = {
apiKey: typeof process === 'undefined' ? '' : process.env['ANTHROPIC_API_KEY'] || '',
baseURL: 'https://api.anthropic.com',
apiKey,
authToken,
baseURL: `https://api.anthropic.com`,
...opts,

@@ -94,6 +101,6 @@ };

});
this.apiKey = options.apiKey || null;
this._options = options;
this.authToken = opts?.authToken || process.env['ANTHROPIC_AUTH_TOKEN'] || null;
this.apiKey = apiKey;
this.authToken = authToken;
}

@@ -100,0 +107,0 @@

@@ -1,1 +0,1 @@

export const VERSION = '0.5.8'; // x-release-please-version
export const VERSION = '0.5.9'; // x-release-please-version

@@ -1,2 +0,2 @@

export declare const VERSION = '0.5.8';
export declare const VERSION = '0.5.9';
//# sourceMappingURL=version.d.ts.map
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.VERSION = void 0;
exports.VERSION = '0.5.8'; // x-release-please-version
exports.VERSION = '0.5.9'; // 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc