mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 09:01:17 +00:00
add agent schemas
This commit is contained in:
commit
c4153c5335
20 changed files with 2735 additions and 0 deletions
55
resources/agent-schemas/src/opencode.ts
Normal file
55
resources/agent-schemas/src/opencode.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import { fetchWithCache } from "./cache.js";
|
||||
import { createNormalizedSchema, openApiToJsonSchema, type NormalizedSchema } from "./normalize.js";
|
||||
import type { JSONSchema7 } from "json-schema";
|
||||
|
||||
const OPENAPI_URL =
|
||||
"https://raw.githubusercontent.com/sst/opencode/dev/packages/sdk/openapi.json";
|
||||
|
||||
// Key schemas we want to extract
|
||||
const TARGET_SCHEMAS = [
|
||||
"Session",
|
||||
"Message",
|
||||
"Part",
|
||||
"Event",
|
||||
"PermissionRequest",
|
||||
"QuestionRequest",
|
||||
"TextPart",
|
||||
"ToolCallPart",
|
||||
"ToolResultPart",
|
||||
"ErrorPart",
|
||||
];
|
||||
|
||||
interface OpenAPISpec {
|
||||
components?: {
|
||||
schemas?: Record<string, unknown>;
|
||||
};
|
||||
}
|
||||
|
||||
export async function extractOpenCodeSchema(): Promise<NormalizedSchema> {
|
||||
console.log("Extracting OpenCode schema from OpenAPI spec...");
|
||||
|
||||
const specText = await fetchWithCache(OPENAPI_URL);
|
||||
const spec: OpenAPISpec = JSON.parse(specText);
|
||||
|
||||
if (!spec.components?.schemas) {
|
||||
throw new Error("OpenAPI spec missing components.schemas");
|
||||
}
|
||||
|
||||
const definitions: Record<string, JSONSchema7> = {};
|
||||
|
||||
// Extract all schemas, not just target ones, to preserve references
|
||||
for (const [name, schema] of Object.entries(spec.components.schemas)) {
|
||||
definitions[name] = openApiToJsonSchema(schema as Record<string, unknown>);
|
||||
}
|
||||
|
||||
// Verify target schemas exist
|
||||
const missing = TARGET_SCHEMAS.filter((name) => !definitions[name]);
|
||||
if (missing.length > 0) {
|
||||
console.warn(` [warn] Missing expected schemas: ${missing.join(", ")}`);
|
||||
}
|
||||
|
||||
const found = TARGET_SCHEMAS.filter((name) => definitions[name]);
|
||||
console.log(` [ok] Extracted ${Object.keys(definitions).length} schemas (${found.length} target schemas)`);
|
||||
|
||||
return createNormalizedSchema("opencode", "OpenCode SDK Schema", definitions);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue