@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
71 lines • 3.62 kB
TypeScript
import type { StandardSchemaV1 } from '@standard-schema/spec';
/** A JSON Schema document (draft-07 / 2020-12 subset). Plain data, so a catalog can be stored and shipped. */
export type JsonSchema = Record<string, unknown>;
/** One problem with a value, addressed by its path from the root of the value. */
export interface GenuiIssue {
path: (string | number)[];
message: string;
}
export type GenuiValidation<T = unknown> = {
ok: true;
value: T;
} | {
ok: false;
issues: GenuiIssue[];
};
/**
* Validates a value against a JSON Schema. The package ships {@link builtinJsonSchemaValidator} (a
* dependency-free subset that covers what component props use); pass {@link ajvValidator} to a
* catalog for full JSON Schema.
*/
export interface JsonSchemaValidator {
validate(schema: JsonSchema, value: unknown): GenuiIssue[];
}
/** A component's props schema: any Standard Schema (Zod, Valibot, ArkType) or a JSON Schema object. */
export type PropsSchema = StandardSchemaV1 | JsonSchema;
export declare function isStandardSchema(schema: unknown): schema is StandardSchemaV1;
/**
* The JSON Schema a props schema presents to a model: the schema itself for a JSON Schema, the
* Standard JSON Schema converter's output for a Standard Schema that has one (Zod 4, Valibot,
* ArkType). `undefined` when neither is available (e.g. Zod 3) — the model then gets the
* component's description only.
*/
export declare function toJsonSchema(schema: PropsSchema): JsonSchema | undefined;
/** Validate against either kind of props schema. A Standard Schema's own (possibly transformed) output wins. */
export declare function validateProps(schema: PropsSchema, value: unknown, validator: JsonSchemaValidator): Promise<GenuiValidation>;
/**
* {@link validateProps} without waiting: the verdict when it is available synchronously (always
* for JSON Schema, and for every Standard Schema whose `validate` does not return a promise — Zod,
* Valibot and ArkType all answer synchronously for synchronous schemas), `undefined` otherwise. What
* a renderer uses to decide on its first paint instead of flashing a placeholder.
*/
export declare function validatePropsSync(schema: PropsSchema, value: unknown, validator: JsonSchemaValidator): GenuiValidation | undefined;
/** `a.b[0].c: message; …` — what a model is handed back when its props were refused. */
export declare function formatIssues(issues: readonly GenuiIssue[]): string;
/**
* Structural type of an Ajv instance, so the package never imports Ajv: `new Ajv({ allErrors: true })`
* satisfies it.
*/
export interface AjvLike {
compile(schema: object): ((data: unknown) => boolean | Promise<unknown>) & {
errors?: {
instancePath?: string;
message?: string;
}[] | null;
};
}
/**
* Full JSON Schema validation through the app's own Ajv instance. Compiled validators are cached
* per schema object.
*/
export declare function ajvValidator(ajv: AjvLike): JsonSchemaValidator;
/**
* A dependency-free JSON Schema validator for the keywords component props actually use: `type`
* (incl. `integer`, `null`, type arrays), `enum`, `const`, `properties`, `required`,
* `additionalProperties`, `items`, `minItems`/`maxItems`, `minLength`/`maxLength`/`pattern`,
* `minimum`/`maximum`, `anyOf`/`oneOf`/`allOf`, `not`, and local `$ref`s (`#`, `#/$defs/…`,
* `#/definitions/…`). Unknown keywords (e.g. `format`) are ignored. Use {@link ajvValidator} when
* you need the rest.
*/
export declare const builtinJsonSchemaValidator: JsonSchemaValidator;
//# sourceMappingURL=schema.d.ts.map