@agy-daddy/plugin-chat-nav 0.0.0-stage → 1.0.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/LICENSE +22 -0
- package/NOTICE +6 -0
- package/README.md +2 -2
- package/agy-plugin.json +59 -0
- package/baseline.json +8 -0
- package/locales/en.json +10 -0
- package/locales/zh-CN.json +10 -0
- package/package.json +30 -4
- package/settings.schema.json +105 -0
- package/src/conversation-export.js +776 -0
- package/src/file-service.js +158 -0
- package/src/node.js +465 -0
- package/src/renderer.js +1817 -0
- package/src/styles.js +426 -0
|
@@ -0,0 +1,776 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const crypto = require('crypto');
|
|
7
|
+
const { execFile } = require('child_process');
|
|
8
|
+
const { pathToFileURL } = require('url');
|
|
9
|
+
const { expandHomePath } = require('./file-service');
|
|
10
|
+
|
|
11
|
+
const EXPORT_FORMATS = Object.freeze(['md', 'html', 'pdf']);
|
|
12
|
+
|
|
13
|
+
function isTestEnv() {
|
|
14
|
+
return process.env.AGY_DADDY_TEST_MODE === '1' || process.env.NODE_ENV === 'test';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function normalizeExportFormat(raw) {
|
|
18
|
+
const s = String(raw || '').trim().toLowerCase();
|
|
19
|
+
if (s === 'markdown') return 'md';
|
|
20
|
+
if (EXPORT_FORMATS.includes(s)) return s;
|
|
21
|
+
return 'md';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function normalizeExportFormats(raw) {
|
|
25
|
+
const arr = Array.isArray(raw) ? raw : (typeof raw === 'string' ? [raw] : []);
|
|
26
|
+
const out = [];
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
for (const item of arr) {
|
|
29
|
+
let val = '';
|
|
30
|
+
if (typeof item === 'string') val = item.trim();
|
|
31
|
+
else if (item && typeof item === 'object') val = String(item.id || item.value || '').trim();
|
|
32
|
+
const norm = val.toLowerCase() === 'markdown' ? 'md' : val.toLowerCase();
|
|
33
|
+
if (!EXPORT_FORMATS.includes(norm) || seen.has(norm)) continue;
|
|
34
|
+
seen.add(norm);
|
|
35
|
+
out.push(norm);
|
|
36
|
+
}
|
|
37
|
+
return out.length > 0 ? out : ['md'];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ensureFileExtension(filePath, format = 'md') {
|
|
41
|
+
const clean = String(filePath || '').trim();
|
|
42
|
+
if (!clean) return '';
|
|
43
|
+
const fmt = normalizeExportFormat(format);
|
|
44
|
+
const ext = `.${fmt}`;
|
|
45
|
+
if (clean.toLowerCase().endsWith(ext)) return clean;
|
|
46
|
+
return `${clean}${ext}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getDefaultBrainDir(options = {}) {
|
|
50
|
+
if (options.brainDir) return path.resolve(options.brainDir);
|
|
51
|
+
if (process.env.AGY_DADDY_BRAIN_DIR) return path.resolve(process.env.AGY_DADDY_BRAIN_DIR);
|
|
52
|
+
return path.join(options.homeDir || os.homedir(), '.gemini', 'antigravity', 'brain');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function listBrainSessions(options = {}) {
|
|
56
|
+
const dir = getDefaultBrainDir(options);
|
|
57
|
+
if (!dir || !fs.existsSync(dir)) return [];
|
|
58
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
59
|
+
return entries
|
|
60
|
+
.filter((e) => e.isDirectory() && /^[a-z0-9-]{8,}$/i.test(e.name))
|
|
61
|
+
.map((e) => {
|
|
62
|
+
const full = path.join(dir, e.name);
|
|
63
|
+
let mtimeMs = 0;
|
|
64
|
+
try { mtimeMs = fs.statSync(full).mtimeMs; } catch {}
|
|
65
|
+
return { id: e.name, path: full, mtimeMs };
|
|
66
|
+
})
|
|
67
|
+
.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function pickLatestCascadeId(summariesObj = {}) {
|
|
71
|
+
if (!summariesObj || typeof summariesObj !== 'object') return null;
|
|
72
|
+
const entries = Object.entries(summariesObj);
|
|
73
|
+
if (!entries.length) return null;
|
|
74
|
+
entries.sort((a, b) => {
|
|
75
|
+
const tA = Date.parse(a[1]?.lastModifiedTime || a[1]?.updatedAt || a[1]?.createdTime || 0) || 0;
|
|
76
|
+
const tB = Date.parse(b[1]?.lastModifiedTime || b[1]?.updatedAt || b[1]?.createdTime || 0) || 0;
|
|
77
|
+
return tB - tA;
|
|
78
|
+
});
|
|
79
|
+
return entries[0][0] || null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sanitizeFilenamePart(raw, maxLen = 48) {
|
|
83
|
+
const clean = String(raw || '')
|
|
84
|
+
.trim()
|
|
85
|
+
.replace(/[<>:"/\\|?*\x00-\x1f]+/g, '-')
|
|
86
|
+
.replace(/\s+/g, '-')
|
|
87
|
+
.replace(/-+/g, '-')
|
|
88
|
+
.replace(/^-+|-+$/g, '');
|
|
89
|
+
if (!clean) return '';
|
|
90
|
+
return Array.from(clean).slice(0, maxLen).join('');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function buildExportFilename(meta = {}) {
|
|
94
|
+
const d = meta.date instanceof Date ? meta.date : new Date();
|
|
95
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
96
|
+
const stamp = `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
97
|
+
const slug = sanitizeFilenamePart(meta.title, 40)
|
|
98
|
+
|| sanitizeFilenamePart(String(meta.cascadeId || '').slice(0, 8), 16)
|
|
99
|
+
|| 'conversation';
|
|
100
|
+
const fmt = normalizeExportFormat(meta.format || 'md');
|
|
101
|
+
return `antigravity-${slug}-${stamp}.${fmt}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function normalizeDomMessagesToSteps(domMessages = []) {
|
|
105
|
+
if (!Array.isArray(domMessages)) return [];
|
|
106
|
+
const steps = [];
|
|
107
|
+
for (const msg of domMessages) {
|
|
108
|
+
if (!msg || typeof msg !== 'object') continue;
|
|
109
|
+
const text = String(msg.text || '').trim();
|
|
110
|
+
if (!text) continue;
|
|
111
|
+
if (msg.role === 'user') {
|
|
112
|
+
steps.push({ userInput: { userResponse: text } });
|
|
113
|
+
} else if (msg.role === 'assistant') {
|
|
114
|
+
steps.push({ plannerResponse: { response: text } });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return steps;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function exportConversationMarkdown(steps = [], meta = {}) {
|
|
121
|
+
const title = String(meta.title || meta.cascadeId || 'Antigravity Conversation').trim();
|
|
122
|
+
const lines = [`# ${title}`, ''];
|
|
123
|
+
if (meta.cascadeId) lines.push(`- Session ID: \`${meta.cascadeId}\``);
|
|
124
|
+
if (meta.model) lines.push(`- Model: \`${meta.model}\``);
|
|
125
|
+
lines.push('');
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < (Array.isArray(steps) ? steps.length : 0); i++) {
|
|
128
|
+
const s = steps[i] || {};
|
|
129
|
+
if (s.userInput) {
|
|
130
|
+
const text = s.userInput.userResponse || (s.userInput.items || []).map((it) => it.text || '').join('\n');
|
|
131
|
+
lines.push(`## Turn ${i + 1} · User`, '', String(text || '').trim(), '');
|
|
132
|
+
} else if (s.plannerResponse) {
|
|
133
|
+
const thinking = String(s.plannerResponse.thinking || '').trim();
|
|
134
|
+
const resp = String(s.plannerResponse.modifiedResponse || s.plannerResponse.response || '').trim();
|
|
135
|
+
lines.push(`## Turn ${i + 1} · Assistant`, '');
|
|
136
|
+
if (thinking) {
|
|
137
|
+
lines.push('<details><summary>Thinking</summary>', '', thinking, '', '</details>', '');
|
|
138
|
+
}
|
|
139
|
+
if (resp) lines.push(resp, '');
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return lines.join('\n').trim() + '\n';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function escapeHtml(raw) {
|
|
146
|
+
return String(raw ?? '')
|
|
147
|
+
.replace(/&/g, '&')
|
|
148
|
+
.replace(/</g, '<')
|
|
149
|
+
.replace(/>/g, '>')
|
|
150
|
+
.replace(/"/g, '"')
|
|
151
|
+
.replace(/'/g, ''');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function isSafeLinkHref(href) {
|
|
155
|
+
const trimmed = String(href || '').trim();
|
|
156
|
+
return /^(?:https?:\/\/[^\s"'<>]+|mailto:[^\s"'<>]+)$/i.test(trimmed);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function renderInlineMarkdownToHtml(rawLine) {
|
|
160
|
+
const codeTokens = [];
|
|
161
|
+
const withCodePlaceholders = String(rawLine ?? '').replace(/`([^`\n]+)`/g, (_, code) => {
|
|
162
|
+
const idx = codeTokens.length;
|
|
163
|
+
codeTokens.push(`<code>${escapeHtml(code)}</code>`);
|
|
164
|
+
return `\x00CODE_${idx}\x00`;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
let escaped = escapeHtml(withCodePlaceholders);
|
|
168
|
+
escaped = escaped.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (_, label, url) => {
|
|
169
|
+
if (!isSafeLinkHref(url)) return label;
|
|
170
|
+
return `<a href="${escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${label}</a>`;
|
|
171
|
+
});
|
|
172
|
+
escaped = escaped.replace(/\*\*([^*\n]+)\*\*/g, '<strong>$1</strong>');
|
|
173
|
+
escaped = escaped.replace(/(^|[^\*])\*([^*\n]+)\*/g, '$1<em>$2</em>');
|
|
174
|
+
escaped = escaped.replace(/\x00CODE_(\d+)\x00/g, (_, i) => codeTokens[Number(i)] || '');
|
|
175
|
+
return escaped;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function renderMarkdownBlockToHtml(markdownText) {
|
|
179
|
+
const src = String(markdownText ?? '').replace(/\r\n/g, '\n');
|
|
180
|
+
if (!src.trim()) return '';
|
|
181
|
+
const lines = src.split('\n');
|
|
182
|
+
const chunks = [];
|
|
183
|
+
let inCodeFence = false;
|
|
184
|
+
let codeLang = '';
|
|
185
|
+
let codeLines = [];
|
|
186
|
+
let listType = '';
|
|
187
|
+
let listItems = [];
|
|
188
|
+
|
|
189
|
+
const flushList = () => {
|
|
190
|
+
if (!listItems.length) return;
|
|
191
|
+
const tag = listType === 'ol' ? 'ol' : 'ul';
|
|
192
|
+
chunks.push(`<${tag}>${listItems.map((it) => `<li>${it}</li>`).join('')}</${tag}>`);
|
|
193
|
+
listItems = [];
|
|
194
|
+
listType = '';
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
const fenceMatch = line.match(/^```([a-zA-Z0-9_-]*)\s*$/);
|
|
199
|
+
if (fenceMatch) {
|
|
200
|
+
flushList();
|
|
201
|
+
if (!inCodeFence) {
|
|
202
|
+
inCodeFence = true;
|
|
203
|
+
codeLang = fenceMatch[1] || '';
|
|
204
|
+
codeLines = [];
|
|
205
|
+
} else {
|
|
206
|
+
const langAttr = codeLang ? ` data-lang="${escapeHtml(codeLang)}"` : '';
|
|
207
|
+
chunks.push(`<pre><code${langAttr}>${escapeHtml(codeLines.join('\n'))}</code></pre>`);
|
|
208
|
+
inCodeFence = false;
|
|
209
|
+
codeLang = '';
|
|
210
|
+
codeLines = [];
|
|
211
|
+
}
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (inCodeFence) {
|
|
216
|
+
codeLines.push(line);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const ulMatch = line.match(/^\s*[-*]\s+(.+)$/);
|
|
221
|
+
if (ulMatch) {
|
|
222
|
+
if (listType && listType !== 'ul') flushList();
|
|
223
|
+
listType = 'ul';
|
|
224
|
+
listItems.push(renderInlineMarkdownToHtml(ulMatch[1]));
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const olMatch = line.match(/^\s*\d+\.\s+(.+)$/);
|
|
228
|
+
if (olMatch) {
|
|
229
|
+
if (listType && listType !== 'ol') flushList();
|
|
230
|
+
listType = 'ol';
|
|
231
|
+
listItems.push(renderInlineMarkdownToHtml(olMatch[1]));
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
flushList();
|
|
235
|
+
|
|
236
|
+
if (!line.trim()) continue;
|
|
237
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
238
|
+
if (headingMatch) {
|
|
239
|
+
const level = Math.min(6, headingMatch[1].length);
|
|
240
|
+
chunks.push(`<h${level}>${renderInlineMarkdownToHtml(headingMatch[2])}</h${level}>`);
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const quoteMatch = line.match(/^>\s?(.*)$/);
|
|
244
|
+
if (quoteMatch) {
|
|
245
|
+
chunks.push(`<blockquote>${renderInlineMarkdownToHtml(quoteMatch[1])}</blockquote>`);
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
chunks.push(`<p>${renderInlineMarkdownToHtml(line)}</p>`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (inCodeFence) {
|
|
252
|
+
const langAttr = codeLang ? ` data-lang="${escapeHtml(codeLang)}"` : '';
|
|
253
|
+
chunks.push(`<pre><code${langAttr}>${escapeHtml(codeLines.join('\n'))}</code></pre>`);
|
|
254
|
+
}
|
|
255
|
+
flushList();
|
|
256
|
+
return chunks.join('\n');
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function exportConversationHtml(steps = [], meta = {}) {
|
|
260
|
+
const title = String(meta.title || meta.cascadeId || 'Antigravity Conversation').trim();
|
|
261
|
+
const expandThinking = Boolean(meta.expandThinking);
|
|
262
|
+
const metaPills = [];
|
|
263
|
+
if (meta.cascadeId) metaPills.push(`<span class="meta-pill">Session ID: <code>${escapeHtml(meta.cascadeId)}</code></span>`);
|
|
264
|
+
if (meta.model) metaPills.push(`<span class="meta-pill">Model: <code>${escapeHtml(meta.model)}</code></span>`);
|
|
265
|
+
const exportedAt = (meta.date instanceof Date ? meta.date : new Date()).toISOString();
|
|
266
|
+
metaPills.push(`<span class="meta-pill">Exported: <code>${escapeHtml(exportedAt)}</code></span>`);
|
|
267
|
+
|
|
268
|
+
const turnHtml = [];
|
|
269
|
+
for (let i = 0; i < (Array.isArray(steps) ? steps.length : 0); i++) {
|
|
270
|
+
const s = steps[i] || {};
|
|
271
|
+
if (s.userInput) {
|
|
272
|
+
const text = s.userInput.userResponse || (s.userInput.items || []).map((it) => it.text || '').join('\n');
|
|
273
|
+
turnHtml.push(
|
|
274
|
+
`<section class="turn turn-user">` +
|
|
275
|
+
`<header class="turn-head"><span class="role-badge role-user">Turn ${i + 1} · User</span></header>` +
|
|
276
|
+
`<div class="turn-body">${renderMarkdownBlockToHtml(String(text || '').trim())}</div>` +
|
|
277
|
+
`</section>`
|
|
278
|
+
);
|
|
279
|
+
} else if (s.plannerResponse) {
|
|
280
|
+
const thinking = String(s.plannerResponse.thinking || '').trim();
|
|
281
|
+
const resp = String(s.plannerResponse.modifiedResponse || s.plannerResponse.response || '').trim();
|
|
282
|
+
const detailsAttrs = expandThinking ? 'class="thinking-box" open' : 'class="thinking-box"';
|
|
283
|
+
const thinkingBlock = thinking
|
|
284
|
+
? `<details ${detailsAttrs}><summary>Thinking</summary><div class="thinking-body">${renderMarkdownBlockToHtml(thinking)}</div></details>`
|
|
285
|
+
: '';
|
|
286
|
+
turnHtml.push(
|
|
287
|
+
`<section class="turn turn-assistant">` +
|
|
288
|
+
`<header class="turn-head"><span class="role-badge role-assistant">Turn ${i + 1} · Assistant</span></header>` +
|
|
289
|
+
`${thinkingBlock}` +
|
|
290
|
+
`<div class="turn-body">${renderMarkdownBlockToHtml(resp)}</div>` +
|
|
291
|
+
`</section>`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return `<!DOCTYPE html>
|
|
297
|
+
<html lang="zh-CN">
|
|
298
|
+
<head>
|
|
299
|
+
<meta charset="utf-8" />
|
|
300
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
301
|
+
<title>${escapeHtml(title)}</title>
|
|
302
|
+
<style>
|
|
303
|
+
:root {
|
|
304
|
+
color-scheme: light;
|
|
305
|
+
--bg: #ffffff;
|
|
306
|
+
--surface: #f8fafc;
|
|
307
|
+
--border: #e4e4e7;
|
|
308
|
+
--text: #18181b;
|
|
309
|
+
--muted: #71717a;
|
|
310
|
+
--code-bg: #f4f4f5;
|
|
311
|
+
--accent: #3f3f46;
|
|
312
|
+
}
|
|
313
|
+
* { box-sizing: border-box; }
|
|
314
|
+
body {
|
|
315
|
+
margin: 0;
|
|
316
|
+
padding: 32px 20px;
|
|
317
|
+
background: var(--bg);
|
|
318
|
+
color: var(--text);
|
|
319
|
+
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
|
|
320
|
+
font-size: 14px;
|
|
321
|
+
line-height: 1.65;
|
|
322
|
+
}
|
|
323
|
+
main { max-width: 860px; margin: 0 auto; }
|
|
324
|
+
.doc-header { padding-bottom: 18px; margin-bottom: 24px; border-bottom: 1px solid var(--border); }
|
|
325
|
+
.doc-title { margin: 0 0 10px 0; font-size: 22px; font-weight: 700; color: var(--text); }
|
|
326
|
+
.doc-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--muted); }
|
|
327
|
+
.meta-pill { padding: 3px 9px; border-radius: 999px; background: var(--code-bg); border: 1px solid var(--border); }
|
|
328
|
+
.turn {
|
|
329
|
+
margin-bottom: 18px;
|
|
330
|
+
padding: 16px 18px;
|
|
331
|
+
border-radius: 12px;
|
|
332
|
+
border: 1px solid var(--border);
|
|
333
|
+
background: var(--bg);
|
|
334
|
+
break-inside: avoid;
|
|
335
|
+
}
|
|
336
|
+
.turn-user { background: var(--surface); }
|
|
337
|
+
.turn-head { margin-bottom: 10px; }
|
|
338
|
+
.role-badge {
|
|
339
|
+
display: inline-block;
|
|
340
|
+
padding: 2px 9px;
|
|
341
|
+
border-radius: 999px;
|
|
342
|
+
font-size: 11.5px;
|
|
343
|
+
font-weight: 600;
|
|
344
|
+
background: var(--code-bg);
|
|
345
|
+
color: var(--accent);
|
|
346
|
+
border: 1px solid var(--border);
|
|
347
|
+
}
|
|
348
|
+
.role-user { background: #18181b; color: #ffffff; border-color: #18181b; }
|
|
349
|
+
.turn-body p { margin: 0 0 10px 0; }
|
|
350
|
+
.turn-body p:last-child { margin-bottom: 0; }
|
|
351
|
+
.turn-body h1, .turn-body h2, .turn-body h3, .turn-body h4 { margin: 14px 0 8px 0; line-height: 1.35; }
|
|
352
|
+
.turn-body ul, .turn-body ol { margin: 6px 0 10px 0; padding-left: 22px; }
|
|
353
|
+
.turn-body blockquote {
|
|
354
|
+
margin: 8px 0;
|
|
355
|
+
padding: 6px 12px;
|
|
356
|
+
border-left: 3px solid var(--border);
|
|
357
|
+
color: var(--muted);
|
|
358
|
+
background: var(--surface);
|
|
359
|
+
}
|
|
360
|
+
code {
|
|
361
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
|
362
|
+
font-size: 12.5px;
|
|
363
|
+
padding: 1px 5px;
|
|
364
|
+
border-radius: 5px;
|
|
365
|
+
background: var(--code-bg);
|
|
366
|
+
}
|
|
367
|
+
pre {
|
|
368
|
+
margin: 10px 0;
|
|
369
|
+
padding: 12px 14px;
|
|
370
|
+
border-radius: 8px;
|
|
371
|
+
background: var(--code-bg);
|
|
372
|
+
border: 1px solid var(--border);
|
|
373
|
+
overflow-x: auto;
|
|
374
|
+
white-space: pre-wrap;
|
|
375
|
+
word-break: break-word;
|
|
376
|
+
}
|
|
377
|
+
pre code { padding: 0; background: transparent; }
|
|
378
|
+
.thinking-box {
|
|
379
|
+
margin: 8px 0 12px 0;
|
|
380
|
+
padding: 8px 12px;
|
|
381
|
+
border-radius: 8px;
|
|
382
|
+
border: 1px dashed var(--border);
|
|
383
|
+
background: var(--surface);
|
|
384
|
+
}
|
|
385
|
+
.thinking-box summary { cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); }
|
|
386
|
+
.thinking-body { margin-top: 8px; font-size: 13px; color: var(--muted); }
|
|
387
|
+
a { color: #27272a; text-decoration: underline; }
|
|
388
|
+
@media print {
|
|
389
|
+
body { padding: 0; }
|
|
390
|
+
.turn { border-color: #d4d4d8; break-inside: auto; }
|
|
391
|
+
.thinking-box { break-inside: auto; }
|
|
392
|
+
pre { page-break-inside: avoid; }
|
|
393
|
+
}
|
|
394
|
+
</style>
|
|
395
|
+
</head>
|
|
396
|
+
<body>
|
|
397
|
+
<main>
|
|
398
|
+
<header class="doc-header">
|
|
399
|
+
<h1 class="doc-title">${escapeHtml(title)}</h1>
|
|
400
|
+
<div class="doc-meta">${metaPills.join('')}</div>
|
|
401
|
+
</header>
|
|
402
|
+
${turnHtml.join('\n ') || '<p style="color:#71717a;">(Empty conversation)</p>'}
|
|
403
|
+
</main>
|
|
404
|
+
</body>
|
|
405
|
+
</html>
|
|
406
|
+
`;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function escapePdfLiteral(str) {
|
|
410
|
+
return String(str ?? '')
|
|
411
|
+
.replace(/[^\x20-\x7e]/g, '?')
|
|
412
|
+
.replace(/\\/g, '\\\\')
|
|
413
|
+
.replace(/\(/g, '\\(')
|
|
414
|
+
.replace(/\)/g, '\\)');
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function buildMinimalPdfBuffer(text = '', meta = {}) {
|
|
418
|
+
const titleLine = String(meta.title || meta.cascadeId || 'Antigravity Conversation').trim();
|
|
419
|
+
const rawText = String(text || '').replace(/\r\n/g, '\n');
|
|
420
|
+
const rawLines = rawText ? rawText.split('\n') : [titleLine];
|
|
421
|
+
const wrapped = [];
|
|
422
|
+
for (const line of rawLines) {
|
|
423
|
+
if (!line) {
|
|
424
|
+
wrapped.push('');
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
for (let i = 0; i < line.length; i += 88) {
|
|
428
|
+
wrapped.push(line.slice(i, i + 88));
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
const linesPerPage = 46;
|
|
432
|
+
const pages = [];
|
|
433
|
+
for (let i = 0; i < wrapped.length; i += linesPerPage) {
|
|
434
|
+
pages.push(wrapped.slice(i, i + linesPerPage));
|
|
435
|
+
}
|
|
436
|
+
if (pages.length === 0) pages.push([titleLine]);
|
|
437
|
+
|
|
438
|
+
const objects = [];
|
|
439
|
+
const addObj = (body) => {
|
|
440
|
+
objects.push(body);
|
|
441
|
+
return objects.length;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const catalogId = addObj('');
|
|
445
|
+
const pagesId = addObj('');
|
|
446
|
+
const fontId = addObj('<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>');
|
|
447
|
+
const pageIds = [];
|
|
448
|
+
|
|
449
|
+
for (const pageLines of pages) {
|
|
450
|
+
const streamCmds = ['BT', '/F1 10 Tf', '48 760 Td', '14 TL'];
|
|
451
|
+
for (let i = 0; i < pageLines.length; i++) {
|
|
452
|
+
const lit = escapePdfLiteral(pageLines[i]);
|
|
453
|
+
if (i === 0) streamCmds.push(`(${lit}) Tj`);
|
|
454
|
+
else streamCmds.push(`T* (${lit}) Tj`);
|
|
455
|
+
}
|
|
456
|
+
streamCmds.push('ET');
|
|
457
|
+
const streamStr = streamCmds.join('\n');
|
|
458
|
+
const contentId = addObj(`<< /Length ${Buffer.byteLength(streamStr, 'utf8')} >>\nstream\n${streamStr}\nendstream`);
|
|
459
|
+
const pageId = addObj(`<< /Type /Page /Parent ${pagesId} 0 R /MediaBox [0 0 612 792] /Resources << /Font << /F1 ${fontId} 0 R >> >> /Contents ${contentId} 0 R >>`);
|
|
460
|
+
pageIds.push(pageId);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
objects[catalogId - 1] = `<< /Type /Catalog /Pages ${pagesId} 0 R >>`;
|
|
464
|
+
objects[pagesId - 1] = `<< /Type /Pages /Kids [${pageIds.map((id) => `${id} 0 R`).join(' ')}] /Count ${pageIds.length} >>`;
|
|
465
|
+
|
|
466
|
+
const chunks = ['%PDF-1.4\n'];
|
|
467
|
+
const offsets = [0];
|
|
468
|
+
let byteLen = Buffer.byteLength(chunks[0], 'utf8');
|
|
469
|
+
for (let i = 0; i < objects.length; i++) {
|
|
470
|
+
offsets.push(byteLen);
|
|
471
|
+
const entry = `${i + 1} 0 obj\n${objects[i]}\nendobj\n`;
|
|
472
|
+
chunks.push(entry);
|
|
473
|
+
byteLen += Buffer.byteLength(entry, 'utf8');
|
|
474
|
+
}
|
|
475
|
+
const xrefPos = byteLen;
|
|
476
|
+
const xrefLines = [`xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`];
|
|
477
|
+
for (let i = 1; i < offsets.length; i++) {
|
|
478
|
+
xrefLines.push(`${String(offsets[i]).padStart(10, '0')} 00000 n \n`);
|
|
479
|
+
}
|
|
480
|
+
xrefLines.push(`trailer\n<< /Size ${objects.length + 1} /Root ${catalogId} 0 R >>\nstartxref\n${xrefPos}\n%%EOF\n`);
|
|
481
|
+
chunks.push(xrefLines.join(''));
|
|
482
|
+
return Buffer.from(chunks.join(''), 'utf8');
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function runExecFile(cmd, args = [], opts = {}) {
|
|
486
|
+
return new Promise((resolve) => {
|
|
487
|
+
execFile(cmd, args, { timeout: opts.timeout || 60000, env: opts.env || process.env }, (err, stdout, stderr) => {
|
|
488
|
+
resolve({
|
|
489
|
+
ok: !err,
|
|
490
|
+
code: err?.code ?? 0,
|
|
491
|
+
stdout: String(stdout || ''),
|
|
492
|
+
stderr: String(stderr || ''),
|
|
493
|
+
error: err?.message || ''
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function findHeadlessChromeBinary(customBin = '') {
|
|
500
|
+
const candidates = [
|
|
501
|
+
customBin,
|
|
502
|
+
process.env.AGY_DADDY_PDF_CHROME,
|
|
503
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
504
|
+
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
|
|
505
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
506
|
+
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
|
507
|
+
'/Applications/Arc.app/Contents/MacOS/Arc',
|
|
508
|
+
'/usr/bin/google-chrome',
|
|
509
|
+
'/usr/bin/chromium',
|
|
510
|
+
'/usr/bin/chromium-browser',
|
|
511
|
+
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
512
|
+
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe'
|
|
513
|
+
].filter(Boolean);
|
|
514
|
+
for (const p of candidates) {
|
|
515
|
+
try {
|
|
516
|
+
if (fs.existsSync(p)) return p;
|
|
517
|
+
} catch {}
|
|
518
|
+
}
|
|
519
|
+
return '';
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
async function renderHtmlToPdfBuffer(html, opts = {}) {
|
|
523
|
+
if (typeof opts.pdfRenderer === 'function') {
|
|
524
|
+
const customBuf = await opts.pdfRenderer(html, opts);
|
|
525
|
+
return Buffer.isBuffer(customBuf) ? customBuf : Buffer.from(customBuf || '');
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (!isTestEnv() && opts.allowSystemPdf !== false) {
|
|
529
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agy-cnav-pdf-'));
|
|
530
|
+
const tmpHtml = path.join(tmpDir, 'export.html');
|
|
531
|
+
const tmpPdf = path.join(tmpDir, 'export.pdf');
|
|
532
|
+
try {
|
|
533
|
+
fs.writeFileSync(tmpHtml, String(html || ''), 'utf8');
|
|
534
|
+
const chromeBin = findHeadlessChromeBinary(opts.chromeBin);
|
|
535
|
+
if (chromeBin) {
|
|
536
|
+
const res = await runExecFile(chromeBin, [
|
|
537
|
+
'--headless',
|
|
538
|
+
'--disable-gpu',
|
|
539
|
+
'--no-sandbox',
|
|
540
|
+
'--no-pdf-header-footer',
|
|
541
|
+
`--print-to-pdf=${tmpPdf}`,
|
|
542
|
+
pathToFileURL(tmpHtml).href
|
|
543
|
+
], { timeout: 45000 });
|
|
544
|
+
if (res.ok && fs.existsSync(tmpPdf)) {
|
|
545
|
+
const buf = fs.readFileSync(tmpPdf);
|
|
546
|
+
if (buf.length > 0 && buf.subarray(0, 5).toString('ascii') === '%PDF-') {
|
|
547
|
+
return buf;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
if (process.platform === 'darwin' && fs.existsSync('/usr/sbin/cupsfilter')) {
|
|
553
|
+
const res = await runExecFile('/usr/sbin/cupsfilter', ['-m', 'application/pdf', tmpHtml], { timeout: 30000 });
|
|
554
|
+
if (res.ok && res.stdout && res.stdout.startsWith('%PDF-')) {
|
|
555
|
+
return Buffer.from(res.stdout, 'binary');
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
} catch {} finally {
|
|
559
|
+
try { fs.rmSync(tmpDir, { recursive: true, force: true }); } catch {}
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return buildMinimalPdfBuffer(opts.plainText || '', opts.meta || {});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function isUserCancelledOsascript(res) {
|
|
567
|
+
const detail = `${res?.stderr || ''} ${res?.error || ''}`;
|
|
568
|
+
return /\(-128\)|\bUser canceled\b/i.test(detail);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
async function openSaveFileDialog(opts = {}) {
|
|
572
|
+
const format = normalizeExportFormat(opts.format || 'md');
|
|
573
|
+
const defaultName = String(opts.defaultName || buildExportFilename({ format })).trim();
|
|
574
|
+
const defaultDir = expandHomePath(opts.defaultDir || '') || path.join(os.homedir(), 'Downloads');
|
|
575
|
+
const promptText = String(opts.title || '导出对话记录').trim();
|
|
576
|
+
|
|
577
|
+
if (typeof opts.saveDialogFn === 'function') {
|
|
578
|
+
const res = await opts.saveDialogFn({ defaultDir, defaultName, format, title: promptText });
|
|
579
|
+
if (res && res.ok === false) {
|
|
580
|
+
return { ok: false, cancelled: false, path: '', error: String(res.error || '无法打开保存对话框') };
|
|
581
|
+
}
|
|
582
|
+
if (!res || res.cancelled || !res.path) {
|
|
583
|
+
return { ok: true, cancelled: true, path: '' };
|
|
584
|
+
}
|
|
585
|
+
return { ok: true, cancelled: false, path: ensureFileExtension(expandHomePath(res.path), format) };
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (isTestEnv()) {
|
|
589
|
+
const testResult = String(process.env.AGY_DADDY_TEST_SAVE_DIALOG_RESULT || '').trim();
|
|
590
|
+
if (!testResult || testResult === '__CANCEL__') {
|
|
591
|
+
return { ok: true, cancelled: true, path: '' };
|
|
592
|
+
}
|
|
593
|
+
return { ok: true, cancelled: false, path: ensureFileExtension(expandHomePath(testResult), format) };
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
const platform = opts.platform || process.platform;
|
|
597
|
+
if (platform === 'darwin') {
|
|
598
|
+
const hasDir = defaultDir && fs.existsSync(defaultDir);
|
|
599
|
+
const script = hasDir
|
|
600
|
+
? [
|
|
601
|
+
'on run argv',
|
|
602
|
+
' set pTitle to item 1 of argv',
|
|
603
|
+
' set pName to item 2 of argv',
|
|
604
|
+
' set pDir to item 3 of argv',
|
|
605
|
+
' tell current application to activate',
|
|
606
|
+
' return POSIX path of (choose file name with prompt pTitle default name pName default location ((POSIX file pDir) as alias))',
|
|
607
|
+
'end run'
|
|
608
|
+
].join('\n')
|
|
609
|
+
: [
|
|
610
|
+
'on run argv',
|
|
611
|
+
' set pTitle to item 1 of argv',
|
|
612
|
+
' set pName to item 2 of argv',
|
|
613
|
+
' tell current application to activate',
|
|
614
|
+
' return POSIX path of (choose file name with prompt pTitle default name pName)',
|
|
615
|
+
'end run'
|
|
616
|
+
].join('\n');
|
|
617
|
+
const args = ['-e', script, '--', promptText, defaultName];
|
|
618
|
+
if (hasDir) args.push(defaultDir);
|
|
619
|
+
const res = await runExecFile('osascript', args, { timeout: 120000 });
|
|
620
|
+
if (!res.ok) {
|
|
621
|
+
if (isUserCancelledOsascript(res)) {
|
|
622
|
+
return { ok: true, cancelled: true, path: '' };
|
|
623
|
+
}
|
|
624
|
+
return { ok: false, cancelled: false, path: '', error: (res.stderr || res.error || '无法打开保存对话框').trim() };
|
|
625
|
+
}
|
|
626
|
+
const picked = res.stdout.trim();
|
|
627
|
+
return picked
|
|
628
|
+
? { ok: true, cancelled: false, path: ensureFileExtension(picked, format) }
|
|
629
|
+
: { ok: true, cancelled: true, path: '' };
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (platform === 'win32') {
|
|
633
|
+
const filterMap = {
|
|
634
|
+
md: 'Markdown (*.md)|*.md|All files (*.*)|*.*',
|
|
635
|
+
html: 'HTML (*.html)|*.html|All files (*.*)|*.*',
|
|
636
|
+
pdf: 'PDF (*.pdf)|*.pdf|All files (*.*)|*.*'
|
|
637
|
+
};
|
|
638
|
+
const psScript = [
|
|
639
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
640
|
+
'$f = New-Object System.Windows.Forms.SaveFileDialog',
|
|
641
|
+
'$f.Title = $env:AGY_DLG_TITLE',
|
|
642
|
+
'$f.FileName = $env:AGY_DLG_NAME',
|
|
643
|
+
'if ($env:AGY_DLG_DIR -and (Test-Path $env:AGY_DLG_DIR)) { $f.InitialDirectory = $env:AGY_DLG_DIR }',
|
|
644
|
+
'$f.Filter = $env:AGY_DLG_FILTER',
|
|
645
|
+
'if ($f.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { Write-Output $f.FileName }'
|
|
646
|
+
].join('; ');
|
|
647
|
+
const res = await runExecFile('powershell.exe', ['-NoProfile', '-Command', psScript], {
|
|
648
|
+
timeout: 120000,
|
|
649
|
+
env: {
|
|
650
|
+
...process.env,
|
|
651
|
+
AGY_DLG_TITLE: promptText,
|
|
652
|
+
AGY_DLG_NAME: defaultName,
|
|
653
|
+
AGY_DLG_DIR: defaultDir,
|
|
654
|
+
AGY_DLG_FILTER: filterMap[format] || filterMap.md
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
const picked = res.ok ? res.stdout.trim() : '';
|
|
658
|
+
return picked
|
|
659
|
+
? { ok: true, cancelled: false, path: ensureFileExtension(picked, format) }
|
|
660
|
+
: { ok: true, cancelled: true, path: '' };
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const initialFile = path.join(defaultDir, defaultName);
|
|
664
|
+
const zen = await runExecFile('zenity', ['--file-selection', '--save', '--confirm-overwrite', `--title=${promptText}`, `--filename=${initialFile}`], { timeout: 120000 });
|
|
665
|
+
if (zen.ok && zen.stdout.trim()) {
|
|
666
|
+
return { ok: true, cancelled: false, path: ensureFileExtension(zen.stdout.trim(), format) };
|
|
667
|
+
}
|
|
668
|
+
const kd = await runExecFile('kdialog', ['--getsavefilename', initialFile, `*.${format}`], { timeout: 120000 });
|
|
669
|
+
if (kd.ok && kd.stdout.trim()) {
|
|
670
|
+
return { ok: true, cancelled: false, path: ensureFileExtension(kd.stdout.trim(), format) };
|
|
671
|
+
}
|
|
672
|
+
return { ok: true, cancelled: true, path: '' };
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
async function openDirectoryDialog(opts = {}) {
|
|
676
|
+
const defaultDir = expandHomePath(opts.defaultDir || '') || path.join(os.homedir(), 'Downloads');
|
|
677
|
+
const promptText = String(opts.title || '选择默认导出保存文件夹').trim();
|
|
678
|
+
|
|
679
|
+
if (typeof opts.dirPickerFn === 'function') {
|
|
680
|
+
const res = await opts.dirPickerFn({ defaultDir, title: promptText });
|
|
681
|
+
if (res && res.ok === false) {
|
|
682
|
+
return { ok: false, cancelled: false, path: '', error: String(res.error || '无法打开文件夹选择对话框') };
|
|
683
|
+
}
|
|
684
|
+
if (!res || res.cancelled || !res.path) {
|
|
685
|
+
return { ok: true, cancelled: true, path: '' };
|
|
686
|
+
}
|
|
687
|
+
return { ok: true, cancelled: false, path: expandHomePath(res.path) };
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (isTestEnv()) {
|
|
691
|
+
const testResult = String(process.env.AGY_DADDY_TEST_DIR_DIALOG_RESULT || '').trim();
|
|
692
|
+
if (!testResult || testResult === '__CANCEL__') {
|
|
693
|
+
return { ok: true, cancelled: true, path: '' };
|
|
694
|
+
}
|
|
695
|
+
return { ok: true, cancelled: false, path: expandHomePath(testResult) };
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const platform = opts.platform || process.platform;
|
|
699
|
+
if (platform === 'darwin') {
|
|
700
|
+
const hasDir = defaultDir && fs.existsSync(defaultDir);
|
|
701
|
+
const script = hasDir
|
|
702
|
+
? [
|
|
703
|
+
'on run argv',
|
|
704
|
+
' set pTitle to item 1 of argv',
|
|
705
|
+
' set pDir to item 2 of argv',
|
|
706
|
+
' tell current application to activate',
|
|
707
|
+
' return POSIX path of (choose folder with prompt pTitle default location ((POSIX file pDir) as alias))',
|
|
708
|
+
'end run'
|
|
709
|
+
].join('\n')
|
|
710
|
+
: [
|
|
711
|
+
'on run argv',
|
|
712
|
+
' set pTitle to item 1 of argv',
|
|
713
|
+
' tell current application to activate',
|
|
714
|
+
' return POSIX path of (choose folder with prompt pTitle)',
|
|
715
|
+
'end run'
|
|
716
|
+
].join('\n');
|
|
717
|
+
const args = ['-e', script, '--', promptText];
|
|
718
|
+
if (hasDir) args.push(defaultDir);
|
|
719
|
+
const res = await runExecFile('osascript', args, { timeout: 120000 });
|
|
720
|
+
if (!res.ok) {
|
|
721
|
+
if (isUserCancelledOsascript(res)) {
|
|
722
|
+
return { ok: true, cancelled: true, path: '' };
|
|
723
|
+
}
|
|
724
|
+
return { ok: false, cancelled: false, path: '', error: (res.stderr || res.error || '无法打开文件夹选择对话框').trim() };
|
|
725
|
+
}
|
|
726
|
+
const picked = res.stdout.trim().replace(/\/+$/, '');
|
|
727
|
+
return picked
|
|
728
|
+
? { ok: true, cancelled: false, path: picked }
|
|
729
|
+
: { ok: true, cancelled: true, path: '' };
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
if (platform === 'win32') {
|
|
733
|
+
const psScript = [
|
|
734
|
+
'Add-Type -AssemblyName System.Windows.Forms',
|
|
735
|
+
'$d = New-Object System.Windows.Forms.FolderBrowserDialog',
|
|
736
|
+
'$d.Description = $env:AGY_DLG_TITLE',
|
|
737
|
+
'if ($env:AGY_DLG_DIR -and (Test-Path $env:AGY_DLG_DIR)) { $d.SelectedPath = $env:AGY_DLG_DIR }',
|
|
738
|
+
'if ($d.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { Write-Output $d.SelectedPath }'
|
|
739
|
+
].join('; ');
|
|
740
|
+
const res = await runExecFile('powershell.exe', ['-NoProfile', '-Command', psScript], {
|
|
741
|
+
timeout: 120000,
|
|
742
|
+
env: { ...process.env, AGY_DLG_TITLE: promptText, AGY_DLG_DIR: defaultDir }
|
|
743
|
+
});
|
|
744
|
+
const picked = res.ok ? res.stdout.trim() : '';
|
|
745
|
+
return picked ? { ok: true, cancelled: false, path: picked } : { ok: true, cancelled: true, path: '' };
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
const zen = await runExecFile('zenity', ['--file-selection', '--directory', `--title=${promptText}`, `--filename=${defaultDir}/`], { timeout: 120000 });
|
|
749
|
+
if (zen.ok && zen.stdout.trim()) {
|
|
750
|
+
return { ok: true, cancelled: false, path: zen.stdout.trim().replace(/\/+$/, '') };
|
|
751
|
+
}
|
|
752
|
+
const kd = await runExecFile('kdialog', ['--getexistingdirectory', defaultDir], { timeout: 120000 });
|
|
753
|
+
if (kd.ok && kd.stdout.trim()) {
|
|
754
|
+
return { ok: true, cancelled: false, path: kd.stdout.trim().replace(/\/+$/, '') };
|
|
755
|
+
}
|
|
756
|
+
return { ok: true, cancelled: true, path: '' };
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
module.exports = {
|
|
760
|
+
EXPORT_FORMATS,
|
|
761
|
+
normalizeExportFormat,
|
|
762
|
+
normalizeExportFormats,
|
|
763
|
+
ensureFileExtension,
|
|
764
|
+
getDefaultBrainDir,
|
|
765
|
+
listBrainSessions,
|
|
766
|
+
pickLatestCascadeId,
|
|
767
|
+
sanitizeFilenamePart,
|
|
768
|
+
buildExportFilename,
|
|
769
|
+
normalizeDomMessagesToSteps,
|
|
770
|
+
exportConversationMarkdown,
|
|
771
|
+
exportConversationHtml,
|
|
772
|
+
buildMinimalPdfBuffer,
|
|
773
|
+
renderHtmlToPdfBuffer,
|
|
774
|
+
openSaveFileDialog,
|
|
775
|
+
openDirectoryDialog
|
|
776
|
+
};
|