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.
- package/dist/chunk-67WA56OD.js +1243 -0
- package/dist/chunk-ONGRYEWS.js +178 -0
- package/dist/{chunk-GX5467VC.js → chunk-ZSRDP5HJ.js} +2143 -2274
- package/dist/cli.js +367 -470
- package/dist/index.js +2 -2
- package/dist/{threads-QAVO2Z4L.js → threads-PTTZUNIJ.js} +43 -12
- package/package.json +1 -1
- package/system.capabilities.md +2 -0
- package/dist/chunk-HTFQL66T.js +0 -488
- package/dist/chunk-PIAF4FJX.js +0 -76
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __flyspaceCreateRequire } from 'node:module';
|
|
3
|
+
const require = __flyspaceCreateRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
SessionStore,
|
|
6
|
+
canSeeChannel,
|
|
7
|
+
getSupabaseClient,
|
|
8
|
+
paths
|
|
9
|
+
} from "./chunk-67WA56OD.js";
|
|
10
|
+
|
|
11
|
+
// src/store/chat-admin-store.ts
|
|
12
|
+
async function listChannels(profile) {
|
|
13
|
+
let query = getSupabaseClient().from("channels").select("id, name, profile, cwd");
|
|
14
|
+
if (profile) query = query.eq("profile", profile);
|
|
15
|
+
const { data, error } = await query.order("name");
|
|
16
|
+
if (error) throw new Error(`listChannels: ${error.message}`);
|
|
17
|
+
return (data ?? []).map((row) => ({
|
|
18
|
+
id: row["id"],
|
|
19
|
+
name: row["name"],
|
|
20
|
+
profile: row["profile"],
|
|
21
|
+
cwd: row["cwd"]
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
async function resolveChannel(nameOrId, profile) {
|
|
25
|
+
const channels = await listChannels(profile);
|
|
26
|
+
const byId = channels.find((c) => c.id === nameOrId);
|
|
27
|
+
if (byId) return byId;
|
|
28
|
+
const wanted = nameOrId.replace(/^#/, "").toLowerCase();
|
|
29
|
+
const matches = channels.filter((c) => c.name.toLowerCase() === wanted);
|
|
30
|
+
if (matches.length === 1) return matches[0];
|
|
31
|
+
if (matches.length > 1) {
|
|
32
|
+
const detail = matches.map((c) => `${c.name} (${c.profile}) ${c.id}`).join("\n ");
|
|
33
|
+
throw new Error(`"${nameOrId}" matches ${matches.length} channels \u2014 pass an id:
|
|
34
|
+
${detail}`);
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`No channel matching "${nameOrId}". Run "flyspace chat channels".`);
|
|
37
|
+
}
|
|
38
|
+
async function listThreads(channelId, limit = 20) {
|
|
39
|
+
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);
|
|
40
|
+
if (error) throw new Error(`listThreads(${channelId}): ${error.message}`);
|
|
41
|
+
return (data ?? []).map(rowToThread);
|
|
42
|
+
}
|
|
43
|
+
async function getThread(threadId) {
|
|
44
|
+
const { data, error } = await getSupabaseClient().from("threads").select("id, channel_id, title, author, updated_at, thread_replies(count)").eq("id", threadId).maybeSingle();
|
|
45
|
+
if (error) throw new Error(`getThread(${threadId}): ${error.message}`);
|
|
46
|
+
return data ? rowToThread(data) : void 0;
|
|
47
|
+
}
|
|
48
|
+
async function firstReplyBody(threadId) {
|
|
49
|
+
const { data, error } = await getSupabaseClient().from("thread_replies").select("body").eq("thread_id", threadId).order("created_at").limit(1).maybeSingle();
|
|
50
|
+
if (error) throw new Error(`firstReplyBody(${threadId}): ${error.message}`);
|
|
51
|
+
return data?.body;
|
|
52
|
+
}
|
|
53
|
+
async function moveThread(threadId, toChannelId) {
|
|
54
|
+
const supabase = getSupabaseClient();
|
|
55
|
+
const { error } = await supabase.from("threads").update({ channel_id: toChannelId }).eq("id", threadId);
|
|
56
|
+
if (error) throw new Error(`moveThread(${threadId}): ${error.message}`);
|
|
57
|
+
const { error: notifyError } = await supabase.from("notifications").update({ channel_id: toChannelId }).eq("thread_id", threadId);
|
|
58
|
+
if (notifyError) throw new Error(`moveThread(${threadId}) notifications: ${notifyError.message}`);
|
|
59
|
+
}
|
|
60
|
+
function rowToThread(row) {
|
|
61
|
+
const counts = row["thread_replies"];
|
|
62
|
+
return {
|
|
63
|
+
id: row["id"],
|
|
64
|
+
channelId: row["channel_id"],
|
|
65
|
+
title: row["title"] ?? null,
|
|
66
|
+
author: row["author"],
|
|
67
|
+
replies: counts?.[0]?.count ?? 0,
|
|
68
|
+
updatedAt: row["updated_at"]
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/store/thread-move.ts
|
|
73
|
+
async function moveThreadFully(threadId, toChannelId) {
|
|
74
|
+
const thread = await getThread(threadId);
|
|
75
|
+
if (!thread) throw new Error(`No thread with id ${threadId}.`);
|
|
76
|
+
if (thread.channelId === toChannelId) return "unchanged";
|
|
77
|
+
const channels = await listChannels();
|
|
78
|
+
const to = channels.find((c) => c.id === toChannelId);
|
|
79
|
+
if (!to) throw new Error(`No channel with id ${toChannelId}.`);
|
|
80
|
+
const from = channels.find((c) => c.id === thread.channelId);
|
|
81
|
+
const store = new SessionStore(paths.DB_FILE);
|
|
82
|
+
try {
|
|
83
|
+
await moveThread(thread.id, to.id);
|
|
84
|
+
const counts = store.moveThread(`chat:${thread.channelId}`, `chat:${to.id}`, thread.id);
|
|
85
|
+
return { from, to, ...counts, cwdChanged: !!from && from.cwd !== to.cwd };
|
|
86
|
+
} finally {
|
|
87
|
+
store.close();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../api/src/dashboard/thread-access.ts
|
|
92
|
+
var ON_BEHALF_HEADER = "x-flyspace-on-behalf-of";
|
|
93
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
94
|
+
function parseThreadRef(input) {
|
|
95
|
+
const raw = input.trim();
|
|
96
|
+
if (UUID.test(raw)) return raw.toLowerCase();
|
|
97
|
+
let url;
|
|
98
|
+
try {
|
|
99
|
+
url = new URL(raw, "http://ref.invalid");
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
const fromPath = /(?:^|\/)chat\/[^/]+\/([^/]+)\/?$/.exec(url.pathname)?.[1];
|
|
104
|
+
if (fromPath && UUID.test(fromPath)) return fromPath.toLowerCase();
|
|
105
|
+
const fromQuery = url.searchParams.get("t");
|
|
106
|
+
return fromQuery && UUID.test(fromQuery) ? fromQuery.toLowerCase() : null;
|
|
107
|
+
}
|
|
108
|
+
function readingFor(query, userId) {
|
|
109
|
+
return userId ? query.setHeader(ON_BEHALF_HEADER, userId) : query;
|
|
110
|
+
}
|
|
111
|
+
async function resolveThreadOwner(threadId, onBehalfOf) {
|
|
112
|
+
if (!UUID.test(threadId)) return null;
|
|
113
|
+
const db = getSupabaseClient();
|
|
114
|
+
const { data: thread, error } = await readingFor(
|
|
115
|
+
db.from("threads").select("id, channel_id").eq("id", threadId),
|
|
116
|
+
onBehalfOf
|
|
117
|
+
).maybeSingle();
|
|
118
|
+
if (error) throw new Error(`resolveThreadOwner: ${error.message}`);
|
|
119
|
+
const channelId = thread?.channel_id;
|
|
120
|
+
if (!channelId) return null;
|
|
121
|
+
const { data: channel, error: channelError } = await readingFor(
|
|
122
|
+
db.from("channels").select("profile, visibility, dm_key, member_emails").eq(UUID.test(channelId) ? "id" : "external_channel_id", channelId),
|
|
123
|
+
onBehalfOf
|
|
124
|
+
).maybeSingle();
|
|
125
|
+
if (channelError) throw new Error(`resolveThreadOwner: ${channelError.message}`);
|
|
126
|
+
const row = channel;
|
|
127
|
+
if (!row?.profile) return null;
|
|
128
|
+
const { data: workspace, error: workspaceError } = await readingFor(
|
|
129
|
+
db.from("workspaces").select("id").eq("slug", row.profile),
|
|
130
|
+
onBehalfOf
|
|
131
|
+
).maybeSingle();
|
|
132
|
+
if (workspaceError) throw new Error(`resolveThreadOwner: ${workspaceError.message}`);
|
|
133
|
+
const workspaceId = workspace?.id;
|
|
134
|
+
if (!workspaceId) return null;
|
|
135
|
+
return {
|
|
136
|
+
threadId,
|
|
137
|
+
channelId,
|
|
138
|
+
workspace: row.profile,
|
|
139
|
+
workspaceId,
|
|
140
|
+
channel: {
|
|
141
|
+
// Same default as rowToChannel: anything not explicitly public is private.
|
|
142
|
+
visibility: row.visibility === "public" ? "public" : "private",
|
|
143
|
+
dmKey: row.dm_key,
|
|
144
|
+
memberEmails: Array.isArray(row.member_emails) ? row.member_emails.filter((e) => typeof e === "string").map((e) => e.trim().toLowerCase()) : []
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async function canReadThread(owner, userId) {
|
|
149
|
+
if (!UUID.test(userId)) return false;
|
|
150
|
+
const { data, error } = await readingFor(
|
|
151
|
+
getSupabaseClient().from("memberships").select("email, role").eq("workspace_id", owner.workspaceId).eq("user_id", userId),
|
|
152
|
+
userId
|
|
153
|
+
).maybeSingle();
|
|
154
|
+
if (error) throw new Error(`canReadThread: ${error.message}`);
|
|
155
|
+
const membership = data;
|
|
156
|
+
if (!membership) return false;
|
|
157
|
+
return canSeeChannel(owner.channel, {
|
|
158
|
+
email: membership.email ?? void 0,
|
|
159
|
+
role: membership.role
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function threadPath(workspace, channelId, threadId) {
|
|
163
|
+
return `/${encodeURIComponent(workspace)}/chat/${encodeURIComponent(channelId)}/${threadId}`;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
listChannels,
|
|
168
|
+
resolveChannel,
|
|
169
|
+
listThreads,
|
|
170
|
+
getThread,
|
|
171
|
+
firstReplyBody,
|
|
172
|
+
moveThreadFully,
|
|
173
|
+
ON_BEHALF_HEADER,
|
|
174
|
+
parseThreadRef,
|
|
175
|
+
resolveThreadOwner,
|
|
176
|
+
canReadThread,
|
|
177
|
+
threadPath
|
|
178
|
+
};
|