UNPKG

wowok_agent

Version:

Making It Easy for AI Agents to Communicate, Collaborate, Trade, and Trust.

188 lines (187 loc) 9.82 kB
import { z } from "zod"; export const WipConstraints = { maxImageSize: 2 * 1024 * 1024, maxTotalSize: 10 * 1024 * 1024, maxImageCount: 10, maxTextLength: 10000, schemaUrl: "https://schema.wip.wowok.net/v1", version: "1.0.0", }; export const TextFormatSchema = z .union([ z.literal("plain").describe("Plain text format"), z.literal("markdown").describe("Markdown format"), z.literal("html").describe("HTML format"), ]) .describe("Text content format"); export const ImageMimeTypeSchema = z .union([ z.literal("image/png").describe("PNG image"), z.literal("image/jpeg").describe("JPEG image"), z.literal("image/gif").describe("GIF image"), z.literal("image/webp").describe("WebP image"), ]) .describe("Image MIME type"); export const HashAlgorithmSchema = z .literal("sha256") .describe("Hash algorithm, fixed as sha256"); export const SignatureAlgorithmSchema = z .literal("Ed25519") .describe("Signature algorithm, fixed as Ed25519"); export const WipContentSchema = z .object({ text: z.string().max(WipConstraints.maxTextLength).describe("Text content"), format: TextFormatSchema.describe("Text format"), }) .describe("WIP content"); export const WipMediaSchema = z .object({ id: z.string().describe("Unique media file identifier"), type: ImageMimeTypeSchema.describe("Media file MIME type"), data: z.string().describe("Base64 encoded file data"), filename: z.string().optional().describe("Optional file name"), }) .describe("WIP media file"); export const WipPayloadSchema = z .object({ content: WipContentSchema.describe("Text content"), media: z.array(WipMediaSchema).max(WipConstraints.maxImageCount).describe("Media file array"), }) .describe("WIP content payload"); export const WipSignatureSchema = z .object({ value: z.string().describe("Base64 encoded signature value"), publicKey: z.string().describe("Verification public key (Base64 encoded 32 bytes) or DID"), algorithm: SignatureAlgorithmSchema.describe("Signature algorithm"), address: z.string().optional().describe("Signer address"), }) .describe("WIP digital signature"); export const WipSignatureArraySchema = z .union([WipSignatureSchema, z.array(WipSignatureSchema)]) .describe("Single signature or signature array (supports multi-signature)"); export const WipMetaSchema = z .object({ type: z.literal("wip").describe("File type identifier, fixed as wip"), version: z.string().describe("Format version number"), created: z.string().describe("Creation time (ISO 8601 format)"), hash: z.string().describe("SHA-256 hash of payload, format: sha256:hexString"), algorithm: HashAlgorithmSchema.describe("Hash algorithm identifier"), signature: WipSignatureArraySchema.optional().describe("Optional digital signature"), }) .describe("WIP metadata"); export const WipFileSchema = z .object({ wip: z.string().describe("Root identifier, value is schema URL"), payload: WipPayloadSchema.describe("Content payload"), meta: WipMetaSchema.describe("Metadata"), }) .describe("Complete WIP file structure"); export const ImageSourceSchema = z .object({ source: z.string().describe("Image source path or URL. Supports: 1) Local file path (e.g., '/path/to/image.png', 'C:\\Users\\name\\image.jpg'), 2) Network URL (e.g., 'https://example.com/image.png', 'http://site.com/photo.jpg'), 3) Data URL (e.g., 'data:image/png;base64,iVBORw0K...')"), id: z.string().optional().describe("Optional image ID for reference in the WIP content. If not provided, an ID will be auto-generated based on index (e.g., 'image_0', 'image_1')"), filename: z.string().optional().describe("Optional file name. If not provided, will be extracted from URL path or local file name"), }) .describe("Image source for WIP generation"); export const WipGenerationOptionsSchema = z .object({ markdown_text: z.string().max(WipConstraints.maxTextLength).describe("Markdown formatted text content"), images: z.array(ImageSourceSchema).max(WipConstraints.maxImageCount).optional().describe("Optional image list"), account: z.string().optional().describe("Optional signing account (account name or address). If specified, uses Account module for signing"), }) .required({ markdown_text: true }) .describe("WIP generation options"); export const WipSignatureVerificationSchema = z .object({ publicKey: z.string().describe("Signature public key"), address: z.string().optional().describe("Address derived from public key"), valid: z.boolean().describe("Whether signature is valid"), }) .describe("Single signature verification result"); export const WipVerificationResultSchema = z .object({ valid: z.boolean().describe("Whether verification passed"), error: z.string().optional().describe("Error message (when verification fails)"), hashValid: z.boolean().describe("Whether hash verification passed"), signatureValid: z.boolean().optional().describe("Whether signature verification passed (when signature exists)"), hasSignature: z.boolean().describe("Whether signature exists"), signatures: z.array(WipSignatureVerificationSchema).optional().describe("Signature verification details list"), }) .catchall(z.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))) .describe("WIP verification result"); export const WipToHtmlOptionsSchema = z .object({ title: z.string().optional().describe("HTML page title"), theme: z.union([z.literal("light"), z.literal("dark")]).optional().describe("Theme style"), outputPath: z.string().optional().describe("Output file path (if specified, saves to file). For single file: saves HTML to this path. For directory: saves all converted HTML files to this directory"), }) .describe("WIP to HTML conversion options"); export const GenerateWip_InputSchema = z .object({ options: WipGenerationOptionsSchema.describe("WIP generation options"), outputPath: z.string().describe("Output file path (.wip file). If file exists, it will be overwritten"), }) .describe("Generate WIP file tool input parameters"); export const VerifyWip_InputSchema = z .object({ wipFilePath: z.string().describe("WIP file path to verify. Supports: 1) Local file path (e.g., '/path/to/file.wip', 'C:\\Users\\name\\doc.wip'), 2) Network URL (e.g., 'https://example.com/doc.wip', 'http://site.com/file.wip'), 3) Data URL (e.g., 'data:application/json;base64,eyJ3aXAiOi...')"), hash_equal: z.string().optional().describe("Optional expected hash value. If provided, the function will first verify if the file's hash matches this value. If not matched, returns hash mismatch error."), requireSignature: z.boolean().optional().describe("Optional flag to require digital signature. If true, verification will fail if WIP file has no signature"), }) .describe("Verify WIP file tool input parameters"); export const SignWip_InputSchema = z .object({ wipFilePath: z.string().describe("WIP file path to sign. Supports: 1) Local file path (e.g., '/path/to/file.wip'), 2) Network URL (e.g., 'https://example.com/doc.wip'). The file will be loaded, validated, and signed"), account: z.string().optional().describe("Signing account (account name or address). If not specified, uses default account"), outputPath: z.string().optional().describe("Output file path. If not specified, adds 'signed_' prefix to original file name (e.g., 'doc.wip' becomes 'signed_doc.wip')"), }) .describe("Sign WIP file tool input parameters"); export const Wip2Html_InputSchema = z .object({ wipPath: z.string().describe("WIP file path or directory path. Supports: 1) Single WIP file (e.g., '/path/to/file.wip'), 2) Directory containing .wip files (e.g., '/path/to/wips/'), 3) Network URL (e.g., 'https://example.com/doc.wip'). When directory is provided, all .wip files in the directory will be converted to HTML"), options: WipToHtmlOptionsSchema.optional().describe("Conversion options"), }) .describe("WIP to HTML tool input parameters"); export const GenerateWip_OutputSchema = z .object({ filePath: z.string().describe("Generated WIP file path"), }) .describe("Generate WIP file tool output result"); export const VerifyWip_OutputSchema = WipVerificationResultSchema.describe("Verify WIP file tool output result"); export const SignWip_OutputSchema = z .object({ filePath: z.string().describe("Signed WIP file path"), }) .describe("Sign WIP file tool output result"); export const Wip2Html_OutputSchema = z .object({ html: z.string().optional().describe("HTML string content (when converting single file without outputPath)"), filePath: z.string().optional().describe("Output file path (when outputPath is specified)"), files: z.array(z.string()).optional().describe("Converted file path array (when processing directory)"), }) .describe("WIP to HTML tool output result"); export const WipOperationOutputSchema = z.discriminatedUnion("type", [ z.object({ type: z.literal("generate"), filePath: z.string(), }), z.object({ type: z.literal("verify"), valid: z.boolean(), error: z.string().optional(), hashValid: z.boolean(), signatureValid: z.boolean().optional(), hasSignature: z.boolean(), signatures: z.array(z.any()).optional(), }), z.object({ type: z.literal("sign"), filePath: z.string(), }), z.object({ type: z.literal("wip2html"), html: z.string().optional(), filePath: z.string().optional(), files: z.array(z.string()).optional(), }), ]).describe("WIP operation output schema with discriminator");