import {z} from 'zod' export type ColumnType = 'smart' | 'static'; export type DataSource = 'meeting_minutes' | 'purchase_orders' | 'online_research' | 'strategic_plans' | 'contacts' | 'annual_budgets' | 'procurement_guidelines' | 'news' | 'rfps' | 'legislation' | 'grants' | 'intent' | 'email' | 'google_search' | 'summary' | 'signals' | 'call_script'; export type QueryLogic = 'AND' | 'OR'; export type AppRoutesV3SmartColumnsKeywordConfig = {logic: QueryLogic, keywords: Array, is_strict: boolean}; export type RerunFrequency = 'daily' | 'weekly' | 'monthly' | 'none'; export type AppRoutesV3SmartColumnsDateRange = {from: string, to?: (string | null) | undefined}; export type IntentFactors = {key_factors: string, scoring_rubric: string}; export type SmartColumnRequest = {column_id?: (string | null) | undefined, column_type: ColumnType, column_name: string, column_version?: (number | null) | undefined, description: string, data_source: DataSource, keyword_config: AppRoutesV3SmartColumnsKeywordConfig, rerun_frequency: RerunFrequency, last_run?: (string | null) | undefined, date_range?: (AppRoutesV3SmartColumnsDateRange | null) | undefined, intent_factors?: IntentFactors | undefined, reference_column_ids?: (Array | null) | undefined}; export type CreateApiApiV3WorkspacesWorkspaceIdSmartColumnsArgs = {workspace_id: string, body: SmartColumnRequest}; export type CreateApiApiV3WorkspacesWorkspaceIdSmartColumnsOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV3WorkspacesWorkspaceIdSmartColumnsResponse = z.unknown(); 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 }; /** * Upsert Smart Column * * POST /api/v3/workspaces/{workspace_id}/smart-columns */ export const createApiApiV3WorkspacesWorkspaceIdSmartColumns = async (args: CreateApiApiV3WorkspacesWorkspaceIdSmartColumnsArgs, options: CreateApiApiV3WorkspacesWorkspaceIdSmartColumnsOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/workspaces/${encodeURIComponent(String(args.workspace_id))}/smart-columns${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV3WorkspacesWorkspaceIdSmartColumnsResponse, await res.json()) };