// settings / ExternalAccessPane.tsx - W63-T06, rulings R4/R14, contract C7. // // This is the shared setup pane opened by the Connectors directory. OAuth clients receive the remote // MCP URL; API-key secrets appear only in the one-time reveal returned by create or rotate. All // editable metadata is seeded again from the server response. // // Setup instructions share one numbered list. Every AI client receives the public starter prompt. import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import type { FormEvent, ReactNode } from "react"; import { Copy } from "@phosphor-icons/react/dist/csr/Copy"; import { Check } from "@phosphor-icons/react/dist/csr/Check"; import { API_V1, CREDENTIALS, UNAUTHORIZED_EVENT, checkTenant } from "../apiContract"; import { Mark } from "../shell/Brand"; import { AiClientMark } from "./aiClientMarks"; import { KeyOpenApiRow, openApiDocumentUrl } from "./KeyOpenApiRow"; import { ExpiryPresets, presetToExpiresAt } from "./ExpiryPresets"; import type { ExpiryPreset } from "./ExpiryPresets"; import { parseTutorialGuide } from "../connectors/ConnectTutorial"; import type { TutorialGuide } from "../connectors/ConnectTutorial"; import "../connectors/connectors.css"; import "../styles/sdlc73/connectors.css"; type Access = "read" | "readwrite"; type ResourceScope = string[] | "all"; type ConnectionKind = "mcp" | "key"; // Copyable instructions never interpolate a stored credential. interface StepAction { label: string; url: string } export interface GuideStep { id?: string; title?: string; text: ReactNode; block?: string; copyValue?: string; action?: StepAction; hint?: string; details?: readonly GuideStep[]; } function GuideInstruction({ text }: { text: string }) { // Split only at an existing sentence or sequencing clause, keeping every character. const boundary = /[.!?](?=\s+[A-Z])|,(?=\s+then\b)/.exec(text); const end = boundary ? boundary.index + 1 : text.length; return
{text.slice(0, end)} {end < text.length ? {text.slice(end)} : null}
; } // S70-T09: the AI setup and connector tutorials share this actual frame and guide renderer. // Each caller owns its steps, fields and actions; the frame makes no requests. export function GuideSteps({ steps, tutorial, finalSteps = [], renderCopy, mode = "full" }: { steps: readonly GuideStep[]; tutorial?: TutorialGuide; finalSteps?: readonly GuideStep[]; renderCopy?: (value: string, index: number, step: GuideStep) => ReactNode; /** Short guides keep preparation and test limits outside the numbered instructions. */ mode?: "full" | "short"; }) { const body: readonly GuideStep[] = tutorial && mode === "full" ? [ { id: "tutorial-need", text: `What you need: ${tutorial.need}` }, ...steps, ...(tutorial.testNote ? [{ id: "tutorial-test", text: `Test: ${tutorial.testNote}` }] : []), { id: "tutorial-failure", text: `If it fails: ${tutorial.failureAction}` }, ] : steps; const entries = [...body, ...finalSteps]; if (!entries.length) return null; const content = (entry: GuideStep, index: number): ReactNode => { const copyValue = entry.copyValue ?? entry.block; return <>{entry.title}
: typeof entry.text === "string" ?{entry.text}
: null} {entry.block ?{entry.block} : null}
{entry.hint ? {entry.hint}
: null} {entry.action ? {entry.action.label} : null} {entry.details?.map((detail, detailIndex) =>{tutorial.need}
: null}{tutorial.testNote}
: null}{tutorial.failureAction}
Choose at least one database for this API key.
: null}{content ?? value}
Copy it now. Loopable cannot show this secret again.
{error}
: null} {notice ?{notice}
: null} {view !== "api" && connectionsLoading ?How should {client.label} reach Loopable?
{keysError}
{view === "client" ? "No saved API keys." : "You have no saved keys yet, so create one here."}
) : !keys.some(keyIsActive) ? ({view === "client" ? "No active API keys." : "No saved key is active. Create one or update its expiry below."}
) : null} {canMint === false ? (Creating API keys requires AI apps access. Ask an administrator for access
) : null} {(shownKeyChoice === "create" || view === "api") && canMint === true ? ( ) : null} {shownKeyChoice === "saved" && client && keys && keys.length > 0 ? ({sharedSteps ? instruction(sharedSteps.keySetup.saved) : null}
{verificationReveal && view !== "client" ?{sharedSteps?.keySetup.saveNew}
: null}Key: {selectedKey.label}
: null} {verificationReveal ?{sharedSteps.verification.newKey}
: ({sharedSteps.verification.savedKey}
{sharedSteps.verification.key}
> ) : ({verifyResult.message}
) : null} > }] : []), ...(starterPrompt ? [{ id: "starter-prompt", text: "Starter prompt", block: starterPrompt, copyValue: starterPrompt, hint: canCopyStarterPrompt ? undefined : "Verify the connection to copy the starter prompt." }] : []), ])} /> : null}Verifying API keys requires AI apps access. Ask an administrator for access
: } {verifyResult ?{verifyResult.message}
: null}| Row | AI app | Status | Access | Databases | Connected | Last used | Actions |
|---|---|---|---|---|---|---|---|
| {index + 1} |
{connection.clientId ? |
{connectionLabel(connection)} | {connection.access === null ? "" : connection.access === "read" ? "Read only" : "Read and write"} | {connection.databases === null ? "" : databaseLabels(connection.databases)} | {when(connection.created)} | {when(connection.last_used)} | {connection.status === "connected" ? ( ) : null} |
You have no API keys yet.
: (