Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
fix(connectors): migrate Gmail to API-key Composio authorization
wytdbf8a539b8ab
diff --git a/src/main/features/connectors/availability.ts b/src/main/features/connectors/availability.tsindex 66e11aa9..4931bc41 100644--- a/src/main/features/connectors/availability.ts+++ b/src/main/features/connectors/availability.ts@@ -38,6 +38,8 @@ export function isGoogleConnectorId(id: string): boolean {}export function connectorAvailabilityForId(id: string): ConnectorAvailability {+ // Gmail uses Composio; legacy Google OAuth switches do not govern this path.+ if (id === 'gmail') return 'enabled';if (!isGoogleConnectorId(id)) return 'enabled';const cfg = getGoogleConnectorsConfig();const overall = _overallStateToAvailability(cfg.google);diff --git a/src/main/features/connectors/catalog-google.ts b/src/main/features/connectors/catalog-google.tsindex dc156732..7e3eefe0 100644--- a/src/main/features/connectors/catalog-google.ts+++ b/src/main/features/connectors/catalog-google.ts@@ -1,18 +1,7 @@/**- * Google Workspace catalog entries — extracted from `catalog.ts` so the Google bundle and- * per-service connectors stay isolated while still syncing to the open-source build. Both PC and the open-source build- * include this file via a try/require in `catalog.ts`; the catch path only keeps older open-source- * checkouts without this file from crashing.- *- * Includes:- * - `google-workspace` (one independent all-in-one connector backed by- * `bin/google-workspace-mcp-server.cjs`)- * - `gmail`, `gcal`, `gdocs`, `gsheets`, `gtasks` (5 independent per-service connectors,- * each backed by a local stdio adapter under `PC/bin/`)- *- * Adding a new Google service: drop a new entry here + `bin/<svc>-mcp-server.cjs` adapter,- * Server's `_SCOPES_BY_CATALOG_ID` row, and wire the adapter into- * `bin/google-workspace-mcp-server.cjs` if you want it covered by the all-in-one connector.+ * Legacy Google OAuth catalog entries. Standalone Gmail is declared as Composio in+ * catalog.ts; the Workspace bundle and adapters remain for compatibility.+ * The hosted catalog currently publishes only Search Console from this module.*/import type { CatalogEntry } from './types';@@ -63,24 +52,6 @@ export const GOOGLE_ENTRIES: CatalogEntry[] = [proxy_target_url: 'https://www.googleapis.com/',},},- {- id: 'gmail',- display_name: 'Gmail',- icon_svg: '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#4285f4" d="M24 5.457v13.909c0 .904-.732 1.636-1.636 1.636h-3.819V11.73L12 16.64l-6.545-4.91v9.273H1.636A1.636 1.636 0 0 1 0 19.366V5.457c0-2.023 2.309-3.178 3.927-1.964L5.455 4.64 12 9.548l6.545-4.91 1.528-1.145C21.69 2.28 24 3.434 24 5.457z"/><path fill="#34a853" d="M5.455 21.003V11.73l-3.819-2.864v10.5c0 .904.732 1.637 1.636 1.637z"/><path fill="#ea4335" d="M18.545 21.003V11.73l3.819-2.864v10.5a1.636 1.636 0 0 1-1.636 1.637z"/><path fill="#fbbc04" d="M5.455 11.73 12 16.64l6.545-4.91V4.64L12 9.548 5.455 4.64z"/><path fill="#c5221f" d="M0 5.457v3.41l5.455 4.092V4.64L3.927 3.494C2.309 2.28 0 3.434 0 5.457z"/></svg>',- category: 'communication',- description_zh: '读 / 发邮件、整理收件箱。',- description_en: 'Read and send mail, organize the inbox.',- auth_mode: 'server_bridge',- oauth: { provider_id: 'google' },- required_oauth_scopes: GOOGLE_SCOPES.gmail,- transport_template: {- kind: 'stdio',- command: '${ORKAS_NODE}',- args: ['${ORKAS_PC_DIR}/bin/gmail-mcp-server.cjs'],- oauth_env_key: 'GOOGLE_ACCESS_TOKEN',- proxy_target_url: 'https://gmail.googleapis.com/',- },- },{id: 'gcal',display_name: 'Google Calendar',diff --git a/src/main/features/connectors/catalog.ts b/src/main/features/connectors/catalog.tsindex a9f46597..f815b2cf 100644--- a/src/main/features/connectors/catalog.ts+++ b/src/main/features/connectors/catalog.ts@@ -216,6 +216,18 @@ export const CONNECTOR_CATALOG: CatalogEntry[] = [oauth_header_key: 'Authorization',},},+ {+ id: 'gmail',+ display_name: 'Gmail',+ icon_svg: '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path fill="#4285f4" d="M24 5.457v13.909c0 .904-.732 1.636-1.636 1.636h-3.819V11.73L12 16.64l-6.545-4.91v9.273H1.636A1.636 1.636 0 0 1 0 19.366V5.457c0-2.023 2.309-3.178 3.927-1.964L5.455 4.64 12 9.548l6.545-4.91 1.528-1.145C21.69 2.28 24 3.434 24 5.457z"/><path fill="#34a853" d="M5.455 21.003V11.73l-3.819-2.864v10.5c0 .904.732 1.637 1.636 1.637z"/><path fill="#ea4335" d="M18.545 21.003V11.73l3.819-2.864v10.5a1.636 1.636 0 0 1-1.636 1.637z"/><path fill="#fbbc04" d="M5.455 11.73 12 16.64l6.545-4.91V4.64L12 9.548 5.455 4.64z"/><path fill="#c5221f" d="M0 5.457v3.41l5.455 4.092V4.64L3.927 3.494C2.309 2.28 0 3.434 0 5.457z"/></svg>',+ category: 'communication',+ description_zh: '读 / 发邮件、整理收件箱。',+ description_en: 'Read and send mail, organize the inbox.',+ requires_credits: true,+ auth_mode: 'composio',+ transport_template: null,+ usage_metering: { provider: 'composio', credits_milli_per_call: 250 },+ },...GOOGLE_ENTRIES,{id: 'bing-webmaster',diff --git a/test/main/features/connectors/gmail-catalog.test.ts b/test/main/features/connectors/gmail-catalog.test.tsnew file mode 100644index 00000000..03df947b--- /dev/null+++ b/test/main/features/connectors/gmail-catalog.test.ts@@ -0,0 +1,54 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';++const config = vi.hoisted(() => ({+ google: { google: 'disabled', gmail: 'disabled' },+ catalog: [] as any[],+}));+vi.mock('../../../../src/main/features/client_config', () => ({+ getGoogleConnectorsConfig: () => config.google,+ getServerConnectorCatalogConfig: () => config.catalog,+}));+import { connectorCatalog, findCatalogEntry } from '../../../../src/main/features/connectors/catalog';+import { GOOGLE_ENTRIES } from '../../../../src/main/features/connectors/catalog-google';+import { assertConnectorRuntimeEnabled, catalogWithAvailability } from '../../../../src/main/features/connectors/availability';++describe('Gmail catalog migration', () => {+ beforeEach(() => {+ config.google = { google: 'disabled', gmail: 'disabled' };+ config.catalog = [];+ });++ it.each([+ ['disabled', 'disabled'], ['disabled', 'enabled'], ['enabled', 'visible_disabled'],+ ])('shows Composio Gmail with legacy switches %s/%s even before remote catalog loads', (google, gmail) => {+ config.google = { google, gmail };+ const visible = catalogWithAvailability(connectorCatalog());+ expect(visible.filter((entry) => entry.id === 'gmail')).toHaveLength(1);+ expect(visible.find((entry) => entry.id === 'gmail')).toMatchObject({+ auth_mode: 'composio', requires_credits: true, transport_template: null,+ usage_metering: { provider: 'composio', credits_milli_per_call: 250 },+ });+ expect(findCatalogEntry('gmail')?.oauth).toBeUndefined();+ expect(GOOGLE_ENTRIES.some((entry) => entry.id === 'gmail')).toBe(false);+ expect(() => assertConnectorRuntimeEnabled('gmail')).not.toThrow();+ // The Gmail exception must not silently enable other legacy Google connectors.+ if (google === 'disabled') {+ expect(visible.some((entry) => entry.id === 'gsearch-console')).toBe(false);+ expect(() => assertConnectorRuntimeEnabled('gsearch-console')).toThrow('connector_unsupported');+ }+ });++ it('merges server Gmail tools and pricing without duplicating it or replacing unrelated OAuth entries', () => {+ config.catalog = [+ { id: 'gmail', auth_mode: 'composio', composio: { toolkit: 'gmail', tools: [{ slug: 'GMAIL_FETCH_EMAILS' }] },+ usage_metering: { provider: 'composio', credits_milli_per_call: 500 } },+ { id: 'github', auth_mode: 'composio' },+ ];+ expect(connectorCatalog().filter((entry) => entry.id === 'gmail')).toHaveLength(1);+ expect(findCatalogEntry('gmail')).toMatchObject({+ auth_mode: 'composio', composio: { toolkit: 'gmail', tools: [{ slug: 'GMAIL_FETCH_EMAILS' }] },+ usage_metering: { credits_milli_per_call: 500 },+ });+ expect(findCatalogEntry('github')?.auth_mode).toBe('server_bridge');+ });+});diff --git a/test/main/features/connectors/manager.test.ts b/test/main/features/connectors/manager.test.tsindex f2bef3e5..a2023679 100644--- a/test/main/features/connectors/manager.test.ts+++ b/test/main/features/connectors/manager.test.ts@@ -383,6 +383,43 @@ afterEach(() => {});describe('features/connectors/manager authorization recovery', () => {+ it('requires reconnect for legacy Google Gmail and replaces it with an API-key Composio grant', async () => {+ await writeGoogleConnectorsConfig({ google: 'disabled', gmail: 'disabled' });+ const registry = await import('../../../../src/main/features/connectors/registry');+ const manager = await import('../../../../src/main/features/connectors/manager');+ await registry.upsert(TEST_UID, googleInstance('gmail', ['https://www.googleapis.com/auth/gmail.modify']));++ await manager.bootstrap(TEST_UID);+ expect(manager.getInstance(TEST_UID, 'gmail')?.status).toMatchObject({+ kind: 'error', message: 'connector_reconnect_required',+ });+ expect(mocks.mcp.connect).not.toHaveBeenCalled();+ expect(mocks.oauth.refreshIfStale).not.toHaveBeenCalled();+ expect(mocks.oauth.startOAuth).not.toHaveBeenCalled();++ mocks.oauth.startComposioConnect.mockResolvedValue({+ connection_id: 'gmail-connection', connection_token: 'a'.repeat(43), toolkit: 'gmail',+ });+ mocks.mcp.listTools.mockResolvedValue([+ { name: 'GMAIL_FETCH_EMAILS', description: 'Fetch email', input_schema: {} },+ ]);+ await expect(manager.connectViaOAuth(TEST_UID, 'gmail')).resolves.toMatchObject({+ id: 'gmail', status: { kind: 'connected' },+ transport: { env: {+ ORKAS_API_KEY: 'orkas-connector-key', COMPOSIO_CONNECTION_ID: 'gmail-connection',+ COMPOSIO_CONNECTION_TOKEN: 'a'.repeat(43),+ } },+ });+ expect(mocks.oauth.startOAuth).not.toHaveBeenCalled();+ expect(mocks.metering.preflightConnectorCredits).toHaveBeenCalledWith(+ expect.objectContaining({ id: 'gmail', auth_mode: 'composio', requires_credits: true }), 'connect',+ );+ const saved = registry.load(TEST_UID).connections.gmail;+ expect(saved.oauth_grant).toBeUndefined();+ expect(saved.composio_grant?.connection_token).toBe('a'.repeat(43));+ expect(saved.transport.kind === 'stdio' && saved.transport.env?.GOOGLE_ACCESS_TOKEN).toBeUndefined();+ });+it('connects a server-catalog Composio connector through the API-key adapter', async () => {await writeComposioCatalog();mocks.oauth.startComposioConnect.mockResolvedValue({@@ -1478,13 +1515,13 @@ describe('OAuth refresh ownership', () => {await writeGoogleConnectorsConfig(true);const registry = await import('../../../../src/main/features/connectors/registry');const manager = await import('../../../../src/main/features/connectors/manager');- const instance = googleInstance('gmail', ['https://www.googleapis.com/auth/gmail.modify']);+ const instance = googleInstance('gsheets', ['https://www.googleapis.com/auth/drive.file']);instance.oauth_grant.expires_at = 1;instance.tools_cache = [{ name: 'search', description: '', input_schema: {} }] as any;await registry.upsert(TEST_UID, instance);mocks.oauth.refreshIfStale = vi.fn(async () => { throw Object.assign(new Error('connector_reconnect_required'), { code: 'connector_reconnect_required' }); });expect(await manager.verifyUsableConnectors(TEST_UID)).toBe(0);- expect(registry.load(TEST_UID).connections.gmail.status.kind).toBe('error');+ expect(registry.load(TEST_UID).connections.gsheets.status.kind).toBe('error');expect(mocks.mcp.connect).not.toHaveBeenCalled();});});diff --git a/test/main/features/connectors/open-source-boundary.test.ts b/test/main/features/connectors/open-source-boundary.test.tsindex c77d6198..0946b3d9 100644--- a/test/main/features/connectors/open-source-boundary.test.ts+++ b/test/main/features/connectors/open-source-boundary.test.ts@@ -7,13 +7,19 @@ const root = path.join(__dirname, '../../../..');const read = (rel: string) => fs.readFileSync(path.join(root, rel), 'utf8');describe('public connector boundary', () => {- it('keeps every catalog connector on a public OAuth mode without credit metering', () => {- expect(CONNECTOR_CATALOG).toHaveLength(21);- expect(CONNECTOR_CATALOG.filter((entry) => entry.auth_mode === 'mcp_dcr')).toHaveLength(11);- expect(CONNECTOR_CATALOG.filter((entry) => entry.auth_mode === 'server_bridge')).toHaveLength(10);+ it('keeps public OAuth modes and confines credit metering to Composio', () => {for (const entry of CONNECTOR_CATALOG) {- expect(['server_bridge', 'mcp_dcr']).toContain(entry.auth_mode);+ expect(['server_bridge', 'mcp_dcr', 'composio']).toContain(entry.auth_mode);expect(entry.icon_svg).toMatch(/^<svg\b/);+ if (entry.auth_mode === 'composio') {+ expect(entry).toMatchObject({+ requires_credits: true,+ transport_template: null,+ usage_metering: { provider: 'composio' },+ });+ expect(entry.oauth).toBeUndefined();+ continue;+ }if (entry.auth_mode === 'mcp_dcr') {expect(entry.transport_template?.kind).toBe('streamable-http');expect(entry.transport_template && 'url' in entry.transport_template