limixbot 0.3.36 → 0.3.37
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/{ActivityPanel-CHOOXhF2.js → ActivityPanel-BD6l_BSa.js} +1 -1
- package/dist/assets/{App-DACLgBBp.js → App-CbT4-h7t.js} +8 -8
- package/dist/assets/{AppEventEditor-yd__W_U5.js → AppEventEditor-CTA5zGkt.js} +1 -1
- package/dist/assets/{BotSettingsDialog-D0TwRB9V.js → BotSettingsDialog-CnxgGek3.js} +1 -1
- package/dist/assets/{BrowserPanel-Drp3HiE6.js → BrowserPanel-CX4xPQmH.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-CBi69tlJ.js → BrowserProfilesManager-YWytzUvr.js} +1 -1
- package/dist/assets/{CloudAddDialog-DuTdELlL.js → CloudAddDialog-BMVUFBLd.js} +1 -1
- package/dist/assets/{ComputerFilesPane-CQw24DeH.js → ComputerFilesPane-CrLU5eGw.js} +1 -1
- package/dist/assets/{ComputerPanel-DNgJVesd.js → ComputerPanel-kJfe7_yh.js} +2 -2
- package/dist/assets/{DataPanel-Cq0KvZP6.js → DataPanel-DKO3bOSP.js} +1 -1
- package/dist/assets/{FilesView-BEtP4Mzr.js → FilesView-DFm53zGa.js} +1 -1
- package/dist/assets/{GrokMoveDialog-CST2pJh9.js → GrokMoveDialog-U4Dn0qjV.js} +1 -1
- package/dist/assets/{InspectorPanel-BP95nKuG.js → InspectorPanel-BQVvubJx.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-Bf8o1jmh.js → KeyboardShortcutsModal-j_XkjjbG.js} +1 -1
- package/dist/assets/{LiveDesktop-DDbR84fh.js → LiveDesktop-Dw246_jb.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-Bwm8wLWQ.js → LocalVmWorkspace-DTumm8ar.js} +1 -1
- package/dist/assets/{MacLocalControl-D7qKApuf.js → MacLocalControl-DGQgQwOC.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-go6WDoyj.js → MarkdownFilePreview-B1ENmVeN.js} +1 -1
- package/dist/assets/{NewBotDialog-B1gjhKhM.js → NewBotDialog-CUPHYfOA.js} +1 -1
- package/dist/assets/{PhoneAppDialog-BjuVpKiH.js → PhoneAppDialog-DBvCTPjD.js} +1 -1
- package/dist/assets/{PluginsPanel-VW25pt0Z.js → PluginsPanel-BHMywRlz.js} +1 -1
- package/dist/assets/{ProIntroduction-Cyu7L6m4.js → ProIntroduction-C-Ngfyha.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-DFT8oaSE.js → RemoteAgentSettingsPanel-B-FM_qkX.js} +1 -1
- package/dist/assets/{RoomPanel-5JTYfABj.js → RoomPanel-CSloRoXd.js} +1 -1
- package/dist/assets/{RoutinesPage-poZPA-e1.js → RoutinesPage-BJnF_272.js} +1 -1
- package/dist/assets/{SettingsModal-CFir3mJE.js → SettingsModal-C2xabwue.js} +1 -1
- package/dist/assets/{ShareTeamDialog-DeHb5M55.js → ShareTeamDialog-iiKMHE9O.js} +1 -1
- package/dist/assets/{SignedInSites-KKFXLoTd.js → SignedInSites-BdgWdVUi.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-Wrxotmve.js → TeamLibraryPanel-gNxRx6dJ.js} +1 -1
- package/dist/assets/{TeamMapPage-DjiTO9Dz.js → TeamMapPage-B04q4kNk.js} +1 -1
- package/dist/assets/{TriggersPage-BAd0XpRJ.js → TriggersPage-BWv-cF6T.js} +1 -1
- package/dist/assets/{VisibilitySection-XakosUpX.js → VisibilitySection-BgHgxqqh.js} +1 -1
- package/dist/assets/{WebhookTrigger-QjSNg9QS.js → WebhookTrigger-DgHEoYp-.js} +1 -1
- package/dist/assets/{WorksOnGrid-C0IlVrdO.js → WorksOnGrid-DpwLxZio.js} +1 -1
- package/dist/assets/{core-BNohLdWF.js → core-U5H80SxZ.js} +1 -1
- package/dist/assets/{import-name-BNYqlOCE.js → import-name-BujoBk4Y.js} +1 -1
- package/dist/assets/{index-DRc3H3Yn.js → index-BEyPuH85.js} +1 -1
- package/dist/assets/{index-By-CYMXf.js → index-BTJoFn8A.js} +2 -2
- package/dist/assets/{mcp-servers-BTdtwb7Q.js → mcp-servers-CIlBM4yB.js} +1 -1
- package/dist/assets/{new-bot-BI7r44Kf.js → new-bot-D2pBdFLY.js} +1 -1
- package/dist/assets/{org-library-C5EqhsGN.js → org-library-xIxGs5VY.js} +1 -1
- package/dist/assets/{package-format-M6l7zHYk.js → package-format-DFnnhVuV.js} +1 -1
- package/dist/assets/{remote-desktop-panel-CRh1d2zD.js → remote-desktop-panel-JUjpGN4N.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/index.js +629 -619
- package/dist-server/package.json +1 -1
- package/dist-server/server/bot-api-host.js +17 -7
- package/dist-server/server/bot-api.js +1 -1
- package/dist-server/server/limix-channel-media.js +66 -0
- package/dist-server/server/webhook-ingress.js +2 -2
- package/package.json +1 -1
package/dist-server/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"0.3.
|
|
1
|
+
{"type":"module","version":"0.3.37"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { channelAttachmentSchema, channelReplyAttachments, saveChannelAttachments } from "./limix-channel-media.js";
|
|
2
|
+
import { deleteAttachment } from "./attachments.js";
|
|
1
3
|
// The Bot API's two sides. Outside: `POST /hooks/api/bots/<id>/messages` on the webhook receiver, a bearer key, a
|
|
2
4
|
// message in, the bot's reply out; the turn it starts is outside work (the "api" trigger), so it never acts for the
|
|
3
5
|
// person, is told the message came from outside, and anything that needs an approval waits for the person in the thread.
|
|
@@ -20,6 +22,7 @@ const PUBLIC_PATH = /^\/hooks\/api\/bots\/([\w-]{1,128})\/messages$/;
|
|
|
20
22
|
const APP_PATH = /^\/api\/bots\/([\w-]{1,128})\/bot-api(?:\/(new-key))?$/;
|
|
21
23
|
const callSchema = z.object({
|
|
22
24
|
message: z.string().min(1).max(BOT_API_MAX_MESSAGE_CHARS),
|
|
25
|
+
attachments: z.array(channelAttachmentSchema).max(4).optional(),
|
|
23
26
|
thread: z.string().regex(/^[\w-]{1,128}$/).optional(),
|
|
24
27
|
/** Seconds to wait for the reply, for a caller that knows nothing in its path drops a quiet connection. */
|
|
25
28
|
wait: z.number().min(0).max(BOT_API_MAX_WAIT_MS / 1000).optional(),
|
|
@@ -92,7 +95,7 @@ export function createBotApiHost(deps) {
|
|
|
92
95
|
return { thread: threadId, status: "needs_approval" };
|
|
93
96
|
if (deps.threadBusy(botId, threadId))
|
|
94
97
|
return { thread: threadId, status: "working" };
|
|
95
|
-
return { reply: replyText(after), thread: threadId };
|
|
98
|
+
return { reply: replyText(after), thread: threadId, ...channelReplyAttachments(after) };
|
|
96
99
|
}
|
|
97
100
|
async function runCall(botId, call, turnStarted, owner = false) {
|
|
98
101
|
const store = deps.store;
|
|
@@ -120,14 +123,15 @@ export function createBotApiHost(deps) {
|
|
|
120
123
|
if (owner)
|
|
121
124
|
markLimixOwnerThread(threadId);
|
|
122
125
|
}
|
|
126
|
+
const media = await saveChannelAttachments(call.attachments ?? []);
|
|
123
127
|
const receivedAt = Date.now();
|
|
124
|
-
const userMessage = store.appendMessage(threadId, { role: "user", kind: "text", text: message, via: "api" });
|
|
128
|
+
const userMessage = store.appendMessage(threadId, { role: "user", kind: "text", text: [message, media.tags].filter(Boolean).join("\n\n"), ...(media.saved.length ? { attachments: media.saved } : {}), via: "api" });
|
|
125
129
|
const after = () => { const all = store.messagesFor(threadId); return all.slice(all.findIndex((line) => line.id === userMessage.id) + 1); };
|
|
126
130
|
let settled;
|
|
127
131
|
let dispatchError;
|
|
128
132
|
markRunning(botId, threadId, true);
|
|
129
133
|
try {
|
|
130
|
-
await deps.startTurn(botId, botApiPrompt(message, receivedAt), {
|
|
134
|
+
await deps.startTurn(botId, [botApiPrompt(message, receivedAt), media.tags].filter(Boolean).join("\n\n"), {
|
|
131
135
|
threadId, automationSource: "api", unattended: true, userMessage,
|
|
132
136
|
onSettled: (outcome) => { settled = outcome; markRunning(botId, threadId, false); },
|
|
133
137
|
onDispatchError: (message) => { dispatchError = message; markRunning(botId, threadId, false); },
|
|
@@ -135,8 +139,11 @@ export function createBotApiHost(deps) {
|
|
|
135
139
|
}
|
|
136
140
|
catch (error) {
|
|
137
141
|
markRunning(botId, threadId, false);
|
|
138
|
-
if (opened)
|
|
142
|
+
if (opened) {
|
|
139
143
|
deps.discard?.(botId, threadId);
|
|
144
|
+
for (const item of media.saved)
|
|
145
|
+
deleteAttachment(item.path);
|
|
146
|
+
}
|
|
140
147
|
const busy = z.object({ code: z.enum(["thread_busy", "thread_limit"]) }).safeParse(error).success;
|
|
141
148
|
fail(busy ? 409 : 502, busy ? BUSY : COULD_NOT_ANSWER, error instanceof Error ? error.message : String(error));
|
|
142
149
|
}
|
|
@@ -157,7 +164,7 @@ export function createBotApiHost(deps) {
|
|
|
157
164
|
return { status: 202, body: { thread: threadId, status: "needs_approval" } };
|
|
158
165
|
if (!settled.ok)
|
|
159
166
|
fail(502, COULD_NOT_ANSWER, settled.text);
|
|
160
|
-
return { status: 200, body: { reply: replyText(after()), thread: threadId } };
|
|
167
|
+
return { status: 200, body: { reply: replyText(after()), thread: threadId, ...channelReplyAttachments(after()) } };
|
|
161
168
|
}
|
|
162
169
|
const door = async (req, res, url) => {
|
|
163
170
|
const match = PUBLIC_PATH.exec(url.pathname);
|
|
@@ -214,11 +221,14 @@ export function createBotApiHost(deps) {
|
|
|
214
221
|
}
|
|
215
222
|
let call;
|
|
216
223
|
try {
|
|
217
|
-
const raw = await readRawBody(req);
|
|
224
|
+
const raw = await readRawBody(req, 15 * 1024 * 1024);
|
|
218
225
|
const contentType = header(req, "content-type")?.toLowerCase() ?? "";
|
|
219
226
|
if (!contentType.includes("json"))
|
|
220
227
|
fail(415, "Send JSON: Content-Type: application/json");
|
|
221
|
-
const
|
|
228
|
+
const input = parseJson(raw);
|
|
229
|
+
if (input && typeof input === "object" && "message" in input && typeof input.message === "string" && input.message.length > BOT_API_MAX_MESSAGE_CHARS)
|
|
230
|
+
fail(413, "Message is too long");
|
|
231
|
+
const parsed = callSchema.safeParse(input);
|
|
222
232
|
if (!parsed.success)
|
|
223
233
|
fail(400, schemaIssue(parsed.error, "Send {\"message\": \"…\"}"));
|
|
224
234
|
call = parsed.data;
|
|
@@ -230,7 +230,7 @@ export class BotApiManager {
|
|
|
230
230
|
export const BOT_API_MESSAGE_DATA = "[UNTRUSTED BOT API MESSAGE]";
|
|
231
231
|
/** Security: the tag names a stored file for the turn to load, so a caller's copy of it never reaches the turn. */
|
|
232
232
|
export function withoutAttachedImages(message) {
|
|
233
|
-
return defuse(message).replace(/<(\s*attached-image)/gi, "($1");
|
|
233
|
+
return defuse(message).replace(/<(\s*attached-(?:image|file))/gi, "($1");
|
|
234
234
|
}
|
|
235
235
|
/** The caller's words go to the model as data from outside, never as the person's request, and can't pass for a note. */
|
|
236
236
|
export function botApiPrompt(message, receivedAt) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, resolve } from "node:path";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { ATTACHMENTS_DIR, deleteAttachment, saveFile, saveImage } from "./attachments.js";
|
|
5
|
+
export const CHANNEL_MEDIA_MAX_BYTES = 10 * 1024 * 1024;
|
|
6
|
+
export const channelAttachmentSchema = z.object({
|
|
7
|
+
name: z.string().min(1).max(200).refine((s) => !/[\\/\x00-\x1f]/.test(s), "Use a filename, not a path"),
|
|
8
|
+
mime: z.string().min(1).max(128),
|
|
9
|
+
data: z.string().min(4).max(Math.ceil(CHANNEL_MEDIA_MAX_BYTES / 3) * 4).regex(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/),
|
|
10
|
+
});
|
|
11
|
+
const attribute = (s) => s.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
12
|
+
export async function saveChannelAttachments(items) {
|
|
13
|
+
if (items.reduce((sum, item) => sum + Buffer.byteLength(item.data, "base64"), 0) > CHANNEL_MEDIA_MAX_BYTES) {
|
|
14
|
+
throw Object.assign(new Error("Attachments exceed 10 MB per message"), { status: 413, forCaller: true });
|
|
15
|
+
}
|
|
16
|
+
const saved = [];
|
|
17
|
+
try {
|
|
18
|
+
for (const item of items) {
|
|
19
|
+
const bytes = Buffer.from(item.data, "base64");
|
|
20
|
+
if (item.mime.startsWith("image/")) {
|
|
21
|
+
saved.push({ ...saveImage(bytes, item.mime), kind: "image", name: item.name });
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
const stream = async function* () { yield bytes; };
|
|
25
|
+
saved.push({ ...await saveFile(stream(), item.name, item.mime), kind: "file" });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { saved, tags: saved.map((item) => `<attached-${item.kind === "image" ? "image" : "file"} path="${attribute(item.path)}" name="${attribute("name" in item ? item.name ?? "attachment" : "attachment")}" />`).join("\n") };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
for (const item of saved)
|
|
32
|
+
deleteAttachment(item.path);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** Export only attachments explicitly emitted in this API reply, never paths mentioned in prose or tool results. */
|
|
37
|
+
export function channelReplyAttachments(lines) {
|
|
38
|
+
const attachments = [];
|
|
39
|
+
let total = 0;
|
|
40
|
+
let mediaError = false;
|
|
41
|
+
for (const line of lines) {
|
|
42
|
+
if (line.role !== "bot")
|
|
43
|
+
continue;
|
|
44
|
+
for (const item of line.attachments ?? []) {
|
|
45
|
+
if ("fromTool" in item && item.fromTool)
|
|
46
|
+
continue;
|
|
47
|
+
try {
|
|
48
|
+
const path = resolve(item.path);
|
|
49
|
+
if (dirname(path) !== resolve(ATTACHMENTS_DIR) || lstatSync(path).isSymbolicLink() || dirname(realpathSync(path)) !== realpathSync(ATTACHMENTS_DIR))
|
|
50
|
+
throw new Error("not an attachment");
|
|
51
|
+
const stat = lstatSync(path);
|
|
52
|
+
if (!stat.isFile() || attachments.length >= 4 || total + stat.size > CHANNEL_MEDIA_MAX_BYTES)
|
|
53
|
+
throw new Error("too large");
|
|
54
|
+
const data = readFileSync(path);
|
|
55
|
+
total += data.length;
|
|
56
|
+
const prefix = item.mime.split("/")[0];
|
|
57
|
+
const kind = prefix === "image" || prefix === "audio" || prefix === "video" ? prefix : "file";
|
|
58
|
+
attachments.push({ name: "name" in item && item.name ? basename(item.name) : basename(path), mime: item.mime, kind, size: data.length, data: data.toString("base64") });
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
mediaError = true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { ...(attachments.length ? { attachments } : {}), ...(mediaError ? { mediaError: true } : {}) };
|
|
66
|
+
}
|
|
@@ -14,14 +14,14 @@ export function json(res, status, body) {
|
|
|
14
14
|
});
|
|
15
15
|
res.end(JSON.stringify(body));
|
|
16
16
|
}
|
|
17
|
-
export async function readRawBody(req) {
|
|
17
|
+
export async function readRawBody(req, maxBytes = MAX_WEBHOOK_BODY_BYTES) {
|
|
18
18
|
const chunks = [];
|
|
19
19
|
let bytes = 0;
|
|
20
20
|
try {
|
|
21
21
|
for await (const chunk of req) {
|
|
22
22
|
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
23
23
|
bytes += buffer.length;
|
|
24
|
-
if (bytes >
|
|
24
|
+
if (bytes > maxBytes) {
|
|
25
25
|
throw Object.assign(new Error("Webhook body is too large"), { status: 413 });
|
|
26
26
|
}
|
|
27
27
|
chunks.push(buffer);
|