diff --git a/apply_events.cfm b/apply_events.cfm index 0b5a1e0..89d57ab 100644 --- a/apply_events.cfm +++ b/apply_events.cfm @@ -8,14 +8,28 @@ + + - + ALTER TABLE spec_events ADD COLUMN IF NOT EXISTS prompt_version UUID + + + ALTER TABLE spec_events ADD COLUMN IF NOT EXISTS source_document_id UUID + + + + + + ALTER TABLE spec_events ADD COLUMN IF NOT EXISTS raw_llm_response JSONB + + + @@ -53,7 +67,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, comment, status, prompt_version, source_document_id, raw_llm_response) SELECT , , @@ -62,7 +76,9 @@ name_hash, 'full_replace', 'applied', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL FROM spec_current WHERE contract_id = @@ -111,7 +127,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version, source_document_id, raw_llm_response) VALUES ( , , @@ -120,7 +136,9 @@ ::jsonb, , 'applied', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL ) RETURNING id @@ -145,7 +163,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version, source_document_id, raw_llm_response) VALUES ( , , @@ -154,7 +172,9 @@ ::jsonb, , 'pending', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL ) @@ -167,7 +187,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, new_values, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, new_values, comment, status, prompt_version, source_document_id, raw_llm_response) VALUES ( , , @@ -177,7 +197,9 @@ ::jsonb, , 'applied', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL ) RETURNING id @@ -199,7 +221,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, target_hash, comment, status, prompt_version, source_document_id, raw_llm_response) VALUES ( , , @@ -208,7 +230,9 @@ , , 'applied', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL ) @@ -220,7 +244,7 @@ - INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version) + INSERT INTO spec_events (contract_id, supplement_id, seq, action, new_values, comment, status, prompt_version, source_document_id, raw_llm_response) VALUES ( , , @@ -229,7 +253,9 @@ ::jsonb, , 'pending', - ::uuidNULL + ::uuidNULL, + ::uuidNULL, + ::jsonbNULL ) diff --git a/deploy/convert_server.py b/deploy/convert_server.py index e584e3a..ef62ecc 100755 --- a/deploy/convert_server.py +++ b/deploy/convert_server.py @@ -113,9 +113,9 @@ class Handler(BaseHTTPRequestHandler): self._sse({"type": "error", "message": f"reset failed: HTTP {r.status_code}"}) return - # 1. Список supplements + # 1. Список supplements (с document_id для provenance) supps = self._lucee_query( - f"SELECT s.id, s.type, d.filename FROM supplements s " + f"SELECT s.id, s.type, d.filename, d.id as document_id FROM supplements s " f"JOIN documents d ON s.document_id=d.id " f"WHERE s.contract_id='{cid}' AND d.elements_json IS NOT NULL ORDER BY s.created_at" ) @@ -234,10 +234,16 @@ class Handler(BaseHTTPRequestHandler): self._sse({"type": "llm_done", "supplement_id": sid, "filename": s["filename"], "ops_count": len(ops), "mode": mode, "time_s": elapsed}) - # Применить + # Применить (с provenance: document_id, prompt_id, raw_llm_response) apply_resp = httpx.post( f"{LUCEE_URL}/apply_events.cfm?contract_id={cid}&mode={mode}", - json={"supplement_id": sid, "ops": ops, "prompt_id": prompt_id}, timeout=30 + json={ + "supplement_id": sid, + "document_id": s.get("document_id", ""), + "ops": ops, + "prompt_id": prompt_id, + "raw_llm_response": llm_result + }, timeout=30 ) if apply_resp.status_code == 200: ar = apply_resp.json() diff --git a/index.cfm b/index.cfm index be255a5..0f7fd40 100644 --- a/index.cfm +++ b/index.cfm @@ -75,7 +75,7 @@
Nubes - Сверка договоров — LLM AI-driven Event Sourcing v1.0.113 — Lucee + Сверка договоров — LLM AI-driven Event Sourcing v1.0.114 — Lucee