0.1.0 • Published 1 year ago
@aiplugin/types v0.1.0
@aiplugin/types
Inofficial Typescript types and Zod schema for AIPlugin Specification.
See the AIPlugin Specification
Usage
Install
npm install @aiplugin/types
Import
import type { Manifest } from '@aiplugin/types';
Because the manifest is written using Zod, you can also import the schema and use it to validate your manifest.
import { Manifest } from '@aiplugin/types';
const validManifest = Manifest.parse({});
See the Zod documentation for more information.
Spec
import { z } from 'zod';
export const HttpAuthType = z.enum(['basic', 'bearer']);
type HttpAuthType = z.infer<typeof HttpAuthType>;
export const ManifestNoAuth = z.object({
type: z.literal('none'),
});
export const ManifestServiceAuth = z.object({
type: z.literal('service_http'),
authorization_type: HttpAuthType,
verification_tokens: z.record(z.string()),
});
export const ManifestUserAuth = z.object({
type: z.literal('user_http'),
authorization_type: HttpAuthType,
});
export const ManifestOAuthAuth = z.object({
type: z.literal('oauth'),
client_url: z.string().url(),
scope: z.string(),
authorization_url: z.string().url(),
authorization_content_type: z.string(),
verification_tokens: z.record(z.string()),
});
export const ManifestAuth = z.discriminatedUnion('type', [
ManifestNoAuth,
ManifestServiceAuth,
ManifestUserAuth,
ManifestOAuthAuth,
]);
// Schema definition
export const ManifestSchema = z.object({
schema_version: z.string(),
name_for_model: z.string(),
name_for_human: z.string(),
description_for_model: z.string(),
description_for_human: z.string(),
auth: ManifestAuth,
api: z.record(z.any()),
logo_url: z.string().url(),
contact_email: z.string().email(),
legal_info_url: z.string().url(),
});
export type Manifest = z.infer<typeof ManifestSchema>;
export type ManifestAuth = z.infer<typeof ManifestAuth>;
export type ManifestNoAuth = z.infer<typeof ManifestNoAuth>;
export type ManifestServiceAuth = z.infer<typeof ManifestServiceAuth>;
export type ManifestUserAuth = z.infer<typeof ManifestUserAuth>;
export type ManifestOAuthAuth = z.infer<typeof ManifestOAuthAuth>;