/** 受控文档正文保存与编辑租约 API */ const API_BASE = ''; export interface SaveDocumentContentPayload { doc_id: string; user_id: number; user_name: string; user_role: string; markdown_body: string; expected_sha256?: string; work_dir?: string; } export async function saveDocumentContent(payload: SaveDocumentContentPayload): Promise<{ content_sha256: string; doc?: { lease_holder_type?: string; lease_holder_id?: string; lease_expires_at?: string; content_sha256?: string; }; }> { const resp = await fetch(`${API_BASE}/api/v1/docgov/content`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload), }); if (!resp.ok) { const text = await resp.text(); throw new Error(text || `save content failed: ${resp.status}`); } return resp.json(); } export function mapLeaseToAstEditLease(doc: { lease_holder_type?: string; lease_holder_id?: string; lease_expires_at?: string; }): { holderType?: 'squad' | 'human' | ''; holderId?: string; expiresAt?: string } | undefined { if (!doc?.lease_holder_type) return undefined; const holderType = doc.lease_holder_type as 'squad' | 'human' | ''; return { holderType, holderId: doc.lease_holder_id, expiresAt: doc.lease_expires_at, }; }