@agent-api/sdk 1.4.0 → 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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — @agent-api/sdk
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Added
6
+
7
+ - Added per-request `apiKeyProvider` support, allowing long-lived applications to supply refreshed bearer tokens without rebuilding clients.
8
+
9
+ ## 1.4.1
10
+
11
+ ### Added
12
+
13
+ - Added `client.memories.search(...)` for the public `/v1/memories/search` API.
14
+
3
15
  ## 1.4.0
4
16
 
5
17
  ### Added
package/dist/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { HTTPClient } from "./internal/http.js";
2
2
  import { AuthResource } from "./resources/auth.js";
3
+ import { MemoriesResource } from "./resources/memories.js";
3
4
  import { ModelsResource } from "./resources/models.js";
4
5
  import { PresetsResource } from "./resources/presets.js";
5
6
  import { ResponsesResource } from "./resources/responses.js";
@@ -13,6 +14,7 @@ export declare const DEFAULT_STREAM_TIMEOUT_MS = 3600000;
13
14
  export declare const DEFAULT_MAX_RETRIES = 2;
14
15
  export declare class AgentAPI {
15
16
  readonly apiKey?: string;
17
+ readonly apiKeyProvider?: ClientOptions["apiKeyProvider"];
16
18
  readonly baseURL: string;
17
19
  readonly timeout: number;
18
20
  readonly streamTimeout: number;
@@ -21,6 +23,7 @@ export declare class AgentAPI {
21
23
  readonly responses: ResponsesResource;
22
24
  readonly agent: ResponsesResource;
23
25
  readonly models: ModelsResource;
26
+ readonly memories: MemoriesResource;
24
27
  readonly presets: PresetsResource;
25
28
  readonly tools: ToolsResource;
26
29
  readonly volumes: VolumesResource;
package/dist/client.js CHANGED
@@ -2,6 +2,7 @@ import { APIConnectionError } from "./errors.js";
2
2
  import { readEnv } from "./internal/env.js";
3
3
  import { HTTPClient } from "./internal/http.js";
4
4
  import { AuthResource } from "./resources/auth.js";
5
+ import { MemoriesResource } from "./resources/memories.js";
5
6
  import { ModelsResource } from "./resources/models.js";
6
7
  import { PresetsResource } from "./resources/presets.js";
7
8
  import { ResponsesResource } from "./resources/responses.js";
@@ -14,6 +15,7 @@ export const DEFAULT_STREAM_TIMEOUT_MS = 3_600_000;
14
15
  export const DEFAULT_MAX_RETRIES = 2;
15
16
  export class AgentAPI {
16
17
  apiKey;
18
+ apiKeyProvider;
17
19
  baseURL;
18
20
  timeout;
19
21
  streamTimeout;
@@ -22,6 +24,7 @@ export class AgentAPI {
22
24
  responses;
23
25
  agent;
24
26
  models;
27
+ memories;
25
28
  presets;
26
29
  tools;
27
30
  volumes;
@@ -30,6 +33,7 @@ export class AgentAPI {
30
33
  http;
31
34
  constructor(options = {}) {
32
35
  this.apiKey = options.apiKey ?? readEnv("AGENT_API_KEY");
36
+ this.apiKeyProvider = options.apiKeyProvider;
33
37
  this.baseURL = (options.baseURL ?? readEnv("AGENT_API_BASE_URL") ?? "https://api.agentsway.dev").replace(/\/+$/, "");
34
38
  this.timeout = options.timeout ?? DEFAULT_TIMEOUT_MS;
35
39
  this.streamTimeout = options.streamTimeout ?? DEFAULT_STREAM_TIMEOUT_MS;
@@ -42,6 +46,7 @@ export class AgentAPI {
42
46
  this.http = new HTTPClient({
43
47
  baseURL: this.baseURL,
44
48
  apiKey: this.apiKey,
49
+ apiKeyProvider: this.apiKeyProvider,
45
50
  timeout: this.timeout,
46
51
  streamTimeout: this.streamTimeout,
47
52
  maxRetries: this.maxRetries,
@@ -51,6 +56,7 @@ export class AgentAPI {
51
56
  this.responses = new ResponsesResource(this.http, "/v1/responses");
52
57
  this.agent = new ResponsesResource(this.http, "/v1/agent");
53
58
  this.models = new ModelsResource(this.http);
59
+ this.memories = new MemoriesResource(this.http);
54
60
  this.presets = new PresetsResource(this.http);
55
61
  this.tools = new ToolsResource(this.http);
56
62
  this.volumes = new VolumesResource(this.http);
package/dist/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetT
9
9
  export { isSupportedVolumeImageContentType, isSupportedVolumeImagePath, normalizeVolumeAssetPath, } from "./volume-assets.js";
10
10
  export type { PresetToolCatalogClient, ResolvePresetToolsOptions, ResolvePresetToolsResult, UnknownPresetToolBehavior, } from "./preset-tools.js";
11
11
  export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
12
+ export { MemoriesResource } from "./resources/memories.js";
package/dist/index.js CHANGED
@@ -6,3 +6,4 @@ export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers
6
6
  export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
7
7
  export { isSupportedVolumeImageContentType, isSupportedVolumeImagePath, normalizeVolumeAssetPath, } from "./volume-assets.js";
8
8
  export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
9
+ export { MemoriesResource } from "./resources/memories.js";
@@ -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;
@@ -79,8 +79,10 @@ export class HTTPClient {
79
79
  if (body !== undefined && !rawBody) {
80
80
  headers["Content-Type"] = "application/json";
81
81
  }
82
- if (this.options.apiKey) {
83
- headers.Authorization = `Bearer ${this.options.apiKey}`;
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,
@@ -0,0 +1,8 @@
1
+ import type { HTTPClient } from "../internal/http.js";
2
+ import type { RequestOptions } from "../types/common.js";
3
+ import type { MemorySearchParams, MemorySearchResponse } from "../types/memories.js";
4
+ export declare class MemoriesResource {
5
+ private readonly http;
6
+ constructor(http: HTTPClient);
7
+ search(params: MemorySearchParams, options?: RequestOptions): Promise<MemorySearchResponse>;
8
+ }
@@ -0,0 +1,9 @@
1
+ export class MemoriesResource {
2
+ http;
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ search(params, options) {
7
+ return this.http.request("POST", "/v1/memories/search", params, options);
8
+ }
9
+ }
@@ -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;
@@ -4,6 +4,7 @@ export * from "./tools.js";
4
4
  export * from "./responses.js";
5
5
  export * from "./streaming.js";
6
6
  export * from "./catalog.js";
7
+ export * from "./memories.js";
7
8
  export * from "./volumes.js";
8
9
  export * from "./skills.js";
9
10
  export * from "./auth.js";
@@ -4,6 +4,7 @@ export * from "./tools.js";
4
4
  export * from "./responses.js";
5
5
  export * from "./streaming.js";
6
6
  export * from "./catalog.js";
7
+ export * from "./memories.js";
7
8
  export * from "./volumes.js";
8
9
  export * from "./skills.js";
9
10
  export * from "./auth.js";
@@ -0,0 +1,37 @@
1
+ import type { Usage } from "./common.js";
2
+ export interface MemorySearchParams {
3
+ query: string;
4
+ limit?: number;
5
+ previous_response_id?: string;
6
+ tenant_search?: boolean;
7
+ lang?: string;
8
+ semantic_weight?: number;
9
+ }
10
+ export interface MemorySearchHit {
11
+ id: string;
12
+ score?: number;
13
+ thread_id?: string;
14
+ created_at?: number;
15
+ fact: string;
16
+ tenant_id?: string;
17
+ user_id?: string;
18
+ response_id?: string;
19
+ metadata?: unknown;
20
+ metadata_text?: string;
21
+ }
22
+ export interface MemorySearchModelUsage {
23
+ source?: string;
24
+ phase?: string;
25
+ provider?: string;
26
+ model?: string;
27
+ attempt_index?: number;
28
+ status?: string;
29
+ usage?: Usage;
30
+ }
31
+ export interface MemorySearchResponse {
32
+ object: "memory_search_result";
33
+ data: MemorySearchHit[];
34
+ total?: number;
35
+ rewritten_query?: string;
36
+ model_usage?: MemorySearchModelUsage[];
37
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.4.0";
2
- export declare const USER_AGENT = "@agent-api/sdk/1.4.0";
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.0";
1
+ export const VERSION = "1.4.2";
2
2
  export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
@@ -5,6 +5,7 @@ const errors_js_1 = require("./errors.js");
5
5
  const env_js_1 = require("./internal/env.js");
6
6
  const http_js_1 = require("./internal/http.js");
7
7
  const auth_js_1 = require("./resources/auth.js");
8
+ const memories_js_1 = require("./resources/memories.js");
8
9
  const models_js_1 = require("./resources/models.js");
9
10
  const presets_js_1 = require("./resources/presets.js");
10
11
  const responses_js_1 = require("./resources/responses.js");
@@ -18,6 +19,7 @@ exports.DEFAULT_STREAM_TIMEOUT_MS = 3_600_000;
18
19
  exports.DEFAULT_MAX_RETRIES = 2;
19
20
  class AgentAPI {
20
21
  apiKey;
22
+ apiKeyProvider;
21
23
  baseURL;
22
24
  timeout;
23
25
  streamTimeout;
@@ -26,6 +28,7 @@ class AgentAPI {
26
28
  responses;
27
29
  agent;
28
30
  models;
31
+ memories;
29
32
  presets;
30
33
  tools;
31
34
  volumes;
@@ -34,6 +37,7 @@ class AgentAPI {
34
37
  http;
35
38
  constructor(options = {}) {
36
39
  this.apiKey = options.apiKey ?? (0, env_js_1.readEnv)("AGENT_API_KEY");
40
+ this.apiKeyProvider = options.apiKeyProvider;
37
41
  this.baseURL = (options.baseURL ?? (0, env_js_1.readEnv)("AGENT_API_BASE_URL") ?? "https://api.agentsway.dev").replace(/\/+$/, "");
38
42
  this.timeout = options.timeout ?? exports.DEFAULT_TIMEOUT_MS;
39
43
  this.streamTimeout = options.streamTimeout ?? exports.DEFAULT_STREAM_TIMEOUT_MS;
@@ -46,6 +50,7 @@ class AgentAPI {
46
50
  this.http = new http_js_1.HTTPClient({
47
51
  baseURL: this.baseURL,
48
52
  apiKey: this.apiKey,
53
+ apiKeyProvider: this.apiKeyProvider,
49
54
  timeout: this.timeout,
50
55
  streamTimeout: this.streamTimeout,
51
56
  maxRetries: this.maxRetries,
@@ -55,6 +60,7 @@ class AgentAPI {
55
60
  this.responses = new responses_js_1.ResponsesResource(this.http, "/v1/responses");
56
61
  this.agent = new responses_js_1.ResponsesResource(this.http, "/v1/agent");
57
62
  this.models = new models_js_1.ModelsResource(this.http);
63
+ this.memories = new memories_js_1.MemoriesResource(this.http);
58
64
  this.presets = new presets_js_1.PresetsResource(this.http);
59
65
  this.tools = new tools_js_1.ToolsResource(this.http);
60
66
  this.volumes = new volumes_js_1.VolumesResource(this.http);
package/dist-cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.browserAuthSessionExpiresWithin = exports.DeviceAuthFlowError = exports.AuthResource = exports.normalizeVolumeAssetPath = exports.isSupportedVolumeImagePath = exports.isSupportedVolumeImageContentType = exports.resolvePresetToolsFromCatalog = exports.resolvePresetTools = exports.publicToolToRequestTool = exports.mergeTools = exports.runLocalFunctionHandlers = exports.pendingFunctionCalls = exports.functionCallOutputInput = exports.parseResponseError = exports.isRetryableStatus = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.BadRequestError = exports.AuthenticationError = exports.APIStatusError = exports.APIConnectionError = exports.APIError = exports.collectPage = exports.Page = exports.VERSION = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_STREAM_TIMEOUT_MS = exports.DEFAULT_MAX_RETRIES = exports.AgentAPI = void 0;
17
+ exports.MemoriesResource = exports.browserAuthSessionExpiresWithin = exports.DeviceAuthFlowError = exports.AuthResource = exports.normalizeVolumeAssetPath = exports.isSupportedVolumeImagePath = exports.isSupportedVolumeImageContentType = exports.resolvePresetToolsFromCatalog = exports.resolvePresetTools = exports.publicToolToRequestTool = exports.mergeTools = exports.runLocalFunctionHandlers = exports.pendingFunctionCalls = exports.functionCallOutputInput = exports.parseResponseError = exports.isRetryableStatus = exports.RateLimitError = exports.PermissionDeniedError = exports.NotFoundError = exports.InternalServerError = exports.BadRequestError = exports.AuthenticationError = exports.APIStatusError = exports.APIConnectionError = exports.APIError = exports.collectPage = exports.Page = exports.VERSION = exports.DEFAULT_TIMEOUT_MS = exports.DEFAULT_STREAM_TIMEOUT_MS = exports.DEFAULT_MAX_RETRIES = exports.AgentAPI = void 0;
18
18
  var client_js_1 = require("./client.js");
19
19
  Object.defineProperty(exports, "AgentAPI", { enumerable: true, get: function () { return client_js_1.AgentAPI; } });
20
20
  Object.defineProperty(exports, "DEFAULT_MAX_RETRIES", { enumerable: true, get: function () { return client_js_1.DEFAULT_MAX_RETRIES; } });
@@ -54,3 +54,5 @@ var auth_js_1 = require("./resources/auth.js");
54
54
  Object.defineProperty(exports, "AuthResource", { enumerable: true, get: function () { return auth_js_1.AuthResource; } });
55
55
  Object.defineProperty(exports, "DeviceAuthFlowError", { enumerable: true, get: function () { return auth_js_1.DeviceAuthFlowError; } });
56
56
  Object.defineProperty(exports, "browserAuthSessionExpiresWithin", { enumerable: true, get: function () { return auth_js_1.browserAuthSessionExpiresWithin; } });
57
+ var memories_js_1 = require("./resources/memories.js");
58
+ Object.defineProperty(exports, "MemoriesResource", { enumerable: true, get: function () { return memories_js_1.MemoriesResource; } });
@@ -82,8 +82,10 @@ class HTTPClient {
82
82
  if (body !== undefined && !rawBody) {
83
83
  headers["Content-Type"] = "application/json";
84
84
  }
85
- if (this.options.apiKey) {
86
- headers.Authorization = `Bearer ${this.options.apiKey}`;
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,
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoriesResource = void 0;
4
+ class MemoriesResource {
5
+ http;
6
+ constructor(http) {
7
+ this.http = http;
8
+ }
9
+ search(params, options) {
10
+ return this.http.request("POST", "/v1/memories/search", params, options);
11
+ }
12
+ }
13
+ exports.MemoriesResource = MemoriesResource;
@@ -20,6 +20,7 @@ __exportStar(require("./tools.js"), exports);
20
20
  __exportStar(require("./responses.js"), exports);
21
21
  __exportStar(require("./streaming.js"), exports);
22
22
  __exportStar(require("./catalog.js"), exports);
23
+ __exportStar(require("./memories.js"), exports);
23
24
  __exportStar(require("./volumes.js"), exports);
24
25
  __exportStar(require("./skills.js"), exports);
25
26
  __exportStar(require("./auth.js"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.USER_AGENT = exports.VERSION = void 0;
4
- exports.VERSION = "1.4.0";
4
+ exports.VERSION = "1.4.2";
5
5
  exports.USER_AGENT = `@agent-api/sdk/${exports.VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-api/sdk",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Production JavaScript SDK for the Managed Agent API",
5
5
  "license": "MIT",
6
6
  "repository": {