import { useEffect, useState } from 'react' import { useOutletContext, useParams } from 'react-router-dom' import { api, ApiError } from '../api/client' import { DevToolsPanel } from '../components/DevToolsPanel' import { AcLink, Badge, Card, ErrorText, Notice, SectionTitle, SuccessText } from '../components/ui' import type { ThreadsAccountConnectionData, ThreadsAccountData } from '../types/api' type WorkspaceContext = { accountId: string account: ThreadsAccountData | null loading: boolean error: string } export function ThreadsAccountConnectionsPage() { const { id = '' } = useParams() const { account, loading: workspaceLoading } = useOutletContext() const [connection, setConnection] = useState(null) const [message, setMessage] = useState('') const [error, setError] = useState('') const load = async () => { if (!id) return setError('') const conn = await api.get( `/api/v1/threads-accounts/${encodeURIComponent(id)}/connection`, { auth: true }, ) setConnection(conn) } useEffect(() => { load().catch((e) => setError(e instanceof ApiError ? e.message : '載入連線設定失敗')) }, [id]) const apiReady = !!connection?.api_connected return (
Threads API 連線

正式流程的唯一通道。搜尋、發文、留言都走官方 API;帳號建立後預設使用此模式。

{apiReady ? 'API 已連線' : 'API 尚未設定'}
{apiReady ? ( ) : ( )}

AI 產文用的 API key 在側欄「設定」管理;人設在 人設庫{' '} 建立,發文時於 發文頁 選擇。

{id && connection ? ( { setConnection(data) load().catch(() => undefined) }} onMessage={setMessage} onError={setError} /> ) : null}
) }