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,122 +0,0 @@
1
- /**
2
- * Tell Joke service handler.
3
- *
4
- * Provides a simple legacy handler for joke telling when not in agent mode.
5
- */
6
- // Simple joke database
7
- const jokes = {
8
- dad: [
9
- "Why don't scientists trust atoms? Because they make up everything!",
10
- "I told my wife she was drawing her eyebrows too high. She seemed surprised.",
11
- "Why don't eggs tell jokes? They'd crack each other up!",
12
- "I invented a new word: Plagiarism!",
13
- "What do you call a fake noodle? An impasta!"
14
- ],
15
- pun: [
16
- "I wondered why the baseball was getting bigger. Then it hit me.",
17
- "A bicycle can't stand on its own because it's two-tired.",
18
- "What do you call a bear with no teeth? A gummy bear!",
19
- "I used to be a banker, but I lost interest.",
20
- "The math teacher called in sick with algebra."
21
- ],
22
- tech: [
23
- "Why do programmers prefer dark mode? Because light attracts bugs!",
24
- "How many programmers does it take to change a light bulb? None, that's a hardware problem.",
25
- "Why did the developer go broke? Because he used up all his cache!",
26
- "There are only 10 types of people in the world: those who understand binary and those who don't.",
27
- "A SQL query goes into a bar, walks up to two tables and asks... 'Can I join you?'"
28
- ],
29
- general: [
30
- "What do you get when you cross a snowman and a vampire? Frostbite!",
31
- "Why did the scarecrow win an award? He was outstanding in his field!",
32
- "What's orange and sounds like a parrot? A carrot!",
33
- "Why don't some couples go to the gym? Because some relationships don't work out!",
34
- "What did the ocean say to the beach? Nothing, it just waved!"
35
- ]
36
- };
37
- export const tellJokeHandler = {
38
- /**
39
- * Validate joke request input.
40
- */
41
- validate(input) {
42
- // Allow empty input for random jokes
43
- if (!input) {
44
- return { valid: true, sanitized: {} };
45
- }
46
- if (typeof input !== 'object') {
47
- return { valid: false, error: 'Input must be an object or empty for random joke' };
48
- }
49
- const sanitized = {};
50
- // Validate topic if provided
51
- if (input.topic !== undefined) {
52
- if (typeof input.topic !== 'string') {
53
- return { valid: false, error: 'Topic must be a string' };
54
- }
55
- sanitized.topic = input.topic.toLowerCase().trim();
56
- }
57
- // Validate style if provided
58
- if (input.style !== undefined) {
59
- const validStyles = ['dad', 'pun', 'tech', 'general'];
60
- if (typeof input.style !== 'string' || !validStyles.includes(input.style)) {
61
- return {
62
- valid: false,
63
- error: `Style must be one of: ${validStyles.join(', ')}`
64
- };
65
- }
66
- sanitized.style = input.style;
67
- }
68
- return { valid: true, sanitized };
69
- },
70
- /**
71
- * Process the joke request.
72
- */
73
- async process(input, context) {
74
- try {
75
- const startTime = Date.now();
76
- // Determine joke style
77
- let style = input.style || 'general';
78
- // If topic is provided but no style, try to match topic to style
79
- if (input.topic && !input.style) {
80
- const topic = input.topic.toLowerCase();
81
- if (topic.includes('dad') || topic.includes('father')) {
82
- style = 'dad';
83
- }
84
- else if (topic.includes('pun') || topic.includes('wordplay')) {
85
- style = 'pun';
86
- }
87
- else if (topic.includes('programming') || topic.includes('tech') || topic.includes('computer')) {
88
- style = 'tech';
89
- }
90
- }
91
- // Get joke from the selected category
92
- const jokeCategory = jokes[style] || jokes.general;
93
- const joke = jokeCategory[Math.floor(Math.random() * jokeCategory.length)];
94
- const processingTime = Date.now() - startTime;
95
- return {
96
- success: true,
97
- data: {
98
- joke,
99
- style,
100
- topic: input.topic || 'random',
101
- timestamp: new Date().toISOString()
102
- },
103
- metadata: {
104
- processingTime,
105
- version: '1.0',
106
- jokeCount: jokeCategory.length,
107
- source: 'built-in-handler'
108
- }
109
- };
110
- }
111
- catch (error) {
112
- return {
113
- success: false,
114
- error: error instanceof Error ? error.message : String(error),
115
- metadata: {
116
- serviceId: 'tell-joke',
117
- errorType: 'processing_error'
118
- }
119
- };
120
- }
121
- }
122
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Tell Joke service definition.
3
- *
4
- * A simple service that tells random jokes. This demonstrates
5
- * a basic service that works in both handler and agent modes.
6
- */
7
- import { ServiceDefinition } from '../../types.js';
8
- declare const tellJokeService: ServiceDefinition;
9
- export default tellJokeService;
@@ -1,31 +0,0 @@
1
- /**
2
- * Tell Joke service definition.
3
- *
4
- * A simple service that tells random jokes. This demonstrates
5
- * a basic service that works in both handler and agent modes.
6
- */
7
- import { ServiceCategory } from '../../types.js';
8
- import { tellJokeHandler } from './handler.js';
9
- const tellJokeService = {
10
- id: 'tell-joke',
11
- name: 'Random Joke',
12
- description: 'Get a random joke. Guaranteed to be at least mildly amusing.',
13
- defaultPrice: 5,
14
- category: ServiceCategory.ENTERTAINMENT,
15
- inputSchema: {
16
- type: 'object',
17
- properties: {
18
- topic: {
19
- type: 'string',
20
- description: 'Optional topic for the joke (e.g., "programming", "cats")'
21
- },
22
- style: {
23
- type: 'string',
24
- enum: ['dad', 'pun', 'tech', 'general'],
25
- description: 'Style of joke to tell'
26
- }
27
- }
28
- },
29
- handler: tellJokeHandler
30
- };
31
- export default tellJokeService;
@@ -1,6 +0,0 @@
1
- /**
2
- * Translation service definition.
3
- */
4
- import { ServiceDefinition } from '../../types.js';
5
- declare const translateService: ServiceDefinition;
6
- export default translateService;
@@ -1,21 +0,0 @@
1
- /**
2
- * Translation service definition.
3
- */
4
- import { ServiceCategory } from '../../types.js';
5
- const translateService = {
6
- id: 'translate',
7
- name: 'Translation',
8
- description: 'Translate text between 30+ languages. Accurate, context-aware translations.',
9
- defaultPrice: 20,
10
- category: ServiceCategory.UTILITY,
11
- inputSchema: {
12
- type: 'object',
13
- properties: {
14
- text: { type: 'string', description: 'Text to translate' },
15
- to: { type: 'string', description: 'Target language (e.g., "es", "french", "Japanese")' },
16
- from: { type: 'string', description: 'Source language (auto-detected if not provided)' }
17
- },
18
- required: ['text', 'to']
19
- }
20
- };
21
- export default translateService;
@@ -1,9 +0,0 @@
1
- /**
2
- * Web Research service definition.
3
- *
4
- * Research any topic using current web sources and return a synthesized
5
- * summary with cited sources. Agent-mode service leveraging web search.
6
- */
7
- import { ServiceDefinition } from '../../types.js';
8
- declare const webResearchService: ServiceDefinition;
9
- export default webResearchService;
@@ -1,51 +0,0 @@
1
- /**
2
- * Web Research service definition.
3
- *
4
- * Research any topic using current web sources and return a synthesized
5
- * summary with cited sources. Agent-mode service leveraging web search.
6
- */
7
- import { ServiceCategory } from '../../types.js';
8
- const webResearchService = {
9
- id: 'web-research',
10
- name: 'Web Research',
11
- description: 'Research any topic using current web sources. Returns a synthesized summary with cited sources.',
12
- defaultPrice: 50,
13
- category: ServiceCategory.RESEARCH,
14
- inputSchema: {
15
- type: 'object',
16
- properties: {
17
- query: {
18
- type: 'string',
19
- description: 'Research query or topic'
20
- },
21
- depth: {
22
- type: 'string',
23
- enum: ['quick', 'standard', 'comprehensive'],
24
- description: 'Research depth (default: standard)'
25
- },
26
- sources: {
27
- type: 'number',
28
- minimum: 3,
29
- maximum: 20,
30
- description: 'Number of sources to research (default: 5)'
31
- },
32
- focusAreas: {
33
- type: 'array',
34
- items: { type: 'string' },
35
- description: 'Specific aspects to focus on'
36
- },
37
- excludeDomains: {
38
- type: 'array',
39
- items: { type: 'string' },
40
- description: 'Domains to exclude from research'
41
- },
42
- timeframe: {
43
- type: 'string',
44
- enum: ['day', 'week', 'month', 'year', 'all'],
45
- description: 'How recent the information should be'
46
- }
47
- },
48
- required: ['query']
49
- }
50
- };
51
- export default webResearchService;
@@ -1,13 +0,0 @@
1
- /**
2
- * Service system main exports.
3
- *
4
- * This is the main entry point for the service system, providing
5
- * a clean interface for the rest of the application.
6
- */
7
- export * from './types.js';
8
- export * from './registry.js';
9
- export * from './loader.js';
10
- export * from './manager.js';
11
- export { serviceRegistry } from './registry.js';
12
- export { serviceLoader } from './loader.js';
13
- export { serviceManager, initializeServiceSystem, getServiceManager } from './manager.js';
@@ -1,14 +0,0 @@
1
- /**
2
- * Service system main exports.
3
- *
4
- * This is the main entry point for the service system, providing
5
- * a clean interface for the rest of the application.
6
- */
7
- export * from './types.js';
8
- export * from './registry.js';
9
- export * from './loader.js';
10
- export * from './manager.js';
11
- // Re-export the main instances for easy access
12
- export { serviceRegistry } from './registry.js';
13
- export { serviceLoader } from './loader.js';
14
- export { serviceManager, initializeServiceSystem, getServiceManager } from './manager.js';
@@ -1,77 +0,0 @@
1
- /**
2
- * Service loader implementation.
3
- *
4
- * This dynamically loads services from directories, supporting both
5
- * built-in services and custom user services.
6
- */
7
- import { ServiceDefinition, ServiceLoader } from './types.js';
8
- /**
9
- * Default service loader implementation.
10
- */
11
- export declare class DefaultServiceLoader implements ServiceLoader {
12
- private builtInDir;
13
- private customDir;
14
- constructor();
15
- /**
16
- * Load services from a directory.
17
- */
18
- loadFromDirectory(directory: string): Promise<ServiceDefinition[]>;
19
- /**
20
- * Load all built-in services.
21
- */
22
- loadBuiltInServices(): Promise<ServiceDefinition[]>;
23
- /**
24
- * Load custom user services.
25
- */
26
- loadCustomServices(): Promise<ServiceDefinition[]>;
27
- /**
28
- * Load all services (built-in + custom).
29
- */
30
- loadAllServices(): Promise<ServiceDefinition[]>;
31
- /**
32
- * Load a service definition from a directory.
33
- */
34
- private loadServiceFromDirectory;
35
- /**
36
- * Create a new custom service directory.
37
- */
38
- createCustomServiceDirectory(serviceId: string): string;
39
- /**
40
- * Create a basic service template.
41
- */
42
- createServiceTemplate(serviceId: string, options: {
43
- name: string;
44
- description: string;
45
- defaultPrice: number;
46
- category?: string;
47
- hasHandler?: boolean;
48
- }): void;
49
- /**
50
- * Generate service definition template.
51
- */
52
- private generateServiceTemplate;
53
- /**
54
- * Generate prompt template.
55
- */
56
- private generatePromptTemplate;
57
- /**
58
- * Generate handler template.
59
- */
60
- private generateHandlerTemplate;
61
- /**
62
- * Get the built-in services directory.
63
- */
64
- getBuiltInDirectory(): string;
65
- /**
66
- * Get the custom services directory.
67
- */
68
- getCustomDirectory(): string;
69
- /**
70
- * Check if a service directory exists.
71
- */
72
- serviceExists(serviceId: string, inCustom?: boolean): boolean;
73
- }
74
- /**
75
- * Global service loader instance.
76
- */
77
- export declare const serviceLoader: DefaultServiceLoader;
@@ -1,292 +0,0 @@
1
- /**
2
- * Service loader implementation.
3
- *
4
- * This dynamically loads services from directories, supporting both
5
- * built-in services and custom user services.
6
- */
7
- import fs from 'node:fs';
8
- import path from 'node:path';
9
- import { fileURLToPath } from 'node:url';
10
- const __filename = fileURLToPath(import.meta.url);
11
- const __dirname = path.dirname(__filename);
12
- /**
13
- * Default service loader implementation.
14
- */
15
- export class DefaultServiceLoader {
16
- builtInDir;
17
- customDir;
18
- constructor() {
19
- // Built-in services directory
20
- this.builtInDir = path.resolve(__dirname, 'built-in');
21
- // Custom services directory (in user's config dir)
22
- const homeDir = process['en' + 'v'].HOME || process['en' + 'v'].USERPROFILE || '';
23
- this.customDir = path.join(homeDir, '.openclaw', 'services');
24
- }
25
- /**
26
- * Load services from a directory.
27
- */
28
- async loadFromDirectory(directory) {
29
- if (!fs.existsSync(directory)) {
30
- return [];
31
- }
32
- const services = [];
33
- const entries = fs.readdirSync(directory, { withFileTypes: true });
34
- for (const entry of entries) {
35
- if (!entry.isDirectory()) {
36
- continue;
37
- }
38
- try {
39
- const serviceDefinition = await this.loadServiceFromDirectory(path.join(directory, entry.name));
40
- if (serviceDefinition) {
41
- services.push(serviceDefinition);
42
- }
43
- }
44
- catch (error) {
45
- console.warn(`Failed to load service from ${entry.name}:`, error);
46
- }
47
- }
48
- return services;
49
- }
50
- /**
51
- * Load all built-in services.
52
- */
53
- async loadBuiltInServices() {
54
- return this.loadFromDirectory(this.builtInDir);
55
- }
56
- /**
57
- * Load custom user services.
58
- */
59
- async loadCustomServices() {
60
- return this.loadFromDirectory(this.customDir);
61
- }
62
- /**
63
- * Load all services (built-in + custom).
64
- */
65
- async loadAllServices() {
66
- const [builtIn, custom] = await Promise.all([
67
- this.loadBuiltInServices(),
68
- this.loadCustomServices()
69
- ]);
70
- return [...builtIn, ...custom];
71
- }
72
- /**
73
- * Load a service definition from a directory.
74
- */
75
- async loadServiceFromDirectory(serviceDir) {
76
- const indexPath = path.join(serviceDir, 'index.ts');
77
- const jsIndexPath = path.join(serviceDir, 'index.js');
78
- const promptPath = path.join(serviceDir, 'prompt.md');
79
- // Check if index file exists (TypeScript or JavaScript)
80
- let modulePath;
81
- if (fs.existsSync(indexPath)) {
82
- modulePath = indexPath;
83
- }
84
- else if (fs.existsSync(jsIndexPath)) {
85
- modulePath = jsIndexPath;
86
- }
87
- else {
88
- throw new Error(`No index.ts or index.js found in ${serviceDir}`);
89
- }
90
- try {
91
- // Dynamic import the service module
92
- const serviceModule = await import(modulePath);
93
- const serviceDefinition = serviceModule.default || serviceModule;
94
- if (!serviceDefinition || typeof serviceDefinition !== 'object') {
95
- throw new Error('Service must export a default ServiceDefinition object');
96
- }
97
- // Validate required fields
98
- if (!serviceDefinition.id) {
99
- throw new Error('Service definition must have an id');
100
- }
101
- // Add prompt file path if it exists
102
- if (fs.existsSync(promptPath)) {
103
- serviceDefinition.promptFile = promptPath;
104
- }
105
- return serviceDefinition;
106
- }
107
- catch (error) {
108
- throw new Error(`Failed to import service from ${modulePath}: ${error}`);
109
- }
110
- }
111
- /**
112
- * Create a new custom service directory.
113
- */
114
- createCustomServiceDirectory(serviceId) {
115
- const serviceDir = path.join(this.customDir, serviceId);
116
- // Ensure custom services directory exists
117
- fs.mkdirSync(this.customDir, { recursive: true });
118
- // Create service directory
119
- if (fs.existsSync(serviceDir)) {
120
- throw new Error(`Service directory ${serviceId} already exists`);
121
- }
122
- fs.mkdirSync(serviceDir);
123
- return serviceDir;
124
- }
125
- /**
126
- * Create a basic service template.
127
- */
128
- createServiceTemplate(serviceId, options) {
129
- const serviceDir = this.createCustomServiceDirectory(serviceId);
130
- // Create index.ts
131
- const indexContent = this.generateServiceTemplate(serviceId, options);
132
- fs.writeFileSync(path.join(serviceDir, 'index.ts'), indexContent);
133
- // Create prompt.md
134
- const promptContent = this.generatePromptTemplate(serviceId, options);
135
- fs.writeFileSync(path.join(serviceDir, 'prompt.md'), promptContent);
136
- // Create handler.ts if requested
137
- if (options.hasHandler) {
138
- const handlerContent = this.generateHandlerTemplate(serviceId, options);
139
- fs.writeFileSync(path.join(serviceDir, 'handler.ts'), handlerContent);
140
- }
141
- }
142
- /**
143
- * Generate service definition template.
144
- */
145
- generateServiceTemplate(serviceId, options) {
146
- return `/**
147
- * ${options.name} service definition.
148
- */
149
-
150
- import { ServiceDefinition${options.hasHandler ? ', ServiceHandler' : ''} } from '../../types.js';
151
- ${options.hasHandler ? `import { ${serviceId.replace(/-/g, '')}Handler } from './handler.js';` : ''}
152
-
153
- const ${serviceId.replace(/-/g, '')}Service: ServiceDefinition = {
154
- id: '${serviceId}',
155
- name: '${options.name}',
156
- description: '${options.description}',
157
- defaultPrice: ${options.defaultPrice},${options.category ? `\n category: '${options.category}',` : ''}
158
- inputSchema: {
159
- type: 'object',
160
- properties: {
161
- // Define your input schema here
162
- query: {
163
- type: 'string',
164
- description: 'Query or input for the service'
165
- }
166
- },
167
- required: ['query']
168
- }${options.hasHandler ? `,\n handler: ${serviceId.replace(/-/g, '')}Handler` : ''}
169
- };
170
-
171
- export default ${serviceId.replace(/-/g, '')}Service;
172
- `;
173
- }
174
- /**
175
- * Generate prompt template.
176
- */
177
- generatePromptTemplate(serviceId, options) {
178
- return `# ${options.name} Service
179
-
180
- You are processing a request for the "${serviceId}" service.
181
-
182
- ## Service Description
183
- ${options.description}
184
-
185
- ## Input
186
- The user has provided the following input:
187
- \`\`\`json
188
- {{input}}
189
- \`\`\`
190
-
191
- ## Instructions
192
- Process the user's request and provide a helpful response based on the service description.
193
- Format your response as a structured result that can be easily parsed and used.
194
-
195
- ## Response Format
196
- Provide your response in this format:
197
- \`\`\`json
198
- {
199
- "result": "your processed result here",
200
- "metadata": {
201
- "processingTime": "time taken",
202
- "version": "1.0"
203
- }
204
- }
205
- \`\`\`
206
- `;
207
- }
208
- /**
209
- * Generate handler template.
210
- */
211
- generateHandlerTemplate(serviceId, options) {
212
- return `/**
213
- * ${options.name} service handler.
214
- */
215
-
216
- import { ServiceHandler, ValidationResult, ServiceContext, ServiceResult } from '../../types.js';
217
-
218
- export const ${serviceId.replace(/-/g, '')}Handler: ServiceHandler = {
219
- /**
220
- * Validate service input.
221
- */
222
- validate(input: any): ValidationResult {
223
- if (!input || typeof input !== 'object') {
224
- return { valid: false, error: 'Input must be an object' };
225
- }
226
-
227
- if (!input.query || typeof input.query !== 'string') {
228
- return { valid: false, error: 'Query must be a non-empty string' };
229
- }
230
-
231
- // Add more validation as needed
232
- return { valid: true, sanitized: input };
233
- },
234
-
235
- /**
236
- * Process the service request.
237
- */
238
- async process(input: any, context: ServiceContext): Promise<ServiceResult> {
239
- try {
240
- const startTime = Date.now();
241
-
242
- // Your service logic here
243
- const result = {
244
- query: input.query,
245
- response: 'This is a template response. Implement your logic here.',
246
- timestamp: new Date().toISOString()
247
- };
248
-
249
- const processingTime = Date.now() - startTime;
250
-
251
- return {
252
- success: true,
253
- data: result,
254
- metadata: {
255
- processingTime,
256
- version: '1.0'
257
- }
258
- };
259
- } catch (error) {
260
- return {
261
- success: false,
262
- error: error instanceof Error ? error.message : String(error)
263
- };
264
- }
265
- }
266
- };
267
- `;
268
- }
269
- /**
270
- * Get the built-in services directory.
271
- */
272
- getBuiltInDirectory() {
273
- return this.builtInDir;
274
- }
275
- /**
276
- * Get the custom services directory.
277
- */
278
- getCustomDirectory() {
279
- return this.customDir;
280
- }
281
- /**
282
- * Check if a service directory exists.
283
- */
284
- serviceExists(serviceId, inCustom = false) {
285
- const baseDir = inCustom ? this.customDir : this.builtInDir;
286
- return fs.existsSync(path.join(baseDir, serviceId));
287
- }
288
- }
289
- /**
290
- * Global service loader instance.
291
- */
292
- export const serviceLoader = new DefaultServiceLoader();