@agent-api/sdk 1.4.1 → 1.4.2
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 +6 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +3 -0
- package/dist/internal/http.d.ts +1 -0
- package/dist/internal/http.js +4 -2
- package/dist/types/common.d.ts +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist-cjs/client.js +3 -0
- package/dist-cjs/internal/http.js +4 -2
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const DEFAULT_STREAM_TIMEOUT_MS = 3600000;
|
|
|
14
14
|
export declare const DEFAULT_MAX_RETRIES = 2;
|
|
15
15
|
export declare class AgentAPI {
|
|
16
16
|
readonly apiKey?: string;
|
|
17
|
+
readonly apiKeyProvider?: ClientOptions["apiKeyProvider"];
|
|
17
18
|
readonly baseURL: string;
|
|
18
19
|
readonly timeout: number;
|
|
19
20
|
readonly streamTimeout: number;
|
package/dist/client.js
CHANGED
|
@@ -15,6 +15,7 @@ export const DEFAULT_STREAM_TIMEOUT_MS = 3_600_000;
|
|
|
15
15
|
export const DEFAULT_MAX_RETRIES = 2;
|
|
16
16
|
export class AgentAPI {
|
|
17
17
|
apiKey;
|
|
18
|
+
apiKeyProvider;
|
|
18
19
|
baseURL;
|
|
19
20
|
timeout;
|
|
20
21
|
streamTimeout;
|
|
@@ -32,6 +33,7 @@ export class AgentAPI {
|
|
|
32
33
|
http;
|
|
33
34
|
constructor(options = {}) {
|
|
34
35
|
this.apiKey = options.apiKey ?? readEnv("AGENT_API_KEY");
|
|
36
|
+
this.apiKeyProvider = options.apiKeyProvider;
|
|
35
37
|
this.baseURL = (options.baseURL ?? readEnv("AGENT_API_BASE_URL") ?? "https://api.agentsway.dev").replace(/\/+$/, "");
|
|
36
38
|
this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
|
|
37
39
|
this.streamTimeout = options.streamTimeout ?? DEFAULT_STREAM_TIMEOUT_MS;
|
|
@@ -44,6 +46,7 @@ export class AgentAPI {
|
|
|
44
46
|
this.http = new HTTPClient({
|
|
45
47
|
baseURL: this.baseURL,
|
|
46
48
|
apiKey: this.apiKey,
|
|
49
|
+
apiKeyProvider: this.apiKeyProvider,
|
|
47
50
|
timeout: this.timeout,
|
|
48
51
|
streamTimeout: this.streamTimeout,
|
|
49
52
|
maxRetries: this.maxRetries,
|
package/dist/internal/http.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { RequestOptions } from "../types/common.js";
|
|
|
2
2
|
export interface HTTPClientOptions {
|
|
3
3
|
baseURL: string;
|
|
4
4
|
apiKey?: string;
|
|
5
|
+
apiKeyProvider?: () => string | undefined | Promise<string | undefined>;
|
|
5
6
|
timeout: number;
|
|
6
7
|
streamTimeout: number;
|
|
7
8
|
maxRetries: number;
|
package/dist/internal/http.js
CHANGED
|
@@ -79,8 +79,10 @@ export class HTTPClient {
|
|
|
79
79
|
if (body !== undefined && !rawBody) {
|
|
80
80
|
headers["Content-Type"] = "application/json";
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
const providedAPIKey = this.options.apiKeyProvider ? await this.options.apiKeyProvider() : undefined;
|
|
83
|
+
const apiKey = providedAPIKey ?? this.options.apiKey;
|
|
84
|
+
if (apiKey) {
|
|
85
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
84
86
|
}
|
|
85
87
|
const response = await this.options.fetchImpl(`${this.options.baseURL}${path}`, {
|
|
86
88
|
method,
|
package/dist/types/common.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type ModelRoutingMode = "auto" | "chain";
|
|
|
7
7
|
export type ModelRoutingStrategy = "balanced" | "high-quality" | "cost-effective";
|
|
8
8
|
export interface ClientOptions {
|
|
9
9
|
apiKey?: string;
|
|
10
|
+
apiKeyProvider?: () => string | undefined | Promise<string | undefined>;
|
|
10
11
|
baseURL?: string;
|
|
11
12
|
/** Default request timeout in milliseconds (non-streaming). */
|
|
12
13
|
timeout?: number;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.4.
|
|
2
|
-
export declare const USER_AGENT = "@agent-api/sdk/1.4.
|
|
1
|
+
export declare const VERSION = "1.4.2";
|
|
2
|
+
export declare const USER_AGENT = "@agent-api/sdk/1.4.2";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "1.4.
|
|
1
|
+
export const VERSION = "1.4.2";
|
|
2
2
|
export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
|
package/dist-cjs/client.js
CHANGED
|
@@ -19,6 +19,7 @@ exports.DEFAULT_STREAM_TIMEOUT_MS = 3_600_000;
|
|
|
19
19
|
exports.DEFAULT_MAX_RETRIES = 2;
|
|
20
20
|
class AgentAPI {
|
|
21
21
|
apiKey;
|
|
22
|
+
apiKeyProvider;
|
|
22
23
|
baseURL;
|
|
23
24
|
timeout;
|
|
24
25
|
streamTimeout;
|
|
@@ -36,6 +37,7 @@ class AgentAPI {
|
|
|
36
37
|
http;
|
|
37
38
|
constructor(options = {}) {
|
|
38
39
|
this.apiKey = options.apiKey ?? (0, env_js_1.readEnv)("AGENT_API_KEY");
|
|
40
|
+
this.apiKeyProvider = options.apiKeyProvider;
|
|
39
41
|
this.baseURL = (options.baseURL ?? (0, env_js_1.readEnv)("AGENT_API_BASE_URL") ?? "https://api.agentsway.dev").replace(/\/+$/, "");
|
|
40
42
|
this.timeout = options.timeout ?? exports.DEFAULT_TIMEOUT_MS;
|
|
41
43
|
this.streamTimeout = options.streamTimeout ?? exports.DEFAULT_STREAM_TIMEOUT_MS;
|
|
@@ -48,6 +50,7 @@ class AgentAPI {
|
|
|
48
50
|
this.http = new http_js_1.HTTPClient({
|
|
49
51
|
baseURL: this.baseURL,
|
|
50
52
|
apiKey: this.apiKey,
|
|
53
|
+
apiKeyProvider: this.apiKeyProvider,
|
|
51
54
|
timeout: this.timeout,
|
|
52
55
|
streamTimeout: this.streamTimeout,
|
|
53
56
|
maxRetries: this.maxRetries,
|
|
@@ -82,8 +82,10 @@ class HTTPClient {
|
|
|
82
82
|
if (body !== undefined && !rawBody) {
|
|
83
83
|
headers["Content-Type"] = "application/json";
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
const providedAPIKey = this.options.apiKeyProvider ? await this.options.apiKeyProvider() : undefined;
|
|
86
|
+
const apiKey = providedAPIKey ?? this.options.apiKey;
|
|
87
|
+
if (apiKey) {
|
|
88
|
+
headers.Authorization = `Bearer ${apiKey}`;
|
|
87
89
|
}
|
|
88
90
|
const response = await this.options.fetchImpl(`${this.options.baseURL}${path}`, {
|
|
89
91
|
method,
|
package/dist-cjs/version.js
CHANGED