import {z} from 'zod' export type CreateApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveArgs = {process_id: string, kind: 'current_process' | 'transformation_proposal', body: {steps: Array<{id: string, targetSteps: Array<{stepId: string, label: string | null, isDefault: boolean}>, title: string, action: string | null, role: string | null, system: string | null, input: string | null, output: string | null, exception: string | null, handling: string | null, assumptions: Array | null, openQuestions: Array | null, confidence: 'low' | 'medium' | 'high', nodeType: 'event', nodeSubtype: 'start' | 'end' | 'timer' | 'message' | 'escalation', description: string | null, rationale: string | null, sources: Array<{attribution: string, excerpt: string, captureId?: string | undefined, evidenceId?: string | undefined, locator?: ({type: 'transcript_message', messageIndex: number, timestampMs?: number | undefined} | {type: 'document_text_range', startOffset: number, endOffset: number, pageNumber?: number | undefined, startLine?: number | undefined, endLine?: number | undefined} | {type: 'bpmn_element', elementId: string, elementType?: string | undefined, name?: string | undefined} | {type: 'screenshare_frame', timestampMs: number} | {type: 'manual'} | {type: 'unresolved', reason?: string | undefined}) | undefined, sourceConfidence?: ('low' | 'medium' | 'high') | undefined, resolutionStatus?: ('resolved' | 'unresolved' | 'legacy' | 'manual') | undefined}>, condition: string | null, extraCaptureNeeded?: ({id: string, gap: string, proposal?: (string | null) | undefined} | null) | undefined, readiness?: ('low' | 'medium' | 'high' | null) | undefined, readinessRationale?: (string | null) | undefined} | {id: string, targetSteps: Array<{stepId: string, label: string | null, isDefault: boolean}>, title: string, action: string | null, role: string | null, system: string | null, input: string | null, output: string | null, exception: string | null, handling: string | null, assumptions: Array | null, openQuestions: Array | null, confidence: 'low' | 'medium' | 'high', nodeType: 'task', nodeSubtype: 'user' | 'service' | 'send' | 'receive' | 'manual' | 'businessRule' | 'script', description: string, rationale: string, sources: Array<{attribution: string, excerpt: string, captureId?: string | undefined, evidenceId?: string | undefined, locator?: ({type: 'transcript_message', messageIndex: number, timestampMs?: number | undefined} | {type: 'document_text_range', startOffset: number, endOffset: number, pageNumber?: number | undefined, startLine?: number | undefined, endLine?: number | undefined} | {type: 'bpmn_element', elementId: string, elementType?: string | undefined, name?: string | undefined} | {type: 'screenshare_frame', timestampMs: number} | {type: 'manual'} | {type: 'unresolved', reason?: string | undefined}) | undefined, sourceConfidence?: ('low' | 'medium' | 'high') | undefined, resolutionStatus?: ('resolved' | 'unresolved' | 'legacy' | 'manual') | undefined}>, condition: string | null, extraCaptureNeeded?: ({id: string, gap: string, proposal?: (string | null) | undefined} | null) | undefined, readiness?: ('low' | 'medium' | 'high' | null) | undefined, readinessRationale?: (string | null) | undefined} | {id: string, targetSteps: Array<{stepId: string, label: string | null, isDefault: boolean}>, title: string, action: string | null, role: string | null, system: string | null, input: string | null, output: string | null, exception: string | null, handling: string | null, assumptions: Array | null, openQuestions: Array | null, confidence: 'low' | 'medium' | 'high', nodeType: 'gateway', nodeSubtype: 'exclusive' | 'parallel' | 'inclusive', description: string, rationale: string, sources: Array<{attribution: string, excerpt: string, captureId?: string | undefined, evidenceId?: string | undefined, locator?: ({type: 'transcript_message', messageIndex: number, timestampMs?: number | undefined} | {type: 'document_text_range', startOffset: number, endOffset: number, pageNumber?: number | undefined, startLine?: number | undefined, endLine?: number | undefined} | {type: 'bpmn_element', elementId: string, elementType?: string | undefined, name?: string | undefined} | {type: 'screenshare_frame', timestampMs: number} | {type: 'manual'} | {type: 'unresolved', reason?: string | undefined}) | undefined, sourceConfidence?: ('low' | 'medium' | 'high') | undefined, resolutionStatus?: ('resolved' | 'unresolved' | 'legacy' | 'manual') | undefined}>, condition: string, extraCaptureNeeded?: ({id: string, gap: string, proposal?: (string | null) | undefined} | null) | undefined, readiness?: ('low' | 'medium' | 'high' | null) | undefined, readinessRationale?: (string | null) | undefined}>, baselineSnapshotId: string, clarityCurrentProcessId?: string | undefined, swot?: ({strengths: Array, weaknesses: Array, opportunities: Array, threats: Array} | null) | undefined, summary?: (string | null) | undefined, projectedImpact?: (string | null) | undefined}}; export type CreateApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveResponse = z.object({snapshot: z.union([z.object({id: z.string(), process_id: z.string(), source_snapshot_id: z.literal("null").nullable(), parent_id: z.string().nullable(), created_at: z.string(), updated_at: z.string(), status: z.enum(["live", "historic", "draft", "generating"]), creator_type: z.enum(["human", "ai"]), user_id: z.string().nullable(), sandbox_id: z.string().nullable(), last_session_id: z.string().nullable(), kind: z.literal("current_process"), data: z.object({version: z.number().int().gte(-9007199254740991).lte(9007199254740991), steps: z.array(z.union([z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("event"), nodeSubtype: z.enum(["start", "end", "timer", "message", "escalation"]), description: z.string().min(1).nullable(), rationale: z.string().min(1).nullable(), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().nullable(), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()}), z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("task"), nodeSubtype: z.enum(["user", "service", "send", "receive", "manual", "businessRule", "script"]), description: z.string().min(1), rationale: z.string().min(1), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().nullable(), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()}), z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("gateway"), nodeSubtype: z.enum(["exclusive", "parallel", "inclusive"]), description: z.string().min(1), rationale: z.string().min(1), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().min(1), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()})])), swot: z.object({strengths: z.array(z.string().min(1)), weaknesses: z.array(z.string().min(1)), opportunities: z.array(z.string().min(1)), threats: z.array(z.string().min(1))}).nullable().optional(), summary: z.string().min(1).nullable().optional()})}), z.object({id: z.string(), process_id: z.string(), source_snapshot_id: z.string(), parent_id: z.string().nullable(), created_at: z.string(), updated_at: z.string(), status: z.enum(["live", "historic", "draft", "generating"]), creator_type: z.enum(["human", "ai"]), user_id: z.string().nullable(), sandbox_id: z.string().nullable(), last_session_id: z.string().nullable(), kind: z.literal("transformation_proposal"), data: z.object({version: z.number().int().gte(-9007199254740991).lte(9007199254740991), steps: z.array(z.union([z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("event"), nodeSubtype: z.enum(["start", "end", "timer", "message", "escalation"]), description: z.string().min(1).nullable(), rationale: z.string().min(1).nullable(), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().nullable(), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()}), z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("task"), nodeSubtype: z.enum(["user", "service", "send", "receive", "manual", "businessRule", "script"]), description: z.string().min(1), rationale: z.string().min(1), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().nullable(), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()}), z.object({id: z.string().min(1), targetSteps: z.array(z.object({stepId: z.string().min(1), label: z.string().nullable(), isDefault: z.boolean()})), title: z.string().min(1), action: z.string().min(1).nullable(), role: z.string().min(1).nullable(), system: z.string().nullable(), input: z.string().nullable(), output: z.string().nullable(), exception: z.string().nullable(), handling: z.string().nullable(), assumptions: z.array(z.string()).nullable(), openQuestions: z.array(z.string()).nullable(), confidence: z.enum(["low", "medium", "high"]), nodeType: z.literal("gateway"), nodeSubtype: z.enum(["exclusive", "parallel", "inclusive"]), description: z.string().min(1), rationale: z.string().min(1), sources: z.array(z.object({attribution: z.string().min(1), excerpt: z.string().min(1), captureId: z.string().min(1).optional(), evidenceId: z.string().min(1).optional(), locator: z.union([z.object({type: z.literal("transcript_message"), messageIndex: z.number().int().gte(0).lte(9007199254740991), timestampMs: z.number().int().gte(0).lte(9007199254740991).optional()}), z.object({type: z.literal("document_text_range"), startOffset: z.number().int().gte(0).lte(9007199254740991), endOffset: z.number().int().lte(9007199254740991), pageNumber: z.number().int().lte(9007199254740991).optional(), startLine: z.number().int().lte(9007199254740991).optional(), endLine: z.number().int().lte(9007199254740991).optional()}), z.object({type: z.literal("bpmn_element"), elementId: z.string().min(1), elementType: z.string().min(1).optional(), name: z.string().min(1).optional()}), z.object({type: z.literal("screenshare_frame"), timestampMs: z.number().int().gte(0).lte(9007199254740991)}), z.object({type: z.literal("manual")}), z.object({type: z.literal("unresolved"), reason: z.string().min(1).optional()})]).optional(), sourceConfidence: z.enum(["low", "medium", "high"]).optional(), resolutionStatus: z.enum(["resolved", "unresolved", "legacy", "manual"]).optional()})), condition: z.string().min(1), extraCaptureNeeded: z.object({id: z.string(), gap: z.string().min(1), proposal: z.string().min(1).nullable().optional()}).nullable().optional(), readiness: z.enum(["low", "medium", "high"]).nullable().optional(), readinessRationale: z.string().nullable().optional()})])), summary: z.string().min(1).nullable().optional(), projectedImpact: z.string().min(1).nullable().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 }; /** * Save Clarity Process Snapshot * * POST /v2/clarity-v2/processes/{process_id}/snapshots/{kind}/save */ export const createApiV2ClarityV2ProcessesProcessIdSnapshotsKindSave = async (args: CreateApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveArgs, options?: CreateApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveOptions) => { const {baseUrl = "https://api.duvo.ai", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/clarity-v2/processes/${encodeURIComponent(String(args.process_id))}/snapshots/${encodeURIComponent(String(args.kind))}/save${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(createApiV2ClarityV2ProcessesProcessIdSnapshotsKindSaveResponse, await res.json()) };