@tenux/cli 0.0.15 → 0.0.17
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-QPS4CXAL.js} +25 -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
|
@@ -59,6 +59,7 @@ function getSupabase() {
|
|
|
59
59
|
accessToken: session.access_token,
|
|
60
60
|
refreshToken: session.refresh_token
|
|
61
61
|
});
|
|
62
|
+
client.realtime.setAuth(session.access_token);
|
|
62
63
|
}
|
|
63
64
|
});
|
|
64
65
|
return client;
|
|
@@ -75,6 +76,7 @@ async function initSupabaseSession() {
|
|
|
75
76
|
if (error) {
|
|
76
77
|
throw new Error(`Failed to restore session: ${error.message}`);
|
|
77
78
|
}
|
|
79
|
+
sb.realtime.setAuth(config.accessToken);
|
|
78
80
|
}
|
|
79
81
|
initialized = true;
|
|
80
82
|
}
|
|
@@ -90,6 +92,9 @@ var Relay = class {
|
|
|
90
92
|
channel = null;
|
|
91
93
|
handlers = /* @__PURE__ */ new Map();
|
|
92
94
|
deviceId;
|
|
95
|
+
pollTimer = null;
|
|
96
|
+
processing = false;
|
|
97
|
+
// guard against overlapping poll + realtime
|
|
93
98
|
constructor(supabase) {
|
|
94
99
|
this.supabase = supabase;
|
|
95
100
|
this.deviceId = loadConfig().deviceId;
|
|
@@ -123,11 +128,16 @@ var Relay = class {
|
|
|
123
128
|
console.log(chalk.green("\u2713"), "Listening for commands");
|
|
124
129
|
}
|
|
125
130
|
});
|
|
131
|
+
this.pollTimer = setInterval(() => this.processPending(), 5e3);
|
|
126
132
|
}
|
|
127
133
|
/**
|
|
128
134
|
* Stop listening.
|
|
129
135
|
*/
|
|
130
136
|
async stop() {
|
|
137
|
+
if (this.pollTimer) {
|
|
138
|
+
clearInterval(this.pollTimer);
|
|
139
|
+
this.pollTimer = null;
|
|
140
|
+
}
|
|
131
141
|
if (this.channel) {
|
|
132
142
|
await this.supabase.removeChannel(this.channel);
|
|
133
143
|
this.channel = null;
|
|
@@ -137,21 +147,28 @@ var Relay = class {
|
|
|
137
147
|
* Process any commands that arrived while the agent was offline.
|
|
138
148
|
*/
|
|
139
149
|
async processPending() {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
150
|
+
if (this.processing) return;
|
|
151
|
+
this.processing = true;
|
|
152
|
+
try {
|
|
153
|
+
const { data: pending } = await this.supabase.from("commands").select("*").eq("device_id", this.deviceId).eq("status", "pending").order("created_at", { ascending: true });
|
|
154
|
+
if (pending && pending.length > 0) {
|
|
155
|
+
console.log(
|
|
156
|
+
chalk.yellow("\u26A1"),
|
|
157
|
+
`Processing ${pending.length} pending command(s)`
|
|
158
|
+
);
|
|
159
|
+
for (const cmd of pending) {
|
|
160
|
+
await this.dispatch(cmd);
|
|
161
|
+
}
|
|
148
162
|
}
|
|
163
|
+
} catch {
|
|
149
164
|
}
|
|
165
|
+
this.processing = false;
|
|
150
166
|
}
|
|
151
167
|
/**
|
|
152
168
|
* Dispatch a command to the appropriate handler.
|
|
153
169
|
*/
|
|
154
170
|
async dispatch(command) {
|
|
171
|
+
if (command.status !== "pending") return;
|
|
155
172
|
const handler = this.handlers.get(command.type);
|
|
156
173
|
if (!handler) {
|
|
157
174
|
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