@agent-api/sdk 1.0.0 → 1.0.1
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 +8 -0
- package/README.md +22 -4
- package/dist/client.d.ts +2 -0
- package/dist/client.js +3 -0
- package/dist/internal/http.d.ts +2 -0
- package/dist/internal/http.js +14 -7
- package/dist/resources/volumes.d.ts +16 -0
- package/dist/resources/volumes.js +52 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/responses.d.ts +1 -0
- package/dist/types/tools.d.ts +7 -1
- package/dist/types/volumes.d.ts +52 -0
- package/dist/types/volumes.js +1 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog — @agent-api/sdk
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Durable volume resource methods for volume CRUD, entry listing/search, and file read/write/delete operations.
|
|
8
|
+
- `volume_id` create-run parameter for attaching an existing durable volume to agent runs.
|
|
9
|
+
|
|
3
10
|
## 1.0.0
|
|
4
11
|
|
|
5
12
|
### Added
|
|
@@ -11,3 +18,4 @@
|
|
|
11
18
|
### Notes
|
|
12
19
|
|
|
13
20
|
- Independent from the Python `cloudsway-agent` package; version and release tags are separate.
|
|
21
|
+
- Registry: https://www.npmjs.com/package/@agent-api/sdk
|
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Production JavaScript/TypeScript SDK for the Managed Agent API.
|
|
4
4
|
|
|
5
|
+
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.0.1)
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -44,7 +46,7 @@ src/
|
|
|
44
46
|
errors.ts # Typed error hierarchy + retry helpers
|
|
45
47
|
pagination.ts # Cursor pagination utilities
|
|
46
48
|
streaming.ts # SSE parser
|
|
47
|
-
resources/ # responses, models, presets, tools
|
|
49
|
+
resources/ # responses, models, presets, tools, volumes
|
|
48
50
|
types/ # Request/response TypeScript types
|
|
49
51
|
internal/http.ts # Retries, timeouts, User-Agent
|
|
50
52
|
```
|
|
@@ -57,6 +59,22 @@ src/
|
|
|
57
59
|
| `client.models` | `list` |
|
|
58
60
|
| `client.presets` | `list` |
|
|
59
61
|
| `client.tools` | `list` |
|
|
62
|
+
| `client.volumes` | `list`, `create`, `retrieve`, `delete`, `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deleteFile` |
|
|
63
|
+
|
|
64
|
+
## Durable Volumes
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const volume = await client.volumes.create({ name: "research-notes" });
|
|
68
|
+
|
|
69
|
+
await client.volumes.writeFile(volume.volume_id, "notes/summary.md", "# Summary\n");
|
|
70
|
+
const file = await client.volumes.readFile(volume.volume_id, "notes/summary.md");
|
|
71
|
+
|
|
72
|
+
const response = await client.agent.create({
|
|
73
|
+
preset: "pro-search",
|
|
74
|
+
input: "Use the attached workspace volume.",
|
|
75
|
+
volume_id: volume.volume_id,
|
|
76
|
+
});
|
|
77
|
+
```
|
|
60
78
|
|
|
61
79
|
## Production features
|
|
62
80
|
|
|
@@ -110,6 +128,6 @@ AGENT_API_INTEGRATION=1 AGENT_API_KEY=sk-... AGENT_API_BASE_URL=https://api.agen
|
|
|
110
128
|
|
|
111
129
|
## Scope
|
|
112
130
|
|
|
113
|
-
The SDK covers the public agent/Responses API and discovery
|
|
114
|
-
auth, workspace administration, and internal audit records
|
|
115
|
-
out of scope.
|
|
131
|
+
The SDK covers the public agent/Responses API, durable volume APIs, and discovery
|
|
132
|
+
endpoints. Console auth, workspace administration, and internal audit records
|
|
133
|
+
are intentionally out of scope.
|
package/dist/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { ModelsResource } from "./resources/models.js";
|
|
|
2
2
|
import { PresetsResource } from "./resources/presets.js";
|
|
3
3
|
import { ResponsesResource } from "./resources/responses.js";
|
|
4
4
|
import { ToolsResource } from "./resources/tools.js";
|
|
5
|
+
import { VolumesResource } from "./resources/volumes.js";
|
|
5
6
|
import type { ClientOptions } from "./types/common.js";
|
|
6
7
|
import { VERSION } from "./version.js";
|
|
7
8
|
export declare const DEFAULT_TIMEOUT_MS = 600000;
|
|
@@ -19,6 +20,7 @@ export declare class AgentAPI {
|
|
|
19
20
|
readonly models: ModelsResource;
|
|
20
21
|
readonly presets: PresetsResource;
|
|
21
22
|
readonly tools: ToolsResource;
|
|
23
|
+
readonly volumes: VolumesResource;
|
|
22
24
|
private readonly http;
|
|
23
25
|
constructor(options?: ClientOptions);
|
|
24
26
|
}
|
package/dist/client.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ModelsResource } from "./resources/models.js";
|
|
|
5
5
|
import { PresetsResource } from "./resources/presets.js";
|
|
6
6
|
import { ResponsesResource } from "./resources/responses.js";
|
|
7
7
|
import { ToolsResource } from "./resources/tools.js";
|
|
8
|
+
import { VolumesResource } from "./resources/volumes.js";
|
|
8
9
|
import { VERSION } from "./version.js";
|
|
9
10
|
export const DEFAULT_TIMEOUT_MS = 600_000;
|
|
10
11
|
export const DEFAULT_STREAM_TIMEOUT_MS = 3_600_000;
|
|
@@ -21,6 +22,7 @@ export class AgentAPI {
|
|
|
21
22
|
models;
|
|
22
23
|
presets;
|
|
23
24
|
tools;
|
|
25
|
+
volumes;
|
|
24
26
|
http;
|
|
25
27
|
constructor(options = {}) {
|
|
26
28
|
this.apiKey = options.apiKey ?? readEnv("AGENT_API_KEY");
|
|
@@ -47,6 +49,7 @@ export class AgentAPI {
|
|
|
47
49
|
this.models = new ModelsResource(this.http);
|
|
48
50
|
this.presets = new PresetsResource(this.http);
|
|
49
51
|
this.tools = new ToolsResource(this.http);
|
|
52
|
+
this.volumes = new VolumesResource(this.http);
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
export { VERSION };
|
package/dist/internal/http.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare class HTTPClient {
|
|
|
12
12
|
private readonly options;
|
|
13
13
|
constructor(options: HTTPClientOptions);
|
|
14
14
|
request<T>(method: string, path: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
15
|
+
requestRaw<T>(method: string, path: string, body: BodyInit, options?: RequestOptions): Promise<T>;
|
|
16
|
+
requestVoid(method: string, path: string, options?: RequestOptions): Promise<void>;
|
|
15
17
|
stream<T>(path: string, body: unknown, options?: RequestOptions): Promise<AsyncIterable<T>>;
|
|
16
18
|
private fetchWithRetry;
|
|
17
19
|
private fetchOnce;
|
package/dist/internal/http.js
CHANGED
|
@@ -7,19 +7,26 @@ export class HTTPClient {
|
|
|
7
7
|
this.options = options;
|
|
8
8
|
}
|
|
9
9
|
async request(method, path, body, options = {}) {
|
|
10
|
-
const response = await this.fetchWithRetry(method, path, body, options, false);
|
|
10
|
+
const response = await this.fetchWithRetry(method, path, body, options, false, false);
|
|
11
11
|
return (await response.json());
|
|
12
12
|
}
|
|
13
|
+
async requestRaw(method, path, body, options = {}) {
|
|
14
|
+
const response = await this.fetchWithRetry(method, path, body, options, false, true);
|
|
15
|
+
return (await response.json());
|
|
16
|
+
}
|
|
17
|
+
async requestVoid(method, path, options = {}) {
|
|
18
|
+
await this.fetchWithRetry(method, path, undefined, options, false, false);
|
|
19
|
+
}
|
|
13
20
|
async stream(path, body, options = {}) {
|
|
14
|
-
const response = await this.fetchWithRetry("POST", path, body, options, true);
|
|
21
|
+
const response = await this.fetchWithRetry("POST", path, body, options, true, false);
|
|
15
22
|
return parseSSE(response);
|
|
16
23
|
}
|
|
17
|
-
async fetchWithRetry(method, path, body, options, stream) {
|
|
24
|
+
async fetchWithRetry(method, path, body, options, stream, rawBody) {
|
|
18
25
|
const maxRetries = options.maxRetries ?? this.options.maxRetries;
|
|
19
26
|
let attempt = 0;
|
|
20
27
|
for (;;) {
|
|
21
28
|
try {
|
|
22
|
-
return await this.fetchOnce(method, path, body, options, stream);
|
|
29
|
+
return await this.fetchOnce(method, path, body, options, stream, rawBody);
|
|
23
30
|
}
|
|
24
31
|
catch (error) {
|
|
25
32
|
if (!(error instanceof APIError) || attempt >= maxRetries) {
|
|
@@ -36,7 +43,7 @@ export class HTTPClient {
|
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
|
-
async fetchOnce(method, path, body, options, stream) {
|
|
46
|
+
async fetchOnce(method, path, body, options, stream, rawBody) {
|
|
40
47
|
const controller = new AbortController();
|
|
41
48
|
const timeout = options.timeout ?? (stream ? this.options.streamTimeout : this.options.timeout);
|
|
42
49
|
const timeoutID = setTimeout(() => controller.abort(), timeout);
|
|
@@ -47,7 +54,7 @@ export class HTTPClient {
|
|
|
47
54
|
...this.options.defaultHeaders,
|
|
48
55
|
...options.headers,
|
|
49
56
|
};
|
|
50
|
-
if (body !== undefined) {
|
|
57
|
+
if (body !== undefined && !rawBody) {
|
|
51
58
|
headers["Content-Type"] = "application/json";
|
|
52
59
|
}
|
|
53
60
|
if (this.options.apiKey) {
|
|
@@ -56,7 +63,7 @@ export class HTTPClient {
|
|
|
56
63
|
const response = await this.options.fetchImpl(`${this.options.baseURL}${path}`, {
|
|
57
64
|
method,
|
|
58
65
|
headers,
|
|
59
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
66
|
+
body: body === undefined ? undefined : rawBody ? body : JSON.stringify(body),
|
|
60
67
|
signal: controller.signal,
|
|
61
68
|
});
|
|
62
69
|
if (!response.ok) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HTTPClient } from "../internal/http.js";
|
|
2
|
+
import type { RequestOptions } from "../types/common.js";
|
|
3
|
+
import type { CreateVolumeParams, ListVolumeEntriesParams, ListVolumeEntriesResponse, ListVolumesParams, ListVolumesResponse, ReadVolumeFileParams, SearchVolumeEntriesParams, VolumeFileRead, VolumeFileWrite, VolumeInfo } from "../types/volumes.js";
|
|
4
|
+
export declare class VolumesResource {
|
|
5
|
+
private readonly http;
|
|
6
|
+
constructor(http: HTTPClient);
|
|
7
|
+
list(params?: ListVolumesParams, options?: RequestOptions): Promise<ListVolumesResponse>;
|
|
8
|
+
create(params?: CreateVolumeParams, options?: RequestOptions): Promise<VolumeInfo>;
|
|
9
|
+
retrieve(volumeID: string, options?: RequestOptions): Promise<VolumeInfo>;
|
|
10
|
+
delete(volumeID: string, options?: RequestOptions): Promise<void>;
|
|
11
|
+
listEntries(volumeID: string, params?: ListVolumeEntriesParams, options?: RequestOptions): Promise<ListVolumeEntriesResponse>;
|
|
12
|
+
searchEntries(volumeID: string, params: SearchVolumeEntriesParams, options?: RequestOptions): Promise<ListVolumeEntriesResponse>;
|
|
13
|
+
readFile(volumeID: string, path: string, params?: ReadVolumeFileParams, options?: RequestOptions): Promise<VolumeFileRead>;
|
|
14
|
+
writeFile(volumeID: string, path: string, content: string | ArrayBuffer | Blob, options?: RequestOptions): Promise<VolumeFileWrite>;
|
|
15
|
+
deleteFile(volumeID: string, path: string, options?: RequestOptions): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { buildQuery } from "../internal/query.js";
|
|
2
|
+
export class VolumesResource {
|
|
3
|
+
http;
|
|
4
|
+
constructor(http) {
|
|
5
|
+
this.http = http;
|
|
6
|
+
}
|
|
7
|
+
list(params = {}, options) {
|
|
8
|
+
return this.http.request("GET", `/v1/volumes${buildQuery({ limit: params.limit, page_token: params.page_token })}`, undefined, options);
|
|
9
|
+
}
|
|
10
|
+
create(params = {}, options) {
|
|
11
|
+
return this.http.request("POST", "/v1/volumes", params, options);
|
|
12
|
+
}
|
|
13
|
+
retrieve(volumeID, options) {
|
|
14
|
+
return this.http.request("GET", `/v1/volumes/${encodeURIComponent(volumeID)}`, undefined, options);
|
|
15
|
+
}
|
|
16
|
+
delete(volumeID, options) {
|
|
17
|
+
return this.http.requestVoid("DELETE", `/v1/volumes/${encodeURIComponent(volumeID)}`, options);
|
|
18
|
+
}
|
|
19
|
+
listEntries(volumeID, params = {}, options) {
|
|
20
|
+
return this.http.request("GET", `/v1/volumes/${encodeURIComponent(volumeID)}/entries${buildQuery({
|
|
21
|
+
path: params.path,
|
|
22
|
+
limit: params.limit,
|
|
23
|
+
page_token: params.page_token,
|
|
24
|
+
})}`, undefined, options);
|
|
25
|
+
}
|
|
26
|
+
searchEntries(volumeID, params, options) {
|
|
27
|
+
return this.http.request("GET", `/v1/volumes/${encodeURIComponent(volumeID)}/search${buildQuery({
|
|
28
|
+
query: params.query,
|
|
29
|
+
path: params.path,
|
|
30
|
+
limit: params.limit,
|
|
31
|
+
page_token: params.page_token,
|
|
32
|
+
})}`, undefined, options);
|
|
33
|
+
}
|
|
34
|
+
readFile(volumeID, path, params = {}, options) {
|
|
35
|
+
return this.http.request("GET", `/v1/volumes/${encodeURIComponent(volumeID)}/files/${volumePath(path)}${buildQuery({
|
|
36
|
+
max_bytes: params.max_bytes,
|
|
37
|
+
})}`, undefined, options);
|
|
38
|
+
}
|
|
39
|
+
writeFile(volumeID, path, content, options) {
|
|
40
|
+
return this.http.requestRaw("PUT", `/v1/volumes/${encodeURIComponent(volumeID)}/files/${volumePath(path)}`, content, options);
|
|
41
|
+
}
|
|
42
|
+
deleteFile(volumeID, path, options) {
|
|
43
|
+
return this.http.requestVoid("DELETE", `/v1/volumes/${encodeURIComponent(volumeID)}/files/${volumePath(path)}`, options);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function volumePath(path) {
|
|
47
|
+
return path
|
|
48
|
+
.split("/")
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.map((part) => encodeURIComponent(part))
|
|
51
|
+
.join("/");
|
|
52
|
+
}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export interface ResponseCreateParamsBase {
|
|
|
18
18
|
metadata?: Record<string, unknown>;
|
|
19
19
|
store?: boolean;
|
|
20
20
|
previous_response_id?: string;
|
|
21
|
+
volume_id?: string;
|
|
21
22
|
prompt_cache_key?: string;
|
|
22
23
|
memory?: MemoryOptions;
|
|
23
24
|
plan_mode_preference?: AgentCapabilityPreference;
|
package/dist/types/tools.d.ts
CHANGED
|
@@ -10,6 +10,12 @@ export interface SmartWebSearchTool {
|
|
|
10
10
|
max_tokens?: number;
|
|
11
11
|
max_tokens_per_page?: number;
|
|
12
12
|
}
|
|
13
|
+
export interface LiteWebSearchTool {
|
|
14
|
+
name: "lite_web_search";
|
|
15
|
+
type?: "search";
|
|
16
|
+
max_tokens?: number;
|
|
17
|
+
max_tokens_per_page?: number;
|
|
18
|
+
}
|
|
13
19
|
export interface FetchURLTool {
|
|
14
20
|
name: "fetch_url";
|
|
15
21
|
type?: "url_reader";
|
|
@@ -27,7 +33,7 @@ export interface SkillTool {
|
|
|
27
33
|
version?: string;
|
|
28
34
|
arguments?: Record<string, unknown>;
|
|
29
35
|
}
|
|
30
|
-
export type Tool = WebSearchTool | SmartWebSearchTool | FetchURLTool | FunctionTool | SkillTool;
|
|
36
|
+
export type Tool = WebSearchTool | SmartWebSearchTool | LiteWebSearchTool | FetchURLTool | FunctionTool | SkillTool;
|
|
31
37
|
export interface PublicTool {
|
|
32
38
|
object: "tool";
|
|
33
39
|
name: string;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface VolumeInfo {
|
|
2
|
+
volume_id: string;
|
|
3
|
+
tenant_id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
oss_prefix?: string;
|
|
6
|
+
created_at_unix?: number;
|
|
7
|
+
updated_at_unix?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface VolumeEntry {
|
|
10
|
+
path: string;
|
|
11
|
+
is_dir: boolean;
|
|
12
|
+
size: number;
|
|
13
|
+
modified_at_unix?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface ListVolumesParams {
|
|
16
|
+
limit?: number;
|
|
17
|
+
page_token?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ListVolumesResponse {
|
|
20
|
+
object: "list";
|
|
21
|
+
data: VolumeInfo[];
|
|
22
|
+
next_page_token?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface CreateVolumeParams {
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ListVolumeEntriesParams {
|
|
28
|
+
path?: string;
|
|
29
|
+
limit?: number;
|
|
30
|
+
page_token?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface SearchVolumeEntriesParams extends ListVolumeEntriesParams {
|
|
33
|
+
query: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ListVolumeEntriesResponse {
|
|
36
|
+
object: "list";
|
|
37
|
+
entries: VolumeEntry[];
|
|
38
|
+
next_page_token?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ReadVolumeFileParams {
|
|
41
|
+
max_bytes?: number;
|
|
42
|
+
}
|
|
43
|
+
export interface VolumeFileRead {
|
|
44
|
+
path: string;
|
|
45
|
+
size: number;
|
|
46
|
+
truncated: boolean;
|
|
47
|
+
content: string;
|
|
48
|
+
}
|
|
49
|
+
export interface VolumeFileWrite {
|
|
50
|
+
path: string;
|
|
51
|
+
size: number;
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.0.
|
|
2
|
-
export declare const USER_AGENT = "@agent-api/sdk/1.0.
|
|
1
|
+
export declare const VERSION = "1.0.1";
|
|
2
|
+
export declare const USER_AGENT = "@agent-api/sdk/1.0.1";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "1.0.
|
|
1
|
+
export const VERSION = "1.0.1";
|
|
2
2
|
export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
|