@openchamber/web 1.21.1 → 1.22.0
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/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-CPvfxh0N.js} +1 -1
- package/dist/assets/{CommitSection-DwGiXyjf.js → CommitSection-CC5mFzO2.js} +1 -1
- package/dist/assets/DiffView-6xGdyI0n.js +4 -0
- package/dist/assets/FilesView-Bm3vT63N.js +17 -0
- package/dist/assets/GitView-B6y1Y69c.js +6 -0
- package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-rwHz84MX.js} +1 -1
- package/dist/assets/LinearIssuesView-B0UM_Rkx.js +1 -0
- package/dist/assets/MarkdownImageGallery-sGilV9Hs.js +1 -0
- package/dist/assets/MarkdownRendererImpl--4sRsKBn.js +12 -0
- package/dist/assets/OnboardingScreen-CECL_Cms.js +1 -0
- package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BGPl1s-U.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-Cvz9Z-io.js} +3 -3
- package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-BFMsnHk3.js} +4 -4
- package/dist/assets/SettingsView-_Gtn5SdT.js +28 -0
- package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-C1Qa09YO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-DzQlzMF4.js} +5 -5
- package/dist/assets/{ToolPartDiffPreview-C7kBQNAA.js → ToolPartDiffPreview-DfVOfwHy.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-DT5MDv-u.js} +1 -1
- package/dist/assets/WalkthroughView-D8sLH_M8.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DmpLWhll.js} +1 -1
- package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-BK78t3M_.js} +1 -1
- package/dist/assets/{de-CEoCz3j6.js → de-C3luvSd_.js} +4 -4
- package/dist/assets/{es-DwyXCqaL.js → es-CmU4HLv9.js} +3 -3
- package/dist/assets/{fr-CS7Csln9.js → fr-Bgyni40l.js} +4 -4
- package/dist/assets/index-C57jT0Sa.css +1 -0
- package/dist/assets/{index-CaPAjwXQ.js → index-CWYs7sMK.js} +1 -1
- package/dist/assets/index-b0zDkWyg.js +7 -0
- package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-BO_q5ezD.js} +1 -1
- package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-D8qPqUAf.js} +1 -1
- package/dist/assets/{ja-vnwqLcx6.js → ja-C1ImKinT.js} +4 -4
- package/dist/assets/{ko-CXuSfZv5.js → ko-CP7OdxYH.js} +4 -4
- package/dist/assets/main-D4rd8Hy5.js +928 -0
- package/dist/assets/{main-D5RWr6sJ.js → main-D7fwjW2z.js} +2 -2
- package/dist/assets/markdownCore-BcmkWZPO.js +3 -0
- package/dist/assets/{miniChat-CqR3icsk.js → miniChat-D5rraz-g.js} +2 -2
- package/dist/assets/{mobile-RN_UTTlB.js → mobile-Cg_DE3KL.js} +2 -2
- package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Bpql0QGw.js} +3 -3
- package/dist/assets/{pl-BJxry0Mi.js → pl-DQYSiGYX.js} +4 -4
- package/dist/assets/{pt-BR-DxLmkhdv.js → pt-BR-DytpsW4M.js} +3 -3
- package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-B_Bn7BbN.js} +2 -2
- package/dist/assets/renderMobileApp-DLfxMzGJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-HlRmXFGW.js +16 -0
- package/dist/assets/scheduledTasksApi-BPvxrynl.js +1 -0
- package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CFAVs_lu.js} +1 -1
- package/dist/assets/tr-aizaUvft.js +6 -0
- package/dist/assets/{uk-ClgQjmlw.js → uk-DwnRxJZd.js} +3 -3
- package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-DWXGRUPZ.js} +191 -151
- package/dist/assets/useInlineCommentController-Cc0OCXr0.js +2 -0
- package/dist/assets/useRootScrollLock-BFZtfciC.js +1 -0
- package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BGFszm8n.js} +2 -2
- package/dist/assets/{web-components-DOXvU-tB.js → web-components-CD-GFayc.js} +4 -4
- package/dist/assets/{zh-CN-Ba6y8H-i.js → zh-CN-UDNMxm7r.js} +3 -3
- package/dist/assets/zh-TW-BsswdYL-.js +15 -0
- 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/index.js +4 -0
- package/server/lib/dictation/DOCUMENTATION.md +19 -6
- package/server/lib/dictation/local/model-catalog.js +220 -0
- package/server/lib/dictation/local/model-catalog.test.js +42 -0
- package/server/lib/dictation/local/sherpa-tts.js +41 -20
- package/server/lib/dictation/local/worker-process.js +2 -0
- package/server/lib/dictation/runtime.js +4 -0
- package/server/lib/dictation/service.js +27 -4
- package/server/lib/fs/DOCUMENTATION.md +4 -0
- package/server/lib/fs/routes.js +129 -0
- package/server/lib/fs/routes.test.js +219 -0
- package/server/lib/linear/DOCUMENTATION.md +97 -0
- package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
- package/server/lib/linear/auth.js +436 -0
- package/server/lib/linear/auth.test.js +242 -0
- package/server/lib/linear/client.js +191 -0
- package/server/lib/linear/index.js +61 -0
- package/server/lib/linear/issues.js +499 -0
- package/server/lib/linear/issues.test.js +512 -0
- package/server/lib/linear/mapping.js +188 -0
- package/server/lib/linear/mapping.test.js +147 -0
- package/server/lib/linear/oauth.js +345 -0
- package/server/lib/linear/oauth.test.js +166 -0
- package/server/lib/linear/parse.js +23 -0
- package/server/lib/linear/routes.js +432 -0
- package/server/lib/linear/routes.test.js +661 -0
- package/server/lib/linear/status-runtime.js +64 -0
- package/server/lib/linear/status-runtime.test.js +167 -0
- package/server/lib/linear/status.js +280 -0
- package/server/lib/linear/status.test.js +271 -0
- package/server/lib/linear/teams.js +72 -0
- package/server/lib/linear/teams.test.js +94 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +3 -3
- package/server/lib/projects/project-config.js +33 -5
- package/server/lib/projects/project-config.test.js +85 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
- package/server/lib/tts/DOCUMENTATION.md +1 -0
- package/server/lib/tts/language-detect.js +210 -0
- package/server/lib/tts/language-detect.test.js +76 -0
- package/server/lib/tts/routes.js +23 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/dist/assets/DiffView-Db6bjVv1.js +0 -4
- package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
- package/dist/assets/GitView-CHzJxTi0.js +0 -6
- package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
- package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
- package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
- package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
- package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
- package/dist/assets/index-CUKcHnUA.css +0 -1
- package/dist/assets/index-DIvDEKE-.js +0 -7
- package/dist/assets/main-DLlfDjQ_.js +0 -926
- package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
- package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
- package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
- package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
- package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
- package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
- package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
- package/dist/assets/zh-TW-Dv8yyhN1.js +0 -15
|
@@ -14,6 +14,7 @@ const createRuntime = async () => {
|
|
|
14
14
|
});
|
|
15
15
|
return {
|
|
16
16
|
runtime,
|
|
17
|
+
tempRoot,
|
|
17
18
|
cleanup: async () => {
|
|
18
19
|
await rm(tempRoot, { recursive: true, force: true });
|
|
19
20
|
},
|
|
@@ -472,6 +473,90 @@ describe('project-config loop reconciliation', () => {
|
|
|
472
473
|
}
|
|
473
474
|
});
|
|
474
475
|
|
|
476
|
+
describe('fields this build does not know', () => {
|
|
477
|
+
// Simulates a config written by a newer build (or a newer UI): the task
|
|
478
|
+
// carries execution and state fields normalization here has never heard of.
|
|
479
|
+
const seedForeignTask = async (runtime, tempRoot) => {
|
|
480
|
+
const created = await runtime.upsertScheduledTask('project-test', {
|
|
481
|
+
name: 'Nightly digest',
|
|
482
|
+
enabled: true,
|
|
483
|
+
schedule: { kind: 'daily', time: '09:30', timezone: 'UTC' },
|
|
484
|
+
execution: { prompt: 'Summarize', providerID: 'openai', modelID: 'gpt-4.1', goalEnabled: true },
|
|
485
|
+
});
|
|
486
|
+
const filePath = path.join(tempRoot, 'project-test.json');
|
|
487
|
+
const stored = JSON.parse(await readFile(filePath, 'utf8'));
|
|
488
|
+
stored.scheduledTasks[0].execution.futureExecutionField = 'keep me';
|
|
489
|
+
stored.scheduledTasks[0].state.futureStateField = 42;
|
|
490
|
+
stored.scheduledTasks[0].futureTopLevelField = true;
|
|
491
|
+
await writeFile(filePath, JSON.stringify(stored, null, 2), 'utf8');
|
|
492
|
+
return { id: created.task.id, filePath };
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const readStoredTask = async (filePath, id) => {
|
|
496
|
+
const stored = JSON.parse(await readFile(filePath, 'utf8'));
|
|
497
|
+
return stored.scheduledTasks.find((task) => task.id === id);
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
it('survive a state update after a run, and the claim update', async () => {
|
|
501
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
502
|
+
try {
|
|
503
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
504
|
+
|
|
505
|
+
await runtime.updateScheduledTaskState('project-test', id, { lastStatus: 'success', lastRunAt: 1000 });
|
|
506
|
+
let stored = await readStoredTask(filePath, id);
|
|
507
|
+
expect(stored.execution.futureExecutionField).toBe('keep me');
|
|
508
|
+
expect(stored.execution.goalEnabled).toBe(true);
|
|
509
|
+
expect(stored.futureTopLevelField).toBe(true);
|
|
510
|
+
expect(stored.state.lastStatus).toBe('success');
|
|
511
|
+
|
|
512
|
+
await runtime.updateScheduledTaskStateIf('project-test', id, () => true, { lastScheduledFor: 5000 });
|
|
513
|
+
stored = await readStoredTask(filePath, id);
|
|
514
|
+
expect(stored.execution.futureExecutionField).toBe('keep me');
|
|
515
|
+
expect(stored.state.lastScheduledFor).toBe(5000);
|
|
516
|
+
} finally {
|
|
517
|
+
await cleanup();
|
|
518
|
+
}
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it('survive writes that replace or delete a different task, and a loop sync', async () => {
|
|
522
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
523
|
+
try {
|
|
524
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
525
|
+
|
|
526
|
+
const other = await runtime.upsertScheduledTask('project-test', {
|
|
527
|
+
id: 'other-task',
|
|
528
|
+
name: 'Other',
|
|
529
|
+
enabled: true,
|
|
530
|
+
schedule: { kind: 'daily', time: '10:00', timezone: 'UTC' },
|
|
531
|
+
execution: { prompt: 'Other', providerID: 'openai', modelID: 'gpt-4.1' },
|
|
532
|
+
});
|
|
533
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
534
|
+
|
|
535
|
+
await runtime.deleteScheduledTask('project-test', other.task.id);
|
|
536
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
537
|
+
|
|
538
|
+
await runtime.reconcileLoopTasks('project-test', []);
|
|
539
|
+
expect((await readStoredTask(filePath, id)).execution.futureExecutionField).toBe('keep me');
|
|
540
|
+
} finally {
|
|
541
|
+
await cleanup();
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('are dropped only when the task itself is deliberately saved', async () => {
|
|
546
|
+
const { runtime, tempRoot, cleanup } = await createRuntime();
|
|
547
|
+
try {
|
|
548
|
+
const { id, filePath } = await seedForeignTask(runtime, tempRoot);
|
|
549
|
+
const [task] = await runtime.listScheduledTasks('project-test');
|
|
550
|
+
await runtime.upsertScheduledTask('project-test', { ...task, name: 'Renamed' });
|
|
551
|
+
const stored = await readStoredTask(filePath, id);
|
|
552
|
+
expect(stored.name).toBe('Renamed');
|
|
553
|
+
expect(stored.execution.futureExecutionField).toBeUndefined();
|
|
554
|
+
} finally {
|
|
555
|
+
await cleanup();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
475
560
|
it('conditionally updates state only when the predicate passes (occurrence claim)', async () => {
|
|
476
561
|
const { runtime, cleanup } = await createRuntime();
|
|
477
562
|
try {
|
|
@@ -25,6 +25,13 @@ in shared project config under the project write lock:
|
|
|
25
25
|
from the winner's persisted `nextRunAt`.
|
|
26
26
|
- Project config writes also take a cross-process `.json.lock` file so the
|
|
27
27
|
read-modify-write is serialized across processes, not only within one process.
|
|
28
|
+
- The sharing processes may run different OpenChamber versions. Normalization
|
|
29
|
+
keeps only the fields a build knows, so every writer persists tasks it did
|
|
30
|
+
not change verbatim from disk and swaps only `state` onto a task whose state
|
|
31
|
+
it updated; a task goes out normalized only when it was deliberately
|
|
32
|
+
replaced (upsert, loop adoption). An older server touching the file after a
|
|
33
|
+
run therefore cannot strip fields a newer build added, such as a task's goal
|
|
34
|
+
or auto-accept settings.
|
|
28
35
|
- Lock timeout / filesystem errors on claim, manual-start, or completion state
|
|
29
36
|
writes always release the in-process running slot (via `finally`) and best-effort
|
|
30
37
|
re-arm the **next future** occurrence; they must not leave the task permanently
|
|
@@ -11,6 +11,7 @@ This module provides server-side Text-to-Speech services using OpenAI's TTS API.
|
|
|
11
11
|
- `packages/web/server/lib/text/summarization.js`: Shared text summarization stub and sanitization utilities. It performs no external Zen calls.
|
|
12
12
|
- `packages/web/server/lib/tts/stt.js`: STT proxy for OpenAI-compatible transcription endpoints.
|
|
13
13
|
- `packages/web/server/lib/tts/base-url.js`: shared base URL validation and normalization for custom OpenAI-compatible endpoints.
|
|
14
|
+
- `packages/web/server/lib/tts/language-detect.js`: dependency-free language detection for voice selection (`detectTextLanguage`, `pickVoiceForLanguage`, `languageOfLocale`). Used by the macOS `say` route (`language: 'auto'` switches to an installed voice whose locale matches the text; the response carries `X-Speech-Voice` and `X-Speech-Language`) and by the dictation module's local TTS model choice.
|
|
14
15
|
|
|
15
16
|
## Public exports
|
|
16
17
|
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Language detection for text-to-speech voice selection.
|
|
3
|
+
*
|
|
4
|
+
* Picks the language a piece of chat text is written in so a TTS provider
|
|
5
|
+
* can choose a matching voice or model. Deliberately small and dependency
|
|
6
|
+
* free: the writing system decides most cases outright, and Latin-script
|
|
7
|
+
* languages are told apart by function words and characteristic letters.
|
|
8
|
+
* The answer is a best effort for voice selection, not a linguistic claim —
|
|
9
|
+
* an unknown language falls back to English rather than failing.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const SCRIPT_RANGES = [
|
|
13
|
+
['hangul', /[가-ᄀ-ᇿ-]/g],
|
|
14
|
+
['kana', /[-ヿ]/g],
|
|
15
|
+
['han', /[一-鿿㐀-䶿]/g],
|
|
16
|
+
['cyrillic', /[Ѐ-ӿ]/g],
|
|
17
|
+
['greek', /[Ͱ-Ͽ]/g],
|
|
18
|
+
['arabic', /[-ۿ]/g],
|
|
19
|
+
['hebrew', /[-]/g],
|
|
20
|
+
['thai', /[-]/g],
|
|
21
|
+
['devanagari', /[ऀ-ॿ]/g],
|
|
22
|
+
['latin', /[A-Za-zÀ-ɏ]/g],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const SCRIPT_LANGUAGE = {
|
|
26
|
+
hangul: 'ko',
|
|
27
|
+
greek: 'el',
|
|
28
|
+
arabic: 'ar',
|
|
29
|
+
hebrew: 'he',
|
|
30
|
+
thai: 'th',
|
|
31
|
+
devanagari: 'hi',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Letters that only (or overwhelmingly) occur in one language of a script.
|
|
35
|
+
const LATIN_MARKERS = {
|
|
36
|
+
pl: /[łęąńśźż]/i,
|
|
37
|
+
cs: /[řěůťďň]/i,
|
|
38
|
+
tr: /[ğışİ]/,
|
|
39
|
+
pt: /[ãõ]/i,
|
|
40
|
+
es: /[ñ¿¡]/,
|
|
41
|
+
de: /[ß]/,
|
|
42
|
+
fr: /[œ]/i,
|
|
43
|
+
sv: /[å]/i,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Frequent function words per language. Scored by whole-word hits; every
|
|
47
|
+
// list has the same length so scores stay comparable.
|
|
48
|
+
const STOPWORDS = {
|
|
49
|
+
en: ['the', 'and', 'is', 'to', 'of', 'that', 'you', 'with', 'for', 'this', 'are', 'it', 'not', 'have', 'can', 'will', 'your', 'from', 'which', 'when'],
|
|
50
|
+
de: ['und', 'der', 'die', 'das', 'ist', 'nicht', 'mit', 'ein', 'eine', 'auch', 'sich', 'auf', 'für', 'wird', 'werden', 'oder', 'aber', 'wenn', 'sind', 'kann'],
|
|
51
|
+
fr: ['le', 'la', 'les', 'et', 'est', 'une', 'des', 'pour', 'que', 'qui', 'dans', 'pas', 'vous', 'sur', 'avec', 'sont', 'nous', 'cette', 'mais', 'plus'],
|
|
52
|
+
es: ['el', 'la', 'los', 'las', 'que', 'es', 'una', 'por', 'para', 'con', 'del', 'como', 'pero', 'más', 'este', 'esta', 'son', 'tiene', 'puede', 'también'],
|
|
53
|
+
it: ['il', 'la', 'che', 'di', 'è', 'una', 'per', 'non', 'con', 'del', 'della', 'come', 'sono', 'anche', 'questo', 'questa', 'gli', 'nel', 'più', 'essere'],
|
|
54
|
+
pt: ['o', 'a', 'os', 'as', 'que', 'é', 'uma', 'para', 'com', 'não', 'do', 'da', 'como', 'mas', 'também', 'este', 'esta', 'são', 'você', 'pode'],
|
|
55
|
+
pl: ['i', 'nie', 'jest', 'się', 'na', 'to', 'że', 'jak', 'ale', 'dla', 'oraz', 'przez', 'czy', 'tym', 'jego', 'można', 'jeśli', 'tego', 'które', 'także'],
|
|
56
|
+
nl: ['de', 'het', 'een', 'en', 'van', 'is', 'niet', 'dat', 'met', 'voor', 'ook', 'zijn', 'maar', 'als', 'wordt', 'deze', 'kan', 'naar', 'bij', 'dan'],
|
|
57
|
+
cs: ['a', 'je', 'se', 'na', 'to', 'že', 'jak', 'ale', 'pro', 'nebo', 'jsou', 'může', 'také', 'tento', 'když', 'jeho', 'které', 'být', 'aby', 'ještě'],
|
|
58
|
+
tr: ['ve', 'bir', 'bu', 'için', 'ile', 'de', 'da', 'ama', 'gibi', 'daha', 'var', 'olarak', 'çok', 'ne', 'her', 'kadar', 'sonra', 'değil', 'olan', 'ise'],
|
|
59
|
+
sv: ['och', 'att', 'det', 'är', 'en', 'som', 'för', 'inte', 'med', 'till', 'den', 'kan', 'har', 'ett', 'men', 'också', 'eller', 'från', 'när', 'vara'],
|
|
60
|
+
uk: ['і', 'та', 'що', 'це', 'не', 'як', 'для', 'він', 'вона', 'але', 'або', 'також', 'тільки', 'вже', 'якщо', 'його', 'цей', 'ця', 'бути', 'коли'],
|
|
61
|
+
ru: ['и', 'что', 'это', 'не', 'как', 'для', 'он', 'она', 'но', 'или', 'также', 'только', 'уже', 'если', 'его', 'этот', 'эта', 'быть', 'когда', 'чтобы'],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const LATIN_LANGUAGES = ['en', 'de', 'fr', 'es', 'it', 'pt', 'pl', 'nl', 'cs', 'tr', 'sv'];
|
|
65
|
+
const CYRILLIC_LANGUAGES = ['uk', 'ru'];
|
|
66
|
+
|
|
67
|
+
const countMatches = (text, pattern) => {
|
|
68
|
+
const matches = text.match(pattern);
|
|
69
|
+
return matches ? matches.length : 0;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const scoreStopwords = (words, languages) => {
|
|
73
|
+
const scores = {};
|
|
74
|
+
for (const language of languages) {
|
|
75
|
+
const list = new Set(STOPWORDS[language]);
|
|
76
|
+
let hits = 0;
|
|
77
|
+
for (const word of words) {
|
|
78
|
+
if (list.has(word)) hits += 1;
|
|
79
|
+
}
|
|
80
|
+
scores[language] = hits;
|
|
81
|
+
}
|
|
82
|
+
return scores;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const bestOf = (scores, fallback) => {
|
|
86
|
+
let best = fallback;
|
|
87
|
+
let bestScore = 0;
|
|
88
|
+
for (const [language, score] of Object.entries(scores)) {
|
|
89
|
+
if (score > bestScore) {
|
|
90
|
+
best = language;
|
|
91
|
+
bestScore = score;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return best;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const pickByMarkers = (text, markers) => {
|
|
98
|
+
for (const [language, pattern] of Object.entries(markers)) {
|
|
99
|
+
if (pattern.test(text)) return language;
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {string} text
|
|
106
|
+
* @returns {{ language: string, script: string }} BCP-47 primary language subtag and the dominant script.
|
|
107
|
+
*/
|
|
108
|
+
export function detectTextLanguage(text) {
|
|
109
|
+
const source = typeof text === 'string' ? text : '';
|
|
110
|
+
const counts = SCRIPT_RANGES.map(([script, pattern]) => [script, countMatches(source, pattern)]);
|
|
111
|
+
const letters = counts.reduce((sum, [, count]) => sum + count, 0);
|
|
112
|
+
if (letters === 0) return { language: 'en', script: 'latin' };
|
|
113
|
+
|
|
114
|
+
// Kana settles Japanese even when Han dominates the character count.
|
|
115
|
+
const kana = counts.find(([script]) => script === 'kana')?.[1] ?? 0;
|
|
116
|
+
const han = counts.find(([script]) => script === 'han')?.[1] ?? 0;
|
|
117
|
+
if (kana > 0 && kana + han >= letters * 0.3) return { language: 'ja', script: 'kana' };
|
|
118
|
+
if (han > 0 && han >= letters * 0.3) return { language: 'zh', script: 'han' };
|
|
119
|
+
|
|
120
|
+
const [script] = counts.reduce((best, entry) => (entry[1] > best[1] ? entry : best));
|
|
121
|
+
|
|
122
|
+
if (script in SCRIPT_LANGUAGE) return { language: SCRIPT_LANGUAGE[script], script };
|
|
123
|
+
|
|
124
|
+
const words = source.toLowerCase().split(/[^\p{L}\p{M}']+/u).filter(Boolean);
|
|
125
|
+
|
|
126
|
+
if (script === 'cyrillic') {
|
|
127
|
+
const scores = scoreStopwords(words, CYRILLIC_LANGUAGES);
|
|
128
|
+
const ukMarkers = countMatches(source, /[іїєґ]/gi);
|
|
129
|
+
const ruMarkers = countMatches(source, /[ыэъё]/gi);
|
|
130
|
+
// Letters decide: the two alphabets differ in letters that occur in
|
|
131
|
+
// nearly every sentence. Function words only settle a text that shows
|
|
132
|
+
// neither set, and a text with no Russian-only letters is far more
|
|
133
|
+
// likely Ukrainian than the reverse, so that tie goes to Ukrainian.
|
|
134
|
+
if (ukMarkers !== ruMarkers) return { language: ukMarkers > ruMarkers ? 'uk' : 'ru', script };
|
|
135
|
+
if (scores.uk !== scores.ru) return { language: scores.uk > scores.ru ? 'uk' : 'ru', script };
|
|
136
|
+
return { language: ruMarkers > 0 ? 'ru' : 'uk', script };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const scores = scoreStopwords(words, LATIN_LANGUAGES);
|
|
140
|
+
const marked = pickByMarkers(source, LATIN_MARKERS);
|
|
141
|
+
// A characteristic letter outranks stopword counts unless another language
|
|
142
|
+
// clearly dominates the function words (a German text quoting "façade").
|
|
143
|
+
if (marked && scores[marked] * 2 >= scores[bestOf(scores, marked)]) {
|
|
144
|
+
return { language: marked, script };
|
|
145
|
+
}
|
|
146
|
+
return { language: bestOf(scores, 'en'), script };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Map a detected language onto the locales a voice list uses (`uk_UA`,
|
|
151
|
+
* `en_US`...). Returns the preferred locale prefixes in order.
|
|
152
|
+
* @param {string} language
|
|
153
|
+
* @returns {string[]}
|
|
154
|
+
*/
|
|
155
|
+
function localePrefixesForLanguage(language) {
|
|
156
|
+
const table = {
|
|
157
|
+
en: ['en_US', 'en_GB', 'en'],
|
|
158
|
+
uk: ['uk_UA', 'uk'],
|
|
159
|
+
ru: ['ru_RU', 'ru'],
|
|
160
|
+
de: ['de_DE', 'de'],
|
|
161
|
+
fr: ['fr_FR', 'fr_CA', 'fr'],
|
|
162
|
+
es: ['es_ES', 'es_MX', 'es'],
|
|
163
|
+
it: ['it_IT', 'it'],
|
|
164
|
+
pt: ['pt_BR', 'pt_PT', 'pt'],
|
|
165
|
+
pl: ['pl_PL', 'pl'],
|
|
166
|
+
nl: ['nl_NL', 'nl_BE', 'nl'],
|
|
167
|
+
cs: ['cs_CZ', 'cs'],
|
|
168
|
+
tr: ['tr_TR', 'tr'],
|
|
169
|
+
sv: ['sv_SE', 'sv'],
|
|
170
|
+
zh: ['zh_CN', 'zh_TW', 'zh_HK', 'zh'],
|
|
171
|
+
ja: ['ja_JP', 'ja'],
|
|
172
|
+
ko: ['ko_KR', 'ko'],
|
|
173
|
+
el: ['el_GR', 'el'],
|
|
174
|
+
ar: ['ar_001', 'ar_SA', 'ar'],
|
|
175
|
+
he: ['he_IL', 'he'],
|
|
176
|
+
th: ['th_TH', 'th'],
|
|
177
|
+
hi: ['hi_IN', 'hi'],
|
|
178
|
+
};
|
|
179
|
+
return table[language] ?? [language];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Choose a voice for a language from a `say`-style voice list.
|
|
184
|
+
* Prefers an enhanced/premium variant of a matching voice, then any voice of
|
|
185
|
+
* the exact locale, then any voice of the language. Returns null when the
|
|
186
|
+
* list has no voice for that language.
|
|
187
|
+
* @param {string} language
|
|
188
|
+
* @param {ReadonlyArray<{ name: string, locale: string }>} voices
|
|
189
|
+
* @returns {string | null}
|
|
190
|
+
*/
|
|
191
|
+
export function pickVoiceForLanguage(language, voices) {
|
|
192
|
+
const prefixes = localePrefixesForLanguage(language);
|
|
193
|
+
for (const prefix of prefixes) {
|
|
194
|
+
const matching = voices.filter((voice) => voice.locale === prefix || voice.locale.startsWith(`${prefix}_`) || (prefix === language && voice.locale.startsWith(`${language}_`)));
|
|
195
|
+
if (matching.length === 0) continue;
|
|
196
|
+
const enhanced = matching.find((voice) => /\((Enhanced|Premium)\)/i.test(voice.name));
|
|
197
|
+
return (enhanced ?? matching[0]).name;
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Language of a voice, from its locale (`uk_UA` → `uk`).
|
|
204
|
+
* @param {string | null | undefined} locale
|
|
205
|
+
* @returns {string | null}
|
|
206
|
+
*/
|
|
207
|
+
export function languageOfLocale(locale) {
|
|
208
|
+
if (typeof locale !== 'string' || !locale) return null;
|
|
209
|
+
return locale.split(/[_-]/)[0].toLowerCase();
|
|
210
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { detectTextLanguage, languageOfLocale, pickVoiceForLanguage } from './language-detect.js';
|
|
3
|
+
|
|
4
|
+
describe('detectTextLanguage', () => {
|
|
5
|
+
it.each([
|
|
6
|
+
['en', 'The build is green and the tests pass, so you can merge this now.'],
|
|
7
|
+
['uk', 'Привіт! Це тестове повідомлення, і воно написане українською мовою.'],
|
|
8
|
+
['ru', 'Привет! Это тестовое сообщение, и оно написано на русском языке.'],
|
|
9
|
+
['de', 'Die Änderung ist fertig und die Tests laufen ohne Fehler durch.'],
|
|
10
|
+
['fr', 'La modification est prête et les tests passent sans erreur.'],
|
|
11
|
+
['es', 'El cambio está listo y las pruebas pasan sin errores.'],
|
|
12
|
+
['it', 'La modifica è pronta e i test passano senza errori.'],
|
|
13
|
+
['pt', 'A alteração está pronta e os testes passam sem erros, você pode continuar.'],
|
|
14
|
+
['pl', 'Zmiana jest gotowa i testy przechodzą bez błędów.'],
|
|
15
|
+
['nl', 'De wijziging is klaar en de tests slagen zonder fouten.'],
|
|
16
|
+
['cs', 'Změna je hotová a testy procházejí bez chyb.'],
|
|
17
|
+
['tr', 'Değişiklik hazır ve testler hatasız geçiyor.'],
|
|
18
|
+
['sv', 'Ändringen är klar och testerna går igenom utan fel.'],
|
|
19
|
+
['zh', '修改已经完成,所有测试都通过了。'],
|
|
20
|
+
['ja', '変更が完了し、すべてのテストに合格しました。'],
|
|
21
|
+
['ko', '변경이 완료되었고 모든 테스트를 통과했습니다.'],
|
|
22
|
+
])('detects %s', (language, text) => {
|
|
23
|
+
expect(detectTextLanguage(text).language).toBe(language);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it.each([
|
|
27
|
+
['uk', 'Готово. Запушено.'],
|
|
28
|
+
['uk', 'Все ок'],
|
|
29
|
+
['uk', 'Добре, давай так зробимо'],
|
|
30
|
+
['ru', 'Хорошо, давай так и сделаем'],
|
|
31
|
+
['ru', 'Готово, всё запушено.'],
|
|
32
|
+
])('tells short %s phrases apart by letters', (language, text) => {
|
|
33
|
+
expect(detectTextLanguage(text).language).toBe(language);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('falls back to English for text without letters', () => {
|
|
37
|
+
expect(detectTextLanguage('1234 ... !!!').language).toBe('en');
|
|
38
|
+
expect(detectTextLanguage('').language).toBe('en');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('does not let a single quoted foreign word flip an English paragraph', () => {
|
|
42
|
+
const text = 'The façade of the building is the part that you see from the street, and it is not the same as the interior.';
|
|
43
|
+
expect(detectTextLanguage(text).language).toBe('en');
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('pickVoiceForLanguage', () => {
|
|
48
|
+
const voices = [
|
|
49
|
+
{ name: 'Samantha', locale: 'en_US' },
|
|
50
|
+
{ name: 'Daniel', locale: 'en_GB' },
|
|
51
|
+
{ name: 'Lesya', locale: 'uk_UA' },
|
|
52
|
+
{ name: 'Lesya (Enhanced)', locale: 'uk_UA' },
|
|
53
|
+
{ name: 'Milena', locale: 'ru_RU' },
|
|
54
|
+
{ name: 'Anna', locale: 'de_DE' },
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
it('prefers the enhanced variant of a matching voice', () => {
|
|
58
|
+
expect(pickVoiceForLanguage('uk', voices)).toBe('Lesya (Enhanced)');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('prefers the primary locale of a language', () => {
|
|
62
|
+
expect(pickVoiceForLanguage('en', voices)).toBe('Samantha');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('returns null when no voice speaks the language', () => {
|
|
66
|
+
expect(pickVoiceForLanguage('ja', voices)).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('languageOfLocale', () => {
|
|
71
|
+
it('reads the language subtag', () => {
|
|
72
|
+
expect(languageOfLocale('uk_UA')).toBe('uk');
|
|
73
|
+
expect(languageOfLocale('en-GB')).toBe('en');
|
|
74
|
+
expect(languageOfLocale(null)).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
package/server/lib/tts/routes.js
CHANGED
|
@@ -2,6 +2,8 @@ import express from 'express';
|
|
|
2
2
|
import { normalizeCustomOpenAIBaseURL } from './base-url.js';
|
|
3
3
|
import { summarizeText, sanitizeForTTS, sanitizeForNote } from '../text/summarization.js';
|
|
4
4
|
|
|
5
|
+
import { detectTextLanguage, languageOfLocale, pickVoiceForLanguage } from './language-detect.js';
|
|
6
|
+
|
|
5
7
|
export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
6
8
|
let ttsModulePromise = null;
|
|
7
9
|
const getTtsModule = async () => {
|
|
@@ -154,7 +156,8 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
|
154
156
|
// macOS 'say' command TTS speak endpoint
|
|
155
157
|
app.post('/api/tts/say/speak', async (req, res) => {
|
|
156
158
|
try {
|
|
157
|
-
const { text,
|
|
159
|
+
const { text, rate = 200, language, languageSample } = req.body || {};
|
|
160
|
+
let voice = typeof req.body?.voice === 'string' && req.body.voice.trim() ? req.body.voice.trim() : 'Samantha';
|
|
158
161
|
|
|
159
162
|
if (!text || typeof text !== 'string' || !text.trim()) {
|
|
160
163
|
return res.status(400).json({ error: 'Text is required' });
|
|
@@ -164,6 +167,23 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
|
164
167
|
if (process.platform !== 'darwin') {
|
|
165
168
|
return res.status(503).json({ error: 'macOS say command not available on this platform' });
|
|
166
169
|
}
|
|
170
|
+
|
|
171
|
+
// `language: 'auto'`: keep the chosen voice while it speaks the text's
|
|
172
|
+
// language, otherwise switch to an installed voice that does. A
|
|
173
|
+
// language with no installed voice keeps the chosen voice — say still
|
|
174
|
+
// reads the text, just with an accent — rather than failing.
|
|
175
|
+
let resolvedLanguage = null;
|
|
176
|
+
if (language === 'auto') {
|
|
177
|
+
const capability = await sayTTSCapability;
|
|
178
|
+
const voices = Array.isArray(capability?.voices) ? capability.voices : [];
|
|
179
|
+
const sample = typeof languageSample === 'string' && languageSample.trim() ? languageSample.slice(0, 4000) : text;
|
|
180
|
+
resolvedLanguage = detectTextLanguage(sample).language;
|
|
181
|
+
const chosen = voices.find((entry) => entry.name === voice);
|
|
182
|
+
if (languageOfLocale(chosen?.locale) !== resolvedLanguage) {
|
|
183
|
+
const match = pickVoiceForLanguage(resolvedLanguage, voices);
|
|
184
|
+
if (match) voice = match;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
167
187
|
|
|
168
188
|
const { exec } = await import('child_process');
|
|
169
189
|
const { promisify } = await import('util');
|
|
@@ -195,6 +215,8 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
|
|
|
195
215
|
|
|
196
216
|
// Send audio response
|
|
197
217
|
res.setHeader('Content-Type', 'audio/mp4');
|
|
218
|
+
res.setHeader('X-Speech-Voice', voice);
|
|
219
|
+
if (resolvedLanguage) res.setHeader('X-Speech-Language', resolvedLanguage);
|
|
198
220
|
res.setHeader('Content-Length', audioBuffer.length);
|
|
199
221
|
res.send(audioBuffer);
|
|
200
222
|
|
|
@@ -33,6 +33,32 @@ describe('tts routes', () => {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
+
it('switches the say voice to the language of the text when asked to', async () => {
|
|
37
|
+
const capability = Promise.resolve({
|
|
38
|
+
available: true,
|
|
39
|
+
voices: [
|
|
40
|
+
{ name: 'Samantha', locale: 'en_US' },
|
|
41
|
+
{ name: 'Lesya', locale: 'uk_UA' },
|
|
42
|
+
{ name: 'Lesya (Enhanced)', locale: 'uk_UA' },
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
const app = createApp(capability);
|
|
46
|
+
const response = await request(app)
|
|
47
|
+
.post('/api/tts/say/speak')
|
|
48
|
+
.send({ text: 'Привіт! Це відповідь українською мовою, і вона досить довга.', voice: 'Samantha', language: 'auto' });
|
|
49
|
+
|
|
50
|
+
// On macOS the route synthesizes; elsewhere it refuses before running say.
|
|
51
|
+
// Either way the chosen voice must be the Ukrainian one when the platform
|
|
52
|
+
// allows the request to proceed.
|
|
53
|
+
if (process.platform === 'darwin') {
|
|
54
|
+
expect(response.status).toBe(200);
|
|
55
|
+
expect(response.headers['x-speech-voice']).toBe('Lesya (Enhanced)');
|
|
56
|
+
expect(response.headers['x-speech-language']).toBe('uk');
|
|
57
|
+
} else {
|
|
58
|
+
expect(response.status).toBe(503);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
36
62
|
it('returns local note fallback while model summarization is retired', async () => {
|
|
37
63
|
const response = await request(createApp())
|
|
38
64
|
.post('/api/text/summarize')
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{R as o,j as n,f as be}from"./vendor-react-BUCujlKS.js";import{W as pn,a as at,u as te,F as Ge}from"./index-DIvDEKE-.js";import{f as we,V as Et,ab as hn,bo as gn,ad as xn,ac as bn,ae as wn,af as ae,y as vt,k as yn,hF as vn,hG as jn,hH as Sn,cB as Nn,t as Ke,hI as Fn,am as Be,B as me,I as A,h as le,a6 as kn,a7 as Cn,a8 as Dn,hs as Bt,hJ as Rn,fs as An,fx as $e,a0 as En,c0 as it,ao as Vt,al as Bn,a$ as Vn,b1 as Ln,fy as Tn,b2 as Mn}from"./useAppFontEffects-KP8_yiGW.js";import{c as _n,p as In}from"./vendor-zustand-BAGL70zf.js";import{P as On}from"./PierreDiffViewer-CY2bx_SB.js";import{u as zn,v as Pn,g as Gn,W as $n}from"./main-DLlfDjQ_.js";import{f as Kn}from"./patchFileDiff-CjRR5ESs.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DrTPkHl4.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./VirtualizedFileDiff-BP7ebDFF.js";import"./isDiffPlainText-ZBvDxhVB.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-HIjtuhxD.js";import"./runtimeEndpointReset-D6SmNZaP.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./useRootScrollLock-BSiQ5F75.js";import"./scheduledTasksApi-mjMDet_H.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";const Hn="openchamber.git-base-branch",Wn=100,He=(s,e)=>JSON.stringify([at(),s,e]),jt=_n()(In((s,e)=>({overrides:{},getOverride:(i,a)=>!i||!a?null:e().overrides[He(i,a)]??null,setOverride:(i,a,d)=>{!i||!a||!d||s(u=>{const p=He(i,a),g=Object.entries({...u.overrides,[p]:d});for(;g.length>Wn;)g.shift();return{overrides:Object.fromEntries(g)}})},clearOverride:(i,a)=>{!i||!a||s(d=>{const u=He(i,a);if(!(u in d.overrides))return d;const p={...d.overrides};return delete p[u],{overrides:p}})}}),{name:Hn,storage:pn(),partialize:s=>({overrides:s.overrides})})),Un=(s,e)=>!!s&&e!==null&&s!==e,qn=(s,e,i,a)=>i?s===null||a&&e===null?!0:e!==null&&s===e:!1,Xn=(s,e)=>s==="branch"&&!e?"working":s,Jn=(s,e,i)=>JSON.stringify([s,e,i]),Yn=(s,e,i,a,d,u)=>{const p=o.useRef({directory:"",attempts:0}),[g,f]=o.useState(()=>({directory:"",exhausted:!1})),m=o.useRef(d);m.current=d;const x=!!s&&g.directory===s&&g.exhausted;return o.useEffect(()=>{if(!s||!e||a||i)return;const c=p.current.directory===s?p.current.attempts:0;if(c>=u){g.directory===s&&g.exhausted||f({directory:s,exhausted:!0});return}p.current={directory:s,attempts:c+1},m.current()},[s,g,a,e,i,u]),x},Qn=(s,e,i,a)=>{const[d,u]=o.useState(()=>new Map),p=o.useRef(d);p.current=d;const g=o.useRef(i);g.current=i;const f=o.useCallback((m,x)=>{const c=new Map(p.current);if(x===null){if(!c.delete(m))return}else c.set(m,x);p.current=c,u(c)},[]);return o.useEffect(()=>{s&&(p.current=new Map,u(p.current))},[s]),o.useEffect(()=>{const m=g.current;if(!s||!m||!e)return;let x=!1;const c=new Set;for(const v of e.split("\0"))p.current.has(v)||(c.add(v),f(v,a),m(v).then(S=>{x||(c.delete(v),f(v,S))}).catch(()=>{x||(c.delete(v),f(v,null))}));return()=>{x=!0;for(const v of c)f(v,null)}},[e,a,s,f]),d},St=(s,e)=>{if(e.length===0)return null;let i=null,a=null;for(const u of e)u.top<=s?(!i||u.top>i.top)&&(i=u):(!a||u.top<a.top)&&(a=u);const d=i??a;return d?{path:d.path,topOffset:d.top-s}:null},Zn=(s,e,i,a)=>Math.min(Math.max(0,a),Math.max(0,s+i-e)),Nt=s=>{if(!s)return null;const e=s.split(`
|
|
2
|
-
`);let i=null;for(const a of e){const d=a.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(d){const u=Number.parseInt(d[1]??"",10);i=Number.isFinite(u)&&u>=1?u:null;continue}if(i!==null){if(a.startsWith(" ")){i+=1;continue}if(a.startsWith("+"))return i;if(a.startsWith("-"))return Math.max(1,i)}}return null},es=1100,ts=15e3,Ft=500,kt=300,ns=1e6,ss=3,rs=s=>s<=6?s:s<=12?6:s<=25?4:2,is={original:"",modified:"",isBinary:!1,contextMode:"patch"},os=3,as=o.memo(()=>{const s=be.c(4),{t:e}=we();let i;s[0]!==e?(i=e("diffView.binary.unavailable"),s[0]=e,s[1]=i):i=s[1];let a;return s[2]!==i?(a=n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:i})}),s[2]=i,s[3]=a):a=s[3],a}),Lt={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},ls=Lt.M,cs=s=>{const e=s.index?.trim(),i=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):i?i.charAt(0):e?.charAt(0)||i?.charAt(0)||"M"},Tt=s=>{const e=cs(s);return Lt[e]??ls},fs=s=>{const{index:e,working_dir:i}=s;return e==="A"||i==="A"||e==="?"||i==="?"},Ct=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Dt=s=>!!s.working_dir?.trim()||s.index==="?",us=(s,e)=>An(s,e),Rt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),At=(s,e)=>{const i=s.split(`
|
|
3
|
-
`),a=e.split(`
|
|
4
|
-
`),d=Math.min(i.length,a.length);for(let u=0;u<d;u+=1)if(i[u]!==a[u])return u+1;return a.length>i.length?i.length+1:i.length>a.length?Math.max(1,a.length):1},ds=s=>/^Binary files .+ differ$/m.test(s)||/^GIT binary patch$/m.test(s),ms=s=>Array.isArray(s)?s.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],ps=s=>s==="added"?"A":s==="deleted"?"D":"M",ot=(s,e,i)=>ds(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:i}:{original:"",modified:"",patch:e,fileDiff:Kn(s,e),contextMode:i},Mt=(s,e,i)=>{const a=s??0,d=e??0;return!a&&!d?null:n.jsxs("span",{className:le("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",i?.className),children:[a?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",a]}):null,d?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d]}):null]})},hs=o.memo(s=>{const e=be.c(58),{scope:i,workingCount:a,stagedCount:d,turnCount:u,branchCount:p,showBranchOption:g,onScopeChange:f}=s,{t:m}=we(),[x,c]=o.useState(!1),v=i==="staged"?d:i==="turn"?u:i==="branch"?p??0:a;let S;e[0]!==i||e[1]!==m?(S=m(i==="staged"?"diffView.scope.staged":i==="turn"?"diffView.scope.lastTurn":i==="branch"?"diffView.scope.branch":"diffView.scope.changed"),e[0]=i,e[1]=m,e[2]=S):S=e[2];const O=S;let T;e[3]!==m?(T=m("diffView.scope.selectorAria"),e[3]=m,e[4]=T):T=e[4];let ne;e[5]!==v?(ne=n.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",v]}),e[5]=v,e[6]=ne):ne=e[6];let y;e[7]!==O||e[8]!==ne?(y=n.jsxs("span",{className:"whitespace-nowrap",children:[O,ne]}),e[7]=O,e[8]=ne,e[9]=y):y=e[9];let V;e[10]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=V):V=e[10];let M;e[11]!==T||e[12]!==y?(M=n.jsx(Vn,{asChild:!0,children:n.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":T,children:[y,V]})}),e[11]=T,e[12]=y,e[13]=M):M=e[13];let q;e[14]!==f?(q=ie=>{(ie==="working"||ie==="staged"||ie==="turn"||ie==="branch")&&(f?.(ie),c(!1))},e[14]=f,e[15]=q):q=e[15];let X;e[16]!==m?(X=m("diffView.scope.changed"),e[16]=m,e[17]=X):X=e[17];let se;e[18]!==X?(se=n.jsx("span",{children:X}),e[18]=X,e[19]=se):se=e[19];let J;e[20]!==a?(J=n.jsx("span",{className:"typography-meta text-muted-foreground",children:a}),e[20]=a,e[21]=J):J=e[21];let Y;e[22]!==J||e[23]!==se?(Y=n.jsx($e,{value:"working",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[se,J]})}),e[22]=J,e[23]=se,e[24]=Y):Y=e[24];let C;e[25]!==m?(C=m("diffView.scope.staged"),e[25]=m,e[26]=C):C=e[26];let _;e[27]!==C?(_=n.jsx("span",{children:C}),e[27]=C,e[28]=_):_=e[28];let re;e[29]!==d?(re=n.jsx("span",{className:"typography-meta text-muted-foreground",children:d}),e[29]=d,e[30]=re):re=e[30];let L;e[31]!==_||e[32]!==re?(L=n.jsx($e,{value:"staged",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[_,re]})}),e[31]=_,e[32]=re,e[33]=L):L=e[33];let G;e[34]!==m?(G=m("diffView.scope.lastTurn"),e[34]=m,e[35]=G):G=e[35];let $;e[36]!==G?($=n.jsx("span",{children:G}),e[36]=G,e[37]=$):$=e[37];let E;e[38]!==u?(E=n.jsx("span",{className:"typography-meta text-muted-foreground",children:u}),e[38]=u,e[39]=E):E=e[39];let K;e[40]!==$||e[41]!==E?(K=n.jsx($e,{value:"turn",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[$,E]})}),e[40]=$,e[41]=E,e[42]=K):K=e[42];let Q;e[43]!==p||e[44]!==g||e[45]!==m?(Q=g?n.jsx($e,{value:"branch",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:m("diffView.scope.branch")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:p??"…"})]})}):null,e[43]=p,e[44]=g,e[45]=m,e[46]=Q):Q=e[46];let z;e[47]!==i||e[48]!==Y||e[49]!==L||e[50]!==K||e[51]!==Q||e[52]!==q?(z=n.jsx(Ln,{align:"start",className:"w-40",children:n.jsxs(Tn,{value:i,onValueChange:q,children:[Y,L,K,Q]})}),e[47]=i,e[48]=Y,e[49]=L,e[50]=K,e[51]=Q,e[52]=q,e[53]=z):z=e[53];let H;return e[54]!==x||e[55]!==z||e[56]!==M?(H=n.jsxs(Mn,{open:x,onOpenChange:c,children:[M,z]}),e[54]=x,e[55]=z,e[56]=M,e[57]=H):H=e[57],H}),gs=o.memo(s=>{const e=be.c(11),{changedFiles:i,selectedFile:a,onSelectFile:d}=s,{t:u}=we();if(i.length===0)return null;let p;if(e[0]!==i||e[1]!==d||e[2]!==a||e[3]!==u){let f;e[5]!==d||e[6]!==a||e[7]!==u?(f=m=>{const x=Tt(m),c=a===m.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>d(m.path),className:le("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",c?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(Vt,{filePath:m.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:x.color},title:u(x.descriptionKey),"aria-label":u(x.descriptionKey),children:x.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:m.path,children:m.path}),Mt(m.insertions,m.deletions)]})},m.path)},e[5]=d,e[6]=a,e[7]=u,e[8]=f):f=e[8],p=i.map(f),e[0]=i,e[1]=d,e[2]=a,e[3]=u,e[4]=p}else p=e[4];let g;return e[9]!==p?(g=n.jsx(it,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:p})}),e[9]=p,e[10]=g):g=e[10],g}),xs=o.memo(s=>{const e=be.c(20),{filePath:i,diff:a,renderSideBySide:d}=s,{t:u}=we(),p=a.original.length>0,g=a.modified.length>0,f=d?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",m=d?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x={contain:"layout"},e[0]=x):x=e[0];let c;e[1]!==a.original||e[2]!==i||e[3]!==p||e[4]!==m||e[5]!==d||e[6]!==u?(c=p&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u("diffView.image.original")}),n.jsx("img",{src:a.original,alt:u("diffView.image.originalAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=a.original,e[2]=i,e[3]=p,e[4]=m,e[5]=d,e[6]=u,e[7]=c):c=e[7];let v;e[8]!==a.modified||e[9]!==i||e[10]!==g||e[11]!==p||e[12]!==m||e[13]!==d||e[14]!==u?(v=g&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u(p?"diffView.image.modified":"diffView.image.new")}),n.jsx("img",{src:a.modified,alt:u("diffView.image.modifiedAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=a.modified,e[9]=i,e[10]=g,e[11]=p,e[12]=m,e[13]=d,e[14]=u,e[15]=v):v=e[15];let S;return e[16]!==f||e[17]!==c||e[18]!==v?(S=n.jsx("div",{className:"w-full overflow-auto p-4",style:x,children:n.jsxs("div",{className:f,children:[c,v]})}),e[16]=f,e[17]=c,e[18]=v,e[19]=S):S=e[19],S}),bs=o.memo(s=>{const e=be.c(16),{filePath:i,diff:a,renderSideBySide:d,wrapLines:u}=s;let p;e[0]!==i?(p=Bn(i)||"text",e[0]=i,e[1]=p):p=e[1];const g=p;if(a.isBinary){let x;return e[2]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(as,{}),e[2]=x):x=e[2],x}if(Be(i)){let x;return e[3]!==a||e[4]!==i||e[5]!==d?(x=n.jsx(xs,{filePath:i,diff:a,renderSideBySide:d}),e[3]=a,e[4]=i,e[5]=d,e[6]=x):x=e[6],x}let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f={contain:"layout"},e[7]=f):f=e[7];let m;return e[8]!==a.fileDiff||e[9]!==a.modified||e[10]!==a.original||e[11]!==i||e[12]!==g||e[13]!==d||e[14]!==u?(m=n.jsx("div",{className:"w-full",style:f,children:n.jsx(On,{original:a.original,modified:a.modified,fileDiff:a.fileDiff,language:g,fileName:i,renderSideBySide:d,wrapLines:u,layout:"inline"})}),e[8]=a.fileDiff,e[9]=a.modified,e[10]=a.original,e[11]=i,e[12]=g,e[13]=d,e[14]=u,e[15]=m):m=e[15],m}),ws=o.memo(s=>{const e=be.c(7),{filePath:i,staged:a,busyAction:d,disabled:u,onAction:p}=s,{t:g}=we();let f;return e[0]!==d||e[1]!==u||e[2]!==i||e[3]!==p||e[4]!==a||e[5]!==g?(f=n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:a?n.jsx(rt,{label:g("gitView.changes.unstageFileAria",{path:i}),icon:"arrow-go-back",loading:d==="unstage",disabled:u,onClick:()=>p("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx(rt,{label:g("gitView.changes.revertFileAria",{path:i}),icon:"arrow-go-back",loading:d==="discard",disabled:u,tone:"failure",onClick:()=>p("discard")}),n.jsx(rt,{label:g("gitView.changes.stageFileAria",{path:i}),icon:"add",loading:d==="stage",disabled:u,tone:"success",onClick:()=>p("stage")})]})}),e[0]=d,e[1]=u,e[2]=i,e[3]=p,e[4]=a,e[5]=g,e[6]=f):f=e[6],f}),rt=s=>{const e=be.c(14),{label:i,icon:a,loading:d,disabled:u,tone:p,onClick:g}=s,f=p==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",m=p==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let x;e[0]!==f||e[1]!==m?(x=le("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",f,m),e[0]=f,e[1]=m,e[2]=x):x=e[2];let c;e[3]!==g?(c=O=>{O.stopPropagation(),g()},e[3]=g,e[4]=c):c=e[4];let v;e[5]!==a||e[6]!==d?(v=d?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:a,className:a==="add"?"size-4":"size-3.5"}),e[5]=a,e[6]=d,e[7]=v):v=e[7];let S;return e[8]!==u||e[9]!==i||e[10]!==x||e[11]!==c||e[12]!==v?(S=n.jsx(me,{variant:"ghost",size:"sm",className:x,disabled:u,title:i,"aria-label":i,onClick:c,children:v}),e[8]=u,e[9]=i,e[10]=x,e[11]=c,e[12]=v,e[13]=S):S=e[13],S},ys=o.memo(({directory:s,file:e,layout:i,wrapLines:a,isSelected:d,isExpanded:u,isMounted:p,onSelect:g,onExpandedChange:f,registerSectionRef:m,showOpenInEditorAction:x=!1,isOpeningInEditor:c=!1,onOpenInEditor:v,staged:S=!1,loadFullFiles:O=!1,initialDiffData:T=null,readOnlyActions:ne=!1})=>{const{t:y}=we(),{git:V}=Et(),M=ae(o.useCallback(w=>w.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),q=ae(w=>w.setDiff),X=ae(w=>w.fetchStatus),se=te(w=>w.setDiffFileLayout),[J,Y]=o.useState(0),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(!1),[Q,z]=o.useState(null),[H,ie]=o.useState(null),ce=o.useRef(null),Ce=o.useRef(null),pe=o.useMemo(()=>Tt(e),[e]),Ve=i==="side-by-side",ye=O?"full":"patch",he=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,Z=o.useMemo(()=>T||(S?H:Q||(M?{original:M.original,modified:M.modified,isBinary:M.isBinary,contextMode:"full"}:null)),[M,T,Q,S,H]),De=Z?.contextMode===ye,b=o.useCallback(w=>{Ce.current=w,m(e.path,w)},[e.path,m]),ge=o.useCallback(w=>{f(e.path,w)},[e.path,f]),fe=o.useCallback(()=>{g(e.path)},[e.path,g]);o.useEffect(()=>{S?ie(null):z(null),_(null),ce.current=null},[he,S]),o.useEffect(()=>{if(!u||!p)return;if(!s||T||Z&&De){ce.current=null,L(!1);return}const w=`${s}::${e.path}::${S?"staged":"unstaged"}::${he}::${ye}::${J}`;if(ce.current===w)return;ce.current=w,_(null),L(!0);let D=!1;const de=at(),Le=O?ns:ss,Te=Be(e.path)?V.getGitFileDiff(s,{path:e.path,staged:S}):V.getGitDiff(s,{path:e.path,staged:S,contextLines:Le}),Me=ts,_e=new Promise((B,W)=>{setTimeout(()=>W(new Error(`Timed out after ${Me}ms`)),Me)});return Promise.race([Te,_e]).then(B=>{if(!D){if("diff"in B){const W=ot(e.path,B.diff,ye);S?ie(W):z(W)}else{const W={original:B.original??"",modified:B.modified??"",isBinary:B.isBinary,contextMode:"full"};S?ie(W):q(s,e.path,W,de)}L(!1)}}).catch(B=>{if(D)return;const W=B instanceof Error?B.message:String(B);_(W),L(!1)}),()=>{D=!0,ce.current===w&&(ce.current=null)}},[ye,Z,De,J,s,e.path,he,V,T,u,p,O,q,S]);const Re=o.useCallback(()=>{ge(!u),fe()},[ge,fe,u]),ue=o.useCallback(async w=>{if(!(!s||G!==null)){$(w);try{w==="stage"?await V.stageGitFile(s,e.path):w==="unstage"?await V.unstageGitFile(s,e.path):await V.revertGitFile(s,e.path,{scope:"working"}),Y(D=>D+1),await X(s,V)}catch(D){const de=w==="unstage"?"gitView.toast.unstageFileFailed":w==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";Ke.error(D instanceof Error?D.message:y(de))}finally{$(D=>D===w?null:D)}}},[s,X,e.path,G,V,y]);return n.jsxs("div",{ref:b,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[n.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:n.jsxs("div",{role:"button",tabIndex:0,onClick:Re,onKeyDown:w=>{w.target===w.currentTarget&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),Re())},className:le("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",d?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:u?n.jsx(A,{name:"arrow-down-s",className:"size-4"}):n.jsx(A,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:pe.color},title:y(pe.descriptionKey),"aria-label":y(pe.descriptionKey),children:pe.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Vt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const w=e.path.lastIndexOf("/");if(w===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const D=e.path.slice(0,w),de=e.path.slice(w+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:D}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:de})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[Mt(e.insertions,e.deletions),x&&v?n.jsx(me,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:y("diffView.actions.openFileInEditorAtChange"),onClick:w=>{w.stopPropagation(),v(e.path,Z)},disabled:c,children:c?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:"edit",className:"size-3.5"})}):null,n.jsx(Bt,{mode:Ve?"side-by-side":"unified",onModeChange:w=>{const D=w==="side-by-side"?"side-by-side":"inline";se(e.path,D)},className:"opacity-70"})]})]})}),u&&n.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!p&&!C?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,C?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.failedToLoadDiff")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:C}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Y(w=>w+1),children:y("diffView.actions.retry")})]}):null,p&&re&&!Z&&!C?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),y("diffView.state.loadingDiff")]}):null,p&&Z&&!E&&e.insertions+e.deletions>Ft?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:y("diffView.state.largeDiffDescription")}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>K(!0),children:y("diffView.actions.renderAnyway")})]}):null,p&&Z&&(E||e.insertions+e.deletions<=Ft)?n.jsxs(n.Fragment,{children:[n.jsx(bs,{filePath:e.path,diff:Z,renderSideBySide:Ve,wrapLines:a}),n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:ne?null:n.jsx(ws,{filePath:e.path,staged:S,busyAction:G,disabled:G!==null,onAction:ue})})})]}):null]})]})}),Mi=({hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,showOpenInEditorAction:a=!1,diffScope:d="all",onDiffScopeChange:u,targetFilePath:p=null,flushContent:g=!1})=>{const{t:f}=we(),{git:m,files:x}=Et(),c=hn(),v=te(t=>t.openContextSurface),S=zn(t=>t.requestSource),{screenWidth:O,isMobile:T}=gn(),ne=xn(c??null),y=bn(c??null),V=wn(c??null),M=ae(t=>t.setActiveDirectory),q=ae(t=>t.ensureStatus),X=ae(t=>t.fetchStatus),se=ae(t=>t.fetchBranches),J=ae(t=>t.clearDiffCache),Y=ae(t=>t.setDiff),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(()=>new Set),[Q,z]=o.useState(()=>new Set),[H,ie]=o.useState(!1),[ce,Ce]=o.useState(0),[pe,Ve]=o.useState(()=>new Map),[ye,he]=o.useState(!1),[Z,De]=o.useState(!1),[b,ge]=o.useState(d);o.useEffect(()=>{ge(d)},[d]);const fe=te(t=>t.pendingDiffFile),Re=te(t=>t.pendingDiffStaged),ue=te(t=>t.pendingDiffScope),w=te(t=>t.setPendingDiffFile),D=te(t=>t.diffLayoutPreference),de=te(t=>t.diffFileLayout),Le=te(t=>t.setDiffFileLayout),Te=te(t=>t.diffWrapLines),Me=te(t=>t.setDiffWrapLines),_e=te(t=>t.openContextFileAtLine),B=vt(t=>t.currentSessionId),W=yn(B??"",c??void 0),We=Te,Ue=b==="staged"?!0:b==="working"?!1:null,Ie=Ue??re,qe=T||O<=768,_t=!!B&&b!=="turn"&&!qe&&!Ge(),It=b!=="turn"&&!qe&&!Ge(),Ot=!s&&!qe&&O>=1024,ve=o.useRef(null),Ae=o.useRef(new Map),xe=o.useRef(null),P=o.useRef(null),je=o.useRef(!1),Se=o.useRef(null),lt=o.useRef(null),Xe=o.useRef(null),Je=o.useRef(null),ct=o.useCallback(()=>{const t=ve.current;if(!t)return null;const r=t.getBoundingClientRect().top,l=[];for(const[h,j]of Ae.current)j&&l.push({path:h,top:j.getBoundingClientRect().top});return St(r,l)},[]),Ne=o.useCallback(()=>{xe.current=null,je.current=!1,$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)},[]),Fe=o.useCallback(t=>{K(r=>{if(r.has(t))return r;const l=new Set(r);return l.add(t),l})},[]),Ee=o.useMemo(()=>{for(let t=W.length-1;t>=0;t-=1){const r=W[t];if(r.role==="user")return ms(r.summary?.diffs)}return[]},[W]),zt=o.useMemo(()=>{const t=new Map;for(const r of Ee)if(r.file){if(typeof r.patch=="string"){t.set(r.file,ot(r.file,r.patch,"patch"));continue}t.set(r.file,{original:r.before??"",modified:r.after??"",contextMode:"full"})}return t},[Ee]),Pt=o.useMemo(()=>y?.files?y.files.filter(Dt).length:0,[y]),Gt=o.useMemo(()=>y?.files?y.files.filter(Ct).length:0,[y]),$t=Ee.length,k=y?.current??null,ke=ae(t=>c?t.directories.get(c)?.branches??null:null),Kt=ae(t=>c?t.directories.get(c)?.isLoadingBranches??!1:!1),Ht=o.useCallback(()=>{c&&se(c,m)},[c,se,m]),Wt=Yn(c??null,ne!==!1,Kt,!!ke,Ht,os),ft=o.useMemo(()=>{const t=y?.tracking?.trim().split("/")[0];return(t&&ke?.defaultBranches?.[t])??ke?.defaultBranches?.origin??null},[ke,y?.tracking]),Ye=!Ge()&&Un(k,ft),Ut=y!==null,ut=Ge()||Wt||qn(k,ft,Ut,ke!==null),qt=jt(t=>t.setOverride),Xt=jt(o.useCallback(t=>c&&k?t.overrides[He(c,k)]??null:null,[k,c])),[Jt,Qe]=o.useState(null),[Yt,Ze]=o.useState(!1),[dt,Qt]=o.useState("");o.useEffect(()=>{const t=Xn(b,!ut);t!==b&&(ge(t),t==="working"&&u?.("working"))},[b,ut,u]),o.useEffect(()=>{if(!Ye||!c||!k){Qe(null),Ze(!1);return}let t=!1;return Ze(!1),vn(c,k).then(r=>{t||Qe(r.base)}).catch(()=>{t||Qe(null)}).finally(()=>{t||Ze(!0)}),()=>{t=!0}},[k,c,Ye]);const oe=Xt??Jt,[Oe,mt]=o.useState(null),[pt,ht]=o.useState(null),ze=o.useRef(0),et=o.useCallback(()=>{if(!c||!k||!oe)return;const t=ze.current+1;ze.current=t,mt(null),ht(null),jn(c,{base:oe,head:k}).then(r=>{ze.current===t&&mt(r)}).catch(r=>{ze.current===t&&ht(r instanceof Error?r.message:f("diffView.branch.loadError"))})},[oe,k,c,f]);o.useEffect(()=>{b==="branch"&&et()},[b,et]);const gt=b==="branch"&&c&&k&&oe?Jn(c,oe,k):null,Zt=o.useMemo(()=>b==="branch"?Array.from(E).sort().join("\0"):"",[b,E]),en=o.useCallback(t=>!c||!oe||!k?Promise.reject(new Error("branch range is unavailable")):Sn(c,{base:oe,head:k,path:t}).then(r=>ot(t,r.diff,"patch")),[oe,k,c]),tn=Qn(gt,Zt,gt?en:null,is),nn=Oe?.length??null,N=o.useMemo(()=>{if(b==="branch")return(Oe??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:0,deletions:0,isNew:l.status==="A"})).sort((l,h)=>l.path.localeCompare(h.path));if(b==="turn")return Ee.map(l=>({path:l.file??"",index:"",working_dir:ps(l.status),insertions:l.additions??0,deletions:l.deletions??0,isNew:l.status==="added"})).filter(l=>l.path).sort((l,h)=>l.path.localeCompare(h.path));if(!y?.files)return[];const t=y.diffStats??{},r=b==="staged"?Ct:b==="working"?Dt:()=>!0;return y.files.filter(r).map(l=>({...l,insertions:t[l.path]?.insertions??0,deletions:t[l.path]?.deletions??0,isNew:fs(l)})).sort((l,h)=>l.path.localeCompare(h.path))},[b,Oe,Ee,y]),tt=o.useMemo(()=>N.map(t=>t.path).join("\0"),[N]);o.useEffect(()=>{const t=tt?tt.split("\0"):[],r=new Set(t),l=`${c??""}:${b}:${e?"collapsed":"default"}`,h=lt.current!==l;lt.current=l,K(j=>{if(h){const R=e?0:rs(t.length);return new Set(t.slice(0,R))}let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j}),z(j=>{if(h)return new Set;let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j})},[b,tt,c,e]);const xt=o.useCallback(()=>{Se.current=null;const t=ve.current;if(!t)return;const r=t.getBoundingClientRect(),l=r.top-kt,h=r.bottom+kt,j={},I=[];for(const[F,R]of Ae.current){if(!R)continue;const U=R.getBoundingClientRect();I.push({path:F,top:U.top}),E.has(F)&&(U.bottom<l||U.top>h||(j[F]=!0))}Xe.current=St(r.top,I),z(F=>{let R=!1;const U=new Set(F);for(const yt of Object.keys(j))U.has(yt)||(U.add(yt),R=!0);return R?U:F})},[E]),ee=o.useCallback(()=>{typeof window>"u"||Se.current===null&&(Se.current=window.requestAnimationFrame(xt))},[xt]);o.useEffect(()=>{const t=ve.current;if(t)return ee(),t.addEventListener("scroll",ee,{passive:!0}),window.addEventListener("resize",ee),()=>{t.removeEventListener("scroll",ee),window.removeEventListener("resize",ee),Se.current!==null&&(window.cancelAnimationFrame(Se.current),Se.current=null)}},[N,E,ee]);const nt=o.useCallback(t=>{const r=de[t.path];if(r)return r;if(D==="inline")return"inline";if(D==="side-by-side")return"side-by-side";const l=O<es;return t.isNew||l?"inline":"side-by-side"},[de,D,O]),bt=o.useMemo(()=>N.length===0?null:N.every(t=>nt(t)==="side-by-side")?"side-by-side":"inline",[N,nt]);o.useEffect(()=>{c&&(M(c),q(c,m))},[c,M,q,m]),o.useEffect(()=>{if(c)return Nn.onGitRefreshHint(t=>{Rt(t.directory)===Rt(c)&&(t.paths?.length&&(Je.current=ct()??Xe.current,J(c,t.paths),Ve(r=>{const l=new Map(r);for(const h of t.paths??[])l.set(h,(l.get(h)??0)+1);return l})),X(c,m,{silent:!0}))})},[ct,J,c,X,m]),o.useLayoutEffect(()=>{const t=Je.current;if(!t)return;Je.current=null;const r=ve.current,l=Ae.current.get(t.path);if(!r||!l)return;const h=r.getBoundingClientRect().top,j=l.getBoundingClientRect().top-h;r.scrollTop=Zn(r.scrollTop,t.topOffset,j,r.scrollHeight-r.clientHeight),Xe.current=t},[pe]),o.useEffect(()=>{b!=="all"&&!ue||fe&&(ue&&ge(ue),_(fe),L(ue==="staged"||!ue&&Re),w(null),je.current=!0,xe.current=fe,Fe(fe),Ce(t=>t+1))},[b,Fe,fe,ue,Re,w]),o.useEffect(()=>{if(b==="all")return;const t=p?.trim();t&&(_(t),L(b==="staged"),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1))},[b,Fe,p]),o.useEffect(()=>{if(!C)return;N.some(r=>r.path===C)||(_(null),L(!1))},[N,C]);const sn=o.useCallback((t,r)=>{const l=Ae.current;r?l.set(t,r):l.delete(t),ee()},[ee]),rn=o.useCallback((t,r)=>{Ne(),K(l=>{const h=l.has(t);if(r===h)return l;const j=new Set(l);return r?j.add(t):j.delete(t),j}),r||z(l=>{if(!l.has(t))return l;const h=new Set(l);return h.delete(t),h}),ee()},[Ne,ee]),on=o.useCallback(()=>{Ne(),K(t=>t.size>0?new Set:new Set(N.map(r=>r.path))),z(new Set),ee()},[Ne,N,ee]),an=o.useCallback(async t=>{if(!B)return;const r=vt.getState().getDirectoryForSession(B)||c||"";if(!r){Ke.error(f("diffView.reviewDialog.toast.noSessionDirectory"));return}De(!0);try{await Fn({originalSessionID:B,directory:r,providerID:t.providerID,modelID:t.modelID,agent:t.agent||void 0,variant:t.variant||void 0,generateHandoff:t.generateHandoff,returnAfterHandoffRequest:t.generateHandoff,autoReview:t.autoReview}),he(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Ke.error(l instanceof Error?l.message:f("diffView.reviewDialog.toast.startFailed"))}finally{De(!1)}},[B,c,f]),Pe=o.useCallback(t=>{const r=Ae.current.get(t),l=ve.current;if(!r||!l)return!1;const h=r.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+h,behavior:"auto"}),!0},[]);o.useEffect(()=>{if(!xe.current)return;let r=0;const l=20;let h=!1;const j=(F=!0)=>{h||(h=!0,xe.current=null,je.current=!1,F&&$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null))},I=()=>{if(h){P.current=null;return}const F=xe.current;if(!F){j(),P.current=null;return}if(!Pe(F)){r+=1,r<l?P.current=window.requestAnimationFrame(I):(j(),P.current=null);return}if(i&&je.current){$(F),j(!1);return}j()};return P.current=window.requestAnimationFrame(I),()=>{h=!0,P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)}},[i,ce,Pe]);const ln=o.useCallback(t=>{},[]),st=o.useCallback(t=>{Ne(),_(t),L(!1),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1),Pe(t)},[Ne,Fe,Pe]);o.useEffect(()=>{const t=r=>{if(!r.altKey||r.metaKey||r.ctrlKey||r.shiftKey||r.key!=="ArrowDown"&&r.key!=="ArrowUp")return;const l=r.target;if(l instanceof HTMLElement&&(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.closest('[role="dialog"]'))||N.length===0)return;const h=r.key==="ArrowDown"?1:-1,j=C?N.findIndex(R=>R.path===C):-1,I=j===-1?h>0?0:N.length-1:j+h,F=N[I];F&&(r.preventDefault(),st(F.path))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[N,C,st]);const cn=o.useCallback(t=>{const r=t==="side-by-side"?"side-by-side":"inline";N.forEach(l=>{Le(l.path,r)})},[N,Le]),[fn,wt]=o.useState(null),un=o.useCallback(async(t,r)=>{if(!c||!t)return;wt(t);const l=at();try{let h=null;if(r?.patch&&!r.isBinary&&!Be(t)?h=Nt(r.patch):r&&r.contextMode==="full"&&!r.isBinary&&!Be(t)&&(h=At(r.original,r.modified)),h===null)try{const U=await m.getGitDiff(c,{path:t,staged:Ie,contextLines:3});h=Nt(U.diff)}catch{h=null}let j=r;if(h===null||!j){const U=await m.getGitFileDiff(c,{path:t,staged:Ie});j={original:U.original??"",modified:U.modified??"",isBinary:U.isBinary},Ie||Y(c,t,j,l)}const I=h??(j.isBinary||Be(t)?1:At(j.original,j.modified)),F=us(c,t),R=await Pn(x,F,{directory:c});if(!R.ok){Ke.error(Gn(R.reason));return}_e(c,F,I,1)}finally{wt(h=>h===t?null:h)}},[Ie,c,x,m,_e,Y]),dn=()=>{if(!c)return null;const t=r=>Ue!==null?Ue:re&&r===C;return n.jsxs("div",{className:le("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Ot&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:f("diffView.section.files")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length})]}),n.jsx(gs,{changedFiles:N,selectedFile:null,onSelectFile:st})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(it,{ref:ve,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:N.map(r=>n.jsx(ys,{directory:c,file:r,layout:nt(r),wrapLines:We,isSelected:!1,isExpanded:E.has(r.path),isMounted:Q.has(r.path)||r.path===G,onSelect:ln,onExpandedChange:rn,registerSectionRef:sn,showOpenInEditorAction:a&&b!=="turn",isOpeningInEditor:fn===r.path,onOpenInEditor:(l,h)=>{un(l,h)},staged:t(r.path),loadFullFiles:H,readOnlyActions:b==="branch",initialDiffData:b==="turn"?zt.get(r.path)??null:b==="branch"?tn.get(r.path)??null:null},`${r.path}:${pe.get(r.path)??0}`))})})})]})},mn=()=>{if(!c)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.selectSessionDirectory")});if(b!=="turn"&&V&&!y)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.state.loadingRepositoryStatus")]});if(b!=="turn"&&ne===!1)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.notGitRepository")});if(b==="branch"){if(!Yt)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.resolvingBase")]});if(!oe){const t=(ke?.all??[]).map(l=>l.replace(/^remotes\//,"")).filter(l=>l!==k&&!l.endsWith(`/${k}`)).sort(),r=En(t,dt,l=>[l]);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx(A,{name:"git-branch",className:"size-6 text-muted-foreground"}),n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.noBaseTitle")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:f("diffView.branch.noBaseDescription")}),n.jsx("input",{type:"text",value:dt,onChange:l=>Qt(l.target.value),placeholder:f("gitView.branch.searchPlaceholder"),"aria-label":f("gitView.branch.searchPlaceholder"),className:"w-full max-w-sm rounded-md border border-border/60 bg-[var(--surface-elevated)] px-2.5 py-1.5 typography-meta text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"}),n.jsx(it,{outerClassName:"max-h-48 w-full max-w-sm min-h-0",className:"px-1 py-1",children:r.length===0?n.jsx("div",{className:"px-2 py-3 typography-meta text-muted-foreground",children:f("gitView.branch.empty")}):n.jsx("div",{className:"flex flex-col gap-0.5",children:r.map(l=>n.jsxs("button",{type:"button",onClick:()=>c&&k&&qt(c,k,l),className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[n.jsx(A,{name:"git-branch",className:"size-3.5 text-primary"}),n.jsx("span",{className:"truncate typography-ui-label text-foreground",title:l,children:l})]},l))})})]})}if(pt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.loadError")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:pt}),n.jsx(me,{variant:"outline",size:"sm",onClick:()=>et(),children:f("diffView.actions.retry")})]});if(Oe===null)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.loadingFiles")]})}return N.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:b==="turn"?f("diffView.state.noLastTurnChanges"):b==="branch"&&oe?f("diffView.branch.empty",{base:oe}):f("diffView.state.cleanWorkingTree")}):dn()};return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!T&&(b==="working"||b==="staged"||b==="turn"||b==="branch"?n.jsx(hs,{scope:b,workingCount:Pt,stagedCount:Gt,turnCount:$t,branchCount:nn,showBranchOption:Ye,onScopeChange:t=>{ge(t),u?.(t)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:V&&!y?f("diffView.state.loadingChanges"):N.length===1?f("diffView.summary.changedFilesSingle",{count:N.length}):f("diffView.summary.changedFilesPlural",{count:N.length})})})),N.length>0&&n.jsxs(me,{variant:"ghost",size:"sm",onClick:on,className:le("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll"),children:[n.jsx(A,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll")})]}),N.length>0&&_t&&n.jsxs(me,{variant:"default",size:"sm",onClick:()=>he(!0),disabled:Z,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":f("diffView.actions.reviewAria"),children:[Z?n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):n.jsx(A,{name:"search-eye",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:f("diffView.actions.review")})]}),N.length>0&&It&&n.jsxs(me,{variant:"outline",size:"sm",onClick:()=>{const t=c??"";S(t,{kind:"working-tree",scope:b==="staged"||b==="working"?b:"all"}),v(t,"walkthrough")},className:le("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",$n),"aria-label":f("walkthrough.action.open"),children:[n.jsx(A,{name:"route",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:f("walkthrough.action.open")})]}),N.length>0&&n.jsxs(kn,{children:[n.jsx(Cn,{asChild:!0,children:n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>ie(t=>!t),"aria-pressed":H,"aria-label":f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:le("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",H&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(A,{name:"file-download",className:"size-4"})})}),n.jsx(Dn,{children:n.jsx("p",{children:f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),N.length>0&&n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>Me(!Te),className:le("h-5 w-5 p-0 transition-opacity",We?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:f(We?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:n.jsx(A,{name:"text-wrap",className:"size-4"})}),bt&&n.jsx(Bt,{mode:bt==="side-by-side"?"side-by-side":"unified",onModeChange:cn})]}),n.jsx(Rn,{open:ye,onOpenChange:he,projectDirectory:c??null,submitting:Z,onConfirm:an}),mn()]})};export{Mi as DiffView};
|