@keyou007/agent-bot 0.1.27-alpha.3 → 0.1.27-alpha.5
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/CHANGELOG.md +32 -0
- package/README.md +102 -18
- package/README.zh.md +102 -18
- package/assets/agent-bot.ico +0 -0
- package/assets/roboto-mono-OFL.txt +93 -0
- package/assets/roboto-mono-latin.woff2 +0 -0
- package/assets/workspace-drafts.js +88 -0
- package/assets/workspace-sessions.js +2676 -243
- package/assets/workspace.css +553 -44
- package/assets/workspace.js +3429 -327
- package/dist/cli/SelfUpdateObserver.js +124 -0
- package/dist/cli/SelfUpdateObserver.js.map +1 -0
- package/dist/cli/SelfUpdateRunner.js +267 -70
- package/dist/cli/SelfUpdateRunner.js.map +1 -1
- package/dist/cli/SelfUpdater.js +54 -15
- package/dist/cli/SelfUpdater.js.map +1 -1
- package/dist/cli/controlProtocol.js.map +1 -1
- package/dist/cli/help.js +6 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli.js +85 -6
- package/dist/cli.js.map +1 -1
- package/dist/codex/CodexEventMapper.js +29 -5
- package/dist/codex/CodexEventMapper.js.map +1 -1
- package/dist/codex/CodexRuntime.js +3 -0
- package/dist/codex/CodexRuntime.js.map +1 -1
- package/dist/feishu/CardRenderer.js +45 -13
- package/dist/feishu/CardRenderer.js.map +1 -1
- package/dist/feishu/ConsoleFeishuClient.js +4 -0
- package/dist/feishu/ConsoleFeishuClient.js.map +1 -1
- package/dist/feishu/FeishuMarkdown.js +2 -14
- package/dist/feishu/FeishuMarkdown.js.map +1 -1
- package/dist/feishu/FeishuMessageClient.js +9 -0
- package/dist/feishu/FeishuMessageClient.js.map +1 -1
- package/dist/feishu/FeishuTurnPresenter.js +51 -22
- package/dist/feishu/FeishuTurnPresenter.js.map +1 -1
- package/dist/index.js +47 -12
- package/dist/index.js.map +1 -1
- package/dist/local-files/DiagramPreview.js +11 -6
- package/dist/local-files/DiagramPreview.js.map +1 -1
- package/dist/local-files/GitDiffPreview.js +106 -14
- package/dist/local-files/GitDiffPreview.js.map +1 -1
- package/dist/local-files/LiveMarkup.js +104 -0
- package/dist/local-files/LiveMarkup.js.map +1 -0
- package/dist/local-files/LocalFileViewerServer.js +141 -122
- package/dist/local-files/LocalFileViewerServer.js.map +1 -1
- package/dist/local-files/MarkdownExport.js +54 -0
- package/dist/local-files/MarkdownExport.js.map +1 -0
- package/dist/local-files/PreviewCodeFont.js +11 -0
- package/dist/local-files/PreviewCodeFont.js.map +1 -0
- package/dist/local-files/PreviewSyntaxHighlight.js +73 -0
- package/dist/local-files/PreviewSyntaxHighlight.js.map +1 -1
- package/dist/local-files/ToolCommandDisplay.js +111 -0
- package/dist/local-files/ToolCommandDisplay.js.map +1 -0
- package/dist/local-files/TurnPreviewPage.js +53 -276
- package/dist/local-files/TurnPreviewPage.js.map +1 -1
- package/dist/local-files/WorkspaceFileEvents.js +206 -0
- package/dist/local-files/WorkspaceFileEvents.js.map +1 -0
- package/dist/local-files/WorkspaceFiles.js +79 -3
- package/dist/local-files/WorkspaceFiles.js.map +1 -1
- package/dist/local-files/WorkspaceImages.js +43 -0
- package/dist/local-files/WorkspaceImages.js.map +1 -0
- package/dist/local-files/WorkspacePage.js +24 -6
- package/dist/local-files/WorkspacePage.js.map +1 -1
- package/dist/local-files/WorkspaceSessions.js +1153 -104
- package/dist/local-files/WorkspaceSessions.js.map +1 -1
- package/dist/local-files/WorkspaceTimeline.js +129 -0
- package/dist/local-files/WorkspaceTimeline.js.map +1 -0
- package/dist/presentation/OutboundRouter.js +15 -6
- package/dist/presentation/OutboundRouter.js.map +1 -1
- package/dist/presentation/TurnStateReducer.js +31 -22
- package/dist/presentation/TurnStateReducer.js.map +1 -1
- package/dist/proxy/ProxySessionController.js +335 -113
- package/dist/proxy/ProxySessionController.js.map +1 -1
- package/dist/proxy/TaskMetadata.js +86 -0
- package/dist/proxy/TaskMetadata.js.map +1 -0
- package/dist/scheduling/ScheduleCards.js +10 -4
- package/dist/scheduling/ScheduleCards.js.map +1 -1
- package/dist/scheduling/ScheduleCommand.js +4 -0
- package/dist/scheduling/ScheduleCommand.js.map +1 -1
- package/dist/scheduling/ScheduledTaskStore.js +53 -12
- package/dist/scheduling/ScheduledTaskStore.js.map +1 -1
- package/dist/scheduling/types.js +19 -4
- package/dist/scheduling/types.js.map +1 -1
- package/dist/state/StateStore.js +213 -23
- package/dist/state/StateStore.js.map +1 -1
- package/dist/state/TurnPreviewJournal.js +157 -39
- package/dist/state/TurnPreviewJournal.js.map +1 -1
- package/dist/state/TurnToolText.js +172 -0
- package/dist/state/TurnToolText.js.map +1 -0
- package/dist/state/migrations.js +4 -0
- package/dist/state/migrations.js.map +1 -1
- package/dist/supervision/SafeRestartNotifier.js +9 -6
- package/dist/supervision/SafeRestartNotifier.js.map +1 -1
- package/dist/terminal/TerminalPage.js +5 -0
- package/dist/terminal/TerminalPage.js.map +1 -1
- package/dist/updates/AutomaticUpdatePreparer.js +63 -12
- package/dist/updates/AutomaticUpdatePreparer.js.map +1 -1
- package/dist/updates/ManualUpdateController.js +7 -2
- package/dist/updates/ManualUpdateController.js.map +1 -1
- package/dist/utils/promptAttachments.js +22 -0
- package/dist/utils/promptAttachments.js.map +1 -0
- package/dist/utils/promptQuotes.js +47 -0
- package/dist/utils/promptQuotes.js.map +1 -0
- package/dist/utils/toolTimestamp.js +6 -0
- package/dist/utils/toolTimestamp.js.map +1 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/agent-bot/SKILL.md +23 -2
- package/src/cli/SelfUpdateObserver.ts +111 -0
- package/src/cli/SelfUpdateRunner.ts +271 -85
- package/src/cli/SelfUpdater.ts +53 -16
- package/src/cli/controlProtocol.ts +1 -0
- package/src/cli/help.ts +6 -0
- package/src/cli.ts +71 -5
- package/src/codex/CodexEventMapper.ts +25 -5
- package/src/codex/CodexRuntime.ts +4 -0
- package/src/feishu/CardRenderer.ts +48 -13
- package/src/feishu/ConsoleFeishuClient.ts +6 -1
- package/src/feishu/FeishuMarkdown.ts +2 -14
- package/src/feishu/FeishuMessageClient.ts +10 -0
- package/src/feishu/FeishuTurnPresenter.ts +49 -16
- package/src/feishu/types.ts +1 -0
- package/src/index.ts +47 -12
- package/src/local-files/DiagramPreview.ts +11 -6
- package/src/local-files/GitDiffPreview.ts +107 -15
- package/src/local-files/LiveMarkup.ts +103 -0
- package/src/local-files/LocalFileViewerServer.ts +128 -125
- package/src/local-files/MarkdownExport.ts +54 -0
- package/src/local-files/PreviewCodeFont.ts +12 -0
- package/src/local-files/PreviewSyntaxHighlight.ts +75 -0
- package/src/local-files/ToolCommandDisplay.ts +104 -0
- package/src/local-files/TurnPreviewPage.ts +58 -261
- package/src/local-files/WorkspaceFileEvents.ts +186 -0
- package/src/local-files/WorkspaceFiles.ts +72 -5
- package/src/local-files/WorkspaceImages.ts +35 -0
- package/src/local-files/WorkspacePage.ts +24 -6
- package/src/local-files/WorkspaceSessions.ts +1057 -111
- package/src/local-files/WorkspaceTimeline.ts +135 -0
- package/src/presentation/OutboundRouter.ts +18 -4
- package/src/presentation/TurnStateReducer.ts +30 -19
- package/src/presentation/turnViewTypes.ts +3 -1
- package/src/proxy/ProxySessionController.ts +336 -96
- package/src/proxy/TaskMetadata.ts +81 -0
- package/src/runtime/types.ts +2 -1
- package/src/scheduling/ScheduleCards.ts +10 -4
- package/src/scheduling/ScheduleCommand.ts +4 -0
- package/src/scheduling/ScheduledTaskStore.ts +56 -9
- package/src/scheduling/types.ts +27 -4
- package/src/state/StateStore.ts +227 -24
- package/src/state/TurnPreviewJournal.ts +155 -38
- package/src/state/TurnToolText.ts +156 -0
- package/src/state/migrations.ts +4 -0
- package/src/supervision/SafeRestartNotifier.ts +9 -6
- package/src/terminal/TerminalPage.ts +5 -0
- package/src/updates/AutomaticUpdatePreparer.ts +52 -11
- package/src/updates/ManualUpdateController.ts +8 -3
- package/src/utils/promptAttachments.ts +27 -0
- package/src/utils/promptQuotes.ts +48 -0
- package/src/utils/toolTimestamp.ts +5 -0
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { TurnPreviewProjection } from "../state/TurnPreviewJournal.js";
|
|
2
|
-
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import http from "node:http";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import hljs from "highlight.js/lib/common";
|
|
9
|
-
import dos from "highlight.js/lib/languages/dos";
|
|
10
|
-
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
|
11
|
-
import powershell from "highlight.js/lib/languages/powershell";
|
|
12
9
|
import MarkdownIt from "markdown-it";
|
|
13
10
|
import { CSV_PREVIEW_CSS, renderCsvPreview, csvSourcePreview } from "./CsvPreview.js";
|
|
14
11
|
import { GIT_DIFF_PREVIEW_CSS, readGitFileDiff, renderGitFileDiff } from "./GitDiffPreview.js";
|
|
15
|
-
import { renderWorkspacePage, WORKSPACE_SCRIPT } from "./WorkspacePage.js";
|
|
12
|
+
import { renderWorkspacePage, WORKSPACE_ICON, WORKSPACE_ICON_NAME, WORKSPACE_INSTANCE, WORKSPACE_INSTANCE_HEADER, WORKSPACE_REVISION, WORKSPACE_REVISION_HEADER, WORKSPACE_SCRIPT } from "./WorkspacePage.js";
|
|
13
|
+
import { PREVIEW_CODE_FONT, PREVIEW_CODE_FONT_NAME, previewCodeFontCss } from "./PreviewCodeFont.js";
|
|
14
|
+
import { highlightLines, highlightTextLines, MAX_SYNTAX_HIGHLIGHT_BYTES, syntaxLanguageFor } from "./PreviewSyntaxHighlight.js";
|
|
16
15
|
import { directWorkspaceOrigin } from "./WorkspaceOrigin.js";
|
|
16
|
+
import { WorkspaceFileEvents } from "./WorkspaceFileEvents.js";
|
|
17
17
|
import { readWebPageTitle } from "./WebPageTitle.js";
|
|
18
18
|
import { WorkspaceError, readWorkspaceAddress, readWorkspaceEntries, readWorkspaceGitStatus, readWorkspaceChanges, readWorkspaceFileVersions, createWorkspaceDiff, renderWorkspaceDiff, resolveWorkspacePath } from "./WorkspaceFiles.js";
|
|
19
19
|
import { enableDiagramFences, DIAGRAM_PREVIEW_CLIENT_SCRIPT, DIAGRAM_PREVIEW_CSS } from "./DiagramPreview.js";
|
|
@@ -28,20 +28,18 @@ const SHORT_TOKEN_BYTES = 12;
|
|
|
28
28
|
const SHORT_TOKEN_LENGTH = 16;
|
|
29
29
|
const MAX_TEXT_PREVIEW_BYTES = 2 * 1024 * 1024;
|
|
30
30
|
const MAX_CONTENT_SAMPLE_BYTES = 64 * 1024;
|
|
31
|
-
const MAX_SYNTAX_HIGHLIGHT_BYTES = 512 * 1024;
|
|
32
31
|
const DIRECTORY_PAGE_SIZE = 100;
|
|
33
32
|
const WORKSPACE_QUERY = z.object({
|
|
34
33
|
api: z.string().optional(), entry: z.string().default(""),
|
|
35
34
|
page: z.coerce.number().int().min(0).max(Number.MAX_SAFE_INTEGER).default(0),
|
|
36
35
|
mode: z.enum(["all", "staged", "unstaged"]).default("all"), original: z.string().optional(),
|
|
36
|
+
source: z.literal("1").optional(),
|
|
37
37
|
prefetch: z.enum(["0", "1"]).optional(), query: z.string().trim().max(160).optional(),
|
|
38
|
+
refresh: z.enum(["1"]).optional(),
|
|
38
39
|
instance: z.string().regex(/^[a-f0-9]{16}$/u).optional(),
|
|
39
40
|
});
|
|
40
41
|
const MARKDOWN_EXTENSIONS = new Set([".markdown", ".md", ".mdown", ".mkd", ".mkdn"]);
|
|
41
42
|
const HTML_EXTENSIONS = new Set([".html", ".htm"]);
|
|
42
|
-
hljs.registerLanguage("dos", dos);
|
|
43
|
-
hljs.registerLanguage("dockerfile", dockerfile);
|
|
44
|
-
hljs.registerLanguage("powershell", powershell);
|
|
45
43
|
const MARKDOWN_RENDERER = new MarkdownIt({
|
|
46
44
|
breaks: false,
|
|
47
45
|
html: false,
|
|
@@ -58,27 +56,18 @@ const MARKDOWN_RENDERER = new MarkdownIt({
|
|
|
58
56
|
},
|
|
59
57
|
});
|
|
60
58
|
enableDiagramFences(MARKDOWN_RENDERER);
|
|
61
|
-
MARKDOWN_RENDERER.renderer.rules.table_open = () => '<div class="markdown-table-scroll" role="region" aria-label="Markdown 表格" tabindex="0"><table>\n';
|
|
59
|
+
MARKDOWN_RENDERER.renderer.rules.table_open = (tokens, index, _options, _env, renderer) => '<div class="markdown-table-scroll" role="region" aria-label="Markdown 表格" tabindex="0"><table' + renderer.renderAttrs(tokens[index]) + '>\n';
|
|
62
60
|
MARKDOWN_RENDERER.renderer.rules.table_close = () => '</table></div>\n';
|
|
61
|
+
for (const kind of ["fence", "code_block"]) {
|
|
62
|
+
const render = MARKDOWN_RENDERER.renderer.rules[kind];
|
|
63
|
+
MARKDOWN_RENDERER.renderer.rules[kind] = (tokens, index, options, env, renderer) => {
|
|
64
|
+
const html = render(tokens, index, options, env, renderer), token = tokens[index];
|
|
65
|
+
const start = token.attrGet("data-source-start"), end = token.attrGet("data-source-end");
|
|
66
|
+
return start === null ? html : `<div data-source-start="${start}" data-source-end="${end}">${html}</div>\n`;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
63
69
|
const validateMarkdownLink = MARKDOWN_RENDERER.validateLink.bind(MARKDOWN_RENDERER);
|
|
64
70
|
MARKDOWN_RENDERER.validateLink = (url) => isFileUrl(url) || validateMarkdownLink(url);
|
|
65
|
-
const HIGHLIGHT_LANGUAGE_BY_EXTENSION = {
|
|
66
|
-
".bash": "bash", ".bat": "dos", ".c": "c", ".cc": "cpp", ".cmd": "dos", ".cpp": "cpp",
|
|
67
|
-
".cs": "csharp", ".css": "css", ".cxx": "cpp", ".diff": "diff", ".go": "go", ".h": "cpp",
|
|
68
|
-
".hpp": "cpp", ".htm": "xml", ".html": "xml", ".ini": "ini", ".ipynb": "json", ".java": "java",
|
|
69
|
-
".js": "javascript", ".json": "json", ".jsonl": "json", ".jsx": "javascript", ".kt": "kotlin",
|
|
70
|
-
".kts": "kotlin", ".less": "less", ".lua": "lua", ".markdown": "markdown", ".md": "markdown",
|
|
71
|
-
".mjs": "javascript", ".patch": "diff", ".php": "php", ".pl": "perl", ".ps1": "powershell",
|
|
72
|
-
".py": "python", ".r": "r", ".rb": "ruby", ".rs": "rust", ".scss": "scss", ".sh": "bash",
|
|
73
|
-
".sql": "sql", ".swift": "swift", ".toml": "ini", ".ts": "typescript", ".tsx": "typescript",
|
|
74
|
-
".vue": "xml", ".xml": "xml", ".yaml": "yaml", ".yml": "yaml", ".zsh": "bash",
|
|
75
|
-
};
|
|
76
|
-
const HIGHLIGHT_LANGUAGE_BY_FILENAME = {
|
|
77
|
-
".env": "ini",
|
|
78
|
-
".gitignore": "ini",
|
|
79
|
-
"dockerfile": "dockerfile",
|
|
80
|
-
"makefile": "makefile",
|
|
81
|
-
};
|
|
82
71
|
const VIEWER_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
|
|
83
72
|
const eventsUrl = document.body.dataset.eventsUrl;
|
|
84
73
|
const content = document.getElementById("viewer-content");
|
|
@@ -126,9 +115,9 @@ const VIEWER_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
|
|
|
126
115
|
const diffBlocks = [];
|
|
127
116
|
if (diffPrevious && diffNext) {
|
|
128
117
|
for (const line of content.querySelectorAll(".git-diff .diff-addition, .git-diff .diff-deletion")) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
118
|
+
if (!line.previousElementSibling?.matches(".diff-addition, .diff-deletion")) {
|
|
119
|
+
diffBlocks.push({ first: line, hash: "#diff-" + line.id });
|
|
120
|
+
}
|
|
132
121
|
}
|
|
133
122
|
}
|
|
134
123
|
let diffPositions = [], selectedDiff = -1;
|
|
@@ -158,8 +147,9 @@ const VIEWER_CLIENT_SCRIPT = DIAGRAM_PREVIEW_CLIENT_SCRIPT + `(() => {
|
|
|
158
147
|
const height = window.innerHeight;
|
|
159
148
|
const readerCenter = (header.getBoundingClientRect().height + height) / 2;
|
|
160
149
|
const maxTop = Math.max(0, document.documentElement.scrollHeight - height);
|
|
161
|
-
diffPositions = diffBlocks.map(({ first
|
|
162
|
-
const
|
|
150
|
+
diffPositions = diffBlocks.map(({ first }) => {
|
|
151
|
+
const line = first.getBoundingClientRect();
|
|
152
|
+
const center = (line.top + line.bottom) / 2;
|
|
163
153
|
return Math.min(maxTop, Math.max(0, window.scrollY + center - readerCenter));
|
|
164
154
|
});
|
|
165
155
|
updateDiffNavigation();
|
|
@@ -315,6 +305,7 @@ export class LocalFileViewerServer {
|
|
|
315
305
|
address;
|
|
316
306
|
basePath = "";
|
|
317
307
|
services = new Map();
|
|
308
|
+
workspaceFileEvents = new WorkspaceFileEvents();
|
|
318
309
|
workspaceAppBase;
|
|
319
310
|
enableWorkspaceApp(base) { this.workspaceAppBase = base; }
|
|
320
311
|
serveWorkspaceAppPage(response, url, headOnly) {
|
|
@@ -400,6 +391,7 @@ export class LocalFileViewerServer {
|
|
|
400
391
|
async close() {
|
|
401
392
|
await Promise.all([...this.services.values()].map((service) => service.close()));
|
|
402
393
|
this.services.clear();
|
|
394
|
+
this.workspaceFileEvents.close();
|
|
403
395
|
const server = this.server;
|
|
404
396
|
this.server = undefined;
|
|
405
397
|
this.address = undefined;
|
|
@@ -506,7 +498,20 @@ export class LocalFileViewerServer {
|
|
|
506
498
|
}
|
|
507
499
|
const requestUrl = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
508
500
|
const route = routeWithinBasePath(requestUrl.pathname, this.basePath);
|
|
501
|
+
const workspaceIcon = route === "/assets/" + WORKSPACE_ICON_NAME;
|
|
502
|
+
if (workspaceIcon || route === "/assets/" + PREVIEW_CODE_FONT_NAME) {
|
|
503
|
+
const asset = workspaceIcon ? WORKSPACE_ICON : PREVIEW_CODE_FONT;
|
|
504
|
+
setSecurityHeaders(response);
|
|
505
|
+
response.statusCode = 200;
|
|
506
|
+
response.setHeader("Content-Type", workspaceIcon ? "image/x-icon" : "font/woff2");
|
|
507
|
+
response.setHeader("Cache-Control", "public, max-age=86400");
|
|
508
|
+
response.setHeader("Content-Length", asset.length);
|
|
509
|
+
response.end(request.method === "HEAD" ? undefined : asset);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
509
512
|
if (route === "/assets/workspace.js") {
|
|
513
|
+
response.setHeader(WORKSPACE_REVISION_HEADER, WORKSPACE_REVISION);
|
|
514
|
+
response.setHeader(WORKSPACE_INSTANCE_HEADER, WORKSPACE_INSTANCE);
|
|
510
515
|
this.sendJavascript(response, request.method === "HEAD", WORKSPACE_SCRIPT);
|
|
511
516
|
return;
|
|
512
517
|
}
|
|
@@ -522,8 +527,7 @@ export class LocalFileViewerServer {
|
|
|
522
527
|
await this.handleWorkspace(request, response, requestUrl, root);
|
|
523
528
|
}
|
|
524
529
|
catch (error) {
|
|
525
|
-
|
|
526
|
-
this.sendWorkspaceJson(response, error instanceof WorkspaceError ? error.status : code === "ENOENT" ? 404 : code === "EACCES" || code === "EPERM" ? 403 : 500, { error: error instanceof Error ? error.message : String(error) }, request.method === "HEAD");
|
|
530
|
+
this.sendWorkspaceJson(response, this.workspaceErrorStatus(error), { error: error instanceof Error ? error.message : String(error) }, request.method === "HEAD");
|
|
527
531
|
}
|
|
528
532
|
return;
|
|
529
533
|
}
|
|
@@ -561,7 +565,7 @@ export class LocalFileViewerServer {
|
|
|
561
565
|
}
|
|
562
566
|
const detailKey = requestUrl.searchParams.get("detail");
|
|
563
567
|
let snapshot = recorded
|
|
564
|
-
? journal.
|
|
568
|
+
? await journal.loadAsync(journalId, detailKey ?? false)
|
|
565
569
|
: this.options.getTurnSnapshot?.(turnId);
|
|
566
570
|
if (!recorded && this.options.loadTurnSnapshot && request.method !== "HEAD"
|
|
567
571
|
&& requestUrl.searchParams.get("events") !== "1" && !requestUrl.searchParams.has("detail")) {
|
|
@@ -940,14 +944,19 @@ export class LocalFileViewerServer {
|
|
|
940
944
|
}
|
|
941
945
|
response.flushHeaders();
|
|
942
946
|
const language = detectTurnPreviewLanguage(request.headers["accept-language"]);
|
|
943
|
-
|
|
947
|
+
let projection = new TurnPreviewProjection(false);
|
|
944
948
|
let offset = 0;
|
|
945
949
|
let closed = false;
|
|
946
950
|
let initial = true;
|
|
947
951
|
const cursor = request.headers["last-event-id"] ?? new URL(request.url, "http://localhost").searchParams.get("after");
|
|
948
952
|
if (typeof cursor === "string" && /^\d+$/u.test(cursor) && Number.isSafeInteger(Number(cursor)) && Number(cursor) > 0
|
|
949
953
|
&& Number(cursor) <= fs.statSync(journal.file(turnId)).size) {
|
|
950
|
-
|
|
954
|
+
const cached = journal.cachedProjection(turnId, Number(cursor));
|
|
955
|
+
if (cached) {
|
|
956
|
+
projection = cached;
|
|
957
|
+
offset = Number(cursor);
|
|
958
|
+
}
|
|
959
|
+
while (!cached && offset < Number(cursor)) {
|
|
951
960
|
const batch = journal.read(turnId, offset, 256 * 1024, Number(cursor));
|
|
952
961
|
for (const record of batch.records)
|
|
953
962
|
projection.apply(record, ++projection.revision);
|
|
@@ -1061,32 +1070,89 @@ export class LocalFileViewerServer {
|
|
|
1061
1070
|
request.once("aborted", cleanup);
|
|
1062
1071
|
response.once("close", cleanup);
|
|
1063
1072
|
}
|
|
1064
|
-
sendWorkspaceJson(response, status, value, headOnly) {
|
|
1073
|
+
sendWorkspaceJson(response, status, value, headOnly, request) {
|
|
1065
1074
|
const body = Buffer.from(JSON.stringify(value), "utf8");
|
|
1066
1075
|
setSecurityHeaders(response);
|
|
1076
|
+
if (request) {
|
|
1077
|
+
const etag = '"' + createHash("sha256").update(body).digest("base64url") + '"';
|
|
1078
|
+
response.setHeader("ETag", etag);
|
|
1079
|
+
if (request.headers["if-none-match"] === etag) {
|
|
1080
|
+
response.writeHead(304, { "Cache-Control": "no-store" });
|
|
1081
|
+
response.end();
|
|
1082
|
+
return;
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1067
1085
|
response.writeHead(status, { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store", "Content-Length": body.length });
|
|
1068
1086
|
response.end(headOnly ? undefined : body);
|
|
1069
1087
|
}
|
|
1070
|
-
async
|
|
1071
|
-
|
|
1088
|
+
async serveTaskDirectory(request, response, url, root, base) {
|
|
1089
|
+
try {
|
|
1090
|
+
await this.handleWorkspace(request, response, url, root, base);
|
|
1091
|
+
}
|
|
1092
|
+
catch (error) {
|
|
1093
|
+
if (response.headersSent)
|
|
1094
|
+
throw error;
|
|
1095
|
+
const status = this.workspaceErrorStatus(error);
|
|
1096
|
+
const message = status < 500 && error instanceof Error ? error.message : "暂时无法打开此目录,请重试。";
|
|
1097
|
+
if (url.searchParams.has("api"))
|
|
1098
|
+
this.sendWorkspaceJson(response, status, { error: message }, request.method === "HEAD");
|
|
1099
|
+
else
|
|
1100
|
+
this.sendHtml(response, status, errorPage("无法打开任务目录", message), request.method === "HEAD", "embedded");
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
workspaceErrorStatus(error) {
|
|
1104
|
+
if (error instanceof WorkspaceError)
|
|
1105
|
+
return error.status;
|
|
1106
|
+
const code = error?.code;
|
|
1107
|
+
return code === "ENOENT" || code === "ENOTDIR" ? 404 : code === "EACCES" || code === "EPERM" ? 403 : 500;
|
|
1108
|
+
}
|
|
1109
|
+
async handleWorkspace(request, response, url, root, scopedBase) {
|
|
1110
|
+
if (!fs.statSync(resolveWorkspacePath(root)).isDirectory())
|
|
1111
|
+
throw new WorkspaceError("目录已不可用。", 404);
|
|
1072
1112
|
const headOnly = request.method === "HEAD";
|
|
1073
1113
|
const published = new URL(this.address.publicBaseUrl);
|
|
1074
|
-
const origin = request.headers.host === published.host ? published.origin : directWorkspaceOrigin(request);
|
|
1075
|
-
const workspaceUrl = this.createWorkspaceUrl(root, origin);
|
|
1076
|
-
if (!url.searchParams.
|
|
1077
|
-
this.sendHtml(response, 200, renderWorkspacePage(root, workspaceUrl, this.basePath + "/assets/workspace.js", this.workspaceAppBase), headOnly, true);
|
|
1114
|
+
const origin = scopedBase?.origin ?? (request.headers.host === published.host ? published.origin : directWorkspaceOrigin(request));
|
|
1115
|
+
const workspaceUrl = scopedBase?.href ?? this.createWorkspaceUrl(root, origin);
|
|
1116
|
+
if (!url.searchParams.get("api")) {
|
|
1117
|
+
this.sendHtml(response, 200, renderWorkspacePage(root, workspaceUrl, this.basePath + "/assets/workspace.js", scopedBase ? undefined : this.workspaceAppBase, Boolean(scopedBase)), headOnly, scopedBase ? "embedded" : true);
|
|
1078
1118
|
return;
|
|
1079
1119
|
}
|
|
1080
1120
|
const parsed = WORKSPACE_QUERY.safeParse(Object.fromEntries(url.searchParams));
|
|
1081
1121
|
if (!parsed.success)
|
|
1082
1122
|
throw new WorkspaceError("工作台参数无效:" + parsed.error.issues.map((issue) => issue.message).join(";"));
|
|
1083
|
-
const { api, entry, page, mode, original, prefetch, query, instance } = parsed.data;
|
|
1084
|
-
if (
|
|
1085
|
-
|
|
1123
|
+
const { api, entry, page, mode, original, prefetch, query, instance, refresh, source } = parsed.data;
|
|
1124
|
+
if (scopedBase && (api === "terminal" || api === "web-title"))
|
|
1125
|
+
throw new WorkspaceError("该目录只支持文件浏览。", 404);
|
|
1126
|
+
if (api === "events") {
|
|
1127
|
+
if (request.headers["sec-fetch-site"] === "cross-site" || (request.headers.origin && request.headers.origin !== origin)) {
|
|
1128
|
+
throw new WorkspaceError("项目实时连接来源不受信任。", 403);
|
|
1129
|
+
}
|
|
1130
|
+
if (headOnly)
|
|
1131
|
+
this.sendWorkspaceJson(response, 200, {}, true);
|
|
1132
|
+
else
|
|
1133
|
+
this.workspaceFileEvents.subscribe(root, response);
|
|
1086
1134
|
return;
|
|
1087
1135
|
}
|
|
1088
|
-
if (api === "tree") {
|
|
1089
|
-
|
|
1136
|
+
if (api === "tree" || api === "changes") {
|
|
1137
|
+
if (refresh)
|
|
1138
|
+
this.workspaceFileEvents.invalidateGit(root);
|
|
1139
|
+
const read = api === "tree" ? readWorkspaceEntries : readWorkspaceChanges;
|
|
1140
|
+
const data = await read(root, entry, page, {
|
|
1141
|
+
prefetch: prefetch === "1" && request.headers["save-data"] !== "on", query, readGitStatus: () => this.workspaceFileEvents.gitStatus(root),
|
|
1142
|
+
});
|
|
1143
|
+
if (!headOnly && !query && page === 0) {
|
|
1144
|
+
this.workspaceFileEvents.watchDirectory(root, entry);
|
|
1145
|
+
if ("preloaded" in data && data.preloaded)
|
|
1146
|
+
for (const item of data.preloaded)
|
|
1147
|
+
if (item.directory)
|
|
1148
|
+
this.workspaceFileEvents.watchDirectory(root, item.path);
|
|
1149
|
+
}
|
|
1150
|
+
this.sendWorkspaceJson(response, 200, data, headOnly, request);
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
if (api === "changes-summary") {
|
|
1154
|
+
const { changes, repository, branch, notice } = await this.workspaceFileEvents.gitStatus(root);
|
|
1155
|
+
this.sendWorkspaceJson(response, 200, { totalChanges: changes.length, repository, branch, notice }, headOnly, request);
|
|
1090
1156
|
return;
|
|
1091
1157
|
}
|
|
1092
1158
|
if (api === "address") {
|
|
@@ -1097,10 +1163,6 @@ export class LocalFileViewerServer {
|
|
|
1097
1163
|
this.sendWorkspaceJson(response, 200, headOnly ? {} : await readWebPageTitle(entry), headOnly);
|
|
1098
1164
|
return;
|
|
1099
1165
|
}
|
|
1100
|
-
if (api === "changes") {
|
|
1101
|
-
this.sendWorkspaceJson(response, 200, await readWorkspaceChanges(root, entry, page, { prefetch: prefetch === "1", query }), headOnly);
|
|
1102
|
-
return;
|
|
1103
|
-
}
|
|
1104
1166
|
if (api === "terminal") {
|
|
1105
1167
|
if (!instance)
|
|
1106
1168
|
throw new WorkspaceError("终端标签标识无效。");
|
|
@@ -1118,12 +1180,12 @@ export class LocalFileViewerServer {
|
|
|
1118
1180
|
const before = classifyContentSample(versions.before, true), after = classifyContentSample(versions.after, true);
|
|
1119
1181
|
let html;
|
|
1120
1182
|
if (before.kind === "binary" || after.kind === "binary")
|
|
1121
|
-
html = '<div class="workspace-notice">这个文件是二进制格式,无法显示文本 Diff
|
|
1183
|
+
html = '<div class="workspace-notice">这个文件是二进制格式,无法显示文本 Diff。</div>';
|
|
1122
1184
|
else {
|
|
1123
1185
|
const previous = decodeText(versions.before, before.encoding, true), current = decodeText(versions.after, after.encoding, true);
|
|
1124
1186
|
html = renderWorkspaceDiff(await createWorkspaceDiff(root, previous, current), current, (value) => highlightTextLines(value, file));
|
|
1125
1187
|
}
|
|
1126
|
-
this.sendWorkspaceJson(response, 200, { html, canViewFile: versions.canViewFile }, headOnly);
|
|
1188
|
+
this.sendWorkspaceJson(response, 200, { html, canViewFile: versions.canViewFile }, headOnly, request);
|
|
1127
1189
|
return;
|
|
1128
1190
|
}
|
|
1129
1191
|
if (api !== "file" && api !== "raw")
|
|
@@ -1141,21 +1203,23 @@ export class LocalFileViewerServer {
|
|
|
1141
1203
|
raw.searchParams.set("entry", entry);
|
|
1142
1204
|
const classification = classifyFileContent(file, stat.size);
|
|
1143
1205
|
const type = binaryContentTypeFor(path.extname(file).toLowerCase());
|
|
1206
|
+
const canTogglePreview = classification.kind === "text" && isMarkdownFile(file);
|
|
1144
1207
|
let html;
|
|
1145
1208
|
if (classification.kind === "text") {
|
|
1146
1209
|
const preview = readTextPreview(file, stat.size, classification.encoding);
|
|
1147
1210
|
const lines = preview.text.split(/\r\n?|\n/u);
|
|
1148
|
-
|
|
1149
|
-
|
|
1211
|
+
const text = lines.slice(0, 10_000).join("\n");
|
|
1212
|
+
html = (preview.truncated || lines.length > 10_000 ? '<div class="workspace-notice">文件较大,仅显示前 2 MiB 或 10000 行。</div>' : "")
|
|
1213
|
+
+ (canTogglePreview && source !== "1" ? this.renderWorkspaceMarkdown(root, file, text, workspaceUrl) : renderText(text, file));
|
|
1150
1214
|
}
|
|
1151
1215
|
else if (type.startsWith("image/")) {
|
|
1152
1216
|
html = '<div class="workspace-media"><img src="' + escapeAttribute(raw.toString()) + '" alt="' + escapeAttribute(path.basename(file)) + '"></div>';
|
|
1153
1217
|
}
|
|
1154
1218
|
else if (type === "application/pdf") {
|
|
1155
|
-
html = '<object class="workspace-pdf" type="application/pdf" data="' + escapeAttribute(raw.toString()) + '"
|
|
1219
|
+
html = '<object class="workspace-pdf" type="application/pdf" data="' + escapeAttribute(raw.toString()) + '">当前浏览器无法显示 PDF 预览。</object>';
|
|
1156
1220
|
}
|
|
1157
1221
|
else {
|
|
1158
|
-
html = '<div class="workspace-notice"
|
|
1222
|
+
html = '<div class="workspace-notice">这个文件是二进制格式,当前没有可用的预览。</div>';
|
|
1159
1223
|
}
|
|
1160
1224
|
let change, gitError;
|
|
1161
1225
|
try {
|
|
@@ -1166,10 +1230,16 @@ export class LocalFileViewerServer {
|
|
|
1166
1230
|
catch (error) {
|
|
1167
1231
|
gitError = error instanceof Error ? error.message : String(error);
|
|
1168
1232
|
}
|
|
1169
|
-
this.sendWorkspaceJson(response, 200, { html, rawUrl: raw.toString(), change, gitError }, headOnly);
|
|
1233
|
+
this.sendWorkspaceJson(response, 200, { html, rawUrl: raw.toString(), canTogglePreview, change, gitError }, headOnly, request);
|
|
1170
1234
|
}
|
|
1171
1235
|
renderWorkspaceMarkdown(root, file, value, workspaceUrl) {
|
|
1172
1236
|
const environment = {}, tokens = MARKDOWN_RENDERER.parse(value, environment), targets = new Map();
|
|
1237
|
+
for (const token of tokens) {
|
|
1238
|
+
if (token.map && !token.hidden && token.tag && token.nesting >= 0) {
|
|
1239
|
+
token.attrSet("data-source-start", String(token.map[0] + 1));
|
|
1240
|
+
token.attrSet("data-source-end", String(token.map[1]));
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1173
1243
|
rewriteMarkdownFileLinks(tokens, file, (target) => {
|
|
1174
1244
|
const entry = path.relative(root, target).split(path.sep).join("/");
|
|
1175
1245
|
try {
|
|
@@ -1299,9 +1369,9 @@ export class LocalFileViewerServer {
|
|
|
1299
1369
|
const body = Buffer.from(html, "utf8");
|
|
1300
1370
|
setSecurityHeaders(response);
|
|
1301
1371
|
// External frame redirects must not expose privileged viewer documents.
|
|
1302
|
-
response.setHeader("X-Frame-Options", "DENY");
|
|
1372
|
+
response.setHeader("X-Frame-Options", workspace === "embedded" ? "SAMEORIGIN" : "DENY");
|
|
1303
1373
|
if (workspace)
|
|
1304
|
-
response.setHeader("Content-Security-Policy", "default-src 'none'; img-src 'self' data:; media-src 'self'; object-src 'self'; frame-src 'self' http: https:; script-src 'self'; connect-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'");
|
|
1374
|
+
response.setHeader("Content-Security-Policy", "default-src 'none'; img-src 'self' data: blob:; media-src 'self'; object-src 'self'; frame-src 'self' http: https:; script-src 'self'; connect-src 'self'; font-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors " + (workspace === "embedded" ? "'self'" : "'none'"));
|
|
1305
1375
|
else
|
|
1306
1376
|
response.setHeader("Content-Security-Policy", String(response.getHeader("Content-Security-Policy")).replace("frame-ancestors 'self'", "frame-ancestors 'none'"));
|
|
1307
1377
|
response.statusCode = status;
|
|
@@ -1346,8 +1416,8 @@ function renderViewerPage(input) {
|
|
|
1346
1416
|
<meta charset="utf-8">
|
|
1347
1417
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
1348
1418
|
<title>${escapeHtml(input.title)} · Agent Bot</title>
|
|
1349
|
-
<style>${input.diagramScriptPath ? DIAGRAM_PREVIEW_CSS : ""}
|
|
1350
|
-
:root { --viewer-header-offset: 56px;
|
|
1419
|
+
<style>${input.scriptPath ? previewCodeFontCss(input.scriptPath) : ""}${input.diagramScriptPath ? DIAGRAM_PREVIEW_CSS : ""}
|
|
1420
|
+
:root { --viewer-header-offset: 56px; color-scheme: light dark; font-family: Inter, "Segoe UI", system-ui, sans-serif; }
|
|
1351
1421
|
* { box-sizing: border-box; }
|
|
1352
1422
|
body { margin: 0; background: #f5f7fa; color: #1f2329; }
|
|
1353
1423
|
header { position: sticky; top: 0; z-index: 2; padding: 7px 12px; background: rgba(255,255,255,.96); border-bottom: 1px solid #dfe3e8; }
|
|
@@ -1370,10 +1440,10 @@ function renderViewerPage(input) {
|
|
|
1370
1440
|
main { padding: 0; }
|
|
1371
1441
|
.notice, .unsupported { margin: 8px; padding: 10px 12px; border: 1px solid #f3cf8f; background: #fff7e6; border-radius: 5px; }
|
|
1372
1442
|
.code { margin: 0; padding: 6px 0; overflow: auto; border: 0; border-radius: 0; background: #fff; color: #1f2329; font-size: 13px; line-height: 1.5; tab-size: 2; }
|
|
1373
|
-
.code, .code code, .code .line, .code .line * { font-family: var(--
|
|
1443
|
+
.code, .code code, .code .line, .code .line * { font-family: var(--preview-code-font); font-variant-ligatures: none; }
|
|
1374
1444
|
.line { display: block; min-height: 1.55em; padding-right: 16px; scroll-margin-top: var(--viewer-header-offset); }
|
|
1375
1445
|
.line:target, .line.is-target-line { background: #fff1b8; box-shadow: inset 4px 0 #e6a700; }
|
|
1376
|
-
.line-number { display: inline-block; width:
|
|
1446
|
+
.line-number { display: inline-block; box-sizing: content-box; width: var(--line-number-width, 2ch); margin-right: 8px; padding: 0 6px; text-align: right; color: #8f959e; border-right: 1px solid #eceff3; text-decoration: none; user-select: none; }
|
|
1377
1447
|
.hljs-comment, .hljs-quote { color: #6a737d; font-style: italic; }
|
|
1378
1448
|
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-link { color: #a626a4; }
|
|
1379
1449
|
.hljs-string, .hljs-regexp, .hljs-title, .hljs-name, .hljs-type, .hljs-attribute, .hljs-symbol, .hljs-bullet, .hljs-addition, .hljs-variable, .hljs-template-tag, .hljs-template-variable { color: #087f5b; }
|
|
@@ -1397,7 +1467,7 @@ function renderViewerPage(input) {
|
|
|
1397
1467
|
.markdown-body blockquote { margin-left: 0; padding: .15em 1em; border-left: 4px solid #c9d0db; color: #646a73; }
|
|
1398
1468
|
.markdown-body a { color: #1456f0; text-decoration: none; }
|
|
1399
1469
|
.markdown-body a:hover { text-decoration: underline; }
|
|
1400
|
-
.markdown-body code { padding: .14em .35em; border-radius: 4px; background: #f2f3f5; font-family: var(--
|
|
1470
|
+
.markdown-body code { padding: .14em .35em; border-radius: 4px; background: #f2f3f5; font-family: var(--preview-code-font); font-size: .9em; }
|
|
1401
1471
|
.markdown-body .markdown-code-block { margin: 0 0 1em; padding: 14px 16px; overflow: auto; border-radius: 6px; background: #f6f8fa; line-height: 1.55; }
|
|
1402
1472
|
.markdown-body .markdown-code-block code { padding: 0; background: transparent; font-size: 13px; }
|
|
1403
1473
|
.markdown-body .diagram-source { padding: 14px 16px; }
|
|
@@ -1743,18 +1813,12 @@ function hasTextLikeCharacters(value) {
|
|
|
1743
1813
|
function renderText(value, filePath) {
|
|
1744
1814
|
const language = syntaxLanguageFor(filePath), lines = highlightTextLines(value, filePath);
|
|
1745
1815
|
const languageClass = language ? ` class="language-${escapeAttribute(language)}"` : "";
|
|
1746
|
-
|
|
1816
|
+
const numberWidth = Math.max(2, String(lines.length).length);
|
|
1817
|
+
return `<pre class="code hljs" style="--line-number-width:${numberWidth}ch"><code${languageClass}>${lines.map((line, index) => {
|
|
1747
1818
|
const lineNumber = index + 1;
|
|
1748
|
-
return `<span class="line" id="L${lineNumber}"><a class="line-number" href="#L${lineNumber}">${lineNumber}</a>${line}</span>`;
|
|
1819
|
+
return `<span class="line" id="L${lineNumber}"><a class="line-number" href="#L${lineNumber}">${lineNumber}</a><span class="line-text">${line}</span></span>`;
|
|
1749
1820
|
}).join("")}</code></pre>`;
|
|
1750
1821
|
}
|
|
1751
|
-
function highlightTextLines(value, filePath) {
|
|
1752
|
-
const normalized = value.replace(/\r\n?/gu, "\n");
|
|
1753
|
-
const language = syntaxLanguageFor(filePath);
|
|
1754
|
-
return language && Buffer.byteLength(normalized, "utf8") <= MAX_SYNTAX_HIGHLIGHT_BYTES
|
|
1755
|
-
? highlightLines(normalized, language)
|
|
1756
|
-
: normalized.split("\n").map(escapeHtml);
|
|
1757
|
-
}
|
|
1758
1822
|
function renderMarkdownDocument(value, filePath, createPreviewUrl) {
|
|
1759
1823
|
const environment = {};
|
|
1760
1824
|
const tokens = MARKDOWN_RENDERER.parse(value, environment);
|
|
@@ -1765,51 +1829,6 @@ function renderMarkdownDocument(value, filePath, createPreviewUrl) {
|
|
|
1765
1829
|
function isMarkdownFile(filePath) {
|
|
1766
1830
|
return MARKDOWN_EXTENSIONS.has(path.extname(filePath).toLowerCase());
|
|
1767
1831
|
}
|
|
1768
|
-
function syntaxLanguageFor(filePath) {
|
|
1769
|
-
if (isMarkdownFile(filePath))
|
|
1770
|
-
return "markdown";
|
|
1771
|
-
const fileName = path.basename(filePath).toLowerCase();
|
|
1772
|
-
return Object.hasOwn(HIGHLIGHT_LANGUAGE_BY_FILENAME, fileName) ? HIGHLIGHT_LANGUAGE_BY_FILENAME[fileName]
|
|
1773
|
-
: HIGHLIGHT_LANGUAGE_BY_EXTENSION[path.extname(fileName)];
|
|
1774
|
-
}
|
|
1775
|
-
function highlightLines(value, language) {
|
|
1776
|
-
try {
|
|
1777
|
-
return splitHighlightedLines(hljs.highlight(value, { language, ignoreIllegals: true }).value);
|
|
1778
|
-
}
|
|
1779
|
-
catch {
|
|
1780
|
-
return value.split("\n").map(escapeHtml);
|
|
1781
|
-
}
|
|
1782
|
-
}
|
|
1783
|
-
function splitHighlightedLines(value) {
|
|
1784
|
-
const lines = [];
|
|
1785
|
-
const openTags = [];
|
|
1786
|
-
const tokenPattern = /<span class="[^"]+">|<\/span>|\n/gu;
|
|
1787
|
-
let current = "";
|
|
1788
|
-
let offset = 0;
|
|
1789
|
-
for (const match of value.matchAll(tokenPattern)) {
|
|
1790
|
-
const token = match[0];
|
|
1791
|
-
const index = match.index ?? offset;
|
|
1792
|
-
current += value.slice(offset, index);
|
|
1793
|
-
offset = index + token.length;
|
|
1794
|
-
if (token === "\n") {
|
|
1795
|
-
current += "</span>".repeat(openTags.length);
|
|
1796
|
-
lines.push(current);
|
|
1797
|
-
current = openTags.join("");
|
|
1798
|
-
}
|
|
1799
|
-
else if (token === "</span>") {
|
|
1800
|
-
current += token;
|
|
1801
|
-
openTags.pop();
|
|
1802
|
-
}
|
|
1803
|
-
else {
|
|
1804
|
-
current += token;
|
|
1805
|
-
openTags.push(token);
|
|
1806
|
-
}
|
|
1807
|
-
}
|
|
1808
|
-
current += value.slice(offset);
|
|
1809
|
-
current += "</span>".repeat(openTags.length);
|
|
1810
|
-
lines.push(current);
|
|
1811
|
-
return lines;
|
|
1812
|
-
}
|
|
1813
1832
|
function contentTypeFor(extension) {
|
|
1814
1833
|
const known = {
|
|
1815
1834
|
".aac": "audio/aac", ".avi": "video/x-msvideo", ".bmp": "image/bmp", ".css": "text/css; charset=utf-8",
|
|
@@ -1889,7 +1908,7 @@ function writeServerSentEvent(response, event, data) {
|
|
|
1889
1908
|
response.write("\n");
|
|
1890
1909
|
}
|
|
1891
1910
|
function setSecurityHeaders(response) {
|
|
1892
|
-
response.setHeader("Content-Security-Policy", "default-src 'none'; img-src 'self' data:; media-src 'self'; object-src 'self'; frame-src 'self'; script-src 'self'; connect-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'self'");
|
|
1911
|
+
response.setHeader("Content-Security-Policy", "default-src 'none'; img-src 'self' data:; media-src 'self'; object-src 'self'; frame-src 'self'; script-src 'self'; connect-src 'self'; font-src 'self'; style-src 'unsafe-inline'; base-uri 'none'; form-action 'none'; frame-ancestors 'self'");
|
|
1893
1912
|
response.setHeader("Cross-Origin-Resource-Policy", "same-origin");
|
|
1894
1913
|
response.setHeader("Referrer-Policy", "no-referrer");
|
|
1895
1914
|
response.setHeader("X-Content-Type-Options", "nosniff");
|