strray-ai 1.22.21 → 1.22.22
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/.strray/state/state.json +1 -0
- package/dist/CHANGELOG.md +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/openclaw/api-server.d.ts +86 -0
- package/dist/integrations/openclaw/api-server.d.ts.map +1 -0
- package/dist/integrations/openclaw/api-server.js +339 -0
- package/dist/integrations/openclaw/api-server.js.map +1 -0
- package/dist/integrations/openclaw/client.d.ts +120 -0
- package/dist/integrations/openclaw/client.d.ts.map +1 -0
- package/dist/integrations/openclaw/client.js +447 -0
- package/dist/integrations/openclaw/client.js.map +1 -0
- package/dist/integrations/openclaw/config.d.ts +97 -0
- package/dist/integrations/openclaw/config.d.ts.map +1 -0
- package/dist/integrations/openclaw/config.js +375 -0
- package/dist/integrations/openclaw/config.js.map +1 -0
- package/dist/integrations/openclaw/hooks/strray-hooks.d.ts +125 -0
- package/dist/integrations/openclaw/hooks/strray-hooks.d.ts.map +1 -0
- package/dist/integrations/openclaw/hooks/strray-hooks.js +281 -0
- package/dist/integrations/openclaw/hooks/strray-hooks.js.map +1 -0
- package/dist/integrations/openclaw/index.d.ts +102 -0
- package/dist/integrations/openclaw/index.d.ts.map +1 -0
- package/dist/integrations/openclaw/index.js +340 -0
- package/dist/integrations/openclaw/index.js.map +1 -0
- package/dist/integrations/openclaw/types.d.ts +427 -0
- package/dist/integrations/openclaw/types.d.ts.map +1 -0
- package/dist/integrations/openclaw/types.js +154 -0
- package/dist/integrations/openclaw/types.js.map +1 -0
- package/package.json +1 -1
- package/scripts/node/universal-version-manager.js +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
package/dist/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Conventional Commits](https://www.conventionalcommits.org/).
|
|
6
6
|
|
|
7
|
+
## [1.22.22] - 2026-04-27
|
|
8
|
+
|
|
9
|
+
### 🔄 Changes
|
|
10
|
+
|
|
11
|
+
- Version bump
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
7
15
|
## [1.22.20] - 2026-04-27
|
|
8
16
|
|
|
9
17
|
### 🔄 Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { frameworkLogger } from "./core/framework-logger.js";
|
|
|
11
11
|
export { BUILTIN_CODEX } from "./core/codex-formatter.js";
|
|
12
12
|
import { defaultStringRayConfig } from "./core/index.js";
|
|
13
13
|
export { defaultStringRayConfig };
|
|
14
|
+
export { OpenClawIntegration, initializeOpenClawIntegration, getOpenClawIntegration, shutdownOpenClawIntegration } from "./integrations/openclaw/index.js";
|
|
15
|
+
export type { OpenClawIntegrationConfig } from "./integrations/openclaw/types.js";
|
|
14
16
|
export declare function initializeStringRay(config?: {}): {
|
|
15
17
|
success: boolean;
|
|
16
18
|
config: {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAElC,OAAO,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC3J,YAAY,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAGlF,wBAAgB,mBAAmB,CAAC,MAAM,KAAK;;;;;;;;;;;;EAS9C"}
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { frameworkLogger } from "./core/framework-logger.js";
|
|
|
11
11
|
export { BUILTIN_CODEX } from "./core/codex-formatter.js";
|
|
12
12
|
import { defaultStringRayConfig } from "./core/index.js";
|
|
13
13
|
export { defaultStringRayConfig };
|
|
14
|
+
export { OpenClawIntegration, initializeOpenClawIntegration, getOpenClawIntegration, shutdownOpenClawIntegration } from "./integrations/openclaw/index.js";
|
|
14
15
|
// Main initialization function
|
|
15
16
|
export function initializeStringRay(config = {}) {
|
|
16
17
|
const mergedConfig = { ...defaultStringRayConfig, ...config };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,uBA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OAAO,EAAE,0CAA0C;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0xRay API Server
|
|
3
|
+
*
|
|
4
|
+
* HTTP API server that OpenClaw skills call to invoke 0xRay capabilities.
|
|
5
|
+
* This is the bridge between OpenClaw skills and 0xRay.
|
|
6
|
+
*
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @since 2026-03-14
|
|
9
|
+
*/
|
|
10
|
+
import { StringRayAPIServerConfig, AgentInvokeRequest, AgentInvokeResponse, APIServerStatistics } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Agent invoker interface - implemented by 0xRay
|
|
13
|
+
*/
|
|
14
|
+
export interface AgentInvoker {
|
|
15
|
+
invoke(request: AgentInvokeRequest): Promise<AgentInvokeResponse>;
|
|
16
|
+
getStatus?(): Promise<{
|
|
17
|
+
healthy: boolean;
|
|
18
|
+
version: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 0xRay API Server
|
|
23
|
+
*/
|
|
24
|
+
export declare class StringRayAPIServer {
|
|
25
|
+
private server;
|
|
26
|
+
private config;
|
|
27
|
+
private agentInvoker;
|
|
28
|
+
private apiKey;
|
|
29
|
+
private stats;
|
|
30
|
+
private responseTimes;
|
|
31
|
+
private logger;
|
|
32
|
+
constructor(config: StringRayAPIServerConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Set the agent invoker
|
|
35
|
+
*/
|
|
36
|
+
setAgentInvoker(invoker: AgentInvoker): void;
|
|
37
|
+
/**
|
|
38
|
+
* Start the API server
|
|
39
|
+
*/
|
|
40
|
+
start(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Stop the API server
|
|
43
|
+
*/
|
|
44
|
+
stop(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if server is running
|
|
47
|
+
*/
|
|
48
|
+
isRunning(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Get server statistics
|
|
51
|
+
*/
|
|
52
|
+
getStats(): APIServerStatistics;
|
|
53
|
+
/**
|
|
54
|
+
* Handle incoming HTTP request
|
|
55
|
+
*/
|
|
56
|
+
private handleRequest;
|
|
57
|
+
/**
|
|
58
|
+
* Handle health check request
|
|
59
|
+
*/
|
|
60
|
+
private handleHealth;
|
|
61
|
+
/**
|
|
62
|
+
* Handle agent invoke request
|
|
63
|
+
*/
|
|
64
|
+
private handleAgentInvoke;
|
|
65
|
+
/**
|
|
66
|
+
* Handle agent status request
|
|
67
|
+
*/
|
|
68
|
+
private handleAgentStatus;
|
|
69
|
+
/**
|
|
70
|
+
* Validate API key using constant-time comparison to prevent timing attacks
|
|
71
|
+
*/
|
|
72
|
+
private validateApiKey;
|
|
73
|
+
/**
|
|
74
|
+
* Read request body
|
|
75
|
+
*/
|
|
76
|
+
private readBody;
|
|
77
|
+
/**
|
|
78
|
+
* Send JSON response
|
|
79
|
+
*/
|
|
80
|
+
private sendResponse;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Factory function to create API server
|
|
84
|
+
*/
|
|
85
|
+
export declare function createStringRayAPIServer(config: StringRayAPIServerConfig): StringRayAPIServer;
|
|
86
|
+
//# sourceMappingURL=api-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-server.d.ts","sourceRoot":"","sources":["../../../src/integrations/openclaw/api-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACL,wBAAwB,EACxB,kBAAkB,EAClB,mBAAmB,EAEnB,mBAAmB,EACpB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAClE,SAAS,CAAC,IAAI,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,MAAM,CAAqC;IACnD,OAAO,CAAC,YAAY,CAA6B;IACjD,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,KAAK,CAOX;IACF,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,MAAM,CAAU;gBAEZ,MAAM,EAAE,wBAAwB;IAe5C;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI5C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,QAAQ,IAAI,mBAAmB;IAa/B;;OAEG;YACW,aAAa;IA6G3B;;OAEG;YACW,YAAY;IAuB1B;;OAEG;YACW,iBAAiB;IAmB/B;;OAEG;YACW,iBAAiB;IA6B/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAsBtB;;OAEG;IACH,OAAO,CAAC,QAAQ;IAgBhB;;OAEG;IACH,OAAO,CAAC,YAAY;CAUrB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,kBAAkB,CAE7F"}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0xRay API Server
|
|
3
|
+
*
|
|
4
|
+
* HTTP API server that OpenClaw skills call to invoke 0xRay capabilities.
|
|
5
|
+
* This is the bridge between OpenClaw skills and 0xRay.
|
|
6
|
+
*
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @since 2026-03-14
|
|
9
|
+
*/
|
|
10
|
+
import * as crypto from 'crypto';
|
|
11
|
+
import * as http from 'http';
|
|
12
|
+
/**
|
|
13
|
+
* 0xRay API Server
|
|
14
|
+
*/
|
|
15
|
+
export class StringRayAPIServer {
|
|
16
|
+
server = null;
|
|
17
|
+
config;
|
|
18
|
+
agentInvoker = null;
|
|
19
|
+
apiKey = '';
|
|
20
|
+
stats = {
|
|
21
|
+
startedAt: 0,
|
|
22
|
+
requestsTotal: 0,
|
|
23
|
+
requestsByEndpoint: {},
|
|
24
|
+
requestsByStatus: {},
|
|
25
|
+
averageResponseTime: 0,
|
|
26
|
+
errors: 0,
|
|
27
|
+
};
|
|
28
|
+
responseTimes = [];
|
|
29
|
+
logger;
|
|
30
|
+
constructor(config) {
|
|
31
|
+
this.config = {
|
|
32
|
+
port: config.port || 18431,
|
|
33
|
+
host: config.host || '127.0.0.1',
|
|
34
|
+
apiKey: config.apiKey || '',
|
|
35
|
+
cors: config.cors ?? false,
|
|
36
|
+
rateLimit: config.rateLimit || {
|
|
37
|
+
windowMs: 60000,
|
|
38
|
+
maxRequests: 100,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
this.logger = console;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set the agent invoker
|
|
45
|
+
*/
|
|
46
|
+
setAgentInvoker(invoker) {
|
|
47
|
+
this.agentInvoker = invoker;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Start the API server
|
|
51
|
+
*/
|
|
52
|
+
async start() {
|
|
53
|
+
if (this.server) {
|
|
54
|
+
this.logger.warn('[StringRayAPIServer] Server already running');
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
this.server = http.createServer((req, res) => {
|
|
59
|
+
this.handleRequest(req, res);
|
|
60
|
+
});
|
|
61
|
+
this.server.on('error', (error) => {
|
|
62
|
+
this.logger.error('[StringRayAPIServer] Server error:', error);
|
|
63
|
+
this.stats.errors++;
|
|
64
|
+
reject(error);
|
|
65
|
+
});
|
|
66
|
+
this.server.listen(this.config.port, this.config.host, () => {
|
|
67
|
+
this.stats.startedAt = Date.now();
|
|
68
|
+
this.logger.info(`[StringRayAPIServer] Listening on http://${this.config.host}:${this.config.port}`);
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Stop the API server
|
|
75
|
+
*/
|
|
76
|
+
async stop() {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
if (this.server) {
|
|
79
|
+
this.server.close(() => {
|
|
80
|
+
this.logger.info('[StringRayAPIServer] Server stopped');
|
|
81
|
+
this.server = null;
|
|
82
|
+
resolve();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
resolve();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Check if server is running
|
|
92
|
+
*/
|
|
93
|
+
isRunning() {
|
|
94
|
+
return this.server !== null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get server statistics
|
|
98
|
+
*/
|
|
99
|
+
getStats() {
|
|
100
|
+
// Calculate average response time
|
|
101
|
+
if (this.responseTimes.length > 0) {
|
|
102
|
+
const total = this.responseTimes.reduce((a, b) => a + b, 0);
|
|
103
|
+
this.stats.averageResponseTime = total / this.responseTimes.length;
|
|
104
|
+
}
|
|
105
|
+
return { ...this.stats };
|
|
106
|
+
}
|
|
107
|
+
// =========================================================================
|
|
108
|
+
// Private Methods
|
|
109
|
+
// =========================================================================
|
|
110
|
+
/**
|
|
111
|
+
* Handle incoming HTTP request
|
|
112
|
+
*/
|
|
113
|
+
async handleRequest(req, res) {
|
|
114
|
+
const startTime = Date.now();
|
|
115
|
+
const url = new URL(req.url || '/', `http://${this.config.host}:${this.config.port}`);
|
|
116
|
+
const method = req.method || 'GET';
|
|
117
|
+
const endpoint = `${method} ${url.pathname}`;
|
|
118
|
+
this.stats.requestsTotal++;
|
|
119
|
+
this.stats.requestsByEndpoint[endpoint] = (this.stats.requestsByEndpoint[endpoint] || 0) + 1;
|
|
120
|
+
// Set CORS headers if enabled
|
|
121
|
+
if (this.config.cors) {
|
|
122
|
+
// Security: When an API key is configured, restrict CORS to localhost only
|
|
123
|
+
// to prevent cross-origin attacks where a malicious site could make
|
|
124
|
+
// authenticated requests using the API key from a victim's browser.
|
|
125
|
+
if (this.config.apiKey) {
|
|
126
|
+
this.logger.warn('[StringRayAPIServer] Security: API key is set with CORS enabled. ' +
|
|
127
|
+
'Restricting Access-Control-Allow-Origin to localhost only. ' +
|
|
128
|
+
'Configure explicit allowed origins if cross-origin access is needed.');
|
|
129
|
+
const origin = req.headers.origin;
|
|
130
|
+
if (origin && ['http://localhost', 'http://127.0.0.1', 'http://localhost:3000',
|
|
131
|
+
'http://127.0.0.1:3000', 'http://localhost:5173', 'http://127.0.0.1:5173'].includes(origin)) {
|
|
132
|
+
res.setHeader('Access-Control-Allow-Origin', origin);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
res.setHeader('Access-Control-Allow-Origin', 'http://127.0.0.1');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
140
|
+
}
|
|
141
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
142
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
143
|
+
}
|
|
144
|
+
// Handle OPTIONS preflight
|
|
145
|
+
if (method === 'OPTIONS') {
|
|
146
|
+
this.sendResponse(res, 204, null);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
// Check API key for non-health endpoints
|
|
150
|
+
if (url.pathname !== '/health' && this.config.apiKey) {
|
|
151
|
+
const authHeader = req.headers.authorization;
|
|
152
|
+
if (!this.validateApiKey(authHeader)) {
|
|
153
|
+
this.sendResponse(res, 401, { error: 'Unauthorized - Invalid or missing API key' });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
let body = '';
|
|
159
|
+
if (method === 'POST' || method === 'PUT') {
|
|
160
|
+
body = await this.readBody(req);
|
|
161
|
+
}
|
|
162
|
+
// Route request
|
|
163
|
+
let result;
|
|
164
|
+
switch (url.pathname) {
|
|
165
|
+
case '/health':
|
|
166
|
+
result = await this.handleHealth();
|
|
167
|
+
this.sendResponse(res, 200, result);
|
|
168
|
+
break;
|
|
169
|
+
case '/api/agent/invoke':
|
|
170
|
+
if (method !== 'POST') {
|
|
171
|
+
this.sendResponse(res, 405, { error: 'Method not allowed - Use POST' });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
result = await this.handleAgentInvoke(JSON.parse(body));
|
|
175
|
+
this.sendResponse(res, 200, result);
|
|
176
|
+
break;
|
|
177
|
+
case '/api/agent/status':
|
|
178
|
+
result = await this.handleAgentStatus();
|
|
179
|
+
this.sendResponse(res, 200, result);
|
|
180
|
+
break;
|
|
181
|
+
case '/stats':
|
|
182
|
+
result = this.getStats();
|
|
183
|
+
this.sendResponse(res, 200, result);
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
this.sendResponse(res, 404, { error: 'Not found' });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
this.logger.error(`[StringRayAPIServer] Error handling request:`, error);
|
|
191
|
+
this.stats.errors++;
|
|
192
|
+
const errorMessage = error instanceof Error ? error.message : 'Internal server error';
|
|
193
|
+
this.sendResponse(res, 500, { error: errorMessage });
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
// Track response time
|
|
197
|
+
const responseTime = Date.now() - startTime;
|
|
198
|
+
this.responseTimes.push(responseTime);
|
|
199
|
+
// Keep only last 1000 response times
|
|
200
|
+
if (this.responseTimes.length > 1000) {
|
|
201
|
+
this.responseTimes.shift();
|
|
202
|
+
}
|
|
203
|
+
// Track status code
|
|
204
|
+
const statusCode = res.statusCode || 500;
|
|
205
|
+
this.stats.requestsByStatus[statusCode] = (this.stats.requestsByStatus[statusCode] || 0) + 1;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Handle health check request
|
|
210
|
+
*/
|
|
211
|
+
async handleHealth() {
|
|
212
|
+
let agentStatus = 'unhealthy';
|
|
213
|
+
if (this.agentInvoker?.getStatus) {
|
|
214
|
+
try {
|
|
215
|
+
const status = await this.agentInvoker.getStatus();
|
|
216
|
+
agentStatus = status.healthy ? 'healthy' : 'degraded';
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
agentStatus = 'unhealthy';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
status: agentStatus,
|
|
224
|
+
version: '1.0.0',
|
|
225
|
+
uptime: this.stats.startedAt ? Date.now() - this.stats.startedAt : 0,
|
|
226
|
+
openclaw: {
|
|
227
|
+
connected: false,
|
|
228
|
+
state: 'disconnected',
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Handle agent invoke request
|
|
234
|
+
*/
|
|
235
|
+
async handleAgentInvoke(request) {
|
|
236
|
+
if (!this.agentInvoker) {
|
|
237
|
+
return {
|
|
238
|
+
success: false,
|
|
239
|
+
error: 'Agent invoker not configured',
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const result = await this.agentInvoker.invoke(request);
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
return {
|
|
248
|
+
success: false,
|
|
249
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Handle agent status request
|
|
255
|
+
*/
|
|
256
|
+
async handleAgentStatus() {
|
|
257
|
+
if (!this.agentInvoker) {
|
|
258
|
+
return {
|
|
259
|
+
healthy: false,
|
|
260
|
+
message: 'Agent invoker not configured',
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (this.agentInvoker.getStatus) {
|
|
264
|
+
try {
|
|
265
|
+
const status = await this.agentInvoker.getStatus();
|
|
266
|
+
return {
|
|
267
|
+
healthy: status.healthy,
|
|
268
|
+
message: `Agent running version ${status.version}`,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return {
|
|
273
|
+
healthy: false,
|
|
274
|
+
message: 'Agent check failed',
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
healthy: true,
|
|
280
|
+
message: 'Agent invoker configured',
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Validate API key using constant-time comparison to prevent timing attacks
|
|
285
|
+
*/
|
|
286
|
+
validateApiKey(authHeader) {
|
|
287
|
+
if (!authHeader) {
|
|
288
|
+
return false;
|
|
289
|
+
}
|
|
290
|
+
const expectedKey = this.config.apiKey;
|
|
291
|
+
const providedKey = authHeader.startsWith('Bearer ')
|
|
292
|
+
? authHeader.slice(7)
|
|
293
|
+
: authHeader;
|
|
294
|
+
// Length mismatch check: return false immediately (length is not secret),
|
|
295
|
+
// but this does not leak information about the key content.
|
|
296
|
+
if (providedKey.length !== expectedKey.length) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
// Use timing-safe comparison for the actual key content
|
|
300
|
+
const expectedBuf = Buffer.from(expectedKey, 'utf-8');
|
|
301
|
+
const providedBuf = Buffer.from(providedKey, 'utf-8');
|
|
302
|
+
return crypto.timingSafeEqual(expectedBuf, providedBuf);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Read request body
|
|
306
|
+
*/
|
|
307
|
+
readBody(req) {
|
|
308
|
+
return new Promise((resolve, reject) => {
|
|
309
|
+
let body = '';
|
|
310
|
+
req.on('data', (chunk) => {
|
|
311
|
+
body += chunk;
|
|
312
|
+
});
|
|
313
|
+
req.on('end', () => {
|
|
314
|
+
resolve(body);
|
|
315
|
+
});
|
|
316
|
+
req.on('error', reject);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Send JSON response
|
|
321
|
+
*/
|
|
322
|
+
sendResponse(res, statusCode, data) {
|
|
323
|
+
res.statusCode = statusCode;
|
|
324
|
+
res.setHeader('Content-Type', 'application/json');
|
|
325
|
+
if (data !== null) {
|
|
326
|
+
res.end(JSON.stringify(data));
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
res.end();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Factory function to create API server
|
|
335
|
+
*/
|
|
336
|
+
export function createStringRayAPIServer(config) {
|
|
337
|
+
return new StringRayAPIServer(config);
|
|
338
|
+
}
|
|
339
|
+
//# sourceMappingURL=api-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-server.js","sourceRoot":"","sources":["../../../src/integrations/openclaw/api-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAiB7B;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,GAAuB,IAAI,CAAC;IAClC,MAAM,CAAqC;IAC3C,YAAY,GAAwB,IAAI,CAAC;IACzC,MAAM,GAAW,EAAE,CAAC;IACpB,KAAK,GAAwB;QACnC,SAAS,EAAE,CAAC;QACZ,aAAa,EAAE,CAAC;QAChB,kBAAkB,EAAE,EAAE;QACtB,gBAAgB,EAAE,EAAE;QACpB,mBAAmB,EAAE,CAAC;QACtB,MAAM,EAAE,CAAC;KACV,CAAC;IACM,aAAa,GAAa,EAAE,CAAC;IAC7B,MAAM,CAAU;IAExB,YAAY,MAAgC;QAC1C,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,K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B,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QAElD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAgC;IACvE,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenClaw WebSocket Client
|
|
3
|
+
*
|
|
4
|
+
* Implements OpenClaw Gateway Protocol v3 with proper request/response handling,
|
|
5
|
+
* reconnection logic, and event management.
|
|
6
|
+
*
|
|
7
|
+
* @version 1.0.0
|
|
8
|
+
* @since 2026-03-14
|
|
9
|
+
*/
|
|
10
|
+
import { OpenClawClientConfig, OpenClawClientState, ClientStatistics } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* OpenClaw WebSocket Client
|
|
13
|
+
*/
|
|
14
|
+
export declare class OpenClawClient {
|
|
15
|
+
private ws;
|
|
16
|
+
private config;
|
|
17
|
+
private state;
|
|
18
|
+
private pendingRequests;
|
|
19
|
+
private eventListeners;
|
|
20
|
+
private stateListeners;
|
|
21
|
+
private reconnectAttempts;
|
|
22
|
+
private reconnectTimeout;
|
|
23
|
+
private pingInterval;
|
|
24
|
+
private stats;
|
|
25
|
+
private logger;
|
|
26
|
+
constructor(config: OpenClawClientConfig);
|
|
27
|
+
/**
|
|
28
|
+
* Connect to OpenClaw Gateway
|
|
29
|
+
*/
|
|
30
|
+
connect(): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Disconnect from OpenClaw Gateway
|
|
33
|
+
*/
|
|
34
|
+
disconnect(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Send request and wait for response
|
|
37
|
+
*/
|
|
38
|
+
sendRequest<T = unknown>(method: string, params?: Record<string, unknown>): Promise<T>;
|
|
39
|
+
/**
|
|
40
|
+
* Subscribe to events
|
|
41
|
+
*/
|
|
42
|
+
subscribeToEvents(events: string[]): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get current state
|
|
45
|
+
*/
|
|
46
|
+
getState(): OpenClawClientState;
|
|
47
|
+
/**
|
|
48
|
+
* Check if connected
|
|
49
|
+
*/
|
|
50
|
+
isConnected(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get statistics
|
|
53
|
+
*/
|
|
54
|
+
getStats(): ClientStatistics;
|
|
55
|
+
/**
|
|
56
|
+
* Add event listener
|
|
57
|
+
*/
|
|
58
|
+
on(event: string, listener: Function): void;
|
|
59
|
+
/**
|
|
60
|
+
* Remove event listener
|
|
61
|
+
*/
|
|
62
|
+
off(event: string, listener: Function): void;
|
|
63
|
+
/**
|
|
64
|
+
* Add state change listener
|
|
65
|
+
*/
|
|
66
|
+
onStateChange(listener: Function): void;
|
|
67
|
+
/**
|
|
68
|
+
* Remove state change listener
|
|
69
|
+
*/
|
|
70
|
+
offStateChange(listener: Function): void;
|
|
71
|
+
/**
|
|
72
|
+
* Send handshake on connect
|
|
73
|
+
*/
|
|
74
|
+
private sendHandshake;
|
|
75
|
+
/**
|
|
76
|
+
* Handle incoming WebSocket message
|
|
77
|
+
*/
|
|
78
|
+
private handleMessage;
|
|
79
|
+
/**
|
|
80
|
+
* Handle response frame
|
|
81
|
+
*/
|
|
82
|
+
private handleResponse;
|
|
83
|
+
/**
|
|
84
|
+
* Handle event frame
|
|
85
|
+
*/
|
|
86
|
+
private handleEvent;
|
|
87
|
+
/**
|
|
88
|
+
* Handle disconnection
|
|
89
|
+
*/
|
|
90
|
+
private handleDisconnect;
|
|
91
|
+
/**
|
|
92
|
+
* Schedule reconnection
|
|
93
|
+
*/
|
|
94
|
+
private scheduleReconnect;
|
|
95
|
+
/**
|
|
96
|
+
* Start ping interval for connection health
|
|
97
|
+
*/
|
|
98
|
+
private startPingInterval;
|
|
99
|
+
/**
|
|
100
|
+
* Set client state
|
|
101
|
+
*/
|
|
102
|
+
private setState;
|
|
103
|
+
/**
|
|
104
|
+
* Generate unique ID for requests
|
|
105
|
+
*/
|
|
106
|
+
private generateId;
|
|
107
|
+
/**
|
|
108
|
+
* Generate nonce for device pairing
|
|
109
|
+
*/
|
|
110
|
+
private generateNonce;
|
|
111
|
+
/**
|
|
112
|
+
* Sign device challenge
|
|
113
|
+
*/
|
|
114
|
+
private signDeviceChallenge;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Factory function to create client
|
|
118
|
+
*/
|
|
119
|
+
export declare function createOpenClawClient(config: OpenClawClientConfig): OpenClawClient;
|
|
120
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/integrations/openclaw/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EAOnB,gBAAgB,EAOjB,MAAM,YAAY,CAAC;AAEpB;;GAEG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,EAAE,CAA0B;IACpC,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,eAAe,CAA0C;IACjE,OAAO,CAAC,cAAc,CAAyC;IAC/D,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,gBAAgB,CAA+B;IACvD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,KAAK,CAQX;IACF,OAAO,CAAC,MAAM,CAAU;gBAEZ,MAAM,EAAE,oBAAoB;IAiBxC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAyD9B;;OAEG;IACH,UA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