@tenux/cli 0.0.10 → 0.0.11
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-V2C4ESKK.js → chunk-KPADLCUM.js} +22 -2
- package/dist/cli.js +13 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -43,6 +43,7 @@ function updateConfig(partial) {
|
|
|
43
43
|
// src/lib/supabase.ts
|
|
44
44
|
import { createClient } from "@supabase/supabase-js";
|
|
45
45
|
var client = null;
|
|
46
|
+
var initialized = false;
|
|
46
47
|
function getSupabase() {
|
|
47
48
|
if (client) return client;
|
|
48
49
|
const config = loadConfig();
|
|
@@ -52,16 +53,34 @@ function getSupabase() {
|
|
|
52
53
|
autoRefreshToken: true
|
|
53
54
|
}
|
|
54
55
|
});
|
|
56
|
+
client.auth.onAuthStateChange((_event, session) => {
|
|
57
|
+
if (session?.access_token && session?.refresh_token) {
|
|
58
|
+
updateConfig({
|
|
59
|
+
accessToken: session.access_token,
|
|
60
|
+
refreshToken: session.refresh_token
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return client;
|
|
65
|
+
}
|
|
66
|
+
async function initSupabaseSession() {
|
|
67
|
+
if (initialized) return;
|
|
68
|
+
const config = loadConfig();
|
|
69
|
+
const sb = getSupabase();
|
|
55
70
|
if (config.accessToken && config.refreshToken) {
|
|
56
|
-
|
|
71
|
+
const { error } = await sb.auth.setSession({
|
|
57
72
|
access_token: config.accessToken,
|
|
58
73
|
refresh_token: config.refreshToken
|
|
59
74
|
});
|
|
75
|
+
if (error) {
|
|
76
|
+
throw new Error(`Failed to restore session: ${error.message}`);
|
|
77
|
+
}
|
|
60
78
|
}
|
|
61
|
-
|
|
79
|
+
initialized = true;
|
|
62
80
|
}
|
|
63
81
|
function resetSupabase() {
|
|
64
82
|
client = null;
|
|
83
|
+
initialized = false;
|
|
65
84
|
}
|
|
66
85
|
|
|
67
86
|
// src/lib/relay.ts
|
|
@@ -321,6 +340,7 @@ export {
|
|
|
321
340
|
saveConfig,
|
|
322
341
|
updateConfig,
|
|
323
342
|
getSupabase,
|
|
343
|
+
initSupabaseSession,
|
|
324
344
|
resetSupabase,
|
|
325
345
|
Relay,
|
|
326
346
|
handleClaudeQuery
|
package/dist/cli.js
CHANGED
|
@@ -5,10 +5,11 @@ import {
|
|
|
5
5
|
getConfigPath,
|
|
6
6
|
getSupabase,
|
|
7
7
|
handleClaudeQuery,
|
|
8
|
+
initSupabaseSession,
|
|
8
9
|
loadConfig,
|
|
9
10
|
saveConfig,
|
|
10
11
|
updateConfig
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-KPADLCUM.js";
|
|
12
13
|
|
|
13
14
|
// src/cli.ts
|
|
14
15
|
import { Command } from "commander";
|
|
@@ -230,13 +231,23 @@ program.command("start").description("Start the agent and listen for commands").
|
|
|
230
231
|
console.log(chalk.dim(" Projects:"), config.projectsDir);
|
|
231
232
|
console.log();
|
|
232
233
|
const supabase = getSupabase();
|
|
234
|
+
try {
|
|
235
|
+
await initSupabaseSession();
|
|
236
|
+
} catch (err) {
|
|
237
|
+
console.log(chalk.red("\u2717"), `Session expired: ${err.message}`);
|
|
238
|
+
console.log(chalk.dim(" Run `tenux login` to re-authenticate."));
|
|
239
|
+
process.exit(1);
|
|
240
|
+
}
|
|
233
241
|
await supabase.from("devices").update({
|
|
234
242
|
name: config.deviceName,
|
|
235
243
|
is_online: true,
|
|
236
244
|
last_seen_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
237
245
|
}).eq("id", config.deviceId);
|
|
238
246
|
const heartbeat = setInterval(async () => {
|
|
239
|
-
await supabase.from("devices").update({ last_seen_at: (/* @__PURE__ */ new Date()).toISOString(), is_online: true }).eq("id", config.deviceId);
|
|
247
|
+
const { error } = await supabase.from("devices").update({ last_seen_at: (/* @__PURE__ */ new Date()).toISOString(), is_online: true }).eq("id", config.deviceId);
|
|
248
|
+
if (error) {
|
|
249
|
+
console.log(chalk.red("\u2717"), chalk.dim(`Heartbeat failed: ${error.message}`));
|
|
250
|
+
}
|
|
240
251
|
}, 3e4);
|
|
241
252
|
const relay = new Relay(supabase);
|
|
242
253
|
const shutdown = async () => {
|
package/dist/index.js
CHANGED