@oversk7/pi-web-dsh-style 1.3.0 → 1.3.2
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/package.json +1 -1
- package/server.ts +10 -1
- package/web/app.js +16 -5
- package/web/assets/markdown.js +15 -15
- package/web/markdown.ts +20 -5
package/package.json
CHANGED
package/server.ts
CHANGED
|
@@ -2337,7 +2337,16 @@ async function handleApi(req: import("node:http").IncomingMessage, res: ServerRe
|
|
|
2337
2337
|
const input = url.searchParams.get("path")?.trim();
|
|
2338
2338
|
if (!input) return sendJson(res, 400, { error: "path is required" });
|
|
2339
2339
|
try {
|
|
2340
|
-
const
|
|
2340
|
+
const sessionId = url.searchParams.get("sessionId");
|
|
2341
|
+
const workspaceId = url.searchParams.get("workspaceId");
|
|
2342
|
+
const session = sessionId ? sessions.get(sessionId) : undefined;
|
|
2343
|
+
const workspace = workspaceId ? state.workspaces.find((item) => item.id === workspaceId) : undefined;
|
|
2344
|
+
if (sessionId && !session) return sendJson(res, 404, { error: "session not found" });
|
|
2345
|
+
if (workspaceId && !workspace) return sendJson(res, 404, { error: "workspace not found" });
|
|
2346
|
+
const activeSession = !sessionId && !workspaceId && state.currentSessionId ? sessions.get(state.currentSessionId) : undefined;
|
|
2347
|
+
const activeWorkspace = !sessionId && !workspaceId
|
|
2348
|
+
? state.workspaces.find((item) => item.id === (activeSession?.workspaceId ?? state.currentWorkspaceId)) : undefined;
|
|
2349
|
+
const target = normalizePath(resolve(session?.cwd ?? workspace?.path ?? activeWorkspace?.path ?? activeSession?.cwd ?? process.cwd(), input));
|
|
2341
2350
|
const info = await stat(target);
|
|
2342
2351
|
if (!info.isFile()) return sendJson(res, 400, { error: "path is not a file" });
|
|
2343
2352
|
const image = url.searchParams.get("format") === "image";
|
package/web/app.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { markdown } from "./assets/markdown.js";
|
|
3
|
+
import { markdown as renderMarkdown } from "./assets/markdown.js";
|
|
4
4
|
import { webSlashCommands, unsupportedSlashCommands, parseSlashCommand } from "./slash-commands.js";
|
|
5
5
|
import { getLanguage, setLanguage, t, translateUi, observeUi } from "./i18n.js";
|
|
6
6
|
|
|
@@ -274,6 +274,14 @@ function snapshotFor(id) {
|
|
|
274
274
|
return S.snapshots.get(id) || { session: null, state: null, stats: null, models: [], thinkingLevels: [], thinkingLevelsByModel: {}, commands: [], extensionStatuses: {}, messages: [], pendingQueue: { steering: [], followUp: [] }, dialogs: [] };
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
+
function markdown(text) {
|
|
278
|
+
const session = S.currentSessionId ? S.snapshots.get(S.currentSessionId)?.session : null;
|
|
279
|
+
const workspace = S.currentSessionId
|
|
280
|
+
? S.workspaces.find((item) => item.sessions?.some((entry) => entry.id === S.currentSessionId))
|
|
281
|
+
: S.workspaces.find((item) => item.id === S.currentWorkspaceId);
|
|
282
|
+
return renderMarkdown(text, { cwd: session?.cwd || workspace?.path });
|
|
283
|
+
}
|
|
284
|
+
|
|
277
285
|
function currentWorkspace() {
|
|
278
286
|
return S.workspaces.find((w) => w.id === S.currentWorkspaceId) || S.workspaces[0] || null;
|
|
279
287
|
}
|
|
@@ -586,7 +594,8 @@ async function openFilePreview(path, line, href, trigger = document.activeElemen
|
|
|
586
594
|
}
|
|
587
595
|
const requestedLine = Number(line);
|
|
588
596
|
const normalizedLine = Number.isFinite(requestedLine) && requestedLine > 0 ? Math.max(1, requestedLine) : null;
|
|
589
|
-
|
|
597
|
+
const previewContext = S.currentSessionId || S.currentWorkspaceId || "";
|
|
598
|
+
if ((S.filePreview?.requestedPath || S.filePreview?.path) === path && S.filePreview?.context === previewContext && !S.filePreview.error) {
|
|
590
599
|
S.filePreview = { ...S.filePreview, line: normalizedLine, href };
|
|
591
600
|
applyFrameLayout();
|
|
592
601
|
renderFilePreview();
|
|
@@ -596,15 +605,17 @@ async function openFilePreview(path, line, href, trigger = document.activeElemen
|
|
|
596
605
|
}
|
|
597
606
|
|
|
598
607
|
const generation = ++S.filePreviewGeneration;
|
|
599
|
-
S.filePreview = { path, line: normalizedLine, href, name: fileNameFromPath(path), loading: true };
|
|
608
|
+
S.filePreview = { path, requestedPath: path, context: previewContext, line: normalizedLine, href, name: fileNameFromPath(path), loading: true };
|
|
600
609
|
applyFrameLayout();
|
|
601
610
|
renderFilePreview();
|
|
602
611
|
if (mobile) $(".pI_x6G_detailsCol")?.focus({ preventScroll: true });
|
|
603
612
|
try {
|
|
604
|
-
const
|
|
613
|
+
const context = S.currentSessionId ? `&sessionId=${encodeURIComponent(S.currentSessionId)}`
|
|
614
|
+
: S.currentWorkspaceId ? `&workspaceId=${encodeURIComponent(S.currentWorkspaceId)}` : "";
|
|
615
|
+
const data = await api(`/api/fs/view?path=${encodeURIComponent(path)}&format=json${context}`);
|
|
605
616
|
if (generation !== S.filePreviewGeneration) return;
|
|
606
617
|
const activeLine = S.filePreview?.path === path ? S.filePreview.line : normalizedLine;
|
|
607
|
-
S.filePreview = { ...data, path, line: activeLine, href, loading: false, error: null };
|
|
618
|
+
S.filePreview = { ...data, path: data.path || path, requestedPath: path, context: previewContext, line: activeLine, href, loading: false, error: null };
|
|
608
619
|
} catch (error) {
|
|
609
620
|
if (generation !== S.filePreviewGeneration) return;
|
|
610
621
|
S.filePreview = { ...S.filePreview, loading: false, error: error.message || String(error) };
|