limixbot 0.3.35 → 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.
Files changed (51) hide show
  1. package/dist/assets/{ActivityPanel-Dy3daMqZ.js → ActivityPanel-BD6l_BSa.js} +1 -1
  2. package/dist/assets/{App-DOhqwPeE.js → App-CbT4-h7t.js} +53 -53
  3. package/dist/assets/{AppEventEditor-D3wkKqsP.js → AppEventEditor-CTA5zGkt.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-BFr8-nYd.js → BotSettingsDialog-CnxgGek3.js} +1 -1
  5. package/dist/assets/{BrowserPanel-CQLyI2_O.js → BrowserPanel-CX4xPQmH.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-CbSlQutT.js → BrowserProfilesManager-YWytzUvr.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-B4j1iPpl.js → CloudAddDialog-BMVUFBLd.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-DxjoI0QJ.js → ComputerFilesPane-CrLU5eGw.js} +1 -1
  9. package/dist/assets/{ComputerPanel-D7FHDawl.js → ComputerPanel-kJfe7_yh.js} +2 -2
  10. package/dist/assets/{DataPanel-DXxDYbO_.js → DataPanel-DKO3bOSP.js} +1 -1
  11. package/dist/assets/{FilesView-C5QQHziy.js → FilesView-DFm53zGa.js} +1 -1
  12. package/dist/assets/{GrokMoveDialog-DkNHrUoe.js → GrokMoveDialog-U4Dn0qjV.js} +1 -1
  13. package/dist/assets/{InspectorPanel-BF0jehfw.js → InspectorPanel-BQVvubJx.js} +1 -1
  14. package/dist/assets/{KeyboardShortcutsModal-DDQf54nB.js → KeyboardShortcutsModal-j_XkjjbG.js} +1 -1
  15. package/dist/assets/{LiveDesktop-U8kh4fxA.js → LiveDesktop-Dw246_jb.js} +1 -1
  16. package/dist/assets/{LocalVmWorkspace-DUSwSRPO.js → LocalVmWorkspace-DTumm8ar.js} +1 -1
  17. package/dist/assets/{MacLocalControl-DRbpu7dT.js → MacLocalControl-DGQgQwOC.js} +1 -1
  18. package/dist/assets/{MarkdownFilePreview-CXncOrns.js → MarkdownFilePreview-B1ENmVeN.js} +1 -1
  19. package/dist/assets/{NewBotDialog-BGANTTjV.js → NewBotDialog-CUPHYfOA.js} +1 -1
  20. package/dist/assets/{PhoneAppDialog-BLEPCUyQ.js → PhoneAppDialog-DBvCTPjD.js} +1 -1
  21. package/dist/assets/{PluginsPanel-DeGC7RZT.js → PluginsPanel-BHMywRlz.js} +1 -1
  22. package/dist/assets/{ProIntroduction-B4cVN7rz.js → ProIntroduction-C-Ngfyha.js} +1 -1
  23. package/dist/assets/{RemoteAgentSettingsPanel-CkX_NzFN.js → RemoteAgentSettingsPanel-B-FM_qkX.js} +1 -1
  24. package/dist/assets/{RoomPanel-C4l7q1pE.js → RoomPanel-CSloRoXd.js} +1 -1
  25. package/dist/assets/{RoutinesPage-BM5X4cwJ.js → RoutinesPage-BJnF_272.js} +1 -1
  26. package/dist/assets/{SettingsModal-BFWuvGVJ.js → SettingsModal-C2xabwue.js} +1 -1
  27. package/dist/assets/{ShareTeamDialog-SVxRxwoE.js → ShareTeamDialog-iiKMHE9O.js} +1 -1
  28. package/dist/assets/{SignedInSites-OqSs1fV3.js → SignedInSites-BdgWdVUi.js} +1 -1
  29. package/dist/assets/{TeamLibraryPanel-B67nbnKH.js → TeamLibraryPanel-gNxRx6dJ.js} +1 -1
  30. package/dist/assets/{TeamMapPage-C089dMgx.js → TeamMapPage-B04q4kNk.js} +1 -1
  31. package/dist/assets/{TriggersPage-BTsrBgM_.js → TriggersPage-BWv-cF6T.js} +1 -1
  32. package/dist/assets/{VisibilitySection-BVsfhXcQ.js → VisibilitySection-BgHgxqqh.js} +1 -1
  33. package/dist/assets/{WebhookTrigger-_6kY97hr.js → WebhookTrigger-DgHEoYp-.js} +1 -1
  34. package/dist/assets/{WorksOnGrid-BIPMOeXV.js → WorksOnGrid-DpwLxZio.js} +1 -1
  35. package/dist/assets/{core-DTfcT-3j.js → core-U5H80SxZ.js} +1 -1
  36. package/dist/assets/{import-name-B2mh0nds.js → import-name-BujoBk4Y.js} +1 -1
  37. package/dist/assets/{index-Cim2I1ag.js → index-BEyPuH85.js} +1 -1
  38. package/dist/assets/{index-BkqG98VF.js → index-BTJoFn8A.js} +2 -2
  39. package/dist/assets/{mcp-servers-C-YJGTCu.js → mcp-servers-CIlBM4yB.js} +1 -1
  40. package/dist/assets/{new-bot-rjcKzZ8q.js → new-bot-D2pBdFLY.js} +1 -1
  41. package/dist/assets/{org-library-CWUcEWkn.js → org-library-xIxGs5VY.js} +1 -1
  42. package/dist/assets/{package-format-D7inMk1b.js → package-format-DFnnhVuV.js} +1 -1
  43. package/dist/assets/{remote-desktop-panel-DoihNdNH.js → remote-desktop-panel-JUjpGN4N.js} +1 -1
  44. package/dist/index.html +1 -1
  45. package/dist-server/index.js +629 -619
  46. package/dist-server/package.json +1 -1
  47. package/dist-server/server/bot-api-host.js +17 -7
  48. package/dist-server/server/bot-api.js +1 -1
  49. package/dist-server/server/limix-channel-media.js +66 -0
  50. package/dist-server/server/webhook-ingress.js +2 -2
  51. package/package.json +1 -1
@@ -1 +1 @@
1
- {"type":"module","version":"0.3.35"}
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 parsed = callSchema.safeParse(parseJson(raw));
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, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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 > MAX_WEBHOOK_BODY_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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "limixbot",
3
- "version": "0.3.35",
3
+ "version": "0.3.37",
4
4
  "description": "Run the Limix Bot server anywhere and pair your devices to it (Leox ৹ Limix AI)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",