Skip to content
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

feat: alpha release #642

Merged
merged 10 commits into from
Dec 20, 2024
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
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ module.exports = {
'no-unused-vars': 'off',
'prettier/prettier': 'error',
'unused-imports/no-unused-imports': 'error',
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['@anthropic-ai/sdk', '@anthropic-ai/sdk/*'],
message: 'Use a relative import, not a package import.',
},
],
},
],
},
overrides: [
{
files: ['tests/**', 'examples/**'],
rules: {
'no-restricted-imports': 'off',
},
},
],
root: true,
};
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
push:
branches:
- main
- alpha
pull_request:
branches:
- main
- next
- alpha

jobs:
lint:
Expand Down Expand Up @@ -64,4 +66,3 @@ jobs:

- name: Run tests
run: ./scripts/test

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.33.1",
".": "0.34.0-alpha.0",
"packages/vertex-sdk": "0.6.1",
"packages/bedrock-sdk": "0.12.0"
}
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 19
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-be055148d227480fcacc9086c37ac8009dcb487731069ada51af35044f65bee4.yml
configured_endpoints: 21
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/anthropic-fd67aea6883f1ee9e46f31a42d3940f0acb1749e787055bd9b9f278b20fa53ec.yml
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Setting up the environment

This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old link was outdated :)

Other package managers may work but are not officially supported for development.

To set up the repository, run:
Expand Down Expand Up @@ -29,10 +29,10 @@ All files in the `examples/` directory are not modified by the generator and can
```

```
chmod +x examples/<your-example>.ts
```sh
$ chmod +x examples/<your-example>.ts
# run the example against your api
yarn tsn -T examples/<your-example>.ts
$ yarn tsn -T examples/<your-example>.ts
```

## Using the repository from source
Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,21 +414,23 @@ validate or strip extra properties from the response from the API.

### Customizing the fetch client

By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
By default, this library expects a global `fetch` function is defined.

If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
add the following import before your first import `from "Anthropic"`:
If you want to use a different `fetch` function, you can either polyfill the global:

```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import '@anthropic-ai/sdk/shims/web';
import Anthropic from '@anthropic-ai/sdk';
import fetch from 'my-fetch';

globalThis.fetch = fetch;
```

To do the inverse, add `import "@anthropic-ai/sdk/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/anthropics/anthropic-sdk-typescript/tree/main/src/_shims#readme)).
Or pass it to the client:

```ts
import fetch from 'my-fetch';

const client = new Anthropic({ fetch });
```

### Logging and middleware

Expand Down Expand Up @@ -481,6 +483,8 @@ await client.messages.create(
);
```

## Frequently Asked Questions

## Semantic versioning

This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
Expand All @@ -495,7 +499,7 @@ We are keen for your feedback; please open an [issue](https://www.github.com/ant

## Requirements

TypeScript >= 4.5 is supported.
TypeScript >= 4.9 is supported.

The following runtimes are supported:

Expand Down
20 changes: 12 additions & 8 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Methods:

Types:

- <code><a href="./src/resources/messages/batches.ts">DeletedMessageBatch</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatch</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchCanceledResult</a></code>
- <code><a href="./src/resources/messages/batches.ts">MessageBatchErroredResult</a></code>
Expand All @@ -82,10 +83,11 @@ Types:
Methods:

- <code title="post /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">create</a>({ ...params }) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">retrieve</a>(messageBatchId) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">retrieve</a>(messageBatchID) -> MessageBatch</code>
- <code title="get /v1/messages/batches">client.messages.batches.<a href="./src/resources/messages/batches.ts">list</a>({ ...params }) -> MessageBatchesPage</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/resources/messages/batches.ts">cancel</a>(messageBatchId) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/resources/messages/batches.ts">results</a>(messageBatchId) -> Response</code>
- <code title="delete /v1/messages/batches/{message_batch_id}">client.messages.batches.<a href="./src/resources/messages/batches.ts">delete</a>(messageBatchID) -> DeletedMessageBatch</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel">client.messages.batches.<a href="./src/resources/messages/batches.ts">cancel</a>(messageBatchID) -> MessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results">client.messages.batches.<a href="./src/resources/messages/batches.ts">results</a>(messageBatchID) -> Response</code>

# Models

Expand All @@ -95,7 +97,7 @@ Types:

Methods:

- <code title="get /v1/models/{model_id}">client.models.<a href="./src/resources/models.ts">retrieve</a>(modelId) -> ModelInfo</code>
- <code title="get /v1/models/{model_id}">client.models.<a href="./src/resources/models.ts">retrieve</a>(modelID) -> ModelInfo</code>
- <code title="get /v1/models">client.models.<a href="./src/resources/models.ts">list</a>({ ...params }) -> ModelInfosPage</code>

# Beta
Expand Down Expand Up @@ -123,7 +125,7 @@ Types:

Methods:

- <code title="get /v1/models/{model_id}?beta=true">client.beta.models.<a href="./src/resources/beta/models.ts">retrieve</a>(modelId) -> BetaModelInfo</code>
- <code title="get /v1/models/{model_id}?beta=true">client.beta.models.<a href="./src/resources/beta/models.ts">retrieve</a>(modelID) -> BetaModelInfo</code>
- <code title="get /v1/models?beta=true">client.beta.models.<a href="./src/resources/beta/models.ts">list</a>({ ...params }) -> BetaModelInfosPage</code>

## Messages
Expand Down Expand Up @@ -175,6 +177,7 @@ Methods:

Types:

- <code><a href="./src/resources/beta/messages/batches.ts">BetaDeletedMessageBatch</a></code>
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatch</a></code>
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchCanceledResult</a></code>
- <code><a href="./src/resources/beta/messages/batches.ts">BetaMessageBatchErroredResult</a></code>
Expand All @@ -187,7 +190,8 @@ Types:
Methods:

- <code title="post /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">create</a>({ ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">retrieve</a>(messageBatchId, { ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">retrieve</a>(messageBatchID, { ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">list</a>({ ...params }) -> BetaMessageBatchesPage</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">cancel</a>(messageBatchId, { ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">results</a>(messageBatchId, { ...params }) -> Response</code>
- <code title="delete /v1/messages/batches/{message_batch_id}?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">delete</a>(messageBatchID, { ...params }) -> BetaDeletedMessageBatch</code>
- <code title="post /v1/messages/batches/{message_batch_id}/cancel?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">cancel</a>(messageBatchID, { ...params }) -> BetaMessageBatch</code>
- <code title="get /v1/messages/batches/{message_batch_id}/results?beta=true">client.beta.messages.batches.<a href="./src/resources/beta/messages/batches.ts">results</a>(messageBatchID, { ...params }) -> Response</code>
1 change: 0 additions & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const config: JestConfigWithTsJest = {
},
moduleNameMapper: {
'^@anthropic-ai/sdk$': '<rootDir>/src/index.ts',
'^@anthropic-ai/sdk/_shims/auto/(.*)$': '<rootDir>/src/_shims/auto/$1-node',
'^@anthropic-ai/sdk/(.*)$': '<rootDir>/src/$1',
},
modulePathIgnorePatterns: [
Expand Down
77 changes: 11 additions & 66 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anthropic-ai/sdk",
"version": "0.33.1",
"version": "0.34.0-alpha.0",
"description": "The official TypeScript library for the Anthropic API",
"author": "Anthropic <[email protected]>",
"types": "dist/index.d.ts",
Expand All @@ -23,101 +23,46 @@
"lint": "./scripts/lint",
"fix": "./scripts/format"
},
"dependencies": {
"@types/node": "^18.11.18",
"@types/node-fetch": "^2.6.4",
"abort-controller": "^3.0.0",
"agentkeepalive": "^4.2.1",
"form-data-encoder": "1.7.2",
"formdata-node": "^4.3.2",
"node-fetch": "^2.6.7"
},
"dependencies": {},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.0",
"@swc/core": "^1.3.102",
"@swc/jest": "^0.2.29",
"@types/jest": "^29.4.0",
"@types/node": "^20.17.6",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.49.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-unused-imports": "^3.0.0",
"iconv-lite": "^0.6.3",
"jest": "^29.4.0",
"prettier": "^3.0.0",
"publint": "^0.2.12",
"ts-jest": "^29.1.0",
"ts-node": "^10.5.0",
"tsc-multi": "^1.1.0",
"tsc-multi": "https://github.com/stainless-api/tsc-multi/releases/download/v1.1.3/tsc-multi.tgz",
"tsconfig-paths": "^4.0.0",
"typescript": "^4.8.2"
},
"sideEffects": [
"./_shims/index.js",
"./_shims/index.mjs",
"./shims/node.js",
"./shims/node.mjs",
"./shims/web.js",
"./shims/web.mjs"
],
"imports": {
"@anthropic-ai/sdk": ".",
"@anthropic-ai/sdk/*": "./src/*"
},
"exports": {
"./_shims/auto/*": {
"deno": {
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*.js",
"default": "./dist/_shims/auto/*.mjs"
},
"bun": {
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*-bun.js",
"default": "./dist/_shims/auto/*-bun.mjs"
},
"browser": {
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*.js",
"default": "./dist/_shims/auto/*.mjs"
},
"worker": {
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*.js",
"default": "./dist/_shims/auto/*.mjs"
},
"workerd": {
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*.js",
"default": "./dist/_shims/auto/*.mjs"
},
"node": {
"types": "./dist/_shims/auto/*-node.d.ts",
"require": "./dist/_shims/auto/*-node.js",
"default": "./dist/_shims/auto/*-node.mjs"
},
"types": "./dist/_shims/auto/*.d.ts",
"require": "./dist/_shims/auto/*.js",
"default": "./dist/_shims/auto/*.mjs"
},
".": {
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./*.mjs": {
"types": "./dist/*.d.ts",
"default": "./dist/*.mjs"
},
"./*.js": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
},
"./*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js",
"default": "./dist/*.mjs"
"import": "./dist/*.mjs",
"require": "./dist/*.js"
}
}
}
8 changes: 4 additions & 4 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rm -rf dist; mkdir dist
# Copy src to dist/src and build from dist/src into dist, so that
# the source map for index.js.map will refer to ./src/index.ts etc
cp -rp src README.md dist
rm dist/src/_shims/*-deno.ts dist/src/_shims/auto/*-deno.ts
for file in LICENSE CHANGELOG.md; do
if [ -e "${file}" ]; then cp "${file}" dist; fi
done
Expand All @@ -29,9 +28,6 @@ node scripts/utils/make-dist-package-json.cjs > dist/package.json

# build to .js/.mjs/.d.ts files
npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Anthropic to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
Expand All @@ -42,6 +38,10 @@ node scripts/utils/fix-index-exports.cjs
# the same export default statement)
cp dist/index.d.ts dist/index.d.mts
cp tsconfig.dist-src.json dist/src/tsconfig.json
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.ts
cp src/internal/shim-types.d.ts dist/internal/shim-types.d.mts
mkdir -p dist/internal/polyfill
cp src/internal/polyfill/*.{mjs,js,d.ts} dist/internal/polyfill

node scripts/utils/postprocess-files.cjs

Expand Down
11 changes: 6 additions & 5 deletions scripts/build-all
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ set -exuo pipefail

bash ./scripts/build

for dir in packages/*; do
if [ -d "$dir" ]; then
(cd "$dir" && yarn install && yarn build)
fi
done
# temporarily disabled
# for dir in packages/*; do
# if [ -d "$dir" ]; then
# (cd "$dir" && yarn install && yarn build)
# fi
# done
13 changes: 10 additions & 3 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ set -e
cd "$(dirname "$0")/.."

echo "==> Running eslint"
ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js .
ESLINT_USE_FLAT_CONFIG="false" ./node_modules/.bin/eslint --ext ts,js . --ignore-pattern="packages/"

echo "==> Running tsc"
./node_modules/.bin/tsc --noEmit
echo "==> Building"
./scripts/build # also checks types

echo "==> Running Are The Types Wrong?"
./node_modules/.bin/attw --pack dist -f json >.attw.json || true
node scripts/utils/attw-report.cjs

echo "==> Running publint"
./node_modules/.bin/publint dist
Loading
Loading