flyspace-cli 0.1.65 → 0.1.66

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/cli.js CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  SHARE_ASSET_PLACEHOLDER,
26
26
  SKIP_SUBTYPES,
27
27
  SUPPORT_AVATAR_URL,
28
+ SUPPORT_GRANT_HOURS,
28
29
  TRANSLATION_LANGUAGES,
29
30
  TRIAL_DAYS,
30
31
  UsageStore,
@@ -59,6 +60,7 @@ import {
59
60
  createRequestSupabaseClient,
60
61
  createSkillFile,
61
62
  createStateToken,
63
+ createSupportGrant,
62
64
  createTtsRouter,
63
65
  createWorkspace,
64
66
  crossOriginShell,
@@ -77,6 +79,7 @@ import {
77
79
  deriveConnectionSlug,
78
80
  deriveThreadTitle,
79
81
  detectSourceLanguage,
82
+ displayCwd,
80
83
  displayNameFor,
81
84
  dropShareAudio,
82
85
  dropShareLangAudioKeys,
@@ -97,6 +100,7 @@ import {
97
100
  findOwningProfile,
98
101
  findSkillDetail,
99
102
  flatDocs,
103
+ getActiveSupportGrant,
100
104
  getAgentPaused,
101
105
  getAllowGuestAccess,
102
106
  getChannelDocsMemberAccess,
@@ -121,6 +125,7 @@ import {
121
125
  getWorkspaceOwnPersona,
122
126
  getWorkspacePermissionMode,
123
127
  getWorkspacePlanStatus,
128
+ grantSupportMembership,
124
129
  handleSupportMention,
125
130
  insertMcpConnection,
126
131
  insertWorkspaceDomain,
@@ -164,6 +169,8 @@ import {
164
169
  listSkillFiles,
165
170
  listSkills,
166
171
  listSlashItems,
172
+ listSupportLog,
173
+ listSupportWorkspaceIds,
167
174
  listThreadMemoryEvents,
168
175
  listWorkspaceSummaries,
169
176
  listWorkspaces,
@@ -176,6 +183,7 @@ import {
176
183
  loadWorkspaceBranding,
177
184
  loadWorkspacePrompt,
178
185
  localDefaults,
186
+ logSupportAction,
179
187
  markChannelGreeted,
180
188
  markInviteResent,
181
189
  markMemoryUsed,
@@ -216,6 +224,8 @@ import {
216
224
  resolveRateCard,
217
225
  resolveUserId,
218
226
  revokeDocShare,
227
+ revokeSupportGrants,
228
+ revokeSupportMembership,
219
229
  rowToMemory,
220
230
  runAutomation,
221
231
  runPersonaCmd,
@@ -243,6 +253,7 @@ import {
243
253
  setMemoryAutoPaused,
244
254
  setOutputStyleDefault,
245
255
  setProfileConfigCache,
256
+ setWorkspaceAgentDefaults,
246
257
  setWorkspaceArchived,
247
258
  setWorkspaceAutoContinueLimit,
248
259
  setWorkspaceOwnPersona,
@@ -284,7 +295,7 @@ import {
284
295
  workspaceHostname,
285
296
  workspaceSkillsDir,
286
297
  writeSkillFile
287
- } from "./chunk-5ISKGSFF.js";
298
+ } from "./chunk-DVHYIWIW.js";
288
299
  import {
289
300
  checkPermissionAction,
290
301
  createThreadAction,
@@ -305,7 +316,7 @@ import {
305
316
  searchThreadsAction,
306
317
  setUiZoomAction,
307
318
  shareDocAction
308
- } from "./chunk-GQ2QZ5WF.js";
319
+ } from "./chunk-ODQS4YBM.js";
309
320
  import {
310
321
  AuthApiError,
311
322
  DEFAULT_API_URL,
@@ -357,7 +368,7 @@ import {
357
368
  slackConfigured,
358
369
  sumR2PrefixBytes,
359
370
  useHostDbWithoutCredentials
360
- } from "./chunk-O7OYNQND.js";
371
+ } from "./chunk-KPZOOR73.js";
361
372
 
362
373
  // ../core/src/logger.ts
363
374
  var ALREADY_STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
@@ -1252,9 +1263,15 @@ function assertLinkable(target) {
1252
1263
  const root = existsSync5(flyspaceRoot()) ? realpathSync2(flyspaceRoot()) : flyspaceRoot();
1253
1264
  const denied = [join5(home2, ".ssh"), join5(home2, "Library"), join5(home2, ".config"), join5(home2, ".gnupg")];
1254
1265
  if (target === home2 || target === "/" || target === root || target.startsWith(`${root}/`)) {
1255
- throw new Error(`cannot link ${target}`);
1266
+ throw new Error(`cannot link ${target}: this folder can't be a channel folder, pick a project folder instead`);
1267
+ }
1268
+ const hit = denied.find((d) => target === d || target.startsWith(`${d}/`));
1269
+ if (hit) {
1270
+ const shown = hit.replace(home2, "~");
1271
+ throw new Error(
1272
+ `cannot link ${target}: ${shown} is blocked for security reasons, copy or move the folder outside ${shown}`
1273
+ );
1256
1274
  }
1257
- if (denied.some((d) => target === d || target.startsWith(`${d}/`))) throw new Error(`cannot link ${target}`);
1258
1275
  }
1259
1276
  function linkProjectFolders(slug, items2) {
1260
1277
  if (!SLUG_RE.test(slug)) throw new Error(`invalid workspace slug: ${slug}`);
@@ -2214,7 +2231,7 @@ function npmEnv(target) {
2214
2231
  return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
2215
2232
  }
2216
2233
  async function runUpgrade() {
2217
- const current = "0.1.65";
2234
+ const current = "0.1.66";
2218
2235
  console.log(`Current version: ${current}`);
2219
2236
  console.log("Checking for updates...\n");
2220
2237
  try {
@@ -6166,7 +6183,7 @@ async function runMcpCmd(args) {
6166
6183
  useHostDbWithoutCredentials();
6167
6184
  switch (server) {
6168
6185
  case "threads": {
6169
- const { startThreadsServer } = await import("./threads-AR6D7V3Y.js");
6186
+ const { startThreadsServer } = await import("./threads-62Y2BIFT.js");
6170
6187
  await startThreadsServer();
6171
6188
  return;
6172
6189
  }
@@ -6247,7 +6264,7 @@ async function ensureServices() {
6247
6264
  }
6248
6265
 
6249
6266
  // ../api/src/dashboard/api.ts
6250
- import { Hono as Hono35 } from "hono";
6267
+ import { Hono as Hono38 } from "hono";
6251
6268
 
6252
6269
  // ../api/src/dashboard/guest-routes.ts
6253
6270
  import { Hono as Hono4 } from "hono";
@@ -6675,7 +6692,9 @@ function createUploadsRouter() {
6675
6692
  );
6676
6693
  });
6677
6694
  app.get("/attachments/:key{.+}", async (c) => {
6678
- const url = await presignAttachmentRead(c.req.param("key"));
6695
+ const key = c.req.param("key");
6696
+ if (key.split("/")[1] !== getProfile()) return c.json({ error: "not found" }, 404);
6697
+ const url = await presignAttachmentRead(key);
6679
6698
  if (!url) return c.json({ error: "not found" }, 404);
6680
6699
  c.header("Cache-Control", `private, max-age=${PRESIGN_TTL_SECONDS - 60}`);
6681
6700
  return c.redirect(url, 302);
@@ -7724,70 +7743,19 @@ function createAuthRouter() {
7724
7743
  return auth;
7725
7744
  }
7726
7745
 
7727
- // ../api/src/store/support-store.ts
7728
- var SUPPORT_HANDLE = "flyspace-support";
7729
- async function logSupportAction(entry) {
7730
- const { error: error2 } = await getSupabaseClient().from("support_access_log").insert({
7731
- workspace_id: entry.workspaceId,
7732
- staff_user_id: entry.staffUserId,
7733
- staff_email: entry.staffEmail,
7734
- action: entry.action,
7735
- detail: entry.detail ?? null
7736
- });
7737
- if (error2) throw new Error(`logSupportAction(${entry.action}): ${error2.message}`);
7738
- }
7739
- async function listSupportWorkspaceIds(userId) {
7740
- const { data, error: error2 } = await getSupabaseClient().from("memberships").select("workspace_id").eq("user_id", userId).eq("is_support", true);
7741
- if (error2) throw new Error(`listSupportWorkspaceIds: ${error2.message}`);
7742
- return new Set((data ?? []).map((r) => r.workspace_id));
7743
- }
7744
- async function grantSupportMembership(params) {
7745
- const db = getSupabaseClient();
7746
- const { data: existing, error: readError } = await db.from("memberships").select("is_support").eq("workspace_id", params.workspaceId).eq("user_id", params.userId).maybeSingle();
7747
- if (readError) throw new Error(`grantSupportMembership: ${readError.message}`);
7748
- if (existing) {
7749
- if (existing.is_support === true) return "existing";
7750
- throw new Error("already a regular member of this workspace");
7751
- }
7752
- const { data: taken } = await db.from("memberships").select("id").eq("workspace_id", params.workspaceId).eq("handle", SUPPORT_HANDLE).maybeSingle();
7753
- const handle = taken ? `${SUPPORT_HANDLE}-${params.userId.slice(0, 8)}` : SUPPORT_HANDLE;
7754
- const { error: error2 } = await db.from("memberships").insert({
7755
- workspace_id: params.workspaceId,
7756
- user_id: params.userId,
7757
- email: params.email,
7758
- handle,
7759
- role: "admin",
7760
- status: "active",
7761
- is_support: true,
7762
- accepted_at: (/* @__PURE__ */ new Date()).toISOString()
7763
- });
7764
- if (error2) throw new Error(`grantSupportMembership: ${error2.message}`);
7765
- return "granted";
7766
- }
7767
- async function revokeSupportMembership(workspaceId, userId) {
7768
- const { data, error: error2 } = await getSupabaseClient().from("memberships").delete().eq("workspace_id", workspaceId).eq("user_id", userId).eq("is_support", true).select("id");
7769
- if (error2) throw new Error(`revokeSupportMembership: ${error2.message}`);
7770
- return (data ?? []).length > 0;
7771
- }
7772
- async function listSupportLog(filter) {
7773
- let query = getSupabaseClient().from("support_access_log").select("*").order("created_at", { ascending: false }).limit(Math.min(filter.limit ?? 200, 1e3));
7774
- if (filter.workspaceId) query = query.eq("workspace_id", filter.workspaceId);
7775
- const { data, error: error2 } = await query;
7776
- if (error2) throw new Error(`listSupportLog: ${error2.message}`);
7777
- return (data ?? []).map((r) => ({
7778
- id: r.id,
7779
- workspaceId: r.workspace_id,
7780
- staffUserId: r.staff_user_id,
7781
- staffEmail: r.staff_email,
7782
- action: r.action,
7783
- detail: r.detail ?? null,
7784
- createdAt: r.created_at
7785
- }));
7786
- }
7787
-
7788
7746
  // ../api/src/dashboard/auth-middleware.ts
7789
7747
  var ENTER_WINDOW_MS = 8 * 60 * 60 * 1e3;
7790
7748
  var lastEnter = /* @__PURE__ */ new Map();
7749
+ var READ_DEDUPE_MS = 60 * 1e3;
7750
+ var lastRead = /* @__PURE__ */ new Map();
7751
+ function shouldLogRead(key, now) {
7752
+ if ((lastRead.get(key) ?? 0) + READ_DEDUPE_MS > now) return false;
7753
+ lastRead.set(key, now);
7754
+ if (lastRead.size > 5e3) {
7755
+ for (const [k, t] of lastRead) if (t + READ_DEDUPE_MS < now) lastRead.delete(k);
7756
+ }
7757
+ return true;
7758
+ }
7791
7759
  function auditSupport(ctx, action, detail) {
7792
7760
  logSupportAction({
7793
7761
  workspaceId: ctx.workspaceId,
@@ -7809,7 +7777,11 @@ var requireWorkspaceMembership = async (c, next) => {
7809
7777
  auditSupport(ctx, "enter");
7810
7778
  }
7811
7779
  await next();
7812
- if (!["GET", "HEAD", "OPTIONS"].includes(c.req.method)) {
7780
+ if (c.req.method === "GET") {
7781
+ if (shouldLogRead(`${key}:${c.req.path}`, Date.now())) {
7782
+ auditSupport(ctx, "read", { path: c.req.path, status: c.res.status });
7783
+ }
7784
+ } else if (!["HEAD", "OPTIONS"].includes(c.req.method)) {
7813
7785
  auditSupport(ctx, "write", { method: c.req.method, path: c.req.path, status: c.res.status });
7814
7786
  }
7815
7787
  };
@@ -8031,6 +8003,9 @@ function createAdminRouter() {
8031
8003
  const operator = c.get("platformOperator");
8032
8004
  const workspaceId = c.req.param("id");
8033
8005
  let result;
8006
+ if (!await getActiveSupportGrant(workspaceId)) {
8007
+ return c.json({ error: "workspace has not granted support access" }, 403);
8008
+ }
8034
8009
  try {
8035
8010
  result = await grantSupportMembership({
8036
8011
  workspaceId,
@@ -8091,8 +8066,132 @@ function createAdminRouter() {
8091
8066
  import { existsSync as existsSync17 } from "fs";
8092
8067
  import sharp4 from "sharp";
8093
8068
 
8094
- // ../api/src/dashboard/automations-routes.ts
8069
+ // ../api/src/dashboard/channel-agent-routes.ts
8070
+ import { Hono as Hono11 } from "hono";
8071
+
8072
+ // ../api/src/dashboard/channel-members-routes.ts
8095
8073
  import { Hono as Hono10 } from "hono";
8074
+ async function isChannelAdmin(ctx, channelId) {
8075
+ if (ctx.role === "admin") return true;
8076
+ const membership = await getMembershipByUserId(ctx.workspaceId, ctx.userId);
8077
+ if (!membership) return false;
8078
+ const members = await listChannelMembers(channelId);
8079
+ return members.some((m) => m.membershipId === membership.id && m.role === "channel_admin");
8080
+ }
8081
+ function createChannelMembersRouter() {
8082
+ const router = new Hono10();
8083
+ router.get("/:id/members", async (c) => {
8084
+ const ctx = await resolveAuthContext(c);
8085
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8086
+ const members = await listChannelMembers(c.req.param("id"));
8087
+ return c.json({ members });
8088
+ });
8089
+ router.put("/:id/members/:membershipId", async (c) => {
8090
+ const ctx = await resolveAuthContext(c);
8091
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8092
+ const channelId = c.req.param("id");
8093
+ if (!await isChannelAdmin(ctx, channelId)) {
8094
+ return c.json({ error: "channel admin access required" }, 403);
8095
+ }
8096
+ const body = await c.req.json().catch(() => ({}));
8097
+ if (body.role !== "channel_admin" && body.role !== "channel_member") {
8098
+ return c.json({ error: "role must be 'channel_admin' or 'channel_member'" }, 400);
8099
+ }
8100
+ const member = await upsertChannelMember({
8101
+ channelId,
8102
+ membershipId: c.req.param("membershipId"),
8103
+ role: body.role
8104
+ });
8105
+ return c.json({ member });
8106
+ });
8107
+ router.delete("/:id/members/:membershipId", async (c) => {
8108
+ const ctx = await resolveAuthContext(c);
8109
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8110
+ const channelId = c.req.param("id");
8111
+ if (!await isChannelAdmin(ctx, channelId)) {
8112
+ return c.json({ error: "channel admin access required" }, 403);
8113
+ }
8114
+ const removed = await removeChannelMember(channelId, c.req.param("membershipId"));
8115
+ if (!removed) return c.json({ error: "no such channel member" }, 404);
8116
+ return c.body(null, 204);
8117
+ });
8118
+ router.get("/:id/docs-access/me", async (c) => {
8119
+ const ctx = await resolveAuthContext(c);
8120
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8121
+ return c.json({ access: await resolveDocsAccess(ctx, c.req.param("id")) });
8122
+ });
8123
+ router.get("/:id/docs-access", async (c) => {
8124
+ const ctx = await resolveAuthContext(c);
8125
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8126
+ const channelId = c.req.param("id");
8127
+ if (!await isChannelAdmin(ctx, channelId)) {
8128
+ return c.json({ error: "channel admin access required" }, 403);
8129
+ }
8130
+ return c.json({ memberAccess: await getChannelDocsMemberAccess(channelId) });
8131
+ });
8132
+ router.put("/:id/docs-access", async (c) => {
8133
+ const ctx = await resolveAuthContext(c);
8134
+ if (!ctx) return c.json({ error: "workspace access required" }, 403);
8135
+ const channelId = c.req.param("id");
8136
+ if (!await isChannelAdmin(ctx, channelId)) {
8137
+ return c.json({ error: "channel admin access required" }, 403);
8138
+ }
8139
+ const body = await c.req.json().catch(() => ({}));
8140
+ if (!isDocsAccess(body.memberAccess)) {
8141
+ return c.json({ error: "memberAccess must be 'none', 'read' or 'write'" }, 400);
8142
+ }
8143
+ if (!await setChannelDocsMemberAccess(channelId, body.memberAccess)) {
8144
+ return c.json({ error: "no such channel" }, 404);
8145
+ }
8146
+ return c.json({ memberAccess: body.memberAccess });
8147
+ });
8148
+ return router;
8149
+ }
8150
+
8151
+ // ../api/src/dashboard/channel-agent-routes.ts
8152
+ function coerce(body, key, valid) {
8153
+ if (!(key in body)) return void 0;
8154
+ const raw = body[key];
8155
+ if (raw === null || raw === "") return null;
8156
+ if (typeof raw !== "string") return "invalid";
8157
+ const value = raw.trim();
8158
+ return valid(value) ? value : "invalid";
8159
+ }
8160
+ function createChannelAgentRouter() {
8161
+ const router = new Hono11();
8162
+ router.patch("/:id", async (c, next) => {
8163
+ const body = await c.req.raw.clone().json().catch(() => null);
8164
+ if (!body || typeof body !== "object" || !("model" in body || "effort" in body)) return next();
8165
+ const auth = await resolveAuthContext(c);
8166
+ if (!auth) return c.json({ error: "workspace access required" }, 403);
8167
+ const id = c.req.param("id");
8168
+ const channel = findChannelById(id);
8169
+ if (!channel || channel.profile !== getProfile()) return c.json({ error: "not found" }, 404);
8170
+ if (!await isChannelAdmin(auth, id)) {
8171
+ return c.json({ error: "channel admin access required" }, 403);
8172
+ }
8173
+ const model = coerce(body, "model", isAllowedModel);
8174
+ const effort = coerce(body, "effort", isEffort);
8175
+ if (model === "invalid") return c.json({ error: "unknown model" }, 400);
8176
+ if (effort === "invalid") {
8177
+ return c.json({ error: "effort must be low, medium, high, xhigh or max" }, 400);
8178
+ }
8179
+ if (Object.keys(body).some((k) => k !== "model" && k !== "effort")) return next();
8180
+ try {
8181
+ const updated = await updateChannelById(id, {
8182
+ ...model !== void 0 ? { model } : {},
8183
+ ...effort !== void 0 ? { effort } : {}
8184
+ });
8185
+ return c.json({ id: updated.id, model: updated.model ?? null, effort: updated.effort ?? null });
8186
+ } catch (err) {
8187
+ return c.json({ error: err.message }, 500);
8188
+ }
8189
+ });
8190
+ return router;
8191
+ }
8192
+
8193
+ // ../api/src/dashboard/automations-routes.ts
8194
+ import { Hono as Hono12 } from "hono";
8096
8195
  var TYPES2 = ["schedule", "trigger", "mention-trigger"];
8097
8196
  function isType(t) {
8098
8197
  return TYPES2.includes(t);
@@ -8109,7 +8208,7 @@ function statusFor(message) {
8109
8208
  return 400;
8110
8209
  }
8111
8210
  function createAutomationWriteRouter() {
8112
- const app = new Hono10();
8211
+ const app = new Hono12();
8113
8212
  const manager = () => new AutomationManager();
8114
8213
  app.get("/:type/:name", (c) => {
8115
8214
  const item = manager().get(c.req.param("name"));
@@ -8165,9 +8264,9 @@ function createAutomationWriteRouter() {
8165
8264
  }
8166
8265
 
8167
8266
  // ../api/src/dashboard/categories-routes.ts
8168
- import { Hono as Hono11 } from "hono";
8267
+ import { Hono as Hono13 } from "hono";
8169
8268
  function createCategoryWriteRouter() {
8170
- const app = new Hono11();
8269
+ const app = new Hono13();
8171
8270
  app.get("/", async (c) => {
8172
8271
  const { data, error: error2 } = await getSupabaseClient().from("categories").select("*").eq("profile", getProfile()).order("position", { ascending: true });
8173
8272
  if (error2) return c.json({ error: error2.message }, 500);
@@ -8221,7 +8320,7 @@ function createCategoryWriteRouter() {
8221
8320
  }
8222
8321
 
8223
8322
  // ../api/src/dashboard/chat-routes.ts
8224
- import { Hono as Hono13 } from "hono";
8323
+ import { Hono as Hono15 } from "hono";
8225
8324
 
8226
8325
  // ../api/src/dashboard/fork-summary.ts
8227
8326
  var MAX_INPUT_CHARS = 6e4;
@@ -8266,7 +8365,7 @@ async function relevantThreadsPage(supabase, handle, channelIds, opts) {
8266
8365
  }
8267
8366
 
8268
8367
  // ../api/src/dashboard/continuous-chat.ts
8269
- import { Hono as Hono12 } from "hono";
8368
+ import { Hono as Hono14 } from "hono";
8270
8369
  var GROQ_API_URL2 = "https://api.groq.com/openai/v1/chat/completions";
8271
8370
  var MODEL = "openai/gpt-oss-120b";
8272
8371
  var STREAM_DAYS = 30;
@@ -8374,7 +8473,7 @@ function tagStoredReply(c, args) {
8374
8473
  }
8375
8474
  var backfilling = /* @__PURE__ */ new Set();
8376
8475
  function createContinuousChatRouter() {
8377
- const app = new Hono12();
8476
+ const app = new Hono14();
8378
8477
  app.get("/channels/:channelId/continuous", async (c) => {
8379
8478
  if (!await isFeatureEnabled(c, "continuous-chat"))
8380
8479
  return c.json({ error: "feature not enabled" }, 403);
@@ -9056,7 +9155,7 @@ async function generateAutoTitle(threadId, channelId, body) {
9056
9155
  await supabase.from("threads").update({ auto_title: autoTitle }).eq("id", threadId).is("title", null);
9057
9156
  }
9058
9157
  function createChatRouter(agent = {}) {
9059
- const app = new Hono13();
9158
+ const app = new Hono15();
9060
9159
  const {
9061
9160
  onChatMessage: onMessage,
9062
9161
  isAgentThinking,
@@ -9787,7 +9886,7 @@ function createChatRouter(agent = {}) {
9787
9886
  }
9788
9887
 
9789
9888
  // ../api/src/dashboard/doc-shares-routes.ts
9790
- import { Hono as Hono14 } from "hono";
9889
+ import { Hono as Hono16 } from "hono";
9791
9890
 
9792
9891
  // ../api/src/dashboard/share-tags.ts
9793
9892
  var MAX_TAGS = 10;
@@ -9876,7 +9975,7 @@ function resolveChannel2(c) {
9876
9975
  }
9877
9976
  var LIST_LIMIT = 500;
9878
9977
  function createDocShareListRouter() {
9879
- const app = new Hono14();
9978
+ const app = new Hono16();
9880
9979
  app.get("/shares", async (c) => {
9881
9980
  const viewer = c.get("auth");
9882
9981
  const readable = await filterReadableDocsChannels(
@@ -9921,7 +10020,7 @@ function createDocShareListRouter() {
9921
10020
  return app;
9922
10021
  }
9923
10022
  function createDocShareWriteRouter(agent = {}) {
9924
- const app = new Hono14();
10023
+ const app = new Hono16();
9925
10024
  app.use("/:id/docs/share", requireDocsAccess);
9926
10025
  app.use("/:id/docs/share/*", requireDocsAccess);
9927
10026
  app.use("/:id/docs/shares", requireDocsAccess);
@@ -10103,7 +10202,7 @@ function createDocShareWriteRouter(agent = {}) {
10103
10202
  }
10104
10203
 
10105
10204
  // ../api/src/dashboard/search-routes.ts
10106
- import { Hono as Hono15 } from "hono";
10205
+ import { Hono as Hono17 } from "hono";
10107
10206
  function matchScore(q, fields) {
10108
10207
  const terms = q.toLowerCase().split(/\s+/).filter(Boolean);
10109
10208
  if (terms.length === 0) return 0;
@@ -10251,7 +10350,7 @@ function searchAutomations(q) {
10251
10350
  }
10252
10351
  var RESULT_LIMIT = 30;
10253
10352
  function createSearchRouter() {
10254
- const app = new Hono15();
10353
+ const app = new Hono17();
10255
10354
  app.get("/", async (c) => {
10256
10355
  const q = c.req.query("q")?.trim();
10257
10356
  if (!q) return c.json({ results: [] });
@@ -10267,7 +10366,7 @@ function createSearchRouter() {
10267
10366
  }
10268
10367
 
10269
10368
  // ../api/src/dashboard/domain-routes.ts
10270
- import { Hono as Hono16 } from "hono";
10369
+ import { Hono as Hono18 } from "hono";
10271
10370
  var FALLBACK_ORIGIN = "custom.flyspace.ai";
10272
10371
  function isValidCustomHostname(hostname2) {
10273
10372
  if (hostname2.length > 253 || hostname2.endsWith(".flyspace.ai") || hostname2 === "flyspace.ai") {
@@ -10337,7 +10436,7 @@ function view(row, dcv) {
10337
10436
  };
10338
10437
  }
10339
10438
  function createDomainRouter() {
10340
- const app = new Hono16();
10439
+ const app = new Hono18();
10341
10440
  app.use("*", async (c, next) => {
10342
10441
  const auth = c.get("auth");
10343
10442
  if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
@@ -10400,15 +10499,77 @@ function createDomainRouter() {
10400
10499
  return app;
10401
10500
  }
10402
10501
 
10502
+ // ../api/src/dashboard/support-grant-routes.ts
10503
+ import { Hono as Hono19 } from "hono";
10504
+ function createSupportGrantRouter() {
10505
+ const app = new Hono19();
10506
+ app.use("*", async (c, next) => {
10507
+ const auth = c.get("auth");
10508
+ if (auth.role !== "admin" || auth.isSupport) {
10509
+ return c.json({ error: "workspace admin access required" }, 403);
10510
+ }
10511
+ await next();
10512
+ });
10513
+ app.get("/", async (c) => {
10514
+ return c.json({ grant: await getActiveSupportGrant(c.get("auth").workspaceId) });
10515
+ });
10516
+ app.get("/activity", async (c) => {
10517
+ const limit = Number(c.req.query("limit")) || 200;
10518
+ return c.json({ entries: await listSupportLog({ workspaceId: c.get("auth").workspaceId, limit }) });
10519
+ });
10520
+ app.post("/", async (c) => {
10521
+ const auth = c.get("auth");
10522
+ const body = await c.req.json().catch(() => ({}));
10523
+ const hours = Number(body.hours);
10524
+ if (!SUPPORT_GRANT_HOURS.includes(hours)) {
10525
+ return c.json({ error: `hours must be one of ${SUPPORT_GRANT_HOURS.join(", ")}` }, 400);
10526
+ }
10527
+ const reason = typeof body.reason === "string" ? body.reason.trim().slice(0, 500) : "";
10528
+ const grant = await createSupportGrant({
10529
+ workspaceId: auth.workspaceId,
10530
+ userId: auth.userId,
10531
+ email: auth.email,
10532
+ hours,
10533
+ ...reason ? { reason } : {}
10534
+ });
10535
+ await logSupportAction({
10536
+ workspaceId: auth.workspaceId,
10537
+ staffUserId: auth.userId,
10538
+ staffEmail: auth.email,
10539
+ action: "granted",
10540
+ detail: { hours, expiresAt: grant.expiresAt, ...reason ? { reason } : {} }
10541
+ });
10542
+ invalidateAuthContextCache();
10543
+ return c.json({ grant });
10544
+ });
10545
+ app.delete("/", async (c) => {
10546
+ const auth = c.get("auth");
10547
+ if (await revokeSupportGrants(auth.workspaceId, auth.userId) > 0) {
10548
+ await logSupportAction({
10549
+ workspaceId: auth.workspaceId,
10550
+ staffUserId: auth.userId,
10551
+ staffEmail: auth.email,
10552
+ action: "revoked"
10553
+ });
10554
+ }
10555
+ invalidateAuthContextCache();
10556
+ return c.json({ grant: null });
10557
+ });
10558
+ return app;
10559
+ }
10560
+
10403
10561
  // ../api/src/dashboard/transcribe-routes.ts
10404
- import { Hono as Hono17 } from "hono";
10562
+ import { Hono as Hono20 } from "hono";
10405
10563
  var GROQ_TRANSCRIBE_URL = "https://api.groq.com/openai/v1/audio/transcriptions";
10406
10564
  var MODEL2 = "whisper-large-v3-turbo";
10407
10565
  var MAX_AUDIO_BYTES = 25 * 1024 * 1024;
10408
10566
  var MAX_PROMPT_CHARS = 400;
10409
10567
  var MAX_TAIL_CHARS = 200;
10410
10568
  var MAX_GLOSSARY_CHARS = 150;
10411
- var STYLE_SEED = "\u9019\u662F\u7E41\u9AD4\u4E2D\u6587\u7684\u53E3\u8FF0\uFF0C\u4E2D\u9593\u593E\u96DC English \u8853\u8A9E\uFF0C\u4F8B\u5982 component\u3001API\u3001deploy\u3002";
10569
+ var STYLE_SEEDS = {
10570
+ "zh-Hant": "\u9019\u662F\u7E41\u9AD4\u4E2D\u6587\u7684\u53E3\u8FF0\uFF0C\u4E2D\u9593\u593E\u96DC English \u8853\u8A9E\uFF0C\u4F8B\u5982 component\u3001API\u3001deploy\u3002",
10571
+ "zh-Hans": "\u8FD9\u662F\u7B80\u4F53\u4E2D\u6587\u7684\u53E3\u8FF0\uFF0C\u4E2D\u95F4\u5939\u6742 English \u672F\u8BED\uFF0C\u4F8B\u5982 component\u3001API\u3001deploy\u3002"
10572
+ };
10412
10573
  var HALLUCINATIONS = [
10413
10574
  /^(謝謝|感謝)(大家|您|你)?(的)?(收看|觀看|收聽|觀賞)[。!!.]?$/,
10414
10575
  /^請不吝點讚.*$/,
@@ -10420,18 +10581,18 @@ function isHallucination(text) {
10420
10581
  const t = text.trim();
10421
10582
  return HALLUCINATIONS.some((re) => re.test(t));
10422
10583
  }
10423
- function buildPrompt(terms, tail) {
10584
+ function buildPrompt(terms, tail, locale) {
10424
10585
  let glossary = "";
10425
10586
  for (const term of terms) {
10426
10587
  const next = glossary ? `${glossary}\u3001${term}` : term;
10427
10588
  if (next.length > MAX_GLOSSARY_CHARS) break;
10428
10589
  glossary = next;
10429
10590
  }
10430
- return [glossary && `${glossary}\u3002`, STYLE_SEED, tail.slice(-MAX_TAIL_CHARS)].filter(Boolean).join(" ").slice(-MAX_PROMPT_CHARS);
10591
+ return [glossary && `${glossary}.`, locale && STYLE_SEEDS[locale], tail.slice(-MAX_TAIL_CHARS)].filter(Boolean).join(" ").slice(-MAX_PROMPT_CHARS);
10431
10592
  }
10432
10593
  var NO_SPEECH_THRESHOLD = 0.6;
10433
10594
  function createTranscribeRouter() {
10434
- const app = new Hono17();
10595
+ const app = new Hono20();
10435
10596
  app.post("/transcribe", async (c) => {
10436
10597
  const apiKey = process.env["GROQ_API_KEY"];
10437
10598
  if (!apiKey) return c.json({ error: "transcription is not configured" }, 503);
@@ -10454,7 +10615,9 @@ function createTranscribeRouter() {
10454
10615
  terms = (glossary.get(channelId)?.terms ?? []).map((t) => t.term);
10455
10616
  }
10456
10617
  }
10457
- form.append("prompt", buildPrompt(terms, tail));
10618
+ const locale = typeof body?.["locale"] === "string" ? body["locale"] : void 0;
10619
+ const prompt = buildPrompt(terms, tail, locale);
10620
+ if (prompt) form.append("prompt", prompt);
10458
10621
  const language = body?.["language"];
10459
10622
  if (typeof language === "string" && /^[a-z]{2}$/.test(language)) {
10460
10623
  form.append("language", language);
@@ -10477,7 +10640,7 @@ function createTranscribeRouter() {
10477
10640
  }
10478
10641
 
10479
10642
  // ../api/src/dashboard/autocomplete-routes.ts
10480
- import { Hono as Hono18 } from "hono";
10643
+ import { Hono as Hono21 } from "hono";
10481
10644
  var GROQ_API_URL4 = "https://api.groq.com/openai/v1/chat/completions";
10482
10645
  var MODEL3 = "openai/gpt-oss-120b";
10483
10646
  var MAX_REPLY_CHARS = 4e3;
@@ -10488,7 +10651,7 @@ Base it on the agent's last reply: answer a question it asked, approve or pick a
10488
10651
  Keep it short (under 15 words), in the language the user writes in. No greetings, thanks or filler.
10489
10652
  Output ONLY the message text, no quotes or explanation. If there is no clear next step, output nothing.`;
10490
10653
  function createAutocompleteRouter() {
10491
- const app = new Hono18();
10654
+ const app = new Hono21();
10492
10655
  app.post("/autocomplete", async (c) => {
10493
10656
  const apiKey = process.env["GROQ_API_KEY"];
10494
10657
  if (!apiKey) return c.json({ error: "autocomplete is not configured" }, 503);
@@ -10554,7 +10717,7 @@ ${last.body.slice(-MAX_REPLY_CHARS)}`;
10554
10717
  }
10555
10718
 
10556
10719
  // ../api/src/dashboard/daily-line-routes.ts
10557
- import { Hono as Hono19 } from "hono";
10720
+ import { Hono as Hono22 } from "hono";
10558
10721
  var GROQ_API_URL5 = "https://api.groq.com/openai/v1/chat/completions";
10559
10722
  var MODEL4 = "openai/gpt-oss-120b";
10560
10723
  var DAY_MS = 864e5;
@@ -10580,7 +10743,7 @@ function pickMemories(memories, day, now = Date.now()) {
10580
10743
  return [...pool, ...pool].slice(start, start + Math.min(CONTEXT_COUNT, pool.length));
10581
10744
  }
10582
10745
  function createDailyLineRouter() {
10583
- const app = new Hono19();
10746
+ const app = new Hono22();
10584
10747
  app.get("/daily-line", async (c) => {
10585
10748
  if (!await isFeatureEnabled(c, "daily-line"))
10586
10749
  return c.json({ error: "feature not enabled" }, 403);
@@ -10636,7 +10799,7 @@ Write it in ${language} (BCP 47 tag). For Chinese use Traditional Chinese (Taiwa
10636
10799
  }
10637
10800
 
10638
10801
  // ../api/src/dashboard/channel-route.ts
10639
- import { Hono as Hono20 } from "hono";
10802
+ import { Hono as Hono23 } from "hono";
10640
10803
  var GROQ_API_URL6 = "https://api.groq.com/openai/v1/chat/completions";
10641
10804
  var MODEL5 = "openai/gpt-oss-120b";
10642
10805
  var MAX_MESSAGE_CHARS2 = 3e3;
@@ -10706,7 +10869,7 @@ A topic word that could fit many projects (notification, scrollbar, login, bug)
10706
10869
  When a screenshot description is given, the app and names visible in it are strong evidence of the project.
10707
10870
  Output ONLY the channel's number and your confidence, e.g. "3 high" or "3 low". Say low when the message could reasonably belong to more than one channel.`;
10708
10871
  function createChannelRouteRouter() {
10709
- const app = new Hono20();
10872
+ const app = new Hono23();
10710
10873
  app.post("/route-channel", async (c) => {
10711
10874
  if (!await isFeatureEnabled(c, "auto-channel"))
10712
10875
  return c.json({ error: "feature not enabled" }, 403);
@@ -10766,7 +10929,7 @@ ${screenshots}` : ""}` }
10766
10929
 
10767
10930
  // ../api/src/dashboard/avatars-routes.ts
10768
10931
  import { createHash as createHash5, randomUUID as randomUUID3 } from "crypto";
10769
- import { Hono as Hono21 } from "hono";
10932
+ import { Hono as Hono24 } from "hono";
10770
10933
  import sharp3 from "sharp";
10771
10934
  import { PutObjectCommand as PutObjectCommand3, DeleteObjectCommand as DeleteObjectCommand2 } from "@aws-sdk/client-s3";
10772
10935
  var AVATAR_SIZE = 192;
@@ -10819,7 +10982,7 @@ function avatarKeyPrefix() {
10819
10982
  return `${KEY_PREFIX2}/${getProfile()}/`;
10820
10983
  }
10821
10984
  function createAvatarsRouter() {
10822
- const app = new Hono21();
10985
+ const app = new Hono24();
10823
10986
  app.get("/avatars/slack", async (c) => {
10824
10987
  const ctx = await resolveAuthContext(c);
10825
10988
  if (!ctx) return c.json({ error: "not signed in" }, 401);
@@ -10868,7 +11031,7 @@ function createAvatarsRouter() {
10868
11031
  }
10869
11032
 
10870
11033
  // ../api/src/dashboard/members-routes.ts
10871
- import { Hono as Hono22 } from "hono";
11034
+ import { Hono as Hono25 } from "hono";
10872
11035
  function inviteLinkFor(c, token) {
10873
11036
  const url = new URL("/auth/invite", callbackUrl(c));
10874
11037
  url.searchParams.set("token", token);
@@ -10876,7 +11039,7 @@ function inviteLinkFor(c, token) {
10876
11039
  }
10877
11040
  var EMAIL_RE2 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
10878
11041
  function createMembersRouter() {
10879
- const members = new Hono22();
11042
+ const members = new Hono25();
10880
11043
  members.get("/", async (c) => {
10881
11044
  const ctx = await resolveAuthContext(c);
10882
11045
  if (ctx?.role !== "admin") return c.json({ error: "admin access required" }, 403);
@@ -11099,7 +11262,7 @@ function createMembersRouter() {
11099
11262
  }
11100
11263
 
11101
11264
  // ../api/src/dashboard/notifications-routes.ts
11102
- import { Hono as Hono23 } from "hono";
11265
+ import { Hono as Hono26 } from "hono";
11103
11266
 
11104
11267
  // ../api/src/store/push-store.ts
11105
11268
  function rowToSubscription(row) {
@@ -11284,7 +11447,7 @@ function startPushWatcher() {
11284
11447
 
11285
11448
  // ../api/src/dashboard/notifications-routes.ts
11286
11449
  function createNotificationsRouter() {
11287
- const notifications = new Hono23();
11450
+ const notifications = new Hono26();
11288
11451
  notifications.get("/", async (c) => {
11289
11452
  const auth = c.get("auth");
11290
11453
  const channelIds = getProfileChannelRegistry().filter((ch) => canSeeChannel(ch, auth)).map((ch) => ch.id);
@@ -11311,7 +11474,7 @@ function createNotificationsRouter() {
11311
11474
  return notifications;
11312
11475
  }
11313
11476
  function createThreadReadRouter() {
11314
- const threads = new Hono23();
11477
+ const threads = new Hono26();
11315
11478
  threads.post("/threads/:threadId/read", async (c) => {
11316
11479
  const { userId } = c.get("auth");
11317
11480
  const threadId = c.req.param("threadId");
@@ -11335,9 +11498,9 @@ function createThreadReadRouter() {
11335
11498
  }
11336
11499
 
11337
11500
  // ../api/src/dashboard/push-routes.ts
11338
- import { Hono as Hono24 } from "hono";
11501
+ import { Hono as Hono27 } from "hono";
11339
11502
  function createPushRouter() {
11340
- const push = new Hono24();
11503
+ const push = new Hono27();
11341
11504
  push.get("/key", (c) => c.json({ publicKey: getVapidPublicKey() }));
11342
11505
  push.post("/subscribe", async (c) => {
11343
11506
  const { userId } = c.get("auth");
@@ -11368,7 +11531,7 @@ function createPushRouter() {
11368
11531
  }
11369
11532
 
11370
11533
  // ../api/src/dashboard/mcp-oauth-routes.ts
11371
- import { Hono as Hono25 } from "hono";
11534
+ import { Hono as Hono28 } from "hono";
11372
11535
  var CONNECTIONS_PAGE = "/settings/connections";
11373
11536
  function callbackUri(c) {
11374
11537
  const proto = c.req.header("x-forwarded-proto") ?? "http";
@@ -11383,7 +11546,7 @@ function backToDashboard(c, to, params) {
11383
11546
  return c.redirect(`${target.pathname}${target.search}`);
11384
11547
  }
11385
11548
  function createMcpOAuthRouter() {
11386
- const app = new Hono25();
11549
+ const app = new Hono28();
11387
11550
  app.get("/oauth/:provider/start", async (c) => {
11388
11551
  const auth = c.get("auth");
11389
11552
  if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
@@ -11510,7 +11673,7 @@ function createMcpOAuthRouter() {
11510
11673
  }
11511
11674
 
11512
11675
  // ../api/src/dashboard/mcp-routes.ts
11513
- import { Hono as Hono26 } from "hono";
11676
+ import { Hono as Hono29 } from "hono";
11514
11677
 
11515
11678
  // ../api/src/mcp/transport.ts
11516
11679
  var KINDS = ["inherit", "npx", "local", "http", "sse"];
@@ -11640,7 +11803,7 @@ function bindingsByConnection() {
11640
11803
  return map;
11641
11804
  }
11642
11805
  function createMcpRouter() {
11643
- const app = new Hono26();
11806
+ const app = new Hono29();
11644
11807
  app.get("/providers", async (c) => {
11645
11808
  const denied = requireAdmin(c.get("auth"));
11646
11809
  if (denied) return c.json({ error: denied }, 403);
@@ -12170,9 +12333,9 @@ ${transcriptOf(data ?? [])}`
12170
12333
  }
12171
12334
 
12172
12335
  // ../api/src/dashboard/permission-routes.ts
12173
- import { Hono as Hono27 } from "hono";
12336
+ import { Hono as Hono30 } from "hono";
12174
12337
  function createPermissionRequestsRouter() {
12175
- const app = new Hono27();
12338
+ const app = new Hono30();
12176
12339
  app.post("/:id", async (c) => {
12177
12340
  const auth = c.get("auth");
12178
12341
  if (auth.role !== "admin") return c.json({ error: "only an admin can answer this" }, 403);
@@ -12202,7 +12365,7 @@ function createPermissionRequestsRouter() {
12202
12365
  }
12203
12366
 
12204
12367
  // ../api/src/dashboard/channel-greeting.ts
12205
- import { Hono as Hono28 } from "hono";
12368
+ import { Hono as Hono31 } from "hono";
12206
12369
  function eligible(ch) {
12207
12370
  return !!ch && !ch.isDefault && !ch.dmKey && !ch.agentName && !ch.archivedAt;
12208
12371
  }
@@ -12231,7 +12394,7 @@ function introOpening(channelName) {
12231
12394
  return `Welcome to #${channelName}. I'm reading this project's folder, docs, skills and automations to work out how I can help here. Below you'll find a short intro and a few first steps you can click to try.`;
12232
12395
  }
12233
12396
  function createChannelGreetingRouter(agent) {
12234
- const app = new Hono28();
12397
+ const app = new Hono31();
12235
12398
  app.get("/:id/greeting", async (c) => {
12236
12399
  const ctx = await resolveAuthContext(c);
12237
12400
  const ch = findChannelById(c.req.param("id"));
@@ -12289,7 +12452,7 @@ async function ensureIntroThread(ch) {
12289
12452
  }
12290
12453
 
12291
12454
  // ../api/src/dashboard/channel-suggest.ts
12292
- import { Hono as Hono29 } from "hono";
12455
+ import { Hono as Hono32 } from "hono";
12293
12456
  var CATEGORY_MAX_CHARS = 16;
12294
12457
  var CATEGORY_MAX_ITEMS = 30;
12295
12458
  var PROMPT_MAX_CHARS = 4e3;
@@ -12337,7 +12500,7 @@ function parseSuggestion(field, raw) {
12337
12500
  return items2.length ? items2.slice(0, CATEGORY_MAX_ITEMS).join("\n") : null;
12338
12501
  }
12339
12502
  function createChannelSuggestRouter(agent) {
12340
- const router = new Hono29();
12503
+ const router = new Hono32();
12341
12504
  router.post("/:id/suggest", async (c) => {
12342
12505
  const channel = findChannel(c.req.param("id"));
12343
12506
  if (!channel || !canSeeChannel(channel, c.get("auth"))) {
@@ -12374,87 +12537,104 @@ function createChannelSuggestRouter(agent) {
12374
12537
  return router;
12375
12538
  }
12376
12539
 
12377
- // ../api/src/dashboard/channel-members-routes.ts
12378
- import { Hono as Hono30 } from "hono";
12379
- async function isChannelAdmin(ctx, channelId) {
12380
- if (ctx.role === "admin") return true;
12381
- const membership = await getMembershipByUserId(ctx.workspaceId, ctx.userId);
12382
- if (!membership) return false;
12383
- const members = await listChannelMembers(channelId);
12384
- return members.some((m) => m.membershipId === membership.id && m.role === "channel_admin");
12385
- }
12386
- function createChannelMembersRouter() {
12387
- const router = new Hono30();
12388
- router.get("/:id/members", async (c) => {
12389
- const ctx = await resolveAuthContext(c);
12390
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12391
- const members = await listChannelMembers(c.req.param("id"));
12392
- return c.json({ members });
12540
+ // ../api/src/dashboard/channel-destroy-routes.ts
12541
+ import { Hono as Hono33 } from "hono";
12542
+ import { DeleteObjectCommand as DeleteObjectCommand3, ListObjectsV2Command } from "@aws-sdk/client-s3";
12543
+ function createChannelDestroyRouter() {
12544
+ const router = new Hono33();
12545
+ const gate = async (c) => {
12546
+ const auth = await resolveAuthContext(c);
12547
+ if (!auth || auth.role !== "admin" || auth.isSupport) return null;
12548
+ return auth;
12549
+ };
12550
+ const loadChannel = async (id) => {
12551
+ const { data } = await getSupabaseClient().from("channels").select(
12552
+ "id, name, cwd, profile, archived_at, is_default, dm_key, agent_name, external_channel_id"
12553
+ ).eq("id", id).maybeSingle();
12554
+ return data && data.profile === getProfile() ? data : null;
12555
+ };
12556
+ const refusal = (ch) => ch.is_default || ch.dm_key || ch.agent_name || ch.id === process.env["SUPPORT_TICKET_CHANNEL_ID"];
12557
+ router.get("/:id/destroy-preview", async (c) => {
12558
+ if (!await gate(c)) return c.json({ error: "workspace admin only" }, 403);
12559
+ const ch = await loadChannel(c.req.param("id"));
12560
+ if (!ch) return c.json({ error: "channel not found" }, 404);
12561
+ const { data, error: error2 } = await getSupabaseClient().rpc("destroy_channel_preview", {
12562
+ p_channel_id: ch.id,
12563
+ p_profile: ch.profile
12564
+ });
12565
+ if (error2) return c.json({ error: error2.message }, 500);
12566
+ return c.json({
12567
+ name: ch.name,
12568
+ cwd: ch.cwd,
12569
+ cwdDisplay: displayCwd(ch.cwd, cachedProfileConfig()?.home),
12570
+ slackBound: !!ch.external_channel_id,
12571
+ counts: data
12572
+ });
12393
12573
  });
12394
- router.put("/:id/members/:membershipId", async (c) => {
12395
- const ctx = await resolveAuthContext(c);
12396
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12397
- const channelId = c.req.param("id");
12398
- if (!await isChannelAdmin(ctx, channelId)) {
12399
- return c.json({ error: "channel admin access required" }, 403);
12400
- }
12574
+ router.delete("/:id", async (c) => {
12575
+ if (!await gate(c)) return c.json({ error: "workspace admin only" }, 403);
12576
+ const ch = await loadChannel(c.req.param("id"));
12577
+ if (!ch) return c.json({ error: "channel not found" }, 404);
12578
+ if (!ch.archived_at) return c.json({ error: "archive the channel first" }, 409);
12579
+ if (refusal(ch)) return c.json({ error: "this channel cannot be destroyed" }, 400);
12401
12580
  const body = await c.req.json().catch(() => ({}));
12402
- if (body.role !== "channel_admin" && body.role !== "channel_member") {
12403
- return c.json({ error: "role must be 'channel_admin' or 'channel_member'" }, 400);
12404
- }
12405
- const member = await upsertChannelMember({
12406
- channelId,
12407
- membershipId: c.req.param("membershipId"),
12408
- role: body.role
12581
+ if (typeof body.confirmName !== "string" || body.confirmName.trim() !== ch.name)
12582
+ return c.json({ error: "confirmName does not match" }, 400);
12583
+ const { data, error: error2 } = await getSupabaseClient().rpc("destroy_channel", {
12584
+ p_channel_id: ch.id,
12585
+ p_profile: ch.profile
12409
12586
  });
12410
- return c.json({ member });
12411
- });
12412
- router.delete("/:id/members/:membershipId", async (c) => {
12413
- const ctx = await resolveAuthContext(c);
12414
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12415
- const channelId = c.req.param("id");
12416
- if (!await isChannelAdmin(ctx, channelId)) {
12417
- return c.json({ error: "channel admin access required" }, 403);
12418
- }
12419
- const removed = await removeChannelMember(channelId, c.req.param("membershipId"));
12420
- if (!removed) return c.json({ error: "no such channel member" }, 404);
12421
- return c.body(null, 204);
12422
- });
12423
- router.get("/:id/docs-access/me", async (c) => {
12424
- const ctx = await resolveAuthContext(c);
12425
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12426
- return c.json({ access: await resolveDocsAccess(ctx, c.req.param("id")) });
12427
- });
12428
- router.get("/:id/docs-access", async (c) => {
12429
- const ctx = await resolveAuthContext(c);
12430
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12431
- const channelId = c.req.param("id");
12432
- if (!await isChannelAdmin(ctx, channelId)) {
12433
- return c.json({ error: "channel admin access required" }, 403);
12434
- }
12435
- return c.json({ memberAccess: await getChannelDocsMemberAccess(channelId) });
12587
+ if (error2) {
12588
+ const status = error2.code === "P0002" ? 404 : error2.code === "55000" ? 409 : error2.code === "22023" ? 400 : 500;
12589
+ return c.json({ error: error2.message }, status);
12590
+ }
12591
+ const {
12592
+ shareIds = [],
12593
+ audioKeys = [],
12594
+ attachmentKeys = [],
12595
+ ...deleted
12596
+ } = data;
12597
+ const r2 = await purgeR2(shareIds, [
12598
+ ...audioKeys,
12599
+ ...attachmentKeys.flatMap(
12600
+ (k) => k.endsWith(".webp") ? [k, k.replace(/\.webp$/, ".thumb.webp")] : [k]
12601
+ )
12602
+ ]);
12603
+ await refreshChannelRegistry().catch(() => {
12604
+ });
12605
+ return c.json({ ok: true, deleted, r2 });
12436
12606
  });
12437
- router.put("/:id/docs-access", async (c) => {
12438
- const ctx = await resolveAuthContext(c);
12439
- if (!ctx) return c.json({ error: "workspace access required" }, 403);
12440
- const channelId = c.req.param("id");
12441
- if (!await isChannelAdmin(ctx, channelId)) {
12442
- return c.json({ error: "channel admin access required" }, 403);
12443
- }
12444
- const body = await c.req.json().catch(() => ({}));
12445
- if (!isDocsAccess(body.memberAccess)) {
12446
- return c.json({ error: "memberAccess must be 'none', 'read' or 'write'" }, 400);
12607
+ return router;
12608
+ }
12609
+ async function purgeR2(shareIds, keys) {
12610
+ let deleted = 0;
12611
+ let failed2 = 0;
12612
+ const del = async (key) => {
12613
+ try {
12614
+ await getR2Client().send(new DeleteObjectCommand3({ Bucket: getR2Bucket(), Key: key }));
12615
+ deleted++;
12616
+ } catch (err) {
12617
+ failed2++;
12618
+ console.error(`[channel-destroy] R2 delete failed for ${key}:`, err);
12447
12619
  }
12448
- if (!await setChannelDocsMemberAccess(channelId, body.memberAccess)) {
12449
- return c.json({ error: "no such channel" }, 404);
12620
+ };
12621
+ for (const id of shareIds) {
12622
+ try {
12623
+ const list = await getR2Client().send(
12624
+ new ListObjectsV2Command({ Bucket: getR2Bucket(), Prefix: `share/${id}/` })
12625
+ );
12626
+ for (const o of list.Contents ?? []) if (o.Key) await del(o.Key);
12627
+ } catch (err) {
12628
+ failed2++;
12629
+ console.error(`[channel-destroy] R2 list failed for share/${id}/:`, err);
12450
12630
  }
12451
- return c.json({ memberAccess: body.memberAccess });
12452
- });
12453
- return router;
12631
+ }
12632
+ for (const key of keys) await del(key);
12633
+ return { deleted, failed: failed2 };
12454
12634
  }
12455
12635
 
12456
12636
  // ../api/src/dashboard/memories-routes.ts
12457
- import { Hono as Hono31 } from "hono";
12637
+ import { Hono as Hono34 } from "hono";
12458
12638
  async function readPatch(c) {
12459
12639
  const body = await c.req.json().catch(() => ({}));
12460
12640
  const patch = {};
@@ -12482,7 +12662,7 @@ var requireAgentMemory = async (c, next) => {
12482
12662
  await next();
12483
12663
  };
12484
12664
  function createMemoriesRouter() {
12485
- const router = new Hono31();
12665
+ const router = new Hono34();
12486
12666
  for (const path of [
12487
12667
  "/:id/memories",
12488
12668
  "/:id/memories/*",
@@ -12555,7 +12735,7 @@ function createMemoriesRouter() {
12555
12735
  return router;
12556
12736
  }
12557
12737
  function createScopedMemoriesRouter() {
12558
- const router = new Hono31();
12738
+ const router = new Hono34();
12559
12739
  router.use("*", requireAgentMemory);
12560
12740
  const workspace = (c) => ({
12561
12741
  scope: "workspace",
@@ -12615,7 +12795,7 @@ function createScopedMemoriesRouter() {
12615
12795
  }
12616
12796
 
12617
12797
  // ../api/src/dashboard/session-import-routes.ts
12618
- import { Hono as Hono32 } from "hono";
12798
+ import { Hono as Hono35 } from "hono";
12619
12799
  var MAX_FOLDERS2 = 20;
12620
12800
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
12621
12801
  var IMPORT_RANGES = ["all", "7d", "latest5"];
@@ -12722,7 +12902,7 @@ async function syncSession(agent, channelId, session, author, existing) {
12722
12902
  return messages.length;
12723
12903
  }
12724
12904
  function createSessionImportRouter(agent) {
12725
- const app = new Hono32();
12905
+ const app = new Hono35();
12726
12906
  const scanFolders = async () => {
12727
12907
  const scan = await ask(agent, { op: "scan", slug: getProfile() });
12728
12908
  return scan && importableFolders(scan.folders, getProfileChannelRegistry());
@@ -12984,6 +13164,7 @@ function registerDataRoutes(api, agent = {}) {
12984
13164
  const auth = c.get("auth");
12985
13165
  const channels = getProfileChannelRegistry().filter((ch) => canSeeChannel(ch, auth));
12986
13166
  const missingCwds = await agent.listMissingCwds?.();
13167
+ const hostHome = cachedProfileConfig()?.home;
12987
13168
  const list = channels.map((ch) => ({
12988
13169
  id: ch.id,
12989
13170
  externalChannelId: ch.externalChannelId,
@@ -12993,6 +13174,8 @@ function registerDataRoutes(api, agent = {}) {
12993
13174
  name: ch.dmKey && !ch.agentName ? ch.name.split(", ").filter((h) => h !== auth.handle).join(", ") || ch.name : ch.name,
12994
13175
  configured: true,
12995
13176
  cwd: ch.cwd,
13177
+ // What the UI shows: never a full absolute path (see displayCwd).
13178
+ cwdDisplay: displayCwd(ch.cwd, hostHome),
12996
13179
  // Surfaces a rotted working directory in the sidebar instead of
12997
13180
  // waiting for the next @agent mention to fail (see auditChannelCwds).
12998
13181
  cwdMissing: missingCwds ? missingCwds.includes(ch.id) : void 0,
@@ -13030,6 +13213,8 @@ function registerDataRoutes(api, agent = {}) {
13030
13213
  api.route("/channels", createChannelGreetingRouter(agent));
13031
13214
  api.route("/channels", createChannelSuggestRouter(agent));
13032
13215
  api.route("/channels", createChannelMembersRouter());
13216
+ api.route("/channels", createChannelAgentRouter());
13217
+ api.route("/channels", createChannelDestroyRouter());
13033
13218
  api.route("/channels", createMemoriesRouter());
13034
13219
  api.route("/memories", createScopedMemoriesRouter());
13035
13220
  api.route("/docs", createDocShareListRouter());
@@ -13153,6 +13338,7 @@ function registerDataRoutes(api, agent = {}) {
13153
13338
  api.route("/tts", createTtsRouter());
13154
13339
  api.route("/feature-flags", createFeatureFlagsRouter());
13155
13340
  api.route("/domain", createDomainRouter());
13341
+ api.route("/support-access", createSupportGrantRouter());
13156
13342
  api.route("/members", createMembersRouter());
13157
13343
  api.route("/notifications", createNotificationsRouter());
13158
13344
  api.route("/push", createPushRouter());
@@ -13185,6 +13371,18 @@ function registerDataRoutes(api, agent = {}) {
13185
13371
  await setWorkspacePermissionMode(auth.workspaceId, body.permissionMode);
13186
13372
  return c.json({ permissionMode: body.permissionMode });
13187
13373
  });
13374
+ api.put("/default-effort", async (c) => {
13375
+ const auth = c.get("auth");
13376
+ if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
13377
+ const { defaultEffort: raw } = await c.req.json().catch(() => ({}));
13378
+ const value = raw === null || raw === "" ? null : typeof raw === "string" && isEffort(raw) ? raw : void 0;
13379
+ if (value === void 0) {
13380
+ return c.json({ error: "defaultEffort must be low, medium, high, xhigh, max or null" }, 400);
13381
+ }
13382
+ await setWorkspaceAgentDefaults(auth.workspaceId, { defaultEffort: value });
13383
+ await refreshChannelRegistry();
13384
+ return c.json({ defaultEffort: value });
13385
+ });
13188
13386
  api.get("/own-persona", async (c) => {
13189
13387
  const auth = c.get("auth");
13190
13388
  return c.json({ enabled: await getWorkspaceOwnPersona(auth.workspaceId) });
@@ -13347,7 +13545,7 @@ function registerDataRoutes(api, agent = {}) {
13347
13545
  // ../api/src/dashboard/device-auth-routes.ts
13348
13546
  import { verify } from "crypto";
13349
13547
  import { getConnInfo } from "@hono/node-server/conninfo";
13350
- import { Hono as Hono33 } from "hono";
13548
+ import { Hono as Hono36 } from "hono";
13351
13549
  var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
13352
13550
  function cleanText(value, max) {
13353
13551
  if (typeof value !== "string") return null;
@@ -13395,7 +13593,7 @@ async function boundWorkspaceIds(publicKey, userId) {
13395
13593
  return new Set(existing ? (await listDeviceWorkspaces(existing)).map((w) => w.id) : []);
13396
13594
  }
13397
13595
  function createDeviceAuthRouter() {
13398
- const app = new Hono33();
13596
+ const app = new Hono36();
13399
13597
  app.post("/code", async (c) => {
13400
13598
  const body = await readBody(c);
13401
13599
  const publicKey = typeof body["public_key"] === "string" ? body["public_key"] : "";
@@ -13714,7 +13912,7 @@ var workspaceRef = () => ({ kind: "workspace" });
13714
13912
  var channelRef = (c) => ({ kind: "channel", channelId: c.req.param("id") });
13715
13913
 
13716
13914
  // ../api/src/dashboard/output-styles-routes.ts
13717
- import { Hono as Hono34 } from "hono";
13915
+ import { Hono as Hono37 } from "hono";
13718
13916
  function requireAdmin3(auth) {
13719
13917
  return auth?.role === "admin" ? null : "admin access required";
13720
13918
  }
@@ -13734,7 +13932,7 @@ function failure(c, err) {
13734
13932
  return c.json({ error: message }, err instanceof OutputStyleConflictError ? 409 : 500);
13735
13933
  }
13736
13934
  function createOutputStylesRouter() {
13737
- const app = new Hono34();
13935
+ const app = new Hono37();
13738
13936
  app.get("/", (c) => {
13739
13937
  const auth = c.get("auth");
13740
13938
  const denied = requireAdmin3(auth);
@@ -13826,7 +14024,7 @@ function createOutputStylesRouter() {
13826
14024
  return app;
13827
14025
  }
13828
14026
  async function handleOutputStylesRequest(req) {
13829
- const app = new Hono34();
14027
+ const app = new Hono37();
13830
14028
  app.use("*", async (c, next) => {
13831
14029
  c.set("auth", { role: "admin" });
13832
14030
  await next();
@@ -13865,7 +14063,7 @@ async function viewerProfile(c, known) {
13865
14063
  return candidates[0]?.w.slug ?? null;
13866
14064
  }
13867
14065
  function createGatedRouter(agent, register) {
13868
- const api = new Hono35();
14066
+ const api = new Hono38();
13869
14067
  api.use("*", async (c, next) => {
13870
14068
  const known = await listKnownWorkspaces();
13871
14069
  const fromHost = profileFromHost(trustedHost(c), known);
@@ -13917,7 +14115,7 @@ import sharp5 from "sharp";
13917
14115
 
13918
14116
  // src/dashboard/channels-routes.ts
13919
14117
  import { existsSync as existsSync19, mkdirSync as mkdirSync8 } from "fs";
13920
- import { Hono as Hono36 } from "hono";
14118
+ import { Hono as Hono39 } from "hono";
13921
14119
  function coerceAccess(raw) {
13922
14120
  if (raw === "open" || raw === "*" || raw === "all") return raw;
13923
14121
  if (Array.isArray(raw) && raw.every((v) => typeof v === "string")) return raw;
@@ -13989,7 +14187,7 @@ function toResponse3(channel) {
13989
14187
  };
13990
14188
  }
13991
14189
  function createChannelWriteRouter() {
13992
- const app = new Hono36();
14190
+ const app = new Hono39();
13993
14191
  app.post("/", async (c) => {
13994
14192
  const body = await c.req.json().catch(() => ({}));
13995
14193
  const name = typeof body["name"] === "string" ? body["name"].trim() : "";
@@ -14118,7 +14316,7 @@ function createChannelWriteRouter() {
14118
14316
  // src/dashboard/skills-routes-host.ts
14119
14317
  import { existsSync as existsSync20, statSync as statSync4 } from "fs";
14120
14318
  import { dirname as dirname7 } from "path";
14121
- import { Hono as Hono37 } from "hono";
14319
+ import { Hono as Hono40 } from "hono";
14122
14320
  function workspaceScope() {
14123
14321
  const claudeConfigDir = profileClaudeConfigDir();
14124
14322
  const cwd = defaultClaudeCwd();
@@ -14224,12 +14422,12 @@ var diskBackend = {
14224
14422
  write: writeSkillAndSync
14225
14423
  };
14226
14424
  function createWorkspaceSkillsRouter() {
14227
- const app = new Hono37();
14425
+ const app = new Hono40();
14228
14426
  mountSkillRoutes(app, "/skills", workspaceRef, diskBackend);
14229
14427
  return app;
14230
14428
  }
14231
14429
  function createChannelSkillsRouter() {
14232
- const app = new Hono37();
14430
+ const app = new Hono40();
14233
14431
  mountSkillRoutes(app, "/:id/skill-files", channelRef, diskBackend);
14234
14432
  return app;
14235
14433
  }
@@ -14361,7 +14559,7 @@ import { randomUUID as randomUUID4 } from "crypto";
14361
14559
  import { chmodSync, existsSync as existsSync22, mkdirSync as mkdirSync9, readFileSync as readFileSync16, writeFileSync as writeFileSync8 } from "fs";
14362
14560
  import { createRequire } from "module";
14363
14561
  import { dirname as dirname8, join as join14 } from "path";
14364
- import { Hono as Hono38 } from "hono";
14562
+ import { Hono as Hono41 } from "hono";
14365
14563
  var SESSION_TTL_MS = 10 * 6e4;
14366
14564
  var URL_WAIT_MS = 3e4;
14367
14565
  var TOKEN_WAIT_MS = 6e4;
@@ -14520,7 +14718,7 @@ function failure2(c, err) {
14520
14718
  return c.json({ error: err.message }, 500);
14521
14719
  }
14522
14720
  function createProviderLoginRouter() {
14523
- const app = new Hono38();
14721
+ const app = new Hono41();
14524
14722
  app.use("*", async (c, next) => {
14525
14723
  const denied = requireAdmin4(c.get("auth"));
14526
14724
  if (denied) return c.json({ error: denied }, 403);
@@ -14564,7 +14762,7 @@ function createProviderLoginRouter() {
14564
14762
  return app;
14565
14763
  }
14566
14764
  async function handleProviderLoginRequest(req) {
14567
- const app = new Hono38();
14765
+ const app = new Hono41();
14568
14766
  app.use("*", async (c, next) => {
14569
14767
  c.set("auth", { role: "admin" });
14570
14768
  await next();
@@ -14719,6 +14917,7 @@ function createHostApiRouter(agent = {}) {
14719
14917
  }
14720
14918
 
14721
14919
  // src/dashboard/agent-bridge-host.ts
14920
+ import { homedir as homedir9 } from "os";
14722
14921
  import { sign as signRaw, timingSafeEqual } from "crypto";
14723
14922
  import { existsSync as existsSync25, readFileSync as readFileSync19 } from "fs";
14724
14923
  import dotenv2 from "dotenv";
@@ -14967,13 +15166,13 @@ function handleSessionImportRequest(req) {
14967
15166
  }
14968
15167
 
14969
15168
  // src/dashboard/docs-relay-host.ts
14970
- import { Hono as Hono39 } from "hono";
15169
+ import { Hono as Hono42 } from "hono";
14971
15170
  var RETURNED_HEADERS = ["content-type", "content-disposition", "content-security-policy", "cache-control"];
14972
15171
  async function handleDocsRequest(req) {
14973
15172
  return runRelayed(req, (app) => app.route("/channels", createDocsRouter({ gate: async (_c, next) => next() })));
14974
15173
  }
14975
15174
  async function runRelayed(req, register) {
14976
- const app = new Hono39();
15175
+ const app = new Hono42();
14977
15176
  app.use("*", async (c, next) => {
14978
15177
  c.set("auth", req.auth);
14979
15178
  await next();
@@ -15156,7 +15355,8 @@ function buildHostConfigSnapshot() {
15156
15355
  env: existsSync25(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync19(paths.CONFIG_FILE, "utf-8")) : {},
15157
15356
  // Only a model someone actually saved: before that it is just the Claude
15158
15357
  // default, which would show the wrong agent in admin for a Codex user.
15159
- agentModel: existsSync25(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
15358
+ agentModel: existsSync25(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0,
15359
+ home: homedir9()
15160
15360
  }));
15161
15361
  }
15162
15362
  return snapshot2;
@@ -15358,7 +15558,7 @@ import { join as join17 } from "path";
15358
15558
  import { serveStatic } from "@hono/node-server/serve-static";
15359
15559
 
15360
15560
  // ../api/src/dashboard/app-icon-routes.ts
15361
- import { Hono as Hono40 } from "hono";
15561
+ import { Hono as Hono43 } from "hono";
15362
15562
  var MANIFEST = {
15363
15563
  id: "/",
15364
15564
  name: "Flyspace",
@@ -15392,7 +15592,7 @@ async function resolvedProfileHost(c) {
15392
15592
  return profileFromHost(trustedHost(c), known);
15393
15593
  }
15394
15594
  function createAppIconRouter() {
15395
- const app = new Hono40();
15595
+ const app = new Hono43();
15396
15596
  app.get("/manifest.json", (c) => c.json(MANIFEST));
15397
15597
  app.get("/icons/app/:profile/:file", async (c) => {
15398
15598
  const profile = c.req.param("profile");
@@ -15978,6 +16178,7 @@ async function runDesktopCmd(args) {
15978
16178
 
15979
16179
  // src/cli.ts
15980
16180
  import { join as join20 } from "path";
16181
+ import { existsSync as existsSync29, readdirSync as readdirSync5 } from "fs";
15981
16182
  var home = flyspaceHome();
15982
16183
  if (home) {
15983
16184
  const bin = join20(home, "bin");
@@ -16036,12 +16237,27 @@ function extractProfileFlag(argv) {
16036
16237
  }
16037
16238
  return { profile, args };
16038
16239
  }
16240
+ function soleNamedProfile() {
16241
+ if (existsSync29(paths.CONFIG_FILE)) return void 0;
16242
+ let names;
16243
+ try {
16244
+ names = readdirSync5(paths.PROFILES_DIR).filter(
16245
+ (n) => existsSync29(join20(paths.PROFILES_DIR, n, "config.env"))
16246
+ );
16247
+ } catch {
16248
+ return void 0;
16249
+ }
16250
+ return names.length === 1 ? names[0] : void 0;
16251
+ }
16039
16252
  async function main() {
16040
16253
  useDirectSupabase();
16041
16254
  useLocalCache();
16042
16255
  const { profile, args } = extractProfileFlag(process.argv.slice(2));
16043
16256
  if (profile) {
16044
16257
  process.env["FLYSPACE_WORKSPACE"] = profile;
16258
+ } else if (!process.env["FLYSPACE_WORKSPACE"]) {
16259
+ const sole = soleNamedProfile();
16260
+ if (sole) process.env["FLYSPACE_WORKSPACE"] = sole;
16045
16261
  }
16046
16262
  getProfile();
16047
16263
  const command = args[0];
@@ -16130,7 +16346,7 @@ async function main() {
16130
16346
  break;
16131
16347
  case "-v":
16132
16348
  case "--version":
16133
- printRaw("0.1.65");
16349
+ printRaw("0.1.66");
16134
16350
  break;
16135
16351
  case "-h":
16136
16352
  case "--help":