@anthropic-ai/foundry-sdk 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +8 -0
- package/README.md +75 -0
- package/client.d.mts +58 -0
- package/client.d.mts.map +1 -0
- package/client.d.ts +58 -0
- package/client.d.ts.map +1 -0
- package/client.js +136 -0
- package/client.js.map +1 -0
- package/client.mjs +98 -0
- package/client.mjs.map +1 -0
- package/core/error.d.mts +2 -0
- package/core/error.d.mts.map +1 -0
- package/core/error.d.ts +2 -0
- package/core/error.d.ts.map +1 -0
- package/core/error.js +18 -0
- package/core/error.js.map +1 -0
- package/core/error.mjs +2 -0
- package/core/error.mjs.map +1 -0
- package/core/pagination.d.mts +2 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +2 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +18 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +2 -0
- package/core/pagination.mjs.map +1 -0
- package/core/streaming.d.mts +2 -0
- package/core/streaming.d.mts.map +1 -0
- package/core/streaming.d.ts +2 -0
- package/core/streaming.d.ts.map +1 -0
- package/core/streaming.js +18 -0
- package/core/streaming.js.map +1 -0
- package/core/streaming.mjs +2 -0
- package/core/streaming.mjs.map +1 -0
- package/index.d.mts +4 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +24 -0
- package/index.js.map +1 -0
- package/index.mjs +3 -0
- package/index.mjs.map +1 -0
- package/internal/builtin-types.d.mts +73 -0
- package/internal/builtin-types.d.mts.map +1 -0
- package/internal/builtin-types.d.ts +73 -0
- package/internal/builtin-types.d.ts.map +1 -0
- package/internal/builtin-types.js +4 -0
- package/internal/builtin-types.js.map +1 -0
- package/internal/builtin-types.mjs +3 -0
- package/internal/builtin-types.mjs.map +1 -0
- package/internal/constants.d.mts +5 -0
- package/internal/constants.d.mts.map +1 -0
- package/internal/constants.d.ts +5 -0
- package/internal/constants.d.ts.map +1 -0
- package/internal/constants.js +18 -0
- package/internal/constants.js.map +1 -0
- package/internal/constants.mjs +15 -0
- package/internal/constants.mjs.map +1 -0
- package/internal/decoders/jsonl.d.mts +10 -0
- package/internal/decoders/jsonl.d.mts.map +1 -0
- package/internal/decoders/jsonl.d.ts +10 -0
- package/internal/decoders/jsonl.d.ts.map +1 -0
- package/internal/decoders/jsonl.js +39 -0
- package/internal/decoders/jsonl.js.map +1 -0
- package/internal/decoders/jsonl.mjs +35 -0
- package/internal/decoders/jsonl.mjs.map +1 -0
- package/internal/decoders/line.d.mts +17 -0
- package/internal/decoders/line.d.mts.map +1 -0
- package/internal/decoders/line.d.ts +17 -0
- package/internal/decoders/line.d.ts.map +1 -0
- package/internal/decoders/line.js +123 -0
- package/internal/decoders/line.js.map +1 -0
- package/internal/decoders/line.mjs +118 -0
- package/internal/decoders/line.mjs.map +1 -0
- package/internal/errors.d.mts +3 -0
- package/internal/errors.d.mts.map +1 -0
- package/internal/errors.d.ts +3 -0
- package/internal/errors.d.ts.map +1 -0
- package/internal/errors.js +41 -0
- package/internal/errors.js.map +1 -0
- package/internal/errors.mjs +36 -0
- package/internal/errors.mjs.map +1 -0
- package/internal/headers.d.mts +22 -0
- package/internal/headers.d.mts.map +1 -0
- package/internal/headers.d.ts +22 -0
- package/internal/headers.d.ts.map +1 -0
- package/internal/headers.js +79 -0
- package/internal/headers.js.map +1 -0
- package/internal/headers.mjs +74 -0
- package/internal/headers.mjs.map +1 -0
- package/internal/parse.d.mts +17 -0
- package/internal/parse.d.mts.map +1 -0
- package/internal/parse.d.ts +17 -0
- package/internal/parse.d.ts.map +1 -0
- package/internal/parse.js +55 -0
- package/internal/parse.js.map +1 -0
- package/internal/parse.mjs +51 -0
- package/internal/parse.mjs.map +1 -0
- package/internal/request-options.d.mts +77 -0
- package/internal/request-options.d.mts.map +1 -0
- package/internal/request-options.d.ts +77 -0
- package/internal/request-options.d.ts.map +1 -0
- package/internal/request-options.js +14 -0
- package/internal/request-options.js.map +1 -0
- package/internal/request-options.mjs +10 -0
- package/internal/request-options.mjs.map +1 -0
- package/internal/shim-types.d.mts +17 -0
- package/internal/shim-types.d.mts.map +1 -0
- package/internal/shim-types.d.ts +17 -0
- package/internal/shim-types.d.ts.map +1 -0
- package/internal/shim-types.js +4 -0
- package/internal/shim-types.js.map +1 -0
- package/internal/shim-types.mjs +3 -0
- package/internal/shim-types.mjs.map +1 -0
- package/internal/shims.d.mts +20 -0
- package/internal/shims.d.mts.map +1 -0
- package/internal/shims.d.ts +20 -0
- package/internal/shims.d.ts.map +1 -0
- package/internal/shims.js +92 -0
- package/internal/shims.js.map +1 -0
- package/internal/shims.mjs +85 -0
- package/internal/shims.mjs.map +1 -0
- package/internal/stream-utils.d.mts +8 -0
- package/internal/stream-utils.d.mts.map +1 -0
- package/internal/stream-utils.d.ts +8 -0
- package/internal/stream-utils.d.ts.map +1 -0
- package/internal/stream-utils.js +38 -0
- package/internal/stream-utils.js.map +1 -0
- package/internal/stream-utils.mjs +35 -0
- package/internal/stream-utils.mjs.map +1 -0
- package/internal/to-file.d.mts +45 -0
- package/internal/to-file.d.mts.map +1 -0
- package/internal/to-file.d.ts +45 -0
- package/internal/to-file.d.ts.map +1 -0
- package/internal/to-file.js +96 -0
- package/internal/to-file.js.map +1 -0
- package/internal/to-file.mjs +93 -0
- package/internal/to-file.mjs.map +1 -0
- package/internal/types.d.mts +69 -0
- package/internal/types.d.mts.map +1 -0
- package/internal/types.d.ts +69 -0
- package/internal/types.d.ts.map +1 -0
- package/internal/types.js +4 -0
- package/internal/types.js.map +1 -0
- package/internal/types.mjs +3 -0
- package/internal/types.mjs.map +1 -0
- package/internal/uploads.d.mts +42 -0
- package/internal/uploads.d.mts.map +1 -0
- package/internal/uploads.d.ts +42 -0
- package/internal/uploads.d.ts.map +1 -0
- package/internal/uploads.js +146 -0
- package/internal/uploads.js.map +1 -0
- package/internal/uploads.mjs +136 -0
- package/internal/uploads.mjs.map +1 -0
- package/internal/utils/base64.d.mts +3 -0
- package/internal/utils/base64.d.mts.map +1 -0
- package/internal/utils/base64.d.ts +3 -0
- package/internal/utils/base64.d.ts.map +1 -0
- package/internal/utils/base64.js +38 -0
- package/internal/utils/base64.js.map +1 -0
- package/internal/utils/base64.mjs +33 -0
- package/internal/utils/base64.mjs.map +1 -0
- package/internal/utils/bytes.d.mts +4 -0
- package/internal/utils/bytes.d.mts.map +1 -0
- package/internal/utils/bytes.d.ts +4 -0
- package/internal/utils/bytes.d.ts.map +1 -0
- package/internal/utils/bytes.js +31 -0
- package/internal/utils/bytes.js.map +1 -0
- package/internal/utils/bytes.mjs +26 -0
- package/internal/utils/bytes.mjs.map +1 -0
- package/internal/utils/env.d.mts +9 -0
- package/internal/utils/env.d.mts.map +1 -0
- package/internal/utils/env.d.ts +9 -0
- package/internal/utils/env.d.ts.map +1 -0
- package/internal/utils/env.js +22 -0
- package/internal/utils/env.js.map +1 -0
- package/internal/utils/env.mjs +18 -0
- package/internal/utils/env.mjs.map +1 -0
- package/internal/utils/log.d.mts +37 -0
- package/internal/utils/log.d.mts.map +1 -0
- package/internal/utils/log.d.ts +37 -0
- package/internal/utils/log.d.ts.map +1 -0
- package/internal/utils/log.js +86 -0
- package/internal/utils/log.js.map +1 -0
- package/internal/utils/log.mjs +80 -0
- package/internal/utils/log.mjs.map +1 -0
- package/internal/utils/path.d.mts +15 -0
- package/internal/utils/path.d.mts.map +1 -0
- package/internal/utils/path.d.ts +15 -0
- package/internal/utils/path.d.ts.map +1 -0
- package/internal/utils/path.js +79 -0
- package/internal/utils/path.js.map +1 -0
- package/internal/utils/path.mjs +74 -0
- package/internal/utils/path.mjs.map +1 -0
- package/internal/utils/sleep.d.mts +2 -0
- package/internal/utils/sleep.d.mts.map +1 -0
- package/internal/utils/sleep.d.ts +2 -0
- package/internal/utils/sleep.d.ts.map +1 -0
- package/internal/utils/sleep.js +7 -0
- package/internal/utils/sleep.js.map +1 -0
- package/internal/utils/sleep.mjs +3 -0
- package/internal/utils/sleep.mjs.map +1 -0
- package/internal/utils/uuid.d.mts +5 -0
- package/internal/utils/uuid.d.mts.map +1 -0
- package/internal/utils/uuid.d.ts +5 -0
- package/internal/utils/uuid.d.ts.map +1 -0
- package/internal/utils/uuid.js +19 -0
- package/internal/utils/uuid.js.map +1 -0
- package/internal/utils/uuid.mjs +15 -0
- package/internal/utils/uuid.mjs.map +1 -0
- package/internal/utils/values.d.mts +19 -0
- package/internal/utils/values.d.mts.map +1 -0
- package/internal/utils/values.d.ts +19 -0
- package/internal/utils/values.d.ts.map +1 -0
- package/internal/utils/values.js +119 -0
- package/internal/utils/values.js.map +1 -0
- package/internal/utils/values.mjs +100 -0
- package/internal/utils/values.mjs.map +1 -0
- package/internal/utils.d.mts +7 -0
- package/internal/utils.d.mts.map +1 -0
- package/internal/utils.d.ts +7 -0
- package/internal/utils.d.ts.map +1 -0
- package/internal/utils.js +24 -0
- package/internal/utils.js.map +1 -0
- package/internal/utils.mjs +8 -0
- package/internal/utils.mjs.map +1 -0
- package/package.json +71 -0
- package/src/client.ts +166 -0
- package/src/core/error.ts +1 -0
- package/src/core/pagination.ts +1 -0
- package/src/core/streaming.ts +1 -0
- package/src/index.ts +3 -0
- package/src/internal/README.md +3 -0
- package/src/internal/builtin-types.ts +93 -0
- package/src/internal/constants.ts +15 -0
- package/src/internal/decoders/jsonl.ts +48 -0
- package/src/internal/decoders/line.ts +135 -0
- package/src/internal/detect-platform.ts +196 -0
- package/src/internal/errors.ts +33 -0
- package/src/internal/headers.ts +99 -0
- package/src/internal/parse.ts +84 -0
- package/src/internal/request-options.ts +93 -0
- package/src/internal/shim-types.ts +26 -0
- package/src/internal/shims.ts +107 -0
- package/src/internal/stream-utils.ts +32 -0
- package/src/internal/to-file.ts +159 -0
- package/src/internal/types.ts +95 -0
- package/src/internal/uploads.ts +193 -0
- package/src/internal/utils/base64.ts +40 -0
- package/src/internal/utils/bytes.ts +32 -0
- package/src/internal/utils/env.ts +18 -0
- package/src/internal/utils/log.ts +127 -0
- package/src/internal/utils/path.ts +88 -0
- package/src/internal/utils/sleep.ts +3 -0
- package/src/internal/utils/uuid.ts +17 -0
- package/src/internal/utils/values.ts +112 -0
- package/src/internal/utils.ts +8 -0
- package/src/tsconfig.json +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 (2025-11-18)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [foundry-sdk-v0.1.0...foundry-sdk-v0.2.0](https://github.com/anthropics/anthropic-sdk-typescript/compare/foundry-sdk-v0.1.0...foundry-sdk-v0.2.0)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
* add Foundry SDK ([40b0e87](https://github.com/anthropics/anthropic-sdk-typescript/commit/40b0e87047887dee3f9fab6e02fa65a1d728cf1e))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Chores
|
|
13
|
+
|
|
14
|
+
* **internal:** version bump ([eb97e85](https://github.com/anthropics/anthropic-sdk-typescript/commit/eb97e8577279fb150582297d2a0924a297185c3c))
|
|
15
|
+
* **internal:** version bump ([8ebaf61](https://github.com/anthropics/anthropic-sdk-typescript/commit/8ebaf616d2e5c6aebc153f19a403dde41ab5a9f1))
|
|
16
|
+
|
|
17
|
+
## Changelog
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright 2023 Anthropic, PBC.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Anthropic Foundry
|
|
2
|
+
|
|
3
|
+
To use this library with Foundry, use the `AnthropicFoundry`
|
|
4
|
+
class instead of the `Anthropic` class.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @anthropic-ai/foundry-sdk
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Basic Usage with API Key
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';
|
|
18
|
+
|
|
19
|
+
const client = new AnthropicFoundry({
|
|
20
|
+
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY, // defaults to process.env.ANTHROPIC_FOUNDRY_API_KEY
|
|
21
|
+
resource: 'example-resource.azure.anthropic.com', // your Azure resource
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const message = await client.messages.create({
|
|
25
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
26
|
+
max_tokens: 1024,
|
|
27
|
+
messages: [{ role: 'user', content: 'Hello, Claude!' }],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log(message.content);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Using Azure AD Token Provider
|
|
34
|
+
|
|
35
|
+
For enhanced security, you can use Azure AD (Microsoft Entra) authentication instead of an API key:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { AnthropicFoundry } from '@anthropic-ai/foundry-sdk';
|
|
39
|
+
import { getBearerTokenProvider, DefaultAzureCredential } from '@azure/identity';
|
|
40
|
+
|
|
41
|
+
const credential = new DefaultAzureCredential();
|
|
42
|
+
const scope = 'https://ai.azure.com/.default';
|
|
43
|
+
const azureADTokenProvider = getBearerTokenProvider(credential, scope);
|
|
44
|
+
|
|
45
|
+
const client = new AnthropicFoundry({
|
|
46
|
+
azureADTokenProvider,
|
|
47
|
+
resource: 'example-resource.azure.anthropic.com', // your Azure resource
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const message = await client.messages.create({
|
|
51
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
52
|
+
max_tokens: 1024,
|
|
53
|
+
messages: [{ role: 'user', content: 'Hello, Claude!' }],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log(message.content);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Using Model Deployments
|
|
60
|
+
|
|
61
|
+
If you have a model deployment configured, you can specify it to have the SDK automatically construct the correct URL path:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const client = new AnthropicFoundry({
|
|
65
|
+
apiKey: process.env.ANTHROPIC_FOUNDRY_API_KEY,
|
|
66
|
+
resource: 'example-resource.azure.anthropic.com',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// The SDK will automatically use /deployments/my-claude-deployment/messages
|
|
70
|
+
const message = await client.messages.create({
|
|
71
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
72
|
+
max_tokens: 1024,
|
|
73
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
74
|
+
});
|
|
75
|
+
```
|
package/client.d.mts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { NullableHeaders } from "./internal/headers.mjs";
|
|
2
|
+
import { Anthropic, ClientOptions } from '@anthropic-ai/sdk/client';
|
|
3
|
+
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
4
|
+
import * as Resources from '@anthropic-ai/sdk/resources/index';
|
|
5
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
6
|
+
export interface FoundryClientOptions extends ClientOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The name of your Foundry resource.
|
|
9
|
+
*
|
|
10
|
+
* For example, `https://{resource}.services.ai.azure.com/anthropic/v1/messages`.
|
|
11
|
+
*/
|
|
12
|
+
resource?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Defaults to process.env['ANTHROPIC_FOUNDRY_API_KEY'].
|
|
15
|
+
*/
|
|
16
|
+
apiKey?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),
|
|
19
|
+
* which will be invoked on every request.
|
|
20
|
+
*/
|
|
21
|
+
azureADTokenProvider?: (() => Promise<string>) | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
24
|
+
export declare class AnthropicFoundry extends Anthropic {
|
|
25
|
+
resource: string | null;
|
|
26
|
+
messages: MessagesResource;
|
|
27
|
+
beta: BetaResource;
|
|
28
|
+
models: undefined;
|
|
29
|
+
/**
|
|
30
|
+
* API Client for interfacing with the Anthropic Foundry API.
|
|
31
|
+
*
|
|
32
|
+
* @param {string | undefined} [opts.resource=process.env['ANTHROPIC_FOUNDRY_RESOURCE'] ?? undefined] - Your Foundry resource name
|
|
33
|
+
* @param {string | undefined} [opts.apiKey=process.env['ANTHROPIC_FOUNDRY_API_KEY'] ?? undefined]
|
|
34
|
+
* @param {string | null | undefined} [opts.organization=process.env['ANTHROPIC_ORG_ID'] ?? null]
|
|
35
|
+
* @param {string} [opts.baseURL=process.env['ANTHROPIC_FOUNDRY_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.anthropic.com/anthropic/`.
|
|
36
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
37
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
38
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
39
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
40
|
+
* @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
41
|
+
* @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
42
|
+
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
|
43
|
+
*/
|
|
44
|
+
constructor({ baseURL, apiKey, resource, azureADTokenProvider, dangerouslyAllowBrowser, ...opts }?: FoundryClientOptions);
|
|
45
|
+
protected authHeaders(): Promise<NullableHeaders | undefined>;
|
|
46
|
+
protected validateHeaders(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The Anthropic Foundry does not currently support the Batch API.
|
|
50
|
+
*/
|
|
51
|
+
type MessagesResource = Omit<Resources.Messages, 'batches'>;
|
|
52
|
+
/**
|
|
53
|
+
* The Anthropic Foundry does not currently support the Batch API.
|
|
54
|
+
*/
|
|
55
|
+
type BetaResource = Omit<Resources.Beta, 'messages'> & {
|
|
56
|
+
messages: Omit<Resources.Beta['messages'], 'batches'>;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=client.d.mts.map
|
package/client.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.mts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,eAAe,EAAE;OAIxB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OACjD,KAAK,SAAS,MAAM,mCAAmC;AAE9D,iEAAiE;AACjE,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CAC5D;AAED,iEAAiE;AACjE,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGtB,QAAQ,EAAE,gBAAgB,CAA8B;IAGxD,IAAI,EAAE,YAAY,CAA0B;IAG5C,MAAM,YAAa;IAC5B;;;;;;;;;;;;;;OAcG;gBACS,EACV,OAA+C,EAC/C,MAA6C,EAC7C,QAAgD,EAChD,oBAAoB,EACpB,uBAAuB,EACvB,GAAG,IAAI,EACR,GAAE,oBAAyB;cAuCH,WAAW,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;cA8BzD,eAAe,IAAI,IAAI;CAG3C;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAW5D;;GAEG;AACH,KAAK,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC;CACvD,CAAC"}
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { NullableHeaders } from "./internal/headers.js";
|
|
2
|
+
import { Anthropic, ClientOptions } from '@anthropic-ai/sdk/client';
|
|
3
|
+
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
4
|
+
import * as Resources from '@anthropic-ai/sdk/resources/index';
|
|
5
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
6
|
+
export interface FoundryClientOptions extends ClientOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The name of your Foundry resource.
|
|
9
|
+
*
|
|
10
|
+
* For example, `https://{resource}.services.ai.azure.com/anthropic/v1/messages`.
|
|
11
|
+
*/
|
|
12
|
+
resource?: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Defaults to process.env['ANTHROPIC_FOUNDRY_API_KEY'].
|
|
15
|
+
*/
|
|
16
|
+
apiKey?: string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* A function that returns an access token for Microsoft Entra (formerly known as Azure Active Directory),
|
|
19
|
+
* which will be invoked on every request.
|
|
20
|
+
*/
|
|
21
|
+
azureADTokenProvider?: (() => Promise<string>) | undefined;
|
|
22
|
+
}
|
|
23
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
24
|
+
export declare class AnthropicFoundry extends Anthropic {
|
|
25
|
+
resource: string | null;
|
|
26
|
+
messages: MessagesResource;
|
|
27
|
+
beta: BetaResource;
|
|
28
|
+
models: undefined;
|
|
29
|
+
/**
|
|
30
|
+
* API Client for interfacing with the Anthropic Foundry API.
|
|
31
|
+
*
|
|
32
|
+
* @param {string | undefined} [opts.resource=process.env['ANTHROPIC_FOUNDRY_RESOURCE'] ?? undefined] - Your Foundry resource name
|
|
33
|
+
* @param {string | undefined} [opts.apiKey=process.env['ANTHROPIC_FOUNDRY_API_KEY'] ?? undefined]
|
|
34
|
+
* @param {string | null | undefined} [opts.organization=process.env['ANTHROPIC_ORG_ID'] ?? null]
|
|
35
|
+
* @param {string} [opts.baseURL=process.env['ANTHROPIC_FOUNDRY_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.anthropic.com/anthropic/`.
|
|
36
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
37
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
38
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
39
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
40
|
+
* @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
41
|
+
* @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
42
|
+
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
|
43
|
+
*/
|
|
44
|
+
constructor({ baseURL, apiKey, resource, azureADTokenProvider, dangerouslyAllowBrowser, ...opts }?: FoundryClientOptions);
|
|
45
|
+
protected authHeaders(): Promise<NullableHeaders | undefined>;
|
|
46
|
+
protected validateHeaders(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The Anthropic Foundry does not currently support the Batch API.
|
|
50
|
+
*/
|
|
51
|
+
type MessagesResource = Omit<Resources.Messages, 'batches'>;
|
|
52
|
+
/**
|
|
53
|
+
* The Anthropic Foundry does not currently support the Batch API.
|
|
54
|
+
*/
|
|
55
|
+
type BetaResource = Omit<Resources.Beta, 'messages'> & {
|
|
56
|
+
messages: Omit<Resources.Beta['messages'], 'batches'>;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=client.d.ts.map
|
package/client.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,eAAe,EAAE;OAIxB,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OACjD,KAAK,SAAS,MAAM,mCAAmC;AAE9D,iEAAiE;AACjE,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACzD;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE9B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC;CAC5D;AAED,iEAAiE;AACjE,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAGtB,QAAQ,EAAE,gBAAgB,CAA8B;IAGxD,IAAI,EAAE,YAAY,CAA0B;IAG5C,MAAM,YAAa;IAC5B;;;;;;;;;;;;;;OAcG;gBACS,EACV,OAA+C,EAC/C,MAA6C,EAC7C,QAAgD,EAChD,oBAAoB,EACpB,uBAAuB,EACvB,GAAG,IAAI,EACR,GAAE,oBAAyB;cAuCH,WAAW,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;cA8BzD,eAAe,IAAI,IAAI;CAG3C;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAW5D;;GAEG;AACH,KAAK,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC;CACvD,CAAC"}
|
package/client.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AnthropicFoundry = exports.BaseAnthropic = void 0;
|
|
37
|
+
const headers_1 = require("./internal/headers.js");
|
|
38
|
+
const Errors = __importStar(require("./core/error.js"));
|
|
39
|
+
const utils_1 = require("./internal/utils.js");
|
|
40
|
+
const client_1 = require("@anthropic-ai/sdk/client");
|
|
41
|
+
var client_2 = require("@anthropic-ai/sdk/client");
|
|
42
|
+
Object.defineProperty(exports, "BaseAnthropic", { enumerable: true, get: function () { return client_2.BaseAnthropic; } });
|
|
43
|
+
const Resources = __importStar(require("@anthropic-ai/sdk/resources/index"));
|
|
44
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
45
|
+
class AnthropicFoundry extends client_1.Anthropic {
|
|
46
|
+
/**
|
|
47
|
+
* API Client for interfacing with the Anthropic Foundry API.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | undefined} [opts.resource=process.env['ANTHROPIC_FOUNDRY_RESOURCE'] ?? undefined] - Your Foundry resource name
|
|
50
|
+
* @param {string | undefined} [opts.apiKey=process.env['ANTHROPIC_FOUNDRY_API_KEY'] ?? undefined]
|
|
51
|
+
* @param {string | null | undefined} [opts.organization=process.env['ANTHROPIC_ORG_ID'] ?? null]
|
|
52
|
+
* @param {string} [opts.baseURL=process.env['ANTHROPIC_FOUNDRY_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.anthropic.com/anthropic/`.
|
|
53
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
54
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
55
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
56
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
57
|
+
* @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
58
|
+
* @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
59
|
+
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
|
60
|
+
*/
|
|
61
|
+
constructor({ baseURL = (0, utils_1.readEnv)('ANTHROPIC_FOUNDRY_BASE_URL'), apiKey = (0, utils_1.readEnv)('ANTHROPIC_FOUNDRY_API_KEY'), resource = (0, utils_1.readEnv)('ANTHROPIC_FOUNDRY_RESOURCE'), azureADTokenProvider, dangerouslyAllowBrowser, ...opts } = {}) {
|
|
62
|
+
if (typeof azureADTokenProvider === 'function') {
|
|
63
|
+
dangerouslyAllowBrowser = true;
|
|
64
|
+
}
|
|
65
|
+
if (!azureADTokenProvider && !apiKey) {
|
|
66
|
+
throw new Errors.AnthropicError('Missing credentials. Please pass one of `apiKey` and `azureTokenProvider`, or set the `ANTHROPIC_FOUNDRY_API_KEY` environment variable.');
|
|
67
|
+
}
|
|
68
|
+
if (azureADTokenProvider && apiKey) {
|
|
69
|
+
throw new Errors.AnthropicError('The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.');
|
|
70
|
+
}
|
|
71
|
+
if (!baseURL) {
|
|
72
|
+
if (!resource) {
|
|
73
|
+
throw new Errors.AnthropicError('Must provide one of the `baseURL` or `resource` arguments, or the `ANTHROPIC_FOUNDRY_RESOURCE` environment variable');
|
|
74
|
+
}
|
|
75
|
+
baseURL = `https://${resource}.services.ai.azure.com/anthropic/`;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
if (resource) {
|
|
79
|
+
throw new Errors.AnthropicError('baseURL and resource are mutually exclusive');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
super({
|
|
83
|
+
apiKey: azureADTokenProvider ?? apiKey,
|
|
84
|
+
baseURL,
|
|
85
|
+
...opts,
|
|
86
|
+
...(dangerouslyAllowBrowser !== undefined ? { dangerouslyAllowBrowser } : {}),
|
|
87
|
+
});
|
|
88
|
+
this.resource = null;
|
|
89
|
+
// @ts-expect-error are using a different Messages type that omits batches
|
|
90
|
+
this.messages = makeMessagesResource(this);
|
|
91
|
+
// @ts-expect-error are using a different Beta type that omits batches
|
|
92
|
+
this.beta = makeBetaResource(this);
|
|
93
|
+
// @ts-expect-error Anthropic Foundry does not support models endpoint
|
|
94
|
+
this.models = undefined;
|
|
95
|
+
}
|
|
96
|
+
async authHeaders() {
|
|
97
|
+
if (typeof this._options.apiKey === 'function') {
|
|
98
|
+
let token;
|
|
99
|
+
try {
|
|
100
|
+
token = await this._options.apiKey();
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (err instanceof Errors.AnthropicError)
|
|
104
|
+
throw err;
|
|
105
|
+
throw new Errors.AnthropicError(`Failed to get token from azureADTokenProvider: ${err.message}`,
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
{ cause: err });
|
|
108
|
+
}
|
|
109
|
+
if (typeof token !== 'string' || !token) {
|
|
110
|
+
throw new Errors.AnthropicError(`Expected azureADTokenProvider function argument to return a string but it returned ${token}`);
|
|
111
|
+
}
|
|
112
|
+
return (0, headers_1.buildHeaders)([{ Authorization: `Bearer ${token}` }]);
|
|
113
|
+
}
|
|
114
|
+
if (typeof this._options.apiKey === 'string') {
|
|
115
|
+
return (0, headers_1.buildHeaders)([{ 'x-api-key': this.apiKey }]);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
validateHeaders() {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.AnthropicFoundry = AnthropicFoundry;
|
|
124
|
+
function makeMessagesResource(client) {
|
|
125
|
+
const resource = new Resources.Messages(client);
|
|
126
|
+
// @ts-expect-error we're deleting non-optional properties
|
|
127
|
+
delete resource.batches;
|
|
128
|
+
return resource;
|
|
129
|
+
}
|
|
130
|
+
function makeBetaResource(client) {
|
|
131
|
+
const resource = new Resources.Beta(client);
|
|
132
|
+
// @ts-expect-error we're deleting non-optional properties
|
|
133
|
+
delete resource.messages.batches;
|
|
134
|
+
return resource;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=client.js.map
|
package/client.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mDAAkD;AAClD,wDAAuC;AACvC,+CAA2C;AAC3C,qDAAoE;AACpE,mDAAyD;AAAhD,uGAAA,aAAa,OAAA;AACtB,6EAA+D;AAuB/D,iEAAiE;AACjE,MAAa,gBAAiB,SAAQ,kBAAS;IAW7C;;;;;;;;;;;;;;OAcG;IACH,YAAY,EACV,OAAO,GAAG,IAAA,eAAO,EAAC,4BAA4B,C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IAExB,OAAO,QAAQ,CAAC;AAClB,CAAC;AASD,SAAS,gBAAgB,CAAC,MAAwB;IAChD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;IAEjC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/client.mjs
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { buildHeaders } from "./internal/headers.mjs";
|
|
2
|
+
import * as Errors from "./core/error.mjs";
|
|
3
|
+
import { readEnv } from "./internal/utils.mjs";
|
|
4
|
+
import { Anthropic } from '@anthropic-ai/sdk/client';
|
|
5
|
+
export { BaseAnthropic } from '@anthropic-ai/sdk/client';
|
|
6
|
+
import * as Resources from '@anthropic-ai/sdk/resources/index';
|
|
7
|
+
/** API Client for interfacing with the Anthropic Foundry API. */
|
|
8
|
+
export class AnthropicFoundry extends Anthropic {
|
|
9
|
+
/**
|
|
10
|
+
* API Client for interfacing with the Anthropic Foundry API.
|
|
11
|
+
*
|
|
12
|
+
* @param {string | undefined} [opts.resource=process.env['ANTHROPIC_FOUNDRY_RESOURCE'] ?? undefined] - Your Foundry resource name
|
|
13
|
+
* @param {string | undefined} [opts.apiKey=process.env['ANTHROPIC_FOUNDRY_API_KEY'] ?? undefined]
|
|
14
|
+
* @param {string | null | undefined} [opts.organization=process.env['ANTHROPIC_ORG_ID'] ?? null]
|
|
15
|
+
* @param {string} [opts.baseURL=process.env['ANTHROPIC_FOUNDRY_BASE_URL']] - Sets the base URL for the API, e.g. `https://example-resource.azure.anthropic.com/anthropic/`.
|
|
16
|
+
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
17
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
|
18
|
+
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
19
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
|
20
|
+
* @param {Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
|
21
|
+
* @param {DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
22
|
+
* @param {boolean} [opts.dangerouslyAllowBrowser=false] - By default, client-side use of this library is not allowed, as it risks exposing your secret API credentials to attackers.
|
|
23
|
+
*/
|
|
24
|
+
constructor({ baseURL = readEnv('ANTHROPIC_FOUNDRY_BASE_URL'), apiKey = readEnv('ANTHROPIC_FOUNDRY_API_KEY'), resource = readEnv('ANTHROPIC_FOUNDRY_RESOURCE'), azureADTokenProvider, dangerouslyAllowBrowser, ...opts } = {}) {
|
|
25
|
+
if (typeof azureADTokenProvider === 'function') {
|
|
26
|
+
dangerouslyAllowBrowser = true;
|
|
27
|
+
}
|
|
28
|
+
if (!azureADTokenProvider && !apiKey) {
|
|
29
|
+
throw new Errors.AnthropicError('Missing credentials. Please pass one of `apiKey` and `azureTokenProvider`, or set the `ANTHROPIC_FOUNDRY_API_KEY` environment variable.');
|
|
30
|
+
}
|
|
31
|
+
if (azureADTokenProvider && apiKey) {
|
|
32
|
+
throw new Errors.AnthropicError('The `apiKey` and `azureADTokenProvider` arguments are mutually exclusive; only one can be passed at a time.');
|
|
33
|
+
}
|
|
34
|
+
if (!baseURL) {
|
|
35
|
+
if (!resource) {
|
|
36
|
+
throw new Errors.AnthropicError('Must provide one of the `baseURL` or `resource` arguments, or the `ANTHROPIC_FOUNDRY_RESOURCE` environment variable');
|
|
37
|
+
}
|
|
38
|
+
baseURL = `https://${resource}.services.ai.azure.com/anthropic/`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (resource) {
|
|
42
|
+
throw new Errors.AnthropicError('baseURL and resource are mutually exclusive');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
super({
|
|
46
|
+
apiKey: azureADTokenProvider ?? apiKey,
|
|
47
|
+
baseURL,
|
|
48
|
+
...opts,
|
|
49
|
+
...(dangerouslyAllowBrowser !== undefined ? { dangerouslyAllowBrowser } : {}),
|
|
50
|
+
});
|
|
51
|
+
this.resource = null;
|
|
52
|
+
// @ts-expect-error are using a different Messages type that omits batches
|
|
53
|
+
this.messages = makeMessagesResource(this);
|
|
54
|
+
// @ts-expect-error are using a different Beta type that omits batches
|
|
55
|
+
this.beta = makeBetaResource(this);
|
|
56
|
+
// @ts-expect-error Anthropic Foundry does not support models endpoint
|
|
57
|
+
this.models = undefined;
|
|
58
|
+
}
|
|
59
|
+
async authHeaders() {
|
|
60
|
+
if (typeof this._options.apiKey === 'function') {
|
|
61
|
+
let token;
|
|
62
|
+
try {
|
|
63
|
+
token = await this._options.apiKey();
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
if (err instanceof Errors.AnthropicError)
|
|
67
|
+
throw err;
|
|
68
|
+
throw new Errors.AnthropicError(`Failed to get token from azureADTokenProvider: ${err.message}`,
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
{ cause: err });
|
|
71
|
+
}
|
|
72
|
+
if (typeof token !== 'string' || !token) {
|
|
73
|
+
throw new Errors.AnthropicError(`Expected azureADTokenProvider function argument to return a string but it returned ${token}`);
|
|
74
|
+
}
|
|
75
|
+
return buildHeaders([{ Authorization: `Bearer ${token}` }]);
|
|
76
|
+
}
|
|
77
|
+
if (typeof this._options.apiKey === 'string') {
|
|
78
|
+
return buildHeaders([{ 'x-api-key': this.apiKey }]);
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
validateHeaders() {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function makeMessagesResource(client) {
|
|
87
|
+
const resource = new Resources.Messages(client);
|
|
88
|
+
// @ts-expect-error we're deleting non-optional properties
|
|
89
|
+
delete resource.batches;
|
|
90
|
+
return resource;
|
|
91
|
+
}
|
|
92
|
+
function makeBetaResource(client) {
|
|
93
|
+
const resource = new Resources.Beta(client);
|
|
94
|
+
// @ts-expect-error we're deleting non-optional properties
|
|
95
|
+
delete resource.messages.batches;
|
|
96
|
+
return resource;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=client.mjs.map
|
package/client.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.mjs","sourceRoot":"","sources":["src/client.ts"],"names":[],"mappings":"OACO,EAAE,YAAY,EAAE;OAChB,KAAK,MAAM;OACX,EAAE,OAAO,EAAE;OACX,EAAE,SAAS,EAAiB,MAAM,0BAA0B;OAC5D,EAAE,aAAa,EAAE,MAAM,0BAA0B;OACjD,KAAK,SAAS,MAAM,mCAAmC;AAuB9D,iEAAiE;AACjE,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAW7C;;;;;;;;;;;;;;OAcG;IACH,YAAY,EACV,OAAO,GAAG,OAAO,CAAC,4BAA4B,CAAC,EAC/C,MAAM,GAAG,OAAO,CAAC,2BAA2B,CAAC,EAC7C,QAAQ,GAAG,OAAO,CAAC,4BAA4B,CAAC,EAChD,oBAAoB,EACpB,uBAAuB,EACvB,GAAG,IAAI,KACiB,EAAE;QAC1B,IAAI,OAAO,oBAAoB,KAAK,UAAU,EAAE,CAAC;YAC/C,uBAAuB,GAAG,IAAI,CAAC;QACjC,CAAC;QAED,IAAI,CAAC,oBAAoB,IAAI,CAAC,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,MAAM,CAAC,cAAc,CAC7B,yIAAyI,CAC1I,CAAC;QACJ,CAAC;QAED,IAAI,oBAAoB,IAAI,MAAM,EAAE,CAAC;YACnC,MAAM,IAAI,MAAM,CAAC,cAAc,CAC7B,6GAA6G,CAC9G,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,MAAM,CAAC,cAAc,CAC7B,qHAAqH,CACtH,CAAC;YACJ,CAAC;YAED,OAAO,G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,CAAC;YAED,OAAO,YAAY,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC;QAC9D,CAAC;QAED,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC7C,OAAO,YAAY,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAEkB,eAAe;QAChC,OAAO;IACT,CAAC;CACF;AAOD,SAAS,oBAAoB,CAAC,MAAwB;IACpD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEhD,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,OAAO,CAAC;IAExB,OAAO,QAAQ,CAAC;AAClB,CAAC;AASD,SAAS,gBAAgB,CAAC,MAAwB;IAChD,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,0DAA0D;IAC1D,OAAO,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC;IAEjC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/core/error.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.mts","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}
|
package/core/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}
|
package/core/error.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@anthropic-ai/sdk/core/error"), exports);
|
|
18
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+DAA6C"}
|
package/core/error.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.mjs","sourceRoot":"","sources":["../src/core/error.ts"],"names":[],"mappings":"cAAc,8BAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.mts","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@anthropic-ai/sdk/core/pagination"), exports);
|
|
18
|
+
//# sourceMappingURL=pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,oEAAkD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pagination.mjs","sourceRoot":"","sources":["../src/core/pagination.ts"],"names":[],"mappings":"cAAc,mCAAmC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.mts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"cAAc,kCAAkC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"cAAc,kCAAkC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("@anthropic-ai/sdk/core/streaming"), exports);
|
|
18
|
+
//# sourceMappingURL=streaming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mEAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming.mjs","sourceRoot":"","sources":["../src/core/streaming.ts"],"names":[],"mappings":"cAAc,kCAAkC"}
|
package/index.d.mts
ADDED
package/index.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";OACO,EAAE,gBAAgB,IAAI,OAAO,EAAE;YAC1B,EAAE,oBAAoB,EAAE"}
|
package/index.d.ts
ADDED