flyspace-cli 0.1.53 → 0.1.54

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.
@@ -1,76 +0,0 @@
1
- #!/usr/bin/env node
2
- import { createRequire as __flyspaceCreateRequire } from 'node:module';
3
- const require = __flyspaceCreateRequire(import.meta.url);
4
- import {
5
- getSupabaseClient
6
- } from "./chunk-HTFQL66T.js";
7
-
8
- // src/store/chat-admin-store.ts
9
- async function listChannels(profile) {
10
- let query = getSupabaseClient().from("channels").select("id, name, profile, cwd");
11
- if (profile) query = query.eq("profile", profile);
12
- const { data, error } = await query.order("name");
13
- if (error) throw new Error(`listChannels: ${error.message}`);
14
- return (data ?? []).map((row) => ({
15
- id: row["id"],
16
- name: row["name"],
17
- profile: row["profile"],
18
- cwd: row["cwd"]
19
- }));
20
- }
21
- async function resolveChannel(nameOrId, profile) {
22
- const channels = await listChannels(profile);
23
- const byId = channels.find((c) => c.id === nameOrId);
24
- if (byId) return byId;
25
- const wanted = nameOrId.replace(/^#/, "").toLowerCase();
26
- const matches = channels.filter((c) => c.name.toLowerCase() === wanted);
27
- if (matches.length === 1) return matches[0];
28
- if (matches.length > 1) {
29
- const detail = matches.map((c) => `${c.name} (${c.profile}) ${c.id}`).join("\n ");
30
- throw new Error(`"${nameOrId}" matches ${matches.length} channels \u2014 pass an id:
31
- ${detail}`);
32
- }
33
- throw new Error(`No channel matching "${nameOrId}". Run "flyspace chat channels".`);
34
- }
35
- async function listThreads(channelId, limit = 20) {
36
- const { data, error } = await getSupabaseClient().from("threads").select("id, channel_id, title, author, updated_at, thread_replies(count)").eq("channel_id", channelId).order("updated_at", { ascending: false }).limit(limit);
37
- if (error) throw new Error(`listThreads(${channelId}): ${error.message}`);
38
- return (data ?? []).map(rowToThread);
39
- }
40
- async function getThread(threadId) {
41
- const { data, error } = await getSupabaseClient().from("threads").select("id, channel_id, title, author, updated_at, thread_replies(count)").eq("id", threadId).maybeSingle();
42
- if (error) throw new Error(`getThread(${threadId}): ${error.message}`);
43
- return data ? rowToThread(data) : void 0;
44
- }
45
- async function firstReplyBody(threadId) {
46
- const { data, error } = await getSupabaseClient().from("thread_replies").select("body").eq("thread_id", threadId).order("created_at").limit(1).maybeSingle();
47
- if (error) throw new Error(`firstReplyBody(${threadId}): ${error.message}`);
48
- return data?.body;
49
- }
50
- async function moveThread(threadId, toChannelId) {
51
- const supabase = getSupabaseClient();
52
- const { error } = await supabase.from("threads").update({ channel_id: toChannelId }).eq("id", threadId);
53
- if (error) throw new Error(`moveThread(${threadId}): ${error.message}`);
54
- const { error: notifyError } = await supabase.from("notifications").update({ channel_id: toChannelId }).eq("thread_id", threadId);
55
- if (notifyError) throw new Error(`moveThread(${threadId}) notifications: ${notifyError.message}`);
56
- }
57
- function rowToThread(row) {
58
- const counts = row["thread_replies"];
59
- return {
60
- id: row["id"],
61
- channelId: row["channel_id"],
62
- title: row["title"] ?? null,
63
- author: row["author"],
64
- replies: counts?.[0]?.count ?? 0,
65
- updatedAt: row["updated_at"]
66
- };
67
- }
68
-
69
- export {
70
- listChannels,
71
- resolveChannel,
72
- listThreads,
73
- getThread,
74
- firstReplyBody,
75
- moveThread
76
- };