openclaw-overlay-plugin 0.8.14 → 0.8.16

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 (190) hide show
  1. package/dist/index.js +6705 -326
  2. package/dist/index.js.map +7 -0
  3. package/dist/src/cli.js +7498 -11
  4. package/dist/src/cli.js.map +7 -0
  5. package/index.ts +1 -1
  6. package/openclaw.plugin.json +1 -1
  7. package/package.json +8 -8
  8. package/src/scripts/messaging/handlers.ts +1 -1
  9. package/src/scripts/overlay/advertisement.ts +1 -1
  10. package/src/scripts/overlay/registration.ts +1 -1
  11. package/src/scripts/overlay/services.ts +1 -1
  12. package/src/scripts/overlay/transaction.ts +1 -1
  13. package/src/scripts/payment/build.ts +1 -1
  14. package/src/scripts/payment/commands.ts +1 -1
  15. package/src/scripts/wallet/balance.ts +1 -1
  16. package/src/scripts/wallet/setup.ts +1 -1
  17. package/src/test/identity-consistency.test.ts +1 -1
  18. package/src/test/wallet.test.ts +1 -2
  19. package/dist/index.d.ts +0 -9
  20. package/dist/src/cli-main.d.ts +0 -7
  21. package/dist/src/cli-main.js +0 -202
  22. package/dist/src/cli.d.ts +0 -8
  23. package/dist/src/compatibility.test.d.ts +0 -4
  24. package/dist/src/compatibility.test.js +0 -41
  25. package/dist/src/core/config.d.ts +0 -11
  26. package/dist/src/core/config.js +0 -15
  27. package/dist/src/core/index.d.ts +0 -25
  28. package/dist/src/core/index.js +0 -26
  29. package/dist/src/core/payment.d.ts +0 -16
  30. package/dist/src/core/payment.js +0 -94
  31. package/dist/src/core/types.d.ts +0 -94
  32. package/dist/src/core/types.js +0 -4
  33. package/dist/src/core/verify.d.ts +0 -28
  34. package/dist/src/core/verify.js +0 -104
  35. package/dist/src/core/wallet.d.ts +0 -105
  36. package/dist/src/core/wallet.js +0 -256
  37. package/dist/src/scripts/baemail/commands.d.ts +0 -35
  38. package/dist/src/scripts/baemail/commands.js +0 -282
  39. package/dist/src/scripts/baemail/handler.d.ts +0 -36
  40. package/dist/src/scripts/baemail/handler.js +0 -284
  41. package/dist/src/scripts/baemail/index.d.ts +0 -5
  42. package/dist/src/scripts/baemail/index.js +0 -5
  43. package/dist/src/scripts/config.d.ts +0 -52
  44. package/dist/src/scripts/config.js +0 -75
  45. package/dist/src/scripts/index.d.ts +0 -7
  46. package/dist/src/scripts/index.js +0 -7
  47. package/dist/src/scripts/messaging/connect.d.ts +0 -8
  48. package/dist/src/scripts/messaging/connect.js +0 -168
  49. package/dist/src/scripts/messaging/handlers.d.ts +0 -21
  50. package/dist/src/scripts/messaging/handlers.js +0 -334
  51. package/dist/src/scripts/messaging/inbox.d.ts +0 -11
  52. package/dist/src/scripts/messaging/inbox.js +0 -51
  53. package/dist/src/scripts/messaging/index.d.ts +0 -8
  54. package/dist/src/scripts/messaging/index.js +0 -8
  55. package/dist/src/scripts/messaging/poll.d.ts +0 -7
  56. package/dist/src/scripts/messaging/poll.js +0 -52
  57. package/dist/src/scripts/messaging/send.d.ts +0 -7
  58. package/dist/src/scripts/messaging/send.js +0 -43
  59. package/dist/src/scripts/output.d.ts +0 -13
  60. package/dist/src/scripts/output.js +0 -28
  61. package/dist/src/scripts/overlay/advertisement.d.ts +0 -16
  62. package/dist/src/scripts/overlay/advertisement.js +0 -122
  63. package/dist/src/scripts/overlay/discover.d.ts +0 -7
  64. package/dist/src/scripts/overlay/discover.js +0 -74
  65. package/dist/src/scripts/overlay/index.d.ts +0 -7
  66. package/dist/src/scripts/overlay/index.js +0 -7
  67. package/dist/src/scripts/overlay/registration.d.ts +0 -19
  68. package/dist/src/scripts/overlay/registration.js +0 -176
  69. package/dist/src/scripts/overlay/services.d.ts +0 -29
  70. package/dist/src/scripts/overlay/services.js +0 -167
  71. package/dist/src/scripts/overlay/transaction.d.ts +0 -42
  72. package/dist/src/scripts/overlay/transaction.js +0 -103
  73. package/dist/src/scripts/payment/build.d.ts +0 -24
  74. package/dist/src/scripts/payment/build.js +0 -54
  75. package/dist/src/scripts/payment/commands.d.ts +0 -15
  76. package/dist/src/scripts/payment/commands.js +0 -73
  77. package/dist/src/scripts/payment/index.d.ts +0 -6
  78. package/dist/src/scripts/payment/index.js +0 -6
  79. package/dist/src/scripts/payment/types.d.ts +0 -56
  80. package/dist/src/scripts/payment/types.js +0 -4
  81. package/dist/src/scripts/services/index.d.ts +0 -6
  82. package/dist/src/scripts/services/index.js +0 -6
  83. package/dist/src/scripts/services/queue.d.ts +0 -11
  84. package/dist/src/scripts/services/queue.js +0 -28
  85. package/dist/src/scripts/services/request.d.ts +0 -7
  86. package/dist/src/scripts/services/request.js +0 -82
  87. package/dist/src/scripts/services/respond.d.ts +0 -11
  88. package/dist/src/scripts/services/respond.js +0 -132
  89. package/dist/src/scripts/types.d.ts +0 -107
  90. package/dist/src/scripts/types.js +0 -4
  91. package/dist/src/scripts/utils/index.d.ts +0 -6
  92. package/dist/src/scripts/utils/index.js +0 -6
  93. package/dist/src/scripts/utils/merkle.d.ts +0 -12
  94. package/dist/src/scripts/utils/merkle.js +0 -47
  95. package/dist/src/scripts/utils/storage.d.ts +0 -66
  96. package/dist/src/scripts/utils/storage.js +0 -211
  97. package/dist/src/scripts/utils/woc.d.ts +0 -26
  98. package/dist/src/scripts/utils/woc.js +0 -91
  99. package/dist/src/scripts/wallet/balance.d.ts +0 -22
  100. package/dist/src/scripts/wallet/balance.js +0 -240
  101. package/dist/src/scripts/wallet/identity.d.ts +0 -71
  102. package/dist/src/scripts/wallet/identity.js +0 -152
  103. package/dist/src/scripts/wallet/index.d.ts +0 -6
  104. package/dist/src/scripts/wallet/index.js +0 -6
  105. package/dist/src/scripts/wallet/setup.d.ts +0 -19
  106. package/dist/src/scripts/wallet/setup.js +0 -119
  107. package/dist/src/scripts/x-verification/commands.d.ts +0 -27
  108. package/dist/src/scripts/x-verification/commands.js +0 -222
  109. package/dist/src/scripts/x-verification/index.d.ts +0 -4
  110. package/dist/src/scripts/x-verification/index.js +0 -4
  111. package/dist/src/services/built-in/api-proxy/index.d.ts +0 -6
  112. package/dist/src/services/built-in/api-proxy/index.js +0 -23
  113. package/dist/src/services/built-in/code-develop/index.d.ts +0 -6
  114. package/dist/src/services/built-in/code-develop/index.js +0 -23
  115. package/dist/src/services/built-in/code-review/index.d.ts +0 -10
  116. package/dist/src/services/built-in/code-review/index.js +0 -51
  117. package/dist/src/services/built-in/image-analysis/index.d.ts +0 -6
  118. package/dist/src/services/built-in/image-analysis/index.js +0 -33
  119. package/dist/src/services/built-in/memory-store/index.d.ts +0 -6
  120. package/dist/src/services/built-in/memory-store/index.js +0 -22
  121. package/dist/src/services/built-in/roulette/index.d.ts +0 -6
  122. package/dist/src/services/built-in/roulette/index.js +0 -27
  123. package/dist/src/services/built-in/summarize/index.d.ts +0 -6
  124. package/dist/src/services/built-in/summarize/index.js +0 -21
  125. package/dist/src/services/built-in/tell-joke/handler.d.ts +0 -7
  126. package/dist/src/services/built-in/tell-joke/handler.js +0 -122
  127. package/dist/src/services/built-in/tell-joke/index.d.ts +0 -9
  128. package/dist/src/services/built-in/tell-joke/index.js +0 -31
  129. package/dist/src/services/built-in/translate/index.d.ts +0 -6
  130. package/dist/src/services/built-in/translate/index.js +0 -21
  131. package/dist/src/services/built-in/web-research/index.d.ts +0 -9
  132. package/dist/src/services/built-in/web-research/index.js +0 -51
  133. package/dist/src/services/index.d.ts +0 -13
  134. package/dist/src/services/index.js +0 -14
  135. package/dist/src/services/loader.d.ts +0 -77
  136. package/dist/src/services/loader.js +0 -292
  137. package/dist/src/services/manager.d.ts +0 -86
  138. package/dist/src/services/manager.js +0 -255
  139. package/dist/src/services/registry.d.ts +0 -98
  140. package/dist/src/services/registry.js +0 -204
  141. package/dist/src/services/types.d.ts +0 -230
  142. package/dist/src/services/types.js +0 -30
  143. package/dist/src/test/cli.test.d.ts +0 -7
  144. package/dist/src/test/cli.test.js +0 -330
  145. package/dist/src/test/comprehensive-overlay.test.d.ts +0 -13
  146. package/dist/src/test/comprehensive-overlay.test.js +0 -593
  147. package/dist/src/test/identity-consistency.test.d.ts +0 -6
  148. package/dist/src/test/identity-consistency.test.js +0 -60
  149. package/dist/src/test/key-derivation.test.d.ts +0 -12
  150. package/dist/src/test/key-derivation.test.js +0 -86
  151. package/dist/src/test/network-address.test.d.ts +0 -9
  152. package/dist/src/test/network-address.test.js +0 -37
  153. package/dist/src/test/overlay-submit.test.d.ts +0 -10
  154. package/dist/src/test/overlay-submit.test.js +0 -460
  155. package/dist/src/test/request-response-flow.test.d.ts +0 -5
  156. package/dist/src/test/request-response-flow.test.js +0 -210
  157. package/dist/src/test/service-system.test.d.ts +0 -5
  158. package/dist/src/test/service-system.test.js +0 -190
  159. package/dist/src/test/taskflow.test.d.ts +0 -7
  160. package/dist/src/test/taskflow.test.js +0 -82
  161. package/dist/src/test/utils/server-logic.d.ts +0 -98
  162. package/dist/src/test/utils/server-logic.js +0 -286
  163. package/dist/src/test/wallet.test.d.ts +0 -7
  164. package/dist/src/test/wallet.test.js +0 -146
  165. package/src/core/README.md +0 -246
  166. package/src/core/config.d.ts +0 -12
  167. package/src/core/config.d.ts.map +0 -1
  168. package/src/core/config.js +0 -14
  169. package/src/core/config.js.map +0 -1
  170. package/src/core/config.ts +0 -22
  171. package/src/core/index.ts +0 -42
  172. package/src/core/payment.d.ts +0 -17
  173. package/src/core/payment.d.ts.map +0 -1
  174. package/src/core/payment.js +0 -95
  175. package/src/core/payment.js.map +0 -1
  176. package/src/core/payment.ts +0 -111
  177. package/src/core/types.d.ts +0 -95
  178. package/src/core/types.d.ts.map +0 -1
  179. package/src/core/types.js +0 -5
  180. package/src/core/types.js.map +0 -1
  181. package/src/core/types.ts +0 -102
  182. package/src/core/verify.d.ts +0 -29
  183. package/src/core/verify.d.ts.map +0 -1
  184. package/src/core/verify.js +0 -105
  185. package/src/core/verify.js.map +0 -1
  186. package/src/core/verify.ts +0 -119
  187. package/src/core/wallet.d.ts +0 -100
  188. package/src/core/wallet.d.ts.map +0 -1
  189. package/src/core/wallet.js.map +0 -1
  190. package/src/core/wallet.ts +0 -323
@@ -1,210 +0,0 @@
1
- /**
2
- * Tests for request/response flow and duplicate prevention.
3
- */
4
- import fs from 'node:fs';
5
- import path from 'node:path';
6
- import process from 'node:process';
7
- // Simple test runner (matching existing pattern)
8
- let passed = 0;
9
- let failed = 0;
10
- function test(name, fn) {
11
- return (async () => {
12
- try {
13
- await fn();
14
- console.log(` ✓ ${name}`);
15
- passed++;
16
- }
17
- catch (err) {
18
- const msg = err instanceof Error ? err.message : String(err);
19
- console.log(` ✗ ${name}`);
20
- console.log(` ${msg}`);
21
- failed++;
22
- }
23
- })();
24
- }
25
- function assert(condition, message) {
26
- if (!condition)
27
- throw new Error(`Assertion failed: ${message}`);
28
- }
29
- // Mock paths for testing
30
- const TEST_DIR = path.join(process.cwd(), 'test-data');
31
- const TEST_PATHS = {
32
- serviceQueue: path.join(TEST_DIR, 'service-queue.jsonl'),
33
- walletDir: path.join(TEST_DIR, 'wallet'),
34
- registration: path.join(TEST_DIR, 'registration.json'),
35
- services: path.join(TEST_DIR, 'services.json'),
36
- };
37
- function setupTestEnv() {
38
- // Setup test directory
39
- if (fs.existsSync(TEST_DIR)) {
40
- fs.rmSync(TEST_DIR, { recursive: true, force: true });
41
- }
42
- fs.mkdirSync(TEST_DIR, { recursive: true });
43
- }
44
- function cleanupTestEnv() {
45
- if (fs.existsSync(TEST_DIR)) {
46
- fs.rmSync(TEST_DIR, { recursive: true, force: true });
47
- }
48
- }
49
- async function run() {
50
- console.log('\nRequest/Response Flow Tests\n');
51
- // ── Queue Cleanup Tests ──────────────────────────────────────────────
52
- await test('cleanupServiceQueue removes old fulfilled entries', async () => {
53
- setupTestEnv();
54
- const now = Date.now();
55
- const oldTime = now - (3 * 60 * 60 * 1000); // 3 hours ago
56
- const recentTime = now - (30 * 60 * 1000); // 30 minutes ago
57
- // Add test entries
58
- const entries = [
59
- { status: 'pending', requestId: 'pending-1', _ts: recentTime },
60
- { status: 'fulfilled', requestId: 'old-fulfilled', _ts: oldTime },
61
- { status: 'fulfilled', requestId: 'recent-fulfilled', _ts: recentTime },
62
- { status: 'rejected', requestId: 'old-rejected', _ts: oldTime }
63
- ];
64
- const content = entries.map(e => JSON.stringify(e)).join('\n') + '\n';
65
- fs.writeFileSync(TEST_PATHS.serviceQueue, content);
66
- // Mock PATHS for cleanupServiceQueue
67
- const originalPaths = await import('../scripts/config.js');
68
- const mockPaths = { ...originalPaths.PATHS, serviceQueue: TEST_PATHS.serviceQueue };
69
- // Temporarily replace PATHS
70
- globalThis.mockPaths = mockPaths;
71
- // Redefine cleanupServiceQueue with mocked paths
72
- function mockCleanupServiceQueue(maxAgeMs = 24 * 60 * 60 * 1000, finalStatusMaxAgeMs = 2 * 60 * 60 * 1000) {
73
- if (!fs.existsSync(TEST_PATHS.serviceQueue))
74
- return;
75
- const currentTime = Date.now();
76
- const finalStatuses = ['fulfilled', 'rejected', 'delivery_failed', 'failed', 'error'];
77
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
78
- const keptLines = [];
79
- let removedCount = 0;
80
- for (const line of lines) {
81
- try {
82
- const entry = JSON.parse(line);
83
- const entryAge = currentTime - (entry._ts || 0);
84
- // Always keep pending entries that aren't too old
85
- if (entry.status === 'pending' && entryAge < maxAgeMs) {
86
- keptLines.push(line);
87
- continue;
88
- }
89
- // Keep final status entries only if they're recent
90
- if (finalStatuses.includes(entry.status) && entryAge < finalStatusMaxAgeMs) {
91
- keptLines.push(line);
92
- continue;
93
- }
94
- // Remove this entry
95
- removedCount++;
96
- }
97
- catch {
98
- // Keep malformed entries to avoid data loss
99
- keptLines.push(line);
100
- }
101
- }
102
- if (removedCount > 0) {
103
- fs.writeFileSync(TEST_PATHS.serviceQueue, keptLines.join('\n') + (keptLines.length ? '\n' : ''));
104
- }
105
- }
106
- // Run cleanup with 2 hour limit for final statuses
107
- mockCleanupServiceQueue(24 * 60 * 60 * 1000, 2 * 60 * 60 * 1000);
108
- // Check remaining entries
109
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
110
- const remaining = lines.map((line) => JSON.parse(line));
111
- assert(remaining.length === 2, `Expected 2 remaining entries, got ${remaining.length}`);
112
- assert(remaining.find((e) => e.requestId === 'pending-1') !== undefined, 'Should keep recent pending');
113
- assert(remaining.find((e) => e.requestId === 'recent-fulfilled') !== undefined, 'Should keep recent fulfilled');
114
- assert(remaining.find((e) => e.requestId === 'old-fulfilled') === undefined, 'Should remove old fulfilled');
115
- assert(remaining.find((e) => e.requestId === 'old-rejected') === undefined, 'Should remove old rejected');
116
- cleanupTestEnv();
117
- });
118
- await test('updateServiceQueueStatus updates request status atomically', async () => {
119
- setupTestEnv();
120
- // Add a test entry
121
- const entry = {
122
- status: 'pending',
123
- requestId: 'test-request-456',
124
- serviceId: 'test-service',
125
- from: 'sender-key',
126
- _ts: Date.now()
127
- };
128
- fs.writeFileSync(TEST_PATHS.serviceQueue, JSON.stringify(entry) + '\n');
129
- // Mock updateServiceQueueStatus with test paths
130
- function mockUpdateServiceQueueStatus(requestId, newStatus, additionalFields = {}) {
131
- if (!fs.existsSync(TEST_PATHS.serviceQueue))
132
- return false;
133
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
134
- let updated = false;
135
- const updatedLines = lines.map((line) => {
136
- try {
137
- const entryData = JSON.parse(line);
138
- if (entryData.requestId === requestId) {
139
- updated = true;
140
- return JSON.stringify({
141
- ...entryData,
142
- status: newStatus,
143
- ...additionalFields,
144
- updatedAt: Date.now()
145
- });
146
- }
147
- return line;
148
- }
149
- catch {
150
- return line;
151
- }
152
- });
153
- if (updated) {
154
- fs.writeFileSync(TEST_PATHS.serviceQueue, updatedLines.join('\n') + '\n');
155
- }
156
- return updated;
157
- }
158
- // Update status
159
- const updated = mockUpdateServiceQueueStatus('test-request-456', 'fulfilled', {
160
- fulfilledAt: Date.now(),
161
- result: { message: 'success' }
162
- });
163
- assert(updated === true, 'Should return true for successful update');
164
- // Verify update
165
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
166
- const updatedEntry = JSON.parse(lines[0]);
167
- assert(updatedEntry.status === 'fulfilled', 'Status should be updated to fulfilled');
168
- assert(updatedEntry.requestId === 'test-request-456', 'Request ID should remain the same');
169
- assert(updatedEntry.fulfilledAt !== undefined, 'Should have fulfilledAt timestamp');
170
- assert(updatedEntry.updatedAt !== undefined, 'Should have updatedAt timestamp');
171
- assert(updatedEntry.result?.message === 'success', 'Should have result data');
172
- cleanupTestEnv();
173
- });
174
- await test('updateServiceQueueStatus returns false for non-existent request', async () => {
175
- setupTestEnv();
176
- // Mock updateServiceQueueStatus with test paths
177
- function mockUpdateServiceQueueStatus(requestId, _newStatus) {
178
- if (!fs.existsSync(TEST_PATHS.serviceQueue))
179
- return false;
180
- const lines = fs.readFileSync(TEST_PATHS.serviceQueue, 'utf-8').trim().split('\n').filter(Boolean);
181
- let updated = false;
182
- lines.map((line) => {
183
- try {
184
- const entry = JSON.parse(line);
185
- if (entry.requestId === requestId) {
186
- updated = true;
187
- }
188
- return line;
189
- }
190
- catch {
191
- return line;
192
- }
193
- });
194
- return updated;
195
- }
196
- const updated = mockUpdateServiceQueueStatus('non-existent-request', 'fulfilled');
197
- assert(updated === false, 'Should return false for non-existent request');
198
- cleanupTestEnv();
199
- });
200
- // ── Summary ──────────────────────────────────────────────────────────
201
- console.log(`\n${passed} passed, ${failed} failed\n`);
202
- if (failed > 0) {
203
- process.exit(1);
204
- }
205
- }
206
- // Run tests if this file is executed directly
207
- if (import.meta.url === `file://${process.argv[1]}`) {
208
- run().catch(console.error);
209
- }
210
- export { run };
@@ -1,5 +0,0 @@
1
- /**
2
- * Service system comprehensive tests.
3
- * Tests service registration, loading, validation, and execution.
4
- */
5
- export {};
@@ -1,190 +0,0 @@
1
- /**
2
- * Service system comprehensive tests.
3
- * Tests service registration, loading, validation, and execution.
4
- */
5
- import fs from 'node:fs';
6
- import path from 'node:path';
7
- import { fileURLToPath } from 'node:url';
8
- import { serviceRegistry, serviceLoader, serviceManager, initializeServiceSystem } from '../services/index.js';
9
- import { ServiceCategory } from '../services/types.js';
10
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
- const projectRoot = path.resolve(__dirname, '..', '..');
12
- // Test helper functions
13
- function assert(condition, message) {
14
- if (!condition) {
15
- throw new Error(`Assertion failed: ${message}`);
16
- }
17
- }
18
- function assertEquals(actual, expected, message) {
19
- if (actual !== expected) {
20
- throw new Error(`Assertion failed: ${message || ''} - Expected ${expected}, got ${actual}`);
21
- }
22
- }
23
- console.log('\n=== Service System Tests ===\n');
24
- // Test 1: Service Registry Basic Operations
25
- console.log('Testing service registry basic operations...');
26
- // Create test service
27
- const testService = {
28
- id: 'test-service',
29
- name: 'Test Service',
30
- description: 'A test service for unit testing',
31
- defaultPrice: 10,
32
- category: ServiceCategory.UTILITY,
33
- inputSchema: {
34
- type: 'object',
35
- properties: {
36
- message: { type: 'string', description: 'Test message' }
37
- },
38
- required: ['message']
39
- }
40
- };
41
- // Clear registry for clean test
42
- serviceRegistry.clear();
43
- // Test registration
44
- serviceRegistry.register(testService);
45
- assert(serviceRegistry.get('test-service') !== undefined, 'Service should be registered');
46
- assertEquals(serviceRegistry.get('test-service')?.name, 'Test Service', 'Service name should match');
47
- // Test listing
48
- const services = serviceRegistry.list();
49
- assert(services.length === 1, 'Should have one registered service');
50
- assertEquals(services[0].id, 'test-service', 'Listed service should match registered service');
51
- console.log('✅ Registry: basic operations work correctly');
52
- // Test 2: Service Registry Validation
53
- console.log('Testing service registry validation...');
54
- // Test duplicate registration
55
- try {
56
- serviceRegistry.register(testService);
57
- throw new Error('Should have thrown error for duplicate registration');
58
- }
59
- catch (error) {
60
- assert(error.message.includes('already registered'), 'Should reject duplicate registration');
61
- }
62
- // Test invalid service (missing required fields)
63
- try {
64
- serviceRegistry.register({
65
- id: '',
66
- name: 'Invalid',
67
- description: 'Missing ID',
68
- defaultPrice: 10
69
- });
70
- throw new Error('Should have thrown error for invalid service');
71
- }
72
- catch (error) {
73
- assert(error.message.includes('Service ID is required'), 'Should reject service without ID');
74
- }
75
- console.log('✅ Registry: validation works correctly');
76
- // Test 3: Service Loader Directory Scanning
77
- console.log('Testing service loader directory scanning...');
78
- // Clear registry for clean test
79
- serviceRegistry.clear();
80
- // Load built-in services
81
- const builtInServices = await serviceLoader.loadBuiltInServices();
82
- assert(builtInServices.length > 0, 'Should load built-in services');
83
- // Check that specific services are loaded
84
- const expectedServices = ['tell-joke', 'api-proxy', 'summarize', 'memory-store', 'roulette', 'code-develop', 'image-analysis'];
85
- for (const serviceId of expectedServices) {
86
- const service = builtInServices.find(s => s.id === serviceId);
87
- assert(service !== undefined, `Should load ${serviceId} service`);
88
- assert(service.name.length > 0, `${serviceId} should have a name`);
89
- assert(service.description.length > 0, `${serviceId} should have a description`);
90
- assert(service.defaultPrice > 0, `${serviceId} should have a valid price`);
91
- }
92
- console.log('✅ Loader: directory scanning works correctly');
93
- // Test 4: Service Manager Integration
94
- console.log('Testing service manager integration...');
95
- // Initialize service system
96
- await initializeServiceSystem();
97
- // Test service discovery
98
- const joke = serviceManager.registry.get('tell-joke');
99
- assert(joke !== undefined, 'Should find tell-joke service');
100
- assertEquals(joke.name, 'Random Joke', 'Service name should match');
101
- // Test validation with valid input
102
- const validationResult = serviceManager.validate('tell-joke', { topic: 'programming' });
103
- assert(validationResult.valid, 'Valid input should pass validation');
104
- // Tell-joke service has no required fields, so empty object is valid
105
- const emptyInputResult = serviceManager.validate('tell-joke', {});
106
- assert(emptyInputResult.valid, 'Empty input should be valid for tell-joke service');
107
- // Test with truly invalid input (wrong type)
108
- const invalidResult = serviceManager.validate('tell-joke', { topic: 123 });
109
- assert(!invalidResult.valid, 'Invalid input type should fail validation');
110
- console.log('✅ Manager: integration works correctly');
111
- // Test 5: Service Input Schema Validation
112
- console.log('Testing service input schema validation...');
113
- // Test api-proxy service validation
114
- const apiProxy = serviceManager.registry.get('api-proxy');
115
- assert(apiProxy !== undefined, 'Should find api-proxy service');
116
- const validApiInput = { url: 'https://api.example.com/test', method: 'GET' };
117
- const validApiResult = serviceManager.validate('api-proxy', validApiInput);
118
- assert(validApiResult.valid, 'Valid api-proxy input should pass');
119
- const invalidApiInput = { method: 'GET' }; // missing required url
120
- const invalidApiResult = serviceManager.validate('api-proxy', invalidApiInput);
121
- assert(!invalidApiResult.valid, 'Invalid api-proxy input should fail');
122
- console.log('✅ Validation: input schema validation works correctly');
123
- // Test 6: Service Categories
124
- console.log('Testing service categories...');
125
- // Check that services have appropriate categories
126
- const categorizedServices = serviceManager.registry.list();
127
- const categories = new Set(categorizedServices.map(s => s.category).filter(Boolean));
128
- assert(categories.size > 0, 'Should have services with categories');
129
- // Verify known categories
130
- const expectedCategories = ['utility', 'ai', 'entertainment', 'development'];
131
- for (const category of expectedCategories) {
132
- const servicesInCategory = categorizedServices.filter(s => s.category === category);
133
- assert(servicesInCategory.length > 0, `Should have services in ${category} category`);
134
- }
135
- console.log('✅ Categories: service categorization works correctly');
136
- // Test 7: Service Loading Error Handling
137
- console.log('Testing service loading error handling...');
138
- // Test loading from non-existent directory
139
- try {
140
- await serviceLoader.loadFromDirectory('/non/existent/directory');
141
- // Should not throw, but return empty array
142
- console.log('✅ Loader: graceful handling of non-existent directory');
143
- }
144
- catch {
145
- // This is also acceptable behavior
146
- console.log('✅ Loader: appropriate error handling for non-existent directory');
147
- }
148
- // Test 8: Service Prompt Files
149
- console.log('Testing service prompt files...');
150
- // Check that services with prompt files can be found
151
- const servicesWithPrompts = categorizedServices.filter(s => s.promptFile);
152
- assert(servicesWithPrompts.length > 0, 'Should have services with prompt files');
153
- // Verify prompt files exist
154
- for (const service of servicesWithPrompts.slice(0, 3)) { // Test first 3 to avoid excessive file I/O
155
- if (service.promptFile) {
156
- const promptPath = path.resolve(projectRoot, service.promptFile);
157
- assert(fs.existsSync(promptPath), `Prompt file should exist: ${service.promptFile}`);
158
- const content = fs.readFileSync(promptPath, 'utf-8');
159
- assert(content.includes(service.id), `Prompt should reference service ID: ${service.id}`);
160
- }
161
- }
162
- console.log('✅ Prompts: service prompt files work correctly');
163
- // Test 9: Service Registry Search and Filter
164
- console.log('Testing service registry search and filter...');
165
- // Test filtering by category
166
- const aiServices = categorizedServices.filter(s => s.category === ServiceCategory.AI);
167
- assert(aiServices.length > 0, 'Should have AI services');
168
- const utilityServices = categorizedServices.filter(s => s.category === ServiceCategory.UTILITY);
169
- assert(utilityServices.length > 0, 'Should have utility services');
170
- // Test name search
171
- const jokeServices = categorizedServices.filter(s => s.name.toLowerCase().includes('joke'));
172
- assert(jokeServices.length > 0, 'Should find joke-related services');
173
- console.log('✅ Search: service filtering works correctly');
174
- // Test 10: Service System State Consistency
175
- console.log('Testing service system state consistency...');
176
- // Verify that registry and manager are in sync
177
- const registryServices = serviceManager.registry.list();
178
- const registryIds = new Set(registryServices.map(s => s.id));
179
- // All services should be unique
180
- assertEquals(registryIds.size, registryServices.length, 'All service IDs should be unique');
181
- // All services should have valid pricing
182
- for (const service of registryServices) {
183
- assert(service.defaultPrice > 0, `Service ${service.id} should have valid price`);
184
- assert(service.name.length > 0, `Service ${service.id} should have a name`);
185
- assert(service.description.length > 0, `Service ${service.id} should have a description`);
186
- }
187
- console.log('✅ Consistency: service system state is consistent');
188
- console.log('\n========================================');
189
- console.log('Service System Tests completed: All tests passed!');
190
- console.log('========================================\n');
@@ -1,7 +0,0 @@
1
- /**
2
- * TaskFlow Integration Tests
3
- *
4
- * Verifies that the plugin correctly interacts with api.runtime.taskFlow
5
- * when receiving service requests or responses.
6
- */
7
- export {};
@@ -1,82 +0,0 @@
1
- /**
2
- * TaskFlow Integration Tests
3
- *
4
- * Verifies that the plugin correctly interacts with api.runtime.taskFlow
5
- * when receiving service requests or responses.
6
- */
7
- import { register } from '../../index.js';
8
- // Simple test runner
9
- let passed = 0;
10
- let failed = 0;
11
- async function test(name, fn) {
12
- try {
13
- await fn();
14
- console.log(` ✓ ${name}`);
15
- passed++;
16
- }
17
- catch (err) {
18
- console.log(` ✗ ${name}`);
19
- console.log(err);
20
- failed++;
21
- }
22
- }
23
- function assert(condition, message) {
24
- if (!condition)
25
- throw new Error(`Assertion failed: ${message}`);
26
- }
27
- async function run() {
28
- console.log('TaskFlow Integration Tests\n');
29
- let createdFlows = [];
30
- let registeredService = null;
31
- const mockApi = {
32
- logger: {
33
- info: () => { },
34
- error: () => { },
35
- warn: () => { },
36
- debug: () => { }
37
- },
38
- runtime: {
39
- taskFlow: {
40
- create: (flow) => {
41
- createdFlows.push(flow);
42
- return { id: `flow_${createdFlows.length}` };
43
- }
44
- }
45
- },
46
- registerTool: () => { },
47
- registerService: (service) => {
48
- registeredService = service;
49
- },
50
- registerCommand: () => { },
51
- registerCli: () => { },
52
- getConfig: () => ({
53
- plugins: {
54
- entries: {
55
- 'sv_overlay': {
56
- config: {
57
- network: 'testnet'
58
- }
59
- }
60
- }
61
- }
62
- })
63
- };
64
- await test('Background service uses taskFlow on events', async () => {
65
- // 1. Register the plugin
66
- register(mockApi);
67
- // 2. Verify service was registered
68
- assert(registeredService !== null, 'service should be registered');
69
- // Note: To truly test the WebSocket event handling, we would need to mock
70
- // the 'spawn' and 'stdout' of the child process. Since that's complex
71
- // for a simple test, we verify the presence of the logic in index.ts.
72
- // We can check if createdFlows is empty initially
73
- assert(createdFlows.length === 0, 'no flows should be created yet');
74
- });
75
- console.log(`\n${passed} passed, ${failed} failed`);
76
- if (failed > 0)
77
- process.exit(1);
78
- }
79
- run().catch(err => {
80
- console.error(err);
81
- process.exit(1);
82
- });
@@ -1,98 +0,0 @@
1
- /**
2
- * Server validation logic mirrored from openclaw-overlay.
3
- *
4
- * This module contains the exact same parsing and validation logic
5
- * used by the server's topic managers, allowing us to validate
6
- * client output before submission.
7
- *
8
- * Updated to use PushDrop tokens instead of plain OP_RETURN.
9
- */
10
- import { Script, LockingScript } from '@bsv/sdk';
11
- export declare const PROTOCOL_ID = "openclaw-overlay-v1";
12
- export interface OpenclawIdentityData {
13
- protocol: string;
14
- type: 'identity';
15
- identityKey: string;
16
- name: string;
17
- description: string;
18
- channels: Record<string, string>;
19
- capabilities: string[];
20
- timestamp: string;
21
- }
22
- export interface OpenclawIdentityRevocationData {
23
- protocol: string;
24
- type: 'identity-revocation';
25
- identityKey: string;
26
- reason?: string;
27
- timestamp: string;
28
- }
29
- export interface OpenclawServiceData {
30
- protocol: string;
31
- type: 'service';
32
- identityKey: string;
33
- serviceId: string;
34
- name: string;
35
- description: string;
36
- pricing: {
37
- model: string;
38
- amountSats: number;
39
- };
40
- timestamp: string;
41
- }
42
- export type OpenclawPayload = OpenclawIdentityData | OpenclawIdentityRevocationData | OpenclawServiceData;
43
- export interface AdmittanceResult {
44
- outputsToAdmit: number[];
45
- coinsToRetain: number[];
46
- }
47
- export interface STEAKResponse {
48
- [topic: string]: AdmittanceResult;
49
- }
50
- /**
51
- * Extract data fields from a PushDrop script using the SDK's decode method.
52
- * Returns the fields array or null if not a valid PushDrop script.
53
- */
54
- export declare function extractPushDropFields(script: Script | LockingScript): number[][] | null;
55
- /**
56
- * Legacy function for backwards compatibility - extracts from OP_RETURN scripts.
57
- * @deprecated Use extractPushDropFields instead
58
- */
59
- export declare function extractOpReturnPushes(script: Script): Uint8Array[] | null;
60
- /**
61
- * Parse identity payload from a PushDrop script.
62
- * The first field contains the JSON payload.
63
- */
64
- export declare function parseIdentityOutput(script: Script | LockingScript): OpenclawIdentityData | null;
65
- /**
66
- * Parse identity revocation payload from a PushDrop script.
67
- */
68
- export declare function parseRevocationOutput(script: Script | LockingScript): OpenclawIdentityRevocationData | null;
69
- /**
70
- * Parse service payload from a PushDrop script.
71
- */
72
- export declare function parseServiceOutput(script: Script | LockingScript): OpenclawServiceData | null;
73
- /**
74
- * Simulate the identity topic manager's identifyAdmissibleOutputs.
75
- */
76
- export declare function identifyIdentityOutputs(beef: number[]): AdmittanceResult;
77
- /**
78
- * Simulate the services topic manager's identifyAdmissibleOutputs.
79
- */
80
- export declare function identifyServiceOutputs(beef: number[]): AdmittanceResult;
81
- /**
82
- * Validate BEEF format and structure.
83
- */
84
- export declare function validateBeef(beef: number[]): {
85
- valid: boolean;
86
- error?: string;
87
- version?: number;
88
- txCount?: number;
89
- hasProofs?: boolean;
90
- };
91
- /**
92
- * Validate BEEF has proper ancestry chain.
93
- */
94
- export declare function validateBeefAncestry(beef: number[]): {
95
- valid: boolean;
96
- error?: string;
97
- chain?: string[];
98
- };