-
Notifications
You must be signed in to change notification settings - Fork 0
Publish integrations.sh discovery metadata #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { createHash } from "node:crypto"; | ||
|
|
||
| import { ORIGIN } from "@/lib/auth/config"; | ||
| import { | ||
| SKILL_DESCRIPTION, | ||
| SKILL_MARKDOWN, | ||
| SKILL_NAME, | ||
| } from "@/lib/skill-content"; | ||
|
|
||
| export const dynamic = "force-static"; | ||
|
|
||
| const digest = createHash("sha256").update(SKILL_MARKDOWN).digest("hex"); | ||
| const BODY = JSON.stringify({ | ||
| $schema: "https://schemas.agentskills.io/discovery/0.2.0/schema.json", | ||
| skills: [ | ||
| { | ||
| name: SKILL_NAME, | ||
| type: "skill-md", | ||
| description: SKILL_DESCRIPTION, | ||
| url: `${ORIGIN}/.well-known/agent-skills/${SKILL_NAME}/SKILL.md`, | ||
| digest: `sha256:${digest}`, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export function GET(): Response { | ||
| return new Response(BODY, { | ||
| headers: { | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { SKILL_MARKDOWN } from "@/lib/skill-content"; | ||
|
|
||
| export const dynamic = "force-static"; | ||
|
|
||
| export function GET(): Response { | ||
| return new Response(SKILL_MARKDOWN, { | ||
| headers: { | ||
| "Content-Type": "text/markdown; charset=utf-8", | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { ORIGIN } from "@/lib/auth/config"; | ||
|
|
||
| export const dynamic = "force-static"; | ||
|
|
||
| const DISCOVERY_URL = `${ORIGIN}/.well-known/integrations.json`; | ||
| const basis = { via: "declared", source: DISCOVERY_URL } as const; | ||
|
|
||
| const BODY = JSON.stringify({ | ||
| version: 3, | ||
| summary: | ||
| "Publish, share, edit, and discuss HTML documents through the justhtml.sh HTTP API.", | ||
| credentials: { | ||
| "justhtml-api-key": { | ||
| type: "api_key", | ||
| label: "justhtml.sh API key", | ||
| generateUrl: `${ORIGIN}/auth.md`, | ||
| setup: | ||
| "Follow the [agent authentication flow](https://justhtml.sh/auth.md): register the human's email, have them read back the emailed 6-digit code, complete the claim, then poll the token endpoint for the long-lived `jh_live_…` key. Store it securely (the examples use `JUSTHTML_API_KEY`) and send it as a Bearer token.", | ||
| }, | ||
| }, | ||
| surfaces: [ | ||
| { | ||
| type: "http", | ||
| slug: "justhtml-api", | ||
| name: "justhtml.sh HTTP API", | ||
| docs: `${ORIGIN}/llms.txt`, | ||
| spec: `${ORIGIN}/openapi.json`, | ||
| url: `${ORIGIN}/api/v1`, | ||
| basis, | ||
| auth: { | ||
| status: "required", | ||
| entries: [ | ||
| { | ||
| use: [ | ||
| { | ||
| id: "justhtml-api-key", | ||
| mechanics: { | ||
| source: "http", | ||
| in: "header", | ||
| headerName: "Authorization", | ||
| scheme: "Bearer", | ||
| }, | ||
| }, | ||
| ], | ||
| basis, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| export function GET(): Response { | ||
| return new Response(BODY, { | ||
| headers: { | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import spec from "@/lib/openapi/generated.json"; | ||
|
|
||
| export const dynamic = "force-static"; | ||
|
|
||
| const BODY = JSON.stringify(spec); | ||
|
|
||
| export function GET(): Response { | ||
| return new Response(BODY, { | ||
| headers: { | ||
| "Content-Type": "application/json; charset=utf-8", | ||
| "Cache-Control": "public, max-age=3600", | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| import { createHash } from "node:crypto"; | ||
|
|
||
| import { describe, expect, it } from "vitest"; | ||
| import { z } from "zod"; | ||
|
|
||
| import { GET as getSkillIndex } from "@/app/.well-known/agent-skills/index.json/route"; | ||
| import { GET as getSkill } from "@/app/.well-known/agent-skills/just-html/SKILL.md/route"; | ||
| import { GET as getIntegrations } from "@/app/.well-known/integrations.json/route"; | ||
| import { GET as getOpenApi } from "@/app/openapi.json/route"; | ||
|
|
||
| const basis = z | ||
| .object({ | ||
| via: z.literal("declared"), | ||
| source: z.literal("https://justhtml.sh/.well-known/integrations.json"), | ||
| }) | ||
| .strict(); | ||
|
|
||
| const integrationsV3 = z | ||
| .object({ | ||
| version: z.literal(3), | ||
| summary: z.string().optional(), | ||
| credentials: z | ||
| .record( | ||
| z.string(), | ||
| z | ||
| .object({ | ||
| type: z.string(), | ||
| label: z.string(), | ||
| generateUrl: z.string().url().optional(), | ||
| setup: z.string(), | ||
| }) | ||
| .strict() | ||
| ) | ||
| .optional(), | ||
| surfaces: z | ||
| .array( | ||
| z | ||
| .object({ | ||
| type: z.literal("http"), | ||
| slug: z.string(), | ||
| name: z.string(), | ||
| docs: z.string().url().optional(), | ||
| spec: z.string().url().optional(), | ||
| url: z.string().url().optional(), | ||
| basis, | ||
| auth: z | ||
| .object({ | ||
| status: z.literal("required"), | ||
| entries: z.array( | ||
| z | ||
| .object({ | ||
| use: z.array( | ||
| z | ||
| .object({ | ||
| id: z.string(), | ||
| mechanics: z | ||
| .object({ | ||
| source: z.literal("http"), | ||
| in: z.literal("header"), | ||
| headerName: z.string(), | ||
| scheme: z.string(), | ||
| }) | ||
| .strict(), | ||
| }) | ||
| .strict() | ||
| ), | ||
| basis, | ||
| }) | ||
| .strict() | ||
| ), | ||
| }) | ||
| .strict(), | ||
| }) | ||
| .strict() | ||
| ) | ||
| .optional(), | ||
| }) | ||
| .strict(); | ||
|
|
||
| describe("integration discovery", () => { | ||
| it("serves a valid integrations.sh v3 declaration", async () => { | ||
| const response = getIntegrations(); | ||
| expect(response.headers.get("content-type")).toBe("application/json; charset=utf-8"); | ||
| expect(response.headers.get("cache-control")).toBe("public, max-age=3600"); | ||
|
|
||
| const document = integrationsV3.parse(await response.json()); | ||
| expect(document.surfaces).toHaveLength(1); | ||
| expect(document.surfaces?.[0]).toMatchObject({ | ||
| type: "http", | ||
| url: "https://justhtml.sh/api/v1", | ||
| spec: "https://justhtml.sh/openapi.json", | ||
| auth: { | ||
| status: "required", | ||
| entries: [ | ||
| { | ||
| use: [ | ||
| { | ||
| id: "justhtml-api-key", | ||
| mechanics: { | ||
| source: "http", | ||
| in: "header", | ||
| headerName: "Authorization", | ||
| scheme: "Bearer", | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("serves the generated OpenAPI document as JSON", async () => { | ||
| const response = getOpenApi(); | ||
| expect(response.headers.get("content-type")).toBe("application/json; charset=utf-8"); | ||
| expect(response.headers.get("cache-control")).toBe("public, max-age=3600"); | ||
|
|
||
| const document = (await response.json()) as { | ||
| openapi: string; | ||
| servers: Array<{ url: string }>; | ||
| components: { securitySchemes: Record<string, unknown> }; | ||
| }; | ||
| expect(document.openapi).toBe("3.1.0"); | ||
| expect(document.servers).toContainEqual( | ||
| expect.objectContaining({ url: "https://justhtml.sh" }) | ||
| ); | ||
| expect(document.components.securitySchemes).toHaveProperty("bearerApiKey"); | ||
| }); | ||
|
|
||
| it("publishes an Agent Skills index with a matching artifact digest", async () => { | ||
| const indexResponse = getSkillIndex(); | ||
| const skillResponse = getSkill(); | ||
| expect(indexResponse.headers.get("content-type")).toBe("application/json; charset=utf-8"); | ||
| expect(skillResponse.headers.get("content-type")).toBe("text/markdown; charset=utf-8"); | ||
|
|
||
| const index = (await indexResponse.json()) as { | ||
| $schema: string; | ||
| skills: Array<{ name: string; type: string; url: string; digest: string }>; | ||
| }; | ||
| const skill = await skillResponse.text(); | ||
| const digest = createHash("sha256").update(skill).digest("hex"); | ||
|
|
||
| expect(index.$schema).toBe("https://schemas.agentskills.io/discovery/0.2.0/schema.json"); | ||
| expect(index.skills).toEqual([ | ||
| expect.objectContaining({ | ||
| name: "just-html", | ||
| type: "skill-md", | ||
| url: "https://justhtml.sh/.well-known/agent-skills/just-html/SKILL.md", | ||
| digest: `sha256:${digest}`, | ||
| }), | ||
| ]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenAPI route bytes mismatch
Medium Severity
The
GET /openapi.jsonendpoint re-serializes the importedgenerated.jsonusingJSON.stringify(). This produces a compact response that differs byte-for-byte from the pretty-printed, committedlib/openapi/generated.jsonfile. This means the served content doesn't match the canonical artifact validated byspec:check, unlike/api/spec.yaml.Reviewed by Cursor Bugbot for commit 805e270. Configure here.