openclaw-http-test 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 rui
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # openclaw-http
2
+
3
+ OpenClaw plugin that manages an Express HTTP server lifecycle and exposes tools to agents.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install openclaw-http
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - Manages an Express HTTP server as an OpenClaw service (auto start/stop with Gateway)
14
+ - Registers agent tools (e.g., `get_weather_demo`)
15
+ - Exposes Gateway RPC method `express-backend.status`
16
+
17
+ ## Usage
18
+
19
+ Load as an OpenClaw plugin. The Gateway will call `start()` on boot and `stop()` on shutdown.
20
+
21
+ ### Files
22
+
23
+ | File | Description |
24
+ |------|-------------|
25
+ | `index.mjs` | Plugin entry point, registers service and tools |
26
+ | `server.cjs` | Express HTTP server (port 8999) |
27
+ | `openclaw.plugin.json` | Plugin metadata |
28
+
29
+ ### Registered Tools
30
+
31
+ - **`get_weather_demo`** - Demo tool that returns mock weather data for a given city
32
+
33
+ ### Quick Test
34
+
35
+ ```bash
36
+ # After Gateway starts the service
37
+ curl http://127.0.0.1:8999/api/runtimes
38
+ ```
39
+
40
+ ## License
41
+
42
+ MIT
package/index.mjs ADDED
@@ -0,0 +1,90 @@
1
+ /*
2
+ * @Author: wr_st 584490439@qq.com
3
+ * @Date: 2026-03-21 20:59:03
4
+ * @LastEditors: wr_st 584490439@qq.com
5
+ * @LastEditTime: 2026-03-23 16:37:10
6
+ * @FilePath: /openclaw-http/index.mjs
7
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+ */
9
+ import { spawn } from 'child_process';
10
+ import { fileURLToPath } from 'url';
11
+ import { dirname, join } from 'path';
12
+
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+
15
+ let child = null;
16
+
17
+ export default function (api) {
18
+ api.registerService({
19
+ id: 'my-backend-service',
20
+ start: async (ctx) => {
21
+ if (child) return;
22
+
23
+ const serverPath = join(__dirname, 'server.cjs');
24
+ child = spawn('node', [serverPath], {
25
+ stdio: ['ignore', 'pipe', 'pipe'],
26
+ });
27
+
28
+ child.stdout.on('data', (data) => {
29
+ ctx.logger.info(data.toString().trimEnd());
30
+ });
31
+ child.stderr.on('data', (data) => {
32
+ ctx.logger.error(data.toString().trimEnd());
33
+ });
34
+ child.on('close', (code) => {
35
+ ctx.logger.info(`[my-backend-service] server.js exited with code ${code}`);
36
+ child = null;
37
+ });
38
+ },
39
+ stop: async (ctx) => {
40
+ if (!child) return;
41
+
42
+ const proc = child;
43
+ child = null;
44
+
45
+ proc.kill('SIGTERM');
46
+ await new Promise((resolve) => proc.on('close', resolve));
47
+ ctx.logger.info('[my-backend-service] server.js stopped');
48
+ },
49
+ });
50
+
51
+ // Optional: a small status RPC to confirm the service is up.
52
+ api.registerGatewayMethod('express-backend.status', async () => ({
53
+ status: 'ok',
54
+ pid: process.pid,
55
+ }));
56
+ api.registerTool({
57
+ name: 'get_weather',
58
+ description: '获取某个城市的演示天气数据',
59
+ parameters: {
60
+ type: 'object',
61
+ additionalProperties: false,
62
+ properties: {
63
+ city: {
64
+ type: 'string',
65
+ description: '城市名,比如 Shanghai',
66
+ },
67
+ },
68
+ required: ['city'],
69
+ },
70
+ async execute(_id, params) {
71
+ const city = params.city?.trim() || 'Unknown';
72
+
73
+ const result = {
74
+ city,
75
+ weather: 'sunny',
76
+ tempC: 26,
77
+ source: 'demo',
78
+ };
79
+
80
+ return {
81
+ content: [
82
+ {
83
+ type: 'text',
84
+ text: JSON.stringify(result, null, 2),
85
+ },
86
+ ],
87
+ };
88
+ },
89
+ });
90
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "id": "openclaw-http-test",
3
+ "name": "OpenClaw HTTP Test",
4
+ "description": "Expose a local ChromeAgent/Relay Tool API to OpenClaw as agent tools.",
5
+ "version": "0.1.0",
6
+ "configSchema": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "properties": {}
10
+ }
11
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "openclaw-http-test",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "index.mjs",
6
+ "description": "OpenClaw plugin - Manage an Express HTTP server lifecycle and expose tools to agents",
7
+ "keywords": [
8
+ "openclaw",
9
+ "openclaw-plugin",
10
+ "http",
11
+ "express",
12
+ "agent-tools"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "rui <584490439@qq.com>",
16
+ "files": [
17
+ "index.mjs",
18
+ "server.cjs",
19
+ "openclaw.plugin.json",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "scripts": {
24
+ "dev": "node ./dev/standalone.js"
25
+ },
26
+ "openclaw": {
27
+ "extensions": [
28
+ "./index.mjs"
29
+ ]
30
+ },
31
+ "dependencies": {
32
+ "express": "^4.18.2"
33
+ },
34
+ "engines": {
35
+ "node": ">=18"
36
+ }
37
+ }
package/server.cjs ADDED
@@ -0,0 +1,39 @@
1
+ /*
2
+ * @Author: wr_st 584490439@qq.com
3
+ * @Date: 2026-03-21 21:08:15
4
+ * @LastEditors: wr_st 584490439@qq.com
5
+ * @LastEditTime: 2026-03-23 16:40:10
6
+ * @FilePath: /openclaw-http/server.cjs
7
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+ */
9
+ /*
10
+ * Local demo HTTP server for the openclaw-http plugin.
11
+ */
12
+ const express = require('express');
13
+ const { createServer } = require('http');
14
+
15
+ const app = express();
16
+ const server = createServer(app);
17
+ const PORT = 8899;
18
+
19
+ app.use((req, res, next) => {
20
+ res.header('Access-Control-Allow-Origin', '*');
21
+ res.header('Access-Control-Allow-Methods', 'GET,POST,PUT,PATCH,DELETE,OPTIONS');
22
+ res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
23
+
24
+ if (req.method === 'OPTIONS') {
25
+ return res.sendStatus(204);
26
+ }
27
+
28
+ next();
29
+ });
30
+
31
+ app.use(express.json());
32
+
33
+ app.get('/api/runtimes', (_req, res) => {
34
+ res.json({ success: true, runtimes: 'ok' });
35
+ });
36
+
37
+ server.listen(PORT, () => {
38
+ console.log(`[Relay] Server running on http://localhost:${PORT}`);
39
+ });