🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: guide task template connector auth (#16036)
YuTengjingb917a81c7784
diff --git a/locales/en-US/marketAuth.json b/locales/en-US/marketAuth.jsonindex 823fa59b139..ec23f839949 100644--- a/locales/en-US/marketAuth.json+++ b/locales/en-US/marketAuth.json@@ -5,6 +5,10 @@"authorize.footer.agreement": "By continuing, you confirm that you have read and agree to the <terms>Terms and Conditions</terms> and <privacy>Privacy Policy</privacy>.","authorize.footer.privacy": "Privacy Policy","authorize.footer.terms": "Terms of Service",+ "authorize.scenes.connector.confirm": "Continue to Market",+ "authorize.scenes.connector.description": "Market is only used to start this service authorization. Your {{appName}} account stays separate.",+ "authorize.scenes.connector.subtitle": "Sign in to Market to connect and authorize this community service.",+ "authorize.scenes.connector.title": "Connect Community Service","authorize.scenes.mcp.subtitle": "Create a community profile to install and run this skill from the community.","authorize.scenes.mcp.title": "Install Community Skill","authorize.scenes.sandbox.subtitle": "Create a community profile to run this tool in the community sandbox.",diff --git a/locales/zh-CN/marketAuth.json b/locales/zh-CN/marketAuth.jsonindex e0fb9e78051..a1711b94008 100644--- a/locales/zh-CN/marketAuth.json+++ b/locales/zh-CN/marketAuth.json@@ -5,6 +5,10 @@"authorize.footer.agreement": "继续操作即表示你确认已理解并同意<terms>条款和条件</terms>和<privacy>隐私政策</privacy>","authorize.footer.privacy": "隐私政策","authorize.footer.terms": "服务条款",+ "authorize.scenes.connector.confirm": "前往 Market",+ "authorize.scenes.connector.description": "Market 仅用于发起该服务授权,你的 {{appName}} 帐号仍保持独立。",+ "authorize.scenes.connector.subtitle": "登录 Market 后即可连接并授权该社区服务。",+ "authorize.scenes.connector.title": "连接社区服务","authorize.scenes.mcp.subtitle": "创建社区个人档案,即可安装并运行该社区技能。","authorize.scenes.mcp.title": "安装社区技能","authorize.scenes.sandbox.subtitle": "创建社区个人档案,即可在社区沙箱中运行该工具。",diff --git a/packages/locales/src/default/marketAuth.ts b/packages/locales/src/default/marketAuth.tsindex 89f17ee817f..c0a64c34c9f 100644--- a/packages/locales/src/default/marketAuth.ts+++ b/packages/locales/src/default/marketAuth.ts@@ -6,6 +6,12 @@ export default {'By continuing, you confirm that you have read and agree to the <terms>Terms and Conditions</terms> and <privacy>Privacy Policy</privacy>.','authorize.footer.privacy': 'Privacy Policy','authorize.footer.terms': 'Terms of Service',+ 'authorize.scenes.connector.confirm': 'Continue to Market',+ 'authorize.scenes.connector.description':+ 'Market is only used to start this service authorization. Your {{appName}} account stays separate.',+ 'authorize.scenes.connector.subtitle':+ 'Sign in to Market to connect and authorize this community service.',+ 'authorize.scenes.connector.title': 'Connect Community Service','authorize.scenes.mcp.subtitle':'Create a community profile to install and run this skill from the community.','authorize.scenes.mcp.title': 'Install Community Skill',diff --git a/src/features/RecommendTaskTemplates/SkillAuthRow.test.tsx b/src/features/RecommendTaskTemplates/ConnectorAuthRow.test.tsxsimilarity index 71%rename from src/features/RecommendTaskTemplates/SkillAuthRow.test.tsxrename to src/features/RecommendTaskTemplates/ConnectorAuthRow.test.tsxindex 5b3c470f057..cb62c7dd189 100644--- a/src/features/RecommendTaskTemplates/SkillAuthRow.test.tsx+++ b/src/features/RecommendTaskTemplates/ConnectorAuthRow.test.tsx@@ -4,13 +4,14 @@import { fireEvent, render, screen } from '@testing-library/react';import { beforeEach, describe, expect, it, vi } from 'vitest';-import { SkillAuthRow } from './SkillAuthRow';+import { ConnectorAuthRow } from './ConnectorAuthRow';const connectMock = vi.hoisted(() => vi.fn());-vi.mock('./useSkillConnection', () => ({- SkillConnectionPopupBlockedError: class SkillConnectionPopupBlockedError extends Error {},- useSkillConnection: () => ({+vi.mock('./useConnectorConnection', () => ({+ ConnectorConnectionMarketAuthRequiredError: class ConnectorConnectionMarketAuthRequiredError extends Error {},+ ConnectorConnectionPopupBlockedError: class ConnectorConnectionPopupBlockedError extends Error {},+ useConnectorConnection: () => ({connect: connectMock,isAllConnected: false,isConnecting: false,@@ -25,14 +26,14 @@ vi.mock('react-i18next', () => ({useTranslation: () => ({ t: (key: string) => key }),}));-describe('SkillAuthRow', () => {+describe('ConnectorAuthRow', () => {beforeEach(() => {connectMock.mockReset();});it('disables provider connection when template actions are disabled', () => {render(- <SkillAuthRow+ <ConnectorAuthRowdisabledspec={{ identifier: 'gmail', source: 'composio' }}onError={vi.fn()}diff --git a/src/features/RecommendTaskTemplates/SkillAuthRow.tsx b/src/features/RecommendTaskTemplates/ConnectorAuthRow.tsxsimilarity index 74%rename from src/features/RecommendTaskTemplates/SkillAuthRow.tsxrename to src/features/RecommendTaskTemplates/ConnectorAuthRow.tsxindex 99a12c67217..9780359f585 100644--- a/src/features/RecommendTaskTemplates/SkillAuthRow.tsx+++ b/src/features/RecommendTaskTemplates/ConnectorAuthRow.tsx@@ -5,24 +5,28 @@ import { memo, useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';import { getProviderMeta } from './providerMeta';-import { SkillConnectionPopupBlockedError, useSkillConnection } from './useSkillConnection';+import {+ ConnectorConnectionMarketAuthRequiredError,+ ConnectorConnectionPopupBlockedError,+ useConnectorConnection,+} from './useConnectorConnection';-interface SkillAuthRowProps {+interface ConnectorAuthRowProps {disabled?: boolean;onError: (error: unknown) => void;spec: TaskTemplateConnectorReference;}/**- * Inline row for a single required/optional skill the user has not yet authorized.+ * Inline row for a single required/optional connector the user has not yet authorized.* Renders `null` once the provider is connected so the caller can collapse the* surrounding container without extra bookkeeping.*/-export const SkillAuthRow = memo<SkillAuthRowProps>(({ disabled, spec, onError }) => {+export const ConnectorAuthRow = memo<ConnectorAuthRowProps>(({ disabled, spec, onError }) => {const { t } = useTranslation('taskTemplate');const specs = useMemo(() => [spec], [spec]);const meta = useMemo(() => getProviderMeta(spec), [spec]);- const { connect, isAllConnected, isConnecting } = useSkillConnection(specs);+ const { connect, isAllConnected, isConnecting } = useConnectorConnection(specs);const handleConnect = useCallback(async () => {if (disabled) return;@@ -60,6 +64,6 @@ export const SkillAuthRow = memo<SkillAuthRowProps>(({ disabled, spec, onError });});-SkillAuthRow.displayName = 'SkillAuthRow';+ConnectorAuthRow.displayName = 'ConnectorAuthRow';-export { SkillConnectionPopupBlockedError };+export { ConnectorConnectionMarketAuthRequiredError, ConnectorConnectionPopupBlockedError };diff --git a/src/features/RecommendTaskTemplates/TaskTemplateCard.tsx b/src/features/RecommendTaskTemplates/TaskTemplateCard.tsxindex e09213b363c..3416474326d 100644--- a/src/features/RecommendTaskTemplates/TaskTemplateCard.tsx+++ b/src/features/RecommendTaskTemplates/TaskTemplateCard.tsx@@ -9,8 +9,8 @@ import { useTranslation } from 'react-i18next';import BriefCardSummary from '@/features/DailyBrief/BriefCardSummary';import { styles as briefStyles } from '@/features/DailyBrief/style';+import { ConnectorAuthRow } from './ConnectorAuthRow';import { resolveTemplateIcon } from './resolveTemplateIcon';-import { SkillAuthRow } from './SkillAuthRow';import { styles } from './style';import { createTaskTemplateDetailModal } from './TaskTemplateDetailModal';import { INTEREST_ICON_MAP, TemplateBriefIcon } from './TemplateBriefIcon';@@ -134,7 +134,7 @@ export const TaskTemplateCard = memo<TaskTemplateCardProps>({visibleAuthSpecs.length > 0 && (<Flexbox gap={6} onClick={(e) => e.stopPropagation()}>{visibleAuthSpecs.map((spec) => (- <SkillAuthRow+ <ConnectorAuthRowdisabled={disabled}key={`${spec.source}:${spec.identifier}`}spec={spec}diff --git a/src/features/RecommendTaskTemplates/TaskTemplateDetailModal.tsx b/src/features/RecommendTaskTemplates/TaskTemplateDetailModal.tsxindex e20dcc17560..98e311792ae 100644--- a/src/features/RecommendTaskTemplates/TaskTemplateDetailModal.tsx+++ b/src/features/RecommendTaskTemplates/TaskTemplateDetailModal.tsx@@ -9,8 +9,8 @@ import { Clock, X } from 'lucide-react';import { memo, useEffect, useMemo } from 'react';import { useTranslation } from 'react-i18next';+import { ConnectorAuthRow } from './ConnectorAuthRow';import { resolveTemplateIcon } from './resolveTemplateIcon';-import { SkillAuthRow } from './SkillAuthRow';import { INTEREST_ICON_MAP, TemplateBriefIcon } from './TemplateBriefIcon';import { useScheduleText } from './useScheduleText';import { useTaskTemplateCreate } from './useTaskTemplateCreate';@@ -83,7 +83,7 @@ const TaskTemplateDetailContent = memo<TaskTemplateDetailContentProps>({visibleAuthSpecs.length > 0 && (<Flexbox gap={6}>{visibleAuthSpecs.map((spec) => (- <SkillAuthRow+ <ConnectorAuthRowdisabled={disabled}key={`${spec.source}:${spec.identifier}`}spec={spec}diff --git a/src/features/RecommendTaskTemplates/providerMeta.ts b/src/features/RecommendTaskTemplates/providerMeta.tsindex dca76fd8608..2db35d38a45 100644--- a/src/features/RecommendTaskTemplates/providerMeta.ts+++ b/src/features/RecommendTaskTemplates/providerMeta.ts@@ -5,7 +5,7 @@ import type {} from '@lobechat/const';import { getComposioAppByIdentifier, getLobehubSkillProviderById } from '@lobechat/const';-export interface SkillProviderMeta {+export interface ConnectorProviderMeta {icon: LobehubSkillProviderType['icon'];identifier: string;label: string;@@ -14,7 +14,7 @@ export interface SkillProviderMeta {export const getProviderMeta = (spec: TaskTemplateConnectorReference,-): SkillProviderMeta | undefined => {+): ConnectorProviderMeta | undefined => {if (spec.source === 'lobehub') {const p = getLobehubSkillProviderById(spec.identifier);if (!p) return undefined;@@ -28,7 +28,7 @@ export const getProviderMeta = (export const findNextUnconnectedSpec = (specs: TaskTemplateConnectorReference[] | undefined,isConnected: (spec: TaskTemplateConnectorReference) => boolean,-): SkillProviderMeta | undefined => {+): ConnectorProviderMeta | undefined => {if (!specs || specs.length === 0) return undefined;for (const spec of specs) {if (isConnected(spec)) continue;diff --git a/src/features/RecommendTaskTemplates/resolveTemplateIcon.test.ts b/src/features/RecommendTaskTemplates/resolveTemplateIcon.test.tsindex 64288b4ce06..a05bd7d410f 100644--- a/src/features/RecommendTaskTemplates/resolveTemplateIcon.test.ts+++ b/src/features/RecommendTaskTemplates/resolveTemplateIcon.test.ts@@ -28,7 +28,7 @@ describe('resolveTemplateIcon', () => {expect(spec).toEqual({ Comp: SiGithub, kind: 'component' });});- it('falls back to a required skill provider icon (component form)', () => {+ it('falls back to a required connector provider icon (component form)', () => {const spec = resolveTemplateIcon(make({connectors: [{ identifier: 'github', required: true, source: 'lobehub' }],@@ -39,7 +39,7 @@ describe('resolveTemplateIcon', () => {expect(spec).toEqual({ Comp: SiGithub, kind: 'component' });});- it('falls back to a required skill provider icon (URL form)', () => {+ it('falls back to a required connector provider icon (URL form)', () => {const spec = resolveTemplateIcon(make({connectors: [{ identifier: 'gmail', required: true, source: 'composio' }],@@ -64,7 +64,7 @@ describe('resolveTemplateIcon', () => {expect(spec).toEqual({ Comp: SiGithub, kind: 'component' });});- it('falls back to optional skill icon when required is absent', () => {+ it('falls back to optional connector icon when required is absent', () => {const spec = resolveTemplateIcon(make({connectors: [{ identifier: 'notion', required: false, source: 'lobehub' }],@@ -90,7 +90,7 @@ describe('resolveTemplateIcon', () => {if (spec.kind === 'url') expect(spec.src).toMatch(/notion/);});- it('uses interest icon when self and skill icons are absent', () => {+ it('uses interest icon when self and connector icons are absent', () => {const spec = resolveTemplateIcon(make({ interests: ['coding'] }), interestMap);expect(spec).toEqual({ Comp: BookOpen, kind: 'component' });});diff --git a/src/features/RecommendTaskTemplates/resolveTemplateIcon.ts b/src/features/RecommendTaskTemplates/resolveTemplateIcon.tsindex 1f945b40a17..c2cd67843ac 100644--- a/src/features/RecommendTaskTemplates/resolveTemplateIcon.ts+++ b/src/features/RecommendTaskTemplates/resolveTemplateIcon.ts@@ -53,9 +53,9 @@ export const resolveTemplateIcon = (};/**- * The skill spec whose visual the card's main icon already represents.+ * The connector spec whose visual the card's main icon already represents.*- * Mirrors the self/skill branches of `resolveTemplateIcon` so callers can hide+ * Mirrors the self/connector branches of `resolveTemplateIcon` so callers can hide* that provider from inline lists (e.g. the auth row) to avoid showing the* same logo twice on a card. Returns `undefined` when the main icon falls back* to the interest icon or `Sparkles` — those carry no provider semantics.diff --git a/src/features/RecommendTaskTemplates/useConnectorConnection.test.ts b/src/features/RecommendTaskTemplates/useConnectorConnection.test.tsnew file mode 100644index 00000000000..e41153351e7--- /dev/null+++ b/src/features/RecommendTaskTemplates/useConnectorConnection.test.ts@@ -0,0 +1,124 @@+/**+ * @vitest-environment happy-dom+ */+import type { TaskTemplateConnectorReference } from '@lobechat/const';+import { act, renderHook } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import {+ ConnectorConnectionMarketAuthRequiredError,+ useConnectorConnection,+} from './useConnectorConnection';++const mocks = vi.hoisted(() => ({+ marketAuth: {+ isAuthenticated: false,+ signIn: vi.fn(),+ },+ toolState: {+ checkLobehubSkillStatus: vi.fn(),+ composioServers: [],+ createComposioConnection: vi.fn(),+ getLobehubSkillAuthorizeUrl: vi.fn(),+ lobehubSkillServers: [],+ refreshComposioConnectionStatus: vi.fn(),+ },+}));++vi.mock('@/layout/AuthProvider/MarketAuth', () => ({+ useMarketAuth: () => mocks.marketAuth,+}));++vi.mock('@/store/tool', () => ({+ useToolStore: <T>(selector: (state: typeof mocks.toolState) => T): T => selector(mocks.toolState),+}));++vi.mock('@/store/user', () => ({+ useUserStore: {+ getState: () => ({ user: { id: 'user-id' } }),+ },+}));++const lobehubSpec: TaskTemplateConnectorReference = { identifier: 'linear', source: 'lobehub' };++describe('useConnectorConnection', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ mocks.marketAuth.isAuthenticated = false;+ mocks.marketAuth.signIn.mockResolvedValue(null);+ mocks.toolState.composioServers = [];+ mocks.toolState.lobehubSkillServers = [];+ mocks.toolState.getLobehubSkillAuthorizeUrl.mockResolvedValue({+ authorizeUrl: 'https://market.example.com/oauth/authorize',+ code: 'code',+ expiresIn: 600,+ });+ vi.spyOn(window, 'open').mockReturnValue({+ close: vi.fn(),+ closed: false,+ } as unknown as Window);+ });++ afterEach(() => {+ vi.restoreAllMocks();+ });++ it('asks the user to sign in to Market before requesting LobeHub connector OAuth', async () => {+ const { result } = renderHook(() => useConnectorConnection([lobehubSpec]));++ let error: unknown;+ await act(async () => {+ try {+ await result.current.connect();+ } catch (caughtError) {+ error = caughtError;+ }+ });++ expect(error).toBeInstanceOf(ConnectorConnectionMarketAuthRequiredError);+ expect(mocks.marketAuth.signIn).toHaveBeenCalledWith('connector');+ expect(mocks.toolState.getLobehubSkillAuthorizeUrl).not.toHaveBeenCalled();+ expect(window.open).not.toHaveBeenCalled();+ });++ it('opens provider OAuth directly when Market is authenticated', async () => {+ mocks.marketAuth.isAuthenticated = true;+ const { result, unmount } = renderHook(() => useConnectorConnection([lobehubSpec]));++ await act(async () => {+ await result.current.connect();+ });++ expect(mocks.marketAuth.signIn).not.toHaveBeenCalled();+ expect(mocks.toolState.getLobehubSkillAuthorizeUrl).toHaveBeenCalledWith('linear', {+ redirectUri: expect.stringContaining('/oauth/callback/success?provider=linear'),+ });+ expect(window.open).toHaveBeenCalledWith(+ 'https://market.example.com/oauth/authorize',+ '_blank',+ 'width=600,height=700',+ );++ unmount();+ });++ it('turns Market 401 from the authorize URL request into a silent auth interruption', async () => {+ mocks.marketAuth.isAuthenticated = true;+ mocks.toolState.getLobehubSkillAuthorizeUrl.mockRejectedValue({+ data: { code: 'UNAUTHORIZED', httpStatus: 401 },+ });+ const { result } = renderHook(() => useConnectorConnection([lobehubSpec]));++ let error: unknown;+ await act(async () => {+ try {+ await result.current.connect();+ } catch (caughtError) {+ error = caughtError;+ }+ });++ expect(error).toBeInstanceOf(ConnectorConnectionMarketAuthRequiredError);+ expect(window.open).not.toHaveBeenCalled();+ });+});diff --git a/src/features/RecommendTaskTemplates/useSkillConnection.ts b/src/features/RecommendTaskTemplates/useConnectorConnection.tssimilarity index 82%rename from src/features/RecommendTaskTemplates/useSkillConnection.tsrename to src/features/RecommendTaskTemplates/useConnectorConnection.tsindex a857144c478..38953a46433 100644--- a/src/features/RecommendTaskTemplates/useSkillConnection.ts+++ b/src/features/RecommendTaskTemplates/useConnectorConnection.ts@@ -3,6 +3,7 @@ import { COMPOSIO_APP_TYPES } from '@lobechat/const';import { useCallback, useEffect, useMemo, useRef, useState } from 'react';import { LOBEHUB_SKILL_AUTH_SUCCESS_MESSAGE } from '@/const/skillConnection';+import { useMarketAuth } from '@/layout/AuthProvider/MarketAuth';import { useToolStore } from '@/store/tool';import { composioStoreSelectors } from '@/store/tool/slices/composioStore/selectors';import { ComposioServerStatus } from '@/store/tool/slices/composioStore/types';@@ -10,13 +11,13 @@ import { lobehubSkillStoreSelectors } from '@/store/tool/slices/lobehubSkillStorimport { LobehubSkillStatus } from '@/store/tool/slices/lobehubSkillStore/types';import { useUserStore } from '@/store/user';-import type { SkillProviderMeta } from './providerMeta';+import type { ConnectorProviderMeta } from './providerMeta';import { findNextUnconnectedSpec } from './providerMeta';// Re-exported for callers that prefer a single import surface for the hook +// its types/helpers. The pure helpers themselves live in `./providerMeta` so// unit tests can import them without dragging in the store-dependency graph.-export type { SkillProviderMeta } from './providerMeta';+export type { ConnectorProviderMeta } from './providerMeta';export { findNextUnconnectedSpec, getProviderMeta } from './providerMeta';const POLL_INTERVAL_MS = 1000;@@ -26,30 +27,48 @@ const POLL_TIMEOUT_MS = 15_000;const OAUTH_OVERALL_TIMEOUT_MS = 5 * 60 * 1000;/** Thrown when the browser blocks the OAuth popup so callers can surface a clear hint. */-export class SkillConnectionPopupBlockedError extends Error {+export class ConnectorConnectionPopupBlockedError extends Error {constructor() {super('Browser popup blocked');- this.name = 'SkillConnectionPopupBlockedError';+ this.name = 'ConnectorConnectionPopupBlockedError';}}-type ConnectTarget = Pick<SkillProviderMeta, 'identifier' | 'source'>;+/** Thrown when connecting a LobeHub connector first needs Market auth. */+export class ConnectorConnectionMarketAuthRequiredError extends Error {+ constructor() {+ super('Market auth required before connecting LobeHub connector');+ this.name = 'ConnectorConnectionMarketAuthRequiredError';+ }+}++const isRecord = (value: unknown): value is Record<string, unknown> =>+ typeof value === 'object' && value !== null;++const isMarketUnauthorizedError = (error: unknown): boolean => {+ if (!isRecord(error)) return false;+ const data = error.data;+ if (!isRecord(data)) return false;+ return data.httpStatus === 401 || data.code === 'UNAUTHORIZED';+};-export interface UseSkillConnectionResult {+type ConnectTarget = Pick<ConnectorProviderMeta, 'identifier' | 'source'>;++export interface UseConnectorConnectionResult {connect: () => Promise<void>;isAllConnected: boolean;isConnecting: boolean;/** True when there is at least one spec and at least one of them is not yet connected. */needsConnect: boolean;/** First spec in input order whose connection is missing. undefined when all connected or specs is empty. */- nextUnconnected: SkillProviderMeta | undefined;+ nextUnconnected: ConnectorProviderMeta | undefined;}/**- * Shared predicate for both `useSkillConnection` and ad-hoc filtering+ * Shared predicate for both `useConnectorConnection` and ad-hoc filtering* (e.g. hiding already-connected providers from the inline auth list).*/-export const useIsSkillConnected = () => {+export const useIsConnectorConnected = () => {const lobehubServers = useToolStore(lobehubSkillStoreSelectors.getServers);const composioServers = useToolStore(composioStoreSelectors.getServers);@@ -68,15 +87,16 @@ export const useIsSkillConnected = () => {);};-export const useSkillConnection = (+export const useConnectorConnection = (specs: TaskTemplateConnectorReference[] | undefined,-): UseSkillConnectionResult => {+): UseConnectorConnectionResult => {const getLobehubAuth = useToolStore((s) => s.getLobehubSkillAuthorizeUrl);const checkLobehubStatus = useToolStore((s) => s.checkLobehubSkillStatus);const createComposioConnection = useToolStore((s) => s.createComposioConnection);const refreshComposioConnectionStatus = useToolStore((s) => s.refreshComposioConnectionStatus);+ const { isAuthenticated: isMarketAuthenticated, signIn: signInMarket } = useMarketAuth();- const isConnectedFor = useIsSkillConnected();+ const isConnectedFor = useIsConnectorConnected();const nextUnconnected = useMemo(() => findNextUnconnectedSpec(specs, isConnectedFor),@@ -216,7 +236,7 @@ export const useSkillConnection = (// Popup blocked — abandon the flow so the caller can surface a clear// error instead of polling forever for an auth that never started.setIsWaitingAuth(false);- throw new SkillConnectionPopupBlockedError();+ throw new ConnectorConnectionPopupBlockedError();}oauthWindowRef.current = oauthWindow;startWindowMonitor(oauthWindow, target);@@ -224,7 +244,7 @@ export const useSkillConnection = ([cleanup, startWindowMonitor],);- // Only LobeHub Skill OAuth signals completion via postMessage; Composio relies on polling.+ // Only LobeHub connector OAuth signals completion via postMessage; Composio relies on polling.useEffect(() => {const handler = (event: MessageEvent) => {if (event.origin !== window.location.origin) return;@@ -249,6 +269,14 @@ export const useSkillConnection = (setIsConnecting(true);try {if (next.source === 'lobehub') {+ if (!isMarketAuthenticated) {+ try {+ await signInMarket('connector');+ } catch {+ // MarketAuthProvider already surfaces auth failures; task templates only need to stop this run.+ }+ throw new ConnectorConnectionMarketAuthRequiredError();+ }// Skip redirectUri on desktop (app:// protocol) since the system browser can't navigate to itconst redirectUri = window.location.protocol.startsWith('http')? `${window.location.origin}/oauth/callback/success?provider=${encodeURIComponent(next.identifier)}`@@ -276,7 +304,11 @@ export const useSkillConnection = (throw new Error('Composio server is missing an OAuth URL');}} catch (error) {- console.error('[useSkillConnection] Failed to connect:', error);+ if (error instanceof ConnectorConnectionMarketAuthRequiredError) throw error;+ if (next.source === 'lobehub' && isMarketUnauthorizedError(error)) {+ throw new ConnectorConnectionMarketAuthRequiredError();+ }+ console.error('[useConnectorConnection] Failed to connect:', error);throw error;} finally {isConnectingRef.current = false;@@ -285,6 +317,8 @@ export const useSkillConnection = (}, [nextUnconnected,isWaitingAuth,+ isMarketAuthenticated,+ signInMarket,getLobehubAuth,createComposioConnection,refreshComposioConnectionStatus,diff --git a/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.test.ts b/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.test.tsindex a590c9b5294..54d85207060 100644--- a/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.test.ts+++ b/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.test.ts@@ -18,7 +18,7 @@ const {mockMutate,mockSetRefreshSeed,mockUseFetchBriefs,- mockUseFetchLobehubSkillConnections,+ mockUseFetchLobehubConnectorConnections,mockUseFetchUserComposioConnections,mockUseResolvedInterestKeys,mockUseSWR,@@ -26,7 +26,7 @@ const {mockMutate: vi.fn(),mockSetRefreshSeed: vi.fn(),mockUseFetchBriefs: vi.fn(),- mockUseFetchLobehubSkillConnections: vi.fn(),+ mockUseFetchLobehubConnectorConnections: vi.fn(),mockUseFetchUserComposioConnections: vi.fn(),mockUseResolvedInterestKeys: vi.fn(),mockUseSWR: vi.fn(),@@ -64,7 +64,7 @@ vi.mock('@/store/brief', () => ({vi.mock('@/store/tool', () => ({useToolStore: (selector: (state: any) => unknown) =>selector({- useFetchLobehubSkillConnections: mockUseFetchLobehubSkillConnections,+ useFetchLobehubSkillConnections: mockUseFetchLobehubConnectorConnections,useFetchUserComposioConnections: mockUseFetchUserComposioConnections,}),}));diff --git a/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.ts b/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.tsindex c8844d2eeeb..6c15d030569 100644--- a/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.ts+++ b/src/features/RecommendTaskTemplates/useDailyBriefRecommendationsUI.ts@@ -214,9 +214,11 @@ export function useDailyBriefRecommendationsUI(return sources;}, [templates]);const useFetchUserComposioConnections = useToolStore((s) => s.useFetchUserComposioConnections);- const useFetchLobehubSkillConnections = useToolStore((s) => s.useFetchLobehubSkillConnections);+ const useFetchLobehubConnectorConnections = useToolStore(+ (s) => s.useFetchLobehubSkillConnections,+ );useFetchUserComposioConnections(requiredSources.has('composio'));- useFetchLobehubSkillConnections(requiredSources.has('lobehub'));+ useFetchLobehubConnectorConnections(requiredSources.has('lobehub'));const displayMode = resolveDailyBriefRecommendationDisplayMode({canFetchRecommendations,diff --git a/src/features/RecommendTaskTemplates/useTaskTemplateCreate.test.ts b/src/features/RecommendTaskTemplates/useTaskTemplateCreate.test.tsnew file mode 100644index 00000000000..149e983a174--- /dev/null+++ b/src/features/RecommendTaskTemplates/useTaskTemplateCreate.test.ts@@ -0,0 +1,27 @@+import { describe, expect, it } from 'vitest';++import {+ ConnectorConnectionMarketAuthRequiredError,+ ConnectorConnectionPopupBlockedError,+} from './useConnectorConnection';+import { resolveTaskTemplateConnectErrorMessageKey } from './useTaskTemplateCreate';++describe('resolveTaskTemplateConnectErrorMessageKey', () => {+ it('suppresses task template toast when Market auth interrupted the connector flow', () => {+ expect(+ resolveTaskTemplateConnectErrorMessageKey(new ConnectorConnectionMarketAuthRequiredError()),+ ).toBeUndefined();+ });++ it('keeps the popup-blocked message for OAuth popup failures', () => {+ expect(+ resolveTaskTemplateConnectErrorMessageKey(new ConnectorConnectionPopupBlockedError()),+ ).toBe('action.connect.popupBlocked');+ });++ it('falls back to the generic connector error for other failures', () => {+ expect(resolveTaskTemplateConnectErrorMessageKey(new Error('network failed'))).toBe(+ 'action.connect.error',+ );+ });+});diff --git a/src/features/RecommendTaskTemplates/useTaskTemplateCreate.ts b/src/features/RecommendTaskTemplates/useTaskTemplateCreate.tsindex f68a0c9a5dc..6005b34d8a4 100644--- a/src/features/RecommendTaskTemplates/useTaskTemplateCreate.ts+++ b/src/features/RecommendTaskTemplates/useTaskTemplateCreate.ts@@ -11,7 +11,11 @@ import { useAgentStore } from '@/store/agent';import { builtinAgentSelectors } from '@/store/agent/selectors';import { useTaskStore } from '@/store/task';-import { SkillConnectionPopupBlockedError, useSkillConnection } from './useSkillConnection';+import {+ ConnectorConnectionMarketAuthRequiredError,+ ConnectorConnectionPopupBlockedError,+ useConnectorConnection,+} from './useConnectorConnection';interface UseTaskTemplateCreateOptions {description: string;@@ -30,6 +34,16 @@ export interface UseTaskTemplateCreateResult {primaryButtonLabel: string;}+type ConnectErrorMessageKey = 'action.connect.error' | 'action.connect.popupBlocked';++export const resolveTaskTemplateConnectErrorMessageKey = (+ error: unknown,+): ConnectErrorMessageKey | undefined => {+ if (error instanceof ConnectorConnectionMarketAuthRequiredError) return undefined;+ if (error instanceof ConnectorConnectionPopupBlockedError) return 'action.connect.popupBlocked';+ return 'action.connect.error';+};+export const useTaskTemplateCreate = ({description,onCreated,@@ -48,7 +62,7 @@ export const useTaskTemplateCreate = ({() => template.connectors.filter((connector) => connector.required),[template.connectors],);- const requiredConnection = useSkillConnection(requiredConnectors);+ const requiredConnection = useConnectorConnection(requiredConnectors);const handleCreate = useCallback(async () => {if (!canCreateTask) return;@@ -97,17 +111,15 @@ export const useTaskTemplateCreate = ({const handleConnectError = useCallback((error: unknown) => {- message.error(- error instanceof SkillConnectionPopupBlockedError- ? t('action.connect.popupBlocked')- : t('action.connect.error'),- );+ const messageKey = resolveTaskTemplateConnectErrorMessageKey(error);+ if (!messageKey) return;+ message.error(t(messageKey));},[message, t],);// Drive the "click Add task -> chain OAuth popups -> create task" flow via a- // pending flag instead of awaiting connect(): useSkillConnection returns as+ // pending flag instead of awaiting connect(): useConnectorConnection returns as// soon as the popup opens, with real status arriving through store polling.const [pendingCreate, setPendingCreate] = useState(false);const requiredConnectionRef = useRef(requiredConnection);diff --git a/src/features/RecommendTaskTemplates/useVisibleAuthSpecs.ts b/src/features/RecommendTaskTemplates/useVisibleAuthSpecs.tsindex 6c6d058b087..f8ab99cc1d3 100644--- a/src/features/RecommendTaskTemplates/useVisibleAuthSpecs.ts+++ b/src/features/RecommendTaskTemplates/useVisibleAuthSpecs.ts@@ -2,13 +2,13 @@ import type { TaskTemplate, TaskTemplateConnector } from '@lobechat/const';import { useMemo } from 'react';import { getMainIconProvider } from './resolveTemplateIcon';-import { useIsSkillConnected } from './useSkillConnection';+import { useIsConnectorConnected } from './useConnectorConnection';interface UseVisibleAuthSpecsOptions {/*** Drop the provider already shown as the main card icon to avoid showing the* same logo twice on the recommend card. Modal callers should keep this off:- * surfacing every unconnected skill prevents surprises when "Add task"+ * surfacing every unconnected connector prevents surprises when "Add task"* triggers OAuth.*/hideMainIconProvider?: boolean;@@ -18,7 +18,7 @@ export const useVisibleAuthSpecs = (template: TaskTemplate,{ hideMainIconProvider = false }: UseVisibleAuthSpecsOptions = {},): TaskTemplateConnector[] => {- const isSkillConnected = useIsSkillConnected();+ const isConnectorConnected = useIsConnectorConnected();const mainIconProvider = useMemo(() => (hideMainIconProvider ? getMainIconProvider(template) : undefined),[hideMainIconProvider, template],@@ -26,7 +26,7 @@ export const useVisibleAuthSpecs = (return useMemo(() => {return template.connectors.filter((spec) => {- if (isSkillConnected(spec)) return false;+ if (isConnectorConnected(spec)) return false;if (mainIconProvider &&mainIconProvider.identifier === spec.identifier &&@@ -36,5 +36,5 @@ export const useVisibleAuthSpecs = (}return true;});- }, [template.connectors, isSkillConnected, mainIconProvider]);+ }, [template.connectors, isConnectorConnected, mainIconProvider]);};diff --git a/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx b/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsxindex 4f6e75c21e6..2e90ea98076 100644--- a/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx+++ b/src/layout/AuthProvider/MarketAuth/MarketAuthConfirmModal.tsx@@ -83,8 +83,8 @@ const MarketAuthConfirmModal = memo<MarketAuthConfirmModalProps>(return (<Modalcentered- cancelText={t('authorize.cancel')}- okText={t('authorize.confirm')}+ cancelText={ts('cancel')}+ okText={ts('confirm')}open={open}title={null}width={440}diff --git a/src/layout/AuthProvider/MarketAuth/scenes.test.ts b/src/layout/AuthProvider/MarketAuth/scenes.test.tsindex f33ce538c16..60da05f3ee8 100644--- a/src/layout/AuthProvider/MarketAuth/scenes.test.ts+++ b/src/layout/AuthProvider/MarketAuth/scenes.test.ts@@ -12,6 +12,11 @@ describe('pathToMarketAuthScene', () => {expect(pathToMarketAuthScene('market.installCloudMcp')).toBe('mcp');});+ it('maps Market connector paths to the connector scene', () => {+ expect(pathToMarketAuthScene('market.connectGetAuthorizeUrl')).toBe('connector');+ expect(pathToMarketAuthScene('market.connectCallTool')).toBe('connector');+ });+it('falls back to the default scene for unknown paths', () => {expect(pathToMarketAuthScene('market.followUser')).toBe('default');expect(pathToMarketAuthScene('market.getUserProfile')).toBe('default');diff --git a/src/layout/AuthProvider/MarketAuth/scenes.ts b/src/layout/AuthProvider/MarketAuth/scenes.tsindex 29ba8324596..224229e0c6c 100644--- a/src/layout/AuthProvider/MarketAuth/scenes.ts+++ b/src/layout/AuthProvider/MarketAuth/scenes.ts@@ -6,7 +6,7 @@* while falling back to the generic community-profile copy when unknown.*/-export type MarketAuthScene = 'default' | 'sandbox' | 'mcp';+export type MarketAuthScene = 'default' | 'sandbox' | 'mcp' | 'connector';/*** Infer the scene from a tRPC procedure path (e.g. `market.execInSandbox`).@@ -15,5 +15,6 @@ export type MarketAuthScene = 'default' | 'sandbox' | 'mcp';export const pathToMarketAuthScene = (path: string): MarketAuthScene => {if (path.includes('execInSandbox')) return 'sandbox';if (path.includes('CloudMcp') || path.includes('callCloudMcpEndpoint')) return 'mcp';+ if (path.startsWith('market.connect')) return 'connector';return 'default';};