@anvia/anthropic 0.5.1 → 1.0.0-rc.10
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/README.md +13 -11
- package/dist/index.d.ts +49 -38
- package/dist/index.js +580 -216
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -19,22 +19,23 @@ pnpm --filter @anvia/anthropic build
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
21
|
```ts
|
|
22
|
-
import {
|
|
22
|
+
import { Agent } from "@anvia/core";
|
|
23
23
|
import { AnthropicClient } from "@anvia/anthropic";
|
|
24
24
|
|
|
25
25
|
const client = new AnthropicClient({
|
|
26
26
|
apiKey,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
const model = client.completionModel("claude-sonnet-4-20250514");
|
|
29
|
+
const model = client.completionModel({ modelId: "claude-sonnet-4-20250514" });
|
|
30
30
|
|
|
31
|
-
const agent = new
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
const agent = new Agent({
|
|
32
|
+
id: "assistant",
|
|
33
|
+
model: model,
|
|
34
|
+
instructions: "Answer clearly and concisely.",
|
|
35
|
+
});
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const result = await agent.generate({ prompt: "Summarize Anvia in one sentence." });
|
|
38
|
+
if (result.status === "completed") console.log(result.output);
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
## Anthropic-Compatible APIs
|
|
@@ -49,7 +50,7 @@ const client = new AnthropicClient({
|
|
|
49
50
|
baseUrl,
|
|
50
51
|
});
|
|
51
52
|
|
|
52
|
-
const model = client.completionModel("provider/model-name");
|
|
53
|
+
const model = client.completionModel({ modelId: "provider/model-name" });
|
|
53
54
|
```
|
|
54
55
|
|
|
55
56
|
## Vertex AI
|
|
@@ -64,7 +65,7 @@ const client = new AnthropicVertexClient({
|
|
|
64
65
|
region: "global",
|
|
65
66
|
});
|
|
66
67
|
|
|
67
|
-
const model = client.completionModel("claude-sonnet-5");
|
|
68
|
+
const model = client.completionModel({ modelId: "claude-sonnet-5" });
|
|
68
69
|
```
|
|
69
70
|
|
|
70
71
|
The client follows the standard Google authentication flow. It reads
|
|
@@ -108,7 +109,8 @@ provide `listModels()`.
|
|
|
108
109
|
|
|
109
110
|
- `AnthropicClient`
|
|
110
111
|
- `AnthropicVertexClient`
|
|
111
|
-
-
|
|
112
|
+
- structural Anthropic and Vertex completion handle types
|
|
113
|
+
- `AnthropicCompletionModelId`
|
|
112
114
|
- `anthropic`
|
|
113
115
|
|
|
114
116
|
## Development
|
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1,70 @@
|
|
|
1
|
-
import Anthropic
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { ModelContextLimits, StreamingCompletionModel } from '@anvia/core/completion';
|
|
2
3
|
import { ModelId, ModelListingClient, ModelList } from '@anvia/core/model-listing';
|
|
3
|
-
import {
|
|
4
|
-
import { StreamingCompletionModel, CompletionModelCapabilities, CompletionModelMetadataOptions, CompletionModelInfo, CompletionRequest, JsonObject, CompletionResponse, CompletionStreamEvent } from '@anvia/core/completion';
|
|
4
|
+
import { ClientOptions, AnthropicVertex } from '@anthropic-ai/vertex-sdk';
|
|
5
5
|
|
|
6
|
-
type
|
|
7
|
-
type
|
|
6
|
+
type KnownAnthropicCompletionModelId = "claude-3-5-sonnet-20240620" | "claude-3-5-sonnet-20241022" | "claude-3-7-sonnet-20250219" | "claude-3-haiku-20240307" | "claude-3-opus-20240229" | "claude-3-sonnet-20240229" | "claude-fable-5" | "claude-haiku-4-5" | "claude-haiku-4-5-20251001" | "claude-opus-4-0" | "claude-opus-4-1" | "claude-opus-4-1-20250805" | "claude-opus-4-20250514" | "claude-opus-4-5" | "claude-opus-4-5-20251101" | "claude-opus-4-6" | "claude-opus-4-7" | "claude-opus-4-8" | "claude-sonnet-4-0" | "claude-sonnet-4-20250514" | "claude-sonnet-4-5" | "claude-sonnet-4-5-20250929" | "claude-sonnet-4-6" | "claude-sonnet-5";
|
|
7
|
+
type AnthropicCompletionModelId = ModelId<KnownAnthropicCompletionModelId>;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly defaultModel: AnthropicCompletionModelName;
|
|
12
|
-
private readonly metadataOptions;
|
|
13
|
-
readonly provider = "anthropic";
|
|
14
|
-
readonly capabilities: CompletionModelCapabilities;
|
|
15
|
-
constructor(client: Anthropic | AnthropicVertex, defaultModel?: AnthropicCompletionModelName, metadataOptions?: CompletionModelMetadataOptions);
|
|
16
|
-
getModelInfo(model?: AnthropicCompletionModelName): CompletionModelInfo<AnthropicCompletionModelName> | undefined;
|
|
17
|
-
traceRequest(request: CompletionRequest<AnthropicCompletionModelName>, options?: {
|
|
18
|
-
stream?: boolean | undefined;
|
|
19
|
-
}): JsonObject;
|
|
20
|
-
completion(request: CompletionRequest<AnthropicCompletionModelName>): Promise<CompletionResponse>;
|
|
21
|
-
streamCompletion(request: CompletionRequest<AnthropicCompletionModelName>): AsyncIterable<CompletionStreamEvent>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type AnthropicClientOptions = {
|
|
25
|
-
apiKey?: string | undefined;
|
|
9
|
+
type AnthropicManagedClientOptions = {
|
|
10
|
+
apiKey: string;
|
|
26
11
|
baseUrl?: string | undefined;
|
|
27
|
-
client?:
|
|
12
|
+
client?: never;
|
|
13
|
+
};
|
|
14
|
+
type AnthropicInjectedClientOptions = {
|
|
15
|
+
client: Anthropic;
|
|
16
|
+
apiKey?: never;
|
|
17
|
+
baseUrl?: never;
|
|
28
18
|
};
|
|
19
|
+
type AnthropicClientOptions = AnthropicManagedClientOptions | AnthropicInjectedClientOptions;
|
|
20
|
+
type AnthropicCompletionModelOptions = {
|
|
21
|
+
modelId: AnthropicCompletionModelId;
|
|
22
|
+
contextLimits?: ModelContextLimits | undefined;
|
|
23
|
+
};
|
|
24
|
+
type AnthropicCompletionModelHandle = StreamingCompletionModel<unknown>;
|
|
29
25
|
declare class AnthropicClient implements ModelListingClient {
|
|
30
|
-
readonly
|
|
31
|
-
constructor(options
|
|
32
|
-
completionModel(
|
|
33
|
-
listModels(
|
|
26
|
+
private readonly sdk;
|
|
27
|
+
constructor(options: AnthropicClientOptions);
|
|
28
|
+
completionModel(options: AnthropicCompletionModelOptions): AnthropicCompletionModelHandle;
|
|
29
|
+
listModels(options?: {
|
|
30
|
+
abortSignal?: AbortSignal | undefined;
|
|
31
|
+
}): Promise<ModelList>;
|
|
34
32
|
}
|
|
35
33
|
|
|
36
|
-
type
|
|
37
|
-
client?:
|
|
34
|
+
type AnthropicVertexManagedClientOptions = Omit<ClientOptions, "maxRetries"> & {
|
|
35
|
+
client?: never;
|
|
36
|
+
};
|
|
37
|
+
type AnthropicVertexInjectedClientOptions = {
|
|
38
|
+
client: AnthropicVertex;
|
|
39
|
+
} & {
|
|
40
|
+
[Key in Exclude<keyof AnthropicVertexManagedClientOptions, "client">]?: never;
|
|
41
|
+
};
|
|
42
|
+
type AnthropicVertexClientOptions = AnthropicVertexManagedClientOptions | AnthropicVertexInjectedClientOptions;
|
|
43
|
+
type AnthropicVertexCompletionModelOptions = {
|
|
44
|
+
modelId: AnthropicCompletionModelId;
|
|
45
|
+
contextLimits?: ModelContextLimits | undefined;
|
|
38
46
|
};
|
|
47
|
+
type AnthropicVertexCompletionModelHandle = StreamingCompletionModel<unknown>;
|
|
39
48
|
declare class AnthropicVertexClient {
|
|
40
|
-
readonly
|
|
41
|
-
constructor(options
|
|
42
|
-
completionModel(
|
|
49
|
+
private readonly sdk;
|
|
50
|
+
constructor(options: AnthropicVertexClientOptions);
|
|
51
|
+
completionModel(options: AnthropicVertexCompletionModelOptions): AnthropicVertexCompletionModelHandle;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
type index_AnthropicClient = AnthropicClient;
|
|
46
55
|
declare const index_AnthropicClient: typeof AnthropicClient;
|
|
47
56
|
type index_AnthropicClientOptions = AnthropicClientOptions;
|
|
48
|
-
type
|
|
49
|
-
|
|
50
|
-
type
|
|
57
|
+
type index_AnthropicCompletionModelHandle = AnthropicCompletionModelHandle;
|
|
58
|
+
type index_AnthropicCompletionModelId = AnthropicCompletionModelId;
|
|
59
|
+
type index_AnthropicCompletionModelOptions = AnthropicCompletionModelOptions;
|
|
51
60
|
type index_AnthropicVertexClient = AnthropicVertexClient;
|
|
52
61
|
declare const index_AnthropicVertexClient: typeof AnthropicVertexClient;
|
|
53
62
|
type index_AnthropicVertexClientOptions = AnthropicVertexClientOptions;
|
|
54
|
-
type
|
|
63
|
+
type index_AnthropicVertexCompletionModelHandle = AnthropicVertexCompletionModelHandle;
|
|
64
|
+
type index_AnthropicVertexCompletionModelOptions = AnthropicVertexCompletionModelOptions;
|
|
65
|
+
type index_KnownAnthropicCompletionModelId = KnownAnthropicCompletionModelId;
|
|
55
66
|
declare namespace index {
|
|
56
|
-
export { index_AnthropicClient as AnthropicClient, type index_AnthropicClientOptions as AnthropicClientOptions,
|
|
67
|
+
export { index_AnthropicClient as AnthropicClient, type index_AnthropicClientOptions as AnthropicClientOptions, type index_AnthropicCompletionModelHandle as AnthropicCompletionModelHandle, type index_AnthropicCompletionModelId as AnthropicCompletionModelId, type index_AnthropicCompletionModelOptions as AnthropicCompletionModelOptions, index_AnthropicVertexClient as AnthropicVertexClient, type index_AnthropicVertexClientOptions as AnthropicVertexClientOptions, type index_AnthropicVertexCompletionModelHandle as AnthropicVertexCompletionModelHandle, type index_AnthropicVertexCompletionModelOptions as AnthropicVertexCompletionModelOptions, type index_KnownAnthropicCompletionModelId as KnownAnthropicCompletionModelId };
|
|
57
68
|
}
|
|
58
69
|
|
|
59
|
-
export { AnthropicClient, type AnthropicClientOptions,
|
|
70
|
+
export { AnthropicClient, type AnthropicClientOptions, type AnthropicCompletionModelHandle, type AnthropicCompletionModelId, type AnthropicCompletionModelOptions, AnthropicVertexClient, type AnthropicVertexClientOptions, type AnthropicVertexCompletionModelHandle, type AnthropicVertexCompletionModelOptions, type KnownAnthropicCompletionModelId, index as anthropic };
|