Files
BrowserOS/packages/browseros-agent/scripts/codegen/lib/protocol-parser.ts
Dani Akash 290ee91a8b Add 'packages/browseros-agent/' from commit '90bd4be3008285bf3825aad3702aff98f872671a'
git-subtree-dir: packages/browseros-agent
git-subtree-mainline: 8f148d0918
git-subtree-split: 90bd4be300
2026-03-13 21:22:09 +05:30

58 lines
1.2 KiB
TypeScript

export interface ProtocolProperty {
name: string
description?: string
optional?: boolean
type?: string
$ref?: string
enum?: string[]
items?: { type?: string; $ref?: string }
properties?: ProtocolProperty[]
}
export interface ProtocolType {
id: string
description?: string
type: string
enum?: string[]
properties?: ProtocolProperty[]
items?: { type?: string; $ref?: string }
}
export interface ProtocolCommand {
name: string
description?: string
parameters?: ProtocolProperty[]
returns?: ProtocolProperty[]
}
export interface ProtocolEvent {
name: string
description?: string
parameters?: ProtocolProperty[]
}
export interface ProtocolDomain {
domain: string
description?: string
dependencies?: string[]
types?: ProtocolType[]
commands?: ProtocolCommand[]
events?: ProtocolEvent[]
}
export interface Protocol {
version: { major: string; minor: string }
domains: ProtocolDomain[]
}
export async function parseProtocol(path: string): Promise<Protocol> {
const file = Bun.file(path)
const data = (await file.json()) as Protocol
if (!data.version || !Array.isArray(data.domains)) {
throw new Error(`Invalid protocol JSON: missing version or domains`)
}
return data
}