@agent-api/sdk 1.1.3 → 1.1.5
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 +11 -0
- package/README.md +26 -4
- package/dist/client.d.ts +4 -1
- package/dist/client.js +5 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -3
- package/dist/local-skills.js +13 -1
- package/dist/node-client.d.ts +6 -0
- package/dist/node-client.js +7 -0
- package/dist/node.d.ts +8 -0
- package/dist/node.js +6 -0
- package/dist/resources/auth.d.ts +3 -1
- package/dist/resources/auth.js +18 -0
- package/dist/resources/skills-node.d.ts +7 -0
- package/dist/resources/skills-node.js +156 -0
- package/dist/resources/skills.d.ts +1 -3
- package/dist/resources/skills.js +0 -153
- package/dist/types/auth.d.ts +3 -0
- package/dist/types/responses.d.ts +4 -0
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist-cjs/client.js +72 -0
- package/dist-cjs/errors.js +146 -0
- package/dist-cjs/index.js +52 -0
- package/dist-cjs/internal/env.js +7 -0
- package/dist-cjs/internal/http.js +108 -0
- package/dist-cjs/internal/output-text.js +15 -0
- package/dist-cjs/internal/query.js +13 -0
- package/dist-cjs/local/context.js +158 -0
- package/dist-cjs/local/core.js +1077 -0
- package/dist-cjs/local/index.js +19 -0
- package/dist-cjs/local/tools.js +380 -0
- package/dist-cjs/local-functions.js +37 -0
- package/dist-cjs/local-skills.js +308 -0
- package/dist-cjs/node-client.js +11 -0
- package/dist-cjs/node.js +32 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/pagination.js +43 -0
- package/dist-cjs/preset-tools.js +91 -0
- package/dist-cjs/resources/auth.js +111 -0
- package/dist-cjs/resources/models.js +13 -0
- package/dist-cjs/resources/presets.js +13 -0
- package/dist-cjs/resources/responses.js +58 -0
- package/dist-cjs/resources/skills-node.js +193 -0
- package/dist-cjs/resources/skills.js +112 -0
- package/dist-cjs/resources/tools.js +13 -0
- package/dist-cjs/resources/volumes.js +114 -0
- package/dist-cjs/streaming.js +42 -0
- package/dist-cjs/tool-validation.js +18 -0
- package/dist-cjs/types/auth.js +2 -0
- package/dist-cjs/types/catalog.js +2 -0
- package/dist-cjs/types/common.js +2 -0
- package/dist-cjs/types/index.js +25 -0
- package/dist-cjs/types/input.js +2 -0
- package/dist-cjs/types/responses.js +2 -0
- package/dist-cjs/types/skills.js +2 -0
- package/dist-cjs/types/streaming.js +2 -0
- package/dist-cjs/types/tools.js +2 -0
- package/dist-cjs/types/volumes.js +2 -0
- package/dist-cjs/version.js +5 -0
- package/package.json +20 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog — @agent-api/sdk
|
|
2
2
|
|
|
3
|
+
## 1.1.5
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added browser-session refresh helpers for long-running CLI and desktop integrations: `client.auth.refreshBrowserSession()` and `browserAuthSessionExpiresWithin()`.
|
|
8
|
+
- Added unified local skill tool-call handling for both local skill and function-call response items.
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Extended response input types so tool-call continuations can carry function-call metadata consistently.
|
|
13
|
+
|
|
3
14
|
## 1.1.2
|
|
4
15
|
|
|
5
16
|
### Added
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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.1.
|
|
5
|
+
**Published on npm:** [`@agent-api/sdk`](https://www.npmjs.com/package/@agent-api/sdk) (v1.1.4)
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -40,6 +40,13 @@ The default base URL is `https://api.agentsway.dev` when neither option nor env
|
|
|
40
40
|
|
|
41
41
|
## Package layout
|
|
42
42
|
|
|
43
|
+
Public package entrypoints:
|
|
44
|
+
|
|
45
|
+
- `@agent-api/sdk`: browser-safe REST client, public types, auth, responses, models, presets, tools, volumes, and skills HTTP APIs.
|
|
46
|
+
- `@agent-api/sdk/browser`: explicit alias of the browser-safe REST client entry.
|
|
47
|
+
- `@agent-api/sdk/local`: Node-only local runtime, workspace, context, and local workspace tool support.
|
|
48
|
+
- `@agent-api/sdk/node`: Node aggregate entry for local helpers such as `localSkillFromDirectory()` plus `NodeAgentAPI`.
|
|
49
|
+
|
|
43
50
|
```
|
|
44
51
|
src/
|
|
45
52
|
client.ts # AgentAPI entrypoint
|
|
@@ -60,8 +67,10 @@ src/
|
|
|
60
67
|
| `client.presets` | `list` |
|
|
61
68
|
| `client.tools` | `list` |
|
|
62
69
|
| `client.volumes` | `list`, `create`, `retrieve`, `update`, `delete`, `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deletePath`, `reconcileUsage`, `createDirectory`, `downloadArchive`, `summarize`, `readLines`, `patchLines`, `grep` |
|
|
63
|
-
| `client.skills` | `list`, `create`, `discover`, `focus`, `createDev`, `updateFile`, `retrieve`, `update`, `archive`, `delete`, `diff`, `acceptDev`, `discardDev`, `exportArchive`, `importArchive`, `
|
|
64
|
-
| `client.auth` | `startDeviceAuth`, `pollDeviceAuth`, `waitForDeviceAuth` |
|
|
70
|
+
| `client.skills` | `list`, `create`, `discover`, `focus`, `createDev`, `updateFile`, `retrieve`, `update`, `archive`, `delete`, `diff`, `acceptDev`, `discardDev`, `exportArchive`, `importArchive`, `listFiles`, `readFile`, `writeFile`, `deleteFile` |
|
|
71
|
+
| `client.auth` | `startDeviceAuth`, `pollDeviceAuth`, `waitForDeviceAuth`, `refreshBrowserSession` |
|
|
72
|
+
|
|
73
|
+
`NodeAgentAPI` from `@agent-api/sdk/node` extends `client.skills` with Node-only `pushDirectory` and `pullDirectory`.
|
|
65
74
|
|
|
66
75
|
## Browser Device Login
|
|
67
76
|
|
|
@@ -81,6 +90,19 @@ console.log(session.access_token);
|
|
|
81
90
|
|
|
82
91
|
The SDK returns URLs and polling helpers only. Opening the browser belongs to the CLI, Electron, Tauri, or native host app.
|
|
83
92
|
|
|
93
|
+
Long-running local apps can keep browser sessions fresh explicitly:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { browserAuthSessionExpiresWithin } from "@agent-api/sdk";
|
|
97
|
+
|
|
98
|
+
if (browserAuthSessionExpiresWithin(session, 5 * 60_000)) {
|
|
99
|
+
session = await client.auth.refreshBrowserSession({
|
|
100
|
+
refresh_token: session.refresh_token,
|
|
101
|
+
});
|
|
102
|
+
// Persist the refreshed session in your app's secure profile store.
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
84
106
|
## Durable Volumes
|
|
85
107
|
|
|
86
108
|
```typescript
|
|
@@ -127,7 +149,7 @@ For long-running apps, cache `client.presets.list()` and `client.tools.list()` a
|
|
|
127
149
|
`localSkillFromDirectory()` reads `SKILL.md` into the descriptor for initial local-skill auto-focus; later focused reads still use the local skill tool bridge.
|
|
128
150
|
|
|
129
151
|
```typescript
|
|
130
|
-
import { localSkillFromDirectory } from "@agent-api/sdk";
|
|
152
|
+
import { localSkillFromDirectory } from "@agent-api/sdk/node";
|
|
131
153
|
|
|
132
154
|
const skill = await client.skills.create({ name: "research-helper" });
|
|
133
155
|
await client.skills.writeFile(skill.skill_id, "SKILL.md", "# Research helper\n");
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HTTPClient } from "./internal/http.js";
|
|
1
2
|
import { AuthResource } from "./resources/auth.js";
|
|
2
3
|
import { ModelsResource } from "./resources/models.js";
|
|
3
4
|
import { PresetsResource } from "./resources/presets.js";
|
|
@@ -25,10 +26,12 @@ export declare class AgentAPI {
|
|
|
25
26
|
readonly volumes: VolumesResource;
|
|
26
27
|
readonly skills: SkillsResource;
|
|
27
28
|
readonly auth: AuthResource;
|
|
28
|
-
|
|
29
|
+
protected readonly http: HTTPClient;
|
|
29
30
|
constructor(options?: ClientOptions);
|
|
31
|
+
protected createSkillsResource(): SkillsResource;
|
|
30
32
|
startDeviceAuth: (...args: Parameters<AuthResource["startDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthStart>;
|
|
31
33
|
pollDeviceAuth: (...args: Parameters<AuthResource["pollDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthPollResult>;
|
|
34
|
+
refreshBrowserSession: (...args: Parameters<AuthResource["refreshBrowserSession"]>) => Promise<import("./index.js").AuthSession>;
|
|
32
35
|
waitForDeviceAuth: (...args: Parameters<AuthResource["waitForDeviceAuth"]>) => Promise<import("./index.js").ApprovedDeviceAuth>;
|
|
33
36
|
}
|
|
34
37
|
export { VERSION };
|
package/dist/client.js
CHANGED
|
@@ -54,11 +54,15 @@ export class AgentAPI {
|
|
|
54
54
|
this.presets = new PresetsResource(this.http);
|
|
55
55
|
this.tools = new ToolsResource(this.http);
|
|
56
56
|
this.volumes = new VolumesResource(this.http);
|
|
57
|
-
this.skills =
|
|
57
|
+
this.skills = this.createSkillsResource();
|
|
58
58
|
this.auth = new AuthResource(this.http);
|
|
59
59
|
}
|
|
60
|
+
createSkillsResource() {
|
|
61
|
+
return new SkillsResource(this.http);
|
|
62
|
+
}
|
|
60
63
|
startDeviceAuth = (...args) => this.auth.startDeviceAuth(...args);
|
|
61
64
|
pollDeviceAuth = (...args) => this.auth.pollDeviceAuth(...args);
|
|
65
|
+
refreshBrowserSession = (...args) => this.auth.refreshBrowserSession(...args);
|
|
62
66
|
waitForDeviceAuth = (...args) => this.auth.waitForDeviceAuth(...args);
|
|
63
67
|
}
|
|
64
68
|
export { VERSION };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,8 +7,4 @@ export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers
|
|
|
7
7
|
export type { LocalFunctionHandler, LocalFunctionHandlers } from "./local-functions.js";
|
|
8
8
|
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
9
9
|
export type { PresetToolCatalogClient, ResolvePresetToolsOptions, ResolvePresetToolsResult, UnknownPresetToolBehavior, } from "./preset-tools.js";
|
|
10
|
-
export {
|
|
11
|
-
export type { LocalWorkspaceAction, LocalWorkspaceAccessMode, LocalWorkspaceToolRegistry, LocalWorkspaceToolRegistryOptions, } from "./local/tools.js";
|
|
12
|
-
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
13
|
-
export type { LocalSkillDirectoryOptions } from "./local-skills.js";
|
|
14
|
-
export { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
10
|
+
export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,4 @@ export { APIError, APIConnectionError, APIStatusError, AuthenticationError, BadR
|
|
|
4
4
|
export * from "./types/index.js";
|
|
5
5
|
export { functionCallOutputInput, pendingFunctionCalls, runLocalFunctionHandlers, } from "./local-functions.js";
|
|
6
6
|
export { mergeTools, publicToolToRequestTool, resolvePresetTools, resolvePresetToolsFromCatalog, } from "./preset-tools.js";
|
|
7
|
-
export {
|
|
8
|
-
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
9
|
-
export { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
7
|
+
export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
|
package/dist/local-skills.js
CHANGED
|
@@ -31,7 +31,19 @@ export async function localSkillFromDirectory(rootDir, options = {}) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
export function pendingLocalSkillCalls(response) {
|
|
34
|
-
return pendingFunctionCalls(response).filter((call) => call
|
|
34
|
+
return pendingFunctionCalls(response).filter((call) => isLocalSkillFocusCall(call));
|
|
35
|
+
}
|
|
36
|
+
function isLocalSkillFocusCall(call) {
|
|
37
|
+
if (call.name !== "skill") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const args = call.arguments ? JSON.parse(call.arguments) : {};
|
|
42
|
+
return String(args.action || "").trim().toLowerCase() === "focus";
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
48
|
export async function runLocalSkillHandlers(response, localSkills) {
|
|
37
49
|
const byRef = await localSkillsByRef(localSkills);
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./index.js";
|
|
2
|
+
export { NodeAgentAPI } from "./node-client.js";
|
|
3
|
+
export { NodeSkillsResource } from "./resources/skills-node.js";
|
|
4
|
+
export { LocalWorkspaceDriver, createLocalWorkspaceToolRegistry, localWorkspaceToolDefinition, localWorkspaceToolInstructions, } from "./local/tools.js";
|
|
5
|
+
export type { LocalWorkspaceAction, LocalWorkspaceAccessMode, LocalWorkspaceToolRegistry, LocalWorkspaceToolRegistryOptions, } from "./local/tools.js";
|
|
6
|
+
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
7
|
+
export type { LocalSkillDirectoryOptions } from "./local-skills.js";
|
|
8
|
+
export * from "./local/index.js";
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./index.js";
|
|
2
|
+
export { NodeAgentAPI } from "./node-client.js";
|
|
3
|
+
export { NodeSkillsResource } from "./resources/skills-node.js";
|
|
4
|
+
export { LocalWorkspaceDriver, createLocalWorkspaceToolRegistry, localWorkspaceToolDefinition, localWorkspaceToolInstructions, } from "./local/tools.js";
|
|
5
|
+
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
6
|
+
export * from "./local/index.js";
|
package/dist/resources/auth.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { HTTPClient } from "../internal/http.js";
|
|
2
|
-
import type { ApprovedDeviceAuth, DeviceAuthPollResult, DeviceAuthStart, PollDeviceAuthParams, StartDeviceAuthParams, WaitForDeviceAuthParams } from "../types/auth.js";
|
|
2
|
+
import type { ApprovedDeviceAuth, AuthSession, DeviceAuthPollResult, DeviceAuthStart, PollDeviceAuthParams, RefreshBrowserSessionParams, StartDeviceAuthParams, WaitForDeviceAuthParams } from "../types/auth.js";
|
|
3
3
|
import type { RequestOptions } from "../types/common.js";
|
|
4
4
|
export declare class AuthResource {
|
|
5
5
|
private readonly http;
|
|
6
6
|
constructor(http: HTTPClient);
|
|
7
7
|
startDeviceAuth(params?: StartDeviceAuthParams, options?: RequestOptions): Promise<DeviceAuthStart>;
|
|
8
8
|
pollDeviceAuth(params: PollDeviceAuthParams, options?: RequestOptions): Promise<DeviceAuthPollResult>;
|
|
9
|
+
refreshBrowserSession(params: RefreshBrowserSessionParams, options?: RequestOptions): Promise<AuthSession>;
|
|
9
10
|
waitForDeviceAuth(params: WaitForDeviceAuthParams, options?: RequestOptions): Promise<ApprovedDeviceAuth>;
|
|
10
11
|
}
|
|
12
|
+
export declare function browserAuthSessionExpiresWithin(session: Pick<AuthSession, "access_token_expires_at">, windowMs?: number, nowMs?: number): boolean;
|
|
11
13
|
export declare class DeviceAuthFlowError extends Error {
|
|
12
14
|
readonly result?: DeviceAuthPollResult;
|
|
13
15
|
constructor(message: string, result?: DeviceAuthPollResult);
|
package/dist/resources/auth.js
CHANGED
|
@@ -11,6 +11,16 @@ export class AuthResource {
|
|
|
11
11
|
requireDeviceCode(params.device_code);
|
|
12
12
|
return this.http.request("POST", "/v1/auth/device/poll", params, options);
|
|
13
13
|
}
|
|
14
|
+
refreshBrowserSession(params, options = {}) {
|
|
15
|
+
requireRefreshToken(params.refresh_token);
|
|
16
|
+
return this.http.request("POST", "/v1/auth/refresh", {}, {
|
|
17
|
+
...options,
|
|
18
|
+
headers: {
|
|
19
|
+
...options.headers,
|
|
20
|
+
Cookie: `agent_api_refresh=${encodeURIComponent(params.refresh_token)}`,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
14
24
|
async waitForDeviceAuth(params, options = {}) {
|
|
15
25
|
requireDeviceCode(params.device_code);
|
|
16
26
|
const startedAt = Date.now();
|
|
@@ -32,6 +42,9 @@ export class AuthResource {
|
|
|
32
42
|
}
|
|
33
43
|
}
|
|
34
44
|
}
|
|
45
|
+
export function browserAuthSessionExpiresWithin(session, windowMs = 60_000, nowMs = Date.now()) {
|
|
46
|
+
return session.access_token_expires_at * 1000 - nowMs <= windowMs;
|
|
47
|
+
}
|
|
35
48
|
export class DeviceAuthFlowError extends Error {
|
|
36
49
|
result;
|
|
37
50
|
constructor(message, result) {
|
|
@@ -46,6 +59,11 @@ function requireDeviceCode(deviceCode) {
|
|
|
46
59
|
throw new TypeError("device_code is required");
|
|
47
60
|
}
|
|
48
61
|
}
|
|
62
|
+
function requireRefreshToken(refreshToken) {
|
|
63
|
+
if (!refreshToken || !refreshToken.trim()) {
|
|
64
|
+
throw new TypeError("refresh_token is required");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
49
67
|
function pollDelayMs(params, result) {
|
|
50
68
|
const seconds = params.interval_seconds ?? result.interval_seconds ?? defaultDevicePollIntervalSeconds;
|
|
51
69
|
return Math.max(1, seconds) * 1000;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SkillsResource } from "./skills.js";
|
|
2
|
+
import type { RequestOptions } from "../types/common.js";
|
|
3
|
+
import type { PullSkillDirectoryParams, PushSkillDirectoryParams, SkillDirectoryPullResult, SkillImportResponse } from "../types/skills.js";
|
|
4
|
+
export declare class NodeSkillsResource extends SkillsResource {
|
|
5
|
+
pushDirectory(skillID: string, rootDir: string, params?: PushSkillDirectoryParams, options?: RequestOptions): Promise<SkillImportResponse>;
|
|
6
|
+
pullDirectory(skillID: string, targetDir: string, params?: PullSkillDirectoryParams, options?: RequestOptions): Promise<SkillDirectoryPullResult>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { SkillsResource } from "./skills.js";
|
|
2
|
+
export class NodeSkillsResource extends SkillsResource {
|
|
3
|
+
async pushDirectory(skillID, rootDir, params = {}, options) {
|
|
4
|
+
const archive = await zipDirectory(rootDir);
|
|
5
|
+
return this.importArchive(skillID, archive, params, options);
|
|
6
|
+
}
|
|
7
|
+
async pullDirectory(skillID, targetDir, params = {}, options) {
|
|
8
|
+
const archive = await this.exportArchive(skillID, params, options);
|
|
9
|
+
return extractStoredZipToDirectory(archive.content, targetDir, { replace: params.replace === true });
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function zipDirectory(rootDir) {
|
|
13
|
+
const fs = await import("node:fs/promises");
|
|
14
|
+
const path = await import("node:path");
|
|
15
|
+
const root = path.resolve(rootDir);
|
|
16
|
+
const files = await walkArchiveFiles(fs, path, root, root);
|
|
17
|
+
const entries = [];
|
|
18
|
+
for (const rel of files.sort()) {
|
|
19
|
+
const content = await fs.readFile(path.join(root, rel));
|
|
20
|
+
entries.push({ path: rel, data: new Uint8Array(content.buffer, content.byteOffset, content.byteLength) });
|
|
21
|
+
}
|
|
22
|
+
return createStoredZip(entries);
|
|
23
|
+
}
|
|
24
|
+
async function walkArchiveFiles(fs, path, root, dir) {
|
|
25
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
26
|
+
const out = [];
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
if (entry.name === ".git" || entry.name === "__pycache__" || entry.name === "node_modules") {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const full = path.join(dir, entry.name);
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
out.push(...await walkArchiveFiles(fs, path, root, full));
|
|
34
|
+
}
|
|
35
|
+
else if (entry.isFile()) {
|
|
36
|
+
out.push(path.relative(root, full).split(path.sep).join("/"));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
async function extractStoredZipToDirectory(archive, targetDir, opts) {
|
|
42
|
+
const fs = await import("node:fs/promises");
|
|
43
|
+
const path = await import("node:path");
|
|
44
|
+
const root = path.resolve(targetDir);
|
|
45
|
+
if (opts.replace) {
|
|
46
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
await fs.mkdir(root, { recursive: true });
|
|
49
|
+
let fileCount = 0;
|
|
50
|
+
let byteCount = 0;
|
|
51
|
+
for (const entry of parseStoredZip(archive)) {
|
|
52
|
+
const dest = path.resolve(root, entry.path);
|
|
53
|
+
const rel = path.relative(root, dest);
|
|
54
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
55
|
+
throw new Error(`archive entry escapes target directory: ${entry.path}`);
|
|
56
|
+
}
|
|
57
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
58
|
+
await fs.writeFile(dest, entry.data);
|
|
59
|
+
fileCount += 1;
|
|
60
|
+
byteCount += entry.data.byteLength;
|
|
61
|
+
}
|
|
62
|
+
return { path: root, file_count: fileCount, byte_count: byteCount };
|
|
63
|
+
}
|
|
64
|
+
function createStoredZip(entries) {
|
|
65
|
+
const encoder = new TextEncoder();
|
|
66
|
+
const localParts = [];
|
|
67
|
+
const centralParts = [];
|
|
68
|
+
let offset = 0;
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const name = encoder.encode(entry.path);
|
|
71
|
+
const crc = crc32(entry.data);
|
|
72
|
+
const local = new Uint8Array(30 + name.length);
|
|
73
|
+
const lv = new DataView(local.buffer);
|
|
74
|
+
lv.setUint32(0, 0x04034b50, true);
|
|
75
|
+
lv.setUint16(4, 20, true);
|
|
76
|
+
lv.setUint16(8, 0, true);
|
|
77
|
+
lv.setUint32(14, crc, true);
|
|
78
|
+
lv.setUint32(18, entry.data.byteLength, true);
|
|
79
|
+
lv.setUint32(22, entry.data.byteLength, true);
|
|
80
|
+
lv.setUint16(26, name.length, true);
|
|
81
|
+
local.set(name, 30);
|
|
82
|
+
localParts.push(local, entry.data);
|
|
83
|
+
const central = new Uint8Array(46 + name.length);
|
|
84
|
+
const cv = new DataView(central.buffer);
|
|
85
|
+
cv.setUint32(0, 0x02014b50, true);
|
|
86
|
+
cv.setUint16(4, 20, true);
|
|
87
|
+
cv.setUint16(6, 20, true);
|
|
88
|
+
cv.setUint32(16, crc, true);
|
|
89
|
+
cv.setUint32(20, entry.data.byteLength, true);
|
|
90
|
+
cv.setUint32(24, entry.data.byteLength, true);
|
|
91
|
+
cv.setUint16(28, name.length, true);
|
|
92
|
+
cv.setUint32(42, offset, true);
|
|
93
|
+
central.set(name, 46);
|
|
94
|
+
centralParts.push(central);
|
|
95
|
+
offset += local.byteLength + entry.data.byteLength;
|
|
96
|
+
}
|
|
97
|
+
const centralOffset = offset;
|
|
98
|
+
const centralSize = centralParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
99
|
+
const end = new Uint8Array(22);
|
|
100
|
+
const ev = new DataView(end.buffer);
|
|
101
|
+
ev.setUint32(0, 0x06054b50, true);
|
|
102
|
+
ev.setUint16(8, entries.length, true);
|
|
103
|
+
ev.setUint16(10, entries.length, true);
|
|
104
|
+
ev.setUint32(12, centralSize, true);
|
|
105
|
+
ev.setUint32(16, centralOffset, true);
|
|
106
|
+
const zip = concatUint8([...localParts, ...centralParts, end]);
|
|
107
|
+
return zip.buffer.slice(zip.byteOffset, zip.byteOffset + zip.byteLength);
|
|
108
|
+
}
|
|
109
|
+
function parseStoredZip(archive) {
|
|
110
|
+
const data = new Uint8Array(archive);
|
|
111
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
112
|
+
const entries = [];
|
|
113
|
+
let pos = 0;
|
|
114
|
+
const decoder = new TextDecoder();
|
|
115
|
+
while (pos + 4 <= data.byteLength && view.getUint32(pos, true) === 0x04034b50) {
|
|
116
|
+
const method = view.getUint16(pos + 8, true);
|
|
117
|
+
if (method !== 0) {
|
|
118
|
+
throw new Error("Only stored ZIP entries are supported by pullDirectory");
|
|
119
|
+
}
|
|
120
|
+
const compressedSize = view.getUint32(pos + 18, true);
|
|
121
|
+
const fileNameLength = view.getUint16(pos + 26, true);
|
|
122
|
+
const extraLength = view.getUint16(pos + 28, true);
|
|
123
|
+
const nameStart = pos + 30;
|
|
124
|
+
const contentStart = nameStart + fileNameLength + extraLength;
|
|
125
|
+
const contentEnd = contentStart + compressedSize;
|
|
126
|
+
if (contentEnd > data.byteLength) {
|
|
127
|
+
throw new Error("Invalid ZIP archive");
|
|
128
|
+
}
|
|
129
|
+
const name = decoder.decode(data.slice(nameStart, nameStart + fileNameLength)).replace(/\\/g, "/");
|
|
130
|
+
if (name && !name.endsWith("/") && !name.startsWith("__MACOSX/") && !name.split("/").includes("..")) {
|
|
131
|
+
entries.push({ path: name.replace(/^\/+/, ""), data: data.slice(contentStart, contentEnd) });
|
|
132
|
+
}
|
|
133
|
+
pos = contentEnd;
|
|
134
|
+
}
|
|
135
|
+
return entries;
|
|
136
|
+
}
|
|
137
|
+
function concatUint8(parts) {
|
|
138
|
+
const total = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
139
|
+
const out = new Uint8Array(total);
|
|
140
|
+
let offset = 0;
|
|
141
|
+
for (const part of parts) {
|
|
142
|
+
out.set(part, offset);
|
|
143
|
+
offset += part.byteLength;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
function crc32(data) {
|
|
148
|
+
let crc = 0xffffffff;
|
|
149
|
+
for (const byte of data) {
|
|
150
|
+
crc ^= byte;
|
|
151
|
+
for (let i = 0; i < 8; i += 1) {
|
|
152
|
+
crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
156
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HTTPClient } from "../internal/http.js";
|
|
2
2
|
import type { RequestOptions } from "../types/common.js";
|
|
3
|
-
import type { CreateSkillParams, CreateSkillDevParams, CreateSkillDevResponse, DiscoverSkillsParams, FocusSkillParams, ImportSkillArchiveParams, ListSkillFilesParams, ListSkillFilesResponse, ListSkillsParams, ListSkillsResponse, ListSkillSummariesResponse,
|
|
3
|
+
import type { CreateSkillParams, CreateSkillDevParams, CreateSkillDevResponse, DiscoverSkillsParams, FocusSkillParams, ImportSkillArchiveParams, ListSkillFilesParams, ListSkillFilesResponse, ListSkillsParams, ListSkillsResponse, ListSkillSummariesResponse, Skill, SkillAcceptStrategy, SkillArchive, SkillArchiveParams, SkillBranchDiff, SkillBranchDiffParams, SkillFile, SkillBranch, SkillFocusResponse, SkillImportResponse, UpdateSkillFilePrimitiveParams, UpdateSkillFilePrimitiveResponse, UpdateSkillParams } from "../types/skills.js";
|
|
4
4
|
export declare class SkillsResource {
|
|
5
5
|
private readonly http;
|
|
6
6
|
constructor(http: HTTPClient);
|
|
@@ -35,6 +35,4 @@ export declare class SkillsResource {
|
|
|
35
35
|
exportArchive(skillID: string, params?: SkillArchiveParams, options?: RequestOptions): Promise<SkillArchive>;
|
|
36
36
|
importArchive(skillID: string, archive: ArrayBuffer | Blob, params?: ImportSkillArchiveParams, options?: RequestOptions): Promise<SkillImportResponse>;
|
|
37
37
|
diff(skillID: string, params?: SkillBranchDiffParams, options?: RequestOptions): Promise<SkillBranchDiff>;
|
|
38
|
-
pushDirectory(skillID: string, rootDir: string, params?: PushSkillDirectoryParams, options?: RequestOptions): Promise<SkillImportResponse>;
|
|
39
|
-
pullDirectory(skillID: string, targetDir: string, params?: PullSkillDirectoryParams, options?: RequestOptions): Promise<SkillDirectoryPullResult>;
|
|
40
38
|
}
|
package/dist/resources/skills.js
CHANGED
|
@@ -95,14 +95,6 @@ export class SkillsResource {
|
|
|
95
95
|
include_unchanged: params.include_unchanged ? "true" : undefined,
|
|
96
96
|
})}`, undefined, options);
|
|
97
97
|
}
|
|
98
|
-
async pushDirectory(skillID, rootDir, params = {}, options) {
|
|
99
|
-
const archive = await zipDirectory(rootDir);
|
|
100
|
-
return this.importArchive(skillID, archive, params, options);
|
|
101
|
-
}
|
|
102
|
-
async pullDirectory(skillID, targetDir, params = {}, options) {
|
|
103
|
-
const archive = await this.exportArchive(skillID, params, options);
|
|
104
|
-
return extractStoredZipToDirectory(archive.content, targetDir, { replace: params.replace === true });
|
|
105
|
-
}
|
|
106
98
|
}
|
|
107
99
|
function skillPath(path) {
|
|
108
100
|
return path
|
|
@@ -114,148 +106,3 @@ function skillPath(path) {
|
|
|
114
106
|
function normalizeArchivePath(path) {
|
|
115
107
|
return (path ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
116
108
|
}
|
|
117
|
-
async function zipDirectory(rootDir) {
|
|
118
|
-
const fs = await import("node:fs/promises");
|
|
119
|
-
const path = await import("node:path");
|
|
120
|
-
const root = path.resolve(rootDir);
|
|
121
|
-
const files = await walkArchiveFiles(fs, path, root, root);
|
|
122
|
-
const entries = [];
|
|
123
|
-
for (const rel of files.sort()) {
|
|
124
|
-
const content = await fs.readFile(path.join(root, rel));
|
|
125
|
-
entries.push({ path: rel, data: new Uint8Array(content.buffer, content.byteOffset, content.byteLength) });
|
|
126
|
-
}
|
|
127
|
-
return createStoredZip(entries);
|
|
128
|
-
}
|
|
129
|
-
async function walkArchiveFiles(fs, path, root, dir) {
|
|
130
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
131
|
-
const out = [];
|
|
132
|
-
for (const entry of entries) {
|
|
133
|
-
if (entry.name === ".git" || entry.name === "__pycache__" || entry.name === "node_modules") {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
const full = path.join(dir, entry.name);
|
|
137
|
-
if (entry.isDirectory()) {
|
|
138
|
-
out.push(...await walkArchiveFiles(fs, path, root, full));
|
|
139
|
-
}
|
|
140
|
-
else if (entry.isFile()) {
|
|
141
|
-
out.push(path.relative(root, full).split(path.sep).join("/"));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
async function extractStoredZipToDirectory(archive, targetDir, opts) {
|
|
147
|
-
const fs = await import("node:fs/promises");
|
|
148
|
-
const path = await import("node:path");
|
|
149
|
-
const root = path.resolve(targetDir);
|
|
150
|
-
if (opts.replace) {
|
|
151
|
-
await fs.rm(root, { recursive: true, force: true });
|
|
152
|
-
}
|
|
153
|
-
await fs.mkdir(root, { recursive: true });
|
|
154
|
-
let fileCount = 0;
|
|
155
|
-
let byteCount = 0;
|
|
156
|
-
for (const entry of parseStoredZip(archive)) {
|
|
157
|
-
const dest = path.resolve(root, entry.path);
|
|
158
|
-
const rel = path.relative(root, dest);
|
|
159
|
-
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
160
|
-
throw new Error(`archive entry escapes target directory: ${entry.path}`);
|
|
161
|
-
}
|
|
162
|
-
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
163
|
-
await fs.writeFile(dest, entry.data);
|
|
164
|
-
fileCount += 1;
|
|
165
|
-
byteCount += entry.data.byteLength;
|
|
166
|
-
}
|
|
167
|
-
return { path: root, file_count: fileCount, byte_count: byteCount };
|
|
168
|
-
}
|
|
169
|
-
function createStoredZip(entries) {
|
|
170
|
-
const encoder = new TextEncoder();
|
|
171
|
-
const localParts = [];
|
|
172
|
-
const centralParts = [];
|
|
173
|
-
let offset = 0;
|
|
174
|
-
for (const entry of entries) {
|
|
175
|
-
const name = encoder.encode(entry.path);
|
|
176
|
-
const crc = crc32(entry.data);
|
|
177
|
-
const local = new Uint8Array(30 + name.length);
|
|
178
|
-
const lv = new DataView(local.buffer);
|
|
179
|
-
lv.setUint32(0, 0x04034b50, true);
|
|
180
|
-
lv.setUint16(4, 20, true);
|
|
181
|
-
lv.setUint16(8, 0, true);
|
|
182
|
-
lv.setUint32(14, crc, true);
|
|
183
|
-
lv.setUint32(18, entry.data.byteLength, true);
|
|
184
|
-
lv.setUint32(22, entry.data.byteLength, true);
|
|
185
|
-
lv.setUint16(26, name.length, true);
|
|
186
|
-
local.set(name, 30);
|
|
187
|
-
localParts.push(local, entry.data);
|
|
188
|
-
const central = new Uint8Array(46 + name.length);
|
|
189
|
-
const cv = new DataView(central.buffer);
|
|
190
|
-
cv.setUint32(0, 0x02014b50, true);
|
|
191
|
-
cv.setUint16(4, 20, true);
|
|
192
|
-
cv.setUint16(6, 20, true);
|
|
193
|
-
cv.setUint32(16, crc, true);
|
|
194
|
-
cv.setUint32(20, entry.data.byteLength, true);
|
|
195
|
-
cv.setUint32(24, entry.data.byteLength, true);
|
|
196
|
-
cv.setUint16(28, name.length, true);
|
|
197
|
-
cv.setUint32(42, offset, true);
|
|
198
|
-
central.set(name, 46);
|
|
199
|
-
centralParts.push(central);
|
|
200
|
-
offset += local.byteLength + entry.data.byteLength;
|
|
201
|
-
}
|
|
202
|
-
const centralOffset = offset;
|
|
203
|
-
const centralSize = centralParts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
204
|
-
const end = new Uint8Array(22);
|
|
205
|
-
const ev = new DataView(end.buffer);
|
|
206
|
-
ev.setUint32(0, 0x06054b50, true);
|
|
207
|
-
ev.setUint16(8, entries.length, true);
|
|
208
|
-
ev.setUint16(10, entries.length, true);
|
|
209
|
-
ev.setUint32(12, centralSize, true);
|
|
210
|
-
ev.setUint32(16, centralOffset, true);
|
|
211
|
-
const zip = concatUint8([...localParts, ...centralParts, end]);
|
|
212
|
-
return zip.buffer.slice(zip.byteOffset, zip.byteOffset + zip.byteLength);
|
|
213
|
-
}
|
|
214
|
-
function parseStoredZip(archive) {
|
|
215
|
-
const data = new Uint8Array(archive);
|
|
216
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
217
|
-
const entries = [];
|
|
218
|
-
let pos = 0;
|
|
219
|
-
const decoder = new TextDecoder();
|
|
220
|
-
while (pos + 4 <= data.byteLength && view.getUint32(pos, true) === 0x04034b50) {
|
|
221
|
-
const method = view.getUint16(pos + 8, true);
|
|
222
|
-
if (method !== 0) {
|
|
223
|
-
throw new Error("Only stored ZIP entries are supported by pullDirectory");
|
|
224
|
-
}
|
|
225
|
-
const compressedSize = view.getUint32(pos + 18, true);
|
|
226
|
-
const fileNameLength = view.getUint16(pos + 26, true);
|
|
227
|
-
const extraLength = view.getUint16(pos + 28, true);
|
|
228
|
-
const nameStart = pos + 30;
|
|
229
|
-
const contentStart = nameStart + fileNameLength + extraLength;
|
|
230
|
-
const contentEnd = contentStart + compressedSize;
|
|
231
|
-
if (contentEnd > data.byteLength) {
|
|
232
|
-
throw new Error("Invalid ZIP archive");
|
|
233
|
-
}
|
|
234
|
-
const name = decoder.decode(data.slice(nameStart, nameStart + fileNameLength)).replace(/\\/g, "/");
|
|
235
|
-
if (name && !name.endsWith("/") && !name.startsWith("__MACOSX/") && !name.split("/").includes("..")) {
|
|
236
|
-
entries.push({ path: name.replace(/^\/+/, ""), data: data.slice(contentStart, contentEnd) });
|
|
237
|
-
}
|
|
238
|
-
pos = contentEnd;
|
|
239
|
-
}
|
|
240
|
-
return entries;
|
|
241
|
-
}
|
|
242
|
-
function concatUint8(parts) {
|
|
243
|
-
const total = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
|
244
|
-
const out = new Uint8Array(total);
|
|
245
|
-
let offset = 0;
|
|
246
|
-
for (const part of parts) {
|
|
247
|
-
out.set(part, offset);
|
|
248
|
-
offset += part.byteLength;
|
|
249
|
-
}
|
|
250
|
-
return out;
|
|
251
|
-
}
|
|
252
|
-
function crc32(data) {
|
|
253
|
-
let crc = 0xffffffff;
|
|
254
|
-
for (const byte of data) {
|
|
255
|
-
crc ^= byte;
|
|
256
|
-
for (let i = 0; i < 8; i += 1) {
|
|
257
|
-
crc = (crc >>> 1) ^ (0xedb88320 & -(crc & 1));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return (crc ^ 0xffffffff) >>> 0;
|
|
261
|
-
}
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export interface CallerContext {
|
|
|
8
8
|
locality?: string;
|
|
9
9
|
extra?: unknown;
|
|
10
10
|
}
|
|
11
|
+
export interface SkillToolOptions {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
11
14
|
export interface ResponseCreateParamsBase {
|
|
12
15
|
input: Input;
|
|
13
16
|
instructions?: string;
|
|
@@ -32,6 +35,7 @@ export interface ResponseCreateParamsBase {
|
|
|
32
35
|
preferred_sites?: string[];
|
|
33
36
|
skills?: SkillReference[];
|
|
34
37
|
local_skills?: LocalSkillDescriptor[];
|
|
38
|
+
skill_tool?: SkillToolOptions;
|
|
35
39
|
prompt_cache_key?: string;
|
|
36
40
|
memory?: MemoryOptions;
|
|
37
41
|
plan_mode_preference?: AgentCapabilityPreference;
|
package/dist/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.1.
|
|
2
|
-
export declare const USER_AGENT = "@agent-api/sdk/1.1.
|
|
1
|
+
export declare const VERSION = "1.1.5";
|
|
2
|
+
export declare const USER_AGENT = "@agent-api/sdk/1.1.5";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "1.1.
|
|
1
|
+
export const VERSION = "1.1.5";
|
|
2
2
|
export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
|