flyspace-cli 0.1.60 → 0.1.61
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-SIR6PTDT.js → chunk-METRJ6PG.js} +982 -315
- package/dist/chunk-PLLJ7M62.js +14799 -0
- package/dist/{chunk-XYS7SVWC.js → chunk-UZMHXV4D.js} +40 -742
- package/dist/cli.js +616 -111
- package/dist/index.js +2 -2
- package/dist/threads-BFRTS4EB.js +245 -0
- package/package.json +1 -1
- package/dist/chunk-PXZUNZ4S.js +0 -230
- package/dist/threads-QQRWT3OM.js +0 -382
package/dist/cli.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { createRequire as __flyspaceCreateRequire } from 'node:module';
|
|
3
3
|
const require = __flyspaceCreateRequire(import.meta.url);
|
|
4
4
|
import {
|
|
5
|
+
AGENT_AUTHOR,
|
|
5
6
|
AutomationManager,
|
|
6
7
|
BOT_DM_KEY,
|
|
7
8
|
BOT_LABEL,
|
|
@@ -9,8 +10,10 @@ import {
|
|
|
9
10
|
BRANDING_DEFAULTS,
|
|
10
11
|
BUILT_IN_OUTPUT_STYLES,
|
|
11
12
|
CLI_VERSION,
|
|
13
|
+
ChannelCwdError,
|
|
12
14
|
ChatAgent,
|
|
13
15
|
DEFAULT_TIMEZONE,
|
|
16
|
+
DefaultChannelError,
|
|
14
17
|
DocShareSlugTakenError,
|
|
15
18
|
HANDLE_PATTERN,
|
|
16
19
|
HandleTakenError,
|
|
@@ -25,12 +28,15 @@ import {
|
|
|
25
28
|
TRIAL_DAYS,
|
|
26
29
|
UsageStore,
|
|
27
30
|
agentViewer,
|
|
31
|
+
allowedOrigins,
|
|
32
|
+
auditChannelCwds,
|
|
28
33
|
authorFor,
|
|
29
34
|
blockToFallbackText,
|
|
30
35
|
bodyTextFor,
|
|
31
36
|
buildAuthorizeUrl,
|
|
32
37
|
buildAutoTitle,
|
|
33
38
|
cachedProfileConfig,
|
|
39
|
+
canSeeChannel,
|
|
34
40
|
canonicalLanguage,
|
|
35
41
|
channelSkillsDir,
|
|
36
42
|
claudeAuthFailed,
|
|
@@ -39,6 +45,7 @@ import {
|
|
|
39
45
|
codexAuthAvailable,
|
|
40
46
|
consumeOAuthState,
|
|
41
47
|
corsForShell,
|
|
48
|
+
createChannel,
|
|
42
49
|
createDocShare,
|
|
43
50
|
createDocsRouter,
|
|
44
51
|
createFeatureFlagsRouter,
|
|
@@ -67,18 +74,25 @@ import {
|
|
|
67
74
|
deleteWorkspace,
|
|
68
75
|
deleteWorkspaceDomain,
|
|
69
76
|
deriveConnectionSlug,
|
|
77
|
+
deriveThreadTitle,
|
|
70
78
|
detectSourceLanguage,
|
|
71
79
|
displayNameFor,
|
|
72
80
|
dropShareAudio,
|
|
73
81
|
dropShareLangAudioKeys,
|
|
74
82
|
effectiveModel,
|
|
83
|
+
ensureAgentDmChannel,
|
|
84
|
+
ensureGeneralChannel,
|
|
85
|
+
ensureMemberDmChannel,
|
|
75
86
|
ensureUsersCached,
|
|
76
87
|
escalateToHuman,
|
|
77
88
|
exchangeCode,
|
|
89
|
+
expandPath,
|
|
78
90
|
explainCost,
|
|
79
91
|
extractCategories,
|
|
80
92
|
extractTitle,
|
|
81
93
|
filterReadableDocsChannels,
|
|
94
|
+
findChannel,
|
|
95
|
+
findChannelById,
|
|
82
96
|
findDocShareBySource,
|
|
83
97
|
findOwningProfile,
|
|
84
98
|
findSkillDetail,
|
|
@@ -87,6 +101,7 @@ import {
|
|
|
87
101
|
getAllowGuestAccess,
|
|
88
102
|
getChannelDocsMemberAccess,
|
|
89
103
|
getChannelMemory,
|
|
104
|
+
getChannelRegistry,
|
|
90
105
|
getLocalCache,
|
|
91
106
|
getMcpConnection,
|
|
92
107
|
getMcpProvider,
|
|
@@ -94,6 +109,7 @@ import {
|
|
|
94
109
|
getMembershipByUserId,
|
|
95
110
|
getMemory,
|
|
96
111
|
getOutputStyleDefault,
|
|
112
|
+
getProfileChannelRegistry,
|
|
97
113
|
getWorkspaceAutoContinueLimit,
|
|
98
114
|
getWorkspaceBilling,
|
|
99
115
|
getWorkspaceBranding,
|
|
@@ -112,14 +128,19 @@ import {
|
|
|
112
128
|
installUsageRecording,
|
|
113
129
|
invalidateAuthContextCache,
|
|
114
130
|
isAllowedModel,
|
|
131
|
+
isCwdUsable,
|
|
115
132
|
isDevHost,
|
|
116
133
|
isDocsAccess,
|
|
117
134
|
isFeatureEnabled,
|
|
135
|
+
isHumanAuthor,
|
|
118
136
|
isLockedPlan,
|
|
137
|
+
isLogicalCwd,
|
|
119
138
|
isMemoryType,
|
|
120
139
|
isOlderVersion,
|
|
140
|
+
isPermissionMode,
|
|
121
141
|
isSlugAvailable,
|
|
122
142
|
isTranslatableLanguage,
|
|
143
|
+
isUnderLogicalRoot,
|
|
123
144
|
isUnknownWorkspaceHost,
|
|
124
145
|
isUuid,
|
|
125
146
|
isValidSkillName,
|
|
@@ -153,6 +174,8 @@ import {
|
|
|
153
174
|
loadFullDashboardSettings,
|
|
154
175
|
loadWorkspaceBranding,
|
|
155
176
|
loadWorkspacePrompt,
|
|
177
|
+
localDefaults,
|
|
178
|
+
markChannelGreeted,
|
|
156
179
|
markInviteResent,
|
|
157
180
|
markMemoryUsed,
|
|
158
181
|
markWorkspaceGreeted,
|
|
@@ -161,6 +184,7 @@ import {
|
|
|
161
184
|
mentionedUserIds,
|
|
162
185
|
onboardingPending,
|
|
163
186
|
pinnedClaudeConfigDir,
|
|
187
|
+
postToDashboardChannel,
|
|
164
188
|
profileClaudeConfigDir,
|
|
165
189
|
profileEnv,
|
|
166
190
|
profileFromHost,
|
|
@@ -172,6 +196,7 @@ import {
|
|
|
172
196
|
recentRunsForWorkspace,
|
|
173
197
|
refreshAutomationRegistry,
|
|
174
198
|
refreshCache,
|
|
199
|
+
refreshChannelRegistry,
|
|
175
200
|
refreshUserCache,
|
|
176
201
|
removeChannelMember,
|
|
177
202
|
renderAppIcon,
|
|
@@ -181,6 +206,8 @@ import {
|
|
|
181
206
|
resolveAuthContext,
|
|
182
207
|
resolveChannelConfig,
|
|
183
208
|
resolveChannelId,
|
|
209
|
+
resolveCwd,
|
|
210
|
+
resolveDashboardChannelId,
|
|
184
211
|
resolveDocPath,
|
|
185
212
|
resolveDocsAccess,
|
|
186
213
|
resolveRateCard,
|
|
@@ -220,15 +247,19 @@ import {
|
|
|
220
247
|
setWorkspaceStripeSubscription,
|
|
221
248
|
slackMrkdwnToMarkdown,
|
|
222
249
|
startAutomationRegistryPolling,
|
|
250
|
+
startChannelRegistryPolling,
|
|
223
251
|
startServer,
|
|
224
252
|
suggestChannelField,
|
|
253
|
+
syncPostToDashboard,
|
|
225
254
|
syncSlackAvatars,
|
|
226
255
|
syncSupportReply,
|
|
227
256
|
transferWorkspaceAdmin,
|
|
228
257
|
trustedHost,
|
|
229
258
|
tsToIso,
|
|
230
259
|
undoMemoryEvent,
|
|
260
|
+
updateChannelById,
|
|
231
261
|
updateChannelMemory,
|
|
262
|
+
updateChannelsMcpConnections,
|
|
232
263
|
updateDocShareFeatures,
|
|
233
264
|
updateDocShareSnapshot,
|
|
234
265
|
updateMcpConnectionSettings,
|
|
@@ -245,101 +276,80 @@ import {
|
|
|
245
276
|
useDirectSupabase,
|
|
246
277
|
useLocalCache,
|
|
247
278
|
validateMemoryInput,
|
|
279
|
+
warnOnBrokenChannelCwds,
|
|
248
280
|
workspaceHostname,
|
|
249
281
|
workspaceSkillsDir,
|
|
250
282
|
writeSkillFile
|
|
251
|
-
} from "./chunk-
|
|
283
|
+
} from "./chunk-METRJ6PG.js";
|
|
252
284
|
import {
|
|
253
|
-
|
|
285
|
+
checkPermissionAction,
|
|
286
|
+
createThreadAction,
|
|
254
287
|
firstReplyBody,
|
|
255
288
|
getThread,
|
|
256
289
|
listChannels,
|
|
290
|
+
listChannelsAction,
|
|
257
291
|
listThreads,
|
|
258
|
-
|
|
292
|
+
moveThread,
|
|
293
|
+
moveThreadAction,
|
|
294
|
+
postReplyAction,
|
|
295
|
+
readThreadAction,
|
|
296
|
+
requestPermissionAction,
|
|
259
297
|
resolveChannel,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
298
|
+
runDocsCmd,
|
|
299
|
+
searchThreadsAction,
|
|
300
|
+
shareDocAction
|
|
301
|
+
} from "./chunk-PLLJ7M62.js";
|
|
263
302
|
import {
|
|
264
|
-
AGENT_AUTHOR,
|
|
265
303
|
AuthApiError,
|
|
266
|
-
ChannelCwdError,
|
|
267
304
|
DEFAULT_API_URL,
|
|
268
305
|
DEFAULT_PROFILE,
|
|
269
|
-
|
|
306
|
+
LOCAL_ACTION_PATH,
|
|
270
307
|
LOCAL_DB_PATH,
|
|
271
|
-
LOCAL_DOC_SHARE_PATH,
|
|
272
308
|
SCRATCH_PREFIX,
|
|
273
309
|
SLACK_ENV,
|
|
274
310
|
SessionStore,
|
|
275
311
|
acquireHostLock,
|
|
276
312
|
apiUrl,
|
|
277
|
-
auditChannelCwds,
|
|
278
313
|
boundWorkspaces,
|
|
279
|
-
canSeeChannel,
|
|
280
314
|
clearLocalAuth,
|
|
281
|
-
createChannel,
|
|
282
315
|
createHostDbClient,
|
|
283
316
|
credentialsPath,
|
|
284
317
|
databaseReachable,
|
|
285
318
|
deviceKeyPath,
|
|
286
|
-
ensureAgentDmChannel,
|
|
287
319
|
ensureDeviceKey,
|
|
288
320
|
ensureDirs,
|
|
289
|
-
ensureGeneralChannel,
|
|
290
|
-
ensureMemberDmChannel,
|
|
291
|
-
expandPath,
|
|
292
321
|
fetchWhoAmI,
|
|
293
|
-
findChannel,
|
|
294
|
-
findChannelById,
|
|
295
322
|
getAccessToken,
|
|
296
|
-
getChannelRegistry,
|
|
297
323
|
getProfile,
|
|
298
|
-
getProfileChannelRegistry,
|
|
299
324
|
getR2Bucket,
|
|
300
325
|
getR2Client,
|
|
301
326
|
getSupabaseClient,
|
|
327
|
+
handleActionResult,
|
|
302
328
|
handleAttachmentUrlResult,
|
|
303
|
-
handleDocShareResult,
|
|
304
329
|
handleHostDbResult,
|
|
305
330
|
handlePluginSvgResult,
|
|
306
331
|
handleShouldRespondResult,
|
|
307
|
-
isCwdUsable,
|
|
308
332
|
isEffort,
|
|
309
|
-
isHumanAuthor,
|
|
310
|
-
isLogicalCwd,
|
|
311
|
-
isPermissionMode,
|
|
312
|
-
isUnderLogicalRoot,
|
|
313
333
|
loadConfig,
|
|
314
334
|
loadCredentials,
|
|
315
335
|
loadEnvFiles,
|
|
316
|
-
markChannelGreeted,
|
|
317
336
|
paths,
|
|
318
337
|
pollDeviceToken,
|
|
319
|
-
postToDashboardChannel,
|
|
320
338
|
publishHostEndpoint,
|
|
321
339
|
readHostEndpoint,
|
|
322
|
-
|
|
340
|
+
requestAction,
|
|
323
341
|
requestDeviceCode,
|
|
324
|
-
requestDocShare,
|
|
325
342
|
requestHostDb,
|
|
326
343
|
requireSlackBotToken,
|
|
327
|
-
resolveCwd,
|
|
328
|
-
resolveDashboardChannelId,
|
|
329
344
|
revokeDevice,
|
|
330
345
|
runWithProfile,
|
|
331
346
|
saveCredentials,
|
|
332
347
|
setHostDbSender,
|
|
333
348
|
setSupabaseClient,
|
|
334
349
|
slackConfigured,
|
|
335
|
-
startChannelRegistryPolling,
|
|
336
350
|
sumR2PrefixBytes,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
updateChannelsMcpConnections,
|
|
340
|
-
useHostDbWithoutCredentials,
|
|
341
|
-
warnOnBrokenChannelCwds
|
|
342
|
-
} from "./chunk-XYS7SVWC.js";
|
|
351
|
+
useHostDbWithoutCredentials
|
|
352
|
+
} from "./chunk-UZMHXV4D.js";
|
|
343
353
|
|
|
344
354
|
// ../core/src/logger.ts
|
|
345
355
|
var ALREADY_STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
@@ -2196,7 +2206,7 @@ function npmEnv(target) {
|
|
|
2196
2206
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
2197
2207
|
}
|
|
2198
2208
|
async function runUpgrade() {
|
|
2199
|
-
const current = "0.1.
|
|
2209
|
+
const current = "0.1.61";
|
|
2200
2210
|
console.log(`Current version: ${current}`);
|
|
2201
2211
|
console.log("Checking for updates...\n");
|
|
2202
2212
|
try {
|
|
@@ -3057,17 +3067,17 @@ async function issueInvite(membershipId, message) {
|
|
|
3057
3067
|
const db = getSupabaseClient();
|
|
3058
3068
|
const token = randomBytes(32).toString("hex");
|
|
3059
3069
|
const expiresAt = new Date(Date.now() + INVITE_TTL_DAYS * 24 * 60 * 60 * 1e3).toISOString();
|
|
3060
|
-
const { data:
|
|
3070
|
+
const { data: pending2, error: pendingError } = await db.from("workspace_invites").select("id, token_hash, previous_token_hashes").eq("membership_id", membershipId).is("accepted_at", null).order("created_at", { ascending: false }).limit(1).maybeSingle();
|
|
3061
3071
|
if (pendingError) throw new Error(`issueInvite(${membershipId}): ${pendingError.message}`);
|
|
3062
|
-
const { error: error2 } =
|
|
3072
|
+
const { error: error2 } = pending2 ? await db.from("workspace_invites").update({
|
|
3063
3073
|
token_hash: hashInviteToken(token),
|
|
3064
3074
|
previous_token_hashes: [
|
|
3065
|
-
...
|
|
3066
|
-
|
|
3075
|
+
...pending2.previous_token_hashes ?? [],
|
|
3076
|
+
pending2.token_hash
|
|
3067
3077
|
],
|
|
3068
3078
|
message,
|
|
3069
3079
|
expires_at: expiresAt
|
|
3070
|
-
}).eq("id",
|
|
3080
|
+
}).eq("id", pending2.id) : await db.from("workspace_invites").insert({
|
|
3071
3081
|
membership_id: membershipId,
|
|
3072
3082
|
token_hash: hashInviteToken(token),
|
|
3073
3083
|
message,
|
|
@@ -5654,10 +5664,31 @@ async function runSlackCmd(args) {
|
|
|
5654
5664
|
}
|
|
5655
5665
|
}
|
|
5656
5666
|
|
|
5667
|
+
// src/store/thread-move.ts
|
|
5668
|
+
async function moveThreadFully(threadId, toChannelId) {
|
|
5669
|
+
const thread = await getThread(threadId);
|
|
5670
|
+
if (!thread) throw new Error(`No thread with id ${threadId}.`);
|
|
5671
|
+
if (thread.channelId === toChannelId) return "unchanged";
|
|
5672
|
+
const channels = await listChannels();
|
|
5673
|
+
const to = channels.find((c) => c.id === toChannelId);
|
|
5674
|
+
if (!to) throw new Error(`No channel with id ${toChannelId}.`);
|
|
5675
|
+
const from = channels.find((c) => c.id === thread.channelId);
|
|
5676
|
+
const store = new SessionStore(paths.DB_FILE);
|
|
5677
|
+
try {
|
|
5678
|
+
await moveThread(thread.id, to.id);
|
|
5679
|
+
const counts = store.moveThread(`chat:${thread.channelId}`, `chat:${to.id}`, thread.id);
|
|
5680
|
+
return { from, to, ...counts, cwdChanged: !!from && from.cwd !== to.cwd };
|
|
5681
|
+
} finally {
|
|
5682
|
+
store.close();
|
|
5683
|
+
}
|
|
5684
|
+
}
|
|
5685
|
+
|
|
5657
5686
|
// ../core/src/bridge-protocol.ts
|
|
5658
5687
|
var HOST_SOCKET_PATH = "/internal/host-socket";
|
|
5659
5688
|
var DEFAULT_DATA_API_PORT = 4757;
|
|
5660
5689
|
var CALL_TIMEOUT_MS = 15e3;
|
|
5690
|
+
var DOCS_CALL_TIMEOUT_MS = 12e4;
|
|
5691
|
+
var MEMORY_EXTRACTION_TIMEOUT_MS = 165e3;
|
|
5661
5692
|
var HEARTBEAT_INTERVAL_MS = 15e3;
|
|
5662
5693
|
var HEARTBEAT_TIMEOUT_MS = HEARTBEAT_INTERVAL_MS * 2.5;
|
|
5663
5694
|
var LOCAL_RELAY_PATH = "/internal/agent-call";
|
|
@@ -6124,7 +6155,7 @@ async function runMcpCmd(args) {
|
|
|
6124
6155
|
useHostDbWithoutCredentials();
|
|
6125
6156
|
switch (server) {
|
|
6126
6157
|
case "threads": {
|
|
6127
|
-
const { startThreadsServer } = await import("./threads-
|
|
6158
|
+
const { startThreadsServer } = await import("./threads-BFRTS4EB.js");
|
|
6128
6159
|
await startThreadsServer();
|
|
6129
6160
|
return;
|
|
6130
6161
|
}
|
|
@@ -6412,26 +6443,26 @@ async function decideDeviceCode(id, userId, decision) {
|
|
|
6412
6443
|
if (error2) fail("decideDeviceCode", error2);
|
|
6413
6444
|
return (data ?? []).length > 0;
|
|
6414
6445
|
}
|
|
6415
|
-
async function redeemDeviceCode(
|
|
6446
|
+
async function redeemDeviceCode(pending2) {
|
|
6416
6447
|
const db = getSupabaseClient();
|
|
6417
|
-
const { data: claimed, error: claimError } = await db.from("device_codes").delete().eq("id",
|
|
6448
|
+
const { data: claimed, error: claimError } = await db.from("device_codes").delete().eq("id", pending2.id).select("id");
|
|
6418
6449
|
if (claimError) fail("redeemDeviceCode", claimError);
|
|
6419
6450
|
if (!claimed?.length) return null;
|
|
6420
|
-
const existing =
|
|
6421
|
-
const { data, error: error2 } = existing ? await db.from("devices").update({ name:
|
|
6422
|
-
user_id:
|
|
6423
|
-
name:
|
|
6424
|
-
platform:
|
|
6425
|
-
public_key:
|
|
6451
|
+
const existing = pending2.approvedBy ? await findDeviceByKey(pending2.publicKey, pending2.approvedBy) : null;
|
|
6452
|
+
const { data, error: error2 } = existing ? await db.from("devices").update({ name: pending2.name, platform: pending2.platform }).eq("id", existing.id).select("*").single() : await db.from("devices").insert({
|
|
6453
|
+
user_id: pending2.approvedBy,
|
|
6454
|
+
name: pending2.name,
|
|
6455
|
+
platform: pending2.platform,
|
|
6456
|
+
public_key: pending2.publicKey
|
|
6426
6457
|
}).select("*").single();
|
|
6427
6458
|
if (error2) fail("redeemDeviceCode", error2);
|
|
6428
6459
|
const device = toDevice(data);
|
|
6429
|
-
if (
|
|
6460
|
+
if (pending2.workspaceIds.length) {
|
|
6430
6461
|
const { error: bindError } = await db.from("device_workspaces").upsert(
|
|
6431
|
-
|
|
6462
|
+
pending2.workspaceIds.map((workspaceId) => ({
|
|
6432
6463
|
device_id: device.id,
|
|
6433
6464
|
workspace_id: workspaceId,
|
|
6434
|
-
bound_by:
|
|
6465
|
+
bound_by: pending2.approvedBy
|
|
6435
6466
|
})),
|
|
6436
6467
|
{ onConflict: "device_id,workspace_id", ignoreDuplicates: true }
|
|
6437
6468
|
);
|
|
@@ -6641,6 +6672,81 @@ function createUploadsRouter() {
|
|
|
6641
6672
|
return app;
|
|
6642
6673
|
}
|
|
6643
6674
|
|
|
6675
|
+
// ../api/src/dashboard/thread-access.ts
|
|
6676
|
+
var ON_BEHALF_HEADER = "x-flyspace-on-behalf-of";
|
|
6677
|
+
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
6678
|
+
function parseThreadRef(input2) {
|
|
6679
|
+
const raw = input2.trim();
|
|
6680
|
+
if (UUID.test(raw)) return raw.toLowerCase();
|
|
6681
|
+
let url;
|
|
6682
|
+
try {
|
|
6683
|
+
url = new URL(raw, "http://ref.invalid");
|
|
6684
|
+
} catch {
|
|
6685
|
+
return null;
|
|
6686
|
+
}
|
|
6687
|
+
const fromPath = /(?:^|\/)chat\/[^/]+\/([^/]+)\/?$/.exec(url.pathname)?.[1];
|
|
6688
|
+
if (fromPath && UUID.test(fromPath)) return fromPath.toLowerCase();
|
|
6689
|
+
const fromQuery = url.searchParams.get("t");
|
|
6690
|
+
return fromQuery && UUID.test(fromQuery) ? fromQuery.toLowerCase() : null;
|
|
6691
|
+
}
|
|
6692
|
+
function readingFor(query, userId) {
|
|
6693
|
+
return userId ? query.setHeader(ON_BEHALF_HEADER, userId) : query;
|
|
6694
|
+
}
|
|
6695
|
+
async function resolveThreadOwner(threadId, onBehalfOf) {
|
|
6696
|
+
if (!UUID.test(threadId)) return null;
|
|
6697
|
+
const db = getSupabaseClient();
|
|
6698
|
+
const { data: thread, error: error2 } = await readingFor(
|
|
6699
|
+
db.from("threads").select("id, channel_id").eq("id", threadId),
|
|
6700
|
+
onBehalfOf
|
|
6701
|
+
).maybeSingle();
|
|
6702
|
+
if (error2) throw new Error(`resolveThreadOwner: ${error2.message}`);
|
|
6703
|
+
const channelId = thread?.channel_id;
|
|
6704
|
+
if (!channelId) return null;
|
|
6705
|
+
const { data: channel, error: channelError } = await readingFor(
|
|
6706
|
+
db.from("channels").select("profile, visibility, dm_key, member_emails").eq(UUID.test(channelId) ? "id" : "external_channel_id", channelId),
|
|
6707
|
+
onBehalfOf
|
|
6708
|
+
).maybeSingle();
|
|
6709
|
+
if (channelError) throw new Error(`resolveThreadOwner: ${channelError.message}`);
|
|
6710
|
+
const row = channel;
|
|
6711
|
+
if (!row?.profile) return null;
|
|
6712
|
+
const { data: workspace, error: workspaceError } = await readingFor(
|
|
6713
|
+
db.from("workspaces").select("id").eq("slug", row.profile),
|
|
6714
|
+
onBehalfOf
|
|
6715
|
+
).maybeSingle();
|
|
6716
|
+
if (workspaceError) throw new Error(`resolveThreadOwner: ${workspaceError.message}`);
|
|
6717
|
+
const workspaceId = workspace?.id;
|
|
6718
|
+
if (!workspaceId) return null;
|
|
6719
|
+
return {
|
|
6720
|
+
threadId,
|
|
6721
|
+
channelId,
|
|
6722
|
+
workspace: row.profile,
|
|
6723
|
+
workspaceId,
|
|
6724
|
+
channel: {
|
|
6725
|
+
// Same default as rowToChannel: anything not explicitly public is private.
|
|
6726
|
+
visibility: row.visibility === "public" ? "public" : "private",
|
|
6727
|
+
dmKey: row.dm_key,
|
|
6728
|
+
memberEmails: Array.isArray(row.member_emails) ? row.member_emails.filter((e) => typeof e === "string").map((e) => e.trim().toLowerCase()) : []
|
|
6729
|
+
}
|
|
6730
|
+
};
|
|
6731
|
+
}
|
|
6732
|
+
async function canReadThread(owner, userId) {
|
|
6733
|
+
if (!UUID.test(userId)) return false;
|
|
6734
|
+
const { data, error: error2 } = await readingFor(
|
|
6735
|
+
getSupabaseClient().from("memberships").select("email, role").eq("workspace_id", owner.workspaceId).eq("user_id", userId),
|
|
6736
|
+
userId
|
|
6737
|
+
).maybeSingle();
|
|
6738
|
+
if (error2) throw new Error(`canReadThread: ${error2.message}`);
|
|
6739
|
+
const membership = data;
|
|
6740
|
+
if (!membership) return false;
|
|
6741
|
+
return canSeeChannel(owner.channel, {
|
|
6742
|
+
email: membership.email ?? void 0,
|
|
6743
|
+
role: membership.role
|
|
6744
|
+
});
|
|
6745
|
+
}
|
|
6746
|
+
function threadPath(workspace, channelId, threadId) {
|
|
6747
|
+
return `/${encodeURIComponent(workspace)}/chat/${encodeURIComponent(channelId)}/${threadId}`;
|
|
6748
|
+
}
|
|
6749
|
+
|
|
6644
6750
|
// ../api/src/dashboard/doc-share-publish.ts
|
|
6645
6751
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
6646
6752
|
import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
|
|
@@ -6822,9 +6928,287 @@ function slugErrorMessage(err) {
|
|
|
6822
6928
|
}
|
|
6823
6929
|
}
|
|
6824
6930
|
|
|
6931
|
+
// ../api/src/dashboard/doc-share-host-request.ts
|
|
6932
|
+
function workspaceShareOrigin(slug) {
|
|
6933
|
+
const wildcard = allowedOrigins().find((o) => o.includes("://*."));
|
|
6934
|
+
return wildcard ? wildcard.replace("://*.", `://${slug}.`) : `https://${slug}.flyspace.ai`;
|
|
6935
|
+
}
|
|
6936
|
+
async function publishDocShareForHost(scopeWorkspaces, req) {
|
|
6937
|
+
if (typeof req.channelId !== "string" || typeof req.path !== "string" || !req.path) {
|
|
6938
|
+
return { error: "channel and path are required" };
|
|
6939
|
+
}
|
|
6940
|
+
const channel = findChannelById(req.channelId);
|
|
6941
|
+
if (!channel || scopeWorkspaces !== null && !scopeWorkspaces.includes(channel.profile)) {
|
|
6942
|
+
return { error: "channel not found" };
|
|
6943
|
+
}
|
|
6944
|
+
let slug;
|
|
6945
|
+
if (typeof req.slug === "string") {
|
|
6946
|
+
const normalized = normalizeSlug(req.slug);
|
|
6947
|
+
if ("error" in normalized) return { error: slugErrorMessage(normalized.error) };
|
|
6948
|
+
slug = normalized.slug;
|
|
6949
|
+
}
|
|
6950
|
+
const workspace = await getWorkspaceBySlug(channel.profile);
|
|
6951
|
+
if (!workspace) return { error: "workspace not found" };
|
|
6952
|
+
return runWithProfile(channel.profile, async () => {
|
|
6953
|
+
let result;
|
|
6954
|
+
try {
|
|
6955
|
+
result = await publishDocShare(
|
|
6956
|
+
{
|
|
6957
|
+
cwd: resolveChannelConfig(channel.id).cwd,
|
|
6958
|
+
workspaceId: workspace.id,
|
|
6959
|
+
profile: channel.profile,
|
|
6960
|
+
channelId: channel.id,
|
|
6961
|
+
sourcePath: req.path,
|
|
6962
|
+
createdBy: "agent",
|
|
6963
|
+
...slug ? { slug } : {},
|
|
6964
|
+
features: {}
|
|
6965
|
+
},
|
|
6966
|
+
remoteAgentCallbacks().readDocShareBundle
|
|
6967
|
+
);
|
|
6968
|
+
} catch (err) {
|
|
6969
|
+
if (err instanceof DocShareSlugTakenError) return { error: `/share/${err.slug} is already taken.` };
|
|
6970
|
+
throw err;
|
|
6971
|
+
}
|
|
6972
|
+
switch (result.status) {
|
|
6973
|
+
case "not-found":
|
|
6974
|
+
return { error: "doc not found" };
|
|
6975
|
+
case "unsupported":
|
|
6976
|
+
return { error: "only Markdown and HTML docs can be shared" };
|
|
6977
|
+
case "too-large":
|
|
6978
|
+
return { error: "doc or its assets too large to share" };
|
|
6979
|
+
case "host-unavailable":
|
|
6980
|
+
case "host-outdated":
|
|
6981
|
+
return { error: "the Host could not read the doc" };
|
|
6982
|
+
default:
|
|
6983
|
+
return { url: `${workspaceShareOrigin(channel.profile)}/share/${result.share.slug ?? result.share.id}` };
|
|
6984
|
+
}
|
|
6985
|
+
});
|
|
6986
|
+
}
|
|
6987
|
+
|
|
6988
|
+
// ../api/src/actions/run-action.ts
|
|
6989
|
+
var ActionError = class extends Error {
|
|
6990
|
+
};
|
|
6991
|
+
var DEFAULT_PERMISSION_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
6992
|
+
var MAX_REPLIES = 100;
|
|
6993
|
+
var inScope = (ctx, workspace) => ctx.scope === null || ctx.scope.includes(workspace);
|
|
6994
|
+
async function channelInScope(ctx, channelId) {
|
|
6995
|
+
const { data, error: error2 } = await getSupabaseClient().from("channels").select("id, name, profile, cwd").eq("id", channelId).maybeSingle();
|
|
6996
|
+
if (error2) throw new Error(error2.message);
|
|
6997
|
+
if (!data || !inScope(ctx, data["profile"]))
|
|
6998
|
+
throw new ActionError(`No channel with id ${channelId}.`);
|
|
6999
|
+
return data;
|
|
7000
|
+
}
|
|
7001
|
+
async function threadInScope(ctx, threadId) {
|
|
7002
|
+
const owner = await resolveThreadOwner(threadId);
|
|
7003
|
+
if (!owner || !inScope(ctx, owner.workspace))
|
|
7004
|
+
throw new ActionError(`No thread with id ${threadId}.`);
|
|
7005
|
+
return owner;
|
|
7006
|
+
}
|
|
7007
|
+
async function requesterUserId(ctx) {
|
|
7008
|
+
const { handle, workspace } = ctx.requester;
|
|
7009
|
+
if (!handle || !workspace || !inScope(ctx, workspace)) return null;
|
|
7010
|
+
const supabase = getSupabaseClient();
|
|
7011
|
+
const { data: ws } = await supabase.from("workspaces").select("id").eq("slug", workspace).maybeSingle();
|
|
7012
|
+
if (!ws) return null;
|
|
7013
|
+
const { data } = await supabase.from("memberships").select("user_id").eq("workspace_id", ws["id"]).ilike("handle", handle).maybeSingle();
|
|
7014
|
+
return data?.["user_id"] ?? null;
|
|
7015
|
+
}
|
|
7016
|
+
async function insertAgentReply(threadId, body) {
|
|
7017
|
+
const { data, error: error2 } = await getSupabaseClient().from("thread_replies").insert({ thread_id: threadId, author: AGENT_AUTHOR, body }).select("id").single();
|
|
7018
|
+
if (error2 || !data)
|
|
7019
|
+
throw new Error(`failed to write reply: ${error2?.message ?? "no row returned"}`);
|
|
7020
|
+
return data["id"];
|
|
7021
|
+
}
|
|
7022
|
+
var searchThreads = async (input2, ctx) => {
|
|
7023
|
+
const limit = Math.min(Math.max(Math.trunc(input2.limit ?? 10), 1), 30);
|
|
7024
|
+
const { data, error: error2 } = await getSupabaseClient().rpc("search_threads", {
|
|
7025
|
+
q: input2.query,
|
|
7026
|
+
match_limit: Math.min(limit * 5, 100)
|
|
7027
|
+
});
|
|
7028
|
+
if (error2) throw new Error(`search failed: ${error2.message}`);
|
|
7029
|
+
let rows = data ?? [];
|
|
7030
|
+
if (input2.channel_id) rows = rows.filter((r) => r.channel_id === input2.channel_id);
|
|
7031
|
+
if (ctx.scope !== null && rows.length) {
|
|
7032
|
+
const { data: channels } = await getSupabaseClient().from("channels").select("id").in("profile", ctx.scope).in("id", [...new Set(rows.map((r) => r.channel_id))]);
|
|
7033
|
+
const own = new Set((channels ?? []).map((c) => c["id"]));
|
|
7034
|
+
rows = rows.filter((r) => own.has(r.channel_id));
|
|
7035
|
+
}
|
|
7036
|
+
return rows.slice(0, limit);
|
|
7037
|
+
};
|
|
7038
|
+
var readThread = async (input2, ctx) => {
|
|
7039
|
+
const threadId = parseThreadRef(input2.thread_id);
|
|
7040
|
+
if (!threadId) throw new ActionError(`Not a thread id or thread link: ${input2.thread_id}`);
|
|
7041
|
+
const userId = await requesterUserId(ctx);
|
|
7042
|
+
const owner = await resolveThreadOwner(threadId);
|
|
7043
|
+
const allowed = !!owner && (userId ? await canReadThread(owner, userId) : inScope(ctx, owner.workspace));
|
|
7044
|
+
if (!owner || !allowed) return null;
|
|
7045
|
+
const supabase = getSupabaseClient();
|
|
7046
|
+
const { data: thread, error: error2 } = await supabase.from("threads").select("title, auto_title, author, created_at").eq("id", threadId).maybeSingle();
|
|
7047
|
+
if (error2) throw new Error(`read failed: ${error2.message}`);
|
|
7048
|
+
if (!thread) return null;
|
|
7049
|
+
const { data: replies, error: repliesError } = await supabase.from("thread_replies").select("author, body, created_at").eq("thread_id", threadId).is("archived_at", null).order("created_at", { ascending: true }).limit(MAX_REPLIES);
|
|
7050
|
+
if (repliesError) throw new Error(`read failed: ${repliesError.message}`);
|
|
7051
|
+
return {
|
|
7052
|
+
link: threadPath(owner.workspace, owner.channelId, threadId),
|
|
7053
|
+
title: thread["title"] ?? thread["auto_title"] ?? null,
|
|
7054
|
+
author: thread["author"],
|
|
7055
|
+
created_at: thread["created_at"],
|
|
7056
|
+
replies: replies ?? []
|
|
7057
|
+
};
|
|
7058
|
+
};
|
|
7059
|
+
var listChannels3 = async (_input, ctx) => {
|
|
7060
|
+
let query = getSupabaseClient().from("channels").select("id, name, profile, cwd");
|
|
7061
|
+
if (ctx.scope !== null) query = query.in("profile", ctx.scope);
|
|
7062
|
+
const { data, error: error2 } = await query.order("name");
|
|
7063
|
+
if (error2) throw new Error(`list channels failed: ${error2.message}`);
|
|
7064
|
+
return data ?? [];
|
|
7065
|
+
};
|
|
7066
|
+
var createThread = async (input2, ctx) => {
|
|
7067
|
+
const channel = await channelInScope(ctx, input2.channel_id);
|
|
7068
|
+
const { data, error: error2 } = await getSupabaseClient().from("threads").insert({
|
|
7069
|
+
channel_id: channel.id,
|
|
7070
|
+
// An untitled thread is effectively invisible in the sidebar, so derive
|
|
7071
|
+
// one from the first line unless the caller named the thread itself.
|
|
7072
|
+
title: input2.title?.trim().replace(/\\([\\`*_{}[\]()#+\-.!~>|])/g, "$1") || deriveThreadTitle(input2.text),
|
|
7073
|
+
author: AGENT_AUTHOR
|
|
7074
|
+
}).select("id").single();
|
|
7075
|
+
if (error2 || !data)
|
|
7076
|
+
throw new Error(`failed to create thread: ${error2?.message ?? "no row returned"}`);
|
|
7077
|
+
const threadId = data["id"];
|
|
7078
|
+
return { threadId, replyId: await insertAgentReply(threadId, input2.text) };
|
|
7079
|
+
};
|
|
7080
|
+
var postReply = async (input2, ctx) => {
|
|
7081
|
+
const owner = await threadInScope(ctx, input2.thread_id);
|
|
7082
|
+
return { threadId: owner.threadId, replyId: await insertAgentReply(owner.threadId, input2.text) };
|
|
7083
|
+
};
|
|
7084
|
+
var moveThread2 = async (input2, ctx) => {
|
|
7085
|
+
const owner = await threadInScope(ctx, input2.thread_id);
|
|
7086
|
+
if (owner.channelId === input2.to_channel_id) return "unchanged";
|
|
7087
|
+
const to = await channelInScope(ctx, input2.to_channel_id);
|
|
7088
|
+
const supabase = getSupabaseClient();
|
|
7089
|
+
const { data: fromRow } = await supabase.from("channels").select("id, name, cwd").eq("id", owner.channelId).maybeSingle();
|
|
7090
|
+
const { error: error2 } = await supabase.from("threads").update({ channel_id: to.id }).eq("id", owner.threadId);
|
|
7091
|
+
if (error2) throw new Error(`move failed: ${error2.message}`);
|
|
7092
|
+
const { error: notifyError } = await supabase.from("notifications").update({ channel_id: to.id }).eq("thread_id", owner.threadId);
|
|
7093
|
+
if (notifyError) throw new Error(`move failed (notifications): ${notifyError.message}`);
|
|
7094
|
+
return {
|
|
7095
|
+
from: fromRow ?? null,
|
|
7096
|
+
to: { id: to.id, name: to.name, cwd: to.cwd }
|
|
7097
|
+
};
|
|
7098
|
+
};
|
|
7099
|
+
var shareDoc = async (input2, ctx) => {
|
|
7100
|
+
const res = await publishDocShareForHost(ctx.scope, {
|
|
7101
|
+
channelId: input2.channel_id,
|
|
7102
|
+
path: input2.path,
|
|
7103
|
+
...input2.slug?.trim() ? { slug: input2.slug.trim() } : {}
|
|
7104
|
+
});
|
|
7105
|
+
if (!res.url) throw new ActionError(`Share failed: ${res.error ?? "unknown error"}`);
|
|
7106
|
+
return { url: res.url };
|
|
7107
|
+
};
|
|
7108
|
+
function describeToolInput(input2) {
|
|
7109
|
+
const pick = input2["command"] ?? input2["file_path"] ?? input2["path"] ?? input2["url"];
|
|
7110
|
+
const text = typeof pick === "string" ? pick : JSON.stringify(input2, null, 2);
|
|
7111
|
+
return text.length > 1500 ? `${text.slice(0, 1500)}\u2026` : text;
|
|
7112
|
+
}
|
|
7113
|
+
var permissionMarker = (id) => `[PERMISSION: ${id}]`;
|
|
7114
|
+
var requestPermission = async (input2, ctx) => {
|
|
7115
|
+
const { threadId, channelId, permissionTimeoutMs } = ctx.requester;
|
|
7116
|
+
if (!threadId || !channelId) throw new ActionError("No thread to ask in.");
|
|
7117
|
+
const owner = await threadInScope(ctx, threadId);
|
|
7118
|
+
if (owner.channelId !== channelId) throw new ActionError(`No thread with id ${threadId}.`);
|
|
7119
|
+
const supabase = getSupabaseClient();
|
|
7120
|
+
const timeoutMs = permissionTimeoutMs && permissionTimeoutMs > 0 ? permissionTimeoutMs : DEFAULT_PERMISSION_TIMEOUT_MS;
|
|
7121
|
+
const { data: request, error: error2 } = await supabase.from("permission_requests").insert({
|
|
7122
|
+
channel_id: channelId,
|
|
7123
|
+
thread_id: threadId,
|
|
7124
|
+
tool_name: input2.tool_name,
|
|
7125
|
+
input: input2.input,
|
|
7126
|
+
expires_at: new Date(Date.now() + timeoutMs).toISOString()
|
|
7127
|
+
}).select("id").single();
|
|
7128
|
+
if (error2 || !request) throw new Error(`failed to create permission request: ${error2?.message}`);
|
|
7129
|
+
const requestId = request["id"];
|
|
7130
|
+
const prompt = `The agent wants to use **${input2.tool_name}**:
|
|
7131
|
+
|
|
7132
|
+
\`\`\`
|
|
7133
|
+
${describeToolInput(input2.input)}
|
|
7134
|
+
\`\`\`
|
|
7135
|
+
|
|
7136
|
+
` + permissionMarker(requestId);
|
|
7137
|
+
const replyId = await insertAgentReply(threadId, prompt).catch(() => null);
|
|
7138
|
+
if (replyId)
|
|
7139
|
+
await supabase.from("permission_requests").update({ reply_id: replyId }).eq("id", requestId);
|
|
7140
|
+
return { requestId };
|
|
7141
|
+
};
|
|
7142
|
+
var checkPermission = async (input2, ctx) => {
|
|
7143
|
+
const supabase = getSupabaseClient();
|
|
7144
|
+
const read = async () => {
|
|
7145
|
+
const { data } = await supabase.from("permission_requests").select("channel_id, thread_id, reply_id, status, decided_by, expires_at").eq("id", input2.request_id).maybeSingle();
|
|
7146
|
+
return data;
|
|
7147
|
+
};
|
|
7148
|
+
let row = await read();
|
|
7149
|
+
if (!row) throw new ActionError(`No permission request ${input2.request_id}.`);
|
|
7150
|
+
const channel = await channelInScope(ctx, row["channel_id"]).catch(() => null);
|
|
7151
|
+
if (!channel) throw new ActionError(`No permission request ${input2.request_id}.`);
|
|
7152
|
+
if (row["status"] === "pending" && Date.parse(row["expires_at"]) <= Date.now()) {
|
|
7153
|
+
await supabase.from("permission_requests").update({ status: "expired" }).eq("id", input2.request_id).eq("status", "pending");
|
|
7154
|
+
row = await read() ?? row;
|
|
7155
|
+
}
|
|
7156
|
+
const status = row["status"];
|
|
7157
|
+
const decidedBy = row["decided_by"] ?? null;
|
|
7158
|
+
const replyId = row["reply_id"];
|
|
7159
|
+
if (status !== "pending" && replyId) {
|
|
7160
|
+
const outcome = status === "allow" ? `\u2705 Allowed by @${decidedBy}` : status === "deny" ? `\u{1F6AB} Denied by @${decidedBy}` : "\u23F0 No answer in time, denied automatically";
|
|
7161
|
+
const { data: reply } = await supabase.from("thread_replies").select("body").eq("id", replyId).maybeSingle();
|
|
7162
|
+
const body = reply?.["body"];
|
|
7163
|
+
if (body?.includes(permissionMarker(input2.request_id))) {
|
|
7164
|
+
await supabase.from("thread_replies").update({ body: body.replace(permissionMarker(input2.request_id), outcome) }).eq("id", replyId).eq("thread_id", row["thread_id"]);
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
return { status, decidedBy };
|
|
7168
|
+
};
|
|
7169
|
+
var HANDLERS = {
|
|
7170
|
+
[searchThreadsAction.name]: searchThreads,
|
|
7171
|
+
[readThreadAction.name]: readThread,
|
|
7172
|
+
[listChannelsAction.name]: listChannels3,
|
|
7173
|
+
[createThreadAction.name]: createThread,
|
|
7174
|
+
[postReplyAction.name]: postReply,
|
|
7175
|
+
[moveThreadAction.name]: moveThread2,
|
|
7176
|
+
[shareDocAction.name]: shareDoc,
|
|
7177
|
+
[requestPermissionAction.name]: requestPermission,
|
|
7178
|
+
[checkPermissionAction.name]: checkPermission
|
|
7179
|
+
};
|
|
7180
|
+
|
|
6825
7181
|
// ../api/src/dashboard/agent-bridge-data.ts
|
|
6826
7182
|
var hosts = /* @__PURE__ */ new Map();
|
|
7183
|
+
var pending = /* @__PURE__ */ new Map();
|
|
6827
7184
|
var hostStatusListeners = /* @__PURE__ */ new Set();
|
|
7185
|
+
var lastAuthFailure = null;
|
|
7186
|
+
function hostFor(profile) {
|
|
7187
|
+
let legacy = null;
|
|
7188
|
+
let scoped = null;
|
|
7189
|
+
for (const [ws, scope] of hosts) {
|
|
7190
|
+
if (ws.readyState !== WebSocket.OPEN) continue;
|
|
7191
|
+
if (scope.workspaces === null) legacy = ws;
|
|
7192
|
+
else if (scope.workspaces.includes(profile)) scoped = ws;
|
|
7193
|
+
}
|
|
7194
|
+
return scoped ?? legacy;
|
|
7195
|
+
}
|
|
7196
|
+
function isHostConnected(profile) {
|
|
7197
|
+
if (profile) return hostFor(profile) !== null;
|
|
7198
|
+
for (const ws of hosts.keys()) if (ws.readyState === WebSocket.OPEN) return true;
|
|
7199
|
+
return false;
|
|
7200
|
+
}
|
|
7201
|
+
function getHostCliVersion(profile) {
|
|
7202
|
+
const ws = hostFor(profile);
|
|
7203
|
+
return ws && hosts.get(ws)?.cliVersion || null;
|
|
7204
|
+
}
|
|
7205
|
+
function getHostPinnedModel(profile) {
|
|
7206
|
+
const ws = hostFor(profile);
|
|
7207
|
+
return ws && hosts.get(ws)?.pinnedModel || null;
|
|
7208
|
+
}
|
|
7209
|
+
function getHostOfflineReason() {
|
|
7210
|
+
return lastAuthFailure;
|
|
7211
|
+
}
|
|
6828
7212
|
function notifyHostStatus() {
|
|
6829
7213
|
const online = hosts.size > 0;
|
|
6830
7214
|
for (const l of hostStatusListeners) l(online);
|
|
@@ -6841,10 +7225,134 @@ function disconnectHostDevice(deviceId) {
|
|
|
6841
7225
|
}
|
|
6842
7226
|
}
|
|
6843
7227
|
var LAST_SEEN_RESOLUTION_MS = 60 * 6e4;
|
|
7228
|
+
var lastCallFailure = /* @__PURE__ */ new Map();
|
|
6844
7229
|
var lastCallError = /* @__PURE__ */ new Map();
|
|
6845
7230
|
function getHostCallError(method, profile = getProfile()) {
|
|
6846
7231
|
return lastCallError.get(`${profile}:${method}`) ?? null;
|
|
6847
7232
|
}
|
|
7233
|
+
function getHostCallFailure(method, profile = getProfile()) {
|
|
7234
|
+
return lastCallFailure.get(`${profile}:${method}`) ?? null;
|
|
7235
|
+
}
|
|
7236
|
+
function callHost(method, args, timeoutMs = CALL_TIMEOUT_MS) {
|
|
7237
|
+
const profile = getProfile();
|
|
7238
|
+
const ws = hostFor(profile);
|
|
7239
|
+
const key = `${profile}:${method}`;
|
|
7240
|
+
lastCallFailure.delete(key);
|
|
7241
|
+
lastCallError.delete(key);
|
|
7242
|
+
if (!ws) {
|
|
7243
|
+
lastCallFailure.set(key, isHostConnected() ? "unscoped" : "offline");
|
|
7244
|
+
console.error(
|
|
7245
|
+
isHostConnected() ? `[host-socket] ${method} -> not scoped to workspace "${profile}"` : `[host-socket] ${method} -> no Host connected`
|
|
7246
|
+
);
|
|
7247
|
+
return Promise.resolve(null);
|
|
7248
|
+
}
|
|
7249
|
+
if (method === "docsRequest") console.log(`[host-socket] docsRequest for "${profile}" -> device ${hosts.get(ws)?.deviceId ?? "legacy"}`);
|
|
7250
|
+
const id = randomUUID2();
|
|
7251
|
+
return new Promise((resolve7) => {
|
|
7252
|
+
const timer2 = setTimeout(() => {
|
|
7253
|
+
pending.delete(id);
|
|
7254
|
+
lastCallFailure.set(key, "timeout");
|
|
7255
|
+
console.error(`[host-socket] ${method} -> timed out after ${timeoutMs}ms`);
|
|
7256
|
+
resolve7(null);
|
|
7257
|
+
}, timeoutMs);
|
|
7258
|
+
pending.set(id, {
|
|
7259
|
+
key,
|
|
7260
|
+
resolve: (value) => {
|
|
7261
|
+
clearTimeout(timer2);
|
|
7262
|
+
resolve7(value);
|
|
7263
|
+
}
|
|
7264
|
+
});
|
|
7265
|
+
const sent = [...args];
|
|
7266
|
+
while (sent.length > 0 && sent[sent.length - 1] === void 0) sent.pop();
|
|
7267
|
+
send(ws, { type: "call", id, method, profile, args: sent });
|
|
7268
|
+
});
|
|
7269
|
+
}
|
|
7270
|
+
function remoteAgentCallbacks() {
|
|
7271
|
+
return {
|
|
7272
|
+
// Fire-and-forget on the Data side exactly as the in-process call was:
|
|
7273
|
+
// the reply lands in Supabase later, via Realtime, not in this response.
|
|
7274
|
+
onChatMessage: (msg) => {
|
|
7275
|
+
void callHost("onChatMessage", [msg]);
|
|
7276
|
+
},
|
|
7277
|
+
isAgentThinking: async (threadId) => await callHost("isAgentThinking", [threadId]) ?? false,
|
|
7278
|
+
getAgentActivities: async (threadId) => await callHost("getAgentActivities", [threadId]) ?? [],
|
|
7279
|
+
getBackgroundTasks: async (threadId) => await callHost("getBackgroundTasks", [threadId]) ?? [],
|
|
7280
|
+
cancelAgentRun: async (threadId) => await callHost("cancelAgentRun", [threadId]) ?? false,
|
|
7281
|
+
regenerateAgentRun: async (threadId, stoppedReplyId) => await callHost("regenerateAgentRun", [threadId, stoppedReplyId]) ?? false,
|
|
7282
|
+
listAgentRuns: async () => await callHost("listAgentRuns", []) ?? [],
|
|
7283
|
+
// `null` (no Host, or no answer in time) passes through: the extractor
|
|
7284
|
+
// reads it as a failed call and retries the thread next sweep.
|
|
7285
|
+
completeMemoryExtraction: (req) => callHost("completeMemoryExtraction", [req], MEMORY_EXTRACTION_TIMEOUT_MS),
|
|
7286
|
+
// `null` passes through: channel-suggest.ts tells "no Host" from "old Host".
|
|
7287
|
+
suggestChannelField: (req) => callHost("suggestChannelField", [req], MEMORY_EXTRACTION_TIMEOUT_MS),
|
|
7288
|
+
// Deliberately passes `null` through rather than defaulting to `[]`: with
|
|
7289
|
+
// no Host connected, claiming every folder is fine would be a guess.
|
|
7290
|
+
listMissingCwds: () => callHost("listMissingCwds", []),
|
|
7291
|
+
// Unlike listMissingCwds, `[]` is a fine fallback here: this only feeds
|
|
7292
|
+
// the "running" badge next to a profile name in the switcher, so with no
|
|
7293
|
+
// Host connected, showing nobody as running is a reasonable default
|
|
7294
|
+
// rather than a false claim of certainty either way.
|
|
7295
|
+
listRunningProfiles: async () => await callHost("listRunningProfiles", []) ?? [],
|
|
7296
|
+
// `null` (no Host) falls back to `offlineAgentIdentities` in api.ts.
|
|
7297
|
+
getAgentIdentities: (viewer) => callHost("getAgentIdentities", [viewer]),
|
|
7298
|
+
// Reading the doc and its assets can only happen where the channel's
|
|
7299
|
+
// real folder is, so this goes to the Host; the DB and R2 work stays here
|
|
7300
|
+
// (doc-share-publish.ts). `null` with no recorded failure means the Host
|
|
7301
|
+
// answered but has no such method: an install from before the split.
|
|
7302
|
+
// Longer timeout because the reply carries the assets' bytes.
|
|
7303
|
+
readDocShareBundle: async (req) => {
|
|
7304
|
+
const bundle = await callHost("readDocShareBundle", [req], DOCS_CALL_TIMEOUT_MS);
|
|
7305
|
+
if (bundle) return bundle;
|
|
7306
|
+
return getHostCallFailure("readDocShareBundle") ? { status: "host-unavailable" } : { status: "host-outdated" };
|
|
7307
|
+
},
|
|
7308
|
+
// Empty is a fine fallback for a discovery list: no Host connected means
|
|
7309
|
+
// no skills to offer, not a fabricated claim about what's available.
|
|
7310
|
+
listChannelSkills: async (args) => await callHost("listChannelSkills", [args]) ?? [],
|
|
7311
|
+
// Same reasoning as listChannelSkills — this only feeds the Docs pane's
|
|
7312
|
+
// List view/search, so an empty result reads as "nothing found yet".
|
|
7313
|
+
listFlatDocs: async (args) => await callHost("listFlatDocs", [args]) ?? [],
|
|
7314
|
+
// `localDefaults()` mirrors what `loadDashboardSettings()` itself returns
|
|
7315
|
+
// for a missing/corrupt file, so "no Host connected" reads the same as a
|
|
7316
|
+
// freshly provisioned workspace rather than as broken settings.
|
|
7317
|
+
getLocalDashboardSettings: async () => await callHost("getLocalDashboardSettings", []) ?? localDefaults(),
|
|
7318
|
+
// A write: no honest empty-ish fallback, so `null` (callHost's own
|
|
7319
|
+
// no-Host/timeout result) surfaces as a 503 on the Data side rather than
|
|
7320
|
+
// a fabricated success (see readDocShareBundle).
|
|
7321
|
+
saveLocalDashboardSettings: (patch) => callHost("saveLocalDashboardSettings", [patch]),
|
|
7322
|
+
// Same posture as saveLocalDashboardSettings: `null` becomes a 503.
|
|
7323
|
+
writeSkill: (ref, write) => callHost("writeSkill", [ref, write]),
|
|
7324
|
+
// Same posture as writeSkill: `null` becomes a 503.
|
|
7325
|
+
outputStylesRequest: (req) => callHost("outputStylesRequest", [req]),
|
|
7326
|
+
// Submitting a Claude code waits on the CLI to mint the token.
|
|
7327
|
+
providerLoginRequest: (req) => callHost("providerLoginRequest", [req], DOCS_CALL_TIMEOUT_MS),
|
|
7328
|
+
// Same posture again. Longer timeout: a first translation of a doc runs a
|
|
7329
|
+
// model call on the Host before it answers.
|
|
7330
|
+
docsRequest: (req) => callHost("docsRequest", [req], DOCS_CALL_TIMEOUT_MS),
|
|
7331
|
+
hostRequest: (req) => callHost("hostRequest", [req], DOCS_CALL_TIMEOUT_MS),
|
|
7332
|
+
// `null` (no Host connected) is passed through rather than defaulting to
|
|
7333
|
+
// `[]` — see listSessions's doc comment on AgentCallbacks.
|
|
7334
|
+
listSessions: () => callHost("listSessions", []),
|
|
7335
|
+
// `claude mcp list` health-checks every server, which takes seconds.
|
|
7336
|
+
listMcpServers: () => callHost("listMcpServers", [], DOCS_CALL_TIMEOUT_MS),
|
|
7337
|
+
upgradeHost: () => callHost("upgradeHost", []),
|
|
7338
|
+
// Both need this machine's disk and CLI history, so `null` (no Host)
|
|
7339
|
+
// surfaces as a 503 rather than an empty scan or a fake success.
|
|
7340
|
+
// A first scan walks every CLI transcript on a cold disk, so it gets the
|
|
7341
|
+
// long timeout; linking can create and seed several folders.
|
|
7342
|
+
scanOnboarding: (slug) => callHost("scanOnboarding", [slug], DOCS_CALL_TIMEOUT_MS),
|
|
7343
|
+
linkProjectFolders: (slug, items2) => callHost("linkProjectFolders", [slug, items2], DOCS_CALL_TIMEOUT_MS),
|
|
7344
|
+
// A first scan or a long transcript walks a lot of disk: the long timeout.
|
|
7345
|
+
sessionImportRequest: (req) => callHost("sessionImportRequest", [req], DOCS_CALL_TIMEOUT_MS),
|
|
7346
|
+
getHostCallFailure: (method) => getHostCallFailure(method),
|
|
7347
|
+
isHostOnline: (profile) => isHostConnected(profile),
|
|
7348
|
+
getHostOfflineReason,
|
|
7349
|
+
getHostCliVersion,
|
|
7350
|
+
getHostPinnedModel
|
|
7351
|
+
};
|
|
7352
|
+
}
|
|
7353
|
+
function send(ws, msg) {
|
|
7354
|
+
if (ws.readyState === WebSocket.OPEN) ws.send(encodeWireMessage(msg));
|
|
7355
|
+
}
|
|
6848
7356
|
|
|
6849
7357
|
// ../api/src/dashboard/unique-channel-name.ts
|
|
6850
7358
|
function uniqueChannelName(raw, taken) {
|
|
@@ -7038,11 +7546,11 @@ function createOnboardingRouter(agent) {
|
|
|
7038
7546
|
const ctx = await resolveAuthContext(c);
|
|
7039
7547
|
if (ctx?.role !== "admin") return c.json({ pending: false });
|
|
7040
7548
|
const greetedAt = await getWorkspaceGreetedAt(ctx.workspaceId);
|
|
7041
|
-
const
|
|
7042
|
-
if (!
|
|
7549
|
+
const pending2 = !!ctx.projectsSetupAt && !greetedAt;
|
|
7550
|
+
if (!pending2) return c.json({ pending: pending2, channelId: null, threadId: null });
|
|
7043
7551
|
const general = await ensureGeneralChannel();
|
|
7044
7552
|
const threadId = await ensureGreetingThread(ctx.workspaceId, general.id, ctx.name?.trim() || ctx.handle);
|
|
7045
|
-
return c.json({ pending, channelId: general.id, threadId });
|
|
7553
|
+
return c.json({ pending: pending2, channelId: general.id, threadId });
|
|
7046
7554
|
});
|
|
7047
7555
|
app.post("/greeting", async (c) => {
|
|
7048
7556
|
const ctx = await resolveAuthContext(c);
|
|
@@ -7875,13 +8383,13 @@ function createContinuousChatRouter() {
|
|
|
7875
8383
|
};
|
|
7876
8384
|
});
|
|
7877
8385
|
const activeSince = Date.now() - ACTIVE_TOPIC_DAYS * 864e5;
|
|
7878
|
-
const
|
|
8386
|
+
const pending2 = replies.filter(
|
|
7879
8387
|
(r) => !tags.has(r.id) && isHumanAuthor(r.author) && Date.parse(r.created_at) >= activeSince && !backfilling.has(r.id)
|
|
7880
8388
|
).slice(0, BACKFILL_PER_REQUEST);
|
|
7881
|
-
if (
|
|
7882
|
-
for (const r of
|
|
8389
|
+
if (pending2.length) {
|
|
8390
|
+
for (const r of pending2) backfilling.add(r.id);
|
|
7883
8391
|
void (async () => {
|
|
7884
|
-
for (const r of
|
|
8392
|
+
for (const r of pending2) {
|
|
7885
8393
|
await tagReply({ channel, replyId: r.id, author: r.author, body: r.body }).catch(
|
|
7886
8394
|
() => {
|
|
7887
8395
|
}
|
|
@@ -7895,7 +8403,7 @@ function createContinuousChatRouter() {
|
|
|
7895
8403
|
messages.filter((m) => m.topic && Date.parse(m.created_at) >= activeSince).map((m) => m.topic)
|
|
7896
8404
|
)
|
|
7897
8405
|
];
|
|
7898
|
-
return c.json({ messages, topics: activeTopics, pendingTags:
|
|
8406
|
+
return c.json({ messages, topics: activeTopics, pendingTags: pending2.length });
|
|
7899
8407
|
});
|
|
7900
8408
|
app.patch("/replies/:replyId/topic", async (c) => {
|
|
7901
8409
|
if (!await isFeatureEnabled(c, "continuous-chat"))
|
|
@@ -9547,7 +10055,7 @@ function snippetAround(text, q) {
|
|
|
9547
10055
|
const end = Math.min(text.length, start + SNIPPET_LENGTH);
|
|
9548
10056
|
return `${start > 0 ? "\u2026" : ""}${text.slice(start, end).trim()}${end < text.length ? "\u2026" : ""}`;
|
|
9549
10057
|
}
|
|
9550
|
-
async function
|
|
10058
|
+
async function searchThreads2(q) {
|
|
9551
10059
|
const supabase = getSupabaseClient();
|
|
9552
10060
|
const { data, error: error2 } = await supabase.rpc("search_threads", { q, match_limit: 20 });
|
|
9553
10061
|
if (error2) {
|
|
@@ -9673,7 +10181,7 @@ function createSearchRouter() {
|
|
|
9673
10181
|
const q = c.req.query("q")?.trim();
|
|
9674
10182
|
if (!q) return c.json({ results: [] });
|
|
9675
10183
|
const [threadResults, channelResults, automationResults] = await Promise.all([
|
|
9676
|
-
|
|
10184
|
+
searchThreads2(q),
|
|
9677
10185
|
Promise.resolve(searchChannels(q)),
|
|
9678
10186
|
Promise.resolve(searchAutomations(q))
|
|
9679
10187
|
]);
|
|
@@ -11620,8 +12128,8 @@ function createChannelGreetingRouter(agent) {
|
|
|
11620
12128
|
app.get("/:id/greeting", async (c) => {
|
|
11621
12129
|
const ctx = await resolveAuthContext(c);
|
|
11622
12130
|
const ch = findChannelById(c.req.param("id"));
|
|
11623
|
-
const
|
|
11624
|
-
if (!
|
|
12131
|
+
const pending2 = isWorkspaceOwner(ctx) && eligible(ch) && !ch.greetedAt && (agent.isHostOnline?.(ch.profile) ?? false);
|
|
12132
|
+
if (!pending2) return c.json({ pending: false, threadId: null });
|
|
11625
12133
|
const threadId = await ensureIntroThread(ch);
|
|
11626
12134
|
return c.json({ pending: !!threadId, threadId });
|
|
11627
12135
|
});
|
|
@@ -12733,7 +13241,7 @@ function registerDataRoutes(api, agent = {}) {
|
|
|
12733
13241
|
import { verify } from "crypto";
|
|
12734
13242
|
import { getConnInfo } from "@hono/node-server/conninfo";
|
|
12735
13243
|
import { Hono as Hono33 } from "hono";
|
|
12736
|
-
var
|
|
13244
|
+
var UUID2 = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12737
13245
|
function cleanText(value, max) {
|
|
12738
13246
|
if (typeof value !== "string") return null;
|
|
12739
13247
|
const trimmed = value.trim();
|
|
@@ -12804,18 +13312,18 @@ function createDeviceAuthRouter() {
|
|
|
12804
13312
|
app.post("/token", async (c) => {
|
|
12805
13313
|
const body = await readBody(c);
|
|
12806
13314
|
const code = typeof body["device_code"] === "string" ? body["device_code"] : "";
|
|
12807
|
-
const
|
|
12808
|
-
if (!
|
|
13315
|
+
const pending2 = code ? await getDeviceCodeBySecret(code) : null;
|
|
13316
|
+
if (!pending2 || Date.parse(pending2.expiresAt) <= Date.now()) {
|
|
12809
13317
|
return c.json({ error: "expired_token" }, 400);
|
|
12810
13318
|
}
|
|
12811
|
-
if (
|
|
12812
|
-
if (!
|
|
12813
|
-
const last =
|
|
12814
|
-
await markPolled(
|
|
13319
|
+
if (pending2.deniedAt) return c.json({ error: "access_denied" }, 400);
|
|
13320
|
+
if (!pending2.approvedBy) {
|
|
13321
|
+
const last = pending2.lastPolledAt ? Date.parse(pending2.lastPolledAt) : 0;
|
|
13322
|
+
await markPolled(pending2.id);
|
|
12815
13323
|
const tooSoon = Date.now() - last < (POLL_INTERVAL_S - 1) * 1e3;
|
|
12816
13324
|
return c.json({ error: tooSoon ? "slow_down" : "authorization_pending" }, 400);
|
|
12817
13325
|
}
|
|
12818
|
-
const device = await redeemDeviceCode(
|
|
13326
|
+
const device = await redeemDeviceCode(pending2);
|
|
12819
13327
|
if (!device) return c.json({ error: "expired_token" }, 400);
|
|
12820
13328
|
const { token, expiresInS } = await issueAccessToken(device.id);
|
|
12821
13329
|
return c.json({
|
|
@@ -12829,14 +13337,14 @@ function createDeviceAuthRouter() {
|
|
|
12829
13337
|
});
|
|
12830
13338
|
app.post("/challenge", async (c) => {
|
|
12831
13339
|
const body = await readBody(c);
|
|
12832
|
-
const deviceId = typeof body["device_id"] === "string" &&
|
|
13340
|
+
const deviceId = typeof body["device_id"] === "string" && UUID2.test(body["device_id"]) ? body["device_id"] : "";
|
|
12833
13341
|
const device = deviceId ? await getDevice(deviceId) : null;
|
|
12834
13342
|
if (!device || device.revokedAt) return c.json({ error: "unknown_device" }, 401);
|
|
12835
13343
|
return c.json({ nonce: await createChallenge(device.id) });
|
|
12836
13344
|
});
|
|
12837
13345
|
app.post("/refresh", async (c) => {
|
|
12838
13346
|
const body = await readBody(c);
|
|
12839
|
-
const deviceId = typeof body["device_id"] === "string" &&
|
|
13347
|
+
const deviceId = typeof body["device_id"] === "string" && UUID2.test(body["device_id"]) ? body["device_id"] : "";
|
|
12840
13348
|
const nonce = typeof body["nonce"] === "string" ? body["nonce"] : "";
|
|
12841
13349
|
const signature = typeof body["signature"] === "string" ? body["signature"] : "";
|
|
12842
13350
|
const device = deviceId ? await getDevice(deviceId) : null;
|
|
@@ -12868,22 +13376,22 @@ function createDeviceAuthRouter() {
|
|
|
12868
13376
|
const userId = await sessionUserId(c);
|
|
12869
13377
|
if (!userId) return c.json({ error: "not signed in" }, 401);
|
|
12870
13378
|
const userCode = normalizeUserCode(c.req.query("user_code") ?? "");
|
|
12871
|
-
const
|
|
12872
|
-
if (!
|
|
13379
|
+
const pending2 = userCode ? await getDeviceCodeByUserCode(userCode) : null;
|
|
13380
|
+
if (!pending2 || Date.parse(pending2.expiresAt) <= Date.now() || pending2.approvedBy || pending2.deniedAt) {
|
|
12873
13381
|
return c.json({ error: "That code is invalid, expired, or already used." }, 404);
|
|
12874
13382
|
}
|
|
12875
13383
|
const workspaces = await listAdminWorkspaces(userId);
|
|
12876
13384
|
const hosts2 = await listWorkspaceHosts(
|
|
12877
13385
|
workspaces.map((w) => w.id),
|
|
12878
|
-
|
|
13386
|
+
pending2.publicKey
|
|
12879
13387
|
);
|
|
12880
|
-
const bound = await boundWorkspaceIds(
|
|
13388
|
+
const bound = await boundWorkspaceIds(pending2.publicKey, userId);
|
|
12881
13389
|
return c.json({
|
|
12882
|
-
user_code:
|
|
12883
|
-
name:
|
|
12884
|
-
platform:
|
|
12885
|
-
ip:
|
|
12886
|
-
created_at:
|
|
13390
|
+
user_code: pending2.userCode,
|
|
13391
|
+
name: pending2.name,
|
|
13392
|
+
platform: pending2.platform,
|
|
13393
|
+
ip: pending2.requesterIp,
|
|
13394
|
+
created_at: pending2.createdAt,
|
|
12887
13395
|
// `host`: another machine this workspace already runs on, so it can't be
|
|
12888
13396
|
// picked. `bound`: this machine already serves it, so there's nothing to pick.
|
|
12889
13397
|
workspaces: workspaces.map((w) => ({ ...w, host: hosts2.get(w.id) ?? null, bound: bound.has(w.id) }))
|
|
@@ -12909,8 +13417,8 @@ function createDeviceAuthRouter() {
|
|
|
12909
13417
|
const userCode = normalizeUserCode(typeof body["user_code"] === "string" ? body["user_code"] : "");
|
|
12910
13418
|
const decision = body["decision"];
|
|
12911
13419
|
if (!userCode || decision !== "approve" && decision !== "deny") return c.json({ error: "invalid request" }, 400);
|
|
12912
|
-
const
|
|
12913
|
-
if (!
|
|
13420
|
+
const pending2 = await getDeviceCodeByUserCode(userCode);
|
|
13421
|
+
if (!pending2 || Date.parse(pending2.expiresAt) <= Date.now()) {
|
|
12914
13422
|
return c.json({ error: "That code is invalid or expired." }, 404);
|
|
12915
13423
|
}
|
|
12916
13424
|
let workspaceIds = [];
|
|
@@ -12921,22 +13429,22 @@ function createDeviceAuthRouter() {
|
|
|
12921
13429
|
if (workspaceIds.some((id) => !allowed.has(id))) {
|
|
12922
13430
|
return c.json({ error: "You can only add a device to workspaces you are an admin of." }, 403);
|
|
12923
13431
|
}
|
|
12924
|
-
if (!workspaceIds.length && !(await boundWorkspaceIds(
|
|
13432
|
+
if (!workspaceIds.length && !(await boundWorkspaceIds(pending2.publicKey, userId)).size) {
|
|
12925
13433
|
return c.json({ error: "Pick at least one workspace." }, 400);
|
|
12926
13434
|
}
|
|
12927
13435
|
}
|
|
12928
|
-
if ((await listWorkspaceHosts(workspaceIds,
|
|
13436
|
+
if ((await listWorkspaceHosts(workspaceIds, pending2.publicKey)).size) {
|
|
12929
13437
|
return c.json({ error: "That workspace already has a Host. Its Host cannot be replaced." }, 409);
|
|
12930
13438
|
}
|
|
12931
13439
|
const decided = await decideDeviceCode(
|
|
12932
|
-
|
|
13440
|
+
pending2.id,
|
|
12933
13441
|
userId,
|
|
12934
13442
|
decision === "approve" ? { approve: true, workspaceIds } : { approve: false }
|
|
12935
13443
|
);
|
|
12936
13444
|
if (!decided) {
|
|
12937
13445
|
return c.json({ error: "That code was already used." }, 409);
|
|
12938
13446
|
}
|
|
12939
|
-
await releaseStaleHosts(workspaceIds,
|
|
13447
|
+
await releaseStaleHosts(workspaceIds, pending2.publicKey);
|
|
12940
13448
|
return c.json({ ok: true });
|
|
12941
13449
|
});
|
|
12942
13450
|
return app;
|
|
@@ -14815,7 +15323,7 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
|
|
|
14815
15323
|
...CLI_VERSION ? { cliVersion: CLI_VERSION } : {},
|
|
14816
15324
|
...pinnedModel ? { pinnedModel } : {}
|
|
14817
15325
|
};
|
|
14818
|
-
|
|
15326
|
+
send2(ws, deviceId ? { type: "auth", signature, deviceId, ...version } : { type: "auth", signature, ...version });
|
|
14819
15327
|
return;
|
|
14820
15328
|
}
|
|
14821
15329
|
if (msg.type === "auth-failed") {
|
|
@@ -14835,11 +15343,11 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
|
|
|
14835
15343
|
}
|
|
14836
15344
|
if (msg.type === "auth-ok") {
|
|
14837
15345
|
console.log("[host-socket] authenticated");
|
|
14838
|
-
setHostDbSender((out) =>
|
|
14839
|
-
|
|
15346
|
+
setHostDbSender((out) => send2(ws, out));
|
|
15347
|
+
send2(ws, { type: "host-config", configs: buildHostConfigSnapshot() });
|
|
14840
15348
|
if (configPushTimer) clearInterval(configPushTimer);
|
|
14841
15349
|
configPushTimer = setInterval(() => {
|
|
14842
|
-
|
|
15350
|
+
send2(ws, { type: "host-config", configs: buildHostConfigSnapshot() });
|
|
14843
15351
|
}, HOST_CONFIG_PUSH_INTERVAL_MS);
|
|
14844
15352
|
onAuthenticated?.();
|
|
14845
15353
|
if (msg.workspaces) onWorkspaces?.(msg.workspaces);
|
|
@@ -14853,8 +15361,8 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
|
|
|
14853
15361
|
handlePluginSvgResult(msg.id, msg.url);
|
|
14854
15362
|
return;
|
|
14855
15363
|
}
|
|
14856
|
-
if (msg.type === "
|
|
14857
|
-
|
|
15364
|
+
if (msg.type === "action-result") {
|
|
15365
|
+
handleActionResult(msg.id, { value: msg.value, error: msg.error });
|
|
14858
15366
|
return;
|
|
14859
15367
|
}
|
|
14860
15368
|
if (msg.type === "attachment-url-result") {
|
|
@@ -14906,9 +15414,9 @@ async function handleCall(msg, callbacks, ws) {
|
|
|
14906
15414
|
try {
|
|
14907
15415
|
const handler = callbacks[msg.method];
|
|
14908
15416
|
const value = await handler?.(...msg.args);
|
|
14909
|
-
|
|
15417
|
+
send2(ws, { type: "result", id: msg.id, value: value ?? null });
|
|
14910
15418
|
} catch (err) {
|
|
14911
|
-
|
|
15419
|
+
send2(ws, { type: "call-error", id: msg.id, message: err.message });
|
|
14912
15420
|
}
|
|
14913
15421
|
});
|
|
14914
15422
|
}
|
|
@@ -14954,7 +15462,7 @@ async function handleLocalRelay(req, callbacks, token) {
|
|
|
14954
15462
|
);
|
|
14955
15463
|
return Response.json({ value: value ?? null });
|
|
14956
15464
|
}
|
|
14957
|
-
function
|
|
15465
|
+
function send2(ws, msg) {
|
|
14958
15466
|
if (ws.readyState === WebSocket2.OPEN) ws.send(encodeWireMessage(msg));
|
|
14959
15467
|
}
|
|
14960
15468
|
|
|
@@ -15157,15 +15665,12 @@ async function startHostDashboard(preferredPort, host) {
|
|
|
15157
15665
|
}
|
|
15158
15666
|
});
|
|
15159
15667
|
}
|
|
15160
|
-
app.post(
|
|
15668
|
+
app.post(LOCAL_ACTION_PATH, async (c) => {
|
|
15161
15669
|
if (!relayAuthorized(c.req.raw, relayToken)) return c.json({ error: "unauthorized" }, 401);
|
|
15162
15670
|
const body = await c.req.json().catch(() => null);
|
|
15163
|
-
if (!body || typeof body.
|
|
15164
|
-
return c.json({ error: "bad request" }, 400);
|
|
15165
|
-
}
|
|
15671
|
+
if (!body || typeof body.name !== "string") return c.json({ error: "bad request" }, 400);
|
|
15166
15672
|
try {
|
|
15167
|
-
|
|
15168
|
-
return c.json(res, res.url ? 200 : 400);
|
|
15673
|
+
return c.json(await requestAction(body.name, body.input, body.requester));
|
|
15169
15674
|
} catch (err) {
|
|
15170
15675
|
return c.json({ error: err.message }, 503);
|
|
15171
15676
|
}
|
|
@@ -15665,7 +16170,7 @@ async function main() {
|
|
|
15665
16170
|
break;
|
|
15666
16171
|
case "-v":
|
|
15667
16172
|
case "--version":
|
|
15668
|
-
printRaw("0.1.
|
|
16173
|
+
printRaw("0.1.61");
|
|
15669
16174
|
break;
|
|
15670
16175
|
case "-h":
|
|
15671
16176
|
case "--help":
|