texlite 0.18.0 → 0.19.1
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/DESIGN.md +442 -26
- package/NPM_TESTING.md +23 -0
- package/OPERATIONS.md +227 -6
- package/README.md +8 -2
- package/README.zh-CN.md +6 -2
- package/THIRD_PARTY_NOTICES.md +73 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js +1 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js.br +0 -0
- package/dist/client/assets/AdminUsers-CuYfWnEk.js.gz +0 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js +1 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js.br +0 -0
- package/dist/client/assets/AgentIcon-ClP5dPRL.js.gz +0 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css +1 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css.br +0 -0
- package/dist/client/assets/AgentIcon-DxrC-zx_.css.gz +0 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js +1 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js.br +0 -0
- package/dist/client/assets/AgentManagement-jY_BF6Qy.js.gz +0 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js +2 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.br +0 -0
- package/dist/client/assets/AgentTerminal-JKP2SVkZ.js.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css +1 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-B5LH8GIb.css.gz +0 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js +16 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.br +0 -0
- package/dist/client/assets/AgentTerminalSurface-CaYNNZ9A.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js +1 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-C2TACfvP.js.gz +0 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js +1 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-BdU9nbgG.js.gz +0 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js +5 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js.br +0 -0
- package/dist/client/assets/Dashboard-B7mMz5Gj.js.gz +0 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js +3 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js.br +0 -0
- package/dist/client/assets/GitDialog-C2H-jKVO.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js +1 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-DdKiE3pw.js.gz +0 -0
- package/dist/client/assets/{GitHubIcon-DNR0CleM.js → GitHubIcon-Cjli8pd_.js} +1 -1
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js +8 -0
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.br +0 -0
- package/dist/client/assets/HistoryDialog-CoxJ3EsK.js.gz +0 -0
- package/dist/client/assets/{LatexEditor-BzAk3WQM.js → LatexEditor-BhAKioho.js} +26 -26
- package/dist/client/assets/LatexEditor-BhAKioho.js.br +0 -0
- package/dist/client/assets/LatexEditor-BhAKioho.js.gz +0 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js +1 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js.br +0 -0
- package/dist/client/assets/PdfPreview-CC8KEz1Y.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js +1 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-vi_HwlCS.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js +4 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Bl1t-Gnh.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js +30 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-1UOdyfBq.js.gz +0 -0
- package/dist/client/assets/{QuickOpenDialog-CyqeckBM.js → QuickOpenDialog-BAzyrB-4.js} +1 -1
- package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-BAzyrB-4.js.gz +0 -0
- package/dist/client/assets/SaveButton-DkyoEu6j.js +1 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js +3 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-DzlVKtxs.js.gz +0 -0
- package/dist/client/assets/SuccessNotice-ubBtzzi_.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js +1 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-C6RVZdJZ.js.gz +0 -0
- package/dist/client/assets/TagColorSelect-xbc2H5ou.js +1 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js +1 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-8pZUVaEI.js.gz +0 -0
- package/dist/client/assets/{WordCountDialog-Bp8kYngA.js → WordCountDialog-BODhL9iz.js} +1 -1
- package/dist/client/assets/WordCountDialog-BODhL9iz.js.br +0 -0
- package/dist/client/assets/WordCountDialog-BODhL9iz.js.gz +0 -0
- package/dist/client/assets/arrow-down-B6T7Z6IO.js +1 -0
- package/dist/client/assets/check-BRlv1lrZ.js +1 -0
- package/dist/client/assets/chevron-up-krb7w67X.js +1 -0
- package/dist/client/assets/{chktex-BcGmZVUy.js → chktex-Bz-LKycq.js} +1 -1
- package/dist/client/assets/{clock-3-x2vcGFSH.js → clock-3-Fb1_e3ec.js} +1 -1
- package/dist/client/assets/{dist-D5mbpudl.js → dist-CMYWzCHL.js} +1 -1
- package/dist/client/assets/dist-CMYWzCHL.js.br +0 -0
- package/dist/client/assets/dist-CMYWzCHL.js.gz +0 -0
- package/dist/client/assets/{eye-CvzXPIMu.js → eye-B6AX_5uX.js} +1 -1
- package/dist/client/assets/{hard-drive-BeGQ5o79.js → hard-drive-CBmnJ2xS.js} +1 -1
- package/dist/client/assets/i18n-DF6keNBA.js +13 -0
- package/dist/client/assets/i18n-DF6keNBA.js.br +0 -0
- package/dist/client/assets/i18n-DF6keNBA.js.gz +0 -0
- package/dist/client/assets/index-DCwfhKK9.js +42 -0
- package/dist/client/assets/index-DCwfhKK9.js.br +0 -0
- package/dist/client/assets/index-DCwfhKK9.js.gz +0 -0
- package/dist/client/assets/index-SVNFLCYh.css +1 -0
- package/dist/client/assets/index-SVNFLCYh.css.br +0 -0
- package/dist/client/assets/index-SVNFLCYh.css.gz +0 -0
- package/dist/client/assets/info-DNSAs0_-.js +1 -0
- package/dist/client/assets/{minimize-2-yYMmsVER.js → minimize-2-C8oL6PTV.js} +1 -1
- package/dist/client/assets/{minus-CNHOVLWS.js → minus-TCBOakyi.js} +1 -1
- package/dist/client/assets/plus-Dfkyfvvy.js +1 -0
- package/dist/client/assets/{refresh-cw-B7vZa5K2.js → refresh-cw-DuLtxWBX.js} +1 -1
- package/dist/client/assets/relativeTime-BR0CVAvz.js +1 -0
- package/dist/client/assets/relativeTime-BR0CVAvz.js.br +0 -0
- package/dist/client/assets/relativeTime-BR0CVAvz.js.gz +0 -0
- package/dist/client/assets/{search-Czv3qsBy.js → search-n-2tBATf.js} +1 -1
- package/dist/client/assets/{spellCheck-DDCaK8Yx.js → spellCheck-xzICTGx1.js} +1 -1
- package/dist/client/assets/spellCheck-xzICTGx1.js.br +0 -0
- package/dist/client/assets/spellCheck-xzICTGx1.js.gz +0 -0
- package/dist/client/assets/tags-Dy96boLq.js +1 -0
- package/dist/client/assets/terminal-C0xh8jVR.js +1 -0
- package/dist/client/assets/{type-NT195OCy.js → type-BjXWxrjH.js} +1 -1
- package/dist/client/assets/{user-plus-BRuwNzcg.js → user-plus-3oJZJXHW.js} +1 -1
- package/dist/client/index.html +13 -7
- package/dist/server/agents/adapters/claude.js +180 -0
- package/dist/server/agents/adapters/codex.js +47 -0
- package/dist/server/agents/adapters/common.js +86 -0
- package/dist/server/agents/adapters/opencode.js +196 -0
- package/dist/server/agents/adapters/types.js +1 -0
- package/dist/server/agents/execution.js +147 -0
- package/dist/server/agents/launcher.js +57 -0
- package/dist/server/agents/processIdentity.js +63 -0
- package/dist/server/agents/registry.js +72 -0
- package/dist/server/agents/sessions.js +574 -0
- package/dist/server/agents/terminal.js +84 -0
- package/dist/server/agents/workspaces.js +341 -0
- package/dist/server/app.js +32 -1
- package/dist/server/cli.js +19 -47
- package/dist/server/collaboration.js +64 -36
- package/dist/server/compileArtifacts.js +11 -44
- package/dist/server/compiler.js +16 -38
- package/dist/server/config.js +8 -2
- package/dist/server/db.js +33 -0
- package/dist/server/editHistory.js +59 -65
- package/dist/server/history.js +28 -13
- package/dist/server/i18n.js +26 -8
- package/dist/server/latexRoot.js +4 -2
- package/dist/server/locales/zh-Hant.js +145 -0
- package/dist/server/lucideIcons.js +14 -17
- package/dist/server/projectMutations.js +21 -0
- package/dist/server/routes/agents.js +135 -0
- package/dist/server/routes/compile.js +23 -43
- package/dist/server/routes/projectHistory.js +13 -6
- package/dist/server/routes/projectShared.js +6 -1
- package/dist/server/routes/projects.js +15 -23
- package/dist/shared/agentMessages.js +51 -0
- package/dist/shared/agentProtocol.js +41 -0
- package/dist/shared/historyFiles.js +1 -1
- package/dist/shared/historyTracking.js +2 -0
- package/dist/shared/locales.js +21 -0
- package/dist/shared/sourceCommentAnchors.js +52 -4
- package/package.json +7 -3
- package/templates/agents/AGENTS.md +135 -0
- package/texlite.config.example.json +3 -2
- package/dist/client/assets/AdminUsers-rPpYTAU6.js +0 -1
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.br +0 -0
- package/dist/client/assets/AdminUsers-rPpYTAU6.js.gz +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js +0 -1
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.br +0 -0
- package/dist/client/assets/AvatarSettingsDialog-CIPKapVe.js.gz +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js +0 -1
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.br +0 -0
- package/dist/client/assets/CitationLibraryDialog-BhZX8BV2.js.gz +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js +0 -5
- package/dist/client/assets/Dashboard-DppEhsjL.js.br +0 -0
- package/dist/client/assets/Dashboard-DppEhsjL.js.gz +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js +0 -3
- package/dist/client/assets/GitDialog-BOu46hxA.js.br +0 -0
- package/dist/client/assets/GitDialog-BOu46hxA.js.gz +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js +0 -1
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.br +0 -0
- package/dist/client/assets/GitHubAccountDialog-hosK9cLW.js.gz +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js +0 -8
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.br +0 -0
- package/dist/client/assets/HistoryDialog-BdkuEl8r.js.gz +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.br +0 -0
- package/dist/client/assets/LatexEditor-BzAk3WQM.js.gz +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js +0 -1
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.br +0 -0
- package/dist/client/assets/PdfPreview-DkjI1eCo.js.gz +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js +0 -1
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.br +0 -0
- package/dist/client/assets/ProjectIconPickerDialog-D8Uo4H10.js.gz +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js +0 -1
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.br +0 -0
- package/dist/client/assets/ProjectSettings-Jdr94nOc.js.gz +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js +0 -30
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.br +0 -0
- package/dist/client/assets/ProjectWorkspace-D9v3Jj8T.js.gz +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.br +0 -0
- package/dist/client/assets/QuickOpenDialog-CyqeckBM.js.gz +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js +0 -3
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.br +0 -0
- package/dist/client/assets/SelectionHistoryDialog-Dlutex-A.js.gz +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js +0 -1
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.br +0 -0
- package/dist/client/assets/SystemMetricsDialog-CCWxXw6g.js.gz +0 -0
- package/dist/client/assets/TagColorSelect-D3T-rw4K.js +0 -1
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js +0 -1
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.br +0 -0
- package/dist/client/assets/TagManagementDialog-CxjrSX-o.js.gz +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.br +0 -0
- package/dist/client/assets/WordCountDialog-Bp8kYngA.js.gz +0 -0
- package/dist/client/assets/binary-B57nBiwS.js +0 -1
- package/dist/client/assets/check-DFoA73zZ.js +0 -1
- package/dist/client/assets/chevron-up-C8DyKLxi.js +0 -1
- package/dist/client/assets/dist-D5mbpudl.js.br +0 -0
- package/dist/client/assets/dist-D5mbpudl.js.gz +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js +0 -9
- package/dist/client/assets/i18n-CRWKZA6W.js.br +0 -0
- package/dist/client/assets/i18n-CRWKZA6W.js.gz +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js +0 -42
- package/dist/client/assets/index-D0eqhDpZ.js.br +0 -0
- package/dist/client/assets/index-D0eqhDpZ.js.gz +0 -0
- package/dist/client/assets/index-DnhiIb1V.css +0 -1
- package/dist/client/assets/index-DnhiIb1V.css.br +0 -0
- package/dist/client/assets/index-DnhiIb1V.css.gz +0 -0
- package/dist/client/assets/plus-BDquy76g.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js +0 -1
- package/dist/client/assets/relativeTime-DuOytR_J.js.br +0 -0
- package/dist/client/assets/relativeTime-DuOytR_J.js.gz +0 -0
- package/dist/client/assets/sigma-CI6gmAkl.js +0 -1
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.br +0 -0
- package/dist/client/assets/spellCheck-DDCaK8Yx.js.gz +0 -0
- package/dist/client/assets/tags-CLK7WRSs.js +0 -1
- package/preview-1.png +0 -0
- package/preview-2.png +0 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { currentUser, requireAdmin, requireUser } from "../auth.js";
|
|
2
|
+
import { apiError, httpError } from "../http.js";
|
|
3
|
+
import { isAgentId } from "../../shared/agentProtocol.js";
|
|
4
|
+
import { digestToken } from "../security.js";
|
|
5
|
+
function title(value, optional = false) {
|
|
6
|
+
if (optional && value === undefined)
|
|
7
|
+
return "";
|
|
8
|
+
if (typeof value !== "string" || (!optional && !value.trim()) || value.length > 160)
|
|
9
|
+
throw httpError(400, "REQUEST_INVALID");
|
|
10
|
+
return value.trim();
|
|
11
|
+
}
|
|
12
|
+
function terminalOriginAllowed(request) {
|
|
13
|
+
const origin = request.headers.origin;
|
|
14
|
+
if (!origin)
|
|
15
|
+
return false;
|
|
16
|
+
try {
|
|
17
|
+
const parsed = new URL(origin);
|
|
18
|
+
const forwarded = request.headers["x-forwarded-proto"];
|
|
19
|
+
const protocol = forwarded === "https" || forwarded === "http" ? forwarded : request.protocol;
|
|
20
|
+
return parsed.host === request.headers.host && parsed.protocol === `${protocol}:` && parsed.origin === origin;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Task owners get terminal access; administrators get separate metadata/cleanup routes. */
|
|
27
|
+
export function registerAgentRoutes(app, { db, agents }) {
|
|
28
|
+
app.get("/api/agents/access", async (request, reply) => {
|
|
29
|
+
const user = requireUser(request, reply, db);
|
|
30
|
+
if (!user)
|
|
31
|
+
return;
|
|
32
|
+
const { project } = request.query;
|
|
33
|
+
return agents.access(user.id, typeof project === "string" ? project : undefined);
|
|
34
|
+
});
|
|
35
|
+
app.get("/api/agents", async (request, reply) => {
|
|
36
|
+
if (!requireUser(request, reply, db))
|
|
37
|
+
return;
|
|
38
|
+
return agents.catalog();
|
|
39
|
+
});
|
|
40
|
+
app.get("/api/admin/agents", async (request, reply) => {
|
|
41
|
+
if (!requireAdmin(request, reply, db))
|
|
42
|
+
return;
|
|
43
|
+
return agents.catalog();
|
|
44
|
+
});
|
|
45
|
+
app.post("/api/admin/agents/refresh", async (request, reply) => {
|
|
46
|
+
if (!requireAdmin(request, reply, db))
|
|
47
|
+
return;
|
|
48
|
+
return agents.catalog(true);
|
|
49
|
+
});
|
|
50
|
+
app.patch("/api/admin/agents", async (request, reply) => {
|
|
51
|
+
if (!requireAdmin(request, reply, db))
|
|
52
|
+
return;
|
|
53
|
+
const body = request.body;
|
|
54
|
+
if (!Array.isArray(body?.allowed) || !body.allowed.every(isAgentId))
|
|
55
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
56
|
+
await agents.setPolicy({ allowed: body.allowed });
|
|
57
|
+
return agents.catalog();
|
|
58
|
+
});
|
|
59
|
+
for (const administration of [false, true]) {
|
|
60
|
+
const prefix = administration ? "/api/admin/agent-tasks" : "/api/agent-tasks";
|
|
61
|
+
app.get(prefix, async (request, reply) => {
|
|
62
|
+
const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
|
|
63
|
+
if (!user)
|
|
64
|
+
return;
|
|
65
|
+
const raw = request.query;
|
|
66
|
+
const query = {};
|
|
67
|
+
for (const key of ["project", "user", "agent", "state", "page"])
|
|
68
|
+
if (typeof raw[key] === "string")
|
|
69
|
+
query[key] = raw[key];
|
|
70
|
+
return agents.list(user, administration, query);
|
|
71
|
+
});
|
|
72
|
+
app.post(`${prefix}/:taskId/stop`, async (request, reply) => {
|
|
73
|
+
const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
|
|
74
|
+
if (!user)
|
|
75
|
+
return;
|
|
76
|
+
return { task: await agents.stop(request.params.taskId, user, administration) };
|
|
77
|
+
});
|
|
78
|
+
app.delete(`${prefix}/:taskId`, async (request, reply) => {
|
|
79
|
+
const user = administration ? requireAdmin(request, reply, db) : requireUser(request, reply, db);
|
|
80
|
+
if (!user)
|
|
81
|
+
return;
|
|
82
|
+
await agents.remove(request.params.taskId, user, administration);
|
|
83
|
+
return { ok: true };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
app.post("/api/projects/:id/agent-tasks", async (request, reply) => {
|
|
87
|
+
const user = requireUser(request, reply, db);
|
|
88
|
+
if (!user)
|
|
89
|
+
return;
|
|
90
|
+
const body = request.body;
|
|
91
|
+
if (!isAgentId(body?.agentId))
|
|
92
|
+
return apiError(reply, 400, "REQUEST_INVALID");
|
|
93
|
+
const task = await agents.create(request.params.id, user, body.agentId, title(body.title, true));
|
|
94
|
+
return reply.code(201).send({ task });
|
|
95
|
+
});
|
|
96
|
+
app.get("/api/agent-tasks/:taskId", async (request, reply) => {
|
|
97
|
+
const user = requireUser(request, reply, db);
|
|
98
|
+
if (!user)
|
|
99
|
+
return;
|
|
100
|
+
return { task: agents.task(request.params.taskId, user) };
|
|
101
|
+
});
|
|
102
|
+
app.patch("/api/agent-tasks/:taskId", async (request, reply) => {
|
|
103
|
+
const user = requireUser(request, reply, db);
|
|
104
|
+
if (!user)
|
|
105
|
+
return;
|
|
106
|
+
const body = request.body;
|
|
107
|
+
return { task: agents.update(request.params.taskId, user, { title: title(body?.title) }) };
|
|
108
|
+
});
|
|
109
|
+
app.post("/api/agent-tasks/:taskId/start", async (request, reply) => {
|
|
110
|
+
const user = requireUser(request, reply, db);
|
|
111
|
+
if (!user)
|
|
112
|
+
return;
|
|
113
|
+
return { task: await agents.start(request.params.taskId, user) };
|
|
114
|
+
});
|
|
115
|
+
app.get("/api/agent-tasks/:taskId/terminal", { websocket: true }, (socket, request) => {
|
|
116
|
+
const user = currentUser(request, db);
|
|
117
|
+
if (!user || !terminalOriginAllowed(request)) {
|
|
118
|
+
socket.close(1008, "Access denied");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const token = digestToken(request.cookies.texlite_session);
|
|
122
|
+
// currentUser intentionally caches one HTTP request. A WebSocket outlives
|
|
123
|
+
// that request, so recheck its actual session row instead of that cache.
|
|
124
|
+
const session = db.prepare(`SELECT 1 FROM sessions s JOIN users u ON u.id = s.user_id
|
|
125
|
+
WHERE s.id = ? AND s.user_id = ? AND s.expires_at > ? AND u.disabled = 0 AND u.must_change_password = 0`);
|
|
126
|
+
try {
|
|
127
|
+
agents.attach(request.params.taskId, user, socket, () => Boolean(session.get(token, user.id, new Date().toISOString())));
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
const code = error instanceof Error && "code" in error ? String(error.code) : "AGENT_SESSION_BUSY";
|
|
131
|
+
socket.send(JSON.stringify({ type: "error", code }));
|
|
132
|
+
socket.close(1008, "Terminal unavailable");
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
@@ -64,13 +64,9 @@ export function registerCompileRoutes(app, context) {
|
|
|
64
64
|
ORDER BY CASE run.status WHEN 'running' THEN 0 WHEN 'queued' THEN 1 ELSE 2 END, run.created_at DESC LIMIT 1`).get(id, mainFile);
|
|
65
65
|
const latestSuccess = db.prepare(`SELECT id, finished_at FROM compile_runs
|
|
66
66
|
WHERE project_id = ? AND main_file = ? AND status = 'succeeded' ORDER BY created_at DESC LIMIT 1`).get(id, mainFile);
|
|
67
|
-
const pdf = availablePdf(config, id, mainFile
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
WHERE id = ? AND project_id = ? AND status = 'succeeded'`).get(published.runId, id) : undefined;
|
|
71
|
-
// A retained legacy PDF has no run bundle, so its file version (mtime) is
|
|
72
|
-
// the only stable token that can be resolved back to those bytes.
|
|
73
|
-
const pdfVersion = published?.runId ?? pdf?.version;
|
|
67
|
+
const pdf = availablePdf(config, id, mainFile);
|
|
68
|
+
const publishedRun = pdf ? db.prepare(`SELECT id, finished_at FROM compile_runs
|
|
69
|
+
WHERE id = ? AND project_id = ? AND status = 'succeeded'`).get(pdf.version, id) : undefined;
|
|
74
70
|
const pdfMetadata = pdfResponseMetadata(config, pdf?.path ?? null);
|
|
75
71
|
return {
|
|
76
72
|
mainFile,
|
|
@@ -85,7 +81,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
85
81
|
} : null
|
|
86
82
|
} : null,
|
|
87
83
|
hasPdf: Boolean(pdf),
|
|
88
|
-
pdfUrl: pdf ? compilePdfUrl(config, id, mainFile,
|
|
84
|
+
pdfUrl: pdf ? compilePdfUrl(config, id, mainFile, pdf.version) : null,
|
|
89
85
|
pdfCompiledAt: publishedRun?.finished_at ?? latestSuccess?.finished_at ?? null,
|
|
90
86
|
...pdfMetadata
|
|
91
87
|
};
|
|
@@ -102,7 +98,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
102
98
|
const mainFile = compileMainFile(config, id, project.main_file, query.mainFile);
|
|
103
99
|
if (!mainFile)
|
|
104
100
|
return apiError(reply, 400, "MAIN_DOCUMENT_INVALID");
|
|
105
|
-
const published = publishedCompileArtifacts(config, id, mainFile
|
|
101
|
+
const published = publishedCompileArtifacts(config, id, mainFile);
|
|
106
102
|
if (!query.path) {
|
|
107
103
|
if (!published)
|
|
108
104
|
return { mainFile, runId: null, artifacts: [] };
|
|
@@ -210,7 +206,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
210
206
|
return apiError(reply, 403, "COMPILE_FORBIDDEN");
|
|
211
207
|
const runs = db.prepare(`SELECT id FROM compile_runs
|
|
212
208
|
WHERE project_id = ? AND main_file = ? AND status NOT IN ('queued', 'running')`).all(id, mainFile);
|
|
213
|
-
cleanCompileArtifacts(config, id, mainFile,
|
|
209
|
+
cleanCompileArtifacts(config, id, mainFile, runs.map((run) => run.id));
|
|
214
210
|
db.prepare("DELETE FROM compile_runs WHERE project_id = ? AND main_file = ? AND status NOT IN ('queued', 'running')").run(id, mainFile);
|
|
215
211
|
pruneCompileRuns(id);
|
|
216
212
|
collaboration.signalCompileState(id, {
|
|
@@ -253,7 +249,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
253
249
|
if (!fs.existsSync(resolveSourcePath(config, id, sourcePath))) {
|
|
254
250
|
return apiError(reply, 404, "SOURCE_FILE_NOT_FOUND");
|
|
255
251
|
}
|
|
256
|
-
const artifacts = syncArtifacts(config, id, mainFile
|
|
252
|
+
const artifacts = syncArtifacts(config, id, mainFile);
|
|
257
253
|
if (!artifacts)
|
|
258
254
|
return apiError(reply, 409, "SYNCTEX_NOT_AVAILABLE");
|
|
259
255
|
return await sourceToPdf(artifacts.source, artifacts.pdf, sourcePath, line, column);
|
|
@@ -281,7 +277,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
281
277
|
return apiError(reply, 400, "SYNC_PDF_INVALID");
|
|
282
278
|
}
|
|
283
279
|
return await projectMutations.runConsistentRead(id, async () => {
|
|
284
|
-
const artifacts = syncArtifacts(config, id, mainFile
|
|
280
|
+
const artifacts = syncArtifacts(config, id, mainFile);
|
|
285
281
|
if (!artifacts)
|
|
286
282
|
return apiError(reply, 409, "SYNCTEX_NOT_AVAILABLE");
|
|
287
283
|
const location = await pdfToSource(artifacts.source, artifacts.pdf, page, x, y);
|
|
@@ -393,7 +389,6 @@ export function registerCompileRoutes(app, context) {
|
|
|
393
389
|
// This key is computed before snapshot creation. The content digest
|
|
394
390
|
// returned by captureCompileSnapshot is only the result revision.
|
|
395
391
|
generation: admission.generation,
|
|
396
|
-
revision: admission.generation,
|
|
397
392
|
onQueued: broadcast,
|
|
398
393
|
onSelected: broadcast,
|
|
399
394
|
onDiscarded: () => {
|
|
@@ -419,20 +414,8 @@ export function registerCompileRoutes(app, context) {
|
|
|
419
414
|
// in-memory collaboration revision to skip before a snapshot: it is
|
|
420
415
|
// not a durable content version and can collide after a room restart
|
|
421
416
|
// or reconnect.
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const currentProject = accessibleProject(db, id, user);
|
|
425
|
-
if (!currentProject || !canEdit(currentProject)) {
|
|
426
|
-
throw new Error("Project access changed while waiting for a source snapshot");
|
|
427
|
-
}
|
|
428
|
-
const currentMainFile = compileMainFile(config, id, currentProject.main_file, body.mainFile);
|
|
429
|
-
if (!currentMainFile)
|
|
430
|
-
throw new Error("Selected main document is no longer available");
|
|
431
|
-
if (!requestedMainFile && currentMainFile !== mainFile)
|
|
432
|
-
throw mainDocumentChangedError();
|
|
433
|
-
project = currentProject;
|
|
434
|
-
mainFile = currentMainFile;
|
|
435
|
-
});
|
|
417
|
+
// Flush and revalidate inside the same reservation used for capture.
|
|
418
|
+
// Releasing a separate validation lock first only repeats this work.
|
|
436
419
|
const captured = await projectMutations.runSerialized(id, async () => {
|
|
437
420
|
throwIfCompileCancelled(signal);
|
|
438
421
|
const currentProject = accessibleProject(db, id, user);
|
|
@@ -506,12 +489,12 @@ export function registerCompileRoutes(app, context) {
|
|
|
506
489
|
discardCompileSnapshot(candidate);
|
|
507
490
|
}
|
|
508
491
|
throw new CompileSnapshotBusyError();
|
|
509
|
-
}
|
|
492
|
+
});
|
|
510
493
|
snapshot = captured;
|
|
511
494
|
throwIfCompileCancelled(signal);
|
|
512
495
|
snapshotMs = performance.now() - snapshotStartedAt;
|
|
513
496
|
metrics.record("compile.snapshot", snapshotMs);
|
|
514
|
-
const published = publishedCompileArtifacts(config, id, mainFile
|
|
497
|
+
const published = publishedCompileArtifacts(config, id, mainFile);
|
|
515
498
|
const publishedRun = published ? db.prepare(`SELECT id, status, log, finished_at
|
|
516
499
|
FROM compile_runs WHERE id = ? AND project_id = ?`).get(published.runId, id) : undefined;
|
|
517
500
|
// The current queued row is intentionally excluded. It is a request
|
|
@@ -662,7 +645,7 @@ export function registerCompileRoutes(app, context) {
|
|
|
662
645
|
const timings = result.timings
|
|
663
646
|
? { snapshotMs: result.snapshotMs ?? 0, ...result.timings, requestMs }
|
|
664
647
|
: { snapshotMs: result.snapshotMs ?? 0, requestMs };
|
|
665
|
-
const responsePdf = result.ok ? availablePdf(config, id, mainFile
|
|
648
|
+
const responsePdf = result.ok ? availablePdf(config, id, mainFile) : null;
|
|
666
649
|
const pdfMetadata = pdfResponseMetadata(config, responsePdf?.path ?? null);
|
|
667
650
|
reply.header("Server-Timing", [
|
|
668
651
|
`snapshot;dur=${timingDuration(result.snapshotMs ?? 0)}`,
|
|
@@ -698,25 +681,22 @@ export function registerCompileRoutes(app, context) {
|
|
|
698
681
|
if (!mainFile)
|
|
699
682
|
return apiError(reply, 400, "MAIN_DOCUMENT_INVALID");
|
|
700
683
|
const downloading = query.download === "1";
|
|
701
|
-
let artifact = availablePdf(config, id, mainFile
|
|
684
|
+
let artifact = availablePdf(config, id, mainFile);
|
|
702
685
|
if (!artifact)
|
|
703
686
|
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
704
687
|
let versioned = false;
|
|
705
688
|
if (query.run) {
|
|
706
|
-
if (
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
artifact = compileRunPdf(config, id, mainFile, query.run);
|
|
713
|
-
if (!artifact)
|
|
714
|
-
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
715
|
-
versioned = true;
|
|
716
|
-
}
|
|
717
|
-
else if (artifact.version !== query.run) {
|
|
689
|
+
if (!/^[a-f0-9-]{36}$/i.test(query.run))
|
|
690
|
+
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
691
|
+
const run = db.prepare(`SELECT main_file, status FROM compile_runs
|
|
692
|
+
WHERE id = ? AND project_id = ?`).get(query.run, id);
|
|
693
|
+
if (!run || run.status !== "succeeded" || run.main_file !== mainFile) {
|
|
718
694
|
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
719
695
|
}
|
|
696
|
+
artifact = compileRunPdf(config, id, mainFile, query.run);
|
|
697
|
+
if (!artifact)
|
|
698
|
+
return apiError(reply, 404, "PDF_NOT_FOUND");
|
|
699
|
+
versioned = true;
|
|
720
700
|
}
|
|
721
701
|
const pdf = artifact.path;
|
|
722
702
|
const stat = regularFileStat(pdf);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { isUtf8 } from "node:buffer";
|
|
3
2
|
import { requireUser } from "../auth.js";
|
|
4
3
|
import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
|
|
5
4
|
import { hashText } from "../editHistory.js";
|
|
@@ -7,7 +6,7 @@ import { HISTORY_RETENTION_DELAY_MS } from "../historyRetention.js";
|
|
|
7
6
|
import { resolveSourcePath, safeRelativePath } from "../files.js";
|
|
8
7
|
import { apiError, httpError } from "../http.js";
|
|
9
8
|
import { MAX_TEXT_PREVIEW_BYTES } from "../limits.js";
|
|
10
|
-
import {
|
|
9
|
+
import { defaultHistoryTracking, historyTextCandidate } from "../../shared/historyTracking.js";
|
|
11
10
|
import { accessibleProject, canEdit } from "../projects.js";
|
|
12
11
|
import { commentsSummaryForProject, projectJson, projectTextSnapshot, reanchorProjectSnapshot, requireEditableProject, requireProjectOwnerPermission, tagsForProject, text, touchProject } from "./projectShared.js";
|
|
13
12
|
/** Register retained project version listing, inspection, restoration, and cleanup routes. */
|
|
@@ -148,13 +147,21 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
148
147
|
const manifest = history.manifest(id, versionId);
|
|
149
148
|
if (!version || !manifest)
|
|
150
149
|
return apiError(reply, 404, "HISTORY_VERSION_NOT_FOUND");
|
|
150
|
+
const changedPaths = new Set(version.changedPaths);
|
|
151
|
+
const deletedPaths = version.changedPaths.filter((filePath) => !manifest.files[filePath]);
|
|
152
|
+
const previous = deletedPaths.length > 0 ? history.previousVersion(id, versionId) : null;
|
|
153
|
+
const previousManifest = previous ? history.manifest(id, previous.id) : null;
|
|
151
154
|
return {
|
|
152
155
|
version,
|
|
153
156
|
scoped: Boolean(manifest.tracking),
|
|
154
157
|
settings: manifest.settings,
|
|
155
158
|
files: [
|
|
156
|
-
...Object.entries(manifest.files).map(([filePath, file]) => ({
|
|
157
|
-
|
|
159
|
+
...Object.entries(manifest.files).map(([filePath, file]) => ({
|
|
160
|
+
path: filePath, size: file.size,
|
|
161
|
+
...(changedPaths.has(filePath) ? { textContent: history.isTextFile(id, filePath, file) } : {})
|
|
162
|
+
})),
|
|
163
|
+
...deletedPaths.map((filePath) => ({ path: filePath, size: 0, deleted: true,
|
|
164
|
+
textContent: history.isTextFile(id, filePath, previousManifest?.files[filePath]) }))
|
|
158
165
|
].sort((left, right) => left.path.localeCompare(right.path))
|
|
159
166
|
};
|
|
160
167
|
});
|
|
@@ -175,7 +182,7 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
175
182
|
if (!manifest.files[filePath] && !version.changedPaths.includes(filePath))
|
|
176
183
|
return apiError(reply, 404, "HISTORY_FILE_NOT_FOUND");
|
|
177
184
|
// Never decode attachment bytes as UTF-8, including direct API calls.
|
|
178
|
-
if (!
|
|
185
|
+
if (!historyTextCandidate(filePath))
|
|
179
186
|
return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
|
|
180
187
|
const historical = manifest.files[filePath] ? history.readTextFile(id, versionId, filePath) : "";
|
|
181
188
|
if (historical === null)
|
|
@@ -200,7 +207,7 @@ export function registerProjectHistoryRoutes(app, context) {
|
|
|
200
207
|
if (fs.statSync(current).size > MAX_TEXT_PREVIEW_BYTES)
|
|
201
208
|
return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
|
|
202
209
|
const bytes = fs.readFileSync(current);
|
|
203
|
-
if (
|
|
210
|
+
if (!defaultHistoryTracking(filePath, bytes))
|
|
204
211
|
return apiError(reply, 415, "HISTORY_FILE_PREVIEW_UNSUPPORTED", { path: filePath });
|
|
205
212
|
comparison = bytes.toString("utf8");
|
|
206
213
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { reanchorFileComments, offsetToLine } from "../anchors.js";
|
|
3
4
|
import { isCollaborativeTextFile, maxCollaborativeFileBytes } from "../collaboration.js";
|
|
4
5
|
import { listProjectFiles, resolveSourcePath } from "../files.js";
|
|
@@ -217,13 +218,16 @@ function commentsForScope(db, config, projectId, filePath) {
|
|
|
217
218
|
WHERE c.project_id = ?${fileClause} ORDER BY ${commentOrder}`)
|
|
218
219
|
.all(projectId, ...(hasFileScope ? [filePath] : []));
|
|
219
220
|
const sourceByPath = new Map();
|
|
221
|
+
const hashByPath = new Map();
|
|
220
222
|
if (!rows.length)
|
|
221
223
|
return { comments: [], sourceByPath };
|
|
222
224
|
for (const row of rows) {
|
|
223
225
|
if (sourceByPath.has(row.file_path))
|
|
224
226
|
continue;
|
|
225
227
|
const absolute = resolveSourcePath(config, projectId, row.file_path);
|
|
226
|
-
|
|
228
|
+
const source = fs.existsSync(absolute) ? fs.readFileSync(absolute, "utf8") : "";
|
|
229
|
+
sourceByPath.set(row.file_path, source);
|
|
230
|
+
hashByPath.set(row.file_path, createHash("sha256").update(source, "utf8").digest("hex"));
|
|
227
231
|
}
|
|
228
232
|
const replies = db.prepare(`SELECT reply.*, user.username AS author_username, user.display_name AS author_display_name, user.avatar_style AS author_avatar_style
|
|
229
233
|
FROM comment_replies reply
|
|
@@ -258,6 +262,7 @@ function commentsForScope(db, config, projectId, filePath) {
|
|
|
258
262
|
selectedText: comment.selected_text,
|
|
259
263
|
contextBefore: comment.context_before,
|
|
260
264
|
contextAfter: comment.context_after,
|
|
265
|
+
anchorSourceHash: hashByPath.get(comment.file_path),
|
|
261
266
|
startOffset: comment.start_offset,
|
|
262
267
|
endOffset: comment.end_offset,
|
|
263
268
|
startLine: offsetToLine(sourceByPath.get(comment.file_path) ?? "", comment.start_offset),
|
|
@@ -12,7 +12,6 @@ import { writeProjectArchive } from "../archive.js";
|
|
|
12
12
|
import { extractProjectZip, ZipValidationError } from "../zip.js";
|
|
13
13
|
import { HarperLintSupersededError, HarperUnavailableError } from "../harper.js";
|
|
14
14
|
import { ChktexLintSupersededError, ChktexUnavailableError } from "../chktex.js";
|
|
15
|
-
import { digestToken } from "../security.js";
|
|
16
15
|
import { supportsChktexChecks, supportsWritingChecks } from "../../shared/writingChecks.js";
|
|
17
16
|
import { unreadMentionCountsForProjects } from "../commentMentions.js";
|
|
18
17
|
import { commentsSummaryForProject, commentsSummaryForProjects, dictionaryWord, escapeLikePattern, now, projectJson, requireProjectOwnerPermission, tagColors, tagsForProject, tagsForProjects, text } from "./projectShared.js";
|
|
@@ -380,13 +379,10 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
380
379
|
if (typeof source !== "string" || typeof sourcePath !== "string") {
|
|
381
380
|
return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
|
|
382
381
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
|
|
388
|
-
}
|
|
389
|
-
if (sequence !== undefined && (typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0 || clientId === undefined)) {
|
|
382
|
+
if (clientId === undefined || sequence === undefined)
|
|
383
|
+
return apiError(reply, 409, "CLIENT_UPDATE_REQUIRED");
|
|
384
|
+
if (typeof clientId !== "string" || !clientIdPattern.test(clientId)
|
|
385
|
+
|| typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0) {
|
|
390
386
|
return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
|
|
391
387
|
}
|
|
392
388
|
if (Buffer.byteLength(source, "utf8") > maxCollaborativeFileBytes(config)) {
|
|
@@ -400,17 +396,14 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
400
396
|
return apiError(reply, 400, "SPELLCHECK_SOURCE_INVALID");
|
|
401
397
|
}
|
|
402
398
|
// Bibliography files are structured reference data rather than prose.
|
|
403
|
-
// Keep this server-side guard for legacy clients and direct API callers.
|
|
404
399
|
if (!supportsWritingChecks(filePath))
|
|
405
400
|
return { lints: [] };
|
|
406
401
|
// A login session is shared by browser tabs. Pair the authenticated user
|
|
407
402
|
// with the page-local client ID so each new editor can replace only its
|
|
408
|
-
// own obsolete waiting work.
|
|
409
|
-
|
|
410
|
-
const laneClientId = clientId ?? `legacy:${digestToken(request.cookies.texlite_session ?? "")}`;
|
|
411
|
-
const lane = `${id}\0${user.id}\0${laneClientId}\0${filePath}`;
|
|
403
|
+
// own obsolete waiting work.
|
|
404
|
+
const lane = `${id}\0${user.id}\0${clientId}\0${filePath}`;
|
|
412
405
|
try {
|
|
413
|
-
return { lints: await harper.lint(source, filePath, lane,
|
|
406
|
+
return { lints: await harper.lint(source, filePath, lane, sequence) };
|
|
414
407
|
}
|
|
415
408
|
catch (error) {
|
|
416
409
|
if (error instanceof HarperLintSupersededError) {
|
|
@@ -433,8 +426,6 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
433
426
|
const project = accessibleProject(db, id, user);
|
|
434
427
|
if (!project)
|
|
435
428
|
return apiError(reply, 404, "PROJECT_NOT_FOUND");
|
|
436
|
-
if (!project.chktex_enabled)
|
|
437
|
-
return { issues: [] };
|
|
438
429
|
const body = request.body;
|
|
439
430
|
const source = body?.source;
|
|
440
431
|
const sourcePath = body?.path;
|
|
@@ -442,12 +433,14 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
442
433
|
const sequence = body?.sequence;
|
|
443
434
|
if (typeof source !== "string" || typeof sourcePath !== "string")
|
|
444
435
|
return apiError(reply, 400, "CHK_TEX_SOURCE_INVALID");
|
|
445
|
-
if (clientId
|
|
446
|
-
return apiError(reply,
|
|
447
|
-
|
|
448
|
-
|
|
436
|
+
if (clientId === undefined || sequence === undefined)
|
|
437
|
+
return apiError(reply, 409, "CLIENT_UPDATE_REQUIRED");
|
|
438
|
+
if (typeof clientId !== "string" || !clientIdPattern.test(clientId)
|
|
439
|
+
|| typeof sequence !== "number" || !Number.isSafeInteger(sequence) || sequence <= 0) {
|
|
449
440
|
return apiError(reply, 400, "CHK_TEX_SOURCE_INVALID");
|
|
450
441
|
}
|
|
442
|
+
if (!project.chktex_enabled)
|
|
443
|
+
return { issues: [] };
|
|
451
444
|
if (Buffer.byteLength(source, "utf8") > maxCollaborativeFileBytes(config)) {
|
|
452
445
|
return apiError(reply, 413, "CHK_TEX_SOURCE_TOO_LARGE");
|
|
453
446
|
}
|
|
@@ -460,10 +453,9 @@ export function registerProjectCatalogRoutes(app, context) {
|
|
|
460
453
|
}
|
|
461
454
|
if (!supportsChktexChecks(filePath))
|
|
462
455
|
return { issues: [] };
|
|
463
|
-
const
|
|
464
|
-
const lane = `${id}\0${user.id}\0${laneClientId}\0${filePath}`;
|
|
456
|
+
const lane = `${id}\0${user.id}\0${clientId}\0${filePath}`;
|
|
465
457
|
try {
|
|
466
|
-
return { issues: await chktex.lint(source, filePath, lane,
|
|
458
|
+
return { issues: await chktex.lint(source, filePath, lane, sequence) };
|
|
467
459
|
}
|
|
468
460
|
catch (error) {
|
|
469
461
|
if (error instanceof ChktexLintSupersededError)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** Stable translated errors shared by HTTP responses and terminal messages. */
|
|
2
|
+
export const agentMessages = {
|
|
3
|
+
en: {
|
|
4
|
+
AGENT_DISABLED: "This tool is disabled or project write access is unavailable.",
|
|
5
|
+
AGENT_UNAVAILABLE: "This agent is not installed or cannot run on the server.",
|
|
6
|
+
AGENT_PTY_UNAVAILABLE: "Terminal support is unavailable. Install the optional node-pty dependency on the server and restart TexLite.",
|
|
7
|
+
AGENT_SESSION_NOT_FOUND: "This agent task does not exist or belongs to another user.",
|
|
8
|
+
AGENT_SESSION_BUSY: "Wait for the current task operation to finish.",
|
|
9
|
+
AGENT_PROJECT_BUSY: "Another agent task is active in this project. It must end before another can start; hiding the terminal does not stop it.",
|
|
10
|
+
AGENT_SYNC_FAILED: "External file synchronization failed. The agent has been stopped; check the project files and server logs.",
|
|
11
|
+
AGENT_SYNC_CONFLICT: "Concurrent edits conflicted. The editor version was preserved and agent files were saved under .texlite-agent-conflicts in this project. The agent has been stopped.",
|
|
12
|
+
AGENT_NO_CONTEXT: "This task's saved conversation cannot be resumed. Create a new task with + to start a new conversation.",
|
|
13
|
+
AGENT_CONTEXT_CHECK_FAILED: "The task's saved conversation could not be verified. Retry, or check the agent's installation and task data. No new conversation was started.",
|
|
14
|
+
AGENT_START_FAILED: "The agent could not start. Check its installation and server logs.",
|
|
15
|
+
AGENT_STOP_FAILED: "The agent has not stopped. Retry ending execution before cleaning its files.",
|
|
16
|
+
AGENT_RECOVERY_FAILED: "A previous execution could not be safely recovered. Its project remains reserved. Retry ending the task; if needed, stop its processes on the host first.",
|
|
17
|
+
AGENT_CLEANUP_FAILED: "Task cleanup did not finish. Its record has been kept for retry."
|
|
18
|
+
},
|
|
19
|
+
zh: {
|
|
20
|
+
AGENT_DISABLED: "此外部工具未启用,或你已没有项目写入权限。",
|
|
21
|
+
AGENT_UNAVAILABLE: "服务器未安装此 agent,或该命令无法运行。",
|
|
22
|
+
AGENT_PTY_UNAVAILABLE: "终端支持不可用。请在服务器安装可选依赖 node-pty 后重启 TexLite。",
|
|
23
|
+
AGENT_SESSION_NOT_FOUND: "此 agent 任务不存在,或属于其他用户。",
|
|
24
|
+
AGENT_SESSION_BUSY: "请等待当前任务操作完成。",
|
|
25
|
+
AGENT_PROJECT_BUSY: "本项目已有 Agent 任务在运行,需先结束该任务才能启动其他任务;收起终端不会停止任务。",
|
|
26
|
+
AGENT_SYNC_FAILED: "外部文件同步失败,Agent 已停止。请检查项目文件和服务器日志。",
|
|
27
|
+
AGENT_SYNC_CONFLICT: "并发修改存在冲突。已保留编辑器版本,Agent 的文件已保存在本项目的 .texlite-agent-conflicts 目录中,Agent 已停止。",
|
|
28
|
+
AGENT_NO_CONTEXT: "无法恢复此任务的对话。请通过+新建任务以开始新对话。",
|
|
29
|
+
AGENT_CONTEXT_CHECK_FAILED: "无法确认此任务的对话状态。请重试,或检查 Agent 安装及任务数据;尚未创建新对话。",
|
|
30
|
+
AGENT_START_FAILED: "无法启动 agent。请检查命令安装情况及服务器日志。",
|
|
31
|
+
AGENT_STOP_FAILED: "Agent 尚未停止。请重试结束运行,再清理其文件。",
|
|
32
|
+
AGENT_RECOVERY_FAILED: "无法安全回收上一次执行,项目执行权仍被保留。请重试结束任务;必要时先在宿主机停止其进程。",
|
|
33
|
+
AGENT_CLEANUP_FAILED: "任务清理未完成。已保留记录,可重试清理。"
|
|
34
|
+
},
|
|
35
|
+
"zh-Hant": {
|
|
36
|
+
AGENT_DISABLED: "此外部工具尚未啟用,或你已沒有專案寫入權限。",
|
|
37
|
+
AGENT_UNAVAILABLE: "伺服器未安裝此 agent,或該命令無法執行。",
|
|
38
|
+
AGENT_PTY_UNAVAILABLE: "終端機支援無法使用。請在伺服器安裝選用相依套件 node-pty 後重新啟動 TexLite。",
|
|
39
|
+
AGENT_SESSION_NOT_FOUND: "此 agent 任務不存在,或屬於其他使用者。",
|
|
40
|
+
AGENT_SESSION_BUSY: "請等待目前任務操作完成。",
|
|
41
|
+
AGENT_PROJECT_BUSY: "此專案已有 Agent 任務正在執行,須先結束該任務才能啟動其他任務;收起終端機不會停止任務。",
|
|
42
|
+
AGENT_SYNC_FAILED: "外部檔案同步失敗,Agent 已停止。請檢查專案檔案與伺服器日誌。",
|
|
43
|
+
AGENT_SYNC_CONFLICT: "並行修改發生衝突。已保留編輯器版本,Agent 的檔案已儲存於此專案的 .texlite-agent-conflicts 目錄中,Agent 已停止。",
|
|
44
|
+
AGENT_NO_CONTEXT: "無法恢復此任務的對話。請透過+新增任務以開始新對話。",
|
|
45
|
+
AGENT_CONTEXT_CHECK_FAILED: "無法確認此任務的對話狀態。請重試,或檢查 Agent 安裝及任務資料;尚未建立新對話。",
|
|
46
|
+
AGENT_START_FAILED: "無法啟動 agent。請檢查命令安裝情況及伺服器日誌。",
|
|
47
|
+
AGENT_STOP_FAILED: "Agent 尚未停止。請重試結束執行,再清理其檔案。",
|
|
48
|
+
AGENT_RECOVERY_FAILED: "無法安全回收上一次執行,專案執行權仍被保留。請重試結束任務;必要時先在主機停止其處理程序。",
|
|
49
|
+
AGENT_CLEANUP_FAILED: "任務清理未完成。已保留記錄,可重試清理。"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Stable identities, rather than executable strings supplied by the browser. */
|
|
2
|
+
export const AGENT_IDS = ["codex", "opencode", "claude"];
|
|
3
|
+
export const AGENT_LABELS = { codex: "Codex", opencode: "OpenCode", claude: "Claude Code" };
|
|
4
|
+
export const AGENT_TASK_PAGE_SIZE = 50;
|
|
5
|
+
export const isAgentId = (value) => AGENT_IDS.includes(value);
|
|
6
|
+
const MAX_INPUT_CHARS = 64 * 1024;
|
|
7
|
+
/** Split large pastes into transport frames without splitting UTF-16 pairs. */
|
|
8
|
+
export function agentInputChunks(input) {
|
|
9
|
+
const chunks = [];
|
|
10
|
+
for (let start = 0; start < input.length;) {
|
|
11
|
+
let end = Math.min(input.length, start + MAX_INPUT_CHARS);
|
|
12
|
+
const last = input.charCodeAt(end - 1);
|
|
13
|
+
if (end < input.length && last >= 0xd800 && last <= 0xdbff)
|
|
14
|
+
end--;
|
|
15
|
+
chunks.push(input.slice(start, end));
|
|
16
|
+
start = end;
|
|
17
|
+
}
|
|
18
|
+
return chunks;
|
|
19
|
+
}
|
|
20
|
+
/** Keep terminal input and resize validation independent of the transport. */
|
|
21
|
+
export function parseAgentClientMessage(raw) {
|
|
22
|
+
let value;
|
|
23
|
+
try {
|
|
24
|
+
value = JSON.parse(raw);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (!value || typeof value !== "object" || !("type" in value))
|
|
30
|
+
return null;
|
|
31
|
+
const message = value;
|
|
32
|
+
if (message.type === "takeControl")
|
|
33
|
+
return { type: "takeControl" };
|
|
34
|
+
if (message.type === "input" && typeof message.data === "string" && message.data.length <= MAX_INPUT_CHARS)
|
|
35
|
+
return { type: "input", data: message.data };
|
|
36
|
+
if (message.type === "resize" && Number.isInteger(message.cols) && Number.isInteger(message.rows)
|
|
37
|
+
&& Number(message.cols) >= 2 && Number(message.cols) <= 500 && Number(message.rows) >= 2 && Number(message.rows) <= 300) {
|
|
38
|
+
return { type: "resize", cols: Number(message.cols), rows: Number(message.rows) };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
export function isHistoryTextFile(filePath) {
|
|
3
3
|
const name = filePath.split("/").at(-1) ?? "";
|
|
4
4
|
return /\.(?:tex|bib|bst|sty|cls|txt|md|rst|dat|csv|tsv|json|ya?ml|toml|xml|html?|css|[cm]?js|tsx?|py|sh|r|log|bbl|aux|idx|ind|gls)$/i.test(name)
|
|
5
|
-
|| /^(?:\.?latexmkrc|readme|licen[cs]e|makefile)$/i.test(name);
|
|
5
|
+
|| /^(?:\.?latexmkrc|readme|licen[cs]e|makefile|\.git(?:ignore|attributes|modules))$/i.test(name);
|
|
6
6
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const supportedLocales = ["en", "zh", "zh-Hant"];
|
|
2
|
+
/** Preserve the existing `zh` preference while distinguishing Chinese scripts. */
|
|
3
|
+
export function supportedLocale(language) {
|
|
4
|
+
const parts = language?.trim().toLowerCase().replaceAll("_", "-").split("-") ?? [];
|
|
5
|
+
if (parts[0] === "en")
|
|
6
|
+
return "en";
|
|
7
|
+
if (parts[0] !== "zh")
|
|
8
|
+
return null;
|
|
9
|
+
if (parts.includes("hant"))
|
|
10
|
+
return "zh-Hant";
|
|
11
|
+
if (parts.includes("hans"))
|
|
12
|
+
return "zh";
|
|
13
|
+
return parts.some((part) => part === "tw" || part === "hk" || part === "mo") ? "zh-Hant" : "zh";
|
|
14
|
+
}
|
|
15
|
+
export function appLocale(language) {
|
|
16
|
+
return supportedLocale(language) ?? "en";
|
|
17
|
+
}
|
|
18
|
+
export function documentLocale(language) {
|
|
19
|
+
const locale = appLocale(language);
|
|
20
|
+
return locale === "zh" ? "zh-CN" : locale;
|
|
21
|
+
}
|