refactor(web): migrate trial app console contracts (#38254)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Stephen Zhou
2026-07-01 16:31:49 +00:00
committed by GitHub
co-authored by autofix-ci[bot]
parent 8540ca9242
commit ca8b680322
23 changed files with 1934 additions and 824 deletions
+258 -5
View File
@@ -1,9 +1,10 @@
import logging
from datetime import datetime
from typing import Any, Literal, cast
from flask import request
from flask_restx import Resource, fields, marshal, marshal_with
from pydantic import BaseModel, Field
from pydantic import AliasChoices, BaseModel, Field, field_validator
from sqlalchemy import select
from werkzeug.exceptions import Forbidden, InternalServerError, NotFound
@@ -63,6 +64,7 @@ from fields.app_fields import (
site_fields,
tag_fields,
)
from fields.base import ResponseModel
from fields.dataset_fields import dataset_fields
from fields.member_fields import simple_account_fields
from fields.message_fields import SuggestedQuestionsResponse
@@ -75,7 +77,7 @@ from fields.workflow_fields import (
from graphon.graph_engine.manager import GraphEngineManager
from graphon.model_runtime.errors.invoke import InvokeError
from libs import helper
from libs.helper import uuid_value
from libs.helper import to_timestamp, uuid_value
from models import Account
from models.account import TenantStatus
from models.model import AppMode, Site
@@ -180,6 +182,254 @@ class TrialDatasetListQuery(BaseModel):
ids: list[str] = Field(default_factory=list, description="Dataset IDs")
type TrialAppMode = Literal["chat", "agent-chat", "advanced-chat", "workflow", "completion"]
type TrialIconType = Literal["emoji", "image", "link"]
type JsonObject = dict[str, Any]
class TrialAppModel(ResponseModel):
provider: str
name: str
mode: str | None = None
completion_params: JsonObject = Field(default_factory=dict)
class TrialAppAgentMode(ResponseModel):
enabled: bool | None = None
strategy: str | None = None
tools: list[JsonObject] = Field(default_factory=list)
class TrialAppModelConfigResponse(ResponseModel):
opening_statement: str | None = None
suggested_questions: list[str] = Field(
default_factory=list,
validation_alias=AliasChoices("suggested_questions_list", "suggested_questions"),
)
suggested_questions_after_answer: JsonObject | None = Field(
default=None,
validation_alias=AliasChoices("suggested_questions_after_answer_dict", "suggested_questions_after_answer"),
)
speech_to_text: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("speech_to_text_dict", "speech_to_text")
)
text_to_speech: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("text_to_speech_dict", "text_to_speech")
)
retriever_resource: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("retriever_resource_dict", "retriever_resource")
)
annotation_reply: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("annotation_reply_dict", "annotation_reply")
)
more_like_this: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("more_like_this_dict", "more_like_this")
)
sensitive_word_avoidance: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("sensitive_word_avoidance_dict", "sensitive_word_avoidance")
)
external_data_tools: list[JsonObject] = Field(
default_factory=list, validation_alias=AliasChoices("external_data_tools_list", "external_data_tools")
)
model: TrialAppModel | None = Field(default=None, validation_alias=AliasChoices("model_dict", "model"))
user_input_form: list[JsonObject] = Field(
default_factory=list, validation_alias=AliasChoices("user_input_form_list", "user_input_form")
)
dataset_query_variable: str | None = None
pre_prompt: str | None = None
agent_mode: TrialAppAgentMode | None = Field(
default=None,
validation_alias=AliasChoices("agent_mode_dict", "agent_mode"),
)
prompt_type: str | None = None
chat_prompt_config: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("chat_prompt_config_dict", "chat_prompt_config")
)
completion_prompt_config: JsonObject | None = Field(
default=None, validation_alias=AliasChoices("completion_prompt_config_dict", "completion_prompt_config")
)
dataset_configs: JsonObject | None = Field(
default=None,
validation_alias=AliasChoices("dataset_configs_dict", "dataset_configs"),
)
file_upload: JsonObject | None = Field(
default=None,
validation_alias=AliasChoices("file_upload_dict", "file_upload"),
)
created_by: str | None = None
created_at: int | None = None
updated_by: str | None = None
updated_at: int | None = None
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
class TrialDeletedToolResponse(ResponseModel):
type: str
tool_name: str
provider_id: str
class TrialTagResponse(ResponseModel):
id: str
name: str
type: str
class TrialSiteResponse(ResponseModel):
access_token: str | None = Field(default=None, validation_alias="code")
code: str | None = None
title: str
icon_type: TrialIconType | None = None
icon: str | None = None
icon_background: str | None = None
description: str | None = None
default_language: str
chat_color_theme: str | None = None
chat_color_theme_inverted: bool | None = None
customize_domain: str | None = None
copyright: str | None = None
privacy_policy: str | None = None
input_placeholder: str | None = None
custom_disclaimer: str | None = None
customize_token_strategy: str | None = None
prompt_public: bool | None = None
app_base_url: str | None = None
show_workflow_steps: bool | None = None
use_icon_as_answer_icon: bool | None = None
created_by: str | None = None
created_at: int | None = None
updated_by: str | None = None
updated_at: int | None = None
icon_url: str | None = None
@field_validator("icon_type", mode="before")
@classmethod
def _normalize_icon_type(cls, value: Any) -> str | None:
if hasattr(value, "value"):
return value.value
return value
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
class TrialWorkflowPartialResponse(ResponseModel):
id: str
created_by: str | None = None
created_at: int | None = None
updated_by: str | None = None
updated_at: int | None = None
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
class TrialAppDetailResponse(ResponseModel):
id: str
name: str
description: str | None = None
mode: TrialAppMode = Field(validation_alias="mode_compatible_with_agent")
icon_type: TrialIconType | None = None
icon: str | None = None
icon_background: str | None = None
icon_url: str | None = None
enable_site: bool
enable_api: bool
model_config_: TrialAppModelConfigResponse | None = Field(
default=None,
validation_alias=AliasChoices("app_model_config", "model_config"),
alias="model_config",
)
workflow: TrialWorkflowPartialResponse | None = None
api_base_url: str | None = None
use_icon_as_answer_icon: bool | None = None
max_active_requests: int | None = None
created_by: str | None = None
created_at: int | None = None
updated_by: str | None = None
updated_at: int | None = None
deleted_tools: list[TrialDeletedToolResponse] = Field(default_factory=list)
access_mode: str | None = None
tags: list[TrialTagResponse] = Field(default_factory=list)
permission_keys: list[str] = Field(default_factory=list)
site: TrialSiteResponse
@field_validator("icon_type", mode="before")
@classmethod
def _normalize_icon_type(cls, value: Any) -> str | None:
if hasattr(value, "value"):
return value.value
return value
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
class TrialDatasetResponse(ResponseModel):
id: str
name: str
description: str | None = None
permission: str | None = None
data_source_type: str | None = None
indexing_technique: str | None = None
created_by: str | None = None
created_at: int | None = None
permission_keys: list[str] = Field(default_factory=list)
class TrialDatasetListResponse(ResponseModel):
data: list[TrialDatasetResponse]
has_more: bool
limit: int
total: int
page: int
class TrialWorkflowAccount(ResponseModel):
id: str
name: str | None = None
email: str | None = None
class TrialWorkflowResponse(ResponseModel):
id: str
graph: JsonObject = Field(validation_alias=AliasChoices("graph_dict", "graph"))
features: JsonObject = Field(default_factory=dict, validation_alias=AliasChoices("features_dict", "features"))
hash: str | None = Field(default=None, validation_alias=AliasChoices("unique_hash", "hash"))
version: str | None = None
marked_name: str | None = None
marked_comment: str | None = None
created_by: TrialWorkflowAccount | None = Field(
default=None,
validation_alias=AliasChoices("created_by_account", "created_by"),
)
created_at: int | None = None
updated_by: TrialWorkflowAccount | None = Field(
default=None,
validation_alias=AliasChoices("updated_by_account", "updated_by"),
)
updated_at: int | None = None
tool_published: bool | None = None
environment_variables: list[JsonObject] = Field(default_factory=list)
conversation_variables: list[JsonObject] = Field(default_factory=list)
rag_pipeline_variables: list[JsonObject] = Field(default_factory=list)
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
register_schema_models(
console_ns,
WorkflowRunRequest,
@@ -197,6 +447,9 @@ register_response_schema_models(
SimpleResultResponse,
SiteResponse,
SuggestedQuestionsResponse,
TrialAppDetailResponse,
TrialDatasetListResponse,
TrialWorkflowResponse,
)
@@ -566,7 +819,7 @@ class TrialAppParameterApi(Resource):
class AppApi(Resource):
@console_ns.response(200, "Success", app_detail_with_site_model)
@console_ns.response(200, "Success", console_ns.models[TrialAppDetailResponse.__name__])
@get_app_model_with_trial(None)
@marshal_with(app_detail_with_site_model)
def get(self, app_model):
@@ -579,7 +832,7 @@ class AppApi(Resource):
class AppWorkflowApi(Resource):
@console_ns.response(200, "Success", workflow_model)
@console_ns.response(200, "Success", console_ns.models[TrialWorkflowResponse.__name__])
@get_app_model_with_trial(None)
@marshal_with(workflow_model)
def get(self, app_model):
@@ -593,7 +846,7 @@ class AppWorkflowApi(Resource):
class DatasetListApi(Resource):
@console_ns.doc(params=query_params_from_model(TrialDatasetListQuery))
@console_ns.response(200, "Success", dataset_list_model)
@console_ns.response(200, "Success", console_ns.models[TrialDatasetListResponse.__name__])
@get_app_model_with_trial(None)
def get(self, app_model):
page = request.args.get("page", default=1, type=int)
+204 -3
View File
@@ -9385,7 +9385,7 @@ Bedrock retrieval test (internal use only)
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [TrialAppDetailWithSite](#trialappdetailwithsite)<br> |
| 200 | Success | **application/json**: [TrialAppDetailResponse](#trialappdetailresponse)<br> |
### [POST] /trial-apps/{app_id}/audio-to-text
#### Parameters
@@ -9452,7 +9452,7 @@ Bedrock retrieval test (internal use only)
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [TrialDatasetList](#trialdatasetlist)<br> |
| 200 | Success | **application/json**: [TrialDatasetListResponse](#trialdatasetlistresponse)<br> |
### [GET] /trial-apps/{app_id}/messages/{message_id}/suggested-questions
#### Parameters
@@ -9532,7 +9532,7 @@ Returns the site configuration for the application including theme, icons, and t
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [TrialWorkflow](#trialworkflow)<br> |
| 200 | Success | **application/json**: [TrialWorkflowResponse](#trialworkflowresponse)<br> |
### [POST] /trial-apps/{app_id}/workflows/run
**Run workflow**
@@ -18048,6 +18048,12 @@ Input field definition for snippet parameters.
| ---- | ---- | ----------- | -------- |
| JSONValueType | | | |
#### JsonObject
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| JsonObject | object | | |
#### JsonValue
| Name | Type | Description | Required |
@@ -21306,6 +21312,43 @@ Enum class for tool provider
| ---- | ---- | ----------- | -------- |
| tracing_provider | string | Tracing provider name | Yes |
#### TrialAppAgentMode
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| enabled | boolean | | No |
| strategy | string | | No |
| tools | [ [JsonObject](#jsonobject) ] | | No |
#### TrialAppDetailResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| access_mode | string | | No |
| api_base_url | string | | No |
| created_at | integer | | No |
| created_by | string | | No |
| deleted_tools | [ [TrialDeletedToolResponse](#trialdeletedtoolresponse) ] | | No |
| description | string | | No |
| enable_api | boolean | | Yes |
| enable_site | boolean | | Yes |
| icon | string | | No |
| icon_background | string | | No |
| icon_type | [TrialIconType](#trialicontype) | | No |
| icon_url | string | | No |
| id | string | | Yes |
| max_active_requests | integer | | No |
| mode | [TrialAppMode](#trialappmode) | | Yes |
| model_config | [TrialAppModelConfigResponse](#trialappmodelconfigresponse) | | No |
| name | string | | Yes |
| permission_keys | [ string ] | | No |
| site | [TrialSiteResponse](#trialsiteresponse) | | Yes |
| tags | [ [TrialTagResponse](#trialtagresponse) ] | | No |
| updated_at | integer | | No |
| updated_by | string | | No |
| use_icon_as_answer_icon | boolean | | No |
| workflow | [TrialWorkflowPartialResponse](#trialworkflowpartialresponse) | | No |
#### TrialAppDetailWithSite
| Name | Type | Description | Required |
@@ -21335,6 +21378,21 @@ Enum class for tool provider
| use_icon_as_answer_icon | boolean | | No |
| workflow | [TrialWorkflowPartial](#trialworkflowpartial) | | No |
#### TrialAppMode
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| TrialAppMode | string | | |
#### TrialAppModel
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| completion_params | [JsonObject](#jsonobject) | | No |
| mode | string | | No |
| name | string | | Yes |
| provider | string | | Yes |
#### TrialAppModelConfig
| Name | Type | Description | Required |
@@ -21364,6 +21422,35 @@ Enum class for tool provider
| updated_by | string | | No |
| user_input_form | [ object ] | | No |
#### TrialAppModelConfigResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| agent_mode | [TrialAppAgentMode](#trialappagentmode) | | No |
| annotation_reply | [JsonObject](#jsonobject) | | No |
| chat_prompt_config | [JsonObject](#jsonobject) | | No |
| completion_prompt_config | [JsonObject](#jsonobject) | | No |
| created_at | integer | | No |
| created_by | string | | No |
| dataset_configs | [JsonObject](#jsonobject) | | No |
| dataset_query_variable | string | | No |
| external_data_tools | [ [JsonObject](#jsonobject) ] | | No |
| file_upload | [JsonObject](#jsonobject) | | No |
| model | [TrialAppModel](#trialappmodel) | | No |
| more_like_this | [JsonObject](#jsonobject) | | No |
| opening_statement | string | | No |
| pre_prompt | string | | No |
| prompt_type | string | | No |
| retriever_resource | [JsonObject](#jsonobject) | | No |
| sensitive_word_avoidance | [JsonObject](#jsonobject) | | No |
| speech_to_text | [JsonObject](#jsonobject) | | No |
| suggested_questions | [ string ] | | No |
| suggested_questions_after_answer | [JsonObject](#jsonobject) | | No |
| text_to_speech | [JsonObject](#jsonobject) | | No |
| updated_at | integer | | No |
| updated_by | string | | No |
| user_input_form | [ [JsonObject](#jsonobject) ] | | No |
#### TrialConversationVariable
| Name | Type | Description | Required |
@@ -21406,6 +21493,30 @@ Enum class for tool provider
| limit | integer, <br>**Default:** 20 | Number of items per page | No |
| page | integer, <br>**Default:** 1 | Page number | No |
#### TrialDatasetListResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| data | [ [TrialDatasetResponse](#trialdatasetresponse) ] | | Yes |
| has_more | boolean | | Yes |
| limit | integer | | Yes |
| page | integer | | Yes |
| total | integer | | Yes |
#### TrialDatasetResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by | string | | No |
| data_source_type | string | | No |
| description | string | | No |
| id | string | | Yes |
| indexing_technique | string | | No |
| name | string | | Yes |
| permission | string | | No |
| permission_keys | [ string ] | | No |
#### TrialDeletedTool
| Name | Type | Description | Required |
@@ -21414,6 +21525,20 @@ Enum class for tool provider
| tool_name | string | | No |
| type | string | | No |
#### TrialDeletedToolResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| provider_id | string | | Yes |
| tool_name | string | | Yes |
| type | string | | Yes |
#### TrialIconType
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| TrialIconType | string | | |
#### TrialModelsResponse
| Name | Type | Description | Required |
@@ -21476,6 +21601,36 @@ Enum class for tool provider
| updated_by | string | | No |
| use_icon_as_answer_icon | boolean | | No |
#### TrialSiteResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| access_token | string | | No |
| app_base_url | string | | No |
| chat_color_theme | string | | No |
| chat_color_theme_inverted | boolean | | No |
| code | string | | No |
| copyright | string | | No |
| created_at | integer | | No |
| created_by | string | | No |
| custom_disclaimer | string | | No |
| customize_domain | string | | No |
| customize_token_strategy | string | | No |
| default_language | string | | Yes |
| description | string | | No |
| icon | string | | No |
| icon_background | string | | No |
| icon_type | [TrialIconType](#trialicontype) | | No |
| icon_url | string | | No |
| input_placeholder | string | | No |
| privacy_policy | string | | No |
| prompt_public | boolean | | No |
| show_workflow_steps | boolean | | No |
| title | string | | Yes |
| updated_at | integer | | No |
| updated_by | string | | No |
| use_icon_as_answer_icon | boolean | | No |
#### TrialTag
| Name | Type | Description | Required |
@@ -21484,6 +21639,14 @@ Enum class for tool provider
| name | string | | No |
| type | string | | No |
#### TrialTagResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| id | string | | Yes |
| name | string | | Yes |
| type | string | | Yes |
#### TrialWorkflow
| Name | Type | Description | Required |
@@ -21504,6 +21667,14 @@ Enum class for tool provider
| updated_by | [TrialSimpleAccount](#trialsimpleaccount) | | No |
| version | string | | No |
#### TrialWorkflowAccount
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| email | string | | No |
| id | string | | Yes |
| name | string | | No |
#### TrialWorkflowPartial
| Name | Type | Description | Required |
@@ -21514,6 +21685,36 @@ Enum class for tool provider
| updated_at | long | | No |
| updated_by | string | | No |
#### TrialWorkflowPartialResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by | string | | No |
| id | string | | Yes |
| updated_at | integer | | No |
| updated_by | string | | No |
#### TrialWorkflowResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| conversation_variables | [ [JsonObject](#jsonobject) ] | | No |
| created_at | integer | | No |
| created_by | [TrialWorkflowAccount](#trialworkflowaccount) | | No |
| environment_variables | [ [JsonObject](#jsonobject) ] | | No |
| features | [JsonObject](#jsonobject) | | No |
| graph | [JsonObject](#jsonobject) | | Yes |
| hash | string | | No |
| id | string | | Yes |
| marked_comment | string | | No |
| marked_name | string | | No |
| rag_pipeline_variables | [ [JsonObject](#jsonobject) ] | | No |
| tool_published | boolean | | No |
| updated_at | integer | | No |
| updated_by | [TrialWorkflowAccount](#trialworkflowaccount) | | No |
| version | string | | No |
#### TriggerCreationMethod
| Name | Type | Description | Required |