feat(phase-5): WS5 — Developer Experience

Implements scaffold ZIP generator, Stoplight Elements API explorer, and CLI scaffold command:

Scaffold API:
- 25 template files for TypeScript/Python/Go/Java/Rust in src/templates/scaffold/
- ScaffoldService: in-memory ZIP via archiver, variable injection (AGENT_ID/NAME/CLIENT_ID/API_URL)
- ScaffoldController: tenant ownership check (403), language validation (400), ZIP stream response
- Route GET /sdk/scaffold/:agentId with rate limiter (10 req/min per tenant)
- Prometheus: scaffold_generated_total + scaffold_generation_duration_ms histogram

Portal:
- Replaced swagger-ui-react with @stoplight/elements API component
- Dynamic import (ssr: false) for browser-only DOM dependency
- Type declarations for @stoplight/elements and CSS module

CLI:
- sentryagent scaffold --agent-id <id> [--language typescript] [--out .]
- Raw fetch for binary ZIP stream → unzipper.Extract() → prints next steps
- Human-readable 400/403/404 error messages

Tests: 19 tests (unit + integration), ScaffoldService 80%+ branch coverage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
SentryAgent.ai Developer
2026-04-03 02:50:32 +00:00
parent 16497706d3
commit 662879f0ee
42 changed files with 6176 additions and 1741 deletions

View File

@@ -1,38 +1,28 @@
import type React from 'react';
import { SwaggerExplorer } from '@/components/SwaggerExplorer';
'use client';
export const metadata = {
title: 'API Explorer — SentryAgent AgentIdP',
description:
'Interactively explore and test the SentryAgent AgentIdP REST API.',
};
import dynamic from 'next/dynamic';
export default function ApiExplorerPage(): React.ReactElement {
const apiUrl =
process.env.NEXT_PUBLIC_API_URL ?? 'http://localhost:3000';
// @stoplight/elements accesses `document` at module load time,
// so it must be imported client-side only (ssr: false).
const ElementsAPI = dynamic(
async () => {
await import('@stoplight/elements/styles.min.css');
const mod = await import('@stoplight/elements');
return mod.API;
},
{ ssr: false },
);
export default function ApiExplorerPage() {
return (
<div className="px-4 py-8">
<div className="mx-auto max-w-7xl">
<div className="mb-8">
<h1 className="text-3xl font-extrabold text-slate-900">
API Explorer
</h1>
<p className="mt-2 text-slate-600">
Explore, authenticate, and test every AgentIdP endpoint directly
from your browser. Use the Authorize button to set your Bearer
token.
</p>
<p className="mt-1 text-sm text-slate-400">
Spec loaded from:{' '}
<code className="rounded bg-slate-100 px-1.5 py-0.5 text-xs">
{apiUrl}/openapi.json
</code>
</p>
</div>
<SwaggerExplorer apiUrl={apiUrl} />
</div>
</div>
<main className="h-screen w-full">
<ElementsAPI
apiDescriptionUrl={`${process.env.NEXT_PUBLIC_API_URL}/openapi.json`}
router="hash"
layout="sidebar"
hideSchemas={false}
tryItCredentialsPolicy="same-origin"
/>
</main>
);
}

5406
portal/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -9,10 +9,10 @@
"lint": "next lint"
},
"dependencies": {
"@stoplight/elements": "^9.0.16",
"next": "14.2.5",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"swagger-ui-react": "^5.17.14"
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^20.14.0",

29
portal/types/stoplight-elements.d.ts vendored Normal file
View File

@@ -0,0 +1,29 @@
/**
* Type declaration for @stoplight/elements.
* Required because the package's `exports` field does not expose types correctly
* under `moduleResolution: "bundler"`.
*/
declare module '@stoplight/elements' {
import type React from 'react';
export interface APIProps {
/** URL of the OpenAPI description (YAML or JSON). */
apiDescriptionUrl: string;
/** Routing strategy. Use "hash" for static hosting. */
router?: 'hash' | 'memory' | 'history' | 'static';
/** Layout variant. */
layout?: 'sidebar' | 'stacked';
/** Whether to hide schema definitions. */
hideSchemas?: boolean;
/** Credentials policy for the Try It panel. */
tryItCredentialsPolicy?: 'omit' | 'same-origin' | 'include';
}
export const API: React.ComponentType<APIProps>;
}
declare module '@stoplight/elements/styles.min.css' {
const content: string;
export default content;
}