import {z} from 'zod' export type GetApiPersonaPersonaIdArgs = {persona_id: number}; export type GetApiPersonaPersonaIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const starterMessage = z.object({name: z.string(), message: z.string()}); export const toolSnapshot = z.object({id: z.number().int(), name: z.string(), description: z.string(), definition: z.record(z.string(), z.unknown()).nullable(), display_name: z.string(), in_code_tool_id: z.string().nullable(), custom_headers: z.array(z.unknown()).nullable(), passthrough_auth: z.boolean(), mcp_server_id: z.number().int().nullable().optional(), user_id: z.string().nullable().optional(), oauth_config_id: z.number().int().nullable().optional(), oauth_config_name: z.string().nullable().optional(), enabled: z.boolean().optional(), user_enabled_in_chat: z.boolean().optional(), default_chat_enabled: z.boolean().nullable().optional(), permissions: z.record(z.string(), z.boolean()).optional(), chat_selectable: z.boolean().optional(), agent_creation_selectable: z.boolean().optional(), default_enabled: z.boolean().optional()}); export const personaLabelSnapshot = z.object({id: z.number().int(), name: z.string()}); export const minimalUserSnapshot = z.object({id: z.string(), email: z.string()}); export const personaOwnerGroupSnapshot = z.object({id: z.number().int(), name: z.string()}); export const personaSharePermission = z.enum(["EDITOR", "VIEWER"]); export const personaUserShare = z.object({user: minimalUserSnapshot, permission: personaSharePermission}); export const personaGroupShare = z.object({group_id: z.number().int(), group_name: z.string(), permission: personaSharePermission}); export const personaSharingStatus = z.enum(["PRIVATE", "SHARED", "PUBLIC"]); export const documentSource = z.enum(["ingestion_api", "slack", "web", "google_drive", "gmail", "github", "gitbook", "gitlab", "guru", "bookstack", "outline", "confluence", "jira", "slab", "productboard", "file", "coda", "canvas", "notion", "zulip", "linear", "hubspot", "document360", "gong", "google_sites", "zendesk", "loopio", "box", "dropbox", "sharepoint", "onedrive", "teams", "outlook", "salesforce", "discourse", "axero", "clickup", "mediawiki", "wikipedia", "asana", "s3", "r2", "google_cloud_storage", "oci_storage", "xenforo", "not_applicable", "discord", "freshdesk", "fireflies", "zoom", "egnyte", "airtable", "highspot", "drupal_wiki", "imap", "bitbucket", "testrail", "braintrust", "lumapps", "youtrack", "mock_connector", "user_file", "craft_file"]); export const accessType = z.enum(["public", "private", "sync", "sync_restricted"]); export const cCPairSummary = z.object({id: z.number().int(), name: z.string(), source: documentSource, access_type: accessType}); export const federatedConnectorSource = z.literal("federated_slack"); export const federatedConnectorSummary = z.object({id: z.number().int(), name: z.string(), source: federatedConnectorSource, entities: z.record(z.string(), z.unknown())}); export const documentSetSummary = z.object({id: z.number().int(), name: z.string(), description: z.string().nullable(), cc_pair_summaries: z.array(cCPairSummary), is_up_to_date: z.boolean(), is_public: z.boolean(), users: z.array(z.string()), groups: z.array(z.number().int()), permissions: z.record(z.string(), z.boolean()).optional(), federated_connector_summaries: z.array(federatedConnectorSummary).optional()}); export const hierarchyNodeType = z.enum(["folder", "source", "stub", "shared_drive", "my_drive", "space", "page", "project", "database", "workspace", "site", "drive", "channel", "mailbox"]); export const hierarchyNodeSnapshot = z.object({id: z.number().int(), raw_node_id: z.string(), display_name: z.string(), link: z.string().nullable(), source: documentSource, node_type: hierarchyNodeType}); export const attachedDocumentSnapshot = z.object({id: z.string(), title: z.string(), link: z.string().nullable(), parent_id: z.number().int().nullable(), last_modified: z.string().nullable(), last_synced: z.string().nullable(), source: documentSource.nullable()}); export const personaAccessLevel = z.enum(["OWNER", "EDITOR", "VIEWER"]); export const fullPersonaSnapshot = z.object({id: z.number().int(), name: z.string(), description: z.string(), is_public: z.boolean(), is_listed: z.boolean(), uploaded_image_id: z.string().nullable(), icon_name: z.string().nullable(), user_file_ids: z.array(z.string()), display_priority: z.number().int().nullable(), is_featured: z.boolean(), builtin_persona: z.boolean(), starter_messages: z.array(starterMessage).nullable(), tools: z.array(toolSnapshot), labels: z.array(personaLabelSnapshot), owner: minimalUserSnapshot.nullable(), owner_group: personaOwnerGroupSnapshot.nullable(), users: z.array(minimalUserSnapshot), groups: z.array(z.number().int()), user_shares: z.array(personaUserShare), group_shares: z.array(personaGroupShare), public_permission: personaSharePermission, sharing_status: personaSharingStatus, document_sets: z.array(documentSetSummary), default_model_configuration_id: z.number().int().nullable().optional(), hierarchy_nodes: z.array(hierarchyNodeSnapshot).optional(), attached_documents: z.array(attachedDocumentSnapshot).optional(), permissions: z.record(z.string(), z.boolean()).optional(), system_prompt: z.string().nullable().optional(), replace_base_system_prompt: z.boolean().optional(), task_prompt: z.string().nullable().optional(), datetime_aware: z.boolean().optional(), search_start_date: z.string().nullable().optional(), user_permission: personaAccessLevel.nullable().optional(), admin_count: z.number().int().optional(), ownership_vacant: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Persona * * GET /persona/{persona_id} */ export const getApiPersonaPersonaId = async (args: GetApiPersonaPersonaIdArgs, options?: GetApiPersonaPersonaIdOptions) => { const {baseUrl = "https://cloud.onyx.app/api", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/persona/${encodeURIComponent(String(args.persona_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(fullPersonaSnapshot, await res.json()) };