@bubblebrain-ai/bubble 0.0.10 → 0.0.12
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/agent.d.ts +1 -0
- package/dist/agent.js +6 -2
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +31 -3
- package/dist/feedback/collect.d.ts +7 -0
- package/dist/feedback/collect.js +119 -0
- package/dist/feedback/config.d.ts +14 -0
- package/dist/feedback/config.js +16 -0
- package/dist/feedback/redact.d.ts +1 -0
- package/dist/feedback/redact.js +25 -0
- package/dist/feedback/submit.d.ts +6 -0
- package/dist/feedback/submit.js +43 -0
- package/dist/feedback/types.d.ts +22 -0
- package/dist/feishu/agent-host/approval-card.d.ts +11 -0
- package/dist/feishu/agent-host/approval-card.js +46 -0
- package/dist/feishu/agent-host/approval-ui.d.ts +59 -0
- package/dist/feishu/agent-host/approval-ui.js +214 -0
- package/dist/feishu/agent-host/run-driver.d.ts +51 -0
- package/dist/feishu/agent-host/run-driver.js +302 -0
- package/dist/feishu/agent-host/runtime-deps.d.ts +33 -0
- package/dist/feishu/agent-host/runtime-deps.js +8 -0
- package/dist/feishu/card/budget.d.ts +40 -0
- package/dist/feishu/card/budget.js +134 -0
- package/dist/feishu/card/renderer.d.ts +29 -0
- package/dist/feishu/card/renderer.js +245 -0
- package/dist/feishu/card/run-state-types.d.ts +49 -0
- package/dist/feishu/card/run-state-types.js +15 -0
- package/dist/feishu/card/run-state.d.ts +21 -0
- package/dist/feishu/card/run-state.js +217 -0
- package/dist/feishu/channel/channel.d.ts +52 -0
- package/dist/feishu/channel/channel.js +74 -0
- package/dist/feishu/config.d.ts +24 -0
- package/dist/feishu/config.js +97 -0
- package/dist/feishu/format.d.ts +6 -0
- package/dist/feishu/format.js +14 -0
- package/dist/feishu/index.d.ts +4 -0
- package/dist/feishu/index.js +4 -0
- package/dist/feishu/logger.d.ts +31 -0
- package/dist/feishu/logger.js +62 -0
- package/dist/feishu/paths.d.ts +12 -0
- package/dist/feishu/paths.js +38 -0
- package/dist/feishu/process-registry.d.ts +29 -0
- package/dist/feishu/process-registry.js +90 -0
- package/dist/feishu/router/commands.d.ts +38 -0
- package/dist/feishu/router/commands.js +286 -0
- package/dist/feishu/router/event-router.d.ts +40 -0
- package/dist/feishu/router/event-router.js +208 -0
- package/dist/feishu/router/whitelist.d.ts +23 -0
- package/dist/feishu/router/whitelist.js +20 -0
- package/dist/feishu/runtime/active-runs.d.ts +32 -0
- package/dist/feishu/runtime/active-runs.js +84 -0
- package/dist/feishu/runtime/pending-queue.d.ts +36 -0
- package/dist/feishu/runtime/pending-queue.js +98 -0
- package/dist/feishu/runtime/process-pool.d.ts +29 -0
- package/dist/feishu/runtime/process-pool.js +49 -0
- package/dist/feishu/schema.d.ts +17 -0
- package/dist/feishu/schema.js +252 -0
- package/dist/feishu/scope/scope-registry.d.ts +39 -0
- package/dist/feishu/scope/scope-registry.js +148 -0
- package/dist/feishu/scope/session-binder.d.ts +44 -0
- package/dist/feishu/scope/session-binder.js +100 -0
- package/dist/feishu/scope/session-store.d.ts +24 -0
- package/dist/feishu/scope/session-store.js +73 -0
- package/dist/feishu/secrets.d.ts +37 -0
- package/dist/feishu/secrets.js +129 -0
- package/dist/feishu/serve.d.ts +12 -0
- package/dist/feishu/serve.js +288 -0
- package/dist/feishu/types.d.ts +75 -0
- package/dist/feishu/types.js +23 -0
- package/dist/feishu/wizard.d.ts +24 -0
- package/dist/feishu/wizard.js +121 -0
- package/dist/main.js +98 -32
- package/dist/model-catalog.js +3 -0
- package/dist/prompt/compose.js +3 -3
- package/dist/prompt/environment.js +2 -0
- package/dist/prompt/reminders.js +1 -1
- package/dist/provider-openai-codex.d.ts +8 -1
- package/dist/provider-openai-codex.js +33 -9
- package/dist/provider.d.ts +2 -0
- package/dist/session-title.d.ts +16 -0
- package/dist/session-title.js +134 -0
- package/dist/session-types.d.ts +5 -0
- package/dist/session.d.ts +16 -0
- package/dist/session.js +154 -2
- package/dist/skills/invocation.js +0 -18
- package/dist/skills/registry.d.ts +1 -0
- package/dist/skills/registry.js +2 -0
- package/dist/slash-commands/commands.js +15 -22
- package/dist/slash-commands/feishu.d.ts +17 -0
- package/dist/slash-commands/feishu.js +400 -0
- package/dist/slash-commands/registry.js +1 -1
- package/dist/slash-commands/types.d.ts +3 -1
- package/dist/text-display.d.ts +3 -0
- package/dist/text-display.js +25 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +3 -1
- package/dist/tools/skill-search.d.ts +10 -0
- package/dist/tools/skill-search.js +134 -0
- package/dist/tools/skill.js +1 -4
- package/dist/tui-ink/app.js +265 -118
- package/dist/tui-ink/code-highlight.js +2 -3
- package/dist/tui-ink/detect-theme.d.ts +1 -18
- package/dist/tui-ink/detect-theme.js +1 -37
- package/dist/tui-ink/display-history.d.ts +20 -3
- package/dist/tui-ink/display-history.js +26 -27
- package/dist/tui-ink/feedback-dialog.d.ts +19 -0
- package/dist/tui-ink/feedback-dialog.js +123 -0
- package/dist/tui-ink/feishu-setup-picker.d.ts +5 -0
- package/dist/tui-ink/feishu-setup-picker.js +261 -0
- package/dist/tui-ink/input-box.d.ts +25 -1
- package/dist/tui-ink/input-box.js +132 -11
- package/dist/tui-ink/input-history.js +3 -5
- package/dist/tui-ink/markdown.d.ts +32 -0
- package/dist/tui-ink/markdown.js +111 -4
- package/dist/tui-ink/message-list.d.ts +1 -6
- package/dist/tui-ink/message-list.js +86 -34
- package/dist/tui-ink/model-picker.d.ts +18 -0
- package/dist/tui-ink/model-picker.js +81 -27
- package/dist/tui-ink/run-session-picker.d.ts +10 -0
- package/dist/tui-ink/run-session-picker.js +22 -0
- package/dist/tui-ink/run.js +7 -2
- package/dist/tui-ink/session-picker.d.ts +10 -0
- package/dist/tui-ink/session-picker.js +110 -0
- package/dist/tui-ink/terminal-mouse.d.ts +4 -0
- package/dist/tui-ink/terminal-mouse.js +23 -0
- package/dist/tui-ink/theme.js +2 -2
- package/dist/tui-ink/trace-groups.js +25 -2
- package/dist/tui-ink/welcome.js +2 -4
- package/package.json +4 -5
- package/dist/tui/clipboard.d.ts +0 -1
- package/dist/tui/clipboard.js +0 -53
- package/dist/tui/display-history.d.ts +0 -44
- package/dist/tui/display-history.js +0 -243
- package/dist/tui/escape-confirmation.d.ts +0 -15
- package/dist/tui/escape-confirmation.js +0 -30
- package/dist/tui/file-mentions.d.ts +0 -29
- package/dist/tui/file-mentions.js +0 -174
- package/dist/tui/global-key-router.d.ts +0 -3
- package/dist/tui/global-key-router.js +0 -87
- package/dist/tui/image-paste.d.ts +0 -95
- package/dist/tui/image-paste.js +0 -505
- package/dist/tui/markdown-inline.d.ts +0 -22
- package/dist/tui/markdown-inline.js +0 -68
- package/dist/tui/markdown-theme-rules.d.ts +0 -23
- package/dist/tui/markdown-theme-rules.js +0 -164
- package/dist/tui/markdown-theme.d.ts +0 -5
- package/dist/tui/markdown-theme.js +0 -27
- package/dist/tui/opencode-spinner.d.ts +0 -21
- package/dist/tui/opencode-spinner.js +0 -216
- package/dist/tui/prompt-keybindings.d.ts +0 -42
- package/dist/tui/prompt-keybindings.js +0 -35
- package/dist/tui/recent-activity.d.ts +0 -8
- package/dist/tui/recent-activity.js +0 -71
- package/dist/tui/render-signature.d.ts +0 -1
- package/dist/tui/render-signature.js +0 -7
- package/dist/tui/run.d.ts +0 -38
- package/dist/tui/run.js +0 -6996
- package/dist/tui/sidebar-mcp.d.ts +0 -31
- package/dist/tui/sidebar-mcp.js +0 -62
- package/dist/tui/sidebar-state.d.ts +0 -12
- package/dist/tui/sidebar-state.js +0 -69
- package/dist/tui/streaming-tool-args.d.ts +0 -15
- package/dist/tui/streaming-tool-args.js +0 -30
- package/dist/tui/tool-renderers/fallback.d.ts +0 -2
- package/dist/tui/tool-renderers/fallback.js +0 -75
- package/dist/tui/tool-renderers/registry.d.ts +0 -3
- package/dist/tui/tool-renderers/registry.js +0 -11
- package/dist/tui/tool-renderers/subagent.d.ts +0 -2
- package/dist/tui/tool-renderers/subagent.js +0 -114
- package/dist/tui/tool-renderers/types.d.ts +0 -36
- package/dist/tui/tool-renderers/write-preview.d.ts +0 -12
- package/dist/tui/tool-renderers/write-preview.js +0 -30
- package/dist/tui/tool-renderers/write.d.ts +0 -6
- package/dist/tui/tool-renderers/write.js +0 -88
- /package/dist/{tui/tool-renderers → feedback}/types.js +0 -0
package/dist/tui/image-paste.js
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Image paste utilities: path detection, file reading, clipboard access, and size-capping.
|
|
3
|
-
*
|
|
4
|
-
* Terminals don't forward image bytes to stdin. Paths arrive as text when users
|
|
5
|
-
* drag files in; Cmd+V of an image produces an empty paste (we probe the
|
|
6
|
-
* clipboard). macOS screenshot shortcut (Cmd+Shift+Ctrl+4) writes to both a
|
|
7
|
-
* TemporaryItems path and the clipboard — the path often gets cleaned up before
|
|
8
|
-
* we can read it, so we fall back to the clipboard.
|
|
9
|
-
*/
|
|
10
|
-
import { execFile } from "node:child_process";
|
|
11
|
-
import fs from "node:fs/promises";
|
|
12
|
-
import os from "node:os";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
import { promisify } from "node:util";
|
|
15
|
-
const execFileAsync = promisify(execFile);
|
|
16
|
-
const IMAGE_EXT = /\.(png|jpe?g|gif|webp|bmp)$/i;
|
|
17
|
-
const IMAGE_EXT_SOURCE = String.raw `(?:png|jpe?g|gif|webp|bmp)`;
|
|
18
|
-
// Anthropic/OpenAI image uploads cap at ~5MB base64. We target a bit below so
|
|
19
|
-
// the base64 inflation (4/3) doesn't push us over.
|
|
20
|
-
const MAX_BASE64_BYTES = 5 * 1024 * 1024;
|
|
21
|
-
const RESIZE_TRIGGER_BYTES = Math.floor(MAX_BASE64_BYTES * 0.95);
|
|
22
|
-
// Target max dimension for auto-resize.
|
|
23
|
-
const RESIZE_MAX_DIM = 2048;
|
|
24
|
-
export function isImageFilePath(raw) {
|
|
25
|
-
const s = raw.trim();
|
|
26
|
-
if (!s)
|
|
27
|
-
return false;
|
|
28
|
-
if (!IMAGE_EXT.test(s))
|
|
29
|
-
return false;
|
|
30
|
-
// Require an absolute or home-relative path. Pasted arbitrary text shouldn't
|
|
31
|
-
// be treated as a path.
|
|
32
|
-
return path.isAbsolute(s) || s.startsWith("~") || /^[A-Za-z]:\\/.test(s);
|
|
33
|
-
}
|
|
34
|
-
export function extractImagePathTokens(input) {
|
|
35
|
-
const pattern = new RegExp(String.raw `(^|\s)(?:"([^"]+\.${IMAGE_EXT_SOURCE})"|'([^']+\.${IMAGE_EXT_SOURCE})'|((?:~|\/|[A-Za-z]:\\)(?:\\ |[^\s"'<>])+\.${IMAGE_EXT_SOURCE}))(?=$|\s)`, "gi");
|
|
36
|
-
const tokens = [];
|
|
37
|
-
for (const match of input.matchAll(pattern)) {
|
|
38
|
-
const leading = match[1] ?? "";
|
|
39
|
-
const rawPath = match[2] ?? match[3] ?? match[4];
|
|
40
|
-
if (!rawPath || !isImageFilePath(rawPath))
|
|
41
|
-
continue;
|
|
42
|
-
const start = (match.index ?? 0) + leading.length;
|
|
43
|
-
const end = (match.index ?? 0) + match[0].length;
|
|
44
|
-
tokens.push({ rawPath, start, end });
|
|
45
|
-
}
|
|
46
|
-
return tokens;
|
|
47
|
-
}
|
|
48
|
-
export function removeImagePathTokens(input, tokens) {
|
|
49
|
-
if (tokens.length === 0)
|
|
50
|
-
return input.trim();
|
|
51
|
-
let out = "";
|
|
52
|
-
let cursor = 0;
|
|
53
|
-
for (const token of tokens) {
|
|
54
|
-
out += input.slice(cursor, token.start);
|
|
55
|
-
out += " ";
|
|
56
|
-
cursor = token.end;
|
|
57
|
-
}
|
|
58
|
-
out += input.slice(cursor);
|
|
59
|
-
return out
|
|
60
|
-
.replace(/[ \t]+/g, " ")
|
|
61
|
-
.replace(/ *\n */g, "\n")
|
|
62
|
-
.replace(/\n{3,}/g, "\n\n")
|
|
63
|
-
.trim();
|
|
64
|
-
}
|
|
65
|
-
export function imageAttachmentLabel(att, index) {
|
|
66
|
-
return `image#${index}${imageExtension(att)}`;
|
|
67
|
-
}
|
|
68
|
-
export function imageAttachmentReference(att, index) {
|
|
69
|
-
return `[${imageAttachmentLabel(att, index)}]`;
|
|
70
|
-
}
|
|
71
|
-
export function imageAttachmentLabelPattern() {
|
|
72
|
-
return /\[image#(\d+)\.[^\]\s]+\]/g;
|
|
73
|
-
}
|
|
74
|
-
function defaultImagePrompt(count) {
|
|
75
|
-
return count === 1
|
|
76
|
-
? "Please analyze the attached image."
|
|
77
|
-
: "Please analyze the attached images.";
|
|
78
|
-
}
|
|
79
|
-
function imageExtension(att) {
|
|
80
|
-
const fromPath = path.extname(att.filename ?? att.sourcePath ?? "").toLowerCase();
|
|
81
|
-
if (fromPath)
|
|
82
|
-
return fromPath;
|
|
83
|
-
if (att.mediaType === "image/jpeg")
|
|
84
|
-
return ".jpg";
|
|
85
|
-
if (att.mediaType === "image/webp")
|
|
86
|
-
return ".webp";
|
|
87
|
-
if (att.mediaType === "image/gif")
|
|
88
|
-
return ".gif";
|
|
89
|
-
if (att.mediaType === "image/bmp")
|
|
90
|
-
return ".bmp";
|
|
91
|
-
return ".png";
|
|
92
|
-
}
|
|
93
|
-
export function buildImageContentParts(promptText, attachments) {
|
|
94
|
-
const text = promptText.trim() || defaultImagePrompt(attachments.length);
|
|
95
|
-
return [
|
|
96
|
-
{ type: "text", text },
|
|
97
|
-
...attachments.map((attachment) => ({
|
|
98
|
-
type: "image_url",
|
|
99
|
-
image_url: { url: attachment.dataUrl },
|
|
100
|
-
})),
|
|
101
|
-
];
|
|
102
|
-
}
|
|
103
|
-
export function formatImageDisplayInput(promptText, attachments, labelStart = 1) {
|
|
104
|
-
const text = promptText.trim() || defaultImagePrompt(attachments.length);
|
|
105
|
-
const imageLines = attachments.map((attachment, index) => imageAttachmentReference(attachment, labelStart + index));
|
|
106
|
-
return `${text}\n${imageLines.join("\n")}`;
|
|
107
|
-
}
|
|
108
|
-
export function buildImageContentPartsFromLabels(input, attachmentsByLabel) {
|
|
109
|
-
const matches = Array.from(input.matchAll(imageAttachmentLabelPattern()));
|
|
110
|
-
const usedLabels = [];
|
|
111
|
-
const parts = [];
|
|
112
|
-
let cursor = 0;
|
|
113
|
-
for (const match of matches) {
|
|
114
|
-
const label = match[0].slice(1, -1);
|
|
115
|
-
const attachment = attachmentsByLabel.get(label);
|
|
116
|
-
if (!attachment)
|
|
117
|
-
continue;
|
|
118
|
-
const start = match.index ?? 0;
|
|
119
|
-
const before = input.slice(cursor, start).trim();
|
|
120
|
-
if (before)
|
|
121
|
-
parts.push({ type: "text", text: before });
|
|
122
|
-
parts.push({ type: "image_url", image_url: { url: attachment.dataUrl } });
|
|
123
|
-
usedLabels.push(label);
|
|
124
|
-
cursor = start + match[0].length;
|
|
125
|
-
}
|
|
126
|
-
if (usedLabels.length === 0)
|
|
127
|
-
return { displayInput: input, usedLabels: [] };
|
|
128
|
-
const rest = input.slice(cursor).trim();
|
|
129
|
-
if (rest)
|
|
130
|
-
parts.push({ type: "text", text: rest });
|
|
131
|
-
if (!parts.some((part) => part.type === "text")) {
|
|
132
|
-
parts.unshift({ type: "text", text: defaultImagePrompt(usedLabels.length) });
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
actualInput: parts,
|
|
136
|
-
displayInput: input.trim() || usedLabels.map((label) => `[${label}]`).join("\n"),
|
|
137
|
-
usedLabels,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Split a pasted blob into candidate path tokens.
|
|
142
|
-
*
|
|
143
|
-
* Multi-drag from Finder delivers a mix of newline- and space-separated
|
|
144
|
-
* absolute paths. Spaces inside a single path are escaped (`\ `) — we split
|
|
145
|
-
* only on a space that is followed by the start of a new absolute path.
|
|
146
|
-
*/
|
|
147
|
-
export function splitPastedPaths(pasted) {
|
|
148
|
-
const out = [];
|
|
149
|
-
for (const line of pasted.split(/\r?\n/)) {
|
|
150
|
-
for (const piece of line.split(/ (?=\/|[A-Za-z]:\\)/)) {
|
|
151
|
-
const t = piece.trim();
|
|
152
|
-
if (t)
|
|
153
|
-
out.push(t);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return out;
|
|
157
|
-
}
|
|
158
|
-
function mediaTypeFromExt(p) {
|
|
159
|
-
const ext = path.extname(p).toLowerCase();
|
|
160
|
-
if (ext === ".jpg" || ext === ".jpeg")
|
|
161
|
-
return "image/jpeg";
|
|
162
|
-
if (ext === ".gif")
|
|
163
|
-
return "image/gif";
|
|
164
|
-
if (ext === ".webp")
|
|
165
|
-
return "image/webp";
|
|
166
|
-
if (ext === ".bmp")
|
|
167
|
-
return "image/bmp";
|
|
168
|
-
return "image/png";
|
|
169
|
-
}
|
|
170
|
-
function resolveHome(p) {
|
|
171
|
-
if (p.startsWith("~/") || p === "~") {
|
|
172
|
-
return path.join(os.homedir(), p.slice(1));
|
|
173
|
-
}
|
|
174
|
-
return p;
|
|
175
|
-
}
|
|
176
|
-
function unescapeShell(p) {
|
|
177
|
-
return p.replace(/\\ /g, " ");
|
|
178
|
-
}
|
|
179
|
-
function attachmentFromBuffer(buffer, mediaType, meta = {}) {
|
|
180
|
-
const base64 = buffer.toString("base64");
|
|
181
|
-
return {
|
|
182
|
-
base64,
|
|
183
|
-
mediaType,
|
|
184
|
-
bytes: buffer.length,
|
|
185
|
-
dataUrl: `data:${mediaType};base64,${base64}`,
|
|
186
|
-
filename: meta.filename,
|
|
187
|
-
sourcePath: meta.sourcePath,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
export async function readImageFromPath(rawPath) {
|
|
191
|
-
const resolved = resolveHome(unescapeShell(rawPath.trim()));
|
|
192
|
-
try {
|
|
193
|
-
const stat = await fs.stat(resolved);
|
|
194
|
-
if (!stat.isFile())
|
|
195
|
-
return null;
|
|
196
|
-
const buffer = await fs.readFile(resolved);
|
|
197
|
-
return attachmentFromBuffer(buffer, mediaTypeFromExt(resolved), {
|
|
198
|
-
filename: path.basename(resolved),
|
|
199
|
-
sourcePath: resolved,
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
catch {
|
|
203
|
-
return null;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/** macOS screenshot shortcut writes to these paths and they may be auto-cleaned. */
|
|
207
|
-
export function isScreenshotTempPath(s) {
|
|
208
|
-
return /\/TemporaryItems\/.*screencaptureui.*\/Screenshot/i.test(s);
|
|
209
|
-
}
|
|
210
|
-
export async function getImageFromClipboard() {
|
|
211
|
-
switch (process.platform) {
|
|
212
|
-
case "darwin":
|
|
213
|
-
return getClipboardImageDarwin();
|
|
214
|
-
case "linux":
|
|
215
|
-
return getClipboardImageLinux();
|
|
216
|
-
case "win32":
|
|
217
|
-
return getClipboardImageWindows();
|
|
218
|
-
default:
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async function getClipboardImageDarwin() {
|
|
223
|
-
// Probe first — `as «class PNGf»` throws if clipboard has no image.
|
|
224
|
-
try {
|
|
225
|
-
await execFileAsync("osascript", ["-e", "the clipboard as «class PNGf»"], {
|
|
226
|
-
timeout: 5000,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
const tmp = path.join(os.tmpdir(), `bubble_clip_${Date.now()}_${process.pid}.png`);
|
|
233
|
-
const script = `set png_data to (the clipboard as «class PNGf»)\n` +
|
|
234
|
-
`set fp to open for access POSIX file "${tmp}" with write permission\n` +
|
|
235
|
-
`write png_data to fp\n` +
|
|
236
|
-
`close access fp`;
|
|
237
|
-
try {
|
|
238
|
-
await execFileAsync("osascript", ["-e", script], { timeout: 5000 });
|
|
239
|
-
const buf = await fs.readFile(tmp);
|
|
240
|
-
return attachmentFromBuffer(buf, "image/png");
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
finally {
|
|
246
|
-
await fs.unlink(tmp).catch(() => undefined);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async function getClipboardImageLinux() {
|
|
250
|
-
const candidates = [
|
|
251
|
-
["xclip", ["-selection", "clipboard", "-t", "image/png", "-o"]],
|
|
252
|
-
["wl-paste", ["--type", "image/png"]],
|
|
253
|
-
];
|
|
254
|
-
for (const [cmd, args] of candidates) {
|
|
255
|
-
try {
|
|
256
|
-
// encoding: "buffer" makes stdout a Buffer instead of a string so PNG
|
|
257
|
-
// bytes survive without UTF-8 mangling.
|
|
258
|
-
const result = await execFileAsync(cmd, args, {
|
|
259
|
-
timeout: 5000,
|
|
260
|
-
encoding: "buffer",
|
|
261
|
-
});
|
|
262
|
-
const buf = result.stdout;
|
|
263
|
-
if (buf && buf.length > 0) {
|
|
264
|
-
return attachmentFromBuffer(buf, "image/png");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch {
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
return null;
|
|
272
|
-
}
|
|
273
|
-
async function getClipboardImageWindows() {
|
|
274
|
-
const tmp = path.join(os.tmpdir(), `bubble_clip_${Date.now()}_${process.pid}.png`);
|
|
275
|
-
const tmpPs = tmp.replace(/\\/g, "\\\\");
|
|
276
|
-
const script = `Add-Type -AssemblyName System.Drawing; ` +
|
|
277
|
-
`$img = Get-Clipboard -Format Image; ` +
|
|
278
|
-
`if ($img) { $img.Save('${tmpPs}', [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'OK' } ` +
|
|
279
|
-
`else { Write-Output 'NONE' }`;
|
|
280
|
-
try {
|
|
281
|
-
const result = await execFileAsync("powershell", ["-NoProfile", "-Command", script], { timeout: 5000 });
|
|
282
|
-
if (!String(result.stdout).includes("OK"))
|
|
283
|
-
return null;
|
|
284
|
-
const buf = await fs.readFile(tmp);
|
|
285
|
-
return attachmentFromBuffer(buf, "image/png");
|
|
286
|
-
}
|
|
287
|
-
catch {
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
finally {
|
|
291
|
-
await fs.unlink(tmp).catch(() => undefined);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
async function which(cmd) {
|
|
295
|
-
try {
|
|
296
|
-
await execFileAsync(process.platform === "win32" ? "where" : "which", [cmd], {
|
|
297
|
-
timeout: 1500,
|
|
298
|
-
});
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
catch {
|
|
302
|
-
return false;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* If the image is close to the API size cap, try to downscale it in place.
|
|
307
|
-
* Uses the OS-native tools that are typically available:
|
|
308
|
-
* - macOS: `sips` (always present)
|
|
309
|
-
* - linux: ImageMagick `convert` (if installed)
|
|
310
|
-
* Returns the original attachment if resize isn't needed or can't run.
|
|
311
|
-
*/
|
|
312
|
-
export async function maybeResizeImage(att) {
|
|
313
|
-
if (att.base64.length < RESIZE_TRIGGER_BYTES)
|
|
314
|
-
return att;
|
|
315
|
-
const tmpDir = os.tmpdir();
|
|
316
|
-
const stamp = `${Date.now()}_${process.pid}`;
|
|
317
|
-
const inExt = path.extname(att.filename ?? att.sourcePath ?? `.png`).toLowerCase() || ".png";
|
|
318
|
-
const tmpIn = path.join(tmpDir, `bubble_img_in_${stamp}${inExt}`);
|
|
319
|
-
const tmpOut = path.join(tmpDir, `bubble_img_out_${stamp}.jpg`);
|
|
320
|
-
try {
|
|
321
|
-
await fs.writeFile(tmpIn, Buffer.from(att.base64, "base64"));
|
|
322
|
-
let ok = false;
|
|
323
|
-
if (process.platform === "darwin") {
|
|
324
|
-
try {
|
|
325
|
-
await execFileAsync("sips", ["-Z", String(RESIZE_MAX_DIM), "-s", "format", "jpeg", "-s", "formatOptions", "80", tmpIn, "--out", tmpOut], { timeout: 10000 });
|
|
326
|
-
ok = true;
|
|
327
|
-
}
|
|
328
|
-
catch {
|
|
329
|
-
ok = false;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
else if (await which("convert")) {
|
|
333
|
-
try {
|
|
334
|
-
await execFileAsync("convert", [tmpIn, "-resize", `${RESIZE_MAX_DIM}x${RESIZE_MAX_DIM}>`, "-quality", "80", tmpOut], { timeout: 10000 });
|
|
335
|
-
ok = true;
|
|
336
|
-
}
|
|
337
|
-
catch {
|
|
338
|
-
ok = false;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
if (!ok)
|
|
342
|
-
return att;
|
|
343
|
-
const resized = await fs.readFile(tmpOut);
|
|
344
|
-
if (resized.length >= att.bytes)
|
|
345
|
-
return att;
|
|
346
|
-
return attachmentFromBuffer(resized, "image/jpeg", {
|
|
347
|
-
filename: att.filename,
|
|
348
|
-
sourcePath: att.sourcePath,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
catch {
|
|
352
|
-
return att;
|
|
353
|
-
}
|
|
354
|
-
finally {
|
|
355
|
-
await fs.unlink(tmpIn).catch(() => undefined);
|
|
356
|
-
await fs.unlink(tmpOut).catch(() => undefined);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
export function validateImageSize(att) {
|
|
360
|
-
if (att.base64.length > MAX_BASE64_BYTES) {
|
|
361
|
-
const kb = Math.round(att.base64.length / 1024);
|
|
362
|
-
const max = Math.round(MAX_BASE64_BYTES / 1024);
|
|
363
|
-
const hint = process.platform === "darwin"
|
|
364
|
-
? " (install/confirm `sips` on PATH to auto-resize)"
|
|
365
|
-
: process.platform === "linux"
|
|
366
|
-
? " (install ImageMagick `convert` to auto-resize)"
|
|
367
|
-
: "";
|
|
368
|
-
return {
|
|
369
|
-
ok: false,
|
|
370
|
-
reason: `image base64 is ${kb}KB, exceeds ${max}KB API cap${hint}`,
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
return { ok: true };
|
|
374
|
-
}
|
|
375
|
-
/** End-to-end: given a file path, read -> resize-if-needed -> validate. */
|
|
376
|
-
export async function ingestImagePath(p) {
|
|
377
|
-
const raw = await readImageFromPath(p);
|
|
378
|
-
if (!raw)
|
|
379
|
-
return { error: `cannot read image at ${p}` };
|
|
380
|
-
const sized = await maybeResizeImage(raw);
|
|
381
|
-
const validation = validateImageSize(sized);
|
|
382
|
-
if (!validation.ok)
|
|
383
|
-
return { error: validation.reason };
|
|
384
|
-
return { attachment: sized };
|
|
385
|
-
}
|
|
386
|
-
export async function ingestClipboardImage() {
|
|
387
|
-
const raw = await getImageFromClipboard();
|
|
388
|
-
if (!raw)
|
|
389
|
-
return { error: "clipboard has no image" };
|
|
390
|
-
const sized = await maybeResizeImage(raw);
|
|
391
|
-
const validation = validateImageSize(sized);
|
|
392
|
-
if (!validation.ok)
|
|
393
|
-
return { error: validation.reason };
|
|
394
|
-
return { attachment: sized };
|
|
395
|
-
}
|
|
396
|
-
export async function resolveImageInput(input, options = {}) {
|
|
397
|
-
const tokens = extractImagePathTokens(input);
|
|
398
|
-
if (tokens.length === 0) {
|
|
399
|
-
return {
|
|
400
|
-
actualInput: input,
|
|
401
|
-
displayInput: input,
|
|
402
|
-
errors: [],
|
|
403
|
-
attachments: [],
|
|
404
|
-
imagePathCount: 0,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
const attachments = [];
|
|
408
|
-
const errors = [];
|
|
409
|
-
const attachmentsByToken = new Map();
|
|
410
|
-
let nextLabelIndex = options.labelStart ?? 1;
|
|
411
|
-
for (const token of tokens) {
|
|
412
|
-
const result = await ingestImagePath(token.rawPath);
|
|
413
|
-
if (result.attachment) {
|
|
414
|
-
attachments.push(result.attachment);
|
|
415
|
-
attachmentsByToken.set(token, {
|
|
416
|
-
attachment: result.attachment,
|
|
417
|
-
label: imageAttachmentLabel(result.attachment, nextLabelIndex++),
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
else {
|
|
421
|
-
errors.push(`${token.rawPath}: ${result.error ?? "could not attach image"}`);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
if (attachments.length === 0) {
|
|
425
|
-
return {
|
|
426
|
-
actualInput: input,
|
|
427
|
-
displayInput: input,
|
|
428
|
-
errors,
|
|
429
|
-
attachments: [],
|
|
430
|
-
imagePathCount: tokens.length,
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
const parts = [];
|
|
434
|
-
let displayInput = "";
|
|
435
|
-
let cursor = 0;
|
|
436
|
-
for (const token of tokens) {
|
|
437
|
-
const entry = attachmentsByToken.get(token);
|
|
438
|
-
if (!entry)
|
|
439
|
-
continue;
|
|
440
|
-
const before = input.slice(cursor, token.start);
|
|
441
|
-
displayInput += before;
|
|
442
|
-
const text = before.trim();
|
|
443
|
-
if (text)
|
|
444
|
-
parts.push({ type: "text", text });
|
|
445
|
-
parts.push({ type: "image_url", image_url: { url: entry.attachment.dataUrl } });
|
|
446
|
-
displayInput += `[${entry.label}]`;
|
|
447
|
-
cursor = token.end;
|
|
448
|
-
}
|
|
449
|
-
const rest = input.slice(cursor);
|
|
450
|
-
displayInput += rest;
|
|
451
|
-
const restText = rest.trim();
|
|
452
|
-
if (restText)
|
|
453
|
-
parts.push({ type: "text", text: restText });
|
|
454
|
-
if (!parts.some((part) => part.type === "text")) {
|
|
455
|
-
parts.unshift({ type: "text", text: defaultImagePrompt(attachments.length) });
|
|
456
|
-
}
|
|
457
|
-
return {
|
|
458
|
-
actualInput: parts,
|
|
459
|
-
displayInput: displayInput.trim(),
|
|
460
|
-
errors,
|
|
461
|
-
attachments,
|
|
462
|
-
imagePathCount: tokens.length,
|
|
463
|
-
};
|
|
464
|
-
}
|
|
465
|
-
export async function resolveComposerImagePaths(input, options = {}) {
|
|
466
|
-
const tokens = extractImagePathTokens(input);
|
|
467
|
-
let nextLabelIndex = options.labelStart ?? 1;
|
|
468
|
-
if (tokens.length === 0) {
|
|
469
|
-
return {
|
|
470
|
-
text: input,
|
|
471
|
-
attachments: [],
|
|
472
|
-
errors: [],
|
|
473
|
-
imagePathCount: 0,
|
|
474
|
-
nextLabelIndex,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
const errors = [];
|
|
478
|
-
const attachments = [];
|
|
479
|
-
const replacements = new Map();
|
|
480
|
-
for (const token of tokens) {
|
|
481
|
-
const result = await ingestImagePath(token.rawPath);
|
|
482
|
-
if (!result.attachment) {
|
|
483
|
-
errors.push(`${token.rawPath}: ${result.error ?? "could not attach image"}`);
|
|
484
|
-
continue;
|
|
485
|
-
}
|
|
486
|
-
const label = imageAttachmentLabel(result.attachment, nextLabelIndex++);
|
|
487
|
-
attachments.push({ ...result.attachment, label });
|
|
488
|
-
replacements.set(token, `[${label}]`);
|
|
489
|
-
}
|
|
490
|
-
let text = "";
|
|
491
|
-
let cursor = 0;
|
|
492
|
-
for (const token of tokens) {
|
|
493
|
-
text += input.slice(cursor, token.start);
|
|
494
|
-
text += replacements.get(token) ?? input.slice(token.start, token.end);
|
|
495
|
-
cursor = token.end;
|
|
496
|
-
}
|
|
497
|
-
text += input.slice(cursor);
|
|
498
|
-
return {
|
|
499
|
-
text,
|
|
500
|
-
attachments,
|
|
501
|
-
errors,
|
|
502
|
-
imagePathCount: tokens.length,
|
|
503
|
-
nextLabelIndex,
|
|
504
|
-
};
|
|
505
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface MarkdownInlineSegment {
|
|
2
|
-
text: string;
|
|
3
|
-
color?: "text" | "textMuted" | "success" | "warning" | "secondary";
|
|
4
|
-
bold?: boolean;
|
|
5
|
-
italic?: boolean;
|
|
6
|
-
dim?: boolean;
|
|
7
|
-
}
|
|
8
|
-
type InlineToken = {
|
|
9
|
-
type?: string;
|
|
10
|
-
text?: string;
|
|
11
|
-
raw?: string;
|
|
12
|
-
href?: string;
|
|
13
|
-
tokens?: InlineToken[];
|
|
14
|
-
};
|
|
15
|
-
interface InlineStyle {
|
|
16
|
-
bold?: boolean;
|
|
17
|
-
italic?: boolean;
|
|
18
|
-
dim?: boolean;
|
|
19
|
-
color?: MarkdownInlineSegment["color"];
|
|
20
|
-
}
|
|
21
|
-
export declare function markdownInlineSegments(tokens: InlineToken[] | undefined, fallback?: string, style?: InlineStyle): MarkdownInlineSegment[];
|
|
22
|
-
export {};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
export function markdownInlineSegments(tokens, fallback = "", style = {}) {
|
|
2
|
-
const segments = [];
|
|
3
|
-
for (const token of tokens ?? []) {
|
|
4
|
-
appendInlineToken(segments, token, style);
|
|
5
|
-
}
|
|
6
|
-
if (segments.length === 0 && fallback) {
|
|
7
|
-
appendStyled(segments, fallback, style);
|
|
8
|
-
}
|
|
9
|
-
return segments;
|
|
10
|
-
}
|
|
11
|
-
function appendInlineToken(segments, token, style) {
|
|
12
|
-
switch (token.type) {
|
|
13
|
-
case "strong":
|
|
14
|
-
appendInlineTokens(segments, token.tokens, { ...style, bold: true });
|
|
15
|
-
return;
|
|
16
|
-
case "em":
|
|
17
|
-
appendInlineTokens(segments, token.tokens, { ...style, italic: true, color: style.color ?? "warning" });
|
|
18
|
-
return;
|
|
19
|
-
case "del":
|
|
20
|
-
appendInlineTokens(segments, token.tokens, { ...style, dim: true, color: style.color ?? "textMuted" });
|
|
21
|
-
return;
|
|
22
|
-
case "codespan":
|
|
23
|
-
appendStyled(segments, token.text ?? "", { ...style, color: "success" });
|
|
24
|
-
return;
|
|
25
|
-
case "link":
|
|
26
|
-
appendInlineTokens(segments, token.tokens, { ...style, color: style.color ?? "secondary" });
|
|
27
|
-
return;
|
|
28
|
-
case "br":
|
|
29
|
-
appendStyled(segments, "\n", style);
|
|
30
|
-
return;
|
|
31
|
-
case "text":
|
|
32
|
-
case "paragraph":
|
|
33
|
-
case "list_item":
|
|
34
|
-
case "heading":
|
|
35
|
-
if (token.tokens?.length) {
|
|
36
|
-
appendInlineTokens(segments, token.tokens, style);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
appendStyled(segments, token.text ?? token.raw ?? "", style);
|
|
40
|
-
}
|
|
41
|
-
return;
|
|
42
|
-
case "space":
|
|
43
|
-
return;
|
|
44
|
-
default:
|
|
45
|
-
if (token.tokens?.length) {
|
|
46
|
-
appendInlineTokens(segments, token.tokens, style);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
appendStyled(segments, token.text ?? token.raw ?? "", style);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function appendInlineTokens(segments, tokens, style) {
|
|
54
|
-
for (const child of tokens ?? []) {
|
|
55
|
-
appendInlineToken(segments, child, style);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
function appendStyled(segments, text, style) {
|
|
59
|
-
if (!text)
|
|
60
|
-
return;
|
|
61
|
-
segments.push({
|
|
62
|
-
text,
|
|
63
|
-
color: style.color ?? "text",
|
|
64
|
-
bold: style.bold,
|
|
65
|
-
italic: style.italic,
|
|
66
|
-
dim: style.dim,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface MarkdownThemePalette {
|
|
2
|
-
text: string;
|
|
3
|
-
textMuted: string;
|
|
4
|
-
background: string;
|
|
5
|
-
secondary: string;
|
|
6
|
-
info: string;
|
|
7
|
-
success: string;
|
|
8
|
-
warning: string;
|
|
9
|
-
accent: string;
|
|
10
|
-
error: string;
|
|
11
|
-
}
|
|
12
|
-
export interface SyntaxThemeRule {
|
|
13
|
-
scope: string[];
|
|
14
|
-
style: {
|
|
15
|
-
foreground?: string;
|
|
16
|
-
background?: string;
|
|
17
|
-
bold?: boolean;
|
|
18
|
-
italic?: boolean;
|
|
19
|
-
underline?: boolean;
|
|
20
|
-
dim?: boolean;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export declare function buildMarkdownThemeRules(theme: MarkdownThemePalette): SyntaxThemeRule[];
|