@shareai-lab/kode-sdk 2.7.0 → 2.7.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.
Files changed (96) hide show
  1. package/dist/index.js +60461 -148
  2. package/dist/index.js.map +7 -0
  3. package/dist/index.mjs +60385 -0
  4. package/dist/index.mjs.map +7 -0
  5. package/package.json +38 -7
  6. package/dist/core/agent/breakpoint-manager.js +0 -36
  7. package/dist/core/agent/message-queue.js +0 -57
  8. package/dist/core/agent/permission-manager.js +0 -32
  9. package/dist/core/agent/todo-manager.js +0 -91
  10. package/dist/core/agent/tool-runner.js +0 -45
  11. package/dist/core/agent.js +0 -2039
  12. package/dist/core/config.js +0 -2
  13. package/dist/core/context-manager.js +0 -241
  14. package/dist/core/errors.js +0 -49
  15. package/dist/core/events.js +0 -329
  16. package/dist/core/file-pool.js +0 -102
  17. package/dist/core/hooks.js +0 -71
  18. package/dist/core/permission-modes.js +0 -61
  19. package/dist/core/pool.js +0 -301
  20. package/dist/core/room.js +0 -57
  21. package/dist/core/scheduler.js +0 -58
  22. package/dist/core/skills/index.js +0 -20
  23. package/dist/core/skills/management-manager.js +0 -557
  24. package/dist/core/skills/manager.js +0 -243
  25. package/dist/core/skills/operation-queue.js +0 -113
  26. package/dist/core/skills/sandbox-file-manager.js +0 -183
  27. package/dist/core/skills/types.js +0 -9
  28. package/dist/core/skills/xml-generator.js +0 -70
  29. package/dist/core/template.js +0 -35
  30. package/dist/core/time-bridge.js +0 -100
  31. package/dist/core/todo.js +0 -89
  32. package/dist/core/types.js +0 -3
  33. package/dist/infra/db/postgres/postgres-store.js +0 -1073
  34. package/dist/infra/db/sqlite/sqlite-store.js +0 -800
  35. package/dist/infra/e2b/e2b-fs.js +0 -128
  36. package/dist/infra/e2b/e2b-sandbox.js +0 -156
  37. package/dist/infra/e2b/e2b-template.js +0 -105
  38. package/dist/infra/e2b/index.js +0 -9
  39. package/dist/infra/e2b/types.js +0 -2
  40. package/dist/infra/provider.js +0 -67
  41. package/dist/infra/providers/anthropic.js +0 -308
  42. package/dist/infra/providers/core/errors.js +0 -353
  43. package/dist/infra/providers/core/fork.js +0 -418
  44. package/dist/infra/providers/core/index.js +0 -76
  45. package/dist/infra/providers/core/logger.js +0 -191
  46. package/dist/infra/providers/core/retry.js +0 -189
  47. package/dist/infra/providers/core/usage.js +0 -376
  48. package/dist/infra/providers/gemini.js +0 -493
  49. package/dist/infra/providers/index.js +0 -83
  50. package/dist/infra/providers/openai.js +0 -662
  51. package/dist/infra/providers/types.js +0 -20
  52. package/dist/infra/providers/utils.js +0 -400
  53. package/dist/infra/sandbox-factory.js +0 -30
  54. package/dist/infra/sandbox.js +0 -243
  55. package/dist/infra/store/factory.js +0 -80
  56. package/dist/infra/store/index.js +0 -26
  57. package/dist/infra/store/json-store.js +0 -606
  58. package/dist/infra/store/types.js +0 -2
  59. package/dist/infra/store.js +0 -29
  60. package/dist/tools/bash_kill/index.js +0 -35
  61. package/dist/tools/bash_kill/prompt.js +0 -14
  62. package/dist/tools/bash_logs/index.js +0 -40
  63. package/dist/tools/bash_logs/prompt.js +0 -14
  64. package/dist/tools/bash_run/index.js +0 -61
  65. package/dist/tools/bash_run/prompt.js +0 -18
  66. package/dist/tools/builtin.js +0 -26
  67. package/dist/tools/define.js +0 -214
  68. package/dist/tools/fs_edit/index.js +0 -62
  69. package/dist/tools/fs_edit/prompt.js +0 -15
  70. package/dist/tools/fs_glob/index.js +0 -40
  71. package/dist/tools/fs_glob/prompt.js +0 -15
  72. package/dist/tools/fs_grep/index.js +0 -66
  73. package/dist/tools/fs_grep/prompt.js +0 -16
  74. package/dist/tools/fs_multi_edit/index.js +0 -106
  75. package/dist/tools/fs_multi_edit/prompt.js +0 -16
  76. package/dist/tools/fs_read/index.js +0 -40
  77. package/dist/tools/fs_read/prompt.js +0 -16
  78. package/dist/tools/fs_write/index.js +0 -40
  79. package/dist/tools/fs_write/prompt.js +0 -15
  80. package/dist/tools/index.js +0 -61
  81. package/dist/tools/mcp.js +0 -185
  82. package/dist/tools/registry.js +0 -26
  83. package/dist/tools/scripts.js +0 -205
  84. package/dist/tools/skills.js +0 -115
  85. package/dist/tools/task_run/index.js +0 -58
  86. package/dist/tools/task_run/prompt.js +0 -25
  87. package/dist/tools/todo_read/index.js +0 -29
  88. package/dist/tools/todo_read/prompt.js +0 -18
  89. package/dist/tools/todo_write/index.js +0 -42
  90. package/dist/tools/todo_write/prompt.js +0 -23
  91. package/dist/tools/tool.js +0 -211
  92. package/dist/tools/toolkit.js +0 -98
  93. package/dist/tools/type-inference.js +0 -207
  94. package/dist/utils/agent-id.js +0 -28
  95. package/dist/utils/logger.js +0 -44
  96. package/dist/utils/session-id.js +0 -64
package/package.json CHANGED
@@ -1,14 +1,24 @@
1
1
  {
2
2
  "name": "@shareai-lab/kode-sdk",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "Event-driven, long-running AI Agent development framework with enterprise-grade persistence and context management",
5
5
  "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
7
15
  "scripts": {
8
- "build": "tsc",
16
+ "build": "node scripts/build.mjs",
17
+ "build:types": "tsc --emitDeclarationOnly --declaration --outDir dist",
18
+ "build:legacy": "tsc",
9
19
  "dev": "tsc --watch",
10
20
  "clean": "rm -rf dist",
11
- "prepare": "npm run build",
21
+ "prepublishOnly": "npm run clean && npm run build",
12
22
  "test": "npm run test:unit",
13
23
  "test:unit": "ts-node --project tsconfig.json ./tests/run-unit.ts",
14
24
  "test:integration": "ts-node --project tsconfig.json ./tests/run-integration.ts",
@@ -42,22 +52,43 @@
42
52
  "author": "",
43
53
  "license": "MIT",
44
54
  "dependencies": {
45
- "@modelcontextprotocol/sdk": "~1.22.0",
46
55
  "ajv": "^8.17.1",
47
- "better-sqlite3": "^12.6.2",
48
56
  "dotenv": "^16.4.5",
49
- "e2b": "^2.10.3",
50
57
  "fast-glob": "^3.3.2",
51
- "pg": "^8.17.2",
52
58
  "undici": "^7.18.2",
53
59
  "zod": "~3.23.8",
54
60
  "zod-to-json-schema": "~3.23.0"
55
61
  },
62
+ "peerDependencies": {
63
+ "better-sqlite3": "^12.0.0",
64
+ "pg": "^8.0.0",
65
+ "e2b": "^2.0.0",
66
+ "@modelcontextprotocol/sdk": "^1.0.0"
67
+ },
68
+ "peerDependenciesMeta": {
69
+ "better-sqlite3": {
70
+ "optional": true
71
+ },
72
+ "pg": {
73
+ "optional": true
74
+ },
75
+ "e2b": {
76
+ "optional": true
77
+ },
78
+ "@modelcontextprotocol/sdk": {
79
+ "optional": true
80
+ }
81
+ },
56
82
  "devDependencies": {
57
83
  "@shareai-lab/kode-sdk": "file:.",
84
+ "@modelcontextprotocol/sdk": "~1.22.0",
58
85
  "@types/better-sqlite3": "^7.6.13",
59
86
  "@types/node": "^20.0.0",
60
87
  "@types/pg": "^8.16.0",
88
+ "better-sqlite3": "^12.6.2",
89
+ "e2b": "^2.10.3",
90
+ "esbuild": "^0.27.2",
91
+ "pg": "^8.17.2",
61
92
  "ts-node": "^10.9.0",
62
93
  "typescript": "^5.3.0"
63
94
  },
@@ -1,36 +0,0 @@
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;
@@ -1,57 +0,0 @@
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;
@@ -1,32 +0,0 @@
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;
@@ -1,91 +0,0 @@
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;
@@ -1,45 +0,0 @@
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;