import { useMemo, useState } from "react";
import { ArrowUpRightIcon, ThumbsDownIcon, ThumbsUpIcon } from "lucide-react";
import { getDomain } from "tldts";
import { trackEvent } from "../api/analytics";
import { useCredentialGuidance } from "../lib/integrations-sh-catalog";
import { cn } from "../lib/utils";
// ---------------------------------------------------------------------------
// What this key is, and where to get one.
//
// The registry records, per provider, what the credential is called, the page
// that mints it, and the provider's own setup steps. Asking someone for a key
// without any of that is the reason the connect form produced "Okay so what
// type of key do I need?" — the answer existed, one fetch away, and was thrown
// out on arrival.
//
// Strictly supplementary: the form works unchanged when the registry knows
// nothing, and this renders nothing at all rather than an empty frame.
// ---------------------------------------------------------------------------
/** The registry's setup text is markdown. Links, bold and inline code are all
* that occur in practice, so render those three rather than pull a markdown
* pipeline into a form. */
function SetupText(props: { readonly text: string }) {
const nodes = useMemo(
() =>
props.text
.split(/(\[[^\]]+\]\([^)]+\)|\*\*[^*]+\*\*|`[^`]+`)/g)
.filter((chunk) => chunk.length > 0)
.map((chunk, index) => {
const link = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(chunk);
if (link) {
return (
{link[1]}
);
}
const bold = /^\*\*([^*]+)\*\*$/.exec(chunk);
if (bold) {
return (
{bold[1]}
);
}
const code = /^`([^`]+)`$/.exec(chunk);
if (code) {
return (
{code[1]}
);
}
return {chunk};
}),
[props.text],
);
return
{nodes}
; } export function CredentialGuidancePanel(props: { /** The integration's display URL; the domain is read from it. */ readonly displayUrl: string | undefined; /** "oauth" hides key guidance — there is no key to fetch. */ readonly methodKind: string | undefined; }) { const domain = useMemo( () => (props.displayUrl ? getDomain(props.displayUrl) : null), [props.displayUrl], ); const guidance = useCredentialGuidance(domain); const relevant = useMemo(() => { if (props.methodKind === "oauth") { return guidance.find((entry) => entry.type.startsWith("oauth")); } // Anything that is not an OAuth grant is the key the form is asking for. return guidance.find((entry) => !entry.type.startsWith("oauth")) ?? guidance[0]; }, [guidance, props.methodKind]); if (!relevant || (!relevant.generateUrl && !relevant.setup)) return null; return (AI-generated guidance via{" "} integrations.sh