limixbot 0.3.119 → 0.3.120
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-l9mkZj3c.js → ActivityPanel-BNI1ux2Y.js} +1 -1
- package/dist/assets/{App-CEAzIqrp.js → App-BtFoKXkb.js} +9 -9
- package/dist/assets/{AppEventEditor-BKzVDU63.js → AppEventEditor-4O6prt9T.js} +1 -1
- package/dist/assets/{BotSettingsDialog-BvwqItvE.js → BotSettingsDialog-DuiiKANg.js} +1 -1
- package/dist/assets/{BrowserPanel-bnuqUOz3.js → BrowserPanel-Cw0XeNKj.js} +1 -1
- package/dist/assets/{BrowserProfilesManager-CUcXphXT.js → BrowserProfilesManager-BXUJZPvf.js} +1 -1
- package/dist/assets/{CloudAddDialog-CLEsRgra.js → CloudAddDialog-CenW3juU.js} +1 -1
- package/dist/assets/{ComputerFilesPane-CE6kJr6z.js → ComputerFilesPane-2CbBxe5x.js} +1 -1
- package/dist/assets/{ComputerPanel-CfHxPV-U.js → ComputerPanel-Dblzz3vs.js} +2 -2
- package/dist/assets/{DataPanel-DlfWhJ2l.js → DataPanel-BE4kBVy_.js} +1 -1
- package/dist/assets/{GrokMoveDialog-BNWxAa5N.js → GrokMoveDialog-Bweic81i.js} +1 -1
- package/dist/assets/{InspectorPanel-B6K0R7ZI.js → InspectorPanel-D8a2VKdd.js} +1 -1
- package/dist/assets/{KeyboardShortcutsModal-BsuaxSbW.js → KeyboardShortcutsModal-BEpU3l5V.js} +1 -1
- package/dist/assets/{LimixResizeHandles-LTylExKz.js → LimixResizeHandles-US6Nri-U.js} +1 -1
- package/dist/assets/{LiveDesktop-wCtWba6M.js → LiveDesktop-DJOZHCzT.js} +1 -1
- package/dist/assets/{LocalVmWorkspace-HjB7RZ-Z.js → LocalVmWorkspace-NGZNs1wG.js} +1 -1
- package/dist/assets/{MacLocalControl-LWJJgz11.js → MacLocalControl-BAy3zv4a.js} +1 -1
- package/dist/assets/{MarkdownFilePreview-DSrxVVhX.js → MarkdownFilePreview-BfNcCQnO.js} +1 -1
- package/dist/assets/{NewBotDialog-CdjLWn-L.js → NewBotDialog-CKoKQIM9.js} +1 -1
- package/dist/assets/{PhoneAppDialog-BoNheaDw.js → PhoneAppDialog-FY9PmkA6.js} +1 -1
- package/dist/assets/PluginsPanel-DvIsIELX.js +8 -0
- package/dist/assets/{ProIntroduction-CTl2MGYw.js → ProIntroduction-CZMEIOV3.js} +1 -1
- package/dist/assets/{RemoteAgentSettingsPanel-BwW8Dn4E.js → RemoteAgentSettingsPanel-BzNM-yd4.js} +1 -1
- package/dist/assets/{RoomPanel-CMUHW-ng.js → RoomPanel-BaXZH_OC.js} +1 -1
- package/dist/assets/{RoutinesPage-DB91MHqs.js → RoutinesPage-Bo4t8FOR.js} +1 -1
- package/dist/assets/{SettingsModal-BsrT3E14.js → SettingsModal-BnIPD1zO.js} +1 -1
- package/dist/assets/{ShareTeamDialog-CcBEpMqD.js → ShareTeamDialog-CKWIMaY6.js} +1 -1
- package/dist/assets/{SignedInSites-DkT1rvTd.js → SignedInSites-B7wKzWCm.js} +1 -1
- package/dist/assets/{TeamLibraryPanel-zV-86ahA.js → TeamLibraryPanel-DOlj0Kyg.js} +1 -1
- package/dist/assets/{TeamMapPage-CZgGndK3.js → TeamMapPage-CdF8LQ0B.js} +1 -1
- package/dist/assets/{TriggersPage-DbVlUurg.js → TriggersPage-CJUxvDcL.js} +1 -1
- package/dist/assets/{VisibilitySection-BFM8tVU4.js → VisibilitySection-BGMvfVcC.js} +1 -1
- package/dist/assets/{WebhookTrigger-CHg2JRGq.js → WebhookTrigger-Jxr8mr7O.js} +1 -1
- package/dist/assets/{WorksOnGrid-Bakox8KX.js → WorksOnGrid-BAc1xQ0J.js} +1 -1
- package/dist/assets/{core-Cjaw1pBq.js → core-CwWz_qwp.js} +1 -1
- package/dist/assets/{import-name-Bjlw9jiM.js → import-name-DLjs1__7.js} +1 -1
- package/dist/assets/{index-EVmEXe2l.js → index-CjgWjXIR.js} +1 -1
- package/dist/assets/{index-1nLJcLwH.js → index-DLhL-159.js} +2 -2
- package/dist/assets/{mcp-servers-zi8N7I1M.js → mcp-servers-DwlkPkVq.js} +1 -1
- package/dist/assets/{new-bot-mpygivK8.js → new-bot-pRpz-Z7k.js} +1 -1
- package/dist/assets/{org-library-YpW2P8UH.js → org-library-BdRqFYyG.js} +1 -1
- package/dist/assets/{package-format-C1QxHZKk.js → package-format-D4N5QpsV.js} +1 -1
- package/dist/assets/{remote-desktop-panel-CDUUA-78.js → remote-desktop-panel-CDov0Xv1.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-server/index.js +2692 -2674
- package/dist-server/package.json +1 -1
- package/dist-server/server/index.js +14 -4
- package/dist-server/server/plugin-hub.js +151 -0
- package/dist-server/shared/plugin-hub.js +3 -0
- package/package.json +1 -1
- package/dist/assets/PluginsPanel-CPjWtDIQ.js +0 -8
package/dist-server/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"type":"module","version":"0.3.
|
|
1
|
+
{"type":"module","version":"0.3.120"}
|
|
@@ -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) =>
|
|
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 });
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{c as dn,t as n,r as d,j as e,X as es,ae as ts,a as G,d as We,l as Bt,S as ws,i as Jt}from"./styles-ezcN4hc0.js";import{S as un,j as w,u as Xe,eC as Ns,eD as As,eE as Cs,eF as ht,w as Ss,eG as Rs,eH as Es,l as zs,G as Sn,eI as Is,eJ as Ts,cT as Os,T as Bs,ah as Xt,bt as Ps,D as en,eK as Rt,eL as ns,eM as Et,eN as ss,an as as,eO as zt,eP as Ms,eQ as is,eR as It,eS as os,eT as Ls,eU as Rn,eV as Us,Y as cs,eW as Nt,eX as $s,eY as Fs,eZ as Ks,e_ as Ds,e$ as Qs,f0 as ct,f1 as En,f2 as Hs,f3 as zn,eg as In,f4 as _s,f5 as Js,f6 as Vs,f7 as Vt,f8 as Gs,f9 as qs,fa as Zs,fb as Ws,fc as Ys,fd as Xs,fe as ea,ff as ta,fg as na,fh as sa,fi as aa}from"./App-CEAzIqrp.js";import{L as ae,P as rs,X as ia,a as oa,v as pn,E as ca,_ as ra,$ as la,B as da}from"./PlacesRail-BesUMTCh.js";import{u as Gt}from"./mcp-servers-zi8N7I1M.js";import{C as ls,R as tn}from"./MenuMotion-Dr44d4Sg.js";import{u as ua}from"./ProIntroduction-CTl2MGYw.js";import"./index-1nLJcLwH.js";import"./monitor-DwKv3TJO.js";const pa=[["path",{d:"M13 2a9 9 0 0 1 9 9",key:"1itnx2"}],["path",{d:"M13 6a5 5 0 0 1 5 5",key:"11nki7"}],["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]],ma=dn("phone-call",pa);const ha=[["path",{d:"M4.9 16.1C1 12.2 1 5.8 4.9 1.9",key:"s0qx1y"}],["path",{d:"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5",key:"1idnkw"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}],["path",{d:"M16.2 4.8c2 2 2.26 5.11.8 7.47",key:"ojru2q"}],["path",{d:"M19.1 1.9a9.96 9.96 0 0 1 0 14.1",key:"rhi7fg"}],["path",{d:"M9.5 18h5",key:"mfy3pd"}],["path",{d:"m8 22 4-11 4 11",key:"25yftu"}]],fa=dn("radio-tower",ha);const xa=[["path",{d:"m10.852 14.772-.383.923",key:"11vil6"}],["path",{d:"M13.148 14.772a3 3 0 1 0-2.296-5.544l-.383-.923",key:"1v3clb"}],["path",{d:"m13.148 9.228.383-.923",key:"t2zzyc"}],["path",{d:"m13.53 15.696-.382-.924a3 3 0 1 1-2.296-5.544",key:"1bxfiv"}],["path",{d:"m14.772 10.852.923-.383",key:"k9m8cz"}],["path",{d:"m14.772 13.148.923.383",key:"1xvhww"}],["path",{d:"M4.5 10H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-.5",key:"tn8das"}],["path",{d:"M4.5 14H4a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-.5",key:"1g2pve"}],["path",{d:"M6 18h.01",key:"uhywen"}],["path",{d:"M6 6h.01",key:"1utrut"}],["path",{d:"m9.228 10.852-.923-.383",key:"1wtb30"}],["path",{d:"m9.228 13.148-.923.383",key:"1a830x"}]],qt=dn("server-cog",xa),ga=new Set(["twitter","x"]);function Tn(t,s){return t!=="managed"||!ga.has(s.trim().toLowerCase())?null:"Twitter/X needs your own X Developer app and Composio auth config. Use self-hosted connected apps for now."}const ba=5,ya=3,Tt=4;function ka(t,s=ba,c=[]){const o=new Map;for(const g of t)for(const k of new Set(g.categories??[]))o.set(k,(o.get(k)??0)+1);const r=[...o].sort((g,k)=>k[1]-g[1]||g[0].localeCompare(k[0])).map(([g])=>g),l=c.filter(g=>r.indexOf(g)>=s),y=[...r.slice(0,Math.max(0,s-l.length)),...l];return{inline:y,more:r.filter(g=>!y.includes(g))}}function nn(t,s){return s===null||(t.categories??[]).includes(s)}function ja(t,s,c){const o=[],r=t.filter(l=>s(l.slug));r.length&&o.push({kind:"connected",cards:r});for(const l of c.slice(0,ya)){const y=t.filter(g=>!s(g.slug)&&nn(g,l));y.length&&o.push({kind:"category",category:l,cards:y.slice(0,Tt),more:y.length>Tt})}return o.push({kind:"all",cards:t.filter(l=>!s(l.slug))}),o}const va={productivity:"productivity","developer tools":"developerTools",communication:"communication",files:"files","sales and crm":"salesCrm",design:"design",marketing:"marketing",analytics:"analytics",social:"social"},wa={"google calendar":"googleCalendar","google sheets":"googleSheets","google docs":"googleDocs",notion:"notion",github:"github",linear:"linear",sentry:"sentry",jira:"jira",slack:"slack",gmail:"gmail",discord:"discord","google drive":"googleDrive",posthog:"posthog","x (twitter)":"xTwitter",reddit:"reddit",zapier:"zapier",hubspot:"hubspot",salesforce:"salesforce",asana:"asana",trello:"trello",dropbox:"dropbox",airtable:"airtable",figma:"figma",stripe:"stripe"};function rt(t){const s=va[t.trim().toLowerCase()];return s?n(`apps.category.${s}`):t}function On(t){const s=wa[t.label.trim().toLowerCase()];return s?n(`apps.catalog.${s}.blurb`):t.blurb}function Na({server:t,disabled:s,onSaved:c}){const[o,r]=d.useState(!1),[l,y]=d.useState(null);if(typeof t.apps!="boolean"||t.apps&&t.hasApps!==!0)return null;const g=t.apps,k=async()=>{r(!0),y(null);try{const p=await w(`/api/mcp/servers/${encodeURIComponent(t.name)}`,{method:"PATCH",body:JSON.stringify({apps:!g})});c(p.servers??[])}catch(p){y(p instanceof Error?p.message:String(p))}finally{r(!1)}};return e.jsxs("div",{"data-mcp-apps":t.name,className:"mt-3 flex items-center gap-3 border-t border-hairline/40 pt-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[13px] font-medium text-ink",children:n("mcp.apps.title")}),e.jsx("div",{role:l?"alert":void 0,className:l?"mt-0.5 text-[12px] text-danger":"mt-0.5 text-[12px] text-ink-secondary",children:l??n("mcp.apps.desc")})]}),o&&e.jsx(ae,{"aria-hidden":"true",size:13,className:"animate-spin text-ink-secondary"}),e.jsx(un,{checked:g,disabled:s||o,onClick:()=>{k()},"aria-label":n("mcp.apps.toggleAria",{name:t.name}),className:"disabled:opacity-40"})]})}function Bn({feature:t,enabled:s,prefix:c}){const{dispatch:o}=Xe(),[r,l]=d.useState(!1),[y,g]=d.useState(!1),k=async()=>{if(!r){l(!0),g(!1);try{const p=await w("/api/config",{method:"PATCH",body:JSON.stringify({features:{[t]:!s}})});o({type:"configStatus",config:p})}catch{g(!0)}finally{l(!1)}}};return e.jsxs("div",{className:"mt-4 flex items-start justify-between gap-4 rounded-2xl border border-hairline/50 bg-card px-4 py-4 sm:px-5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:n(`${c}.title`)}),e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:n(`${c}.desc`)}),y&&e.jsx("p",{role:"alert",className:"mt-1 text-[12px] text-danger",children:n("mcp.claude.error")})]}),e.jsx(un,{checked:s,"aria-label":n(`${c}.aria`),disabled:r,onClick:()=>{k()},className:"mt-0.5 shrink-0 disabled:cursor-wait disabled:opacity-50"})]})}function Aa(){const{state:t}=Xe();return e.jsxs(e.Fragment,{children:[e.jsx(Bn,{feature:"claudeUserMcp",enabled:Ns(t.config),prefix:"mcp.claude"}),e.jsx(Bn,{feature:"claudeUserSkills",enabled:As(t.config),prefix:"mcp.claudeSkills"})]})}function Pn({app:t}){if("image"in t.icon)return e.jsx("img",{src:t.icon.image,alt:"",className:"size-10 shrink-0 rounded-xl object-contain"});const s=t.icon.glyph;return e.jsx("span",{className:"flex size-10 shrink-0 items-center justify-center rounded-xl bg-raised text-ink-secondary",children:e.jsx(s,{size:19,"aria-hidden":"true"})})}class me extends Error{key;constructor(s){super(s),this.key=s}}const sn=/^https?:\/\//i,ds=/^[A-Za-z_][A-Za-z0-9_]*=/,Ca=/^[!#$%&'*+.^_`|~0-9A-Za-z-]+:/,Sa=new Set(["npx","uvx","bunx"]),Ra=new Set(["pnpm","yarn"]);function Ea(t,s=[]){const c=za(t).trim();if(!c)return null;try{const o=/^[{[]/.test(c)?La(c):sn.test(c)&&!/\s/.test(c)?[mn(void 0,c,void 0,[])]:Ia(c);return{ok:!0,servers:Da(o,s)}}catch(o){if(o instanceof me)return{ok:!1,error:o.key};throw o}}function za(t){return t.replace(/[“”„]/g,'"').replace(/[‘’]/g,"'").replace(/(^|\s)[–—](?=[a-z])/g,"$1--")}function us(t){const s=[];let c=[],o="",r=!1;const l=()=>{r&&c.push(o),o="",r=!1},y=()=>{l(),c.length&&s.push(c),c=[]},g=k=>t[k]===`
|
|
2
|
-
`?1:t[k]==="\r"&&t[k+1]===`
|
|
3
|
-
`?2:0;for(let k=0;k<t.length;k+=1){const p=t[k];if(p==="\\"||(p==="`"||p==="^")&&g(k+1)){const h=g(k+1);if(h){k+=h;continue}k+1<t.length&&(o+=t[k+1],r=!0,k+=1);continue}if(p==="'"){const h=t.indexOf("'",k+1);if(h<0)throw new me("mcp.paste.notRecognized");o+=t.slice(k+1,h),r=!0,k=h;continue}if(p==='"'){let h=k+1;for(;h<t.length&&t[h]!=='"';h+=1){if(t[h]==="\\"&&h+1<t.length){const A=g(h+1);if(A){h+=A;continue}if('"\\$`'.includes(t[h+1])){o+=t[h+1],h+=1;continue}}o+=t[h]}if(h>=t.length)throw new me("mcp.paste.notRecognized");r=!0,k=h;continue}if(p==="$"&&t[k+1]==="("){const h=t.indexOf(")",k+2);if(h<0)throw new me("mcp.paste.notRecognized");o+=t.slice(k,h+1),r=!0,k=h;continue}if(p==="#"&&!r){for(;k+1<t.length&&t[k+1]!==`
|
|
4
|
-
`;)k+=1;continue}if(p===`
|
|
5
|
-
`||p===";"){y();continue}if(p==="&"&&t[k+1]==="&"){y(),k+=1;continue}if(/\s/.test(p)){l();continue}o+=p,r=!0}return y(),s}function Ia(t){const s=us(t);if(!s.length)throw new me("mcp.paste.notRecognized");return s.map(c=>{const o=c[0]==="$"||c[0]===">"?c.slice(1):c;return o[0]==="claude"&&o[1]==="mcp"&&o[2]==="add"?Ta(o.slice(3)):o[0]==="claude"&&o[1]==="mcp"&&o[2]==="add-json"?Oa(o.slice(3)):Ba(o)})}function Ta(t){let s,c;const o=[],r=[],l=[];let y=[];for(let h=0;h<t.length;h+=1){const A=t[h];if(A==="--"){y=t.slice(h+1);break}const Q=/^(--[a-z][a-z-]*|-[a-zA-Z])(?:=([\s\S]*))?$/.exec(A);if(!Q){l.push(A);continue}const C=()=>Q[2]??t[++h]??"",M=(_,K)=>{for(;h+1<t.length&&_.test(t[h+1])&&!sn.test(t[h+1]);)K.push(t[++h])};switch(Q[1]){case"--transport":case"-t":s=C().toLowerCase();break;case"--header":case"-H":o.push(C()),Q[2]===void 0&&M(Ca,o);break;case"--env":case"-e":r.push(C()),Q[2]===void 0&&M(ds,r);break;case"--client-id":c=C();break;case"--scope":case"-s":case"--callback-port":C();break}}const[g,k,...p]=[...l,...y];if(!g||!k)throw new me("mcp.paste.incomplete");if(s!=="stdio"&&(s==="http"||s==="sse"||sn.test(k))){const h=mn(g,k,s==="sse"?"sse":s==="http"?"http":void 0,o.map(Ua));return c?{...h,oauthClientId:c}:h}return{transport:"stdio",name:ht(g),command:k,args:p,env:r.map(hn)}}function Oa(t){const s=[];for(let l=0;l<t.length;l+=1){const y=t[l];if(y==="--scope"||y==="-s"){l+=1;continue}y.startsWith("-")&&!y.startsWith("{")||s.push(y)}const[c,o]=s;if(!c||!o)throw new me("mcp.paste.incomplete");const r=an(c,ps(o));if(!r)throw new me("mcp.paste.notRecognized");return r}function Ba(t){let s=0;const c=[];for(;s<t.length&&ds.test(t[s]);)c.push(hn(t[s++]));const[o,...r]=t.slice(s);if(!o)throw new me("mcp.paste.notRecognized");if(o==="docker"&&r[0]==="run")return Ma(r,c);if(!Sa.has(o)&&!(Ra.has(o)&&r[0]==="dlx"))throw new me("mcp.paste.notRecognized");const l=r.find((y,g)=>!y.startsWith("-")&&!(g===0&&y==="dlx"));if(!l)throw new me("mcp.paste.incomplete");return{transport:"stdio",name:xn(l),command:o,args:r,env:c}}const Pa=new Set(["-i","-t","-it","-ti","-d","--rm","--init","--interactive","--tty","--detach","--privileged"]);function Ma(t,s){const c=[t[0]];let o;for(let r=1;r<t.length;r+=1){const l=t[r];if(o||!l.startsWith("-"))o??=l,c.push(l);else if((l==="-e"||l==="--env")&&r+1<t.length){const y=t[++r],g=y.split("=")[0];s.push(y.includes("=")?hn(y):{name:g,value:"",gap:{kind:"variable",names:[g],before:"",after:""}}),c.push(l,g)}else l.includes("=")||Pa.has(l)||r+1>=t.length?c.push(l):c.push(l,t[++r])}if(!o)throw new me("mcp.paste.incomplete");return{transport:"stdio",name:xn(o.replace(/:[^/:]*$/,"")),command:"docker",args:c,env:s}}function ps(t){try{return JSON.parse(t)}catch{throw new me("mcp.paste.badJson")}}const ut=t=>!!t&&typeof t=="object"&&!Array.isArray(t);function La(t){const s=ps(t);if(!ut(s))throw new me("mcp.paste.notRecognized");const c=an(typeof s.name=="string"?s.name:void 0,s);if(c)return[c];const o=ut(s.mcpServers)?s.mcpServers:ut(s.servers)?s.servers:s,r=Object.entries(o).map(([l,y])=>an(l,y));if(!r.length||r.some(l=>!l))throw new me("mcp.paste.notRecognized");return r}const Mn=t=>ut(t)?Object.entries(t).filter(s=>typeof s[1]=="string"):[];function an(t,s){if(!ut(s))return null;const c=typeof s.url=="string"?s.url:typeof s.serverUrl=="string"?s.serverUrl:void 0,o=typeof s.type=="string"?s.type.toLowerCase():"";if(c!==void 0){const p=Mn(s.headers).map(([h,A])=>Ot(h,A));return mn(t,c,o==="sse"?"sse":o?"http":void 0,p)}if(typeof s.command!="string"||!s.command.trim())return null;const r=Array.isArray(s.args)?s.args.filter(p=>typeof p=="string"):[],[l,...y]=r.length?[s.command.trim()]:us(s.command)[0]??[s.command],g=Mn(s.env).map(([p,h])=>Ot(p,h)),k=[...y,...r];return{transport:"stdio",name:t?ht(t):xn(k.find(p=>!p.startsWith("-"))??l??""),command:l,args:k,env:g}}function mn(t,s,c,o){const r=fn(s);return{transport:"remote",name:t?ht(t):Ka(s),type:c??(/\/sse\/?(?:[?#]|$)/i.test(s)?"sse":"http"),url:s,...r?{urlGap:r}:{},headers:o}}function Ua(t){const s=t.indexOf(":");if(s<=0)throw new me("mcp.paste.badPair");return Ot(t.slice(0,s).trim(),t.slice(s+1).trim())}function hn(t){const s=t.indexOf("=");if(s<=0)throw new me("mcp.paste.badPair");return Ot(t.slice(0,s),t.slice(s+1))}function Ot(t,s){const c=fn(s);return c?{name:t,value:"",gap:c}:{name:t,value:s}}const $a=/\$\{([^}]*)\}|\$\(([^)]*)\)|\$([A-Za-z_][A-Za-z0-9_]*)/g,Fa=/<([^<>\s][^<>]{0,63})>|\b(YOUR[_-][A-Za-z0-9_-]+|your[_-][a-z0-9_-]+)\b/g;function fn(t){const s=[];for(const l of t.matchAll($a)){const y=(l[1]??l[2]??l[3]??"").replace(/^(?:env|input):/,"").replace(/:-[\s\S]*$/,"").trim();s.push({start:l.index,end:l.index+l[0].length,name:y||l[0],kind:"variable"})}for(const l of t.matchAll(Fa))s.some(y=>l.index<y.end&&l.index+l[0].length>y.start)||s.push({start:l.index,end:l.index+l[0].length,name:(l[1]??l[2]??"").trim(),kind:"placeholder"});if(!s.length)return;const c=[...new Set(s.map(l=>l.name))],o=s.some(l=>l.kind==="variable")?"variable":"placeholder",r=s.length===1?s[0]:null;return{kind:o,names:c,before:r?t.slice(0,r.start):"",after:r?t.slice(r.end):""}}const ms=new Set(["www","mcp","api","server","servers","app","remote","sse","gateway","co","com","org","net","ac","gov"]);function Ka(t){let s;try{s=new URL(t).hostname}catch{return""}if(/^[\d.]+$/.test(s)||s.includes(":"))return"server";const c=s.split(".").filter(Boolean);return c.length>1&&c.pop(),ht(c.filter(o=>!ms.has(o)).at(-1)??c.at(-1)??"server")}function xn(t){const s=t.replace(/(?!^)@[^/@]*$/,"").split("/"),c=s.at(-1)??t,o=c.replace(/^(?:mcp-server-|server-|mcp-)/,"").replace(/(?:-mcp-server|-mcp|-server)$/,""),r=(s.at(-2)??"").replace(/^@/,"");return ht(ms.has(o)&&r?r:o||c)||"server"}function Da(t,s){const c=new Set(s);return t.map(o=>{let r=o.name||"server";if(c.has(r))for(let l=2;c.has(r);l+=1)r=Cs(`${o.name.slice(0,29)}-${l}`);return c.add(r),r===o.name?o:{...o,name:r}})}const Qa=2e6;function Ha(t){const s=t.trim(),o=/^\d{1,3}([\s,._ '])\d{3}(?:\1\d{3})*$/.test(s)?s.replace(/\D/g,""):s;return o?!/^\d+$/.test(o)||Number(o)>Qa?{ok:!1,error:{key:"mcp.err.resultBudget"}}:{ok:!0,value:Number(o)}:{ok:!0,value:void 0}}function Ln(t){return t.resultBudget===void 0?"":String(t.resultBudget)}function _a(t,s){const c=Ha(t);if(!c.ok)return c;const o=s();return!o.ok||c.value===void 0?o:{ok:!0,body:{...o.body,resultBudget:c.value}}}function Ja({value:t,onChange:s}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[12px] font-medium text-ink-secondary",children:n("mcp.field.resultBudget")}),e.jsx("input",{value:t,onChange:c=>s(c.target.value),inputMode:"numeric",placeholder:"8000",className:"mt-1.5 w-full rounded-lg border border-hairline/60 bg-raised px-3 py-2.5 text-[13px] text-ink outline-none focus:border-accent"}),e.jsx("span",{className:"mt-1.5 block text-[11px] text-ink-secondary",children:n("mcp.resultBudgetHint")})]})}function pe(t){return"url"in t}let Un=0;function Be(t={name:"",value:""}){return Un+=1,{id:Un,...t}}function Ye(){return{name:"",transport:"remote",command:"",args:"",env:[Be()],type:"http",url:"",headers:[Be()],oauthClientId:"",oauthClientSecret:"",oauthScopes:"",oauthForgetSecret:!1,resultBudget:""}}const $n=t=>t.length?t.map(s=>Be({name:s,value:"",saved:!0})):[Be()],Fn=t=>t.length?t.map(s=>Be({...s})):[Be()];function Va(t){return pe(t)?{...Ye(),name:t.name,type:t.type,url:t.url,headers:$n(t.headerKeys),oauthClientId:t.oauth?.clientId??"",oauthScopes:t.oauth?.scopes.join(" ")??"",resultBudget:Ln(t)}:{...Ye(),name:t.name,transport:"stdio",command:t.command,args:t.args.join(`
|
|
6
|
-
`),env:$n(t.envKeys),resultBudget:Ln(t)}}function Ga(t){return t.transport==="remote"?{...Ye(),name:t.name,type:t.type,url:t.url,...t.urlGap?{urlGap:t.urlGap}:{},headers:Fn(t.headers),oauthClientId:t.oauthClientId??""}:{...Ye(),name:t.name,transport:"stdio",command:t.command,args:t.args.join(`
|
|
7
|
-
`),env:Fn(t.env)}}function on(t){const s=t.value.trim();if(!t.gap||!s)return t.value;const{before:c,after:o}=t.gap;return c.trim()&&s.toLowerCase().startsWith(c.trim().toLowerCase())?s:`${c}${s}${o}`}const qa=/^[A-Za-z_][A-Za-z0-9_]*$/,Za=/^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,128}$/;function Kn(t,s){const c={};for(const o of t){const r=o.name.trim(),l=s==="header"?on(o).trim():on(o);if(!(!r&&!l)){if(!r)return{ok:!1,error:{key:"mcp.err.rowName"}};if(!(s==="header"?Za:qa).test(r))return{ok:!1,error:{key:s==="header"?"mcp.headers.invalidName":"mcp.env.invalidName",params:{key:r}}};if(Object.hasOwn(c,r))return{ok:!1,error:{key:s==="header"?"mcp.headers.duplicate":"mcp.env.duplicate",params:{key:r}}};if(l)c[r]=l;else if(o.saved)c[r]=!0;else return{ok:!1,error:{key:"mcp.err.missingValue",params:{name:r}}}}}return{ok:!0,values:c}}function Wa(t){return t.split(/\r?\n/).map(s=>s.trim()).filter(Boolean)}function Ya(t,s){const c=t.clientId.trim();if(!c)return;const o=t.clientSecret.trim(),r=t.scopes.split(/[\s,]+/).filter(Boolean);return{clientId:c,...o?{clientSecret:o}:s?.clientSecretConfigured&&!t.forgetSecret?{clientSecret:!0}:{},...r.length?{scopes:r}:{}}}function Xa(t,s){const c=t.name.trim();if(t.transport==="remote"){const l=t.url.trim();if(!c||!/^https?:\/\/\S+$/i.test(l))return{ok:!1,error:{key:"mcp.err.nameAndUrl"}};if(fn(l))return{ok:!1,error:{key:"mcp.paste.urlMissing"}};const y=Kn(t.headers,"header");if(!y.ok)return y;const g=Ya({clientId:t.oauthClientId,clientSecret:t.oauthClientSecret,scopes:t.oauthScopes,forgetSecret:t.oauthForgetSecret},s&&pe(s)?s.oauth:void 0);return{ok:!0,body:{type:t.type,url:l,headers:y.values,...g?{oauth:g}:{}}}}const o=t.command.trim();if(!c||!o)return{ok:!1,error:{key:"mcp.err.nameAndCommand"}};const r=Kn(t.env,"env");return r.ok?{ok:!0,body:{command:o,args:Wa(t.args),env:r.values}}:r}function Dn(t){if(t.transport!=="remote"||t.oauthClientId.trim())return null;const s=t.headers.filter(c=>c.name.trim());return s.length===1&&on(s[0]).trim()||null}function ei(t){return n(t.kind==="variable"?"mcp.paste.variable":"mcp.paste.placeholder",{name:t.names.join(", ")})}const Qn="w-full min-w-0 rounded-lg border border-hairline/60 bg-raised px-3 py-2.5 font-mono text-[12px] text-ink outline-none focus:border-accent";function Ve({kind:t,rows:s,onChange:c,valuesOf:o,placeholder:r}){const l=(p,h)=>c(s.map(A=>A.id===p?{...A,...h}:A)),y=t==="header"?":":"=",g=(p,h)=>{const A=h.clipboardData.getData("text"),Q=A.indexOf(y);Q<=0||(h.preventDefault(),l(p.id,{name:A.slice(0,Q).trim(),value:A.slice(Q+1).trim()}))},k=p=>e.jsx("input",{type:"password","aria-label":p.name.trim()||n("mcp.row.value"),value:p.value,autoComplete:"new-password",spellCheck:!1,placeholder:r??(p.saved?n("mcp.oauth.secretSaved"):n("mcp.row.value")),onChange:h=>l(p.id,{value:h.target.value}),className:Qn});return e.jsxs("div",{className:"space-y-2",children:[s.filter(p=>o==="gaps"?p.gap:o==="named"?p.name.trim():!0).map(p=>e.jsxs("div",{children:[o?e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"mb-1.5 block font-mono text-[12px] font-medium text-ink-secondary",children:p.name}),k(p)]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{"aria-label":n(t==="header"?"mcp.row.headerName":"mcp.row.envName"),value:p.name,spellCheck:!1,autoComplete:"off",placeholder:t==="header"?"Authorization":"API_KEY",onChange:h=>l(p.id,{name:h.target.value}),onPaste:h=>g(p,h),className:`${Qn} max-w-[42%]`}),k(p),e.jsx("button",{type:"button","aria-label":n("mcp.row.remove",{name:p.name.trim()||n("mcp.row.value")}),onClick:()=>c(s.length>1?s.filter(h=>h.id!==p.id):[Be()]),className:"shrink-0 rounded-lg p-2 text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(es,{size:14})})]}),p.gap&&!p.value.trim()&&e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-warning",children:ei(p.gap)})]},p.id)),!o&&e.jsxs("button",{type:"button",onClick:()=>c([...s,Be()]),className:"inline-flex items-center gap-1 rounded-lg px-1 py-1 text-[12px] font-medium text-accent hover:underline",children:[e.jsx(rs,{size:13})," ",n("mcp.row.add")]})]})}const Te="mt-1.5 w-full rounded-lg border border-hairline/60 bg-raised px-3 py-2.5 text-[13px] text-ink outline-none focus:border-accent",Ce="text-[12px] font-medium text-ink-secondary";function ti(t){if(t.transport==="stdio")return t.command;try{return new URL(t.url).host}catch{return t.url}}function ni({server:t,fixKeys:s=!1,taken:c,team:o,busy:r,onCancel:l,onSubmit:y}){const g=!t,[k,p]=d.useState(""),[h,A]=d.useState(()=>t?[Va(t)]:[]),[Q,C]=d.useState(null),M=s&&t!==void 0&&pe(t),[_,K]=d.useState(!g&&!M),[H,$]=d.useState(!1),[L,le]=d.useState(null),v=h.length===1?h[0]:null,J=b=>A(x=>x.length===1?[b(x[0])]:x),Z=t&&pe(t)?t.oauth:void 0,he=!!(Z?.clientSecretConfigured&&!v?.oauthForgetSecret),X=o&&g&&v!==null&&Dn(v)!==null,ee=b=>{p(b),le(null);const x=Ea(b,c);C(x&&!x.ok?x.error:null),A(S=>x?.ok?x.servers.map(Ga):_?S.length===1?S:[Ye()]:[])},ye=()=>{const b=[];for(const x of h){const S=_a(x.resultBudget,()=>Xa(x,t));if(!S.ok){le(S.error);return}const E=X&&H?Dn(x):null;b.push({name:x.name.trim(),body:S.body,...E?{ownKey:E}:{}})}le(null),y(b)},W=!_&&h.some(b=>b.urlGap||b.headers.some(x=>x.gap)||b.env.some(x=>x.gap));return e.jsxs("div",{"data-mcp-editor":!0,className:"mt-4 rounded-2xl border border-hairline/60 bg-card p-4 sm:p-5",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:g?n("mcp.editorNew"):n(M?"mcp.fixKeys.title":"mcp.editorEdit",{name:t.name})}),M&&v&&!_&&e.jsxs("div",{className:"mt-3 space-y-3",children:[e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:n("mcp.fixKeys.hint")}),v.headers.some(b=>b.name.trim())?e.jsx(Ve,{kind:"header",valuesOf:"named",placeholder:n("mcp.fixKeys.placeholder"),rows:v.headers,onChange:b=>J(x=>({...x,headers:b}))}):e.jsx(Ve,{kind:"header",rows:v.headers,onChange:b=>J(x=>({...x,headers:b}))})]}),g&&e.jsxs("label",{className:"mt-3 block",children:[e.jsx("span",{className:"text-[13px] text-ink",children:n("mcp.paste.prompt")}),e.jsx("textarea",{autoFocus:!0,"aria-label":n("mcp.paste.label"),value:k,onChange:b=>ee(b.target.value),spellCheck:!1,rows:3,placeholder:"https://mcp.example.com/mcp",className:"mt-2 w-full resize-y rounded-lg border border-hairline/60 bg-raised px-3 py-2.5 font-mono text-[12px] leading-relaxed text-ink outline-none focus:border-accent"})]}),Q&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] leading-relaxed text-danger",children:n(Q)}),g&&k.trim()&&h.length>0&&!Q&&e.jsx("p",{role:"status",className:"mt-2 text-[12px] text-ink-secondary",children:v?n("mcp.paste.foundOne",{name:v.name,where:ti(v)}):n("mcp.paste.foundMany",{count:h.length,names:h.map(b=>b.name).join(", ")})}),W&&e.jsx("div",{className:"mt-3 space-y-3",children:h.map((b,x)=>e.jsxs("div",{className:"space-y-3",children:[h.length>1&&(b.urlGap||b.headers.some(S=>S.gap)||b.env.some(S=>S.gap))&&e.jsx("div",{className:"text-[12px] font-medium text-ink",children:b.name}),b.urlGap&&e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.field.url")}),e.jsx("input",{value:b.url,spellCheck:!1,onChange:S=>A(E=>E.map((U,B)=>B===x?{...U,url:S.target.value}:U)),className:Te}),e.jsx("span",{className:"mt-1 block text-[11px] text-warning",children:n("mcp.paste.urlMissing")})]}),e.jsx(Ve,{kind:"header",valuesOf:"gaps",rows:b.headers,onChange:S=>A(E=>E.map((U,B)=>B===x?{...U,headers:S}:U))}),e.jsx(Ve,{kind:"env",valuesOf:"gaps",rows:b.env,onChange:S=>A(E=>E.map((U,B)=>B===x?{...U,env:S}:U))})]},x))}),(g||M)&&h.length<=1&&e.jsxs("button",{type:"button","aria-expanded":_,onClick:()=>{K(!_),h.length||A([Ye()])},className:"mt-3 inline-flex items-center gap-1 text-[12px] font-medium text-ink-secondary hover:text-ink",children:[_?e.jsx(ts,{size:14}):e.jsx(ls,{size:14})," ",n("mcp.details")]}),_&&v&&e.jsxs("div",{className:"mt-3",children:[g&&e.jsx("div",{className:"inline-flex rounded-lg bg-raised p-0.5",role:"radiogroup","aria-label":n("mcp.field.type"),children:["remote","stdio"].map(b=>e.jsx("button",{type:"button",role:"radio","aria-checked":v.transport===b,onClick:()=>J(x=>({...x,transport:b})),className:G("rounded-md px-3 py-1.5 text-[12px] font-medium transition-colors",v.transport===b?"bg-card text-ink shadow-sm":"text-ink-secondary hover:text-ink"),children:n(b==="stdio"?"mcp.transport.stdio":"mcp.transport.remote")},b))}),e.jsxs("div",{className:"mt-4 grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.field.name")}),e.jsx("input",{disabled:!g,value:v.name,maxLength:32,placeholder:"github",className:G(Te,"disabled:opacity-60"),onChange:b=>J(x=>({...x,name:b.target.value.toLowerCase()}))})]}),v.transport==="remote"?e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.field.url")}),e.jsx("input",{autoFocus:!g,value:v.url,spellCheck:!1,placeholder:"https://mcp.example.com/mcp",className:Te,onChange:b=>J(x=>({...x,url:b.target.value}))}),v.urlGap&&e.jsx("span",{className:"mt-1 block text-[11px] text-warning",children:n("mcp.paste.urlMissing")})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.field.type")}),e.jsxs(Ss,{className:"mt-1.5 w-full",value:v.type,onChange:b=>J(x=>({...x,type:b.target.value==="sse"?"sse":"http"})),children:[e.jsx("option",{value:"http",children:n("mcp.type.http")}),e.jsx("option",{value:"sse",children:n("mcp.type.sse")})]})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("div",{className:G(Ce,"mb-1.5"),children:n("mcp.field.headerRows")}),e.jsx(Ve,{kind:"header",rows:v.headers,onChange:b=>J(x=>({...x,headers:b}))}),e.jsx("span",{className:"mt-1.5 block text-[11px] text-ink-secondary",children:n("mcp.headersHint")})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("div",{className:"text-[12px] font-medium text-ink",children:n("mcp.oauth.title")}),e.jsx("p",{className:"mt-1 text-[11px] leading-relaxed text-ink-secondary",children:Z?n("mcp.oauth.hintRedirect",{uri:Z.redirectUri}):n("mcp.oauth.hint")}),e.jsxs("div",{className:"mt-2 grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.oauth.clientId")}),e.jsx("input",{value:v.oauthClientId,spellCheck:!1,autoComplete:"off",className:G(Te,"font-mono text-[12px]"),onChange:b=>J(x=>({...x,oauthClientId:b.target.value}))})]}),e.jsxs("label",{className:"block",children:[e.jsxs("span",{className:"flex items-center justify-between gap-2 text-[12px] font-medium text-ink-secondary",children:[n("mcp.oauth.clientSecret"),he&&e.jsx("button",{type:"button",onClick:()=>J(b=>({...b,oauthClientSecret:"",oauthForgetSecret:!0})),className:"text-[11px] font-normal text-ink-secondary underline-offset-2 hover:text-ink hover:underline",children:n("mcp.oauth.removeSecret")})]}),e.jsx("input",{type:"password",value:v.oauthClientSecret,autoComplete:"new-password",className:G(Te,"font-mono text-[12px]"),placeholder:he?n("mcp.oauth.secretSaved"):n("mcp.oauth.secretOptional"),onChange:b=>J(x=>({...x,oauthClientSecret:b.target.value}))})]}),e.jsxs("label",{className:"block sm:col-span-2",children:[e.jsx("span",{className:Ce,children:n("mcp.oauth.scopes")}),e.jsx("input",{value:v.oauthScopes,placeholder:"offline_access api://my-app/mcp.read",spellCheck:!1,className:G(Te,"font-mono text-[12px]"),onChange:b=>J(x=>({...x,oauthScopes:b.target.value}))})]})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:Ce,children:n("mcp.field.command")}),e.jsx("input",{autoFocus:!g,value:v.command,placeholder:"npx",className:Te,onChange:b=>J(x=>({...x,command:b.target.value}))})]}),e.jsxs("label",{className:"block sm:col-span-2",children:[e.jsx("span",{className:Ce,children:n("mcp.field.args")}),e.jsx("textarea",{value:v.args,placeholder:`-y
|
|
8
|
-
@modelcontextprotocol/server-github`,rows:4,className:G(Te,"resize-y font-mono text-[12px]"),onChange:b=>J(x=>({...x,args:b.target.value}))})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx("div",{className:G(Ce,"mb-1.5"),children:n("mcp.field.envRows")}),e.jsx(Ve,{kind:"env",rows:v.env,onChange:b=>J(x=>({...x,env:b}))})]})]}),e.jsx(Ja,{value:v.resultBudget,onChange:b=>J(x=>({...x,resultBudget:b}))})]})]}),o&&g&&h.length>0&&e.jsxs("div",{"data-mcp-team-scope":!0,className:"mt-4 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-lg bg-raised/50 px-3 py-2 text-[12px]",children:[e.jsx("span",{className:"text-ink-secondary",children:n(X&&H?"mcp.team.onlyMeOn":"mcp.team.everyone")}),X&&e.jsxs("label",{className:"flex items-center gap-1.5 text-ink",children:[e.jsx("input",{type:"checkbox",checked:H,onChange:b=>$(b.target.checked)})," ",n("mcp.team.onlyMe")]})]}),L&&e.jsx("p",{role:"alert",className:"mt-3 text-[12px] text-danger",children:n(L.key,L.params)}),e.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[e.jsx("button",{type:"button",onClick:l,className:"rounded-lg px-3 py-2 text-[13px] text-ink-secondary hover:bg-raised",children:n("mcp.cancel")}),e.jsxs("button",{type:"button",disabled:r||!h.length,onClick:ye,className:"flex items-center gap-1.5 rounded-lg bg-accent px-3.5 py-2 text-[13px] font-medium text-white disabled:opacity-50",children:[r&&e.jsx(ae,{size:13,className:"animate-spin"})," ",n(g?"mcp.add":"mcp.save")]})]})]})}const si="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAaEAAAGhCAMAAAD/dvvwAAACf1BMVEX////6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6Rhb6RhYZ6Qt0AAAA1XRSTlMAFThdfpaqwNbl8P/74dKwjmxDDgsvUXWMpLjM4Oz4/OLYtpRyTRg9X4CXq8LX5vH60K5qPgVilcj+1Z0iVYi7qW4jBzVom83z/dGZWREEOny/JiisjTsBBj/EdyEPrfRpR5jk3BRjtPbBDGH5ni0CSKPvuRC+JySE1GREpgllQGCC69oZi7UuF2eQ915m6CztJc57HaUTRXDKA0IaU+dYS3axTuq9N1Leicm3w8+i0xLZvAoxMoZzcRxP9VRaFjxbDVaDKcayTFwgnOma43i6CEF6bTOoblYlAAAHlElEQVR4AezBxQECMBAAsOJwh7s73X9ExugnSQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoJFOt9cfDEfjSURmTmM2XyxX601pabvbH46n8+V6i3vmI56v9+f7q6Wp+meuHhQrZ+IogJ81ztq2dbP12qjdpLaxtm3bts267/XZuDeTzEz6e4DBnxMnTZ4yddr0GV19JI2uw2YGDQoO6QeFQvuHhUf4+J9mzZ4zqQ08MHfe/AVd+N+GLVy0GB5YsnTZ8hUr+Z8io6JjYqFAXHxC4gj6NysiIQk6JQenDGcAo1PTTGhkpU/OMOhf5LTMLEiV3S4nl/ZE5MVCi9D8gkLaU9Q+C3oUl5SW0Z7ysL6QpKJySDcKqKqugWqrVq9ZSxHr8k2otj5vQyQFlE3ZCPfMidW5FLYgHypt2lxIYVu2WlBo1bbtIyhqVmk63NmxcwudidgFRcz8dXRm2O44KFLRu4jObGgL54r37KVznZZCAWvrFjq3b54JBfYf6ErnDh5ymp/5uXRlVvVhSBZ3ZBTdKe8vPz9Hj9GVkWNjIa5ici5d842Lg0SrjhfRtZHh6yFTbK9jdG34CRNiVoWdpBRDT0GaiUMpRZfxkCZu0WlK0ekMRKSdpSxV50IhxfmplObCRchxaTplKbu8CnZlF8yiRFcWw72ri1ZSohnXIEGbwZQp8TrsuXGTcvluwa2aK5QrcnMc3Np9mnINvw0b1q+hfMuXwI1Vd6ooXcZ+uNLmLuVLvYpAro2iChFuwpE1jSrcbAsX7t2nCg8uwq+rm2dRjZsP4dQjH9WoqoRT1lEq8vgQ/JiQSGWq5qmPhbAnJhzJukJlclfjf6WdpEKzLsOB60+p0mALDqxeS4W67cb/2GlQrVQTotrepFoLsiFsYCTVOof/cjWcyk0xIWZSFVV7KpqiJReo3Hz8W8UzalB9FQLMPRSlPkUXn1OchAV5/QW1uHAVtlkvqcWr17Bv7htqEY6/SxpFTabArn5vqcnTd7Dr/V5qshl/9WEvtfkIe4qfUpu3FuwJ8VGbT/jTLh81+gw7vmyhRjmrYMf4Mmq0G7+7VEadIr8isDb7qNUT2HDPoE5Gujf3kt/eB07QK2oWhoC+G9TrdBJ+VmtQt8K6VpcgGvUIoCGSur1p9OZe8u1V+JM9k/rNqBNOkHopQFMkvdDsN0FP6YUHV4UTpN5lPKcn9lmtLkEsa2l9CeIaj8JR9OVH9u5BV7IsDKDwHjueYGzbtm172rbdYdu2bdt29/u0ouafunX3qVo3WesRzhecbSDQeCDQyHFnPggLaPlOgc4DOkOEAmov0AVAp4k+FggJdO24jKMPgfK365eUAiICkEABEQFIoICIACRQQAQBEigmEggAFBMJNP1uAFBAJNAzAKCASCAAUEAkEAAoIBIIABQQCQQAiokEAgDFRAIBgGIigQBAMZFAAKCYSCAAUEwkEAAoJhIIABQQCQQAiokEAgDFRAIBgGIigQBAMZFAAKCYSCAAUEwkEAAoJhIIABQTCQQAiokEAgDlJroHCPTMbixQ5Yn+7wgEmg4FykkkEAAoJhIIABQTCQQAiokEAgDFRAIBgGKi8oF+WSZQDFQ8UQy0S6AAKA+RQACgmEggAFBMJBAAKCYSCAAUEi0ViAAUtLaeQFyggEggAlBAVOeAxqOB8hPVPaBGN1Wl+XmBAiKByqr98pQqTyQQAyggEogAFBAJRAAKiAQiAAVEAhGAAiKBCEABkUAIoIDoPYGgQHECCSSQQAIJJJBAAgkkkEACCSSQQAIJlKGbBWIDfbpFoNK6XyAiULzVUSCJBCqfSCCJBCqH6A6Blid0Hf8XKEkkUH4igWBEAkkkEJxIIDiRQHAigeBEAsGJQqArBao6UQg062mBiicSiE8kEJ9IID6RQHwigfhEAvGJBOITsYF+OwMkERdo3p8pSSQQn0ggPpFAcCKB4EQCwYkEghMJBCcSCE4kEJxIIDiRQHSiAQKxif4RiE0kEJxIIDiRQHAigeBEApGJBOITCQQnEghOJBCEaIZA8Fr0EYhPJBCfSCA+kUB8IoHQRCUC3Vp9IIn+KVVSoMoTCcQnEohOJBCcSCA40Ut1F8gEEkgggQQSSCATSCCBBOInkEACCfSsQGygxVckEwiQQAoJBCASSKIMQBIJJFEGIIkEkkigcokEkqi2QBIJJJFAcCKB4EQCoYkEAhAJBCASCEA0oxCgeaOSkR+wbvxnsmyNeDY70A/dk2Vs632Zgeb+nCxr497K6bN+T7LsrbsxG1DfFqmAbG/jTED7mqRCspZT78rgs396Kiz7bmatgQ58mQrMft54sFY+t/+UCs66f/NJ2T637Pk5FZ/V731jWT73fPhLssrU7tDBGvssfESfSvbVm4dfrQFP/24PJ6t0a4cvLI3n05kD/0xVyd5bc7jRTXFDrn1pSapiduTosV2TLqNTr9vxEy2TAVrywsBVI6/r/NTfZ2GePvjs4eaPPvKBczun2oNjAQAAAIBB/taz2FUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJcA09LUTxlsWtoAAAAASUVORK5CYII=",Oe="postiz",lt="https://api.postiz.com",ai="https://platform.postiz.com/settings";function ii(t){if(!t||typeof t!="object")return!1;const s=t;return typeof s.state=="string"&&typeof s.address=="string"&&typeof s.host=="string"&&(s.how===null||s.how==="sign-in"||s.how==="key")}const pt=[{id:"whop",label:"Whop",url:"https://mcp.whop.com/mcp",icon:{image:si},description:"whop.description",notice:"whop.notice",keywords:"whop checkout memberships"},{id:"agentcard",label:"Agentcard",url:"https://mcp.agentcard.sh/mcp",icon:{glyph:Rs},description:"agentcard.description",notice:"agentcard.notice",keywords:"agentcard agent card opencommerce shopping payments buy virtual debit card"},{id:"agentmail",label:"AgentMail",url:"https://mcp.agentmail.to/mcp",icon:{glyph:Es},description:"agentmail.description",notice:"agentmail.notice",keywords:"agentmail email inbox mail address send reply"},{id:"vapi",label:"Vapi",url:"https://mcp.vapi.ai/mcp",key:{url:"https://dashboard.vapi.ai"},icon:{glyph:ma},description:"vapi.description",notice:"vapi.notice",keywords:"vapi phone call calls voice dial assistant"},{id:"telnyx",label:"Telnyx",url:"https://api.telnyx.com/v2/mcp",key:{url:"https://portal.telnyx.com/#/api-keys"},icon:{glyph:fa},description:"telnyx.description",notice:"telnyx.notice",keywords:"telnyx phone number numbers sms text call calls international"},{id:"agentphone",label:"AgentPhone",url:"https://mcp.agentphone.ai/mcp",icon:{glyph:ia},description:"agentphone.description",notice:"agentphone.notice",keywords:"agentphone phone number sms text call calls"}];function gn(t){if(t.type!=="http"||!t.url)return;let s;try{s=new URL(t.url)}catch{return}if(!(s.search||s.hash||s.username||s.password))return pt.find(c=>{const o=new URL(c.url);return s.origin===o.origin&&(s.pathname===o.pathname||s.pathname===`${o.pathname}/`)})}function Hn(t,s){const c=new Set(s.map(r=>r.name));let o=t.id;for(let r=2;c.has(o);r++)o=`${t.id}-${r}`;return o}const hs="Authorization";function oi(t){const s=c=>c.headerKeys?.some(o=>o.toLowerCase()===hs.toLowerCase())===!0;return Object.fromEntries(pt.map(c=>[c.id,t.some(o=>gn(o)===c&&o.enabled&&("key"in c?s(o):o.auth==="signed-in"))]))}function cn(t){return t.url===void 0||!(gn(t)||t.name===Oe)}function fs(t){return t.enabled&&t.auth!=="needs-sign-in"}const xs=128;function ci(t,s=xs){return t>=s?"exceeds":t*2>=s?"crowds":"fits"}const ri=1500;async function St(t,s,c){try{return await s(`/api/mcp/servers/${encodeURIComponent(t)}/test`,{method:"POST",signal:c})}catch(o){if(c?.aborted)throw o;return{ok:!1,error:o instanceof Error?o.message:String(o),reason:"unreachable"}}}async function _n(t,s,c,o,r="hostedMcp.testFailed"){const l=await St(t,s,c);if(l.ok)return l;const y=(l.error??"").trim();return{...l,error:n(r,{service:o,reason:y&&!/[.!?]$/.test(y)?`${y}.`:y})}}function Jn(t,s){if(s.reason!=="keys"||!pe(t))return s.error??"";const c=s.status?`HTTP ${s.status}`:n("mcp.check.unauthorized");return t.headerKeys.length?n("mcp.check.keysRefused",{reason:c,names:new Intl.ListFormat(Bt(),{style:"long",type:"conjunction"}).format(t.headerKeys)}):n("mcp.check.keysNeeded",{reason:c})}function li(t){const s=Math.max(t.total??0,t.tools?.length??0);if(!s)return n("mcp.check.connectedNone");const c=s===1?n("mcp.check.connectedOne"):n("mcp.check.connectedMany",{count:s}),o=ci(s);return o==="fits"?c:`${c}. ${n(o==="exceeds"?"mcp.check.overLimit":"mcp.check.crowdsLimit",{count:s,limit:xs})}`}function Vn({embedded:t=!1,hostedCards:s,hideHosted:c=!1,refreshKey:o=0}={}){const{state:r,dispatch:l}=Xe(),y=a=>r.bots?.find(u=>u.id===a)?.name??a,g=r.config?.managedPolicy,k=!!(g&&!g.mcp.allowCustom),[p,h]=d.useState(null),[A,Q]=d.useState(null),[C,M]=d.useState(null),[_,K]=d.useState(null),[H,$]=d.useState(null),[L,le]=d.useState({}),[v,J]=d.useState(null),Z=d.useRef(null),he=d.useRef(null),[X,ee]=d.useState(null),[ye,W]=d.useState(""),[b,x]=d.useState(null),[S,E]=d.useState(!1),[U,B]=d.useState(!1),Y=d.useRef({}),[Pe,Me]=d.useState(null),[Le,we]=d.useState(null),[Re,Ue]=d.useState({}),ne=d.useRef(0),q=d.useRef(!0),xe=a=>pe(a)?gn(a):void 0,V=d.useMemo(()=>p&&oi(p),[p]),ke=s?.onConnections;d.useEffect(()=>{V&&ke?.(V)},[V,ke]);const $e=s?.onServers;d.useEffect(()=>{p&&$e?.(p)},[p,$e]);const oe=a=>(h(a??[]),Gt(a??[]),a??[]),je=a=>le(u=>{const f={...u};return delete f[a],f}),Ne=d.useCallback(()=>{const a=++ne.current;return M("load"),K(null),w("/api/mcp/servers").then(u=>{a===ne.current&&(h(u.servers??[]),Gt(u.servers??[]))}).catch(u=>{a===ne.current&&K(u instanceof Error?u.message:String(u))}).finally(()=>{a===ne.current&&M(null)})},[]);d.useEffect(()=>(q.current=!0,Ne(),()=>{q.current=!1,ne.current+=1}),[Ne,o]);const R=d.useRef(null);R.current=C,d.useEffect(()=>{const a=()=>{if(R.current!==null)return;const u=ne.current;w("/api/mcp/servers").then(f=>{!q.current||R.current!==null||u!==ne.current||(h(f.servers??[]),Gt(f.servers??[]))}).catch(()=>{})};return zs({onFrame:u=>{u.kind==="mcp.changed"&&a()},onMissedFrames:a})},[]);const I=()=>{Q(null),B(!1)},ce=(a,u=!1)=>{Q(a),B(u),K(null),$(null)},se=async(a,u=!1)=>{M(`test:${a}`),Me(a),ne.current+=1,je(a);let f=await St(a,w);if(f.ok)try{oe((await w(`/api/mcp/servers/${encodeURIComponent(a)}`,{method:"PATCH",body:JSON.stringify({enabled:!0})})).servers),Y.current[a]=Date.now()}catch(m){f={ok:!1,error:m instanceof Error?m.message:String(m)}}return u&&(f={...f,saved:!0}),q.current&&(le(m=>({...m,[a]:f})),M(null),Me(null)),f},ue=async a=>{M("save"),ne.current+=1,K(null),$(null);const u=[];let f=p??[];try{for(const m of a){const P=m.ownKey?{...m.body,headers:Object.fromEntries(Object.keys(m.body.headers??{}).map(N=>[N,""]))}:m.body;f=oe((await w("/api/mcp/servers",{method:"POST",body:JSON.stringify({name:m.name,...P})})).servers),m.ownKey&&(await w("/api/team/connection-scopes",{method:"PUT",body:JSON.stringify({kind:"mcp",id:m.name,scope:"person"})}),await w(`/api/team/my-connections/mcp/${encodeURIComponent(m.name)}/key`,{method:"PUT",body:JSON.stringify({value:m.ownKey,url:P.url})}),f=oe((await w(`/api/mcp/servers/${encodeURIComponent(m.name)}`,{method:"PUT",body:JSON.stringify({...P,enabled:!1})})).servers)),u.push(m.name)}}catch(m){K(m instanceof Error?m.message:String(m))}M(null),u.length&&I();for(const m of u){const P=await se(m,!0),N=f.find(te=>te.name===m);P.auth==="required"&&N&&u.length===1&&q.current&&await Ee(N)}},re=async([a])=>{const u=p?.find(f=>f.name===A);if(!(!a||!u)){M("save"),ne.current+=1,K(null),$(null);try{let f=a.body,m;if(r.config?.team&&u.scope!=="team"&&typeof f.url=="string"&&!f.oauth&&(await w("/api/team/my-connections")).mcp.some(N=>N.name===a.name)){const N=f.headers??{};if(Object.keys(N).length>1)throw new Error(n("mcp.personal.oneHeader"));const te=Object.values(N)[0];m=typeof te=="string"?te:void 0,f={...f,headers:Object.fromEntries(Object.keys(N).map(ie=>[ie,""]))}}oe((await w(`/api/mcp/servers/${encodeURIComponent(a.name)}`,{method:"PUT",body:JSON.stringify({...f,enabled:u.enabled})})).servers),m&&await w(`/api/team/my-connections/mcp/${encodeURIComponent(a.name)}/key`,{method:"PUT",body:JSON.stringify({value:m,url:f.url})}),I()}catch(f){K(f instanceof Error?f.message:String(f)),M(null);return}M(null),u.runsOn||await se(a.name,!0)}},Se=async a=>{if(a.enabled&&Date.now()-(Y.current[a.name]??0)<ri){$({key:"mcp.switchedOnByTest",params:{name:a.name}});return}M(`toggle:${a.name}`),ne.current+=1,K(null);try{oe((await w(`/api/mcp/servers/${a.name}`,{method:"PATCH",body:JSON.stringify({enabled:!a.enabled})})).servers),$({key:"mcp.toggled",params:{name:a.name},stateKey:a.enabled?"mcp.state.off":"mcp.state.on"})}catch(u){K(u instanceof Error?u.message:String(u))}finally{M(null)}},fe=async a=>{M(`test:${a.name}`),ne.current+=1,K(null),je(a.name);const u=await St(a.name,w);le(f=>({...f,[a.name]:u})),M(null)};async function Ee(a){const u=Rt(),f=new AbortController;Z.current=f,J(a.name),ee(null),W(""),x(null),K(null),we(null),$(null),je(a.name);const m=xe(a);try{const P=async te=>{!await u.open(te)&&q.current&&!f.signal.aborted&&x(n("connectors.card.popupBlocked"))},N=await ns(a.name,{api:w,open:P,signal:f.signal,onStarted:(te,ie)=>{ee(te),he.current=ie}});if(!q.current||f.signal.aborted)return;if(N.phase==="succeeded"){ee({...N,flowId:null,authorizationUrl:null});const te=m?await _n(a.name,w,f.signal,m.label):await St(a.name,w,f.signal);if(f.signal.aborted||!q.current||(le(De=>({...De,[a.name]:te})),!te.ok))return;const ie=await w(`/api/mcp/servers/${a.name}`,{method:"PATCH",body:JSON.stringify({enabled:!0})});if(!q.current)return;oe(ie.servers),m&&$({key:"hostedMcp.connected",params:{service:m.label}})}else N.phase!=="cancelled"&&le(te=>({...te,[a.name]:{ok:!1,error:N.message||n("mcp.auth.failed")}}))}catch(P){q.current&&!f.signal.aborted&&le(N=>({...N,[a.name]:{ok:!1,error:P instanceof Error?P.message:String(P)}}))}finally{u.cancel(),Z.current===f&&(Z.current=null,he.current=null,E(!1),J(null),ee(null),W(""),x(null),q.current&&Ne())}}const et=async a=>{if(!p||C!==null||v!==null)return;const u=p.find(m=>xe(m)===a);if("key"in a){await tt(a,u);return}if(u){await Ee(u);return}M(`hosted:${a.id}`),ne.current+=1,K(null),we(null),$(null);let f;try{const m=Hn(a,p),P=await w("/api/mcp/servers",{method:"POST",body:JSON.stringify({name:m,type:"http",url:a.url,enabled:!1})});if(!q.current)return;if(f=oe(P.servers).find(N=>N.name===m&&xe(N)===a),!f)throw new Error(n("hostedMcp.setupFailed",{service:a.label}))}catch(m){q.current&&we({id:a.id,message:m instanceof Error?m.message:String(m)})}finally{q.current&&M(null)}f&&q.current&&await Ee(f)},tt=async(a,u)=>{const f=Re[a.id]?.trim();if(!p||!f)return;M(`hosted:${a.id}`),ne.current+=1,K(null),we(null),$(null);const m=u?.name??Hn(a,p);je(m);try{const P={type:"http",url:a.url,headers:{[hs]:`Bearer ${f}`},enabled:!1};oe((await w(u?`/api/mcp/servers/${m}`:"/api/mcp/servers",{method:u?"PUT":"POST",body:JSON.stringify(u?P:{name:m,...P})})).servers);const N=await _n(m,w,void 0,a.label,"hostedMcp.keyTestFailed");if(!q.current||(le(te=>({...te,[m]:N.reason==="keys"?{...N,error:n("hostedMcp.keyRefused",{service:a.label})}:N})),!N.ok))return;oe((await w(`/api/mcp/servers/${m}`,{method:"PATCH",body:JSON.stringify({enabled:!0})})).servers),Ue(te=>({...te,[a.id]:""})),$({key:"hostedMcp.connected",params:{service:a.label}})}catch(P){q.current&&we({id:a.id,message:P instanceof Error?P.message:String(P)})}finally{q.current&&M(null)}},ft=async()=>{if(!v||!X?.flowId||S)return;const a=Z.current;E(!0),x(null);try{const u=await ss(v,X.flowId,ye,w);Z.current===a&&he.current?.(u)}catch(u){Z.current===a&&x(u instanceof Error?u.message:String(u))}finally{Z.current===a&&E(!1)}},Fe=async(a,u)=>{M(`signout:${a.name}`),ne.current+=1,K(null),we(null),$(null),je(a.name);try{if(u&&"key"in u){oe((await w(`/api/mcp/servers/${a.name}`,{method:"DELETE"})).servers);return}xe(a)&&oe((await w(`/api/mcp/servers/${a.name}`,{method:"PATCH",body:JSON.stringify({enabled:!1})})).servers),oe((await w(`/api/mcp/servers/${a.name}/sign-out`,{method:"POST"})).servers)}catch(f){const m=f instanceof Error?f.message:String(f);u?we({id:u.id,message:m}):K(m)}finally{M(null)}};d.useEffect(()=>()=>Z.current?.abort(),[]);const be=async a=>{if(window.confirm(n("mcp.removeConfirm",{name:a.name}))){M(`delete:${a.name}`),ne.current+=1,K(null);try{oe((await w(`/api/mcp/servers/${a.name}`,{method:"DELETE"})).servers),je(a.name),A===a.name&&I()}catch(u){K(u instanceof Error?u.message:String(u))}finally{M(null)}}},Ke=A&&A!=="new"?p?.find(a=>a.name===A):void 0;function xt(a){return e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"mt-3 block",htmlFor:`mcp-callback-${a.name}`,children:n("mcp.auth.callbackUrl")}),e.jsx("input",{id:`mcp-callback-${a.name}`,type:"text",value:ye,disabled:S,onChange:u=>W(u.target.value),autoComplete:"off",spellCheck:!1,placeholder:"http://127.0.0.1:…/mcp-oauth/callback?…",className:"mt-1 w-full rounded-lg border border-hairline bg-inset px-3 py-2 text-ink outline-none focus:border-accent"}),e.jsxs("button",{type:"button",disabled:!ye.trim()||S,"aria-busy":S,onClick:()=>{ft()},className:"mt-2 inline-flex items-center gap-2 rounded-lg bg-accent px-3 py-2 font-medium text-white disabled:opacity-40",children:[S&&e.jsx(ae,{size:14,className:"animate-spin","aria-hidden":"true"}),n(S?"mcp.auth.completing":"mcp.auth.complete")]})]})}function nt(a){const u=xe(a);return v===a.name&&e.jsxs("div",{className:"mt-3 space-y-3 rounded-lg bg-raised px-3 py-3 text-[12px] text-ink-secondary",children:[e.jsxs("div",{role:"status",className:"flex items-center gap-2",children:[e.jsx(ae,{size:13,className:"animate-spin"})," ",X?.phase!=="succeeded"?n("mcp.auth.waiting"):u?n("hostedMcp.loadingTools",{service:u.label}):n("mcp.auth.loadingTools")]}),X?.authorizationUrl&&Et(X.authorizationUrl)&&e.jsx("button",{type:"button",onClick:()=>{x(null),en(X.authorizationUrl).catch(()=>x(n("mcp.auth.openFailed")))},className:"text-accent hover:underline",children:n("mcp.auth.openAgain")}),X?.flowId&&(X.pasteBack?e.jsxs("div",{children:[e.jsx("p",{className:"leading-relaxed text-ink",children:n("mcp.auth.pasteBackHint")}),xt(a)]}):e.jsxs("details",{children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:n("mcp.auth.otherComputer")}),e.jsx("p",{className:"mt-2 leading-relaxed",children:n("mcp.auth.otherComputerHint")}),xt(a)]})),b&&e.jsx("p",{role:"alert",className:"text-danger",children:b})]})}function Pt(a){const u=p?.find(ie=>xe(ie)===a),f=!!V?.[a.id],m=u&&L[u.name],P=_||(Le?.id===a.id?Le.message:null)||(m&&!m.ok?m.error:null),N=C!==null||v!==null,te=C===`hosted:${a.id}`||u!==void 0&&(v===u.name||C===`signout:${u.name}`);return e.jsxs("div",{"data-app-tile":a.id,className:"flex min-w-0 flex-col rounded-xl px-2 py-2 transition-colors hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pn,{app:a}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold leading-5 text-ink",children:a.label}),f&&e.jsx(We,{size:13,strokeWidth:2.5,className:"shrink-0 text-success","aria-label":n("apps.connected")})]}),e.jsx("p",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",title:n(a.description),children:n(a.description)})]}),u&&v===u.name?e.jsx("button",{type:"button",onClick:()=>Z.current?.abort(),className:"inline-flex h-7 shrink-0 items-center rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink",children:n("mcp.auth.cancel")}):e.jsx("button",{type:"button","aria-label":n(f?"hostedMcp.disconnect":"hostedMcp.connect",{service:a.label}),disabled:N||p!==null&&!f&&(!!u?.managedBy||k&&!g?.mcp.allowlist.length||"key"in a&&!Re[a.id]?.trim()),onClick:()=>{p===null?Ne():f&&u?Fe(u,a):et(a)},className:"inline-flex h-7 min-w-[64px] shrink-0 items-center justify-center gap-2 rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink hover:bg-raised-hover disabled:opacity-40",children:N&&(te||C==="load")?e.jsx(ae,{size:14,className:"animate-spin"}):p===null?n("connectors.action.retry"):n(f?"connectors.disconnect":"connectors.action.connect")})]}),e.jsxs("div",{className:"ps-[52px]",children:["key"in a&&!f&&p!==null&&e.jsxs("div",{className:"mt-2 flex flex-col items-start gap-2",children:[e.jsx("input",{type:"password",value:Re[a.id]??"",disabled:N,autoComplete:"off",spellCheck:!1,"aria-label":n("hostedMcp.keyLabel",{service:a.label}),placeholder:n("hostedMcp.keyPlaceholder",{service:a.label}),onChange:ie=>{const De=ie.target.value;Ue(Lt=>({...Lt,[a.id]:De}))},onKeyDown:ie=>{ie.key==="Enter"&&et(a)},className:"h-8 w-full min-w-0 rounded-lg bg-inset px-2.5 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none focus:ring-1 focus:ring-accent/50"}),e.jsxs("button",{type:"button",onClick:()=>{en(a.key.url)},className:"inline-flex items-center gap-1 text-[12px] font-medium text-accent-text hover:underline",children:[n("hostedMcp.getKey",{service:a.label}),e.jsx(pn,{size:11,"aria-hidden":"true"})]})]}),P&&e.jsx("p",{role:"alert",className:"mt-1.5 text-[12px] text-danger",children:typeof P=="string"?P:n(P.key,P.params)}),u&&nt(u),e.jsxs("details",{className:"mt-1 text-[12px] text-ink-secondary",children:[e.jsx("summary",{className:"cursor-pointer",children:n("hostedMcp.access")}),e.jsx("p",{className:"mt-2 leading-relaxed",children:n(a.notice)}),e.jsx("p",{className:"mt-2 leading-relaxed",children:n("hostedMcp.accessHint")}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:(r.bots??[]).filter(ie=>!ie.hidden).map(ie=>e.jsx("button",{type:"button",onClick:()=>{l({type:"togglePlugins",open:!1}),Xt(l,"access",{botId:ie.id,page:"mcp"})},className:"rounded-lg bg-control px-2.5 py-1.5 text-ink hover:bg-raised-hover",children:n("hostedMcp.botSettings",{name:ie.name})},ie.id))})]})]})]})}function Mt(a,u){const f=pe(a)&&a.auth==="needs-sign-in",m=L[a.name],P=m&&!m.ok&&!m.auth?n("mcp.check.failed",{reason:Jn(a,m)}):null,N=f?n("mcp.auth.needsSignIn"):a.offFor?.length?n("mcp.offFor",{bots:a.offFor.map(y).join(", ")}):pe(a)?a.url:[a.command,...a.args].join(" ");return e.jsxs("div",{"data-app-tile":a.name,"data-mcp-tile":"",className:"flex min-w-0 flex-col rounded-xl px-2 py-2 transition-colors hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[8px] bg-raised text-ink-secondary",children:pe(a)?e.jsx(Sn,{size:19}):e.jsx(qt,{size:19})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold leading-5 text-ink",children:a.name}),fs(a)&&e.jsx(We,{size:13,strokeWidth:2.5,className:"shrink-0 text-success","aria-label":n("apps.connected")})]}),e.jsx("p",{className:G("truncate text-[13px] leading-[18px]",f?"text-warning":"text-ink-secondary"),title:N,children:N})]}),v===a.name?e.jsx("button",{type:"button",onClick:()=>Z.current?.abort(),className:"inline-flex h-7 shrink-0 items-center rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink",children:n("mcp.auth.cancel")}):e.jsx("button",{type:"button",disabled:f&&(C!==null||v!==null||!!a.managedBy),onClick:()=>{f?Ee(a):u()},className:"inline-flex h-7 min-w-[64px] shrink-0 items-center justify-center rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink hover:bg-raised-hover disabled:opacity-40",children:n(f?"mcp.auth.signIn":"apps.mcp.manage")})]}),e.jsxs("div",{className:"ps-[52px]",children:[P&&e.jsx("p",{role:"alert",className:"mt-1.5 text-[12px] text-danger",children:P}),nt(a)]})]},a.name)}if(s){const a=s.ownServers;return e.jsxs(e.Fragment,{children:[pt.map(u=>e.jsx("div",{className:s.shown(u.id)?"contents":"hidden",children:Pt(u)},u.id)),a&&p?.filter(u=>u.enabled&&cn(u)&&a.shown(u)).map(u=>Mt(u,a.manage))]})}const ze=p?.filter(a=>!c||cn(a));return e.jsx("section",{"data-mcp-servers":!0,"aria-labelledby":"mcp-servers-title",className:t?"":"min-h-0 flex-1 overflow-y-auto px-6 pb-7 pt-5 sm:px-8",children:e.jsxs("div",{className:t?"":"mx-auto max-w-[840px]",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_280px]",children:[e.jsx("h3",{id:"mcp-servers-title",className:"text-[15px] font-semibold text-ink",children:n("mcp.title")}),e.jsx("p",{className:"mt-1 max-w-[610px] break-words text-[13px] leading-relaxed text-ink-secondary",children:n("mcp.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{Ne()},disabled:C!==null,className:"rounded-lg p-2 text-ink-secondary transition-colors hover:bg-raised hover:text-ink disabled:opacity-40","aria-label":n("mcp.refreshAria"),children:e.jsx(tn,{size:16,className:G(C==="load"&&"animate-spin")})}),e.jsxs("button",{type:"button",disabled:C!==null||k&&!g?.mcp.allowlist.length,title:k&&g?n("policy.managedBy",{organization:g.organizationName}):void 0,onClick:()=>ce("new"),className:"flex items-center gap-1.5 rounded-lg bg-accent px-3 py-2 text-[13px] font-medium text-white disabled:opacity-40",children:[e.jsx(rs,{size:14})," ",n(t?"apps.mcp.add":"mcp.addServer")]})]})]}),k&&g&&e.jsx("p",{role:"status",className:"mt-3 text-[13px] leading-relaxed text-ink-secondary",children:n("policy.mcpRestricted",{organization:g.organizationName})}),(A==="new"||Ke)&&e.jsx(ni,{server:Ke,fixKeys:U,taken:(p??[]).map(a=>a.name),team:!!r.config?.team,busy:C!==null,onCancel:I,onSubmit:a=>{A==="new"?ue(a):re(a)}},`${A}${U?":keys":""}`),_&&e.jsx("div",{role:"alert",className:"mt-3 rounded-lg bg-danger/10 px-3 py-2 text-[12px] text-danger",children:typeof _=="string"?_:n(_.key,_.params)}),H&&e.jsx("div",{role:"status",className:"mt-3 rounded-lg bg-success/10 px-3 py-2 text-[12px] text-success",children:n(H.key,{...H.params,...H.stateKey?{state:n(H.stateKey)}:{}})}),e.jsx(Aa,{}),e.jsx("div",{className:"mt-4 rounded-xl border border-hairline/50 bg-raised/35 px-4 py-3 text-[12px] leading-relaxed text-ink-secondary",children:n("mcp.trustNotice")}),p===null?e.jsxs("div",{className:"flex items-center justify-center gap-2 py-24 text-[13px] text-ink-secondary",children:[e.jsx(ae,{size:14,className:"animate-spin"})," ",n("mcp.loading")]}):ze?.length===0&&!A?e.jsxs("div",{className:"mt-5 flex min-h-32 flex-col items-center justify-center rounded-2xl border border-dashed border-hairline/60 text-center",children:[e.jsx("div",{className:"flex size-11 items-center justify-center rounded-xl bg-raised text-ink-secondary",children:e.jsx(qt,{size:21})}),e.jsx("div",{className:"mt-3 text-[14px] font-medium text-ink",children:n("mcp.empty.title")}),e.jsx("div",{className:"mt-1 max-w-sm text-[13px] text-ink-secondary",children:n("mcp.empty.desc")})]}):e.jsx("div",{className:"mt-5 space-y-3",children:ze?.map(a=>{const u=xe(a),f=L[a.name],m=pe(a)?a.auth:void 0,P=pe(a)&&!a.runsOn&&(m==="needs-sign-in"||f?.auth==="required"||(!!u||!!a.oauth)&&m!=="signed-in");return e.jsxs("div",{"data-hosted-server":u?.id,className:"rounded-2xl border border-hairline/50 bg-card px-4 py-4 sm:px-5",children:[e.jsxs("div",{"data-mcp-row":!0,className:"flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:G("flex size-10 shrink-0 items-center justify-center rounded-xl",a.enabled?"bg-success/10 text-success":"bg-raised text-ink-secondary"),children:u?e.jsx(Pn,{app:u}):pe(a)?e.jsx(Sn,{size:19}):e.jsx(qt,{size:19})}),e.jsxs("div",{className:"min-w-0 flex-[1_1_220px]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-[14px] font-medium text-ink",children:u?u.label:a.name}),e.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[11px]",a.enabled?"bg-success/10 text-success":"bg-raised text-ink-secondary"),children:n(a.enabled?"mcp.badge.on":"mcp.badge.off")}),m&&e.jsx("span",{className:G("rounded-full px-2 py-0.5 text-[11px]",m==="signed-in"?"bg-success/10 text-success":"bg-warning/10 text-warning"),children:n(m==="signed-in"?"mcp.auth.signedIn":"mcp.auth.needsSignIn")}),a.managedBy&&e.jsx("span",{className:"rounded-full bg-raised px-2 py-0.5 text-[11px] text-ink-secondary",children:n("policy.managedBy",{organization:a.managedBy})})]}),a.managedBy&&e.jsx("div",{className:"mt-1 text-[12px] text-ink-secondary",children:n("policy.mcpBlocked",{organization:a.managedBy})}),a.runsOn&&e.jsx("div",{"data-mcp-runs-on":!0,className:"mt-1 text-[12px] text-ink-secondary",children:n("mcp.runsOn",{computer:a.runsOn.label})}),a.bot&&e.jsx("div",{"data-mcp-own-bot":!0,className:"mt-1 text-[12px] text-ink-secondary",children:n("mcp.ownBot",{bot:y(a.bot)})}),a.offFor?.length?e.jsx("div",{"data-mcp-off-for":!0,className:"mt-1 text-[12px] text-ink-secondary",children:n("mcp.offFor",{bots:a.offFor.map(y).join(", ")})}):null,a.keyOff&&e.jsx("div",{"data-mcp-key-off":!0,className:"mt-1 text-[12px] text-warning",children:n("mcp.keyOff")}),e.jsx("div",{className:"mt-1 truncate font-mono text-[12px] text-ink-secondary",children:pe(a)?a.url:[a.command,...a.args].join(" ")}),pe(a)?a.headerKeys.length>0&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-ink-secondary",children:n("mcp.headersSaved",{keys:a.headerKeys.join(", ")})}):a.envKeys.length>0&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-ink-secondary",children:n("mcp.secretsSaved",{keys:a.envKeys.join(", ")})}),pe(a)&&a.oauth&&e.jsx("div",{className:"mt-1 truncate text-[11px] text-ink-secondary",children:n(a.oauth.clientSecretConfigured?"mcp.oauth.savedWithSecret":"mcp.oauth.saved",{clientId:a.oauth.clientId})})]}),e.jsxs("div",{"data-mcp-row-actions":!0,className:"ml-auto flex flex-wrap items-center justify-end gap-1",children:[v===a.name?e.jsxs("button",{type:"button",onClick:()=>Z.current?.abort(),className:"flex items-center gap-1.5 rounded-lg px-2.5 py-2 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink",children:[e.jsx(ae,{size:14,className:"animate-spin"})," ",n("mcp.auth.cancel")]}):P?e.jsxs("button",{type:"button",disabled:C!==null||v!==null||!!a.managedBy,onClick:()=>{Ee(a)},className:"flex items-center gap-1.5 rounded-lg bg-accent px-2.5 py-2 text-[12px] font-medium text-white hover:brightness-110 disabled:opacity-40",children:[e.jsx(Is,{size:14})," ",u?n("hostedMcp.connect",{service:u.label}):n("mcp.auth.signIn")]}):m==="signed-in"?e.jsxs("button",{type:"button",disabled:C!==null||v!==null,onClick:()=>{Fe(a)},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-2 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:[C===`signout:${a.name}`?e.jsx(ae,{size:14,className:"animate-spin"}):e.jsx(oa,{size:14})," ",u?n("hostedMcp.disconnect",{service:u.label}):n("mcp.auth.signOut")]}):null,e.jsxs("button",{type:"button",disabled:C!==null||v!==null,onClick:()=>{fe(a)},className:"flex items-center gap-1.5 rounded-lg px-2.5 py-2 text-[12px] text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40",children:[C===`test:${a.name}`?e.jsx(ae,{size:14,className:"animate-spin"}):e.jsx(Ts,{size:14})," ",n("mcp.test")]}),e.jsx("button",{type:"button",disabled:C!==null||v!==null,onClick:()=>ce(a.name),className:"rounded-lg p-2 text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-40","aria-label":n("mcp.editAria",{name:a.name}),children:e.jsx(Os,{size:14})}),e.jsx("button",{type:"button",disabled:C!==null||v!==null,onClick:()=>{be(a)},className:"rounded-lg p-2 text-ink-secondary hover:bg-danger/10 hover:text-danger disabled:opacity-40","aria-label":n("mcp.removeAria",{name:a.name}),children:e.jsx(Bs,{size:14})}),e.jsxs("span",{className:"ml-1 flex items-center",children:[C===`toggle:${a.name}`&&e.jsx(ae,{size:13,className:"mr-1.5 animate-spin text-ink-secondary"}),e.jsx(un,{checked:a.enabled,disabled:C!==null||v!==null,onClick:()=>{Se(a)},"aria-label":n("mcp.toggleAria",{name:a.name,state:n(a.enabled?"mcp.state.off":"mcp.state.on")}),className:"disabled:opacity-40"})]})]})]}),u&&e.jsxs("div",{className:"mt-3 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("p",{children:n(u.notice)}),e.jsxs("details",{className:"mt-2",children:[e.jsx("summary",{className:"cursor-pointer font-medium text-ink",children:n("hostedMcp.access")}),e.jsx("p",{className:"mt-2",children:n("hostedMcp.accessHint")}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:(r.bots??[]).filter(N=>!N.hidden).map(N=>e.jsx("button",{type:"button",onClick:()=>{l({type:"togglePlugins",open:!1}),Xt(l,"access",{botId:N.id,page:"mcp"})},className:"rounded-lg bg-control px-2.5 py-1.5 text-ink hover:bg-raised-hover",children:n("hostedMcp.botSettings",{name:N.name})},N.id))})]})]}),e.jsx(Na,{server:a,disabled:C!==null||v!==null,onSaved:N=>{ne.current+=1,oe(N)}}),nt(a),Pe===a.name&&!a.enabled&&!f&&e.jsxs("div",{role:"status","data-mcp-testing":!0,className:"mt-3 flex items-center gap-2 rounded-lg bg-raised px-3 py-2 text-[12px] text-ink-secondary",children:[e.jsx(ae,{size:13,className:"animate-spin","aria-hidden":"true"})," ",n("mcp.check.testingOff")]}),f&&v!==a.name&&e.jsx("div",{role:"status",className:G("mt-3 flex flex-wrap items-center justify-between gap-2 rounded-lg px-3 py-2 text-[12px]",f.ok?"bg-success/10 text-success":f.auth==="required"?"bg-warning/10 text-warning":"bg-danger/10 text-danger"),children:f.auth==="required"?n("mcp.auth.required"):f.ok?e.jsxs("span",{className:"flex items-start gap-2",children:[e.jsx(Ps,{size:14,className:"mt-px shrink-0"})," ",li(f)]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1",children:n(a.enabled?"mcp.check.failed":f.saved?"mcp.check.savedOff":"mcp.check.failedOff",{reason:Jn(a,f)})}),f.reason==="keys"&&pe(a)||f.reason==="unreachable"||f.reason==="timeout"?e.jsx("button",{type:"button",disabled:C!==null||v!==null,onClick:()=>f.reason==="keys"?ce(a.name,!0):void se(a.name),className:"shrink-0 rounded-lg bg-card px-2.5 py-1.5 font-medium text-ink hover:bg-raised-hover disabled:opacity-40",children:n(f.reason==="keys"?"mcp.check.fixKeys":"mcp.check.tryAgain")}):null]})})]},a.name)})})]})})}const Ge="/api/postiz",di="postiz social media posts schedule linkedin instagram facebook tiktok threads bluesky",Zt={slug:Oe,categories:["Social"]};function mt(t){try{return new URL(t.trim()).host}catch{return t.trim()}}function rn(t,s){const c=t?.body,o=typeof c?.code=="string"?c.code:null,r=mt(s);return o==="key_rejected"?n("postiz.error.keyRejected"):o==="unreachable"?n("postiz.error.unreachable",{host:r}):o==="not_postiz"?n("postiz.error.notPostiz",{host:r}):o==="address"?n("postiz.error.address"):o==="taken"?n("postiz.taken"):typeof c?.error=="string"&&c.error?c.error:t instanceof Error?t.message:String(t)}function ui(t,s){const c=t instanceof Error?t.message:"";return/didn't accept this API key/u.test(c)||t?.name==="KeyRejected"?n("postiz.error.keyRejected"):/Couldn't reach a Postiz server/u.test(c)?n("postiz.error.unreachable",{host:mt(s)}):/didn't answer like Postiz/u.test(c)?n("postiz.error.notPostiz",{host:mt(s)}):rn(t,s)}const qe="inline-flex h-7 min-w-[64px] shrink-0 items-center justify-center gap-2 rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink transition-colors hover:bg-raised-hover disabled:opacity-40",Wt="h-8 w-full min-w-0 rounded-lg bg-inset px-2.5 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none focus:ring-1 focus:ring-accent/50",Gn="text-[12px] text-accent-text underline underline-offset-2",Ze=encodeURIComponent(Oe),pi=1500,mi=5*6e4;function hi(){return e.jsxs("svg",{viewBox:"0 0 40 40",className:"size-10 shrink-0 rounded-[8px]","aria-hidden":"true",children:[e.jsx("rect",{width:"40",height:"40",rx:"10",fill:"#612bd3"}),e.jsx("path",{d:"M14 29V11h7.2c4.1 0 6.8 2.3 6.8 5.9s-2.7 5.9-6.8 5.9h-3.1V29zm4.1-9.7h2.8c1.9 0 3-0.9 3-2.4s-1.1-2.4-3-2.4h-2.8z",fill:"#fff",fillRule:"evenodd"})]})}function fi({refreshKey:t=0,onConnection:s}){const{state:c,dispatch:o}=Xe(),[r,l]=d.useState(null),[y,g]=d.useState(!1),[k,p]=d.useState(!1),[h,A]=d.useState(null),[Q,C]=d.useState(null),[M,_]=d.useState(!1),[K,H]=d.useState(""),[$,L]=d.useState(null),[le,v]=d.useState(!1),[J,Z]=d.useState(""),[he,X]=d.useState(""),[ee,ye]=d.useState(!1),[W,b]=d.useState(null),x=d.useRef(!0),S=d.useRef(null),E=d.useCallback(async()=>{const I=(await w("/api/team/my-connections").catch(()=>null))?.mcp?.find(ce=>ce.name===Oe);return I?{connected:I.connected,how:I.how}:{connected:!1,how:null}},[]),U=d.useCallback(async(R=!1)=>{try{const I=await w(R?`${Ge}/check`:Ge,R?{method:"POST"}:void 0);if(!x.current)return null;if(!ii(I))throw new Error("unexpected Postiz status");return l(I),p(!1),I.team&&I.scope==="person"&&b(await E()),I}catch(I){return x.current&&(I.status===403?g(!0):p(!0)),null}},[E]);d.useEffect(()=>(x.current=!0,U().then(R=>{R?.state==="connected"&&R.scope==="team"&&U(!0)}),()=>{x.current=!1,S.current?.controller.abort(),S.current=null}),[U,t]);const B=r?.team===!0&&r.scope==="person",Y=B?W?.connected===!0:r?.state==="connected";d.useEffect(()=>{s?.(r?Y:null)},[r,Y,s]);const Pe=R=>o({type:"configStatus",config:R}),Me=async()=>{await w("/api/team/connection-scopes",{method:"PUT",body:JSON.stringify({kind:"mcp",id:Oe,scope:"person"})}),await w(`/api/mcp/servers/${Ze}`,{method:"PATCH",body:JSON.stringify({enabled:!0})})},Le=async(R,I)=>{const ce=await w(`/api/team/my-connections/mcp/${Ze}/sign-in`,{method:"POST"}),se=Et(ce.auth.authorizationUrl);if(!se)throw new Error(n("mcp.auth.failed"));C({...ce.auth,flowId:null,pasteBack:!1}),!await I(se)&&x.current&&L(n("connectors.popupBlockedContinue"));const ue=Date.now()+mi;for(;!R.signal.aborted&&Date.now()<ue;)if(await new Promise(Se=>setTimeout(Se,pi)),(await E())?.connected)return;if(!R.signal.aborted)throw new Error(n("postiz.signInExpired"))},we=async()=>{if(h||S.current)return;const R=Rt(),I=new AbortController;S.current={controller:I},A("sign-in"),L(null),H("");const ce=async se=>{const ue=await R.open(se);return R.cancel(),ue};try{if(await w(`${Ge}/sign-in`,{method:"POST"}),ee||B){ee&&!B&&await Me(),await Le(I,ce);return}const se=await ns(Oe,{api:w,signal:I.signal,open:async re=>{!await ce(re)&&x.current&&!I.signal.aborted&&L(n("connectors.popupBlockedContinue"))},onStarted:(re,Se)=>{S.current?.controller===I&&(S.current.complete=Se),x.current&&C(re)}});if(I.signal.aborted||!x.current)return;if(se.phase!=="succeeded"){se.phase!=="cancelled"&&L(se.message||n("mcp.auth.failed"));return}_(!0);const ue=await w(`/api/mcp/servers/${Ze}/test`,{method:"POST",signal:I.signal});if(!ue.ok){const re=(ue.error??"").trim();L(n("postiz.error.testFailed",{reason:re&&!/[.!?]$/u.test(re)?`${re}.`:re}));return}await w(`/api/mcp/servers/${Ze}`,{method:"PATCH",body:JSON.stringify({enabled:!0})})}catch(se){x.current&&!I.signal.aborted&&L(rn(se,lt))}finally{R.cancel(),S.current?.controller===I&&(S.current=null),x.current&&(C(null),_(!1),A(null),await U())}},Re=async()=>{const R=S.current;if(!(!R||!Q?.flowId||!K.trim()))try{R.complete?.(await ss(Oe,Q.flowId,K,w))}catch(I){x.current&&L(I instanceof Error?I.message:String(I))}},Ue=async()=>{const R=Ms(J),I=B||ee?"":he.trim();if(!h){if(!is(R))return L(n("keys.notAKey"));A("key"),L(null);try{if(await w(`${Ge}/key-check`,{method:"POST",body:JSON.stringify({key:R,...I?{address:I}:{}})}),ee||B){await w(`${Ge}/sign-in`,{method:"POST"}),B||await Me();const se=(await w("/api/mcp/servers")).servers?.find(ue=>ue.name===Oe)?.url;await w(`/api/team/my-connections/mcp/${Ze}/key`,{method:"PUT",body:JSON.stringify({value:R,url:se})})}else{const ce=c.config?.postiz?.url??"",se=I&&mt(I)!==mt(lt)?I:"";se!==ce&&Pe(await w("/api/config",{method:"PUT",body:JSON.stringify({postiz:{url:se}})})),Pe(await zt("postiz",R,c.config?.postiz?.configured!==!0))}if(It("postiz","apps","ok"),!x.current)return;Z(""),v(!1)}catch(ce){It("postiz","apps",os(ce)),x.current&&L(ui(ce,I||lt))}finally{x.current&&(A(null),await U())}}},ne=async()=>{if(!(h||!window.confirm(n("postiz.disconnectConfirm")))){A("disconnect"),L(null);try{B?await w(`/api/team/my-connections/mcp/${Ze}`,{method:"DELETE"}):(r?.keySaved&&Pe(await zt("postiz","",!1)),await w(Ge,{method:"DELETE"}))}catch(R){x.current&&L(rn(R,r?.address??lt))}finally{x.current&&(A(null),await U())}}},q=()=>S.current?.controller.abort();if(y)return null;const xe=h==="sign-in",V=!B&&r?.state==="needs-sign-in",ke=!B&&r?.state==="key-refused",$e=r?.state==="blocked"||r?.state==="taken",oe=r?.state==="taken"?n("postiz.taken"):r?.state==="blocked"?r.message??n("postiz.description"):Y?B?n("postiz.connectedOwn"):r?.how==="key"?n("postiz.connectedKey",{host:r.host}):n("postiz.connectedTo",{host:r?.host??""}):V?n("connectors.signedOut"):ke?n("postiz.keyRefused"):n("postiz.description"),je=(Y||V||ke)&&e.jsx(as,{placement:"below",ariaLabel:n("postiz.menu"),triggerClassName:"shrink-0",items:[{key:"disconnect",label:n("connectors.disconnect"),disabled:h!==null,onSelect:()=>{ne()}}],renderTrigger:()=>e.jsx("span",{className:"inline-flex size-7 items-center justify-center rounded-full bg-control/80 text-ink hover:bg-raised-hover",children:h==="disconnect"?e.jsx(ae,{size:14,className:"animate-spin"}):e.jsx(ca,{size:15,"aria-hidden":"true"})})}),Ne=r!==null&&!Y&&!$e;return e.jsxs("div",{"data-app-tile":"postiz","data-postiz-state":r?.state??"loading",className:"flex min-w-0 flex-col rounded-xl px-2 py-2 transition-colors hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hi,{}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold leading-5 text-ink",children:"Postiz"}),Y&&e.jsx(We,{size:13,strokeWidth:2.5,className:"shrink-0 text-success","aria-label":n("apps.connected")})]}),e.jsx("p",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",title:oe,children:oe})]}),xe?e.jsx("button",{type:"button",onClick:q,className:qe,children:n("mcp.auth.cancel")}):r===null?k?e.jsx("button",{type:"button",onClick:()=>{U()},className:qe,children:n("connectors.action.retry")}):e.jsx("button",{type:"button",disabled:!0,className:qe,"aria-label":n("common.checking"),children:e.jsx(ae,{size:14,className:"animate-spin"})}):Y?je:Ne&&!le?e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button","aria-label":n(V||ke?"postiz.reconnect":"postiz.connect"),disabled:h!==null,onClick:()=>ke?(v(!0),L(null)):void we(),className:qe,children:n(V||ke?"connectors.action.reconnect":"connectors.action.connect")}),je]}):null]}),e.jsxs("div",{className:"ps-[52px]",children:[xe&&e.jsxs("div",{role:"status",className:"mt-1.5 flex flex-col gap-1.5 text-[12px] text-ink-secondary",children:[e.jsxs("p",{className:"flex items-center gap-2",children:[e.jsx(ae,{size:12,className:"shrink-0 animate-spin","aria-hidden":"true"}),e.jsx("span",{children:n(M?"postiz.loadingTools":"postiz.finishInBrowser")}),Q?.authorizationUrl&&Et(Q.authorizationUrl)&&e.jsx("button",{type:"button",onClick:()=>{en(Q.authorizationUrl).catch(()=>L(n("mcp.auth.openFailed")))},className:Gn,children:n("mcp.auth.openAgain")})]}),Q?.flowId&&Q.pasteBack&&e.jsxs("form",{"data-postiz-paste":!0,className:"flex flex-col gap-1.5",onSubmit:R=>{R.preventDefault(),Re()},children:[e.jsx("span",{className:"leading-relaxed text-ink",children:n("mcp.auth.pasteBackHint")}),e.jsx("input",{type:"text",value:K,onChange:R=>H(R.target.value),autoComplete:"off",spellCheck:!1,"aria-label":n("mcp.auth.callbackUrl"),placeholder:"http://127.0.0.1:…/mcp-oauth/callback?…",className:Wt}),e.jsx("button",{type:"submit",disabled:!K.trim(),className:qe,children:n("mcp.auth.complete")})]})]}),$&&e.jsx("p",{role:"alert",className:"mt-1.5 text-[12px] text-danger",children:$}),Ne&&!xe&&r.team&&!B&&e.jsxs("label",{"data-postiz-only-me":!0,className:"mt-1.5 flex items-center gap-2 text-[12px] text-ink-secondary",children:[e.jsx("input",{type:"checkbox",checked:ee,onChange:R=>ye(R.target.checked)})," ",n("mcp.team.onlyMe")]}),B&&!Y&&!xe&&e.jsx("p",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:n("postiz.personScope")}),Ne&&!xe&&(le?e.jsxs("form",{"data-postiz-key-form":!0,className:"mt-2 flex flex-col gap-2",onSubmit:R=>{R.preventDefault(),Ue()},children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,"aria-label":n("postiz.keyField"),placeholder:n("keys.postiz.placeholder"),value:J,disabled:h==="key",onChange:R=>{L(null),Z(R.target.value)},className:Wt}),!B&&!ee&&e.jsx("input",{type:"url",autoComplete:"off",spellCheck:!1,"aria-label":n("postiz.addressField"),placeholder:lt,value:he,disabled:h==="key",onChange:R=>{L(null),X(R.target.value)},className:Wt}),e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:n(B||ee?"postiz.keyHelp":"postiz.keyAndAddressHelp")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsx("button",{type:"submit",disabled:h!==null||!J.trim(),className:qe,children:h==="key"?e.jsx(ae,{size:14,className:"animate-spin"}):n("connectors.action.connect")}),e.jsxs("a",{href:ai,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] font-medium text-accent-text hover:underline",children:[n("postiz.keyLink"),e.jsx(pn,{size:11,"aria-hidden":"true"})]}),e.jsx("button",{type:"button",onClick:()=>{v(!1),L(null)},className:"text-[12px] text-ink-secondary underline underline-offset-2 hover:text-ink",children:n("postiz.useSignIn")})]})]}):e.jsx("button",{type:"button",onClick:()=>{v(!0),L(null),X(r.selfHosted?r.address:"")},className:`mt-1.5 inline-block ${Gn}`,children:n("postiz.useKey")}))]})]})}const qn=t=>typeof t=="number"&&Number.isSafeInteger(t)&&t>=0,Zn=t=>typeof t=="string"&&t.length<=40&&!Number.isNaN(Date.parse(t));function xi(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const{calls:s,max:c,usedUp:o,resetsAt:r,trialEndsAt:l}=t;return!qn(s)||!qn(c)||!Zn(r)||l!==void 0&&!Zn(l)?null:{calls:Math.min(s,c),max:c,...o===!0||s>=c?{usedUp:!0}:{},resetsAt:r,...l!==void 0?{trialEndsAt:l}:{}}}function gi(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const s=t;return(s.using==="own"||s.using==="included"||s.using===null)&&typeof s.ownKey=="boolean"&&typeof s.included=="boolean"&&(s.usage===void 0||xi(s.usage)!==null)}const bi="https://treg.to",At="inline-flex h-7 min-w-[64px] shrink-0 items-center justify-center gap-2 rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink transition-colors hover:bg-raised-hover disabled:opacity-40",yi="h-8 w-full min-w-0 rounded-lg bg-inset px-2.5 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none focus:ring-1 focus:ring-accent/50",ki="x twitter treg tweets posts";function ji(){return e.jsxs("svg",{viewBox:"0 0 40 40",className:"size-10 shrink-0 rounded-[8px]","aria-hidden":"true",children:[e.jsx("rect",{width:"40",height:"40",rx:"10",fill:"#000"}),e.jsx("path",{transform:"translate(9 9) scale(0.9167)",fill:"#fff",d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"})]})}const Yt=t=>new Intl.DateTimeFormat(Bt(),{day:"numeric",month:"long",timeZone:"UTC"}).format(new Date(t)),Wn=t=>t.toLocaleString(Bt());function vi(t){const s={used:Wn(t.calls),max:Wn(t.max)};return t.trialEndsAt?t.usedUp?{line:n("apps.x.usedUpTrial",{date:Yt(t.trialEndsAt)}),usedUp:!0}:{line:n("apps.x.usageTrial",s),usedUp:!1}:t.usedUp?{line:n("apps.x.usedUp",{date:Yt(t.resetsAt)}),usedUp:!0}:{line:`${n("apps.x.usage",s)} ${n("apps.x.resets",{date:Yt(t.resetsAt)})}`,usedUp:!1}}function wi({refreshKey:t=0,onConnection:s}){const{state:c,dispatch:o}=Xe(),[r,l]=d.useState(null),[y,g]=d.useState(!1),[k,p]=d.useState(null),[h,A]=d.useState(""),[Q,C]=d.useState(null),[M,_]=d.useState(null),[K,H]=d.useState(!1),$=d.useRef(!0),L=d.useRef(!1),le=ra(ua()?.view??null)==="connecting",v=c.config?.treg?.configured===!0,J=c.config?.xResearch?.included===!0,Z=d.useCallback(async(E=!1)=>{try{const U=await w(`/api/x/status${E?"?refresh=1":""}`);if(!$.current)return;if(!gi(U))throw new Error("unexpected X status");l(U),g(!1)}catch{$.current&&g(!0)}},[]);d.useEffect(()=>($.current=!0,Z(t>0),()=>{$.current=!1}),[Z,t,v,J]),d.useEffect(()=>{s?.(r?r.using!==null:null)},[r,s]);const he=E=>(o({type:"configStatus",config:E}),Z(!0)),X=async()=>{p("test"),_(null);try{const E=await w("/api/keys/test",{method:"POST",body:JSON.stringify({provider:"treg"})});return $.current&&_(Ls(E)),Rn(E)}catch(E){return $.current&&_(E instanceof Error?E.message:String(E)),Rn(null)}finally{$.current&&p(null)}},ee=async()=>{const E=h.trim();if(!(k||!E)){if(!is(E))return C(n("keys.notAKey"));p("save"),C(null),_(null);try{if(await he(await zt("treg",E,!v)),!$.current)return;A(""),H(!1),It("treg","apps",await X())}catch(U){$.current&&C(U instanceof Error?U.message:String(U)),It("treg","apps",os(U))}finally{$.current&&p(U=>U==="save"?null:U)}}},ye=async()=>{if(!k){p("remove"),C(null),_(null);try{await he(await zt("treg","",!1)),Us("treg","apps")}catch(E){$.current&&C(E instanceof Error?E.message:String(E))}finally{$.current&&p(null)}}};d.useEffect(()=>{L.current&&(L.current=!1,ee())});const W=r?.using??null,b=r?.usage?vi(r.usage):null,x=r!==null&&W!=="own"&&(W===null||K||b?.usedUp===!0),S=r===null?n("apps.x.description"):W==="own"?n("apps.x.own"):W==="included"?n("apps.x.included"):le&&!r.unavailable?n("apps.x.connecting"):n("apps.x.addKey");return e.jsxs("div",{"data-app-tile":"x","data-x-state":r===null?"loading":W??"none",className:"flex min-w-0 flex-col rounded-xl px-2 py-2 transition-colors hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ji,{}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold leading-5 text-ink",children:n("apps.x.title")}),W!==null&&e.jsx(We,{size:13,strokeWidth:2.5,className:"shrink-0 text-success","aria-label":n("apps.connected")})]}),e.jsx("p",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",title:S,children:S})]}),r===null?y?e.jsx("button",{type:"button",onClick:()=>{Z(!0)},className:At,children:n("connectors.action.retry")}):e.jsx("button",{type:"button",disabled:!0,className:At,"aria-label":n("common.checking"),children:e.jsx(ae,{size:14,className:"animate-spin"})}):W==="own"?e.jsx("button",{type:"button",disabled:k!==null,onClick:()=>{X()},className:At,children:k==="test"?e.jsx(ae,{size:14,className:"animate-spin"}):n("keys.test")}):null]}),e.jsxs("div",{className:"ps-[52px]",children:[W==="own"&&e.jsx("p",{className:"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:r?.included?n("apps.x.ownFirst"):n("apps.x.ownBilled")}),W==="included"&&b&&e.jsx("p",{"data-x-usage":!0,className:b.usedUp?"mt-1 text-[12px] leading-relaxed text-warning":"mt-1 text-[12px] leading-relaxed text-ink-secondary",children:b.line}),W==="own"&&e.jsxs("button",{type:"button",disabled:k!==null,onClick:()=>{ye()},className:"mt-1.5 inline-flex items-center gap-1.5 text-[12px] text-danger underline underline-offset-2 disabled:opacity-50",children:[k==="remove"&&e.jsx(ae,{size:12,className:"animate-spin","aria-hidden":"true"}),n("apps.x.remove")]}),W==="included"&&!x&&e.jsx("button",{type:"button",onClick:()=>{H(!0),C(null)},className:"mt-1.5 inline-block text-[12px] text-accent-text underline underline-offset-2",children:n("apps.x.useOwnKey")}),x&&e.jsxs("form",{"data-x-key-form":!0,className:"mt-2 flex flex-col gap-2",onSubmit:E=>{E.preventDefault(),ee()},children:[W===null&&e.jsx("p",{className:"text-[12px] leading-relaxed text-ink-secondary",children:n("apps.x.addKeyHelp")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"password",autoComplete:"off",spellCheck:!1,"aria-label":n("keys.treg.label"),placeholder:n("keys.treg.placeholder"),value:h,disabled:k==="save",onChange:E=>{C(null),A(E.target.value)},onPaste:()=>{L.current=!0},className:yi}),e.jsx("button",{type:"submit",disabled:k!==null||!h.trim(),className:At,children:k==="save"?e.jsx(ae,{size:14,className:"animate-spin"}):n("common.save")})]}),e.jsxs("a",{href:bi,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-[12px] font-medium text-accent-text hover:underline",children:[n("keys.treg.link"),e.jsx(pn,{size:11,"aria-hidden":"true"})]})]}),M&&e.jsx("p",{role:"status",className:"mt-1.5 text-[12px] text-ink-secondary",children:M}),Q&&e.jsx("p",{role:"alert",className:"mt-1.5 text-[12px] text-danger",children:Q})]})]})}function ln(t,s,c,o){const r={...t};for(const[l,y]of Object.entries(s))(c.get(l)??0)===(o.get(l)??0)&&(r[l]=y);return r}function Ni(t,s,c,o,r=!0){const l={...t};if(!r)return ln(l,s,c,o);for(const[y,g]of Object.entries(t))s[y]||!g.connected&&!g.accounts?.length||(c.get(y)??0)===(o.get(y)??0)&&(l[y]={connected:!1,pending:!1,status:"not_connected",accounts:[]});return ln(l,s,c,o)}function Ai(t,s,c){return Object.fromEntries(Object.entries(t).filter(([o])=>(s.get(o)??0)===(c.get(o)??0)))}async function Ci(t=window.ogb){if(!t?.credentialStore||t.remoteClient?.active===!0)return!1;try{return await t.credentialStore.unreadable()===!0}catch{return!1}}let dt=null;function Yn({notice:t=!1}){const[s,c]=d.useState(!1),[o,r]=d.useState(()=>dt!==null);if(d.useEffect(()=>{let g=!0;return Ci().then(k=>{g&&c(k)}),dt?.finally(()=>{g&&r(!1)}),()=>{g=!1}},[]),!s)return null;const l=()=>{if(dt)return;r(!0),dt=Promise.resolve(window.ogb?.credentialStore?.reset()).then(()=>{},()=>{}).finally(()=>{dt=null,r(!1)})},y=e.jsx("button",{type:"button",onClick:l,disabled:o,className:"ms-2 font-medium underline underline-offset-2 hover:opacity-80 disabled:opacity-60",children:n("connectors.resetSavedKeys")});return t?e.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-xl bg-warning/10 px-3 py-2 text-[13px] text-warning",children:[e.jsx(cs,{size:14,className:"mt-px shrink-0"}),e.jsxs("span",{children:[n("connectors.savedKeysUnreadable"),y]})]}):y}function Ct({id:t,title:s,note:c,viewAll:o,after:r,children:l}){return e.jsxs("section",{"aria-labelledby":t,"data-apps-section":t,children:[e.jsxs("div",{className:"mb-1.5 flex min-h-7 items-center justify-between gap-3 px-2",children:[e.jsxs("h3",{id:t,className:"min-w-0 truncate text-[14px] font-semibold leading-5 text-ink",children:[s,c&&e.jsx("span",{className:"ms-2 text-[12px] font-normal text-ink-secondary",children:c})]}),o&&e.jsx("button",{type:"button",onClick:o.onClick,className:"shrink-0 rounded-full px-2 text-[13px] font-medium leading-5 text-ink-secondary transition-colors hover:text-ink",children:o.label})]}),e.jsx("div",{className:"grid grid-cols-1 items-start gap-x-6 gap-y-1 @xl:grid-cols-2",children:l}),r]})}function Si(t,s){const c=s.alias?`“${s.alias}” (${s.id})`:`“${s.id}”`;return n("connectors.disconnectConfirm",{identity:c,service:t})}function Ri(t,s,c){return t.filter(o=>{if(o.hidden||o.composio===!1||!s.find(y=>y.instanceId===o.modelSelection.instanceId)?.capabilities?.composioMcp)return!1;const r=o.connectorTools;if(!r||typeof r!="object"||Array.isArray(r))return!1;const l=r[c];return l===void 0?!0:!ta(l)||l.tools!=="*"})}function Ei(t,s,c,o){return(!s||`${t.label} ${t.keywords} ${n(t.description)}`.toLowerCase().includes(s.toLowerCase().trim()))&&(c==="all"||c==="connected"&&o?.[t.id]!==!1)}function zi(t){return t.configured||t.stale?null:t.setup==="needs-setup"?{key:t.remoteClient?"connectors.setupNeededRemote":"connectors.setupNeeded",tone:"info"}:{key:"connectors.notConfigured",tone:"warning"}}const Xn=48,Ii=16;function Ti(t,s,c){return Ws(t,s).filter(o=>Ys(o,c)!==null)}function Ki(){const{state:t,dispatch:s}=Xe(),c=window.ogb?.remoteClient?.active===!0,o=d.useRef(null),r=t.pluginsSurface,[l,y]=d.useState(null),[g,k]=d.useState("curated"),[p,h]=d.useState(null),[A,Q]=d.useState(!1),[C,M]=d.useState("unavailable"),[_,K]=d.useState(void 0),[H,$]=d.useState(()=>Nt()?.services??$s()?.services??{}),[L,le]=d.useState(Nt()?.authoritative===!1),[v,J]=d.useState({}),[Z,he]=d.useState(null),[X,ee]=d.useState(""),[ye,W]=d.useState(null),[b,x]=d.useState(!1),[S,E]=d.useState(Nt()===null?"loading":"ready"),[U,B]=d.useState(null),[Y,Pe]=d.useState(""),[Me,Le]=d.useState("marketplace"),[we,Re]=d.useState(!1),[Ue,ne]=d.useState(null),[q,xe]=d.useState(0),[V,ke]=d.useState(null),[$e,oe]=d.useState(null),[je,Ne]=d.useState(null),[R,I]=d.useState(null),[ce,se]=d.useState([]),ue=d.useRef(new Map),re=d.useRef(new Map),Se=d.useRef(new Map),fe=d.useRef(null),Ee=d.useRef(new Set),et=(i,j)=>{const O=Object.entries(i).filter(([z,F])=>(re.current.get(z)??0)===(j.get(z)??0)&&(F.connected&&!F.pending||/^(expired|failed)$/i.test(F.status??""))).map(([z])=>z);O.length&&J(z=>O.some(F=>z[F])?Object.fromEntries(Object.entries(z).filter(([F])=>!O.includes(F))):z)},tt=d.useCallback(i=>{if(!i.length)return Promise.resolve({});const j=new Map(i.map(z=>[z,re.current.get(z)??0])),O=new Map(i.map(z=>{const F=(Se.current.get(z)??0)+1;return Se.current.set(z,F),[z,F]}));return w(`/api/connectors?services=${i.join(",")}`).then(z=>{const F=Ai(z.services??{},Se.current,O);return $(D=>ln(D,F,re.current,j)),et(F,j),F}).catch(()=>({}))},[]),ft=d.useCallback((i=!1)=>{const j=new Map(re.current);return x(!0),Fs(i).then(({services:O,authoritative:z,refused:F})=>(le(!z),F&&B({key:"connectors.adminOnly"}),$(D=>Ni(D,O,re.current,j,z)),et(O,j),O)).finally(()=>x(!1))},[]),Fe=d.useCallback((i=!1)=>{const j=Nt()!==null;return j||E("loading"),B(null),ft(i).then(O=>(E("ready"),O)).catch(O=>(j||E("error"),B(O instanceof Error?O.message:String(O)),{}))},[ft]);d.useEffect(()=>()=>{fe.current?.cancel(),fe.current=null;for(const i of ue.current.values())i();ue.current.clear()},[]);const be=Ks({status:H,emailConnected:R,inventoryReady:S==="ready"&&!L});d.useEffect(()=>{S==="ready"&&aa(H,!L)},[S,L,H]),d.useEffect(()=>{let i=!0;return Fe(),w("/api/connectors/catalog").then(j=>{i&&(y(j.cards??[]),k(j.source??"curated"),h(j.pagination??null),Q(!!j.configured),M(j.mode??"unavailable"),K(j.setup))}).catch(j=>{i&&(y(O=>O??[]),B(Ds(j)?{key:"connectors.adminOnly"}:j.message))}),()=>{i=!1}},[Fe]),d.useEffect(()=>{const i=document.activeElement instanceof HTMLElement?document.activeElement:null,j=o.current,O=()=>Array.from(j?.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])')??[]).filter(D=>D.getClientRects().length>0),z=O();(z.find(D=>D.matches("input"))??z[0]??j)?.focus();const F=D=>{if(D.key==="Escape"){D.preventDefault(),s({type:"togglePlugins",open:!1});return}if(D.key!=="Tab"||!j)return;const de=O();if(de.length===0){D.preventDefault(),j.focus();return}const ve=de[0],Ae=de.at(-1);de.some(ge=>ge===document.activeElement)?D.shiftKey&&document.activeElement===ve?(D.preventDefault(),Ae.focus()):!D.shiftKey&&document.activeElement===Ae&&(D.preventDefault(),ve.focus()):(D.preventDefault(),(D.shiftKey?Ae:ve).focus())};return window.addEventListener("keydown",F),()=>{window.removeEventListener("keydown",F),i?.focus()}},[s]);const{suggestions:Ke,picking:xt,pick:nt}=Qs(l!==null&&A&&S==="ready",`${q}:${Object.keys(H).filter(i=>H[i]?.connected).sort().join()}`),Pt=async i=>{if(fe.current)return;const j=Rt();fe.current=j;try{!await j.open(i)&&fe.current===j&&B({key:"connectors.popupBlockedContinue"})}finally{j.cancel(),fe.current===j&&(fe.current=null)}},Mt=(i,j,O)=>{ue.current.get(i)?.();const z=na(j,()=>tt([i]).then(F=>F[i]),F=>{ue.current.get(i)===z&&ue.current.delete(i),sa(i,F),F==="connected"&&O&&be.appConnected(i,l?.find(D=>D.slug===i)?.label??i)});ue.current.set(i,z)},ze=async(i,j,O)=>{if(ye||fe.current)return;const z=Rt();fe.current=z,re.current.set(i,(re.current.get(i)??0)+1),W(i),B(null),O&&Ee.current.add(i);const F=!Ee.current.has(i)&&!ct(H[i]);try{const D=Date.now();O&&await w(`/api/connectors/${i}/accounts/${encodeURIComponent(O.id)}`,{method:"DELETE"});const de={method:"POST"};j&&(de.body=JSON.stringify({alias:j}));const ve=await w(`/api/connectors/${i}/authorize`,de);if(fe.current!==z)return;const Ae=Et(typeof ve.url=="string"?ve.url:null);if(!Ae)throw new Error(n("connectors.invalidAuthorizationUrl"));J(ge=>({...ge,[i]:{url:Ae,createdAt:D}})),$(ge=>({...ge,[i]:{...ge[i],connected:ge[i]?.connected??!1,pending:!0,status:"INITIATED"}})),he(null),ee(""),Mt(i,H[i],F),!await z.open(Ae)&&fe.current===z&&B({key:"connectors.popupBlockedContinue"})}catch(D){if(fe.current!==z)return;const de=D instanceof Error?D.message:String(D);Xs(de)?(he(i),ee(""),B({key:"connectors.aliasNeeded"}),tt([i])):B(ea(de)?{key:"connectors.aliasTaken"}:de)}finally{z.cancel(),fe.current===z&&(fe.current=null,W(null))}},a=(i,j)=>{W(i),w(`/api/connectors/${i}/accounts/${encodeURIComponent(j)}`,{method:"DELETE"}).then(()=>tt([i])).catch(O=>B(O.message)).finally(()=>W(null))},u=(l??[]).filter(i=>(!Tn(C,i.slug)||ct(H[i.slug]))&&En(`${i.label} ${i.slug} ${On(i)} ${(i.categories??[]).join(" ")}`,Y)),f=i=>!!(H[i]?.connected||H[i]?.accounts?.length),m=r==="mcp"?"mcp":Me==="connected"?"connected":"all",P=Y.trim().length>0,N=P&&m==="connected"?"all":m,te=new Set(pt.filter(i=>Ei(i,Y,N,Ue)).map(i=>i.id)),ie=(!Y||`email mail imap smtp mailbox ${n("email.description")}`.toLowerCase().includes(Y.toLowerCase().trim()))&&(N==="all"||N==="connected"&&R!==!1),De=(!Y||`${ki} ${n("apps.x.description")}`.toLowerCase().includes(Y.toLowerCase().trim()))&&(N==="all"||N==="connected"&&$e!==!1),Lt=(!Y||`${di} ${n("postiz.description")}`.toLowerCase().includes(Y.toLowerCase().trim()))&&(N==="all"||N==="connected"&&je!==!1),Ut=(N==="connected"?u.filter(i=>f(i.slug)):u).map((i,j)=>({card:i,index:j})).sort((i,j)=>Number(f(j.card.slug))-Number(f(i.card.slug))||i.index-j.index).map(({card:i})=>i),$t=pt.filter(i=>Ue?.[i.id]),bn=ce.filter(i=>cn(i)),yn=i=>En(`${i.name} ${pe(i)?i.url:[i.command,...i.args].join(" ")}`,Y),kn=Object.values(H).filter(ct).length+$t.length+bn.filter(fs).length+ +(R===!0)+ +($e===!0)+ +(je===!0),jn=Hs(S),st=()=>s({type:"togglePlugins",open:!1}),gt=zi({configured:A,stale:L,setup:_,remoteClient:c}),at=i=>{if(ke(null),i==="mcp"){s({type:"togglePlugins",open:!0,surface:"mcp"});return}Le(i==="connected"?"connected":"marketplace"),r!=="apps"&&s({type:"togglePlugins",open:!0,surface:"apps"})},Ft=ka([...l??[],Zt],void 0,Zt.categories),Kt=Ft.more,Dt=V!==null&&Kt.includes(V),Qe=m==="all"&&V!==null&&!P,vn=Lt&&(!Qe||nn(Zt,V)),gs=!Qe&&(te.size>0||ie||De)||vn||m==="connected"&&bn.some(i=>i.enabled&&yn(i)),bs=Qe?Ut.filter(i=>nn(i,V)):Ut,bt=m==="all"&&!P&&V===null,it=bt?ja(Ut,f,Ft.inline):[],ys=it.find(i=>i.kind==="all"),yt=bt?ys?.cards??[]:bs,Qt=bt&&!we&&yt.length>Xn,wn=Qt?yt.slice(0,Xn):yt,Nn=(l??[]).filter(i=>ct(H[i.slug])),Ht=i=>{ke(i),Le("marketplace"),r!=="apps"&&s({type:"togglePlugins",open:!0,surface:"apps"})},ks=P?n("connectors.section.results"):m==="connected"?n("connectors.section.yours"):V?rt(V):it.length>1?n("apps.section.all"):n("connectors.section.available"),He="inline-flex h-7 shrink-0 items-center justify-center gap-2 rounded-full px-3 text-[13px] font-medium leading-5 transition-colors",_t=i=>i?"bg-ink text-app":"bg-control/70 text-ink-secondary hover:bg-raised-hover hover:text-ink";return e.jsxs("div",{className:"glass-popup-frame",style:Vs(),onMouseDown:i=>i.stopPropagation(),children:[e.jsx("div",{"aria-hidden":"true",className:"glass-scrim pointer-events-none absolute inset-0"}),e.jsxs("div",{ref:o,"data-tour":"apps-panel",role:"dialog","data-look":"dialog","aria-modal":"true","aria-labelledby":"plugins-title",tabIndex:-1,className:"glass-surface glass-popup animate-pop-in relative flex max-w-[780px] flex-col overflow-hidden rounded-2xl",children:[e.jsxs("header",{className:"flex flex-col gap-4 px-5 pb-4 pt-5 sm:px-7 sm:pt-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h2",{id:"plugins-title",className:"min-w-0 truncate text-[20px] font-semibold leading-7 tracking-[-0.01em] text-ink",children:n("apps.title")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsxs("button",{type:"button","data-apps-filter":"connected","aria-pressed":m==="connected",onClick:()=>at(m==="connected"?"all":"connected"),className:G("inline-flex h-8 items-center gap-2 rounded-full ps-1.5 pe-2 text-[13px] font-medium leading-5 transition-colors",m==="connected"?"bg-raised text-ink":"text-ink-secondary hover:bg-raised/60 hover:text-ink"),children:[Nn.length>0&&e.jsx("span",{"aria-hidden":"true",className:"flex -space-x-1.5 rtl:space-x-reverse",children:Nn.slice(0,4).map(i=>e.jsx("span",{className:"flex size-5 items-center justify-center overflow-hidden rounded-md bg-menu ring-2 ring-menu",children:e.jsx(zn,{card:i,className:"size-5 rounded-md"})},i.slug))}),e.jsx("span",{className:"whitespace-nowrap",children:kn>0?n("apps.connectedCount",{count:kn}):n("apps.filter.connected")}),e.jsx(ls,{size:14,"aria-hidden":"true",className:"shrink-0 rtl:-scale-x-100"})]}),e.jsx("button",{onClick:()=>{xe(i=>i+1),Fe(!0)},disabled:b,className:"flex size-8 items-center justify-center rounded-full text-ink-secondary hover:bg-raised hover:text-ink disabled:opacity-50",title:n("connectors.refreshTitle"),"aria-label":n("connectors.refreshTitle"),children:e.jsx(tn,{size:16,className:G(b&&"animate-spin")})}),e.jsx("button",{"data-tour":"apps-close",onClick:st,"aria-label":n("connectors.closeAria"),className:"flex size-8 items-center justify-center rounded-full text-ink-secondary hover:bg-raised hover:text-ink",children:e.jsx(es,{size:18})})]})]}),e.jsx("p",{className:"mt-0.5 text-[13px] leading-5 text-ink-secondary",children:n("apps.subtitle")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex h-9 min-w-0 flex-1 items-center gap-2.5 rounded-full bg-control/70 px-3.5 focus-within:ring-1 focus-within:ring-accent",children:[e.jsx(ws,{size:15,className:"shrink-0 text-ink-secondary"}),e.jsx("input",{value:Y,onChange:i=>Pe(i.target.value),placeholder:n("connectors.searchPlaceholder"),"aria-label":n("connectors.searchPlaceholder"),className:"min-w-0 flex-1 bg-transparent text-[14px] text-ink placeholder:text-ink-secondary focus:outline-none"})]}),e.jsxs("button",{type:"button","data-apps-filter":"mcp","aria-pressed":m==="mcp",onClick:()=>at(m==="mcp"?"all":"mcp"),className:G(He,"h-9 border border-hairline/40 px-3.5",m==="mcp"?"bg-ink text-app":"text-ink hover:bg-raised"),children:[e.jsx(la,{size:14,"aria-hidden":"true"}),e.jsx("span",{className:"hidden sm:inline",children:n("apps.filter.mcp")}),e.jsx("span",{className:"sr-only sm:hidden",children:n("apps.filter.mcp")})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":n("apps.categoriesAria"),children:[e.jsx("button",{type:"button","data-apps-filter":"all","aria-pressed":m==="all"&&V===null,onClick:()=>{at("all"),ke(null)},className:G(He,_t(m==="all"&&V===null)),children:n("apps.filter.all")}),Ft.inline.map(i=>e.jsx("button",{type:"button","data-apps-category":i,"aria-pressed":m==="all"&&V===i,onClick:()=>Ht(V===i?null:i),className:G(He,_t(m==="all"&&V===i)),children:rt(i)},i)),Kt.length>0&&e.jsx(as,{ariaLabel:n("apps.moreCategories"),items:Kt.map(i=>({key:i,label:rt(i),active:V===i,onSelect:()=>Ht(i)})),renderTrigger:({open:i})=>e.jsxs("span",{className:G(He,_t(m==="all"&&Dt),i&&!Dt&&"bg-raised-hover text-ink"),children:[Dt?rt(V):n("apps.more"),e.jsx(ts,{size:14,"aria-hidden":"true"})]})})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 pb-7 sm:px-7",children:[L?e.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-xl bg-warning/10 px-3 py-2 text-[13px] text-warning",children:[e.jsx(cs,{size:14,className:"mt-px shrink-0"}),e.jsxs("span",{children:[n("connectors.stale"),e.jsx(Yn,{})]})]}):e.jsx(Yn,{notice:!0}),gt&&m!=="mcp"&&e.jsxs("div",{className:G("mb-3 rounded-xl px-4 py-3 text-[13px]",gt.tone==="warning"?"bg-warning/10 text-warning":"bg-control/50 text-ink-secondary"),children:[$t.length>0?n("hostedMcp.otherAppsSetup",{services:new Intl.ListFormat(Bt(),{style:"long",type:"conjunction"}).format($t.map(i=>i.label))}):n(gt.key)," ",e.jsx("button",{className:G("font-medium underline underline-offset-2",gt.tone==="info"&&"text-ink",c&&"hidden"),onClick:()=>{st(),s(In("composio"))},children:n("connectors.openSettings")})]}),A&&!c&&g==="curated"&&C==="self-hosted"&&m!=="mcp"&&e.jsxs("div",{className:"mb-3 text-[12px] text-ink-secondary",children:[n("connectors.featuredBefore")," ",e.jsx("button",{className:"underline underline-offset-2 hover:text-ink",onClick:()=>{st(),s({type:"toggleAppSettings",open:!0})},children:n("connectors.updateKey")})," ",n("connectors.featuredAfter")]}),U&&e.jsx("div",{role:"alert",className:"mb-3 rounded-xl bg-danger/10 px-3 py-2 text-[12px] text-danger",children:typeof U=="string"?U:n(U.key)}),m!=="mcp"&&e.jsxs("div",{"data-apps-grid":!0,className:"@container flex flex-col gap-7 pt-1",children:[!it.some(i=>i.kind==="connected")&&An(),it.filter(i=>i.kind!=="all").map(i=>i.kind==="connected"?e.jsxs(d.Fragment,{children:[e.jsx(Ct,{id:"apps-section-connected",title:n("apps.section.connected"),viewAll:i.cards.length>Tt?{label:n("apps.viewAll"),onClick:()=>at("connected")}:void 0,children:i.cards.slice(0,Tt).map(j=>kt(j))}),An()]},"connected"):e.jsx(Ct,{id:`apps-section-${i.category}`,title:rt(i.category),viewAll:i.more?{label:n("apps.viewAll"),onClick:()=>Ht(i.category)}:void 0,children:i.cards.map(j=>kt(j))},i.category)),e.jsxs(Ct,{id:"apps-grid-title",title:ks,note:m==="all"&&!Y&&V===null&&p&&(p.stalled||p.totalItems!==void 0&&p.items<p.totalItems)?`${p.totalItems!==void 0&&p.items<p.totalItems?n("connectors.marketplace.partialCount",{shown:p.items.toLocaleString(Jt()),total:p.totalItems.toLocaleString(Jt())}):n("connectors.marketplace.partialStalled")}${p.reason?` — ${n("connectors.marketplace.partialReason",{reason:p.reason})}`:""}`:void 0,viewAll:Qt?{label:n("apps.viewAll"),onClick:()=>Re(!0)}:void 0,after:e.jsxs(e.Fragment,{children:[l===null&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-24 text-[13px] text-ink-secondary",children:[e.jsx(ae,{size:14,className:"animate-spin"})," ",n("connectors.loadingCatalog")]}),Qt&&e.jsx("div",{className:"mt-4 flex justify-center",children:e.jsx("button",{type:"button",onClick:()=>Re(!0),className:G(He,"bg-control/70 px-4 text-ink hover:bg-raised-hover"),children:n("apps.showAll",{count:yt.length.toLocaleString(Jt())})})}),l!==null&&wn.length===0&&!gs&&it.length<=1&&e.jsxs("div",{className:"flex min-h-40 flex-col items-center justify-center text-center",children:[e.jsx("div",{className:"text-[14px] font-medium text-ink",children:N==="connected"?jn.title:n("connectors.noAppsFound")}),e.jsx("div",{className:"mt-1 text-[13px] text-ink-secondary",children:N==="connected"?jn.description:n("connectors.tryDifferentSearch")}),m==="connected"&&S==="error"&&e.jsxs("button",{type:"button",disabled:b,onClick:()=>{Fe(!0)},className:G(He,"mt-4 bg-raised text-ink hover:bg-raised-hover disabled:opacity-50"),children:[e.jsx(tn,{size:14,className:G(b&&"animate-spin")}),n("connectors.action.retry")]})]})]}),children:[e.jsx(Vn,{hostedCards:{shown:i=>!Qe&&te.has(i),onConnections:ne,onServers:se,...m==="connected"?{ownServers:{shown:yn,manage:()=>at("mcp")}}:{}},refreshKey:q}),e.jsx("div",{"data-native-card":"x",className:De&&!Qe?"contents":"hidden",children:e.jsx(wi,{refreshKey:q,onConnection:oe})}),e.jsx("div",{"data-native-card":"email",className:ie&&!Qe?"contents":"hidden",children:e.jsx(_s,{refreshKey:q,onConnection:I})}),e.jsx("div",{"data-native-card":"postiz",className:vn?"contents":"hidden",children:e.jsx(fi,{refreshKey:q,onConnection:Ne})}),wn.map(i=>kt(i))]})]}),m!=="connected"&&V===null&&e.jsx("div",{className:G(m==="all"&&"mt-8 border-t border-hairline/30 pt-6",m==="mcp"&&"pt-1"),children:e.jsx(Vn,{embedded:!0,hideHosted:m==="all"})})]}),be.changing&&e.jsx(Js,{app:l?.find(i=>i.slug===be.changing)?.label??be.changing,slug:be.changing,bots:be.bots,onDone:be.done,onDismiss:be.dismiss},be.changing)]})]});function An(){const i=Ke.cards.filter(O=>!f(O.slug));if(!bt||i.length===0)return null;const j=Ke.pick==="available"?{label:n(xt?"apps.suggested.picking":"apps.suggested.show"),onClick:nt}:Ke.pick==="needs-key"&&!c?{label:n("apps.suggested.addKey"),onClick:()=>{st(),s(In("jev"))}}:void 0;return e.jsx(Ct,{id:"apps-section-suggested",title:n("apps.section.suggested"),note:Ke.pick==="picked"?n("apps.suggested.picked"):void 0,viewAll:j,children:i.map(O=>kt(O))})}function kt(i){const j=H[i.slug],O=j?.status&&/^(expired|failed)$/i.test(j.status),z=j?.pending&&!O,F=z&&!O?v[i.slug]:void 0,D=Vt(F),de=j?.accounts??[],ve=i.noAuth===!0||j?.connected===!0&&!de.length&&!z&&!O,Ae=ct(j),ge=z?void 0:Gs(j),js=Z===i.slug&&!ve,_e=ye===i.slug,jt=t.config?.managedPolicy,vt=jt?.apps&&!jt.apps.allowAll&&!jt.apps.allowlist.includes(i.slug)?n("policy.managedBy",{organization:jt.organizationName}):Tn(C,i.slug)?n("connectors.selfHostOnlyReason"):null,ot=Ae||ve?Ti(t.bots,t.instances,i.slug):[],wt=n("apps.usedBy",{names:ot.map(T=>T.name).join(", ")}),Cn=vt??(z?D?n("connectors.finishSetup"):n("connectors.finishSetupOrDisconnect"):ge?n("connectors.signedOut"):O&&!de.length?n("connectors.authExpired"):On(i));return e.jsxs("div",{"data-app-tile":i.slug,className:"flex min-w-0 flex-col rounded-xl px-2 py-2 transition-colors hover:bg-raised/40",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(zn,{card:i,className:"size-10 shrink-0 rounded-[8px]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[14px] font-semibold leading-5 text-ink",children:i.label}),Ae&&!z&&e.jsx(We,{size:13,strokeWidth:2.5,className:"shrink-0 text-success","aria-label":n("apps.connected")}),ot.length>0&&e.jsx("span",{className:"ms-1 flex shrink-0 -space-x-1.5 rtl:space-x-reverse",title:wt,"aria-label":wt,role:"img",children:ot.slice(0,3).map(T=>e.jsx("span",{"data-used-by-avatar":T.id,className:"flex size-5 shrink-0 items-center justify-center overflow-hidden rounded-full bg-menu ring-2 ring-menu",children:e.jsx(da,{bot:T,size:Ii,animated:!1})},T.id))})]}),e.jsx("div",{className:"truncate text-[13px] leading-[18px] text-ink-secondary",title:Cn,children:Cn})]}),e.jsx("button",{type:"button",disabled:!A||S!=="ready"||_e||ve||!!vt,title:vt??void 0,onClick:()=>{if(z&&!O){const T=Vt(F);T?(B(null),Pt(T).catch(Ie=>B(Ie.message))):ze(i.slug)}else ge?ze(i.slug,ge.alias,ge):(he(T=>T===i.slug?null:i.slug),ee(""))},className:"inline-flex h-7 min-w-[64px] shrink-0 items-center justify-center gap-2 rounded-full bg-control/80 px-3 text-[13px] font-medium leading-5 text-ink transition-colors hover:bg-raised-hover disabled:opacity-40",children:vt?n("connectors.selfHostOnly"):_e?e.jsx(ae,{size:14,className:"animate-spin"}):qs(S,{busy:_e,included:ve,canContinue:!!F,pending:z,reconnect:!!ge,hasAccounts:de.length>0,failed:!!O})})]}),e.jsxs("div",{className:"ps-[52px]",children:[D&&e.jsx("a",{href:D,target:"_blank",rel:"noopener noreferrer",onClick:T=>{Vt(F)||(T.preventDefault(),ze(i.slug))},className:"mt-1.5 inline-block text-[12px] text-accent-text underline underline-offset-2",children:n("connectors.openAuthorizationPage")}),Ae&&!z&&e.jsxs("div",{"data-app-bots":i.slug,className:"mt-1.5 flex min-w-0 items-center gap-2 text-[12px] leading-5 text-ink-secondary",children:[e.jsx("span",{className:"min-w-0 truncate",title:ot.length?wt:void 0,children:ot.length?wt:n("apps.usedByNone")}),be.canChange&&e.jsx("button",{type:"button",onClick:()=>be.change(i.slug),"aria-label":n("apps.whichBots",{app:i.label}),className:"ms-auto shrink-0 rounded-full px-2 text-[12px] font-medium leading-5 text-accent-text transition-colors hover:bg-raised-hover",children:n("apps.usedByChange")})]}),de.length>0&&e.jsx("div",{className:"mt-1.5 space-y-0.5",children:de.map(T=>{const Ie=/^active$/i.test(T.status),Je=Zs(T)&&T.id!==ge?.id;return e.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-[12px] leading-5",children:[Ie?e.jsx(We,{size:12,className:"shrink-0 text-success"}):e.jsx("span",{className:"size-3 shrink-0"}),e.jsxs("span",{className:"min-w-0 truncate text-ink",title:`${T.alias?`${T.id} · `:""}${T.status.toLowerCase()}`,children:[T.alias||T.id,e.jsxs("span",{className:"text-ink-secondary",children:[" · ",T.status.toLowerCase()]})]}),Je&&e.jsx("button",{type:"button",disabled:_e,onClick:()=>{ze(i.slug,T.alias,T)},className:"ms-auto shrink-0 rounded-full px-2 text-[12px] font-medium leading-5 text-accent-text transition-colors hover:bg-raised-hover disabled:opacity-40","aria-label":n("connectors.reconnectAria",{account:T.alias||T.id,service:i.label}),children:n("connectors.action.reconnect")}),e.jsx("button",{type:"button",disabled:_e,onClick:()=>{window.confirm(Si(i.label,T))&&a(i.slug,T.id)},className:G("shrink-0 rounded-full px-2 text-[12px] font-medium leading-5 text-ink-secondary transition-colors hover:bg-danger/10 hover:text-danger disabled:opacity-40",!Je&&"ms-auto"),"aria-label":n("connectors.disconnectAria",{account:T.alias||T.id,service:i.label}),children:n("connectors.disconnect")})]},T.id)})}),(j?.connected||ve)&&(()=>{const T=Ri(t.bots,t.instances,i.slug);if(!T.length)return null;const Ie=T.slice(0,4).map((Je,vs)=>e.jsxs("span",{children:[vs>0&&", ",e.jsx("button",{type:"button",onClick:()=>{st(),Xt(s,"access",{botId:Je.id,page:"apps"})},className:"font-medium text-ink underline underline-offset-2 hover:text-accent-text",children:Je.name})]},Je.id));return e.jsxs("div",{className:"mt-1.5 text-[12px] leading-relaxed text-ink-secondary",children:[e.jsx("span",{children:n("connectors.grants.limited",{count:T.length})})," ",Ie,T.length>4&&e.jsx("span",{children:n("connectors.grants.more",{count:T.length-4})})]})})(),js&&e.jsxs("form",{className:"mt-2 flex items-center gap-2",onSubmit:T=>{T.preventDefault();const Ie=X.trim();if(!Ie){B({key:"connectors.aliasRequired"});return}ze(i.slug,Ie)},children:[e.jsx("input",{autoFocus:!0,value:X,maxLength:64,onChange:T=>ee(T.target.value),placeholder:n("connectors.aliasPlaceholder"),"aria-label":de.length>0?n("connectors.aliasAriaAnother",{service:i.label}):n("connectors.aliasAriaNew",{service:i.label}),className:"h-8 min-w-0 flex-1 rounded-full bg-inset px-3 text-[13px] text-ink placeholder:text-ink-secondary focus:outline-none focus:ring-1 focus:ring-accent"}),e.jsx("button",{type:"submit",disabled:_e||!X.trim(),className:"inline-flex h-7 shrink-0 items-center rounded-full bg-accent px-3 text-[13px] font-medium leading-5 text-accent-ink disabled:opacity-40",children:n("connectors.action.continue")})]})]})]},i.slug)}}export{Xn as APPS_PREVIEW_COUNT,Ki as PluginsPanel,zn as ServiceIcon,Ii as USED_BY_AVATAR_SIZE,Ti as botsUsingService,Ri as botsWithLimitedServiceTools,zi as connectorSetupNotice,Si as disconnectAccountConfirmation,Ei as hostedShown,Fs as preloadConnectedApps};
|