@elizaos/plugin-tunnel 2.0.0-beta.1 → 2.0.11-beta.7

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -6
  3. package/package.json +22 -5
  4. package/src/__tests__/unit/local-tunnel-service.test.ts +244 -13
  5. package/src/actions/start-tunnel.ts +5 -0
  6. package/src/actions/tunnel.ts +7 -30
  7. package/src/environment.ts +4 -3
  8. package/src/index.ts +1 -1
  9. package/src/services/LocalTunnelService.ts +3 -3
  10. package/dist/__tests__/TunnelTestSuite.d.ts +0 -6
  11. package/dist/__tests__/TunnelTestSuite.d.ts.map +0 -1
  12. package/dist/__tests__/TunnelTestSuite.js +0 -47
  13. package/dist/__tests__/TunnelTestSuite.js.map +0 -1
  14. package/dist/actions/get-tunnel-status.d.ts +0 -3
  15. package/dist/actions/get-tunnel-status.d.ts.map +0 -1
  16. package/dist/actions/get-tunnel-status.js +0 -43
  17. package/dist/actions/get-tunnel-status.js.map +0 -1
  18. package/dist/actions/start-tunnel.d.ts +0 -3
  19. package/dist/actions/start-tunnel.d.ts.map +0 -1
  20. package/dist/actions/start-tunnel.js +0 -96
  21. package/dist/actions/start-tunnel.js.map +0 -1
  22. package/dist/actions/stop-tunnel.d.ts +0 -3
  23. package/dist/actions/stop-tunnel.d.ts.map +0 -1
  24. package/dist/actions/stop-tunnel.js +0 -41
  25. package/dist/actions/stop-tunnel.js.map +0 -1
  26. package/dist/actions/tunnel.d.ts +0 -20
  27. package/dist/actions/tunnel.d.ts.map +0 -1
  28. package/dist/actions/tunnel.js +0 -159
  29. package/dist/actions/tunnel.js.map +0 -1
  30. package/dist/environment.d.ts +0 -18
  31. package/dist/environment.d.ts.map +0 -1
  32. package/dist/environment.js +0 -66
  33. package/dist/environment.js.map +0 -1
  34. package/dist/index.d.ts +0 -21
  35. package/dist/index.d.ts.map +0 -1
  36. package/dist/index.js +0 -46
  37. package/dist/index.js.map +0 -1
  38. package/dist/providers/tunnel-state.d.ts +0 -12
  39. package/dist/providers/tunnel-state.d.ts.map +0 -1
  40. package/dist/providers/tunnel-state.js +0 -43
  41. package/dist/providers/tunnel-state.js.map +0 -1
  42. package/dist/services/LocalTunnelService.d.ts +0 -37
  43. package/dist/services/LocalTunnelService.d.ts.map +0 -1
  44. package/dist/services/LocalTunnelService.js +0 -186
  45. package/dist/services/LocalTunnelService.js.map +0 -1
  46. package/dist/types.d.ts +0 -47
  47. package/dist/types.d.ts.map +0 -1
  48. package/dist/types.js +0 -34
  49. package/dist/types.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shaw Walters and elizaOS Contributors
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 CHANGED
@@ -4,19 +4,19 @@ Local Tailscale-CLI tunnel backend for elizaOS.
4
4
 
5
5
  Registers `serviceType = "tunnel"` and exposes:
6
6
 
7
- - **`TUNNEL` action** — dispatcher with `op` parameter-enum (`start | stop | status`). Legacy `TAILSCALE`-prefixed action names are kept as similes.
7
+ - **`TUNNEL` action** — provider-neutral dispatcher with `action=start | stop | status`.
8
8
  - **`TUNNEL_STATE` provider** — reads the active service's `getStatus()` into model state.
9
9
  - **`LocalTunnelService`** — wraps `tailscale serve` / `tailscale funnel`.
10
10
 
11
11
  ## Coexistence
12
12
 
13
- `plugin-tunnel`, [`@elizaos/plugin-elizacloud`](../plugin-elizacloud) (hosted headscale + reverse proxy), and [`@elizaos/plugin-ngrok`](https://github.com/elizaos-plugins/plugin-ngrok) all register under `serviceType="tunnel"`. **First active wins** — each plugin's `init` only registers if its credentials are present *and* the slot is free.
13
+ `plugin-tunnel`, [`@elizaos/plugin-elizacloud`](../plugin-elizacloud) (hosted headscale + reverse proxy), and [`@elizaos/plugin-ngrok`](../plugin-ngrok) all register under `serviceType="tunnel"`. **First active wins** — each plugin's `init` calls `tunnelSlotIsFree(runtime)` and only registers its service if the slot is still free (plus any backend-specific check: `plugin-tunnel` also requires the `tailscale` binary on PATH).
14
14
 
15
15
  ```
16
16
  character.plugins = [
17
- '@elizaos/plugin-elizacloud', // wins if ELIZAOS_CLOUD_API_KEY set
18
- '@elizaos/plugin-tunnel', // falls back to local tailscale CLI
19
- '@elizaos/plugin-ngrok', // last-resort, if NGROK_AUTHTOKEN set
17
+ '@elizaos/plugin-elizacloud', // hosted headscale backend (ELIZAOS_CLOUD_API_KEY)
18
+ '@elizaos/plugin-tunnel', // local tailscale CLI (requires tailscale on PATH)
19
+ '@elizaos/plugin-ngrok', // ngrok backend (NGROK_AUTH_TOKEN)
20
20
  ];
21
21
  ```
22
22
 
@@ -36,4 +36,6 @@ character.plugins = [
36
36
  | `TUNNEL_FUNNEL` | `false` | When true, uses `tailscale funnel` instead of `tailscale serve` |
37
37
  | `TUNNEL_DEFAULT_PORT` | `3000` | Used when no port is extracted from the user's message |
38
38
 
39
- `TAILSCALE_*` aliases are accepted for one release window.
39
+ `TUNNEL_*` env vars are canonical. `TAILSCALE_*` env vars are accepted only as
40
+ backend configuration aliases for the local Tailscale provider, not as action
41
+ names.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/plugin-tunnel",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.11-beta.7",
4
4
  "description": "Tunnel plugin for elizaOS — local Tailscale CLI backend (serve/funnel). Pair with @elizaos/plugin-elizacloud for the hosted headscale backend.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -10,8 +10,24 @@
10
10
  "./package.json": "./package.json",
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
+ "eliza-source": {
14
+ "types": "./src/index.ts",
15
+ "import": "./src/index.ts",
16
+ "default": "./src/index.ts"
17
+ },
13
18
  "import": "./dist/index.js",
14
19
  "default": "./dist/index.js"
20
+ },
21
+ "./*.css": "./dist/*.css",
22
+ "./*": {
23
+ "types": "./dist/*.d.ts",
24
+ "eliza-source": {
25
+ "types": "./src/*.ts",
26
+ "import": "./src/*.ts",
27
+ "default": "./src/*.ts"
28
+ },
29
+ "import": "./dist/*.js",
30
+ "default": "./dist/*.js"
15
31
  }
16
32
  },
17
33
  "files": [
@@ -21,7 +37,7 @@
21
37
  "scripts": {
22
38
  "build": "tsc --noCheck -p tsconfig.json",
23
39
  "dev": "tsc --watch",
24
- "typecheck": "tsc --noEmit",
40
+ "typecheck": "tsgo --noEmit",
25
41
  "test": "bun test",
26
42
  "test:unit": "bun test src/__tests__/",
27
43
  "lint": "bunx @biomejs/biome check --write --unsafe .",
@@ -37,10 +53,10 @@
37
53
  "networking"
38
54
  ],
39
55
  "peerDependencies": {
40
- "@elizaos/core": "2.0.0-beta.1"
56
+ "@elizaos/core": "2.0.11-beta.7"
41
57
  },
42
58
  "dependencies": {
43
- "@elizaos/core": "2.0.0-beta.1",
59
+ "@elizaos/core": "2.0.11-beta.7",
44
60
  "zod": "^4.4.2"
45
61
  },
46
62
  "devDependencies": {
@@ -55,5 +71,6 @@
55
71
  "agentConfig": {
56
72
  "pluginType": "elizaos:plugin:1.0.0",
57
73
  "pluginParameters": {}
58
- }
74
+ },
75
+ "gitHead": "cdbc876f793d96073d7eb0d09715a031ce0cd32e"
59
76
  }
@@ -1,23 +1,254 @@
1
- import { describe, expect, it } from 'vitest';
1
+ import { describe, expect, it, mock } from 'bun:test';
2
+ import type { HandlerCallback, IAgentRuntime, Memory } from '@elizaos/core';
3
+ import { ModelType } from '@elizaos/core';
4
+ import { handleGetTunnelStatus } from '../../actions/get-tunnel-status';
5
+ import { handleStartTunnel } from '../../actions/start-tunnel';
6
+ import { handleStopTunnel } from '../../actions/stop-tunnel';
2
7
  import { tunnelAction } from '../../actions/tunnel';
8
+ import { validateTunnelConfig } from '../../environment';
3
9
  import { tunnelStateProvider } from '../../providers/tunnel-state';
4
10
  import { LocalTunnelService } from '../../services/LocalTunnelService';
11
+ import type { ITunnelService } from '../../types';
5
12
 
6
- describe('plugin-tunnel exports', () => {
7
- it('LocalTunnelService registers under serviceType="tunnel"', () => {
8
- expect(LocalTunnelService.serviceType).toBe('tunnel');
13
+ function tunnelService(overrides: Partial<ITunnelService> = {}): ITunnelService {
14
+ return {
15
+ getStatus: mock(() => ({
16
+ active: false,
17
+ url: 'https://device.example.ts.net',
18
+ port: 8080,
19
+ startedAt: new Date('2026-01-01T00:00:00.000Z'),
20
+ provider: 'tailscale',
21
+ backend: 'local-cli',
22
+ })),
23
+ getUrl: mock(() => 'https://device.example.ts.net'),
24
+ isActive: mock(() => false),
25
+ startTunnel: mock(async () => 'https://device.example.ts.net'),
26
+ stopTunnel: mock(async () => {}),
27
+ ...overrides,
28
+ };
29
+ }
30
+
31
+ function runtime(service: ITunnelService | null, modelResponse = '{"port": 3000}'): IAgentRuntime {
32
+ return {
33
+ getService: mock(() => service),
34
+ useModel: mock(async () => modelResponse),
35
+ } as unknown as IAgentRuntime;
36
+ }
37
+
38
+ const message = { content: { text: 'start a tunnel' } } as Memory;
39
+
40
+ describe('plugin-tunnel start action', () => {
41
+ it('starts the active tunnel service with an explicit string port and reports callback data', async () => {
42
+ const service = tunnelService();
43
+ const callback = mock(async () => {}) as HandlerCallback;
44
+
45
+ const result = await handleStartTunnel(
46
+ runtime(service),
47
+ message,
48
+ undefined,
49
+ { port: '8080' },
50
+ callback
51
+ );
52
+
53
+ expect(service.startTunnel).toHaveBeenCalledWith(8080);
54
+ expect(callback).toHaveBeenCalledWith({
55
+ text: 'Tunnel started (tailscale).\n\nURL: https://device.example.ts.net\nLocal port: 8080',
56
+ });
57
+ expect(result).toEqual({
58
+ success: true,
59
+ text: 'Tunnel started on port 8080',
60
+ data: {
61
+ action: 'tunnel_started',
62
+ tunnelUrl: 'https://device.example.ts.net',
63
+ port: 8080,
64
+ provider: 'tailscale',
65
+ },
66
+ });
67
+ });
68
+
69
+ it('falls back to model-derived ports and defaults invalid model output to 3000', async () => {
70
+ const validService = tunnelService();
71
+ const validRuntime = runtime(validService, '{"port": 4321}');
72
+
73
+ await handleStartTunnel(validRuntime, message);
74
+
75
+ expect(validRuntime.useModel).toHaveBeenCalledWith(ModelType.TEXT_SMALL, expect.any(Object));
76
+ expect(validService.startTunnel).toHaveBeenCalledWith(4321);
77
+
78
+ const invalidService = tunnelService();
79
+ await handleStartTunnel(runtime(invalidService, '{"port": 999999}'), message);
80
+
81
+ expect(invalidService.startTunnel).toHaveBeenCalledWith(3000);
9
82
  });
10
83
 
11
- it('TUNNEL action exposes start/stop/status enum and similes', () => {
12
- expect(tunnelAction.name).toBe('TUNNEL');
13
- const opParam = tunnelAction.parameters?.find((p) => p.name === 'action');
14
- expect(opParam).toBeDefined();
15
- expect((opParam?.schema as { enum?: string[] }).enum).toEqual(['start', 'stop', 'status']);
16
- expect(tunnelAction.similes).toEqual(expect.arrayContaining(['TAILSCALE', 'START_TUNNEL']));
84
+ it('does not start when the tunnel service is missing or already active', async () => {
85
+ const missingCallback = mock(async () => {}) as HandlerCallback;
86
+
87
+ await expect(
88
+ handleStartTunnel(runtime(null), message, undefined, undefined, missingCallback)
89
+ ).resolves.toEqual({ success: false, error: 'tunnel service unavailable' });
90
+ expect(missingCallback).toHaveBeenCalledWith({
91
+ text: 'Tunnel service is not available. Configure plugin-tunnel, plugin-elizacloud, or plugin-ngrok.',
92
+ });
93
+
94
+ const activeService = tunnelService({ isActive: mock(() => true) });
95
+ await expect(handleStartTunnel(runtime(activeService), message)).resolves.toEqual({
96
+ success: false,
97
+ error: 'tunnel already active',
98
+ });
99
+ expect(activeService.startTunnel).not.toHaveBeenCalled();
17
100
  });
18
101
 
19
- it('TUNNEL_STATE provider has get() and is named correctly', () => {
20
- expect(tunnelStateProvider.name).toBe('TUNNEL_STATE');
21
- expect(typeof tunnelStateProvider.get).toBe('function');
102
+ it.each([
103
+ 0,
104
+ 65_536,
105
+ 1.5,
106
+ Number.NaN,
107
+ 'abc',
108
+ '../../3000',
109
+ ])('rejects explicit hostile port %s before model fallback or service start', async (port) => {
110
+ const service = tunnelService();
111
+ const rt = runtime(service);
112
+ const callback = mock(async () => {}) as HandlerCallback;
113
+
114
+ await expect(handleStartTunnel(rt, message, undefined, { port }, callback)).resolves.toEqual({
115
+ success: false,
116
+ error: 'invalid tunnel port',
117
+ });
118
+
119
+ expect(rt.useModel).not.toHaveBeenCalled();
120
+ expect(service.startTunnel).not.toHaveBeenCalled();
121
+ expect(callback).toHaveBeenCalledWith({
122
+ text: 'Invalid tunnel port. Port must be an integer between 1 and 65535.',
123
+ });
124
+ });
125
+
126
+ it('dispatches nested TUNNEL action parameters to start without leaking action into sub-options', async () => {
127
+ const service = tunnelService();
128
+
129
+ const result = await tunnelAction.handler(runtime(service), message, undefined, {
130
+ parameters: { action: 'start', parameters: { port: 9090 } },
131
+ });
132
+
133
+ expect(service.startTunnel).toHaveBeenCalledWith(9090);
134
+ expect(result.success).toBe(true);
135
+ });
136
+
137
+ it('returns structured errors for missing and unknown TUNNEL actions', async () => {
138
+ const callback = mock(async () => {}) as HandlerCallback;
139
+ const rt = runtime(tunnelService());
140
+
141
+ await expect(tunnelAction.handler(rt, message, undefined, {}, callback)).resolves.toEqual({
142
+ success: false,
143
+ error: 'TUNNEL requires action=start|stop|status',
144
+ });
145
+ await expect(
146
+ tunnelAction.handler(rt, message, undefined, { action: 'restart<script>' }, callback)
147
+ ).resolves.toEqual({
148
+ success: false,
149
+ error: 'Unknown TUNNEL action "restart<script>". Supported: start, stop, status',
150
+ });
151
+ });
152
+ });
153
+
154
+ describe('plugin-tunnel stop/status/provider/config behavior', () => {
155
+ it('stops an active tunnel and reports the previous endpoint', async () => {
156
+ const service = tunnelService({
157
+ isActive: mock(() => true),
158
+ getStatus: mock(() => ({
159
+ active: true,
160
+ url: 'https://device.example.ts.net',
161
+ port: 8080,
162
+ startedAt: new Date('2026-01-01T00:00:00.000Z'),
163
+ provider: 'tailscale',
164
+ backend: 'local-cli',
165
+ })),
166
+ });
167
+ const callback = mock(async () => {}) as HandlerCallback;
168
+
169
+ await expect(
170
+ handleStopTunnel(runtime(service), message, undefined, undefined, callback)
171
+ ).resolves.toMatchObject({
172
+ success: true,
173
+ data: {
174
+ action: 'tunnel_stopped',
175
+ previousUrl: 'https://device.example.ts.net',
176
+ previousPort: 8080,
177
+ },
178
+ });
179
+ expect(service.stopTunnel).toHaveBeenCalledTimes(1);
180
+ expect(callback).toHaveBeenCalledWith({
181
+ text: 'Tunnel stopped.\n\nWas running on port: 8080\nPrevious URL: https://device.example.ts.net',
182
+ });
183
+ });
184
+
185
+ it('reports status and provider state without mutating inactive services', async () => {
186
+ const service = tunnelService({
187
+ isActive: mock(() => false),
188
+ getStatus: mock(() => ({
189
+ active: false,
190
+ url: null,
191
+ port: null,
192
+ startedAt: null,
193
+ provider: 'tailscale',
194
+ backend: 'local-cli',
195
+ })),
196
+ });
197
+
198
+ await expect(handleGetTunnelStatus(runtime(service), message)).resolves.toMatchObject({
199
+ success: true,
200
+ data: {
201
+ action: 'tunnel_status',
202
+ active: false,
203
+ provider: 'tailscale',
204
+ backend: 'local-cli',
205
+ },
206
+ });
207
+ await expect(tunnelStateProvider.get(runtime(service), message)).resolves.toEqual({
208
+ text: 'Tunnel idle (tailscale ready).',
209
+ data: {
210
+ available: true,
211
+ active: false,
212
+ url: null,
213
+ port: null,
214
+ startedAt: null,
215
+ provider: 'tailscale',
216
+ backend: 'local-cli',
217
+ },
218
+ });
219
+ expect(service.startTunnel).not.toHaveBeenCalled();
220
+ expect(service.stopTunnel).not.toHaveBeenCalled();
221
+ });
222
+
223
+ it('sanitizes tunnel config and falls back on hostile default ports', async () => {
224
+ const getSetting = mock((key: string) => {
225
+ const values: Record<string, unknown> = {
226
+ TUNNEL_TAGS: ' tag:one, ,tag:two ',
227
+ TUNNEL_FUNNEL: '1',
228
+ TUNNEL_DEFAULT_PORT: '../../99999',
229
+ };
230
+ return values[key] ?? null;
231
+ });
232
+
233
+ await expect(validateTunnelConfig({ getSetting } as unknown as IAgentRuntime)).resolves.toEqual(
234
+ {
235
+ TUNNEL_TAGS: ['tag:one', 'tag:two'],
236
+ TUNNEL_FUNNEL: true,
237
+ TUNNEL_DEFAULT_PORT: 3000,
238
+ }
239
+ );
240
+ });
241
+
242
+ it.each([
243
+ 0,
244
+ 65_536,
245
+ 1.5,
246
+ Number.NaN,
247
+ ])('LocalTunnelService rejects hostile runtime port %s before config or CLI calls', async (port) => {
248
+ const service = new LocalTunnelService({
249
+ getSetting: mock(() => null),
250
+ } as unknown as IAgentRuntime);
251
+
252
+ await expect(service.startTunnel(port as number)).rejects.toThrow('Invalid port number');
22
253
  });
23
254
  });
@@ -84,6 +84,11 @@ export async function handleStartTunnel(
84
84
  const parsed = Number.parseInt(explicitPort, 10);
85
85
  if (isValidPort(parsed)) port = parsed;
86
86
  }
87
+ if (explicitPort !== undefined && port === undefined) {
88
+ const message = 'Invalid tunnel port. Port must be an integer between 1 and 65535.';
89
+ if (callback) await callback({ text: message });
90
+ return { success: false, error: 'invalid tunnel port' };
91
+ }
87
92
 
88
93
  if (port === undefined) {
89
94
  const userMessage = message.content.text ?? '';
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @module tunnel
3
3
  * @description Single dispatcher action that fans out to the active
4
- * tunnel-service implementation. The action's name is `TUNNEL`; legacy
5
- * `TAILSCALE`-prefixed action names are kept as `similes` so older
6
- * characters and callers still resolve.
4
+ * tunnel-service implementation. The action's name is `TUNNEL`; concrete
5
+ * providers such as local Tailscale, Eliza Cloud headscale, and ngrok only
6
+ * register the service backend.
7
7
  *
8
8
  * Sub-ops (selected via the `action` parameter-enum):
9
9
  * - start -> handleStartTunnel (optional `port`, defaults to 3000)
@@ -45,7 +45,7 @@ function resolveDispatch(options: Record<string, unknown> | undefined): {
45
45
  }
46
46
  const nested = pickRecord(options.parameters);
47
47
  const actionSource = nested ?? options;
48
- const rawAction = actionSource.action ?? actionSource.subaction ?? actionSource.op;
48
+ const rawAction = actionSource.action;
49
49
  const action = typeof rawAction === 'string' ? rawAction.toLowerCase() : null;
50
50
 
51
51
  let subOptions: Record<string, unknown>;
@@ -54,17 +54,11 @@ function resolveDispatch(options: Record<string, unknown> | undefined): {
54
54
  if (innerParams) {
55
55
  subOptions = { ...innerParams };
56
56
  } else {
57
- const {
58
- action: _omitAction,
59
- subaction: _omitSubaction,
60
- op: _omitOp,
61
- parameters: _omitParams,
62
- ...rest
63
- } = nested;
57
+ const { action: _omitAction, parameters: _omitParams, ...rest } = nested;
64
58
  subOptions = rest;
65
59
  }
66
60
  } else {
67
- const { action: _omitAction, subaction: _omitSubaction, op: _omitOp, ...rest } = options;
61
+ const { action: _omitAction, ...rest } = options;
68
62
  subOptions = rest;
69
63
  }
70
64
 
@@ -73,24 +67,7 @@ function resolveDispatch(options: Record<string, unknown> | undefined): {
73
67
 
74
68
  export const tunnelAction: Action = {
75
69
  name: 'TUNNEL',
76
- similes: [
77
- // Legacy action names kept so existing characters/transcripts still resolve.
78
- 'TAILSCALE',
79
- 'START_TAILSCALE',
80
- 'STOP_TAILSCALE',
81
- 'GET_TAILSCALE_STATUS',
82
- 'START_TUNNEL',
83
- 'OPEN_TUNNEL',
84
- 'CREATE_TUNNEL',
85
- 'TAILSCALE_UP',
86
- 'STOP_TUNNEL',
87
- 'CLOSE_TUNNEL',
88
- 'TAILSCALE_DOWN',
89
- 'TAILSCALE_STATUS',
90
- 'CHECK_TUNNEL',
91
- 'TUNNEL_INFO',
92
- 'TUNNEL_STATUS',
93
- ],
70
+ similes: ['OPEN_TUNNEL', 'CREATE_TUNNEL', 'CLOSE_TUNNEL', 'CHECK_TUNNEL', 'TUNNEL_INFO'],
94
71
  description:
95
72
  'Tunnel operations dispatched by `action`: start, stop, status. The `start` action accepts an optional `port` (defaults to 3000); `stop` and `status` take no parameters. Backed by whichever tunnel plugin is active (local Tailscale CLI, Eliza Cloud headscale, or ngrok).',
96
73
 
@@ -14,7 +14,8 @@ export const tunnelEnvSchema = z.object({
14
14
  .union([z.string(), z.array(z.string())])
15
15
  .optional()
16
16
  .transform((value) => {
17
- if (Array.isArray(value)) return value.filter((tag) => tag.length > 0);
17
+ if (Array.isArray(value))
18
+ return value.map((tag) => tag.trim()).filter((tag) => tag.length > 0);
18
19
  if (typeof value === 'string' && value.length > 0)
19
20
  return value
20
21
  .split(',')
@@ -33,8 +34,8 @@ export const tunnelEnvSchema = z.object({
33
34
  .optional()
34
35
  .transform((value) => {
35
36
  if (value === undefined || value === '') return 3000;
36
- const num = typeof value === 'string' ? Number.parseInt(value, 10) : value;
37
- if (Number.isNaN(num) || num <= 0 || num > 65535) return 3000;
37
+ const num = typeof value === 'string' && /^\d+$/.test(value) ? Number(value) : value;
38
+ if (typeof num !== 'number' || !Number.isInteger(num) || num <= 0 || num > 65535) return 3000;
38
39
  return num;
39
40
  })
40
41
  .default(3000),
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { elizaLogger, promoteSubactionsToActions, type Plugin } from '@elizaos/core';
1
+ import { elizaLogger, type Plugin, promoteSubactionsToActions } from '@elizaos/core';
2
2
  import { TunnelTestSuite } from './__tests__/TunnelTestSuite';
3
3
  import { tunnelAction } from './actions/tunnel';
4
4
  import { tunnelStateProvider } from './providers/tunnel-state';
@@ -32,8 +32,8 @@ function runCommand(cmd: string, args: string[]): Promise<SpawnResult> {
32
32
  const child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'pipe'] });
33
33
  const out: Buffer[] = [];
34
34
  const err: Buffer[] = [];
35
- child.stdout?.on('data', (chunk: Buffer) => out.push(chunk));
36
- child.stderr?.on('data', (chunk: Buffer) => err.push(chunk));
35
+ child.stdout.on('data', (chunk: Buffer) => out.push(chunk));
36
+ child.stderr.on('data', (chunk: Buffer) => err.push(chunk));
37
37
  child.on('error', reject);
38
38
  child.on('exit', (code) =>
39
39
  resolve({
@@ -122,7 +122,7 @@ export class LocalTunnelService extends Service implements ITunnelService {
122
122
  return;
123
123
  }
124
124
 
125
- if (port < 1 || port > 65535) {
125
+ if (!Number.isInteger(port) || port < 1 || port > 65535) {
126
126
  throw new Error('Invalid port number');
127
127
  }
128
128
 
@@ -1,6 +0,0 @@
1
- import type { TestCase, TestSuite } from '@elizaos/core';
2
- export declare class TunnelTestSuite implements TestSuite {
3
- name: string;
4
- tests: TestCase[];
5
- }
6
- //# sourceMappingURL=TunnelTestSuite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TunnelTestSuite.d.ts","sourceRoot":"","sources":["../../src/__tests__/TunnelTestSuite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,QAAQ,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAKxE,qBAAa,eAAgB,YAAW,SAAS;IAC/C,IAAI,SAAY;IAChB,KAAK,EAAE,QAAQ,EAAE,CAqCf;CACH"}
@@ -1,47 +0,0 @@
1
- import { tunnelAction } from '../actions/tunnel';
2
- import { tunnelStateProvider } from '../providers/tunnel-state';
3
- import { LocalTunnelService } from '../services/LocalTunnelService';
4
- export class TunnelTestSuite {
5
- name = 'tunnel';
6
- tests = [
7
- {
8
- name: 'LocalTunnelService — service-type contract',
9
- fn: (_runtime) => {
10
- if (LocalTunnelService.serviceType !== 'tunnel') {
11
- throw new Error('LocalTunnelService.serviceType must be "tunnel"');
12
- }
13
- },
14
- },
15
- {
16
- name: 'tunnelAction — name and op enum',
17
- fn: (_runtime) => {
18
- if (tunnelAction.name !== 'TUNNEL') {
19
- throw new Error(`tunnelAction.name must be "TUNNEL", got ${tunnelAction.name}`);
20
- }
21
- const opParam = tunnelAction.parameters?.find((p) => p.name === 'op');
22
- if (!opParam)
23
- throw new Error('tunnelAction must declare an `op` parameter');
24
- const enumVals = opParam.schema?.enum;
25
- if (!Array.isArray(enumVals))
26
- throw new Error('op parameter must declare a string enum');
27
- for (const expected of ['start', 'stop', 'status']) {
28
- if (!enumVals.includes(expected)) {
29
- throw new Error(`op enum missing "${expected}"`);
30
- }
31
- }
32
- },
33
- },
34
- {
35
- name: 'TUNNEL_STATE provider — name and shape',
36
- fn: (_runtime) => {
37
- if (tunnelStateProvider.name !== 'TUNNEL_STATE') {
38
- throw new Error(`tunnelStateProvider.name must be "TUNNEL_STATE"`);
39
- }
40
- if (typeof tunnelStateProvider.get !== 'function') {
41
- throw new Error('tunnelStateProvider must define get()');
42
- }
43
- },
44
- },
45
- ];
46
- }
47
- //# sourceMappingURL=TunnelTestSuite.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TunnelTestSuite.js","sourceRoot":"","sources":["../../src/__tests__/TunnelTestSuite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,MAAM,OAAO,eAAe;IAC1B,IAAI,GAAG,QAAQ,CAAC;IAChB,KAAK,GAAe;QAClB;YACE,IAAI,EAAE,4CAA4C;YAClD,EAAE,EAAE,CAAC,QAAuB,EAAE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,mBAAmB,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;oBAClD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBAC3D,CAAC;YACH,CAAC;SACF;KACF,CAAC;CACH"}
@@ -1,3 +0,0 @@
1
- import { type ActionResult, type HandlerCallback, type IAgentRuntime, type Memory, type State } from '@elizaos/core';
2
- export declare function handleGetTunnelStatus(runtime: IAgentRuntime, _message?: Memory, _state?: State, _options?: Record<string, unknown>, callback?: HandlerCallback): Promise<ActionResult>;
3
- //# sourceMappingURL=get-tunnel-status.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-tunnel-status.d.ts","sourceRoot":"","sources":["../../src/actions/get-tunnel-status.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,MAAM,EACX,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AAavB,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,KAAK,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,QAAQ,CAAC,EAAE,eAAe,GACzB,OAAO,CAAC,YAAY,CAAC,CAiCvB"}
@@ -1,43 +0,0 @@
1
- import { elizaLogger, } from '@elizaos/core';
2
- import { getTunnelService } from '../types';
3
- function formatUptime(startedAt) {
4
- const ms = Date.now() - startedAt.getTime();
5
- const minutes = Math.floor(ms / 60_000);
6
- const hours = Math.floor(minutes / 60);
7
- if (hours > 0) {
8
- return `${hours} hour${hours === 1 ? '' : 's'}, ${minutes % 60} minute${minutes % 60 === 1 ? '' : 's'}`;
9
- }
10
- return `${minutes} minute${minutes === 1 ? '' : 's'}`;
11
- }
12
- export async function handleGetTunnelStatus(runtime, _message, _state, _options, callback) {
13
- const tunnelService = getTunnelService(runtime);
14
- if (!tunnelService) {
15
- if (callback) {
16
- await callback({ text: 'Tunnel service is not available.' });
17
- }
18
- return { success: false, error: 'tunnel service unavailable' };
19
- }
20
- elizaLogger.info('[get-tunnel-status] reading status');
21
- const status = tunnelService.getStatus();
22
- const uptime = status.startedAt ? formatUptime(status.startedAt) : 'N/A';
23
- const responseText = status.active
24
- ? `✅ tunnel active (${status.provider}).\n\nURL: ${status.url}\nLocal port: ${status.port}\nUptime: ${uptime}`
25
- : '❌ No active tunnel. Say "start tunnel on port [PORT]" to start one.';
26
- if (callback) {
27
- await callback({ text: responseText });
28
- }
29
- return {
30
- success: true,
31
- text: responseText,
32
- data: {
33
- action: 'tunnel_status',
34
- active: status.active,
35
- url: status.url ?? '',
36
- port: status.port ?? 0,
37
- provider: status.provider,
38
- backend: status.backend ?? '',
39
- uptime,
40
- },
41
- };
42
- }
43
- //# sourceMappingURL=get-tunnel-status.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-tunnel-status.js","sourceRoot":"","sources":["../../src/actions/get-tunnel-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,GAKZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,SAAS,YAAY,CAAC,SAAe;IACnC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC;IACvC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACd,OAAO,GAAG,KAAK,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,GAAG,EAAE,UAAU,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC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AM;YACrB,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,EAAE;YACrB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC;YACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,EAAE;YAC7B,MAAM;SACP;KACF,CAAC;AACJ,CAAC"}
@@ -1,3 +0,0 @@
1
- import { type ActionResult, type HandlerCallback, type IAgentRuntime, type Memory, type State } from '@elizaos/core';
2
- export declare function handleStartTunnel(runtime: IAgentRuntime, message: Memory, _state?: State, options?: Record<string, unknown>, callback?: HandlerCallback): Promise<ActionResult>;
3
- //# sourceMappingURL=start-tunnel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"start-tunnel.d.ts","sourceRoot":"","sources":["../../src/actions/start-tunnel.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,MAAM,EAEX,KAAK,KAAK,EACX,MAAM,eAAe,CAAC;AA0CvB,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,KAAK,EACd,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,QAAQ,CAAC,EAAE,eAAe,GACzB,OAAO,CAAC,YAAY,CAAC,CA4DvB"}