flyspace-cli 0.1.47 → 0.1.49
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-F5CXKDZV.js → chunk-HTFQL66T.js} +5 -7
- package/dist/{chunk-ETFEQSMF.js → chunk-PIAF4FJX.js} +1 -1
- package/dist/{chunk-AMA7LCCE.js → chunk-YPKJR5LT.js} +176 -95
- package/dist/cli.js +760 -242
- package/dist/index.js +2 -2
- package/dist/{threads-S4L5QX7T.js → threads-QAVO2Z4L.js} +89 -4
- package/package.json +1 -1
- package/system.capabilities.md +5 -4
package/dist/cli.js
CHANGED
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
disableFeatureFlag,
|
|
53
53
|
displayNameFor,
|
|
54
54
|
docsAccessPromptNote,
|
|
55
|
+
effectiveModel,
|
|
55
56
|
enableFeatureFlag,
|
|
56
57
|
ensureAgentDmChannel,
|
|
57
58
|
ensureGeneralChannel,
|
|
@@ -83,6 +84,7 @@ import {
|
|
|
83
84
|
getWorkspaceBySlug,
|
|
84
85
|
getWorkspaceByStripeCustomerId,
|
|
85
86
|
getWorkspaceGreetedAt,
|
|
87
|
+
getWorkspacePermissionMode,
|
|
86
88
|
getWorkspacePlanStatus,
|
|
87
89
|
installUsageRecording,
|
|
88
90
|
isAllowedModel,
|
|
@@ -94,6 +96,7 @@ import {
|
|
|
94
96
|
isLockedPlan,
|
|
95
97
|
isLogicalCwd,
|
|
96
98
|
isMemoryType,
|
|
99
|
+
isPermissionMode,
|
|
97
100
|
isUnderLogicalRoot,
|
|
98
101
|
isUuid,
|
|
99
102
|
isValidSkillName,
|
|
@@ -144,6 +147,7 @@ import {
|
|
|
144
147
|
resetWorkspaceOnboarding,
|
|
145
148
|
resetWorkspacePrompt,
|
|
146
149
|
resolveChannelId,
|
|
150
|
+
resolveChannelPermissionMode,
|
|
147
151
|
resolveChannelPrompt,
|
|
148
152
|
resolveCwd,
|
|
149
153
|
resolveFeatureFlags,
|
|
@@ -166,6 +170,7 @@ import {
|
|
|
166
170
|
setMemoryAutoPaused,
|
|
167
171
|
setOutputStyleDefault,
|
|
168
172
|
setWorkspaceArchived,
|
|
173
|
+
setWorkspacePermissionMode,
|
|
169
174
|
setWorkspaceStripeSubscription,
|
|
170
175
|
slackConfigured,
|
|
171
176
|
startAutomationRegistryPolling,
|
|
@@ -191,7 +196,7 @@ import {
|
|
|
191
196
|
warnOnBrokenChannelCwds,
|
|
192
197
|
workspaceSkillsDir,
|
|
193
198
|
writeSkillFile
|
|
194
|
-
} from "./chunk-
|
|
199
|
+
} from "./chunk-YPKJR5LT.js";
|
|
195
200
|
import {
|
|
196
201
|
firstReplyBody,
|
|
197
202
|
getThread,
|
|
@@ -199,7 +204,7 @@ import {
|
|
|
199
204
|
listThreads,
|
|
200
205
|
moveThread,
|
|
201
206
|
resolveChannel
|
|
202
|
-
} from "./chunk-
|
|
207
|
+
} from "./chunk-PIAF4FJX.js";
|
|
203
208
|
import {
|
|
204
209
|
AGENT_AUTHOR,
|
|
205
210
|
DEFAULT_PROFILE,
|
|
@@ -224,7 +229,7 @@ import {
|
|
|
224
229
|
sumR2PrefixBytes,
|
|
225
230
|
syncPostToDashboard,
|
|
226
231
|
uploadLocalImages
|
|
227
|
-
} from "./chunk-
|
|
232
|
+
} from "./chunk-HTFQL66T.js";
|
|
228
233
|
|
|
229
234
|
// ../../node_modules/.pnpm/delayed-stream@1.0.0/node_modules/delayed-stream/lib/delayed_stream.js
|
|
230
235
|
var require_delayed_stream = __commonJS({
|
|
@@ -11914,9 +11919,9 @@ var require_axios = __commonJS({
|
|
|
11914
11919
|
var { toString } = Object.prototype;
|
|
11915
11920
|
var { getPrototypeOf } = Object;
|
|
11916
11921
|
var { iterator, toStringTag } = Symbol;
|
|
11917
|
-
var kindOf = /* @__PURE__ */ ((
|
|
11922
|
+
var kindOf = /* @__PURE__ */ ((cache8) => (thing) => {
|
|
11918
11923
|
const str = toString.call(thing);
|
|
11919
|
-
return
|
|
11924
|
+
return cache8[str] || (cache8[str] = str.slice(8, -1).toLowerCase());
|
|
11920
11925
|
})(/* @__PURE__ */ Object.create(null));
|
|
11921
11926
|
var kindOfTest = (type) => {
|
|
11922
11927
|
type = type.toLowerCase();
|
|
@@ -19492,7 +19497,7 @@ async function runAuthCmd(args) {
|
|
|
19492
19497
|
|
|
19493
19498
|
// ../api/src/version.ts
|
|
19494
19499
|
import { readFileSync as readFileSync8 } from "fs";
|
|
19495
|
-
var CLI_VERSION = true ? "0.1.
|
|
19500
|
+
var CLI_VERSION = true ? "0.1.49" : devVersion();
|
|
19496
19501
|
function isOlderVersion(a, b) {
|
|
19497
19502
|
const parse = (v) => v.replace(/^v/, "").split("-")[0].split(".").map(Number);
|
|
19498
19503
|
const [pa, pb] = [parse(a), parse(b)];
|
|
@@ -20120,7 +20125,7 @@ function npmEnv(target) {
|
|
|
20120
20125
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
20121
20126
|
}
|
|
20122
20127
|
async function runUpgrade() {
|
|
20123
|
-
const current = "0.1.
|
|
20128
|
+
const current = "0.1.49";
|
|
20124
20129
|
console.log(`Current version: ${current}`);
|
|
20125
20130
|
console.log("Checking for updates...\n");
|
|
20126
20131
|
try {
|
|
@@ -20899,6 +20904,7 @@ function resolveChannelConfig(channelId) {
|
|
|
20899
20904
|
effort: channel?.effort ?? defaultEffort(),
|
|
20900
20905
|
runtime: channel?.runtime ?? "host",
|
|
20901
20906
|
mounts: channel?.mounts ?? [],
|
|
20907
|
+
permissionMode: resolveChannelPermissionMode(channelId),
|
|
20902
20908
|
prompt: channel?.prompt?.trim() || void 0,
|
|
20903
20909
|
codexModel: profileEnv("CUSTIE_CODEX_MODEL")?.trim() || DEFAULT_CODEX_MODEL,
|
|
20904
20910
|
claudeConfigDir: profileClaudeConfigDir(),
|
|
@@ -21342,11 +21348,67 @@ function clearKnownWorkspacesCache() {
|
|
|
21342
21348
|
warned = false;
|
|
21343
21349
|
}
|
|
21344
21350
|
|
|
21351
|
+
// ../api/src/store/workspace-domain-store.ts
|
|
21352
|
+
async function getWorkspaceDomain(workspaceId) {
|
|
21353
|
+
const { data, error: error2 } = await getSupabaseClient().from("workspace_domains").select("workspace_id, hostname, cf_hostname_id, status, verified_at").eq("workspace_id", workspaceId).maybeSingle();
|
|
21354
|
+
if (error2) throw new Error(`getWorkspaceDomain(${workspaceId}): ${error2.message}`);
|
|
21355
|
+
return data ?? null;
|
|
21356
|
+
}
|
|
21357
|
+
async function insertWorkspaceDomain(row) {
|
|
21358
|
+
const { error: error2 } = await getSupabaseClient().from("workspace_domains").insert(row);
|
|
21359
|
+
if (error2) throw new Error(`insertWorkspaceDomain(${row.hostname}): ${error2.message}`);
|
|
21360
|
+
invalidateCustomDomainCache();
|
|
21361
|
+
}
|
|
21362
|
+
async function updateWorkspaceDomainStatus(workspaceId, status) {
|
|
21363
|
+
const { error: error2 } = await getSupabaseClient().from("workspace_domains").update({ status, ...status === "active" ? { verified_at: (/* @__PURE__ */ new Date()).toISOString() } : {} }).eq("workspace_id", workspaceId);
|
|
21364
|
+
if (error2) throw new Error(`updateWorkspaceDomainStatus(${workspaceId}): ${error2.message}`);
|
|
21365
|
+
invalidateCustomDomainCache();
|
|
21366
|
+
}
|
|
21367
|
+
async function deleteWorkspaceDomain(workspaceId) {
|
|
21368
|
+
const { error: error2 } = await getSupabaseClient().from("workspace_domains").delete().eq("workspace_id", workspaceId);
|
|
21369
|
+
if (error2) throw new Error(`deleteWorkspaceDomain(${workspaceId}): ${error2.message}`);
|
|
21370
|
+
invalidateCustomDomainCache();
|
|
21371
|
+
}
|
|
21372
|
+
var CACHE_TTL_MS = 6e4;
|
|
21373
|
+
var cache3 = null;
|
|
21374
|
+
var refreshing = false;
|
|
21375
|
+
function invalidateCustomDomainCache() {
|
|
21376
|
+
cache3 = null;
|
|
21377
|
+
}
|
|
21378
|
+
async function refreshCustomDomainCache() {
|
|
21379
|
+
if (refreshing) return;
|
|
21380
|
+
refreshing = true;
|
|
21381
|
+
try {
|
|
21382
|
+
const { data, error: error2 } = await getSupabaseClient().from("workspace_domains").select("hostname, workspaces(slug)").eq("status", "active");
|
|
21383
|
+
if (error2) throw new Error(error2.message);
|
|
21384
|
+
const map = /* @__PURE__ */ new Map();
|
|
21385
|
+
for (const row of data ?? []) {
|
|
21386
|
+
if (row.workspaces?.slug) map.set(row.hostname, row.workspaces.slug);
|
|
21387
|
+
}
|
|
21388
|
+
cache3 = { map, fetchedAt: Date.now() };
|
|
21389
|
+
} catch (err) {
|
|
21390
|
+
console.error("[custom-domains] cache refresh failed:", err);
|
|
21391
|
+
} finally {
|
|
21392
|
+
refreshing = false;
|
|
21393
|
+
}
|
|
21394
|
+
}
|
|
21395
|
+
function customDomainSlug(host) {
|
|
21396
|
+
const name = host?.trim().toLowerCase().replace(/:\d+$/, "");
|
|
21397
|
+
if (!name) return null;
|
|
21398
|
+
if ((!cache3 || Date.now() - cache3.fetchedAt > CACHE_TTL_MS) && databaseReachable()) {
|
|
21399
|
+
void refreshCustomDomainCache();
|
|
21400
|
+
}
|
|
21401
|
+
return cache3?.map.get(name) ?? null;
|
|
21402
|
+
}
|
|
21403
|
+
|
|
21345
21404
|
// ../api/src/dashboard/cors.ts
|
|
21346
21405
|
function allowedOrigins() {
|
|
21347
21406
|
return (process.env["DASHBOARD_ALLOWED_ORIGINS"] ?? "").split(",").map((o) => o.trim().replace(/\/+$/, "")).filter(Boolean);
|
|
21348
21407
|
}
|
|
21349
21408
|
function isAllowedOrigin(origin) {
|
|
21409
|
+
if (origin.startsWith("https://") && customDomainSlug(origin.slice("https://".length))) {
|
|
21410
|
+
return true;
|
|
21411
|
+
}
|
|
21350
21412
|
return allowedOrigins().some((entry) => {
|
|
21351
21413
|
if (!entry.includes("://*.")) return entry === origin;
|
|
21352
21414
|
const [scheme, suffix] = entry.split("://*.");
|
|
@@ -21402,6 +21464,8 @@ function subdomainLabel(host) {
|
|
|
21402
21464
|
return label2;
|
|
21403
21465
|
}
|
|
21404
21466
|
function profileFromHost(host, known) {
|
|
21467
|
+
const custom = customDomainSlug(bareHost(host) ?? void 0);
|
|
21468
|
+
if (custom) return known.includes(custom) ? custom : null;
|
|
21405
21469
|
const label2 = subdomainLabel(host);
|
|
21406
21470
|
if (!label2) return null;
|
|
21407
21471
|
const bare = label2.startsWith("api-") ? label2.slice(4) : label2.startsWith("dev-") ? label2.slice(4) : label2;
|
|
@@ -21831,7 +21895,8 @@ async function startWorkspaceTrial(workspace, plan, ownerEmail) {
|
|
|
21831
21895
|
plan,
|
|
21832
21896
|
stripeCustomerId: customer.id,
|
|
21833
21897
|
stripeSubscriptionId: subscription.id,
|
|
21834
|
-
planStatus: "trialing"
|
|
21898
|
+
planStatus: "trialing",
|
|
21899
|
+
trialEndsAt: subscription.trial_end ? new Date(subscription.trial_end * 1e3).toISOString() : null
|
|
21835
21900
|
});
|
|
21836
21901
|
}
|
|
21837
21902
|
|
|
@@ -22406,7 +22471,8 @@ async function handleSubscriptionUpdated(subscription) {
|
|
|
22406
22471
|
if (!workspace) return;
|
|
22407
22472
|
const planStatus = planStatusFor(subscription.status);
|
|
22408
22473
|
if (!planStatus) return;
|
|
22409
|
-
|
|
22474
|
+
const trialEndsAt = subscription.trial_end ? new Date(subscription.trial_end * 1e3).toISOString() : null;
|
|
22475
|
+
await updateWorkspacePlanStatus(workspace.id, planStatus, trialEndsAt);
|
|
22410
22476
|
}
|
|
22411
22477
|
async function handleCardAdded(session) {
|
|
22412
22478
|
if (session.mode !== "setup" || !session.setup_intent || !session.customer) return;
|
|
@@ -23655,6 +23721,33 @@ async function runSlackCmd(args) {
|
|
|
23655
23721
|
}
|
|
23656
23722
|
}
|
|
23657
23723
|
|
|
23724
|
+
// ../core/src/bridge-protocol.ts
|
|
23725
|
+
var HOST_SOCKET_PATH = "/internal/host-socket";
|
|
23726
|
+
var DEFAULT_DATA_API_PORT = 4757;
|
|
23727
|
+
var CALL_TIMEOUT_MS = 15e3;
|
|
23728
|
+
var HEARTBEAT_INTERVAL_MS = 15e3;
|
|
23729
|
+
var HEARTBEAT_TIMEOUT_MS = HEARTBEAT_INTERVAL_MS * 2.5;
|
|
23730
|
+
var LOCAL_RELAY_PATH = "/internal/agent-call";
|
|
23731
|
+
var RELAYED_METHODS = [
|
|
23732
|
+
"onChatMessage",
|
|
23733
|
+
"isAgentThinking",
|
|
23734
|
+
"getAgentActivities",
|
|
23735
|
+
"cancelAgentRun",
|
|
23736
|
+
"regenerateAgentRun",
|
|
23737
|
+
"listAgentRuns",
|
|
23738
|
+
"wakeAgentRun"
|
|
23739
|
+
];
|
|
23740
|
+
function encodeWireMessage(msg) {
|
|
23741
|
+
return JSON.stringify(msg);
|
|
23742
|
+
}
|
|
23743
|
+
function parseWireMessage(raw) {
|
|
23744
|
+
try {
|
|
23745
|
+
return JSON.parse(String(raw));
|
|
23746
|
+
} catch {
|
|
23747
|
+
return null;
|
|
23748
|
+
}
|
|
23749
|
+
}
|
|
23750
|
+
|
|
23658
23751
|
// src/commands/chat.ts
|
|
23659
23752
|
var USAGE4 = `
|
|
23660
23753
|
Usage: flyspace chat <subcommand> [options]
|
|
@@ -23665,6 +23758,8 @@ var USAGE4 = `
|
|
|
23665
23758
|
move <thread-id> --to <channel> Move a thread to another channel
|
|
23666
23759
|
post --channel <c> --text <t> Start a new thread, or reply with --thread
|
|
23667
23760
|
[--thread <id>] [--title <t>]
|
|
23761
|
+
wake --thread <id> --text <t> Post a background task's result AND start a
|
|
23762
|
+
new agent turn on the thread to act on it
|
|
23668
23763
|
|
|
23669
23764
|
Options:
|
|
23670
23765
|
--to <name-or-id> Destination channel for "move"
|
|
@@ -23774,7 +23869,7 @@ async function runPost(args) {
|
|
|
23774
23869
|
);
|
|
23775
23870
|
}
|
|
23776
23871
|
const channelId = threadArg ? void 0 : (await resolveChannel(channelArg, getArg3(args, "--profile-name"))).id;
|
|
23777
|
-
const threadId = await postToDashboardChannel({
|
|
23872
|
+
const { threadId } = await postToDashboardChannel({
|
|
23778
23873
|
channelId,
|
|
23779
23874
|
threadId: threadArg,
|
|
23780
23875
|
text,
|
|
@@ -23782,6 +23877,28 @@ async function runPost(args) {
|
|
|
23782
23877
|
});
|
|
23783
23878
|
console.log(threadArg ? `Replied in thread ${threadId}.` : `Posted new thread ${threadId}.`);
|
|
23784
23879
|
}
|
|
23880
|
+
async function runWake(args) {
|
|
23881
|
+
const threadId = getArg3(args, "--thread");
|
|
23882
|
+
const text = getArg3(args, "--text");
|
|
23883
|
+
if (!threadId || !text) throw new Error("Usage: flyspace chat wake --thread <id> --text <t>");
|
|
23884
|
+
const { replyId } = await postToDashboardChannel({ threadId, text });
|
|
23885
|
+
const endpoint = readHostEndpoint();
|
|
23886
|
+
if (!endpoint) {
|
|
23887
|
+
console.log(`Replied in thread ${threadId}, but no Host is running to wake the agent.`);
|
|
23888
|
+
return;
|
|
23889
|
+
}
|
|
23890
|
+
const res = await fetch(`http://127.0.0.1:${endpoint.port}${LOCAL_RELAY_PATH}`, {
|
|
23891
|
+
method: "POST",
|
|
23892
|
+
headers: { authorization: `Bearer ${endpoint.token}`, "content-type": "application/json" },
|
|
23893
|
+
body: JSON.stringify({ method: "wakeAgentRun", profile: getProfile(), args: [threadId, replyId, text] }),
|
|
23894
|
+
signal: AbortSignal.timeout(3e4)
|
|
23895
|
+
});
|
|
23896
|
+
if (!res.ok) throw new Error(`Replied in thread ${threadId}, but the Host answered ${res.status}`);
|
|
23897
|
+
const { value } = await res.json();
|
|
23898
|
+
console.log(
|
|
23899
|
+
value ? `Replied in thread ${threadId} and woke the agent.` : `Replied in thread ${threadId}; wake refused (too many wakes in a row without a human message).`
|
|
23900
|
+
);
|
|
23901
|
+
}
|
|
23785
23902
|
async function runChatCmd(args) {
|
|
23786
23903
|
loadEnvFiles();
|
|
23787
23904
|
useHostDbWithoutCredentials();
|
|
@@ -23800,6 +23917,9 @@ async function runChatCmd(args) {
|
|
|
23800
23917
|
case "post":
|
|
23801
23918
|
await runPost(rest);
|
|
23802
23919
|
break;
|
|
23920
|
+
case "wake":
|
|
23921
|
+
await runWake(rest);
|
|
23922
|
+
break;
|
|
23803
23923
|
case "-h":
|
|
23804
23924
|
case "--help":
|
|
23805
23925
|
case void 0:
|
|
@@ -24074,7 +24194,7 @@ async function runMcpCmd(args) {
|
|
|
24074
24194
|
loadEnvFiles();
|
|
24075
24195
|
switch (server) {
|
|
24076
24196
|
case "threads": {
|
|
24077
|
-
const { startThreadsServer } = await import("./threads-
|
|
24197
|
+
const { startThreadsServer } = await import("./threads-QAVO2Z4L.js");
|
|
24078
24198
|
await startThreadsServer();
|
|
24079
24199
|
return;
|
|
24080
24200
|
}
|
|
@@ -24262,7 +24382,93 @@ var requireDocsAccess = async (c, next) => {
|
|
|
24262
24382
|
};
|
|
24263
24383
|
|
|
24264
24384
|
// ../api/src/dashboard/api.ts
|
|
24265
|
-
import { Hono as
|
|
24385
|
+
import { Hono as Hono35 } from "hono";
|
|
24386
|
+
|
|
24387
|
+
// ../api/src/dashboard/supabase-server-client.ts
|
|
24388
|
+
import { createServerClient, parseCookieHeader, serializeCookieHeader } from "@supabase/ssr";
|
|
24389
|
+
|
|
24390
|
+
// ../api/src/dashboard/scoped-auth-cookies.ts
|
|
24391
|
+
import { stringFromBase64URL } from "@supabase/ssr";
|
|
24392
|
+
var SESSION_NAME = /^(sb-.+-auth-token)(?:\.\d+)?$/;
|
|
24393
|
+
var SCOPE_MARK = "fsw_";
|
|
24394
|
+
var SCOPE_END = "__";
|
|
24395
|
+
function hostLabel(host) {
|
|
24396
|
+
return host.toLowerCase().replace(/:\d+$/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
24397
|
+
}
|
|
24398
|
+
var scopePrefix = (label2) => `${SCOPE_MARK}${label2}${SCOPE_END}`;
|
|
24399
|
+
function sessionUserId(cookies) {
|
|
24400
|
+
const base = cookies.map((c) => SESSION_NAME.exec(c.name)?.[1]).find(Boolean);
|
|
24401
|
+
if (!base) return null;
|
|
24402
|
+
const whole = cookies.find((c) => c.name === base)?.value;
|
|
24403
|
+
const raw = whole ?? cookies.filter((c) => c.name.startsWith(`${base}.`)).sort((a, b) => Number(a.name.split(".").pop()) - Number(b.name.split(".").pop())).map((c) => c.value).join("");
|
|
24404
|
+
if (!raw) return null;
|
|
24405
|
+
try {
|
|
24406
|
+
const json = raw.startsWith("base64-") ? stringFromBase64URL(raw.slice(7)) : raw;
|
|
24407
|
+
const id = JSON.parse(json).user?.id;
|
|
24408
|
+
return typeof id === "string" ? id : null;
|
|
24409
|
+
} catch {
|
|
24410
|
+
return null;
|
|
24411
|
+
}
|
|
24412
|
+
}
|
|
24413
|
+
var isScoped = (name) => name.startsWith(SCOPE_MARK);
|
|
24414
|
+
function readScopedCookies(all, label2) {
|
|
24415
|
+
const prefix = scopePrefix(label2);
|
|
24416
|
+
const own = all.filter((c) => c.name.startsWith(prefix)).map((c) => ({ name: c.name.slice(prefix.length), value: c.value }));
|
|
24417
|
+
return own.length ? own : all.filter((c) => !isScoped(c.name));
|
|
24418
|
+
}
|
|
24419
|
+
function routeCookieWrites(all, label2, writes) {
|
|
24420
|
+
const prefix = scopePrefix(label2);
|
|
24421
|
+
const hasOwn = all.some((c) => c.name.startsWith(prefix));
|
|
24422
|
+
const incoming = sessionUserId(writes.filter((c) => c.value !== ""));
|
|
24423
|
+
const shared = sessionUserId(all.filter((c) => !isScoped(c.name)));
|
|
24424
|
+
const toScoped = hasOwn || incoming !== null && shared !== null && incoming !== shared;
|
|
24425
|
+
return writes.map(
|
|
24426
|
+
(c) => toScoped ? { name: prefix + c.name, value: c.value, scoped: true } : { ...c, scoped: false }
|
|
24427
|
+
);
|
|
24428
|
+
}
|
|
24429
|
+
|
|
24430
|
+
// ../api/src/dashboard/supabase-server-client.ts
|
|
24431
|
+
var REQUEST_TIMEOUT_MS2 = 5e3;
|
|
24432
|
+
function fetchWithTimeout(input2, init2) {
|
|
24433
|
+
return fetch(input2, { ...init2, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2) });
|
|
24434
|
+
}
|
|
24435
|
+
function createRequestSupabaseClient(c) {
|
|
24436
|
+
const url = process.env["SUPABASE_URL"];
|
|
24437
|
+
const key = process.env["VITE_SUPABASE_PUBLISHABLE_KEY"];
|
|
24438
|
+
if (!url || !key) {
|
|
24439
|
+
throw new Error("SUPABASE_URL / VITE_SUPABASE_PUBLISHABLE_KEY not set \u2014 check .env");
|
|
24440
|
+
}
|
|
24441
|
+
const origin = c.req.header("Origin");
|
|
24442
|
+
const label2 = hostLabel(
|
|
24443
|
+
(origin ? URL.parse(origin)?.host : void 0) ?? c.req.header("X-Forwarded-Host") ?? c.req.header("Host") ?? ""
|
|
24444
|
+
);
|
|
24445
|
+
const rawCookies = () => parseCookieHeader(c.req.header("Cookie") ?? "").map(({ name, value }) => ({
|
|
24446
|
+
name,
|
|
24447
|
+
value: value ?? ""
|
|
24448
|
+
}));
|
|
24449
|
+
return createServerClient(url, key, {
|
|
24450
|
+
global: { fetch: fetchWithTimeout },
|
|
24451
|
+
cookies: {
|
|
24452
|
+
// `parseCookieHeader` types `value` as optional; the client requires a
|
|
24453
|
+
// string, and a valueless cookie is the same as an empty one here.
|
|
24454
|
+
getAll: () => readScopedCookies(rawCookies(), label2),
|
|
24455
|
+
setAll: (cookies) => {
|
|
24456
|
+
const domain = process.env["AUTH_COOKIE_DOMAIN"]?.trim();
|
|
24457
|
+
const overrides = {
|
|
24458
|
+
...domain ? { domain } : {},
|
|
24459
|
+
...crossOriginShell(c) ? { sameSite: "none", secure: true } : {}
|
|
24460
|
+
};
|
|
24461
|
+
const routed = routeCookieWrites(rawCookies(), label2, cookies);
|
|
24462
|
+
cookies.forEach(({ options }, i) => {
|
|
24463
|
+
const { name, value } = routed[i];
|
|
24464
|
+
c.header("Set-Cookie", serializeCookieHeader(name, value, { ...options, ...overrides }), {
|
|
24465
|
+
append: true
|
|
24466
|
+
});
|
|
24467
|
+
});
|
|
24468
|
+
}
|
|
24469
|
+
}
|
|
24470
|
+
});
|
|
24471
|
+
}
|
|
24266
24472
|
|
|
24267
24473
|
// ../api/src/dashboard/public-share-routes.ts
|
|
24268
24474
|
import { existsSync as existsSync17, readFileSync as readFileSync17, statSync as statSync3 } from "fs";
|
|
@@ -24744,7 +24950,7 @@ var LAYOUT = {
|
|
|
24744
24950
|
};
|
|
24745
24951
|
var PLAIN_LOGO = 0.84;
|
|
24746
24952
|
var PLATE_RADIUS = 0.18;
|
|
24747
|
-
var
|
|
24953
|
+
var cache4 = /* @__PURE__ */ new Map();
|
|
24748
24954
|
function decodeLogo(logo) {
|
|
24749
24955
|
if (!logo?.startsWith("data:image/")) return null;
|
|
24750
24956
|
const comma = logo.indexOf(",");
|
|
@@ -24811,12 +25017,12 @@ async function renderAppIcon({
|
|
|
24811
25017
|
plain ? "plain" : "badged",
|
|
24812
25018
|
logo ? createHash2("sha1").update(logo).digest("hex").slice(0, 12) : transparent ? "stock-transparent" : "stock"
|
|
24813
25019
|
].join(":");
|
|
24814
|
-
const hit =
|
|
25020
|
+
const hit = cache4.get(key);
|
|
24815
25021
|
if (hit) return hit;
|
|
24816
25022
|
const out = logo && await composeIcon(logo, size, maskable, plain).catch(() => null) || // No workspace logo to lead with — the stock mark is still the best icon,
|
|
24817
25023
|
// either on its usual dark plate or, for a favicon, trimmed and bare.
|
|
24818
25024
|
(transparent ? await renderBadge(size) : await sharp2(readFileSync16(MARK_FILE)).resize(size, size, { fit: "cover" }).png().toBuffer());
|
|
24819
|
-
|
|
25025
|
+
cache4.set(key, out);
|
|
24820
25026
|
return out;
|
|
24821
25027
|
}
|
|
24822
25028
|
async function composeIcon(logo, size, maskable, plain) {
|
|
@@ -25686,7 +25892,7 @@ function backdrop(input2, hasLogo) {
|
|
|
25686
25892
|
`<svg xmlns="http://www.w3.org/2000/svg" width="${WIDTH}" height="${HEIGHT}"><defs><pattern id="grid" width="56" height="56" patternUnits="userSpaceOnUse"><path d="M56 0H0V56" fill="none" stroke="${gridStroke}" stroke-opacity="0.035" stroke-width="1"/></pattern>` + glowDefs + `</defs><rect width="${WIDTH}" height="${HEIGHT}" fill="${palette.bg}"/><rect width="${WIDTH}" height="${HEIGHT}" fill="url(#grid)"/>` + glowRect + initialChip + nameText + title + description + `<text x="${PAD}" y="${FOOTER_BASELINE}" font-family="${SANS}" font-size="21" fill="${palette.muted}">Powered by Flyspace</text>` + published + `</svg>`
|
|
25687
25893
|
);
|
|
25688
25894
|
}
|
|
25689
|
-
var
|
|
25895
|
+
var cache5 = /* @__PURE__ */ new Map();
|
|
25690
25896
|
var CACHE_MAX = 64;
|
|
25691
25897
|
function cacheKey(input2) {
|
|
25692
25898
|
const parts = [
|
|
@@ -25701,13 +25907,13 @@ function cacheKey(input2) {
|
|
|
25701
25907
|
}
|
|
25702
25908
|
async function renderShareOgImage(input2) {
|
|
25703
25909
|
const key = cacheKey(input2);
|
|
25704
|
-
const hit =
|
|
25910
|
+
const hit = cache5.get(key);
|
|
25705
25911
|
if (hit) return hit;
|
|
25706
25912
|
const chip = input2.workspaceName?.trim() ? await renderLogoChip(decodeLogo(input2.logo)) : null;
|
|
25707
25913
|
const composed = sharp3(backdrop(input2, !!chip));
|
|
25708
25914
|
const out = await (chip ? composed.composite([{ input: chip, left: PAD, top: LOGO_TOP }]) : composed).png({ compressionLevel: 9 }).toBuffer();
|
|
25709
|
-
if (
|
|
25710
|
-
|
|
25915
|
+
if (cache5.size >= CACHE_MAX) cache5.delete(cache5.keys().next().value);
|
|
25916
|
+
cache5.set(key, out);
|
|
25711
25917
|
return out;
|
|
25712
25918
|
}
|
|
25713
25919
|
|
|
@@ -26304,92 +26510,6 @@ function createGuestRouter() {
|
|
|
26304
26510
|
// ../api/src/dashboard/auth-routes.ts
|
|
26305
26511
|
import { Hono as Hono9 } from "hono";
|
|
26306
26512
|
|
|
26307
|
-
// ../api/src/dashboard/supabase-server-client.ts
|
|
26308
|
-
import { createServerClient, parseCookieHeader, serializeCookieHeader } from "@supabase/ssr";
|
|
26309
|
-
|
|
26310
|
-
// ../api/src/dashboard/scoped-auth-cookies.ts
|
|
26311
|
-
import { stringFromBase64URL } from "@supabase/ssr";
|
|
26312
|
-
var SESSION_NAME = /^(sb-.+-auth-token)(?:\.\d+)?$/;
|
|
26313
|
-
var SCOPE_MARK = "fsw_";
|
|
26314
|
-
var SCOPE_END = "__";
|
|
26315
|
-
function hostLabel(host) {
|
|
26316
|
-
return host.toLowerCase().replace(/:\d+$/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
26317
|
-
}
|
|
26318
|
-
var scopePrefix = (label2) => `${SCOPE_MARK}${label2}${SCOPE_END}`;
|
|
26319
|
-
function sessionUserId(cookies) {
|
|
26320
|
-
const base = cookies.map((c) => SESSION_NAME.exec(c.name)?.[1]).find(Boolean);
|
|
26321
|
-
if (!base) return null;
|
|
26322
|
-
const whole = cookies.find((c) => c.name === base)?.value;
|
|
26323
|
-
const raw = whole ?? cookies.filter((c) => c.name.startsWith(`${base}.`)).sort((a, b) => Number(a.name.split(".").pop()) - Number(b.name.split(".").pop())).map((c) => c.value).join("");
|
|
26324
|
-
if (!raw) return null;
|
|
26325
|
-
try {
|
|
26326
|
-
const json = raw.startsWith("base64-") ? stringFromBase64URL(raw.slice(7)) : raw;
|
|
26327
|
-
const id = JSON.parse(json).user?.id;
|
|
26328
|
-
return typeof id === "string" ? id : null;
|
|
26329
|
-
} catch {
|
|
26330
|
-
return null;
|
|
26331
|
-
}
|
|
26332
|
-
}
|
|
26333
|
-
var isScoped = (name) => name.startsWith(SCOPE_MARK);
|
|
26334
|
-
function readScopedCookies(all, label2) {
|
|
26335
|
-
const prefix = scopePrefix(label2);
|
|
26336
|
-
const own = all.filter((c) => c.name.startsWith(prefix)).map((c) => ({ name: c.name.slice(prefix.length), value: c.value }));
|
|
26337
|
-
return own.length ? own : all.filter((c) => !isScoped(c.name));
|
|
26338
|
-
}
|
|
26339
|
-
function routeCookieWrites(all, label2, writes) {
|
|
26340
|
-
const prefix = scopePrefix(label2);
|
|
26341
|
-
const hasOwn = all.some((c) => c.name.startsWith(prefix));
|
|
26342
|
-
const incoming = sessionUserId(writes.filter((c) => c.value !== ""));
|
|
26343
|
-
const shared = sessionUserId(all.filter((c) => !isScoped(c.name)));
|
|
26344
|
-
const toScoped = hasOwn || incoming !== null && shared !== null && incoming !== shared;
|
|
26345
|
-
return writes.map(
|
|
26346
|
-
(c) => toScoped ? { name: prefix + c.name, value: c.value, scoped: true } : { ...c, scoped: false }
|
|
26347
|
-
);
|
|
26348
|
-
}
|
|
26349
|
-
|
|
26350
|
-
// ../api/src/dashboard/supabase-server-client.ts
|
|
26351
|
-
var REQUEST_TIMEOUT_MS2 = 5e3;
|
|
26352
|
-
function fetchWithTimeout(input2, init2) {
|
|
26353
|
-
return fetch(input2, { ...init2, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2) });
|
|
26354
|
-
}
|
|
26355
|
-
function createRequestSupabaseClient(c) {
|
|
26356
|
-
const url = process.env["SUPABASE_URL"];
|
|
26357
|
-
const key = process.env["VITE_SUPABASE_PUBLISHABLE_KEY"];
|
|
26358
|
-
if (!url || !key) {
|
|
26359
|
-
throw new Error("SUPABASE_URL / VITE_SUPABASE_PUBLISHABLE_KEY not set \u2014 check .env");
|
|
26360
|
-
}
|
|
26361
|
-
const origin = c.req.header("Origin");
|
|
26362
|
-
const label2 = hostLabel(
|
|
26363
|
-
(origin ? URL.parse(origin)?.host : void 0) ?? c.req.header("X-Forwarded-Host") ?? c.req.header("Host") ?? ""
|
|
26364
|
-
);
|
|
26365
|
-
const rawCookies = () => parseCookieHeader(c.req.header("Cookie") ?? "").map(({ name, value }) => ({
|
|
26366
|
-
name,
|
|
26367
|
-
value: value ?? ""
|
|
26368
|
-
}));
|
|
26369
|
-
return createServerClient(url, key, {
|
|
26370
|
-
global: { fetch: fetchWithTimeout },
|
|
26371
|
-
cookies: {
|
|
26372
|
-
// `parseCookieHeader` types `value` as optional; the client requires a
|
|
26373
|
-
// string, and a valueless cookie is the same as an empty one here.
|
|
26374
|
-
getAll: () => readScopedCookies(rawCookies(), label2),
|
|
26375
|
-
setAll: (cookies) => {
|
|
26376
|
-
const domain = process.env["AUTH_COOKIE_DOMAIN"]?.trim();
|
|
26377
|
-
const overrides = {
|
|
26378
|
-
...domain ? { domain } : {},
|
|
26379
|
-
...crossOriginShell(c) ? { sameSite: "none", secure: true } : {}
|
|
26380
|
-
};
|
|
26381
|
-
const routed = routeCookieWrites(rawCookies(), label2, cookies);
|
|
26382
|
-
cookies.forEach(({ options }, i) => {
|
|
26383
|
-
const { name, value } = routed[i];
|
|
26384
|
-
c.header("Set-Cookie", serializeCookieHeader(name, value, { ...options, ...overrides }), {
|
|
26385
|
-
append: true
|
|
26386
|
-
});
|
|
26387
|
-
});
|
|
26388
|
-
}
|
|
26389
|
-
}
|
|
26390
|
-
});
|
|
26391
|
-
}
|
|
26392
|
-
|
|
26393
26513
|
// ../api/src/dashboard/auth-context.ts
|
|
26394
26514
|
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
26395
26515
|
import { isAuthApiError, isAuthRetryableFetchError } from "@supabase/supabase-js";
|
|
@@ -26402,7 +26522,7 @@ function onboardingPending(ctx) {
|
|
|
26402
26522
|
return pending2;
|
|
26403
26523
|
}
|
|
26404
26524
|
var inFlight3 = /* @__PURE__ */ new Map();
|
|
26405
|
-
var
|
|
26525
|
+
var CACHE_TTL_MS2 = 3e4;
|
|
26406
26526
|
var resolved = /* @__PURE__ */ new Map();
|
|
26407
26527
|
function invalidateAuthContextCache() {
|
|
26408
26528
|
resolved.clear();
|
|
@@ -26436,7 +26556,7 @@ async function resolveAuthContextCached(c, opts) {
|
|
|
26436
26556
|
const inflight = inFlight3.get(key);
|
|
26437
26557
|
if (inflight) return inflight;
|
|
26438
26558
|
const promise = resolveAuthContextUncached(c).then((value) => {
|
|
26439
|
-
resolved.set(key, { value, expires: Date.now() +
|
|
26559
|
+
resolved.set(key, { value, expires: Date.now() + CACHE_TTL_MS2 });
|
|
26440
26560
|
return value;
|
|
26441
26561
|
}).finally(() => inFlight3.delete(key));
|
|
26442
26562
|
inFlight3.set(key, promise);
|
|
@@ -26499,18 +26619,18 @@ import { GetObjectCommand as GetObjectCommand2 } from "@aws-sdk/client-s3";
|
|
|
26499
26619
|
import { getSignedUrl as getSignedUrl2 } from "@aws-sdk/s3-request-presigner";
|
|
26500
26620
|
var TTL_SECONDS = 24 * 60 * 60;
|
|
26501
26621
|
var REUSE_MS = 20 * 60 * 60 * 1e3;
|
|
26502
|
-
var
|
|
26622
|
+
var cache6 = /* @__PURE__ */ new Map();
|
|
26503
26623
|
async function signAvatarUrl(key) {
|
|
26504
26624
|
const now = Date.now();
|
|
26505
|
-
const hit =
|
|
26625
|
+
const hit = cache6.get(key);
|
|
26506
26626
|
if (hit && now - hit.signedAt < REUSE_MS) return hit.url;
|
|
26507
|
-
for (const [k, v] of
|
|
26627
|
+
for (const [k, v] of cache6) if (now - v.signedAt >= REUSE_MS) cache6.delete(k);
|
|
26508
26628
|
const url = await getSignedUrl2(
|
|
26509
26629
|
getR2Client(),
|
|
26510
26630
|
new GetObjectCommand2({ Bucket: getR2Bucket(), Key: key }),
|
|
26511
26631
|
{ expiresIn: TTL_SECONDS }
|
|
26512
26632
|
);
|
|
26513
|
-
|
|
26633
|
+
cache6.set(key, { url, signedAt: now });
|
|
26514
26634
|
return url;
|
|
26515
26635
|
}
|
|
26516
26636
|
|
|
@@ -26882,32 +27002,6 @@ function createUploadsRouter() {
|
|
|
26882
27002
|
return app;
|
|
26883
27003
|
}
|
|
26884
27004
|
|
|
26885
|
-
// ../core/src/bridge-protocol.ts
|
|
26886
|
-
var HOST_SOCKET_PATH = "/internal/host-socket";
|
|
26887
|
-
var DEFAULT_DATA_API_PORT = 4757;
|
|
26888
|
-
var CALL_TIMEOUT_MS = 15e3;
|
|
26889
|
-
var HEARTBEAT_INTERVAL_MS = 15e3;
|
|
26890
|
-
var HEARTBEAT_TIMEOUT_MS = HEARTBEAT_INTERVAL_MS * 2.5;
|
|
26891
|
-
var LOCAL_RELAY_PATH = "/internal/agent-call";
|
|
26892
|
-
var RELAYED_METHODS = [
|
|
26893
|
-
"onChatMessage",
|
|
26894
|
-
"isAgentThinking",
|
|
26895
|
-
"getAgentActivities",
|
|
26896
|
-
"cancelAgentRun",
|
|
26897
|
-
"regenerateAgentRun",
|
|
26898
|
-
"listAgentRuns"
|
|
26899
|
-
];
|
|
26900
|
-
function encodeWireMessage(msg) {
|
|
26901
|
-
return JSON.stringify(msg);
|
|
26902
|
-
}
|
|
26903
|
-
function parseWireMessage(raw) {
|
|
26904
|
-
try {
|
|
26905
|
-
return JSON.parse(String(raw));
|
|
26906
|
-
} catch {
|
|
26907
|
-
return null;
|
|
26908
|
-
}
|
|
26909
|
-
}
|
|
26910
|
-
|
|
26911
27005
|
// ../api/src/dashboard/slack-format.ts
|
|
26912
27006
|
import { nameToEmoji } from "gemoji";
|
|
26913
27007
|
var SLACK_EMOJI_ALIASES = {
|
|
@@ -28238,14 +28332,19 @@ async function relevantThreadsPage(supabase, handle, channelIds, opts) {
|
|
|
28238
28332
|
import { createHash as createHash8 } from "crypto";
|
|
28239
28333
|
|
|
28240
28334
|
// ../api/src/store/thread-translation-store.ts
|
|
28241
|
-
|
|
28335
|
+
var TABLES = {
|
|
28336
|
+
reply: { table: "thread_reply_translations", idColumn: "reply_id" },
|
|
28337
|
+
title: { table: "thread_title_translations", idColumn: "thread_id" }
|
|
28338
|
+
};
|
|
28339
|
+
async function getThreadTranslations(lang, keys, kind = "reply") {
|
|
28340
|
+
const { table, idColumn } = TABLES[kind];
|
|
28242
28341
|
const found = /* @__PURE__ */ new Map();
|
|
28243
28342
|
if (keys.length === 0) return found;
|
|
28244
|
-
const clauses = keys.map((k) => `and(
|
|
28245
|
-
const { data, error: error2 } = await getSupabaseClient().from(
|
|
28343
|
+
const clauses = keys.map((k) => `and(${idColumn}.eq.${k.replyId},body_hash.eq.${k.bodyHash})`).join(",");
|
|
28344
|
+
const { data, error: error2 } = await getSupabaseClient().from(table).select(`${idColumn}, body, passthrough`).eq("lang", lang).or(clauses);
|
|
28246
28345
|
if (error2) throw new Error(`getThreadTranslations(${lang}): ${error2.message}`);
|
|
28247
28346
|
for (const row of data ?? []) {
|
|
28248
|
-
const replyId = row[
|
|
28347
|
+
const replyId = row[idColumn];
|
|
28249
28348
|
found.set(replyId, {
|
|
28250
28349
|
replyId,
|
|
28251
28350
|
body: row["body"],
|
|
@@ -28254,21 +28353,41 @@ async function getThreadTranslations(lang, keys) {
|
|
|
28254
28353
|
}
|
|
28255
28354
|
return found;
|
|
28256
28355
|
}
|
|
28257
|
-
async function putThreadTranslations(lang, rows) {
|
|
28356
|
+
async function putThreadTranslations(lang, rows, kind = "reply") {
|
|
28258
28357
|
if (rows.length === 0) return;
|
|
28259
|
-
const {
|
|
28358
|
+
const { table, idColumn } = TABLES[kind];
|
|
28359
|
+
const { error: error2 } = await getSupabaseClient().from(table).upsert(
|
|
28260
28360
|
rows.map((r) => ({
|
|
28261
|
-
|
|
28361
|
+
[idColumn]: r.replyId,
|
|
28262
28362
|
lang,
|
|
28263
28363
|
body_hash: r.bodyHash,
|
|
28264
28364
|
body: r.body,
|
|
28265
28365
|
passthrough: r.passthrough
|
|
28266
28366
|
})),
|
|
28267
|
-
{ onConflict:
|
|
28367
|
+
{ onConflict: `${idColumn},lang,body_hash` }
|
|
28268
28368
|
);
|
|
28269
28369
|
if (error2) throw new Error(`putThreadTranslations(${lang}): ${error2.message}`);
|
|
28270
28370
|
}
|
|
28271
28371
|
|
|
28372
|
+
// ../api/src/store/translation-usage-store.ts
|
|
28373
|
+
function today() {
|
|
28374
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
28375
|
+
}
|
|
28376
|
+
async function getTranslationTokensToday(workspaceId) {
|
|
28377
|
+
const { data, error: error2 } = await getSupabaseClient().from("translation_usage").select("tokens").eq("workspace_id", workspaceId).eq("day", today()).maybeSingle();
|
|
28378
|
+
if (error2) throw new Error(`getTranslationTokensToday: ${error2.message}`);
|
|
28379
|
+
return Number(data?.tokens ?? 0);
|
|
28380
|
+
}
|
|
28381
|
+
async function addTranslationTokens(workspaceId, tokens2) {
|
|
28382
|
+
if (tokens2 <= 0) return;
|
|
28383
|
+
const { error: error2 } = await getSupabaseClient().rpc("add_translation_usage", {
|
|
28384
|
+
p_workspace_id: workspaceId,
|
|
28385
|
+
p_day: today(),
|
|
28386
|
+
p_tokens: tokens2
|
|
28387
|
+
});
|
|
28388
|
+
if (error2) throw new Error(`addTranslationTokens: ${error2.message}`);
|
|
28389
|
+
}
|
|
28390
|
+
|
|
28272
28391
|
// ../api/src/dashboard/thread-translate.ts
|
|
28273
28392
|
var GROQ_API_URL6 = "https://api.groq.com/openai/v1/chat/completions";
|
|
28274
28393
|
var TRANSLATION_MODEL2 = "openai/gpt-oss-120b";
|
|
@@ -28277,6 +28396,16 @@ var BATCH_CHAR_BUDGET = 16e3;
|
|
|
28277
28396
|
var CONTEXT_MESSAGES = 4;
|
|
28278
28397
|
var MAX_MESSAGE_CHARS = 12e3;
|
|
28279
28398
|
var MAX_OUTPUT_TOKENS2 = 32768;
|
|
28399
|
+
var DAILY_TOKEN_LIMIT = Number(process.env["TRANSLATION_DAILY_TOKEN_LIMIT"] ?? 2e6);
|
|
28400
|
+
var TranslationLimitError = class extends Error {
|
|
28401
|
+
constructor() {
|
|
28402
|
+
super("daily translation limit reached");
|
|
28403
|
+
}
|
|
28404
|
+
};
|
|
28405
|
+
function glossaryFor(glossary, bodies) {
|
|
28406
|
+
const text = bodies.join("\n").toLowerCase();
|
|
28407
|
+
return glossary.filter((g) => text.includes(g.term.toLowerCase()));
|
|
28408
|
+
}
|
|
28280
28409
|
var BY_CODE2 = new Map(TRANSLATION_LANGUAGES.map((l) => [l.code, l]));
|
|
28281
28410
|
function isTranslatableLanguage2(lang) {
|
|
28282
28411
|
return BY_CODE2.has(lang);
|
|
@@ -28292,6 +28421,7 @@ function systemPrompt2(languageName2) {
|
|
|
28292
28421
|
You receive a JSON object with two keys:
|
|
28293
28422
|
- "context": earlier messages, for reference only. NEVER translate these and never mention them in your output.
|
|
28294
28423
|
- "translate": the messages to translate, each with an "n" and a "body".
|
|
28424
|
+
- "glossary" (optional): terms specific to this group. Follow each entry's "note"; an entry with an empty note is kept exactly as written.
|
|
28295
28425
|
|
|
28296
28426
|
Reply with ONLY a JSON object of this exact shape, one entry per message in "translate", in the same order:
|
|
28297
28427
|
{"messages":[{"n":1,"body":"...","already_target":false}]}
|
|
@@ -28329,14 +28459,18 @@ function batchMessages(messages) {
|
|
|
28329
28459
|
if (current.length > 0) batches.push(current);
|
|
28330
28460
|
return batches;
|
|
28331
28461
|
}
|
|
28332
|
-
async function translateBatch(batch, context, lang) {
|
|
28462
|
+
async function translateBatch(batch, context, lang, scope) {
|
|
28333
28463
|
const language = BY_CODE2.get(lang);
|
|
28334
28464
|
if (!language) throw new Error(`unsupported translation language: ${lang}`);
|
|
28335
28465
|
const apiKey = process.env["GROQ_API_KEY"];
|
|
28336
28466
|
if (!apiKey) throw new Error("GROQ_API_KEY is not configured");
|
|
28337
28467
|
const payload = {
|
|
28338
28468
|
context: context.map((m) => ({ author: m.author, body: clip(m.body) })),
|
|
28339
|
-
translate: batch.map((m, i) => ({ n: i + 1, author: m.author, body: clip(m.body) }))
|
|
28469
|
+
translate: batch.map((m, i) => ({ n: i + 1, author: m.author, body: clip(m.body) })),
|
|
28470
|
+
glossary: glossaryFor(
|
|
28471
|
+
scope.glossary,
|
|
28472
|
+
batch.map((m) => m.body)
|
|
28473
|
+
)
|
|
28340
28474
|
};
|
|
28341
28475
|
const res = await fetch(GROQ_API_URL6, {
|
|
28342
28476
|
method: "POST",
|
|
@@ -28354,6 +28488,9 @@ async function translateBatch(batch, context, lang) {
|
|
|
28354
28488
|
});
|
|
28355
28489
|
if (!res.ok) throw new Error(`translation model returned ${res.status}`);
|
|
28356
28490
|
const data = await res.json();
|
|
28491
|
+
await addTranslationTokens(scope.workspaceId, data.usage?.total_tokens ?? 0).catch(
|
|
28492
|
+
(err) => console.error("Translation usage not recorded:", err)
|
|
28493
|
+
);
|
|
28357
28494
|
const choice = data.choices?.[0];
|
|
28358
28495
|
if (choice?.finish_reason === "length") {
|
|
28359
28496
|
throw new Error("the translation ran past the model output limit");
|
|
@@ -28382,52 +28519,121 @@ async function translateBatch(batch, context, lang) {
|
|
|
28382
28519
|
});
|
|
28383
28520
|
}
|
|
28384
28521
|
var inFlight4 = /* @__PURE__ */ new Map();
|
|
28385
|
-
async function
|
|
28522
|
+
async function translateCached(lang, scope, messages, contextFor) {
|
|
28386
28523
|
if (!BY_CODE2.has(lang)) throw new Error(`unsupported translation language: ${lang}`);
|
|
28387
28524
|
if (messages.length === 0) return [];
|
|
28388
|
-
const
|
|
28389
|
-
const
|
|
28525
|
+
const keyed = messages.map((m) => ({ ...m, hash: translationHash2(m.author, m.body) }));
|
|
28526
|
+
const shape = createHash8("sha256").update(keyed.map((m) => `${m.kind}:${m.id}:${m.hash}`).join("\n")).digest("hex");
|
|
28527
|
+
const key = `${lang}:${shape}`;
|
|
28390
28528
|
const running2 = inFlight4.get(key);
|
|
28391
28529
|
if (running2) return running2;
|
|
28392
28530
|
const job = (async () => {
|
|
28393
|
-
const
|
|
28394
|
-
|
|
28395
|
-
|
|
28396
|
-
|
|
28397
|
-
|
|
28398
|
-
|
|
28531
|
+
const kinds = ["reply", "title"];
|
|
28532
|
+
const cachedByKind = new Map(
|
|
28533
|
+
await Promise.all(
|
|
28534
|
+
kinds.map(
|
|
28535
|
+
async (kind) => [
|
|
28536
|
+
kind,
|
|
28537
|
+
await getThreadTranslations(
|
|
28538
|
+
lang,
|
|
28539
|
+
keyed.filter((m) => m.kind === kind).map((m) => ({ replyId: m.id, bodyHash: m.hash })),
|
|
28540
|
+
kind
|
|
28541
|
+
)
|
|
28542
|
+
]
|
|
28543
|
+
)
|
|
28544
|
+
)
|
|
28545
|
+
);
|
|
28546
|
+
const cachedOf = (m) => cachedByKind.get(m.kind)?.get(m.id);
|
|
28547
|
+
const missing = keyed.filter((m) => !cachedOf(m));
|
|
28399
28548
|
const fresh = /* @__PURE__ */ new Map();
|
|
28549
|
+
const freshKey = (m) => `${m.kind}:${m.id}`;
|
|
28400
28550
|
if (missing.length > 0) {
|
|
28401
|
-
|
|
28551
|
+
if (await getTranslationTokensToday(scope.workspaceId) >= DAILY_TOKEN_LIMIT) {
|
|
28552
|
+
throw new TranslationLimitError();
|
|
28553
|
+
}
|
|
28402
28554
|
const batches = batchMessages(missing);
|
|
28403
28555
|
const results = await Promise.all(
|
|
28404
|
-
batches.map((batch) =>
|
|
28405
|
-
const first = index.get(batch[0].id) ?? 0;
|
|
28406
|
-
const context = messages.slice(Math.max(0, first - CONTEXT_MESSAGES), first);
|
|
28407
|
-
return translateBatch(batch, context, lang);
|
|
28408
|
-
})
|
|
28556
|
+
batches.map((batch) => translateBatch(batch, contextFor(batch[0]), lang, scope))
|
|
28409
28557
|
);
|
|
28410
|
-
|
|
28411
|
-
|
|
28412
|
-
|
|
28413
|
-
|
|
28414
|
-
|
|
28415
|
-
|
|
28416
|
-
|
|
28417
|
-
|
|
28418
|
-
|
|
28419
|
-
|
|
28558
|
+
batches.forEach(
|
|
28559
|
+
(batch, b) => batch.forEach((m, i) => fresh.set(freshKey(m), results[b][i]))
|
|
28560
|
+
);
|
|
28561
|
+
await Promise.all(
|
|
28562
|
+
kinds.map(
|
|
28563
|
+
(kind) => putThreadTranslations(
|
|
28564
|
+
lang,
|
|
28565
|
+
missing.filter((m) => m.kind === kind).map((m) => {
|
|
28566
|
+
const r = fresh.get(freshKey(m));
|
|
28567
|
+
return {
|
|
28568
|
+
replyId: m.id,
|
|
28569
|
+
bodyHash: m.hash,
|
|
28570
|
+
body: r.body,
|
|
28571
|
+
passthrough: r.passthrough
|
|
28572
|
+
};
|
|
28573
|
+
}),
|
|
28574
|
+
kind
|
|
28575
|
+
)
|
|
28576
|
+
)
|
|
28420
28577
|
);
|
|
28421
28578
|
}
|
|
28422
|
-
return
|
|
28423
|
-
const hit =
|
|
28579
|
+
return keyed.map((m) => {
|
|
28580
|
+
const hit = cachedOf(m);
|
|
28424
28581
|
if (hit) return { id: m.id, body: hit.body, passthrough: hit.passthrough };
|
|
28425
|
-
return fresh.get(m
|
|
28582
|
+
return fresh.get(freshKey(m)) ?? { id: m.id, body: m.body, passthrough: true };
|
|
28426
28583
|
});
|
|
28427
28584
|
})().finally(() => inFlight4.delete(key));
|
|
28428
28585
|
inFlight4.set(key, job);
|
|
28429
28586
|
return job;
|
|
28430
28587
|
}
|
|
28588
|
+
async function translateThread(lang, scope, messages) {
|
|
28589
|
+
const index = new Map(messages.map((m, i) => [m.id, i]));
|
|
28590
|
+
return translateCached(
|
|
28591
|
+
lang,
|
|
28592
|
+
scope,
|
|
28593
|
+
messages.map((m) => ({ ...m, kind: "reply" })),
|
|
28594
|
+
(first) => {
|
|
28595
|
+
const at = index.get(first.id) ?? 0;
|
|
28596
|
+
return messages.slice(Math.max(0, at - CONTEXT_MESSAGES), at);
|
|
28597
|
+
}
|
|
28598
|
+
);
|
|
28599
|
+
}
|
|
28600
|
+
async function translateTopics(lang, scope, topics) {
|
|
28601
|
+
const sources = [];
|
|
28602
|
+
for (const t of topics) {
|
|
28603
|
+
if (t.title) sources.push({ id: t.threadId, author: t.author, body: t.title, kind: "title" });
|
|
28604
|
+
if (t.opening) sources.push({ ...t.opening, kind: "reply" });
|
|
28605
|
+
}
|
|
28606
|
+
const out = await translateCached(lang, scope, sources, () => []);
|
|
28607
|
+
const byKey = new Map(out.map((r, i) => [`${sources[i].kind}:${r.id}`, r]));
|
|
28608
|
+
const shown = (r) => r && !r.passthrough ? r.body : null;
|
|
28609
|
+
return topics.map((t) => ({
|
|
28610
|
+
id: t.threadId,
|
|
28611
|
+
title: shown(byKey.get(`title:${t.threadId}`)),
|
|
28612
|
+
preview: t.opening ? shown(byKey.get(`reply:${t.opening.id}`)) : null
|
|
28613
|
+
}));
|
|
28614
|
+
}
|
|
28615
|
+
|
|
28616
|
+
// ../api/src/store/channel-glossary-store.ts
|
|
28617
|
+
function toTerms(raw) {
|
|
28618
|
+
if (!Array.isArray(raw)) return [];
|
|
28619
|
+
return raw.flatMap(
|
|
28620
|
+
(t) => t && typeof t.term === "string" && t.term.trim() ? [{ term: t.term.trim(), note: typeof t.note === "string" ? t.note.trim() : "" }] : []
|
|
28621
|
+
);
|
|
28622
|
+
}
|
|
28623
|
+
async function getChannelGlossaries(channelIds) {
|
|
28624
|
+
const found = /* @__PURE__ */ new Map();
|
|
28625
|
+
if (channelIds.length === 0) return found;
|
|
28626
|
+
const { data, error: error2 } = await getSupabaseClient().from("channel_glossary").select("channel_id, terms, scanned_at").in("channel_id", [...new Set(channelIds)]);
|
|
28627
|
+
if (error2) throw new Error(`getChannelGlossaries: ${error2.message}`);
|
|
28628
|
+
for (const row of data ?? []) {
|
|
28629
|
+
found.set(row.channel_id, {
|
|
28630
|
+
channelId: row.channel_id,
|
|
28631
|
+
terms: toTerms(row.terms),
|
|
28632
|
+
scannedAt: row.scanned_at
|
|
28633
|
+
});
|
|
28634
|
+
}
|
|
28635
|
+
return found;
|
|
28636
|
+
}
|
|
28431
28637
|
|
|
28432
28638
|
// ../api/src/dashboard/chat-routes.ts
|
|
28433
28639
|
function isNonEmptyString(v) {
|
|
@@ -28494,6 +28700,7 @@ var THREADS_PAGE_SIZE_MAX = 100;
|
|
|
28494
28700
|
var REPLIES_PAGE_SIZE = 50;
|
|
28495
28701
|
var REPLIES_PAGE_SIZE_MAX = 200;
|
|
28496
28702
|
var TRANSLATABLE_REPLIES_MAX = 400;
|
|
28703
|
+
var TOPICS_TRANSLATION_MAX = 50;
|
|
28497
28704
|
var BOARD_PAGE_SIZE = 50;
|
|
28498
28705
|
var BOARD_PAGE_SIZE_MAX = 100;
|
|
28499
28706
|
function ownChannelIds(c) {
|
|
@@ -28884,13 +29091,56 @@ function createChatRouter(agent = {}) {
|
|
|
28884
29091
|
(r) => ({ id: r.id, author: r.author, body: slackMrkdwnToMarkdown(r.body) })
|
|
28885
29092
|
);
|
|
28886
29093
|
try {
|
|
28887
|
-
|
|
29094
|
+
const glossary = (await getChannelGlossaries([channelId])).get(channelId)?.terms ?? [];
|
|
29095
|
+
const scope = { workspaceId: c.get("auth").workspaceId, glossary };
|
|
29096
|
+
return c.json({ lang, messages: await translateThread(lang, scope, messages) });
|
|
28888
29097
|
} catch (err) {
|
|
29098
|
+
if (err instanceof TranslationLimitError) return c.json({ error: err.message }, 429);
|
|
28889
29099
|
const message = err instanceof Error ? err.message : "translation failed";
|
|
28890
29100
|
console.error(`Thread translation failed (${id} \u2192 ${lang}):`, err);
|
|
28891
29101
|
return c.json({ error: message }, 502);
|
|
28892
29102
|
}
|
|
28893
29103
|
});
|
|
29104
|
+
app.post("/topics/translation/:lang", async (c) => {
|
|
29105
|
+
const lang = canonicalLanguage(c.req.param("lang"));
|
|
29106
|
+
if (!isTranslatableLanguage2(lang)) return c.json({ error: "unsupported language" }, 400);
|
|
29107
|
+
const body = await c.req.json().catch(() => null);
|
|
29108
|
+
const ids = Array.isArray(body?.ids) ? [...new Set(body.ids.filter((v) => typeof v === "string"))] : [];
|
|
29109
|
+
if (ids.length === 0) return c.json({ lang, topics: [] });
|
|
29110
|
+
if (ids.length > TOPICS_TRANSLATION_MAX) return c.json({ error: "too many topics" }, 400);
|
|
29111
|
+
const threads = await getSupabaseClient().from("threads").select("id, channel_id, author, title, auto_title").in("id", ids);
|
|
29112
|
+
if (threads.error) return c.json({ error: threads.error.message }, 500);
|
|
29113
|
+
const visible = await globalChannelMeta(c);
|
|
29114
|
+
const rows = (threads.data ?? []).filter((t) => visible.has(t.channel_id));
|
|
29115
|
+
const openings = await Promise.all(
|
|
29116
|
+
rows.map(
|
|
29117
|
+
(t) => getSupabaseClient().from("thread_replies").select("id, author, body").eq("thread_id", t.id).is("archived_at", null).order("created_at", { ascending: true }).limit(1).maybeSingle()
|
|
29118
|
+
)
|
|
29119
|
+
);
|
|
29120
|
+
try {
|
|
29121
|
+
const glossaries = await getChannelGlossaries(rows.map((t) => t.channel_id));
|
|
29122
|
+
const glossary = [...glossaries.values()].flatMap((g) => g.terms);
|
|
29123
|
+
const topics = await translateTopics(
|
|
29124
|
+
lang,
|
|
29125
|
+
{ workspaceId: c.get("auth").workspaceId, glossary },
|
|
29126
|
+
rows.map((t, i) => {
|
|
29127
|
+
const o = openings[i]?.data;
|
|
29128
|
+
return {
|
|
29129
|
+
threadId: t.id,
|
|
29130
|
+
author: t.author,
|
|
29131
|
+
title: t.title || t.auto_title,
|
|
29132
|
+
// Normalised like the thread view, so this shares its cache rows.
|
|
29133
|
+
opening: o ? { id: o.id, author: o.author, body: slackMrkdwnToMarkdown(o.body) } : null
|
|
29134
|
+
};
|
|
29135
|
+
})
|
|
29136
|
+
);
|
|
29137
|
+
return c.json({ lang, topics });
|
|
29138
|
+
} catch (err) {
|
|
29139
|
+
if (err instanceof TranslationLimitError) return c.json({ error: err.message }, 429);
|
|
29140
|
+
console.error(`Topic translation failed (\u2192 ${lang}):`, err);
|
|
29141
|
+
return c.json({ error: err instanceof Error ? err.message : "translation failed" }, 502);
|
|
29142
|
+
}
|
|
29143
|
+
});
|
|
28894
29144
|
app.patch("/threads/:id/board-status", async (c) => {
|
|
28895
29145
|
const id = c.req.param("id");
|
|
28896
29146
|
const input2 = await c.req.json().catch(() => null);
|
|
@@ -29906,15 +30156,149 @@ function createSearchRouter() {
|
|
|
29906
30156
|
return app;
|
|
29907
30157
|
}
|
|
29908
30158
|
|
|
29909
|
-
// ../api/src/dashboard/
|
|
30159
|
+
// ../api/src/dashboard/domain-routes.ts
|
|
29910
30160
|
import { Hono as Hono17 } from "hono";
|
|
30161
|
+
var FALLBACK_ORIGIN = "custom.flyspace.ai";
|
|
30162
|
+
function isValidCustomHostname(hostname2) {
|
|
30163
|
+
if (hostname2.length > 253 || hostname2.endsWith(".flyspace.ai") || hostname2 === "flyspace.ai") {
|
|
30164
|
+
return false;
|
|
30165
|
+
}
|
|
30166
|
+
const labels = hostname2.split(".");
|
|
30167
|
+
if (labels.length < 2) return false;
|
|
30168
|
+
return labels.every((l) => /^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$/.test(l));
|
|
30169
|
+
}
|
|
30170
|
+
async function cloudflare(method, path, body) {
|
|
30171
|
+
const token = process.env["CLOUDFLARE_SAAS_API_TOKEN"];
|
|
30172
|
+
const zone = process.env["CLOUDFLARE_SAAS_ZONE_ID"];
|
|
30173
|
+
if (!token || !zone) {
|
|
30174
|
+
throw new Error("CLOUDFLARE_SAAS_API_TOKEN / CLOUDFLARE_SAAS_ZONE_ID not set");
|
|
30175
|
+
}
|
|
30176
|
+
const res = await fetch(`https://api.cloudflare.com/client/v4/zones/${zone}/custom_hostnames${path}`, {
|
|
30177
|
+
method,
|
|
30178
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
30179
|
+
...body ? { body: JSON.stringify(body) } : {},
|
|
30180
|
+
signal: AbortSignal.timeout(1e4)
|
|
30181
|
+
});
|
|
30182
|
+
const json = await res.json();
|
|
30183
|
+
if (!json.success) {
|
|
30184
|
+
throw new Error(`Cloudflare ${method} ${path || "/"}: ${json.errors?.[0]?.message ?? res.status}`);
|
|
30185
|
+
}
|
|
30186
|
+
return json.result;
|
|
30187
|
+
}
|
|
30188
|
+
function statusFrom(cf) {
|
|
30189
|
+
if (cf.status === "active" && cf.ssl?.status === "active") return "active";
|
|
30190
|
+
if ((cf.ssl?.validation_errors?.length ?? 0) > 0 || cf.status === "deleted") return "failed";
|
|
30191
|
+
return "pending";
|
|
30192
|
+
}
|
|
30193
|
+
async function syncAuthRedirectAllowlist(hostname2, present) {
|
|
30194
|
+
const token = process.env["SUPABASE_ACCESS_TOKEN"];
|
|
30195
|
+
const ref = URL.parse(process.env["SUPABASE_URL"] ?? "")?.hostname.split(".")[0];
|
|
30196
|
+
if (!token || !ref) {
|
|
30197
|
+
console.warn("[custom-domains] SUPABASE_ACCESS_TOKEN not set; redirect allowlist not updated");
|
|
30198
|
+
return;
|
|
30199
|
+
}
|
|
30200
|
+
try {
|
|
30201
|
+
const base = `https://api.supabase.com/v1/projects/${ref}/config/auth`;
|
|
30202
|
+
const headers = { Authorization: `Bearer ${token}`, "Content-Type": "application/json" };
|
|
30203
|
+
const current = await (await fetch(base, { headers })).json();
|
|
30204
|
+
const entry = `https://${hostname2}/**`;
|
|
30205
|
+
const list = (current.uri_allow_list ?? "").split(",").map((u) => u.trim()).filter(Boolean);
|
|
30206
|
+
const next = present ? [.../* @__PURE__ */ new Set([...list, entry])] : list.filter((u) => u !== entry);
|
|
30207
|
+
if (next.join(",") === list.join(",")) return;
|
|
30208
|
+
const res = await fetch(base, {
|
|
30209
|
+
method: "PATCH",
|
|
30210
|
+
headers,
|
|
30211
|
+
body: JSON.stringify({ uri_allow_list: next.join(",") })
|
|
30212
|
+
});
|
|
30213
|
+
if (!res.ok) throw new Error(`PATCH config/auth: ${res.status}`);
|
|
30214
|
+
} catch (err) {
|
|
30215
|
+
console.error("[custom-domains] redirect allowlist update failed:", err);
|
|
30216
|
+
}
|
|
30217
|
+
}
|
|
30218
|
+
function view(row, dcv) {
|
|
30219
|
+
return {
|
|
30220
|
+
hostname: row.hostname,
|
|
30221
|
+
status: row.status,
|
|
30222
|
+
verifiedAt: row.verified_at,
|
|
30223
|
+
records: [
|
|
30224
|
+
{ type: "CNAME", name: row.hostname, value: FALLBACK_ORIGIN },
|
|
30225
|
+
...dcv.map((r) => ({ type: "TXT", name: r.txt_name, value: r.txt_value }))
|
|
30226
|
+
]
|
|
30227
|
+
};
|
|
30228
|
+
}
|
|
30229
|
+
function createDomainRouter() {
|
|
30230
|
+
const app = new Hono17();
|
|
30231
|
+
app.use("*", async (c, next) => {
|
|
30232
|
+
const auth = c.get("auth");
|
|
30233
|
+
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
30234
|
+
await next();
|
|
30235
|
+
});
|
|
30236
|
+
app.get("/", async (c) => {
|
|
30237
|
+
const auth = c.get("auth");
|
|
30238
|
+
const row = await getWorkspaceDomain(auth.workspaceId);
|
|
30239
|
+
if (!row) return c.json({ domain: null });
|
|
30240
|
+
let dcv = [];
|
|
30241
|
+
if (row.status !== "active") {
|
|
30242
|
+
const cf = await cloudflare("GET", `/${row.cf_hostname_id}`);
|
|
30243
|
+
if (cf) {
|
|
30244
|
+
dcv = cf.ssl?.validation_records ?? [];
|
|
30245
|
+
const status = statusFrom(cf);
|
|
30246
|
+
if (status !== row.status) {
|
|
30247
|
+
await updateWorkspaceDomainStatus(auth.workspaceId, status);
|
|
30248
|
+
row.status = status;
|
|
30249
|
+
if (status === "active") await syncAuthRedirectAllowlist(row.hostname, true);
|
|
30250
|
+
}
|
|
30251
|
+
}
|
|
30252
|
+
}
|
|
30253
|
+
return c.json({ domain: view(row, dcv) });
|
|
30254
|
+
});
|
|
30255
|
+
app.post("/", async (c) => {
|
|
30256
|
+
const auth = c.get("auth");
|
|
30257
|
+
const { hostname: hostname2 } = await c.req.json().catch(() => ({})) ?? {};
|
|
30258
|
+
const name = hostname2?.trim().toLowerCase() ?? "";
|
|
30259
|
+
if (!isValidCustomHostname(name)) return c.json({ error: "not a usable hostname" }, 400);
|
|
30260
|
+
if (await getWorkspaceDomain(auth.workspaceId)) {
|
|
30261
|
+
return c.json({ error: "this workspace already has a domain; remove it first" }, 409);
|
|
30262
|
+
}
|
|
30263
|
+
const cf = await cloudflare("POST", "", { hostname: name, ssl: { method: "txt", type: "dv" } });
|
|
30264
|
+
if (!cf) return c.json({ error: "Cloudflare returned no hostname" }, 502);
|
|
30265
|
+
try {
|
|
30266
|
+
await insertWorkspaceDomain({ workspace_id: auth.workspaceId, hostname: name, cf_hostname_id: cf.id });
|
|
30267
|
+
} catch (err) {
|
|
30268
|
+
await cloudflare("DELETE", `/${cf.id}`).catch(() => {
|
|
30269
|
+
});
|
|
30270
|
+
throw err;
|
|
30271
|
+
}
|
|
30272
|
+
return c.json({
|
|
30273
|
+
domain: view(
|
|
30274
|
+
{ workspace_id: auth.workspaceId, hostname: name, cf_hostname_id: cf.id, status: "pending", verified_at: null },
|
|
30275
|
+
cf.ssl?.validation_records ?? []
|
|
30276
|
+
)
|
|
30277
|
+
});
|
|
30278
|
+
});
|
|
30279
|
+
app.delete("/", async (c) => {
|
|
30280
|
+
const auth = c.get("auth");
|
|
30281
|
+
const row = await getWorkspaceDomain(auth.workspaceId);
|
|
30282
|
+
if (!row) return c.json({ error: "no domain configured" }, 404);
|
|
30283
|
+
await cloudflare("DELETE", `/${row.cf_hostname_id}`).catch((err) => {
|
|
30284
|
+
if (!String(err).includes("not found")) throw err;
|
|
30285
|
+
});
|
|
30286
|
+
await deleteWorkspaceDomain(auth.workspaceId);
|
|
30287
|
+
await syncAuthRedirectAllowlist(row.hostname, false);
|
|
30288
|
+
return c.json({ ok: true });
|
|
30289
|
+
});
|
|
30290
|
+
return app;
|
|
30291
|
+
}
|
|
30292
|
+
|
|
30293
|
+
// ../api/src/dashboard/feature-flags-routes.ts
|
|
30294
|
+
import { Hono as Hono18 } from "hono";
|
|
29911
30295
|
async function isFeatureEnabled(c, flagId) {
|
|
29912
30296
|
const auth = c.get("auth");
|
|
29913
30297
|
const enabled = await listEnabledFeatureFlags(auth.workspaceId);
|
|
29914
30298
|
return resolveFeatureFlags(enabled, isDevHost(c))[flagId];
|
|
29915
30299
|
}
|
|
29916
30300
|
function createFeatureFlagsRouter() {
|
|
29917
|
-
const app = new
|
|
30301
|
+
const app = new Hono18();
|
|
29918
30302
|
app.get("/", async (c) => {
|
|
29919
30303
|
const auth = c.get("auth");
|
|
29920
30304
|
const devHost = isDevHost(c);
|
|
@@ -29940,14 +30324,14 @@ function createFeatureFlagsRouter() {
|
|
|
29940
30324
|
}
|
|
29941
30325
|
|
|
29942
30326
|
// ../api/src/dashboard/transcribe-routes.ts
|
|
29943
|
-
import { Hono as
|
|
30327
|
+
import { Hono as Hono19 } from "hono";
|
|
29944
30328
|
var GROQ_TRANSCRIBE_URL = "https://api.groq.com/openai/v1/audio/transcriptions";
|
|
29945
30329
|
var MODEL = "whisper-large-v3-turbo";
|
|
29946
30330
|
var MAX_AUDIO_BYTES = 5 * 1024 * 1024;
|
|
29947
30331
|
var MAX_PROMPT_CHARS = 400;
|
|
29948
30332
|
var NO_SPEECH_THRESHOLD = 0.6;
|
|
29949
30333
|
function createTranscribeRouter() {
|
|
29950
|
-
const app = new
|
|
30334
|
+
const app = new Hono19();
|
|
29951
30335
|
app.post("/transcribe", async (c) => {
|
|
29952
30336
|
if (!await isFeatureEnabled(c, "dictation"))
|
|
29953
30337
|
return c.json({ error: "feature not enabled" }, 403);
|
|
@@ -29986,7 +30370,7 @@ function createTranscribeRouter() {
|
|
|
29986
30370
|
}
|
|
29987
30371
|
|
|
29988
30372
|
// ../api/src/dashboard/autocomplete-routes.ts
|
|
29989
|
-
import { Hono as
|
|
30373
|
+
import { Hono as Hono20 } from "hono";
|
|
29990
30374
|
var GROQ_API_URL8 = "https://api.groq.com/openai/v1/chat/completions";
|
|
29991
30375
|
var MODEL2 = "openai/gpt-oss-120b";
|
|
29992
30376
|
var MAX_REPLY_CHARS = 4e3;
|
|
@@ -29997,7 +30381,7 @@ Base it on the agent's last reply: answer a question it asked, approve or pick a
|
|
|
29997
30381
|
Keep it short (under 15 words), in the language the user writes in. No greetings, thanks or filler.
|
|
29998
30382
|
Output ONLY the message text, no quotes or explanation. If there is no clear next step, output nothing.`;
|
|
29999
30383
|
function createAutocompleteRouter() {
|
|
30000
|
-
const app = new
|
|
30384
|
+
const app = new Hono20();
|
|
30001
30385
|
app.post("/autocomplete", async (c) => {
|
|
30002
30386
|
if (!await isFeatureEnabled(c, "autocomplete"))
|
|
30003
30387
|
return c.json({ error: "feature not enabled" }, 403);
|
|
@@ -30062,7 +30446,7 @@ ${last.body.slice(-MAX_REPLY_CHARS)}`;
|
|
|
30062
30446
|
|
|
30063
30447
|
// ../api/src/dashboard/avatars-routes.ts
|
|
30064
30448
|
import { createHash as createHash9, randomUUID as randomUUID4 } from "crypto";
|
|
30065
|
-
import { Hono as
|
|
30449
|
+
import { Hono as Hono21 } from "hono";
|
|
30066
30450
|
import sharp5 from "sharp";
|
|
30067
30451
|
import { PutObjectCommand as PutObjectCommand4, DeleteObjectCommand as DeleteObjectCommand3 } from "@aws-sdk/client-s3";
|
|
30068
30452
|
var AVATAR_SIZE = 192;
|
|
@@ -30115,7 +30499,7 @@ function avatarKeyPrefix() {
|
|
|
30115
30499
|
return `${KEY_PREFIX2}/${getProfile()}/`;
|
|
30116
30500
|
}
|
|
30117
30501
|
function createAvatarsRouter() {
|
|
30118
|
-
const app = new
|
|
30502
|
+
const app = new Hono21();
|
|
30119
30503
|
app.get("/avatars/slack", async (c) => {
|
|
30120
30504
|
const ctx = await resolveAuthContext(c);
|
|
30121
30505
|
if (!ctx) return c.json({ error: "not signed in" }, 401);
|
|
@@ -30164,7 +30548,7 @@ function createAvatarsRouter() {
|
|
|
30164
30548
|
}
|
|
30165
30549
|
|
|
30166
30550
|
// ../api/src/dashboard/members-routes.ts
|
|
30167
|
-
import { Hono as
|
|
30551
|
+
import { Hono as Hono22 } from "hono";
|
|
30168
30552
|
function inviteLinkFor(c, token) {
|
|
30169
30553
|
const url = new URL("/auth/invite", callbackUrl(c));
|
|
30170
30554
|
url.searchParams.set("token", token);
|
|
@@ -30172,7 +30556,7 @@ function inviteLinkFor(c, token) {
|
|
|
30172
30556
|
}
|
|
30173
30557
|
var EMAIL_RE2 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
30174
30558
|
function createMembersRouter() {
|
|
30175
|
-
const members = new
|
|
30559
|
+
const members = new Hono22();
|
|
30176
30560
|
members.get("/", async (c) => {
|
|
30177
30561
|
const ctx = await resolveAuthContext(c);
|
|
30178
30562
|
if (ctx?.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
@@ -30395,7 +30779,7 @@ function createMembersRouter() {
|
|
|
30395
30779
|
}
|
|
30396
30780
|
|
|
30397
30781
|
// ../api/src/dashboard/notifications-routes.ts
|
|
30398
|
-
import { Hono as
|
|
30782
|
+
import { Hono as Hono23 } from "hono";
|
|
30399
30783
|
|
|
30400
30784
|
// ../api/src/store/notification-store.ts
|
|
30401
30785
|
function rowToNotification(row) {
|
|
@@ -30463,7 +30847,7 @@ async function markAllRead(channelIds, userId) {
|
|
|
30463
30847
|
|
|
30464
30848
|
// ../api/src/dashboard/notifications-routes.ts
|
|
30465
30849
|
function createNotificationsRouter() {
|
|
30466
|
-
const notifications = new
|
|
30850
|
+
const notifications = new Hono23();
|
|
30467
30851
|
notifications.get("/", async (c) => {
|
|
30468
30852
|
const auth = c.get("auth");
|
|
30469
30853
|
const channelIds = getProfileChannelRegistry().filter((ch) => canSeeChannel(ch, auth)).map((ch) => ch.id);
|
|
@@ -30490,7 +30874,7 @@ function createNotificationsRouter() {
|
|
|
30490
30874
|
return notifications;
|
|
30491
30875
|
}
|
|
30492
30876
|
function createThreadReadRouter() {
|
|
30493
|
-
const threads = new
|
|
30877
|
+
const threads = new Hono23();
|
|
30494
30878
|
threads.post("/threads/:threadId/read", async (c) => {
|
|
30495
30879
|
const { userId } = c.get("auth");
|
|
30496
30880
|
const threadId = c.req.param("threadId");
|
|
@@ -30502,7 +30886,7 @@ function createThreadReadRouter() {
|
|
|
30502
30886
|
}
|
|
30503
30887
|
|
|
30504
30888
|
// ../api/src/dashboard/push-routes.ts
|
|
30505
|
-
import { Hono as
|
|
30889
|
+
import { Hono as Hono24 } from "hono";
|
|
30506
30890
|
|
|
30507
30891
|
// ../api/src/push/send.ts
|
|
30508
30892
|
import webpush from "web-push";
|
|
@@ -30605,7 +30989,7 @@ async function pushToUser(userId, payload) {
|
|
|
30605
30989
|
|
|
30606
30990
|
// ../api/src/dashboard/push-routes.ts
|
|
30607
30991
|
function createPushRouter() {
|
|
30608
|
-
const push = new
|
|
30992
|
+
const push = new Hono24();
|
|
30609
30993
|
push.get("/key", (c) => c.json({ publicKey: getVapidPublicKey() }));
|
|
30610
30994
|
push.post("/subscribe", async (c) => {
|
|
30611
30995
|
const { userId } = c.get("auth");
|
|
@@ -30636,7 +31020,7 @@ function createPushRouter() {
|
|
|
30636
31020
|
}
|
|
30637
31021
|
|
|
30638
31022
|
// ../api/src/dashboard/mcp-oauth-routes.ts
|
|
30639
|
-
import { Hono as
|
|
31023
|
+
import { Hono as Hono25 } from "hono";
|
|
30640
31024
|
|
|
30641
31025
|
// ../api/src/mcp/crypto.ts
|
|
30642
31026
|
import { createCipheriv, createDecipheriv, randomBytes as randomBytes7, timingSafeEqual } from "crypto";
|
|
@@ -31151,7 +31535,7 @@ function backToDashboard(c, to, params) {
|
|
|
31151
31535
|
return c.redirect(`${target.pathname}${target.search}`);
|
|
31152
31536
|
}
|
|
31153
31537
|
function createMcpOAuthRouter() {
|
|
31154
|
-
const app = new
|
|
31538
|
+
const app = new Hono25();
|
|
31155
31539
|
app.get("/oauth/:provider/start", async (c) => {
|
|
31156
31540
|
const auth = c.get("auth");
|
|
31157
31541
|
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
@@ -31278,7 +31662,7 @@ function createMcpOAuthRouter() {
|
|
|
31278
31662
|
}
|
|
31279
31663
|
|
|
31280
31664
|
// ../api/src/dashboard/mcp-routes.ts
|
|
31281
|
-
import { Hono as
|
|
31665
|
+
import { Hono as Hono26 } from "hono";
|
|
31282
31666
|
|
|
31283
31667
|
// ../api/src/mcp/transport.ts
|
|
31284
31668
|
var KINDS = ["inherit", "npx", "local", "http", "sse"];
|
|
@@ -31408,7 +31792,7 @@ function bindingsByConnection() {
|
|
|
31408
31792
|
return map;
|
|
31409
31793
|
}
|
|
31410
31794
|
function createMcpRouter() {
|
|
31411
|
-
const app = new
|
|
31795
|
+
const app = new Hono26();
|
|
31412
31796
|
app.get("/providers", async (c) => {
|
|
31413
31797
|
const denied = requireAdmin(c.get("auth"));
|
|
31414
31798
|
if (denied) return c.json({ error: denied }, 403);
|
|
@@ -31824,8 +32208,40 @@ async function buildThreadUsage(threadTs) {
|
|
|
31824
32208
|
}
|
|
31825
32209
|
}
|
|
31826
32210
|
|
|
32211
|
+
// ../api/src/dashboard/permission-routes.ts
|
|
32212
|
+
import { Hono as Hono27 } from "hono";
|
|
32213
|
+
function createPermissionRequestsRouter() {
|
|
32214
|
+
const app = new Hono27();
|
|
32215
|
+
app.post("/:id", async (c) => {
|
|
32216
|
+
const auth = c.get("auth");
|
|
32217
|
+
if (auth.role !== "admin") return c.json({ error: "only an admin can answer this" }, 403);
|
|
32218
|
+
const body = await c.req.json().catch(() => ({}));
|
|
32219
|
+
if (body.decision !== "allow" && body.decision !== "deny") {
|
|
32220
|
+
return c.json({ error: "decision must be 'allow' or 'deny'" }, 400);
|
|
32221
|
+
}
|
|
32222
|
+
const supabase = getSupabaseClient();
|
|
32223
|
+
const { data: request } = await supabase.from("permission_requests").select("channel_id, status, expires_at").eq("id", c.req.param("id")).maybeSingle();
|
|
32224
|
+
const ownChannels = new Set(getProfileChannelRegistry().map((ch) => ch.id));
|
|
32225
|
+
if (!request || !ownChannels.has(request["channel_id"])) {
|
|
32226
|
+
return c.json({ error: "not found" }, 404);
|
|
32227
|
+
}
|
|
32228
|
+
if (request["status"] !== "pending" || Date.parse(request["expires_at"]) < Date.now()) {
|
|
32229
|
+
return c.json({ status: request["status"] === "pending" ? "expired" : request["status"] }, 409);
|
|
32230
|
+
}
|
|
32231
|
+
const { data, error: error2 } = await supabase.from("permission_requests").update({
|
|
32232
|
+
status: body.decision,
|
|
32233
|
+
decided_by: auth.handle,
|
|
32234
|
+
decided_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
32235
|
+
}).eq("id", c.req.param("id")).eq("status", "pending").select("status");
|
|
32236
|
+
if (error2) return c.json({ error: error2.message }, 500);
|
|
32237
|
+
if (!data?.length) return c.json({ error: "already answered" }, 409);
|
|
32238
|
+
return c.json({ status: body.decision });
|
|
32239
|
+
});
|
|
32240
|
+
return app;
|
|
32241
|
+
}
|
|
32242
|
+
|
|
31827
32243
|
// ../api/src/dashboard/channel-greeting.ts
|
|
31828
|
-
import { Hono as
|
|
32244
|
+
import { Hono as Hono28 } from "hono";
|
|
31829
32245
|
function eligible(ch) {
|
|
31830
32246
|
return !!ch && !ch.isDefault && !ch.dmKey && !ch.agentName && !ch.archivedAt;
|
|
31831
32247
|
}
|
|
@@ -31854,7 +32270,7 @@ function introOpening(channelName) {
|
|
|
31854
32270
|
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.`;
|
|
31855
32271
|
}
|
|
31856
32272
|
function createChannelGreetingRouter(agent) {
|
|
31857
|
-
const app = new
|
|
32273
|
+
const app = new Hono28();
|
|
31858
32274
|
app.get("/:id/greeting", async (c) => {
|
|
31859
32275
|
const ctx = await resolveAuthContext(c);
|
|
31860
32276
|
const ch = findChannelById(c.req.param("id"));
|
|
@@ -31912,7 +32328,7 @@ async function ensureIntroThread(ch) {
|
|
|
31912
32328
|
}
|
|
31913
32329
|
|
|
31914
32330
|
// ../api/src/dashboard/channel-suggest.ts
|
|
31915
|
-
import { Hono as
|
|
32331
|
+
import { Hono as Hono29 } from "hono";
|
|
31916
32332
|
var CATEGORY_MAX_CHARS = 16;
|
|
31917
32333
|
var CATEGORY_MAX_ITEMS = 30;
|
|
31918
32334
|
var PROMPT_MAX_CHARS = 4e3;
|
|
@@ -31960,7 +32376,7 @@ function parseSuggestion(field, raw) {
|
|
|
31960
32376
|
return items.length ? items.slice(0, CATEGORY_MAX_ITEMS).join("\n") : null;
|
|
31961
32377
|
}
|
|
31962
32378
|
function createChannelSuggestRouter(agent) {
|
|
31963
|
-
const router = new
|
|
32379
|
+
const router = new Hono29();
|
|
31964
32380
|
router.post("/:id/suggest", async (c) => {
|
|
31965
32381
|
const channel = findChannel(c.req.param("id"));
|
|
31966
32382
|
if (!channel || !canSeeChannel(channel, c.get("auth"))) {
|
|
@@ -31998,7 +32414,7 @@ function createChannelSuggestRouter(agent) {
|
|
|
31998
32414
|
}
|
|
31999
32415
|
|
|
32000
32416
|
// ../api/src/dashboard/channel-members-routes.ts
|
|
32001
|
-
import { Hono as
|
|
32417
|
+
import { Hono as Hono30 } from "hono";
|
|
32002
32418
|
async function isChannelAdmin(ctx, channelId) {
|
|
32003
32419
|
if (ctx.role === "admin") return true;
|
|
32004
32420
|
const membership = await getMembershipByUserId(ctx.workspaceId, ctx.userId);
|
|
@@ -32007,7 +32423,7 @@ async function isChannelAdmin(ctx, channelId) {
|
|
|
32007
32423
|
return members.some((m) => m.membershipId === membership.id && m.role === "channel_admin");
|
|
32008
32424
|
}
|
|
32009
32425
|
function createChannelMembersRouter() {
|
|
32010
|
-
const router = new
|
|
32426
|
+
const router = new Hono30();
|
|
32011
32427
|
router.get("/:id/members", async (c) => {
|
|
32012
32428
|
const ctx = await resolveAuthContext(c);
|
|
32013
32429
|
if (!ctx) return c.json({ error: "workspace access required" }, 403);
|
|
@@ -32077,7 +32493,7 @@ function createChannelMembersRouter() {
|
|
|
32077
32493
|
}
|
|
32078
32494
|
|
|
32079
32495
|
// ../api/src/dashboard/memories-routes.ts
|
|
32080
|
-
import { Hono as
|
|
32496
|
+
import { Hono as Hono31 } from "hono";
|
|
32081
32497
|
async function readPatch(c) {
|
|
32082
32498
|
const body = await c.req.json().catch(() => ({}));
|
|
32083
32499
|
const patch = {};
|
|
@@ -32105,7 +32521,7 @@ var requireAgentMemory = async (c, next) => {
|
|
|
32105
32521
|
await next();
|
|
32106
32522
|
};
|
|
32107
32523
|
function createMemoriesRouter() {
|
|
32108
|
-
const router = new
|
|
32524
|
+
const router = new Hono31();
|
|
32109
32525
|
for (const path of [
|
|
32110
32526
|
"/:id/memories",
|
|
32111
32527
|
"/:id/memories/*",
|
|
@@ -32178,7 +32594,7 @@ function createMemoriesRouter() {
|
|
|
32178
32594
|
return router;
|
|
32179
32595
|
}
|
|
32180
32596
|
function createScopedMemoriesRouter() {
|
|
32181
|
-
const router = new
|
|
32597
|
+
const router = new Hono31();
|
|
32182
32598
|
router.use("*", requireAgentMemory);
|
|
32183
32599
|
const workspace = (c) => ({
|
|
32184
32600
|
scope: "workspace",
|
|
@@ -32238,7 +32654,7 @@ function createScopedMemoriesRouter() {
|
|
|
32238
32654
|
}
|
|
32239
32655
|
|
|
32240
32656
|
// ../api/src/dashboard/session-import-routes.ts
|
|
32241
|
-
import { Hono as
|
|
32657
|
+
import { Hono as Hono32 } from "hono";
|
|
32242
32658
|
var MAX_FOLDERS2 = 20;
|
|
32243
32659
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
32244
32660
|
var IMPORT_RANGES = ["all", "7d", "latest5"];
|
|
@@ -32344,7 +32760,7 @@ async function syncSession(agent, channelId, session, author, existing) {
|
|
|
32344
32760
|
return messages.length;
|
|
32345
32761
|
}
|
|
32346
32762
|
function createSessionImportRouter(agent) {
|
|
32347
|
-
const app = new
|
|
32763
|
+
const app = new Hono32();
|
|
32348
32764
|
const scanFolders = async () => {
|
|
32349
32765
|
const scan = await ask(agent, { op: "scan", slug: getProfile() });
|
|
32350
32766
|
return scan && importableFolders(scan.folders, getProfileChannelRegistry());
|
|
@@ -32622,6 +33038,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32622
33038
|
effort: ch.effort ?? void 0,
|
|
32623
33039
|
prompt: ch.prompt ?? void 0,
|
|
32624
33040
|
topicCategories: ch.topicCategories,
|
|
33041
|
+
permissionMode: ch.permissionMode,
|
|
32625
33042
|
access: ch.access,
|
|
32626
33043
|
visibility: ch.visibility,
|
|
32627
33044
|
memberEmails: ch.memberEmails,
|
|
@@ -32632,7 +33049,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32632
33049
|
}));
|
|
32633
33050
|
return c.json({
|
|
32634
33051
|
channels: list,
|
|
32635
|
-
defaultModel: defaultModel(),
|
|
33052
|
+
defaultModel: effectiveModel(defaultModel(), agent.getHostPinnedModel?.(getProfile()) ?? null),
|
|
32636
33053
|
defaultEffort: defaultEffort() ?? null,
|
|
32637
33054
|
defaultCwd: getProfile()
|
|
32638
33055
|
});
|
|
@@ -32685,7 +33102,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32685
33102
|
});
|
|
32686
33103
|
return c.json({
|
|
32687
33104
|
...auto,
|
|
32688
|
-
defaultModel: defaultModel(),
|
|
33105
|
+
defaultModel: effectiveModel(defaultModel(), agent.getHostPinnedModel?.(getProfile()) ?? null),
|
|
32689
33106
|
schedules: auto.schedules.map((s) => ({
|
|
32690
33107
|
...withRun(s),
|
|
32691
33108
|
channelLabel: s.channel ? channelLabel(s.channel) : "Workspace"
|
|
@@ -32759,6 +33176,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32759
33176
|
});
|
|
32760
33177
|
api.route("/tts", createTtsRouter());
|
|
32761
33178
|
api.route("/feature-flags", createFeatureFlagsRouter());
|
|
33179
|
+
api.route("/domain", createDomainRouter());
|
|
32762
33180
|
api.route("/members", createMembersRouter());
|
|
32763
33181
|
api.route("/notifications", createNotificationsRouter());
|
|
32764
33182
|
api.route("/push", createPushRouter());
|
|
@@ -32777,6 +33195,21 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32777
33195
|
await setAllowGuestAccess(auth.workspaceId, body.allowGuestAccess);
|
|
32778
33196
|
return c.json({ allowGuestAccess: body.allowGuestAccess });
|
|
32779
33197
|
});
|
|
33198
|
+
api.get("/permission-mode", async (c) => {
|
|
33199
|
+
const auth = c.get("auth");
|
|
33200
|
+
return c.json({ permissionMode: await getWorkspacePermissionMode(auth.workspaceId) });
|
|
33201
|
+
});
|
|
33202
|
+
api.put("/permission-mode", async (c) => {
|
|
33203
|
+
const auth = c.get("auth");
|
|
33204
|
+
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
33205
|
+
const body = await c.req.json().catch(() => ({}));
|
|
33206
|
+
if (!isPermissionMode(body.permissionMode)) {
|
|
33207
|
+
return c.json({ error: "permissionMode must be 'bypass' or 'ask'" }, 400);
|
|
33208
|
+
}
|
|
33209
|
+
await setWorkspacePermissionMode(auth.workspaceId, body.permissionMode);
|
|
33210
|
+
return c.json({ permissionMode: body.permissionMode });
|
|
33211
|
+
});
|
|
33212
|
+
api.route("/permission-requests", createPermissionRequestsRouter());
|
|
32780
33213
|
api.route("/mcp", createMcpOAuthRouter());
|
|
32781
33214
|
api.route("/mcp", createMcpRouter());
|
|
32782
33215
|
api.get("/agent-pause", async (c) => {
|
|
@@ -32904,7 +33337,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
32904
33337
|
// ../api/src/dashboard/device-auth-routes.ts
|
|
32905
33338
|
import { verify } from "crypto";
|
|
32906
33339
|
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
32907
|
-
import { Hono as
|
|
33340
|
+
import { Hono as Hono33 } from "hono";
|
|
32908
33341
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
32909
33342
|
function cleanText(value, max) {
|
|
32910
33343
|
if (typeof value !== "string") return null;
|
|
@@ -32952,7 +33385,7 @@ async function boundWorkspaceIds(publicKey, userId) {
|
|
|
32952
33385
|
return new Set(existing ? (await listDeviceWorkspaces(existing)).map((w) => w.id) : []);
|
|
32953
33386
|
}
|
|
32954
33387
|
function createDeviceAuthRouter() {
|
|
32955
|
-
const app = new
|
|
33388
|
+
const app = new Hono33();
|
|
32956
33389
|
app.post("/code", async (c) => {
|
|
32957
33390
|
const body = await readBody(c);
|
|
32958
33391
|
const publicKey = typeof body["public_key"] === "string" ? body["public_key"] : "";
|
|
@@ -33271,7 +33704,7 @@ var workspaceRef = () => ({ kind: "workspace" });
|
|
|
33271
33704
|
var channelRef = (c) => ({ kind: "channel", channelId: c.req.param("id") });
|
|
33272
33705
|
|
|
33273
33706
|
// ../api/src/dashboard/output-styles-routes.ts
|
|
33274
|
-
import { Hono as
|
|
33707
|
+
import { Hono as Hono34 } from "hono";
|
|
33275
33708
|
function requireAdmin3(auth) {
|
|
33276
33709
|
return auth?.role === "admin" ? null : "admin access required";
|
|
33277
33710
|
}
|
|
@@ -33291,7 +33724,7 @@ function failure(c, err) {
|
|
|
33291
33724
|
return c.json({ error: message }, err instanceof OutputStyleConflictError ? 409 : 500);
|
|
33292
33725
|
}
|
|
33293
33726
|
function createOutputStylesRouter() {
|
|
33294
|
-
const app = new
|
|
33727
|
+
const app = new Hono34();
|
|
33295
33728
|
app.get("/", (c) => {
|
|
33296
33729
|
const auth = c.get("auth");
|
|
33297
33730
|
const denied = requireAdmin3(auth);
|
|
@@ -33383,7 +33816,7 @@ function createOutputStylesRouter() {
|
|
|
33383
33816
|
return app;
|
|
33384
33817
|
}
|
|
33385
33818
|
async function handleOutputStylesRequest(req) {
|
|
33386
|
-
const app = new
|
|
33819
|
+
const app = new Hono34();
|
|
33387
33820
|
app.use("*", async (c, next) => {
|
|
33388
33821
|
c.set("auth", { role: "admin" });
|
|
33389
33822
|
await next();
|
|
@@ -33403,8 +33836,25 @@ async function handleOutputStylesRequest(req) {
|
|
|
33403
33836
|
import { streamSSE } from "hono/streaming";
|
|
33404
33837
|
|
|
33405
33838
|
// ../api/src/dashboard/api.ts
|
|
33839
|
+
async function viewerProfile(c, known) {
|
|
33840
|
+
if (!c.req.header("Cookie")) return null;
|
|
33841
|
+
const {
|
|
33842
|
+
data: { user }
|
|
33843
|
+
} = await createRequestSupabaseClient(c).auth.getUser().catch(() => ({ data: { user: null } }));
|
|
33844
|
+
if (!user?.email) return null;
|
|
33845
|
+
const [memberships, workspaces] = await Promise.all([
|
|
33846
|
+
listMembershipsByEmail(user.email),
|
|
33847
|
+
listWorkspaces()
|
|
33848
|
+
]);
|
|
33849
|
+
const slugById = new Map(workspaces.map((w) => [w.id, w.slug]));
|
|
33850
|
+
for (const m of memberships) {
|
|
33851
|
+
const slug = slugById.get(m.workspaceId);
|
|
33852
|
+
if (slug && known.includes(slug)) return slug;
|
|
33853
|
+
}
|
|
33854
|
+
return null;
|
|
33855
|
+
}
|
|
33406
33856
|
function createGatedRouter(agent, register) {
|
|
33407
|
-
const api = new
|
|
33857
|
+
const api = new Hono35();
|
|
33408
33858
|
api.use("*", async (c, next) => {
|
|
33409
33859
|
const known = await listKnownWorkspaces();
|
|
33410
33860
|
const fromHost = profileFromHost(trustedHost(c), known);
|
|
@@ -33413,7 +33863,9 @@ function createGatedRouter(agent, register) {
|
|
|
33413
33863
|
if (known.includes(requested)) return runWithProfile(requested, () => next());
|
|
33414
33864
|
if (!fromHost) return c.json({ error: `unknown profile: ${requested}` }, 400);
|
|
33415
33865
|
}
|
|
33416
|
-
|
|
33866
|
+
if (fromHost) return runWithProfile(fromHost, () => next());
|
|
33867
|
+
const viewer = await viewerProfile(c, known);
|
|
33868
|
+
return viewer ? runWithProfile(viewer, () => next()) : next();
|
|
33417
33869
|
});
|
|
33418
33870
|
api.route("/auth/device", createDeviceAuthRouter());
|
|
33419
33871
|
api.route("/auth", createAuthRouter());
|
|
@@ -33457,7 +33909,7 @@ import sharp7 from "sharp";
|
|
|
33457
33909
|
|
|
33458
33910
|
// src/dashboard/channels-routes.ts
|
|
33459
33911
|
import { existsSync as existsSync22, mkdirSync as mkdirSync10 } from "fs";
|
|
33460
|
-
import { Hono as
|
|
33912
|
+
import { Hono as Hono36 } from "hono";
|
|
33461
33913
|
function coerceAccess(raw) {
|
|
33462
33914
|
if (raw === "open" || raw === "*" || raw === "all") return raw;
|
|
33463
33915
|
if (Array.isArray(raw) && raw.every((v) => typeof v === "string")) return raw;
|
|
@@ -33469,6 +33921,10 @@ function coerceVisibility(raw) {
|
|
|
33469
33921
|
function coerceRuntime(raw) {
|
|
33470
33922
|
return raw === "host" || raw === "container" || raw === "sandbox" ? raw : void 0;
|
|
33471
33923
|
}
|
|
33924
|
+
function coercePermissionMode(raw) {
|
|
33925
|
+
if (raw === null || raw === "") return null;
|
|
33926
|
+
return isPermissionMode(raw) ? raw : void 0;
|
|
33927
|
+
}
|
|
33472
33928
|
function coerceEffort(raw) {
|
|
33473
33929
|
return typeof raw === "string" && isEffort(raw) ? raw : void 0;
|
|
33474
33930
|
}
|
|
@@ -33517,6 +33973,7 @@ function toResponse3(channel) {
|
|
|
33517
33973
|
memberEmails: channel.memberEmails,
|
|
33518
33974
|
runtime: channel.runtime,
|
|
33519
33975
|
mounts: channel.mounts,
|
|
33976
|
+
permissionMode: channel.permissionMode,
|
|
33520
33977
|
agentName: channel.agentName,
|
|
33521
33978
|
dmKey: channel.dmKey,
|
|
33522
33979
|
isDefault: channel.isDefault,
|
|
@@ -33524,7 +33981,7 @@ function toResponse3(channel) {
|
|
|
33524
33981
|
};
|
|
33525
33982
|
}
|
|
33526
33983
|
function createChannelWriteRouter() {
|
|
33527
|
-
const app = new
|
|
33984
|
+
const app = new Hono36();
|
|
33528
33985
|
app.post("/", async (c) => {
|
|
33529
33986
|
const body = await c.req.json().catch(() => ({}));
|
|
33530
33987
|
const name = typeof body["name"] === "string" ? body["name"].trim() : "";
|
|
@@ -33578,7 +34035,8 @@ function createChannelWriteRouter() {
|
|
|
33578
34035
|
visibility: coerceVisibility(body["visibility"]),
|
|
33579
34036
|
memberEmails: coerceMemberEmails(body["memberEmails"]),
|
|
33580
34037
|
runtime: coerceRuntime(body["runtime"]),
|
|
33581
|
-
mounts: coerceMounts(body["mounts"])
|
|
34038
|
+
mounts: coerceMounts(body["mounts"]),
|
|
34039
|
+
permissionMode: coercePermissionMode(body["permissionMode"])
|
|
33582
34040
|
});
|
|
33583
34041
|
ensureCwdDir(cwd);
|
|
33584
34042
|
dropSessionsIfRuntimeChanged(id, existing.runtime, channel.runtime);
|
|
@@ -33633,6 +34091,7 @@ function createChannelWriteRouter() {
|
|
|
33633
34091
|
if (r) patch.runtime = r;
|
|
33634
34092
|
}
|
|
33635
34093
|
if ("mounts" in body) patch.mounts = coerceMounts(body["mounts"]);
|
|
34094
|
+
if ("permissionMode" in body) patch.permissionMode = coercePermissionMode(body["permissionMode"]);
|
|
33636
34095
|
if (typeof body["archived"] === "boolean") {
|
|
33637
34096
|
patch.archivedAt = body["archived"] ? (/* @__PURE__ */ new Date()).toISOString() : null;
|
|
33638
34097
|
}
|
|
@@ -33667,7 +34126,7 @@ import {
|
|
|
33667
34126
|
} from "fs";
|
|
33668
34127
|
import { Readable } from "stream";
|
|
33669
34128
|
import { basename as basename8, dirname as dirname8, extname, join as join23, relative, resolve as resolve5, sep } from "path";
|
|
33670
|
-
import { Hono as
|
|
34129
|
+
import { Hono as Hono37 } from "hono";
|
|
33671
34130
|
import { streamSSE as streamSSE2 } from "hono/streaming";
|
|
33672
34131
|
|
|
33673
34132
|
// src/dashboard/docs-watcher.ts
|
|
@@ -34154,8 +34613,9 @@ function writeMcpConfigFile(config) {
|
|
|
34154
34613
|
cleanup: () => rmSync6(dir, { recursive: true, force: true })
|
|
34155
34614
|
};
|
|
34156
34615
|
}
|
|
34157
|
-
async function withMcpConfig(profile, connectionIds, fn) {
|
|
34616
|
+
async function withMcpConfig(profile, connectionIds, fn, extraServers = {}) {
|
|
34158
34617
|
const { config, skipped } = await buildMcpConfig(profile, connectionIds);
|
|
34618
|
+
Object.assign(config.mcpServers, extraServers);
|
|
34159
34619
|
if (!Object.keys(config.mcpServers).length && !mcpStrictConfigEnabled()) {
|
|
34160
34620
|
return fn(void 0, skipped);
|
|
34161
34621
|
}
|
|
@@ -34758,6 +35218,8 @@ function guardDocMentions(body, root) {
|
|
|
34758
35218
|
}
|
|
34759
35219
|
|
|
34760
35220
|
// src/dashboard/chat-agent.ts
|
|
35221
|
+
var PERMISSION_SERVER = "flyspace_permission";
|
|
35222
|
+
var PERMISSION_PROMPT_TOOL = `mcp__${PERMISSION_SERVER}__request_permission`;
|
|
34761
35223
|
var CLASSIFIER_CONTEXT_SIZE = 10;
|
|
34762
35224
|
var DEFAULT_SESSION_COMPACT_THRESHOLD_TOKENS = 14e4;
|
|
34763
35225
|
var DEFAULT_RECENT_VERBATIM_TOKENS = 2e4;
|
|
@@ -34800,6 +35262,7 @@ function loadChatAgentConfig() {
|
|
|
34800
35262
|
};
|
|
34801
35263
|
}
|
|
34802
35264
|
var RETRY_DELAY_MS = 3e3;
|
|
35265
|
+
var MAX_CONSECUTIVE_WAKES = 5;
|
|
34803
35266
|
var MISSED_MESSAGE_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
34804
35267
|
var MISSED_MESSAGE_THREAD_LIMIT = 100;
|
|
34805
35268
|
var delay = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -34862,6 +35325,10 @@ var ChatAgent = class {
|
|
|
34862
35325
|
* never re-runs a message that is queued, in flight, or was deliberately
|
|
34863
35326
|
* left unanswered by the ambient classifier. */
|
|
34864
35327
|
seenReplies = /* @__PURE__ */ new Set();
|
|
35328
|
+
/** threadId → wakes since the last human message. Capped at
|
|
35329
|
+
* `MAX_CONSECUTIVE_WAKES` so a woken turn that launches another background
|
|
35330
|
+
* job (which wakes it again, and so on) can't loop forever unattended. */
|
|
35331
|
+
consecutiveWakes = /* @__PURE__ */ new Map();
|
|
34865
35332
|
/** Workspace roots (workspaces.root_path) for path-prefix stripping in
|
|
34866
35333
|
* activity labels. Fetched once per process — roots change ~never, and a
|
|
34867
35334
|
* restart picks up edits. */
|
|
@@ -34899,6 +35366,7 @@ var ChatAgent = class {
|
|
|
34899
35366
|
handleMessage(msg) {
|
|
34900
35367
|
if (msg.author === AGENT_AUTHOR) return;
|
|
34901
35368
|
this.seenReplies.add(msg.replyId);
|
|
35369
|
+
if (!msg.resumed && !msg.woken) this.consecutiveWakes.delete(msg.threadId);
|
|
34902
35370
|
this.queue.enqueue(msg.threadId, () => this.maybeRun(msg));
|
|
34903
35371
|
void this.maybeSupersede(msg);
|
|
34904
35372
|
}
|
|
@@ -34933,6 +35401,30 @@ var ChatAgent = class {
|
|
|
34933
35401
|
this.supersedingReplies.add(msg.replyId);
|
|
34934
35402
|
run5.abort.abort();
|
|
34935
35403
|
}
|
|
35404
|
+
/**
|
|
35405
|
+
* A background task the agent launched in an earlier turn has finished and
|
|
35406
|
+
* reported back via `flyspace chat wake` (its result is already posted as
|
|
35407
|
+
* reply `replyId`). Each turn is a one-shot CLI process, so nothing else is
|
|
35408
|
+
* left to notice the task ending: this queues a new turn on the thread,
|
|
35409
|
+
* which resumes the same session with the result as its prompt. Goes
|
|
35410
|
+
* through the per-thread queue like any message, so it waits for an
|
|
35411
|
+
* in-flight run instead of racing it. Returns false when refused: the
|
|
35412
|
+
* consecutive-wake cap was hit, or no human ever spoke in the thread.
|
|
35413
|
+
*/
|
|
35414
|
+
async wake(threadId, replyId, text) {
|
|
35415
|
+
const wakes = this.consecutiveWakes.get(threadId) ?? 0;
|
|
35416
|
+
if (wakes >= MAX_CONSECUTIVE_WAKES) {
|
|
35417
|
+
console.log(`[chat-agent] wake refused, cap of ${MAX_CONSECUTIVE_WAKES} reached. thread=${threadId}`);
|
|
35418
|
+
return false;
|
|
35419
|
+
}
|
|
35420
|
+
const { data } = await this.supabase().from("thread_replies").select("author").eq("thread_id", threadId).is("archived_at", null).order("created_at", { ascending: false }).limit(50);
|
|
35421
|
+
const asker = (data ?? []).find((r) => isHumanAuthor(r.author));
|
|
35422
|
+
if (!asker) return false;
|
|
35423
|
+
this.consecutiveWakes.set(threadId, wakes + 1);
|
|
35424
|
+
console.log(`[chat-agent] woken by background task. thread=${threadId}`);
|
|
35425
|
+
this.handleMessage({ threadId, replyId, author: asker.author, body: text, woken: true });
|
|
35426
|
+
return true;
|
|
35427
|
+
}
|
|
34936
35428
|
/**
|
|
34937
35429
|
* Picks up messages nobody answered. `handleMessage` is fire-and-forget and
|
|
34938
35430
|
* every bit of run state lives in this process, so a message is silently
|
|
@@ -35007,7 +35499,7 @@ var ChatAgent = class {
|
|
|
35007
35499
|
async maybeRun(msg) {
|
|
35008
35500
|
const superseding = this.supersedingReplies.delete(msg.replyId);
|
|
35009
35501
|
if (await this.isPausedForThread(msg.threadId)) return;
|
|
35010
|
-
if (superseding || msg.resumed) {
|
|
35502
|
+
if (superseding || msg.resumed || msg.woken) {
|
|
35011
35503
|
await this.run(msg);
|
|
35012
35504
|
return;
|
|
35013
35505
|
}
|
|
@@ -35314,6 +35806,10 @@ var ChatAgent = class {
|
|
|
35314
35806
|
...isHumanAuthor(msg.author) ? { senderHandle: msg.author } : {}
|
|
35315
35807
|
});
|
|
35316
35808
|
if (memory.enabled) channelConfig = { ...channelConfig, disableAutoMemory: true };
|
|
35809
|
+
channelConfig = {
|
|
35810
|
+
...channelConfig,
|
|
35811
|
+
permissionThread: { threadId: msg.threadId, channelId: thread.channel_id }
|
|
35812
|
+
};
|
|
35317
35813
|
if (memory.memoryPrompt) channelConfig = { ...channelConfig, memoryPrompt: memory.memoryPrompt };
|
|
35318
35814
|
const store = this.openSessionStore();
|
|
35319
35815
|
try {
|
|
@@ -35335,6 +35831,9 @@ var ChatAgent = class {
|
|
|
35335
35831
|
const body = msg.resumed ? `[note: nobody sent a new message. The agent process restarted after your last reply in this thread, quoted below, which left work unfinished. Anything you had running or meant to do next may have died with it. Check what actually got done (a background job may also still be running, or have finished), then complete what is left and report the result. If there turns out to be nothing left to do, say so in one line. Do not promise another follow-up, and do not apologise for the gap.]
|
|
35336
35832
|
|
|
35337
35833
|
[your last reply]
|
|
35834
|
+
${msg.body}` : msg.woken ? `[background task finished]
|
|
35835
|
+
[note: nobody sent a new message. A background task you launched earlier in this thread has finished and reported the result below (it is already posted in the thread, so do not repeat it). Carry on with whatever was meant to happen next, then report. If nothing is left to do, say so in one line.]
|
|
35836
|
+
|
|
35338
35837
|
${msg.body}` : msg.body;
|
|
35339
35838
|
const barePrompt = header + interruptionNote + recoveryNote + body + buildFilesPromptSection(attachments);
|
|
35340
35839
|
let resumableSessionId = session?.runner === activeRunner ? session.sessionId : void 0;
|
|
@@ -35704,6 +36203,16 @@ ${msg.body}` : msg.body;
|
|
|
35704
36203
|
async tryAsk(channelConfig, prompt, sessionId, onActivity, signal, usageContext) {
|
|
35705
36204
|
const name = subAgentName(channelConfig.agentName);
|
|
35706
36205
|
const agentPersona = name ? readAgentPersona(channelConfig.claudeConfigDir, channelConfig.cwd, name) : void 0;
|
|
36206
|
+
const permissionServer = channelConfig.permissionMode === "ask" && channelConfig.runtime === "host" && channelConfig.permissionThread ? {
|
|
36207
|
+
[PERMISSION_SERVER]: {
|
|
36208
|
+
command: "flyspace",
|
|
36209
|
+
args: ["mcp", "threads"],
|
|
36210
|
+
env: {
|
|
36211
|
+
FLYSPACE_PERMISSION_THREAD_ID: channelConfig.permissionThread.threadId,
|
|
36212
|
+
FLYSPACE_PERMISSION_CHANNEL_ID: channelConfig.permissionThread.channelId
|
|
36213
|
+
}
|
|
36214
|
+
}
|
|
36215
|
+
} : void 0;
|
|
35707
36216
|
try {
|
|
35708
36217
|
return await withMcpConfig(
|
|
35709
36218
|
channelConfig.profile,
|
|
@@ -35717,6 +36226,8 @@ ${msg.body}` : msg.body;
|
|
|
35717
36226
|
effort: channelConfig.effort,
|
|
35718
36227
|
runtime: channelConfig.runtime,
|
|
35719
36228
|
mounts: channelConfig.mounts,
|
|
36229
|
+
permissionMode: channelConfig.permissionMode,
|
|
36230
|
+
...permissionServer ? { permissionPromptTool: PERMISSION_PROMPT_TOOL } : {},
|
|
35720
36231
|
maxBudgetUsd: this.config.maxBudgetUsd,
|
|
35721
36232
|
agentPersona,
|
|
35722
36233
|
channelPrompt: channelConfig.prompt,
|
|
@@ -35732,7 +36243,8 @@ ${msg.body}` : msg.body;
|
|
|
35732
36243
|
channelConfig.claudeConfigDir,
|
|
35733
36244
|
sessionId,
|
|
35734
36245
|
channelConfig.claudeCodeOauthToken
|
|
35735
|
-
)
|
|
36246
|
+
),
|
|
36247
|
+
permissionServer ?? {}
|
|
35736
36248
|
);
|
|
35737
36249
|
} catch (err) {
|
|
35738
36250
|
console.error("[chat-agent] ask failed:", err.message);
|
|
@@ -36050,14 +36562,14 @@ async function exportDocAsArtifact(channelId, docPath) {
|
|
|
36050
36562
|
if (!abs) throw new Error(`doc not found: ${docPath}`);
|
|
36051
36563
|
const content = readFileSync21(abs, "utf8");
|
|
36052
36564
|
const title = extractTitle(abs, "md");
|
|
36053
|
-
const
|
|
36565
|
+
const today2 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
36054
36566
|
const prompt = `Publish the document at \`${docPath}\` (already read below) as a Claude Artifact, then record the result as a stub file under this channel's \`docs/artifacts/\` folder (create the folder if it doesn't exist).
|
|
36055
36567
|
|
|
36056
|
-
Follow the exact stub convention already used elsewhere in this workspace: filename \`YYYY-MM-<topic-slug>.md\` (today is ${
|
|
36568
|
+
Follow the exact stub convention already used elsewhere in this workspace: filename \`YYYY-MM-<topic-slug>.md\` (today is ${today2}), containing the creation date, a short topic line, and the published artifact URL near the top, e.g.:
|
|
36057
36569
|
|
|
36058
36570
|
# ${title}
|
|
36059
36571
|
|
|
36060
|
-
\u5EFA\u7ACB\u65E5\u671F\uFF1A${
|
|
36572
|
+
\u5EFA\u7ACB\u65E5\u671F\uFF1A${today2}
|
|
36061
36573
|
\u4E3B\u984C\uFF1A<one-line topic in the doc's own language>
|
|
36062
36574
|
\u7DDA\u4E0A\u7248\uFF1A<the artifact URL>
|
|
36063
36575
|
|
|
@@ -36607,7 +37119,7 @@ function deleteDocEntry(root, path) {
|
|
|
36607
37119
|
};
|
|
36608
37120
|
}
|
|
36609
37121
|
function createDocsRouter({ gate = requireDocsAccess } = {}) {
|
|
36610
|
-
const app = new
|
|
37122
|
+
const app = new Hono37();
|
|
36611
37123
|
app.use("/:id/docs", gate);
|
|
36612
37124
|
app.use("/:id/docs/*", gate);
|
|
36613
37125
|
app.get("/:id/docs", (c) => {
|
|
@@ -36945,7 +37457,7 @@ function withDocLinkBridge(html) {
|
|
|
36945
37457
|
// src/dashboard/skills-routes-host.ts
|
|
36946
37458
|
import { existsSync as existsSync28, statSync as statSync7 } from "fs";
|
|
36947
37459
|
import { dirname as dirname9 } from "path";
|
|
36948
|
-
import { Hono as
|
|
37460
|
+
import { Hono as Hono38 } from "hono";
|
|
36949
37461
|
function workspaceScope() {
|
|
36950
37462
|
const claudeConfigDir = profileClaudeConfigDir();
|
|
36951
37463
|
const cwd = defaultClaudeCwd();
|
|
@@ -37051,12 +37563,12 @@ var diskBackend = {
|
|
|
37051
37563
|
write: writeSkillAndSync
|
|
37052
37564
|
};
|
|
37053
37565
|
function createWorkspaceSkillsRouter() {
|
|
37054
|
-
const app = new
|
|
37566
|
+
const app = new Hono38();
|
|
37055
37567
|
mountSkillRoutes(app, "/skills", workspaceRef, diskBackend);
|
|
37056
37568
|
return app;
|
|
37057
37569
|
}
|
|
37058
37570
|
function createChannelSkillsRouter() {
|
|
37059
|
-
const app = new
|
|
37571
|
+
const app = new Hono38();
|
|
37060
37572
|
mountSkillRoutes(app, "/:id/skill-files", channelRef, diskBackend);
|
|
37061
37573
|
return app;
|
|
37062
37574
|
}
|
|
@@ -37096,9 +37608,9 @@ var PROVIDER_LABELS = {
|
|
|
37096
37608
|
codex: "Codex"
|
|
37097
37609
|
};
|
|
37098
37610
|
var TTL_MS2 = 6e4;
|
|
37099
|
-
var
|
|
37611
|
+
var cache7 = /* @__PURE__ */ new Map();
|
|
37100
37612
|
function clearProviderStatusCache() {
|
|
37101
|
-
|
|
37613
|
+
cache7.clear();
|
|
37102
37614
|
}
|
|
37103
37615
|
function binaryOnPath(bin) {
|
|
37104
37616
|
try {
|
|
@@ -37176,11 +37688,11 @@ function withAuthFailure(status) {
|
|
|
37176
37688
|
}
|
|
37177
37689
|
function providerStatuses() {
|
|
37178
37690
|
const key = getProfile();
|
|
37179
|
-
const hit =
|
|
37691
|
+
const hit = cache7.get(key);
|
|
37180
37692
|
let statuses = hit && Date.now() - hit.at < TTL_MS2 ? hit.statuses : void 0;
|
|
37181
37693
|
if (!statuses) {
|
|
37182
37694
|
statuses = ["claude", "codex"].map(probe2);
|
|
37183
|
-
|
|
37695
|
+
cache7.set(key, { at: Date.now(), statuses });
|
|
37184
37696
|
}
|
|
37185
37697
|
return statuses.map((st) => st.runner === "claude" && st.connected ? withAuthFailure(st) : st);
|
|
37186
37698
|
}
|
|
@@ -37191,7 +37703,7 @@ import { randomUUID as randomUUID5 } from "crypto";
|
|
|
37191
37703
|
import { chmodSync, existsSync as existsSync30, mkdirSync as mkdirSync12, readFileSync as readFileSync24, writeFileSync as writeFileSync12 } from "fs";
|
|
37192
37704
|
import { createRequire } from "module";
|
|
37193
37705
|
import { dirname as dirname10, join as join25 } from "path";
|
|
37194
|
-
import { Hono as
|
|
37706
|
+
import { Hono as Hono39 } from "hono";
|
|
37195
37707
|
var SESSION_TTL_MS = 10 * 6e4;
|
|
37196
37708
|
var URL_WAIT_MS = 3e4;
|
|
37197
37709
|
var TOKEN_WAIT_MS = 6e4;
|
|
@@ -37348,7 +37860,7 @@ function failure2(c, err) {
|
|
|
37348
37860
|
return c.json({ error: err.message }, 500);
|
|
37349
37861
|
}
|
|
37350
37862
|
function createProviderLoginRouter() {
|
|
37351
|
-
const app = new
|
|
37863
|
+
const app = new Hono39();
|
|
37352
37864
|
app.use("*", async (c, next) => {
|
|
37353
37865
|
const denied = requireAdmin4(c.get("auth"));
|
|
37354
37866
|
if (denied) return c.json({ error: denied }, 403);
|
|
@@ -37392,7 +37904,7 @@ function createProviderLoginRouter() {
|
|
|
37392
37904
|
return app;
|
|
37393
37905
|
}
|
|
37394
37906
|
async function handleProviderLoginRequest(req) {
|
|
37395
|
-
const app = new
|
|
37907
|
+
const app = new Hono39();
|
|
37396
37908
|
app.use("*", async (c, next) => {
|
|
37397
37909
|
c.set("auth", { role: "admin" });
|
|
37398
37910
|
await next();
|
|
@@ -37784,13 +38296,13 @@ function handleSessionImportRequest(req) {
|
|
|
37784
38296
|
}
|
|
37785
38297
|
|
|
37786
38298
|
// src/dashboard/docs-relay-host.ts
|
|
37787
|
-
import { Hono as
|
|
38299
|
+
import { Hono as Hono40 } from "hono";
|
|
37788
38300
|
var RETURNED_HEADERS = ["content-type", "content-disposition", "content-security-policy", "cache-control"];
|
|
37789
38301
|
async function handleDocsRequest(req) {
|
|
37790
38302
|
return runRelayed(req, (app) => app.route("/channels", createDocsRouter({ gate: async (_c, next) => next() })));
|
|
37791
38303
|
}
|
|
37792
38304
|
async function runRelayed(req, register) {
|
|
37793
|
-
const app = new
|
|
38305
|
+
const app = new Hono40();
|
|
37794
38306
|
app.use("*", async (c, next) => {
|
|
37795
38307
|
c.set("auth", req.auth);
|
|
37796
38308
|
await next();
|
|
@@ -38159,6 +38671,7 @@ function localAgentCallbacks(chatAgent) {
|
|
|
38159
38671
|
cancelAgentRun: (threadId) => chatAgent.cancel(threadId),
|
|
38160
38672
|
regenerateAgentRun: (threadId, stoppedReplyId) => chatAgent.regenerate(threadId, stoppedReplyId),
|
|
38161
38673
|
listAgentRuns: () => chatAgent.runningThreadIds(),
|
|
38674
|
+
wakeAgentRun: (threadId, replyId, text) => chatAgent.wake(threadId, replyId, text),
|
|
38162
38675
|
completeMemoryExtraction: (req) => chatAgent.completeMemoryExtraction(req),
|
|
38163
38676
|
suggestChannelField: (req) => suggestChannelField(req),
|
|
38164
38677
|
listMissingCwds: () => auditChannelCwds().map((ch) => ch.id),
|
|
@@ -38465,8 +38978,8 @@ import { existsSync as existsSync34 } from "fs";
|
|
|
38465
38978
|
import { join as join28 } from "path";
|
|
38466
38979
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
38467
38980
|
|
|
38468
|
-
// src/dashboard/app-icon-routes.ts
|
|
38469
|
-
import { Hono as
|
|
38981
|
+
// ../api/src/dashboard/app-icon-routes.ts
|
|
38982
|
+
import { Hono as Hono41 } from "hono";
|
|
38470
38983
|
var NEUTRAL_MANIFEST = {
|
|
38471
38984
|
id: "/",
|
|
38472
38985
|
name: "Flyspace",
|
|
@@ -38504,7 +39017,7 @@ async function withResolvedProfile2(c, next) {
|
|
|
38504
39017
|
return profile ? runWithProfile(profile, () => next()) : next();
|
|
38505
39018
|
}
|
|
38506
39019
|
function createAppIconRouter() {
|
|
38507
|
-
const app = new
|
|
39020
|
+
const app = new Hono41();
|
|
38508
39021
|
app.get("/manifest.json", withResolvedProfile2, async (c) => {
|
|
38509
39022
|
if (!await resolvedProfileHost(c)) return c.json(NEUTRAL_MANIFEST);
|
|
38510
39023
|
const profile = getProfile();
|
|
@@ -38858,6 +39371,11 @@ async function provisionChannels(specs) {
|
|
|
38858
39371
|
console.log(` channel "${spec.name}" exists`);
|
|
38859
39372
|
continue;
|
|
38860
39373
|
}
|
|
39374
|
+
if (spec.name === "general") {
|
|
39375
|
+
await ensureGeneralChannel();
|
|
39376
|
+
console.log(' channel "general" created (default)');
|
|
39377
|
+
continue;
|
|
39378
|
+
}
|
|
38861
39379
|
const cwd = expandPath(spec.cwd);
|
|
38862
39380
|
if (!existsSync36(cwd)) {
|
|
38863
39381
|
mkdirSync14(cwd, { recursive: true });
|
|
@@ -39078,7 +39596,7 @@ async function main() {
|
|
|
39078
39596
|
break;
|
|
39079
39597
|
case "-v":
|
|
39080
39598
|
case "--version":
|
|
39081
|
-
printRaw("0.1.
|
|
39599
|
+
printRaw("0.1.49");
|
|
39082
39600
|
break;
|
|
39083
39601
|
case "-h":
|
|
39084
39602
|
case "--help":
|