refactor(api): migrate web chat endpoints to BaseModel#37962
Open
cqjjjzr wants to merge 2 commits into
Open
Conversation
5 tasks
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-27 18:36:58.555014340 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-27 18:36:43.710965525 +0000
@@ -624,8 +624,6 @@
--> tests/test_containers_integration_tests/controllers/mcp/test_mcp.py:455:37
ERROR Class member `SessionMatcher.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/test_containers_integration_tests/controllers/service_api/dataset/test_dataset.py:28:9
-ERROR `in` is not supported between `Literal['webapp-logo']` and `None` [not-iterable]
- --> tests/test_containers_integration_tests/controllers/web/test_site.py:136:16
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
--> tests/test_containers_integration_tests/controllers/web/test_wraps.py:75:33
ERROR Argument `SimpleNamespace` is not assignable to parameter `webapp_settings` with type `WebAppSettings | None` in function `controllers.web.wraps._validate_user_accessibility` [bad-argument-type]
@@ -2446,14 +2444,6 @@
--> tests/unit_tests/controllers/trigger/test_webhook.py:84:16
ERROR Cannot index into `Response` [bad-index]
--> tests/unit_tests/controllers/trigger/test_webhook.py:101:16
-ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
- --> tests/unit_tests/controllers/web/test_human_input_form.py:217:54
-ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
- --> tests/unit_tests/controllers/web/test_human_input_form.py:217:65
-ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
- --> tests/unit_tests/controllers/web/test_human_input_form.py:251:54
-ERROR Argument `SimpleNamespace` is not assignable to parameter `site` with type `Site` in function `controllers.web.site.serialize_app_site_payload` [bad-argument-type]
- --> tests/unit_tests/controllers/web/test_human_input_form.py:251:65
ERROR Object of class `ModuleType` has no attribute `web_ns` [missing-attribute]
--> tests/unit_tests/controllers/web/test_message_list.py:41:9
ERROR Object of class `ModuleType` has no attribute `WebApiResource` [missing-attribute]
@@ -4836,10 +4826,10 @@
--> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:62:9
ERROR Class member `_FieldExpression.__eq__` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/unit_tests/core/rag/extractor/test_excel_extractor.py:62:9
-ERROR Argument `SimpleNamespace` is not assignable to parameter `upload_file` with type `UploadFile` in function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` [bad-argument-type]
- --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:73:67
-ERROR Argument `SimpleNamespace` is not assignable to parameter `upload_file` with type `UploadFile` in function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` [bad-argument-type]
- --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:74:67
+ERROR No matching overload found for function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` called with arguments: (upload_file=SimpleNamespace, return_text=Literal[False]) [no-matching-overload]
+ --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:73:54
+ERROR No matching overload found for function `core.rag.extractor.extract_processor.ExtractProcessor.load_from_upload_file` called with arguments: (upload_file=SimpleNamespace, return_text=Literal[True]) [no-matching-overload]
+ --> tests/unit_tests/core/rag/extractor/test_extract_processor.py:74:54
ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
--> tests/unit_tests/core/rag/extractor/test_extract_processor.py:150:41
ERROR Argument `SimpleNamespace` is not assignable to parameter `extract_setting` with type `ExtractSetting` in function `core.rag.extractor.extract_processor.ExtractProcessor.extract` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
Contributor
There was a problem hiding this comment.
Pull request overview
Migrates several web-facing Flask-RESTX request/response definitions toward Pydantic ResponseModel/BaseModel shapes, and updates the generated OpenAPI markdown + TypeScript contracts to match the new schemas (notably around human-input forms and web site metadata).
Changes:
- Refactors multiple web controllers to return
ResponseModel().model_dump(mode="json")/dump_response(...)payloads and updates response registrations accordingly. - Updates human-input form payload typing end-to-end (backend responses + frontend types/guards + generated contracts).
- Adds OpenAPI post-processing in
openapi-ts.api.config.tsto forge an “opaque” schema for responses that lack explicit schemas during codegen.
Reviewed changes
Copilot reviewed 21 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| web/types/workflow.ts | Makes form_token / expiration_time nullable for human-input form typing. |
| web/features/agent-v2/agent-detail/configure/components/preview/chat.tsx | Simplifies debug message answer extraction (but currently breaks typing). |
| web/contract/console/trigger.ts | Adjusts trigger subscription update contract output shape. |
| web/app/components/base/chat/chat/answer/human-input-content/human-input-form.tsx | Prevents submitting human-input actions when formToken is missing. |
| packages/contracts/openapi-ts.api.config.ts | Enhances OpenAPI normalization and zod resolver behavior for codegen. |
| packages/contracts/generated/api/web/zod.gen.ts | Regenerated web zod schemas after OpenAPI/model changes. |
| packages/contracts/generated/api/web/types.gen.ts | Regenerated web TS types after OpenAPI/model changes. |
| packages/contracts/generated/api/web/orpc.gen.ts | Regenerated web ORPC router bindings after OpenAPI/model changes. |
| packages/contracts/generated/api/console/files/zod.gen.ts | Regenerated console files zod schemas due to UploadConfig requiredness changes. |
| packages/contracts/generated/api/console/files/types.gen.ts | Regenerated console files TS types due to UploadConfig requiredness changes. |
| api/tests/unit_tests/controllers/web/test_human_input_form.py | Updates unit tests to match new controller return shapes and site disclaimer defaults. |
| api/tests/test_containers_integration_tests/controllers/web/test_site.py | Updates integration tests for new WebAppSiteResponse / WebModelConfigResponse models. |
| api/services/file_service.py | Tightens return type + simplifies get_file_preview implementation. |
| api/openapi/markdown/web-openapi.md | Regenerated web OpenAPI markdown (new schemas / response descriptions). |
| api/openapi/markdown/console-openapi.md | Regenerated console OpenAPI markdown (UploadConfig requiredness changes). |
| api/fields/file_fields.py | Makes UploadConfig limits required (no longer nullable). |
| api/controllers/web/workflow.py | Removes GeneratedAppResponse response model wiring; returns SimpleResultResponse JSON for stop. |
| api/controllers/web/site.py | Replaces RESTX marshalling with Pydantic response models (WebSiteResponse, WebAppSiteResponse, etc.). |
| api/controllers/web/saved_message.py | Minor formatting + documents 204 delete response. |
| api/controllers/web/remote_files.py | Streamlines response dumping and return flow. |
| api/controllers/web/message.py | Removes GeneratedAppResponse response model wiring; keeps compact response generation. |
| api/controllers/web/human_input_form.py | Converts HITL endpoints to ResponseModel responses + richer OpenAPI docs. |
| api/controllers/web/human_input_file_upload.py | Uses dump_response for local upload response and returns pre-dumped payload. |
| api/controllers/web/files.py | Uses dump_response for uploaded file responses. |
| api/controllers/web/completion.py | Removes GeneratedAppResponse response model wiring; keeps compact response generation + returns typed stop responses. |
| api/controllers/web/audio.py | Introduces AudioToTextResponse ResponseModel and uses dump_response for ASR results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
220
to
222
| const getAgentDebugMessageAnswer = (message: MessageDetailResponse) => { | ||
| const legacyAnswer = (message as AgentDebugMessageWithLegacyAnswer).answer | ||
|
|
||
| return message.re_sign_file_url_answer ?? legacyAnswer ?? '' | ||
| return message.answer ?? '' | ||
| } |
Comment on lines
+217
to
+221
| const hasOpaqueContractSuccessResponse = (operation: SwaggerOperation) => { | ||
| return Object.entries(operation.responses ?? {}).some(([status, response]) => { | ||
| return /^2\d\d$/.test(status) && isObject(response) && isOpaqueContractResponse(response) | ||
| }) | ||
| } |
Comment on lines
+223
to
+242
| const normalizeOpaqueContractResponses = (document: SwaggerDocument) => { | ||
| // Some backend endpoints has no schema (e.g. external) and will trap heyapi here | ||
| // So we forge an opaque schema here | ||
| for (const pathItem of Object.values(document.paths ?? {})) { | ||
| for (const [method, operation] of Object.entries(pathItem)) { | ||
| if (!operationMethods.has(method) || !isObject(operation)) | ||
| continue | ||
|
|
||
| const swaggerOperation = operation as SwaggerOperation | ||
| if (!hasOpaqueContractSuccessResponse(swaggerOperation)) | ||
| continue | ||
|
|
||
| Object.values(swaggerOperation.responses ?? {}) | ||
| .filter(response => isObject(response) && isOpaqueContractResponse(response)) | ||
| .forEach((response) => { | ||
| response.content = opaqueJsonContent() | ||
| }) | ||
| } | ||
| } | ||
| } |
ffe3a57 to
eb199e4
Compare
Comment on lines
7
to
10
| import services | ||
| from controllers.common.controller_schemas import TextToAudioPayload as TextToAudioPayloadBase | ||
| from controllers.common.fields import AudioBinaryResponse, AudioTranscriptResponse | ||
| from controllers.web import web_ns | ||
| from controllers.web.error import ( |
Comment on lines
52
to
+53
| register_schema_models(web_ns, TextToAudioPayload) | ||
| register_response_schema_models(web_ns, AudioBinaryResponse, AudioTranscriptResponse) | ||
| register_response_schema_models(web_ns, AudioToTextResponse) |
Comment on lines
+122
to
124
| # response-contract:ignore provider audio bytes; TODO: model binary audio response if shape is standardized. | ||
| @web_ns.response(200, "Success") | ||
| def post(self, app_model: App, end_user: EndUser): |
Comment on lines
+71
to
+72
| class HumanInputFormSubmitResponse(ResponseModel): | ||
| pass |
Comment on lines
+159
to
+162
| assert response.site.input_placeholder == "Ask the app" | ||
| assert response.site.custom_disclaimer == "" | ||
|
|
||
| def test_nullable_site_fields_preserve_none(self) -> None: |
2df04db to
9bb23b7
Compare
Squashes the response contract generation fixes from PR langgenius#38042 into the branch base.
Squashes the branch payload, including generated markdown and TypeScript contract updates.
9bb23b7 to
871a6f1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #<issue number>.Summary
See #28015 . Migrating Flask-RESTX request/response payload and query param models to Pydantic BaseModels.
Affected:
Also fixing generated response contract output to stay fresh for this slice.
Recommended/Required to merge: None.
Checklist
make lint && make type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods