@aigne/anthropic 0.11.1 → 0.11.3

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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.11.3](https://github.com/AIGNE-io/aigne-framework/compare/anthropic-v0.11.2...anthropic-v0.11.3) (2025-08-16)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **core:** make getCredential async for aigne-hub mount point retrieval ([#372](https://github.com/AIGNE-io/aigne-framework/issues/372)) ([34ce7a6](https://github.com/AIGNE-io/aigne-framework/commit/34ce7a645fa83994d3dfe0f29ca70098cfecac9c))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @aigne/core bumped to 1.50.1
16
+ * devDependencies
17
+ * @aigne/test-utils bumped to 0.5.29
18
+
19
+ ## [0.11.2](https://github.com/AIGNE-io/aigne-framework/compare/anthropic-v0.11.1...anthropic-v0.11.2) (2025-08-14)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **cli:** log only once in loadAIGNE ([#357](https://github.com/AIGNE-io/aigne-framework/issues/357)) ([6e6d968](https://github.com/AIGNE-io/aigne-framework/commit/6e6d96814fbc87f210522ae16daf94c1f84f311a))
25
+
26
+
27
+ ### Dependencies
28
+
29
+ * The following workspace dependencies were updated
30
+ * dependencies
31
+ * @aigne/core bumped to 1.50.0
32
+ * devDependencies
33
+ * @aigne/test-utils bumped to 0.5.28
34
+
3
35
  ## [0.11.1](https://github.com/AIGNE-io/aigne-framework/compare/anthropic-v0.11.0...anthropic-v0.11.1) (2025-08-12)
4
36
 
5
37
 
@@ -104,8 +104,12 @@ export declare class AnthropicChatModel extends ChatModel {
104
104
  * @hidden
105
105
  */
106
106
  protected _client?: Anthropic;
107
- get client(): Anthropic;
107
+ client(): Promise<Anthropic>;
108
108
  get modelOptions(): ChatModelOptions | undefined;
109
+ getCredential(): Promise<{
110
+ apiKey: string | undefined;
111
+ model: string;
112
+ }>;
109
113
  private getMaxTokens;
110
114
  /**
111
115
  * Process the input using Claude's chat model
@@ -62,8 +62,8 @@ class AnthropicChatModel extends core_1.ChatModel {
62
62
  * @hidden
63
63
  */
64
64
  _client;
65
- get client() {
66
- const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || process.env.CLAUDE_API_KEY;
65
+ async client() {
66
+ const { apiKey } = await this.getCredential();
67
67
  if (!apiKey)
68
68
  throw new Error("AnthropicChatModel requires an API key. Please provide it via `options.apiKey`, or set the `ANTHROPIC_API_KEY` or `CLAUDE_API_KEY` environment variable");
69
69
  this._client ??= new sdk_1.default({
@@ -76,6 +76,13 @@ class AnthropicChatModel extends core_1.ChatModel {
76
76
  get modelOptions() {
77
77
  return this.options?.modelOptions;
78
78
  }
79
+ async getCredential() {
80
+ const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || process.env.CLAUDE_API_KEY;
81
+ return {
82
+ apiKey,
83
+ model: this.options?.model || CHAT_MODEL_CLAUDE_DEFAULT_MODEL,
84
+ };
85
+ }
79
86
  getMaxTokens(model) {
80
87
  const matchers = [
81
88
  [/claude-opus-4-/, 32000],
@@ -101,7 +108,7 @@ class AnthropicChatModel extends core_1.ChatModel {
101
108
  }
102
109
  ajv = new ajv_1.Ajv();
103
110
  async _process(input) {
104
- const model = this.options?.model || CHAT_MODEL_CLAUDE_DEFAULT_MODEL;
111
+ const { model } = await this.getCredential();
105
112
  const disableParallelToolUse = input.modelOptions?.parallelToolCalls === false ||
106
113
  this.modelOptions?.parallelToolCalls === false;
107
114
  const body = {
@@ -118,7 +125,8 @@ class AnthropicChatModel extends core_1.ChatModel {
118
125
  if (!input.tools?.length && input.responseFormat?.type === "json_schema") {
119
126
  return this.requestStructuredOutput(body, input.responseFormat);
120
127
  }
121
- const stream = this.client.messages.stream({
128
+ const client = await this.client();
129
+ const stream = client.messages.stream({
122
130
  ...body,
123
131
  stream: true,
124
132
  });
@@ -223,7 +231,8 @@ class AnthropicChatModel extends core_1.ChatModel {
223
231
  if (responseFormat?.type !== "json_schema") {
224
232
  throw new Error("Expected json_schema response format");
225
233
  }
226
- const result = await this.client.messages.create({
234
+ const client = await this.client();
235
+ const result = await client.messages.create({
227
236
  ...body,
228
237
  tools: [
229
238
  {
@@ -104,8 +104,12 @@ export declare class AnthropicChatModel extends ChatModel {
104
104
  * @hidden
105
105
  */
106
106
  protected _client?: Anthropic;
107
- get client(): Anthropic;
107
+ client(): Promise<Anthropic>;
108
108
  get modelOptions(): ChatModelOptions | undefined;
109
+ getCredential(): Promise<{
110
+ apiKey: string | undefined;
111
+ model: string;
112
+ }>;
109
113
  private getMaxTokens;
110
114
  /**
111
115
  * Process the input using Claude's chat model
@@ -104,8 +104,12 @@ export declare class AnthropicChatModel extends ChatModel {
104
104
  * @hidden
105
105
  */
106
106
  protected _client?: Anthropic;
107
- get client(): Anthropic;
107
+ client(): Promise<Anthropic>;
108
108
  get modelOptions(): ChatModelOptions | undefined;
109
+ getCredential(): Promise<{
110
+ apiKey: string | undefined;
111
+ model: string;
112
+ }>;
109
113
  private getMaxTokens;
110
114
  /**
111
115
  * Process the input using Claude's chat model
@@ -56,8 +56,8 @@ export class AnthropicChatModel extends ChatModel {
56
56
  * @hidden
57
57
  */
58
58
  _client;
59
- get client() {
60
- const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || process.env.CLAUDE_API_KEY;
59
+ async client() {
60
+ const { apiKey } = await this.getCredential();
61
61
  if (!apiKey)
62
62
  throw new Error("AnthropicChatModel requires an API key. Please provide it via `options.apiKey`, or set the `ANTHROPIC_API_KEY` or `CLAUDE_API_KEY` environment variable");
63
63
  this._client ??= new Anthropic({
@@ -70,6 +70,13 @@ export class AnthropicChatModel extends ChatModel {
70
70
  get modelOptions() {
71
71
  return this.options?.modelOptions;
72
72
  }
73
+ async getCredential() {
74
+ const apiKey = this.options?.apiKey || process.env[this.apiKeyEnvName] || process.env.CLAUDE_API_KEY;
75
+ return {
76
+ apiKey,
77
+ model: this.options?.model || CHAT_MODEL_CLAUDE_DEFAULT_MODEL,
78
+ };
79
+ }
73
80
  getMaxTokens(model) {
74
81
  const matchers = [
75
82
  [/claude-opus-4-/, 32000],
@@ -95,7 +102,7 @@ export class AnthropicChatModel extends ChatModel {
95
102
  }
96
103
  ajv = new Ajv();
97
104
  async _process(input) {
98
- const model = this.options?.model || CHAT_MODEL_CLAUDE_DEFAULT_MODEL;
105
+ const { model } = await this.getCredential();
99
106
  const disableParallelToolUse = input.modelOptions?.parallelToolCalls === false ||
100
107
  this.modelOptions?.parallelToolCalls === false;
101
108
  const body = {
@@ -112,7 +119,8 @@ export class AnthropicChatModel extends ChatModel {
112
119
  if (!input.tools?.length && input.responseFormat?.type === "json_schema") {
113
120
  return this.requestStructuredOutput(body, input.responseFormat);
114
121
  }
115
- const stream = this.client.messages.stream({
122
+ const client = await this.client();
123
+ const stream = client.messages.stream({
116
124
  ...body,
117
125
  stream: true,
118
126
  });
@@ -217,7 +225,8 @@ export class AnthropicChatModel extends ChatModel {
217
225
  if (responseFormat?.type !== "json_schema") {
218
226
  throw new Error("Expected json_schema response format");
219
227
  }
220
- const result = await this.client.messages.create({
228
+ const client = await this.client();
229
+ const result = await client.messages.create({
221
230
  ...body,
222
231
  tools: [
223
232
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/anthropic",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "AIGNE Anthropic SDK for integrating with Claude AI models",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -38,7 +38,7 @@
38
38
  "@anthropic-ai/sdk": "^0.56.0",
39
39
  "ajv": "^8.17.1",
40
40
  "zod": "^3.25.67",
41
- "@aigne/core": "^1.49.1"
41
+ "@aigne/core": "^1.50.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/bun": "^1.2.18",
@@ -46,7 +46,7 @@
46
46
  "npm-run-all": "^4.1.5",
47
47
  "rimraf": "^6.0.1",
48
48
  "typescript": "^5.8.3",
49
- "@aigne/test-utils": "^0.5.27"
49
+ "@aigne/test-utils": "^0.5.29"
50
50
  },
51
51
  "scripts": {
52
52
  "lint": "tsc --noEmit",