@pi-chamber/web 1.0.6-rc.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{DiagramView--XO16VPB.js → DiagramView-DsCdfDOP.js} +1 -1
- package/dist/assets/{DiffView-Duy2_7Gp.js → DiffView-BWo7yT-P.js} +6 -6
- package/dist/assets/{FileSaveConflictDialog-B1DvL9zy.js → FileSaveConflictDialog-IFbuQCcP.js} +1 -1
- package/dist/assets/{FilesView-CjjPpE4c.js → FilesView-DLIQkVep.js} +4 -4
- package/dist/assets/{GitHubDetailScaffold-DqxAKqCT.js → GitHubDetailScaffold-CxGg6x7R.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-ELF_chia.js → GitHubLinkPicker-BmqbTUpE.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-C2nGTntk.js → GitHubListPrimitives-a1DxU6Zp.js} +1 -1
- package/dist/assets/{GitView-5fIq2nzM.js → GitView-DbqM8Qi1.js} +5 -5
- package/dist/assets/{IssuesSurface-Dq5A_bWq.js → IssuesSurface-B2EfICtZ.js} +3 -3
- package/dist/assets/{JsonTreeView-BjFFSUwi.js → JsonTreeView-DzVqgwz-.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-B9Cu4TCh.js → MarkdownRendererImpl-7yTzCIEI.js} +3 -3
- package/dist/assets/PatchDiff-Dvfm6eOV.js +1 -0
- package/dist/assets/{PierreDiffViewer-H2f4pJ1k.js → PierreDiffViewer-ByYaUifK.js} +2 -2
- package/dist/assets/{PullRequestsSurface-DPpb2RW_.js → PullRequestsSurface-1IP_dDn8.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-B5DaBWZU.js → SessionSwitcherContent-DVxWhG4x.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-D86FaZg_.js → SessionSwitcherDropdown-DiBGmmtD.js} +2 -2
- package/dist/assets/{SessionUnreadDot-CY9-1iV2.js → SessionUnreadDot-qw67HcBO.js} +1 -1
- package/dist/assets/SettingsView-CMTIIpWD.js +6 -0
- package/dist/assets/{SettingsWindow-Bw1dUoJ1.js → SettingsWindow-DZUSs5Is.js} +1 -1
- package/dist/assets/{ToolOutputDialog-aR4kcgKL.js → ToolOutputDialog-pgTNzNPN.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-B_wWmhtE.js → ToolPartDiffPreview-Cvnr4JkU.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-BYby097w.js → VirtualizedFileDiff-D8dSHI_H.js} +3 -3
- package/dist/assets/{collapsible-Dz0bPrJ_.js → collapsible-ZT74WYMA.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-8MuwxSC6.js → computeVirtualFileMetrics-g1aOl5nF.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-fZ2NIQMQ.js → contextFileOpenGuard-IWdho_6z.js} +1 -1
- package/dist/assets/{fileTreeStatus-BzhMMLA9.js → fileTreeStatus-trDHgX4B.js} +2 -2
- package/dist/assets/{gitStatusPredicates-Cyh9UhYX.js → gitStatusPredicates-CfBh9Rne.js} +1 -1
- package/dist/assets/{githubLink-D2PznPcI.js → githubLink-CuQ2WFBa.js} +1 -1
- package/dist/assets/index-BaLCg7tL.css +1 -0
- package/dist/assets/{index-BX5pAOQX.js → index-CK9t5Znh.js} +1 -1
- package/dist/assets/{index-Cs2nBW_t.js → index-fmzQmSSv.js} +3 -3
- package/dist/assets/{main-BI6qe8pz.js → main-DOlk_lfi.js} +2 -2
- package/dist/assets/{main-7vBNPBMb.js → main-UnRe9F68.js} +4 -4
- package/dist/assets/{markdownCore-D5jiabKe.js → markdownCore-DuZmdypZ.js} +2 -2
- package/dist/assets/{miniChat-B3up4Bnz.js → miniChat-Dy9h0B6G.js} +2 -2
- package/dist/assets/{mobile-B4vLFgBc.js → mobile-CWrtn0Si.js} +2 -2
- package/dist/assets/{nativeFileSave-DpBH1Sa3.js → nativeFileSave-B4Rg6n8u.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-BrB72skF.js → pi-session-focus-preference-q-s-Bhf0.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-B6T04JGG.js → renderDiffWithHighlighter-HRnE6vfE.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-CX10w321.js → renderElectronMiniChatApp-OZ2fG5eY.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-DtAcGyJr.js → renderFileWithHighlighter-tJRUQWjE.js} +1 -1
- package/dist/assets/{renderMobileApp-C9n-BhPZ.js → renderMobileApp-D1nkBJLP.js} +3 -3
- package/dist/assets/runtimeEndpointReset-Bby2E_Je.js +62 -0
- package/dist/assets/{runtimeSurface-DiP2a57a.js → runtimeSurface-X62LLBLv.js} +1 -1
- package/dist/assets/{useAppFontEffects-Oyin3dgQ.js → useAppFontEffects-BFgKpDYT.js} +86 -86
- package/dist/assets/{useGitHubRemoteSearch-CZ9Hauw0.js → useGitHubRemoteSearch-MxC4J-VO.js} +1 -1
- package/dist/assets/{useSwitcherItems-BSqDA1IF.js → useSwitcherItems-D5TsQEbM.js} +1 -1
- package/dist/assets/{web-components-CkTNGkJ2.js → web-components-B_NMC-2c.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/server/lib/pi/routes.js +5 -1
- package/server/lib/pi/routes.test.js +3 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +1 -1
- package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +60 -1
- package/server/lib/pi/session-daemon/session-daemon.js +34 -10
- package/server/lib/pi/session-daemon/session-engine-router.js +5 -1
- package/server/lib/pi/session-daemon/session-engine-router.test.js +21 -0
- package/dist/assets/PatchDiff-CTqTTcg7.js +0 -1
- package/dist/assets/SettingsView-CiIuOi_E.js +0 -6
- package/dist/assets/index-tmO0fZa4.css +0 -1
- package/dist/assets/runtimeEndpointReset-aGyXPXPs.js +0 -62
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import { mkdir, mkdtemp } from 'node:fs/promises';
|
|
2
|
+
import { mkdir, mkdtemp, stat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createConnection } from 'node:net';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
@@ -227,6 +227,65 @@ describe('session daemon list live status', () => {
|
|
|
227
227
|
expect(Object.keys(live).sort()).toEqual(['lifecycle', 'retry', 'runStartedAt', 'sequence', 'serverNow']);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
it("lists a removed folder's sessions from the session store, and rejects a path that is not a folder", async () => {
|
|
231
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
232
|
+
await mkdir(join(root, 'agent'), { recursive: true });
|
|
233
|
+
const removed = join(root, 'removed-worktree');
|
|
234
|
+
const listedDirectories = [];
|
|
235
|
+
const { daemon, endpoint } = await startDaemon(root, new FakeSession('unused'), async ({ cwd }) => {
|
|
236
|
+
listedDirectories.push(cwd);
|
|
237
|
+
return cwd === removed ? [{ ...diskRow(removed, 'orphan'), cwd: removed }] : [];
|
|
238
|
+
});
|
|
239
|
+
daemons.push(daemon);
|
|
240
|
+
const client = connectClient(endpoint);
|
|
241
|
+
sockets.push(client);
|
|
242
|
+
await client.authenticate();
|
|
243
|
+
|
|
244
|
+
const listed = await client.request('sessions.list', { directory: removed });
|
|
245
|
+
expect(listed.error).toBeUndefined();
|
|
246
|
+
expect(listed.result.sessions.map((item) => item.session.id)).toEqual(['orphan']);
|
|
247
|
+
expect(listedDirectories).toContain(removed);
|
|
248
|
+
|
|
249
|
+
// A failed request closes the connection with an error frame, so each case gets its own client.
|
|
250
|
+
const rejects = async (directory) => {
|
|
251
|
+
const other = connectClient(endpoint);
|
|
252
|
+
sockets.push(other);
|
|
253
|
+
await other.authenticate();
|
|
254
|
+
other.socket.write(`${JSON.stringify({ protocolVersion: 1, kind: 'request', requestId: 'bad', command: 'sessions.list', payload: { directory } })}\n`);
|
|
255
|
+
return (await other.next((message) => message.kind === 'error')).error.code;
|
|
256
|
+
};
|
|
257
|
+
const file = join(root, 'not-a-folder.txt');
|
|
258
|
+
await writeFile(file, 'x');
|
|
259
|
+
expect(await rejects(file)).toBe('INVALID_ARGUMENT');
|
|
260
|
+
expect(await rejects('relative/folder')).toBe('INVALID_ARGUMENT');
|
|
261
|
+
// A Windows client's home is not an absolute path on a POSIX server.
|
|
262
|
+
if (process.platform !== 'win32') expect(await rejects('C:/Users/Someone')).toBe('INVALID_ARGUMENT');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("deletes a removed folder's session from a freshly started daemon", async () => {
|
|
266
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
267
|
+
await mkdir(join(root, 'agent'), { recursive: true });
|
|
268
|
+
const removed = join(root, 'removed-worktree');
|
|
269
|
+
// The transcript lives in the session store; its folder is gone.
|
|
270
|
+
const sessionFile = join(root, 'orphan.jsonl');
|
|
271
|
+
await writeFile(sessionFile, `${JSON.stringify({ type: 'session', id: 'orphan', cwd: removed })}\n`);
|
|
272
|
+
// A new daemon has never seen the folder, as after a restart.
|
|
273
|
+
const { daemon, endpoint } = await startDaemon(root, new FakeSession('unused'), async ({ cwd }) => (
|
|
274
|
+
cwd === removed ? [{ ...diskRow(root, 'orphan'), cwd: removed }] : []
|
|
275
|
+
));
|
|
276
|
+
daemons.push(daemon);
|
|
277
|
+
const client = connectClient(endpoint);
|
|
278
|
+
sockets.push(client);
|
|
279
|
+
await client.authenticate();
|
|
280
|
+
|
|
281
|
+
const deleted = await client.request('sessions.delete', { sessionId: 'orphan', directory: removed });
|
|
282
|
+
expect(deleted.error).toBeUndefined();
|
|
283
|
+
await expect(stat(sessionFile)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
284
|
+
// The removed folder does not become a known project.
|
|
285
|
+
const projects = await client.request('projects.list', {});
|
|
286
|
+
expect(JSON.stringify(projects.result)).not.toContain('removed-worktree');
|
|
287
|
+
});
|
|
288
|
+
|
|
230
289
|
it('an unpersisted resident session is listed with its live status too', async () => {
|
|
231
290
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
232
291
|
await mkdir(join(root, 'agent'), { recursive: true });
|
|
@@ -544,6 +544,26 @@ export function createSessionDaemon({
|
|
|
544
544
|
return activeDirectory || cwd;
|
|
545
545
|
};
|
|
546
546
|
|
|
547
|
+
// Listing or deleting a folder's sessions reads Pi's session store, not the
|
|
548
|
+
// folder, so a folder that has since been removed still resolves: its
|
|
549
|
+
// sessions stay listable, archivable, and deletable. A path that exists must
|
|
550
|
+
// still be a directory, and opening or creating a session keeps the strict
|
|
551
|
+
// check in `resolveDirectory`.
|
|
552
|
+
const resolveSessionStoreDirectory = async (requested) => {
|
|
553
|
+
if (typeof requested !== 'string' || requested.trim().length === 0) return activeDirectory || cwd;
|
|
554
|
+
const trimmed = requested.trim();
|
|
555
|
+
const normalized = trimmed === '~' ? homedir() : trimmed;
|
|
556
|
+
if (!isAbsolute(normalized)) {
|
|
557
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The directory path must be absolute.');
|
|
558
|
+
}
|
|
559
|
+
try {
|
|
560
|
+
await stat(normalized);
|
|
561
|
+
} catch (error) {
|
|
562
|
+
if (error?.code === 'ENOENT') return normalized;
|
|
563
|
+
}
|
|
564
|
+
return resolveDirectory(normalized);
|
|
565
|
+
};
|
|
566
|
+
|
|
547
567
|
const deriveSessionTitle = (text, maxLength = 50) => {
|
|
548
568
|
if (!text || typeof text !== 'string') return '';
|
|
549
569
|
const cleaned = text
|
|
@@ -1499,7 +1519,7 @@ export function createSessionDaemon({
|
|
|
1499
1519
|
};
|
|
1500
1520
|
|
|
1501
1521
|
const listSessionItems = async (requestedDirectory) => {
|
|
1502
|
-
const targetDir =
|
|
1522
|
+
const targetDir = await resolveSessionStoreDirectory(requestedDirectory);
|
|
1503
1523
|
const inflight = listInflightByDirectory.get(targetDir);
|
|
1504
1524
|
if (inflight) return inflight;
|
|
1505
1525
|
const pending = listSessionItemsUnshared(targetDir).finally(() => {
|
|
@@ -1541,15 +1561,18 @@ export function createSessionDaemon({
|
|
|
1541
1561
|
publish('session.updated', { title: redactAttachmentPaths(title) }, sessionId, targetDir);
|
|
1542
1562
|
};
|
|
1543
1563
|
|
|
1544
|
-
|
|
1564
|
+
// Deletion passes `allowRemovedDirectory`: a session whose folder has since
|
|
1565
|
+
// been removed is still found in the store. Opening keeps the strict check.
|
|
1566
|
+
const findPersistedSession = async (sessionId, requestedDirectory, { allowRemovedDirectory = false } = {}) => {
|
|
1545
1567
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
1546
1568
|
throw new SessionDaemonProtocolError('INVALID_SESSION', 'The Pi session does not exist.');
|
|
1547
1569
|
}
|
|
1570
|
+
const resolve = allowRemovedDirectory ? resolveSessionStoreDirectory : resolveDirectory;
|
|
1548
1571
|
const candidateDirs = new Set();
|
|
1549
1572
|
let requestedTargetDirectory;
|
|
1550
1573
|
if (requestedDirectory) {
|
|
1551
1574
|
try {
|
|
1552
|
-
requestedTargetDirectory = await
|
|
1575
|
+
requestedTargetDirectory = await resolve(requestedDirectory);
|
|
1553
1576
|
candidateDirs.add(requestedTargetDirectory);
|
|
1554
1577
|
} catch {}
|
|
1555
1578
|
}
|
|
@@ -1587,8 +1610,9 @@ export function createSessionDaemon({
|
|
|
1587
1610
|
const named = await findPiSessionJsonlById({ sessionId, agentDir });
|
|
1588
1611
|
if (named?.path && named.cwd) {
|
|
1589
1612
|
await validatePiSessionJsonlFile(named.path);
|
|
1590
|
-
|
|
1591
|
-
|
|
1613
|
+
// `resolveDirectory` records an existing folder as known; a removed
|
|
1614
|
+
// one is never added.
|
|
1615
|
+
const directory = await resolve(named.cwd);
|
|
1592
1616
|
return { target: { id: sessionId, path: named.path }, directory };
|
|
1593
1617
|
}
|
|
1594
1618
|
} catch {
|
|
@@ -1629,8 +1653,7 @@ export function createSessionDaemon({
|
|
|
1629
1653
|
lines.close();
|
|
1630
1654
|
if (fileId === sessionId && sessionCwd) {
|
|
1631
1655
|
await validatePiSessionJsonlFile(fullPath);
|
|
1632
|
-
const validated = await
|
|
1633
|
-
knownDirectories.add(validated);
|
|
1656
|
+
const validated = await resolve(sessionCwd);
|
|
1634
1657
|
return { target: { id: sessionId, path: fullPath }, directory: validated };
|
|
1635
1658
|
}
|
|
1636
1659
|
} catch {}
|
|
@@ -3793,7 +3816,7 @@ export function createSessionDaemon({
|
|
|
3793
3816
|
throw new SessionDaemonProtocolError('RUNTIME_DISPOSAL_FAILED', 'The Pi session runtime could not be disposed.');
|
|
3794
3817
|
}
|
|
3795
3818
|
const active = runtimeRegistry?.findBySessionId(sessionId);
|
|
3796
|
-
let targetDir = requestedDirectory ? await
|
|
3819
|
+
let targetDir = requestedDirectory ? await resolveSessionStoreDirectory(requestedDirectory) : active?.cwd || activeDirectory || cwd;
|
|
3797
3820
|
const activeSessionFile = active?.session?.sessionManager?.getSessionFile?.();
|
|
3798
3821
|
if (active) {
|
|
3799
3822
|
if (active.session?.isStreaming) await active.session.abort();
|
|
@@ -3804,7 +3827,7 @@ export function createSessionDaemon({
|
|
|
3804
3827
|
if (active && typeof activeSessionFile === 'string' && activeSessionFile.length > 0) {
|
|
3805
3828
|
await rm(activeSessionFile, { force: true });
|
|
3806
3829
|
} else if (!active) {
|
|
3807
|
-
const { target, directory } = await findPersistedSession(sessionId, targetDir);
|
|
3830
|
+
const { target, directory } = await findPersistedSession(sessionId, targetDir, { allowRemovedDirectory: true });
|
|
3808
3831
|
targetDir = directory;
|
|
3809
3832
|
await acquireResidentLease({ cwd: targetDir, sessionId });
|
|
3810
3833
|
try {
|
|
@@ -4281,6 +4304,7 @@ export function createSessionDaemon({
|
|
|
4281
4304
|
const engineRouter = createSessionEngineRouter({
|
|
4282
4305
|
getRegistry: () => engineRegistry,
|
|
4283
4306
|
resolveDirectory,
|
|
4307
|
+
resolveSessionStoreDirectory,
|
|
4284
4308
|
sessionInput,
|
|
4285
4309
|
redact: (value) => redactAttachmentValues(value),
|
|
4286
4310
|
createError: (code, message) => new SessionDaemonProtocolError(code, message),
|
|
@@ -4677,7 +4701,7 @@ export function createSessionDaemon({
|
|
|
4677
4701
|
return;
|
|
4678
4702
|
}
|
|
4679
4703
|
const listDir = message.payload?.directory || message.payload?.cwd;
|
|
4680
|
-
const listTargetDir =
|
|
4704
|
+
const listTargetDir = await resolveSessionStoreDirectory(listDir);
|
|
4681
4705
|
const merged = await engineRouter.mergeSessionList(sessions, listTargetDir);
|
|
4682
4706
|
writeFrame(socket, {
|
|
4683
4707
|
protocolVersion: PROTOCOL_VERSION,
|
|
@@ -43,6 +43,7 @@ const invalidArgument = (createError, message) => {
|
|
|
43
43
|
* @param {{
|
|
44
44
|
* getRegistry: () => ({ size: number } | undefined),
|
|
45
45
|
* resolveDirectory: (requested: unknown) => Promise<string>,
|
|
46
|
+
* resolveSessionStoreDirectory?: (requested: unknown) => Promise<string>,
|
|
46
47
|
* sessionInput: (payload: object, delivery?: string, execute?: (payload: object) => Promise<object>) => Promise<object>,
|
|
47
48
|
* redact: (value: unknown) => unknown,
|
|
48
49
|
* createError: (code: string, message: string) => Error,
|
|
@@ -60,6 +61,8 @@ const invalidArgument = (createError, message) => {
|
|
|
60
61
|
export const createSessionEngineRouter = ({
|
|
61
62
|
getRegistry,
|
|
62
63
|
resolveDirectory,
|
|
64
|
+
// Deleting reads the session store, so a removed folder still resolves.
|
|
65
|
+
resolveSessionStoreDirectory = resolveDirectory,
|
|
63
66
|
sessionInput,
|
|
64
67
|
redact,
|
|
65
68
|
createError,
|
|
@@ -228,8 +231,9 @@ export const createSessionEngineRouter = ({
|
|
|
228
231
|
if (owner) {
|
|
229
232
|
const payload = message.payload ?? {};
|
|
230
233
|
const requestedDir = payload.directory || payload.cwd;
|
|
234
|
+
const resolve = message.command === 'sessions.delete' ? resolveSessionStoreDirectory : resolveDirectory;
|
|
231
235
|
const enginePayload = requestedDir !== undefined
|
|
232
|
-
? { ...payload, directory: await
|
|
236
|
+
? { ...payload, directory: await resolve(requestedDir) }
|
|
233
237
|
: payload;
|
|
234
238
|
if (PROMPT_COMMANDS.has(message.command)) {
|
|
235
239
|
const delivery = deliveryOf(message.command);
|
|
@@ -106,6 +106,27 @@ describe('session engine router', () => {
|
|
|
106
106
|
})).rejects.toMatchObject({ code: ENGINE_UNSUPPORTED_OPERATION });
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
it('resolves a delete through the session store and every other command strictly', async () => {
|
|
110
|
+
const seen = [];
|
|
111
|
+
const engine = makeEngine('fake', {
|
|
112
|
+
ownsSession: (id) => id === 'engine-1',
|
|
113
|
+
handlers: {
|
|
114
|
+
'sessions.delete': async (payload) => { seen.push(['delete', payload.directory]); return {}; },
|
|
115
|
+
'sessions.rename': async (payload) => { seen.push(['rename', payload.directory]); return {}; },
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const { router } = makeRouter({
|
|
119
|
+
getRegistry: () => makeRegistry([engine]),
|
|
120
|
+
resolveDirectory: async () => { throw Object.assign(new Error('missing'), { code: 'INVALID_ARGUMENT' }); },
|
|
121
|
+
resolveSessionStoreDirectory: async (dir) => `store:${dir}`,
|
|
122
|
+
});
|
|
123
|
+
await router.dispatch({}, { command: 'sessions.delete', requestId: 'r1', payload: { sessionId: 'engine-1', directory: '/gone' } });
|
|
124
|
+
expect(seen).toEqual([['delete', 'store:/gone']]);
|
|
125
|
+
await expect(router.dispatch({}, {
|
|
126
|
+
command: 'sessions.rename', requestId: 'r2', payload: { sessionId: 'engine-1', directory: '/gone', title: 'x' },
|
|
127
|
+
})).rejects.toMatchObject({ code: 'INVALID_ARGUMENT' });
|
|
128
|
+
});
|
|
129
|
+
|
|
109
130
|
it('throws unsupported automatically when the handler is missing', async () => {
|
|
110
131
|
const engine = makeEngine('fake', {
|
|
111
132
|
ownsSession: () => true,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ep as j,dO as y,dS as D}from"./useAppFontEffects-Oyin3dgQ.js";import{f as k,B as C}from"./web-components-CkTNGkJ2.js";import{M as O,G as P,u as L,W as A,a as M,b as R,n as F,t as H}from"./Virtualizer-okhy9Aq3.js";import{j as d}from"./vendor-boot-3SaHYVb1.js";import{V as _,F as N}from"./VirtualizedFileDiff-BYby097w.js";import{a as w}from"./vendor-react-Bz1tRBxM.js";function T({hunkIndex:e,lineIndex:t,conflictIndex:n}){return`merge-conflict-action-${e}-${t}-${n}`}function V(e,t){const n=t.hunks[e.hunkIndex];if(n!=null)return{hunkIndex:e.hunkIndex,lineIndex:z(n,e.startContentIndex)}}function z(e,t){let n=e.unifiedLineStart;for(let l=0;l<t;l++){const s=e.hunkContent[l];n+=s.type==="context"?s.lines:s.deletions+s.additions}return n}function U(e){const t=j(e);if(t.length!==1)throw console.error(t),new Error("PatchDiff: Provided patch must include only 1 patch, with 1 diff");const{files:n}=t[0];if(n.length!==1)throw console.error(n),new Error("FileDiff: Provided patch must contain exactly 1 file diff");return n[0]}function $({fileDiff:e,actions:t,renderCustomHeader:n,renderHeaderPrefix:l,renderHeaderFilenameSuffix:s,renderHeaderMetadata:x,renderAnnotation:f,renderGutterUtility:u,renderMergeConflictUtility:o,lineAnnotations:a,getHoveredLine:g,getInstance:m}){const p=n?.(e),c=l?.(e),i=s?.(e),v=x?.(e);return d.jsxs(d.Fragment,{children:[p!=null?d.jsx("div",{slot:y,children:p}):d.jsxs(d.Fragment,{children:[c!=null&&d.jsx("div",{slot:"header-prefix",children:c}),i!=null&&d.jsx("div",{slot:"header-filename-suffix",children:i}),v!=null&&d.jsx("div",{slot:"header-metadata",children:v})]}),f!=null&&a?.map((r,h)=>d.jsx("div",{slot:k(r),children:f(r)},h)),t!=null&&o!=null&&m!=null&&t.map(r=>{if(r==null)return;const h=b(r,e);return d.jsx("div",{slot:h,style:O,children:o(r,m)},h)}),u!=null&&d.jsx("div",{slot:"gutter-utility-slot",style:P,children:u(g)})]})}function b(e,t){const n=V(e,t);return n!=null?T({hunkIndex:n.hunkIndex,lineIndex:n.lineIndex,conflictIndex:e.conflictIndex}):void 0}const S=typeof window>"u"?w.useEffect:w.useLayoutEffect;function G({fileDiff:e,options:t,lineAnnotations:n,selectedLines:l,prerenderedHTML:s,metrics:x,hasGutterRenderUtility:f,hasCustomHeader:u,disableWorkerPool:o,contentEditable:a}){const g=L(),m=l!==void 0,p=w.useContext(A),c=M(),i=w.useRef(null),v=R(r=>{if(r!=null){if(i.current!=null)throw new Error("useFileDiffInstance: An instance should not already exist when a node is created");g!=null?i.current=new _(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),g,x,o?void 0:p,!0):i.current=new N(E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),o?void 0:p,!0),i.current.hydrate({fileDiff:e,fileContainer:r,lineAnnotations:n,prerenderedHTML:s})}else{if(i.current==null)throw new Error("useFileDiffInstance: A FileDiff instance should exist when unmounting");i.current.cleanUp(),i.current=null}});return S(()=>{const{current:r}=i;if(r==null)return;const h=E({controlledSelection:m,contentEditable:a,hasCustomHeader:u,hasEditor:c!==void 0,hasGutterRenderUtility:f,options:t}),I=!C(r.options,h);r.setOptions(h),r.render({forceRender:I,fileDiff:e,lineAnnotations:n}),l!==void 0&&r.setSelectedLines(l)}),S(()=>{if(a&&i.current!=null){if(c===void 0)throw new Error("FileDiff: Editor is not attached");return c.edit(i.current)}},[a,c]),{ref:v,getHoveredLine:w.useCallback(()=>i.current?.getHoveredLine(),[])}}function E({options:e,controlledSelection:t,contentEditable:n,hasCustomHeader:l,hasEditor:s,hasGutterRenderUtility:x}){const f=n&&s,u=t||x||l;if(!u&&!f)return e;let o={...e};return u&&(o={...o,controlledSelection:t,renderCustomHeader:l?F:e?.renderCustomHeader,renderGutterUtility:x?F:e?.renderGutterUtility}),f&&(o={...o,useTokenTransformer:!0,enableGutterUtility:!1,enableLineSelection:!1,expandUnchanged:!0,lineHoverHighlight:"disabled"}),o}function Y({patch:e,options:t,metrics:n,lineAnnotations:l,selectedLines:s,className:x,style:f,prerenderedHTML:u,renderAnnotation:o,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderGutterUtility:c,disableWorkerPool:i=!1,contentEditable:v=!1}){const r=q(e),{ref:h,getHoveredLine:I}=G({fileDiff:r,options:t,metrics:n,lineAnnotations:l,selectedLines:s,prerenderedHTML:u,hasGutterRenderUtility:c!=null,hasCustomHeader:a!=null,disableWorkerPool:i,contentEditable:v});return d.jsx(D,{ref:h,className:x,style:f,children:H($({fileDiff:r,renderCustomHeader:a,renderHeaderPrefix:g,renderHeaderFilenameSuffix:m,renderHeaderMetadata:p,renderAnnotation:o,lineAnnotations:l,renderGutterUtility:c,getHoveredLine:I}),u)})}function q(e){return w.useMemo(()=>U(e),[e])}export{Y as P};
|