@agent-api/sdk 1.1.5 → 1.2.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 +13 -6
- package/README.md +21 -17
- 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/index.d.ts +1 -0
- package/dist/local/index.js +1 -0
- package/dist/local/shell.d.ts +82 -0
- package/dist/local/shell.js +318 -0
- package/dist/local/tools.d.ts +17 -17
- package/dist/local/tools.js +46 -46
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist-cjs/local/context.js +10 -10
- package/dist-cjs/local/core.js +15 -15
- package/dist-cjs/local/index.js +1 -0
- package/dist-cjs/local/shell.js +329 -0
- package/dist-cjs/local/tools.js +51 -51
- package/dist-cjs/node.js +11 -6
- package/dist-cjs/version.js +1 -1
- package/package.json +1 -1
package/dist-cjs/local/tools.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
3
|
+
exports.LocalWorkdirDriver = void 0;
|
|
4
|
+
exports.createLocalWorkdirToolRegistry = createLocalWorkdirToolRegistry;
|
|
5
|
+
exports.localWorkdirToolDefinition = localWorkdirToolDefinition;
|
|
6
|
+
exports.localWorkdirToolInstructions = localWorkdirToolInstructions;
|
|
7
7
|
const context_js_1 = require("./context.js");
|
|
8
|
-
class
|
|
9
|
-
|
|
8
|
+
class LocalWorkdirDriver {
|
|
9
|
+
workdir;
|
|
10
10
|
accessMode;
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
11
|
+
constructor(workdir, options = {}) {
|
|
12
|
+
this.workdir = workdir;
|
|
13
13
|
this.accessMode = options.accessMode ?? "approval";
|
|
14
14
|
}
|
|
15
15
|
async dispatch(args) {
|
|
16
|
-
const action =
|
|
16
|
+
const action = workdirAction(args);
|
|
17
17
|
switch (action) {
|
|
18
18
|
case "summarize":
|
|
19
|
-
return localToolResult(action, localSummaryResult(await this.
|
|
19
|
+
return localToolResult(action, localSummaryResult(await this.workdir.summarize(summaryArgs(args))));
|
|
20
20
|
case "list":
|
|
21
|
-
return localToolResult(action, await this.
|
|
21
|
+
return localToolResult(action, await this.workdir.listEntries(optionalStringArg(args, "path") ?? ".", listArgs(args)));
|
|
22
22
|
case "search":
|
|
23
|
-
return localToolResult(action, await this.
|
|
23
|
+
return localToolResult(action, await this.workdir.searchEntries(searchEntriesArgs(args)));
|
|
24
24
|
case "grep":
|
|
25
|
-
return localToolResult(action, await this.
|
|
25
|
+
return localToolResult(action, await this.workdir.grep(grepArgs(args)));
|
|
26
26
|
case "read":
|
|
27
|
-
return localToolResult(action, await this.
|
|
27
|
+
return localToolResult(action, await this.workdir.readFile(stringArg(args, "path"), readFileArgs(args)));
|
|
28
28
|
case "read_lines":
|
|
29
|
-
return localToolResult(action, await this.
|
|
29
|
+
return localToolResult(action, await this.workdir.readLines(stringArg(args, "path"), readLinesArgs(args)));
|
|
30
30
|
case "context":
|
|
31
|
-
return localToolResult(action, await (0, context_js_1.createLocalContextPackage)(this.
|
|
31
|
+
return localToolResult(action, await (0, context_js_1.createLocalContextPackage)(this.workdir, contextPackageArgs(args)));
|
|
32
32
|
case "snapshot":
|
|
33
|
-
return localToolResult(action, await this.
|
|
33
|
+
return localToolResult(action, await this.workdir.snapshot(snapshotArgs(args)));
|
|
34
34
|
case "classify_path":
|
|
35
|
-
return localToolResult(action, this.
|
|
35
|
+
return localToolResult(action, this.workdir.classifyPath(stringArg(args, "path")));
|
|
36
36
|
case "preview_edits":
|
|
37
|
-
return localToolResult(action, await this.
|
|
37
|
+
return localToolResult(action, await this.workdir.previewEdits(editsArg(args)));
|
|
38
38
|
case "apply_edits":
|
|
39
39
|
return await this.dispatchApplyEdits(args);
|
|
40
40
|
case "write":
|
|
@@ -44,74 +44,74 @@ class LocalWorkspaceDriver {
|
|
|
44
44
|
case "delete":
|
|
45
45
|
return await this.dispatchDelete(args);
|
|
46
46
|
default:
|
|
47
|
-
throw new Error(`unsupported
|
|
47
|
+
throw new Error(`unsupported local_workdir action: ${action}`);
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
requiresApproval(args) {
|
|
51
51
|
if (this.accessMode === "full") {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return mutatingLocalWorkdirActions.has(workdirAction(args));
|
|
55
55
|
}
|
|
56
56
|
async dispatchApplyEdits(args) {
|
|
57
57
|
const edits = editsArg(args);
|
|
58
58
|
if (this.accessMode !== "full") {
|
|
59
|
-
return approvalRequired("apply_edits", args, await this.
|
|
59
|
+
return approvalRequired("apply_edits", args, await this.workdir.previewEdits(edits));
|
|
60
60
|
}
|
|
61
|
-
return localToolResult("apply_edits", await this.
|
|
61
|
+
return localToolResult("apply_edits", await this.workdir.applyEdits(edits));
|
|
62
62
|
}
|
|
63
63
|
async dispatchWrite(args) {
|
|
64
64
|
if (this.accessMode !== "full") {
|
|
65
65
|
return approvalRequired("write", args);
|
|
66
66
|
}
|
|
67
|
-
return localToolResult("write", await this.
|
|
67
|
+
return localToolResult("write", await this.workdir.writeText(stringArg(args, "path"), stringArg(args, "content")));
|
|
68
68
|
}
|
|
69
69
|
async dispatchMkdir(args) {
|
|
70
70
|
if (this.accessMode !== "full") {
|
|
71
71
|
return approvalRequired("mkdir", args);
|
|
72
72
|
}
|
|
73
|
-
return localToolResult("mkdir", await this.
|
|
73
|
+
return localToolResult("mkdir", await this.workdir.createDirectory(stringArg(args, "path")));
|
|
74
74
|
}
|
|
75
75
|
async dispatchDelete(args) {
|
|
76
76
|
if (this.accessMode !== "full") {
|
|
77
77
|
return approvalRequired("delete", args);
|
|
78
78
|
}
|
|
79
|
-
return localToolResult("delete", await this.
|
|
79
|
+
return localToolResult("delete", await this.workdir.deletePath(stringArg(args, "path")));
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
exports.
|
|
83
|
-
function
|
|
84
|
-
const toolName = options.toolName ?? "
|
|
85
|
-
const driver = new
|
|
86
|
-
const definition =
|
|
82
|
+
exports.LocalWorkdirDriver = LocalWorkdirDriver;
|
|
83
|
+
function createLocalWorkdirToolRegistry(workdir, options = {}) {
|
|
84
|
+
const toolName = options.toolName ?? "local_workdir";
|
|
85
|
+
const driver = new LocalWorkdirDriver(workdir, { accessMode: options.accessMode });
|
|
86
|
+
const definition = localWorkdirToolDefinition(toolName);
|
|
87
87
|
return {
|
|
88
|
-
|
|
88
|
+
workdir,
|
|
89
89
|
accessMode: driver.accessMode,
|
|
90
90
|
toolName,
|
|
91
91
|
definitions: () => [{ ...definition }],
|
|
92
92
|
handlers: () => ({ [toolName]: (args) => driver.dispatch(args) }),
|
|
93
93
|
execute: async (name, args) => {
|
|
94
94
|
if (name !== toolName) {
|
|
95
|
-
throw new Error(`unknown local
|
|
95
|
+
throw new Error(`unknown local workdir tool: ${name}`);
|
|
96
96
|
}
|
|
97
97
|
return await driver.dispatch(args);
|
|
98
98
|
},
|
|
99
99
|
requiresApproval: (name, args = {}) => name === toolName && driver.requiresApproval(args),
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function localWorkdirToolDefinition(name = "local_workdir") {
|
|
103
103
|
return {
|
|
104
104
|
type: "function",
|
|
105
105
|
name,
|
|
106
|
-
description:
|
|
107
|
-
parameters:
|
|
106
|
+
description: localWorkdirToolDescription,
|
|
107
|
+
parameters: localWorkdirToolParameters(),
|
|
108
108
|
strict: false,
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
111
|
+
function localWorkdirToolInstructions() {
|
|
112
|
+
return localWorkdirToolDescription;
|
|
113
113
|
}
|
|
114
|
-
const
|
|
114
|
+
const localWorkdirActions = [
|
|
115
115
|
"summarize",
|
|
116
116
|
"list",
|
|
117
117
|
"search",
|
|
@@ -127,24 +127,24 @@ const localWorkspaceActions = [
|
|
|
127
127
|
"mkdir",
|
|
128
128
|
"delete",
|
|
129
129
|
];
|
|
130
|
-
const
|
|
130
|
+
const mutatingLocalWorkdirActions = new Set([
|
|
131
131
|
"apply_edits",
|
|
132
132
|
"write",
|
|
133
133
|
"mkdir",
|
|
134
134
|
"delete",
|
|
135
135
|
]);
|
|
136
|
-
const
|
|
137
|
-
"Inspect and modify the selected local
|
|
136
|
+
const localWorkdirToolDescription = [
|
|
137
|
+
"Inspect and modify the selected local workdir through one model-facing primitive.",
|
|
138
138
|
"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.",
|
|
139
139
|
"In approval mode, mutating actions return requires_approval with a safe preview instead of changing files. In full mode, mutating actions execute immediately.",
|
|
140
|
-
"Paths are relative to the selected local
|
|
140
|
+
"Paths are relative to the selected local workdir; never use absolute paths.",
|
|
141
141
|
].join(" ");
|
|
142
|
-
function
|
|
142
|
+
function localWorkdirToolParameters() {
|
|
143
143
|
return objectSchema({
|
|
144
144
|
action: {
|
|
145
145
|
type: "string",
|
|
146
|
-
enum:
|
|
147
|
-
description: "
|
|
146
|
+
enum: localWorkdirActions,
|
|
147
|
+
description: "Workdir operation. Prefer summarize/list/search/grep before reading or editing. Prefer read_lines and apply_edits for source changes.",
|
|
148
148
|
},
|
|
149
149
|
path: stringSchema("Relative path. File path for read/write/delete/edit actions; directory base for list/search/grep/summarize/context/snapshot."),
|
|
150
150
|
query: stringSchema("Path/name query for search, or optional context query."),
|
|
@@ -175,17 +175,17 @@ function localWorkspaceToolParameters() {
|
|
|
175
175
|
max_bytes_per_file: integerSchema("Maximum bytes per file."),
|
|
176
176
|
max_previews: integerSchema("Maximum summary previews."),
|
|
177
177
|
include_content: booleanSchema("Include file contents in context packages."),
|
|
178
|
-
include_summary: booleanSchema("Include
|
|
178
|
+
include_summary: booleanSchema("Include workdir summary in context packages."),
|
|
179
179
|
include_search: booleanSchema("Include grep results in context packages when query is set."),
|
|
180
180
|
include_secrets: booleanSchema("Include likely secret file contents in context packages."),
|
|
181
181
|
hash: booleanSchema("Include SHA-256 hashes in snapshots."),
|
|
182
182
|
}),
|
|
183
183
|
}, ["action"]);
|
|
184
184
|
}
|
|
185
|
-
function
|
|
185
|
+
function workdirAction(args) {
|
|
186
186
|
const value = stringArg(args, "action").trim().toLowerCase();
|
|
187
|
-
if (!
|
|
188
|
-
throw new Error(`unsupported
|
|
187
|
+
if (!localWorkdirActions.includes(value)) {
|
|
188
|
+
throw new Error(`unsupported local_workdir action: ${value}`);
|
|
189
189
|
}
|
|
190
190
|
return value;
|
|
191
191
|
}
|
|
@@ -352,7 +352,7 @@ function approvalRequired(action, args, preview) {
|
|
|
352
352
|
requires_approval: true,
|
|
353
353
|
arguments: args,
|
|
354
354
|
preview,
|
|
355
|
-
message: `
|
|
355
|
+
message: `local_workdir action ${action} requires approval`,
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
358
|
function objectSchema(properties, required = []) {
|
package/dist-cjs/node.js
CHANGED
|
@@ -14,17 +14,22 @@ 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.runLocalSkillHandlers = exports.pendingLocalSkillCalls = exports.localSkillFromDirectory = exports.
|
|
17
|
+
exports.runLocalSkillHandlers = exports.pendingLocalSkillCalls = exports.localSkillFromDirectory = exports.localWorkdirToolInstructions = exports.localWorkdirToolDefinition = exports.createLocalWorkdirToolRegistry = exports.localShellToolInstructions = exports.localShellToolDefinition = exports.LocalShellDriver = exports.HostLocalShellRunner = exports.LocalWorkdirDriver = exports.createLocalShellToolRegistry = exports.NodeSkillsResource = exports.NodeAgentAPI = void 0;
|
|
18
18
|
__exportStar(require("./index.js"), exports);
|
|
19
19
|
var node_client_js_1 = require("./node-client.js");
|
|
20
20
|
Object.defineProperty(exports, "NodeAgentAPI", { enumerable: true, get: function () { return node_client_js_1.NodeAgentAPI; } });
|
|
21
21
|
var skills_node_js_1 = require("./resources/skills-node.js");
|
|
22
22
|
Object.defineProperty(exports, "NodeSkillsResource", { enumerable: true, get: function () { return skills_node_js_1.NodeSkillsResource; } });
|
|
23
|
-
var
|
|
24
|
-
Object.defineProperty(exports, "
|
|
25
|
-
Object.defineProperty(exports, "
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
-
Object.defineProperty(exports, "
|
|
23
|
+
var index_js_1 = require("./local/index.js");
|
|
24
|
+
Object.defineProperty(exports, "createLocalShellToolRegistry", { enumerable: true, get: function () { return index_js_1.createLocalShellToolRegistry; } });
|
|
25
|
+
Object.defineProperty(exports, "LocalWorkdirDriver", { enumerable: true, get: function () { return index_js_1.LocalWorkdirDriver; } });
|
|
26
|
+
Object.defineProperty(exports, "HostLocalShellRunner", { enumerable: true, get: function () { return index_js_1.HostLocalShellRunner; } });
|
|
27
|
+
Object.defineProperty(exports, "LocalShellDriver", { enumerable: true, get: function () { return index_js_1.LocalShellDriver; } });
|
|
28
|
+
Object.defineProperty(exports, "localShellToolDefinition", { enumerable: true, get: function () { return index_js_1.localShellToolDefinition; } });
|
|
29
|
+
Object.defineProperty(exports, "localShellToolInstructions", { enumerable: true, get: function () { return index_js_1.localShellToolInstructions; } });
|
|
30
|
+
Object.defineProperty(exports, "createLocalWorkdirToolRegistry", { enumerable: true, get: function () { return index_js_1.createLocalWorkdirToolRegistry; } });
|
|
31
|
+
Object.defineProperty(exports, "localWorkdirToolDefinition", { enumerable: true, get: function () { return index_js_1.localWorkdirToolDefinition; } });
|
|
32
|
+
Object.defineProperty(exports, "localWorkdirToolInstructions", { enumerable: true, get: function () { return index_js_1.localWorkdirToolInstructions; } });
|
|
28
33
|
var local_skills_js_1 = require("./local-skills.js");
|
|
29
34
|
Object.defineProperty(exports, "localSkillFromDirectory", { enumerable: true, get: function () { return local_skills_js_1.localSkillFromDirectory; } });
|
|
30
35
|
Object.defineProperty(exports, "pendingLocalSkillCalls", { enumerable: true, get: function () { return local_skills_js_1.pendingLocalSkillCalls; } });
|
package/dist-cjs/version.js
CHANGED