import {z} from 'zod' export type CreateApiApiPreviewCapsulesIdDuplicateArgs = {id: string, body: {target?: 'personal' | undefined}}; export type CreateApiApiPreviewCapsulesIdDuplicateOptions = {baseUrl: string, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiPreviewCapsulesIdDuplicateResponse = z.object({agent_meta: z.record(z.string(), z.unknown()).nullable().optional(), alias_dropped: z.boolean().optional(), alias_reclaimable: z.boolean().optional(), alias_reclaimed: z.boolean().optional(), alsoAvailableAsSkill: z.string().max(200).optional(), archive_event_id: z.string().max(128).nullable().optional(), archive_reason: z.string().max(4000).nullable().optional(), archived_at: z.string().max(64).nullable().optional(), attachments: z.array(z.record(z.string(), z.unknown())).optional(), capsule_keys: z.array(z.record(z.string(), z.unknown())).optional(), categories: z.array(z.object({name: z.string().max(200), slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))).optional(), code_excerpt: z.string().max(20000).nullable().optional(), content: z.object({bindings: z.record(z.string(), z.unknown()).optional(), fields: z.record(z.string(), z.unknown()).optional(), format: z.enum(["markdown", "composed", "structured", "log"]), source: z.string().max(128).optional(), summary: z.string().max(2000).nullable().optional(), text: z.string().max(100000).optional()}).and(z.record(z.string(), z.unknown())).optional(), content_excerpt: z.string().max(20000).nullable().optional(), content_md: z.string().max(100000).nullable().optional(), content_rendered: z.string().max(100000).nullable().optional(), converted_entry: z.object({entry_at: z.string().max(64), entry_number: z.number().int().gte(-9007199254740991).lte(9007199254740991), field_values: z.record(z.string(), z.unknown())}).and(z.record(z.string(), z.unknown())).optional(), cover: z.record(z.string(), z.unknown()).nullable().optional(), created_at: z.string().max(64).optional(), created_by: z.string().max(128).optional(), deadCrossRefs: z.record(z.string(), z.object({reason: z.literal("deleted")})).optional(), deleted_at: z.string().max(64).nullable().optional(), dependency_review: z.object({can_confirm: z.boolean().optional(), enabled: z.boolean(), pending_count: z.number().int().gte(-9007199254740991).lte(9007199254740991), receipt: z.string().max(1024).nullable(), receipt_expires_at: z.string().max(64).nullable(), revision: z.string().max(64)}).and(z.record(z.string(), z.unknown())).optional(), draftAttachmentsMap: z.record(z.string(), z.unknown()).optional(), dropped_tags: z.array(z.string().max(200)).optional(), effective_guidance_hash: z.string().max(64).optional(), evicted_version_nums: z.array(z.number().int().gte(-9007199254740991).lte(9007199254740991)).optional(), field_values: z.record(z.string(), z.unknown()).optional(), flag_reason: z.string().max(4000).nullable().optional(), flagged_at: z.string().max(64).nullable().optional(), guidance_checks: z.array(z.object({check: z.string().max(400), prompt: z.string().max(1000)}).and(z.record(z.string(), z.unknown()))).optional(), guidance_manifest: z.array(z.object({capsuleId: z.string().max(64).nullable(), contentHash: z.string().max(128).nullable(), ref: z.string().max(600)})).optional(), id: z.string().max(36), impact: z.object({changed_fields: z.array(z.string().max(200)), dependents: z.object({items: z.array(z.object({id: z.string().max(128), ref: z.string().max(200), title: z.string().max(500), type_slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))), next_cursor: z.string().max(128).nullable(), total: z.number().int().gte(-9007199254740991).lte(9007199254740991)}).and(z.record(z.string(), z.unknown())), diff: z.object({text: z.string().max(8000), truncated: z.boolean()}).and(z.record(z.string(), z.unknown())).nullable()}).and(z.record(z.string(), z.unknown())).optional(), inbound_ref_count: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), incomplete: z.boolean().optional(), is_agent: z.boolean().optional(), is_encrypted: z.boolean().optional(), is_prompt: z.boolean().optional(), is_shared: z.boolean().optional(), is_stale: z.boolean().optional(), language: z.string().max(64).nullable().optional(), last_entry_at: z.string().max(64).nullable().optional(), last_fetched_at: z.string().max(64).nullable().optional(), lifecycle_updated_at: z.string().max(64).nullable().optional(), log: z.object({append_via: z.string().max(512), bound_type: z.object({id: z.string().max(36), name: z.string().max(200), slug: z.string().max(200)}), owned_log_ref: z.string().max(300).nullable(), owner_ref: z.string().max(300).nullable().optional(), role: z.enum(["owner", "log"])}).and(z.record(z.string(), z.unknown())).optional(), log_entries: z.array(z.record(z.string(), z.unknown())).optional(), log_entries_next_cursor: z.string().max(4096).nullable().optional(), log_entries_total: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), log_entry_order: z.string().max(128).optional(), log_field_schema: z.array(z.record(z.string(), z.unknown())).optional(), log_paragraph_rendering: z.enum(["plain", "markdown"]).optional(), log_period_key: z.string().max(128).nullable().optional(), log_period_next: z.string().max(128).nullable().optional(), log_period_prev: z.string().max(128).nullable().optional(), marked_complete: z.boolean().optional(), missing_required_fields: z.array(z.string().max(200)).optional(), owned_log: z.record(z.string(), z.unknown()).nullable().optional(), owner_capsule: z.record(z.string(), z.unknown()).nullable().optional(), owner_capsule_id: z.string().max(128).nullable().optional(), owner_log_binding: z.boolean().optional(), owner_log_type: z.record(z.string(), z.unknown()).nullable().optional(), packaging: z.object({republish_refused: z.string().max(4000).nullable().optional()}).and(z.record(z.string(), z.unknown())).optional(), preview_fields: z.array(z.record(z.string(), z.unknown())).optional(), project_color: z.string().max(128).nullable().optional(), project_id: z.string().max(128).nullable().optional(), project_name: z.string().max(200).nullable().optional(), project_slug: z.string().max(200).nullable().optional(), prompt_meta: z.record(z.string(), z.unknown()).nullable().optional(), prompt_name: z.string().max(200).nullable().optional(), ref_id: z.number().int().gte(-9007199254740991).lte(9007199254740991).optional(), republish: z.union([z.object({message: z.string().max(4000), status: z.literal("started")}), z.object({message: z.string().max(4000), reason: z.enum(["opted_out", "caller_default", "blocked", "name_changed", "no_refresh_right", "rate_limited", "check_failed"]), status: z.literal("not_started")})]).optional(), resolvedCrossRefs: z.record(z.string(), z.unknown()).optional(), rollover: z.string().max(128).nullable().optional(), share_display: z.enum(["article", "prompt", "showcase"]).nullable().optional(), share_display_effective: z.enum(["article", "prompt", "showcase"]).nullable().optional(), share_display_rendered: z.enum(["article", "prompt", "showcase"]).optional(), share_display_unhonored: z.literal("showcase_no_cover").nullable().optional(), skill_files: z.union([z.object({files: z.array(z.object({executable: z.boolean(), is_text: z.boolean(), path: z.string().min(1).max(512), revision_id: z.string().max(36), sha256: z.string().max(64), size: z.number().int().gte(-9007199254740991).lte(9007199254740991), source_kind: z.enum(["stored", "linked"]), updated_at: z.string().max(40)})), limits: z.object({file_max_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991), max_history_rows: z.number().int().gte(-9007199254740991).lte(9007199254740991), max_paths: z.number().int().gte(-9007199254740991).lte(9007199254740991), retained_max_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991), total_max_bytes: z.number().int().gte(-9007199254740991).lte(9007199254740991)})}).and(z.record(z.string(), z.unknown())), z.object({files: z.array(z.object({executable: z.boolean(), is_text: z.boolean(), path: z.string().max(1024), revision_id: z.string().max(64), size: z.number().int().gte(0).lte(9007199254740991)}).and(z.record(z.string(), z.unknown())))}).and(z.record(z.string(), z.unknown()))]).optional(), skill_name_next: z.string().max(200).optional(), skill_name_served: z.string().max(200).optional(), skill_republish_needed: z.boolean().optional(), skill_republish_reasons: z.array(z.enum(["name_changed", "content_changed"])).optional(), slug: z.string().max(200).nullable().optional(), stale_reasons: z.array(z.union([z.object({kind: z.literal("age"), last_updated_at: z.string().max(64), stale_after_days: z.number().int().gte(-9007199254740991).lte(9007199254740991)}).and(z.record(z.string(), z.unknown())), z.object({dependencies: z.array(z.object({changed_at: z.string().max(64).nullable(), id: z.string().max(128), ref: z.string().max(200), title: z.string().max(500), type_slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))), kind: z.literal("dependency_changed"), total: z.number().int().gte(-9007199254740991).lte(9007199254740991), truncated: z.boolean(), unavailable_count: z.number().int().gte(-9007199254740991).lte(9007199254740991)}).and(z.record(z.string(), z.unknown()))])).optional(), summary: z.string().max(2000).nullable().optional(), summary_stale: z.boolean().optional(), summary_updated_at: z.string().max(64).nullable().optional(), tags: z.array(z.object({name: z.string().max(200), slug: z.string().max(200)}).and(z.record(z.string(), z.unknown()))).optional(), tags_dropped: z.boolean().optional(), tags_truncated: z.boolean().optional(), title: z.string().max(2000).optional(), token_bindings: z.record(z.string(), z.unknown()).optional(), type_color: z.string().max(128).nullable().optional(), type_content_md_max: z.number().int().gte(-9007199254740991).lte(9007199254740991).nullable().optional(), type_guidance: z.string().max(90000).nullable().optional(), type_guidance_check: z.object({check: z.string().max(400), prompt: z.string().max(1000)}).and(z.record(z.string(), z.unknown())).optional(), type_guidance_note: z.string().max(4000).optional(), type_guidance_status: z.enum(["current", "delivered"]).optional(), type_guidance_status_reason: z.string().max(128).optional(), type_icon: z.string().max(128).nullable().optional(), type_id: z.string().max(36).optional(), type_log_entry_order: z.string().max(128).nullable().optional(), type_log_target_type_id: z.string().max(128).nullable().optional(), type_name: z.string().max(200).optional(), type_paragraph_rendering: z.string().max(128).nullable().optional(), type_rollover: z.string().max(128).nullable().optional(), type_share_template: z.string().max(128).nullable().optional(), type_slug: z.string().max(200).optional(), type_structure: z.string().max(128).nullable().optional(), unreferenced: z.boolean().optional(), updated_at: z.string().max(64).optional(), version_skip_reason: z.string().max(128).nullable().optional(), version_skipped: z.boolean().optional(), viewer_can_write: z.boolean().optional(), visibility: z.enum(["self", "link", "public", "org_view", "org_edit"]).optional(), warnings: z.array(z.string().max(4000)).optional(), workspace_id: z.string().max(128).nullable().optional()}).and(z.record(z.string(), 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 }; /** * Duplicate a capsule * * POST /api/preview/capsules/{id}/duplicate * * Also accepts auth: cookieAuth, oauth2 */ export const createApiApiPreviewCapsulesIdDuplicate = async (args: CreateApiApiPreviewCapsulesIdDuplicateArgs, options: CreateApiApiPreviewCapsulesIdDuplicateOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/preview/capsules/${encodeURIComponent(String(args.id))}/duplicate${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(createApiApiPreviewCapsulesIdDuplicateResponse, await res.json()) };