Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
Remove parse job SSE events
jinzhenj672183124dbb
diff --git a/docs/next/api.md b/docs/next/api.mdindex 1d4e38c0..2cb59360 100644--- a/docs/next/api.md+++ b/docs/next/api.md@@ -21,7 +21,7 @@ Unified API 文档描述两类部署形态下的同一套 API:2. [响应与错误](api/responses.md): 成功响应、错误 envelope、请求追踪。3. [Health、Models 与 Tiers](api/health-models.md): 服务能力、模型列表、解析档位。4. [Uploads 与 Files](api/uploads-files.md): 上传生命周期、文件对象、产物下载。-5. [Parse Jobs](api/parse-jobs.md): 解析任务、轮询、SSE。+5. [Parse Jobs](api/parse-jobs.md): 解析任务、轮询。6. [Chat 与 Responses](api/chat.md): OpenAI-compatible 文档对话接口。7. [Webhooks](api/webhooks.md): 异步回调协议。8. [Usage 与 Limits](api/usage-limits.md): access level、限流、用量查询。diff --git a/docs/next/api/README.md b/docs/next/api/README.mdindex f7aab744..a9a8630f 100644--- a/docs/next/api/README.md+++ b/docs/next/api/README.md@@ -56,7 +56,6 @@ ID 使用 OpenAI 风格的前缀加随机串。官方 API 使用 24 字符 base6| `DELETE` | `/v1/files/{file_id}` | 删除文件 || `POST` | `/v1/parse/jobs` | 创建解析任务 || `GET` | `/v1/parse/jobs/{job_id}` | 查询任务 |-| `GET` | `/v1/parse/jobs/{job_id}/events` | SSE 任务事件 || `GET` | `/v1/parse/jobs` | 列出任务 || `DELETE` | `/v1/parse/jobs/{job_id}` | 取消任务 || `POST` | `/v1/chat/completions` | Chat Completions 文档对话 |@@ -92,7 +91,6 @@ Local Parse Server 默认监听 loopback 且不启用鉴权。启用 `--api-key`Local Parse Server 的目标是复用客户端协议,而不是完整模拟公网平台。它可以简化以下能力:- 不支持 Webhook。-- 不支持 Parse Job SSE 事件流时,客户端使用轮询。- 上传 URL 可以指向本地 server 的临时上传 endpoint,而不是 OSS。- 文件产物下载可以直接返回 `200 + body`,不必返回 CDN 重定向。- 支持 `local` source,由 server 直接读取 allowlist 内的本地路径。diff --git a/docs/next/api/changes.md b/docs/next/api/changes.mdindex ed192fe9..d695a9db 100644--- a/docs/next/api/changes.md+++ b/docs/next/api/changes.md@@ -2,6 +2,12 @@范围: NEXT v1 API 标准的破坏性或需要迁移的行为变化。+## 2026-07-08: 删除 parse job SSE events++NEXT v1 API 不再定义 `GET /v1/parse/jobs/{job_id}/events`,parse job 响应中也不再返回 `links.events`。客户端统一通过 `GET /v1/parse/jobs/{job_id}` 查询任务状态和结果。++线上 API Server 不支持长连接;本地 SSE 实现也只是服务端每秒检查 job 状态后通过长连接转发,相比客户端轮询没有实质效率收益。删除这一路径可以避免线上/本地协议分叉,并让 parse job 保持单一轮询模型。+## 2026-07-08: 删除 parse job `wait` 参数`POST /v1/parse/jobs` 不再支持 `wait`。创建 parse job 始终返回 `202` 和 job 引用,客户端通过 `GET /v1/parse/jobs/{job_id}` 查询状态和结果。diff --git a/docs/next/api/health-models.md b/docs/next/api/health-models.mdindex be0fa8a2..6a9ec8a5 100644--- a/docs/next/api/health-models.md+++ b/docs/next/api/health-models.md@@ -22,7 +22,6 @@ GET /v1/health HTTP/1.1"status": "ok","version": "1.0.0","features": {- "sse": true,"webhook": true}}@@ -35,7 +34,6 @@ GET /v1/health HTTP/1.1| `status` | string | 是 | 固定为 `"ok"`。如果服务不可用,应由 HTTP 状态码表达,而不是返回其他 status。 || `version` | string | 是 | API 服务版本。 || `features` | object | 是 | 当前部署支持的外围能力。 |-| `features.sse` | bool | 是 | 是否支持 Parse Job SSE 事件流。 || `features.webhook` | bool | 是 | 是否支持 Webhook 回调。 |错误:@@ -175,7 +173,6 @@ Local Parse Server 的 `health` 通常返回:"status": "ok","version": "1.0.0","features": {- "sse": false,"webhook": false}}diff --git a/docs/next/api/parse-jobs.md b/docs/next/api/parse-jobs.mdindex 1acf3d0e..b09bc836 100644--- a/docs/next/api/parse-jobs.md+++ b/docs/next/api/parse-jobs.md@@ -2,7 +2,7 @@状态: Draft读者: API 使用者、服务端开发者、SDK 开发者-范围: 解析任务创建、查询、轮询和事件流+范围: 解析任务创建、查询和轮询来源: 由根目录旧 Unified API 底稿迁移整理而来## 任务模型@@ -159,7 +159,6 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定],"links": {"self": "/v1/parse/jobs/job_01HXYZ123ABCDEF",- "events": "/v1/parse/jobs/job_01HXYZ123ABCDEF/events","cancel": "/v1/parse/jobs/job_01HXYZ123ABCDEF"}}@@ -177,7 +176,6 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定| `access_level` | string | `anonymous` 或 `registered`。 || `files[]` | array | 输入文件的队列状态。 || `links.self` | string | 查询任务 URL。 |-| `links.events` | string 或 null | SSE URL;不支持 SSE 时可以为 `null` 或省略。 || `links.cancel` | string | 取消任务 URL。 |### 终态响应@@ -262,42 +260,6 @@ OCR 策略和图片分析能力由 `tier` 与服务端实际引擎自动决定|------|------|| 404 | `job_not_found` |-## GET `/v1/parse/jobs/{job_id}/events`--官方 API 支持 SSE 任务事件流。--```http-GET /v1/parse/jobs/job_01HXYZ.../events-Authorization: Bearer <MINERU_API_KEY>-Accept: text/event-stream-```--事件示例:--```text-event: status-data: {"status":"running","progress":{"completed":0,"total":2}}--event: file_completed-data: {"file_id":"file-01HXYZA","status":"completed"}--event: done-data: {"job_id":"job_01HXYZ...","status":"completed"}-```--事件类型:--| 事件 | 说明 |-|------|------|-| `status` | job 级状态或进度变化。 |-| `file_started` | 单文件开始处理。 |-| `file_completed` | 单文件处理成功。 |-| `file_failed` | 单文件处理失败。 |-| `done` | job 进入终态。 |-| `error` | 事件流自身发生错误。 |--客户端必须同时实现轮询,因为本地 server 和部分部署可能不支持 SSE。-## GET `/v1/parse/jobs`列出任务。anonymous 用户调用返回 `403 list_requires_api_key`。@@ -377,7 +339,6 @@ data: {"job_id":"job_01HXYZ...","status":"completed"}Local Parse Server 的任务 API 与官方 API 保持同一结构,但有以下实现差异:- 不支持 Webhook 时,`health.features.webhook` 必须为 `false`;收到 `callback` 时应返回 `400 invalid_request` 或明确忽略。-- 不支持 SSE 时,`health.features.sse` 必须为 `false`,`links.events` 可以为 `null` 或省略。- 支持 `local` source,但必须限制在配置允许的根目录内。- `local` source 可以不生成输入 `file_id`;响应中应保留 `name` 和文件级状态。- 省略 `tier` 或传 `null` 时,只能选择本地可发现的 `medium` 或 `high`,不能回退到 `flash`。diff --git a/mineru/parser/api_server.py b/mineru/parser/api_server.pyindex d6ad0227..579c956f 100644--- a/mineru/parser/api_server.py+++ b/mineru/parser/api_server.py@@ -35,7 +35,7 @@ import uvicornfrom fastapi import APIRouter, Body, Depends, FastAPI, HTTPException, Path, Query, Request, Response, statusfrom fastapi.exceptions import RequestValidationErrorfrom fastapi.middleware.gzip import GZipMiddleware-from fastapi.responses import JSONResponse, StreamingResponse+from fastapi.responses import JSONResponsefrom pydantic import BaseModel, ConfigDict, Fieldfrom ..types import Tier, validate_tier@@ -121,17 +121,6 @@ AccessLevel = Literal["anonymous", "registered"]FilePurpose = Literal["parse", "parse_output", "input_image"]"""File purpose: source files, parse artifacts, or chat/response input images."""-SSEEventType = Literal[- "status",- "file_started",- "file_completed",- "file_failed",- "done",- "error",-]-"""SSE event types."""--# ── helper ───────────────────────────────────────────────────────────@@ -283,7 +272,6 @@ class ModelHealthStatus(BaseModel):class HealthFeatures(BaseModel):model_config = _PYDANTIC_CONFIG- sse: bool = Falsewebhook: bool = False@@ -293,7 +281,7 @@ class HealthResponse(BaseModel):version: strparser_version: str | None = Nonemodels: ModelHealthStatus | None = None- features: HealthFeatures = Field(default_factory=lambda: HealthFeatures(sse=False, webhook=False))+ features: HealthFeatures = Field(default_factory=HealthFeatures)# ── Models API ───────────────────────────────────────────────────────@@ -465,7 +453,6 @@ class CreateJobRequest(BaseModel):class JobLinks(BaseModel):model_config = _PYDANTIC_CONFIGself: str- events: strcancel: str@@ -1070,7 +1057,6 @@ class JobStore:output_formats=req.output_formats,links=JobLinks(self=f"/v1/parse/jobs/{job_id}",- events=f"/v1/parse/jobs/{job_id}/events",cancel=f"/v1/parse/jobs/{job_id}",),)@@ -1162,7 +1148,7 @@ class JobStore:access_level=access_level,progress=rec.progress,files=rec.files,- links=rec.links or JobLinks(self="", events="", cancel=""),+ links=rec.links or JobLinks(self="", cancel=""),)def usage(self, access_level: AccessLevel) -> UsageResponse:@@ -1755,69 +1741,6 @@ async def get_job(return job_store.build_response(job_store.get(job_id))-@_router.get(- "/parse/jobs/{job_id}/events",- response_model=None,- status_code=status.HTTP_200_OK,- responses={**_ERR_404},- tags=["Jobs"],-)-async def get_job_events(- job_id: str = Path(description="Job ID"),- job_store: JobStore = Depends(_get_job_store),-) -> StreamingResponse:- """SSE stream of job status events."""- rec = job_store.get(job_id)-- async def _event_stream() -> Any:- last_status = rec.status- yielded: set[str] = set() # file names already yielded per-file events-- def _yield_event(event: str, data: str) -> str:- return f"event: {event}\ndata: {data}\n\n"-- yield _yield_event(- "status",- f'{{"status":"{rec.status}","progress":{{"completed":{rec.progress.completed},"failed":{rec.progress.failed},"total":{rec.progress.total}}}}}',- )-- while rec.status in ("queued", "running"):- if rec.status != last_status:- yield _yield_event(- "status",- f'{{"status":"{rec.status}","progress":{{"completed":{rec.progress.completed},"failed":{rec.progress.failed},"total":{rec.progress.total}}}}}',- )- last_status = rec.status-- for fr in rec.files:- name = fr.name or fr.file_id- if fr.status == "running" and name not in yielded:- yield _yield_event(- "file_started",- f'{{"file_id":"{fr.file_id}","status":"running"}}',- )- yielded.add(name)- elif fr.status == "completed" and (f"done_{name}" not in yielded):- yield _yield_event(- "file_completed",- f'{{"file_id":"{fr.file_id}","status":"completed"}}',- )- yielded.add(f"done_{name}")- elif fr.status == "failed" and (f"done_{name}" not in yielded):- err_msg = fr.error.message.replace('"', '\\"') if fr.error else ""- yield _yield_event(- "file_failed",- f'{{"file_id":"{fr.file_id}","status":"failed","error":{{"code":"{fr.error.code}","message":"{err_msg}"}}}}',- )- yielded.add(f"done_{name}")-- await asyncio.sleep(1)-- yield _yield_event("done", f'{{"job_id":"{rec.id}","status":"{rec.status}"}}')-- return StreamingResponse(_event_stream(), media_type="text/event-stream")--@_router.get("/parse/jobs",response_model=JobListResponse,diff --git a/tests/unittest/test_parser_api_contract.py b/tests/unittest/test_parser_api_contract.pyindex fee1d9b9..8b4154ba 100644--- a/tests/unittest/test_parser_api_contract.py+++ b/tests/unittest/test_parser_api_contract.py@@ -28,6 +28,7 @@ from mineru.parser.api_server import (FileParseInfo,FileStore,HealthResponse,+ JobLinks,JobListItem,OutputFileRef,OutputFiles,@@ -1231,6 +1232,24 @@ def test_output_files_expose_new_names_without_inline_content() -> None:OutputFileRef.model_validate({"file_id": "file-1", "bytes": 12, "content": "inline"})+def test_job_links_do_not_expose_sse_events() -> None:+ links = JobLinks(self="/v1/parse/jobs/job_1", cancel="/v1/parse/jobs/job_1")++ assert links.model_dump() == {+ "self": "/v1/parse/jobs/job_1",+ "cancel": "/v1/parse/jobs/job_1",+ }++ with pytest.raises(ValidationError):+ JobLinks.model_validate(+ {+ "self": "/v1/parse/jobs/job_1",+ "events": "/v1/parse/jobs/job_1/events",+ "cancel": "/v1/parse/jobs/job_1",+ }+ )++@pytest.mark.parametrize(("output_format", "output_attr"),[@@ -1708,7 +1727,7 @@ def test_api_contract_uses_parser_version_not_backend_version() -> None:"status": "ok","version": "3.2.1","parser_version": "3.2.1",- "features": {"sse": False, "webhook": False},+ "features": {"webhook": False},}with pytest.raises(ValidationError):