/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { safeParse } from "../../lib/schemas.js"; import { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * The scope of the instruction. Determines whether the instruction is applied to the entire document or to each chunk of the document. Options are `'document'` or `'chunk'`. Generally `'document'` should be used when analyzing the full document is desired, such as when generating a summary or determining sentiment, and `'chunk'` should be used when a fine grained search over a document is desired. */ export const CreateInstructionParamsScope = { Document: "document", Chunk: "chunk", } as const; /** * The scope of the instruction. Determines whether the instruction is applied to the entire document or to each chunk of the document. Options are `'document'` or `'chunk'`. Generally `'document'` should be used when analyzing the full document is desired, such as when generating a summary or determining sentiment, and `'chunk'` should be used when a fine grained search over a document is desired. */ export type CreateInstructionParamsScope = ClosedEnum< typeof CreateInstructionParamsScope >; export type CreateInstructionParams = { /** * The name of the instruction. Must be unique. */ name: string; /** * Whether the instruction is active. Active instructions are applied to documents when they're created or when their file is updated. */ active?: boolean | undefined; /** * The scope of the instruction. Determines whether the instruction is applied to the entire document or to each chunk of the document. Options are `'document'` or `'chunk'`. Generally `'document'` should be used when analyzing the full document is desired, such as when generating a summary or determining sentiment, and `'chunk'` should be used when a fine grained search over a document is desired. */ scope?: CreateInstructionParamsScope | undefined; /** * A natural language instruction which will be applied to documents as they are created and updated. The results of the `instruction_prompt` will be stored as an `entity` in the schema defined by the `entity_schema` parameter. */ prompt: string; entitySchema: { [k: string]: any }; /** * An optional metadata filter that is matched against document metadata during update and creation. The instruction will only be applied to documents with metadata matching the filter. The following filter operators are supported: $eq - Equal to (number, string, boolean), $ne - Not equal to (number, string, boolean), $gt - Greater than (number), $gte - Greater than or equal to (number), $lt - Less than (number), $lte - Less than or equal to (number), $in - In array (string or number), $nin - Not in array (string or number). The operators can be combined with AND and OR. Read [Metadata & Filters guide](https://docs.ragie.ai/docs/metadata-filters) for more details and examples. */ filter?: { [k: string]: any } | undefined; /** * An optional partition identifier. Instructions can be scoped to a partition. An instruction that defines a partition will only be executed for documents in that partition. */ partition?: string | undefined; }; /** @internal */ export const CreateInstructionParamsScope$inboundSchema: z.ZodNativeEnum< typeof CreateInstructionParamsScope > = z.nativeEnum(CreateInstructionParamsScope); /** @internal */ export const CreateInstructionParamsScope$outboundSchema: z.ZodNativeEnum< typeof CreateInstructionParamsScope > = CreateInstructionParamsScope$inboundSchema; /** @internal */ export const CreateInstructionParams$inboundSchema: z.ZodType< CreateInstructionParams, z.ZodTypeDef, unknown > = z.object({ name: z.string(), active: z.boolean().default(true), scope: CreateInstructionParamsScope$inboundSchema.default("chunk"), prompt: z.string(), entity_schema: z.record(z.any()), filter: z.record(z.any()).optional(), partition: z.string().optional(), }).transform((v) => { return remap$(v, { "entity_schema": "entitySchema", }); }); /** @internal */ export type CreateInstructionParams$Outbound = { name: string; active: boolean; scope: string; prompt: string; entity_schema: { [k: string]: any }; filter?: { [k: string]: any } | undefined; partition?: string | undefined; }; /** @internal */ export const CreateInstructionParams$outboundSchema: z.ZodType< CreateInstructionParams$Outbound, z.ZodTypeDef, CreateInstructionParams > = z.object({ name: z.string(), active: z.boolean().default(true), scope: CreateInstructionParamsScope$outboundSchema.default("chunk"), prompt: z.string(), entitySchema: z.record(z.any()), filter: z.record(z.any()).optional(), partition: z.string().optional(), }).transform((v) => { return remap$(v, { entitySchema: "entity_schema", }); }); export function createInstructionParamsToJSON( createInstructionParams: CreateInstructionParams, ): string { return JSON.stringify( CreateInstructionParams$outboundSchema.parse(createInstructionParams), ); } export function createInstructionParamsFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => CreateInstructionParams$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'CreateInstructionParams' from JSON`, ); }