@bolloon/bolloon-agent 0.4.14 → 0.4.15
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 +127 -127
- package/bin/bolloon-cli.cjs +183 -183
- package/bin/bolloon-daemon.sh +207 -0
- package/bin/bolloon.cjs +0 -0
- package/dist/agents/constraint-layer.js +19 -19
- package/dist/agents/judgment-protocol.js +14 -14
- package/dist/agents/pi-sdk-types.js +12 -12
- package/dist/agents/pi-sdk.js +101 -101
- package/dist/agents/skill-organizer.js +19 -19
- package/dist/agents/workflow-pivot-loop.js +2 -2
- package/dist/agents/x402/x402Pay.js +4 -0
- 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 -13
- package/dist/bollharness-integration/llm-judgment-engine.js +134 -134
- package/dist/bollharness-integration/skill-adapter.js +21 -21
- package/dist/bootstrap/chat-archiver.js +14 -14
- package/dist/bootstrap/context-os.js +24 -24
- package/dist/bootstrap/memory-compressor.js +13 -13
- package/dist/cli-entry.js +36 -36
- package/dist/constraint-runtime/reference_data/archive_surface_snapshot.json +63 -0
- package/dist/constraint-runtime/reference_data/commands_snapshot.json +1037 -0
- package/dist/constraint-runtime/reference_data/subsystems/assistant.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bootstrap.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/bridge.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/buddy.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/cli.json +26 -0
- package/dist/constraint-runtime/reference_data/subsystems/components.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/constants.json +28 -0
- package/dist/constraint-runtime/reference_data/subsystems/coordinator.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/entrypoints.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/hooks.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/keybindings.json +21 -0
- package/dist/constraint-runtime/reference_data/subsystems/memdir.json +15 -0
- package/dist/constraint-runtime/reference_data/subsystems/migrations.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/moreright.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/native_ts.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/outputStyles.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/plugins.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/remote.json +11 -0
- package/dist/constraint-runtime/reference_data/subsystems/schemas.json +8 -0
- package/dist/constraint-runtime/reference_data/subsystems/screens.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/server.json +10 -0
- package/dist/constraint-runtime/reference_data/subsystems/services.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/skills.json +27 -0
- package/dist/constraint-runtime/reference_data/subsystems/state.json +13 -0
- package/dist/constraint-runtime/reference_data/subsystems/types.json +18 -0
- package/dist/constraint-runtime/reference_data/subsystems/upstreamproxy.json +9 -0
- package/dist/constraint-runtime/reference_data/subsystems/utils.json +32 -0
- package/dist/constraint-runtime/reference_data/subsystems/vim.json +12 -0
- package/dist/constraint-runtime/reference_data/subsystems/voice.json +8 -0
- package/dist/constraint-runtime/reference_data/tools_snapshot.json +922 -0
- package/dist/context-compaction/auto-compact.js +7 -7
- package/dist/electron/config.js.map +1 -0
- package/dist/electron/dialogs.js.map +1 -0
- package/dist/electron/first-run.js +54 -54
- package/dist/electron/first-run.js.map +1 -0
- package/dist/electron/ipc.js.map +1 -0
- package/dist/electron/logger.js.map +1 -0
- package/dist/electron/main.js.map +1 -0
- package/dist/electron/menu.js.map +1 -0
- package/dist/electron/paths.js.map +1 -0
- package/dist/electron/server.js.map +1 -0
- package/dist/electron/tray.js.map +1 -0
- package/dist/electron/window.js.map +1 -0
- package/dist/electron-build/electron/first-run.js +54 -54
- package/dist/electron-preload.js.map +1 -1
- package/dist/electron.js.map +1 -1
- package/dist/index.js +112 -112
- package/dist/llm/llm-judgment-client.js +102 -102
- package/dist/llm/pi-ai.js +48 -48
- package/dist/llm/system-prompt/layers/channel/human-async.md +41 -41
- 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-peer-sync.md +51 -51
- package/dist/llm/system-prompt/layers/channel/p2p-proactive.md +43 -43
- package/dist/llm/system-prompt/layers/channel/p2p-visitor.md +19 -19
- package/dist/llm/system-prompt/layers/channel/session-handoff.md +61 -61
- 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/external-engagement.md +73 -73
- package/dist/llm/system-prompt/layers/core/hibs_reminders.md +15 -15
- package/dist/llm/system-prompt/layers/core/identity.md +48 -48
- 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/goal_handoff.md +77 -77
- 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/p2p_request.md +61 -61
- 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/index.js +59 -0
- 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/network/p2p.js +78 -4
- 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/index.js +1 -1
- 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/utils/auto-update.js.map +1 -0
- package/dist/web/a2ui-client.js +1594 -223
- package/dist/web/api-config.html +779 -779
- package/dist/web/client-hearth.js +10 -10
- package/dist/web/client.js.map +7 -0
- package/dist/web/components/wallet-viem.mjs +118 -118
- package/dist/web/index.html +502 -502
- package/dist/web/manifest.json +20 -20
- package/dist/web/mobile-agent.js +397 -0
- package/dist/web/mobile-core.js +86235 -0
- package/dist/web/mobile-data.js +346 -0
- package/dist/web/mobile-http-api.js +71 -0
- package/dist/web/mobile-p2p.js +250 -0
- package/dist/web/mobile-payments.js +80 -0
- package/dist/web/mobile-wallet.js +226 -0
- package/dist/web/mobile.css +483 -6
- package/dist/web/mobile.html +99 -50
- package/dist/web/mobile.js +1040 -187
- package/dist/web/server.js +13 -13
- package/dist/web/style.css +4946 -4946
- package/package.json +201 -198
- package/scripts/build-cli.js +215 -215
- package/scripts/build-web.ts +162 -149
- package/scripts/postinstall.js +152 -152
- package/bin/bolloon.js +0 -157
- package/dist/agents/python-exec.js +0 -115
- package/dist/pi-ecosystem-colony/index.js +0 -365
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +0 -101
- package/dist/social/ant-colony/PheromoneEngine.js +0 -227
- package/dist/social/ant-colony/index.js +0 -6
- package/dist/social/ant-colony/types.js +0 -24
- package/dist/storage/trajectory.js +0 -101
- package/dist/test/ai-judgment-test.js +0 -80
- package/dist/test/bollharness-integration.test.js +0 -318
- package/dist/test/channel-agent-multi-dialogue.js +0 -205
- package/dist/test/channel-heartbeat-agent-test.js +0 -201
- package/dist/test/constraint-layer.test.js +0 -164
- package/dist/test/diap-identity-test.js +0 -172
- package/dist/test/diap-quick-test.js +0 -62
- package/dist/test/global-shared-context.test.js +0 -315
- package/dist/test/harness-judgment-injection.test.js +0 -246
- package/dist/test/harness-workflow-integrator-test.js +0 -228
- package/dist/test/human-value-store.test.js +0 -243
- package/dist/test/hybrid-integration-test.js +0 -118
- package/dist/test/hybrid-messenger-verify.js +0 -55
- package/dist/test/iroh-bistream-debug.js +0 -38
- package/dist/test/iroh-communication.test.js +0 -66
- package/dist/test/iroh-debug-test.js +0 -57
- package/dist/test/iroh-diap-test.js +0 -71
- package/dist/test/iroh-direct-connect.js +0 -55
- package/dist/test/iroh-e2e-fixed.js +0 -89
- package/dist/test/iroh-e2e-same-process.js +0 -63
- package/dist/test/iroh-e2e.js +0 -66
- package/dist/test/iroh-final-e2e.js +0 -72
- package/dist/test/iroh-relay-test.js +0 -37
- package/dist/test/iroh-simple-test.js +0 -41
- package/dist/test/iroh-transport-verify.js +0 -54
- package/dist/test/iroh-transport.test.js +0 -37
- package/dist/test/iroh-two-nodes.js +0 -70
- package/dist/test/iroh-verify.js +0 -44
- package/dist/test/judgment-decision.test.js +0 -219
- package/dist/test/llm-judgment-integration.test.js +0 -220
- package/dist/test/p2p-agent-complex-dialogue.js +0 -385
- package/dist/test/p2p-agent-dialogue.js +0 -341
- package/dist/test/p2p-agent-full-bidirectional.js +0 -510
- package/dist/test/p2p-agent-harness-flow.js +0 -437
- package/dist/test/p2p-agent-harness-single.js +0 -143
- package/dist/test/p2p-ai-dialogue-test.js +0 -318
- package/dist/test/p2p-cid-connect-test.js +0 -195
- package/dist/test/p2p-connect-receiver.js +0 -69
- package/dist/test/p2p-doc-transfer.js +0 -110
- package/dist/test/p2p-identity-page-test.js +0 -77
- package/dist/test/p2p-iroh-test.js +0 -171
- package/dist/test/p2p-minimal-test.js +0 -241
- package/dist/test/p2p-node-1.js +0 -148
- package/dist/test/p2p-node-2.js +0 -148
- package/dist/test/p2p-server.js +0 -281
- package/dist/test/p2p-two-nodes-test.js +0 -438
- package/dist/test/pi-sdk.test.js +0 -44
- package/dist/test/set-persona.js +0 -40
- package/dist/test/simple.test.js +0 -9
- package/dist/test/storage-integration.test.js +0 -150
- package/dist/test/subagent-manager.test.js +0 -276
- package/dist/test/test-gate-flow.test.js +0 -81
- package/dist/test/workflow-engine.test.js +0 -87
- package/dist/test/workflow-pivot-loop.test.js +0 -246
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
import { config } from 'dotenv';
|
|
2
|
-
import { describe, it, expect } from 'vitest';
|
|
3
|
-
import { WorkflowPivotLoop, createDefaultPivotConfig, runPivotLoop } from '../agents/workflow-pivot-loop.js';
|
|
4
|
-
config();
|
|
5
|
-
const mockTools = [
|
|
6
|
-
{
|
|
7
|
-
name: 'read_document',
|
|
8
|
-
description: '读取文档内容',
|
|
9
|
-
parameters: { path: '文件路径' },
|
|
10
|
-
execute: async (args) => {
|
|
11
|
-
if (args.path === 'nonexistent.txt') {
|
|
12
|
-
return { success: false, error: '文件不存在' };
|
|
13
|
-
}
|
|
14
|
-
return { success: true, output: `文件内容: ${args.path}` };
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: 'list_files',
|
|
19
|
-
description: '列出文件',
|
|
20
|
-
parameters: {},
|
|
21
|
-
execute: async () => {
|
|
22
|
-
return { success: true, output: 'file1.txt\nfile2.txt' };
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: 'get_time',
|
|
27
|
-
description: '获取当前时间',
|
|
28
|
-
parameters: {},
|
|
29
|
-
execute: async () => {
|
|
30
|
-
return { success: true, output: new Date().toISOString() };
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
];
|
|
34
|
-
function createMockLLM(mock) {
|
|
35
|
-
return {
|
|
36
|
-
chat: async (context, systemPrompt) => {
|
|
37
|
-
mock.callCount++;
|
|
38
|
-
console.log(`[MockLLM] 调用 #${mock.callCount}, context长度: ${context.length}`);
|
|
39
|
-
if (mock.shouldReturnFinal || mock.callCount >= 2) {
|
|
40
|
-
return { reply: `${mock.finalResponse}\n\n<final gen>` };
|
|
41
|
-
}
|
|
42
|
-
if (context.includes('list_files') || context.includes('列出文件')) {
|
|
43
|
-
return { reply: '调用工具: list_files()' };
|
|
44
|
-
}
|
|
45
|
-
if (context.includes('read_document') || context.includes('读取文档')) {
|
|
46
|
-
const hasNonexistent = context.includes('nonexistent');
|
|
47
|
-
if (hasNonexistent) {
|
|
48
|
-
return {
|
|
49
|
-
reply: '调用工具: read_document(path: nonexistent.txt)'
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return { reply: '调用工具: read_document(path: test.txt)' };
|
|
53
|
-
}
|
|
54
|
-
if (context.includes('get_time') || context.includes('时间')) {
|
|
55
|
-
return { reply: '调用工具: get_time()' };
|
|
56
|
-
}
|
|
57
|
-
return { reply: '调用工具: list_files()' };
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
describe('WorkflowPivotLoop', () => {
|
|
62
|
-
describe('基础功能', () => {
|
|
63
|
-
it('应该正确初始化', () => {
|
|
64
|
-
const loop = new WorkflowPivotLoop({ maxIterations: 10 });
|
|
65
|
-
expect(loop).toBeDefined();
|
|
66
|
-
expect(loop.getState().iteration).toBe(0);
|
|
67
|
-
});
|
|
68
|
-
it('应该注册工具', () => {
|
|
69
|
-
const loop = new WorkflowPivotLoop({ maxIterations: 10 });
|
|
70
|
-
loop.registerTool(mockTools[0]);
|
|
71
|
-
loop.registerTools(mockTools.slice(1));
|
|
72
|
-
const state = loop.getState();
|
|
73
|
-
expect(state.pendingToolUses).toBeDefined();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe('工具调用', () => {
|
|
77
|
-
it('应该正确解析工具调用', async () => {
|
|
78
|
-
const loop = new WorkflowPivotLoop({ maxIterations: 10 });
|
|
79
|
-
loop.registerTools(mockTools);
|
|
80
|
-
const mock = {
|
|
81
|
-
callCount: 0,
|
|
82
|
-
shouldReturnFinal: false,
|
|
83
|
-
finalResponse: '初始响应'
|
|
84
|
-
};
|
|
85
|
-
const llm = createMockLLM(mock);
|
|
86
|
-
const systemPrompt = '测试系统提示';
|
|
87
|
-
const result = await loop.execute('读取文件', llm, systemPrompt);
|
|
88
|
-
console.log('[Test] 结果:', {
|
|
89
|
-
iterations: result.iterations,
|
|
90
|
-
toolCalls: result.toolCalls,
|
|
91
|
-
exitReason: result.exitReason
|
|
92
|
-
});
|
|
93
|
-
expect(result.iterations).toBeGreaterThan(0);
|
|
94
|
-
expect(result.toolCalls).toBeGreaterThan(0);
|
|
95
|
-
});
|
|
96
|
-
it('应该正确处理 final gen 标记', async () => {
|
|
97
|
-
const loop = new WorkflowPivotLoop({
|
|
98
|
-
maxIterations: 10,
|
|
99
|
-
minIterations: 1,
|
|
100
|
-
qualityThreshold: 0.5
|
|
101
|
-
});
|
|
102
|
-
loop.registerTools(mockTools);
|
|
103
|
-
const mock = {
|
|
104
|
-
callCount: 0,
|
|
105
|
-
shouldReturnFinal: true,
|
|
106
|
-
finalResponse: '这是最终答案'
|
|
107
|
-
};
|
|
108
|
-
const llm = createMockLLM(mock);
|
|
109
|
-
const result = await loop.execute('简单任务', llm, '系统提示');
|
|
110
|
-
console.log('[Test] 最终响应测试结果:', result);
|
|
111
|
-
expect(result.exitReason).toMatch(/final|pending|quality/);
|
|
112
|
-
});
|
|
113
|
-
it('应该处理工具执行失败', async () => {
|
|
114
|
-
const loop = new WorkflowPivotLoop({
|
|
115
|
-
maxIterations: 10,
|
|
116
|
-
maxConsecutiveNoProgress: 3
|
|
117
|
-
});
|
|
118
|
-
loop.registerTools(mockTools);
|
|
119
|
-
const mock = {
|
|
120
|
-
callCount: 0,
|
|
121
|
-
shouldReturnFinal: false,
|
|
122
|
-
finalResponse: '尝试读取'
|
|
123
|
-
};
|
|
124
|
-
const llm = createMockLLM(mock);
|
|
125
|
-
const result = await loop.execute('读取不存在的文件', llm, '系统提示');
|
|
126
|
-
console.log('[Test] 失败处理结果:', result);
|
|
127
|
-
expect(result.iterations).toBeGreaterThan(0);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
describe('中断条件', () => {
|
|
131
|
-
it('应该达到最大迭代次数时中断', async () => {
|
|
132
|
-
const loop = new WorkflowPivotLoop({ maxIterations: 3 });
|
|
133
|
-
loop.registerTools(mockTools);
|
|
134
|
-
const mock = {
|
|
135
|
-
callCount: 0,
|
|
136
|
-
shouldReturnFinal: false,
|
|
137
|
-
finalResponse: '继续'
|
|
138
|
-
};
|
|
139
|
-
const llm = createMockLLM(mock);
|
|
140
|
-
const result = await loop.execute('需要多次迭代的任务', llm, '系统提示');
|
|
141
|
-
console.log('[Test] 最大迭代结果:', result);
|
|
142
|
-
expect(result.iterations).toBeLessThanOrEqual(3);
|
|
143
|
-
});
|
|
144
|
-
it('应该在质量达标时提前结束', async () => {
|
|
145
|
-
const loop = new WorkflowPivotLoop({
|
|
146
|
-
maxIterations: 50,
|
|
147
|
-
qualityThreshold: 0.4 // 0.55 quality score will exceed this
|
|
148
|
-
});
|
|
149
|
-
loop.registerTools(mockTools);
|
|
150
|
-
const mock = {
|
|
151
|
-
callCount: 0,
|
|
152
|
-
shouldReturnFinal: true,
|
|
153
|
-
finalResponse: '这是一个高质量的完整回答,包含足够的细节和结构化内容。'
|
|
154
|
-
};
|
|
155
|
-
const llm = createMockLLM(mock);
|
|
156
|
-
const result = await loop.execute('需要高质量回答的任务', llm, '系统提示');
|
|
157
|
-
console.log('[Test] 质量达标结果:', result);
|
|
158
|
-
expect(result.exitReason).toBe('quality_threshold_met');
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe('任务复杂度分析', () => {
|
|
162
|
-
it('应该识别简单任务', async () => {
|
|
163
|
-
const loop = new WorkflowPivotLoop(createDefaultPivotConfig('simple'));
|
|
164
|
-
loop.registerTools(mockTools);
|
|
165
|
-
const mock = {
|
|
166
|
-
callCount: 0,
|
|
167
|
-
shouldReturnFinal: true,
|
|
168
|
-
finalResponse: '简单回答'
|
|
169
|
-
};
|
|
170
|
-
const llm = createMockLLM(mock);
|
|
171
|
-
const result = await loop.execute('查看当前时间', llm, '系统提示');
|
|
172
|
-
console.log('[Test] 简单任务结果:', result);
|
|
173
|
-
expect(result.iterations).toBeLessThanOrEqual(15);
|
|
174
|
-
});
|
|
175
|
-
it('应该识别复杂任务', async () => {
|
|
176
|
-
const loop = new WorkflowPivotLoop(createDefaultPivotConfig('complex'));
|
|
177
|
-
loop.registerTools(mockTools);
|
|
178
|
-
const mock = {
|
|
179
|
-
callCount: 0,
|
|
180
|
-
shouldReturnFinal: true,
|
|
181
|
-
finalResponse: '复杂的分析结果'
|
|
182
|
-
};
|
|
183
|
-
const llm = createMockLLM(mock);
|
|
184
|
-
const result = await loop.execute('分析并比较这个项目的所有文档,设计优化方案并实现重构', llm, '系统提示');
|
|
185
|
-
console.log('[Test] 复杂任务结果:', result);
|
|
186
|
-
expect(result.iterations).toBeLessThanOrEqual(60);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
describe('runPivotLoop 快捷函数', () => {
|
|
190
|
-
it('应该使用默认配置运行', async () => {
|
|
191
|
-
const mock = {
|
|
192
|
-
callCount: 0,
|
|
193
|
-
shouldReturnFinal: true,
|
|
194
|
-
finalResponse: '快速回答'
|
|
195
|
-
};
|
|
196
|
-
const llm = createMockLLM(mock);
|
|
197
|
-
const result = await runPivotLoop('查看时间', llm, mockTools, '你是一个助手');
|
|
198
|
-
console.log('[Test] 快捷函数结果:', result);
|
|
199
|
-
expect(result.success).toBe(true);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
describe('状态重置', () => {
|
|
203
|
-
it('应该正确重置状态', async () => {
|
|
204
|
-
const loop = new WorkflowPivotLoop({ maxIterations: 10 });
|
|
205
|
-
loop.registerTools(mockTools);
|
|
206
|
-
const mock = {
|
|
207
|
-
callCount: 0,
|
|
208
|
-
shouldReturnFinal: true,
|
|
209
|
-
finalResponse: '回答'
|
|
210
|
-
};
|
|
211
|
-
const llm = createMockLLM(mock);
|
|
212
|
-
await loop.execute('任务1', llm, '提示');
|
|
213
|
-
const state1 = loop.getState();
|
|
214
|
-
loop.reset();
|
|
215
|
-
const state2 = loop.getState();
|
|
216
|
-
expect(state1.iteration).toBeGreaterThan(0);
|
|
217
|
-
expect(state2.iteration).toBe(0);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
describe('PiSDK PivotLoop Integration', () => {
|
|
222
|
-
it('should export promptWithPivotLoop method', async () => {
|
|
223
|
-
const { createAgentSession } = await import('../agents/pi-sdk.js');
|
|
224
|
-
const session = await createAgentSession({
|
|
225
|
-
cwd: process.cwd(),
|
|
226
|
-
usePivotLoop: true
|
|
227
|
-
});
|
|
228
|
-
expect(typeof session.promptWithPivotLoop).toBe('function');
|
|
229
|
-
});
|
|
230
|
-
it('should use pivot loop when configured', async () => {
|
|
231
|
-
const { createAgentSession } = await import('../agents/pi-sdk.js');
|
|
232
|
-
const session = await createAgentSession({
|
|
233
|
-
cwd: process.cwd(),
|
|
234
|
-
usePivotLoop: true,
|
|
235
|
-
pivotLoopConfig: createDefaultPivotConfig('simple')
|
|
236
|
-
});
|
|
237
|
-
const result = await session.promptWithPivotLoop('你好');
|
|
238
|
-
console.log('[Test] Pivot Loop 集成测试结果:', {
|
|
239
|
-
success: result.success,
|
|
240
|
-
iterations: result.iterations,
|
|
241
|
-
exitReason: result.exitReason
|
|
242
|
-
});
|
|
243
|
-
expect(result).toBeDefined();
|
|
244
|
-
expect(result.exitReason).toBeDefined();
|
|
245
|
-
});
|
|
246
|
-
});
|