fix: align local doc_id prefix and createdAt format with the cloud

Local doc ids now carry the cloud's pi- namespace prefix (random token
stays uuid4 hex — nothing parses cuid internals, the prefix is the
contract; chat ids already mirrored chatcmpl-). createdAt now matches
the server byte for byte: the cloud emits the DB datetime's bare
isoformat — naive UTC, second precision — while we emitted microseconds
plus +00:00.
This commit is contained in:
Ray
2026-08-06 18:21:39 +08:00
parent fd2ba98ddb
commit cd44ef0bd5
2 changed files with 6 additions and 2 deletions
+3 -2
View File
@@ -58,7 +58,8 @@ CHAT_CONTEXT_TOKEN_LIMIT = 100_000
def _now_iso() -> str:
return datetime.now(timezone.utc).isoformat()
# Mirror the cloud's createdAt format: naive UTC ISO, second precision.
return datetime.now(timezone.utc).replace(tzinfo=None).isoformat(timespec="seconds")
class LocalAPI:
@@ -117,7 +118,7 @@ class LocalAPI:
except Exception as e:
raise PageIndexAPIError(f"Failed to submit document: {e}") from e
doc_id = str(uuid.uuid4())
doc_id = "pi-" + uuid.uuid4().hex
meta = {
"id": doc_id,
"name": os.path.basename(file_path),
+3
View File
@@ -1,5 +1,6 @@
"""SDK surface tests: PageIndexClient in local and cloud mode."""
import json
import re
import shutil
import sys
import types
@@ -156,8 +157,10 @@ def test_get_ocr(local_client, indexed_doc):
def test_document_management(local_client, indexed_doc):
assert indexed_doc.startswith("pi-")
doc = local_client.get_document(indexed_doc)
assert doc["id"] == indexed_doc
assert re.fullmatch(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}", doc["createdAt"])
assert doc["name"] == "sample.pdf"
assert doc["description"] == "A test document."
assert doc["status"] == "completed"