@agent-api/sdk 1.1.4 → 1.2.0
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 +17 -5
- package/README.md +29 -16
- 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/context.d.ts +4 -4
- package/dist/local/context.js +10 -10
- package/dist/local/core.d.ts +30 -30
- package/dist/local/core.js +12 -12
- package/dist/local/tools.d.ts +17 -17
- package/dist/local/tools.js +46 -46
- package/dist/local-skills.js +13 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -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/context.js +10 -10
- package/dist-cjs/local/core.js +15 -15
- package/dist-cjs/local/tools.js +51 -51
- package/dist-cjs/local-skills.js +13 -1
- package/dist-cjs/node.js +5 -5
- package/dist-cjs/resources/auth.js +19 -0
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
package/dist/local/tools.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
import { createLocalContextPackage } from "./context.js";
|
|
2
|
-
export class
|
|
3
|
-
|
|
2
|
+
export class LocalWorkdirDriver {
|
|
3
|
+
workdir;
|
|
4
4
|
accessMode;
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
5
|
+
constructor(workdir, options = {}) {
|
|
6
|
+
this.workdir = workdir;
|
|
7
7
|
this.accessMode = options.accessMode ?? "approval";
|
|
8
8
|
}
|
|
9
9
|
async dispatch(args) {
|
|
10
|
-
const action =
|
|
10
|
+
const action = workdirAction(args);
|
|
11
11
|
switch (action) {
|
|
12
12
|
case "summarize":
|
|
13
|
-
return localToolResult(action, localSummaryResult(await this.
|
|
13
|
+
return localToolResult(action, localSummaryResult(await this.workdir.summarize(summaryArgs(args))));
|
|
14
14
|
case "list":
|
|
15
|
-
return localToolResult(action, await this.
|
|
15
|
+
return localToolResult(action, await this.workdir.listEntries(optionalStringArg(args, "path") ?? ".", listArgs(args)));
|
|
16
16
|
case "search":
|
|
17
|
-
return localToolResult(action, await this.
|
|
17
|
+
return localToolResult(action, await this.workdir.searchEntries(searchEntriesArgs(args)));
|
|
18
18
|
case "grep":
|
|
19
|
-
return localToolResult(action, await this.
|
|
19
|
+
return localToolResult(action, await this.workdir.grep(grepArgs(args)));
|
|
20
20
|
case "read":
|
|
21
|
-
return localToolResult(action, await this.
|
|
21
|
+
return localToolResult(action, await this.workdir.readFile(stringArg(args, "path"), readFileArgs(args)));
|
|
22
22
|
case "read_lines":
|
|
23
|
-
return localToolResult(action, await this.
|
|
23
|
+
return localToolResult(action, await this.workdir.readLines(stringArg(args, "path"), readLinesArgs(args)));
|
|
24
24
|
case "context":
|
|
25
|
-
return localToolResult(action, await createLocalContextPackage(this.
|
|
25
|
+
return localToolResult(action, await createLocalContextPackage(this.workdir, contextPackageArgs(args)));
|
|
26
26
|
case "snapshot":
|
|
27
|
-
return localToolResult(action, await this.
|
|
27
|
+
return localToolResult(action, await this.workdir.snapshot(snapshotArgs(args)));
|
|
28
28
|
case "classify_path":
|
|
29
|
-
return localToolResult(action, this.
|
|
29
|
+
return localToolResult(action, this.workdir.classifyPath(stringArg(args, "path")));
|
|
30
30
|
case "preview_edits":
|
|
31
|
-
return localToolResult(action, await this.
|
|
31
|
+
return localToolResult(action, await this.workdir.previewEdits(editsArg(args)));
|
|
32
32
|
case "apply_edits":
|
|
33
33
|
return await this.dispatchApplyEdits(args);
|
|
34
34
|
case "write":
|
|
@@ -38,73 +38,73 @@ export class LocalWorkspaceDriver {
|
|
|
38
38
|
case "delete":
|
|
39
39
|
return await this.dispatchDelete(args);
|
|
40
40
|
default:
|
|
41
|
-
throw new Error(`unsupported
|
|
41
|
+
throw new Error(`unsupported local_workdir action: ${action}`);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
requiresApproval(args) {
|
|
45
45
|
if (this.accessMode === "full") {
|
|
46
46
|
return false;
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return mutatingLocalWorkdirActions.has(workdirAction(args));
|
|
49
49
|
}
|
|
50
50
|
async dispatchApplyEdits(args) {
|
|
51
51
|
const edits = editsArg(args);
|
|
52
52
|
if (this.accessMode !== "full") {
|
|
53
|
-
return approvalRequired("apply_edits", args, await this.
|
|
53
|
+
return approvalRequired("apply_edits", args, await this.workdir.previewEdits(edits));
|
|
54
54
|
}
|
|
55
|
-
return localToolResult("apply_edits", await this.
|
|
55
|
+
return localToolResult("apply_edits", await this.workdir.applyEdits(edits));
|
|
56
56
|
}
|
|
57
57
|
async dispatchWrite(args) {
|
|
58
58
|
if (this.accessMode !== "full") {
|
|
59
59
|
return approvalRequired("write", args);
|
|
60
60
|
}
|
|
61
|
-
return localToolResult("write", await this.
|
|
61
|
+
return localToolResult("write", await this.workdir.writeText(stringArg(args, "path"), stringArg(args, "content")));
|
|
62
62
|
}
|
|
63
63
|
async dispatchMkdir(args) {
|
|
64
64
|
if (this.accessMode !== "full") {
|
|
65
65
|
return approvalRequired("mkdir", args);
|
|
66
66
|
}
|
|
67
|
-
return localToolResult("mkdir", await this.
|
|
67
|
+
return localToolResult("mkdir", await this.workdir.createDirectory(stringArg(args, "path")));
|
|
68
68
|
}
|
|
69
69
|
async dispatchDelete(args) {
|
|
70
70
|
if (this.accessMode !== "full") {
|
|
71
71
|
return approvalRequired("delete", args);
|
|
72
72
|
}
|
|
73
|
-
return localToolResult("delete", await this.
|
|
73
|
+
return localToolResult("delete", await this.workdir.deletePath(stringArg(args, "path")));
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
export function
|
|
77
|
-
const toolName = options.toolName ?? "
|
|
78
|
-
const driver = new
|
|
79
|
-
const definition =
|
|
76
|
+
export function createLocalWorkdirToolRegistry(workdir, options = {}) {
|
|
77
|
+
const toolName = options.toolName ?? "local_workdir";
|
|
78
|
+
const driver = new LocalWorkdirDriver(workdir, { accessMode: options.accessMode });
|
|
79
|
+
const definition = localWorkdirToolDefinition(toolName);
|
|
80
80
|
return {
|
|
81
|
-
|
|
81
|
+
workdir,
|
|
82
82
|
accessMode: driver.accessMode,
|
|
83
83
|
toolName,
|
|
84
84
|
definitions: () => [{ ...definition }],
|
|
85
85
|
handlers: () => ({ [toolName]: (args) => driver.dispatch(args) }),
|
|
86
86
|
execute: async (name, args) => {
|
|
87
87
|
if (name !== toolName) {
|
|
88
|
-
throw new Error(`unknown local
|
|
88
|
+
throw new Error(`unknown local workdir tool: ${name}`);
|
|
89
89
|
}
|
|
90
90
|
return await driver.dispatch(args);
|
|
91
91
|
},
|
|
92
92
|
requiresApproval: (name, args = {}) => name === toolName && driver.requiresApproval(args),
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
export function
|
|
95
|
+
export function localWorkdirToolDefinition(name = "local_workdir") {
|
|
96
96
|
return {
|
|
97
97
|
type: "function",
|
|
98
98
|
name,
|
|
99
|
-
description:
|
|
100
|
-
parameters:
|
|
99
|
+
description: localWorkdirToolDescription,
|
|
100
|
+
parameters: localWorkdirToolParameters(),
|
|
101
101
|
strict: false,
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
export function
|
|
105
|
-
return
|
|
104
|
+
export function localWorkdirToolInstructions() {
|
|
105
|
+
return localWorkdirToolDescription;
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const localWorkdirActions = [
|
|
108
108
|
"summarize",
|
|
109
109
|
"list",
|
|
110
110
|
"search",
|
|
@@ -120,24 +120,24 @@ const localWorkspaceActions = [
|
|
|
120
120
|
"mkdir",
|
|
121
121
|
"delete",
|
|
122
122
|
];
|
|
123
|
-
const
|
|
123
|
+
const mutatingLocalWorkdirActions = new Set([
|
|
124
124
|
"apply_edits",
|
|
125
125
|
"write",
|
|
126
126
|
"mkdir",
|
|
127
127
|
"delete",
|
|
128
128
|
]);
|
|
129
|
-
const
|
|
130
|
-
"Inspect and modify the selected local
|
|
129
|
+
const localWorkdirToolDescription = [
|
|
130
|
+
"Inspect and modify the selected local workdir through one model-facing primitive.",
|
|
131
131
|
"Use action=list/search/grep/summarize/context to discover files, read/read_lines for file content, preview_edits before edits, and apply_edits/write/mkdir/delete only when mutation is intended.",
|
|
132
132
|
"In approval mode, mutating actions return requires_approval with a safe preview instead of changing files. In full mode, mutating actions execute immediately.",
|
|
133
|
-
"Paths are relative to the selected local
|
|
133
|
+
"Paths are relative to the selected local workdir; never use absolute paths.",
|
|
134
134
|
].join(" ");
|
|
135
|
-
function
|
|
135
|
+
function localWorkdirToolParameters() {
|
|
136
136
|
return objectSchema({
|
|
137
137
|
action: {
|
|
138
138
|
type: "string",
|
|
139
|
-
enum:
|
|
140
|
-
description: "
|
|
139
|
+
enum: localWorkdirActions,
|
|
140
|
+
description: "Workdir operation. Prefer summarize/list/search/grep before reading or editing. Prefer read_lines and apply_edits for source changes.",
|
|
141
141
|
},
|
|
142
142
|
path: stringSchema("Relative path. File path for read/write/delete/edit actions; directory base for list/search/grep/summarize/context/snapshot."),
|
|
143
143
|
query: stringSchema("Path/name query for search, or optional context query."),
|
|
@@ -168,17 +168,17 @@ function localWorkspaceToolParameters() {
|
|
|
168
168
|
max_bytes_per_file: integerSchema("Maximum bytes per file."),
|
|
169
169
|
max_previews: integerSchema("Maximum summary previews."),
|
|
170
170
|
include_content: booleanSchema("Include file contents in context packages."),
|
|
171
|
-
include_summary: booleanSchema("Include
|
|
171
|
+
include_summary: booleanSchema("Include workdir summary in context packages."),
|
|
172
172
|
include_search: booleanSchema("Include grep results in context packages when query is set."),
|
|
173
173
|
include_secrets: booleanSchema("Include likely secret file contents in context packages."),
|
|
174
174
|
hash: booleanSchema("Include SHA-256 hashes in snapshots."),
|
|
175
175
|
}),
|
|
176
176
|
}, ["action"]);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function workdirAction(args) {
|
|
179
179
|
const value = stringArg(args, "action").trim().toLowerCase();
|
|
180
|
-
if (!
|
|
181
|
-
throw new Error(`unsupported
|
|
180
|
+
if (!localWorkdirActions.includes(value)) {
|
|
181
|
+
throw new Error(`unsupported local_workdir action: ${value}`);
|
|
182
182
|
}
|
|
183
183
|
return value;
|
|
184
184
|
}
|
|
@@ -345,7 +345,7 @@ function approvalRequired(action, args, preview) {
|
|
|
345
345
|
requires_approval: true,
|
|
346
346
|
arguments: args,
|
|
347
347
|
preview,
|
|
348
|
-
message: `
|
|
348
|
+
message: `local_workdir action ${action} requires approval`,
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
351
|
function objectSchema(properties, required = []) {
|
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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from "./index.js";
|
|
2
2
|
export { NodeAgentAPI } from "./node-client.js";
|
|
3
3
|
export { NodeSkillsResource } from "./resources/skills-node.js";
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
4
|
+
export { LocalWorkdirDriver, createLocalWorkdirToolRegistry, localWorkdirToolDefinition, localWorkdirToolInstructions, } from "./local/tools.js";
|
|
5
|
+
export type { LocalWorkdirAction, LocalWorkdirAccessMode, LocalWorkdirToolRegistry, LocalWorkdirToolRegistryOptions, } from "./local/tools.js";
|
|
6
6
|
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
7
7
|
export type { LocalSkillDirectoryOptions } from "./local-skills.js";
|
|
8
8
|
export * from "./local/index.js";
|
package/dist/node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from "./index.js";
|
|
2
2
|
export { NodeAgentAPI } from "./node-client.js";
|
|
3
3
|
export { NodeSkillsResource } from "./resources/skills-node.js";
|
|
4
|
-
export {
|
|
4
|
+
export { LocalWorkdirDriver, createLocalWorkdirToolRegistry, localWorkdirToolDefinition, localWorkdirToolInstructions, } from "./local/tools.js";
|
|
5
5
|
export { localSkillFromDirectory, pendingLocalSkillCalls, runLocalSkillHandlers } from "./local-skills.js";
|
|
6
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;
|
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.
|
|
2
|
-
export declare const USER_AGENT = "@agent-api/sdk/1.
|
|
1
|
+
export declare const VERSION = "1.2.0";
|
|
2
|
+
export declare const USER_AGENT = "@agent-api/sdk/1.2.0";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "1.
|
|
1
|
+
export const VERSION = "1.2.0";
|
|
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; } });
|
|
@@ -5,7 +5,7 @@ exports.summarizeLocalContextSensitivity = summarizeLocalContextSensitivity;
|
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const promises_1 = require("node:fs/promises");
|
|
7
7
|
const core_js_1 = require("./core.js");
|
|
8
|
-
async function createLocalContextPackage(
|
|
8
|
+
async function createLocalContextPackage(workdir, params = {}) {
|
|
9
9
|
const basePath = params.path ?? ".";
|
|
10
10
|
const maxFiles = positiveInt(params.maxFiles, 80);
|
|
11
11
|
const maxBytes = positiveInt(params.maxBytes, 256 * 1024);
|
|
@@ -16,7 +16,7 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
16
16
|
const includeSummary = params.includeSummary ?? true;
|
|
17
17
|
const includeSearch = Boolean(params.includeSearch && params.query?.trim());
|
|
18
18
|
const includeSecrets = params.includeSecrets ?? false;
|
|
19
|
-
const stats = await
|
|
19
|
+
const stats = await workdir.list(basePath, { recursive: true });
|
|
20
20
|
const fileStats = stats
|
|
21
21
|
.filter((item) => item.type === "file")
|
|
22
22
|
.filter((item) => matchesPathFilters(item.path, params.include, params.exclude))
|
|
@@ -53,7 +53,7 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
53
53
|
truncated = true;
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
const delivered = await
|
|
56
|
+
const delivered = await workdir.readFile(item.path, { maxBytes: readBudget });
|
|
57
57
|
includedBytes += delivered.encoding === "text"
|
|
58
58
|
? Buffer.byteLength(delivered.content ?? "", "utf8")
|
|
59
59
|
: Buffer.byteLength(delivered.content_base64 ?? "", "base64");
|
|
@@ -68,7 +68,7 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
68
68
|
packaged.content_base64 = delivered.content_base64;
|
|
69
69
|
}
|
|
70
70
|
if (includeHashes) {
|
|
71
|
-
packaged.sha256 = await sha256File(
|
|
71
|
+
packaged.sha256 = await sha256File(workdir, item.path);
|
|
72
72
|
}
|
|
73
73
|
if (delivered.truncated) {
|
|
74
74
|
truncated = true;
|
|
@@ -76,7 +76,7 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
76
76
|
files.push(packaged);
|
|
77
77
|
}
|
|
78
78
|
const summary = includeSummary
|
|
79
|
-
? await
|
|
79
|
+
? await workdir.summarize({
|
|
80
80
|
path: basePath,
|
|
81
81
|
maxFiles,
|
|
82
82
|
previewBytes,
|
|
@@ -84,7 +84,7 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
84
84
|
})
|
|
85
85
|
: undefined;
|
|
86
86
|
const search = includeSearch
|
|
87
|
-
? await
|
|
87
|
+
? await workdir.grep({
|
|
88
88
|
pattern: params.query,
|
|
89
89
|
path: basePath,
|
|
90
90
|
limit: maxFiles,
|
|
@@ -94,8 +94,8 @@ async function createLocalContextPackage(workspace, params = {}) {
|
|
|
94
94
|
: undefined;
|
|
95
95
|
return {
|
|
96
96
|
object: "local_context_manifest",
|
|
97
|
-
root:
|
|
98
|
-
|
|
97
|
+
root: workdir.root,
|
|
98
|
+
workdir_name: workdir.name,
|
|
99
99
|
generated_at_unix: Math.floor(Date.now() / 1000),
|
|
100
100
|
base_path: basePath,
|
|
101
101
|
file_count: fileStats.length,
|
|
@@ -152,7 +152,7 @@ function positiveInt(value, fallback) {
|
|
|
152
152
|
const parsed = Number(value);
|
|
153
153
|
return Number.isFinite(parsed) && parsed > 0 ? Math.trunc(parsed) : fallback;
|
|
154
154
|
}
|
|
155
|
-
async function sha256File(
|
|
156
|
-
const fullPath =
|
|
155
|
+
async function sha256File(workdir, relativePath) {
|
|
156
|
+
const fullPath = workdir.files.resolvePath(relativePath);
|
|
157
157
|
return (0, node_crypto_1.createHash)("sha256").update(await (0, promises_1.readFile)(fullPath)).digest("hex");
|
|
158
158
|
}
|
package/dist-cjs/local/core.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LocalSkillStore = exports.
|
|
6
|
+
exports.LocalSkillStore = exports.LocalWorkdir = exports.LocalWorkdirManager = exports.LocalConfigStore = exports.LocalFileStore = exports.LocalConfigError = exports.LocalNotTextFileError = exports.LocalFileTooLargeError = exports.LocalIgnoredPathError = exports.LocalPathError = exports.LocalError = void 0;
|
|
7
7
|
exports.createLocalRuntime = createLocalRuntime;
|
|
8
8
|
exports.localAppDirs = localAppDirs;
|
|
9
9
|
exports.classifyLocalPathSensitivity = classifyLocalPathSensitivity;
|
|
@@ -33,7 +33,7 @@ class LocalPathError extends LocalError {
|
|
|
33
33
|
exports.LocalPathError = LocalPathError;
|
|
34
34
|
class LocalIgnoredPathError extends LocalError {
|
|
35
35
|
constructor(path) {
|
|
36
|
-
super("local_ignored_path", `local
|
|
36
|
+
super("local_ignored_path", `local workdir path is ignored: ${path}`, { path });
|
|
37
37
|
this.name = "LocalIgnoredPathError";
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -77,9 +77,9 @@ function createLocalRuntime(options) {
|
|
|
77
77
|
temp,
|
|
78
78
|
config: new LocalConfigStore(configFiles),
|
|
79
79
|
skills: new LocalSkillStore(data.child("skills")),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return new
|
|
80
|
+
workdirs: new LocalWorkdirManager(),
|
|
81
|
+
workdir(root, workdirOptions = {}) {
|
|
82
|
+
return new LocalWorkdir(root, workdirOptions);
|
|
83
83
|
},
|
|
84
84
|
async ensure() {
|
|
85
85
|
await Promise.all([data.ensure(), cache.ensure(), logs.ensure(), temp.ensure(), configFiles.ensure()]);
|
|
@@ -473,13 +473,13 @@ class LocalConfigStore {
|
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
475
|
exports.LocalConfigStore = LocalConfigStore;
|
|
476
|
-
class
|
|
476
|
+
class LocalWorkdirManager {
|
|
477
477
|
open(root, options = {}) {
|
|
478
|
-
return new
|
|
478
|
+
return new LocalWorkdir(root, options);
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
-
exports.
|
|
482
|
-
class
|
|
481
|
+
exports.LocalWorkdirManager = LocalWorkdirManager;
|
|
482
|
+
class LocalWorkdir {
|
|
483
483
|
root;
|
|
484
484
|
name;
|
|
485
485
|
metadata;
|
|
@@ -490,11 +490,11 @@ class LocalWorkspace {
|
|
|
490
490
|
maxFileBytes;
|
|
491
491
|
constructor(root, options = {}) {
|
|
492
492
|
this.root = node_path_1.default.resolve(root);
|
|
493
|
-
this.name = options.name?.trim() || node_path_1.default.basename(this.root) || "
|
|
493
|
+
this.name = options.name?.trim() || node_path_1.default.basename(this.root) || "workdir";
|
|
494
494
|
this.metadata = { ...(options.metadata ?? {}) };
|
|
495
495
|
this.trusted = options.trusted ?? false;
|
|
496
|
-
this.files = new LocalFileStore(this.root, { label: "
|
|
497
|
-
this.ignore = [...
|
|
496
|
+
this.files = new LocalFileStore(this.root, { label: "workdir" });
|
|
497
|
+
this.ignore = [...defaultWorkdirIgnoreRules(), ...(options.ignore ?? [])];
|
|
498
498
|
this.gitignore = options.gitignore ?? true;
|
|
499
499
|
this.maxFileBytes = positiveInt(options.maxFileBytes, 10 * 1024 * 1024);
|
|
500
500
|
}
|
|
@@ -521,7 +521,7 @@ class LocalWorkspace {
|
|
|
521
521
|
return loaded;
|
|
522
522
|
}
|
|
523
523
|
child(relativePath, options = {}) {
|
|
524
|
-
return new
|
|
524
|
+
return new LocalWorkdir(this.files.resolvePath(relativePath), {
|
|
525
525
|
name: options.name,
|
|
526
526
|
metadata: options.metadata ?? this.metadata,
|
|
527
527
|
trusted: options.trusted ?? this.trusted,
|
|
@@ -731,7 +731,7 @@ class LocalWorkspace {
|
|
|
731
731
|
}
|
|
732
732
|
}
|
|
733
733
|
}
|
|
734
|
-
exports.
|
|
734
|
+
exports.LocalWorkdir = LocalWorkdir;
|
|
735
735
|
class LocalSkillStore {
|
|
736
736
|
files;
|
|
737
737
|
constructor(files) {
|
|
@@ -904,7 +904,7 @@ function ignored(relativePath, ignore) {
|
|
|
904
904
|
function ignoredDirectoryName(name) {
|
|
905
905
|
return name === ".git" || name === "node_modules" || name === "__pycache__";
|
|
906
906
|
}
|
|
907
|
-
function
|
|
907
|
+
function defaultWorkdirIgnoreRules() {
|
|
908
908
|
return [
|
|
909
909
|
".git",
|
|
910
910
|
"node_modules",
|