flyspace-cli 0.1.51 → 0.1.53
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-R5RECXRP.js → chunk-GX5467VC.js} +942 -851
- package/dist/cli.js +715 -144
- package/dist/index.js +1 -1
- package/package.json +2 -1
- package/system.capabilities.md +7 -36
- package/system.default.md +3 -3
- package/system.slack.md +28 -0
package/dist/cli.js
CHANGED
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
bodyTextFor,
|
|
36
36
|
buildAuthorizeUrl,
|
|
37
37
|
buildAutoTitle,
|
|
38
|
-
buildManifest,
|
|
39
38
|
cachedProfileConfig,
|
|
40
39
|
canSeeChannel,
|
|
41
40
|
canonicalLanguage,
|
|
@@ -86,6 +85,7 @@ import {
|
|
|
86
85
|
escalateToHuman,
|
|
87
86
|
exchangeCode,
|
|
88
87
|
expandPath,
|
|
88
|
+
explainCost,
|
|
89
89
|
extractCategories,
|
|
90
90
|
extractTitle,
|
|
91
91
|
filterReadableDocsChannels,
|
|
@@ -208,9 +208,11 @@ import {
|
|
|
208
208
|
resolveCwd,
|
|
209
209
|
resolveDocPath,
|
|
210
210
|
resolveDocsAccess,
|
|
211
|
+
resolveRateCard,
|
|
211
212
|
resolveRawPath,
|
|
212
213
|
resolveUserId,
|
|
213
214
|
revokeDocShare,
|
|
215
|
+
rowToMemory,
|
|
214
216
|
runAutomation,
|
|
215
217
|
runScriptAutomation,
|
|
216
218
|
runnerForModel,
|
|
@@ -275,7 +277,7 @@ import {
|
|
|
275
277
|
workspaceHostname,
|
|
276
278
|
workspaceSkillsDir,
|
|
277
279
|
writeSkillFile
|
|
278
|
-
} from "./chunk-
|
|
280
|
+
} from "./chunk-GX5467VC.js";
|
|
279
281
|
import {
|
|
280
282
|
firstReplyBody,
|
|
281
283
|
getThread,
|
|
@@ -1387,12 +1389,12 @@ function assertLinkable(target) {
|
|
|
1387
1389
|
}
|
|
1388
1390
|
if (denied.some((d) => target === d || target.startsWith(`${d}/`))) throw new Error(`cannot link ${target}`);
|
|
1389
1391
|
}
|
|
1390
|
-
function linkProjectFolders(slug,
|
|
1392
|
+
function linkProjectFolders(slug, items2) {
|
|
1391
1393
|
if (!SLUG_RE.test(slug)) throw new Error(`invalid workspace slug: ${slug}`);
|
|
1392
1394
|
const dir = join6(flyspaceRoot(), slug);
|
|
1393
1395
|
mkdirSync4(dir, { recursive: true });
|
|
1394
1396
|
const results = [];
|
|
1395
|
-
for (const item of
|
|
1397
|
+
for (const item of items2) {
|
|
1396
1398
|
if (!SLUG_RE.test(item.name)) throw new Error(`invalid channel name: ${item.name}`);
|
|
1397
1399
|
const dest = join6(dir, item.name);
|
|
1398
1400
|
let exists = true;
|
|
@@ -2152,8 +2154,8 @@ async function runUninstall(args = []) {
|
|
|
2152
2154
|
if (backup) {
|
|
2153
2155
|
const dir = join9(homedir4(), "Flyspace", ".uninstall-backups");
|
|
2154
2156
|
mkdirSync6(dir, { recursive: true });
|
|
2155
|
-
const
|
|
2156
|
-
backupFile = join9(dir, `flyspace-${
|
|
2157
|
+
const stamp2 = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
2158
|
+
backupFile = join9(dir, `flyspace-${stamp2}.tar.gz`);
|
|
2157
2159
|
const rel = backupSources.map((s) => `"${s.replace(/^\//, "")}"`).join(" ");
|
|
2158
2160
|
try {
|
|
2159
2161
|
run2(`tar -czf "${backupFile}" -C / ${rel}`);
|
|
@@ -2345,7 +2347,7 @@ function npmEnv(target) {
|
|
|
2345
2347
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
2346
2348
|
}
|
|
2347
2349
|
async function runUpgrade() {
|
|
2348
|
-
const current = "0.1.
|
|
2350
|
+
const current = "0.1.53";
|
|
2349
2351
|
console.log(`Current version: ${current}`);
|
|
2350
2352
|
console.log("Checking for updates...\n");
|
|
2351
2353
|
try {
|
|
@@ -5767,6 +5769,7 @@ var USAGE4 = `
|
|
|
5767
5769
|
[--thread <id>] [--title <t>]
|
|
5768
5770
|
wake --thread <id> --text <t> Post a background task's result AND start a
|
|
5769
5771
|
new agent turn on the thread to act on it
|
|
5772
|
+
[--about <t>] What the job waits for (shown in the thread)
|
|
5770
5773
|
|
|
5771
5774
|
Options:
|
|
5772
5775
|
--to <name-or-id> Destination channel for "move"
|
|
@@ -6216,7 +6219,7 @@ async function runMcpCmd(args) {
|
|
|
6216
6219
|
import { spawn as spawn6, spawnSync } from "child_process";
|
|
6217
6220
|
import { existsSync as existsSync28 } from "fs";
|
|
6218
6221
|
import { platform as platform7 } from "os";
|
|
6219
|
-
import { join as
|
|
6222
|
+
import { join as join20 } from "path";
|
|
6220
6223
|
|
|
6221
6224
|
// src/reconcile.ts
|
|
6222
6225
|
import { existsSync as existsSync15, mkdirSync as mkdirSync7, writeFileSync as writeFileSync7 } from "fs";
|
|
@@ -6282,7 +6285,7 @@ async function ensureServices() {
|
|
|
6282
6285
|
}
|
|
6283
6286
|
|
|
6284
6287
|
// ../api/src/dashboard/api.ts
|
|
6285
|
-
import { Hono as
|
|
6288
|
+
import { Hono as Hono35 } from "hono";
|
|
6286
6289
|
|
|
6287
6290
|
// ../api/src/dashboard/supabase-server-client.ts
|
|
6288
6291
|
import { createServerClient, parseCookieHeader, serializeCookieHeader } from "@supabase/ssr";
|
|
@@ -7064,9 +7067,9 @@ function createOnboardingRouter(agent) {
|
|
|
7064
7067
|
if (unknown) return c.json({ error: "folder was not offered by the scan" }, 400);
|
|
7065
7068
|
const taken = new Set(getProfileChannelRegistry().map((ch) => ch.name));
|
|
7066
7069
|
taken.add("general");
|
|
7067
|
-
const
|
|
7068
|
-
for (const path of folders)
|
|
7069
|
-
const linked = await agent.linkProjectFolders?.(getProfile(),
|
|
7070
|
+
const items2 = [{ name: "general" }];
|
|
7071
|
+
for (const path of folders) items2.push({ name: uniqueChannelName(offered.get(path).name, taken), path });
|
|
7072
|
+
const linked = await agent.linkProjectFolders?.(getProfile(), items2);
|
|
7070
7073
|
if (!linked) return hostUnavailable(c, agent, "linkProjectFolders");
|
|
7071
7074
|
if (runner === "claude" || runner === "codex") {
|
|
7072
7075
|
await agent.saveLocalDashboardSettings?.({ providers: [{ runner }] });
|
|
@@ -7632,6 +7635,10 @@ function createAdminRouter() {
|
|
|
7632
7635
|
// ../api/src/dashboard/agent-identities.ts
|
|
7633
7636
|
var BOT_LABEL = "Workspace Agent";
|
|
7634
7637
|
var BOT_DM_KEY = "claude";
|
|
7638
|
+
async function agentViewer(c) {
|
|
7639
|
+
const ctx = await resolveAuthContext(c);
|
|
7640
|
+
return ctx?.userId && ctx.email ? { userId: ctx.userId, email: ctx.email } : null;
|
|
7641
|
+
}
|
|
7635
7642
|
|
|
7636
7643
|
// ../api/src/dashboard/data-api.ts
|
|
7637
7644
|
import { existsSync as existsSync18 } from "fs";
|
|
@@ -7767,7 +7774,7 @@ function createCategoryWriteRouter() {
|
|
|
7767
7774
|
}
|
|
7768
7775
|
|
|
7769
7776
|
// ../api/src/dashboard/chat-routes.ts
|
|
7770
|
-
import { Hono as
|
|
7777
|
+
import { Hono as Hono13 } from "hono";
|
|
7771
7778
|
|
|
7772
7779
|
// ../api/src/dashboard/fork-summary.ts
|
|
7773
7780
|
var MAX_INPUT_CHARS = 6e4;
|
|
@@ -7811,6 +7818,188 @@ async function relevantThreadsPage(supabase, handle, channelIds, opts) {
|
|
|
7811
7818
|
return data ?? [];
|
|
7812
7819
|
}
|
|
7813
7820
|
|
|
7821
|
+
// ../api/src/dashboard/continuous-chat.ts
|
|
7822
|
+
import { Hono as Hono12 } from "hono";
|
|
7823
|
+
var GROQ_API_URL2 = "https://api.groq.com/openai/v1/chat/completions";
|
|
7824
|
+
var MODEL = "openai/gpt-oss-120b";
|
|
7825
|
+
var STREAM_DAYS = 30;
|
|
7826
|
+
var STREAM_LIMIT = 500;
|
|
7827
|
+
var ACTIVE_TOPIC_DAYS = 7;
|
|
7828
|
+
var BACKFILL_PER_REQUEST = 5;
|
|
7829
|
+
var UNSORTED = "unsorted";
|
|
7830
|
+
var isDmChannel = (ch) => !!(ch.dmKey || ch.agentName);
|
|
7831
|
+
var channelKeys = (ch) => ch.externalChannelId ? [ch.id, ch.externalChannelId] : [ch.id];
|
|
7832
|
+
function findChannel2(c, channelId) {
|
|
7833
|
+
return getProfileChannelRegistry().find(
|
|
7834
|
+
(ch) => (ch.id === channelId || ch.externalChannelId === channelId) && canSeeChannel(ch, c.get("auth"))
|
|
7835
|
+
);
|
|
7836
|
+
}
|
|
7837
|
+
function isShortAck(body) {
|
|
7838
|
+
const text = body.trim();
|
|
7839
|
+
return [...text].length <= 12 && !/[??]/.test(text);
|
|
7840
|
+
}
|
|
7841
|
+
var RULES = `You file one chat message from a personal assistant DM under a topic, so the user can later find everything about one subject together.
|
|
7842
|
+
You get the topics active in the last few days and the message (with a little preceding context).
|
|
7843
|
+
Pick the existing topic it belongs to, or name a NEW topic (2 to 5 words, in the language the user writes in, no punctuation) when it clearly starts a new subject.
|
|
7844
|
+
When you are not confident, answer unsorted.
|
|
7845
|
+
Output ONLY the topic name, or unsorted. No quotes, no explanation.`;
|
|
7846
|
+
async function askModel(apiKey, topics, examples, context, body) {
|
|
7847
|
+
const prompt = [
|
|
7848
|
+
`Active topics:
|
|
7849
|
+
${topics.length ? topics.map((t) => `- ${t}`).join("\n") : "(none yet)"}`,
|
|
7850
|
+
examples.length ? `Corrections the user made earlier (message -> topic):
|
|
7851
|
+
${examples.map((e) => `- ${e.body.slice(0, 160)} -> ${e.topic}`).join("\n")}` : "",
|
|
7852
|
+
context ? `Preceding messages:
|
|
7853
|
+
${context}` : "",
|
|
7854
|
+
`Message to file:
|
|
7855
|
+
${body.slice(0, 1500)}`
|
|
7856
|
+
].filter(Boolean).join("\n\n");
|
|
7857
|
+
const res = await fetch(GROQ_API_URL2, {
|
|
7858
|
+
method: "POST",
|
|
7859
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
7860
|
+
signal: AbortSignal.timeout(1e4),
|
|
7861
|
+
body: JSON.stringify({
|
|
7862
|
+
model: MODEL,
|
|
7863
|
+
max_completion_tokens: 300,
|
|
7864
|
+
reasoning_effort: "low",
|
|
7865
|
+
include_reasoning: false,
|
|
7866
|
+
temperature: 0,
|
|
7867
|
+
messages: [
|
|
7868
|
+
{ role: "system", content: RULES },
|
|
7869
|
+
{ role: "user", content: prompt }
|
|
7870
|
+
]
|
|
7871
|
+
})
|
|
7872
|
+
}).catch(() => null);
|
|
7873
|
+
if (!res?.ok) return null;
|
|
7874
|
+
const data = await res.json();
|
|
7875
|
+
const raw = (data.choices?.[0]?.message?.content ?? "").split("\n")[0].trim();
|
|
7876
|
+
const topic = raw.replace(/^["'「『]+|["'」』.。]+$/g, "").trim().slice(0, 60);
|
|
7877
|
+
if (!topic) return null;
|
|
7878
|
+
return topics.find((t) => t.toLowerCase() === topic.toLowerCase()) ?? topic;
|
|
7879
|
+
}
|
|
7880
|
+
async function tagReply(args) {
|
|
7881
|
+
const { channel, replyId, author, body, replyToId } = args;
|
|
7882
|
+
if (!isDmChannel(channel) || !isHumanAuthor(author)) return;
|
|
7883
|
+
const supabase = getSupabaseClient();
|
|
7884
|
+
const keys = channelKeys(channel);
|
|
7885
|
+
const channelKey = channel.id;
|
|
7886
|
+
const save = (topic2, source) => supabase.from("reply_topics").upsert({ reply_id: replyId, channel_id: channelKey, topic: topic2, source }).then(({ error: error2 }) => {
|
|
7887
|
+
if (error2) console.error("Reply topic save failed:", error2.message);
|
|
7888
|
+
});
|
|
7889
|
+
if (replyToId) {
|
|
7890
|
+
const { data } = await supabase.from("reply_topics").select("topic").eq("reply_id", replyToId).maybeSingle();
|
|
7891
|
+
if (data?.topic) return save(data.topic, "inherit");
|
|
7892
|
+
}
|
|
7893
|
+
const since2 = new Date(Date.now() - ACTIVE_TOPIC_DAYS * 864e5).toISOString();
|
|
7894
|
+
const { data: recentRows } = await supabase.from("reply_topics").select("reply_id, topic, source, created_at").in("channel_id", keys).gte("created_at", since2).order("created_at", { ascending: false }).limit(200);
|
|
7895
|
+
const recent = (recentRows ?? []).filter((r) => r.reply_id !== replyId);
|
|
7896
|
+
const previous = recent[0]?.topic;
|
|
7897
|
+
if (previous && isShortAck(body)) return save(previous, "inherit");
|
|
7898
|
+
const apiKey = process.env["GROQ_API_KEY"];
|
|
7899
|
+
if (!apiKey) return;
|
|
7900
|
+
const topics = [...new Set(recent.map((r) => r.topic).filter((t) => t !== UNSORTED))].slice(
|
|
7901
|
+
0,
|
|
7902
|
+
15
|
|
7903
|
+
);
|
|
7904
|
+
const manual = recent.filter((r) => r.source === "manual").slice(0, 5);
|
|
7905
|
+
const { data: manualBodies } = manual.length ? await supabase.from("thread_replies").select("id, body").in(
|
|
7906
|
+
"id",
|
|
7907
|
+
manual.map((m) => m.reply_id)
|
|
7908
|
+
) : { data: [] };
|
|
7909
|
+
const bodyOf = new Map(
|
|
7910
|
+
(manualBodies ?? []).map((r) => [r.id, r.body])
|
|
7911
|
+
);
|
|
7912
|
+
const examples = manual.flatMap(
|
|
7913
|
+
(m) => bodyOf.has(m.reply_id) ? [{ body: bodyOf.get(m.reply_id), topic: m.topic }] : []
|
|
7914
|
+
);
|
|
7915
|
+
const { data: ctxRows } = await supabase.from("thread_replies").select("author, body, created_at, threads!inner(channel_id)").in("threads.channel_id", keys).neq("id", replyId).is("archived_at", null).order("created_at", { ascending: false }).limit(3);
|
|
7916
|
+
const context = (ctxRows ?? []).reverse().map((r) => `${r.author}: ${r.body.slice(0, 300)}`).join("\n");
|
|
7917
|
+
const topic = await askModel(apiKey, topics, examples, context, body);
|
|
7918
|
+
if (topic) await save(topic, "model");
|
|
7919
|
+
}
|
|
7920
|
+
function tagStoredReply(c, args) {
|
|
7921
|
+
void (async () => {
|
|
7922
|
+
if (!await isFeatureEnabled(c, "continuous-chat")) return;
|
|
7923
|
+
const { data } = await getSupabaseClient().from("threads").select("channel_id").eq("id", args.threadId).maybeSingle();
|
|
7924
|
+
const channel = data?.channel_id ? findChannel2(c, data.channel_id) : void 0;
|
|
7925
|
+
if (channel) await tagReply({ channel, ...args });
|
|
7926
|
+
})().catch((err) => console.error("Reply topic tagging failed:", err));
|
|
7927
|
+
}
|
|
7928
|
+
var backfilling = /* @__PURE__ */ new Set();
|
|
7929
|
+
function createContinuousChatRouter() {
|
|
7930
|
+
const app = new Hono12();
|
|
7931
|
+
app.get("/channels/:channelId/continuous", async (c) => {
|
|
7932
|
+
if (!await isFeatureEnabled(c, "continuous-chat"))
|
|
7933
|
+
return c.json({ error: "feature not enabled" }, 403);
|
|
7934
|
+
const channel = findChannel2(c, c.req.param("channelId"));
|
|
7935
|
+
if (!channel || !isDmChannel(channel)) return c.json({ error: "not found" }, 404);
|
|
7936
|
+
const supabase = getSupabaseClient();
|
|
7937
|
+
const since2 = new Date(Date.now() - STREAM_DAYS * 864e5).toISOString();
|
|
7938
|
+
const { data: rows, error: error2 } = await supabase.from("thread_replies").select("id, thread_id, author, body, created_at, threads!inner(channel_id)").in("threads.channel_id", channelKeys(channel)).is("archived_at", null).gte("created_at", since2).order("created_at", { ascending: false }).limit(STREAM_LIMIT);
|
|
7939
|
+
if (error2) return c.json({ error: error2.message }, 500);
|
|
7940
|
+
const replies = (rows ?? []).reverse();
|
|
7941
|
+
const { data: tagRows } = replies.length ? await supabase.from("reply_topics").select("reply_id, topic, source, created_at").in(
|
|
7942
|
+
"reply_id",
|
|
7943
|
+
replies.map((r) => r.id)
|
|
7944
|
+
) : { data: [] };
|
|
7945
|
+
const tags = new Map((tagRows ?? []).map((t) => [t.reply_id, t]));
|
|
7946
|
+
const lastInThread = /* @__PURE__ */ new Map();
|
|
7947
|
+
const messages = replies.map((r) => {
|
|
7948
|
+
const tag = tags.get(r.id);
|
|
7949
|
+
const topic = tag?.topic ?? lastInThread.get(r.thread_id) ?? null;
|
|
7950
|
+
if (topic) lastInThread.set(r.thread_id, topic);
|
|
7951
|
+
return {
|
|
7952
|
+
id: r.id,
|
|
7953
|
+
thread_id: r.thread_id,
|
|
7954
|
+
author: r.author,
|
|
7955
|
+
body: slackMrkdwnToMarkdown(r.body),
|
|
7956
|
+
created_at: r.created_at,
|
|
7957
|
+
topic,
|
|
7958
|
+
tagged: !!tag
|
|
7959
|
+
};
|
|
7960
|
+
});
|
|
7961
|
+
const activeSince = Date.now() - ACTIVE_TOPIC_DAYS * 864e5;
|
|
7962
|
+
const pending = replies.filter(
|
|
7963
|
+
(r) => !tags.has(r.id) && isHumanAuthor(r.author) && Date.parse(r.created_at) >= activeSince && !backfilling.has(r.id)
|
|
7964
|
+
).slice(0, BACKFILL_PER_REQUEST);
|
|
7965
|
+
if (pending.length) {
|
|
7966
|
+
for (const r of pending) backfilling.add(r.id);
|
|
7967
|
+
void (async () => {
|
|
7968
|
+
for (const r of pending) {
|
|
7969
|
+
await tagReply({ channel, replyId: r.id, author: r.author, body: r.body }).catch(
|
|
7970
|
+
() => {
|
|
7971
|
+
}
|
|
7972
|
+
);
|
|
7973
|
+
backfilling.delete(r.id);
|
|
7974
|
+
}
|
|
7975
|
+
})();
|
|
7976
|
+
}
|
|
7977
|
+
const activeTopics = [
|
|
7978
|
+
...new Set(
|
|
7979
|
+
messages.filter((m) => m.topic && Date.parse(m.created_at) >= activeSince).map((m) => m.topic)
|
|
7980
|
+
)
|
|
7981
|
+
];
|
|
7982
|
+
return c.json({ messages, topics: activeTopics, pendingTags: pending.length });
|
|
7983
|
+
});
|
|
7984
|
+
app.patch("/replies/:replyId/topic", async (c) => {
|
|
7985
|
+
if (!await isFeatureEnabled(c, "continuous-chat"))
|
|
7986
|
+
return c.json({ error: "feature not enabled" }, 403);
|
|
7987
|
+
const replyId = c.req.param("replyId");
|
|
7988
|
+
const input2 = await c.req.json().catch(() => null);
|
|
7989
|
+
const topic = typeof input2?.topic === "string" ? input2.topic.trim().slice(0, 60) : "";
|
|
7990
|
+
if (!topic) return c.json({ error: "topic is required" }, 400);
|
|
7991
|
+
const supabase = getSupabaseClient();
|
|
7992
|
+
const { data } = await supabase.from("thread_replies").select("id, threads!inner(channel_id)").eq("id", replyId).maybeSingle();
|
|
7993
|
+
const channelId = data?.threads?.channel_id;
|
|
7994
|
+
const channel = channelId ? findChannel2(c, channelId) : void 0;
|
|
7995
|
+
if (!channel || !isDmChannel(channel)) return c.json({ error: "not found" }, 404);
|
|
7996
|
+
const { error: error2 } = await supabase.from("reply_topics").upsert({ reply_id: replyId, channel_id: channel.id, topic, source: "manual" });
|
|
7997
|
+
if (error2) return c.json({ error: error2.message }, 500);
|
|
7998
|
+
return c.json({ ok: true, topic });
|
|
7999
|
+
});
|
|
8000
|
+
return app;
|
|
8001
|
+
}
|
|
8002
|
+
|
|
7814
8003
|
// ../api/src/dashboard/thread-translate.ts
|
|
7815
8004
|
import { createHash as createHash3 } from "crypto";
|
|
7816
8005
|
|
|
@@ -7820,11 +8009,11 @@ var TABLES = {
|
|
|
7820
8009
|
title: { table: "thread_title_translations", idColumn: "thread_id" }
|
|
7821
8010
|
};
|
|
7822
8011
|
async function getThreadTranslations(lang, keys, kind = "reply") {
|
|
7823
|
-
const { table, idColumn } = TABLES[kind];
|
|
8012
|
+
const { table: table2, idColumn } = TABLES[kind];
|
|
7824
8013
|
const found = /* @__PURE__ */ new Map();
|
|
7825
8014
|
if (keys.length === 0) return found;
|
|
7826
8015
|
const clauses = keys.map((k) => `and(${idColumn}.eq.${k.replyId},body_hash.eq.${k.bodyHash})`).join(",");
|
|
7827
|
-
const { data, error: error2 } = await getSupabaseClient().from(
|
|
8016
|
+
const { data, error: error2 } = await getSupabaseClient().from(table2).select(`${idColumn}, body, passthrough`).eq("lang", lang).or(clauses);
|
|
7828
8017
|
if (error2) throw new Error(`getThreadTranslations(${lang}): ${error2.message}`);
|
|
7829
8018
|
for (const row of data ?? []) {
|
|
7830
8019
|
const replyId = row[idColumn];
|
|
@@ -7838,8 +8027,8 @@ async function getThreadTranslations(lang, keys, kind = "reply") {
|
|
|
7838
8027
|
}
|
|
7839
8028
|
async function putThreadTranslations(lang, rows, kind = "reply") {
|
|
7840
8029
|
if (rows.length === 0) return;
|
|
7841
|
-
const { table, idColumn } = TABLES[kind];
|
|
7842
|
-
const { error: error2 } = await getSupabaseClient().from(
|
|
8030
|
+
const { table: table2, idColumn } = TABLES[kind];
|
|
8031
|
+
const { error: error2 } = await getSupabaseClient().from(table2).upsert(
|
|
7843
8032
|
rows.map((r) => ({
|
|
7844
8033
|
[idColumn]: r.replyId,
|
|
7845
8034
|
lang,
|
|
@@ -7872,7 +8061,7 @@ async function addTranslationTokens(workspaceId, tokens2) {
|
|
|
7872
8061
|
}
|
|
7873
8062
|
|
|
7874
8063
|
// ../api/src/dashboard/thread-translate.ts
|
|
7875
|
-
var
|
|
8064
|
+
var GROQ_API_URL3 = "https://api.groq.com/openai/v1/chat/completions";
|
|
7876
8065
|
var TRANSLATION_MODEL = "openai/gpt-oss-120b";
|
|
7877
8066
|
var RECIPE_VERSION = 1;
|
|
7878
8067
|
var BATCH_CHAR_BUDGET = 16e3;
|
|
@@ -7955,7 +8144,7 @@ async function translateBatch(batch, context, lang, scope) {
|
|
|
7955
8144
|
batch.map((m) => m.body)
|
|
7956
8145
|
)
|
|
7957
8146
|
};
|
|
7958
|
-
const res = await fetch(
|
|
8147
|
+
const res = await fetch(GROQ_API_URL3, {
|
|
7959
8148
|
method: "POST",
|
|
7960
8149
|
headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
|
|
7961
8150
|
body: JSON.stringify({
|
|
@@ -8221,9 +8410,9 @@ async function threadIsKnown(threadId, c) {
|
|
|
8221
8410
|
const channelId = data?.channel_id;
|
|
8222
8411
|
return !!channelId && (await globalChannelMeta(c)).has(channelId);
|
|
8223
8412
|
}
|
|
8224
|
-
function chunk(
|
|
8413
|
+
function chunk(items2, size) {
|
|
8225
8414
|
const out = [];
|
|
8226
|
-
for (let i = 0; i <
|
|
8415
|
+
for (let i = 0; i < items2.length; i += size) out.push(items2.slice(i, i + size));
|
|
8227
8416
|
return out;
|
|
8228
8417
|
}
|
|
8229
8418
|
async function withPreviews(supabase, threads) {
|
|
@@ -8316,7 +8505,7 @@ async function generateAutoTitle(threadId, channelId, body) {
|
|
|
8316
8505
|
await supabase.from("threads").update({ auto_title: autoTitle }).eq("id", threadId).is("title", null);
|
|
8317
8506
|
}
|
|
8318
8507
|
function createChatRouter(agent = {}) {
|
|
8319
|
-
const app = new
|
|
8508
|
+
const app = new Hono13();
|
|
8320
8509
|
const {
|
|
8321
8510
|
onChatMessage: onMessage,
|
|
8322
8511
|
isAgentThinking,
|
|
@@ -8842,6 +9031,12 @@ function createChatRouter(agent = {}) {
|
|
|
8842
9031
|
effort: effortFromRow(reply["effort"])
|
|
8843
9032
|
});
|
|
8844
9033
|
askSupport(c, thread.id, input2.author, input2.body);
|
|
9034
|
+
tagStoredReply(c, {
|
|
9035
|
+
threadId: thread.id,
|
|
9036
|
+
replyId: reply.id,
|
|
9037
|
+
author: input2.author,
|
|
9038
|
+
body: input2.body
|
|
9039
|
+
});
|
|
8845
9040
|
}
|
|
8846
9041
|
if (!replayed && pickedStatus !== void 0) {
|
|
8847
9042
|
void rememberComposerStatus(c, channelId, pickedStatus).catch(
|
|
@@ -8960,6 +9155,13 @@ function createChatRouter(agent = {}) {
|
|
|
8960
9155
|
effort: effortFromRow(data.effort)
|
|
8961
9156
|
});
|
|
8962
9157
|
askSupport(c, threadId, input2.author, input2.body);
|
|
9158
|
+
tagStoredReply(c, {
|
|
9159
|
+
threadId,
|
|
9160
|
+
replyId: data.id,
|
|
9161
|
+
author: input2.author,
|
|
9162
|
+
body: input2.body,
|
|
9163
|
+
replyToId: isNonEmptyString(input2.replyToId) ? input2.replyToId : void 0
|
|
9164
|
+
});
|
|
8963
9165
|
void syncSupportReply({ threadId, author: input2.author, body: input2.body });
|
|
8964
9166
|
return c.json(data, 201);
|
|
8965
9167
|
});
|
|
@@ -8990,7 +9192,7 @@ function createChatRouter(agent = {}) {
|
|
|
8990
9192
|
}
|
|
8991
9193
|
|
|
8992
9194
|
// ../api/src/dashboard/doc-shares-routes.ts
|
|
8993
|
-
import { Hono as
|
|
9195
|
+
import { Hono as Hono14 } from "hono";
|
|
8994
9196
|
|
|
8995
9197
|
// ../api/src/dashboard/doc-share-features.ts
|
|
8996
9198
|
import { DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
@@ -9056,7 +9258,7 @@ import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-s
|
|
|
9056
9258
|
var SHARE_ASSET_PLACEHOLDER = "/share/{{flyspace-share-id}}/assets/";
|
|
9057
9259
|
|
|
9058
9260
|
// ../api/src/dashboard/share-language.ts
|
|
9059
|
-
var
|
|
9261
|
+
var GROQ_API_URL4 = "https://api.groq.com/openai/v1/chat/completions";
|
|
9060
9262
|
var CLASSIFIER_MODEL = "openai/gpt-oss-20b";
|
|
9061
9263
|
var SAMPLE_CHARS = 4e3;
|
|
9062
9264
|
var NOISE = [
|
|
@@ -9095,7 +9297,7 @@ async function detectSourceLanguage(title, content) {
|
|
|
9095
9297
|
const sample = languageSample(title, content);
|
|
9096
9298
|
if (sample.length < MIN_SAMPLE_CHARS) return null;
|
|
9097
9299
|
try {
|
|
9098
|
-
const res = await fetch(
|
|
9300
|
+
const res = await fetch(GROQ_API_URL4, {
|
|
9099
9301
|
method: "POST",
|
|
9100
9302
|
headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
|
|
9101
9303
|
body: JSON.stringify({
|
|
@@ -9325,7 +9527,7 @@ function resolveChannel2(c) {
|
|
|
9325
9527
|
}
|
|
9326
9528
|
var LIST_LIMIT = 500;
|
|
9327
9529
|
function createDocShareListRouter() {
|
|
9328
|
-
const app = new
|
|
9530
|
+
const app = new Hono14();
|
|
9329
9531
|
app.get("/shares", async (c) => {
|
|
9330
9532
|
const viewer = c.get("auth");
|
|
9331
9533
|
const readable = await filterReadableDocsChannels(
|
|
@@ -9369,7 +9571,7 @@ function createDocShareListRouter() {
|
|
|
9369
9571
|
return app;
|
|
9370
9572
|
}
|
|
9371
9573
|
function createDocShareWriteRouter(agent = {}) {
|
|
9372
|
-
const app = new
|
|
9574
|
+
const app = new Hono14();
|
|
9373
9575
|
app.use("/:id/docs/share", requireDocsAccess);
|
|
9374
9576
|
app.use("/:id/docs/share/*", requireDocsAccess);
|
|
9375
9577
|
app.use("/:id/docs/shares", requireDocsAccess);
|
|
@@ -9542,7 +9744,7 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9542
9744
|
}
|
|
9543
9745
|
|
|
9544
9746
|
// ../api/src/dashboard/search-routes.ts
|
|
9545
|
-
import { Hono as
|
|
9747
|
+
import { Hono as Hono15 } from "hono";
|
|
9546
9748
|
function matchScore(q, fields) {
|
|
9547
9749
|
const terms = q.toLowerCase().split(/\s+/).filter(Boolean);
|
|
9548
9750
|
if (terms.length === 0) return 0;
|
|
@@ -9690,7 +9892,7 @@ function searchAutomations(q) {
|
|
|
9690
9892
|
}
|
|
9691
9893
|
var RESULT_LIMIT = 30;
|
|
9692
9894
|
function createSearchRouter() {
|
|
9693
|
-
const app = new
|
|
9895
|
+
const app = new Hono15();
|
|
9694
9896
|
app.get("/", async (c) => {
|
|
9695
9897
|
const q = c.req.query("q")?.trim();
|
|
9696
9898
|
if (!q) return c.json({ results: [] });
|
|
@@ -9706,7 +9908,7 @@ function createSearchRouter() {
|
|
|
9706
9908
|
}
|
|
9707
9909
|
|
|
9708
9910
|
// ../api/src/dashboard/domain-routes.ts
|
|
9709
|
-
import { Hono as
|
|
9911
|
+
import { Hono as Hono16 } from "hono";
|
|
9710
9912
|
var FALLBACK_ORIGIN = "custom.flyspace.ai";
|
|
9711
9913
|
function isValidCustomHostname(hostname2) {
|
|
9712
9914
|
if (hostname2.length > 253 || hostname2.endsWith(".flyspace.ai") || hostname2 === "flyspace.ai") {
|
|
@@ -9776,7 +9978,7 @@ function view(row, dcv) {
|
|
|
9776
9978
|
};
|
|
9777
9979
|
}
|
|
9778
9980
|
function createDomainRouter() {
|
|
9779
|
-
const app = new
|
|
9981
|
+
const app = new Hono16();
|
|
9780
9982
|
app.use("*", async (c, next) => {
|
|
9781
9983
|
const auth = c.get("auth");
|
|
9782
9984
|
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
@@ -9840,17 +10042,15 @@ function createDomainRouter() {
|
|
|
9840
10042
|
}
|
|
9841
10043
|
|
|
9842
10044
|
// ../api/src/dashboard/transcribe-routes.ts
|
|
9843
|
-
import { Hono as
|
|
10045
|
+
import { Hono as Hono17 } from "hono";
|
|
9844
10046
|
var GROQ_TRANSCRIBE_URL = "https://api.groq.com/openai/v1/audio/transcriptions";
|
|
9845
|
-
var
|
|
10047
|
+
var MODEL2 = "whisper-large-v3-turbo";
|
|
9846
10048
|
var MAX_AUDIO_BYTES = 5 * 1024 * 1024;
|
|
9847
10049
|
var MAX_PROMPT_CHARS = 400;
|
|
9848
10050
|
var NO_SPEECH_THRESHOLD = 0.6;
|
|
9849
10051
|
function createTranscribeRouter() {
|
|
9850
|
-
const app = new
|
|
10052
|
+
const app = new Hono17();
|
|
9851
10053
|
app.post("/transcribe", async (c) => {
|
|
9852
|
-
if (!await isFeatureEnabled(c, "dictation"))
|
|
9853
|
-
return c.json({ error: "feature not enabled" }, 403);
|
|
9854
10054
|
const apiKey = process.env["GROQ_API_KEY"];
|
|
9855
10055
|
if (!apiKey) return c.json({ error: "transcription is not configured" }, 503);
|
|
9856
10056
|
const body = await c.req.parseBody().catch(() => null);
|
|
@@ -9859,7 +10059,7 @@ function createTranscribeRouter() {
|
|
|
9859
10059
|
if (file.size > MAX_AUDIO_BYTES) return c.json({ error: "audio segment too large" }, 400);
|
|
9860
10060
|
const form = new FormData();
|
|
9861
10061
|
form.append("file", file, file.name || "segment.wav");
|
|
9862
|
-
form.append("model",
|
|
10062
|
+
form.append("model", MODEL2);
|
|
9863
10063
|
form.append("temperature", "0");
|
|
9864
10064
|
form.append("response_format", "verbose_json");
|
|
9865
10065
|
const prompt = body?.["prompt"];
|
|
@@ -9886,21 +10086,19 @@ function createTranscribeRouter() {
|
|
|
9886
10086
|
}
|
|
9887
10087
|
|
|
9888
10088
|
// ../api/src/dashboard/autocomplete-routes.ts
|
|
9889
|
-
import { Hono as
|
|
9890
|
-
var
|
|
9891
|
-
var
|
|
10089
|
+
import { Hono as Hono18 } from "hono";
|
|
10090
|
+
var GROQ_API_URL5 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10091
|
+
var MODEL3 = "openai/gpt-oss-120b";
|
|
9892
10092
|
var MAX_REPLY_CHARS = 4e3;
|
|
9893
10093
|
var MAX_EARLIER_CHARS = 1500;
|
|
9894
10094
|
var THREAD_TAIL_REPLIES = 5;
|
|
9895
|
-
var
|
|
10095
|
+
var RULES2 = `You predict the next message a user will send in a chat thread, right after the AI agent's last reply, like Claude Code's prompt suggestions. The composer is empty; you suggest the whole message.
|
|
9896
10096
|
Base it on the agent's last reply: answer a question it asked, approve or pick an option it offered, or ask for the obvious next step (commit, deploy, run the tests, check a specific file or feature it named). Use specific nouns from the reply.
|
|
9897
10097
|
Keep it short (under 15 words), in the language the user writes in. No greetings, thanks or filler.
|
|
9898
10098
|
Output ONLY the message text, no quotes or explanation. If there is no clear next step, output nothing.`;
|
|
9899
10099
|
function createAutocompleteRouter() {
|
|
9900
|
-
const app = new
|
|
10100
|
+
const app = new Hono18();
|
|
9901
10101
|
app.post("/autocomplete", async (c) => {
|
|
9902
|
-
if (!await isFeatureEnabled(c, "autocomplete"))
|
|
9903
|
-
return c.json({ error: "feature not enabled" }, 403);
|
|
9904
10102
|
const apiKey = process.env["GROQ_API_KEY"];
|
|
9905
10103
|
if (!apiKey) return c.json({ error: "autocomplete is not configured" }, 503);
|
|
9906
10104
|
const body = await c.req.json().catch(() => null);
|
|
@@ -9912,12 +10110,12 @@ function createAutocompleteRouter() {
|
|
|
9912
10110
|
const context = `Channel: #${channel.name}${channel.prompt ? `
|
|
9913
10111
|
Channel instructions: ${channel.prompt.slice(0, 500)}` : ""}
|
|
9914
10112
|
${thread}`;
|
|
9915
|
-
const res = await fetch(
|
|
10113
|
+
const res = await fetch(GROQ_API_URL5, {
|
|
9916
10114
|
method: "POST",
|
|
9917
10115
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
9918
10116
|
signal: AbortSignal.timeout(5e3),
|
|
9919
10117
|
body: JSON.stringify({
|
|
9920
|
-
model:
|
|
10118
|
+
model: MODEL3,
|
|
9921
10119
|
// gpt-oss reasons first; a newline stop would cut it off before any content.
|
|
9922
10120
|
max_completion_tokens: 200,
|
|
9923
10121
|
reasoning_effort: "low",
|
|
@@ -9926,8 +10124,8 @@ ${thread}`;
|
|
|
9926
10124
|
messages: [
|
|
9927
10125
|
{
|
|
9928
10126
|
role: "system",
|
|
9929
|
-
content: typeof body.language === "string" && /^[A-Za-z-]{2,16}$/.test(body.language) ? `${
|
|
9930
|
-
The user reads this thread in ${body.language}: write the suggestion in that language (BCP 47 tag).` :
|
|
10127
|
+
content: typeof body.language === "string" && /^[A-Za-z-]{2,16}$/.test(body.language) ? `${RULES2}
|
|
10128
|
+
The user reads this thread in ${body.language}: write the suggestion in that language (BCP 47 tag).` : RULES2
|
|
9931
10129
|
},
|
|
9932
10130
|
{ role: "user", content: context }
|
|
9933
10131
|
]
|
|
@@ -9964,9 +10162,220 @@ Agent's last reply:
|
|
|
9964
10162
|
${last.body.slice(-MAX_REPLY_CHARS)}`;
|
|
9965
10163
|
}
|
|
9966
10164
|
|
|
10165
|
+
// ../api/src/dashboard/daily-line-routes.ts
|
|
10166
|
+
import { Hono as Hono19 } from "hono";
|
|
10167
|
+
var GROQ_API_URL6 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10168
|
+
var MODEL4 = "openai/gpt-oss-120b";
|
|
10169
|
+
var DAY_MS = 864e5;
|
|
10170
|
+
var RULES3 = `You write one short line of encouragement shown in the corner of an empty screen, for a founder building a product with a small team.
|
|
10171
|
+
You are given what the team recently built and decided. Draw on its real substance to remind them how far they have come or why the work matters, so they feel like pushing on.
|
|
10172
|
+
Never a task, reminder, instruction or rule (no "remember to", "do X first", "never Y"). Not a summary of the item either.
|
|
10173
|
+
Under 30 Chinese characters or 18 English words. Warm but plain, like a note from a friend: no hype, no exclamation marks, no emoji, no quotes, no cliches.
|
|
10174
|
+
Output ONLY the line.`;
|
|
10175
|
+
var CONTEXT_COUNT = 5;
|
|
10176
|
+
var cache3 = /* @__PURE__ */ new Map();
|
|
10177
|
+
function dayIndex(now = /* @__PURE__ */ new Date()) {
|
|
10178
|
+
const local = new Date(now.toLocaleString("en-US", { timeZone: "Australia/Sydney" }));
|
|
10179
|
+
return Math.floor(Date.UTC(local.getFullYear(), local.getMonth(), local.getDate()) / DAY_MS);
|
|
10180
|
+
}
|
|
10181
|
+
var RECENT_MS = 60 * DAY_MS;
|
|
10182
|
+
function pickMemories(memories, day, now = Date.now()) {
|
|
10183
|
+
const recent = memories.filter((m) => now - Date.parse(m.updatedAt) < RECENT_MS);
|
|
10184
|
+
const pool = (recent.length ? recent : memories).sort(
|
|
10185
|
+
(a, b) => b.updatedAt.localeCompare(a.updatedAt)
|
|
10186
|
+
);
|
|
10187
|
+
if (!pool.length) return [];
|
|
10188
|
+
const start = day % pool.length;
|
|
10189
|
+
return [...pool, ...pool].slice(start, start + Math.min(CONTEXT_COUNT, pool.length));
|
|
10190
|
+
}
|
|
10191
|
+
function createDailyLineRouter() {
|
|
10192
|
+
const app = new Hono19();
|
|
10193
|
+
app.get("/daily-line", async (c) => {
|
|
10194
|
+
if (!await isFeatureEnabled(c, "daily-line"))
|
|
10195
|
+
return c.json({ error: "feature not enabled" }, 403);
|
|
10196
|
+
const apiKey = process.env["GROQ_API_KEY"];
|
|
10197
|
+
if (!apiKey) return c.json({ text: "" });
|
|
10198
|
+
const auth = c.get("auth");
|
|
10199
|
+
const language = c.req.query("language") ?? "en";
|
|
10200
|
+
if (!/^[A-Za-z-]{2,16}$/.test(language)) return c.json({ text: "" });
|
|
10201
|
+
const { data } = await getSupabaseClient().from("memories").select("*").eq("workspace_id", auth.workspaceId).in("scope", ["channel", "workspace"]).in("type", ["decision", "fact"]);
|
|
10202
|
+
const visible = new Set(
|
|
10203
|
+
getChannelRegistry().filter((ch) => canSeeChannel(ch, auth)).map((ch) => ch.id)
|
|
10204
|
+
);
|
|
10205
|
+
const memories = (data ?? []).map(rowToMemory).filter((m) => !m.channelId || visible.has(m.channelId));
|
|
10206
|
+
const day = dayIndex();
|
|
10207
|
+
const picked = pickMemories(memories, day);
|
|
10208
|
+
const memory = picked[0];
|
|
10209
|
+
if (!memory) return c.json({ text: "" });
|
|
10210
|
+
const key = `${day}:${memory.id}:${language}`;
|
|
10211
|
+
let text = cache3.get(key);
|
|
10212
|
+
if (text === void 0) {
|
|
10213
|
+
const res = await fetch(GROQ_API_URL6, {
|
|
10214
|
+
method: "POST",
|
|
10215
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10216
|
+
signal: AbortSignal.timeout(8e3),
|
|
10217
|
+
body: JSON.stringify({
|
|
10218
|
+
model: MODEL4,
|
|
10219
|
+
max_completion_tokens: 300,
|
|
10220
|
+
reasoning_effort: "low",
|
|
10221
|
+
include_reasoning: false,
|
|
10222
|
+
temperature: 0.7,
|
|
10223
|
+
messages: [
|
|
10224
|
+
{
|
|
10225
|
+
role: "system",
|
|
10226
|
+
content: `${RULES3}
|
|
10227
|
+
Write it in ${language} (BCP 47 tag). For Chinese use Traditional Chinese (Taiwan) with full-width punctuation.`
|
|
10228
|
+
},
|
|
10229
|
+
{
|
|
10230
|
+
role: "user",
|
|
10231
|
+
content: picked.map((m) => `- ${m.description}
|
|
10232
|
+
${m.body.slice(0, 400)}`).join("\n")
|
|
10233
|
+
}
|
|
10234
|
+
]
|
|
10235
|
+
})
|
|
10236
|
+
}).catch(() => null);
|
|
10237
|
+
if (!res?.ok) return c.json({ text: "" });
|
|
10238
|
+
const out = await res.json();
|
|
10239
|
+
text = (out.choices?.[0]?.message?.content ?? "").trim().split("\n")[0];
|
|
10240
|
+
if (text) cache3.set(key, text);
|
|
10241
|
+
}
|
|
10242
|
+
return c.json({ text, date: memory.updatedAt, threadId: memory.sourceThreadId });
|
|
10243
|
+
});
|
|
10244
|
+
return app;
|
|
10245
|
+
}
|
|
10246
|
+
|
|
10247
|
+
// ../api/src/dashboard/channel-route.ts
|
|
10248
|
+
import { Hono as Hono20 } from "hono";
|
|
10249
|
+
var GROQ_API_URL7 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10250
|
+
var MODEL5 = "openai/gpt-oss-120b";
|
|
10251
|
+
var MAX_MESSAGE_CHARS2 = 3e3;
|
|
10252
|
+
var MAX_PROMPT_CHARS2 = 300;
|
|
10253
|
+
var TITLES_PER_CHANNEL = 8;
|
|
10254
|
+
var RECENT_THREADS = 600;
|
|
10255
|
+
var TABLE_TTL_MS = 30 * 6e4;
|
|
10256
|
+
var VISION_MODEL = "qwen/qwen3.8-27b";
|
|
10257
|
+
var MAX_IMAGES = 3;
|
|
10258
|
+
var ATTACHMENT_KEY = /\/api\/attachments\/([^)?\s]+)/g;
|
|
10259
|
+
var DESCRIBE = `Describe these screenshots in 2 to 4 short lines so someone can tell which project they belong to: the app or website shown, its visible product, brand, workspace and channel names, and the screen or feature. Quote names exactly as written. No guesses beyond what is visible.`;
|
|
10260
|
+
async function describeImages(text, workspace, apiKey) {
|
|
10261
|
+
if (!workspace) return "";
|
|
10262
|
+
const keys = [...text.matchAll(ATTACHMENT_KEY)].map((m) => decodeURIComponent(m[1])).filter((key) => key.split("/")[1] === workspace).slice(0, MAX_IMAGES);
|
|
10263
|
+
const urls = (await Promise.all(keys.map((k) => presignAttachmentRead(k).catch(() => null)))).filter(
|
|
10264
|
+
(u) => !!u
|
|
10265
|
+
);
|
|
10266
|
+
if (urls.length === 0) return "";
|
|
10267
|
+
const res = await fetch(GROQ_API_URL7, {
|
|
10268
|
+
method: "POST",
|
|
10269
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10270
|
+
signal: AbortSignal.timeout(1e4),
|
|
10271
|
+
body: JSON.stringify({
|
|
10272
|
+
model: VISION_MODEL,
|
|
10273
|
+
max_completion_tokens: 200,
|
|
10274
|
+
reasoning_effort: "none",
|
|
10275
|
+
temperature: 0,
|
|
10276
|
+
messages: [
|
|
10277
|
+
{
|
|
10278
|
+
role: "user",
|
|
10279
|
+
content: [
|
|
10280
|
+
{ type: "text", text: DESCRIBE },
|
|
10281
|
+
...urls.map((url) => ({ type: "image_url", image_url: { url } }))
|
|
10282
|
+
]
|
|
10283
|
+
}
|
|
10284
|
+
]
|
|
10285
|
+
})
|
|
10286
|
+
}).catch(() => null);
|
|
10287
|
+
if (!res?.ok) return "";
|
|
10288
|
+
const data = await res.json();
|
|
10289
|
+
return (data.choices?.[0]?.message?.content ?? "").trim();
|
|
10290
|
+
}
|
|
10291
|
+
var table = null;
|
|
10292
|
+
async function recentTitles(channels) {
|
|
10293
|
+
const key = channels.map((ch) => ch.id).sort().join(",");
|
|
10294
|
+
if (table?.key === key && Date.now() - table.builtAt < TABLE_TTL_MS) return table.titles;
|
|
10295
|
+
const keyOf = /* @__PURE__ */ new Map();
|
|
10296
|
+
for (const ch of channels) {
|
|
10297
|
+
keyOf.set(ch.id, ch.id);
|
|
10298
|
+
if (ch.externalChannelId) keyOf.set(ch.externalChannelId, ch.id);
|
|
10299
|
+
}
|
|
10300
|
+
const { data: threads } = await getSupabaseClient().from("threads").select("channel_id, title, auto_title").in("channel_id", [...keyOf.keys()]).order("created_at", { ascending: false }).limit(RECENT_THREADS);
|
|
10301
|
+
const titles = /* @__PURE__ */ new Map();
|
|
10302
|
+
for (const t of threads ?? []) {
|
|
10303
|
+
const id = keyOf.get(t.channel_id);
|
|
10304
|
+
const title = t.title ?? t.auto_title;
|
|
10305
|
+
if (!id || !title) continue;
|
|
10306
|
+
const list = titles.get(id) ?? [];
|
|
10307
|
+
if (list.length < TITLES_PER_CHANNEL) titles.set(id, [...list, title]);
|
|
10308
|
+
}
|
|
10309
|
+
table = { key, builtAt: Date.now(), titles };
|
|
10310
|
+
return titles;
|
|
10311
|
+
}
|
|
10312
|
+
var RULES4 = `You route a new chat topic to the channel it belongs in. Each channel is a project or area of work; you get its name, instructions and recent topic titles.
|
|
10313
|
+
Pick the single channel whose project the message is about. Prefer a specific project channel over a general one. Match on concrete nouns (product, client, repo, feature names) rather than tone.
|
|
10314
|
+
A topic word that could fit many projects (notification, scrollbar, login, bug) is not evidence: unless the message clearly names another project, pick the channel the user is currently in.
|
|
10315
|
+
When a screenshot description is given, the app and names visible in it are strong evidence of the project.
|
|
10316
|
+
Output ONLY the channel's number and your confidence, e.g. "3 high" or "3 low". Say low when the message could reasonably belong to more than one channel.`;
|
|
10317
|
+
function createChannelRouteRouter() {
|
|
10318
|
+
const app = new Hono20();
|
|
10319
|
+
app.post("/route-channel", async (c) => {
|
|
10320
|
+
if (!await isFeatureEnabled(c, "auto-channel"))
|
|
10321
|
+
return c.json({ error: "feature not enabled" }, 403);
|
|
10322
|
+
const apiKey = process.env["GROQ_API_KEY"];
|
|
10323
|
+
if (!apiKey) return c.json({ error: "channel routing is not configured" }, 503);
|
|
10324
|
+
const body = await c.req.json().catch(() => null);
|
|
10325
|
+
const text = typeof body?.text === "string" ? body.text.trim().slice(0, MAX_MESSAGE_CHARS2) : "";
|
|
10326
|
+
if (!text) return c.json({ channelId: null, confident: false });
|
|
10327
|
+
const auth = c.get("auth");
|
|
10328
|
+
const channels = getChannelRegistry().filter((ch) => !ch.archivedAt && canSeeChannel(ch, auth));
|
|
10329
|
+
if (channels.length <= 1) return c.json({ channelId: channels[0]?.id ?? null, confident: true });
|
|
10330
|
+
const [titles, screenshots] = await Promise.all([
|
|
10331
|
+
recentTitles(getChannelRegistry().filter((ch) => !ch.archivedAt)),
|
|
10332
|
+
describeImages(text, c.req.query("workspace"), apiKey)
|
|
10333
|
+
]);
|
|
10334
|
+
const current = channels.findIndex((ch) => ch.id === body?.currentChannelId);
|
|
10335
|
+
const listing = channels.map(
|
|
10336
|
+
(ch, i) => [
|
|
10337
|
+
`${i + 1}. ${ch.agentName ? "@" : "#"}${ch.name}`,
|
|
10338
|
+
ch.prompt ? ` Instructions: ${ch.prompt.replace(/\s+/g, " ").slice(0, MAX_PROMPT_CHARS2)}` : "",
|
|
10339
|
+
titles.get(ch.id)?.length ? ` Recent topics: ${titles.get(ch.id).join(" | ")}` : ""
|
|
10340
|
+
].filter(Boolean).join("\n")
|
|
10341
|
+
).join("\n");
|
|
10342
|
+
const res = await fetch(GROQ_API_URL7, {
|
|
10343
|
+
method: "POST",
|
|
10344
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10345
|
+
signal: AbortSignal.timeout(8e3),
|
|
10346
|
+
body: JSON.stringify({
|
|
10347
|
+
model: MODEL5,
|
|
10348
|
+
max_completion_tokens: 400,
|
|
10349
|
+
reasoning_effort: "low",
|
|
10350
|
+
include_reasoning: false,
|
|
10351
|
+
temperature: 0,
|
|
10352
|
+
messages: [
|
|
10353
|
+
{ role: "system", content: RULES4 },
|
|
10354
|
+
{ role: "user", content: `Channels:
|
|
10355
|
+
${listing}${current >= 0 ? `
|
|
10356
|
+
|
|
10357
|
+
The user is currently in channel ${current + 1}.` : ""}
|
|
10358
|
+
|
|
10359
|
+
New topic:
|
|
10360
|
+
${text}${screenshots ? `
|
|
10361
|
+
|
|
10362
|
+
Attached screenshots show:
|
|
10363
|
+
${screenshots}` : ""}` }
|
|
10364
|
+
]
|
|
10365
|
+
})
|
|
10366
|
+
}).catch(() => null);
|
|
10367
|
+
if (!res?.ok) return c.json({ channelId: null, confident: false });
|
|
10368
|
+
const data = await res.json();
|
|
10369
|
+
const reply = data.choices?.[0]?.message?.content ?? "";
|
|
10370
|
+
const channelId = channels[Number(reply.match(/\d+/)?.[0]) - 1]?.id ?? null;
|
|
10371
|
+
return c.json({ channelId, confident: !!channelId && /\bhigh\b/i.test(reply) });
|
|
10372
|
+
});
|
|
10373
|
+
return app;
|
|
10374
|
+
}
|
|
10375
|
+
|
|
9967
10376
|
// ../api/src/dashboard/avatars-routes.ts
|
|
9968
10377
|
import { createHash as createHash4, randomUUID as randomUUID3 } from "crypto";
|
|
9969
|
-
import { Hono as
|
|
10378
|
+
import { Hono as Hono21 } from "hono";
|
|
9970
10379
|
import sharp3 from "sharp";
|
|
9971
10380
|
import { PutObjectCommand as PutObjectCommand3, DeleteObjectCommand as DeleteObjectCommand2 } from "@aws-sdk/client-s3";
|
|
9972
10381
|
var AVATAR_SIZE = 192;
|
|
@@ -10019,7 +10428,7 @@ function avatarKeyPrefix() {
|
|
|
10019
10428
|
return `${KEY_PREFIX2}/${getProfile()}/`;
|
|
10020
10429
|
}
|
|
10021
10430
|
function createAvatarsRouter() {
|
|
10022
|
-
const app = new
|
|
10431
|
+
const app = new Hono21();
|
|
10023
10432
|
app.get("/avatars/slack", async (c) => {
|
|
10024
10433
|
const ctx = await resolveAuthContext(c);
|
|
10025
10434
|
if (!ctx) return c.json({ error: "not signed in" }, 401);
|
|
@@ -10068,7 +10477,7 @@ function createAvatarsRouter() {
|
|
|
10068
10477
|
}
|
|
10069
10478
|
|
|
10070
10479
|
// ../api/src/dashboard/members-routes.ts
|
|
10071
|
-
import { Hono as
|
|
10480
|
+
import { Hono as Hono22 } from "hono";
|
|
10072
10481
|
function inviteLinkFor(c, token) {
|
|
10073
10482
|
const url = new URL("/auth/invite", callbackUrl(c));
|
|
10074
10483
|
url.searchParams.set("token", token);
|
|
@@ -10076,7 +10485,7 @@ function inviteLinkFor(c, token) {
|
|
|
10076
10485
|
}
|
|
10077
10486
|
var EMAIL_RE2 = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
10078
10487
|
function createMembersRouter() {
|
|
10079
|
-
const members = new
|
|
10488
|
+
const members = new Hono22();
|
|
10080
10489
|
members.get("/", async (c) => {
|
|
10081
10490
|
const ctx = await resolveAuthContext(c);
|
|
10082
10491
|
if (ctx?.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
@@ -10299,7 +10708,7 @@ function createMembersRouter() {
|
|
|
10299
10708
|
}
|
|
10300
10709
|
|
|
10301
10710
|
// ../api/src/dashboard/notifications-routes.ts
|
|
10302
|
-
import { Hono as
|
|
10711
|
+
import { Hono as Hono23 } from "hono";
|
|
10303
10712
|
|
|
10304
10713
|
// ../api/src/store/notification-store.ts
|
|
10305
10714
|
function rowToNotification(row) {
|
|
@@ -10551,7 +10960,7 @@ function startPushWatcher() {
|
|
|
10551
10960
|
|
|
10552
10961
|
// ../api/src/dashboard/notifications-routes.ts
|
|
10553
10962
|
function createNotificationsRouter() {
|
|
10554
|
-
const notifications = new
|
|
10963
|
+
const notifications = new Hono23();
|
|
10555
10964
|
notifications.get("/", async (c) => {
|
|
10556
10965
|
const auth = c.get("auth");
|
|
10557
10966
|
const channelIds = getProfileChannelRegistry().filter((ch) => canSeeChannel(ch, auth)).map((ch) => ch.id);
|
|
@@ -10578,7 +10987,7 @@ function createNotificationsRouter() {
|
|
|
10578
10987
|
return notifications;
|
|
10579
10988
|
}
|
|
10580
10989
|
function createThreadReadRouter() {
|
|
10581
|
-
const threads = new
|
|
10990
|
+
const threads = new Hono23();
|
|
10582
10991
|
threads.post("/threads/:threadId/read", async (c) => {
|
|
10583
10992
|
const { userId } = c.get("auth");
|
|
10584
10993
|
const threadId = c.req.param("threadId");
|
|
@@ -10590,9 +10999,9 @@ function createThreadReadRouter() {
|
|
|
10590
10999
|
}
|
|
10591
11000
|
|
|
10592
11001
|
// ../api/src/dashboard/push-routes.ts
|
|
10593
|
-
import { Hono as
|
|
11002
|
+
import { Hono as Hono24 } from "hono";
|
|
10594
11003
|
function createPushRouter() {
|
|
10595
|
-
const push = new
|
|
11004
|
+
const push = new Hono24();
|
|
10596
11005
|
push.get("/key", (c) => c.json({ publicKey: getVapidPublicKey() }));
|
|
10597
11006
|
push.post("/subscribe", async (c) => {
|
|
10598
11007
|
const { userId } = c.get("auth");
|
|
@@ -10623,7 +11032,7 @@ function createPushRouter() {
|
|
|
10623
11032
|
}
|
|
10624
11033
|
|
|
10625
11034
|
// ../api/src/dashboard/mcp-oauth-routes.ts
|
|
10626
|
-
import { Hono as
|
|
11035
|
+
import { Hono as Hono25 } from "hono";
|
|
10627
11036
|
var CONNECTIONS_PAGE = "/settings/connections";
|
|
10628
11037
|
function callbackUri(c) {
|
|
10629
11038
|
const proto = c.req.header("x-forwarded-proto") ?? "http";
|
|
@@ -10638,7 +11047,7 @@ function backToDashboard(c, to, params) {
|
|
|
10638
11047
|
return c.redirect(`${target.pathname}${target.search}`);
|
|
10639
11048
|
}
|
|
10640
11049
|
function createMcpOAuthRouter() {
|
|
10641
|
-
const app = new
|
|
11050
|
+
const app = new Hono25();
|
|
10642
11051
|
app.get("/oauth/:provider/start", async (c) => {
|
|
10643
11052
|
const auth = c.get("auth");
|
|
10644
11053
|
if (auth.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
@@ -10765,7 +11174,7 @@ function createMcpOAuthRouter() {
|
|
|
10765
11174
|
}
|
|
10766
11175
|
|
|
10767
11176
|
// ../api/src/dashboard/mcp-routes.ts
|
|
10768
|
-
import { Hono as
|
|
11177
|
+
import { Hono as Hono26 } from "hono";
|
|
10769
11178
|
|
|
10770
11179
|
// ../api/src/mcp/transport.ts
|
|
10771
11180
|
var KINDS = ["inherit", "npx", "local", "http", "sse"];
|
|
@@ -10895,7 +11304,7 @@ function bindingsByConnection() {
|
|
|
10895
11304
|
return map;
|
|
10896
11305
|
}
|
|
10897
11306
|
function createMcpRouter() {
|
|
10898
|
-
const app = new
|
|
11307
|
+
const app = new Hono26();
|
|
10899
11308
|
app.get("/providers", async (c) => {
|
|
10900
11309
|
const denied = requireAdmin(c.get("auth"));
|
|
10901
11310
|
if (denied) return c.json({ error: denied }, 403);
|
|
@@ -11170,6 +11579,21 @@ async function latestMainRun(workspace, threadTs) {
|
|
|
11170
11579
|
label: latest.label ?? void 0
|
|
11171
11580
|
};
|
|
11172
11581
|
}
|
|
11582
|
+
async function threadRuns(workspace, threadTs) {
|
|
11583
|
+
const rows = await fetchUsageRows(workspace, { threadTs });
|
|
11584
|
+
return rows.sort((a, b) => a.ran_at.localeCompare(b.ran_at)).map((r) => ({
|
|
11585
|
+
ranAt: r.ran_at,
|
|
11586
|
+
model: r.model ?? void 0,
|
|
11587
|
+
label: r.label ?? void 0,
|
|
11588
|
+
numTurns: r.num_turns ?? void 0,
|
|
11589
|
+
inputTokens: r.input_tokens,
|
|
11590
|
+
outputTokens: r.output_tokens,
|
|
11591
|
+
cacheReadTokens: r.cache_read_tokens,
|
|
11592
|
+
cacheCreationTokens: r.cache_creation_tokens,
|
|
11593
|
+
costUsd: Number(r.cost_usd),
|
|
11594
|
+
isError: r.is_error
|
|
11595
|
+
}));
|
|
11596
|
+
}
|
|
11173
11597
|
|
|
11174
11598
|
// ../api/src/dashboard/usage-report.ts
|
|
11175
11599
|
import { existsSync as existsSync17 } from "fs";
|
|
@@ -11311,10 +11735,108 @@ async function buildThreadUsage(threadTs) {
|
|
|
11311
11735
|
}
|
|
11312
11736
|
}
|
|
11313
11737
|
|
|
11738
|
+
// ../api/src/dashboard/session-retro.ts
|
|
11739
|
+
var MAX_REPLY_CHARS2 = 600;
|
|
11740
|
+
var MAX_TRANSCRIPT_CHARS = 24e3;
|
|
11741
|
+
var MAX_ACTIVITIES_PER_REPLY = 40;
|
|
11742
|
+
var MAX_ITEMS = 3;
|
|
11743
|
+
var SYSTEM_PROMPT2 = `You review how an AI coding agent spent money in one chat thread and coach the user on doing it cheaper next time. Reply with JSON only, no code fence:
|
|
11744
|
+
{"headline": string, "items": [{"problem": string, "detail": string, "fix": string}]}
|
|
11745
|
+
|
|
11746
|
+
- headline: one sentence on the overall picture (was the spend reasonable for the work done?).
|
|
11747
|
+
- items: at most ${MAX_ITEMS}, the biggest cost drivers you can support from the data, each paired with the one thing the USER can do about it. Examples: the same file or log read repeatedly (fix: ask for a summary or the relevant lines), a long thread that switched topics (fix: start a new thread per topic), returning after a long idle gap so the cache went cold (fix: start a new thread instead of resuming), failed runs retried.
|
|
11748
|
+
- Only habits the user controls. Never mention billing, pricing, cost accounting or the app's own bugs, even if the transcript discusses them: the thread's topic is not a cost driver. Never suggest switching models; the user does not pick the model per turn.
|
|
11749
|
+
- cache_read and context_total are summed over every API call inside one run (turns=N), so a large figure means many steps, not a huge context. Do not call it context size.
|
|
11750
|
+
- Be brief: problem at most 6 words, detail one short clause with a number from the data (at most 15 words), fix one short imperative clause (at most 12 words).
|
|
11751
|
+
- Write headline, problem, detail and fix entirely in the output language given in the user message, whatever language the transcript is in. For Traditional Chinese (zh-TW), use Taiwan wording, full-width punctuation, Arabic numerals, and keep technical terms in English.
|
|
11752
|
+
- Never use em dashes or en dashes. No Markdown.`;
|
|
11753
|
+
function runLine(r, i) {
|
|
11754
|
+
const ctx = r.inputTokens + r.cacheReadTokens + r.cacheCreationTokens;
|
|
11755
|
+
return `#${i + 1} ${r.ranAt} model=${r.model ?? "?"}${r.label ? ` label=${r.label}` : ""} turns=${r.numTurns ?? "?"} input=${r.inputTokens} cache_read=${r.cacheReadTokens} cache_write=${r.cacheCreationTokens} output=${r.outputTokens} context_total=${ctx} cost=$${r.costUsd.toFixed(3)}${r.isError ? " FAILED" : ""}`;
|
|
11756
|
+
}
|
|
11757
|
+
function transcriptOf(rows) {
|
|
11758
|
+
const parts = rows.map((r) => {
|
|
11759
|
+
const body = r.body.length > MAX_REPLY_CHARS2 ? `${r.body.slice(0, MAX_REPLY_CHARS2)}\u2026` : r.body;
|
|
11760
|
+
const acts = (r.activities ?? []).slice(0, MAX_ACTIVITIES_PER_REPLY).map((a) => ` - ${a.tool ?? "?"}: ${(a.label ?? "").slice(0, 160)}`);
|
|
11761
|
+
const more = (r.activities?.length ?? 0) > MAX_ACTIVITIES_PER_REPLY ? [` - (+${r.activities.length - MAX_ACTIVITIES_PER_REPLY} more tool calls)`] : [];
|
|
11762
|
+
return [`${r.author}: ${body}`, ...acts.length ? [" tool calls:", ...acts, ...more] : []].join("\n");
|
|
11763
|
+
});
|
|
11764
|
+
const text = parts.join("\n\n");
|
|
11765
|
+
return text.length > MAX_TRANSCRIPT_CHARS ? `\u2026${text.slice(-MAX_TRANSCRIPT_CHARS)}` : text;
|
|
11766
|
+
}
|
|
11767
|
+
function clean(s, max) {
|
|
11768
|
+
if (typeof s !== "string") return "";
|
|
11769
|
+
return s.replace(/\s*[–—]\s*/g, ", ").trim().slice(0, max);
|
|
11770
|
+
}
|
|
11771
|
+
function items(v) {
|
|
11772
|
+
if (!Array.isArray(v)) return [];
|
|
11773
|
+
return v.map((i) => ({
|
|
11774
|
+
problem: clean(i?.problem, 80),
|
|
11775
|
+
detail: clean(i?.detail, 300),
|
|
11776
|
+
fix: clean(i?.fix, 200)
|
|
11777
|
+
})).filter((i) => i.problem && i.fix).slice(0, MAX_ITEMS);
|
|
11778
|
+
}
|
|
11779
|
+
function parseJson(raw) {
|
|
11780
|
+
const start = raw.indexOf("{");
|
|
11781
|
+
const end = raw.lastIndexOf("}");
|
|
11782
|
+
if (start < 0 || end <= start) return null;
|
|
11783
|
+
try {
|
|
11784
|
+
return JSON.parse(raw.slice(start, end + 1));
|
|
11785
|
+
} catch {
|
|
11786
|
+
return null;
|
|
11787
|
+
}
|
|
11788
|
+
}
|
|
11789
|
+
async function buildSessionRetro(threadId, complete, locale = "en") {
|
|
11790
|
+
const runs2 = await threadRuns(getProfile(), threadId);
|
|
11791
|
+
if (runs2.length === 0) return null;
|
|
11792
|
+
const { data, error: error2 } = await getSupabaseClient().from("thread_replies").select("author, body, activities").eq("thread_id", threadId).is("archived_at", null).order("created_at", { ascending: true });
|
|
11793
|
+
if (error2) throw new Error(error2.message);
|
|
11794
|
+
const costUsd = runs2.reduce((s, r) => s + r.costUsd, 0);
|
|
11795
|
+
const inputSide = runs2.reduce((s, r) => s + r.inputTokens + r.cacheReadTokens + r.cacheCreationTokens, 0);
|
|
11796
|
+
const cacheRead = runs2.reduce((s, r) => s + r.cacheReadTokens, 0);
|
|
11797
|
+
const cacheReadShare = inputSide ? cacheRead / inputSide : 0;
|
|
11798
|
+
const breakdown2 = { cacheRead: 0, cacheWrite: 0, input: 0, output: 0 };
|
|
11799
|
+
for (const r of runs2) {
|
|
11800
|
+
const card = resolveRateCard(r.model, new Date(r.ranAt));
|
|
11801
|
+
if (card) for (const l of explainCost(r, card)) breakdown2[l.kind] += l.costUsd;
|
|
11802
|
+
}
|
|
11803
|
+
const { data: thread } = await getSupabaseClient().from("threads").select("channel_id").eq("id", threadId).maybeSingle();
|
|
11804
|
+
if (!thread?.channel_id) return null;
|
|
11805
|
+
const result = await complete({
|
|
11806
|
+
channelId: thread.channel_id,
|
|
11807
|
+
tier: "cheap",
|
|
11808
|
+
system: SYSTEM_PROMPT2,
|
|
11809
|
+
user: `Output language: ${locale}
|
|
11810
|
+
|
|
11811
|
+
Total: $${costUsd.toFixed(2)} over ${runs2.length} runs.
|
|
11812
|
+
|
|
11813
|
+
Runs (oldest first):
|
|
11814
|
+
${runs2.map(runLine).join("\n")}
|
|
11815
|
+
|
|
11816
|
+
Transcript with tool calls (oldest first):
|
|
11817
|
+
${transcriptOf(data ?? [])}`
|
|
11818
|
+
});
|
|
11819
|
+
if (!result) return "host-offline";
|
|
11820
|
+
if (!result.ok) {
|
|
11821
|
+
console.error("Session retro failed:", result.error);
|
|
11822
|
+
return null;
|
|
11823
|
+
}
|
|
11824
|
+
const parsed = parseJson(result.raw);
|
|
11825
|
+
if (!parsed) return null;
|
|
11826
|
+
return {
|
|
11827
|
+
costUsd,
|
|
11828
|
+
runs: runs2.length,
|
|
11829
|
+
cacheReadShare,
|
|
11830
|
+
breakdown: breakdown2,
|
|
11831
|
+
headline: clean(parsed.headline, 300),
|
|
11832
|
+
items: items(parsed.items)
|
|
11833
|
+
};
|
|
11834
|
+
}
|
|
11835
|
+
|
|
11314
11836
|
// ../api/src/dashboard/permission-routes.ts
|
|
11315
|
-
import { Hono as
|
|
11837
|
+
import { Hono as Hono27 } from "hono";
|
|
11316
11838
|
function createPermissionRequestsRouter() {
|
|
11317
|
-
const app = new
|
|
11839
|
+
const app = new Hono27();
|
|
11318
11840
|
app.post("/:id", async (c) => {
|
|
11319
11841
|
const auth = c.get("auth");
|
|
11320
11842
|
if (auth.role !== "admin") return c.json({ error: "only an admin can answer this" }, 403);
|
|
@@ -11344,7 +11866,7 @@ function createPermissionRequestsRouter() {
|
|
|
11344
11866
|
}
|
|
11345
11867
|
|
|
11346
11868
|
// ../api/src/dashboard/channel-greeting.ts
|
|
11347
|
-
import { Hono as
|
|
11869
|
+
import { Hono as Hono28 } from "hono";
|
|
11348
11870
|
function eligible(ch) {
|
|
11349
11871
|
return !!ch && !ch.isDefault && !ch.dmKey && !ch.agentName && !ch.archivedAt;
|
|
11350
11872
|
}
|
|
@@ -11373,7 +11895,7 @@ function introOpening(channelName) {
|
|
|
11373
11895
|
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.`;
|
|
11374
11896
|
}
|
|
11375
11897
|
function createChannelGreetingRouter(agent) {
|
|
11376
|
-
const app = new
|
|
11898
|
+
const app = new Hono28();
|
|
11377
11899
|
app.get("/:id/greeting", async (c) => {
|
|
11378
11900
|
const ctx = await resolveAuthContext(c);
|
|
11379
11901
|
const ch = findChannelById(c.req.param("id"));
|
|
@@ -11431,7 +11953,7 @@ async function ensureIntroThread(ch) {
|
|
|
11431
11953
|
}
|
|
11432
11954
|
|
|
11433
11955
|
// ../api/src/dashboard/channel-suggest.ts
|
|
11434
|
-
import { Hono as
|
|
11956
|
+
import { Hono as Hono29 } from "hono";
|
|
11435
11957
|
var CATEGORY_MAX_CHARS = 16;
|
|
11436
11958
|
var CATEGORY_MAX_ITEMS = 30;
|
|
11437
11959
|
var PROMPT_MAX_CHARS = 4e3;
|
|
@@ -11468,18 +11990,18 @@ function parseSuggestion(field, raw) {
|
|
|
11468
11990
|
const text = raw.replace(/^```[^\n]*\n?|\n?```\s*$/g, "").replace(/\s*[\u2013\u2014]\s*/g, ", ").trim();
|
|
11469
11991
|
if (field === "prompt") return text ? text.slice(0, PROMPT_MAX_CHARS) : null;
|
|
11470
11992
|
const seen = /* @__PURE__ */ new Set();
|
|
11471
|
-
const
|
|
11993
|
+
const items2 = [];
|
|
11472
11994
|
for (const line of text.split("\n")) {
|
|
11473
11995
|
const item = line.replace(/^\s*(?:[-*•]|\d+[.)])\s*/, "").replace(/[`*"[\]]/g, "").trim();
|
|
11474
11996
|
const key = item.toLowerCase();
|
|
11475
11997
|
if (!item || item.length > CATEGORY_MAX_CHARS || seen.has(key)) continue;
|
|
11476
11998
|
seen.add(key);
|
|
11477
|
-
|
|
11999
|
+
items2.push(item);
|
|
11478
12000
|
}
|
|
11479
|
-
return
|
|
12001
|
+
return items2.length ? items2.slice(0, CATEGORY_MAX_ITEMS).join("\n") : null;
|
|
11480
12002
|
}
|
|
11481
12003
|
function createChannelSuggestRouter(agent) {
|
|
11482
|
-
const router = new
|
|
12004
|
+
const router = new Hono29();
|
|
11483
12005
|
router.post("/:id/suggest", async (c) => {
|
|
11484
12006
|
const channel = findChannel(c.req.param("id"));
|
|
11485
12007
|
if (!channel || !canSeeChannel(channel, c.get("auth"))) {
|
|
@@ -11517,7 +12039,7 @@ function createChannelSuggestRouter(agent) {
|
|
|
11517
12039
|
}
|
|
11518
12040
|
|
|
11519
12041
|
// ../api/src/dashboard/channel-members-routes.ts
|
|
11520
|
-
import { Hono as
|
|
12042
|
+
import { Hono as Hono30 } from "hono";
|
|
11521
12043
|
async function isChannelAdmin(ctx, channelId) {
|
|
11522
12044
|
if (ctx.role === "admin") return true;
|
|
11523
12045
|
const membership = await getMembershipByUserId(ctx.workspaceId, ctx.userId);
|
|
@@ -11526,7 +12048,7 @@ async function isChannelAdmin(ctx, channelId) {
|
|
|
11526
12048
|
return members.some((m) => m.membershipId === membership.id && m.role === "channel_admin");
|
|
11527
12049
|
}
|
|
11528
12050
|
function createChannelMembersRouter() {
|
|
11529
|
-
const router = new
|
|
12051
|
+
const router = new Hono30();
|
|
11530
12052
|
router.get("/:id/members", async (c) => {
|
|
11531
12053
|
const ctx = await resolveAuthContext(c);
|
|
11532
12054
|
if (!ctx) return c.json({ error: "workspace access required" }, 403);
|
|
@@ -11596,7 +12118,7 @@ function createChannelMembersRouter() {
|
|
|
11596
12118
|
}
|
|
11597
12119
|
|
|
11598
12120
|
// ../api/src/dashboard/memories-routes.ts
|
|
11599
|
-
import { Hono as
|
|
12121
|
+
import { Hono as Hono31 } from "hono";
|
|
11600
12122
|
async function readPatch(c) {
|
|
11601
12123
|
const body = await c.req.json().catch(() => ({}));
|
|
11602
12124
|
const patch = {};
|
|
@@ -11624,7 +12146,7 @@ var requireAgentMemory = async (c, next) => {
|
|
|
11624
12146
|
await next();
|
|
11625
12147
|
};
|
|
11626
12148
|
function createMemoriesRouter() {
|
|
11627
|
-
const router = new
|
|
12149
|
+
const router = new Hono31();
|
|
11628
12150
|
for (const path of [
|
|
11629
12151
|
"/:id/memories",
|
|
11630
12152
|
"/:id/memories/*",
|
|
@@ -11697,7 +12219,7 @@ function createMemoriesRouter() {
|
|
|
11697
12219
|
return router;
|
|
11698
12220
|
}
|
|
11699
12221
|
function createScopedMemoriesRouter() {
|
|
11700
|
-
const router = new
|
|
12222
|
+
const router = new Hono31();
|
|
11701
12223
|
router.use("*", requireAgentMemory);
|
|
11702
12224
|
const workspace = (c) => ({
|
|
11703
12225
|
scope: "workspace",
|
|
@@ -11757,9 +12279,9 @@ function createScopedMemoriesRouter() {
|
|
|
11757
12279
|
}
|
|
11758
12280
|
|
|
11759
12281
|
// ../api/src/dashboard/session-import-routes.ts
|
|
11760
|
-
import { Hono as
|
|
12282
|
+
import { Hono as Hono32 } from "hono";
|
|
11761
12283
|
var MAX_FOLDERS2 = 20;
|
|
11762
|
-
var
|
|
12284
|
+
var DAY_MS2 = 24 * 60 * 60 * 1e3;
|
|
11763
12285
|
var IMPORT_RANGES = ["all", "7d", "latest5"];
|
|
11764
12286
|
async function ask(agent, req) {
|
|
11765
12287
|
const res = await agent.sessionImportRequest?.(req);
|
|
@@ -11776,7 +12298,7 @@ function hostUnavailable2(c, agent) {
|
|
|
11776
12298
|
}
|
|
11777
12299
|
function pickSessions(sessions2, range, now = Date.now()) {
|
|
11778
12300
|
if (range === "latest5") return sessions2.slice(0, 5);
|
|
11779
|
-
if (range === "7d") return sessions2.filter((s) => s.lastUsed >= now - 7 *
|
|
12301
|
+
if (range === "7d") return sessions2.filter((s) => s.lastUsed >= now - 7 * DAY_MS2);
|
|
11780
12302
|
return sessions2;
|
|
11781
12303
|
}
|
|
11782
12304
|
function channelForFolder(folder, channels) {
|
|
@@ -11863,7 +12385,7 @@ async function syncSession(agent, channelId, session, author, existing) {
|
|
|
11863
12385
|
return messages.length;
|
|
11864
12386
|
}
|
|
11865
12387
|
function createSessionImportRouter(agent) {
|
|
11866
|
-
const app = new
|
|
12388
|
+
const app = new Hono32();
|
|
11867
12389
|
const scanFolders = async () => {
|
|
11868
12390
|
const scan = await ask(agent, { op: "scan", slug: getProfile() });
|
|
11869
12391
|
return scan && importableFolders(scan.folders, getProfileChannelRegistry());
|
|
@@ -11905,15 +12427,15 @@ function createSessionImportRouter(agent) {
|
|
|
11905
12427
|
return c.json({ error: "workspace owner access required to add new folders" }, 403);
|
|
11906
12428
|
}
|
|
11907
12429
|
const taken = new Set(getProfileChannelRegistry().map((ch) => ch.name));
|
|
11908
|
-
const
|
|
12430
|
+
const items2 = needLink.map((p) => ({
|
|
11909
12431
|
name: uniqueChannelName(offered.get(p.path).folder.name, taken),
|
|
11910
12432
|
path: p.path
|
|
11911
12433
|
}));
|
|
11912
|
-
const linked =
|
|
12434
|
+
const linked = items2.length ? await agent.linkProjectFolders?.(getProfile(), items2) : [];
|
|
11913
12435
|
if (!linked) return hostUnavailable2(c, agent);
|
|
11914
12436
|
const created = /* @__PURE__ */ new Map();
|
|
11915
12437
|
for (const [i, l] of linked.entries())
|
|
11916
|
-
created.set(
|
|
12438
|
+
created.set(items2[i].path, await createChannel({ name: l.name, cwd: l.cwd }));
|
|
11917
12439
|
const results = [];
|
|
11918
12440
|
for (const p of picks) {
|
|
11919
12441
|
const { folder, channel: existing } = offered.get(p.path);
|
|
@@ -12017,9 +12539,9 @@ function channelLabel(channel) {
|
|
|
12017
12539
|
return channel.startsWith("#") ? channel : `#${channel}`;
|
|
12018
12540
|
}
|
|
12019
12541
|
var THREAD_ID_CHUNK = 100;
|
|
12020
|
-
function chunk2(
|
|
12542
|
+
function chunk2(items2, size) {
|
|
12021
12543
|
const out = [];
|
|
12022
|
-
for (let i = 0; i <
|
|
12544
|
+
for (let i = 0; i < items2.length; i += size) out.push(items2.slice(i, i + size));
|
|
12023
12545
|
return out;
|
|
12024
12546
|
}
|
|
12025
12547
|
async function fetchThreadRows(column, values) {
|
|
@@ -12131,7 +12653,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12131
12653
|
categoryId: ch.categoryId,
|
|
12132
12654
|
position: ch.position,
|
|
12133
12655
|
// A DM is stored as "<a>, <b>"; each side sees the other's handle.
|
|
12134
|
-
name: ch.dmKey ? ch.name.split(", ").filter((h) => h !== auth.handle).join(", ") || ch.name : ch.name,
|
|
12656
|
+
name: ch.dmKey && !ch.agentName ? ch.name.split(", ").filter((h) => h !== auth.handle).join(", ") || ch.name : ch.name,
|
|
12135
12657
|
configured: true,
|
|
12136
12658
|
cwd: ch.cwd,
|
|
12137
12659
|
// Surfaces a rotted working directory in the sidebar instead of
|
|
@@ -12269,8 +12791,22 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12269
12791
|
if (!await isFeatureEnabled(c, "ai-cost")) return c.json({ error: "feature not enabled" }, 403);
|
|
12270
12792
|
return c.json(await buildThreadUsage(c.req.param("threadTs")));
|
|
12271
12793
|
});
|
|
12794
|
+
api.post("/usage/threads/:threadTs/retro", async (c) => {
|
|
12795
|
+
const ctx = await resolveAuthContext(c);
|
|
12796
|
+
if (ctx?.role !== "admin") return c.json({ error: "admin access required" }, 403);
|
|
12797
|
+
if (!await isFeatureEnabled(c, "session-retro")) return c.json({ error: "feature not enabled" }, 403);
|
|
12798
|
+
const complete = agent.completeMemoryExtraction;
|
|
12799
|
+
if (!complete) return c.json({ error: "host offline" }, 503);
|
|
12800
|
+
const body = await c.req.json().catch(() => ({}));
|
|
12801
|
+
const locale = typeof body.locale === "string" && /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(body.locale) ? body.locale : "en";
|
|
12802
|
+
const retro = await buildSessionRetro(c.req.param("threadTs"), complete, locale);
|
|
12803
|
+
if (retro === "host-offline") return c.json({ error: "host offline" }, 503);
|
|
12804
|
+
if (!retro) return c.json({ error: "could not generate a retro" }, 502);
|
|
12805
|
+
return c.json(retro);
|
|
12806
|
+
});
|
|
12272
12807
|
api.route("/automations", createAutomationWriteRouter());
|
|
12273
12808
|
api.route("/billing", createBillingRouter());
|
|
12809
|
+
api.route("/chat", createContinuousChatRouter());
|
|
12274
12810
|
api.route("/chat", createChatRouter(agent));
|
|
12275
12811
|
api.route("/search", createSearchRouter());
|
|
12276
12812
|
api.use("/tts/*", async (c, next) => {
|
|
@@ -12358,6 +12894,8 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12358
12894
|
api.route("/", createUploadsRouter());
|
|
12359
12895
|
api.route("/", createTranscribeRouter());
|
|
12360
12896
|
api.route("/", createAutocompleteRouter());
|
|
12897
|
+
api.route("/", createDailyLineRouter());
|
|
12898
|
+
api.route("/", createChannelRouteRouter());
|
|
12361
12899
|
api.route("/", createAvatarsRouter());
|
|
12362
12900
|
api.get("/profiles", async (c) => {
|
|
12363
12901
|
const active = getProfile();
|
|
@@ -12367,7 +12905,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12367
12905
|
const running2 = new Set(await agent.listRunningProfiles?.() ?? []);
|
|
12368
12906
|
const auth = c.get("auth");
|
|
12369
12907
|
const [{ data: memberships }, workspaces] = await Promise.all([
|
|
12370
|
-
getSupabaseClient().from("memberships").select("workspace_id").eq("user_id", auth.userId),
|
|
12908
|
+
getSupabaseClient().from("memberships").select("workspace_id").eq("user_id", auth.userId).eq("status", "active").eq("is_support", false),
|
|
12371
12909
|
listWorkspaces()
|
|
12372
12910
|
]);
|
|
12373
12911
|
const memberOf = new Set(
|
|
@@ -12455,7 +12993,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12455
12993
|
// ../api/src/dashboard/device-auth-routes.ts
|
|
12456
12994
|
import { verify } from "crypto";
|
|
12457
12995
|
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
12458
|
-
import { Hono as
|
|
12996
|
+
import { Hono as Hono33 } from "hono";
|
|
12459
12997
|
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12460
12998
|
function cleanText(value, max) {
|
|
12461
12999
|
if (typeof value !== "string") return null;
|
|
@@ -12503,7 +13041,7 @@ async function boundWorkspaceIds(publicKey, userId) {
|
|
|
12503
13041
|
return new Set(existing ? (await listDeviceWorkspaces(existing)).map((w) => w.id) : []);
|
|
12504
13042
|
}
|
|
12505
13043
|
function createDeviceAuthRouter() {
|
|
12506
|
-
const app = new
|
|
13044
|
+
const app = new Hono33();
|
|
12507
13045
|
app.post("/code", async (c) => {
|
|
12508
13046
|
const body = await readBody(c);
|
|
12509
13047
|
const publicKey = typeof body["public_key"] === "string" ? body["public_key"] : "";
|
|
@@ -12822,7 +13360,7 @@ var workspaceRef = () => ({ kind: "workspace" });
|
|
|
12822
13360
|
var channelRef = (c) => ({ kind: "channel", channelId: c.req.param("id") });
|
|
12823
13361
|
|
|
12824
13362
|
// ../api/src/dashboard/output-styles-routes.ts
|
|
12825
|
-
import { Hono as
|
|
13363
|
+
import { Hono as Hono34 } from "hono";
|
|
12826
13364
|
function requireAdmin3(auth) {
|
|
12827
13365
|
return auth?.role === "admin" ? null : "admin access required";
|
|
12828
13366
|
}
|
|
@@ -12842,7 +13380,7 @@ function failure(c, err) {
|
|
|
12842
13380
|
return c.json({ error: message }, err instanceof OutputStyleConflictError ? 409 : 500);
|
|
12843
13381
|
}
|
|
12844
13382
|
function createOutputStylesRouter() {
|
|
12845
|
-
const app = new
|
|
13383
|
+
const app = new Hono34();
|
|
12846
13384
|
app.get("/", (c) => {
|
|
12847
13385
|
const auth = c.get("auth");
|
|
12848
13386
|
const denied = requireAdmin3(auth);
|
|
@@ -12934,7 +13472,7 @@ function createOutputStylesRouter() {
|
|
|
12934
13472
|
return app;
|
|
12935
13473
|
}
|
|
12936
13474
|
async function handleOutputStylesRequest(req) {
|
|
12937
|
-
const app = new
|
|
13475
|
+
const app = new Hono34();
|
|
12938
13476
|
app.use("*", async (c, next) => {
|
|
12939
13477
|
c.set("auth", { role: "admin" });
|
|
12940
13478
|
await next();
|
|
@@ -12972,15 +13510,12 @@ async function viewerProfile(c, known) {
|
|
|
12972
13510
|
return null;
|
|
12973
13511
|
}
|
|
12974
13512
|
function createGatedRouter(agent, register) {
|
|
12975
|
-
const api = new
|
|
13513
|
+
const api = new Hono35();
|
|
12976
13514
|
api.use("*", async (c, next) => {
|
|
12977
13515
|
const known = await listKnownWorkspaces();
|
|
12978
13516
|
const fromHost = profileFromHost(trustedHost(c), known);
|
|
12979
13517
|
const requested = c.req.query("workspace");
|
|
12980
|
-
if (requested)
|
|
12981
|
-
if (known.includes(requested)) return runWithProfile(requested, () => next());
|
|
12982
|
-
if (!fromHost) return c.json({ error: `unknown profile: ${requested}` }, 400);
|
|
12983
|
-
}
|
|
13518
|
+
if (requested && known.includes(requested)) return runWithProfile(requested, () => next());
|
|
12984
13519
|
if (fromHost) return runWithProfile(fromHost, () => next());
|
|
12985
13520
|
const viewer = await viewerProfile(c, known);
|
|
12986
13521
|
return viewer ? runWithProfile(viewer, () => next()) : next();
|
|
@@ -13027,7 +13562,7 @@ import sharp5 from "sharp";
|
|
|
13027
13562
|
|
|
13028
13563
|
// src/dashboard/channels-routes.ts
|
|
13029
13564
|
import { existsSync as existsSync20, mkdirSync as mkdirSync9 } from "fs";
|
|
13030
|
-
import { Hono as
|
|
13565
|
+
import { Hono as Hono36 } from "hono";
|
|
13031
13566
|
function coerceAccess(raw) {
|
|
13032
13567
|
if (raw === "open" || raw === "*" || raw === "all") return raw;
|
|
13033
13568
|
if (Array.isArray(raw) && raw.every((v) => typeof v === "string")) return raw;
|
|
@@ -13099,7 +13634,7 @@ function toResponse3(channel) {
|
|
|
13099
13634
|
};
|
|
13100
13635
|
}
|
|
13101
13636
|
function createChannelWriteRouter() {
|
|
13102
|
-
const app = new
|
|
13637
|
+
const app = new Hono36();
|
|
13103
13638
|
app.post("/", async (c) => {
|
|
13104
13639
|
const body = await c.req.json().catch(() => ({}));
|
|
13105
13640
|
const name = typeof body["name"] === "string" ? body["name"].trim() : "";
|
|
@@ -13228,7 +13763,7 @@ function createChannelWriteRouter() {
|
|
|
13228
13763
|
// src/dashboard/skills-routes-host.ts
|
|
13229
13764
|
import { existsSync as existsSync21, statSync as statSync4 } from "fs";
|
|
13230
13765
|
import { dirname as dirname8 } from "path";
|
|
13231
|
-
import { Hono as
|
|
13766
|
+
import { Hono as Hono37 } from "hono";
|
|
13232
13767
|
function workspaceScope() {
|
|
13233
13768
|
const claudeConfigDir = profileClaudeConfigDir();
|
|
13234
13769
|
const cwd = defaultClaudeCwd();
|
|
@@ -13334,35 +13869,32 @@ var diskBackend = {
|
|
|
13334
13869
|
write: writeSkillAndSync
|
|
13335
13870
|
};
|
|
13336
13871
|
function createWorkspaceSkillsRouter() {
|
|
13337
|
-
const app = new
|
|
13872
|
+
const app = new Hono37();
|
|
13338
13873
|
mountSkillRoutes(app, "/skills", workspaceRef, diskBackend);
|
|
13339
13874
|
return app;
|
|
13340
13875
|
}
|
|
13341
13876
|
function createChannelSkillsRouter() {
|
|
13342
|
-
const app = new
|
|
13877
|
+
const app = new Hono37();
|
|
13343
13878
|
mountSkillRoutes(app, "/:id/skill-files", channelRef, diskBackend);
|
|
13344
13879
|
return app;
|
|
13345
13880
|
}
|
|
13346
13881
|
|
|
13347
13882
|
// src/dashboard/agent-identities-host.ts
|
|
13348
|
-
async function resolveAgentIdentities() {
|
|
13883
|
+
async function resolveAgentIdentities(viewer) {
|
|
13349
13884
|
const settings = loadDashboardSettings();
|
|
13350
|
-
const { cwd: defaultCwd } = resolveChannelConfig("");
|
|
13351
13885
|
const main2 = [
|
|
13352
13886
|
{
|
|
13353
13887
|
name: BOT_DM_KEY,
|
|
13354
13888
|
label: BOT_LABEL,
|
|
13355
13889
|
kind: "main",
|
|
13356
|
-
cwd: defaultCwd,
|
|
13357
13890
|
model: settings.agentProfiles?.[BOT_DM_KEY]?.model,
|
|
13358
13891
|
...await loadBotIdentity()
|
|
13359
13892
|
}
|
|
13360
13893
|
];
|
|
13361
13894
|
return Promise.all(
|
|
13362
|
-
main2.map(async (
|
|
13363
|
-
const dm = await ensureAgentDmChannel(agent.name, {
|
|
13364
|
-
name: agent.displayName ?? agent.label
|
|
13365
|
-
cwd
|
|
13895
|
+
main2.map(async (agent) => {
|
|
13896
|
+
const dm = await ensureAgentDmChannel(agent.name, viewer, {
|
|
13897
|
+
name: agent.displayName ?? agent.label
|
|
13366
13898
|
});
|
|
13367
13899
|
return { ...agent, channelId: dm.id };
|
|
13368
13900
|
})
|
|
@@ -13379,9 +13911,9 @@ var PROVIDER_LABELS = {
|
|
|
13379
13911
|
codex: "Codex"
|
|
13380
13912
|
};
|
|
13381
13913
|
var TTL_MS2 = 6e4;
|
|
13382
|
-
var
|
|
13914
|
+
var cache4 = /* @__PURE__ */ new Map();
|
|
13383
13915
|
function clearProviderStatusCache() {
|
|
13384
|
-
|
|
13916
|
+
cache4.clear();
|
|
13385
13917
|
}
|
|
13386
13918
|
function binaryOnPath(bin) {
|
|
13387
13919
|
try {
|
|
@@ -13459,11 +13991,11 @@ function withAuthFailure(status) {
|
|
|
13459
13991
|
}
|
|
13460
13992
|
function providerStatuses() {
|
|
13461
13993
|
const key = getProfile();
|
|
13462
|
-
const hit =
|
|
13994
|
+
const hit = cache4.get(key);
|
|
13463
13995
|
let statuses = hit && Date.now() - hit.at < TTL_MS2 ? hit.statuses : void 0;
|
|
13464
13996
|
if (!statuses) {
|
|
13465
13997
|
statuses = ["claude", "codex"].map(probe2);
|
|
13466
|
-
|
|
13998
|
+
cache4.set(key, { at: Date.now(), statuses });
|
|
13467
13999
|
}
|
|
13468
14000
|
return statuses.map((st) => st.runner === "claude" && st.connected ? withAuthFailure(st) : st);
|
|
13469
14001
|
}
|
|
@@ -13474,7 +14006,7 @@ import { randomUUID as randomUUID4 } from "crypto";
|
|
|
13474
14006
|
import { chmodSync, existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as readFileSync16, writeFileSync as writeFileSync9 } from "fs";
|
|
13475
14007
|
import { createRequire } from "module";
|
|
13476
14008
|
import { dirname as dirname9, join as join15 } from "path";
|
|
13477
|
-
import { Hono as
|
|
14009
|
+
import { Hono as Hono38 } from "hono";
|
|
13478
14010
|
var SESSION_TTL_MS = 10 * 6e4;
|
|
13479
14011
|
var URL_WAIT_MS = 3e4;
|
|
13480
14012
|
var TOKEN_WAIT_MS = 6e4;
|
|
@@ -13633,7 +14165,7 @@ function failure2(c, err) {
|
|
|
13633
14165
|
return c.json({ error: err.message }, 500);
|
|
13634
14166
|
}
|
|
13635
14167
|
function createProviderLoginRouter() {
|
|
13636
|
-
const app = new
|
|
14168
|
+
const app = new Hono38();
|
|
13637
14169
|
app.use("*", async (c, next) => {
|
|
13638
14170
|
const denied = requireAdmin4(c.get("auth"));
|
|
13639
14171
|
if (denied) return c.json({ error: denied }, 403);
|
|
@@ -13677,7 +14209,7 @@ function createProviderLoginRouter() {
|
|
|
13677
14209
|
return app;
|
|
13678
14210
|
}
|
|
13679
14211
|
async function handleProviderLoginRequest(req) {
|
|
13680
|
-
const app = new
|
|
14212
|
+
const app = new Hono38();
|
|
13681
14213
|
app.use("*", async (c, next) => {
|
|
13682
14214
|
c.set("auth", { role: "admin" });
|
|
13683
14215
|
await next();
|
|
@@ -13762,7 +14294,11 @@ function registerHostRoutes(api) {
|
|
|
13762
14294
|
"/settings/bot",
|
|
13763
14295
|
async (c) => c.json({ name: BOT_PROFILE_KEY, label: "Workspace Agent", ...await loadBotIdentity() })
|
|
13764
14296
|
);
|
|
13765
|
-
api.get("/settings/agents", async (c) =>
|
|
14297
|
+
api.get("/settings/agents", async (c) => {
|
|
14298
|
+
const viewer = await agentViewer(c);
|
|
14299
|
+
if (!viewer) return c.json({ error: "not signed in" }, 401);
|
|
14300
|
+
return c.json({ agents: await resolveAgentIdentities(viewer) });
|
|
14301
|
+
});
|
|
13766
14302
|
api.put("/settings/agents/:name", async (c) => {
|
|
13767
14303
|
const body = await c.req.json().catch(() => ({}));
|
|
13768
14304
|
const displayName = body["displayName"] === null || typeof body["displayName"] === "string" ? body["displayName"] : void 0;
|
|
@@ -14047,15 +14583,15 @@ function readSessionMessages(agent, sessionId, afterUuid) {
|
|
|
14047
14583
|
const idx = messages.findIndex((m) => m.uuid === afterUuid);
|
|
14048
14584
|
return idx === -1 ? [] : messages.slice(idx + 1);
|
|
14049
14585
|
}
|
|
14050
|
-
function bindSessions(
|
|
14586
|
+
function bindSessions(items2) {
|
|
14051
14587
|
const store = new SessionStore(paths.DB_FILE);
|
|
14052
14588
|
try {
|
|
14053
|
-
for (const i of
|
|
14589
|
+
for (const i of items2)
|
|
14054
14590
|
store.saveSession(`chat:${i.channelId}`, i.threadId, i.sessionId, i.agent);
|
|
14055
14591
|
} finally {
|
|
14056
14592
|
store.close();
|
|
14057
14593
|
}
|
|
14058
|
-
return
|
|
14594
|
+
return items2.length;
|
|
14059
14595
|
}
|
|
14060
14596
|
function handleSessionImportRequest(req) {
|
|
14061
14597
|
switch (req.op) {
|
|
@@ -14069,13 +14605,13 @@ function handleSessionImportRequest(req) {
|
|
|
14069
14605
|
}
|
|
14070
14606
|
|
|
14071
14607
|
// src/dashboard/docs-relay-host.ts
|
|
14072
|
-
import { Hono as
|
|
14608
|
+
import { Hono as Hono39 } from "hono";
|
|
14073
14609
|
var RETURNED_HEADERS = ["content-type", "content-disposition", "content-security-policy", "cache-control"];
|
|
14074
14610
|
async function handleDocsRequest(req) {
|
|
14075
14611
|
return runRelayed(req, (app) => app.route("/channels", createDocsRouter({ gate: async (_c, next) => next() })));
|
|
14076
14612
|
}
|
|
14077
14613
|
async function runRelayed(req, register) {
|
|
14078
|
-
const app = new
|
|
14614
|
+
const app = new Hono39();
|
|
14079
14615
|
app.use("*", async (c, next) => {
|
|
14080
14616
|
c.set("auth", req.auth);
|
|
14081
14617
|
await next();
|
|
@@ -14450,7 +14986,7 @@ function localAgentCallbacks(chatAgent) {
|
|
|
14450
14986
|
suggestChannelField: (req) => suggestChannelField(req),
|
|
14451
14987
|
listMissingCwds: () => auditChannelCwds().map((ch) => ch.id),
|
|
14452
14988
|
listRunningProfiles: () => listProfiles().filter(isServiceRunning2),
|
|
14453
|
-
getAgentIdentities: () => resolveAgentIdentities(),
|
|
14989
|
+
getAgentIdentities: (viewer) => resolveAgentIdentities(viewer),
|
|
14454
14990
|
readDocShareBundle: (req) => readDocShareBundle(req.channelId ? { ...req, cwd: resolveChannelConfig(req.channelId).cwd } : req),
|
|
14455
14991
|
listChannelSkills: (args) => {
|
|
14456
14992
|
const { cwd, claudeConfigDir } = args.channelId ? resolveChannelConfig(args.channelId) : args;
|
|
@@ -14468,7 +15004,7 @@ function localAgentCallbacks(chatAgent) {
|
|
|
14468
15004
|
listMcpServers: () => listMcpServers(),
|
|
14469
15005
|
upgradeHost: () => startHostUpgrade(),
|
|
14470
15006
|
scanOnboarding: (slug) => scanOnboarding(slug),
|
|
14471
|
-
linkProjectFolders: (slug,
|
|
15007
|
+
linkProjectFolders: (slug, items2) => linkProjectFolders(slug, items2),
|
|
14472
15008
|
sessionImportRequest: (req) => handleSessionImportRequest(req),
|
|
14473
15009
|
isHostOnline: () => true,
|
|
14474
15010
|
getHostCliVersion: () => CLI_VERSION,
|
|
@@ -14669,8 +15205,8 @@ import { join as join18 } from "path";
|
|
|
14669
15205
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
14670
15206
|
|
|
14671
15207
|
// ../api/src/dashboard/app-icon-routes.ts
|
|
14672
|
-
import { Hono as
|
|
14673
|
-
var
|
|
15208
|
+
import { Hono as Hono40 } from "hono";
|
|
15209
|
+
var MANIFEST = {
|
|
14674
15210
|
id: "/",
|
|
14675
15211
|
name: "Flyspace",
|
|
14676
15212
|
short_name: "Flyspace",
|
|
@@ -14702,17 +15238,9 @@ async function resolvedProfileHost(c) {
|
|
|
14702
15238
|
if (requested && known.includes(requested)) return requested;
|
|
14703
15239
|
return profileFromHost(trustedHost(c), known);
|
|
14704
15240
|
}
|
|
14705
|
-
async function withResolvedProfile2(c, next) {
|
|
14706
|
-
const profile = await resolvedProfileHost(c);
|
|
14707
|
-
return profile ? runWithProfile(profile, () => next()) : next();
|
|
14708
|
-
}
|
|
14709
15241
|
function createAppIconRouter() {
|
|
14710
|
-
const app = new
|
|
14711
|
-
app.get("/manifest.json",
|
|
14712
|
-
if (!await resolvedProfileHost(c)) return c.json(NEUTRAL_MANIFEST);
|
|
14713
|
-
const profile = getProfile();
|
|
14714
|
-
return c.json(buildManifest(profile, (await loadWorkspaceBranding()).displayName));
|
|
14715
|
-
});
|
|
15242
|
+
const app = new Hono40();
|
|
15243
|
+
app.get("/manifest.json", (c) => c.json(MANIFEST));
|
|
14716
15244
|
app.get("/icons/app/:profile/:file", async (c) => {
|
|
14717
15245
|
const profile = c.req.param("profile");
|
|
14718
15246
|
if (!(await listKnownWorkspaces()).includes(profile)) return c.text("unknown profile", 404);
|
|
@@ -14726,11 +15254,14 @@ function createAppIconRouter() {
|
|
|
14726
15254
|
const size = LINKED_ICONS[file];
|
|
14727
15255
|
if (!size) return next();
|
|
14728
15256
|
const transparent = file.startsWith("favicon-");
|
|
14729
|
-
const profile = await resolvedProfileHost(c);
|
|
15257
|
+
const profile = transparent ? await resolvedProfileHost(c) : null;
|
|
14730
15258
|
if (!profile) {
|
|
14731
15259
|
return pngResponse(c, await renderAppIcon({ size, stock: true, transparent }));
|
|
14732
15260
|
}
|
|
14733
|
-
return pngResponse(
|
|
15261
|
+
return pngResponse(
|
|
15262
|
+
c,
|
|
15263
|
+
await runWithProfile(profile, () => renderAppIcon({ size, transparent }))
|
|
15264
|
+
);
|
|
14734
15265
|
});
|
|
14735
15266
|
return app;
|
|
14736
15267
|
}
|
|
@@ -14786,9 +15317,49 @@ The JSON API is live under /api.` : "This install has no bundled Workspace UI.\n
|
|
|
14786
15317
|
});
|
|
14787
15318
|
}
|
|
14788
15319
|
|
|
15320
|
+
// src/dashboard/host-log-file.ts
|
|
15321
|
+
import { createWriteStream, fstatSync, mkdirSync as mkdirSync12, statSync as statSync7 } from "fs";
|
|
15322
|
+
import { join as join19 } from "path";
|
|
15323
|
+
var STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
15324
|
+
function stamp(text) {
|
|
15325
|
+
const ts2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
15326
|
+
return text.split("\n").map((line, i, all) => i === all.length - 1 && line === "" || STAMPED.test(line) ? line : `[${ts2}] ${line}`).join("\n");
|
|
15327
|
+
}
|
|
15328
|
+
function alreadyRedirected(fd, file) {
|
|
15329
|
+
try {
|
|
15330
|
+
const a = fstatSync(fd);
|
|
15331
|
+
const b = statSync7(file);
|
|
15332
|
+
return a.dev === b.dev && a.ino === b.ino;
|
|
15333
|
+
} catch {
|
|
15334
|
+
return false;
|
|
15335
|
+
}
|
|
15336
|
+
}
|
|
15337
|
+
function tee(stream, fd, file) {
|
|
15338
|
+
if (alreadyRedirected(fd, file)) return;
|
|
15339
|
+
const out = createWriteStream(file, { flags: "a" });
|
|
15340
|
+
out.on("error", () => {
|
|
15341
|
+
});
|
|
15342
|
+
const write = stream.write.bind(stream);
|
|
15343
|
+
stream.write = ((chunk3, ...rest) => {
|
|
15344
|
+
const text = typeof chunk3 === "string" ? chunk3 : Buffer.from(chunk3).toString("utf8");
|
|
15345
|
+
out.write(stamp(text));
|
|
15346
|
+
return write(chunk3, ...rest);
|
|
15347
|
+
});
|
|
15348
|
+
}
|
|
15349
|
+
function ensureHostLogFiles() {
|
|
15350
|
+
try {
|
|
15351
|
+
mkdirSync12(paths.LOG_DIR, { recursive: true });
|
|
15352
|
+
} catch {
|
|
15353
|
+
return;
|
|
15354
|
+
}
|
|
15355
|
+
tee(process.stdout, 1, join19(paths.LOG_DIR, "host.log"));
|
|
15356
|
+
tee(process.stderr, 2, join19(paths.LOG_DIR, "host-error.log"));
|
|
15357
|
+
}
|
|
15358
|
+
|
|
14789
15359
|
// src/dashboard/host-dashboard.ts
|
|
14790
15360
|
async function startHostDashboard(preferredPort, host) {
|
|
14791
15361
|
loadEnvFiles();
|
|
15362
|
+
ensureHostLogFiles();
|
|
14792
15363
|
let lateCallbacks;
|
|
14793
15364
|
let onHostConnected;
|
|
14794
15365
|
const bootCallbacks = new Proxy({}, {
|
|
@@ -14908,8 +15479,8 @@ function openBrowser2(url) {
|
|
|
14908
15479
|
}
|
|
14909
15480
|
}
|
|
14910
15481
|
function ensureWebBuild() {
|
|
14911
|
-
if (existsSync28(
|
|
14912
|
-
if (!existsSync28(
|
|
15482
|
+
if (existsSync28(join20(paths.WEB_ROOT, "dist", "index.html"))) return;
|
|
15483
|
+
if (!existsSync28(join20(paths.WEB_ROOT, "package.json"))) return;
|
|
14913
15484
|
console.log(" packages/ui/dist missing, building the dashboard UI...");
|
|
14914
15485
|
const result = spawnSync("pnpm", ["build"], {
|
|
14915
15486
|
cwd: paths.WEB_ROOT,
|
|
@@ -14959,7 +15530,7 @@ async function runDashboard(args) {
|
|
|
14959
15530
|
}
|
|
14960
15531
|
|
|
14961
15532
|
// src/commands/workspace.ts
|
|
14962
|
-
import { existsSync as existsSync29, mkdirSync as
|
|
15533
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync13, writeFileSync as writeFileSync10 } from "fs";
|
|
14963
15534
|
var USAGE7 = `
|
|
14964
15535
|
Usage: flyspace workspace <subcommand> [options]
|
|
14965
15536
|
|
|
@@ -15068,7 +15639,7 @@ async function provisionChannels(specs) {
|
|
|
15068
15639
|
}
|
|
15069
15640
|
const cwd = expandPath(spec.cwd);
|
|
15070
15641
|
if (!existsSync29(cwd)) {
|
|
15071
|
-
|
|
15642
|
+
mkdirSync13(cwd, { recursive: true });
|
|
15072
15643
|
console.log(` created cwd ${cwd}`);
|
|
15073
15644
|
}
|
|
15074
15645
|
await createChannel({ name: spec.name, cwd, position: index });
|
|
@@ -15145,10 +15716,10 @@ async function runReconcileCmd(args) {
|
|
|
15145
15716
|
}
|
|
15146
15717
|
|
|
15147
15718
|
// src/cli.ts
|
|
15148
|
-
import { join as
|
|
15719
|
+
import { join as join21 } from "path";
|
|
15149
15720
|
var home = flyspaceHome();
|
|
15150
15721
|
if (home) {
|
|
15151
|
-
const bin =
|
|
15722
|
+
const bin = join21(home, "bin");
|
|
15152
15723
|
const path = process.env.PATH ?? "";
|
|
15153
15724
|
if (!path.split(":").includes(bin)) process.env.PATH = path ? `${bin}:${path}` : bin;
|
|
15154
15725
|
}
|
|
@@ -15286,7 +15857,7 @@ async function main() {
|
|
|
15286
15857
|
break;
|
|
15287
15858
|
case "-v":
|
|
15288
15859
|
case "--version":
|
|
15289
|
-
printRaw("0.1.
|
|
15860
|
+
printRaw("0.1.53");
|
|
15290
15861
|
break;
|
|
15291
15862
|
case "-h":
|
|
15292
15863
|
case "--help":
|