@shareai-lab/kode-sdk 1.0.0-beta.8 → 1.0.0-beta.9
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/dist/tools/builtin.js +4 -4
- package/dist/tools/fs.d.ts +6 -6
- package/dist/tools/fs.js +15 -15
- package/package.json +2 -2
package/dist/tools/builtin.js
CHANGED
|
@@ -11,10 +11,10 @@ exports.builtin = {
|
|
|
11
11
|
return (0, fs_1.toolTune)(tool, {
|
|
12
12
|
preToolUse(call, ctx) {
|
|
13
13
|
// 确保 call.args 是对象
|
|
14
|
-
if (call.args && typeof call.args === 'object' && '
|
|
15
|
-
call.args.
|
|
16
|
-
if (!ctx.sandbox.fs.isInside(call.args.
|
|
17
|
-
return { decision: 'deny', reason: `Path outside sandbox: ${call.args.
|
|
14
|
+
if (call.args && typeof call.args === 'object' && 'path' in call.args) {
|
|
15
|
+
call.args.path = ctx.sandbox.fs.resolve(call.args.path);
|
|
16
|
+
if (!ctx.sandbox.fs.isInside(call.args.path)) {
|
|
17
|
+
return { decision: 'deny', reason: `Path outside sandbox: ${call.args.path}` };
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
},
|
package/dist/tools/fs.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare class FsRead implements Tool {
|
|
|
14
14
|
input_schema: {
|
|
15
15
|
type: string;
|
|
16
16
|
properties: {
|
|
17
|
-
|
|
17
|
+
path: {
|
|
18
18
|
type: string;
|
|
19
19
|
description: string;
|
|
20
20
|
};
|
|
@@ -30,7 +30,7 @@ export declare class FsRead implements Tool {
|
|
|
30
30
|
required: string[];
|
|
31
31
|
};
|
|
32
32
|
exec(args: {
|
|
33
|
-
|
|
33
|
+
path: string;
|
|
34
34
|
offset?: number;
|
|
35
35
|
limit?: number;
|
|
36
36
|
}, ctx: ToolContext): Promise<any>;
|
|
@@ -41,7 +41,7 @@ export declare class FsWrite implements Tool {
|
|
|
41
41
|
input_schema: {
|
|
42
42
|
type: string;
|
|
43
43
|
properties: {
|
|
44
|
-
|
|
44
|
+
path: {
|
|
45
45
|
type: string;
|
|
46
46
|
description: string;
|
|
47
47
|
};
|
|
@@ -53,7 +53,7 @@ export declare class FsWrite implements Tool {
|
|
|
53
53
|
required: string[];
|
|
54
54
|
};
|
|
55
55
|
exec(args: {
|
|
56
|
-
|
|
56
|
+
path: string;
|
|
57
57
|
content: string;
|
|
58
58
|
}, ctx: ToolContext): Promise<any>;
|
|
59
59
|
}
|
|
@@ -63,7 +63,7 @@ export declare class FsEdit implements Tool {
|
|
|
63
63
|
input_schema: {
|
|
64
64
|
type: string;
|
|
65
65
|
properties: {
|
|
66
|
-
|
|
66
|
+
path: {
|
|
67
67
|
type: string;
|
|
68
68
|
description: string;
|
|
69
69
|
};
|
|
@@ -83,7 +83,7 @@ export declare class FsEdit implements Tool {
|
|
|
83
83
|
required: string[];
|
|
84
84
|
};
|
|
85
85
|
exec(args: {
|
|
86
|
-
|
|
86
|
+
path: string;
|
|
87
87
|
old_string: string;
|
|
88
88
|
new_string: string;
|
|
89
89
|
replace_all?: boolean;
|
package/dist/tools/fs.js
CHANGED
|
@@ -9,15 +9,15 @@ class FsRead {
|
|
|
9
9
|
this.input_schema = {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {
|
|
12
|
-
|
|
12
|
+
path: { type: 'string', description: 'Path to file' },
|
|
13
13
|
offset: { type: 'number', description: 'Line offset (optional)' },
|
|
14
14
|
limit: { type: 'number', description: 'Max lines to read (optional)' },
|
|
15
15
|
},
|
|
16
|
-
required: ['
|
|
16
|
+
required: ['path'],
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
async exec(args, ctx) {
|
|
20
|
-
const content = await ctx.sandbox.fs.read(args.
|
|
20
|
+
const content = await ctx.sandbox.fs.read(args.path);
|
|
21
21
|
const lines = content.split('\n');
|
|
22
22
|
const offset = args.offset || 0;
|
|
23
23
|
const limit = args.limit || lines.length;
|
|
@@ -33,16 +33,16 @@ class FsWrite {
|
|
|
33
33
|
this.input_schema = {
|
|
34
34
|
type: 'object',
|
|
35
35
|
properties: {
|
|
36
|
-
|
|
36
|
+
path: { type: 'string', description: 'Path to file' },
|
|
37
37
|
content: { type: 'string', description: 'Content to write' },
|
|
38
38
|
},
|
|
39
|
-
required: ['
|
|
39
|
+
required: ['path', 'content'],
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
async exec(args, ctx) {
|
|
43
|
-
await ctx.sandbox.fs.write(args.
|
|
43
|
+
await ctx.sandbox.fs.write(args.path, args.content);
|
|
44
44
|
const bytes = Buffer.byteLength(args.content, 'utf8');
|
|
45
|
-
return `Wrote ${bytes} bytes to ${args.
|
|
45
|
+
return `Wrote ${bytes} bytes to ${args.path}`;
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
exports.FsWrite = FsWrite;
|
|
@@ -53,33 +53,33 @@ class FsEdit {
|
|
|
53
53
|
this.input_schema = {
|
|
54
54
|
type: 'object',
|
|
55
55
|
properties: {
|
|
56
|
-
|
|
56
|
+
path: { type: 'string', description: 'Path to file' },
|
|
57
57
|
old_string: { type: 'string', description: 'String to replace' },
|
|
58
58
|
new_string: { type: 'string', description: 'Replacement string' },
|
|
59
59
|
replace_all: { type: 'boolean', description: 'Replace all occurrences (default: false)' },
|
|
60
60
|
},
|
|
61
|
-
required: ['
|
|
61
|
+
required: ['path', 'old_string', 'new_string'],
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
async exec(args, ctx) {
|
|
65
|
-
const content = await ctx.sandbox.fs.read(args.
|
|
65
|
+
const content = await ctx.sandbox.fs.read(args.path);
|
|
66
66
|
if (args.replace_all) {
|
|
67
67
|
const updated = content.split(args.old_string).join(args.new_string);
|
|
68
|
-
await ctx.sandbox.fs.write(args.
|
|
68
|
+
await ctx.sandbox.fs.write(args.path, updated);
|
|
69
69
|
const count = content.split(args.old_string).length - 1;
|
|
70
|
-
return `Replaced ${count} occurrence(s) in ${args.
|
|
70
|
+
return `Replaced ${count} occurrence(s) in ${args.path}`;
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
const occurrences = content.split(args.old_string).length - 1;
|
|
74
74
|
if (occurrences === 0) {
|
|
75
|
-
throw new Error(`old_string not found in ${args.
|
|
75
|
+
throw new Error(`old_string not found in ${args.path}`);
|
|
76
76
|
}
|
|
77
77
|
if (occurrences > 1) {
|
|
78
78
|
throw new Error(`old_string appears ${occurrences} times; use replace_all=true or provide unique string`);
|
|
79
79
|
}
|
|
80
80
|
const updated = content.replace(args.old_string, args.new_string);
|
|
81
|
-
await ctx.sandbox.fs.write(args.
|
|
82
|
-
return `Replaced 1 occurrence in ${args.
|
|
81
|
+
await ctx.sandbox.fs.write(args.path, updated);
|
|
82
|
+
return `Replaced 1 occurrence in ${args.path}`;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shareai-lab/kode-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.9",
|
|
4
4
|
"description": "Event-driven Agent Model Client SDK for building long-running, collaborative AI agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@shareai-lab/kode-sdk": "^1.0.0-beta.
|
|
35
|
+
"@shareai-lab/kode-sdk": "^1.0.0-beta.9",
|
|
36
36
|
"@types/node": "^20.0.0",
|
|
37
37
|
"ts-node": "^10.9.0",
|
|
38
38
|
"typescript": "^5.3.0"
|