Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
feat(composio): route ck_ Connect keys to connect.composio.dev/mcp (#146)
Abdurrahman Fakhrul25887ab1dd7f
diff --git a/frontend/slices/integrations/composio-session-panel.tsx b/frontend/slices/integrations/composio-session-panel.tsxindex 53bb3555..5e761082 100644--- a/frontend/slices/integrations/composio-session-panel.tsx+++ b/frontend/slices/integrations/composio-session-panel.tsx@@ -4,7 +4,31 @@ import { useCallback, useEffect, useState } from "react";import { Button } from "@/components/ui/button";const SESSION_PATH = "/api/v1/integrations/composio/session";+const EXECUTE_PATH = "/api/v1/integrations";type KeyKind = "organization" | "user" | "project" | "connect" | null;+type ConnectTool = { name: string; description: string };++/**+ * Connect keys run under the Connect account, so only bounded tool discovery is+ * offered. The credential owner and connection come from the same snapshot the+ * manager uses; the key itself never leaves the server.+ */+async function listConnectTools(): Promise<ConnectTool[]> {+ const query = await fetch("/api/v1/integrations?view=snapshot", { headers: { accept: "application/json" }, cache: "no-store" });+ const snapshot = await query.json().catch(() => ({}));+ if (!query.ok) throw new Error(String(snapshot.error ?? "composio_connect_tools_failed"));+ const connection = (Array.isArray(snapshot.connections) ? snapshot.connections : [])+ .find((row: { provider?: string; id?: string }) => row?.provider === "composio" && typeof row.id === "string");+ if (!snapshot.user || !connection) throw new Error("Configure a Composio connection under this credential owner first.");+ const response = await fetch(EXECUTE_PATH, {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({ mode: "execute", user: snapshot.user, provider: "composio", connection: connection.id, operation: "composio.tools.list", confirm: true }),+ });+ const body = await response.json().catch(() => ({}));+ if (!response.ok) throw new Error(String(body.error ?? "composio_connect_tools_failed"));+ return (Array.isArray(body?.tools) ? body.tools as ConnectTool[] : []).filter(tool => typeof tool?.name === "string");+}/*** Composio agent session, shown for a Platform key only. The session credential@@ -16,6 +40,7 @@ export function ComposioSessionPanel() {const [mcpUrl, setMcpUrl] = useState("");const [status, setStatus] = useState("");const [busy, setBusy] = useState(false);+ const [tools, setTools] = useState<ConnectTool[] | null>(null);useEffect(() => {let live = true;@@ -47,14 +72,32 @@ export function ComposioSessionPanel() {} finally { setBusy(false); }}, []);+ const loadTools = useCallback(async () => {+ setBusy(true);+ setStatus("Listing Composio Connect tools…");+ try {+ setTools(await listConnectTools());+ setStatus("");+ } catch (error) {+ setStatus(error instanceof Error ? error.message : "The Connect tool list could not be loaded.");+ } finally { setBusy(false); }+ }, []);+if (kind === undefined) return null;if (kind === "connect") {return (- <section className="border-b p-3" aria-label="Composio Connect key">- <p className="text-sm text-muted-foreground">- This is a Composio Connect consumer key (ck_…). It belongs to Project MCP with the endpoint- https://connect.composio.dev/mcp, and cannot create a per-user agent session.+ <section className="border-b p-3" aria-label="Composio Connect">+ <div className="flex flex-wrap items-center gap-3">+ <p className="text-sm">Composio Connect</p>+ <Button variant="secondary" disabled={busy} onClick={() => void loadTools()}>List tools</Button>+ </div>+ <p className="mt-2 text-sm text-muted-foreground">+ Connect tools run under the Composio Connect account and cannot create a per-user agent session.</p>+ {tools && (+ <ul className="mt-2 text-sm">{tools.map(tool => <li key={tool.name}>{tool.name}</li>)}</ul>+ )}+ {status && <p role="status" className="mt-2 text-sm text-muted-foreground">{status}</p>}</section>);}diff --git a/lib/infra/composio-connect.test.ts b/lib/infra/composio-connect.test.tsnew file mode 100644index 00000000..b9cc90b4--- /dev/null+++ b/lib/infra/composio-connect.test.ts@@ -0,0 +1,174 @@+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import { promises as fs } from "node:fs";+import os from "node:os";+import path from "node:path";++vi.mock("server-only", () => ({}));+type Call = { url: string; httpMethod: string; method: string; headers: Headers; params: Record<string, unknown> };+const state = vi.hoisted(() => ({ calls: [] as Call[], toolResult: null as unknown, toolError: "" }));+const reply = (id: unknown, payload: Record<string, unknown>, type = "application/json") =>+ new Response(type === "text/event-stream" ? `event: message\ndata: ${JSON.stringify({ jsonrpc: "2.0", id, ...payload })}\n\n` : JSON.stringify({ jsonrpc: "2.0", id, ...payload }), { status: 200, headers: { "content-type": type } });+vi.mock("@/lib/host/ssrf", () => ({+ safeProviderFetch: vi.fn(async (url: string, init: RequestInit) => {+ const body = JSON.parse(String(init.body)) as { id?: unknown; method: string; params?: Record<string, unknown> };+ state.calls.push({ url: String(url), httpMethod: String(init.method ?? "POST"), method: body.method, headers: new Headers(init.headers), params: body.params ?? {} });+ if (body.method === "server/discover") return reply(body.id, { error: { code: -32601, message: "Method not found" } });+ if (body.method === "initialize") return reply(body.id, { result: { protocolVersion: "2025-06-18", capabilities: { tools: {} } } }, "text/event-stream");+ if (body.method === "notifications/initialized") return new Response(null, { status: 202 });+ if (body.method === "tools/list") return reply(body.id, { result: { tools: [{ name: "COMPOSIO_SEARCH_TOOLS", description: "Search", inputSchema: { type: "object" } }, { name: "COMPOSIO_GET_TOOLKIT", description: "Toolkit", inputSchema: { type: "object" } }] } }, "text/event-stream");+ if (state.toolError) return reply(body.id, { error: { code: -32000, message: state.toolError } }, "text/event-stream");+ return reply(body.id, { result: state.toolResult }, "text/event-stream");+ }),+}));++import { callComposioConnectTool, composioConnectServer, listComposioConnectTools } from "./composio-connect";+import { composioKeyKind } from "./composio";++const TOKEN = "ck_synthetic_connect_token_1234567890";+const PLATFORM = "ak_synthetic_platform_key_1234567890";+const HOST = "connect.composio.dev";+const CONNECT = "https://connect.composio.dev/mcp";++beforeEach(() => { state.calls = []; state.toolError = ""; state.toolResult = { content: [{ type: "text", text: "ok" }], isError: false }; });+afterEach(() => vi.unstubAllGlobals());++describe("Composio Connect MCP client", () => {+ it("builds an in-memory HTTP server on the constant endpoint with the bearer token", () => {+ const server = composioConnectServer({ apiKey: TOKEN });+ expect(server).toMatchObject({ transport: "http", url: CONNECT, oauthConfigured: false });+ expect(server.headers).toEqual({ Authorization: "Bearer " + TOKEN });+ expect(new URL(server.url).hostname).toBe(HOST);+ });++ it("ignores any stored endpoint value: the URL is a constant, never caller input", () => {+ const server = composioConnectServer({ apiKey: TOKEN, endpoint: "https://attacker.invalid/mcp", url: "https://attacker.invalid/mcp" });+ expect(server.url).toBe(CONNECT);+ });++ it("lists tools over tools/list with the bearer and SSE accept, parsing the SSE body", async () => {+ const listed = await listComposioConnectTools({ apiKey: TOKEN });+ expect(listed.tools.map((tool) => tool.name)).toEqual(["COMPOSIO_GET_TOOLKIT", "COMPOSIO_SEARCH_TOOLS"]);+ const list = state.calls.find((call) => call.method === "tools/list")!;+ expect(list.url).toBe(CONNECT);+ expect(list.headers.get("authorization")).toBe("Bearer " + TOKEN);+ expect(list.httpMethod).toBe("POST");+ expect(list.headers.get("accept")).toContain("text/event-stream");+ for (const call of state.calls) expect(new URL(call.url).hostname).toBe(HOST);+ });++ it("calls tools/call with the exact name and arguments", async () => {+ await callComposioConnectTool({ apiKey: TOKEN }, "COMPOSIO_SEARCH_TOOLS", { query: "deploy" });+ const call = state.calls.find((row) => row.method === "tools/call")!;+ expect(call.url).toBe(CONNECT);+ expect(call.params).toMatchObject({ name: "COMPOSIO_SEARCH_TOOLS", arguments: { query: "deploy" } });+ expect(call.headers.get("authorization")).toBe("Bearer " + TOKEN);+ });++ it("redacts the token echoed by an upstream error", async () => {+ state.toolError = `invalid credential ${TOKEN} for this server`;+ const failure = await callComposioConnectTool({ apiKey: TOKEN }, "COMPOSIO_SEARCH_TOOLS", {}).catch((error: Error) => error);+ expect(failure).toBeInstanceOf(Error);+ expect(String(failure)).toContain("[redacted]");+ expect(String(failure)).not.toContain(TOKEN);+ });++ it("redacts the token echoed inside a successful tool result", async () => {+ state.toolResult = { content: [{ type: "text", text: `session ${TOKEN} active` }], meta: { token: TOKEN } };+ const result = await callComposioConnectTool({ apiKey: TOKEN }, "COMPOSIO_SEARCH_TOOLS", {});+ expect(JSON.stringify(result)).toContain("[redacted]");+ expect(JSON.stringify(result)).not.toContain(TOKEN);+ });++ it("refuses a Platform key before any request, so it never reaches connect.composio.dev", async () => {+ expect(composioKeyKind({ apiKey: PLATFORM })).toBe("project");+ await expect(listComposioConnectTools({ apiKey: PLATFORM })).rejects.toMatchObject({ code: "composio_connect_key_required" });+ await expect(callComposioConnectTool({ apiKey: PLATFORM }, "COMPOSIO_SEARCH_TOOLS", {})).rejects.toMatchObject({ code: "composio_connect_key_required" });+ await expect(listComposioConnectTools({})).rejects.toMatchObject({ code: "composio_connect_key_required" });+ expect(state.calls).toHaveLength(0);+ });++ it("rejects an invalid tool name with the MCP client's own shape", async () => {+ await expect(callComposioConnectTool({ apiKey: TOKEN }, "bad name!", {})).rejects.toMatchObject({ code: "invalid_tool_arguments" });+ expect(state.calls).toHaveLength(0);+ });+});++/** Every test owns a fresh store: the storage path is resolved at module load, so reset modules too. */+let root = "";+beforeEach(async () => {+ root = await fs.mkdtemp(path.join(os.tmpdir(), "mso-composio-connect-"));+ process.env.OS_INFRA_STORE = path.join(root, "infra.json");+ process.env.VITEST = "1";+ vi.resetModules();+});+afterEach(async () => { delete process.env.OS_INFRA_STORE; delete process.env.VITEST; await fs.rm(root, { recursive: true, force: true }); });++async function broker(key?: string) {+ const { integrationManage } = await import("./connection-manage");+ const service = await import("./connection-service");+ await integrationManage({ action: "user.create", user: "owner", confirm: true });+ await integrationManage({ action: "connection.create", user: "owner", provider: "composio", connection: "broker", source: "direct", authMethod: "project", confirm: true });+ await integrationManage({ action: "connection.create", user: "owner", provider: "github", connection: "work", source: "composio", authMethod: "oauth2", confirm: true });+ if (!key) return;+ const snapshot = await service.credentialSnapshot("composio", { user: "owner", connection: "broker" });+ await service.saveConnectionValues("composio", { user: "owner", connection: "broker" }, { apiKey: key }, snapshot.connection);+}++describe("Composio routing by key kind", () => {+ it("routes a ck_ key to Connect for both operations and never to the Platform API", async () => {+ await broker(TOKEN);+ const platformUrls: string[] = [];+ vi.stubGlobal("fetch", vi.fn(async (url: RequestInfo | URL) => { platformUrls.push(String(url)); return new Response("{}", { status: 200 }); }));+ const { executeIntegrationAction } = await import("./connection-dispatch");+ const listed = await executeIntegrationAction({ user: "owner", provider: "composio", operation: "composio.tools.list", connection: "broker", confirm: true }) as { tools: { name: string }[] };+ expect(listed.tools.map((tool) => tool.name)).toEqual(["COMPOSIO_GET_TOOLKIT", "COMPOSIO_SEARCH_TOOLS"]);+ const called = await executeIntegrationAction({ user: "owner", provider: "composio", operation: "composio.tool", connection: "broker", tool: "COMPOSIO_SEARCH_TOOLS", arguments: { query: "x" }, confirm: true });+ expect(JSON.stringify(called)).toContain("ok");+ expect(platformUrls).toHaveLength(0);+ expect(state.calls.length).toBeGreaterThan(0);+ for (const call of state.calls) expect(new URL(call.url).hostname).toBe(HOST);+ // A Connect credential is not a Platform credential for any other provider route.+ await expect(executeIntegrationAction({ user: "owner", provider: "github", connection: "work", operation: "composio.tool", tool: "GITHUB_GET_THE_AUTHENTICATED_USER", arguments: {}, confirm: true }))+ .rejects.toMatchObject({ code: "provider_operation_mismatch" });+ });++ it("routes an ak_ key to the Platform path for both operations and never to connect", async () => {+ await broker(PLATFORM);+ const platformUrls: string[] = [];+ let remoteUser = "";+ vi.stubGlobal("fetch", vi.fn(async (url: RequestInfo | URL, init?: RequestInit) => {+ const href = String(url); platformUrls.push(href);+ const body = init?.body ? JSON.parse(String(init.body)) as Record<string, unknown> : {};+ if (href.includes("/tools/execute/")) return new Response(JSON.stringify({ data: { login: "octo" } }), { status: 200 });+ if (href.endsWith("/connected_accounts/link")) { remoteUser = String(body.user_id); return new Response(JSON.stringify({ connected_account_id: "ca_1", redirect_url: "https://connect.composio.dev/link/x" }), { status: 200 }); }+ if (href.includes("/connected_accounts/")) return new Response(JSON.stringify({ id: "ca_1", toolkit: { slug: "github" }, auth_config: { id: "ac_1" }, user_id: remoteUser, status: "ACTIVE" }), { status: 200 });+ if (href.includes("/auth_configs/")) return new Response(JSON.stringify({ id: "ac_1", toolkit: { slug: "github" }, auth_scheme: "OAUTH2", status: "ENABLED" }), { status: 200 });+ return new Response("{}", { status: 200 });+ }));+ const external = await import("./connection-external");+ await external.authorizeIntegration("github", { user: "owner", connection: "work" }, { authConfigId: "ac_1", brokerConnection: "broker" });+ await external.verifyExternalIntegration("github", { user: "owner", connection: "work" });+ const { executeIntegrationAction } = await import("./connection-dispatch");+ const result = await executeIntegrationAction({ user: "owner", provider: "github", connection: "work", operation: "composio.tool", tool: "GITHUB_GET_THE_AUTHENTICATED_USER", arguments: {}, confirm: true });+ expect(JSON.stringify(result)).toContain("octo");+ expect(platformUrls.length).toBeGreaterThan(0);+ for (const href of platformUrls) expect(new URL(href).hostname).toBe("backend.composio.dev");+ expect(state.calls).toHaveLength(0);+ });++ it("refuses tools.list on a Platform key instead of reusing the tool-call path", async () => {+ await broker(PLATFORM);+ const { executeIntegrationAction } = await import("./connection-dispatch");+ await expect(executeIntegrationAction({ user: "owner", provider: "composio", connection: "broker", operation: "composio.tools.list", confirm: true }))+ .rejects.toMatchObject({ code: "composio_tools_list_requires_connect_key", status: 409 });+ expect(state.calls).toHaveLength(0);+ });++ it("fails closed with composio_project_key_required when no Composio key is stored", async () => {+ await broker();+ const { executeIntegrationAction } = await import("./connection-dispatch");+ await expect(executeIntegrationAction({ user: "owner", provider: "composio", operation: "composio.tools.list", connection: "broker", confirm: true }))+ .rejects.toMatchObject({ code: "composio_project_key_required", status: 409 });+ expect(state.calls).toHaveLength(0);+ });+});diff --git a/lib/infra/composio-connect.ts b/lib/infra/composio-connect.tsnew file mode 100644index 00000000..72d2a688--- /dev/null+++ b/lib/infra/composio-connect.ts@@ -0,0 +1,67 @@+import { callMcpServerTool, listMcpServerTools } from "@/lib/host/project-mcp-client";+import type { ProjectMcpServer } from "@/lib/host/project-mcp-config";+import { composioKeyKind } from "./composio";+import { COMPOSIO_MCP_HOSTS, redactComposioMessage } from "./composio-session-contract";+import { IntegrationError } from "./identity";+import { normalizeMcpEndpoint } from "./mcp-policy";+import type { InfraProviderValues } from "./types";++/**+ * Composio Connect (`ck_…`) is a different product from the Platform API, not a+ * lesser key: it is a client credential for the Connect MCP server. The endpoint+ * is a constant, never caller input and never derived from a stored value, so a+ * stored key can never retarget where its own credential is sent.+ */+export const COMPOSIO_CONNECT_MCP_URL = "https://connect.composio.dev/mcp";++/** Same shape the MCP client enforces; kept identical so the guard never loosens it. */+const TOOL_NAME = /^[A-Za-z0-9_.-]{1,128}$/;++/** One redactor for every message and every payload: an upstream server can echo the key. */+function redactConnectValue(value: unknown, token: string): unknown {+ if (typeof value === "string") return redactComposioMessage(value, [token]);+ if (Array.isArray(value)) return value.map((item) => redactConnectValue(item, token));+ if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [String(redactConnectValue(key, token)), redactConnectValue(item, token)]));+ return value;+}++function connectToken(values: InfraProviderValues): string {+ // Guard order: a Platform key or an empty form must fail before any request,+ // because connect.composio.dev must never receive a Platform credential.+ if (composioKeyKind(values) !== "connect") throw new IntegrationError("composio_connect_key_required", 409);+ const token = (values.apiKey?.trim().startsWith("ck_") ? values.apiKey : values.orgApiKey ?? "").trim();+ if (!/^ck_[\x21-\x7e]{1,4090}$/.test(token)) throw new IntegrationError("invalid_composio_connect_key", 409);+ return token;+}++/** In-memory HTTP server descriptor; no stored integration binding, the caller resolved the token. */+export function composioConnectServer(values: InfraProviderValues): ProjectMcpServer & { transport: "http"; url: string; headers: { Authorization: string } } {+ const token = connectToken(values);+ let url: string;+ try { url = normalizeMcpEndpoint(COMPOSIO_CONNECT_MCP_URL); }+ catch { throw new IntegrationError("invalid_composio_mcp_endpoint", 502); }+ // Constant endpoint: the allowlist check documents the invariant instead of trusting it.+ if (!COMPOSIO_MCP_HOSTS.includes(new URL(url).hostname)) throw new IntegrationError("invalid_composio_mcp_host", 502);+ return { name: "composio-connect", transport: "http", url, headers: { Authorization: "Bearer " + token }, oauthConfigured: false };+}++export async function listComposioConnectTools(values: InfraProviderValues): Promise<{ tools: { name: string; description: string }[] }> {+ const token = connectToken(values);+ let tools;+ try { tools = await listMcpServerTools(composioConnectServer(values)); }+ catch (error) { throw new IntegrationError(String(redactConnectValue(error instanceof Error ? error.message : "composio_connect_tools_failed", token)), 502); }+ return {+ tools: tools+ .map((tool) => ({ name: String(redactConnectValue(tool.name, token)), description: String(redactConnectValue(tool.description ?? "", token)) }))+ .sort((a, b) => a.name.localeCompare(b.name)),+ };+}++export async function callComposioConnectTool(values: InfraProviderValues, tool: string, args: unknown): Promise<unknown> {+ const token = connectToken(values);+ if (!TOOL_NAME.test(tool)) throw new IntegrationError("invalid_tool_arguments");+ let result: unknown;+ try { result = await callMcpServerTool(composioConnectServer(values), tool, args); }+ catch (error) { throw new IntegrationError(String(redactConnectValue(error instanceof Error ? error.message : "composio_connect_tool_failed", token)), 502); }+ return redactConnectValue(result, token);+}diff --git a/lib/infra/composio.test.ts b/lib/infra/composio.test.tsindex ea9bc7e8..dc2e05f0 100644--- a/lib/infra/composio.test.ts+++ b/lib/infra/composio.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, it, vi } from "vitest";vi.mock("server-only", () => ({}));-import { composioAuthHeader, composioKeyKind, doctorComposio } from "./composio";+import { COMPOSIO_CONNECT_KEY_MESSAGE, composioAuthHeader, composioKeyKind, doctorComposio } from "./composio";afterEach(() => vi.unstubAllGlobals());@@ -32,9 +32,10 @@ describe("composio credential routing", () => {describe("composio connect consumer keys", () => {it("refuses a ck_ Connect key instead of sending it to the Platform API", () => {- expect(() => composioAuthHeader({ apiKey: "ck_consumer_key" })).toThrow(/Project MCP/);- expect(() => composioAuthHeader({ orgApiKey: "ck_consumer_key" })).toThrow(/Project MCP/);+ expect(() => composioAuthHeader({ apiKey: "ck_consumer_key" })).toThrow(/Connect key works for Composio Connect tool access/);+ expect(() => composioAuthHeader({ orgApiKey: "ck_consumer_key" })).toThrow(/cannot authorize Platform connected accounts/);expect(() => composioAuthHeader({ apiKey: "ak_project" })).not.toThrow();+ expect(COMPOSIO_CONNECT_KEY_MESSAGE).not.toMatch(/Project MCP/);});it("reports the key kind for a form without exposing the value", () => {diff --git a/lib/infra/composio.ts b/lib/infra/composio.tsindex 6a3b0652..273b0038 100644--- a/lib/infra/composio.ts+++ b/lib/infra/composio.ts@@ -6,20 +6,20 @@ export const COMPOSIO_API_BASE = "https://backend.composio.dev/api/v3.1";const API = COMPOSIO_API_BASE;/**- * Composio keys live on two different products and only one of them is this- * provider. Platform keys (ak_ project, uak_ user from `composio login`, org- * keys) authenticate against backend.composio.dev/api/v3.1. A ck_ Connect- * consumer key belongs to the Connect MCP product at connect.composio.dev/mcp- * and is rejected by every Platform route with 401, so storing it here can- * never work. Connect MCP keys belong in the Project MCP provider, which speaks- * streamable HTTP and already accepts them.+ * Composio keys live on two different products. Platform keys (ak_ project,+ * uak_ user from `composio login`, org keys) authenticate against+ * backend.composio.dev/api/v3.1. A ck_ Connect consumer key belongs to the+ * Connect MCP product at connect.composio.dev/mcp: it works for Connect tool+ * access (`composio.tools.list` / `composio.tool` through lib/infra/composio-connect.ts)+ * and it cannot authorize Platform connected accounts, which stay on the three+ * Platform header kinds below.*/export function composioConnectKey(value: string | undefined): boolean {return Boolean(value?.trim().startsWith("ck_"));}export const COMPOSIO_CONNECT_KEY_MESSAGE =- "Composio Connect key (ck_…) is not a Platform key. Use Integrations → Project MCP with https://connect.composio.dev/mcp. Platform keys start ak_ or uak_.";+ "Composio Connect key (ck_…). A Connect key works for Composio Connect tool access and cannot authorize Platform connected accounts. Platform keys start ak_ (project) or uak_ (user).";export function composioAuthHeader(values: InfraProviderValues): { header: Record<string, string>; kind: "organization" | "user" | "project" } | null {const orgKey = values.orgApiKey?.trim();diff --git a/lib/infra/connection-dispatch.ts b/lib/infra/connection-dispatch.tsindex ea8a7422..e528151d 100644--- a/lib/infra/connection-dispatch.ts+++ b/lib/infra/connection-dispatch.ts@@ -1,8 +1,10 @@import { isGoogleProvider, GOOGLE_APP_PROVIDER, googlePublicOrigin } from "./google-native-config";import { bindGoogleApp, disconnectGoogle, runNativeGoogle, nativeGoogleStatus, googleOperations } from "./google-native";import { integrationManage } from "./connection-manage";-import { integrationQuery, withIntegrationSelection, resolveIntegration } from "./connection-service";+import { integrationQuery, withIntegrationSelection, resolveIntegration, directConnectionValues } from "./connection-service";import { authorizeIntegration, composioConnectionCall } from "./connection-external";+import { composioKeyKind } from "./composio";+import { callComposioConnectTool, listComposioConnectTools } from "./composio-connect";import { IntegrationError, identity, metadataOnly, type ConnectionSelector } from "./identity";import { importConvexCliPersonalConnection } from "./convex-cli-import";import { listConvexCustomDomains, ensureConvexCustomDomain, getConvexCanonicalUrls, setConvexCanonicalUrl, getConvexEnvPresence, deployConvexCloudProject, importConvexCloudSnapshot } from "./convex-cloud";@@ -52,7 +54,7 @@ export async function executeIntegrationAction(raw:Record<string,unknown>){if(operation==="google.disconnect"||operation==="google.operations.list"){if(Object.keys(body).length)throw new IntegrationError("invalid_tool_arguments");return operation==="google.disconnect"?disconnectGoogle(provider,selection):{operations:googleOperations(provider)}}return runNativeGoogle(provider,selection,operation,body);}- if(operation==="composio.tool")return composioConnectionCall(provider,selection,String(a.tool),args as Record<string,unknown>);+ if(operation==="composio.tool"||operation==="composio.tools.list")return composioOperation(provider,selection,operation,String(a.tool),args as Record<string,unknown>);const verbs:Record<string,{provider:string;fields:string[];run:()=>Promise<unknown>}>= {"dokploy.projects.list":{provider:"dokploy",fields:[],run:()=>listDokployProjects()},"dokploy.applications.list":{provider:"dokploy",fields:["projectId"],run:()=>listDokployApplications(String((args as Record<string,unknown>).projectId))},@@ -92,3 +94,30 @@ export async function executeIntegrationAction(raw:Record<string,unknown>){return withIntegrationSelection(selection,async()=>({identity:route,result:await verb.run()}));}export const queryIntegrationAction=(input:Record<string,unknown>)=>integrationQuery(safeActionInput(input));++/**+ * One branch for both Composio operations so the key-kind routing cannot drift.+ * Connect uses the stored provider credential directly (no connection selector,+ * like doctorComposio); Platform keeps its existing /connected_accounts path.+ */+async function composioOperation(provider:string,selection:ConnectionSelector,operation:string,tool:string,args:Record<string,unknown>){+ // Read the stored Composio credential for the same credential owner, the way+ // doctorComposio reads it: no connection selector, no endpoint from the caller.+ // A store that cannot resolve a Composio row for this owner falls through to the+ // Platform path unchanged, which raises its own existing error.+ let values:Record<string,string>|undefined;+ try{values=await directConnectionValues("composio",{user:selection.user});}catch{values=undefined;}+ if(values){+ const kind=composioKeyKind(values);+ if(kind==="connect"){+ // Connect tools run under the Connect account; only the composio provider owns that surface.+ if(provider!=="composio")throw new IntegrationError("provider_operation_mismatch");+ return operation==="composio.tools.list"?listComposioConnectTools(values):callComposioConnectTool(values,tool,args);+ }+ if(kind===null)throw new IntegrationError("composio_project_key_required",409);+ // Platform discovery is per connected account and never was this operation: refuse it clearly.+ if(operation==="composio.tools.list")throw new IntegrationError("composio_tools_list_requires_connect_key",409);+ }+ return composioConnectionCall(provider,selection,tool,args);+}+diff --git a/lib/infra/connection-ui.ts b/lib/infra/connection-ui.tsindex 49296663..b328f7da 100644--- a/lib/infra/connection-ui.ts+++ b/lib/infra/connection-ui.ts@@ -24,7 +24,7 @@ function mountConnectionManager(root,catalog,bridge,initial={}){popup.addEventListener("keydown",event=>{if(event.key==="ArrowDown")move(event,1);else if(event.key==="ArrowUp")move(event,-1);else if(event.key==="Home"){event.preventDefault();options[0]?.[1].focus()}else if(event.key==="End"){event.preventDefault();options.at(-1)?.[1].focus()}else if(event.key==="Escape"){event.preventDefault();close(true)}});wrap.addEventListener("focusout",()=>setTimeout(()=>{if(!wrap.contains(document.activeElement))close()},0));wrap.append(caption,trigger,popup);paint();return{wrap,get value(){return value},set value(next){value=next;paint()}};};- const textError=e=>({user_required:"Select a credential owner first.",connection_ambiguous:"Choose a named connection; more than one account exists.",connection_has_folder_binding:"Remove or change this connection's folder binding before deleting it.",integration_has_variables:"Remove Integration Variables that point to this owner or connection first.",invalid_variable_key:"Variable names use uppercase A-Z, 0-9 and underscore.",connection_busy:"This connection is being used. Retry after that operation finishes.",choose_auth_config_id:"Several Composio auth configs match. Enter the intended auth config ID.",matching_auth_config_required:"Select a matching Composio auth config, or explicitly permit managed OAuth setup.",composio_project_key_required:"Configure a Composio project key under this same credential owner first.",composio_connect_key_wrong_provider:"This is a Composio Connect consumer key (ck_…), not a Platform key. It only works under Integrations → Project MCP with the endpoint https://connect.composio.dev/mcp. Platform keys start with ak_ (project) or uak_ (user).",external_source_requires_own_executor:"This connection uses an external backend; a local API key will not be substituted.",user_has_shared_dependents:"Unshare this owner’s shared connections before deleting the owner.",connection_has_shared_dependents:"Unshare dependent accounts before deleting this connection.",shared_alias_readonly:"Shared connections are read-only. Rotate credentials from the owner connection.",shared_alias_cannot_share:"A shared connection cannot be shared again. Share from its owner instead.",external_connections_cannot_share:"Only direct MSO credentials can be shared between credential owners.",shared_alias_use_unshare:"Use Unshare to remove a shared connection without touching its owner.",owner_required:"Sign in as an Owner before changing connections."}[e.code||e.message]||e.message||"Operation failed.");+ const textError=e=>({user_required:"Select a credential owner first.",connection_ambiguous:"Choose a named connection; more than one account exists.",connection_has_folder_binding:"Remove or change this connection's folder binding before deleting it.",integration_has_variables:"Remove Integration Variables that point to this owner or connection first.",invalid_variable_key:"Variable names use uppercase A-Z, 0-9 and underscore.",connection_busy:"This connection is being used. Retry after that operation finishes.",choose_auth_config_id:"Several Composio auth configs match. Enter the intended auth config ID.",matching_auth_config_required:"Select a matching Composio auth config, or explicitly permit managed OAuth setup.",composio_project_key_required:"Configure a Composio project key under this same credential owner first.",composio_connect_key_wrong_provider:"This is a Composio Connect consumer key (ck_…). It works for Composio Connect tool access and cannot authorize a Platform connected account. Platform keys start with ak_ (project) or uak_ (user).",external_source_requires_own_executor:"This connection uses an external backend; a local API key will not be substituted.",user_has_shared_dependents:"Unshare this owner’s shared connections before deleting the owner.",connection_has_shared_dependents:"Unshare dependent accounts before deleting this connection.",shared_alias_readonly:"Shared connections are read-only. Rotate credentials from the owner connection.",shared_alias_cannot_share:"A shared connection cannot be shared again. Share from its owner instead.",external_connections_cannot_share:"Only direct MSO credentials can be shared between credential owners.",shared_alias_use_unshare:"Use Unshare to remove a shared connection without touching its owner.",owner_required:"Sign in as an Owner before changing connections."}[e.code||e.message]||e.message||"Operation failed.");function remember(){if(bridge.remember)bridge.remember({user,provider:provider.id})}async function reload(){const version=++sequence;if(!bridge.query){draw();return}try{const next=await bridge.query({view:"snapshot",...(user?{user}:{})});if(disposed||version!==sequence)return;snapshot=next;user=next.user||user;draw();remember()}catch(e){if(!disposed){draw();status.textContent=textError(e)}}}async function change(args,after=reload){if(!bridge.manage)return;try{status.textContent="Saving connection metadata…";await bridge.manage({...args,confirm:true});await after()}catch(e){status.textContent=textError(e)}}