@shareai-lab/kode-sdk 2.7.1 → 2.7.2
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/core/agent/breakpoint-manager.js +36 -0
- package/dist/core/agent/message-queue.js +57 -0
- package/dist/core/agent/permission-manager.js +32 -0
- package/dist/core/agent/todo-manager.js +91 -0
- package/dist/core/agent/tool-runner.js +45 -0
- package/dist/core/agent.js +2035 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.js +241 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/events.js +329 -0
- package/dist/core/file-pool.d.ts +2 -0
- package/dist/core/file-pool.js +125 -0
- package/dist/core/hooks.js +71 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.js +301 -0
- package/dist/core/room.js +57 -0
- package/dist/core/scheduler.js +58 -0
- package/dist/core/skills/index.js +20 -0
- package/dist/core/skills/management-manager.js +557 -0
- package/dist/core/skills/manager.js +243 -0
- package/dist/core/skills/operation-queue.js +113 -0
- package/dist/core/skills/sandbox-file-manager.js +183 -0
- package/dist/core/skills/types.js +9 -0
- package/dist/core/skills/xml-generator.js +70 -0
- package/dist/core/template.js +35 -0
- package/dist/core/time-bridge.js +100 -0
- package/dist/core/todo.js +89 -0
- package/dist/core/types.js +3 -0
- package/dist/index.js +148 -60461
- package/dist/infra/db/postgres/postgres-store.js +1073 -0
- package/dist/infra/db/sqlite/sqlite-store.js +800 -0
- package/dist/infra/e2b/e2b-fs.js +128 -0
- package/dist/infra/e2b/e2b-sandbox.js +156 -0
- package/dist/infra/e2b/e2b-template.js +105 -0
- package/dist/infra/e2b/index.js +9 -0
- package/dist/infra/e2b/types.js +2 -0
- package/dist/infra/provider.js +67 -0
- package/dist/infra/providers/anthropic.js +308 -0
- package/dist/infra/providers/core/errors.js +353 -0
- package/dist/infra/providers/core/fork.js +418 -0
- package/dist/infra/providers/core/index.js +76 -0
- package/dist/infra/providers/core/logger.js +191 -0
- package/dist/infra/providers/core/retry.js +189 -0
- package/dist/infra/providers/core/usage.js +376 -0
- package/dist/infra/providers/gemini.js +493 -0
- package/dist/infra/providers/index.js +83 -0
- package/dist/infra/providers/openai.js +662 -0
- package/dist/infra/providers/types.js +20 -0
- package/dist/infra/providers/utils.js +400 -0
- package/dist/infra/sandbox-factory.js +30 -0
- package/dist/infra/sandbox.js +243 -0
- package/dist/infra/store/factory.js +80 -0
- package/dist/infra/store/index.js +26 -0
- package/dist/infra/store/json-store.js +606 -0
- package/dist/infra/store/types.js +2 -0
- package/dist/infra/store.js +29 -0
- package/dist/tools/bash_kill/index.js +35 -0
- package/dist/tools/bash_kill/prompt.js +14 -0
- package/dist/tools/bash_logs/index.js +40 -0
- package/dist/tools/bash_logs/prompt.js +14 -0
- package/dist/tools/bash_run/index.js +61 -0
- package/dist/tools/bash_run/prompt.js +18 -0
- package/dist/tools/builtin.js +26 -0
- package/dist/tools/define.js +214 -0
- package/dist/tools/fs_edit/index.js +62 -0
- package/dist/tools/fs_edit/prompt.js +15 -0
- package/dist/tools/fs_glob/index.js +40 -0
- package/dist/tools/fs_glob/prompt.js +15 -0
- package/dist/tools/fs_grep/index.js +66 -0
- package/dist/tools/fs_grep/prompt.js +16 -0
- package/dist/tools/fs_multi_edit/index.js +106 -0
- package/dist/tools/fs_multi_edit/prompt.js +16 -0
- package/dist/tools/fs_read/index.js +40 -0
- package/dist/tools/fs_read/prompt.js +16 -0
- package/dist/tools/fs_write/index.js +40 -0
- package/dist/tools/fs_write/prompt.js +15 -0
- package/dist/tools/index.js +61 -0
- package/dist/tools/mcp.js +185 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/scripts.js +205 -0
- package/dist/tools/skills.js +115 -0
- package/dist/tools/task_run/index.js +58 -0
- package/dist/tools/task_run/prompt.js +25 -0
- package/dist/tools/todo_read/index.js +29 -0
- package/dist/tools/todo_read/prompt.js +18 -0
- package/dist/tools/todo_write/index.js +42 -0
- package/dist/tools/todo_write/prompt.js +23 -0
- package/dist/tools/tool.js +211 -0
- package/dist/tools/toolkit.js +98 -0
- package/dist/tools/type-inference.js +207 -0
- package/dist/utils/agent-id.js +28 -0
- package/dist/utils/logger.js +44 -0
- package/dist/utils/session-id.js +64 -0
- package/package.json +7 -38
- package/dist/index.js.map +0 -7
- package/dist/index.mjs +0 -60385
- package/dist/index.mjs.map +0 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BreakpointManager = void 0;
|
|
4
|
+
class BreakpointManager {
|
|
5
|
+
constructor(onChange) {
|
|
6
|
+
this.onChange = onChange;
|
|
7
|
+
this.current = 'READY';
|
|
8
|
+
this.history = [];
|
|
9
|
+
}
|
|
10
|
+
getCurrent() {
|
|
11
|
+
return this.current;
|
|
12
|
+
}
|
|
13
|
+
getHistory() {
|
|
14
|
+
return this.history;
|
|
15
|
+
}
|
|
16
|
+
set(state, note) {
|
|
17
|
+
if (this.current === state)
|
|
18
|
+
return;
|
|
19
|
+
const entry = {
|
|
20
|
+
state,
|
|
21
|
+
timestamp: Date.now(),
|
|
22
|
+
note,
|
|
23
|
+
};
|
|
24
|
+
const previous = this.current;
|
|
25
|
+
this.current = state;
|
|
26
|
+
this.history.push(entry);
|
|
27
|
+
if (this.onChange) {
|
|
28
|
+
this.onChange(previous, state, entry);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
reset(state = 'READY') {
|
|
32
|
+
this.current = state;
|
|
33
|
+
this.history = [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BreakpointManager = BreakpointManager;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageQueue = void 0;
|
|
4
|
+
const logger_1 = require("../../utils/logger");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
class MessageQueue {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.pending = [];
|
|
10
|
+
}
|
|
11
|
+
send(content, opts = {}) {
|
|
12
|
+
const kind = opts.kind ?? 'user';
|
|
13
|
+
const isText = typeof content === 'string';
|
|
14
|
+
if (kind === 'reminder' && !isText) {
|
|
15
|
+
throw new errors_1.MultimodalValidationError('Reminder messages must be plain text.');
|
|
16
|
+
}
|
|
17
|
+
const payload = isText
|
|
18
|
+
? kind === 'reminder'
|
|
19
|
+
? this.options.wrapReminder(content, opts.reminder)
|
|
20
|
+
: content
|
|
21
|
+
: content;
|
|
22
|
+
const id = `msg-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
23
|
+
this.pending.push({
|
|
24
|
+
message: {
|
|
25
|
+
role: 'user',
|
|
26
|
+
content: isText ? [{ type: 'text', text: payload }] : payload,
|
|
27
|
+
},
|
|
28
|
+
kind,
|
|
29
|
+
metadata: { id, ...(opts.metadata || {}) },
|
|
30
|
+
});
|
|
31
|
+
if (kind === 'user') {
|
|
32
|
+
this.options.ensureProcessing();
|
|
33
|
+
}
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
async flush() {
|
|
37
|
+
if (this.pending.length === 0)
|
|
38
|
+
return;
|
|
39
|
+
const queue = this.pending;
|
|
40
|
+
try {
|
|
41
|
+
// 先添加到消息历史
|
|
42
|
+
for (const entry of queue) {
|
|
43
|
+
this.options.addMessage(entry.message, entry.kind);
|
|
44
|
+
}
|
|
45
|
+
// 持久化成功后才清空队列
|
|
46
|
+
await this.options.persist();
|
|
47
|
+
// 成功:从队列中移除已处理的消息
|
|
48
|
+
this.pending = this.pending.filter(item => !queue.includes(item));
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
// 失败:保留队列,下次重试
|
|
52
|
+
logger_1.logger.error('[MessageQueue] Flush failed, messages retained:', err);
|
|
53
|
+
throw err; // 重新抛出让调用者知道失败
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.MessageQueue = MessageQueue;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PermissionManager = void 0;
|
|
4
|
+
const permission_modes_1 = require("../permission-modes");
|
|
5
|
+
class PermissionManager {
|
|
6
|
+
constructor(config, descriptors) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.descriptors = descriptors;
|
|
9
|
+
}
|
|
10
|
+
evaluate(toolName) {
|
|
11
|
+
if (this.config.denyTools?.includes(toolName)) {
|
|
12
|
+
return 'deny';
|
|
13
|
+
}
|
|
14
|
+
if (this.config.allowTools && this.config.allowTools.length > 0 && !this.config.allowTools.includes(toolName)) {
|
|
15
|
+
return 'deny';
|
|
16
|
+
}
|
|
17
|
+
if (this.config.requireApprovalTools?.includes(toolName)) {
|
|
18
|
+
return 'ask';
|
|
19
|
+
}
|
|
20
|
+
const handler = permission_modes_1.permissionModes.get(this.config.mode || 'auto') || permission_modes_1.permissionModes.get('auto');
|
|
21
|
+
if (!handler) {
|
|
22
|
+
return 'allow';
|
|
23
|
+
}
|
|
24
|
+
const context = {
|
|
25
|
+
toolName,
|
|
26
|
+
descriptor: this.descriptors.get(toolName),
|
|
27
|
+
config: this.config,
|
|
28
|
+
};
|
|
29
|
+
return handler(context);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.PermissionManager = PermissionManager;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoManager = void 0;
|
|
4
|
+
class TodoManager {
|
|
5
|
+
constructor(opts) {
|
|
6
|
+
this.opts = opts;
|
|
7
|
+
this.stepsSinceReminder = 0;
|
|
8
|
+
}
|
|
9
|
+
get enabled() {
|
|
10
|
+
return !!this.opts.service && !!this.opts.config?.enabled;
|
|
11
|
+
}
|
|
12
|
+
list() {
|
|
13
|
+
return this.opts.service ? this.opts.service.list() : [];
|
|
14
|
+
}
|
|
15
|
+
async setTodos(todos) {
|
|
16
|
+
if (!this.opts.service)
|
|
17
|
+
throw new Error('Todo service not enabled for this agent');
|
|
18
|
+
const prev = this.opts.service.list();
|
|
19
|
+
await this.opts.service.setTodos(todos);
|
|
20
|
+
this.publishChange(prev, this.opts.service.list());
|
|
21
|
+
}
|
|
22
|
+
async update(todo) {
|
|
23
|
+
if (!this.opts.service)
|
|
24
|
+
throw new Error('Todo service not enabled for this agent');
|
|
25
|
+
const prev = this.opts.service.list();
|
|
26
|
+
await this.opts.service.update(todo);
|
|
27
|
+
this.publishChange(prev, this.opts.service.list());
|
|
28
|
+
}
|
|
29
|
+
async remove(id) {
|
|
30
|
+
if (!this.opts.service)
|
|
31
|
+
throw new Error('Todo service not enabled for this agent');
|
|
32
|
+
const prev = this.opts.service.list();
|
|
33
|
+
await this.opts.service.delete(id);
|
|
34
|
+
this.publishChange(prev, this.opts.service.list());
|
|
35
|
+
}
|
|
36
|
+
handleStartup() {
|
|
37
|
+
if (!this.enabled || !this.opts.config?.reminderOnStart)
|
|
38
|
+
return;
|
|
39
|
+
const todos = this.list().filter((todo) => todo.status !== 'completed');
|
|
40
|
+
if (todos.length === 0) {
|
|
41
|
+
this.sendEmptyReminder();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.sendReminder(todos, 'startup');
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
onStep() {
|
|
48
|
+
if (!this.enabled)
|
|
49
|
+
return;
|
|
50
|
+
if (!this.opts.config?.remindIntervalSteps)
|
|
51
|
+
return;
|
|
52
|
+
if (this.opts.config.remindIntervalSteps <= 0)
|
|
53
|
+
return;
|
|
54
|
+
this.stepsSinceReminder += 1;
|
|
55
|
+
if (this.stepsSinceReminder < this.opts.config.remindIntervalSteps)
|
|
56
|
+
return;
|
|
57
|
+
const todos = this.list().filter((todo) => todo.status !== 'completed');
|
|
58
|
+
if (todos.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
this.sendReminder(todos, 'interval');
|
|
61
|
+
}
|
|
62
|
+
publishChange(previous, current) {
|
|
63
|
+
if (!this.opts.events)
|
|
64
|
+
return;
|
|
65
|
+
this.stepsSinceReminder = 0;
|
|
66
|
+
this.opts.events.emitMonitor({ channel: 'monitor', type: 'todo_changed', previous, current });
|
|
67
|
+
if (current.length === 0) {
|
|
68
|
+
this.sendEmptyReminder();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
sendReminder(todos, reason) {
|
|
72
|
+
this.stepsSinceReminder = 0;
|
|
73
|
+
this.opts.events.emitMonitor({ channel: 'monitor', type: 'todo_reminder', todos, reason });
|
|
74
|
+
this.opts.remind(this.formatTodoReminder(todos), { category: 'todo', priority: 'medium' });
|
|
75
|
+
}
|
|
76
|
+
sendEmptyReminder() {
|
|
77
|
+
this.opts.remind('当前 todo 列表为空,如需跟踪任务请使用 todo_write 建立清单。', {
|
|
78
|
+
category: 'todo',
|
|
79
|
+
priority: 'low',
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
formatTodoReminder(todos) {
|
|
83
|
+
const bulletList = todos
|
|
84
|
+
.slice(0, 10)
|
|
85
|
+
.map((todo, index) => `${index + 1}. [${todo.status}] ${todo.title}`)
|
|
86
|
+
.join('\n');
|
|
87
|
+
const more = todos.length > 10 ? `\n… 还有 ${todos.length - 10} 项` : '';
|
|
88
|
+
return `Todo 列表仍有未完成项:\n${bulletList}${more}\n请结合 todo_write 及时更新进度,不要向用户直接提及本提醒。`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.TodoManager = TodoManager;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ToolRunner = void 0;
|
|
4
|
+
class ToolRunner {
|
|
5
|
+
constructor(concurrency) {
|
|
6
|
+
this.concurrency = concurrency;
|
|
7
|
+
this.active = 0;
|
|
8
|
+
this.queue = [];
|
|
9
|
+
if (!Number.isFinite(concurrency) || concurrency <= 0) {
|
|
10
|
+
throw new Error('ToolRunner requires a positive concurrency limit');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
run(task) {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
const execute = () => {
|
|
16
|
+
this.active += 1;
|
|
17
|
+
task()
|
|
18
|
+
.then(resolve, reject)
|
|
19
|
+
.finally(() => {
|
|
20
|
+
this.active -= 1;
|
|
21
|
+
this.flush();
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
if (this.active < this.concurrency) {
|
|
25
|
+
execute();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this.queue.push(execute);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
clear() {
|
|
33
|
+
this.queue.length = 0;
|
|
34
|
+
}
|
|
35
|
+
flush() {
|
|
36
|
+
if (this.queue.length === 0)
|
|
37
|
+
return;
|
|
38
|
+
if (this.active >= this.concurrency)
|
|
39
|
+
return;
|
|
40
|
+
const next = this.queue.shift();
|
|
41
|
+
if (next)
|
|
42
|
+
next();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.ToolRunner = ToolRunner;
|