@tenux/cli 0.0.15 → 0.0.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.
- package/dist/{chunk-IQO7AGGC.js → chunk-MB4X6UQJ.js} +23 -8
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -90,6 +90,9 @@ var Relay = class {
|
|
|
90
90
|
channel = null;
|
|
91
91
|
handlers = /* @__PURE__ */ new Map();
|
|
92
92
|
deviceId;
|
|
93
|
+
pollTimer = null;
|
|
94
|
+
processing = false;
|
|
95
|
+
// guard against overlapping poll + realtime
|
|
93
96
|
constructor(supabase) {
|
|
94
97
|
this.supabase = supabase;
|
|
95
98
|
this.deviceId = loadConfig().deviceId;
|
|
@@ -123,11 +126,16 @@ var Relay = class {
|
|
|
123
126
|
console.log(chalk.green("\u2713"), "Listening for commands");
|
|
124
127
|
}
|
|
125
128
|
});
|
|
129
|
+
this.pollTimer = setInterval(() => this.processPending(), 5e3);
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
132
|
* Stop listening.
|
|
129
133
|
*/
|
|
130
134
|
async stop() {
|
|
135
|
+
if (this.pollTimer) {
|
|
136
|
+
clearInterval(this.pollTimer);
|
|
137
|
+
this.pollTimer = null;
|
|
138
|
+
}
|
|
131
139
|
if (this.channel) {
|
|
132
140
|
await this.supabase.removeChannel(this.channel);
|
|
133
141
|
this.channel = null;
|
|
@@ -137,21 +145,28 @@ var Relay = class {
|
|
|
137
145
|
* Process any commands that arrived while the agent was offline.
|
|
138
146
|
*/
|
|
139
147
|
async processPending() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
+
if (this.processing) return;
|
|
149
|
+
this.processing = true;
|
|
150
|
+
try {
|
|
151
|
+
const { data: pending } = await this.supabase.from("commands").select("*").eq("device_id", this.deviceId).eq("status", "pending").order("created_at", { ascending: true });
|
|
152
|
+
if (pending && pending.length > 0) {
|
|
153
|
+
console.log(
|
|
154
|
+
chalk.yellow("\u26A1"),
|
|
155
|
+
`Processing ${pending.length} pending command(s)`
|
|
156
|
+
);
|
|
157
|
+
for (const cmd of pending) {
|
|
158
|
+
await this.dispatch(cmd);
|
|
159
|
+
}
|
|
148
160
|
}
|
|
161
|
+
} catch {
|
|
149
162
|
}
|
|
163
|
+
this.processing = false;
|
|
150
164
|
}
|
|
151
165
|
/**
|
|
152
166
|
* Dispatch a command to the appropriate handler.
|
|
153
167
|
*/
|
|
154
168
|
async dispatch(command) {
|
|
169
|
+
if (command.status !== "pending") return;
|
|
155
170
|
const handler = this.handlers.get(command.type);
|
|
156
171
|
if (!handler) {
|
|
157
172
|
console.log(
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Relay —
|
|
4
|
+
* Relay — Listens for incoming commands via Supabase.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Uses Realtime subscription (when available) AND polling fallback (every 5s)
|
|
7
|
+
* to ensure commands are always picked up, even when Realtime is unreliable.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
interface Command {
|
|
@@ -24,6 +24,8 @@ declare class Relay {
|
|
|
24
24
|
private channel;
|
|
25
25
|
private handlers;
|
|
26
26
|
private deviceId;
|
|
27
|
+
private pollTimer;
|
|
28
|
+
private processing;
|
|
27
29
|
constructor(supabase: SupabaseClient);
|
|
28
30
|
/**
|
|
29
31
|
* Register a handler for a command type (e.g., "git.clone", "claude.query").
|
package/dist/index.js
CHANGED