flyspace-cli 0.1.63 → 0.1.65
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-SBNBTJKW.js → chunk-5ISKGSFF.js} +491 -76
- package/dist/{chunk-PLLJ7M62.js → chunk-GQ2QZ5WF.js} +40 -1
- package/dist/{chunk-UZMHXV4D.js → chunk-O7OYNQND.js} +46 -15
- package/dist/cli.js +187 -277
- package/dist/index.js +2 -2
- package/dist/{threads-BFRTS4EB.js → threads-AR6D7V3Y.js} +24 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
MEMORY_TYPES,
|
|
23
23
|
OutputStyleConflictError,
|
|
24
24
|
PLATE,
|
|
25
|
+
SHARE_ASSET_PLACEHOLDER,
|
|
25
26
|
SKIP_SUBTYPES,
|
|
26
27
|
SUPPORT_AVATAR_URL,
|
|
27
28
|
TRANSLATION_LANGUAGES,
|
|
@@ -89,7 +90,6 @@ import {
|
|
|
89
90
|
expandPath,
|
|
90
91
|
explainCost,
|
|
91
92
|
extractCategories,
|
|
92
|
-
extractTitle,
|
|
93
93
|
filterReadableDocsChannels,
|
|
94
94
|
findChannel,
|
|
95
95
|
findChannelById,
|
|
@@ -122,7 +122,6 @@ import {
|
|
|
122
122
|
getWorkspacePermissionMode,
|
|
123
123
|
getWorkspacePlanStatus,
|
|
124
124
|
handleSupportMention,
|
|
125
|
-
highlightLanguageOf,
|
|
126
125
|
insertMcpConnection,
|
|
127
126
|
insertWorkspaceDomain,
|
|
128
127
|
installUsageRecording,
|
|
@@ -149,6 +148,7 @@ import {
|
|
|
149
148
|
latestCliVersion,
|
|
150
149
|
listActiveUsers,
|
|
151
150
|
listAgents,
|
|
151
|
+
listAutoUpdateDocShares,
|
|
152
152
|
listChannelMembers,
|
|
153
153
|
listChannelMemories,
|
|
154
154
|
listLiveDocShares,
|
|
@@ -185,6 +185,7 @@ import {
|
|
|
185
185
|
mentionedUserIds,
|
|
186
186
|
onboardingPending,
|
|
187
187
|
pinnedClaudeConfigDir,
|
|
188
|
+
platformAdminEmails,
|
|
188
189
|
postToDashboardChannel,
|
|
189
190
|
profileClaudeConfigDir,
|
|
190
191
|
profileEnv,
|
|
@@ -192,6 +193,7 @@ import {
|
|
|
192
193
|
profileOauthToken,
|
|
193
194
|
promoteChannelMemory,
|
|
194
195
|
queueShareAudio,
|
|
196
|
+
readDocShareBundle,
|
|
195
197
|
readOAuthClient,
|
|
196
198
|
readSkillFile,
|
|
197
199
|
recentRunsForWorkspace,
|
|
@@ -202,6 +204,7 @@ import {
|
|
|
202
204
|
removeChannelMember,
|
|
203
205
|
renderAppIcon,
|
|
204
206
|
requireDocsAccess,
|
|
207
|
+
requirePlatformOperator,
|
|
205
208
|
resetWorkspaceOnboarding,
|
|
206
209
|
resetWorkspacePrompt,
|
|
207
210
|
resolveAuthContext,
|
|
@@ -209,10 +212,8 @@ import {
|
|
|
209
212
|
resolveChannelId,
|
|
210
213
|
resolveCwd,
|
|
211
214
|
resolveDashboardChannelId,
|
|
212
|
-
resolveDocPath,
|
|
213
215
|
resolveDocsAccess,
|
|
214
216
|
resolveRateCard,
|
|
215
|
-
resolveRawPath,
|
|
216
217
|
resolveUserId,
|
|
217
218
|
revokeDocShare,
|
|
218
219
|
rowToMemory,
|
|
@@ -234,6 +235,7 @@ import {
|
|
|
234
235
|
setAgentPaused,
|
|
235
236
|
setAllowGuestAccess,
|
|
236
237
|
setChannelDocsMemberAccess,
|
|
238
|
+
setDocShareAutoUpdate,
|
|
237
239
|
setDocShareSlug,
|
|
238
240
|
setDocShareTags,
|
|
239
241
|
setMcpConnectionApiKey,
|
|
@@ -278,28 +280,32 @@ import {
|
|
|
278
280
|
useLocalCache,
|
|
279
281
|
validateMemoryInput,
|
|
280
282
|
warnOnBrokenChannelCwds,
|
|
283
|
+
watchDocs,
|
|
281
284
|
workspaceHostname,
|
|
282
285
|
workspaceSkillsDir,
|
|
283
286
|
writeSkillFile
|
|
284
|
-
} from "./chunk-
|
|
287
|
+
} from "./chunk-5ISKGSFF.js";
|
|
285
288
|
import {
|
|
286
289
|
checkPermissionAction,
|
|
287
290
|
createThreadAction,
|
|
288
291
|
firstReplyBody,
|
|
289
292
|
getThread,
|
|
293
|
+
listAutoUpdateSharesAction,
|
|
290
294
|
listChannels,
|
|
291
295
|
listChannelsAction,
|
|
292
296
|
listThreads,
|
|
293
297
|
moveThread,
|
|
294
298
|
moveThreadAction,
|
|
299
|
+
openDocAction,
|
|
295
300
|
postReplyAction,
|
|
296
301
|
readThreadAction,
|
|
297
302
|
requestPermissionAction,
|
|
298
303
|
resolveChannel,
|
|
299
304
|
runDocsCmd,
|
|
300
305
|
searchThreadsAction,
|
|
306
|
+
setUiZoomAction,
|
|
301
307
|
shareDocAction
|
|
302
|
-
} from "./chunk-
|
|
308
|
+
} from "./chunk-GQ2QZ5WF.js";
|
|
303
309
|
import {
|
|
304
310
|
AuthApiError,
|
|
305
311
|
DEFAULT_API_URL,
|
|
@@ -329,6 +335,7 @@ import {
|
|
|
329
335
|
handleAttachmentUrlResult,
|
|
330
336
|
handleHostDbResult,
|
|
331
337
|
handlePluginSvgResult,
|
|
338
|
+
handleScratchImageResult,
|
|
332
339
|
handleShouldRespondResult,
|
|
333
340
|
isEffort,
|
|
334
341
|
loadConfig,
|
|
@@ -350,7 +357,7 @@ import {
|
|
|
350
357
|
slackConfigured,
|
|
351
358
|
sumR2PrefixBytes,
|
|
352
359
|
useHostDbWithoutCredentials
|
|
353
|
-
} from "./chunk-
|
|
360
|
+
} from "./chunk-O7OYNQND.js";
|
|
354
361
|
|
|
355
362
|
// ../core/src/logger.ts
|
|
356
363
|
var ALREADY_STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
@@ -2207,7 +2214,7 @@ function npmEnv(target) {
|
|
|
2207
2214
|
return nodeBin ? { ...process.env, PATH: `${nodeBin}:${process.env.PATH ?? ""}` } : process.env;
|
|
2208
2215
|
}
|
|
2209
2216
|
async function runUpgrade() {
|
|
2210
|
-
const current = "0.1.
|
|
2217
|
+
const current = "0.1.65";
|
|
2211
2218
|
console.log(`Current version: ${current}`);
|
|
2212
2219
|
console.log("Checking for updates...\n");
|
|
2213
2220
|
try {
|
|
@@ -6159,7 +6166,7 @@ async function runMcpCmd(args) {
|
|
|
6159
6166
|
useHostDbWithoutCredentials();
|
|
6160
6167
|
switch (server) {
|
|
6161
6168
|
case "threads": {
|
|
6162
|
-
const { startThreadsServer } = await import("./threads-
|
|
6169
|
+
const { startThreadsServer } = await import("./threads-AR6D7V3Y.js");
|
|
6163
6170
|
await startThreadsServer();
|
|
6164
6171
|
return;
|
|
6165
6172
|
}
|
|
@@ -6755,9 +6762,6 @@ function threadPath(workspace, channelId, threadId) {
|
|
|
6755
6762
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
6756
6763
|
import { CopyObjectCommand, PutObjectCommand as PutObjectCommand2 } from "@aws-sdk/client-s3";
|
|
6757
6764
|
|
|
6758
|
-
// ../api/src/dashboard/bridge-types.ts
|
|
6759
|
-
var SHARE_ASSET_PLACEHOLDER = "/share/{{flyspace-share-id}}/assets/";
|
|
6760
|
-
|
|
6761
6765
|
// ../api/src/dashboard/doc-share-features.ts
|
|
6762
6766
|
import { DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
6763
6767
|
var DEFAULT_FEATURES = {
|
|
@@ -7109,6 +7113,39 @@ var shareDoc = async (input2, ctx) => {
|
|
|
7109
7113
|
if (!res.url) throw new ActionError(`Share failed: ${res.error ?? "unknown error"}`);
|
|
7110
7114
|
return { url: res.url };
|
|
7111
7115
|
};
|
|
7116
|
+
var openDoc = async (input2, ctx) => {
|
|
7117
|
+
const channel = await channelInScope(ctx, input2.channel_id);
|
|
7118
|
+
const { threadId } = ctx.requester;
|
|
7119
|
+
if (!threadId) throw new ActionError("No thread to open the doc in.");
|
|
7120
|
+
await threadInScope(ctx, threadId);
|
|
7121
|
+
const targetUserId = await requesterUserId(ctx);
|
|
7122
|
+
if (!targetUserId) throw new ActionError("No requester to open the doc for.");
|
|
7123
|
+
const res = await getSupabaseClient().channel(`agent-thinking:${threadId}`).httpSend("open-doc", {
|
|
7124
|
+
channelId: channel.id,
|
|
7125
|
+
path: input2.path,
|
|
7126
|
+
...input2.line ? { line: input2.line } : {},
|
|
7127
|
+
targetUserId
|
|
7128
|
+
});
|
|
7129
|
+
if (!res.success) throw new Error(`broadcast failed: ${res.error}`);
|
|
7130
|
+
return { opened: true };
|
|
7131
|
+
};
|
|
7132
|
+
var setUiZoom = async (input2, ctx) => {
|
|
7133
|
+
const { threadId } = ctx.requester;
|
|
7134
|
+
if (!threadId) throw new ActionError("No thread to reach the requester through.");
|
|
7135
|
+
await threadInScope(ctx, threadId);
|
|
7136
|
+
const targetUserId = await requesterUserId(ctx);
|
|
7137
|
+
if (!targetUserId) throw new ActionError("No requester to set the zoom for.");
|
|
7138
|
+
const zoom = Math.round(input2.percent / 10) / 10;
|
|
7139
|
+
const res = await getSupabaseClient().channel(`agent-thinking:${threadId}`).httpSend("set-ui-zoom", { zoom, targetUserId });
|
|
7140
|
+
if (!res.success) throw new Error(`broadcast failed: ${res.error}`);
|
|
7141
|
+
return { zoom };
|
|
7142
|
+
};
|
|
7143
|
+
var listAutoUpdateShares = async (_input, ctx) => ({
|
|
7144
|
+
shares: (await listAutoUpdateDocShares(ctx.scope)).map((s) => ({
|
|
7145
|
+
channel_id: s.channelId,
|
|
7146
|
+
path: s.sourcePath
|
|
7147
|
+
}))
|
|
7148
|
+
});
|
|
7112
7149
|
function describeToolInput(input2) {
|
|
7113
7150
|
const pick = input2["command"] ?? input2["file_path"] ?? input2["path"] ?? input2["url"];
|
|
7114
7151
|
const text = typeof pick === "string" ? pick : JSON.stringify(input2, null, 2);
|
|
@@ -7178,6 +7215,9 @@ var HANDLERS = {
|
|
|
7178
7215
|
[postReplyAction.name]: postReply,
|
|
7179
7216
|
[moveThreadAction.name]: moveThread2,
|
|
7180
7217
|
[shareDocAction.name]: shareDoc,
|
|
7218
|
+
[openDocAction.name]: openDoc,
|
|
7219
|
+
[setUiZoomAction.name]: setUiZoom,
|
|
7220
|
+
[listAutoUpdateSharesAction.name]: listAutoUpdateShares,
|
|
7181
7221
|
[requestPermissionAction.name]: requestPermission,
|
|
7182
7222
|
[checkPermissionAction.name]: checkPermission
|
|
7183
7223
|
};
|
|
@@ -7606,27 +7646,6 @@ async function ensureGreetingThread(workspaceId, channelId, ownerName) {
|
|
|
7606
7646
|
return error2?.code === "23505" ? (await existing()).data?.id ?? null : null;
|
|
7607
7647
|
}
|
|
7608
7648
|
|
|
7609
|
-
// ../api/src/dashboard/admin-middleware.ts
|
|
7610
|
-
function platformAdminEmails() {
|
|
7611
|
-
const raw = process.env["PLATFORM_ADMIN_EMAILS"] ?? "";
|
|
7612
|
-
return new Set(
|
|
7613
|
-
raw.split(",").map((e) => e.trim().toLowerCase()).filter(Boolean)
|
|
7614
|
-
);
|
|
7615
|
-
}
|
|
7616
|
-
var requirePlatformOperator = async (c, next) => {
|
|
7617
|
-
const supabase = createRequestSupabaseClient(c);
|
|
7618
|
-
const {
|
|
7619
|
-
data: { user }
|
|
7620
|
-
} = await supabase.auth.getUser();
|
|
7621
|
-
if (!user?.email) return c.json({ error: "not signed in" }, 401);
|
|
7622
|
-
const email = user.email.trim().toLowerCase();
|
|
7623
|
-
if (!platformAdminEmails().has(email)) {
|
|
7624
|
-
return c.json({ error: "platform operator access required" }, 403);
|
|
7625
|
-
}
|
|
7626
|
-
c.set("platformOperator", { userId: user.id, email });
|
|
7627
|
-
return next();
|
|
7628
|
-
};
|
|
7629
|
-
|
|
7630
7649
|
// ../api/src/dashboard/auth-routes.ts
|
|
7631
7650
|
function createAuthRouter() {
|
|
7632
7651
|
const auth = new Hono7();
|
|
@@ -9813,7 +9832,8 @@ function shareJson(c, share) {
|
|
|
9813
9832
|
social: share.socialEnabled,
|
|
9814
9833
|
branding: share.brandingEnabled,
|
|
9815
9834
|
translation: share.translationEnabled,
|
|
9816
|
-
translationLangs: share.translationLangs
|
|
9835
|
+
translationLangs: share.translationLangs,
|
|
9836
|
+
autoUpdate: share.autoUpdate
|
|
9817
9837
|
};
|
|
9818
9838
|
}
|
|
9819
9839
|
function readFeatures(body) {
|
|
@@ -9888,6 +9908,7 @@ function createDocShareListRouter() {
|
|
|
9888
9908
|
branding: s.brandingEnabled,
|
|
9889
9909
|
translation: s.translationEnabled,
|
|
9890
9910
|
translationLangs: s.translationLangs,
|
|
9911
|
+
autoUpdate: s.autoUpdate,
|
|
9891
9912
|
audioStatus: s.audioStatus,
|
|
9892
9913
|
channelId: s.channelId,
|
|
9893
9914
|
// `channels` is what produced the id filter, so this always hits — the
|
|
@@ -9998,8 +10019,11 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
9998
10019
|
},
|
|
9999
10020
|
503
|
|
10000
10021
|
);
|
|
10001
|
-
default:
|
|
10002
|
-
|
|
10022
|
+
default: {
|
|
10023
|
+
const autoUpdate = body["autoUpdate"];
|
|
10024
|
+
const share = typeof autoUpdate === "boolean" && autoUpdate !== result.share.autoUpdate ? await setDocShareAutoUpdate(result.share.id, autoUpdate) ?? result.share : result.share;
|
|
10025
|
+
return c.json(shareJson(c, share), 201);
|
|
10026
|
+
}
|
|
10003
10027
|
}
|
|
10004
10028
|
});
|
|
10005
10029
|
app.patch("/:id/docs/share", async (c) => {
|
|
@@ -10014,10 +10038,11 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
10014
10038
|
return c.json({ error: slugErrorMessage(slug.invalid), field: "slug" }, 400);
|
|
10015
10039
|
const features = readFeatures(body);
|
|
10016
10040
|
const tags = normalizeTags(body["tags"]);
|
|
10017
|
-
|
|
10041
|
+
const autoUpdate = typeof body["autoUpdate"] === "boolean" ? body["autoUpdate"] : void 0;
|
|
10042
|
+
if (!("slug" in slug) && tags === null && autoUpdate === void 0 && features.audio === void 0 && features.ask === void 0 && features.social === void 0 && features.branding === void 0 && features.translation === void 0 && features.translationLangs === void 0) {
|
|
10018
10043
|
return c.json(
|
|
10019
10044
|
{
|
|
10020
|
-
error: "slug, tags, audio, ask, social, branding, translation or translationLangs is required"
|
|
10045
|
+
error: "slug, tags, autoUpdate, audio, ask, social, branding, translation or translationLangs is required"
|
|
10021
10046
|
},
|
|
10022
10047
|
400
|
|
10023
10048
|
);
|
|
@@ -10045,6 +10070,11 @@ function createDocShareWriteRouter(agent = {}) {
|
|
|
10045
10070
|
if (!next) return c.json({ error: "not shared" }, 404);
|
|
10046
10071
|
tagged = next;
|
|
10047
10072
|
}
|
|
10073
|
+
if (autoUpdate !== void 0 && autoUpdate !== tagged.autoUpdate) {
|
|
10074
|
+
const next = await setDocShareAutoUpdate(tagged.id, autoUpdate);
|
|
10075
|
+
if (!next) return c.json({ error: "not shared" }, 404);
|
|
10076
|
+
tagged = next;
|
|
10077
|
+
}
|
|
10048
10078
|
const updated = await updateShareFeatures(tagged, features);
|
|
10049
10079
|
if (!updated) return c.json({ error: "not shared" }, 404);
|
|
10050
10080
|
return c.json(shareJson(c, updated));
|
|
@@ -10376,6 +10406,29 @@ var GROQ_TRANSCRIBE_URL = "https://api.groq.com/openai/v1/audio/transcriptions";
|
|
|
10376
10406
|
var MODEL2 = "whisper-large-v3-turbo";
|
|
10377
10407
|
var MAX_AUDIO_BYTES = 25 * 1024 * 1024;
|
|
10378
10408
|
var MAX_PROMPT_CHARS = 400;
|
|
10409
|
+
var MAX_TAIL_CHARS = 200;
|
|
10410
|
+
var MAX_GLOSSARY_CHARS = 150;
|
|
10411
|
+
var STYLE_SEED = "\u9019\u662F\u7E41\u9AD4\u4E2D\u6587\u7684\u53E3\u8FF0\uFF0C\u4E2D\u9593\u593E\u96DC English \u8853\u8A9E\uFF0C\u4F8B\u5982 component\u3001API\u3001deploy\u3002";
|
|
10412
|
+
var HALLUCINATIONS = [
|
|
10413
|
+
/^(謝謝|感謝)(大家|您|你)?(的)?(收看|觀看|收聽|觀賞)[。!!.]?$/,
|
|
10414
|
+
/^請不吝點讚.*$/,
|
|
10415
|
+
/^字幕(由|製作|提供).{0,20}$/,
|
|
10416
|
+
/^(thank you|thanks)( (so much|very much))?( for watching)?[.!]?$/i,
|
|
10417
|
+
/^(you|bye)[.!]?$/i
|
|
10418
|
+
];
|
|
10419
|
+
function isHallucination(text) {
|
|
10420
|
+
const t = text.trim();
|
|
10421
|
+
return HALLUCINATIONS.some((re) => re.test(t));
|
|
10422
|
+
}
|
|
10423
|
+
function buildPrompt(terms, tail) {
|
|
10424
|
+
let glossary = "";
|
|
10425
|
+
for (const term of terms) {
|
|
10426
|
+
const next = glossary ? `${glossary}\u3001${term}` : term;
|
|
10427
|
+
if (next.length > MAX_GLOSSARY_CHARS) break;
|
|
10428
|
+
glossary = next;
|
|
10429
|
+
}
|
|
10430
|
+
return [glossary && `${glossary}\u3002`, STYLE_SEED, tail.slice(-MAX_TAIL_CHARS)].filter(Boolean).join(" ").slice(-MAX_PROMPT_CHARS);
|
|
10431
|
+
}
|
|
10379
10432
|
var NO_SPEECH_THRESHOLD = 0.6;
|
|
10380
10433
|
function createTranscribeRouter() {
|
|
10381
10434
|
const app = new Hono17();
|
|
@@ -10391,9 +10444,17 @@ function createTranscribeRouter() {
|
|
|
10391
10444
|
form.append("model", MODEL2);
|
|
10392
10445
|
form.append("temperature", "0");
|
|
10393
10446
|
form.append("response_format", "verbose_json");
|
|
10394
|
-
const
|
|
10395
|
-
|
|
10396
|
-
|
|
10447
|
+
const tail = typeof body?.["prompt"] === "string" ? body["prompt"] : "";
|
|
10448
|
+
const channelId = body?.["channelId"];
|
|
10449
|
+
let terms = [];
|
|
10450
|
+
if (typeof channelId === "string" && channelId) {
|
|
10451
|
+
const visible = await globalChannelMeta(c).catch(() => /* @__PURE__ */ new Map());
|
|
10452
|
+
if (visible.has(channelId)) {
|
|
10453
|
+
const glossary = await getChannelGlossaries([channelId]).catch(() => /* @__PURE__ */ new Map());
|
|
10454
|
+
terms = (glossary.get(channelId)?.terms ?? []).map((t) => t.term);
|
|
10455
|
+
}
|
|
10456
|
+
}
|
|
10457
|
+
form.append("prompt", buildPrompt(terms, tail));
|
|
10397
10458
|
const language = body?.["language"];
|
|
10398
10459
|
if (typeof language === "string" && /^[a-z]{2}$/.test(language)) {
|
|
10399
10460
|
form.append("language", language);
|
|
@@ -10409,7 +10470,8 @@ function createTranscribeRouter() {
|
|
|
10409
10470
|
if (segments.length > 0 && segments.every((s) => (s.no_speech_prob ?? 0) > NO_SPEECH_THRESHOLD)) {
|
|
10410
10471
|
return c.json({ text: "" });
|
|
10411
10472
|
}
|
|
10412
|
-
|
|
10473
|
+
const text = (data.text ?? "").trim();
|
|
10474
|
+
return c.json({ text: isHallucination(text) ? "" : text });
|
|
10413
10475
|
});
|
|
10414
10476
|
return app;
|
|
10415
10477
|
}
|
|
@@ -14658,7 +14720,7 @@ function createHostApiRouter(agent = {}) {
|
|
|
14658
14720
|
|
|
14659
14721
|
// src/dashboard/agent-bridge-host.ts
|
|
14660
14722
|
import { sign as signRaw, timingSafeEqual } from "crypto";
|
|
14661
|
-
import { existsSync as existsSync25, readFileSync as
|
|
14723
|
+
import { existsSync as existsSync25, readFileSync as readFileSync19 } from "fs";
|
|
14662
14724
|
import dotenv2 from "dotenv";
|
|
14663
14725
|
import { WebSocket as WebSocket2 } from "ws";
|
|
14664
14726
|
|
|
@@ -14933,236 +14995,6 @@ async function handleHostRequest(req) {
|
|
|
14933
14995
|
return runRelayed(req, (app) => registerHostRoutes(app));
|
|
14934
14996
|
}
|
|
14935
14997
|
|
|
14936
|
-
// src/dashboard/doc-share-publisher.ts
|
|
14937
|
-
import { readFileSync as readFileSync19, statSync as statSync6 } from "fs";
|
|
14938
|
-
import { extname, posix } from "path";
|
|
14939
|
-
var MAX_ASSET_BYTES = 20 * 1024 * 1024;
|
|
14940
|
-
var MAX_CONTENT_BYTES = 2 * 1024 * 1024;
|
|
14941
|
-
var MAX_ASSETS = 50;
|
|
14942
|
-
var MAX_BUNDLE_ASSET_BYTES = 48 * 1024 * 1024;
|
|
14943
|
-
var MAX_INLINE_BYTES = 200 * 1024;
|
|
14944
|
-
var MAX_TOTAL_INLINE_BYTES = 1024 * 1024;
|
|
14945
|
-
var MD_LINK = /(!?\[[^\]]*\]\()\s*(<[^>]+>|[^)\s]+)/g;
|
|
14946
|
-
var MD_LINK_FULL = /(!?)\[([^\]]*)\]\(\s*(<[^>]+>|[^)\s]+)((?:\s+"[^"]*"|\s+'[^']*'|\s+\([^)]*\))?)\s*\)/g;
|
|
14947
|
-
var HTML_URL_ATTR = /\b(src|href|poster)\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi;
|
|
14948
|
-
var HTML_CSS_URL = /\burl\(\s*("[^"]*"|'[^']*'|[^)'"\s]+)\s*\)/gi;
|
|
14949
|
-
var HTML_URL_PATTERNS = [
|
|
14950
|
-
{ re: HTML_URL_ATTR, group: 2 },
|
|
14951
|
-
{ re: HTML_CSS_URL, group: 1 }
|
|
14952
|
-
];
|
|
14953
|
-
function unquote2(value) {
|
|
14954
|
-
const q = value[0];
|
|
14955
|
-
if ((q === '"' || q === "'") && value.length >= 2 && value.endsWith(q)) {
|
|
14956
|
-
return { quote: q, url: value.slice(1, -1) };
|
|
14957
|
-
}
|
|
14958
|
-
return { quote: "", url: value };
|
|
14959
|
-
}
|
|
14960
|
-
function htmlUrls(source) {
|
|
14961
|
-
const seen = /* @__PURE__ */ new Set();
|
|
14962
|
-
const out = [];
|
|
14963
|
-
for (const { re, group } of HTML_URL_PATTERNS) {
|
|
14964
|
-
for (const match of source.matchAll(re)) {
|
|
14965
|
-
const { url } = unquote2(match[group]);
|
|
14966
|
-
if (!url || seen.has(url)) continue;
|
|
14967
|
-
seen.add(url);
|
|
14968
|
-
out.push(url);
|
|
14969
|
-
}
|
|
14970
|
-
}
|
|
14971
|
-
return out;
|
|
14972
|
-
}
|
|
14973
|
-
function rewriteHtml(source, rewritten) {
|
|
14974
|
-
return source.replace(HTML_URL_ATTR, (whole, attr, value) => {
|
|
14975
|
-
const { quote, url } = unquote2(value);
|
|
14976
|
-
const next = rewritten.get(url);
|
|
14977
|
-
return next ? `${attr}=${quote || '"'}${next}${quote || '"'}` : whole;
|
|
14978
|
-
}).replace(HTML_CSS_URL, (whole, value) => {
|
|
14979
|
-
const { quote, url } = unquote2(value);
|
|
14980
|
-
const next = rewritten.get(url);
|
|
14981
|
-
return next ? `url(${quote || '"'}${next}${quote || '"'})` : whole;
|
|
14982
|
-
});
|
|
14983
|
-
}
|
|
14984
|
-
function shareKindOf(absPath) {
|
|
14985
|
-
const ext = extname(absPath).toLowerCase();
|
|
14986
|
-
if (ext === ".md" || ext === ".markdown") return "markdown";
|
|
14987
|
-
if (ext === ".html" || ext === ".htm") return "html";
|
|
14988
|
-
if (ext === ".excalidraw") return "excalidraw";
|
|
14989
|
-
return null;
|
|
14990
|
-
}
|
|
14991
|
-
function isExternalHref(href) {
|
|
14992
|
-
return /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith("//") || href.startsWith("#");
|
|
14993
|
-
}
|
|
14994
|
-
function sanitizeAssetName(name) {
|
|
14995
|
-
const base = name.split(/[/\\]/).pop() ?? "";
|
|
14996
|
-
const cleaned = base.replace(/\s+/g, "-").replace(/[^\w.-]/g, "").trim();
|
|
14997
|
-
return (cleaned || "file").slice(-100);
|
|
14998
|
-
}
|
|
14999
|
-
function renderAttachments(files) {
|
|
15000
|
-
if (files.length === 0) return "";
|
|
15001
|
-
const blocks = files.map((f) => {
|
|
15002
|
-
const longest = Math.max(0, ...[...f.text.matchAll(/`{3,}/g)].map((m) => m[0].length));
|
|
15003
|
-
const fence = "`".repeat(Math.max(3, longest + 1));
|
|
15004
|
-
const label2 = f.path.replace(/["\r\n]/g, "");
|
|
15005
|
-
return `${fence}${f.lang} file="${label2}" id=${f.anchor}
|
|
15006
|
-
${f.text.replace(/\s+$/, "")}
|
|
15007
|
-
${fence}`;
|
|
15008
|
-
});
|
|
15009
|
-
return `
|
|
15010
|
-
|
|
15011
|
-
---
|
|
15012
|
-
|
|
15013
|
-
${blocks.join("\n\n")}
|
|
15014
|
-
`;
|
|
15015
|
-
}
|
|
15016
|
-
function classifyHref(cwd, docDir, rawHref) {
|
|
15017
|
-
const href = rawHref.startsWith("<") && rawHref.endsWith(">") ? rawHref.slice(1, -1) : rawHref;
|
|
15018
|
-
if (!href) return null;
|
|
15019
|
-
const attachment = href.match(/^\/api\/attachments\/(.+)$/);
|
|
15020
|
-
if (attachment) {
|
|
15021
|
-
const key = attachment[1].split("/").map((s) => {
|
|
15022
|
-
try {
|
|
15023
|
-
return decodeURIComponent(s);
|
|
15024
|
-
} catch {
|
|
15025
|
-
return s;
|
|
15026
|
-
}
|
|
15027
|
-
}).join("/");
|
|
15028
|
-
return key.startsWith("chat/") ? { kind: "attachment", key } : null;
|
|
15029
|
-
}
|
|
15030
|
-
if (isExternalHref(href)) return null;
|
|
15031
|
-
const pathPart = href.split(/[?#]/)[0];
|
|
15032
|
-
if (!pathPart) return null;
|
|
15033
|
-
if (pathPart.startsWith("/")) {
|
|
15034
|
-
if (pathPart !== cwd && !pathPart.startsWith(`${cwd}/`)) return null;
|
|
15035
|
-
return { kind: "local", rel: pathPart.slice(cwd.length).replace(/^\/+/, "") };
|
|
15036
|
-
}
|
|
15037
|
-
return { kind: "local", rel: posix.normalize(docDir ? `${docDir}/${pathPart}` : pathPart) };
|
|
15038
|
-
}
|
|
15039
|
-
function readDocShareBundle({ cwd, sourcePath }) {
|
|
15040
|
-
const abs = resolveDocPath(cwd, sourcePath);
|
|
15041
|
-
if (!abs) return { status: "not-found" };
|
|
15042
|
-
const kind = shareKindOf(abs);
|
|
15043
|
-
if (!kind) return { status: "unsupported" };
|
|
15044
|
-
let stat;
|
|
15045
|
-
try {
|
|
15046
|
-
stat = statSync6(abs);
|
|
15047
|
-
} catch {
|
|
15048
|
-
return { status: "not-found" };
|
|
15049
|
-
}
|
|
15050
|
-
if (!stat.isFile()) return { status: "not-found" };
|
|
15051
|
-
if (stat.size > MAX_CONTENT_BYTES) return { status: "too-large" };
|
|
15052
|
-
const source = readFileSync19(abs, "utf8");
|
|
15053
|
-
const title = extractTitle(abs, kind === "markdown" ? "md" : kind);
|
|
15054
|
-
if (kind === "excalidraw") {
|
|
15055
|
-
try {
|
|
15056
|
-
const parsed = JSON.parse(source);
|
|
15057
|
-
if (!parsed || typeof parsed !== "object") return { status: "unsupported" };
|
|
15058
|
-
} catch {
|
|
15059
|
-
return { status: "unsupported" };
|
|
15060
|
-
}
|
|
15061
|
-
return { status: "ok", kind, title, content: source, assets: [] };
|
|
15062
|
-
}
|
|
15063
|
-
const docDir = sourcePath.includes("/") ? sourcePath.slice(0, sourcePath.lastIndexOf("/")) : "";
|
|
15064
|
-
const rewritten = /* @__PURE__ */ new Map();
|
|
15065
|
-
const usedNames = /* @__PURE__ */ new Set();
|
|
15066
|
-
const usedAnchors = /* @__PURE__ */ new Set();
|
|
15067
|
-
const assets = [];
|
|
15068
|
-
let assetBytes = 0;
|
|
15069
|
-
const attachments = [];
|
|
15070
|
-
let inlinedBytes = 0;
|
|
15071
|
-
const claimName = (candidate) => {
|
|
15072
|
-
const safe = sanitizeAssetName(candidate);
|
|
15073
|
-
if (!usedNames.has(safe)) {
|
|
15074
|
-
usedNames.add(safe);
|
|
15075
|
-
return safe;
|
|
15076
|
-
}
|
|
15077
|
-
const ext = extname(safe);
|
|
15078
|
-
const stem = safe.slice(0, safe.length - ext.length);
|
|
15079
|
-
for (let n = 2; ; n += 1) {
|
|
15080
|
-
const next = `${stem}-${n}${ext}`;
|
|
15081
|
-
if (!usedNames.has(next)) {
|
|
15082
|
-
usedNames.add(next);
|
|
15083
|
-
return next;
|
|
15084
|
-
}
|
|
15085
|
-
}
|
|
15086
|
-
};
|
|
15087
|
-
const claimAnchor = (rel) => {
|
|
15088
|
-
const stem = sanitizeAssetName(rel).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
15089
|
-
const base = `file-${stem || "attachment"}`;
|
|
15090
|
-
if (!usedAnchors.has(base)) {
|
|
15091
|
-
usedAnchors.add(base);
|
|
15092
|
-
return base;
|
|
15093
|
-
}
|
|
15094
|
-
for (let n = 2; ; n += 1) {
|
|
15095
|
-
const next = `${base}-${n}`;
|
|
15096
|
-
if (!usedAnchors.has(next)) {
|
|
15097
|
-
usedAnchors.add(next);
|
|
15098
|
-
return next;
|
|
15099
|
-
}
|
|
15100
|
-
}
|
|
15101
|
-
};
|
|
15102
|
-
const refs = [];
|
|
15103
|
-
const hrefs = kind === "html" ? htmlUrls(source) : [...source.matchAll(MD_LINK)].map((m) => m[2]);
|
|
15104
|
-
for (const href of hrefs) {
|
|
15105
|
-
if (rewritten.has(href) || refs.some((r) => r.href === href)) continue;
|
|
15106
|
-
const ref = classifyHref(cwd, docDir, href);
|
|
15107
|
-
if (ref) refs.push({ href, ref });
|
|
15108
|
-
}
|
|
15109
|
-
for (const { href, ref } of refs.slice(0, MAX_ASSETS)) {
|
|
15110
|
-
if (ref.kind === "attachment") {
|
|
15111
|
-
const name2 = claimName(ref.key.split("/").pop() ?? "file");
|
|
15112
|
-
assets.push({ name: name2, copyFrom: ref.key });
|
|
15113
|
-
rewritten.set(href, `${SHARE_ASSET_PLACEHOLDER}${name2}`);
|
|
15114
|
-
continue;
|
|
15115
|
-
}
|
|
15116
|
-
const docAbs = kind === "markdown" ? resolveDocPath(cwd, ref.rel) : null;
|
|
15117
|
-
const lang = docAbs ? highlightLanguageOf(docAbs) : null;
|
|
15118
|
-
if (docAbs && lang) {
|
|
15119
|
-
const budget = Math.min(MAX_INLINE_BYTES, MAX_TOTAL_INLINE_BYTES - inlinedBytes);
|
|
15120
|
-
let text = null;
|
|
15121
|
-
try {
|
|
15122
|
-
const size = statSync6(docAbs).size;
|
|
15123
|
-
if (size <= budget) text = readFileSync19(docAbs, "utf8");
|
|
15124
|
-
} catch {
|
|
15125
|
-
continue;
|
|
15126
|
-
}
|
|
15127
|
-
if (text !== null) {
|
|
15128
|
-
const anchor = claimAnchor(ref.rel);
|
|
15129
|
-
inlinedBytes += Buffer.byteLength(text);
|
|
15130
|
-
attachments.push({ anchor, path: ref.rel, lang, text });
|
|
15131
|
-
rewritten.set(href, `#${anchor}`);
|
|
15132
|
-
continue;
|
|
15133
|
-
}
|
|
15134
|
-
}
|
|
15135
|
-
const resolved = resolveRawPath(cwd, ref.rel) ?? (docAbs ? { abs: docAbs, contentType: "text/plain; charset=utf-8" } : null);
|
|
15136
|
-
if (!resolved) continue;
|
|
15137
|
-
let body;
|
|
15138
|
-
try {
|
|
15139
|
-
if (statSync6(resolved.abs).size > MAX_ASSET_BYTES) continue;
|
|
15140
|
-
body = readFileSync19(resolved.abs);
|
|
15141
|
-
} catch {
|
|
15142
|
-
continue;
|
|
15143
|
-
}
|
|
15144
|
-
assetBytes += body.length;
|
|
15145
|
-
if (assetBytes > MAX_BUNDLE_ASSET_BYTES) return { status: "too-large" };
|
|
15146
|
-
const name = claimName(ref.rel.split("/").pop() ?? "file");
|
|
15147
|
-
assets.push({ name, contentType: resolved.contentType, data: body.toString("base64") });
|
|
15148
|
-
rewritten.set(href, `${SHARE_ASSET_PLACEHOLDER}${name}`);
|
|
15149
|
-
}
|
|
15150
|
-
if (kind === "html") {
|
|
15151
|
-
return { status: "ok", kind, title, content: rewriteHtml(source, rewritten), assets };
|
|
15152
|
-
}
|
|
15153
|
-
const content = source.replace(
|
|
15154
|
-
MD_LINK_FULL,
|
|
15155
|
-
(whole, bang, label2, href, title2) => {
|
|
15156
|
-
const replacement = rewritten.get(href);
|
|
15157
|
-
if (replacement?.startsWith("#") && bang) return label2;
|
|
15158
|
-
if (replacement) return `${bang}[${label2}](${replacement}${title2})`;
|
|
15159
|
-
if (classifyHref(cwd, docDir, href)?.kind === "local") return label2;
|
|
15160
|
-
return whole;
|
|
15161
|
-
}
|
|
15162
|
-
);
|
|
15163
|
-
return { status: "ok", kind, title, content: content + renderAttachments(attachments), assets };
|
|
15164
|
-
}
|
|
15165
|
-
|
|
15166
14998
|
// src/dashboard/host-upgrade.ts
|
|
15167
14999
|
import { spawn as spawn5 } from "child_process";
|
|
15168
15000
|
import { mkdirSync as mkdirSync10, openSync as openSync3 } from "fs";
|
|
@@ -15321,7 +15153,7 @@ function buildHostConfigSnapshot() {
|
|
|
15321
15153
|
const snapshot2 = {};
|
|
15322
15154
|
for (const profile of listProfiles()) {
|
|
15323
15155
|
snapshot2[profile] = runWithProfile(profile, () => ({
|
|
15324
|
-
env: existsSync25(paths.CONFIG_FILE) ? dotenv2.parse(
|
|
15156
|
+
env: existsSync25(paths.CONFIG_FILE) ? dotenv2.parse(readFileSync19(paths.CONFIG_FILE, "utf-8")) : {},
|
|
15325
15157
|
// Only a model someone actually saved: before that it is just the Claude
|
|
15326
15158
|
// default, which would show the wrong agent in admin for a Codex user.
|
|
15327
15159
|
agentModel: existsSync25(paths.DASHBOARD_SETTINGS_FILE) ? loadDashboardSettings().agent : void 0
|
|
@@ -15411,6 +15243,10 @@ function connectHostSocket(url, callbacks, onAuthenticated, onWorkspaces) {
|
|
|
15411
15243
|
handlePluginSvgResult(msg.id, msg.url);
|
|
15412
15244
|
return;
|
|
15413
15245
|
}
|
|
15246
|
+
if (msg.type === "scratch-image-result") {
|
|
15247
|
+
handleScratchImageResult(msg.id, msg.url);
|
|
15248
|
+
return;
|
|
15249
|
+
}
|
|
15414
15250
|
if (msg.type === "action-result") {
|
|
15415
15251
|
handleActionResult(msg.id, { value: msg.value, error: msg.error });
|
|
15416
15252
|
return;
|
|
@@ -15635,7 +15471,7 @@ The JSON API is live under /api.` : "This install has no bundled Workspace UI.\n
|
|
|
15635
15471
|
}
|
|
15636
15472
|
|
|
15637
15473
|
// src/dashboard/host-log-file.ts
|
|
15638
|
-
import { createWriteStream, fstatSync, mkdirSync as mkdirSync11, statSync as
|
|
15474
|
+
import { createWriteStream, fstatSync, mkdirSync as mkdirSync11, statSync as statSync6 } from "fs";
|
|
15639
15475
|
import { join as join18 } from "path";
|
|
15640
15476
|
var STAMPED = /^\[\d{4}-\d{2}-\d{2}T/;
|
|
15641
15477
|
function stamp(text) {
|
|
@@ -15645,7 +15481,7 @@ function stamp(text) {
|
|
|
15645
15481
|
function alreadyRedirected(fd, file) {
|
|
15646
15482
|
try {
|
|
15647
15483
|
const a = fstatSync(fd);
|
|
15648
|
-
const b =
|
|
15484
|
+
const b = statSync6(file);
|
|
15649
15485
|
return a.dev === b.dev && a.ino === b.ino;
|
|
15650
15486
|
} catch {
|
|
15651
15487
|
return false;
|
|
@@ -15673,6 +15509,77 @@ function ensureHostLogFiles() {
|
|
|
15673
15509
|
tee(process.stderr, 2, join18(paths.LOG_DIR, "host-error.log"));
|
|
15674
15510
|
}
|
|
15675
15511
|
|
|
15512
|
+
// src/dashboard/doc-share-auto-update.ts
|
|
15513
|
+
var REFRESH_MS = 6e4;
|
|
15514
|
+
var QUIET_MS = 5e3;
|
|
15515
|
+
function startDocShareAutoUpdate() {
|
|
15516
|
+
const watched = /* @__PURE__ */ new Map();
|
|
15517
|
+
const timers = /* @__PURE__ */ new Map();
|
|
15518
|
+
const publish = (channelId, path) => {
|
|
15519
|
+
void requestAction(shareDocAction.name, { channel_id: channelId, path }).then((res) => {
|
|
15520
|
+
if (res.error !== void 0) console.error(`[doc-share-auto] ${path}: ${res.error}`);
|
|
15521
|
+
});
|
|
15522
|
+
};
|
|
15523
|
+
const refresh = async () => {
|
|
15524
|
+
const res = await requestAction(listAutoUpdateSharesAction.name, {});
|
|
15525
|
+
if (res.error !== void 0) return;
|
|
15526
|
+
const parsed = listAutoUpdateSharesAction.output.safeParse(res.value);
|
|
15527
|
+
if (!parsed.success) return;
|
|
15528
|
+
const wanted = /* @__PURE__ */ new Map();
|
|
15529
|
+
for (const s of parsed.data.shares) {
|
|
15530
|
+
const set = wanted.get(s.channel_id) ?? /* @__PURE__ */ new Set();
|
|
15531
|
+
set.add(s.path);
|
|
15532
|
+
wanted.set(s.channel_id, set);
|
|
15533
|
+
}
|
|
15534
|
+
for (const [channelId, entry] of watched) {
|
|
15535
|
+
if (!wanted.has(channelId)) {
|
|
15536
|
+
entry.off();
|
|
15537
|
+
watched.delete(channelId);
|
|
15538
|
+
}
|
|
15539
|
+
}
|
|
15540
|
+
for (const [channelId, paths2] of wanted) {
|
|
15541
|
+
const existing = watched.get(channelId);
|
|
15542
|
+
if (existing) {
|
|
15543
|
+
existing.paths = paths2;
|
|
15544
|
+
continue;
|
|
15545
|
+
}
|
|
15546
|
+
let off;
|
|
15547
|
+
try {
|
|
15548
|
+
off = watchDocs(resolveChannelConfig(channelId).cwd, (changed) => {
|
|
15549
|
+
const entry = watched.get(channelId);
|
|
15550
|
+
if (!entry) return;
|
|
15551
|
+
for (const path of changed) {
|
|
15552
|
+
if (!entry.paths.has(path)) continue;
|
|
15553
|
+
const key = `${channelId}:${path}`;
|
|
15554
|
+
clearTimeout(timers.get(key));
|
|
15555
|
+
timers.set(
|
|
15556
|
+
key,
|
|
15557
|
+
setTimeout(() => {
|
|
15558
|
+
timers.delete(key);
|
|
15559
|
+
publish(channelId, path);
|
|
15560
|
+
}, QUIET_MS)
|
|
15561
|
+
);
|
|
15562
|
+
}
|
|
15563
|
+
});
|
|
15564
|
+
} catch {
|
|
15565
|
+
continue;
|
|
15566
|
+
}
|
|
15567
|
+
watched.set(channelId, { paths: paths2, off });
|
|
15568
|
+
}
|
|
15569
|
+
};
|
|
15570
|
+
const tick = () => void refresh().catch((err) => console.error("[doc-share-auto] refresh failed:", err.message));
|
|
15571
|
+
tick();
|
|
15572
|
+
const interval = setInterval(tick, REFRESH_MS);
|
|
15573
|
+
interval.unref();
|
|
15574
|
+
return () => {
|
|
15575
|
+
clearInterval(interval);
|
|
15576
|
+
for (const t of timers.values()) clearTimeout(t);
|
|
15577
|
+
timers.clear();
|
|
15578
|
+
for (const entry of watched.values()) entry.off();
|
|
15579
|
+
watched.clear();
|
|
15580
|
+
};
|
|
15581
|
+
}
|
|
15582
|
+
|
|
15676
15583
|
// src/dashboard/host-dashboard.ts
|
|
15677
15584
|
async function startHostDashboard(preferredPort, host) {
|
|
15678
15585
|
loadEnvFiles();
|
|
@@ -15696,6 +15603,8 @@ async function startHostDashboard(preferredPort, host) {
|
|
|
15696
15603
|
onHostConnected = () => void chatAgent.recoverMissed().catch((err) => console.error("[chat-agent] recoverMissed failed:", err.message));
|
|
15697
15604
|
if (earlyHostSocket) onHostConnected();
|
|
15698
15605
|
const stopSkillSync = installSkillSync(listProfiles());
|
|
15606
|
+
const stopDocShareAutoUpdate = earlyHostSocket ? startDocShareAutoUpdate() : () => {
|
|
15607
|
+
};
|
|
15699
15608
|
const app = createBaseApp();
|
|
15700
15609
|
app.route("/api", createHostApiRouter(agent));
|
|
15701
15610
|
mountDataRootRoutes(app);
|
|
@@ -15740,6 +15649,7 @@ async function startHostDashboard(preferredPort, host) {
|
|
|
15740
15649
|
stopServiceWatch();
|
|
15741
15650
|
stopPushWatcher();
|
|
15742
15651
|
stopSkillSync();
|
|
15652
|
+
stopDocShareAutoUpdate();
|
|
15743
15653
|
hostSocketClient.stop();
|
|
15744
15654
|
server.close();
|
|
15745
15655
|
}
|
|
@@ -16220,7 +16130,7 @@ async function main() {
|
|
|
16220
16130
|
break;
|
|
16221
16131
|
case "-v":
|
|
16222
16132
|
case "--version":
|
|
16223
|
-
printRaw("0.1.
|
|
16133
|
+
printRaw("0.1.65");
|
|
16224
16134
|
break;
|
|
16225
16135
|
case "-h":
|
|
16226
16136
|
case "--help":
|