@bolloon/bolloon-agent 0.2.9 → 0.2.11
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 +467 -467
- package/bin/bolloon-cli.cjs +183 -183
- package/bin/bolloon.cjs +0 -0
- package/bin/bolloon.js +157 -0
- package/dist/agents/agent-manifest-protocol.js +0 -52
- package/dist/agents/constraint-layer.js +19 -19
- package/dist/agents/pi-sdk.js +287 -1213
- package/dist/agents/shell-guard.js +2 -2
- package/dist/agents/workflow-pivot-loop.js +2 -81
- package/dist/bollharness/src/scripts/deploy-guard.js +8 -8
- package/dist/bollharness-integration/context-router-judgment.js +4 -4
- package/dist/bollharness-integration/context-router.js +292 -292
- package/dist/bollharness-integration/gate-state-machine.js +13 -26
- package/dist/bollharness-integration/integration.js +0 -71
- package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
- package/dist/bollharness-integration/skill-adapter.js +127 -52
- package/dist/bootstrap/context-collector.js +3 -6
- package/dist/bootstrap/lifecycle-hooks.js +1 -15
- package/dist/cli-entry.js +35 -39
- package/dist/constraint-runtime/src/_archive_helper.js +9 -0
- package/dist/constraint-runtime/src/agent/coordinator.js +48 -0
- package/dist/constraint-runtime/src/agent/index.js +1 -0
- package/dist/constraint-runtime/src/assistant/index.js +12 -0
- package/dist/constraint-runtime/src/bootstrap/index.js +12 -0
- package/dist/constraint-runtime/src/bootstrap_graph.js +13 -0
- package/dist/constraint-runtime/src/bridge/index.js +12 -0
- package/dist/constraint-runtime/src/buddy/index.js +12 -0
- package/dist/constraint-runtime/src/cli/index.js +12 -0
- package/dist/constraint-runtime/src/command_graph.js +10 -0
- package/dist/constraint-runtime/src/commands.js +60 -0
- package/dist/constraint-runtime/src/components/index.js +12 -0
- package/dist/constraint-runtime/src/constants/index.js +12 -0
- package/dist/constraint-runtime/src/constraint/budget.js +22 -0
- package/dist/constraint-runtime/src/constraint/index.js +2 -0
- package/dist/constraint-runtime/src/constraint/permission.js +20 -0
- package/dist/constraint-runtime/src/context.js +30 -0
- package/dist/constraint-runtime/src/coordinator/index.js +12 -0
- package/dist/constraint-runtime/src/cost_hook.js +4 -0
- package/dist/constraint-runtime/src/cost_tracker.js +8 -0
- package/dist/constraint-runtime/src/deferred_init.js +10 -0
- package/dist/constraint-runtime/src/direct_modes.js +6 -0
- package/dist/constraint-runtime/src/dynamic-tool-loader.js +85 -0
- package/dist/constraint-runtime/src/entrypoints/index.js +12 -0
- package/dist/constraint-runtime/src/execution_registry.js +44 -0
- package/dist/constraint-runtime/src/history.js +9 -0
- package/dist/constraint-runtime/src/hooks/index.js +12 -0
- package/dist/constraint-runtime/src/index.js +26 -0
- package/dist/constraint-runtime/src/ink.js +4 -0
- package/dist/constraint-runtime/src/keybindings/index.js +12 -0
- package/dist/constraint-runtime/src/memdir/index.js +12 -0
- package/dist/constraint-runtime/src/migrations/index.js +12 -0
- package/dist/constraint-runtime/src/models.js +1 -0
- package/dist/constraint-runtime/src/moreright/index.js +12 -0
- package/dist/constraint-runtime/src/native_ts/index.js +12 -0
- package/dist/constraint-runtime/src/output_styles/index.js +12 -0
- package/dist/constraint-runtime/src/parity_audit.js +12 -0
- package/dist/constraint-runtime/src/plugins/index.js +12 -0
- package/dist/constraint-runtime/src/port_manifest.js +11 -0
- package/dist/constraint-runtime/src/prefetch.js +9 -0
- package/dist/constraint-runtime/src/query.js +1 -0
- package/dist/constraint-runtime/src/remote/index.js +12 -0
- package/dist/constraint-runtime/src/remote_runtime.js +9 -0
- package/dist/constraint-runtime/src/runtime/index.js +1 -0
- package/dist/constraint-runtime/src/runtime/session.js +35 -0
- package/dist/constraint-runtime/src/schemas/index.js +12 -0
- package/dist/constraint-runtime/src/screens/index.js +12 -0
- package/dist/constraint-runtime/src/server/index.js +12 -0
- package/dist/constraint-runtime/src/services/index.js +12 -0
- package/dist/constraint-runtime/src/session_store.js +22 -0
- package/dist/constraint-runtime/src/setup.js +30 -0
- package/dist/constraint-runtime/src/skills/index.js +1 -0
- package/dist/constraint-runtime/src/skills/skill-registry.js +28 -0
- package/dist/constraint-runtime/src/state/index.js +12 -0
- package/dist/constraint-runtime/src/system_init.js +20 -0
- package/dist/constraint-runtime/src/thinking/engine.js +42 -0
- package/dist/constraint-runtime/src/thinking/index.js +1 -0
- package/dist/constraint-runtime/src/tool_pool.js +8 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/execAdapter.js +7 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/listAdapters.js +7 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/runCommand.js +7 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/confirmTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/createTransaction.js +8 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/executeTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/getBalance.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/proposeTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools.js +80 -0
- package/dist/constraint-runtime/src/transcript.js +19 -0
- package/dist/constraint-runtime/src/types/index.js +12 -0
- package/dist/constraint-runtime/src/upstream_proxy/index.js +12 -0
- package/dist/constraint-runtime/src/utils/index.js +12 -0
- package/dist/constraint-runtime/src/vim/index.js +12 -0
- package/dist/constraint-runtime/src/voice/index.js +12 -0
- package/dist/constraint-runtime/tests/agent.test.js +16 -0
- package/dist/constraint-runtime/tests/constraint.test.js +41 -0
- package/dist/constraint-runtime/tests/skill.test.js +19 -0
- package/dist/constraint-runtime/tests/thinking.test.js +22 -0
- package/dist/context-compaction/auto-compact.js +7 -7
- package/dist/electron-preload.js +1 -18
- package/dist/electron-preload.js.map +1 -1
- package/dist/electron.js +168 -3
- package/dist/electron.js.map +1 -1
- package/dist/index.js +116 -136
- package/dist/llm/config-store.js +8 -24
- package/dist/llm/llm-judgment-client.js +102 -102
- package/dist/llm/pi-ai.js +85 -126
- package/dist/llm/system-prompt/layers/channel/local.md +14 -14
- package/dist/llm/system-prompt/layers/channel/p2p-agent.md +18 -18
- package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
- package/dist/llm/system-prompt/layers/core/artifacts_storage.md +89 -89
- package/dist/llm/system-prompt/layers/core/evenhandedness.md +21 -21
- package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
- package/dist/llm/system-prompt/layers/core/identity.md +37 -37
- package/dist/llm/system-prompt/layers/core/knowledge.md +17 -17
- package/dist/llm/system-prompt/layers/core/memory_system.md +12 -12
- package/dist/llm/system-prompt/layers/core/network_filesystem.md +28 -28
- package/dist/llm/system-prompt/layers/core/refusal.md +37 -37
- package/dist/llm/system-prompt/layers/core/tone.md +31 -31
- package/dist/llm/system-prompt/layers/core/tools.thin.md +13 -13
- package/dist/llm/system-prompt/layers/core/wellbeing.md +41 -41
- package/dist/llm/system-prompt/layers/role/architect.md +20 -20
- package/dist/llm/system-prompt/layers/role/expert.md +19 -19
- package/dist/llm/system-prompt/layers/role/implementer.md +15 -15
- package/dist/llm/system-prompt/layers/role/security.md +15 -15
- package/dist/llm/system-prompt/layers/tool/artifacts.md +72 -72
- package/dist/llm/system-prompt/layers/tool/bash.md +25 -25
- package/dist/llm/system-prompt/layers/tool/hibs_api.md +171 -171
- package/dist/llm/system-prompt/layers/tool/image_search.md +70 -70
- package/dist/llm/system-prompt/layers/tool/manifest.md +89 -89
- package/dist/llm/system-prompt/layers/tool/mcp_apps.md +53 -53
- package/dist/llm/system-prompt/layers/tool/web_search.md +83 -83
- package/dist/llm/tool-manifest/ask_user_input.js +1 -1
- package/dist/llm/tool-manifest/bash.js +3 -3
- package/dist/llm/tool-manifest/create_file.js +4 -4
- package/dist/llm/tool-manifest/fetch_sports_data.js +3 -3
- package/dist/llm/tool-manifest/image_search.js +2 -2
- package/dist/llm/tool-manifest/mcp.js +2 -2
- package/dist/llm/tool-manifest/message_compose.js +3 -3
- package/dist/llm/tool-manifest/places.js +2 -2
- package/dist/llm/tool-manifest/present_files.js +1 -1
- package/dist/llm/tool-manifest/recipe.js +2 -2
- package/dist/llm/tool-manifest/str_replace.js +5 -5
- package/dist/llm/tool-manifest/view.js +3 -3
- package/dist/llm/tool-manifest/weather.js +4 -4
- package/dist/llm/tool-manifest/web.js +4 -4
- package/dist/pi-ecosystem-colony/index.js +365 -0
- package/dist/pi-ecosystem-judgment/causal-judge.js +51 -51
- package/dist/pi-ecosystem-judgment/distill-prompt.js +42 -42
- package/dist/pi-ecosystem-judgment/distillation.js +14 -14
- package/dist/pi-ecosystem-judgment/monitor-gate.js +28 -28
- package/dist/pi-ecosystem-judgment/value-injection.js +102 -102
- package/dist/security/context-router-tool.js +15 -15
- package/dist/security/tool-gate.js +0 -11
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +101 -0
- package/dist/social/ant-colony/PheromoneEngine.js +227 -0
- package/dist/social/ant-colony/index.js +6 -0
- package/dist/social/ant-colony/types.js +24 -0
- package/dist/test/ai-judgment-test.js +80 -0
- package/dist/test/bollharness-integration.test.js +318 -0
- package/dist/test/channel-agent-multi-dialogue.js +205 -0
- package/dist/test/channel-heartbeat-agent-test.js +201 -0
- package/dist/test/constraint-layer.test.js +164 -0
- package/dist/test/diap-identity-test.js +172 -0
- package/dist/test/diap-quick-test.js +62 -0
- package/dist/test/global-shared-context.test.js +315 -0
- package/dist/test/harness-judgment-injection.test.js +246 -0
- package/dist/test/harness-workflow-integrator-test.js +228 -0
- package/dist/test/human-value-store.test.js +243 -0
- package/dist/test/hybrid-integration-test.js +118 -0
- package/dist/test/hybrid-messenger-verify.js +55 -0
- package/dist/test/iroh-bistream-debug.js +38 -0
- package/dist/test/iroh-communication.test.js +66 -0
- package/dist/test/iroh-debug-test.js +57 -0
- package/dist/test/iroh-diap-test.js +71 -0
- package/dist/test/iroh-direct-connect.js +55 -0
- package/dist/test/iroh-e2e-fixed.js +89 -0
- package/dist/test/iroh-e2e-same-process.js +63 -0
- package/dist/test/iroh-e2e.js +66 -0
- package/dist/test/iroh-final-e2e.js +72 -0
- package/dist/test/iroh-relay-test.js +37 -0
- package/dist/test/iroh-simple-test.js +41 -0
- package/dist/test/iroh-transport-verify.js +54 -0
- package/dist/test/iroh-transport.test.js +37 -0
- package/dist/test/iroh-two-nodes.js +70 -0
- package/dist/test/iroh-verify.js +44 -0
- package/dist/test/judgment-decision.test.js +219 -0
- package/dist/test/llm-judgment-integration.test.js +220 -0
- package/dist/test/p2p-agent-complex-dialogue.js +385 -0
- package/dist/test/p2p-agent-dialogue.js +341 -0
- package/dist/test/p2p-agent-full-bidirectional.js +510 -0
- package/dist/test/p2p-agent-harness-flow.js +437 -0
- package/dist/test/p2p-agent-harness-single.js +143 -0
- package/dist/test/p2p-ai-dialogue-test.js +318 -0
- package/dist/test/p2p-cid-connect-test.js +195 -0
- package/dist/test/p2p-connect-receiver.js +69 -0
- package/dist/test/p2p-doc-transfer.js +110 -0
- package/dist/test/p2p-identity-page-test.js +77 -0
- package/dist/test/p2p-iroh-test.js +171 -0
- package/dist/test/p2p-minimal-test.js +241 -0
- package/dist/test/p2p-node-1.js +148 -0
- package/dist/test/p2p-node-2.js +148 -0
- package/dist/test/p2p-server.js +281 -0
- package/dist/test/p2p-two-nodes-test.js +438 -0
- package/dist/test/pi-sdk.test.js +44 -0
- package/dist/test/set-persona.js +40 -0
- package/dist/test/simple.test.js +9 -0
- package/dist/test/storage-integration.test.js +150 -0
- package/dist/test/subagent-manager.test.js +276 -0
- package/dist/test/test-gate-flow.test.js +81 -0
- package/dist/test/workflow-engine.test.js +87 -0
- package/dist/test/workflow-pivot-loop.test.js +246 -0
- package/dist/web/api-config.html +520 -520
- package/dist/web/client.js +2917 -3791
- package/dist/web/components/p2p/index.js +234 -276
- package/dist/web/components/wallet-viem.mjs +118 -118
- package/dist/web/index.html +374 -373
- package/dist/web/manifest.json +20 -20
- package/dist/web/server.js +23 -775
- package/dist/web/style.css +4737 -4737
- package/dist/web/ui/message-renderer.js +373 -451
- package/dist/web/ui/step-timeline.js +255 -351
- package/package.json +160 -160
- package/scripts/build-cli.js +215 -215
- package/scripts/build-web.ts +125 -125
- package/scripts/postinstall.js +152 -152
- package/bin/bolloon-daemon.sh +0 -207
- package/bin/ipfs +0 -0
- package/dist/agents/chat-segmenter.js +0 -298
- package/dist/agents/judgment-protocol.js +0 -479
- package/dist/agents/parse-tool-call.js +0 -304
- package/dist/agents/peer-manifest-loader.js +0 -210
- package/dist/agents/react-loop.js +0 -120
- package/dist/agents/session-store.js +0 -171
- package/dist/agents/tool-registry.js +0 -136
- package/dist/bootstrap/chat-archiver.js +0 -276
- package/dist/bootstrap/memory-compressor.js +0 -170
- package/dist/bootstrap/persona-loader.js +0 -94
- package/dist/electron/config.js +0 -16
- package/dist/electron/config.js.map +0 -1
- package/dist/electron/dialogs.js +0 -71
- package/dist/electron/dialogs.js.map +0 -1
- package/dist/electron/first-run.js +0 -129
- package/dist/electron/first-run.js.map +0 -1
- package/dist/electron/ipc.js +0 -16
- package/dist/electron/ipc.js.map +0 -1
- package/dist/electron/logger.js +0 -77
- package/dist/electron/logger.js.map +0 -1
- package/dist/electron/main.js +0 -60
- package/dist/electron/main.js.map +0 -1
- package/dist/electron/menu.js +0 -140
- package/dist/electron/menu.js.map +0 -1
- package/dist/electron/paths.js +0 -33
- package/dist/electron/paths.js.map +0 -1
- package/dist/electron/server.js +0 -74
- package/dist/electron/server.js.map +0 -1
- package/dist/electron/tray.js +0 -73
- package/dist/electron/tray.js.map +0 -1
- package/dist/electron/window.js +0 -69
- package/dist/electron/window.js.map +0 -1
- package/dist/network/local-inbox-bus.js +0 -73
- package/dist/network/p2p-outbox.js +0 -161
- package/dist/network/peer-fs.js +0 -420
- package/dist/network/peer-resource-bridge.js +0 -216
- package/dist/web/components/p2p/P2PModal.js +0 -188
- package/dist/web/components/p2p/p2p-modal.js +0 -664
- package/dist/web/components/p2p/p2p-tools.js +0 -248
- package/dist/web/input-validator.js +0 -103
- package/dist/web/util/safe-name.js +0 -32
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIAP Identity Test - 测试 DIAP 身份生成和 DID 注册
|
|
3
|
+
*
|
|
4
|
+
* 测试内容:
|
|
5
|
+
* 1. 生成 DIAP 身份 (KeyManager)
|
|
6
|
+
* 2. 创建 DID 文档
|
|
7
|
+
* 3. 模拟发布到 IPFS(不依赖真实 IPFS)
|
|
8
|
+
* 4. 模拟从 IPFS 解析 DID 文档
|
|
9
|
+
*
|
|
10
|
+
* 运行: npx tsx src/test/diap-identity-test.ts
|
|
11
|
+
*/
|
|
12
|
+
import { KeyManager } from '@diap/sdk';
|
|
13
|
+
async function main() {
|
|
14
|
+
console.log('\n╔═══════════════════════════════════════════════════════╗');
|
|
15
|
+
console.log('║ DIAP Identity Test - 身份生成与 DID 注册 ║');
|
|
16
|
+
console.log('╚═══════════════════════════════════════════════════════╝\n');
|
|
17
|
+
// ============================================================
|
|
18
|
+
// 测试 1: 生成 DIAP 身份
|
|
19
|
+
// ============================================================
|
|
20
|
+
console.log('[Test 1/4] 生成 DIAP 身份...');
|
|
21
|
+
console.log('─'.repeat(50));
|
|
22
|
+
const keyManager = KeyManager.generate();
|
|
23
|
+
const did = keyManager.did;
|
|
24
|
+
const publicKeyHex = Buffer.from(keyManager.publicKey).toString('hex');
|
|
25
|
+
console.log(` ✅ DID 生成成功`);
|
|
26
|
+
console.log(` DID: ${did}`);
|
|
27
|
+
console.log(` 公钥: ${publicKeyHex.substring(0, 32)}...`);
|
|
28
|
+
// 提取用户名
|
|
29
|
+
const username = process.env.USER || process.env.USERNAME || 'mechrevo';
|
|
30
|
+
const didSuffix = did.split(':').pop() || '';
|
|
31
|
+
const shortSuffix = didSuffix.substring(0, Math.min(4, didSuffix.length));
|
|
32
|
+
const agentName = `blln-${username.toLowerCase()}-${shortSuffix}`;
|
|
33
|
+
console.log(` 名称: ${agentName}`);
|
|
34
|
+
// ============================================================
|
|
35
|
+
// 测试 2: 创建 DID 文档
|
|
36
|
+
// ============================================================
|
|
37
|
+
console.log('\n[Test 2/4] 创建 DID 文档...');
|
|
38
|
+
console.log('─'.repeat(50));
|
|
39
|
+
const diapDoc = {
|
|
40
|
+
id: did,
|
|
41
|
+
name: agentName,
|
|
42
|
+
version: '1.0',
|
|
43
|
+
capabilities: ['chat', 'reasoning', 'judgment-injection', 'harness-workflow'],
|
|
44
|
+
interests: ['ai', 'p2p', 'judgment-system'],
|
|
45
|
+
publicKey: publicKeyHex,
|
|
46
|
+
channels: [
|
|
47
|
+
{ id: `ch_${Date.now()}`, name: '主对话' }
|
|
48
|
+
],
|
|
49
|
+
createdAt: new Date().toISOString(),
|
|
50
|
+
updatedAt: new Date().toISOString()
|
|
51
|
+
};
|
|
52
|
+
const docJson = JSON.stringify(diapDoc, null, 2);
|
|
53
|
+
console.log(` ✅ DID 文档创建成功`);
|
|
54
|
+
console.log(` 文档大小: ${docJson.length} 字节`);
|
|
55
|
+
console.log(` 能力列表: ${diapDoc.capabilities.join(', ')}`);
|
|
56
|
+
console.log(` 兴趣领域: ${diapDoc.interests.join(', ')}`);
|
|
57
|
+
// ============================================================
|
|
58
|
+
// 测试 3: 模拟发布到 IPFS
|
|
59
|
+
// ============================================================
|
|
60
|
+
console.log('\n[Test 3/4] 模拟发布到 IPFS...');
|
|
61
|
+
console.log('─'.repeat(50));
|
|
62
|
+
// 模拟 IPFS CID 生成(使用 DID 的哈希)
|
|
63
|
+
const crypto = await import('crypto');
|
|
64
|
+
const docHash = crypto.createHash('sha256').update(docJson).digest('base64url');
|
|
65
|
+
const simulatedCid = `baf${docHash.substring(0, 50)}`;
|
|
66
|
+
console.log(` ✅ 模拟 IPFS 发布成功`);
|
|
67
|
+
console.log(` 模拟 CID: ${simulatedCid}`);
|
|
68
|
+
// 测试 AgentAuthManager(需要真实 IPFS)
|
|
69
|
+
console.log('\n 📡 尝试连接真实 IPFS...');
|
|
70
|
+
try {
|
|
71
|
+
const { AgentAuthManager } = await import('@diap/sdk');
|
|
72
|
+
const authManager = await AgentAuthManager.newWithRemoteIpfs('http://127.0.0.1:5001', 'http://127.0.0.1:8080');
|
|
73
|
+
const result = await authManager.registerAgent({ name: agentName, services: [] }, keyManager, '');
|
|
74
|
+
console.log(` ✅ 真实 IPFS 注册成功`);
|
|
75
|
+
console.log(` CID: ${result.cid || 'N/A'}`);
|
|
76
|
+
console.log(` IPNS: ${result.ipnsName || 'N/A'}`);
|
|
77
|
+
return {
|
|
78
|
+
did,
|
|
79
|
+
agentName,
|
|
80
|
+
publicKey: publicKeyHex,
|
|
81
|
+
diapDoc,
|
|
82
|
+
cid: result.cid || simulatedCid,
|
|
83
|
+
ipnsName: result.ipnsName
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
const error = e;
|
|
88
|
+
console.log(` ⚠️ 真实 IPFS 不可用: ${error.message}`);
|
|
89
|
+
console.log(' 将使用模拟数据继续测试');
|
|
90
|
+
return {
|
|
91
|
+
did,
|
|
92
|
+
agentName,
|
|
93
|
+
publicKey: publicKeyHex,
|
|
94
|
+
diapDoc,
|
|
95
|
+
cid: simulatedCid,
|
|
96
|
+
ipnsName: null
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async function testParseDID(doc, cid) {
|
|
101
|
+
// ============================================================
|
|
102
|
+
// 测试 4: 解析 DID 文档
|
|
103
|
+
// ============================================================
|
|
104
|
+
console.log('\n[Test 4/4] 解析 DID 文档...');
|
|
105
|
+
console.log('─'.repeat(50));
|
|
106
|
+
// 从 IPFS 获取内容
|
|
107
|
+
console.log(' 📡 从 IPFS 解析...');
|
|
108
|
+
// 方式1: 使用 IpfsClient
|
|
109
|
+
try {
|
|
110
|
+
const { IpfsClient } = await import('@diap/sdk');
|
|
111
|
+
const ipfs = new IpfsClient('http://127.0.0.1:5001', null);
|
|
112
|
+
console.log(` 尝试从 CID ${cid} 获取...`);
|
|
113
|
+
const content = await ipfs.get(cid);
|
|
114
|
+
const parsedDoc = JSON.parse(content);
|
|
115
|
+
console.log(` ✅ IpfsClient 解析成功`);
|
|
116
|
+
console.log(` DID: ${parsedDoc.id}`);
|
|
117
|
+
console.log(` 创建时间: ${parsedDoc.created}`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
console.log(` ⚠️ IpfsClient 解析失败: ${e.message}`);
|
|
122
|
+
}
|
|
123
|
+
// 方式2: 直接使用 fetch
|
|
124
|
+
console.log(' 📡 尝试直接使用 fetch...');
|
|
125
|
+
try {
|
|
126
|
+
const response = await fetch(`http://127.0.0.1:5001/api/v0/cat?arg=${cid}`, {
|
|
127
|
+
method: 'POST'
|
|
128
|
+
});
|
|
129
|
+
const text = await response.text();
|
|
130
|
+
const parsedDoc = JSON.parse(text);
|
|
131
|
+
console.log(` ✅ 直接 fetch 解析成功`);
|
|
132
|
+
console.log(` DID: ${parsedDoc.id}`);
|
|
133
|
+
console.log(` 验证方法数: ${parsedDoc.verificationMethod?.length || 0}`);
|
|
134
|
+
if (parsedDoc.service) {
|
|
135
|
+
console.log(` 服务端点数: ${parsedDoc.service.length}`);
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
console.log(` ⚠️ 直接 fetch 解析失败: ${e.message}`);
|
|
141
|
+
}
|
|
142
|
+
// 方式3: 使用本地文档模拟
|
|
143
|
+
console.log(` ⚠️ 使用本地文档模拟解析结果`);
|
|
144
|
+
console.log(` ✅ 本地解析成功`);
|
|
145
|
+
console.log(` DID: ${doc.id}`);
|
|
146
|
+
console.log(` 名称: ${doc.name}`);
|
|
147
|
+
console.log(` 公钥: ${doc.publicKey.substring(0, 32)}...`);
|
|
148
|
+
console.log(` 能力: ${doc.capabilities.join(', ')}`);
|
|
149
|
+
console.log(` 频道: ${doc.channels?.map(c => c.name).join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
// 运行测试
|
|
152
|
+
(async () => {
|
|
153
|
+
try {
|
|
154
|
+
const result = await main();
|
|
155
|
+
console.log('\n' + '═'.repeat(50));
|
|
156
|
+
console.log(' 测试结果摘要');
|
|
157
|
+
console.log('═'.repeat(50));
|
|
158
|
+
console.log(` DID: ${result.did}`);
|
|
159
|
+
console.log(` 名称: ${result.agentName}`);
|
|
160
|
+
console.log(` CID: ${result.cid}`);
|
|
161
|
+
if (result.ipnsName) {
|
|
162
|
+
console.log(` IPNS: ${result.ipnsName}`);
|
|
163
|
+
}
|
|
164
|
+
console.log('═'.repeat(50));
|
|
165
|
+
await testParseDID(result.diapDoc, result.cid);
|
|
166
|
+
console.log('\n✅ 所有测试完成!\n');
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
console.error('\n❌ 测试失败:', e.message);
|
|
170
|
+
process.exit(1);
|
|
171
|
+
}
|
|
172
|
+
})();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DIAP Quick Test - 快速验证 DIAP 功能(跳过慢速 IPNS)
|
|
3
|
+
*/
|
|
4
|
+
import { KeyManager } from '@diap/sdk';
|
|
5
|
+
async function main() {
|
|
6
|
+
console.log('\n🔑 DIAP 快速验证测试\n');
|
|
7
|
+
// 1. 生成身份
|
|
8
|
+
console.log('[1] 生成 DIAP 身份...');
|
|
9
|
+
const km = KeyManager.generate();
|
|
10
|
+
console.log(` ✅ DID: ${km.did}`);
|
|
11
|
+
// 2. 验证可以直接获取公钥
|
|
12
|
+
console.log('\n[2] 获取公钥...');
|
|
13
|
+
const pkHex = Buffer.from(km.publicKey).toString('hex');
|
|
14
|
+
console.log(` ✅ 公钥: ${pkHex.substring(0, 24)}...`);
|
|
15
|
+
// 3. 测试本地 IPFS
|
|
16
|
+
console.log('\n[3] 测试本地 IPFS...');
|
|
17
|
+
const testContent = JSON.stringify({
|
|
18
|
+
test: true,
|
|
19
|
+
did: km.did,
|
|
20
|
+
timestamp: Date.now()
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
// 上传 - 使用 form-data 格式
|
|
24
|
+
const formData = new FormData();
|
|
25
|
+
const blob = new Blob([testContent], { type: 'application/json' });
|
|
26
|
+
formData.append('file', blob, 'test.json');
|
|
27
|
+
const addResponse = await fetch('http://127.0.0.1:5001/api/v0/add', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
body: formData
|
|
30
|
+
});
|
|
31
|
+
const addResult = await addResponse.text();
|
|
32
|
+
// IPFS add 返回格式: {"Name":"test.json","Hash":"Qm...","Size":"..."}
|
|
33
|
+
const cidMatch = addResult.match(/"Hash":"([^"]+)"/);
|
|
34
|
+
const cid = cidMatch ? cidMatch[1] : null;
|
|
35
|
+
if (!cid) {
|
|
36
|
+
console.log(` ⚠️ 解析 CID 失败: ${addResult}`);
|
|
37
|
+
throw new Error('CID not found');
|
|
38
|
+
}
|
|
39
|
+
console.log(` ✅ 上传成功: ${cid}`);
|
|
40
|
+
// 下载
|
|
41
|
+
const getResponse = await fetch(`http://127.0.0.1:5001/api/v0/cat?arg=${cid}`, {
|
|
42
|
+
method: 'POST'
|
|
43
|
+
});
|
|
44
|
+
const retrieved = await getResponse.text();
|
|
45
|
+
const parsed = JSON.parse(retrieved);
|
|
46
|
+
console.log(` ✅ 下载成功: test=${parsed.test}`);
|
|
47
|
+
console.log('\n═══════════════════════════════════════');
|
|
48
|
+
console.log(' ✅ DIAP + IPFS 基本功能正常!');
|
|
49
|
+
console.log('═══════════════════════════════════════');
|
|
50
|
+
console.log(`\n 本节点信息:`);
|
|
51
|
+
console.log(` · DID: ${km.did}`);
|
|
52
|
+
console.log(` · CID: ${cid}`);
|
|
53
|
+
console.log(`\n 供另一台电脑使用的连接信息:`);
|
|
54
|
+
console.log(` · DID: ${km.did}`);
|
|
55
|
+
console.log(` · CID: ${cid}`);
|
|
56
|
+
console.log('');
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.log(` ❌ IPFS 操作失败: ${e.message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
main().catch(console.error);
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import * as fs from 'fs/promises';
|
|
3
|
+
import * as path from 'path';
|
|
4
|
+
import { GlobalSharedContextManager, resetGlobalSharedContext } from '../social/global-shared-context.js';
|
|
5
|
+
const TEST_CONTEXT_PATH = path.join('/tmp', '.bolloon-test', 'sessions', 'test-global-context.json');
|
|
6
|
+
describe('GlobalSharedContext', () => {
|
|
7
|
+
let contextManager;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
resetGlobalSharedContext();
|
|
10
|
+
contextManager = new GlobalSharedContextManager(TEST_CONTEXT_PATH);
|
|
11
|
+
try {
|
|
12
|
+
await fs.rm(path.dirname(TEST_CONTEXT_PATH), { recursive: true, force: true });
|
|
13
|
+
}
|
|
14
|
+
catch { }
|
|
15
|
+
});
|
|
16
|
+
describe('SharedMemory - recentActions', () => {
|
|
17
|
+
it('should add user action', async () => {
|
|
18
|
+
await contextManager.initialize();
|
|
19
|
+
await contextManager.addUserAction('用户要求总结文档', 'agent1', 'channel1', 8);
|
|
20
|
+
const actions = await contextManager.getRecentActions();
|
|
21
|
+
expect(actions).toHaveLength(1);
|
|
22
|
+
expect(actions[0].content).toBe('用户要求总结文档');
|
|
23
|
+
expect(actions[0].agentId).toBe('agent1');
|
|
24
|
+
expect(actions[0].channelId).toBe('channel1');
|
|
25
|
+
expect(actions[0].importance).toBe(8);
|
|
26
|
+
});
|
|
27
|
+
it('should limit recent actions to 50', async () => {
|
|
28
|
+
await contextManager.initialize();
|
|
29
|
+
for (let i = 0; i < 60; i++) {
|
|
30
|
+
await contextManager.addUserAction(`Action ${i}`);
|
|
31
|
+
}
|
|
32
|
+
const actions = await contextManager.getRecentActions(60);
|
|
33
|
+
expect(actions).toHaveLength(50);
|
|
34
|
+
});
|
|
35
|
+
it('should return formatted summary', async () => {
|
|
36
|
+
await contextManager.initialize();
|
|
37
|
+
await contextManager.addUserAction('测试行动1');
|
|
38
|
+
await contextManager.addUserAction('测试行动2');
|
|
39
|
+
const summary = await contextManager.getRecentActionsSummary(10);
|
|
40
|
+
expect(summary).toContain('测试行动1');
|
|
41
|
+
expect(summary).toContain('测试行动2');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe('SharedMemory - sharedKnowledge', () => {
|
|
45
|
+
it('should add shared knowledge', async () => {
|
|
46
|
+
await contextManager.initialize();
|
|
47
|
+
await contextManager.addSharedKnowledge('这是一个重要的跨Agent共享知识');
|
|
48
|
+
const knowledge = await contextManager.getSharedKnowledge();
|
|
49
|
+
expect(knowledge).toContain('这是一个重要的跨Agent共享知识');
|
|
50
|
+
});
|
|
51
|
+
it('should not duplicate knowledge', async () => {
|
|
52
|
+
await contextManager.initialize();
|
|
53
|
+
await contextManager.addSharedKnowledge('共享知识');
|
|
54
|
+
await contextManager.addSharedKnowledge('共享知识');
|
|
55
|
+
const knowledge = await contextManager.getSharedKnowledge();
|
|
56
|
+
expect(knowledge.filter(k => k === '共享知识')).toHaveLength(1);
|
|
57
|
+
});
|
|
58
|
+
it('should limit shared knowledge to 100', async () => {
|
|
59
|
+
await contextManager.initialize();
|
|
60
|
+
for (let i = 0; i < 110; i++) {
|
|
61
|
+
await contextManager.addSharedKnowledge(`Knowledge ${i}`);
|
|
62
|
+
}
|
|
63
|
+
const knowledge = await contextManager.getSharedKnowledge();
|
|
64
|
+
expect(knowledge).toHaveLength(100);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
describe('SharedMemory - currentTask', () => {
|
|
68
|
+
it('should set and get current task', async () => {
|
|
69
|
+
await contextManager.initialize();
|
|
70
|
+
const task = await contextManager.setCurrentTask({
|
|
71
|
+
description: '完成文档总结',
|
|
72
|
+
status: 'in_progress'
|
|
73
|
+
});
|
|
74
|
+
expect(task.id).toBeDefined();
|
|
75
|
+
expect(task.description).toBe('完成文档总结');
|
|
76
|
+
expect(task.status).toBe('in_progress');
|
|
77
|
+
expect(task.createdAt).toBeDefined();
|
|
78
|
+
const currentTask = await contextManager.getCurrentTask();
|
|
79
|
+
expect(currentTask?.description).toBe('完成文档总结');
|
|
80
|
+
});
|
|
81
|
+
it('should complete current task', async () => {
|
|
82
|
+
await contextManager.initialize();
|
|
83
|
+
await contextManager.setCurrentTask({
|
|
84
|
+
description: '完成文档总结',
|
|
85
|
+
status: 'in_progress'
|
|
86
|
+
});
|
|
87
|
+
await contextManager.completeCurrentTask('文档总结已完成');
|
|
88
|
+
const currentTask = await contextManager.getCurrentTask();
|
|
89
|
+
expect(currentTask?.status).toBe('completed');
|
|
90
|
+
expect(currentTask?.result).toBe('文档总结已完成');
|
|
91
|
+
expect(currentTask?.completedAt).toBeDefined();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('AgentRegistry', () => {
|
|
95
|
+
it('should register agent', async () => {
|
|
96
|
+
await contextManager.initialize();
|
|
97
|
+
await contextManager.registerAgent({
|
|
98
|
+
agentId: 'agent-001',
|
|
99
|
+
sessionId: 'session-001',
|
|
100
|
+
channelId: 'channel-001',
|
|
101
|
+
capabilities: ['coding', 'writing'],
|
|
102
|
+
status: 'active',
|
|
103
|
+
name: 'TestAgent'
|
|
104
|
+
});
|
|
105
|
+
const agent = await contextManager.getAgent('agent-001');
|
|
106
|
+
expect(agent).toBeDefined();
|
|
107
|
+
expect(agent?.name).toBe('TestAgent');
|
|
108
|
+
expect(agent?.capabilities).toEqual(['coding', 'writing']);
|
|
109
|
+
expect(agent?.status).toBe('active');
|
|
110
|
+
});
|
|
111
|
+
it('should update agent status', async () => {
|
|
112
|
+
await contextManager.initialize();
|
|
113
|
+
await contextManager.registerAgent({
|
|
114
|
+
agentId: 'agent-001',
|
|
115
|
+
sessionId: 'session-001',
|
|
116
|
+
channelId: 'channel-001',
|
|
117
|
+
capabilities: ['coding'],
|
|
118
|
+
status: 'active'
|
|
119
|
+
});
|
|
120
|
+
await contextManager.updateAgentStatus('agent-001', 'busy');
|
|
121
|
+
const agent = await contextManager.getAgent('agent-001');
|
|
122
|
+
expect(agent?.status).toBe('busy');
|
|
123
|
+
});
|
|
124
|
+
it('should get all agents', async () => {
|
|
125
|
+
await contextManager.initialize();
|
|
126
|
+
await contextManager.registerAgent({
|
|
127
|
+
agentId: 'agent-001',
|
|
128
|
+
sessionId: 'session-001',
|
|
129
|
+
channelId: 'channel-001',
|
|
130
|
+
capabilities: ['coding'],
|
|
131
|
+
status: 'active'
|
|
132
|
+
});
|
|
133
|
+
await contextManager.registerAgent({
|
|
134
|
+
agentId: 'agent-002',
|
|
135
|
+
sessionId: 'session-002',
|
|
136
|
+
channelId: 'channel-002',
|
|
137
|
+
capabilities: ['writing'],
|
|
138
|
+
status: 'idle'
|
|
139
|
+
});
|
|
140
|
+
const agents = await contextManager.getAllAgents();
|
|
141
|
+
expect(agents).toHaveLength(2);
|
|
142
|
+
});
|
|
143
|
+
it('should find agents by capability', async () => {
|
|
144
|
+
await contextManager.initialize();
|
|
145
|
+
await contextManager.registerAgent({
|
|
146
|
+
agentId: 'agent-001',
|
|
147
|
+
sessionId: 'session-001',
|
|
148
|
+
channelId: 'channel-001',
|
|
149
|
+
capabilities: ['coding', 'debugging'],
|
|
150
|
+
status: 'active'
|
|
151
|
+
});
|
|
152
|
+
await contextManager.registerAgent({
|
|
153
|
+
agentId: 'agent-002',
|
|
154
|
+
sessionId: 'session-002',
|
|
155
|
+
channelId: 'channel-002',
|
|
156
|
+
capabilities: ['writing', 'editing'],
|
|
157
|
+
status: 'active'
|
|
158
|
+
});
|
|
159
|
+
const codingAgents = await contextManager.findAgentByCapability('coding');
|
|
160
|
+
expect(codingAgents).toHaveLength(1);
|
|
161
|
+
expect(codingAgents[0].agentId).toBe('agent-001');
|
|
162
|
+
});
|
|
163
|
+
it('should get active agents', async () => {
|
|
164
|
+
await contextManager.initialize();
|
|
165
|
+
await contextManager.registerAgent({
|
|
166
|
+
agentId: 'agent-001',
|
|
167
|
+
sessionId: 'session-001',
|
|
168
|
+
channelId: 'channel-001',
|
|
169
|
+
capabilities: ['coding'],
|
|
170
|
+
status: 'active'
|
|
171
|
+
});
|
|
172
|
+
await contextManager.registerAgent({
|
|
173
|
+
agentId: 'agent-002',
|
|
174
|
+
sessionId: 'session-002',
|
|
175
|
+
channelId: 'channel-002',
|
|
176
|
+
capabilities: ['writing'],
|
|
177
|
+
status: 'idle'
|
|
178
|
+
});
|
|
179
|
+
const activeAgents = await contextManager.getActiveAgents();
|
|
180
|
+
expect(activeAgents).toHaveLength(1);
|
|
181
|
+
expect(activeAgents[0].agentId).toBe('agent-001');
|
|
182
|
+
});
|
|
183
|
+
it('should unregister agent', async () => {
|
|
184
|
+
await contextManager.initialize();
|
|
185
|
+
await contextManager.registerAgent({
|
|
186
|
+
agentId: 'agent-001',
|
|
187
|
+
sessionId: 'session-001',
|
|
188
|
+
channelId: 'channel-001',
|
|
189
|
+
capabilities: ['coding'],
|
|
190
|
+
status: 'active'
|
|
191
|
+
});
|
|
192
|
+
await contextManager.unregisterAgent('agent-001');
|
|
193
|
+
const agent = await contextManager.getAgent('agent-001');
|
|
194
|
+
expect(agent).toBeUndefined();
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
describe('CooperationQueue', () => {
|
|
198
|
+
it('should create cooperation task', async () => {
|
|
199
|
+
await contextManager.initialize();
|
|
200
|
+
const cooperation = await contextManager.createCooperation('consult', 'agent-001', '请帮我分析这段代码', 'agent-002', 'context here');
|
|
201
|
+
expect(cooperation.id).toBeDefined();
|
|
202
|
+
expect(cooperation.type).toBe('consult');
|
|
203
|
+
expect(cooperation.fromAgentId).toBe('agent-001');
|
|
204
|
+
expect(cooperation.toAgentId).toBe('agent-002');
|
|
205
|
+
expect(cooperation.task).toBe('请帮我分析这段代码');
|
|
206
|
+
expect(cooperation.context).toBe('context here');
|
|
207
|
+
expect(cooperation.status).toBe('pending');
|
|
208
|
+
});
|
|
209
|
+
it('should update cooperation status', async () => {
|
|
210
|
+
await contextManager.initialize();
|
|
211
|
+
const cooperation = await contextManager.createCooperation('delegate', 'agent-001', '完成这个任务');
|
|
212
|
+
await contextManager.updateCooperationStatus(cooperation.id, 'in_progress');
|
|
213
|
+
const updated = await contextManager.getCooperation(cooperation.id);
|
|
214
|
+
expect(updated?.status).toBe('in_progress');
|
|
215
|
+
});
|
|
216
|
+
it('should get pending cooperations for agent', async () => {
|
|
217
|
+
await contextManager.initialize();
|
|
218
|
+
await contextManager.createCooperation('consult', 'agent-001', 'Task 1', 'agent-002');
|
|
219
|
+
await contextManager.createCooperation('delegate', 'agent-001', 'Task 2');
|
|
220
|
+
const pending = await contextManager.getPendingCooperations('agent-001');
|
|
221
|
+
expect(pending).toHaveLength(2);
|
|
222
|
+
});
|
|
223
|
+
it('should get cooperations for specific agent', async () => {
|
|
224
|
+
await contextManager.initialize();
|
|
225
|
+
await contextManager.createCooperation('consult', 'agent-001', 'Task for agent-002', 'agent-002');
|
|
226
|
+
await contextManager.createCooperation('delegate', 'agent-003', 'Task for agent-003', 'agent-003');
|
|
227
|
+
const agent002Coops = await contextManager.getCooperationsForAgent('agent-002');
|
|
228
|
+
expect(agent002Coops).toHaveLength(1);
|
|
229
|
+
expect(agent002Coops[0].task).toBe('Task for agent-002');
|
|
230
|
+
});
|
|
231
|
+
it('should add result to cooperation', async () => {
|
|
232
|
+
await contextManager.initialize();
|
|
233
|
+
const cooperation = await contextManager.createCooperation('consult', 'agent-001', '请分析');
|
|
234
|
+
await contextManager.updateCooperationStatus(cooperation.id, 'done', '分析结果:代码有bug');
|
|
235
|
+
const updated = await contextManager.getCooperation(cooperation.id);
|
|
236
|
+
expect(updated?.status).toBe('done');
|
|
237
|
+
expect(updated?.result).toBe('分析结果:代码有bug');
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
describe('Full context', () => {
|
|
241
|
+
it('should get full context', async () => {
|
|
242
|
+
await contextManager.initialize();
|
|
243
|
+
await contextManager.addUserAction('Test action');
|
|
244
|
+
await contextManager.addSharedKnowledge('Test knowledge');
|
|
245
|
+
await contextManager.registerAgent({
|
|
246
|
+
agentId: 'agent-001',
|
|
247
|
+
sessionId: 'session-001',
|
|
248
|
+
channelId: 'channel-001',
|
|
249
|
+
capabilities: ['coding'],
|
|
250
|
+
status: 'active'
|
|
251
|
+
});
|
|
252
|
+
const fullContext = await contextManager.getFullContext();
|
|
253
|
+
expect(fullContext.memory.recentActions).toHaveLength(1);
|
|
254
|
+
expect(fullContext.memory.sharedKnowledge).toHaveLength(1);
|
|
255
|
+
expect(fullContext.agentRegistry['agent-001']).toBeDefined();
|
|
256
|
+
});
|
|
257
|
+
it('should get context summary', async () => {
|
|
258
|
+
await contextManager.initialize();
|
|
259
|
+
await contextManager.addUserAction('用户执行了操作A');
|
|
260
|
+
await contextManager.registerAgent({
|
|
261
|
+
agentId: 'agent-001',
|
|
262
|
+
sessionId: 'session-001',
|
|
263
|
+
channelId: 'channel-001',
|
|
264
|
+
capabilities: ['coding'],
|
|
265
|
+
status: 'active',
|
|
266
|
+
name: '编码助手'
|
|
267
|
+
});
|
|
268
|
+
const summary = await contextManager.getContextSummary();
|
|
269
|
+
expect(summary).toContain('全局共享上下文');
|
|
270
|
+
expect(summary).toContain('最近行动');
|
|
271
|
+
expect(summary).toContain('用户执行了操作A');
|
|
272
|
+
expect(summary).toContain('Agent 注册');
|
|
273
|
+
expect(summary).toContain('编码助手');
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
describe('Persistence', () => {
|
|
277
|
+
it('should persist and reload context', async () => {
|
|
278
|
+
await contextManager.initialize();
|
|
279
|
+
await contextManager.addUserAction('持久化测试');
|
|
280
|
+
await contextManager.registerAgent({
|
|
281
|
+
agentId: 'agent-001',
|
|
282
|
+
sessionId: 'session-001',
|
|
283
|
+
channelId: 'channel-001',
|
|
284
|
+
capabilities: ['coding'],
|
|
285
|
+
status: 'active'
|
|
286
|
+
});
|
|
287
|
+
const newManager = new GlobalSharedContextManager(TEST_CONTEXT_PATH);
|
|
288
|
+
await newManager.initialize();
|
|
289
|
+
const actions = await newManager.getRecentActions();
|
|
290
|
+
expect(actions).toHaveLength(1);
|
|
291
|
+
expect(actions[0].content).toBe('持久化测试');
|
|
292
|
+
const agent = await newManager.getAgent('agent-001');
|
|
293
|
+
expect(agent).toBeDefined();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe('Clear', () => {
|
|
297
|
+
it('should clear all data', async () => {
|
|
298
|
+
await contextManager.initialize();
|
|
299
|
+
await contextManager.addUserAction('Test action');
|
|
300
|
+
await contextManager.addSharedKnowledge('Test knowledge');
|
|
301
|
+
await contextManager.registerAgent({
|
|
302
|
+
agentId: 'agent-001',
|
|
303
|
+
sessionId: 'session-001',
|
|
304
|
+
channelId: 'channel-001',
|
|
305
|
+
capabilities: ['coding'],
|
|
306
|
+
status: 'active'
|
|
307
|
+
});
|
|
308
|
+
await contextManager.clear();
|
|
309
|
+
const context = await contextManager.getFullContext();
|
|
310
|
+
expect(context.memory.recentActions).toHaveLength(0);
|
|
311
|
+
expect(context.memory.sharedKnowledge).toHaveLength(0);
|
|
312
|
+
expect(Object.keys(context.agentRegistry)).toHaveLength(0);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|