flyspace-cli 0.1.53 → 0.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-67WA56OD.js +1243 -0
- package/dist/chunk-ONGRYEWS.js +178 -0
- package/dist/{chunk-GX5467VC.js → chunk-ZSRDP5HJ.js} +2143 -2274
- package/dist/cli.js +367 -470
- package/dist/index.js +2 -2
- package/dist/{threads-QAVO2Z4L.js → threads-PTTZUNIJ.js} +43 -12
- package/package.json +1 -1
- package/system.capabilities.md +2 -0
- package/dist/chunk-HTFQL66T.js +0 -488
- package/dist/chunk-PIAF4FJX.js +0 -76
package/dist/cli.js
CHANGED
|
@@ -3,14 +3,14 @@ import { createRequire as __flyspaceCreateRequire } from 'node:module';
|
|
|
3
3
|
const require = __flyspaceCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
5
|
AutomationManager,
|
|
6
|
+
BOT_DM_KEY,
|
|
7
|
+
BOT_LABEL,
|
|
6
8
|
BOT_PROFILE_KEY,
|
|
7
9
|
BRANDING_DEFAULTS,
|
|
8
10
|
BUILT_IN_OUTPUT_STYLES,
|
|
9
11
|
CLI_VERSION,
|
|
10
|
-
ChannelCwdError,
|
|
11
12
|
ChatAgent,
|
|
12
13
|
DEFAULT_TIMEZONE,
|
|
13
|
-
DefaultChannelError,
|
|
14
14
|
DocShareSlugTakenError,
|
|
15
15
|
HANDLE_PATTERN,
|
|
16
16
|
HandleTakenError,
|
|
@@ -22,21 +22,18 @@ import {
|
|
|
22
22
|
PLATE,
|
|
23
23
|
SKIP_SUBTYPES,
|
|
24
24
|
SLACK_ENV,
|
|
25
|
-
|
|
26
|
-
SessionStore,
|
|
25
|
+
SUPPORT_AVATAR_URL,
|
|
27
26
|
TRANSLATION_LANGUAGES,
|
|
28
27
|
TRIAL_DAYS,
|
|
29
28
|
UsageStore,
|
|
30
29
|
acquireHostLock,
|
|
31
|
-
|
|
32
|
-
auditChannelCwds,
|
|
30
|
+
agentViewer,
|
|
33
31
|
authorFor,
|
|
34
32
|
blockToFallbackText,
|
|
35
33
|
bodyTextFor,
|
|
36
34
|
buildAuthorizeUrl,
|
|
37
35
|
buildAutoTitle,
|
|
38
36
|
cachedProfileConfig,
|
|
39
|
-
canSeeChannel,
|
|
40
37
|
canonicalLanguage,
|
|
41
38
|
channelSkillsDir,
|
|
42
39
|
claudeAuthFailed,
|
|
@@ -45,7 +42,6 @@ import {
|
|
|
45
42
|
codexAuthAvailable,
|
|
46
43
|
consumeOAuthState,
|
|
47
44
|
corsForShell,
|
|
48
|
-
createChannel,
|
|
49
45
|
createDocShare,
|
|
50
46
|
createDocsRouter,
|
|
51
47
|
createFeatureFlagsRouter,
|
|
@@ -56,6 +52,7 @@ import {
|
|
|
56
52
|
createPkcePair,
|
|
57
53
|
createPublicShareApiRouter,
|
|
58
54
|
createPublicShareAssetRouter,
|
|
55
|
+
createRequestSupabaseClient,
|
|
59
56
|
createSkillFile,
|
|
60
57
|
createStateToken,
|
|
61
58
|
createTtsRouter,
|
|
@@ -74,23 +71,18 @@ import {
|
|
|
74
71
|
deleteWorkspace,
|
|
75
72
|
deleteWorkspaceDomain,
|
|
76
73
|
deriveConnectionSlug,
|
|
74
|
+
detectSourceLanguage,
|
|
77
75
|
displayNameFor,
|
|
78
76
|
dropShareAudio,
|
|
79
77
|
dropShareLangAudioKeys,
|
|
80
78
|
effectiveModel,
|
|
81
|
-
ensureAgentDmChannel,
|
|
82
|
-
ensureGeneralChannel,
|
|
83
|
-
ensureMemberDmChannel,
|
|
84
79
|
ensureUsersCached,
|
|
85
80
|
escalateToHuman,
|
|
86
81
|
exchangeCode,
|
|
87
|
-
expandPath,
|
|
88
82
|
explainCost,
|
|
89
83
|
extractCategories,
|
|
90
84
|
extractTitle,
|
|
91
85
|
filterReadableDocsChannels,
|
|
92
|
-
findChannel,
|
|
93
|
-
findChannelById,
|
|
94
86
|
findDocShareBySource,
|
|
95
87
|
findOwningProfile,
|
|
96
88
|
findSkillDetail,
|
|
@@ -99,7 +91,6 @@ import {
|
|
|
99
91
|
getAllowGuestAccess,
|
|
100
92
|
getChannelDocsMemberAccess,
|
|
101
93
|
getChannelMemory,
|
|
102
|
-
getChannelRegistry,
|
|
103
94
|
getLocalCache,
|
|
104
95
|
getMcpConnection,
|
|
105
96
|
getMcpProvider,
|
|
@@ -107,7 +98,6 @@ import {
|
|
|
107
98
|
getMembershipByUserId,
|
|
108
99
|
getMemory,
|
|
109
100
|
getOutputStyleDefault,
|
|
110
|
-
getProfileChannelRegistry,
|
|
111
101
|
getWorkspaceAutoContinueLimit,
|
|
112
102
|
getWorkspaceBilling,
|
|
113
103
|
getWorkspaceBranding,
|
|
@@ -120,25 +110,22 @@ import {
|
|
|
120
110
|
getWorkspacePlanStatus,
|
|
121
111
|
handleAttachmentUrlResult,
|
|
122
112
|
handleHostDbResult,
|
|
113
|
+
handleShouldRespondResult,
|
|
123
114
|
handleSupportMention,
|
|
124
115
|
highlightLanguageOf,
|
|
125
116
|
insertMcpConnection,
|
|
126
117
|
insertWorkspaceDomain,
|
|
127
118
|
installUsageRecording,
|
|
119
|
+
invalidateAuthContextCache,
|
|
128
120
|
isAllowedModel,
|
|
129
|
-
isCwdUsable,
|
|
130
121
|
isDevHost,
|
|
131
122
|
isDocsAccess,
|
|
132
|
-
isEffort,
|
|
133
123
|
isFeatureEnabled,
|
|
134
124
|
isLockedPlan,
|
|
135
|
-
isLogicalCwd,
|
|
136
125
|
isMemoryType,
|
|
137
126
|
isOlderVersion,
|
|
138
|
-
isPermissionMode,
|
|
139
127
|
isSlugAvailable,
|
|
140
128
|
isTranslatableLanguage,
|
|
141
|
-
isUnderLogicalRoot,
|
|
142
129
|
isUnknownWorkspaceHost,
|
|
143
130
|
isUuid,
|
|
144
131
|
isValidSkillName,
|
|
@@ -173,13 +160,13 @@ import {
|
|
|
173
160
|
loadFullDashboardSettings,
|
|
174
161
|
loadWorkspaceBranding,
|
|
175
162
|
loadWorkspacePrompt,
|
|
176
|
-
markChannelGreeted,
|
|
177
163
|
markInviteResent,
|
|
178
164
|
markMemoryUsed,
|
|
179
165
|
markWorkspaceGreeted,
|
|
180
166
|
markWorkspaceProjectsSetup,
|
|
181
167
|
markdownToBlocks,
|
|
182
168
|
mentionedUserIds,
|
|
169
|
+
onboardingPending,
|
|
183
170
|
pinnedClaudeConfigDir,
|
|
184
171
|
profileClaudeConfigDir,
|
|
185
172
|
profileEnv,
|
|
@@ -194,7 +181,6 @@ import {
|
|
|
194
181
|
recentRunsForWorkspace,
|
|
195
182
|
refreshAutomationRegistry,
|
|
196
183
|
refreshCache,
|
|
197
|
-
refreshChannelRegistry,
|
|
198
184
|
refreshUserCache,
|
|
199
185
|
removeChannelMember,
|
|
200
186
|
renderAppIcon,
|
|
@@ -203,9 +189,9 @@ import {
|
|
|
203
189
|
requireSlackBotToken,
|
|
204
190
|
resetWorkspaceOnboarding,
|
|
205
191
|
resetWorkspacePrompt,
|
|
192
|
+
resolveAuthContext,
|
|
206
193
|
resolveChannelConfig,
|
|
207
194
|
resolveChannelId,
|
|
208
|
-
resolveCwd,
|
|
209
195
|
resolveDocPath,
|
|
210
196
|
resolveDocsAccess,
|
|
211
197
|
resolveRateCard,
|
|
@@ -245,7 +231,6 @@ import {
|
|
|
245
231
|
slackConfigured,
|
|
246
232
|
slackMrkdwnToMarkdown,
|
|
247
233
|
startAutomationRegistryPolling,
|
|
248
|
-
startChannelRegistryPolling,
|
|
249
234
|
startServer,
|
|
250
235
|
suggestChannelField,
|
|
251
236
|
syncSlackAvatars,
|
|
@@ -254,9 +239,7 @@ import {
|
|
|
254
239
|
trustedHost,
|
|
255
240
|
tsToIso,
|
|
256
241
|
undoMemoryEvent,
|
|
257
|
-
updateChannelById,
|
|
258
242
|
updateChannelMemory,
|
|
259
|
-
updateChannelsMcpConnections,
|
|
260
243
|
updateDocShareFeatures,
|
|
261
244
|
updateDocShareSnapshot,
|
|
262
245
|
updateMcpConnectionSettings,
|
|
@@ -273,39 +256,66 @@ import {
|
|
|
273
256
|
useDirectSupabase,
|
|
274
257
|
useLocalCache,
|
|
275
258
|
validateMemoryInput,
|
|
276
|
-
warnOnBrokenChannelCwds,
|
|
277
259
|
workspaceHostname,
|
|
278
260
|
workspaceSkillsDir,
|
|
279
261
|
writeSkillFile
|
|
280
|
-
} from "./chunk-
|
|
262
|
+
} from "./chunk-ZSRDP5HJ.js";
|
|
281
263
|
import {
|
|
264
|
+
canReadThread,
|
|
282
265
|
firstReplyBody,
|
|
283
266
|
getThread,
|
|
284
267
|
listChannels,
|
|
285
268
|
listThreads,
|
|
286
|
-
|
|
287
|
-
resolveChannel
|
|
288
|
-
|
|
269
|
+
moveThreadFully,
|
|
270
|
+
resolveChannel,
|
|
271
|
+
resolveThreadOwner
|
|
272
|
+
} from "./chunk-ONGRYEWS.js";
|
|
289
273
|
import {
|
|
290
274
|
AGENT_AUTHOR,
|
|
275
|
+
ChannelCwdError,
|
|
291
276
|
DEFAULT_PROFILE,
|
|
277
|
+
DefaultChannelError,
|
|
292
278
|
SCRATCH_PREFIX,
|
|
279
|
+
SessionStore,
|
|
280
|
+
auditChannelCwds,
|
|
281
|
+
canSeeChannel,
|
|
282
|
+
createChannel,
|
|
293
283
|
databaseReachable,
|
|
284
|
+
ensureAgentDmChannel,
|
|
294
285
|
ensureDirs,
|
|
286
|
+
ensureGeneralChannel,
|
|
287
|
+
ensureMemberDmChannel,
|
|
288
|
+
expandPath,
|
|
289
|
+
findChannel,
|
|
290
|
+
findChannelById,
|
|
291
|
+
getChannelRegistry,
|
|
295
292
|
getProfile,
|
|
293
|
+
getProfileChannelRegistry,
|
|
296
294
|
getR2Bucket,
|
|
297
295
|
getR2Client,
|
|
298
296
|
getSupabaseClient,
|
|
299
297
|
hasSupabaseCredentials,
|
|
298
|
+
isCwdUsable,
|
|
299
|
+
isEffort,
|
|
300
300
|
isHumanAuthor,
|
|
301
|
+
isLogicalCwd,
|
|
302
|
+
isPermissionMode,
|
|
303
|
+
isUnderLogicalRoot,
|
|
304
|
+
markChannelGreeted,
|
|
301
305
|
paths,
|
|
302
306
|
postToDashboardChannel,
|
|
307
|
+
refreshChannelRegistry,
|
|
308
|
+
resolveCwd,
|
|
303
309
|
resolveDashboardChannelId,
|
|
304
310
|
runWithProfile,
|
|
305
311
|
setSupabaseClient,
|
|
312
|
+
startChannelRegistryPolling,
|
|
306
313
|
sumR2PrefixBytes,
|
|
307
|
-
syncPostToDashboard
|
|
308
|
-
|
|
314
|
+
syncPostToDashboard,
|
|
315
|
+
updateChannelById,
|
|
316
|
+
updateChannelsMcpConnections,
|
|
317
|
+
warnOnBrokenChannelCwds
|
|
318
|
+
} from "./chunk-67WA56OD.js";
|
|
309
319
|
|
|
310
320
|
// ../core/src/logger.ts
|
|
311
321
|
var ALREADY_STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
@@ -2347,7 +2357,7 @@ function npmEnv(target) {
|
|
|
2347
2357
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
2348
2358
|
}
|
|
2349
2359
|
async function runUpgrade() {
|
|
2350
|
-
const current = "0.1.
|
|
2360
|
+
const current = "0.1.54";
|
|
2351
2361
|
console.log(`Current version: ${current}`);
|
|
2352
2362
|
console.log("Checking for updates...\n");
|
|
2353
2363
|
try {
|
|
@@ -2407,11 +2417,15 @@ function loadAutomationsFile() {
|
|
|
2407
2417
|
}
|
|
2408
2418
|
|
|
2409
2419
|
// src/commands/automation.ts
|
|
2420
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
2410
2421
|
var USAGE2 = `
|
|
2411
2422
|
Usage: flyspace automation <subcommand> [options]
|
|
2412
2423
|
|
|
2413
2424
|
Subcommands:
|
|
2414
2425
|
list List all automations (grouped by channel)
|
|
2426
|
+
show <name> Print one automation as JSON, prompt included
|
|
2427
|
+
edit <name> --prompt <text>|--prompt-file <path>
|
|
2428
|
+
Replace an automation's prompt
|
|
2415
2429
|
add --type schedule|trigger|mention-trigger Add an automation
|
|
2416
2430
|
remove <name> Remove an automation
|
|
2417
2431
|
enable <name> Enable an automation
|
|
@@ -2662,6 +2676,43 @@ async function handleRun(manager, name) {
|
|
|
2662
2676
|
});
|
|
2663
2677
|
console.log("Done.");
|
|
2664
2678
|
}
|
|
2679
|
+
function automationType(item) {
|
|
2680
|
+
if ("cron" in item) return "schedule";
|
|
2681
|
+
if ("patterns" in item) return "trigger";
|
|
2682
|
+
return "mention-trigger";
|
|
2683
|
+
}
|
|
2684
|
+
function handleShow(manager, name) {
|
|
2685
|
+
const located = manager.locate(name);
|
|
2686
|
+
if (!located) {
|
|
2687
|
+
console.error(`Automation "${name}" not found.`);
|
|
2688
|
+
process.exit(1);
|
|
2689
|
+
}
|
|
2690
|
+
console.log(JSON.stringify({ type: automationType(located.item), ...located.item }, null, 2));
|
|
2691
|
+
}
|
|
2692
|
+
async function handleEdit(manager, name, args) {
|
|
2693
|
+
const inline = getArg(args, "--prompt");
|
|
2694
|
+
const file = getArg(args, "--prompt-file");
|
|
2695
|
+
if (!inline === !file) {
|
|
2696
|
+
console.error("Specify exactly one of --prompt or --prompt-file");
|
|
2697
|
+
process.exit(1);
|
|
2698
|
+
}
|
|
2699
|
+
const located = manager.locate(name);
|
|
2700
|
+
if (!located) {
|
|
2701
|
+
console.error(`Automation "${name}" not found.`);
|
|
2702
|
+
process.exit(1);
|
|
2703
|
+
}
|
|
2704
|
+
if ("script" in located.item && located.item.script) {
|
|
2705
|
+
console.error(`"${name}" runs a script, not a prompt.`);
|
|
2706
|
+
process.exit(1);
|
|
2707
|
+
}
|
|
2708
|
+
const prompt = inline ?? readFileSync11(file, "utf8");
|
|
2709
|
+
if (!prompt.trim()) {
|
|
2710
|
+
console.error("Prompt must not be empty.");
|
|
2711
|
+
process.exit(1);
|
|
2712
|
+
}
|
|
2713
|
+
await manager.update(automationType(located.item), name, { ...located.item, prompt });
|
|
2714
|
+
console.log(`Prompt of "${name}" updated.`);
|
|
2715
|
+
}
|
|
2665
2716
|
async function handleImport(manager) {
|
|
2666
2717
|
const file = loadAutomationsFile();
|
|
2667
2718
|
const existing = new Set(loadAutomations().schedules.map((s) => s.name));
|
|
@@ -2708,6 +2759,20 @@ async function runAutomationCmd(args) {
|
|
|
2708
2759
|
case "list":
|
|
2709
2760
|
printList(manager);
|
|
2710
2761
|
break;
|
|
2762
|
+
case "show":
|
|
2763
|
+
if (!args[1]) {
|
|
2764
|
+
console.error("Usage: flyspace automation show <name>");
|
|
2765
|
+
process.exit(1);
|
|
2766
|
+
}
|
|
2767
|
+
handleShow(manager, args[1]);
|
|
2768
|
+
break;
|
|
2769
|
+
case "edit":
|
|
2770
|
+
if (!args[1]) {
|
|
2771
|
+
console.error("Usage: flyspace automation edit <name> --prompt <text>|--prompt-file <path>");
|
|
2772
|
+
process.exit(1);
|
|
2773
|
+
}
|
|
2774
|
+
await handleEdit(manager, args[1], args.slice(2));
|
|
2775
|
+
break;
|
|
2711
2776
|
case "add":
|
|
2712
2777
|
await handleAdd(manager, args.slice(1));
|
|
2713
2778
|
break;
|
|
@@ -3025,7 +3090,7 @@ async function runLogs(args) {
|
|
|
3025
3090
|
|
|
3026
3091
|
// src/commands/slack.ts
|
|
3027
3092
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
3028
|
-
import { existsSync as existsSync13, readFileSync as
|
|
3093
|
+
import { existsSync as existsSync13, readFileSync as readFileSync12, writeFileSync as writeFileSync6 } from "fs";
|
|
3029
3094
|
import { resolve as resolve4 } from "path";
|
|
3030
3095
|
import { tmpdir as tmpdir2, homedir as homedir5 } from "os";
|
|
3031
3096
|
import { input, confirm as confirm4, select, checkbox } from "@inquirer/prompts";
|
|
@@ -3538,6 +3603,7 @@ async function issueSetupInvite(params) {
|
|
|
3538
3603
|
message: params.message,
|
|
3539
3604
|
invited_by: params.invitedBy,
|
|
3540
3605
|
token_hash: hashInviteToken(token),
|
|
3606
|
+
link_token: token,
|
|
3541
3607
|
expires_at: expiresAt.toISOString()
|
|
3542
3608
|
});
|
|
3543
3609
|
if (error2) throw new Error(`issueSetupInvite(${params.email}): ${error2.message}`);
|
|
@@ -3560,6 +3626,7 @@ async function reissueSetupInvite(id) {
|
|
|
3560
3626
|
const expiresAt = new Date(Date.now() + INVITE_TTL_DAYS * 24 * 60 * 60 * 1e3);
|
|
3561
3627
|
const { error: updateError } = await db.from("workspace_setup_invites").update({
|
|
3562
3628
|
token_hash: hashInviteToken(token),
|
|
3629
|
+
link_token: token,
|
|
3563
3630
|
previous_token_hashes: [
|
|
3564
3631
|
...data.previous_token_hashes ?? [],
|
|
3565
3632
|
data.token_hash
|
|
@@ -3576,11 +3643,18 @@ async function reissueSetupInvite(id) {
|
|
|
3576
3643
|
}
|
|
3577
3644
|
};
|
|
3578
3645
|
}
|
|
3646
|
+
async function currentSetupInviteToken(id) {
|
|
3647
|
+
const { data, error: error2 } = await getSupabaseClient().from("workspace_setup_invites").select("link_token").eq("id", id).is("accepted_at", null).maybeSingle();
|
|
3648
|
+
if (error2) throw new Error(`currentSetupInviteToken(${id}): ${error2.message}`);
|
|
3649
|
+
if (!data) throw new Error("no pending invite with that id");
|
|
3650
|
+
return data.link_token ?? (await reissueSetupInvite(id)).token;
|
|
3651
|
+
}
|
|
3579
3652
|
async function lookupSetupInvite(token) {
|
|
3580
3653
|
const { data, error: error2 } = await getSupabaseClient().from("workspace_setup_invites").select("id, email, owner_name, plan, message, expires_at, accepted_at, workspace_id").or(tokenHashFilter(token)).maybeSingle();
|
|
3581
3654
|
if (error2) throw new Error(`lookupSetupInvite: ${error2.message}`);
|
|
3582
3655
|
if (!data) return { state: "unknown" };
|
|
3583
|
-
if (data.accepted_at)
|
|
3656
|
+
if (data.accepted_at)
|
|
3657
|
+
return { state: "used", workspaceId: data.workspace_id ?? null };
|
|
3584
3658
|
if (new Date(data.expires_at).getTime() <= Date.now()) return { state: "expired" };
|
|
3585
3659
|
return {
|
|
3586
3660
|
state: "valid",
|
|
@@ -3646,6 +3720,18 @@ var RESERVED = /* @__PURE__ */ new Set([
|
|
|
3646
3720
|
"portal",
|
|
3647
3721
|
"home",
|
|
3648
3722
|
"root",
|
|
3723
|
+
// Top-level Workspace routes: the slug is the first URL path segment
|
|
3724
|
+
// (`app.flyspace.ai/<slug>/...`), see packages/ui/src/lib/workspace-path.ts.
|
|
3725
|
+
"chat",
|
|
3726
|
+
"global",
|
|
3727
|
+
"device",
|
|
3728
|
+
"onboarding",
|
|
3729
|
+
"reset-password",
|
|
3730
|
+
"channels",
|
|
3731
|
+
"automations",
|
|
3732
|
+
"profiles",
|
|
3733
|
+
"sessions",
|
|
3734
|
+
"logs",
|
|
3649
3735
|
"share",
|
|
3650
3736
|
"shared",
|
|
3651
3737
|
"data",
|
|
@@ -4976,7 +5062,7 @@ async function threadReplies(client2, nameOrId, ts2) {
|
|
|
4976
5062
|
async function postMessage(client2, args) {
|
|
4977
5063
|
const channelArg = getArg2(args, "--channel");
|
|
4978
5064
|
const textFilePath = getArg2(args, "--text-file");
|
|
4979
|
-
const text = textFilePath ?
|
|
5065
|
+
const text = textFilePath ? readFileSync12(textFilePath, "utf8") : getArg2(args, "--text");
|
|
4980
5066
|
const threadTs = getArg2(args, "--thread");
|
|
4981
5067
|
const markdown = args.includes("--markdown");
|
|
4982
5068
|
const broadcast = args.includes("--broadcast") && Boolean(threadTs);
|
|
@@ -5131,7 +5217,7 @@ async function ensureClaudeCodeReady() {
|
|
|
5131
5217
|
}
|
|
5132
5218
|
function getManifestYaml(botName) {
|
|
5133
5219
|
const manifestPath = resolve4(paths.PACKAGE_ROOT, "slack-app-manifest.yml");
|
|
5134
|
-
const raw =
|
|
5220
|
+
const raw = readFileSync12(manifestPath, "utf-8");
|
|
5135
5221
|
return raw.replace(/name: Custie/g, `name: ${botName}`);
|
|
5136
5222
|
}
|
|
5137
5223
|
async function stepPersonalise() {
|
|
@@ -5563,7 +5649,7 @@ function copyDefaultPrompt(botName) {
|
|
|
5563
5649
|
if (!existsSync13(paths.PROMPT_FILE)) {
|
|
5564
5650
|
const defaultPrompt = resolve4(paths.PACKAGE_ROOT, "system.default.md");
|
|
5565
5651
|
if (existsSync13(defaultPrompt)) {
|
|
5566
|
-
const content =
|
|
5652
|
+
const content = readFileSync12(defaultPrompt, "utf-8").replace(/\{\{botName\}\}/g, botName);
|
|
5567
5653
|
writeFileSync6(paths.PROMPT_FILE, content);
|
|
5568
5654
|
success4(`Default prompt copied to ${paths.PROMPT_FILE}`);
|
|
5569
5655
|
}
|
|
@@ -5844,25 +5930,19 @@ async function runMove(args) {
|
|
|
5844
5930
|
console.log("\n--dry-run: nothing changed.");
|
|
5845
5931
|
return;
|
|
5846
5932
|
}
|
|
5847
|
-
await
|
|
5848
|
-
|
|
5849
|
-
const moved = store.moveThread(
|
|
5850
|
-
`chat:${thread.channelId}`,
|
|
5851
|
-
`chat:${destination.id}`,
|
|
5852
|
-
thread.id
|
|
5853
|
-
);
|
|
5854
|
-
store.close();
|
|
5933
|
+
const moved = await moveThreadFully(thread.id, destination.id);
|
|
5934
|
+
if (moved === "unchanged") return;
|
|
5855
5935
|
console.log(
|
|
5856
5936
|
`
|
|
5857
5937
|
Moved. Re-keyed ${moved.sessions} session(s), ${moved.modelOverrides} model override(s), ${moved.effortOverrides} effort override(s).`
|
|
5858
5938
|
);
|
|
5859
|
-
if (
|
|
5939
|
+
if (moved.cwdChanged && source) {
|
|
5860
5940
|
console.log(
|
|
5861
5941
|
`
|
|
5862
5942
|
Note: the channels have different working directories.
|
|
5863
5943
|
${source.cwd}
|
|
5864
5944
|
${destination.cwd}
|
|
5865
|
-
Files this thread created live in the old one
|
|
5945
|
+
Files this thread created live in the old one, move them yourself if the
|
|
5866
5946
|
thread still refers to them.`
|
|
5867
5947
|
);
|
|
5868
5948
|
}
|
|
@@ -5943,10 +6023,10 @@ async function runChatCmd(args) {
|
|
|
5943
6023
|
}
|
|
5944
6024
|
|
|
5945
6025
|
// src/commands/memory.ts
|
|
5946
|
-
import { readFileSync as
|
|
6026
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
5947
6027
|
|
|
5948
6028
|
// src/store/claude-memory-import.ts
|
|
5949
|
-
import { existsSync as existsSync14, readdirSync as readdirSync3, readFileSync as
|
|
6029
|
+
import { existsSync as existsSync14, readdirSync as readdirSync3, readFileSync as readFileSync13 } from "fs";
|
|
5950
6030
|
import { homedir as homedir6 } from "os";
|
|
5951
6031
|
import { basename as basename5, join as join12 } from "path";
|
|
5952
6032
|
import dotenv from "dotenv";
|
|
@@ -5956,7 +6036,7 @@ function claudeMemoryDir(cwd, configDir2) {
|
|
|
5956
6036
|
function profileClaudeConfigDirFor(profile) {
|
|
5957
6037
|
const dir = profile === "default" ? paths.BASE_CONFIG_DIR : join12(paths.PROFILES_DIR, profile);
|
|
5958
6038
|
const file = join12(dir, "config.env");
|
|
5959
|
-
const env = existsSync14(file) ? dotenv.parse(
|
|
6039
|
+
const env = existsSync14(file) ? dotenv.parse(readFileSync13(file)) : {};
|
|
5960
6040
|
return env["CLAUDE_CONFIG_DIR"]?.trim() || join12(homedir6(), ".claude");
|
|
5961
6041
|
}
|
|
5962
6042
|
var TYPE_MAP = {
|
|
@@ -6006,7 +6086,7 @@ async function importClaudeMemories(dir, channelId, opts = {}) {
|
|
|
6006
6086
|
const files = readdirSync3(dir).filter((f) => f.endsWith(".md") && f !== "MEMORY.md").sort();
|
|
6007
6087
|
const results = [];
|
|
6008
6088
|
for (const file of files) {
|
|
6009
|
-
const parsed = parseClaudeMemory(file,
|
|
6089
|
+
const parsed = parseClaudeMemory(file, readFileSync13(join12(dir, file), "utf-8"), channelId);
|
|
6010
6090
|
if ("skip" in parsed) {
|
|
6011
6091
|
results.push({ file, outcome: "skipped", reason: parsed.skip });
|
|
6012
6092
|
continue;
|
|
@@ -6118,7 +6198,7 @@ ${memory.body}`);
|
|
|
6118
6198
|
);
|
|
6119
6199
|
}
|
|
6120
6200
|
if (!isMemoryType(type)) throw new Error(`--type must be one of ${MEMORY_TYPES.join(", ")}`);
|
|
6121
|
-
const body = bodyArg === "-" ?
|
|
6201
|
+
const body = bodyArg === "-" ? readFileSync14(0, "utf-8") : bodyArg;
|
|
6122
6202
|
const thread = getArg4(rest, "--thread");
|
|
6123
6203
|
const { created, changed } = await saveMemory(
|
|
6124
6204
|
target,
|
|
@@ -6202,9 +6282,10 @@ async function runMcpCmd(args) {
|
|
|
6202
6282
|
}
|
|
6203
6283
|
restoreStdout();
|
|
6204
6284
|
loadEnvFiles();
|
|
6285
|
+
useHostDbWithoutCredentials();
|
|
6205
6286
|
switch (server) {
|
|
6206
6287
|
case "threads": {
|
|
6207
|
-
const { startThreadsServer } = await import("./threads-
|
|
6288
|
+
const { startThreadsServer } = await import("./threads-PTTZUNIJ.js");
|
|
6208
6289
|
await startThreadsServer();
|
|
6209
6290
|
return;
|
|
6210
6291
|
}
|
|
@@ -6287,92 +6368,6 @@ async function ensureServices() {
|
|
|
6287
6368
|
// ../api/src/dashboard/api.ts
|
|
6288
6369
|
import { Hono as Hono35 } from "hono";
|
|
6289
6370
|
|
|
6290
|
-
// ../api/src/dashboard/supabase-server-client.ts
|
|
6291
|
-
import { createServerClient, parseCookieHeader, serializeCookieHeader } from "@supabase/ssr";
|
|
6292
|
-
|
|
6293
|
-
// ../api/src/dashboard/scoped-auth-cookies.ts
|
|
6294
|
-
import { stringFromBase64URL } from "@supabase/ssr";
|
|
6295
|
-
var SESSION_NAME = /^(sb-.+-auth-token)(?:\.\d+)?$/;
|
|
6296
|
-
var SCOPE_MARK = "fsw_";
|
|
6297
|
-
var SCOPE_END = "__";
|
|
6298
|
-
function hostLabel(host) {
|
|
6299
|
-
return host.toLowerCase().replace(/:\d+$/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
6300
|
-
}
|
|
6301
|
-
var scopePrefix = (label2) => `${SCOPE_MARK}${label2}${SCOPE_END}`;
|
|
6302
|
-
function sessionUserId(cookies) {
|
|
6303
|
-
const base = cookies.map((c) => SESSION_NAME.exec(c.name)?.[1]).find(Boolean);
|
|
6304
|
-
if (!base) return null;
|
|
6305
|
-
const whole = cookies.find((c) => c.name === base)?.value;
|
|
6306
|
-
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("");
|
|
6307
|
-
if (!raw) return null;
|
|
6308
|
-
try {
|
|
6309
|
-
const json = raw.startsWith("base64-") ? stringFromBase64URL(raw.slice(7)) : raw;
|
|
6310
|
-
const id = JSON.parse(json).user?.id;
|
|
6311
|
-
return typeof id === "string" ? id : null;
|
|
6312
|
-
} catch {
|
|
6313
|
-
return null;
|
|
6314
|
-
}
|
|
6315
|
-
}
|
|
6316
|
-
var isScoped = (name) => name.startsWith(SCOPE_MARK);
|
|
6317
|
-
function readScopedCookies(all, label2) {
|
|
6318
|
-
const prefix = scopePrefix(label2);
|
|
6319
|
-
const own = all.filter((c) => c.name.startsWith(prefix)).map((c) => ({ name: c.name.slice(prefix.length), value: c.value }));
|
|
6320
|
-
return own.length ? own : all.filter((c) => !isScoped(c.name));
|
|
6321
|
-
}
|
|
6322
|
-
function routeCookieWrites(all, label2, writes) {
|
|
6323
|
-
const prefix = scopePrefix(label2);
|
|
6324
|
-
const hasOwn = all.some((c) => c.name.startsWith(prefix));
|
|
6325
|
-
const incoming = sessionUserId(writes.filter((c) => c.value !== ""));
|
|
6326
|
-
const shared = sessionUserId(all.filter((c) => !isScoped(c.name)));
|
|
6327
|
-
const toScoped = hasOwn || incoming !== null && shared !== null && incoming !== shared;
|
|
6328
|
-
return writes.map(
|
|
6329
|
-
(c) => toScoped ? { name: prefix + c.name, value: c.value, scoped: true } : { ...c, scoped: false }
|
|
6330
|
-
);
|
|
6331
|
-
}
|
|
6332
|
-
|
|
6333
|
-
// ../api/src/dashboard/supabase-server-client.ts
|
|
6334
|
-
var REQUEST_TIMEOUT_MS = 5e3;
|
|
6335
|
-
function fetchWithTimeout(input2, init2) {
|
|
6336
|
-
return fetch(input2, { ...init2, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
6337
|
-
}
|
|
6338
|
-
function createRequestSupabaseClient(c) {
|
|
6339
|
-
const url = process.env["SUPABASE_URL"];
|
|
6340
|
-
const key = process.env["VITE_SUPABASE_PUBLISHABLE_KEY"];
|
|
6341
|
-
if (!url || !key) {
|
|
6342
|
-
throw new Error("SUPABASE_URL / VITE_SUPABASE_PUBLISHABLE_KEY not set \u2014 check .env");
|
|
6343
|
-
}
|
|
6344
|
-
const origin = c.req.header("Origin");
|
|
6345
|
-
const label2 = hostLabel(
|
|
6346
|
-
(origin ? URL.parse(origin)?.host : void 0) ?? c.req.header("X-Forwarded-Host") ?? c.req.header("Host") ?? ""
|
|
6347
|
-
);
|
|
6348
|
-
const rawCookies = () => parseCookieHeader(c.req.header("Cookie") ?? "").map(({ name, value }) => ({
|
|
6349
|
-
name,
|
|
6350
|
-
value: value ?? ""
|
|
6351
|
-
}));
|
|
6352
|
-
return createServerClient(url, key, {
|
|
6353
|
-
global: { fetch: fetchWithTimeout },
|
|
6354
|
-
cookies: {
|
|
6355
|
-
// `parseCookieHeader` types `value` as optional; the client requires a
|
|
6356
|
-
// string, and a valueless cookie is the same as an empty one here.
|
|
6357
|
-
getAll: () => readScopedCookies(rawCookies(), label2),
|
|
6358
|
-
setAll: (cookies) => {
|
|
6359
|
-
const domain = process.env["AUTH_COOKIE_DOMAIN"]?.trim();
|
|
6360
|
-
const overrides = {
|
|
6361
|
-
...domain ? { domain } : {},
|
|
6362
|
-
...crossOriginShell(c) ? { sameSite: "none", secure: true } : {}
|
|
6363
|
-
};
|
|
6364
|
-
const routed = routeCookieWrites(rawCookies(), label2, cookies);
|
|
6365
|
-
cookies.forEach(({ options }, i) => {
|
|
6366
|
-
const { name, value } = routed[i];
|
|
6367
|
-
c.header("Set-Cookie", serializeCookieHeader(name, value, { ...options, ...overrides }), {
|
|
6368
|
-
append: true
|
|
6369
|
-
});
|
|
6370
|
-
});
|
|
6371
|
-
}
|
|
6372
|
-
}
|
|
6373
|
-
});
|
|
6374
|
-
}
|
|
6375
|
-
|
|
6376
6371
|
// ../api/src/dashboard/guest-routes.ts
|
|
6377
6372
|
import { Hono as Hono4 } from "hono";
|
|
6378
6373
|
async function guestAccessAllowed() {
|
|
@@ -6417,110 +6412,6 @@ function createGuestRouter() {
|
|
|
6417
6412
|
// ../api/src/dashboard/auth-routes.ts
|
|
6418
6413
|
import { Hono as Hono7 } from "hono";
|
|
6419
6414
|
|
|
6420
|
-
// ../api/src/dashboard/auth-context.ts
|
|
6421
|
-
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
6422
|
-
import { isAuthApiError, isAuthRetryableFetchError } from "@supabase/supabase-js";
|
|
6423
|
-
function onboardingPending(ctx) {
|
|
6424
|
-
const pending = [];
|
|
6425
|
-
if (!ctx.onboarded && !ctx.passwordSet) pending.push("account");
|
|
6426
|
-
if (!ctx.onboarded) pending.push("profile");
|
|
6427
|
-
if (ctx.role === "admin" && !ctx.agentConnectedAt) pending.push("agent");
|
|
6428
|
-
if (ctx.role === "admin" && !ctx.projectsSetupAt) pending.push("projects");
|
|
6429
|
-
return pending;
|
|
6430
|
-
}
|
|
6431
|
-
var inFlight = /* @__PURE__ */ new Map();
|
|
6432
|
-
var CACHE_TTL_MS = 3e4;
|
|
6433
|
-
var resolved = /* @__PURE__ */ new Map();
|
|
6434
|
-
function invalidateAuthContextCache() {
|
|
6435
|
-
resolved.clear();
|
|
6436
|
-
}
|
|
6437
|
-
function pruneExpired(now) {
|
|
6438
|
-
for (const [key, entry] of resolved) {
|
|
6439
|
-
if (entry.expires <= now) resolved.delete(key);
|
|
6440
|
-
}
|
|
6441
|
-
}
|
|
6442
|
-
var SUPPORT_NAME = "Flyspace Support";
|
|
6443
|
-
var SUPPORT_AVATAR_URL = "/logo/flyspace-support.svg";
|
|
6444
|
-
function workspaceArchivedError() {
|
|
6445
|
-
return new HTTPException2(403, {
|
|
6446
|
-
res: Response.json({ error: "workspace archived", archived: true }, { status: 403 })
|
|
6447
|
-
});
|
|
6448
|
-
}
|
|
6449
|
-
async function resolveAuthContext(c, opts = {}) {
|
|
6450
|
-
const ctx = await resolveAuthContextCached(c, opts);
|
|
6451
|
-
if (ctx?.archived && !ctx.isSupport) throw workspaceArchivedError();
|
|
6452
|
-
return ctx;
|
|
6453
|
-
}
|
|
6454
|
-
async function resolveAuthContextCached(c, opts) {
|
|
6455
|
-
const cookie = c.req?.header("Cookie") ?? "";
|
|
6456
|
-
if (!cookie) return resolveAuthContextUncached(c);
|
|
6457
|
-
const key = `${getProfile()}\0${cookie}`;
|
|
6458
|
-
const now = Date.now();
|
|
6459
|
-
pruneExpired(now);
|
|
6460
|
-
if (opts.fresh) resolved.delete(key);
|
|
6461
|
-
const cached = resolved.get(key);
|
|
6462
|
-
if (cached) return cached.value;
|
|
6463
|
-
const inflight = inFlight.get(key);
|
|
6464
|
-
if (inflight) return inflight;
|
|
6465
|
-
const promise = resolveAuthContextUncached(c).then((value) => {
|
|
6466
|
-
resolved.set(key, { value, expires: Date.now() + CACHE_TTL_MS });
|
|
6467
|
-
return value;
|
|
6468
|
-
}).finally(() => inFlight.delete(key));
|
|
6469
|
-
inFlight.set(key, promise);
|
|
6470
|
-
return promise;
|
|
6471
|
-
}
|
|
6472
|
-
async function getUserWithRetry(supabase) {
|
|
6473
|
-
let result = await supabase.auth.getUser();
|
|
6474
|
-
if (isAuthRetryableFetchError(result.error)) result = await supabase.auth.getUser();
|
|
6475
|
-
const { error: error2 } = result;
|
|
6476
|
-
if (isAuthRetryableFetchError(error2) || isAuthApiError(error2) && error2.status === 429) {
|
|
6477
|
-
throw error2;
|
|
6478
|
-
}
|
|
6479
|
-
return result;
|
|
6480
|
-
}
|
|
6481
|
-
async function resolveAuthContextUncached(c) {
|
|
6482
|
-
const supabase = createRequestSupabaseClient(c);
|
|
6483
|
-
let user;
|
|
6484
|
-
try {
|
|
6485
|
-
({
|
|
6486
|
-
data: { user }
|
|
6487
|
-
} = await getUserWithRetry(supabase));
|
|
6488
|
-
} catch (err) {
|
|
6489
|
-
if (isAuthRetryableFetchError(err)) {
|
|
6490
|
-
throw new HTTPException2(503, { message: "auth service unreachable" });
|
|
6491
|
-
}
|
|
6492
|
-
if (isAuthApiError(err) && err.status === 429) {
|
|
6493
|
-
throw new HTTPException2(503, { message: "auth service rate limited" });
|
|
6494
|
-
}
|
|
6495
|
-
return null;
|
|
6496
|
-
}
|
|
6497
|
-
if (!user?.email) return null;
|
|
6498
|
-
const workspace = await getWorkspaceBySlug(getProfile());
|
|
6499
|
-
if (!workspace) return null;
|
|
6500
|
-
const membership = await getMembershipByEmail(workspace.id, user.email);
|
|
6501
|
-
if (!membership) return null;
|
|
6502
|
-
if (membership.status === "invited") {
|
|
6503
|
-
await activateMembership(workspace.id, user.email);
|
|
6504
|
-
}
|
|
6505
|
-
const metadata = user.user_metadata ?? {};
|
|
6506
|
-
return {
|
|
6507
|
-
email: user.email,
|
|
6508
|
-
userId: user.id,
|
|
6509
|
-
handle: membership.handle,
|
|
6510
|
-
role: membership.role,
|
|
6511
|
-
workspaceId: workspace.id,
|
|
6512
|
-
// A support admin posts into a customer's workspace as Flyspace, not as
|
|
6513
|
-
// the staff member's personal profile.
|
|
6514
|
-
...membership.isSupport ? { name: SUPPORT_NAME, isSupport: true } : { name: metadata.name, avatarKey: metadata.avatarKey },
|
|
6515
|
-
onboarded: Boolean(metadata.onboardedAt),
|
|
6516
|
-
passwordSet: Boolean(metadata.passwordSetAt),
|
|
6517
|
-
agentConnectedAt: workspace.agentConnectedAt ?? null,
|
|
6518
|
-
projectsSetupAt: workspace.projectsSetupAt ?? null,
|
|
6519
|
-
plan: workspace.plan ?? null,
|
|
6520
|
-
...workspace.archivedAt ? { archived: true } : {}
|
|
6521
|
-
};
|
|
6522
|
-
}
|
|
6523
|
-
|
|
6524
6415
|
// ../api/src/dashboard/avatar-url.ts
|
|
6525
6416
|
import { GetObjectCommand } from "@aws-sdk/client-s3";
|
|
6526
6417
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
@@ -6543,13 +6434,13 @@ async function signAvatarUrl(key) {
|
|
|
6543
6434
|
|
|
6544
6435
|
// ../api/src/dashboard/turnstile.ts
|
|
6545
6436
|
var VERIFY_URL = "https://challenges.cloudflare.com/turnstile/v0/siteverify";
|
|
6546
|
-
var
|
|
6437
|
+
var REQUEST_TIMEOUT_MS = 5e3;
|
|
6547
6438
|
function siteverify(secret, token) {
|
|
6548
6439
|
return fetch(VERIFY_URL, {
|
|
6549
6440
|
method: "POST",
|
|
6550
6441
|
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
6551
6442
|
body: new URLSearchParams({ secret, response: token }),
|
|
6552
|
-
signal: AbortSignal.timeout(
|
|
6443
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
6553
6444
|
});
|
|
6554
6445
|
}
|
|
6555
6446
|
async function verifyTurnstileToken(token) {
|
|
@@ -6816,7 +6707,7 @@ import { WebSocket, WebSocketServer } from "ws";
|
|
|
6816
6707
|
|
|
6817
6708
|
// ../api/src/dashboard/host-identity.ts
|
|
6818
6709
|
import { createPrivateKey as createPrivateKey2, createPublicKey as createPublicKey3, generateKeyPairSync as generateKeyPairSync2 } from "crypto";
|
|
6819
|
-
import { existsSync as existsSync16, mkdirSync as mkdirSync8, readFileSync as
|
|
6710
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync8, readFileSync as readFileSync15, writeFileSync as writeFileSync8 } from "fs";
|
|
6820
6711
|
import { dirname as dirname6, join as join13 } from "path";
|
|
6821
6712
|
function hostPrivateKeyPath() {
|
|
6822
6713
|
return process.env["FLYSPACE_HOST_KEY_PATH"] || join13(paths.BASE_CONFIG_DIR, "host.key");
|
|
@@ -6827,7 +6718,7 @@ function loadHostPrivateKey(path = hostPrivateKeyPath()) {
|
|
|
6827
6718
|
`No Host identity at ${path}. Run \`pnpm run generate-host-key\` on this machine, then set FLYSPACE_HOST_PUBLIC_KEY on the Data process to the printed public key.`
|
|
6828
6719
|
);
|
|
6829
6720
|
}
|
|
6830
|
-
return createPrivateKey2(
|
|
6721
|
+
return createPrivateKey2(readFileSync15(path, "utf8"));
|
|
6831
6722
|
}
|
|
6832
6723
|
|
|
6833
6724
|
// ../api/src/dashboard/uploads-routes.ts
|
|
@@ -7542,6 +7433,17 @@ function createAdminRouter() {
|
|
|
7542
7433
|
await revokeSetupInvite(c.req.param("id"));
|
|
7543
7434
|
return c.json({ revoked: true });
|
|
7544
7435
|
});
|
|
7436
|
+
admin.get("/setup-invites/:id/link", async (c) => {
|
|
7437
|
+
let token;
|
|
7438
|
+
try {
|
|
7439
|
+
token = await currentSetupInviteToken(c.req.param("id"));
|
|
7440
|
+
} catch (err) {
|
|
7441
|
+
return c.json({ error: err instanceof Error ? err.message : "lookup failed" }, 404);
|
|
7442
|
+
}
|
|
7443
|
+
const inviteUrl = new URL(`${workspaceOrigin(c, "app")}/auth/new-workspace`);
|
|
7444
|
+
inviteUrl.searchParams.set("token", token);
|
|
7445
|
+
return c.json({ inviteLink: inviteUrl.toString() });
|
|
7446
|
+
});
|
|
7545
7447
|
admin.post("/setup-invites/:id/resend", async (c) => {
|
|
7546
7448
|
const operator = c.get("platformOperator");
|
|
7547
7449
|
let token;
|
|
@@ -7632,14 +7534,6 @@ function createAdminRouter() {
|
|
|
7632
7534
|
return admin;
|
|
7633
7535
|
}
|
|
7634
7536
|
|
|
7635
|
-
// ../api/src/dashboard/agent-identities.ts
|
|
7636
|
-
var BOT_LABEL = "Workspace Agent";
|
|
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
|
-
}
|
|
7642
|
-
|
|
7643
7537
|
// ../api/src/dashboard/data-api.ts
|
|
7644
7538
|
import { existsSync as existsSync18 } from "fs";
|
|
7645
7539
|
import sharp4 from "sharp";
|
|
@@ -8190,14 +8084,14 @@ async function translateBatch(batch, context, lang, scope) {
|
|
|
8190
8084
|
};
|
|
8191
8085
|
});
|
|
8192
8086
|
}
|
|
8193
|
-
var
|
|
8087
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
8194
8088
|
async function translateCached(lang, scope, messages, contextFor) {
|
|
8195
8089
|
if (!BY_CODE.has(lang)) throw new Error(`unsupported translation language: ${lang}`);
|
|
8196
8090
|
if (messages.length === 0) return [];
|
|
8197
8091
|
const keyed = messages.map((m) => ({ ...m, hash: translationHash(m.author, m.body) }));
|
|
8198
8092
|
const shape = createHash3("sha256").update(keyed.map((m) => `${m.kind}:${m.id}:${m.hash}`).join("\n")).digest("hex");
|
|
8199
8093
|
const key = `${lang}:${shape}`;
|
|
8200
|
-
const running2 =
|
|
8094
|
+
const running2 = inFlight.get(key);
|
|
8201
8095
|
if (running2) return running2;
|
|
8202
8096
|
const job = (async () => {
|
|
8203
8097
|
const kinds = ["reply", "title"];
|
|
@@ -8253,8 +8147,8 @@ async function translateCached(lang, scope, messages, contextFor) {
|
|
|
8253
8147
|
if (hit) return { id: m.id, body: hit.body, passthrough: hit.passthrough };
|
|
8254
8148
|
return fresh.get(freshKey(m)) ?? { id: m.id, body: m.body, passthrough: true };
|
|
8255
8149
|
});
|
|
8256
|
-
})().finally(() =>
|
|
8257
|
-
|
|
8150
|
+
})().finally(() => inFlight.delete(key));
|
|
8151
|
+
inFlight.set(key, job);
|
|
8258
8152
|
return job;
|
|
8259
8153
|
}
|
|
8260
8154
|
async function translateThread(lang, scope, messages) {
|
|
@@ -8307,6 +8201,75 @@ async function getChannelGlossaries(channelIds) {
|
|
|
8307
8201
|
return found;
|
|
8308
8202
|
}
|
|
8309
8203
|
|
|
8204
|
+
// ../api/src/store/notification-store.ts
|
|
8205
|
+
function rowToNotification(row) {
|
|
8206
|
+
const reply = row["thread_replies"];
|
|
8207
|
+
return {
|
|
8208
|
+
id: row["id"],
|
|
8209
|
+
threadId: row["thread_id"],
|
|
8210
|
+
channelId: row["channel_id"],
|
|
8211
|
+
replyId: row["reply_id"] ?? null,
|
|
8212
|
+
kind: row["kind"],
|
|
8213
|
+
createdAt: row["created_at"],
|
|
8214
|
+
author: reply?.author ?? null,
|
|
8215
|
+
body: reply?.body ?? null
|
|
8216
|
+
};
|
|
8217
|
+
}
|
|
8218
|
+
async function listUnreadNotifications(channelIds, userId, limit = 100) {
|
|
8219
|
+
if (channelIds.length === 0) return [];
|
|
8220
|
+
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("id, thread_id, channel_id, reply_id, kind, created_at, thread_replies (author, body)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).order("created_at", { ascending: false }).limit(limit);
|
|
8221
|
+
if (error2) throw new Error(`listUnreadNotifications(${userId}): ${error2.message}`);
|
|
8222
|
+
return (data ?? []).map(rowToNotification);
|
|
8223
|
+
}
|
|
8224
|
+
async function countUnreadNotifications(channelIds, userId) {
|
|
8225
|
+
if (channelIds.length === 0) return 0;
|
|
8226
|
+
const { count, error: error2 } = await getSupabaseClient().from("notifications").select("id, threads!inner(archived_at)", { count: "exact", head: true }).eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
8227
|
+
if (error2) throw new Error(`countUnreadNotifications(${userId}): ${error2.message}`);
|
|
8228
|
+
return count ?? 0;
|
|
8229
|
+
}
|
|
8230
|
+
async function countUnreadByChannel(channelIds, userId) {
|
|
8231
|
+
if (channelIds.length === 0) return {};
|
|
8232
|
+
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("channel_id, thread_id, threads!inner(archived_at)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
8233
|
+
if (error2) throw new Error(`countUnreadByChannel(${userId}): ${error2.message}`);
|
|
8234
|
+
const threads = /* @__PURE__ */ new Map();
|
|
8235
|
+
for (const row of data ?? []) {
|
|
8236
|
+
const channelId = row["channel_id"];
|
|
8237
|
+
const set = threads.get(channelId) ?? /* @__PURE__ */ new Set();
|
|
8238
|
+
set.add(row["thread_id"]);
|
|
8239
|
+
threads.set(channelId, set);
|
|
8240
|
+
}
|
|
8241
|
+
return Object.fromEntries([...threads].map(([id, set]) => [id, set.size]));
|
|
8242
|
+
}
|
|
8243
|
+
async function countUnreadByThread(channelIds, userId) {
|
|
8244
|
+
if (channelIds.length === 0) return {};
|
|
8245
|
+
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("thread_id, kind, threads!inner(archived_at)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
8246
|
+
if (error2) throw new Error(`countUnreadByThread(${userId}): ${error2.message}`);
|
|
8247
|
+
const byThread = {};
|
|
8248
|
+
for (const row of data ?? []) {
|
|
8249
|
+
const threadId = row["thread_id"];
|
|
8250
|
+
const entry = byThread[threadId] ?? { count: 0, mention: false };
|
|
8251
|
+
entry.count += 1;
|
|
8252
|
+
if (row["kind"] === "mention") entry.mention = true;
|
|
8253
|
+
byThread[threadId] = entry;
|
|
8254
|
+
}
|
|
8255
|
+
return byThread;
|
|
8256
|
+
}
|
|
8257
|
+
async function markThreadRead(userId, threadId) {
|
|
8258
|
+
const supabase = getSupabaseClient();
|
|
8259
|
+
const { error: readError } = await supabase.from("thread_reads").upsert(
|
|
8260
|
+
{ user_id: userId, thread_id: threadId, seen_at: (/* @__PURE__ */ new Date()).toISOString() },
|
|
8261
|
+
{ onConflict: "user_id,thread_id" }
|
|
8262
|
+
);
|
|
8263
|
+
if (readError) throw new Error(`markThreadRead(${threadId}): ${readError.message}`);
|
|
8264
|
+
const { error: notifError } = await supabase.from("notifications").update({ read_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("user_id", userId).eq("thread_id", threadId).is("read_at", null);
|
|
8265
|
+
if (notifError) throw new Error(`markThreadRead(${threadId}): ${notifError.message}`);
|
|
8266
|
+
}
|
|
8267
|
+
async function markAllRead(channelIds, userId) {
|
|
8268
|
+
if (channelIds.length === 0) return;
|
|
8269
|
+
const { error: error2 } = await getSupabaseClient().from("notifications").update({ read_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("user_id", userId).in("channel_id", channelIds).is("read_at", null);
|
|
8270
|
+
if (error2) throw new Error(`markAllRead(${userId}): ${error2.message}`);
|
|
8271
|
+
}
|
|
8272
|
+
|
|
8310
8273
|
// ../api/src/dashboard/chat-routes.ts
|
|
8311
8274
|
function isNonEmptyString(v) {
|
|
8312
8275
|
return typeof v === "string" && v.trim().length > 0;
|
|
@@ -8469,7 +8432,7 @@ var MARKDOWN_IMAGE_RE = /!\[[^\]]*\]\(\s*<?([^\s)>]+)>?(?:\s+"[^"]*")?\s*\)/g;
|
|
|
8469
8432
|
function markdownImageUrls(markdown) {
|
|
8470
8433
|
return [...markdown.matchAll(MARKDOWN_IMAGE_RE)].map((m) => m[1]);
|
|
8471
8434
|
}
|
|
8472
|
-
async function labelThread(channelId, body, scope) {
|
|
8435
|
+
async function labelThread(channelId, body, scope, language) {
|
|
8473
8436
|
const channel = getProfileChannelRegistry().find(
|
|
8474
8437
|
(ch) => ch.id === channelId || ch.externalChannelId === channelId
|
|
8475
8438
|
);
|
|
@@ -8490,7 +8453,8 @@ async function labelThread(channelId, body, scope) {
|
|
|
8490
8453
|
titlePrompt: (await loadWorkspaceBranding()).autoTitlePrompt,
|
|
8491
8454
|
existingCategories,
|
|
8492
8455
|
body,
|
|
8493
|
-
scope
|
|
8456
|
+
scope,
|
|
8457
|
+
language
|
|
8494
8458
|
});
|
|
8495
8459
|
}
|
|
8496
8460
|
function deriveForkTitle(body) {
|
|
@@ -8555,6 +8519,12 @@ function createChatRouter(agent = {}) {
|
|
|
8555
8519
|
const supabase = getSupabaseClient();
|
|
8556
8520
|
let query = supabase.from("threads").select("*").eq("channel_id", channelId).is("archived_at", null).order(sortColumn, { ascending: false }).limit(limit);
|
|
8557
8521
|
if (before) query = query.lt(sortColumn, before);
|
|
8522
|
+
if (c.req.query("unread") === "1") {
|
|
8523
|
+
const userId = c.get("auth")?.userId;
|
|
8524
|
+
const ids = userId ? Object.keys(await countUnreadByThread([channelId], userId)) : [];
|
|
8525
|
+
if (ids.length === 0) return c.json({ threads: [], nextCursor: null });
|
|
8526
|
+
query = query.in("id", ids);
|
|
8527
|
+
}
|
|
8558
8528
|
if (statusFilter.length) {
|
|
8559
8529
|
const withoutNone = statusFilter.filter((s) => s !== NO_STATUS_COLUMN);
|
|
8560
8530
|
const includeNone = statusFilter.includes(NO_STATUS_COLUMN);
|
|
@@ -8887,12 +8857,14 @@ function createChatRouter(agent = {}) {
|
|
|
8887
8857
|
app.post("/threads/:id/suggest-title", async (c) => {
|
|
8888
8858
|
const id = c.req.param("id");
|
|
8889
8859
|
if (!await threadIsKnown(id, c)) return c.json({ error: "not found" }, 404);
|
|
8860
|
+
const input2 = await c.req.json().catch(() => null);
|
|
8861
|
+
const language = typeof input2?.language === "string" && /^[A-Za-z-]{2,16}$/.test(input2.language) ? input2.language : void 0;
|
|
8890
8862
|
const { data: thread } = await getSupabaseClient().from("threads").select("channel_id").eq("id", id).single();
|
|
8891
8863
|
if (!thread) return c.json({ error: "not found" }, 404);
|
|
8892
8864
|
const { data: rows, error: error2 } = await getSupabaseClient().from("thread_replies").select("author, body").eq("thread_id", id).is("archived_at", null).order("created_at", { ascending: true });
|
|
8893
8865
|
if (error2) return c.json({ error: error2.message }, 500);
|
|
8894
8866
|
const transcript = (rows ?? []).map((r) => `${r.author}: ${slackMrkdwnToMarkdown(r.body)}`).join("\n\n");
|
|
8895
|
-
const title = await labelThread(thread.channel_id, transcript, "thread");
|
|
8867
|
+
const title = await labelThread(thread.channel_id, transcript, "thread", language);
|
|
8896
8868
|
if (!title) return c.json({ error: "could not generate a topic" }, 502);
|
|
8897
8869
|
return c.json({ title });
|
|
8898
8870
|
});
|
|
@@ -9257,72 +9229,6 @@ import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-s
|
|
|
9257
9229
|
// ../api/src/dashboard/bridge-types.ts
|
|
9258
9230
|
var SHARE_ASSET_PLACEHOLDER = "/share/{{flyspace-share-id}}/assets/";
|
|
9259
9231
|
|
|
9260
|
-
// ../api/src/dashboard/share-language.ts
|
|
9261
|
-
var GROQ_API_URL4 = "https://api.groq.com/openai/v1/chat/completions";
|
|
9262
|
-
var CLASSIFIER_MODEL = "openai/gpt-oss-20b";
|
|
9263
|
-
var SAMPLE_CHARS = 4e3;
|
|
9264
|
-
var NOISE = [
|
|
9265
|
-
/```[\s\S]*?```/g,
|
|
9266
|
-
/`[^`\n]*`/g,
|
|
9267
|
-
/!?\[[^\]]*\]\([^)]*\)/g,
|
|
9268
|
-
/https?:\/\/\S+/g
|
|
9269
|
-
];
|
|
9270
|
-
function languageSample(title, content) {
|
|
9271
|
-
let text = content;
|
|
9272
|
-
for (const pattern of NOISE) text = text.replace(pattern, " ");
|
|
9273
|
-
return `${title}
|
|
9274
|
-
|
|
9275
|
-
${text}`.replace(/\s+/g, " ").trim().slice(0, SAMPLE_CHARS);
|
|
9276
|
-
}
|
|
9277
|
-
var MIN_SAMPLE_CHARS = 40;
|
|
9278
|
-
var CODES = SOURCE_LANGUAGES.map((l) => l.code);
|
|
9279
|
-
function systemPrompt2() {
|
|
9280
|
-
const list = SOURCE_LANGUAGES.map((l) => `${l.code} (${l.name})`).join("\n");
|
|
9281
|
-
return `You identify the language an article is written in.
|
|
9282
|
-
|
|
9283
|
-
Reply with exactly one code from this list, and nothing else:
|
|
9284
|
-
${list}
|
|
9285
|
-
|
|
9286
|
-
If the article is written in a language that is not on the list, or you cannot tell, reply with exactly: unknown
|
|
9287
|
-
|
|
9288
|
-
Rules:
|
|
9289
|
-
- Judge by the PROSE the author wrote, not by code, product names, technical terms, or quoted fragments. An article written in one language routinely keeps technical vocabulary in English; that does not make it English.
|
|
9290
|
-
- Mixed-language articles take the language the body is mostly written in.
|
|
9291
|
-
- Traditional Chinese is zh-TW and Simplified Chinese is zh-CN. Decide by the characters used, not by the topic.
|
|
9292
|
-
- Output the code alone. No explanation, no punctuation, no quotes.`;
|
|
9293
|
-
}
|
|
9294
|
-
async function detectSourceLanguage(title, content) {
|
|
9295
|
-
const apiKey = process.env["GROQ_API_KEY"];
|
|
9296
|
-
if (!apiKey) return null;
|
|
9297
|
-
const sample = languageSample(title, content);
|
|
9298
|
-
if (sample.length < MIN_SAMPLE_CHARS) return null;
|
|
9299
|
-
try {
|
|
9300
|
-
const res = await fetch(GROQ_API_URL4, {
|
|
9301
|
-
method: "POST",
|
|
9302
|
-
headers: { "content-type": "application/json", authorization: `Bearer ${apiKey}` },
|
|
9303
|
-
body: JSON.stringify({
|
|
9304
|
-
model: CLASSIFIER_MODEL,
|
|
9305
|
-
temperature: 0,
|
|
9306
|
-
reasoning_effort: "low",
|
|
9307
|
-
// gpt-oss reasons before it answers, and those tokens count against
|
|
9308
|
-
// this cap — 8 was right for the old non-reasoning model but leaves
|
|
9309
|
-
// no room for the answer itself here.
|
|
9310
|
-
max_tokens: 150,
|
|
9311
|
-
messages: [
|
|
9312
|
-
{ role: "system", content: systemPrompt2() },
|
|
9313
|
-
{ role: "user", content: sample }
|
|
9314
|
-
]
|
|
9315
|
-
})
|
|
9316
|
-
});
|
|
9317
|
-
if (!res.ok) return null;
|
|
9318
|
-
const data = await res.json();
|
|
9319
|
-
const answer = data.choices?.[0]?.message?.content?.trim() ?? "";
|
|
9320
|
-
return CODES.find((code) => code.toLowerCase() === answer.toLowerCase()) ?? null;
|
|
9321
|
-
} catch {
|
|
9322
|
-
return null;
|
|
9323
|
-
}
|
|
9324
|
-
}
|
|
9325
|
-
|
|
9326
9232
|
// ../api/src/dashboard/doc-share-publish.ts
|
|
9327
9233
|
var SHARE_KEY_PREFIX = "share";
|
|
9328
9234
|
function generateShareId() {
|
|
@@ -9576,17 +9482,17 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9576
9482
|
app.use("/:id/docs/share/*", requireDocsAccess);
|
|
9577
9483
|
app.use("/:id/docs/shares", requireDocsAccess);
|
|
9578
9484
|
app.get("/:id/docs/share", async (c) => {
|
|
9579
|
-
const
|
|
9580
|
-
if ("error" in
|
|
9485
|
+
const resolved = resolveChannel2(c);
|
|
9486
|
+
if ("error" in resolved) return resolved.error;
|
|
9581
9487
|
const path = c.req.query("path") ?? "";
|
|
9582
9488
|
if (!path) return c.json({ error: "path is required" }, 400);
|
|
9583
|
-
const share = await findDocShareBySource(
|
|
9489
|
+
const share = await findDocShareBySource(resolved.auth.workspaceId, resolved.channel.id, path);
|
|
9584
9490
|
return c.json({ share: share ? shareJson(c, share) : null });
|
|
9585
9491
|
});
|
|
9586
9492
|
app.get("/:id/docs/shares", async (c) => {
|
|
9587
|
-
const
|
|
9588
|
-
if ("error" in
|
|
9589
|
-
const shares = await listLiveDocShares([
|
|
9493
|
+
const resolved = resolveChannel2(c);
|
|
9494
|
+
if ("error" in resolved) return resolved.error;
|
|
9495
|
+
const shares = await listLiveDocShares([resolved.channel.id], LIST_LIMIT + 1);
|
|
9590
9496
|
return c.json({
|
|
9591
9497
|
truncated: shares.length > LIST_LIMIT,
|
|
9592
9498
|
shares: shares.slice(0, LIST_LIMIT).map((s) => ({
|
|
@@ -9599,14 +9505,14 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9599
9505
|
});
|
|
9600
9506
|
});
|
|
9601
9507
|
app.get("/:id/docs/share/slug", async (c) => {
|
|
9602
|
-
const
|
|
9603
|
-
if ("error" in
|
|
9508
|
+
const resolved = resolveChannel2(c);
|
|
9509
|
+
if ("error" in resolved) return resolved.error;
|
|
9604
9510
|
const normalized = normalizeSlug(c.req.query("slug") ?? "");
|
|
9605
9511
|
if ("error" in normalized) {
|
|
9606
9512
|
return c.json({ available: false, reason: slugErrorMessage(normalized.error) });
|
|
9607
9513
|
}
|
|
9608
9514
|
const path = c.req.query("path");
|
|
9609
|
-
const own = path ? await findDocShareBySource(
|
|
9515
|
+
const own = path ? await findDocShareBySource(resolved.auth.workspaceId, resolved.channel.id, path) : null;
|
|
9610
9516
|
const available = await isSlugAvailable(normalized.slug, own?.id);
|
|
9611
9517
|
return c.json({
|
|
9612
9518
|
slug: normalized.slug,
|
|
@@ -9615,8 +9521,8 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9615
9521
|
});
|
|
9616
9522
|
});
|
|
9617
9523
|
app.post("/:id/docs/share", async (c) => {
|
|
9618
|
-
const
|
|
9619
|
-
if ("error" in
|
|
9524
|
+
const resolved = resolveChannel2(c);
|
|
9525
|
+
if ("error" in resolved) return resolved.error;
|
|
9620
9526
|
const body = await c.req.json().catch(() => null);
|
|
9621
9527
|
if (!body || typeof body["path"] !== "string" || !body["path"]) {
|
|
9622
9528
|
return c.json({ error: "path is required" }, 400);
|
|
@@ -9624,18 +9530,18 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9624
9530
|
const slug = readSlug(body);
|
|
9625
9531
|
if ("invalid" in slug)
|
|
9626
9532
|
return c.json({ error: slugErrorMessage(slug.invalid), field: "slug" }, 400);
|
|
9627
|
-
const { cwd } = resolveChannelConfig(
|
|
9533
|
+
const { cwd } = resolveChannelConfig(resolved.channel.id);
|
|
9628
9534
|
let result;
|
|
9629
9535
|
try {
|
|
9630
9536
|
const readBundle = agent.readDocShareBundle;
|
|
9631
9537
|
result = readBundle ? await publishDocShare(
|
|
9632
9538
|
{
|
|
9633
9539
|
cwd,
|
|
9634
|
-
workspaceId:
|
|
9635
|
-
profile:
|
|
9636
|
-
channelId:
|
|
9540
|
+
workspaceId: resolved.auth.workspaceId,
|
|
9541
|
+
profile: resolved.channel.profile,
|
|
9542
|
+
channelId: resolved.channel.id,
|
|
9637
9543
|
sourcePath: body["path"],
|
|
9638
|
-
createdBy:
|
|
9544
|
+
createdBy: resolved.auth.email,
|
|
9639
9545
|
..."slug" in slug ? { slug: slug.slug } : {},
|
|
9640
9546
|
features: readFeatures(body)
|
|
9641
9547
|
},
|
|
@@ -9674,8 +9580,8 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9674
9580
|
}
|
|
9675
9581
|
});
|
|
9676
9582
|
app.patch("/:id/docs/share", async (c) => {
|
|
9677
|
-
const
|
|
9678
|
-
if ("error" in
|
|
9583
|
+
const resolved = resolveChannel2(c);
|
|
9584
|
+
if ("error" in resolved) return resolved.error;
|
|
9679
9585
|
const body = await c.req.json().catch(() => null);
|
|
9680
9586
|
if (!body || typeof body["path"] !== "string" || !body["path"]) {
|
|
9681
9587
|
return c.json({ error: "path is required" }, 400);
|
|
@@ -9694,8 +9600,8 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9694
9600
|
);
|
|
9695
9601
|
}
|
|
9696
9602
|
const existing = await findDocShareBySource(
|
|
9697
|
-
|
|
9698
|
-
|
|
9603
|
+
resolved.auth.workspaceId,
|
|
9604
|
+
resolved.channel.id,
|
|
9699
9605
|
body["path"]
|
|
9700
9606
|
);
|
|
9701
9607
|
if (!existing) return c.json({ error: "not shared" }, 404);
|
|
@@ -9721,13 +9627,13 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9721
9627
|
return c.json(shareJson(c, updated));
|
|
9722
9628
|
});
|
|
9723
9629
|
app.delete("/:id/docs/share", async (c) => {
|
|
9724
|
-
const
|
|
9725
|
-
if ("error" in
|
|
9630
|
+
const resolved = resolveChannel2(c);
|
|
9631
|
+
if ("error" in resolved) return resolved.error;
|
|
9726
9632
|
const path = c.req.query("path") ?? "";
|
|
9727
9633
|
if (!path) return c.json({ error: "path is required" }, 400);
|
|
9728
9634
|
const existing = await findDocShareBySource(
|
|
9729
|
-
|
|
9730
|
-
|
|
9635
|
+
resolved.auth.workspaceId,
|
|
9636
|
+
resolved.channel.id,
|
|
9731
9637
|
path
|
|
9732
9638
|
);
|
|
9733
9639
|
if (!existing) return c.json({ error: "not shared" }, 404);
|
|
@@ -10087,7 +9993,7 @@ function createTranscribeRouter() {
|
|
|
10087
9993
|
|
|
10088
9994
|
// ../api/src/dashboard/autocomplete-routes.ts
|
|
10089
9995
|
import { Hono as Hono18 } from "hono";
|
|
10090
|
-
var
|
|
9996
|
+
var GROQ_API_URL4 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10091
9997
|
var MODEL3 = "openai/gpt-oss-120b";
|
|
10092
9998
|
var MAX_REPLY_CHARS = 4e3;
|
|
10093
9999
|
var MAX_EARLIER_CHARS = 1500;
|
|
@@ -10110,7 +10016,7 @@ function createAutocompleteRouter() {
|
|
|
10110
10016
|
const context = `Channel: #${channel.name}${channel.prompt ? `
|
|
10111
10017
|
Channel instructions: ${channel.prompt.slice(0, 500)}` : ""}
|
|
10112
10018
|
${thread}`;
|
|
10113
|
-
const res = await fetch(
|
|
10019
|
+
const res = await fetch(GROQ_API_URL4, {
|
|
10114
10020
|
method: "POST",
|
|
10115
10021
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10116
10022
|
signal: AbortSignal.timeout(5e3),
|
|
@@ -10164,7 +10070,7 @@ ${last.body.slice(-MAX_REPLY_CHARS)}`;
|
|
|
10164
10070
|
|
|
10165
10071
|
// ../api/src/dashboard/daily-line-routes.ts
|
|
10166
10072
|
import { Hono as Hono19 } from "hono";
|
|
10167
|
-
var
|
|
10073
|
+
var GROQ_API_URL5 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10168
10074
|
var MODEL4 = "openai/gpt-oss-120b";
|
|
10169
10075
|
var DAY_MS = 864e5;
|
|
10170
10076
|
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.
|
|
@@ -10210,7 +10116,7 @@ function createDailyLineRouter() {
|
|
|
10210
10116
|
const key = `${day}:${memory.id}:${language}`;
|
|
10211
10117
|
let text = cache3.get(key);
|
|
10212
10118
|
if (text === void 0) {
|
|
10213
|
-
const res = await fetch(
|
|
10119
|
+
const res = await fetch(GROQ_API_URL5, {
|
|
10214
10120
|
method: "POST",
|
|
10215
10121
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10216
10122
|
signal: AbortSignal.timeout(8e3),
|
|
@@ -10246,7 +10152,7 @@ Write it in ${language} (BCP 47 tag). For Chinese use Traditional Chinese (Taiwa
|
|
|
10246
10152
|
|
|
10247
10153
|
// ../api/src/dashboard/channel-route.ts
|
|
10248
10154
|
import { Hono as Hono20 } from "hono";
|
|
10249
|
-
var
|
|
10155
|
+
var GROQ_API_URL6 = "https://api.groq.com/openai/v1/chat/completions";
|
|
10250
10156
|
var MODEL5 = "openai/gpt-oss-120b";
|
|
10251
10157
|
var MAX_MESSAGE_CHARS2 = 3e3;
|
|
10252
10158
|
var MAX_PROMPT_CHARS2 = 300;
|
|
@@ -10264,7 +10170,7 @@ async function describeImages(text, workspace, apiKey) {
|
|
|
10264
10170
|
(u) => !!u
|
|
10265
10171
|
);
|
|
10266
10172
|
if (urls.length === 0) return "";
|
|
10267
|
-
const res = await fetch(
|
|
10173
|
+
const res = await fetch(GROQ_API_URL6, {
|
|
10268
10174
|
method: "POST",
|
|
10269
10175
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10270
10176
|
signal: AbortSignal.timeout(1e4),
|
|
@@ -10339,7 +10245,7 @@ function createChannelRouteRouter() {
|
|
|
10339
10245
|
titles.get(ch.id)?.length ? ` Recent topics: ${titles.get(ch.id).join(" | ")}` : ""
|
|
10340
10246
|
].filter(Boolean).join("\n")
|
|
10341
10247
|
).join("\n");
|
|
10342
|
-
const res = await fetch(
|
|
10248
|
+
const res = await fetch(GROQ_API_URL6, {
|
|
10343
10249
|
method: "POST",
|
|
10344
10250
|
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
10345
10251
|
signal: AbortSignal.timeout(8e3),
|
|
@@ -10710,73 +10616,6 @@ function createMembersRouter() {
|
|
|
10710
10616
|
// ../api/src/dashboard/notifications-routes.ts
|
|
10711
10617
|
import { Hono as Hono23 } from "hono";
|
|
10712
10618
|
|
|
10713
|
-
// ../api/src/store/notification-store.ts
|
|
10714
|
-
function rowToNotification(row) {
|
|
10715
|
-
const reply = row["thread_replies"];
|
|
10716
|
-
return {
|
|
10717
|
-
id: row["id"],
|
|
10718
|
-
threadId: row["thread_id"],
|
|
10719
|
-
channelId: row["channel_id"],
|
|
10720
|
-
replyId: row["reply_id"] ?? null,
|
|
10721
|
-
kind: row["kind"],
|
|
10722
|
-
createdAt: row["created_at"],
|
|
10723
|
-
author: reply?.author ?? null,
|
|
10724
|
-
body: reply?.body ?? null
|
|
10725
|
-
};
|
|
10726
|
-
}
|
|
10727
|
-
async function listUnreadNotifications(channelIds, userId, limit = 100) {
|
|
10728
|
-
if (channelIds.length === 0) return [];
|
|
10729
|
-
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("id, thread_id, channel_id, reply_id, kind, created_at, thread_replies (author, body)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).order("created_at", { ascending: false }).limit(limit);
|
|
10730
|
-
if (error2) throw new Error(`listUnreadNotifications(${userId}): ${error2.message}`);
|
|
10731
|
-
return (data ?? []).map(rowToNotification);
|
|
10732
|
-
}
|
|
10733
|
-
async function countUnreadNotifications(channelIds, userId) {
|
|
10734
|
-
if (channelIds.length === 0) return 0;
|
|
10735
|
-
const { count, error: error2 } = await getSupabaseClient().from("notifications").select("id, threads!inner(archived_at)", { count: "exact", head: true }).eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
10736
|
-
if (error2) throw new Error(`countUnreadNotifications(${userId}): ${error2.message}`);
|
|
10737
|
-
return count ?? 0;
|
|
10738
|
-
}
|
|
10739
|
-
async function countUnreadByChannel(channelIds, userId) {
|
|
10740
|
-
if (channelIds.length === 0) return {};
|
|
10741
|
-
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("channel_id, threads!inner(archived_at)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
10742
|
-
if (error2) throw new Error(`countUnreadByChannel(${userId}): ${error2.message}`);
|
|
10743
|
-
const byChannel = {};
|
|
10744
|
-
for (const row of data ?? []) {
|
|
10745
|
-
const channelId = row["channel_id"];
|
|
10746
|
-
byChannel[channelId] = (byChannel[channelId] ?? 0) + 1;
|
|
10747
|
-
}
|
|
10748
|
-
return byChannel;
|
|
10749
|
-
}
|
|
10750
|
-
async function countUnreadByThread(channelIds, userId) {
|
|
10751
|
-
if (channelIds.length === 0) return {};
|
|
10752
|
-
const { data, error: error2 } = await getSupabaseClient().from("notifications").select("thread_id, kind, threads!inner(archived_at)").eq("user_id", userId).in("channel_id", channelIds).is("read_at", null).is("threads.archived_at", null);
|
|
10753
|
-
if (error2) throw new Error(`countUnreadByThread(${userId}): ${error2.message}`);
|
|
10754
|
-
const byThread = {};
|
|
10755
|
-
for (const row of data ?? []) {
|
|
10756
|
-
const threadId = row["thread_id"];
|
|
10757
|
-
const entry = byThread[threadId] ?? { count: 0, mention: false };
|
|
10758
|
-
entry.count += 1;
|
|
10759
|
-
if (row["kind"] === "mention") entry.mention = true;
|
|
10760
|
-
byThread[threadId] = entry;
|
|
10761
|
-
}
|
|
10762
|
-
return byThread;
|
|
10763
|
-
}
|
|
10764
|
-
async function markThreadRead(userId, threadId) {
|
|
10765
|
-
const supabase = getSupabaseClient();
|
|
10766
|
-
const { error: readError } = await supabase.from("thread_reads").upsert(
|
|
10767
|
-
{ user_id: userId, thread_id: threadId, seen_at: (/* @__PURE__ */ new Date()).toISOString() },
|
|
10768
|
-
{ onConflict: "user_id,thread_id" }
|
|
10769
|
-
);
|
|
10770
|
-
if (readError) throw new Error(`markThreadRead(${threadId}): ${readError.message}`);
|
|
10771
|
-
const { error: notifError } = await supabase.from("notifications").update({ read_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("user_id", userId).eq("thread_id", threadId).is("read_at", null);
|
|
10772
|
-
if (notifError) throw new Error(`markThreadRead(${threadId}): ${notifError.message}`);
|
|
10773
|
-
}
|
|
10774
|
-
async function markAllRead(channelIds, userId) {
|
|
10775
|
-
if (channelIds.length === 0) return;
|
|
10776
|
-
const { error: error2 } = await getSupabaseClient().from("notifications").update({ read_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("user_id", userId).in("channel_id", channelIds).is("read_at", null);
|
|
10777
|
-
if (error2) throw new Error(`markAllRead(${userId}): ${error2.message}`);
|
|
10778
|
-
}
|
|
10779
|
-
|
|
10780
10619
|
// ../api/src/store/push-store.ts
|
|
10781
10620
|
function rowToSubscription(row) {
|
|
10782
10621
|
return {
|
|
@@ -10995,6 +10834,18 @@ function createThreadReadRouter() {
|
|
|
10995
10834
|
await markThreadRead(userId, threadId);
|
|
10996
10835
|
return c.json({ ok: true });
|
|
10997
10836
|
});
|
|
10837
|
+
threads.get("/threads/:threadId/workspace", async (c) => {
|
|
10838
|
+
const { userId } = c.get("auth");
|
|
10839
|
+
const owner = await resolveThreadOwner(c.req.param("threadId"));
|
|
10840
|
+
if (!owner || !await canReadThread(owner, userId)) {
|
|
10841
|
+
return c.json({ error: "not found" }, 404);
|
|
10842
|
+
}
|
|
10843
|
+
return c.json({
|
|
10844
|
+
workspace: owner.workspace,
|
|
10845
|
+
channelId: owner.channelId,
|
|
10846
|
+
threadId: owner.threadId
|
|
10847
|
+
});
|
|
10848
|
+
});
|
|
10998
10849
|
return threads;
|
|
10999
10850
|
}
|
|
11000
10851
|
|
|
@@ -11700,7 +11551,7 @@ async function buildChannelUsageReport(channelId, days, labelChannel) {
|
|
|
11700
11551
|
}
|
|
11701
11552
|
}
|
|
11702
11553
|
}
|
|
11703
|
-
var COMPACT_THRESHOLD_TOKENS = Number(process.env["SESSION_COMPACT_THRESHOLD_TOKENS"]) ||
|
|
11554
|
+
var COMPACT_THRESHOLD_TOKENS = Number(process.env["SESSION_COMPACT_THRESHOLD_TOKENS"]) || 8e4;
|
|
11704
11555
|
function contextOf(run4) {
|
|
11705
11556
|
if (!run4) return void 0;
|
|
11706
11557
|
const total = run4.inputTokens + run4.cacheReadTokens + run4.cacheCreationTokens;
|
|
@@ -12326,8 +12177,9 @@ var rowKey = (channelId, agent, sessionId) => `${channelId}:${agent}:${sessionId
|
|
|
12326
12177
|
function replyRows(threadId, messages, author, fallbackAt) {
|
|
12327
12178
|
return messages.map((m, i) => ({
|
|
12328
12179
|
thread_id: threadId,
|
|
12329
|
-
author: m.role === "user" ? author : AGENT_AUTHOR,
|
|
12180
|
+
author: m.role === "user" && !m.compactSummary ? author : AGENT_AUTHOR,
|
|
12330
12181
|
body: m.text,
|
|
12182
|
+
...m.compactSummary ? { author_kind: "compact_summary" } : {},
|
|
12331
12183
|
created_at: m.at ?? new Date(fallbackAt + i).toISOString()
|
|
12332
12184
|
}));
|
|
12333
12185
|
}
|
|
@@ -12911,12 +12763,17 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12911
12763
|
const memberOf = new Set(
|
|
12912
12764
|
(memberships ?? []).map((m) => m.workspace_id)
|
|
12913
12765
|
);
|
|
12914
|
-
const
|
|
12915
|
-
allowed.
|
|
12766
|
+
const live = workspaces.filter((w) => !w.archivedAt);
|
|
12767
|
+
const allowed = new Set(live.filter((w) => memberOf.has(w.id)).map((w) => w.slug));
|
|
12768
|
+
if (live.some((w) => w.slug === active)) allowed.add(active);
|
|
12769
|
+
const bySlug = new Map(live.map((w) => [w.slug, w]));
|
|
12916
12770
|
const list = await Promise.all(
|
|
12917
12771
|
known.filter((name) => allowed.has(name)).map(async (name) => {
|
|
12918
12772
|
const branding = await loadWorkspaceBranding(name);
|
|
12773
|
+
const w = bySlug.get(name);
|
|
12774
|
+
const billing = w?.planStatus === "canceled" ? "expired" : w?.planStatus === "paused" || w?.trialEndsAt && Date.parse(w.trialEndsAt) < Date.now() ? "trial_ended" : void 0;
|
|
12919
12775
|
return {
|
|
12776
|
+
billing,
|
|
12920
12777
|
name,
|
|
12921
12778
|
active: name === active,
|
|
12922
12779
|
running: running2.has(name),
|
|
@@ -13023,7 +12880,7 @@ async function readBody(c) {
|
|
|
13023
12880
|
return {};
|
|
13024
12881
|
}
|
|
13025
12882
|
}
|
|
13026
|
-
async function
|
|
12883
|
+
async function sessionUserId(c) {
|
|
13027
12884
|
try {
|
|
13028
12885
|
const { data } = await createRequestSupabaseClient(c).auth.getUser();
|
|
13029
12886
|
return data.user?.id ?? null;
|
|
@@ -13126,7 +12983,7 @@ function createDeviceAuthRouter() {
|
|
|
13126
12983
|
return c.json({ ok: true });
|
|
13127
12984
|
});
|
|
13128
12985
|
app.get("/lookup", async (c) => {
|
|
13129
|
-
const userId = await
|
|
12986
|
+
const userId = await sessionUserId(c);
|
|
13130
12987
|
if (!userId) return c.json({ error: "not signed in" }, 401);
|
|
13131
12988
|
const userCode = normalizeUserCode(c.req.query("user_code") ?? "");
|
|
13132
12989
|
const pending = userCode ? await getDeviceCodeByUserCode(userCode) : null;
|
|
@@ -13151,7 +13008,7 @@ function createDeviceAuthRouter() {
|
|
|
13151
13008
|
});
|
|
13152
13009
|
});
|
|
13153
13010
|
app.get("/workspace", async (c) => {
|
|
13154
|
-
const userId = await
|
|
13011
|
+
const userId = await sessionUserId(c);
|
|
13155
13012
|
if (!userId) return c.json({ error: "not signed in" }, 401);
|
|
13156
13013
|
const slug = getProfile();
|
|
13157
13014
|
const workspace = (await listAdminWorkspaces(userId)).find((w) => w.slug === slug);
|
|
@@ -13164,7 +13021,7 @@ function createDeviceAuthRouter() {
|
|
|
13164
13021
|
});
|
|
13165
13022
|
});
|
|
13166
13023
|
app.post("/approve", async (c) => {
|
|
13167
|
-
const userId = await
|
|
13024
|
+
const userId = await sessionUserId(c);
|
|
13168
13025
|
if (!userId) return c.json({ error: "not signed in" }, 401);
|
|
13169
13026
|
const body = await readBody(c);
|
|
13170
13027
|
const userCode = normalizeUserCode(typeof body["user_code"] === "string" ? body["user_code"] : "");
|
|
@@ -13502,12 +13359,13 @@ async function viewerProfile(c, known) {
|
|
|
13502
13359
|
listMembershipsByEmail(user.email),
|
|
13503
13360
|
listWorkspaces()
|
|
13504
13361
|
]);
|
|
13505
|
-
const
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
}
|
|
13510
|
-
|
|
13362
|
+
const byId = new Map(workspaces.filter((w) => !w.archivedAt).map((w) => [w.id, w]));
|
|
13363
|
+
const candidates = memberships.map((m) => ({ m, w: byId.get(m.workspaceId) })).filter(
|
|
13364
|
+
(x) => !!x.w && known.includes(x.w.slug)
|
|
13365
|
+
);
|
|
13366
|
+
const rank = ({ m, w }) => (m.isSupport ? 2 : 0) + (isLockedPlan(w.planStatus ?? null) ? 1 : 0);
|
|
13367
|
+
candidates.sort((a, b) => rank(a) - rank(b));
|
|
13368
|
+
return candidates[0]?.w.slug ?? null;
|
|
13511
13369
|
}
|
|
13512
13370
|
function createGatedRouter(agent, register) {
|
|
13513
13371
|
const api = new Hono35();
|
|
@@ -13530,8 +13388,8 @@ function createGatedRouter(agent, register) {
|
|
|
13530
13388
|
api.get("/public-branding", async (c) => {
|
|
13531
13389
|
const requested = c.req.query("workspace");
|
|
13532
13390
|
const known = await listKnownWorkspaces();
|
|
13533
|
-
const
|
|
13534
|
-
if (!
|
|
13391
|
+
const resolved = requested && known.includes(requested) ? requested : profileFromHost(trustedHost(c), known);
|
|
13392
|
+
if (!resolved) {
|
|
13535
13393
|
return c.json({
|
|
13536
13394
|
unknownWorkspace: isUnknownWorkspaceHost(trustedHost(c), known),
|
|
13537
13395
|
theme: BRANDING_DEFAULTS.theme,
|
|
@@ -13542,7 +13400,7 @@ function createGatedRouter(agent, register) {
|
|
|
13542
13400
|
logo: "/icons/favicon-64.png"
|
|
13543
13401
|
});
|
|
13544
13402
|
}
|
|
13545
|
-
const branding = await loadWorkspaceBranding(
|
|
13403
|
+
const branding = await loadWorkspaceBranding(resolved);
|
|
13546
13404
|
return c.json({
|
|
13547
13405
|
theme: branding.theme,
|
|
13548
13406
|
font: branding.font,
|
|
@@ -13557,7 +13415,7 @@ function createGatedRouter(agent, register) {
|
|
|
13557
13415
|
}
|
|
13558
13416
|
|
|
13559
13417
|
// src/dashboard/host-api.ts
|
|
13560
|
-
import { existsSync as existsSync24, readFileSync as
|
|
13418
|
+
import { existsSync as existsSync24, readFileSync as readFileSync18, statSync as statSync5 } from "fs";
|
|
13561
13419
|
import sharp5 from "sharp";
|
|
13562
13420
|
|
|
13563
13421
|
// src/dashboard/channels-routes.ts
|
|
@@ -13903,7 +13761,7 @@ async function resolveAgentIdentities(viewer) {
|
|
|
13903
13761
|
|
|
13904
13762
|
// ../api/src/dashboard/providers.ts
|
|
13905
13763
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
13906
|
-
import { existsSync as existsSync22, readFileSync as
|
|
13764
|
+
import { existsSync as existsSync22, readFileSync as readFileSync16 } from "fs";
|
|
13907
13765
|
import { homedir as homedir7 } from "os";
|
|
13908
13766
|
import { join as join14, resolve as resolve5 } from "path";
|
|
13909
13767
|
var PROVIDER_LABELS = {
|
|
@@ -13972,7 +13830,7 @@ function claudeAccount() {
|
|
|
13972
13830
|
function codexAccount() {
|
|
13973
13831
|
const home2 = process.env["CODEX_HOME"]?.trim() || join14(homedir7(), ".codex");
|
|
13974
13832
|
try {
|
|
13975
|
-
const auth = JSON.parse(
|
|
13833
|
+
const auth = JSON.parse(readFileSync16(join14(home2, "auth.json"), "utf8"));
|
|
13976
13834
|
const payload = auth.tokens?.id_token?.split(".")[1];
|
|
13977
13835
|
if (!payload) return void 0;
|
|
13978
13836
|
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
@@ -14003,7 +13861,7 @@ function providerStatuses() {
|
|
|
14003
13861
|
// src/dashboard/provider-login-host.ts
|
|
14004
13862
|
import { spawn as spawn4 } from "child_process";
|
|
14005
13863
|
import { randomUUID as randomUUID4 } from "crypto";
|
|
14006
|
-
import { chmodSync, existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as
|
|
13864
|
+
import { chmodSync, existsSync as existsSync23, mkdirSync as mkdirSync10, readFileSync as readFileSync17, writeFileSync as writeFileSync9 } from "fs";
|
|
14007
13865
|
import { createRequire } from "module";
|
|
14008
13866
|
import { dirname as dirname9, join as join15 } from "path";
|
|
14009
13867
|
import { Hono as Hono38 } from "hono";
|
|
@@ -14112,7 +13970,7 @@ async function startClaude() {
|
|
|
14112
13970
|
}
|
|
14113
13971
|
function saveClaudeToken(configFile, token) {
|
|
14114
13972
|
mkdirSync10(dirname9(configFile), { recursive: true });
|
|
14115
|
-
const current = existsSync23(configFile) ?
|
|
13973
|
+
const current = existsSync23(configFile) ? readFileSync17(configFile, "utf-8") : "";
|
|
14116
13974
|
writeFileSync9(configFile, upsertEnvLine(current, "CLAUDE_CODE_OAUTH_TOKEN", token), { mode: 384 });
|
|
14117
13975
|
const cached = cachedProfileConfig();
|
|
14118
13976
|
if (cached) cached.env["CLAUDE_CODE_OAUTH_TOKEN"] = token;
|
|
@@ -14347,7 +14205,7 @@ function registerHostRoutes(api) {
|
|
|
14347
14205
|
}
|
|
14348
14206
|
function tailFile(file, limit) {
|
|
14349
14207
|
if (!existsSync24(file)) return [];
|
|
14350
|
-
const lines =
|
|
14208
|
+
const lines = readFileSync18(file, "utf-8").split("\n");
|
|
14351
14209
|
if (lines.at(-1) === "") lines.pop();
|
|
14352
14210
|
return lines.slice(-limit);
|
|
14353
14211
|
}
|
|
@@ -14365,7 +14223,7 @@ function createHostApiRouter(agent = {}) {
|
|
|
14365
14223
|
|
|
14366
14224
|
// src/dashboard/agent-bridge-host.ts
|
|
14367
14225
|
import { sign as signRaw, timingSafeEqual } from "crypto";
|
|
14368
|
-
import { existsSync as existsSync26, readFileSync as
|
|
14226
|
+
import { existsSync as existsSync26, readFileSync as readFileSync21 } from "fs";
|
|
14369
14227
|
import dotenv2 from "dotenv";
|
|
14370
14228
|
import { WebSocket as WebSocket2 } from "ws";
|
|
14371
14229
|
|
|
@@ -14375,7 +14233,7 @@ import {
|
|
|
14375
14233
|
existsSync as existsSync25,
|
|
14376
14234
|
openSync as openSync2,
|
|
14377
14235
|
readdirSync as readdirSync4,
|
|
14378
|
-
readFileSync as
|
|
14236
|
+
readFileSync as readFileSync19,
|
|
14379
14237
|
readSync as readSync2,
|
|
14380
14238
|
realpathSync as realpathSync4
|
|
14381
14239
|
} from "fs";
|
|
@@ -14435,11 +14293,18 @@ function claudeMessages(lines) {
|
|
|
14435
14293
|
continue;
|
|
14436
14294
|
if (o["entrypoint"] === "sdk-cli") continue;
|
|
14437
14295
|
const role = o["type"];
|
|
14438
|
-
const
|
|
14296
|
+
const message = o["message"];
|
|
14297
|
+
if (message?.model === "<synthetic>") continue;
|
|
14298
|
+
const text = blocksText(message?.content, ["text"]);
|
|
14439
14299
|
if (!text || typeof o["uuid"] !== "string") continue;
|
|
14300
|
+
if (role === "user" && text.startsWith("[Request interrupted by user")) continue;
|
|
14440
14301
|
const at = typeof o["timestamp"] === "string" ? o["timestamp"] : null;
|
|
14302
|
+
if (o["isCompactSummary"]) {
|
|
14303
|
+
out.push({ uuid: o["uuid"], role: "assistant", text, at, compactSummary: true });
|
|
14304
|
+
continue;
|
|
14305
|
+
}
|
|
14441
14306
|
const last = out[out.length - 1];
|
|
14442
|
-
if (role === "assistant" && last?.role === "assistant") {
|
|
14307
|
+
if (role === "assistant" && last?.role === "assistant" && !last.compactSummary) {
|
|
14443
14308
|
last.text += `
|
|
14444
14309
|
|
|
14445
14310
|
${text}`;
|
|
@@ -14577,7 +14442,7 @@ function findTranscript(agent, sessionId) {
|
|
|
14577
14442
|
function readSessionMessages(agent, sessionId, afterUuid) {
|
|
14578
14443
|
const file = findTranscript(agent, sessionId);
|
|
14579
14444
|
if (!file) return null;
|
|
14580
|
-
const lines = parseLines(
|
|
14445
|
+
const lines = parseLines(readFileSync19(file, "utf-8"));
|
|
14581
14446
|
const messages = agent === "claude" ? claudeMessages(lines) : codexMessages(lines);
|
|
14582
14447
|
if (!afterUuid) return messages;
|
|
14583
14448
|
const idx = messages.findIndex((m) => m.uuid === afterUuid);
|
|
@@ -14634,7 +14499,7 @@ async function handleHostRequest(req) {
|
|
|
14634
14499
|
}
|
|
14635
14500
|
|
|
14636
14501
|
// src/dashboard/doc-share-publisher.ts
|
|
14637
|
-
import { readFileSync as
|
|
14502
|
+
import { readFileSync as readFileSync20, statSync as statSync6 } from "fs";
|
|
14638
14503
|
import { extname, posix } from "path";
|
|
14639
14504
|
var MAX_ASSET_BYTES = 20 * 1024 * 1024;
|
|
14640
14505
|
var MAX_CONTENT_BYTES = 2 * 1024 * 1024;
|
|
@@ -14749,7 +14614,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14749
14614
|
}
|
|
14750
14615
|
if (!stat.isFile()) return { status: "not-found" };
|
|
14751
14616
|
if (stat.size > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
14752
|
-
const source =
|
|
14617
|
+
const source = readFileSync20(abs, "utf8");
|
|
14753
14618
|
const title = extractTitle(abs, kind === "markdown" ? "md" : kind);
|
|
14754
14619
|
if (kind === "excalidraw") {
|
|
14755
14620
|
try {
|
|
@@ -14820,7 +14685,7 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14820
14685
|
let text = null;
|
|
14821
14686
|
try {
|
|
14822
14687
|
const size = statSync6(docAbs).size;
|
|
14823
|
-
if (size <= budget) text =
|
|
14688
|
+
if (size <= budget) text = readFileSync20(docAbs, "utf8");
|
|
14824
14689
|
} catch {
|
|
14825
14690
|
continue;
|
|
14826
14691
|
}
|
|
@@ -14832,19 +14697,19 @@ function readDocShareBundle({ cwd, sourcePath }) {
|
|
|
14832
14697
|
continue;
|
|
14833
14698
|
}
|
|
14834
14699
|
}
|
|
14835
|
-
const
|
|
14836
|
-
if (!
|
|
14700
|
+
const resolved = resolveRawPath(cwd, ref.rel) ?? (docAbs ? { abs: docAbs, contentType: "text/plain; charset=utf-8" } : null);
|
|
14701
|
+
if (!resolved) continue;
|
|
14837
14702
|
let body;
|
|
14838
14703
|
try {
|
|
14839
|
-
if (statSync6(
|
|
14840
|
-
body =
|
|
14704
|
+
if (statSync6(resolved.abs).size > MAX_ASSET_BYTES) continue;
|
|
14705
|
+
body = readFileSync20(resolved.abs);
|
|
14841
14706
|
} catch {
|
|
14842
14707
|
continue;
|
|
14843
14708
|
}
|
|
14844
14709
|
assetBytes += body.length;
|
|
14845
14710
|
if (assetBytes > MAX_BUNDLE_ASSET_BYTES) return { status: "too-large" };
|
|
14846
14711
|
const name = claimName(ref.rel.split("/").pop() ?? "file");
|
|
14847
|
-
assets.push({ name, contentType:
|
|
14712
|
+
assets.push({ name, contentType: resolved.contentType, data: body.toString("base64") });
|
|
14848
14713
|
rewritten.set(href, `${SHARE_ASSET_PLACEHOLDER}${name}`);
|
|
14849
14714
|
}
|
|
14850
14715
|
if (kind === "html") {
|
|
@@ -15016,7 +14881,7 @@ function buildHostConfigSnapshot() {
|
|
|
15016
14881
|
const snapshot2 = {};
|
|
15017
14882
|
for (const profile of listProfiles()) {
|
|
15018
14883
|
snapshot2[profile] = runWithProfile(profile, () => ({
|
|
15019
|
-
env: existsSync26(paths.CONFIG_FILE) ? dotenv2.parse(
|
|
14884
|
+
env: existsSync26(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync21(paths.CONFIG_FILE, "utf-8")) : {},
|
|
15020
14885
|
// Only a model someone actually saved: before that it is just the Claude
|
|
15021
14886
|
// default, which would show the wrong agent in admin for a Codex user.
|
|
15022
14887
|
agentModel: existsSync26(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
|
|
@@ -15106,6 +14971,10 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
|
|
|
15106
14971
|
handleAttachmentUrlResult(msg.id, msg.url);
|
|
15107
14972
|
return;
|
|
15108
14973
|
}
|
|
14974
|
+
if (msg.type === "should-respond-result") {
|
|
14975
|
+
handleShouldRespondResult(msg.id, msg.respond);
|
|
14976
|
+
return;
|
|
14977
|
+
}
|
|
15109
14978
|
if (msg.type === "call") {
|
|
15110
14979
|
void handleCall(msg, callbacks, ws);
|
|
15111
14980
|
}
|
|
@@ -15715,6 +15584,30 @@ async function runReconcileCmd(args) {
|
|
|
15715
15584
|
printLog(target, log5);
|
|
15716
15585
|
}
|
|
15717
15586
|
|
|
15587
|
+
// src/commands/desktop.ts
|
|
15588
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
15589
|
+
var SCRIPT_SH = "https://flyspace.ai/install-desktop.sh";
|
|
15590
|
+
var SCRIPT_PS1 = "https://flyspace.ai/install-desktop.ps1";
|
|
15591
|
+
var USAGE9 = "Usage: flyspace desktop install [--dev]";
|
|
15592
|
+
async function runDesktopCmd(args) {
|
|
15593
|
+
const [sub, ...rest] = args;
|
|
15594
|
+
if (sub !== "install" || rest.some((a) => a !== "--dev")) {
|
|
15595
|
+
printRaw(USAGE9);
|
|
15596
|
+
process.exit(1);
|
|
15597
|
+
}
|
|
15598
|
+
const dev = rest.includes("--dev");
|
|
15599
|
+
const result = process.platform === "win32" ? spawnSync2(
|
|
15600
|
+
"powershell",
|
|
15601
|
+
["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", `& ([scriptblock]::Create((irm ${SCRIPT_PS1})))${dev ? " -Dev" : ""}`],
|
|
15602
|
+
{ stdio: "inherit" }
|
|
15603
|
+
) : spawnSync2("bash", ["-c", `curl -fsSL ${SCRIPT_SH} | bash -s --${dev ? " --dev" : ""}`], { stdio: "inherit" });
|
|
15604
|
+
if (result.error) {
|
|
15605
|
+
printRaw(`Could not run the desktop installer: ${result.error.message}`);
|
|
15606
|
+
process.exit(1);
|
|
15607
|
+
}
|
|
15608
|
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
15609
|
+
}
|
|
15610
|
+
|
|
15718
15611
|
// src/cli.ts
|
|
15719
15612
|
import { join as join21 } from "path";
|
|
15720
15613
|
var home = flyspaceHome();
|
|
@@ -15724,7 +15617,7 @@ if (home) {
|
|
|
15724
15617
|
if (!path.split(":").includes(bin)) process.env.PATH = path ? `${bin}:${path}` : bin;
|
|
15725
15618
|
}
|
|
15726
15619
|
var XERO_USAGE = false ? " xero Connect to Xero and expose it as an MCP server\n" : "";
|
|
15727
|
-
var
|
|
15620
|
+
var USAGE10 = `
|
|
15728
15621
|
Usage: flyspace <command> [options]
|
|
15729
15622
|
|
|
15730
15623
|
Commands:
|
|
@@ -15737,6 +15630,7 @@ var USAGE9 = `
|
|
|
15737
15630
|
restart Restart the service
|
|
15738
15631
|
logs Tail the service log (-e for error log)
|
|
15739
15632
|
upgrade Upgrade Flyspace to the latest version
|
|
15633
|
+
desktop Install or update the desktop app (desktop install [--dev])
|
|
15740
15634
|
uninstall Remove Flyspace from this machine (CLI, services, config)
|
|
15741
15635
|
config Show resolved config (--edit to edit, --path for file path)
|
|
15742
15636
|
automation Manage scheduled tasks and triggers
|
|
@@ -15852,17 +15746,20 @@ async function main() {
|
|
|
15852
15746
|
case "dashboard":
|
|
15853
15747
|
await runDashboard(args.slice(1));
|
|
15854
15748
|
break;
|
|
15749
|
+
case "desktop":
|
|
15750
|
+
await runDesktopCmd(args.slice(1));
|
|
15751
|
+
break;
|
|
15855
15752
|
case "mcp":
|
|
15856
15753
|
await runMcpCmd(args.slice(1));
|
|
15857
15754
|
break;
|
|
15858
15755
|
case "-v":
|
|
15859
15756
|
case "--version":
|
|
15860
|
-
printRaw("0.1.
|
|
15757
|
+
printRaw("0.1.54");
|
|
15861
15758
|
break;
|
|
15862
15759
|
case "-h":
|
|
15863
15760
|
case "--help":
|
|
15864
15761
|
case void 0:
|
|
15865
|
-
printRaw(
|
|
15762
|
+
printRaw(USAGE10);
|
|
15866
15763
|
break;
|
|
15867
15764
|
case "xero":
|
|
15868
15765
|
if (false) {
|
|
@@ -15873,7 +15770,7 @@ async function main() {
|
|
|
15873
15770
|
// falls through
|
|
15874
15771
|
default:
|
|
15875
15772
|
printRaw(`Unknown command: ${command}`);
|
|
15876
|
-
printRaw(
|
|
15773
|
+
printRaw(USAGE10);
|
|
15877
15774
|
process.exit(1);
|
|
15878
15775
|
}
|
|
15879
15776
|
}
|