diff --git a/src/components/AgentsAPIViewer/APIViewer.tsx b/src/components/AgentsAPIViewer/APIViewer.tsx new file mode 100644 index 000000000..987017da6 --- /dev/null +++ b/src/components/AgentsAPIViewer/APIViewer.tsx @@ -0,0 +1,294 @@ +import { useCallback, useEffect, useState } from "react"; + +interface OpenAPIInfo { + title: string; + description: string; +} + +interface OpenAPIParameter { + name: string; + in: string; + description: string; + required: boolean; + schema?: any; + example?: any; +} + +interface OpenAPIExample { + summary: string; + value: any; +} + +interface OpenAPIContent { + schema?: any; + examples?: Record; +} + +interface OpenAPIResponse { + description: string; + content?: Record; +} + +interface OpenAPIRequestBody { + required?: boolean; + content?: Record; +} + +interface OpenAPIMethod { + summary: string; + description: string; + parameters?: OpenAPIParameter[]; + requestBody?: OpenAPIRequestBody; + responses: Record; +} + +interface OpenAPIData { + openapi: string; + info: OpenAPIInfo; + paths: Record>; + components: any; + tags: Array<{ name: string }>; +} + +const APIViewer = () => { + // Fetch the OpenAPI spec at build time + const [apiData, setApiData] = useState(); + const [error, setError] = useState(); + + const fetchData = useCallback(async () => { + try { + const response = await fetch("https://api.fleek.xyz/api/openapi.json"); + if (!response.ok) { + throw new Error( + `Failed to fetch API spec: ${response.status} ${response.statusText}`, + ); + } + + const fullData = await response.json(); + + const aiAgentsPaths: Record> = {}; + + for (const [path, methods] of Object.entries(fullData.paths)) { + if (path.includes("ai-agents")) { + aiAgentsPaths[path] = methods as Record; + } + } + + setApiData({ + openapi: fullData.openapi, + info: fullData.info, + paths: aiAgentsPaths, + components: fullData.components, + tags: fullData.tags.filter( + (tag: { name: string }) => tag.name === "AI Agents", + ), + }); + } catch (err) { + console.error("Error fetching or parsing OpenAPI spec:", err); + setError("Failed to load API documentation. Please try again later."); + } + }, []); + + useEffect(() => { + fetchData(); + }, [fetchData]); + + function getMethodColor(method: string): string { + switch (method.toLowerCase()) { + case "get": + return "bg-blue-500"; + case "post": + return "bg-green-500"; + case "put": + return "bg-yellow-dark-8"; + case "delete": + return "bg-red-dark-8"; + default: + return "bg-gray-500"; + } + } + + function formatJSON(obj: any): string { + return JSON.stringify(obj, null, 2); + } + + if (error) { + return
{error}
; + } + + if (!apiData) { + return
Loading API documentation...
; + } + + return ( +
+
+ {Object.entries(apiData.paths).map(([path, methods]) => ( +
+

{path}

+ +
+ {Object.entries(methods).map(([method, details]) => ( +
+
+ + {method} + + {details.summary} +
+ +
+ {details.description} +
+ + {details.parameters && details.parameters.length > 0 && ( +
+

+ Parameters: +

+
    + {details.parameters.map((param) => ( +
  • + {param.name} + {param.required && ( + * + )} + ({param.in}) - + {param.description} + {param.example && ( +
    + + Example:{" "} + + + {param.example.toString()} + +
    + )} +
  • + ))} +
+
+ )} + + {details.requestBody && ( +
+

+ Request Body: +

+
+ {details.requestBody.required && ( + Required. + )} + {details.requestBody.content && + Object.entries(details.requestBody.content).map( + ([contentType, content]) => ( +
+
+ + {contentType} + +
+ + {/* Request Body Examples */} + {content.examples && + Object.keys(content.examples).length > 0 && ( +
+
+ Examples: +
+
+ {Object.entries(content.examples).map( + ([exampleName, example]) => ( +
+ + {example.summary || exampleName} + + + {formatJSON(example.value)} + +
+ ), + )} +
+
+ )} +
+ ), + )} +
+
+ )} + +
+

Responses:

+
+ {Object.entries(details.responses).map( + ([status, response]) => ( +
+
Status: {status}
+
+ {response.description} +
+ + {/* Response Examples */} + {response.content && + Object.entries(response.content).map( + ([contentType, content]) => ( +
+
+ {contentType} +
+ + {content.examples && + Object.keys(content.examples).length > + 0 && ( +
+
+ + View Example + +
+ {Object.entries( + content.examples, + ).map( + ([exampleName, example]) => ( +
+ {example.summary && ( +
+ {example.summary} +
+ )} + + {formatJSON( + example.value, + )} + +
+ ), + )} +
+
+
+ )} +
+ ), + )} +
+ ), + )} +
+
+
+ ))} +
+
+ ))} +
+
+ ); +}; + +export default APIViewer; diff --git a/src/content/docs/ai-agents/Agents-APIs/index.mdx b/src/content/docs/ai-agents/Agents-APIs/index.mdx index 81d247b93..5f68a05ef 100644 --- a/src/content/docs/ai-agents/Agents-APIs/index.mdx +++ b/src/content/docs/ai-agents/Agents-APIs/index.mdx @@ -5,6 +5,8 @@ date: 2025-01-24 desc: AI agent APIs from Fleek. --- +import AIAgentsAPIViewer from '@base/components/AgentsAPIViewer/APIViewer.tsx'; + # Fleek AI Agent APIs :::info @@ -103,3 +105,11 @@ fetch('https://api.fleek.xyz/api/v1/ai-agents/12345/api/message', { ``` For more details, check the full API docs . + +## Agent API endpoints + +:::note +Each request to the Fleek AI agent API must include the `X-Api-Key` header with the API key you generated. +::: + +