### Install @anima-labs/schemas with npm or bun Source: https://github.com/anima-labs-ai/schemas/blob/main/README.md Install the package using npm or bun. The bun command is an alternative to npm. ```bash npm install @anima-labs/schemas # or bun add @anima-labs/schemas ``` -------------------------------- ### Usage example for MessageListInput, MessageSearchInput, MessageListOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/message.md Example showing how to parse message list and search inputs and outputs using the exported schemas from @anima-labs/schemas. ```typescript import { MessageListInput, MessageSearchInput, MessageListOutput } from "@anima-labs/schemas"; const list = MessageListInput.parse({ agentId: "clxagent1...", direction: "INBOUND" }); const page = MessageListOutput.parse(await api.listMessages(list)); const search = MessageSearchInput.parse({ query: "invoice #{123}", filters: { channel: "EMAIL", status: "DELIVERED" }, pagination: { limit: 50 }, }); ``` -------------------------------- ### FeedbackListInput and FeedbackListOutput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/feedback.md Shows how to parse a FeedbackListInput and FeedbackListOutput. The example uses a limit of 50 and demonstrates accessing the pagination fields. ```typescript import { FeedbackListInput, FeedbackListOutput } from "@anima-labs/schemas"; const page = FeedbackListOutput.parse( await api.listFeedback(FeedbackListInput.parse({ limit: 50 })), ); if (page.pagination.hasMore) page.pagination.nextCursor; // feed into next call ``` -------------------------------- ### CreateApiKeyInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/api-keys.md Shows how to parse input for creating an API key. The example passes an agentId and scopes, and the parsed result includes mode "LIVE" and the provided scopes. ```typescript import { CreateApiKeyInput } from "@anima-labs/schemas"; const input = CreateApiKeyInput.parse({ agentId: "clxagent1...", scopes: ["messages:write"] }); // { mode: "LIVE", scopes: ["messages:write"], ... } ``` -------------------------------- ### FeedbackInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/feedback.md Shows how to import and parse a FeedbackInput object. The example uses a bug type, a message, an email, and metadata. ```typescript import { FeedbackInput } from "@anima-labs/schemas"; const feedback = FeedbackInput.parse({ type: "bug", message: "Slug regex rejected a valid slug", email: "dev@example.com", metadata: { page: "/settings" }, }); ``` -------------------------------- ### InboxListInput and InboxListOutput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/inbox.md Shows how to parse list input and output. The example calls api.listInboxes with a parsed query and iterates over the resulting items. ```typescript import { InboxListInput, InboxListOutput } from "@anima-labs/schemas"; const { items } = InboxListOutput.parse( await api.listInboxes(InboxListInput.parse({ query: "support" })), ); for (const inbox of items) console.log(inbox.email, inbox.agentId); ``` -------------------------------- ### OpenClaw Self-Signup Usage Example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/openclaw.md Shows how to parse input and output using the schemas. The apiKey is returned only once and must be stored securely. ```typescript import { OpenClawSelfSignupInput, OpenClawSelfSignupOutput } from "@anima-labs/schemas"; const input = OpenClawSelfSignupInput.parse({ openclawAgentId: "oc_42", organizationName: "Acme", organizationSlug: "acme", agentName: "Acme Agent", agentSlug: "acme-agent", email: "ops@acme.example", phoneNumber: "+14155550132", }); const result = OpenClawSelfSignupOutput.parse(await api.selfSignup(input)); // result.credentials.apiKey — store securely, it is not returned again ``` -------------------------------- ### CreateAgentInput - Usage Example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/agent.md Shows how to parse a valid agent input and how to handle validation errors. The safeParse example demonstrates that both name and slug issues are reported together. ```typescript import { CreateAgentInput } from "@anima-labs/schemas"; const input = CreateAgentInput.parse({ orgId: "clxorgid0001...", name: "Support Agent", slug: "support-agent", provisionPhone: true, }); // { orgId, name, slug, provisionPhone: true, metadata: {} } const bad = CreateAgentInput.safeParse({ orgId: "clx...", name: "X", slug: "Bad_Slug!" }); if (!bad.success) { // issues for name (too short) and slug (regex mismatch) are both reported console.log(bad.error.issues.map((i) => i.path)); } ``` -------------------------------- ### Parsing an AgentOutput Example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/agent.md Shows how to import and parse an AgentOutput object. The example logs the status field, which is 'ACTIVE'. ```typescript import { AgentOutput } from "@anima-labs/schemas"; const agent = AgentOutput.parse({ id: "clxagent1...", orgId: "clxorgid1...", name: "Support Agent", slug: "support-agent", status: "ACTIVE", apiKeyPrefix: "anim_", metadata: {}, emailIdentities: [], phoneIdentities: [], createdAt: "...", updatedAt: "...", }); console.log(agent.status); // "ACTIVE" ``` -------------------------------- ### Usage example for schemas namespace Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/api-keys.md Shows how to import the schemas namespace and use it to parse input for creating an API key. ```typescript import { schemas } from "@anima-labs/schemas"; const input = schemas.CreateApiKeyInput.parse({ name: "ci", scopes: [] }); ``` -------------------------------- ### Usage example for BillingCheckoutInput and BillingSessionOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/billing.md Shows how to parse billing input and session output, then redirect to the session URL if present. Imports from @anima-labs/schemas. ```typescript import { BillingCheckoutInput, BillingSessionOutput } from "@anima-labs/schemas"; const checkout = BillingCheckoutInput.parse({ tier: "growth", successUrl: "https://app.example.com/billing?done=1", }); const session = BillingSessionOutput.parse({ url: "https://checkout.stripe.com/c/pay_..." }); if (session.url) window.location.assign(session.url); ``` -------------------------------- ### BillingUsageOutput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/billing.md Shows how to import and parse a usage object with BillingUsageOutput. The example uses period '2025-06' and sample usage counters. ```typescript import { BillingUsageOutput } from "@anima-labs/schemas"; const usage = BillingUsageOutput.parse({ period: "2025-06", usage: { message_sent: 3, message_received: 1, sms_sent: 0, sms_received: 0, call_minute: 0, embedding_generated: 12 }, }); ``` -------------------------------- ### Usage example for ListPhonesOutput and SendSmsInput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/phone.md Shows how to parse ListPhonesInput and ListPhonesOutput, find the primary phone, and send an SMS using SendSmsInput. The example uses the @anima-labs/schemas package. ```typescript import { ListPhonesInput, ListPhonesOutput, SendSmsInput } from "@anima-labs/schemas"; const list = ListPhonesOutput.parse(await api.listPhones(ListPhonesInput.parse({ agentId: "clxagent1..." }))); const primary = list.items.find((p) => p.isPrimary); if (primary) await api.sendSms(SendSmsInput.parse({ agentId: "clxagent1...", to: primary.phoneNumber, body: "Hi" })); ``` -------------------------------- ### Import schemas from package root Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/index.md Shows how to import schemas directly from the package root. The example imports AgentOutput and AgentListInput. ```typescript import { AgentOutput, AgentListInput } from "@anima-labs/schemas"; ``` -------------------------------- ### Usage example for AgentListInput and AgentListOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/agent.md Shows how to parse input, validate an API response, and paginate using the nextCursor. The example imports both schemas from @anima-labs/schemas and uses AgentListInput.parse for the initial query and subsequent cursor-based requests. ```typescript import { AgentListInput, AgentListOutput } from "@anima-labs/schemas"; const query = AgentListInput.parse({ status: "ACTIVE", limit: 10 }); const response: unknown = await api.listAgents(query); const { items, pagination } = AgentListOutput.parse(response); if (pagination.hasMore) { await api.listAgents(AgentListInput.parse({ cursor: pagination.nextCursor })); } ``` -------------------------------- ### SecurityPolicySchema usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/security.md Shows how to parse a policy with custom values and how parsing an empty object yields the documented defaults. The example imports from '@anima-labs/schemas' and demonstrates that all fields have defaults. ```typescript import { SecurityPolicySchema } from "@anima-labs/schemas"; const policy = SecurityPolicySchema.parse({ scanLevel: "strict", autoApproveBelow: "high", allowedDomains: ["example.com"], }); // { scanLevel: "strict", injectionScanEnabled: true, autoApproveBelow: "high", // allowedDomains: ["example.com"], blockedPatterns: [] } const defaults = SecurityPolicySchema.parse({}); // { scanLevel: "basic", injectionScanEnabled: true, autoApproveBelow: "medium", // allowedDomains: [], blockedPatterns: [] } ``` -------------------------------- ### Usage example for OrgListInput and OrgListOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/organization.md Shows how to parse an OrgListInput with a query and limit, pass it to an API call, parse the response as OrgListOutput, and iterate over the items. ```typescript import { OrgListInput, OrgListOutput } from "@anima-labs/schemas"; const page = OrgListOutput.parse( await api.listOrgs(OrgListInput.parse({ query: "acme", limit: 50 })), ); for (const org of page.items) console.log(org.id, org.tier); ``` -------------------------------- ### UpdateAgentInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/agent.md Shows how to parse a partial update payload using UpdateAgentInput. The example passes an id and a status, demonstrating that other fields are optional. ```typescript import { UpdateAgentInput } from "@anima-labs/schemas"; const patch = UpdateAgentInput.parse({ id: "clxagent1...", status: "SUSPENDED" }); ``` -------------------------------- ### InvoiceListInput and InvoiceUpdateInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/invoice.md Shows how to parse an update and a list input using the schemas. ```typescript import { InvoiceListInput, InvoiceUpdateInput, InvoiceStatusSchema } from "@anima-labs/schemas"; const update = InvoiceUpdateInput.parse({ invoiceId: "inv_123", status: "confirmed", metadata: { reviewedBy: "ops@anima.dev" }, }); const list = InvoiceListInput.parse({ status: "confirmed" }); ``` -------------------------------- ### Update security policy usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/security.md Shows how to parse input and output for updating a security policy. The example uses UpdateSecurityPolicyInput.parse and UpdateSecurityPolicyOutput.parse with an api.updatePolicy call. The output's policy.injectionScanEnabled defaults to true. ```typescript import { UpdateSecurityPolicyInput, UpdateSecurityPolicyOutput } from "@anima-labs/schemas"; const input = UpdateSecurityPolicyInput.parse({ orgId: "org_1", agentId: "agent_2", policy: { scanLevel: "strict", allowedDomains: ["example.com"] }, }); const saved = UpdateSecurityPolicyOutput.parse(await api.updatePolicy(input)); console.log(saved.policy.injectionScanEnabled); // true (default applied) ``` -------------------------------- ### Usage example for VaultCredentialIdInput and related schemas Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/vault.md Shows how to import and use VaultCredentialIdInput, TotpOutput, GeneratePasswordInput, and GeneratePasswordOutput. Parses inputs and outputs for getTotp and generatePassword API calls. ```typescript import { VaultCredentialIdInput, TotpOutput, GeneratePasswordInput, GeneratePasswordOutput } from "@anima-labs/schemas"; const target = VaultCredentialIdInput.parse({ agentId: "clxagent1...", id: "cred_1" }); const totp = TotpOutput.parse(await api.getTotp(target)); const pwd = GeneratePasswordOutput.parse( await api.generatePassword(GeneratePasswordInput.parse({ agentId: "clxagent1...", length: 24, special: true })), ); ``` -------------------------------- ### SendSmsInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/message.md Example of importing SendSmsInput from @anima-labs/schemas and parsing a sample SMS object. Demonstrates the expected shape with agentId, to, and body fields. ```typescript import { SendSmsInput } from "@anima-labs/schemas"; const sms = SendSmsInput.parse({ agentId: "clxagent1...", to: "+14155550132", body: "Your code is 123456", }); ``` -------------------------------- ### UpdateOrgInput Usage Example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/organization.md Shows how to import and use UpdateOrgInput to parse a patch object. The example passes a null clerkOrgId to unlink from Clerk and sets the tier to 'SCALE'. ```typescript import { UpdateOrgInput } from "@anima-labs/schemas"; const patch = UpdateOrgInput.parse({ id: "clxorgid1...", clerkOrgId: null, // unlink from Clerk tier: "SCALE", }); ``` -------------------------------- ### Usage example for ApprovalActionInput and ApprovalActionOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/security.md Shows how to parse an approval input and output using the schemas, including a call to an API function and logging the result status. ```typescript import { ApprovalActionInput, ApprovalActionOutput } from "@anima-labs/schemas"; const input = ApprovalActionInput.parse({ orgId: "org_1", messageId: "msg_2", action: "reject", reason: "Spam" }); const result = ApprovalActionOutput.parse(await api.approveOrReject(input)); console.log(result.status); // "REJECTED" | "SENT" | "FAILED" ``` -------------------------------- ### Using CreateCredentialInput and UpdateCredentialInput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/vault.md Shows how to parse data with CreateCredentialInput and UpdateCredentialInput. The example creates a login credential and then updates it with a new password and favorite flag. ```typescript import { CreateCredentialInput, UpdateCredentialInput } from "@anima-labs/schemas"; const created = CreateCredentialInput.parse({ agentId: "clxagent1...", type: "login", name: "dashboard", login: { username: "ops", password: "s3cret", uris: [{ uri: "https://app.example.com", match: "host" }] }, }); const updated = UpdateCredentialInput.parse({ agentId: "clxagent1...", login: { username: "ops", password: "new-s3cret" }, favorite: true, }); ``` -------------------------------- ### CreateOrgInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/organization.md Shows how to import and use CreateOrgInput to parse an organization object. The parsed result includes the tier and default settings. ```typescript import { CreateOrgInput } from "@anima-labs/schemas"; const org = CreateOrgInput.parse({ name: "Acme Inc", slug: "acme", tier: "DEVELOPER" }); // { tier: "DEVELOPER", settings: {} } ``` -------------------------------- ### InvoiceOutput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/invoice.md Shows how to parse an invoice from an API response and check its status and amount before approving. ```typescript import { InvoiceOutput } from "@anima-labs/schemas"; const invoice = InvoiceOutput.parse(await api.getInvoice(invoiceId)); if (invoice.status === "detected" && invoice.amountCents !== null) { await approve(invoice.id, invoice.amountCents, invoice.currency); } ``` -------------------------------- ### DateRange usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/common.md Parses a DateRange with explicit from and to ISO datetime strings. ```typescript import { DateRange } from "@anima-labs/schemas"; const range = DateRange.parse({ from: "2025-01-01T00:00:00.000Z", to: "2025-01-31T23:59:59.000Z", }); ``` -------------------------------- ### Usage example for RevokeApiKeyInput and RotateApiKeyInput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/api-keys.md Shows how to import and use the RevokeApiKeyInput and RotateApiKeyInput schemas to parse input objects with an id field. ```typescript import { RevokeApiKeyInput, RotateApiKeyInput } from "@anima-labs/schemas"; const revoke = RevokeApiKeyInput.parse({ id: "clxkey1..." }); const rotate = RotateApiKeyInput.parse({ id: "clxkey1..." }); ``` -------------------------------- ### Webhook schema usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/webhook.md Shows how to parse the webhook schemas with sample data and use the parsed values with a hypothetical API. Includes a conditional check on successRate and a call to listDeliveries. ```typescript import { CreateWebhookInput, TestWebhookInput, WebhookDeliveryListInput, WebhookStatsOutput } from "@anima-labs/schemas"; const created = CreateWebhookInput.parse({ url: "https://app.example.com/hooks", events: ["message.sent", "agent.created"], description: "prod app", }); const test = TestWebhookInput.parse({ id: "wbhook1234..." }); const stats = WebhookStatsOutput.parse(await api.webhookStats({ id: "wbhook1234..." })); if (stats.successRate < 90) { const deliveries = await api.listDeliveries(WebhookDeliveryListInput.parse({ webhookId: "wbhook1234...", limit: 20 })); // inspect WebhookDeliveryOutput records: statusCode, attempts, maxAttempts, nextAttemptAt } ``` -------------------------------- ### Parsing OpenClawCallbackInput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/openclaw.md Example of parsing query parameters with OpenClawCallbackInput and handling the error case. ```typescript import { OpenClawCallbackInput } from "@anima-labs/schemas"; const callback = OpenClawCallbackInput.parse(queryParams); if (callback.error) console.error("OAuth failed:", callback.error); else handleCode(callback.code!); ``` -------------------------------- ### Usage example: search and provision phone numbers Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/phone.md Demonstrates parsing search input, parsing search output, and provisioning a phone. ProvisionPhoneInput only carries agentId and preferred region/capabilities; the number is chosen server-side. ```typescript import { SearchNumbersInput, SearchNumbersOutput, ProvisionPhoneInput } from "@anima-labs/schemas"; const search = SearchNumbersInput.parse({ areaCode: "415", capabilities: ["sms", "voice"], limit: 5 }); const numbers = SearchNumbersOutput.parse(await api.searchNumbers(search)); if (numbers.items.length > 0) { // ProvisionPhoneInput carries only agentId + preferred region/capabilities — the number is chosen server-side const provision = ProvisionPhoneInput.parse({ agentId: "clxagent1...", capabilities: ["sms", "voice"] }); await api.provisionPhone(provision); } ``` -------------------------------- ### EmailListOutput schema definition and usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/email.md Defines the paginated email list output schema with items of MessageOutput and CursorPagination. The usage example shows parsing an EmailListInput and EmailListOutput with an API call. ```typescript export const EmailListOutput = z.object({ items: z.array(MessageOutput), pagination: CursorPagination, }); ``` ```typescript import { EmailListInput, EmailListOutput } from "@anima-labs/schemas"; const request = EmailListInput.parse({ agentId: "clxagent1...", limit: 25 }); const { items, pagination } = EmailListOutput.parse(await api.listEmails(request)); ``` -------------------------------- ### SendEmailInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/message.md Shows how to parse a valid email input using SendEmailInput. The parsed result includes default values for cc, bcc, headers, and metadata. ```typescript import { SendEmailInput } from "@anima-labs/schemas"; const email = SendEmailInput.parse({ agentId: "clxagent1...", to: ["a@example.com"], subject: "Hello", body: "World", bodyHtml: "
World
", }); // { cc: [], bcc: [], headers: {}, metadata: {} } ``` -------------------------------- ### Parsing and using MessageOutput Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/message.md Shows how to import MessageOutput from @anima-labs/schemas and parse an incoming webhook body. After parsing, the example checks for an inbound SMS message and routes it to an agent. ```typescript import { MessageOutput } from "@anima-labs/schemas"; const msg = MessageOutput.parse(webhook.body); if (msg.channel === "SMS" && msg.direction === "INBOUND") { await routeToAgent(msg.agentId, msg.body); } ``` -------------------------------- ### Parse ListCredentialsOutput from searchCredentials API Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/vault.md Example of parsing the output of api.searchCredentials using ListCredentialsOutput. The input is parsed with SearchCredentialsInput, which requires an agentId and a search string. ```typescript import { SearchCredentialsInput, ListCredentialsOutput } from "@anima-labs/schemas"; const page = ListCredentialsOutput.parse( await api.searchCredentials(SearchCredentialsInput.parse({ agentId: "clxagent1...", search: "aws" })), ); ``` -------------------------------- ### WebhookEventSchema usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/webhook.md Shows how to import and use WebhookEventSchema to parse a valid event string. The parse call with "message.received" succeeds. ```typescript import { WebhookEventSchema } from "@anima-labs/schemas"; WebhookEventSchema.parse("message.received"); // ok ``` -------------------------------- ### AddDomainInput usage example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/email.md Shows how to parse and validate a domain using AddDomainInput. The parse method lowercases the input, and safeParse returns an error with the message "Invalid domain format" for invalid domains. ```typescript import { AddDomainInput } from "@anima-labs/schemas"; const input = AddDomainInput.parse({ domain: "Example.COM" }); // input.domain === "example.com" (lowercased) const result = AddDomainInput.safeParse({ domain: "not_a_domain" }); if (!result.success) { console.log(result.error.issues[0].message); // "Invalid domain format" } ``` -------------------------------- ### EmailSendEmailInput Usage Example Source: https://github.com/anima-labs-ai/schemas/blob/main/_autodocs/api-reference/email.md Parses an email input with agentId, to, subject, body, and inReplyTo. The parsed result includes defaults for references, cc, bcc, headers, and metadata. ```typescript import { EmailSendEmailInput } from "@anima-labs/schemas"; const email = EmailSendEmailInput.parse({ agentId: "clxagent1...", to: ["cust@example.com"], subject: "Your receipt", body: "Hi — please find your receipt attached.", inReplyTo: "