xiaozuoassistant 0.1.82 → 0.1.84
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/README.md +3 -3
- package/dist/client/assets/{browser-ponyfill-DG-Mloyd.js → browser-ponyfill-CSWz9c5m.js} +1 -1
- package/dist/client/assets/index-Be5IGwUA.css +1 -0
- package/dist/client/assets/{index-Cpq9njn6.js → index-CHqwpkIC.js} +15 -15
- package/dist/client/index.html +2 -2
- package/dist/server/agents/office.js +3 -3
- package/dist/server/core/memories/structured.js +65 -76
- package/dist/server/core/plugin-manager.js +30 -14
- package/dist/server/index.js +42 -43
- package/dist/server/{skills → plugins/core-skills/src}/create-agent.js +13 -9
- package/dist/server/{skills → plugins/core-skills/src}/delegate.js +9 -5
- package/dist/server/{skills → plugins/core-skills/src}/file-system.js +33 -23
- package/dist/server/plugins/core-skills/src/index.js +28 -0
- package/dist/server/{skills → plugins/core-skills/src}/list-agents.js +8 -4
- package/dist/server/{skills → plugins/core-skills/src}/search.js +6 -2
- package/dist/server/{skills → plugins/core-skills/src}/system-time.js +6 -2
- package/dist/server/plugins/office-skills/src/index.js +21 -0
- package/dist/server/{skills → plugins/office-skills/src}/office-excel.js +20 -12
- package/dist/server/{skills → plugins/office-skills/src}/office-ppt.js +11 -4
- package/dist/server/{skills → plugins/office-skills/src}/office-word.js +18 -10
- package/package.json +1 -1
- package/dist/client/assets/index-BBXxfEv9.css +0 -1
package/dist/client/index.html
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🍇</text></svg>" />
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<title>xiaozuoAssistant</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-CHqwpkIC.js"></script>
|
|
9
|
+
<link rel="stylesheet" crossorigin href="/assets/index-Be5IGwUA.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<div id="root"></div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentRuntime } from '../core/agents/runtime.js';
|
|
2
|
-
import { ReadWordSkill, CreateWordSkill } from '../skills/office-word.js';
|
|
3
|
-
import { ReadExcelSkill, CreateExcelSkill } from '../skills/office-excel.js';
|
|
4
|
-
import { CreatePptxSkill } from '../skills/office-ppt.js';
|
|
2
|
+
import { ReadWordSkill, CreateWordSkill } from '../plugins/office-skills/src/office-word.js';
|
|
3
|
+
import { ReadExcelSkill, CreateExcelSkill } from '../plugins/office-skills/src/office-excel.js';
|
|
4
|
+
import { CreatePptxSkill } from '../plugins/office-skills/src/office-ppt.js';
|
|
5
5
|
export const createOfficeAgent = () => {
|
|
6
6
|
return new AgentRuntime({
|
|
7
7
|
name: 'office_agent',
|
|
@@ -30,17 +30,18 @@ export class StructuredMemory {
|
|
|
30
30
|
)
|
|
31
31
|
`).run();
|
|
32
32
|
// User Profile: specialized facts (multi-user)
|
|
33
|
+
// V3: Simplified profile (name, email only)
|
|
33
34
|
this.db.prepare(`
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
35
|
+
CREATE TABLE IF NOT EXISTS user_profile_v3 (
|
|
36
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
37
|
+
user_id TEXT NOT NULL,
|
|
38
|
+
name TEXT,
|
|
39
|
+
email TEXT,
|
|
40
|
+
updated_at INTEGER,
|
|
41
|
+
UNIQUE(user_id)
|
|
42
|
+
)
|
|
43
|
+
`).run();
|
|
44
|
+
this.migrateUserProfileV3();
|
|
44
45
|
// Graph nodes (Entities)
|
|
45
46
|
this.db.prepare(`
|
|
46
47
|
CREATE TABLE IF NOT EXISTS entities (
|
|
@@ -106,64 +107,43 @@ export class StructuredMemory {
|
|
|
106
107
|
throw error; // Rethrow to stop startup if DB is critical
|
|
107
108
|
}
|
|
108
109
|
}
|
|
109
|
-
|
|
110
|
+
migrateUserProfileV3() {
|
|
110
111
|
try {
|
|
111
|
-
const columns = this.db.prepare(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const names = cols.map(c => c?.name).filter(Boolean);
|
|
121
|
-
if (names.length === 2 && names.includes('user_id') && names.includes('key')) {
|
|
122
|
-
hasUniqueUserIdKey = true;
|
|
123
|
-
break;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
hasUniqueUserIdKey = false;
|
|
129
|
-
}
|
|
130
|
-
if (hasUserId && hasUniqueUserIdKey)
|
|
112
|
+
const columns = this.db.prepare('PRAGMA table_info(user_profile)').all();
|
|
113
|
+
// If old table doesn't exist, we are good (new install will use v3)
|
|
114
|
+
// But wait, we created v3 table above.
|
|
115
|
+
// We need to check if we need to migrate from v1/v2 to v3.
|
|
116
|
+
// Strategy:
|
|
117
|
+
// 1. Check if 'user_profile' table exists.
|
|
118
|
+
// 2. If it does, read data, transform, insert into v3, drop old table.
|
|
119
|
+
const tableExists = this.db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='user_profile'").get();
|
|
120
|
+
if (!tableExists)
|
|
131
121
|
return;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const ins = this.db.prepare('INSERT OR REPLACE INTO user_profile_v2 (user_id, key, value, updated_at) VALUES (?, ?, ?, ?)');
|
|
145
|
-
const tx = this.db.transaction(() => {
|
|
146
|
-
for (const row of rows) {
|
|
147
|
-
ins.run('default', row.key, row.value, row.updated_at ?? Date.now());
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
tx();
|
|
122
|
+
console.log('[StructuredMemory] Migrating user profile to V3...');
|
|
123
|
+
const rows = this.db.prepare('SELECT * FROM user_profile').all();
|
|
124
|
+
// Group by user_id
|
|
125
|
+
const users = {};
|
|
126
|
+
for (const row of rows) {
|
|
127
|
+
const uid = row.user_id || 'default';
|
|
128
|
+
if (!users[uid])
|
|
129
|
+
users[uid] = {};
|
|
130
|
+
if (row.key === 'name')
|
|
131
|
+
users[uid].name = row.value;
|
|
132
|
+
if (row.key === 'email')
|
|
133
|
+
users[uid].email = row.value;
|
|
151
134
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
this.db.prepare('DROP TABLE IF EXISTS user_profile').run();
|
|
163
|
-
this.db.prepare('ALTER TABLE user_profile_v2 RENAME TO user_profile').run();
|
|
135
|
+
const ins = this.db.prepare('INSERT OR REPLACE INTO user_profile_v3 (user_id, name, email, updated_at) VALUES (?, ?, ?, ?)');
|
|
136
|
+
const tx = this.db.transaction(() => {
|
|
137
|
+
for (const [uid, data] of Object.entries(users)) {
|
|
138
|
+
ins.run(uid, data.name || null, data.email || null, Date.now());
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
tx();
|
|
142
|
+
this.db.prepare('DROP TABLE user_profile').run();
|
|
143
|
+
this.db.prepare('DROP TABLE IF EXISTS user_profile_v2').run(); // Clean up intermediate v2 if any
|
|
164
144
|
}
|
|
165
|
-
catch {
|
|
166
|
-
|
|
145
|
+
catch (e) {
|
|
146
|
+
console.error('[StructuredMemory] Migration to V3 failed:', e);
|
|
167
147
|
}
|
|
168
148
|
}
|
|
169
149
|
addFact(category, key, value, source = 'user') {
|
|
@@ -180,20 +160,29 @@ export class StructuredMemory {
|
|
|
180
160
|
return this.db.prepare('SELECT * FROM facts').all();
|
|
181
161
|
}
|
|
182
162
|
updateUserProfile(userId, key, value) {
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
163
|
+
const uid = userId || 'default';
|
|
164
|
+
const now = Date.now();
|
|
165
|
+
// V3: Column based
|
|
166
|
+
if (key !== 'name' && key !== 'email') {
|
|
167
|
+
console.warn(`[StructuredMemory] Unknown profile key: ${key}`);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// Use dynamic SQL for specific column update
|
|
171
|
+
this.db.prepare(`
|
|
172
|
+
INSERT INTO user_profile_v3 (user_id, ${key}, updated_at)
|
|
173
|
+
VALUES (?, ?, ?)
|
|
174
|
+
ON CONFLICT(user_id) DO UPDATE SET ${key} = excluded.${key}, updated_at = excluded.updated_at
|
|
175
|
+
`).run(uid, value, now);
|
|
189
176
|
}
|
|
190
177
|
getUserProfile(userId) {
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
178
|
+
const row = this.db.prepare('SELECT * FROM user_profile_v3 WHERE user_id = ?').get(userId || 'default');
|
|
179
|
+
if (!row)
|
|
180
|
+
return {};
|
|
181
|
+
// Map back to object for compatibility
|
|
182
|
+
return {
|
|
183
|
+
name: row.name || '',
|
|
184
|
+
email: row.email || ''
|
|
185
|
+
};
|
|
197
186
|
}
|
|
198
187
|
// Simple Graph Operations
|
|
199
188
|
addEntity(name, type, metadata = {}) {
|
|
@@ -33,26 +33,42 @@ export class PluginManager {
|
|
|
33
33
|
}
|
|
34
34
|
async loadPlugins() {
|
|
35
35
|
try {
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
await
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const entries = await fs.readdir(this.pluginDir, { withFileTypes: true });
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
if (entry.isDirectory()) {
|
|
48
|
-
await this.loadPluginFromDir(path.join(this.pluginDir, entry.name));
|
|
49
|
-
}
|
|
36
|
+
// 1. Load built-in plugins (migrated skills) from local src/plugins
|
|
37
|
+
const internalPluginDir = path.resolve(__dirname, '../plugins');
|
|
38
|
+
await this.scanAndLoad(internalPluginDir);
|
|
39
|
+
// 2. Load user plugins from configured plugin directory
|
|
40
|
+
// Only if it's different from internal directory to avoid duplicates
|
|
41
|
+
if (path.resolve(this.pluginDir) !== internalPluginDir) {
|
|
42
|
+
await this.scanAndLoad(this.pluginDir);
|
|
50
43
|
}
|
|
51
44
|
}
|
|
52
45
|
catch (error) {
|
|
53
46
|
console.error('[PluginManager] Error loading plugins:', error);
|
|
54
47
|
}
|
|
55
48
|
}
|
|
49
|
+
async scanAndLoad(dir) {
|
|
50
|
+
try {
|
|
51
|
+
await fs.access(dir);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return; // Directory doesn't exist, skip
|
|
55
|
+
}
|
|
56
|
+
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
57
|
+
for (const entry of entries) {
|
|
58
|
+
if (entry.isDirectory()) {
|
|
59
|
+
await this.loadPluginFromDir(path.join(dir, entry.name));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getPlugins() {
|
|
64
|
+
return Array.from(this.plugins.values()).map(p => ({
|
|
65
|
+
name: p.metadata.name,
|
|
66
|
+
version: p.metadata.version,
|
|
67
|
+
description: p.metadata.description,
|
|
68
|
+
author: p.metadata.author,
|
|
69
|
+
enabled: true // Todo: Implement enable/disable persistence
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
56
72
|
async loadPluginFromDir(dirPath) {
|
|
57
73
|
try {
|
|
58
74
|
// Check for package.json or index.js/ts
|
package/dist/server/index.js
CHANGED
|
@@ -12,15 +12,10 @@ import fsPromises from 'fs/promises'; // For async file operations if needed
|
|
|
12
12
|
import crypto from 'crypto';
|
|
13
13
|
import axios from 'axios';
|
|
14
14
|
import { memory } from './core/memory.js';
|
|
15
|
-
import { skillRegistry } from './skills/registry.js';
|
|
16
|
-
import { SystemTimeSkill } from './skills/system-time.js';
|
|
17
|
-
import { SearchSkill } from './skills/search.js';
|
|
18
|
-
import { ListDirectorySkill, ReadFileSkill, WriteFileSkill, DeleteFileSkill } from './skills/file-system.js';
|
|
19
15
|
import { PluginManager } from './core/plugin-manager.js';
|
|
20
16
|
import { initScheduler, runMaintenanceNow, getSchedulerStatus, startScheduler, stopScheduler } from './core/scheduler.js';
|
|
21
17
|
import { agentManager } from './core/agents/manager.js';
|
|
22
18
|
import { createOfficeAgent } from './agents/office.js';
|
|
23
|
-
import { DelegateSkill } from './skills/delegate.js';
|
|
24
19
|
import { createChannels } from './channels/create-channels.js';
|
|
25
20
|
import { createHttpStack } from './server/create-http.js';
|
|
26
21
|
import { taskQueue } from './core/task-queue.js';
|
|
@@ -391,20 +386,28 @@ const thirdPartySkillsMeta = {
|
|
|
391
386
|
isBuiltIn: false
|
|
392
387
|
}
|
|
393
388
|
};
|
|
394
|
-
|
|
395
|
-
app.get('/api/skills', (req, res) => {
|
|
389
|
+
app.get('/api/plugins', (req, res) => {
|
|
396
390
|
try {
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
391
|
+
const plugins = pluginManager.getPlugins();
|
|
392
|
+
// Merge with third-party auth state (WPS/Lark)
|
|
393
|
+
// Todo: This should be handled by the plugin system itself
|
|
394
|
+
const enhancedPlugins = plugins.map(p => {
|
|
395
|
+
if (p.name === 'wps_office') {
|
|
396
|
+
return { ...p, enabled: thirdPartySkillsMeta.wps_office.enabled };
|
|
397
|
+
}
|
|
398
|
+
if (p.name === 'lark_docs') {
|
|
399
|
+
return { ...p, enabled: thirdPartySkillsMeta.lark_docs.enabled };
|
|
400
|
+
}
|
|
401
|
+
return p;
|
|
402
|
+
});
|
|
403
|
+
// Add pending third-party plugins if not loaded yet
|
|
404
|
+
if (!enhancedPlugins.find(p => p.name === 'wps_office')) {
|
|
405
|
+
enhancedPlugins.push(thirdPartySkillsMeta.wps_office);
|
|
406
|
+
}
|
|
407
|
+
if (!enhancedPlugins.find(p => p.name === 'lark_docs')) {
|
|
408
|
+
enhancedPlugins.push(thirdPartySkillsMeta.lark_docs);
|
|
409
|
+
}
|
|
410
|
+
res.json(enhancedPlugins);
|
|
408
411
|
}
|
|
409
412
|
catch (e) {
|
|
410
413
|
res.status(500).json({ error: e.message });
|
|
@@ -420,7 +423,10 @@ app.get('/api/auth/:provider/authorize', (req, res) => {
|
|
|
420
423
|
const state = crypto.randomBytes(16).toString('hex');
|
|
421
424
|
oauthStates.set(state, { provider, expiresAt: Date.now() + 10 * 60 * 1000 });
|
|
422
425
|
let authUrl = '';
|
|
423
|
-
|
|
426
|
+
// 使用相对路径或动态获取 host,这里使用 req.get('host') 自动适配当前后端运行的端口
|
|
427
|
+
const protocol = req.protocol || 'http';
|
|
428
|
+
const host = req.get('host') || 'localhost:3001';
|
|
429
|
+
const redirectUri = encodeURIComponent(`${protocol}://${host}/api/auth/${provider}/callback`);
|
|
424
430
|
if (provider === 'lark') {
|
|
425
431
|
const appId = config.channels?.feishu?.appId || 'cli_a939363208f8dbb4'; // 使用已有配置或默认
|
|
426
432
|
authUrl = `https://open.feishu.cn/open-apis/authen/v1/user_auth_page_beta?app_id=${appId}&redirect_uri=${redirectUri}&state=${state}`;
|
|
@@ -448,6 +454,13 @@ app.get('/api/auth/:provider/callback', async (req, res) => {
|
|
|
448
454
|
return res.status(400).send('Invalid or expired state');
|
|
449
455
|
}
|
|
450
456
|
oauthStates.delete(state);
|
|
457
|
+
// 尝试判断前端地址,如果是开发环境通常是 5173,生产环境可能是同源
|
|
458
|
+
const protocol = req.protocol || 'http';
|
|
459
|
+
const host = req.get('host') || 'localhost:3001';
|
|
460
|
+
// 简单策略:重定向回同源的 /settings(前端路由会处理)
|
|
461
|
+
const frontendBaseUrl = host.includes('3001') && process.env.NODE_ENV !== 'production'
|
|
462
|
+
? 'http://localhost:5173'
|
|
463
|
+
: `${protocol}://${host}`;
|
|
451
464
|
try {
|
|
452
465
|
let tokenData;
|
|
453
466
|
if (provider === 'lark') {
|
|
@@ -483,13 +496,19 @@ app.get('/api/auth/:provider/callback', async (req, res) => {
|
|
|
483
496
|
oauthTokens.set('wps', tokenData); // 实际应持久化
|
|
484
497
|
}
|
|
485
498
|
console.log(`[OAuth] Successfully authenticated with ${provider}`);
|
|
499
|
+
// 更新内存中的插件状态为已启用
|
|
500
|
+
const pluginId = provider === 'wps' ? 'wps_office' : 'lark_docs';
|
|
501
|
+
if (thirdPartySkillsMeta[pluginId]) {
|
|
502
|
+
thirdPartySkillsMeta[pluginId].enabled = true;
|
|
503
|
+
// 实际项目中,这里应该实例化对应的 Skill 类并调用 skillRegistry.register()
|
|
504
|
+
// 例如: skillRegistry.register(new LarkDocSkill(tokenData.access_token));
|
|
505
|
+
}
|
|
486
506
|
// 授权成功,重定向回前端并带上成功标志
|
|
487
|
-
|
|
488
|
-
res.redirect(`http://localhost:5173/settings?auth_success=true&provider=${provider}`);
|
|
507
|
+
res.redirect(`${frontendBaseUrl}/?auth_success=true&provider=${provider}`);
|
|
489
508
|
}
|
|
490
509
|
catch (error) {
|
|
491
510
|
console.error(`[OAuth] Failed to exchange token for ${provider}:`, error.response?.data || error.message);
|
|
492
|
-
res.redirect(
|
|
511
|
+
res.redirect(`${frontendBaseUrl}/?auth_success=false&error=token_exchange_failed`);
|
|
493
512
|
}
|
|
494
513
|
});
|
|
495
514
|
app.get('/api/projects', async (req, res) => {
|
|
@@ -627,30 +646,10 @@ app.delete('/api/notes/:id', async (req, res) => {
|
|
|
627
646
|
res.status(500).json({ error: e.message });
|
|
628
647
|
}
|
|
629
648
|
});
|
|
630
|
-
import { ReadWordSkill, CreateWordSkill } from './skills/office-word.js';
|
|
631
|
-
import { ReadExcelSkill, CreateExcelSkill } from './skills/office-excel.js';
|
|
632
|
-
import { CreatePptxSkill } from './skills/office-ppt.js';
|
|
633
|
-
import { CreateAgentSkill } from './skills/create-agent.js';
|
|
634
|
-
import { ListAgentsSkill } from './skills/list-agents.js';
|
|
635
649
|
// 初始化 Agents
|
|
636
650
|
agentManager.registerAgent(createOfficeAgent());
|
|
637
|
-
// 注册技能
|
|
638
|
-
skillRegistry.register(new CreateAgentSkill()); // 允许动态创建 Agent
|
|
639
|
-
skillRegistry.register(new ListAgentsSkill()); // 允许列出所有 Agent
|
|
640
|
-
skillRegistry.register(new DelegateSkill()); // 允许主 Brain 委派任务
|
|
641
|
-
skillRegistry.register(new SystemTimeSkill());
|
|
642
|
-
skillRegistry.register(new SearchSkill());
|
|
643
|
-
skillRegistry.register(new ListDirectorySkill());
|
|
644
|
-
skillRegistry.register(new ReadFileSkill());
|
|
645
|
-
skillRegistry.register(new WriteFileSkill());
|
|
646
|
-
skillRegistry.register(new DeleteFileSkill());
|
|
647
|
-
skillRegistry.register(new ReadWordSkill());
|
|
648
|
-
skillRegistry.register(new CreateWordSkill());
|
|
649
|
-
skillRegistry.register(new ReadExcelSkill());
|
|
650
|
-
skillRegistry.register(new CreateExcelSkill());
|
|
651
|
-
skillRegistry.register(new CreatePptxSkill());
|
|
652
651
|
// 初始化插件管理器
|
|
653
|
-
const pluginManager = new PluginManager(path.
|
|
652
|
+
const pluginManager = new PluginManager(path.join(process.cwd(), 'plugins'));
|
|
654
653
|
await pluginManager.loadPlugins();
|
|
655
654
|
// 初始化通道
|
|
656
655
|
const channels = createChannels({ app, io, config, pluginManager });
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateAgentSkill = void 0;
|
|
4
|
+
const base_skill_js_1 = require("../../../skills/base-skill.js");
|
|
5
|
+
const runtime_js_1 = require("../../../core/agents/runtime.js");
|
|
6
|
+
const manager_js_1 = require("../../../core/agents/manager.js");
|
|
7
|
+
const registry_js_1 = require("../../../skills/registry.js");
|
|
8
|
+
class CreateAgentSkill extends base_skill_js_1.BaseSkill {
|
|
6
9
|
constructor() {
|
|
7
10
|
super(...arguments);
|
|
8
11
|
this.name = 'create_agent';
|
|
@@ -34,25 +37,26 @@ export class CreateAgentSkill extends BaseSkill {
|
|
|
34
37
|
};
|
|
35
38
|
}
|
|
36
39
|
async execute(args, _ctx) {
|
|
37
|
-
if (agentManager.getAgent(args.name)) {
|
|
40
|
+
if (manager_js_1.agentManager.getAgent(args.name)) {
|
|
38
41
|
return { error: `Agent '${args.name}' already exists.` };
|
|
39
42
|
}
|
|
40
43
|
const assignedSkills = [];
|
|
41
44
|
if (args.skills) {
|
|
42
45
|
for (const skillName of args.skills) {
|
|
43
|
-
const skill = skillRegistry.getSkill(skillName);
|
|
46
|
+
const skill = registry_js_1.skillRegistry.getSkill(skillName);
|
|
44
47
|
if (skill) {
|
|
45
48
|
assignedSkills.push(skill);
|
|
46
49
|
}
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
|
-
const newAgent = new AgentRuntime({
|
|
52
|
+
const newAgent = new runtime_js_1.AgentRuntime({
|
|
50
53
|
name: args.name,
|
|
51
54
|
description: args.description,
|
|
52
55
|
systemPrompt: args.systemPrompt,
|
|
53
56
|
skills: assignedSkills
|
|
54
57
|
});
|
|
55
|
-
agentManager.registerAgent(newAgent);
|
|
58
|
+
manager_js_1.agentManager.registerAgent(newAgent);
|
|
56
59
|
return { success: true, message: `Agent '${args.name}' created successfully.` };
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
exports.CreateAgentSkill = CreateAgentSkill;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DelegateSkill = void 0;
|
|
4
|
+
const base_skill_js_1 = require("../../../skills/base-skill.js");
|
|
5
|
+
const manager_js_1 = require("../../../core/agents/manager.js");
|
|
6
|
+
class DelegateSkill extends base_skill_js_1.BaseSkill {
|
|
4
7
|
constructor() {
|
|
5
8
|
super(...arguments);
|
|
6
9
|
this.name = 'delegate_task';
|
|
@@ -22,9 +25,9 @@ export class DelegateSkill extends BaseSkill {
|
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
27
|
async execute(args, _ctx) {
|
|
25
|
-
const agent = agentManager.getAgent(args.agentName);
|
|
28
|
+
const agent = manager_js_1.agentManager.getAgent(args.agentName);
|
|
26
29
|
if (!agent) {
|
|
27
|
-
return { error: `Agent '${args.agentName}' not found. Available agents: ${agentManager.getAllAgents().map(a => a.name).join(', ')}` };
|
|
30
|
+
return { error: `Agent '${args.agentName}' not found. Available agents: ${manager_js_1.agentManager.getAllAgents().map(a => a.name).join(', ')}` };
|
|
28
31
|
}
|
|
29
32
|
console.log(`[DelegateSkill] Delegating to ${args.agentName}: ${args.task}`);
|
|
30
33
|
try {
|
|
@@ -37,3 +40,4 @@ export class DelegateSkill extends BaseSkill {
|
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
exports.DelegateSkill = DelegateSkill;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DeleteFileSkill = exports.WriteFileSkill = exports.ReadFileSkill = exports.ListDirectorySkill = void 0;
|
|
7
|
+
const base_skill_js_1 = require("../../../skills/base-skill.js");
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const paths_js_1 = require("../../../config/paths.js");
|
|
11
|
+
class ListDirectorySkill extends base_skill_js_1.BaseSkill {
|
|
6
12
|
constructor() {
|
|
7
13
|
super(...arguments);
|
|
8
14
|
this.name = 'fs_list_directory';
|
|
@@ -19,10 +25,10 @@ export class ListDirectorySkill extends BaseSkill {
|
|
|
19
25
|
};
|
|
20
26
|
}
|
|
21
27
|
async execute(params, ctx) {
|
|
22
|
-
const workspace = resolveSessionWorkspace(ctx);
|
|
23
|
-
const dirPath = params.path ? resolvePathWithinWorkspace(workspace, String(params.path)) : workspace;
|
|
28
|
+
const workspace = (0, paths_js_1.resolveSessionWorkspace)(ctx);
|
|
29
|
+
const dirPath = params.path ? (0, paths_js_1.resolvePathWithinWorkspace)(workspace, String(params.path)) : workspace;
|
|
24
30
|
try {
|
|
25
|
-
const files = await
|
|
31
|
+
const files = await promises_1.default.readdir(dirPath, { withFileTypes: true });
|
|
26
32
|
return files.map(file => ({
|
|
27
33
|
name: file.name,
|
|
28
34
|
type: file.isDirectory() ? 'directory' : 'file'
|
|
@@ -33,7 +39,8 @@ export class ListDirectorySkill extends BaseSkill {
|
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
|
|
42
|
+
exports.ListDirectorySkill = ListDirectorySkill;
|
|
43
|
+
class ReadFileSkill extends base_skill_js_1.BaseSkill {
|
|
37
44
|
constructor() {
|
|
38
45
|
super(...arguments);
|
|
39
46
|
this.name = 'fs_read_file';
|
|
@@ -55,11 +62,11 @@ export class ReadFileSkill extends BaseSkill {
|
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
64
|
async execute(params, ctx) {
|
|
58
|
-
const workspace = resolveSessionWorkspace(ctx);
|
|
59
|
-
const filePath = resolvePathWithinWorkspace(workspace, String(params.path));
|
|
65
|
+
const workspace = (0, paths_js_1.resolveSessionWorkspace)(ctx);
|
|
66
|
+
const filePath = (0, paths_js_1.resolvePathWithinWorkspace)(workspace, String(params.path));
|
|
60
67
|
const encoding = params.encoding || 'utf-8';
|
|
61
68
|
try {
|
|
62
|
-
const content = await
|
|
69
|
+
const content = await promises_1.default.readFile(filePath, { encoding: encoding });
|
|
63
70
|
return content;
|
|
64
71
|
}
|
|
65
72
|
catch (error) {
|
|
@@ -67,7 +74,8 @@ export class ReadFileSkill extends BaseSkill {
|
|
|
67
74
|
}
|
|
68
75
|
}
|
|
69
76
|
}
|
|
70
|
-
|
|
77
|
+
exports.ReadFileSkill = ReadFileSkill;
|
|
78
|
+
class WriteFileSkill extends base_skill_js_1.BaseSkill {
|
|
71
79
|
constructor() {
|
|
72
80
|
super(...arguments);
|
|
73
81
|
this.name = 'fs_write_file';
|
|
@@ -88,12 +96,12 @@ export class WriteFileSkill extends BaseSkill {
|
|
|
88
96
|
};
|
|
89
97
|
}
|
|
90
98
|
async execute(params, ctx) {
|
|
91
|
-
const workspace = resolveSessionWorkspace(ctx);
|
|
92
|
-
const filePath = resolvePathWithinWorkspace(workspace, String(params.path));
|
|
99
|
+
const workspace = (0, paths_js_1.resolveSessionWorkspace)(ctx);
|
|
100
|
+
const filePath = (0, paths_js_1.resolvePathWithinWorkspace)(workspace, String(params.path));
|
|
93
101
|
try {
|
|
94
102
|
// Ensure directory exists
|
|
95
|
-
await
|
|
96
|
-
await
|
|
103
|
+
await promises_1.default.mkdir(path_1.default.dirname(filePath), { recursive: true });
|
|
104
|
+
await promises_1.default.writeFile(filePath, params.content, 'utf-8');
|
|
97
105
|
return `Successfully wrote to ${filePath}`;
|
|
98
106
|
}
|
|
99
107
|
catch (error) {
|
|
@@ -101,7 +109,8 @@ export class WriteFileSkill extends BaseSkill {
|
|
|
101
109
|
}
|
|
102
110
|
}
|
|
103
111
|
}
|
|
104
|
-
|
|
112
|
+
exports.WriteFileSkill = WriteFileSkill;
|
|
113
|
+
class DeleteFileSkill extends base_skill_js_1.BaseSkill {
|
|
105
114
|
constructor() {
|
|
106
115
|
super(...arguments);
|
|
107
116
|
this.name = 'fs_delete_file';
|
|
@@ -122,16 +131,16 @@ export class DeleteFileSkill extends BaseSkill {
|
|
|
122
131
|
};
|
|
123
132
|
}
|
|
124
133
|
async execute(params, ctx) {
|
|
125
|
-
const workspace = resolveSessionWorkspace(ctx);
|
|
126
|
-
const filePath = resolvePathWithinWorkspace(workspace, String(params.path));
|
|
134
|
+
const workspace = (0, paths_js_1.resolveSessionWorkspace)(ctx);
|
|
135
|
+
const filePath = (0, paths_js_1.resolvePathWithinWorkspace)(workspace, String(params.path));
|
|
127
136
|
const recursive = params.recursive || false;
|
|
128
137
|
try {
|
|
129
|
-
const stats = await
|
|
138
|
+
const stats = await promises_1.default.stat(filePath);
|
|
130
139
|
if (stats.isDirectory()) {
|
|
131
|
-
await
|
|
140
|
+
await promises_1.default.rm(filePath, { recursive, force: true });
|
|
132
141
|
}
|
|
133
142
|
else {
|
|
134
|
-
await
|
|
143
|
+
await promises_1.default.unlink(filePath);
|
|
135
144
|
}
|
|
136
145
|
return `Successfully deleted ${filePath}`;
|
|
137
146
|
}
|
|
@@ -140,3 +149,4 @@ export class DeleteFileSkill extends BaseSkill {
|
|
|
140
149
|
}
|
|
141
150
|
}
|
|
142
151
|
}
|
|
152
|
+
exports.DeleteFileSkill = DeleteFileSkill;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const file_system_js_1 = require("./file-system.js");
|
|
4
|
+
const search_js_1 = require("./search.js");
|
|
5
|
+
const system_time_js_1 = require("./system-time.js");
|
|
6
|
+
const create_agent_js_1 = require("./create-agent.js");
|
|
7
|
+
const delegate_js_1 = require("./delegate.js");
|
|
8
|
+
const list_agents_js_1 = require("./list-agents.js");
|
|
9
|
+
const plugin = {
|
|
10
|
+
metadata: {
|
|
11
|
+
name: 'core-skills',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
description: 'Core system skills for XiaoZuoClaw',
|
|
14
|
+
author: 'XiaoZuoClaw Team'
|
|
15
|
+
},
|
|
16
|
+
onLoad: (context) => {
|
|
17
|
+
context.registerSkill(new file_system_js_1.ListDirectorySkill());
|
|
18
|
+
context.registerSkill(new file_system_js_1.ReadFileSkill());
|
|
19
|
+
context.registerSkill(new file_system_js_1.WriteFileSkill());
|
|
20
|
+
context.registerSkill(new file_system_js_1.DeleteFileSkill());
|
|
21
|
+
context.registerSkill(new search_js_1.SearchSkill());
|
|
22
|
+
context.registerSkill(new system_time_js_1.SystemTimeSkill());
|
|
23
|
+
context.registerSkill(new create_agent_js_1.CreateAgentSkill());
|
|
24
|
+
context.registerSkill(new delegate_js_1.DelegateSkill());
|
|
25
|
+
context.registerSkill(new list_agents_js_1.ListAgentsSkill());
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
exports.default = plugin;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ListAgentsSkill = void 0;
|
|
4
|
+
const base_skill_js_1 = require("../../../skills/base-skill.js");
|
|
5
|
+
const manager_js_1 = require("../../../core/agents/manager.js");
|
|
6
|
+
class ListAgentsSkill extends base_skill_js_1.BaseSkill {
|
|
4
7
|
constructor() {
|
|
5
8
|
super(...arguments);
|
|
6
9
|
this.name = 'list_agents';
|
|
@@ -12,7 +15,7 @@ export class ListAgentsSkill extends BaseSkill {
|
|
|
12
15
|
};
|
|
13
16
|
}
|
|
14
17
|
async execute(_params, _ctx) {
|
|
15
|
-
const agents = agentManager.getAllAgents();
|
|
18
|
+
const agents = manager_js_1.agentManager.getAllAgents();
|
|
16
19
|
return {
|
|
17
20
|
agents: agents.map(a => ({
|
|
18
21
|
name: a.name,
|
|
@@ -22,3 +25,4 @@ export class ListAgentsSkill extends BaseSkill {
|
|
|
22
25
|
};
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.ListAgentsSkill = ListAgentsSkill;
|