limixbot 0.3.119 → 0.3.121

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 (55) hide show
  1. package/dist/assets/{ActivityPanel-l9mkZj3c.js → ActivityPanel-oH7zEe1h.js} +1 -1
  2. package/dist/assets/{App-CEAzIqrp.js → App-C8J3XlgX.js} +9 -9
  3. package/dist/assets/{AppEventEditor-BKzVDU63.js → AppEventEditor-lsrjdXGL.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-BvwqItvE.js → BotSettingsDialog-BLVf7lNL.js} +1 -1
  5. package/dist/assets/{BrowserPanel-bnuqUOz3.js → BrowserPanel-jSj0h--T.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-CUcXphXT.js → BrowserProfilesManager-D8QTMXbY.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-CLEsRgra.js → CloudAddDialog-CJtv0FXr.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-CE6kJr6z.js → ComputerFilesPane-BybRekwz.js} +1 -1
  9. package/dist/assets/{ComputerPanel-CfHxPV-U.js → ComputerPanel-DiOEMYnD.js} +2 -2
  10. package/dist/assets/{DataPanel-DlfWhJ2l.js → DataPanel-D3DoJnrd.js} +1 -1
  11. package/dist/assets/{GrokMoveDialog-BNWxAa5N.js → GrokMoveDialog-CLpqy9bk.js} +1 -1
  12. package/dist/assets/{InspectorPanel-B6K0R7ZI.js → InspectorPanel-BPvo8nZZ.js} +1 -1
  13. package/dist/assets/{KeyboardShortcutsModal-BsuaxSbW.js → KeyboardShortcutsModal-DrsY7KSu.js} +1 -1
  14. package/dist/assets/{LimixResizeHandles-LTylExKz.js → LimixResizeHandles-BN2p7F7v.js} +1 -1
  15. package/dist/assets/{LiveDesktop-wCtWba6M.js → LiveDesktop-DxEwcNB2.js} +1 -1
  16. package/dist/assets/{LocalVmWorkspace-HjB7RZ-Z.js → LocalVmWorkspace-DJqDfber.js} +1 -1
  17. package/dist/assets/{MacLocalControl-LWJJgz11.js → MacLocalControl-d0NFbMGE.js} +1 -1
  18. package/dist/assets/{MarkdownFilePreview-DSrxVVhX.js → MarkdownFilePreview-BgsQgg1i.js} +1 -1
  19. package/dist/assets/{NewBotDialog-CdjLWn-L.js → NewBotDialog-C4UKPcXX.js} +1 -1
  20. package/dist/assets/{PhoneAppDialog-BoNheaDw.js → PhoneAppDialog-xv4wn1mI.js} +1 -1
  21. package/dist/assets/PluginsPanel-BwMqAsml.js +8 -0
  22. package/dist/assets/{ProIntroduction-CTl2MGYw.js → ProIntroduction-r5lv0CF0.js} +1 -1
  23. package/dist/assets/{RemoteAgentSettingsPanel-BwW8Dn4E.js → RemoteAgentSettingsPanel-D4mqcx4G.js} +1 -1
  24. package/dist/assets/{RoomPanel-CMUHW-ng.js → RoomPanel-Cc1ir5Pl.js} +1 -1
  25. package/dist/assets/{RoutinesPage-DB91MHqs.js → RoutinesPage-B2YvkjVI.js} +1 -1
  26. package/dist/assets/{SettingsModal-BsrT3E14.js → SettingsModal-BrhwprP3.js} +1 -1
  27. package/dist/assets/{ShareTeamDialog-CcBEpMqD.js → ShareTeamDialog-DqP_VnFb.js} +1 -1
  28. package/dist/assets/{SignedInSites-DkT1rvTd.js → SignedInSites-CUea4XRc.js} +1 -1
  29. package/dist/assets/{TeamLibraryPanel-zV-86ahA.js → TeamLibraryPanel-BLrtwnPP.js} +1 -1
  30. package/dist/assets/{TeamMapPage-CZgGndK3.js → TeamMapPage-66LUkJrG.js} +1 -1
  31. package/dist/assets/{TriggersPage-DbVlUurg.js → TriggersPage-BSq-2mGc.js} +1 -1
  32. package/dist/assets/{VisibilitySection-BFM8tVU4.js → VisibilitySection-c3v2Urid.js} +1 -1
  33. package/dist/assets/{WebhookTrigger-CHg2JRGq.js → WebhookTrigger-CNOxLHYz.js} +1 -1
  34. package/dist/assets/{WorksOnGrid-Bakox8KX.js → WorksOnGrid-mltm5SpQ.js} +1 -1
  35. package/dist/assets/{core-Cjaw1pBq.js → core-d8uKQbt4.js} +1 -1
  36. package/dist/assets/{import-name-Bjlw9jiM.js → import-name-BWQG-MzO.js} +1 -1
  37. package/dist/assets/{index-1nLJcLwH.js → index-C9y4_V8D.js} +2 -2
  38. package/dist/assets/{index-EVmEXe2l.js → index-DpOAIW5C.js} +1 -1
  39. package/dist/assets/{mcp-servers-zi8N7I1M.js → mcp-servers-BS2X7Buc.js} +1 -1
  40. package/dist/assets/{new-bot-mpygivK8.js → new-bot-BM05ocFQ.js} +1 -1
  41. package/dist/assets/{org-library-YpW2P8UH.js → org-library-C1IF7HY_.js} +1 -1
  42. package/dist/assets/{package-format-C1QxHZKk.js → package-format-DwAaZAgV.js} +1 -1
  43. package/dist/assets/{remote-desktop-panel-CDUUA-78.js → remote-desktop-panel-lMPAPeAh.js} +1 -1
  44. package/dist/index.html +1 -1
  45. package/dist-server/index.js +2766 -2746
  46. package/dist-server/package.json +1 -1
  47. package/dist-server/server/decider/index.js +32 -1
  48. package/dist-server/server/decider/relay.js +1 -1
  49. package/dist-server/server/extractor/contract.js +1 -1
  50. package/dist-server/server/index.js +15 -5
  51. package/dist-server/server/plugin-hub.js +151 -0
  52. package/dist-server/server/routes/helper-tools.js +1 -1
  53. package/dist-server/shared/plugin-hub.js +3 -0
  54. package/package.json +1 -1
  55. package/dist/assets/PluginsPanel-CPjWtDIQ.js +0 -8
@@ -1 +1 @@
1
- {"type":"module","version":"0.3.119"}
1
+ {"type":"module","version":"0.3.121"}
@@ -1,3 +1,4 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { userError } from "../user-errors.js";
2
3
  import { deciderCredential } from "../included-services.js";
3
4
  import { helpersOn, includedAccount, jevAccount, openrouterAccount, sharedOpenRouterKey, workersAiAccount, } from "./accounts.js";
@@ -151,6 +152,7 @@ const isJob = (seam) => DECIDER_JOBS.includes(seam);
151
152
  export function createDecider(deps) {
152
153
  const fetchImpl = deps.fetch ?? fetch;
153
154
  const now = deps.now ?? (() => performance.now());
155
+ const decisions = new Map();
154
156
  function gate(cfg, seam) {
155
157
  if (cfg.decider?.provider === "off")
156
158
  return "disabled";
@@ -248,7 +250,36 @@ export function createDecider(deps) {
248
250
  // Through the included token, only the exact requests the relay takes.
249
251
  if (account.included && !relayAccepts(seam, state, questions))
250
252
  return { ok: false, reason: "misconfigured" };
251
- return await call(seam, account, { ...openrouterRequest(cfg, account), state, questions }, options);
253
+ const request = { ...openrouterRequest(cfg, account), state, questions };
254
+ if (account.provider !== "jev" || seam !== "botDecide" || !options.turnScope || options.signal) {
255
+ return await call(seam, account, request, options);
256
+ }
257
+ const key = createHash("sha256").update(JSON.stringify([options.turnScope, account.token, account.api, account.included, options.timeoutMs, request])).digest("hex");
258
+ const lookupStarted = now();
259
+ const prior = decisions.get(key);
260
+ if (prior && prior.expires > now()) {
261
+ const cached = await prior.result;
262
+ if (cached.ok)
263
+ return { ...cached, answers: structuredClone(cached.answers), latencyMs: Math.max(0, Math.round(now() - lookupStarted)), inputTokens: 0 };
264
+ return cached;
265
+ }
266
+ decisions.delete(key);
267
+ if (decisions.size >= 128)
268
+ decisions.delete(decisions.keys().next().value);
269
+ const result = call(seam, account, request, options);
270
+ const entry = { expires: now() + 30_000, result };
271
+ decisions.set(key, entry);
272
+ try {
273
+ const answer = await result;
274
+ if (!answer.ok && decisions.get(key) === entry)
275
+ decisions.delete(key);
276
+ return structuredClone(answer);
277
+ }
278
+ catch (error) {
279
+ if (decisions.get(key) === entry)
280
+ decisions.delete(key);
281
+ throw error;
282
+ }
252
283
  }
253
284
  catch {
254
285
  return { ok: false, reason: "malformed" };
@@ -3,7 +3,7 @@
3
3
  import { jevRequestBody } from "./jev.js";
4
4
  import { INBOX_DISMISSED_MAX, INBOX_EMAIL_KEYS, INBOX_TRIAGE_INSTRUCTIONS, INBOX_TRIAGE_OPTIONS, INBOX_TRIAGE_STATE_KEYS } from "./inbox-triage.js";
5
5
  import { ROOM_ROUTING_INSTRUCTIONS, ROOM_ROUTING_STATE_KEYS } from "./room-routing.js";
6
- export const KEY_CHECK_STATE = { purpose: "Limix Bot is checking that a decision-model key works." };
6
+ export const KEY_CHECK_STATE = { purpose: "OpenMausBot is checking that a decision-model key works." };
7
7
  export const KEY_CHECK_QUESTION = "Is this a connection check?";
8
8
  /** Measured in UTF-8 bytes. */
9
9
  export const RELAY_MAX_BODY_BYTES = 64 * 1024;
@@ -18,7 +18,7 @@ export const IMAGE_MIMES = new Set(["image/png", "image/jpeg", "image/webp"]);
18
18
  const SEAMS = new Set(["inboxTriage", "botExtract", "keyCheck"]);
19
19
  export const EXTRACT_KEY_CHECK = {
20
20
  fields: { ok: { type: "boolean", description: "Is this a connection check?" } },
21
- input: { text: "Limix Bot is checking that an extraction-model key works." },
21
+ input: { text: "OpenMausBot is checking that an extraction-model key works." },
22
22
  };
23
23
  /** The proactive inbox reads these from one email, and the relay takes inbox triage only with exactly these. */
24
24
  export const INBOX_KINDS = ["personal", "work", "newsletter", "receipt", "notification", "marketing", "other"];
@@ -535,6 +535,7 @@ import { createGroupOrderRoutes } from "./routes/group-order.js";
535
535
  import { createBotLifecycleRoutes } from "./routes/bot-lifecycle.js";
536
536
  import { createBotSkillsRoutes } from "./routes/bot-skills.js";
537
537
  import { startHubAutoSync } from "./limix-skill-hub.js";
538
+ import { createPluginHub } from "./plugin-hub.js";
538
539
  import { limixBundledFor, limixSelectBundled, limixSkillDefaultsMigration } from "./limix-skill-store.js";
539
540
  import { createSkillShareRoutes } from "./routes/skill-share.js";
540
541
  import { createTeamContextRoutes } from "./routes/team-context.js";
@@ -3048,6 +3049,7 @@ function previewSystemPrompt(bot) {
3048
3049
  { id: "profile", label: "Profile changes", text: agentsMounted ? PROFILE_PROMPT : "" },
3049
3050
  { id: "section-context", label: "Section context", text: sectionContextSystemPrompt(bot.section) },
3050
3051
  { id: "team-memory", label: "Team memory", text: teamMemory.systemPrompt(bot.section) + (agentsMounted ? TEAM_MEMORY_PROMPT : "") },
3052
+ { id: "skill-instructions", label: "Plugin instructions", text: pluginHub.instructions(bot, caps?.customMcp ? Object.keys(engineMcpServers(bot)) : []) },
3051
3053
  teamAvailabilityPart(agentsMounted && coordination ? peers : []),
3052
3054
  { id: "memory", label: "Memory", text: memorySystemPrompt(bot.id, { managedWrites: agentsMounted, fileTools: Boolean(privateWorkspace), enabled: bot.memoryEnabled !== false }) },
3053
3055
  { id: "skills", label: "Skills index", text: privateWorkspace ? skillsHost.skillsIndex(bot, undefined, instance) : "" },
@@ -8731,7 +8733,7 @@ async function beginTurn(botId, text, opts) {
8731
8733
  { id: "memory", label: "Memory", text: memorySystemPrompt(teamHost.layer(bot.id, threadId), { managedWrites: Boolean(integrations.agents), fileTools: worksInWorkspace && !apiFenced, enabled: bot.memoryEnabled !== false, writesRefused: notesRefused }) + teamHost.sharedNotesPrompt(bot.id, threadId) },
8732
8734
  // liveBot predates awaited setup work; an assignment PUT in that window must still reach this prompt.
8733
8735
  { id: "skills", label: "Skills index", text: privateWorkspace ? skillsHost.skillsIndex(store.bot(bot.id) ?? bot, threadId, instance) : "" },
8734
- { id: "skill-instructions", label: "Skill instructions", text: skillInstructions },
8736
+ { id: "skill-instructions", label: "Skill instructions", text: skillInstructions + pluginHub.instructions(bot, Object.keys(integrations.custom ?? {})) },
8735
8737
  { id: "playbooks", label: "Playbooks", text: packagePlaybooks },
8736
8738
  { id: "webhook", label: "Webhook provenance", text: opts?.automationSource === "webhook" ? WEBHOOK_PROMPT : opts?.automationSource === "api" ? BOT_API_PROMPT : "" },
8737
8739
  { id: "automation-reply", label: "Automation reply", text: opts?.automationSource && automationReports.reportsElsewhere(threadId) ? AUTOMATION_REPLY_PROMPT : "" },
@@ -10578,7 +10580,7 @@ setupRetry = 0) {
10578
10580
  { id: "team-memory", label: "Team memory", text: teamMemory.systemPrompt(bot.section) + (integrations.agents ? TEAM_MEMORY_PROMPT : "") },
10579
10581
  { id: "memory", label: "Memory", text: roomMemory ? `\n${roomMemory.trim()}` : "" },
10580
10582
  { id: "skills", label: "Skills index", text: workspace ? skillsHost.skillsIndex(bot, threadId, instance) : "" },
10581
- { id: "skill-instructions", label: "Skill instructions", text: renderSkillInstructions(selectedSkills, { includeRoot: Boolean(workspace) }) },
10583
+ { id: "skill-instructions", label: "Skill instructions", text: renderSkillInstructions(selectedSkills, { includeRoot: Boolean(workspace) }) + pluginHub.instructions(bot, Object.keys(integrations.custom ?? {})) },
10582
10584
  { id: "playbooks", label: "Playbooks", text: installedPlaybookInstructions(text, bot.playbooks) },
10583
10585
  ], integrations.agents, { rules: cfg.everyBotRules });
10584
10586
  // Claim /learn only after setup succeeded, so a failed first responder does not consume it.
@@ -12537,8 +12539,13 @@ ROUTES.push(createBotLifecycleRoutes({
12537
12539
  store, routines: () => routines, interruptAllDirectThreads, cancelDirectTurnDispatch, revokeInternalCapabilitiesForThread,
12538
12540
  activeGroupTurnForBot, cancelGroupTurnOperations, runningTurnInstance, closeOpenApprovals, deleteBotWithLifecycle,
12539
12541
  }));
12542
+ const pluginHub = createPluginHub(DATA_DIR, () => ({
12543
+ bots: store.bots.map(({ id, name, section }) => ({ id, name, section })),
12544
+ teams: store.sections.filter(Boolean),
12545
+ }));
12546
+ pluginHub.pruneTeams(store.sections);
12540
12547
  const skillsRoutes = createBotSkillsRoutes({ store, cfg, listBotSkills, readBotSkillFile, stagedSkillListing });
12541
- ROUTES.push(skillsRoutes);
12548
+ ROUTES.push(skillsRoutes, pluginHub.route);
12542
12549
  startHubAutoSync();
12543
12550
  ROUTES.push(createEmailRoutes({ service: emailService }));
12544
12551
  ROUTES.push(phones.routes);
@@ -12600,7 +12607,10 @@ ROUTES.push(createDeciderRoutes({ decider, extractor, config: () => cfg }), crea
12600
12607
  } : {}) }), createTtsRoutes({ config: () => cfg }), createHelperSuggestionRoutes({ notNow: proactive.suggestionNotNow }), createSetupRequestRoutes({ store, language: () => appLanguage() ?? Intl.DateTimeFormat().resolvedOptions().locale, sendRefusal: cloudGuestSendRefusal, presser: (auth) => setupPresser(sharedMembership(), auth, messageSender(auth)), canSetUp: (botId, threadId) => registry.get(store.projectBotForTask(botId, threadId)?.modelSelection.instanceId ?? "")?.adapter.capabilities.agentsMcp === true, send: (auth, botId, threadId, text) => acceptDirectSend({ botId, threadId, text, sender: messageSender(auth), trigger: usageTriggerFor(auth), personPresent: auth.kind === "session" || DESKTOP_MANAGED }) }), createNotificationRoutes(undefined, notificationListed), createUpdateCheckRoutes({ check: serverUpdateChecker({ desktopManaged: DESKTOP_MANAGED, managed: Boolean(CLOUD_HOME || HOSTED_WORKSPACE) }) }), createSeatsRoutes({ signInList: signInAllowList, sessions: () => sessions.list() }), createTimeZoneRoutes({ adopts: Boolean(CLOUD_HOME), dataDir: DATA_DIR, changed: () => routines?.rescheduleLocalTimes() }), createCloudSendRoutes({ appVersion: serverVersion(), ...(CLOUD_TEAM ? { refusal: personalMoveRefusal(CLOUD_TEAM), scope: (auth) => teamMoveIn?.scope(auth) ?? null } : {}), bots: () => store.bots, messagesTail: (threadId, limit) => store.messagesTail(threadId, limit), skills: (bot) => listSkills(bot.id), logins, config: () => cfg, lineLanguage: personLanguages.forLine, chats: { store, dataDir: DATA_DIR, owner: cloudSendOwner, ...(CLOUD_OWNER_KEY ? { ownerKey: CLOUD_OWNER_KEY } : {}), stamped: (threadId) => ownerOnlyCache.delete(threadId), instanceExists: (id) => Boolean(registry.get(id)), approvalSupported: (selection, mode) => supportsApprovalMode(selection, mode) }, cloudHome: Boolean(CLOUD_HOME), ownHome: ownHome.owner, automations: { routines: () => routines, calls: () => calendarCalls, webhooks: () => webhooks, appEvents: () => appTriggers.manager, waits: () => botWaits }, connectionsMoved: (language) => cloudConnections.moved(language), connections: () => cloudConnections.connections(), connectionFingerprints: (nonce) => cloudConnections.fingerprints(nonce), move: { dataDir: DATA_DIR, store, routines: () => routines, calls: () => calendarCalls, webhooks: () => webhooks, appEvents: () => appTriggers.manager, claudeCodeSkills: () => (claudeUserSkillsEnabled(cfg) ? claudeCodeSkillInputs() : []), instanceExists: (id) => Boolean(registry.get(id)), owner: cloudSendOwner, ownRoutine: (routine, person) => { cloudRoutineAuthors?.record(routine.id, routine); cloudRoutineAuthors?.wrote(routine.id, person); }, arrived: () => ownerOnlyCache.clear(), teamMemory, aboutMe: () => cfg.profile?.aboutMe ?? "", saveAboutMe: (text) => { saveConfig({ profile: { ...cfg.profile, aboutMe: text } }); Object.assign(cfg, loadConfig()); broadcast({ kind: "config", ...configStatus() }); } } }), cloudConnections.routes, createTodayRoutes({ visibleFor: (auth) => visibleTo(viewerFor(auth)), ...(teamOwners.asks ? { asks: teamOwners.asks, messages: teamMessages.needsYou } : {}), sources: () => ({ bots: store.bots, groups: store.groups, routines, parked: coordinator.active(), engines: registry.instances().map((instance) => ({ instanceId: instance.instanceId, snapshot: registry.lastSnapshot(instance.instanceId) })) }) }), createInboxRoutes(teamMessages));
12601
12608
  if (CLOUD_TEAM)
12602
12609
  teamHost.adoptServerProfile(sessions.list().flatMap((session) => session.email ? [session.email] : []));
12603
- const sidebarRoutes = createSidebarSectionRoutes({ store, teamComputers, maxBots: MAX_WORKSPACE_BOTS, assertTeamComputerChangeIdle, wireBot, renamed: (from, to) => (to ? botHolds.rename(from, to) : botHolds.forget("department", from)) });
12610
+ const sidebarRoutes = createSidebarSectionRoutes({ store, teamComputers, maxBots: MAX_WORKSPACE_BOTS, assertTeamComputerChangeIdle, wireBot, renamed: (from, to) => { pluginHub.renameTeam(from, to); if (to)
12611
+ botHolds.rename(from, to);
12612
+ else
12613
+ botHolds.forget("department", from); } });
12604
12614
  ROUTES.push(teamPresence.routes, sidebarRoutes, createPresenceRoutes({ isOwner: ownerOrAdmin, heard: (auth, language) => personLanguages.heard(auth.kind === "session" ? actorKey(auth) : THIS_COMPUTER, language), sawChat: (_auth, threadId) => { if (store.botByThread(threadId))
12605
12615
  sawThread(threadId); }, active: async (source, zone, language) => { const answer = await proactive.brief.active(source, zone, language); firstHourHooks.arrived(); return answer; }, ...(CLOUD_TEAM ? { member: (auth) => { noAiNotice.flush(); return teamMessages.arrived(auth); } } : {}) }), createMeRoutes({ team: CLOUD_TEAM, session: (auth) => (auth.kind === "session" ? auth.session : null), welcome: teamWelcome, profile: teamHost.memberProfile, save: teamHost.saveMemberProfile, seed: teamHost.seedMemberProfile, seeded: teamHost.seededFields, changed: () => broadcast({ kind: "config", ...configStatus() }) }), teamAway.routes, createTeamPhoneRoutes({ team: CLOUD_TEAM, sessions, publicBase: (req, auth) => pairingLinkBase(publicUrl(), auth.kind === "session" ? requestOrigin(req) : null) }), createTeamConnectionRoutes({ host: teamConnections, cfg: () => cfg, composio, policy: managedPolicy, publicOrigin: CLOUD_HOME?.publicOrigin ?? null, record: (auth, row) => appendAdminAction(DATA_DIR, { ...row, actor: decisionActorFor(auth) }) }), createSignInCardRoutes({ settle: signInSettle.settle, saveLogin: (botId, threadId, messageId, body, auth) => CLOUD_TEAM && !auth.scopes.includes("admin") ? Promise.resolve({ status: 403, body: memberLoginRefusal(CLOUD_TEAM) }) : saveLoginFromCard(botId, threadId, messageId, body), saveTarget: signInSaveTarget, threadVisible: (auth, threadId) => visibleTo(viewerFor(auth)).thread(threadId), vault: createSignInVaultChoices({ logins, cardBots: (id) => botLogins.cardBots(id), settle: signInSettle.settle, openCard: (botId, threadId, messageId) => { const card = signInMessage(botId, threadId, messageId)?.signIn; return card && card.place === "browser" && !card.superseded && !card.answeredInChat && !card.stopped && !signInOutcome(card) ? card : null; } }) }));
12606
12616
  const appSuggestions = createAppSuggestions({ dataDir: DATA_DIR, store, configured: () => composio.configured(cfg), catalog: () => composio.listToolkits(cfg), services: () => composio.connectedServices(cfg), offerable: (slug) => !managedPolicy.appRefusal(slug) && !managedConnectorUnavailableReason(composio.connectionMode(cfg), slug) && !teamConnections.personApps().includes(slug), pickAvailable: () => appPickAvailable(cfg), decider });
@@ -13433,7 +13443,7 @@ const handleRequest = async (req, res) => {
13433
13443
  }
13434
13444
  };
13435
13445
  const botFolders = async () => ({ roots: messageFileRootsForThread(internalSender.id, internalCapability.threadId).filter((root) => root !== ATTACHMENTS_DIR), vmWorkspace: (await attachmentVmForTurn(internalCapability))?.workspaceDir ?? null });
13436
- if (await lentMcp.route({ method, path, req, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS || await internalToolRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, folders: botFolders }) !== PASS || await waitRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, ...waitTurnChecks(internalCapability, internalSender) }) !== PASS || await teamMessages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || await devsReports.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || (computerAsks && await computerAsks.internal({ method, path, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS) || await meetingsHost.internal({ method, path, res, json, readBody: readInternalBody, bot: internalSender, threadId: internalCapability.threadId, active: () => internalCapabilityIsActive(internalCapability) }) !== PASS || await imageTools.internal({ botId: internalSender.id, method, path, res, json, readBody: readInternalBody, threadId: internalCapability.threadId, requireActive: requireActiveInternalCapability, personTurn: turnOrigin(internalCapability).kind === "user" || (Boolean(roomRun(internalCapability.generation)?.requestMessageId) && guestDrivenTurns.get(internalCapability.threadId) !== internalCapability.generation) }) !== PASS)
13446
+ if (await lentMcp.route({ method, path, req, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS || await internalToolRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, turnScope: JSON.stringify([internalSender.id, internalCapability.threadId, internalCapability.generation]), readBody: readInternalBody, folders: botFolders }) !== PASS || await waitRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, ...waitTurnChecks(internalCapability, internalSender) }) !== PASS || await teamMessages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || await devsReports.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || (computerAsks && await computerAsks.internal({ method, path, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS) || await meetingsHost.internal({ method, path, res, json, readBody: readInternalBody, bot: internalSender, threadId: internalCapability.threadId, active: () => internalCapabilityIsActive(internalCapability) }) !== PASS || await imageTools.internal({ botId: internalSender.id, method, path, res, json, readBody: readInternalBody, threadId: internalCapability.threadId, requireActive: requireActiveInternalCapability, personTurn: turnOrigin(internalCapability).kind === "user" || (Boolean(roomRun(internalCapability.generation)?.requestMessageId) && guestDrivenTurns.get(internalCapability.threadId) !== internalCapability.generation) }) !== PASS)
13437
13447
  return;
13438
13448
  const callSignal = turnCallSignals.signal(internalCapability, res);
13439
13449
  if (await publishedPages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, requireActive: requireActiveInternalCapability, signal: callSignal, folders: botFolders, post: (text, publishedPage, bundle) => { const source = connectorThread(internalSender.id, internalCapability.threadId); return !source ? null : (bundle && publishedPages.show({ threadId: internalCapability.threadId, card: publishedPage, bundle, bot: internalSender })) || store.appendMessage(internalCapability.threadId, { role: "bot", kind: "text", text, publishedPage, ...(source.group ? { from: { botId: internalSender.id, name: internalSender.name, color: internalSender.color } } : {}) }).id; } }) !== PASS)
@@ -0,0 +1,151 @@
1
+ import { createHash } from "node:crypto";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { z } from "zod";
5
+ import { writeFileAtomic } from "./atomic.js";
6
+ import { ownerOrAdmin } from "./request-auth.js";
7
+ import { PASS } from "./routes/table.js";
8
+ import { pluginEnabled } from "../shared/plugin-hub.js";
9
+ const root = "https://raw.githubusercontent.com/leomieo/limix-plugin-hub/main/";
10
+ const slug = z.string().max(64).regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
11
+ const labels = (max) => z.object({ en: z.string().min(1).max(max), vi: z.string().min(1).max(max) }).strict();
12
+ const metadata = z.object({
13
+ id: slug, version: z.string().max(40).regex(/^\d+\.\d+\.\d+$/),
14
+ name: labels(96), description: labels(600),
15
+ requiresMcp: z.array(z.string().regex(/^[\w-]{1,80}$/)).max(12),
16
+ }).strict();
17
+ const digest = z.string().regex(/^[a-f0-9]{64}$/);
18
+ const entry = metadata.extend({ sha256: digest });
19
+ const catalog = z.array(entry).max(500).refine(rows => new Set(rows.map(r => r.id)).size === rows.length);
20
+ const bundle = metadata.extend({ instructions: z.string().trim().min(1).max(8000) });
21
+ const installed = bundle.extend({ sha256: digest, teams: z.array(z.string()), bots: z.record(z.string(), z.boolean()) });
22
+ const database = z.object({ catalog, installed: z.array(installed) });
23
+ const change = z.discriminatedUnion("action", [
24
+ z.object({ action: z.literal("sync") }),
25
+ z.object({ action: z.literal("install"), id: slug, sha256: digest }),
26
+ z.object({ action: z.literal("remove"), id: slug }),
27
+ z.object({ action: z.literal("assign"), id: slug, sha256: digest, target: z.enum(["bot", "team"]), key: z.string().min(1).max(256), enabled: z.boolean().nullable() }),
28
+ ]);
29
+ async function download(path, limit) {
30
+ const response = await fetch(root + path, { redirect: "error", signal: AbortSignal.timeout(15000) });
31
+ if (!response.ok || !response.body)
32
+ throw Error("Plugin download failed (" + response.status + ")");
33
+ const reader = response.body.getReader();
34
+ const chunks = [];
35
+ let size = 0;
36
+ while (true) {
37
+ const { done, value } = await reader.read();
38
+ if (done)
39
+ break;
40
+ size += value.length;
41
+ if (size > limit) {
42
+ await reader.cancel();
43
+ throw Error("Plugin download exceeds size limit");
44
+ }
45
+ chunks.push(value);
46
+ }
47
+ return Buffer.concat(chunks);
48
+ }
49
+ export function createPluginHub(dir, targets, load = download) {
50
+ const file = join(dir, "plugin-library.json");
51
+ let state = { catalog: [], installed: [] };
52
+ let readable = true;
53
+ if (existsSync(file)) {
54
+ try {
55
+ state = database.parse(JSON.parse(readFileSync(file, "utf8")));
56
+ }
57
+ catch {
58
+ readable = false;
59
+ }
60
+ }
61
+ const save = (next) => { writeFileAtomic(file, JSON.stringify(next), { mode: 0o600 }); state = next; };
62
+ const view = () => ({ ...state, ...targets() });
63
+ const route = async ({ req, res, path, method, auth, json, readBody }) => {
64
+ if (path !== "/api/limix/plugins")
65
+ return PASS;
66
+ if (!ownerOrAdmin(auth) || (auth.kind === "loopback" && auth.companionDevice))
67
+ return json(res, 403, { error: "forbidden: this session lacks the admin scope" });
68
+ if (!readable)
69
+ return json(res, 503, { error: "The saved plugin library could not be read" });
70
+ if (method === "GET")
71
+ return json(res, 200, view());
72
+ if (method !== "POST")
73
+ return json(res, 405, { error: "Method not allowed" });
74
+ const parsed = change.safeParse(await readBody(req));
75
+ if (!parsed.success)
76
+ return json(res, 400, { error: "Invalid plugin action" });
77
+ const input = parsed.data;
78
+ if (input.action === "sync") {
79
+ try {
80
+ const rows = catalog.parse(JSON.parse((await load("catalog.json", 1024 * 1024)).toString()));
81
+ save({ ...state, catalog: rows });
82
+ }
83
+ catch {
84
+ return json(res, 502, { error: "Could not sync the plugin catalog" });
85
+ }
86
+ }
87
+ else if (input.action === "install") {
88
+ const row = state.catalog.find(r => r.id === input.id && r.sha256 === input.sha256);
89
+ if (!row)
90
+ return json(res, 409, { error: "Refresh the catalog and review this version" });
91
+ try {
92
+ const bytes = await load("plugins/" + row.id + ".json", 65536);
93
+ if (createHash("sha256").update(bytes).digest("hex") !== row.sha256)
94
+ throw Error("digest");
95
+ const pack = bundle.parse(JSON.parse(bytes.toString()));
96
+ if (JSON.stringify(packMetadata(pack)) !== JSON.stringify(packMetadata(row)))
97
+ throw Error("metadata");
98
+ if (!state.catalog.some(r => r.id === row.id && r.sha256 === row.sha256))
99
+ throw Error("stale");
100
+ if (!state.installed.some(p => p.id === row.id && p.sha256 === row.sha256)) {
101
+ save({ ...state, installed: [...state.installed.filter(p => p.id !== row.id), { ...pack, sha256: row.sha256, teams: [], bots: {} }] });
102
+ }
103
+ }
104
+ catch {
105
+ return json(res, 422, { error: "Plugin download or integrity check failed" });
106
+ }
107
+ }
108
+ else if (input.action === "remove") {
109
+ save({ ...state, installed: state.installed.filter(p => p.id !== input.id) });
110
+ }
111
+ else {
112
+ const current = state.installed.find(p => p.id === input.id && p.sha256 === input.sha256);
113
+ if (!current)
114
+ return json(res, 409, { error: "Review the installed version first" });
115
+ const { bots, teams } = targets();
116
+ const next = structuredClone(current);
117
+ if (input.target === "bot") {
118
+ if (!bots.some(b => b.id === input.key))
119
+ return json(res, 404, { error: "Unknown bot" });
120
+ if (input.enabled === null)
121
+ delete next.bots[input.key];
122
+ else
123
+ next.bots[input.key] = input.enabled;
124
+ }
125
+ else {
126
+ if (!teams.includes(input.key))
127
+ return json(res, 404, { error: "Unknown team" });
128
+ next.teams = next.teams.filter(s => s !== input.key);
129
+ if (input.enabled)
130
+ next.teams.push(input.key);
131
+ }
132
+ save({ ...state, installed: state.installed.map(p => p.id === next.id ? next : p) });
133
+ }
134
+ return json(res, 200, view());
135
+ };
136
+ return { route, pruneTeams(teams) {
137
+ if (!state.installed.some(p => p.teams.some(team => !teams.includes(team))))
138
+ return;
139
+ save({ ...state, installed: state.installed.map(p => ({ ...p, teams: p.teams.filter(team => teams.includes(team)) })) });
140
+ }, renameTeam(from, to) {
141
+ if (!state.installed.some(p => p.teams.includes(from)))
142
+ return;
143
+ save({ ...state, installed: state.installed.map(p => ({ ...p, teams: p.teams.flatMap(team => team !== from ? [team] : to ? [to] : []) })) });
144
+ }, instructions(bot, availableMcp) {
145
+ return state.installed.filter(p => pluginEnabled(p, bot) && p.requiresMcp.every(name => availableMcp.includes(name)))
146
+ .map(p => "\n\nPlugin " + p.id + " (" + p.version + ")\n" + p.instructions).join("");
147
+ } };
148
+ }
149
+ function packMetadata({ id, version, name, description, requiresMcp }) {
150
+ return { id, version, name, description, requiresMcp };
151
+ }
@@ -108,7 +108,7 @@ export function createHelperToolRoutes(deps) {
108
108
  const state = typeof body.state === "string" ? body.state : "";
109
109
  if (!relayAccepts("botDecide", state, questions))
110
110
  return void ctx.json(ctx.res, 400, { error: HELPER_MESSAGES.decideShape });
111
- const result = await deps.decider.ask("botDecide", state, questions, { careful: true, timeoutMs: HELPER_TOOL_TIMEOUT_MS });
111
+ const result = await deps.decider.ask("botDecide", state, questions, { careful: true, timeoutMs: HELPER_TOOL_TIMEOUT_MS, turnScope: ctx.turnScope });
112
112
  if (!result.ok) {
113
113
  const off = result.reason === "disabled" || result.reason === "no_key";
114
114
  return void ctx.json(ctx.res, off ? 409 : 502, { error: off ? HELPER_MESSAGES.decideOff : FAILURE[result.reason] ?? "The decision model's answer could not be read. Try again." });
@@ -0,0 +1,3 @@
1
+ export function pluginEnabled(plugin, bot) {
2
+ return Object.hasOwn(plugin.bots, bot.id) ? plugin.bots[bot.id] : plugin.teams.includes(bot.section ?? "");
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "limixbot",
3
- "version": "0.3.119",
3
+ "version": "0.3.121",
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",