@agent-api/sdk 1.1.4 → 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 +14 -1
- package/dist/client.d.ts +1 -0
- package/dist/client.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/local-skills.js +13 -1
- package/dist/resources/auth.d.ts +3 -1
- package/dist/resources/auth.js +18 -0
- 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 +1 -0
- package/dist-cjs/index.js +2 -1
- package/dist-cjs/local-skills.js +13 -1
- package/dist-cjs/resources/auth.js +19 -0
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
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
|
@@ -68,7 +68,7 @@ src/
|
|
|
68
68
|
| `client.tools` | `list` |
|
|
69
69
|
| `client.volumes` | `list`, `create`, `retrieve`, `update`, `delete`, `listEntries`, `searchEntries`, `readFile`, `writeFile`, `deletePath`, `reconcileUsage`, `createDirectory`, `downloadArchive`, `summarize`, `readLines`, `patchLines`, `grep` |
|
|
70
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` |
|
|
71
|
+
| `client.auth` | `startDeviceAuth`, `pollDeviceAuth`, `waitForDeviceAuth`, `refreshBrowserSession` |
|
|
72
72
|
|
|
73
73
|
`NodeAgentAPI` from `@agent-api/sdk/node` extends `client.skills` with Node-only `pushDirectory` and `pullDirectory`.
|
|
74
74
|
|
|
@@ -90,6 +90,19 @@ console.log(session.access_token);
|
|
|
90
90
|
|
|
91
91
|
The SDK returns URLs and polling helpers only. Opening the browser belongs to the CLI, Electron, Tauri, or native host app.
|
|
92
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
|
+
|
|
93
106
|
## Durable Volumes
|
|
94
107
|
|
|
95
108
|
```typescript
|
package/dist/client.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class AgentAPI {
|
|
|
31
31
|
protected createSkillsResource(): SkillsResource;
|
|
32
32
|
startDeviceAuth: (...args: Parameters<AuthResource["startDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthStart>;
|
|
33
33
|
pollDeviceAuth: (...args: Parameters<AuthResource["pollDeviceAuth"]>) => Promise<import("./index.js").DeviceAuthPollResult>;
|
|
34
|
+
refreshBrowserSession: (...args: Parameters<AuthResource["refreshBrowserSession"]>) => Promise<import("./index.js").AuthSession>;
|
|
34
35
|
waitForDeviceAuth: (...args: Parameters<AuthResource["waitForDeviceAuth"]>) => Promise<import("./index.js").ApprovedDeviceAuth>;
|
|
35
36
|
}
|
|
36
37
|
export { VERSION };
|
package/dist/client.js
CHANGED
|
@@ -62,6 +62,7 @@ export class AgentAPI {
|
|
|
62
62
|
}
|
|
63
63
|
startDeviceAuth = (...args) => this.auth.startDeviceAuth(...args);
|
|
64
64
|
pollDeviceAuth = (...args) => this.auth.pollDeviceAuth(...args);
|
|
65
|
+
refreshBrowserSession = (...args) => this.auth.refreshBrowserSession(...args);
|
|
65
66
|
waitForDeviceAuth = (...args) => this.auth.waitForDeviceAuth(...args);
|
|
66
67
|
}
|
|
67
68
|
export { VERSION };
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +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 { AuthResource, DeviceAuthFlowError } from "./resources/auth.js";
|
|
10
|
+
export { AuthResource, DeviceAuthFlowError, browserAuthSessionExpiresWithin } from "./resources/auth.js";
|
package/dist/index.js
CHANGED
|
@@ -4,4 +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 { 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/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;
|
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}`;
|
package/dist-cjs/client.js
CHANGED
|
@@ -66,6 +66,7 @@ class AgentAPI {
|
|
|
66
66
|
}
|
|
67
67
|
startDeviceAuth = (...args) => this.auth.startDeviceAuth(...args);
|
|
68
68
|
pollDeviceAuth = (...args) => this.auth.pollDeviceAuth(...args);
|
|
69
|
+
refreshBrowserSession = (...args) => this.auth.refreshBrowserSession(...args);
|
|
69
70
|
waitForDeviceAuth = (...args) => this.auth.waitForDeviceAuth(...args);
|
|
70
71
|
}
|
|
71
72
|
exports.AgentAPI = AgentAPI;
|
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.DeviceAuthFlowError = exports.AuthResource = 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.browserAuthSessionExpiresWithin = exports.DeviceAuthFlowError = exports.AuthResource = 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; } });
|
|
@@ -49,3 +49,4 @@ Object.defineProperty(exports, "resolvePresetToolsFromCatalog", { enumerable: tr
|
|
|
49
49
|
var auth_js_1 = require("./resources/auth.js");
|
|
50
50
|
Object.defineProperty(exports, "AuthResource", { enumerable: true, get: function () { return auth_js_1.AuthResource; } });
|
|
51
51
|
Object.defineProperty(exports, "DeviceAuthFlowError", { enumerable: true, get: function () { return auth_js_1.DeviceAuthFlowError; } });
|
|
52
|
+
Object.defineProperty(exports, "browserAuthSessionExpiresWithin", { enumerable: true, get: function () { return auth_js_1.browserAuthSessionExpiresWithin; } });
|
package/dist-cjs/local-skills.js
CHANGED
|
@@ -69,7 +69,19 @@ async function localSkillFromDirectory(rootDir, options = {}) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
function pendingLocalSkillCalls(response) {
|
|
72
|
-
return (0, local_functions_js_1.pendingFunctionCalls)(response).filter((call) => call
|
|
72
|
+
return (0, local_functions_js_1.pendingFunctionCalls)(response).filter((call) => isLocalSkillFocusCall(call));
|
|
73
|
+
}
|
|
74
|
+
function isLocalSkillFocusCall(call) {
|
|
75
|
+
if (call.name !== "skill") {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
const args = call.arguments ? JSON.parse(call.arguments) : {};
|
|
80
|
+
return String(args.action || "").trim().toLowerCase() === "focus";
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
73
85
|
}
|
|
74
86
|
async function runLocalSkillHandlers(response, localSkills) {
|
|
75
87
|
const byRef = await localSkillsByRef(localSkills);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DeviceAuthFlowError = exports.AuthResource = void 0;
|
|
4
|
+
exports.browserAuthSessionExpiresWithin = browserAuthSessionExpiresWithin;
|
|
4
5
|
const defaultDevicePollIntervalSeconds = 5;
|
|
5
6
|
class AuthResource {
|
|
6
7
|
http;
|
|
@@ -14,6 +15,16 @@ class AuthResource {
|
|
|
14
15
|
requireDeviceCode(params.device_code);
|
|
15
16
|
return this.http.request("POST", "/v1/auth/device/poll", params, options);
|
|
16
17
|
}
|
|
18
|
+
refreshBrowserSession(params, options = {}) {
|
|
19
|
+
requireRefreshToken(params.refresh_token);
|
|
20
|
+
return this.http.request("POST", "/v1/auth/refresh", {}, {
|
|
21
|
+
...options,
|
|
22
|
+
headers: {
|
|
23
|
+
...options.headers,
|
|
24
|
+
Cookie: `agent_api_refresh=${encodeURIComponent(params.refresh_token)}`,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
17
28
|
async waitForDeviceAuth(params, options = {}) {
|
|
18
29
|
requireDeviceCode(params.device_code);
|
|
19
30
|
const startedAt = Date.now();
|
|
@@ -36,6 +47,9 @@ class AuthResource {
|
|
|
36
47
|
}
|
|
37
48
|
}
|
|
38
49
|
exports.AuthResource = AuthResource;
|
|
50
|
+
function browserAuthSessionExpiresWithin(session, windowMs = 60_000, nowMs = Date.now()) {
|
|
51
|
+
return session.access_token_expires_at * 1000 - nowMs <= windowMs;
|
|
52
|
+
}
|
|
39
53
|
class DeviceAuthFlowError extends Error {
|
|
40
54
|
result;
|
|
41
55
|
constructor(message, result) {
|
|
@@ -51,6 +65,11 @@ function requireDeviceCode(deviceCode) {
|
|
|
51
65
|
throw new TypeError("device_code is required");
|
|
52
66
|
}
|
|
53
67
|
}
|
|
68
|
+
function requireRefreshToken(refreshToken) {
|
|
69
|
+
if (!refreshToken || !refreshToken.trim()) {
|
|
70
|
+
throw new TypeError("refresh_token is required");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
54
73
|
function pollDelayMs(params, result) {
|
|
55
74
|
const seconds = params.interval_seconds ?? result.interval_seconds ?? defaultDevicePollIntervalSeconds;
|
|
56
75
|
return Math.max(1, seconds) * 1000;
|
package/dist-cjs/version.js
CHANGED