opc-agent 3.0.1 → 4.0.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 (216) hide show
  1. package/README.md +404 -74
  2. package/README.zh-CN.md +82 -0
  3. package/dist/channels/dingtalk.d.ts +17 -0
  4. package/dist/channels/dingtalk.js +38 -0
  5. package/dist/channels/googlechat.d.ts +14 -0
  6. package/dist/channels/googlechat.js +37 -0
  7. package/dist/channels/imessage.d.ts +13 -0
  8. package/dist/channels/imessage.js +28 -0
  9. package/dist/channels/irc.d.ts +20 -0
  10. package/dist/channels/irc.js +71 -0
  11. package/dist/channels/line.d.ts +14 -0
  12. package/dist/channels/line.js +28 -0
  13. package/dist/channels/matrix.d.ts +15 -0
  14. package/dist/channels/matrix.js +28 -0
  15. package/dist/channels/mattermost.d.ts +18 -0
  16. package/dist/channels/mattermost.js +49 -0
  17. package/dist/channels/msteams.d.ts +14 -0
  18. package/dist/channels/msteams.js +28 -0
  19. package/dist/channels/nostr.d.ts +14 -0
  20. package/dist/channels/nostr.js +28 -0
  21. package/dist/channels/qq.d.ts +15 -0
  22. package/dist/channels/qq.js +28 -0
  23. package/dist/channels/signal.d.ts +14 -0
  24. package/dist/channels/signal.js +28 -0
  25. package/dist/channels/sms.d.ts +15 -0
  26. package/dist/channels/sms.js +28 -0
  27. package/dist/channels/twitch.d.ts +17 -0
  28. package/dist/channels/twitch.js +59 -0
  29. package/dist/channels/voice-call.d.ts +27 -0
  30. package/dist/channels/voice-call.js +82 -0
  31. package/dist/channels/whatsapp.d.ts +14 -0
  32. package/dist/channels/whatsapp.js +28 -0
  33. package/dist/cli/chat.d.ts +2 -0
  34. package/dist/cli/chat.js +134 -0
  35. package/dist/cli/setup.d.ts +4 -0
  36. package/dist/cli/setup.js +303 -0
  37. package/dist/cli.js +142 -6
  38. package/dist/core/api-server.d.ts +25 -0
  39. package/dist/core/api-server.js +286 -0
  40. package/dist/core/audio.d.ts +50 -0
  41. package/dist/core/audio.js +68 -0
  42. package/dist/core/context-discovery.d.ts +16 -0
  43. package/dist/core/context-discovery.js +107 -0
  44. package/dist/core/context-refs.d.ts +29 -0
  45. package/dist/core/context-refs.js +162 -0
  46. package/dist/core/gateway.d.ts +53 -0
  47. package/dist/core/gateway.js +80 -0
  48. package/dist/core/heartbeat.d.ts +19 -0
  49. package/dist/core/heartbeat.js +50 -0
  50. package/dist/core/hooks.d.ts +28 -0
  51. package/dist/core/hooks.js +82 -0
  52. package/dist/core/ide-bridge.d.ts +53 -0
  53. package/dist/core/ide-bridge.js +97 -0
  54. package/dist/core/node-network.d.ts +23 -0
  55. package/dist/core/node-network.js +77 -0
  56. package/dist/core/profiles.d.ts +27 -0
  57. package/dist/core/profiles.js +131 -0
  58. package/dist/core/sandbox.d.ts +25 -0
  59. package/dist/core/sandbox.js +84 -1
  60. package/dist/core/session-manager.d.ts +33 -0
  61. package/dist/core/session-manager.js +157 -0
  62. package/dist/core/vision.d.ts +45 -0
  63. package/dist/core/vision.js +177 -0
  64. package/dist/hub/brain-seed.d.ts +14 -0
  65. package/dist/hub/brain-seed.js +77 -0
  66. package/dist/hub/client.d.ts +25 -0
  67. package/dist/hub/client.js +44 -0
  68. package/dist/index.d.ts +66 -1
  69. package/dist/index.js +95 -3
  70. package/dist/memory/context-compressor.d.ts +43 -0
  71. package/dist/memory/context-compressor.js +167 -0
  72. package/dist/memory/index.d.ts +4 -0
  73. package/dist/memory/index.js +5 -1
  74. package/dist/memory/user-profiler.d.ts +50 -0
  75. package/dist/memory/user-profiler.js +201 -0
  76. package/dist/providers/index.d.ts +1 -1
  77. package/dist/providers/index.js +54 -1
  78. package/dist/scheduler/cron-engine.d.ts +41 -0
  79. package/dist/scheduler/cron-engine.js +200 -0
  80. package/dist/scheduler/index.d.ts +3 -0
  81. package/dist/scheduler/index.js +7 -0
  82. package/dist/schema/oad.d.ts +12 -12
  83. package/dist/security/approvals.d.ts +53 -0
  84. package/dist/security/approvals.js +115 -0
  85. package/dist/security/elevated.d.ts +41 -0
  86. package/dist/security/elevated.js +89 -0
  87. package/dist/security/index.d.ts +6 -0
  88. package/dist/security/index.js +7 -1
  89. package/dist/security/secrets.d.ts +34 -0
  90. package/dist/security/secrets.js +115 -0
  91. package/dist/skills/builtin/index.d.ts +6 -0
  92. package/dist/skills/builtin/index.js +402 -0
  93. package/dist/skills/marketplace.d.ts +30 -0
  94. package/dist/skills/marketplace.js +142 -0
  95. package/dist/skills/types.d.ts +34 -0
  96. package/dist/skills/types.js +16 -0
  97. package/dist/studio/server.d.ts +25 -0
  98. package/dist/studio/server.js +780 -0
  99. package/dist/studio/templates-data.d.ts +21 -0
  100. package/dist/studio/templates-data.js +148 -0
  101. package/dist/studio-ui/index.html +2502 -1073
  102. package/dist/tools/builtin/browser.d.ts +47 -0
  103. package/dist/tools/builtin/browser.js +284 -0
  104. package/dist/tools/builtin/home-assistant.d.ts +12 -0
  105. package/dist/tools/builtin/home-assistant.js +126 -0
  106. package/dist/tools/builtin/index.d.ts +7 -1
  107. package/dist/tools/builtin/index.js +23 -2
  108. package/dist/tools/builtin/rl-tools.d.ts +13 -0
  109. package/dist/tools/builtin/rl-tools.js +228 -0
  110. package/dist/tools/builtin/vision.d.ts +6 -0
  111. package/dist/tools/builtin/vision.js +61 -0
  112. package/dist/tools/builtin/web-search.d.ts +9 -0
  113. package/dist/tools/builtin/web-search.js +150 -0
  114. package/dist/tools/document-processor.d.ts +39 -0
  115. package/dist/tools/document-processor.js +188 -0
  116. package/dist/tools/image-generator.d.ts +42 -0
  117. package/dist/tools/image-generator.js +136 -0
  118. package/dist/tools/web-scraper.d.ts +20 -0
  119. package/dist/tools/web-scraper.js +148 -0
  120. package/dist/tools/web-search.d.ts +51 -0
  121. package/dist/tools/web-search.js +152 -0
  122. package/install.ps1 +154 -0
  123. package/install.sh +164 -0
  124. package/package.json +63 -52
  125. package/src/channels/dingtalk.ts +46 -0
  126. package/src/channels/googlechat.ts +42 -0
  127. package/src/channels/imessage.ts +32 -0
  128. package/src/channels/irc.ts +82 -0
  129. package/src/channels/line.ts +33 -0
  130. package/src/channels/matrix.ts +34 -0
  131. package/src/channels/mattermost.ts +57 -0
  132. package/src/channels/msteams.ts +33 -0
  133. package/src/channels/nostr.ts +33 -0
  134. package/src/channels/qq.ts +34 -0
  135. package/src/channels/signal.ts +33 -0
  136. package/src/channels/sms.ts +34 -0
  137. package/src/channels/twitch.ts +65 -0
  138. package/src/channels/voice-call.ts +100 -0
  139. package/src/channels/whatsapp.ts +33 -0
  140. package/src/cli/chat.ts +99 -0
  141. package/src/cli/setup.ts +314 -0
  142. package/src/cli.ts +148 -6
  143. package/src/core/api-server.ts +277 -0
  144. package/src/core/audio.ts +98 -0
  145. package/src/core/context-discovery.ts +85 -0
  146. package/src/core/context-refs.ts +140 -0
  147. package/src/core/gateway.ts +106 -0
  148. package/src/core/heartbeat.ts +51 -0
  149. package/src/core/hooks.ts +105 -0
  150. package/src/core/ide-bridge.ts +133 -0
  151. package/src/core/node-network.ts +86 -0
  152. package/src/core/profiles.ts +122 -0
  153. package/src/core/sandbox.ts +100 -0
  154. package/src/core/session-manager.ts +137 -0
  155. package/src/core/vision.ts +180 -0
  156. package/src/hub/brain-seed.ts +54 -0
  157. package/src/hub/client.ts +60 -0
  158. package/src/index.ts +86 -1
  159. package/src/memory/context-compressor.ts +189 -0
  160. package/src/memory/index.ts +4 -0
  161. package/src/memory/user-profiler.ts +215 -0
  162. package/src/providers/index.ts +64 -1
  163. package/src/scheduler/cron-engine.ts +191 -0
  164. package/src/scheduler/index.ts +2 -0
  165. package/src/security/approvals.ts +143 -0
  166. package/src/security/elevated.ts +105 -0
  167. package/src/security/index.ts +6 -0
  168. package/src/security/secrets.ts +129 -0
  169. package/src/skills/builtin/index.ts +408 -0
  170. package/src/skills/marketplace.ts +113 -0
  171. package/src/skills/types.ts +42 -0
  172. package/src/studio/server.ts +1591 -791
  173. package/src/studio/templates-data.ts +178 -0
  174. package/src/studio-ui/index.html +2502 -1073
  175. package/src/tools/builtin/browser.ts +299 -0
  176. package/src/tools/builtin/home-assistant.ts +116 -0
  177. package/src/tools/builtin/index.ts +37 -28
  178. package/src/tools/builtin/rl-tools.ts +243 -0
  179. package/src/tools/builtin/vision.ts +64 -0
  180. package/src/tools/builtin/web-search.ts +126 -0
  181. package/src/tools/document-processor.ts +213 -0
  182. package/src/tools/image-generator.ts +150 -0
  183. package/src/tools/web-scraper.ts +179 -0
  184. package/src/tools/web-search.ts +180 -0
  185. package/tests/api-server.test.ts +148 -0
  186. package/tests/approvals.test.ts +89 -0
  187. package/tests/audio.test.ts +40 -0
  188. package/tests/browser.test.ts +179 -0
  189. package/tests/builtin-tools.test.ts +83 -83
  190. package/tests/channels-extra.test.ts +45 -0
  191. package/tests/context-compressor.test.ts +172 -0
  192. package/tests/context-refs.test.ts +121 -0
  193. package/tests/cron-engine.test.ts +101 -0
  194. package/tests/document-processor.test.ts +69 -0
  195. package/tests/e2e-nocode.test.ts +442 -0
  196. package/tests/elevated.test.ts +69 -0
  197. package/tests/gateway.test.ts +63 -71
  198. package/tests/home-assistant.test.ts +40 -0
  199. package/tests/hooks.test.ts +79 -0
  200. package/tests/ide-bridge.test.ts +38 -0
  201. package/tests/image-generator.test.ts +84 -0
  202. package/tests/node-network.test.ts +74 -0
  203. package/tests/profiles.test.ts +61 -0
  204. package/tests/rl-tools.test.ts +93 -0
  205. package/tests/sandbox-manager.test.ts +46 -0
  206. package/tests/secrets.test.ts +107 -0
  207. package/tests/settings-api.test.ts +148 -0
  208. package/tests/setup.test.ts +73 -0
  209. package/tests/studio.test.ts +402 -229
  210. package/tests/tools/builtin-extended.test.ts +138 -138
  211. package/tests/user-profiler.test.ts +169 -0
  212. package/tests/v090-features.test.ts +254 -0
  213. package/tests/vision.test.ts +61 -0
  214. package/tests/voice-call.test.ts +47 -0
  215. package/tests/voice-interaction.test.ts +38 -0
  216. package/tests/web-search.test.ts +155 -0
@@ -0,0 +1,148 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import * as fs from 'fs';
3
+ import * as path from 'path';
4
+
5
+ describe('Settings API & UI', () => {
6
+ describe('Backend - server.ts settings routes', () => {
7
+ const serverSrc = fs.readFileSync(path.join(__dirname, '../src/studio/server.ts'), 'utf-8');
8
+
9
+ it('has settings/models GET route', () => {
10
+ expect(serverSrc).toContain("route === 'settings/models' && req.method === 'GET'");
11
+ });
12
+
13
+ it('has settings/models PUT route', () => {
14
+ expect(serverSrc).toContain("route === 'settings/models' && req.method === 'PUT'");
15
+ });
16
+
17
+ it('has settings/models/test POST route', () => {
18
+ expect(serverSrc).toContain("route === 'settings/models/test' && req.method === 'POST'");
19
+ });
20
+
21
+ it('has settings/models/local GET route', () => {
22
+ expect(serverSrc).toContain("route === 'settings/models/local' && req.method === 'GET'");
23
+ });
24
+
25
+ it('has settings/channels GET route', () => {
26
+ expect(serverSrc).toContain("route === 'settings/channels' && req.method === 'GET'");
27
+ });
28
+
29
+ it('has settings/channels/:name PUT route', () => {
30
+ expect(serverSrc).toContain("settings\\/channels\\/[^/]+");
31
+ });
32
+
33
+ it('has settings/status GET route', () => {
34
+ expect(serverSrc).toContain("route === 'settings/status' && req.method === 'GET'");
35
+ });
36
+
37
+ it('has settings/usage GET route', () => {
38
+ expect(serverSrc).toContain("route === 'settings/usage' && req.method === 'GET'");
39
+ });
40
+
41
+ it('has detectLocalOllama method', () => {
42
+ expect(serverSrc).toContain('detectLocalOllama');
43
+ });
44
+
45
+ it('has testModelConnection method', () => {
46
+ expect(serverSrc).toContain('testModelConnection');
47
+ });
48
+
49
+ it('saves config to ~/.opc/config.json', () => {
50
+ expect(serverSrc).toContain("'.opc'");
51
+ expect(serverSrc).toContain("'config.json'");
52
+ });
53
+ });
54
+
55
+ describe('Frontend - index.html settings UI', () => {
56
+ const html = fs.readFileSync(path.join(__dirname, '../src/studio-ui/index.html'), 'utf-8');
57
+
58
+ it('has settings page container', () => {
59
+ expect(html).toContain('id="page-settings"');
60
+ });
61
+
62
+ it('has settings navigation items', () => {
63
+ expect(html).toContain('data-settings="models"');
64
+ expect(html).toContain('data-settings="channels"');
65
+ expect(html).toContain('data-settings="memory"');
66
+ expect(html).toContain('data-settings="role"');
67
+ expect(html).toContain('data-settings="status"');
68
+ expect(html).toContain('data-settings="usage"');
69
+ });
70
+
71
+ it('has models panel with local/cloud tabs', () => {
72
+ expect(html).toContain('id="sp-models"');
73
+ expect(html).toContain('id="mt-local"');
74
+ expect(html).toContain('id="mt-cloud"');
75
+ });
76
+
77
+ it('has Ollama detection UI', () => {
78
+ expect(html).toContain('id="ollama-status"');
79
+ expect(html).toContain('id="ollama-models"');
80
+ expect(html).toContain('id="ollama-tutorial"');
81
+ expect(html).toContain('ollama.com');
82
+ });
83
+
84
+ it('has cloud provider cards', () => {
85
+ expect(html).toContain('pv-openai');
86
+ expect(html).toContain('pv-deepseek');
87
+ expect(html).toContain('pv-anthropic');
88
+ });
89
+
90
+ it('has model assignment dropdowns', () => {
91
+ expect(html).toContain('id="cfg-chat-model"');
92
+ expect(html).toContain('id="cfg-embed-model"');
93
+ expect(html).toContain('qwen2.5:7b');
94
+ expect(html).toContain('nomic-embed-text');
95
+ });
96
+
97
+ it('has channels panel', () => {
98
+ expect(html).toContain('id="sp-channels"');
99
+ expect(html).toContain('id="channels-grid"');
100
+ });
101
+
102
+ it('has memory panel with DeepBrain iframe reference', () => {
103
+ expect(html).toContain('id="sp-memory"');
104
+ expect(html).toContain('localhost:4001');
105
+ expect(html).toContain('DeepBrain');
106
+ });
107
+
108
+ it('has role panel with Workstation iframe reference', () => {
109
+ expect(html).toContain('id="sp-role"');
110
+ expect(html).toContain('localhost:4003');
111
+ expect(html).toContain('Workstation');
112
+ });
113
+
114
+ it('has status panel with logs viewer', () => {
115
+ expect(html).toContain('id="sp-status"');
116
+ expect(html).toContain('id="status-logs"');
117
+ });
118
+
119
+ it('has usage panel', () => {
120
+ expect(html).toContain('id="sp-usage"');
121
+ expect(html).toContain('id="usage-stats"');
122
+ });
123
+
124
+ it('has provider config dialog', () => {
125
+ expect(html).toContain('id="provider-dialog"');
126
+ expect(html).toContain('id="pd-apikey"');
127
+ expect(html).toContain('testProvider');
128
+ });
129
+
130
+ it('has channel config dialog', () => {
131
+ expect(html).toContain('id="channel-dialog"');
132
+ });
133
+
134
+ it('has settings nav in sidebar', () => {
135
+ expect(html).toContain('data-page="settings"');
136
+ expect(html).toContain('Settings');
137
+ });
138
+
139
+ it('has Chinese-friendly copy', () => {
140
+ expect(html).toContain('模型配置');
141
+ expect(html).toContain('渠道配置');
142
+ expect(html).toContain('记忆管理');
143
+ expect(html).toContain('角色编辑');
144
+ expect(html).toContain('运行状态');
145
+ expect(html).toContain('用量统计');
146
+ });
147
+ });
148
+ });
@@ -0,0 +1,73 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { Readable, Writable } from 'stream';
3
+ import * as fs from 'fs';
4
+ import * as path from 'path';
5
+ import * as os from 'os';
6
+
7
+ // Mock http to control Ollama detection
8
+ vi.mock('http', async () => {
9
+ const actual = await vi.importActual<typeof import('http')>('http');
10
+ return { ...actual };
11
+ });
12
+
13
+ describe('setup wizard', () => {
14
+ const OPC_HOME = path.join(os.tmpdir(), `.opc-test-${Date.now()}`);
15
+ const CONFIG_PATH = path.join(OPC_HOME, 'config.json');
16
+
17
+ beforeEach(() => {
18
+ // Override HOME so setup writes to temp
19
+ vi.stubEnv('HOME', os.tmpdir());
20
+ fs.mkdirSync(OPC_HOME, { recursive: true });
21
+ });
22
+
23
+ afterEach(() => {
24
+ fs.rmSync(OPC_HOME, { recursive: true, force: true });
25
+ vi.unstubAllEnvs();
26
+ });
27
+
28
+ function createMockInput(lines: string[]): Readable {
29
+ const input = new Readable({ read() {} });
30
+ // Push lines async to simulate user typing
31
+ let i = 0;
32
+ const interval = setInterval(() => {
33
+ if (i < lines.length) {
34
+ input.push(lines[i] + '\n');
35
+ i++;
36
+ } else {
37
+ input.push(null);
38
+ clearInterval(interval);
39
+ }
40
+ }, 50);
41
+ return input;
42
+ }
43
+
44
+ function createMockOutput(): Writable {
45
+ const chunks: Buffer[] = [];
46
+ const output = new Writable({
47
+ write(chunk, _enc, cb) { chunks.push(Buffer.from(chunk)); cb(); },
48
+ });
49
+ (output as any).getOutput = () => Buffer.concat(chunks).toString();
50
+ return output;
51
+ }
52
+
53
+ it('should export runSetup function', async () => {
54
+ const { runSetup } = await import('../src/cli/setup');
55
+ expect(typeof runSetup).toBe('function');
56
+ });
57
+
58
+ it('should have TEMPLATES defined', async () => {
59
+ // Just test that the module loads without error
60
+ const mod = await import('../src/cli/setup');
61
+ expect(mod).toBeDefined();
62
+ });
63
+
64
+ it('createRL should return a readline interface', async () => {
65
+ const { createRL } = await import('../src/cli/setup');
66
+ const input = new Readable({ read() {} });
67
+ const output = createMockOutput();
68
+ const rl = createRL(input, output);
69
+ expect(rl).toBeDefined();
70
+ rl.close();
71
+ input.destroy();
72
+ });
73
+ });