refactor(api): migrate snippet workspace endpoints to BaseModel

This commit is contained in:
chariri 2026-06-26 03:15:11 +09:00
parent bb921bcc45
commit a045cd1fc0
No known key found for this signature in database
GPG Key ID: 23A554A36F7FF2FD
23 changed files with 990 additions and 853 deletions

View File

@ -145,6 +145,8 @@ class PublishWorkflowPayload(BaseModel):
"""Payload for publishing snippet workflow."""
knowledge_base_setting: dict[str, Any] | None = Field(default=None)
marked_name: str | None = Field(default=None, max_length=20)
marked_comment: str | None = Field(default=None, max_length=100)
class SnippetImportPayload(BaseModel):

View File

@ -1,16 +1,13 @@
import logging
import re
from typing import Any
from urllib.parse import quote
from flask import Response, request
from flask_restx import Resource, marshal
from pydantic import RootModel
from flask_restx import Resource
from sqlalchemy.orm import Session, sessionmaker
from werkzeug.datastructures import MultiDict
from werkzeug.exceptions import NotFound
from controllers.common.fields import TextFileResponse
from controllers.common.schema import query_params_from_model, register_response_schema_models, register_schema_models
from controllers.console import console_ns
from controllers.console.snippets.payloads import (
@ -32,12 +29,13 @@ from controllers.console.wraps import (
)
from extensions.ext_database import db
from fields.base import ResponseModel
from fields.snippet_fields import snippet_fields, snippet_list_fields, snippet_pagination_fields
from fields.snippet_fields import SnippetPaginationResponse, SnippetResponse
from libs.helper import dump_response
from libs.login import login_required
from models import Account
from models.snippet import SnippetType
from services.app_dsl_service import ImportStatus
from services.snippet_dsl_service import SnippetDslService
from services.snippet_dsl_service import CheckDependenciesResult, SnippetDslService, SnippetImportInfo
from services.snippet_service import SnippetService
logger = logging.getLogger(__name__)
@ -45,15 +43,7 @@ _TAG_IDS_BRACKET_PATTERN = re.compile(r"^tag_ids\[(\d+)\]$")
_CREATOR_IDS_BRACKET_PATTERN = re.compile(r"^creator_ids\[(\d+)\]$")
class SnippetImportResponse(RootModel[dict[str, Any]]):
root: dict[str, Any]
class SnippetDependencyCheckResponse(RootModel[dict[str, Any]]):
root: dict[str, Any]
class SnippetUseCountResponse(ResponseModel):
class SnippetUseCountIncrementResponse(ResponseModel):
result: str
use_count: int
@ -100,30 +90,22 @@ register_schema_models(
IncludeSecretQuery,
)
register_response_schema_models(
console_ns,
TextFileResponse,
SnippetImportResponse,
SnippetDependencyCheckResponse,
SnippetUseCountResponse,
console_ns, SnippetResponse, SnippetPaginationResponse, SnippetUseCountIncrementResponse, SnippetImportInfo
)
# Create namespace models for marshaling
snippet_model = console_ns.model("Snippet", snippet_fields)
snippet_list_model = console_ns.model("SnippetList", snippet_list_fields)
snippet_pagination_model = console_ns.model("SnippetPagination", snippet_pagination_fields)
@console_ns.route("/workspaces/current/customized-snippets")
class CustomizedSnippetsApi(Resource):
@console_ns.doc("list_customized_snippets")
@console_ns.doc(params=query_params_from_model(SnippetListQuery))
@console_ns.response(200, "Snippets retrieved successfully", snippet_pagination_model)
@console_ns.response(200, "Snippets retrieved successfully", console_ns.models[SnippetPaginationResponse.__name__])
@setup_required
@login_required
@account_initialization_required
@with_current_tenant_id
def get(self, current_tenant_id: str):
"""List customized snippets with pagination and search."""
query = SnippetListQuery.model_validate(_normalize_snippet_list_query_args(request.args))
snippet_service = _snippet_service()
@ -138,17 +120,20 @@ class CustomizedSnippetsApi(Resource):
tag_ids=query.tag_ids,
)
return {
"data": marshal(snippets, snippet_list_fields),
"page": query.page,
"limit": query.limit,
"total": total,
"has_more": has_more,
}, 200
return dump_response(
SnippetPaginationResponse,
{
"data": snippets,
"page": query.page,
"limit": query.limit,
"total": total,
"has_more": has_more,
},
), 200
@console_ns.doc("create_customized_snippet")
@console_ns.expect(console_ns.models.get(CreateSnippetPayload.__name__))
@console_ns.response(201, "Snippet created successfully", snippet_model)
@console_ns.response(201, "Snippet created successfully", console_ns.models[SnippetResponse.__name__])
@console_ns.response(400, "Invalid request")
@setup_required
@login_required
@ -161,6 +146,7 @@ class CustomizedSnippetsApi(Resource):
@with_current_tenant_id
def post(self, current_tenant_id: str, current_user: Account):
"""Create a new customized snippet."""
payload = CreateSnippetPayload.model_validate(console_ns.payload or {})
try:
@ -185,13 +171,13 @@ class CustomizedSnippetsApi(Resource):
except ValueError as e:
return {"message": str(e)}, 400
return marshal(snippet, snippet_fields), 201
return dump_response(SnippetResponse, snippet), 201
@console_ns.route("/workspaces/current/customized-snippets/<uuid:snippet_id>")
class CustomizedSnippetDetailApi(Resource):
@console_ns.doc("get_customized_snippet")
@console_ns.response(200, "Snippet retrieved successfully", snippet_model)
@console_ns.response(200, "Snippet retrieved successfully", console_ns.models[SnippetResponse.__name__])
@console_ns.response(404, "Snippet not found")
@setup_required
@login_required
@ -199,20 +185,21 @@ class CustomizedSnippetDetailApi(Resource):
@with_current_tenant_id
def get(self, current_tenant_id: str, snippet_id: str):
"""Get customized snippet details."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
if not snippet:
raise NotFound("Snippet not found")
return marshal(snippet, snippet_fields), 200
return dump_response(SnippetResponse, snippet), 200
@console_ns.doc("update_customized_snippet")
@console_ns.expect(console_ns.models.get(UpdateSnippetPayload.__name__))
@console_ns.response(200, "Snippet updated successfully", snippet_model)
@console_ns.response(200, "Snippet updated successfully", console_ns.models[SnippetResponse.__name__])
@console_ns.response(400, "Invalid request")
@console_ns.response(404, "Snippet not found")
@setup_required
@ -226,9 +213,10 @@ class CustomizedSnippetDetailApi(Resource):
@with_current_tenant_id
def patch(self, current_tenant_id: str, current_user: Account, snippet_id: str):
"""Update customized snippet."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
@ -257,7 +245,7 @@ class CustomizedSnippetDetailApi(Resource):
except ValueError as e:
return {"message": str(e)}, 400
return marshal(snippet, snippet_fields), 200
return dump_response(SnippetResponse, snippet), 200
@console_ns.doc("delete_customized_snippet")
@console_ns.response(204, "Snippet deleted successfully")
@ -270,9 +258,10 @@ class CustomizedSnippetDetailApi(Resource):
@with_current_tenant_id
def delete(self, current_tenant_id: str, snippet_id: str):
"""Delete customized snippet."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
@ -296,7 +285,7 @@ class CustomizedSnippetExportApi(Resource):
@console_ns.doc(description="Export snippet configuration as DSL")
@console_ns.doc(params={"snippet_id": "Snippet ID to export"})
@console_ns.doc(params=query_params_from_model(IncludeSecretQuery))
@console_ns.response(200, "Snippet exported successfully", console_ns.models[TextFileResponse.__name__])
@console_ns.response(200, "Snippet exported successfully")
@console_ns.response(404, "Snippet not found")
@setup_required
@login_required
@ -308,9 +297,10 @@ class CustomizedSnippetExportApi(Resource):
@with_current_tenant_id
def get(self, current_tenant_id: str, snippet_id: str):
"""Export snippet as DSL."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
@ -343,8 +333,8 @@ class CustomizedSnippetImportApi(Resource):
@console_ns.doc("import_customized_snippet")
@console_ns.doc(description="Import snippet from DSL")
@console_ns.expect(console_ns.models.get(SnippetImportPayload.__name__))
@console_ns.response(200, "Snippet imported successfully", console_ns.models[SnippetImportResponse.__name__])
@console_ns.response(202, "Import pending confirmation", console_ns.models[SnippetImportResponse.__name__])
@console_ns.response(200, "Snippet imported successfully", console_ns.models[SnippetImportInfo.__name__])
@console_ns.response(202, "Import pending confirmation", console_ns.models[SnippetImportInfo.__name__])
@console_ns.response(400, "Import failed")
@setup_required
@login_required
@ -385,7 +375,7 @@ class CustomizedSnippetImportConfirmApi(Resource):
@console_ns.doc("confirm_snippet_import")
@console_ns.doc(description="Confirm a pending snippet import")
@console_ns.doc(params={"import_id": "Import ID to confirm"})
@console_ns.response(200, "Import confirmed successfully", console_ns.models[SnippetImportResponse.__name__])
@console_ns.response(200, "Import confirmed successfully", console_ns.models[SnippetImportInfo.__name__])
@console_ns.response(400, "Import failed")
@setup_required
@login_required
@ -412,11 +402,7 @@ class CustomizedSnippetCheckDependenciesApi(Resource):
@console_ns.doc("check_snippet_dependencies")
@console_ns.doc(description="Check dependencies for a snippet")
@console_ns.doc(params={"snippet_id": "Snippet ID"})
@console_ns.response(
200,
"Dependencies checked successfully",
console_ns.models[SnippetDependencyCheckResponse.__name__],
)
@console_ns.response(200, "Dependencies checked successfully", console_ns.models[CheckDependenciesResult.__name__])
@console_ns.response(404, "Snippet not found")
@setup_required
@login_required
@ -430,7 +416,7 @@ class CustomizedSnippetCheckDependenciesApi(Resource):
"""Check dependencies for a snippet."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
@ -449,7 +435,11 @@ class CustomizedSnippetUseCountIncrementApi(Resource):
@console_ns.doc("increment_snippet_use_count")
@console_ns.doc(description="Increment snippet use count by 1")
@console_ns.doc(params={"snippet_id": "Snippet ID"})
@console_ns.response(200, "Use count incremented successfully", console_ns.models[SnippetUseCountResponse.__name__])
@console_ns.response(
200,
"Use count incremented successfully",
console_ns.models[SnippetUseCountIncrementResponse.__name__],
)
@console_ns.response(404, "Snippet not found")
@setup_required
@login_required
@ -461,9 +451,10 @@ class CustomizedSnippetUseCountIncrementApi(Resource):
@with_current_tenant_id
def post(self, current_tenant_id: str, snippet_id: str):
"""Increment snippet use count when it is inserted into a workflow."""
snippet_service = _snippet_service()
snippet = snippet_service.get_snippet_by_id(
snippet_id=str(snippet_id),
snippet_id=snippet_id,
tenant_id=current_tenant_id,
)
@ -476,4 +467,6 @@ class CustomizedSnippetUseCountIncrementApi(Resource):
session.commit()
session.refresh(snippet)
return {"result": "success", "use_count": snippet.use_count}, 200
return SnippetUseCountIncrementResponse(result="success", use_count=snippet.use_count).model_dump(
mode="json"
), 200

View File

@ -15,13 +15,13 @@ simple_account_fields = {
}
class SimpleAccount(ResponseModel):
class SimpleAccountResponse(ResponseModel):
id: str
name: str
email: str
class _AccountAvatar(ResponseModel):
class _AccountAvatarResponseMixin(ResponseModel):
avatar: str | None = None
@computed_field(return_type=str | None) # type: ignore[prop-decorator]
@ -30,7 +30,7 @@ class _AccountAvatar(ResponseModel):
return build_avatar_url(self.avatar)
class Account(_AccountAvatar):
class AccountResponse(_AccountAvatarResponseMixin):
id: str
name: str
email: str
@ -48,7 +48,7 @@ class Account(_AccountAvatar):
return to_timestamp(value)
class AccountWithRole(_AccountAvatar):
class AccountWithRoleResponse(_AccountAvatarResponseMixin):
id: str
name: str
email: str
@ -65,5 +65,11 @@ class AccountWithRole(_AccountAvatar):
return to_timestamp(value)
class AccountWithRoleList(ResponseModel):
accounts: list[AccountWithRole]
class AccountWithRoleListResponse(ResponseModel):
accounts: list[AccountWithRoleResponse]
SimpleAccount = SimpleAccountResponse
Account = AccountResponse
AccountWithRole = AccountWithRoleResponse
AccountWithRoleList = AccountWithRoleListResponse

View File

@ -1,61 +1,67 @@
from typing import override
from datetime import datetime
from typing import Any
from flask_restx import fields
from pydantic import Field, field_validator
from fields.member_fields import simple_account_fields
from libs.helper import TimestampField
from fields.base import ResponseModel
from fields.member_fields import SimpleAccountResponse
from libs.helper import to_timestamp
class OpaqueRawField(fields.Raw):
@override
def schema(self) -> dict[str, object]:
return {"type": "object"}
class SnippetTagResponse(ResponseModel):
id: str
name: str
type: str
tag_fields = {"id": fields.String, "name": fields.String, "type": fields.String}
class SnippetListItemResponse(ResponseModel):
id: str
name: str
description: str | None = None
type: str
version: int
use_count: int
is_published: bool
icon_info: dict[str, Any] | None = None
tags: list[SnippetTagResponse] = Field(default_factory=list)
created_by: str | None = None
author_name: str | None = None
created_at: int | None = None
updated_by: str | None = None
updated_at: int | None = None
# Snippet list item fields (lightweight for list display)
snippet_list_fields = {
"id": fields.String,
"name": fields.String,
"description": fields.String,
"type": fields.String,
"version": fields.Integer,
"use_count": fields.Integer,
"is_published": fields.Boolean,
"icon_info": OpaqueRawField,
"tags": fields.List(fields.Nested(tag_fields)),
"created_by": fields.String,
"author_name": fields.String,
"created_at": TimestampField,
"updated_by": fields.String,
"updated_at": TimestampField,
}
@field_validator("created_at", "updated_at", mode="before")
@classmethod
def _normalize_timestamp(cls, value: datetime | int | None) -> int | None:
return to_timestamp(value)
# Full snippet fields (includes creator info and graph data)
snippet_fields = {
"id": fields.String,
"name": fields.String,
"description": fields.String,
"type": fields.String,
"version": fields.Integer,
"use_count": fields.Integer,
"is_published": fields.Boolean,
"icon_info": OpaqueRawField,
"graph": OpaqueRawField(attribute="graph_dict"),
"input_fields": OpaqueRawField(attribute="input_fields_list"),
"tags": fields.List(fields.Nested(tag_fields)),
"created_by": fields.Nested(simple_account_fields, attribute="created_by_account", allow_null=True),
"created_at": TimestampField,
"updated_by": fields.Nested(simple_account_fields, attribute="updated_by_account", allow_null=True),
"updated_at": TimestampField,
}
# Pagination response fields
snippet_pagination_fields = {
"data": fields.List(fields.Nested(snippet_list_fields)),
"page": fields.Integer,
"limit": fields.Integer,
"total": fields.Integer,
"has_more": fields.Boolean,
}
class SnippetResponse(ResponseModel):
id: str
name: str
description: str | None = None
type: str
version: int
use_count: int
is_published: bool
icon_info: dict[str, Any] | None = None
graph: dict[str, Any] | None = Field(default=None, validation_alias="graph_dict")
input_fields: list[dict[str, Any]] | None = Field(default=None, validation_alias="input_fields_list")
tags: list[SnippetTagResponse] = Field(default_factory=list)
created_by: SimpleAccountResponse | None = Field(default=None, validation_alias="created_by_account")
created_at: int | None = None
updated_by: SimpleAccountResponse | None = Field(default=None, validation_alias="updated_by_account")
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 SnippetPaginationResponse(ResponseModel):
data: list[SnippetListItemResponse]
page: int
limit: int
total: int
has_more: bool

View File

@ -38,7 +38,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/change-email
#### Request Body
@ -77,7 +77,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/change-email/validity
#### Request Body
@ -198,7 +198,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/interface-theme
#### Request Body
@ -211,7 +211,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/name
#### Request Body
@ -224,7 +224,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/password
#### Request Body
@ -237,14 +237,14 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [GET] /account/profile
#### Responses
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /account/timezone
#### Request Body
@ -257,7 +257,7 @@ Get account avatar url
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [Account](#account)<br> |
| 200 | Success | **application/json**: [AccountResponse](#accountresponse)<br> |
### [POST] /activate
Activate account with invitation token
@ -9104,7 +9104,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Snippets retrieved successfully | **application/json**: [SnippetPagination](#snippetpagination)<br> |
| 200 | Snippets retrieved successfully | **application/json**: [SnippetPaginationResponse](#snippetpaginationresponse)<br> |
### [POST] /workspaces/current/customized-snippets
**Create a new customized snippet**
@ -9119,7 +9119,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 201 | Snippet created successfully | **application/json**: [Snippet](#snippet)<br> |
| 201 | Snippet created successfully | **application/json**: [SnippetResponse](#snippetresponse)<br> |
| 400 | Invalid request | |
### [POST] /workspaces/current/customized-snippets/imports
@ -9135,8 +9135,8 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Snippet imported successfully | **application/json**: [SnippetImportResponse](#snippetimportresponse)<br> |
| 202 | Import pending confirmation | **application/json**: [SnippetImportResponse](#snippetimportresponse)<br> |
| 200 | Snippet imported successfully | **application/json**: [SnippetImportInfo](#snippetimportinfo)<br> |
| 202 | Import pending confirmation | **application/json**: [SnippetImportInfo](#snippetimportinfo)<br> |
| 400 | Import failed | |
### [POST] /workspaces/current/customized-snippets/imports/{import_id}/confirm
@ -9152,7 +9152,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Import confirmed successfully | **application/json**: [SnippetImportResponse](#snippetimportresponse)<br> |
| 200 | Import confirmed successfully | **application/json**: [SnippetImportInfo](#snippetimportinfo)<br> |
| 400 | Import failed | |
### [DELETE] /workspaces/current/customized-snippets/{snippet_id}
@ -9184,7 +9184,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Snippet retrieved successfully | **application/json**: [Snippet](#snippet)<br> |
| 200 | Snippet retrieved successfully | **application/json**: [SnippetResponse](#snippetresponse)<br> |
| 404 | Snippet not found | |
### [PATCH] /workspaces/current/customized-snippets/{snippet_id}
@ -9206,7 +9206,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Snippet updated successfully | **application/json**: [Snippet](#snippet)<br> |
| 200 | Snippet updated successfully | **application/json**: [SnippetResponse](#snippetresponse)<br> |
| 400 | Invalid request | |
| 404 | Snippet not found | |
@ -9223,7 +9223,7 @@ Get list of available agent providers
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Dependencies checked successfully | **application/json**: [SnippetDependencyCheckResponse](#snippetdependencycheckresponse)<br> |
| 200 | Dependencies checked successfully | **application/json**: [CheckDependenciesResult](#checkdependenciesresult)<br> |
| 404 | Snippet not found | |
### [GET] /workspaces/current/customized-snippets/{snippet_id}/export
@ -9240,10 +9240,10 @@ Export snippet configuration as DSL
#### Responses
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Snippet exported successfully | **application/json**: [TextFileResponse](#textfileresponse)<br> |
| 404 | Snippet not found | |
| Code | Description |
| ---- | ----------- |
| 200 | Snippet exported successfully |
| 404 | Snippet not found |
### [POST] /workspaces/current/customized-snippets/{snippet_id}/use-count/increment
**Increment snippet use count when it is inserted into a workflow**
@ -9260,7 +9260,7 @@ Increment snippet use count by 1
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Use count incremented successfully | **application/json**: [SnippetUseCountResponse](#snippetusecountresponse)<br> |
| 200 | Use count incremented successfully | **application/json**: [SnippetUseCountIncrementResponse](#snippetusecountincrementresponse)<br> |
| 404 | Snippet not found | |
### [GET] /workspaces/current/dataset-operators
@ -9268,7 +9268,7 @@ Increment snippet use count by 1
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [AccountWithRoleList](#accountwithrolelist)<br> |
| 200 | Success | **application/json**: [AccountWithRoleListResponse](#accountwithrolelistresponse)<br> |
### [GET] /workspaces/current/default-model
#### Parameters
@ -9477,7 +9477,7 @@ Update a plugin endpoint
| Code | Description | Schema |
| ---- | ----------- | ------ |
| 200 | Success | **application/json**: [AccountWithRoleList](#accountwithrolelist)<br> |
| 200 | Success | **application/json**: [AccountWithRoleListResponse](#accountwithrolelistresponse)<br> |
### [POST] /workspaces/current/members/invite-email
#### Request Body
@ -11928,23 +11928,6 @@ Default namespace
| role_name | string | | No |
| tenant_id | string | | No |
#### Account
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| avatar | string | | No |
| avatar_url | string | | Yes |
| created_at | integer | | No |
| email | string | | Yes |
| id | string | | Yes |
| interface_language | string | | No |
| interface_theme | string | | No |
| is_password_set | boolean | | Yes |
| last_login_at | integer | | No |
| last_login_ip | string | | No |
| name | string | | Yes |
| timezone | string | | No |
#### AccountAvatarPayload
| Name | Type | Description | Required |
@ -12020,13 +12003,36 @@ Default namespace
| password | string | | No |
| repeat_new_password | string | | Yes |
#### AccountResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| avatar | string | | No |
| avatar_url | string | | Yes |
| created_at | integer | | No |
| email | string | | Yes |
| id | string | | Yes |
| interface_language | string | | No |
| interface_theme | string | | No |
| is_password_set | boolean | | Yes |
| last_login_at | integer | | No |
| last_login_ip | string | | No |
| name | string | | Yes |
| timezone | string | | No |
#### AccountTimezonePayload
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| timezone | string | | Yes |
#### AccountWithRole
#### AccountWithRoleListResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| accounts | [ [AccountWithRoleResponse](#accountwithroleresponse) ] | | Yes |
#### AccountWithRoleResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
@ -12041,12 +12047,6 @@ Default namespace
| roles | [ object ] | | No |
| status | string | | Yes |
#### AccountWithRoleList
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| accounts | [ [AccountWithRole](#accountwithrole) ] | | Yes |
#### ActivateCheckQuery
| Name | Type | Description | Required |
@ -12095,7 +12095,7 @@ Default namespace
| ---- | ---- | ----------- | -------- |
| conversation_id | string | | No |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| elapsed_time | number | | No |
| exceptions_count | integer | | No |
| finished_at | integer | | No |
@ -18564,6 +18564,8 @@ Payload for publishing snippet workflow.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| knowledge_base_setting | object | | No |
| marked_comment | string | | No |
| marked_name | string | | No |
#### PublishedWorkflowRunPayload
@ -19151,6 +19153,14 @@ Model class for provider quota configuration.
| id | string | | Yes |
| name | string | | Yes |
#### SimpleAccountResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| email | string | | Yes |
| id | string | | Yes |
| name | string | | Yes |
#### SimpleConversation
| Name | Type | Description | Required |
@ -19288,32 +19298,6 @@ Validated metadata extracted from a Skill package.
| inferable | boolean | | Yes |
| reason | string | | No |
#### Snippet
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | long | | No |
| created_by | [_AnonymousInlineModel_b0fd3f86d9d5](#_anonymousinlinemodel_b0fd3f86d9d5) | | No |
| description | string | | No |
| graph | object | | No |
| icon_info | object | | No |
| id | string | | No |
| input_fields | object | | No |
| is_published | boolean | | No |
| name | string | | No |
| tags | [ [_AnonymousInlineModel_7b8b49ca164e](#_anonymousinlinemodel_7b8b49ca164e) ] | | No |
| type | string | | No |
| updated_at | long | | No |
| updated_by | [_AnonymousInlineModel_b0fd3f86d9d5](#_anonymousinlinemodel_b0fd3f86d9d5) | | No |
| use_count | integer | | No |
| version | integer | | No |
#### SnippetDependencyCheckResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| SnippetDependencyCheckResponse | object | | |
#### SnippetDraftConfigResponse
| Name | Type | Description | Required |
@ -19350,6 +19334,17 @@ Payload for syncing snippet draft workflow.
| hash | string | | No |
| input_fields | [ object ] | | No |
#### SnippetImportInfo
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| current_dsl_version | string, <br>**Default:** 0.1.0 | | No |
| error | string | | No |
| id | string | | Yes |
| imported_dsl_version | string | | No |
| snippet_id | string | | No |
| status | [ImportStatus](#importstatus) | | Yes |
#### SnippetImportPayload
Payload for importing snippet from DSL.
@ -19363,12 +19358,6 @@ Payload for importing snippet from DSL.
| yaml_content | string | YAML content (required for yaml-content mode) | No |
| yaml_url | string | YAML URL (required for yaml-url mode) | No |
#### SnippetImportResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| SnippetImportResponse | object | | |
#### SnippetIterationNodeRunPayload
Payload for running an iteration node in snippet draft workflow.
@ -19377,24 +19366,24 @@ Payload for running an iteration node in snippet draft workflow.
| ---- | ---- | ----------- | -------- |
| inputs | object | | No |
#### SnippetList
#### SnippetListItemResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| author_name | string | | No |
| created_at | long | | No |
| created_at | integer | | No |
| created_by | string | | No |
| description | string | | No |
| icon_info | object | | No |
| id | string | | No |
| is_published | boolean | | No |
| name | string | | No |
| tags | [ [_AnonymousInlineModel_7b8b49ca164e](#_anonymousinlinemodel_7b8b49ca164e) ] | | No |
| type | string | | No |
| updated_at | long | | No |
| id | string | | Yes |
| is_published | boolean | | Yes |
| name | string | | Yes |
| tags | [ [SnippetTagResponse](#snippettagresponse) ] | | No |
| type | string | | Yes |
| updated_at | integer | | No |
| updated_by | string | | No |
| use_count | integer | | No |
| version | integer | | No |
| use_count | integer | | Yes |
| version | integer | | Yes |
#### SnippetListQuery
@ -19417,17 +19406,45 @@ Payload for running a loop node in snippet draft workflow.
| ---- | ---- | ----------- | -------- |
| inputs | object | | No |
#### SnippetPagination
#### SnippetPaginationResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| data | [ [_AnonymousInlineModel_744ff9cc03e6](#_anonymousinlinemodel_744ff9cc03e6) ] | | No |
| has_more | boolean | | No |
| limit | integer | | No |
| page | integer | | No |
| total | integer | | No |
| data | [ [SnippetListItemResponse](#snippetlistitemresponse) ] | | Yes |
| has_more | boolean | | Yes |
| limit | integer | | Yes |
| page | integer | | Yes |
| total | integer | | Yes |
#### SnippetUseCountResponse
#### SnippetResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| description | string | | No |
| graph | object | | No |
| icon_info | object | | No |
| id | string | | Yes |
| input_fields | [ object ] | | No |
| is_published | boolean | | Yes |
| name | string | | Yes |
| tags | [ [SnippetTagResponse](#snippettagresponse) ] | | No |
| type | string | | Yes |
| updated_at | integer | | No |
| updated_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| use_count | integer | | Yes |
| version | integer | | Yes |
#### SnippetTagResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| id | string | | Yes |
| name | string | | Yes |
| type | string | | Yes |
#### SnippetUseCountIncrementResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
@ -19458,7 +19475,7 @@ Query parameters for listing snippet published workflows.
| ---- | ---- | ----------- | -------- |
| conversation_variables | [ [WorkflowConversationVariableResponse](#workflowconversationvariableresponse) ] | | Yes |
| created_at | integer | | Yes |
| created_by | [SimpleAccount](#simpleaccount) | | No |
| created_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| environment_variables | [ [WorkflowEnvironmentVariableResponse](#workflowenvironmentvariableresponse) ] | | Yes |
| features | object | | Yes |
| graph | object | | Yes |
@ -19470,7 +19487,7 @@ Query parameters for listing snippet published workflows.
| rag_pipeline_variables | [ [PipelineVariableResponse](#pipelinevariableresponse) ] | | Yes |
| tool_published | boolean | | Yes |
| updated_at | integer | | Yes |
| updated_by | [SimpleAccount](#simpleaccount) | | No |
| updated_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| version | string | | Yes |
#### StarredAppListQuery
@ -20390,7 +20407,7 @@ How a workflow node is bound to an Agent.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| created_by_end_user | [SimpleEndUser](#simpleenduser) | | No |
| created_by_role | string | | No |
| created_from | string | | No |
@ -20427,7 +20444,7 @@ How a workflow node is bound to an Agent.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| created_by_end_user | [SimpleEndUser](#simpleenduser) | | No |
| id | string | | Yes |
| trigger_metadata | | | No |
@ -20528,7 +20545,7 @@ How a workflow node is bound to an Agent.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| users | [ [AccountWithRole](#accountwithrole) ] | | Yes |
| users | [ [AccountWithRoleResponse](#accountwithroleresponse) ] | | Yes |
#### WorkflowCommentReply
@ -20877,7 +20894,7 @@ can reuse its existing handler.
| ---- | ---- | ----------- | -------- |
| conversation_variables | [ [WorkflowConversationVariableResponse](#workflowconversationvariableresponse) ] | | Yes |
| created_at | integer | | Yes |
| created_by | [SimpleAccount](#simpleaccount) | | No |
| created_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| environment_variables | [ [WorkflowEnvironmentVariableResponse](#workflowenvironmentvariableresponse) ] | | Yes |
| features | object | | Yes |
| graph | object | | Yes |
@ -20888,7 +20905,7 @@ can reuse its existing handler.
| rag_pipeline_variables | [ [PipelineVariableResponse](#pipelinevariableresponse) ] | | Yes |
| tool_published | boolean | | Yes |
| updated_at | integer | | Yes |
| updated_by | [SimpleAccount](#simpleaccount) | | No |
| updated_by | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| version | string | | Yes |
#### WorkflowRestoreResponse
@ -20923,7 +20940,7 @@ can reuse its existing handler.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| created_by_end_user | [SimpleEndUser](#simpleenduser) | | No |
| created_by_role | string | | No |
| elapsed_time | number | | No |
@ -20962,7 +20979,7 @@ can reuse its existing handler.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| elapsed_time | number | | No |
| exceptions_count | integer | | No |
| finished_at | integer | | No |
@ -21009,7 +21026,7 @@ can reuse its existing handler.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| created_by_end_user | [SimpleEndUser](#simpleenduser) | | No |
| created_by_role | string | | No |
| elapsed_time | number | | No |
@ -21246,41 +21263,6 @@ Workflow tool configuration
| data | [ [AccessPolicy](#accesspolicy) ] | | No |
| pagination | [Pagination](#pagination) | | No |
#### _AnonymousInlineModel_744ff9cc03e6
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| author_name | string | | No |
| created_at | long | | No |
| created_by | string | | No |
| description | string | | No |
| icon_info | object | | No |
| id | string | | No |
| is_published | boolean | | No |
| name | string | | No |
| tags | [ [_AnonymousInlineModel_7b8b49ca164e](#_anonymousinlinemodel_7b8b49ca164e) ] | | No |
| type | string | | No |
| updated_at | long | | No |
| updated_by | string | | No |
| use_count | integer | | No |
| version | integer | | No |
#### _AnonymousInlineModel_7b8b49ca164e
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| id | string | | No |
| name | string | | No |
| type | string | | No |
#### _AnonymousInlineModel_b0fd3f86d9d5
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| email | string | | No |
| id | string | | No |
| name | string | | No |
#### _AnonymousInlineModel_b1954337d565
| Name | Type | Description | Required |

View File

@ -3937,7 +3937,7 @@ Model class for provider with models response.
| output_variable_name | string | | Yes |
| type | string | | No |
#### SimpleAccount
#### SimpleAccountResponse
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
@ -4147,7 +4147,7 @@ in form definiton, or a variable while the workflow is running.
| Name | Type | Description | Required |
| ---- | ---- | ----------- | -------- |
| created_at | integer | | No |
| created_by_account | [SimpleAccount](#simpleaccount) | | No |
| created_by_account | [SimpleAccountResponse](#simpleaccountresponse) | | No |
| created_by_end_user | [SimpleEndUser](#simpleenduser) | | No |
| created_by_role | string | | No |
| created_from | string | | No |

View File

@ -1,6 +1,6 @@
import json
import logging
from collections.abc import Iterator, Mapping, Sequence
from collections.abc import Generator, Mapping, Sequence
from contextlib import contextmanager
from datetime import UTC, datetime
from typing import Any
@ -70,7 +70,7 @@ class SnippetService:
self._workflow_run_repo = DifyAPIRepositoryFactory.create_api_workflow_run_repository(session_maker)
@contextmanager
def _session_scope(self) -> Iterator[Session]:
def _session_scope(self) -> Generator[Session]:
current_session = getattr(self, "_session", None)
if current_session is not None:
yield current_session
@ -627,8 +627,6 @@ class SnippetService:
conversation_variables=[],
rag_pipeline_variables=draft_workflow.rag_pipeline_variables,
kind=WorkflowKind.SNIPPET.value,
marked_name="",
marked_comment="",
)
session.add(workflow)

View File

@ -1,3 +1,4 @@
from datetime import datetime
from inspect import unwrap
from types import SimpleNamespace
from unittest.mock import ANY, Mock
@ -46,12 +47,73 @@ def _snippet(**overrides) -> CustomizedSnippet:
"name": "Snippet",
"description": "Description",
"type": snippets_module.SnippetType.NODE,
"version": 3,
"use_count": 7,
"is_published": True,
"icon_info": {"icon": "star", "icon_background": "#101828", "icon_type": "emoji"},
"input_fields": '[{"label": "Question", "variable": "query", "type": "text-input"}]',
"created_by": "account-1",
"created_at": datetime(2024, 1, 2, 3, 4, 5),
"updated_by": None,
"updated_at": datetime(2024, 1, 3, 4, 5, 6),
}
data.update(overrides)
return CustomizedSnippet(**data)
def _patch_snippet_response_properties(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
CustomizedSnippet,
"tags",
property(lambda _snippet: [{"id": "tag-1", "name": "Search", "type": "snippet"}]),
)
monkeypatch.setattr(CustomizedSnippet, "created_by_account", property(lambda _snippet: _account("account-1")))
monkeypatch.setattr(CustomizedSnippet, "updated_by_account", property(lambda _snippet: None))
def _expected_snippet_list_item(snippet: CustomizedSnippet) -> dict:
return {
"id": snippet.id,
"name": snippet.name,
"description": snippet.description,
"type": snippet.type,
"version": snippet.version,
"use_count": snippet.use_count,
"is_published": snippet.is_published,
"icon_info": snippet.icon_info,
"tags": [{"id": "tag-1", "name": "Search", "type": "snippet"}],
"created_by": snippet.created_by,
"author_name": "Test User",
"created_at": int(snippet.created_at.timestamp()),
"updated_by": snippet.updated_by,
"updated_at": int(snippet.updated_at.timestamp()),
}
def _expected_snippet_response(snippet: CustomizedSnippet) -> dict:
return {
"id": snippet.id,
"name": snippet.name,
"description": snippet.description,
"type": snippet.type,
"version": snippet.version,
"use_count": snippet.use_count,
"is_published": snippet.is_published,
"icon_info": snippet.icon_info,
"graph": {},
"input_fields": [{"label": "Question", "variable": "query", "type": "text-input"}],
"tags": [{"id": "tag-1", "name": "Search", "type": "snippet"}],
"created_by": {
"id": "account-1",
"name": "Test User",
"email": "account-1@example.com",
},
"created_at": int(snippet.created_at.timestamp()),
"updated_by": None,
"updated_at": int(snippet.updated_at.timestamp()),
}
def test_normalize_snippet_list_query_args_sorts_indexed_values():
query_args = snippets_module.MultiDict(
[
@ -75,7 +137,7 @@ def test_list_snippets_returns_pagination(app: Flask, monkeypatch: pytest.Monkey
tag_id = "11111111-1111-1111-1111-111111111111"
get_snippets = Mock(return_value=(snippets, 1, False))
monkeypatch.setattr(snippets_module.SnippetService, "get_snippets", get_snippets)
monkeypatch.setattr(snippets_module, "marshal", Mock(return_value=[{"id": "snippet-1"}]))
_patch_snippet_response_properties(monkeypatch)
api = snippets_module.CustomizedSnippetsApi()
handler = unwrap(api.get)
@ -87,7 +149,7 @@ def test_list_snippets_returns_pagination(app: Flask, monkeypatch: pytest.Monkey
assert status_code == 200
assert response == {
"data": [{"id": "snippet-1"}],
"data": [_expected_snippet_list_item(snippets[0])],
"page": 2,
"limit": 10,
"total": 1,
@ -110,6 +172,7 @@ def test_create_snippet_defaults_unknown_type_and_returns_created(app: Flask, mo
snippet = _snippet()
create_snippet = Mock(return_value=snippet)
monkeypatch.setattr(snippets_module.SnippetService, "create_snippet", create_snippet)
_patch_snippet_response_properties(monkeypatch)
monkeypatch.setattr(
snippets_module.CreateSnippetPayload,
"model_validate",
@ -124,7 +187,6 @@ def test_create_snippet_defaults_unknown_type_and_returns_created(app: Flask, mo
)
),
)
monkeypatch.setattr(snippets_module, "marshal", Mock(return_value={"id": "snippet-1"}))
api = snippets_module.CustomizedSnippetsApi()
handler = unwrap(api.post)
@ -137,7 +199,7 @@ def test_create_snippet_defaults_unknown_type_and_returns_created(app: Flask, mo
response, status_code = handler(api, "tenant-1", user)
assert status_code == 201
assert response == {"id": "snippet-1"}
assert response == _expected_snippet_response(snippet)
assert create_snippet.call_args.kwargs["snippet_type"] == snippets_module.SnippetType.NODE
@ -184,7 +246,7 @@ def test_get_snippet_detail_raises_when_missing(app: Flask, monkeypatch: pytest.
def test_get_snippet_detail_returns_snippet(app: Flask, monkeypatch: pytest.MonkeyPatch):
snippet = _snippet()
monkeypatch.setattr(snippets_module.SnippetService, "get_snippet_by_id", Mock(return_value=snippet))
monkeypatch.setattr(snippets_module, "marshal", Mock(return_value={"id": "snippet-1"}))
_patch_snippet_response_properties(monkeypatch)
api = snippets_module.CustomizedSnippetDetailApi()
handler = unwrap(api.get)
@ -193,7 +255,7 @@ def test_get_snippet_detail_returns_snippet(app: Flask, monkeypatch: pytest.Monk
response, status_code = handler(api, "tenant-1", snippet_id="snippet-1")
assert status_code == 200
assert response == {"id": "snippet-1"}
assert response == _expected_snippet_response(snippet)
def test_patch_snippet_returns_400_for_empty_payload(app: Flask, monkeypatch: pytest.MonkeyPatch):
@ -230,7 +292,7 @@ def test_patch_snippet_updates_and_commits(app: Flask, monkeypatch: pytest.Monke
monkeypatch.setattr(snippets_module.SnippetService, "update_snippet", update_snippet)
monkeypatch.setattr(snippets_module, "Session", SessionContext)
monkeypatch.setattr(snippets_module, "db", SimpleNamespace(engine=object()))
monkeypatch.setattr(snippets_module, "marshal", Mock(return_value={"id": "snippet-1", "name": "New"}))
_patch_snippet_response_properties(monkeypatch)
api = snippets_module.CustomizedSnippetDetailApi()
handler = unwrap(api.patch)
@ -243,7 +305,7 @@ def test_patch_snippet_updates_and_commits(app: Flask, monkeypatch: pytest.Monke
response, status_code = handler(api, "tenant-1", user, snippet_id="snippet-1")
assert status_code == 200
assert response == {"id": "snippet-1", "name": "New"}
assert response == _expected_snippet_response(updated_snippet)
update_snippet.assert_called_once()
assert update_snippet.call_args.kwargs["data"] == {
"name": "New",

View File

@ -1,8 +1,7 @@
from types import SimpleNamespace
from flask_restx import marshal
from fields.snippet_fields import snippet_list_fields
from fields.snippet_fields import SnippetListItemResponse
from libs.helper import dump_response
def test_snippet_list_fields_include_author_name() -> None:
@ -23,6 +22,6 @@ def test_snippet_list_fields_include_author_name() -> None:
updated_at=None,
)
result = marshal(snippet, snippet_list_fields)
result = dump_response(SnippetListItemResponse, snippet)
assert result["author_name"] == "Alice"

View File

@ -12,7 +12,7 @@ export type AccountAvatarPayload = {
avatar: string
}
export type Account = {
export type AccountResponse = {
avatar?: string | null
readonly avatar_url: string | null
created_at?: number | null
@ -140,7 +140,7 @@ export type AccountIntegrateResponse = {
provider: string
}
export type AccountWritable = {
export type AccountResponseWritable = {
avatar?: string | null
created_at?: number | null
email: string
@ -177,7 +177,7 @@ export type PostAccountAvatarData = {
}
export type PostAccountAvatarResponses = {
200: Account
200: AccountResponse
}
export type PostAccountAvatarResponse = PostAccountAvatarResponses[keyof PostAccountAvatarResponses]
@ -218,7 +218,7 @@ export type PostAccountChangeEmailResetData = {
}
export type PostAccountChangeEmailResetResponses = {
200: Account
200: AccountResponse
}
export type PostAccountChangeEmailResetResponse
@ -374,7 +374,7 @@ export type PostAccountInterfaceLanguageData = {
}
export type PostAccountInterfaceLanguageResponses = {
200: Account
200: AccountResponse
}
export type PostAccountInterfaceLanguageResponse
@ -388,7 +388,7 @@ export type PostAccountInterfaceThemeData = {
}
export type PostAccountInterfaceThemeResponses = {
200: Account
200: AccountResponse
}
export type PostAccountInterfaceThemeResponse
@ -402,7 +402,7 @@ export type PostAccountNameData = {
}
export type PostAccountNameResponses = {
200: Account
200: AccountResponse
}
export type PostAccountNameResponse = PostAccountNameResponses[keyof PostAccountNameResponses]
@ -415,7 +415,7 @@ export type PostAccountPasswordData = {
}
export type PostAccountPasswordResponses = {
200: Account
200: AccountResponse
}
export type PostAccountPasswordResponse
@ -429,7 +429,7 @@ export type GetAccountProfileData = {
}
export type GetAccountProfileResponses = {
200: Account
200: AccountResponse
}
export type GetAccountProfileResponse = GetAccountProfileResponses[keyof GetAccountProfileResponses]
@ -442,7 +442,7 @@ export type PostAccountTimezoneData = {
}
export type PostAccountTimezoneResponses = {
200: Account
200: AccountResponse
}
export type PostAccountTimezoneResponse

View File

@ -17,9 +17,9 @@ export const zAccountAvatarPayload = z.object({
})
/**
* Account
* AccountResponse
*/
export const zAccount = z.object({
export const zAccountResponse = z.object({
avatar: z.string().nullish(),
avatar_url: z.string().nullable(),
created_at: z.int().nullish(),
@ -212,9 +212,9 @@ export const zAccountIntegrateListResponse = z.object({
})
/**
* Account
* AccountResponse
*/
export const zAccountWritable = z.object({
export const zAccountResponseWritable = z.object({
avatar: z.string().nullish(),
created_at: z.int().nullish(),
email: z.string(),
@ -242,7 +242,7 @@ export const zPostAccountAvatarBody = zAccountAvatarPayload
/**
* Success
*/
export const zPostAccountAvatarResponse = zAccount
export const zPostAccountAvatarResponse = zAccountResponse
export const zPostAccountChangeEmailBody = zChangeEmailSendPayload
@ -263,7 +263,7 @@ export const zPostAccountChangeEmailResetBody = zChangeEmailResetPayload
/**
* Success
*/
export const zPostAccountChangeEmailResetResponse = zAccount
export const zPostAccountChangeEmailResetResponse = zAccountResponse
export const zPostAccountChangeEmailValidityBody = zChangeEmailValidityPayload
@ -336,37 +336,37 @@ export const zPostAccountInterfaceLanguageBody = zAccountInterfaceLanguagePayloa
/**
* Success
*/
export const zPostAccountInterfaceLanguageResponse = zAccount
export const zPostAccountInterfaceLanguageResponse = zAccountResponse
export const zPostAccountInterfaceThemeBody = zAccountInterfaceThemePayload
/**
* Success
*/
export const zPostAccountInterfaceThemeResponse = zAccount
export const zPostAccountInterfaceThemeResponse = zAccountResponse
export const zPostAccountNameBody = zAccountNamePayload
/**
* Success
*/
export const zPostAccountNameResponse = zAccount
export const zPostAccountNameResponse = zAccountResponse
export const zPostAccountPasswordBody = zAccountPasswordPayload
/**
* Success
*/
export const zPostAccountPasswordResponse = zAccount
export const zPostAccountPasswordResponse = zAccountResponse
/**
* Success
*/
export const zGetAccountProfileResponse = zAccount
export const zGetAccountProfileResponse = zAccountResponse
export const zPostAccountTimezoneBody = zAccountTimezonePayload
/**
* Success
*/
export const zPostAccountTimezoneResponse = zAccount
export const zPostAccountTimezoneResponse = zAccountResponse

View File

@ -731,7 +731,7 @@ export type WorkflowRunPaginationResponse = {
export type WorkflowRunDetailResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -799,7 +799,7 @@ export type WorkflowCommentCreate = {
}
export type WorkflowCommentMentionUsersPayload = {
users: Array<AccountWithRole>
users: Array<AccountWithRoleResponse>
}
export type WorkflowCommentDetail = {
@ -887,7 +887,7 @@ export type DefaultBlockConfigResponse = {
export type WorkflowResponse = {
conversation_variables: Array<WorkflowConversationVariableResponse>
created_at: number
created_by?: SimpleAccount | null
created_by?: SimpleAccountResponse | null
environment_variables: Array<WorkflowEnvironmentVariableResponse>
features: {
[key: string]: unknown
@ -902,7 +902,7 @@ export type WorkflowResponse = {
rag_pipeline_variables: Array<PipelineVariableResponse>
tool_published: boolean
updated_at: number
updated_by?: SimpleAccount | null
updated_by?: SimpleAccountResponse | null
version: string
}
@ -1029,7 +1029,7 @@ export type AgentComposerValidateResponse = {
export type WorkflowRunNodeExecutionResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -1146,6 +1146,8 @@ export type PublishWorkflowPayload = {
knowledge_base_setting?: {
[key: string]: unknown
} | null
marked_comment?: string | null
marked_name?: string | null
}
export type WorkflowPublishResponse = {
@ -1289,7 +1291,7 @@ export type WorkflowOnlineUsersByApp = {
export type AdvancedChatWorkflowRunForListResponse = {
conversation_id?: string | null
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
elapsed_time?: number | null
exceptions_count?: number | null
finished_at?: number | null
@ -1596,7 +1598,7 @@ export type UserSatisfactionRateStatisticItem = {
export type WorkflowAppLogPartialResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
created_from?: string | null
@ -1607,7 +1609,7 @@ export type WorkflowAppLogPartialResponse = {
export type WorkflowArchivedLogPartialResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
id: string
trigger_metadata?: unknown
@ -1616,7 +1618,7 @@ export type WorkflowArchivedLogPartialResponse = {
export type WorkflowRunForListResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
elapsed_time?: number | null
exceptions_count?: number | null
finished_at?: number | null
@ -1628,7 +1630,7 @@ export type WorkflowRunForListResponse = {
version?: string | null
}
export type SimpleAccount = {
export type SimpleAccountResponse = {
email: string
id: string
name: string
@ -1671,7 +1673,7 @@ export type WorkflowCommentBasic = {
updated_at?: number | null
}
export type AccountWithRole = {
export type AccountWithRoleResponse = {
avatar?: string | null
created_at?: number | null
email: string
@ -2054,6 +2056,12 @@ export type SimpleMessageDetail = {
query: string
}
export type SimpleAccount = {
email: string
id: string
name: string
}
export type HumanInputFormDefinition = {
actions?: Array<UserActionConfig>
display_in_ui?: boolean

View File

@ -728,6 +728,8 @@ export const zWorkflowDraftVariableUpdatePayload = z.object({
*/
export const zPublishWorkflowPayload = z.object({
knowledge_base_setting: z.record(z.string(), z.unknown()).nullish(),
marked_comment: z.string().max(100).nullish(),
marked_name: z.string().max(20).nullish(),
})
/**
@ -1319,9 +1321,9 @@ export const zUserSatisfactionRateStatisticResponse = z.object({
})
/**
* SimpleAccount
* SimpleAccountResponse
*/
export const zSimpleAccount = z.object({
export const zSimpleAccountResponse = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
@ -1333,7 +1335,7 @@ export const zSimpleAccount = z.object({
export const zAdvancedChatWorkflowRunForListResponse = z.object({
conversation_id: z.string().nullish(),
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
elapsed_time: z.number().nullish(),
exceptions_count: z.int().nullish(),
finished_at: z.int().nullish(),
@ -1355,72 +1357,12 @@ export const zAdvancedChatWorkflowRunPaginationResponse = z.object({
limit: z.int(),
})
/**
* ConversationAnnotation
*/
export const zConversationAnnotation = z.object({
account: zSimpleAccount.nullish(),
content: z.string(),
created_at: z.int().nullish(),
id: z.string(),
question: z.string().nullish(),
})
/**
* ConversationAnnotationHitHistory
*/
export const zConversationAnnotationHitHistory = z.object({
annotation_create_account: zSimpleAccount.nullish(),
created_at: z.int().nullish(),
id: z.string(),
})
/**
* Feedback
*/
export const zFeedback = z.object({
content: z.string().nullish(),
from_account: zSimpleAccount.nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
rating: z.string(),
})
/**
* MessageDetail
*/
export const zMessageDetail = z.object({
agent_thoughts: z.array(zAgentThought),
annotation: zConversationAnnotation.nullish(),
annotation_hit_history: zConversationAnnotationHitHistory.nullish(),
answer_tokens: z.int(),
conversation_id: z.string(),
created_at: z.int().nullish(),
error: z.string().nullish(),
feedbacks: z.array(zFeedback),
from_account_id: z.string().nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
id: z.string(),
inputs: z.record(z.string(), zJsonValue),
message: zJsonValue,
message_files: z.array(zMessageFile),
message_metadata_dict: zJsonValue,
message_tokens: z.int(),
parent_message_id: z.string().nullish(),
provider_response_latency: z.number(),
query: z.string(),
re_sign_file_url_answer: z.string(),
status: z.string(),
workflow_run_id: z.string().nullish(),
})
/**
* WorkflowRunForListResponse
*/
export const zWorkflowRunForListResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
elapsed_time: z.number().nullish(),
exceptions_count: z.int().nullish(),
finished_at: z.int().nullish(),
@ -1456,7 +1398,7 @@ export const zSimpleEndUser = z.object({
*/
export const zWorkflowRunDetailResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -1478,7 +1420,7 @@ export const zWorkflowRunDetailResponse = z.object({
*/
export const zWorkflowRunNodeExecutionResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -1544,9 +1486,9 @@ export const zSandboxUploadResponse = z.object({
})
/**
* AccountWithRole
* AccountWithRoleResponse
*/
export const zAccountWithRole = z.object({
export const zAccountWithRoleResponse = z.object({
avatar: z.string().nullish(),
created_at: z.int().nullish(),
email: z.string(),
@ -1563,7 +1505,7 @@ export const zAccountWithRole = z.object({
* WorkflowCommentMentionUsersPayload
*/
export const zWorkflowCommentMentionUsersPayload = z.object({
users: z.array(zAccountWithRole),
users: z.array(zAccountWithRoleResponse),
})
/**
@ -1752,7 +1694,7 @@ export const zPipelineVariableResponse = z.object({
export const zWorkflowResponse = z.object({
conversation_variables: z.array(zWorkflowConversationVariableResponse),
created_at: z.int(),
created_by: zSimpleAccount.nullish(),
created_by: zSimpleAccountResponse.nullish(),
environment_variables: z.array(zWorkflowEnvironmentVariableResponse),
features: z.record(z.string(), z.unknown()),
graph: z.record(z.string(), z.unknown()),
@ -1763,7 +1705,7 @@ export const zWorkflowResponse = z.object({
rag_pipeline_variables: z.array(zPipelineVariableResponse),
tool_published: z.boolean(),
updated_at: z.int(),
updated_by: zSimpleAccount.nullish(),
updated_by: zSimpleAccountResponse.nullish(),
version: z.string(),
})
@ -2152,20 +2094,6 @@ export const zConversationDetail = z.object({
user_feedback_stats: zFeedbackStat.nullish(),
})
/**
* ConversationMessageDetail
*/
export const zConversationMessageDetail = z.object({
created_at: z.int().nullish(),
first_message: zMessageDetail.nullish(),
from_account_id: z.string().nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
id: z.string(),
model_config: zModelConfig.nullish(),
status: z.string(),
})
/**
* Type
*/
@ -2366,6 +2294,26 @@ export const zSimpleMessageDetail = z.object({
query: z.string(),
})
/**
* SimpleAccount
*/
export const zSimpleAccount = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
})
/**
* ConversationAnnotation
*/
export const zConversationAnnotation = z.object({
account: zSimpleAccount.nullish(),
content: z.string(),
created_at: z.int().nullish(),
id: z.string(),
question: z.string().nullish(),
})
/**
* Conversation
*/
@ -2398,6 +2346,69 @@ export const zConversationPagination = z.object({
total: z.int(),
})
/**
* ConversationAnnotationHitHistory
*/
export const zConversationAnnotationHitHistory = z.object({
annotation_create_account: zSimpleAccount.nullish(),
created_at: z.int().nullish(),
id: z.string(),
})
/**
* Feedback
*/
export const zFeedback = z.object({
content: z.string().nullish(),
from_account: zSimpleAccount.nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
rating: z.string(),
})
/**
* MessageDetail
*/
export const zMessageDetail = z.object({
agent_thoughts: z.array(zAgentThought),
annotation: zConversationAnnotation.nullish(),
annotation_hit_history: zConversationAnnotationHitHistory.nullish(),
answer_tokens: z.int(),
conversation_id: z.string(),
created_at: z.int().nullish(),
error: z.string().nullish(),
feedbacks: z.array(zFeedback),
from_account_id: z.string().nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
id: z.string(),
inputs: z.record(z.string(), zJsonValue),
message: zJsonValue,
message_files: z.array(zMessageFile),
message_metadata_dict: zJsonValue,
message_tokens: z.int(),
parent_message_id: z.string().nullish(),
provider_response_latency: z.number(),
query: z.string(),
re_sign_file_url_answer: z.string(),
status: z.string(),
workflow_run_id: z.string().nullish(),
})
/**
* ConversationMessageDetail
*/
export const zConversationMessageDetail = z.object({
created_at: z.int().nullish(),
first_message: zMessageDetail.nullish(),
from_account_id: z.string().nullish(),
from_end_user_id: z.string().nullish(),
from_source: z.string(),
id: z.string(),
model_config: zModelConfig.nullish(),
status: z.string(),
})
/**
* ExecutionContentType
*/
@ -2425,7 +2436,7 @@ export const zWorkflowRunForLogResponse = z.object({
*/
export const zWorkflowAppLogPartialResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
created_from: z.string().nullish(),
@ -2461,7 +2472,7 @@ export const zWorkflowRunForArchivedLogResponse = z.object({
*/
export const zWorkflowArchivedLogPartialResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
id: z.string(),
trigger_metadata: z.unknown().optional(),

View File

@ -119,7 +119,7 @@ export type SimpleResultResponse = {
export type WorkflowRunDetailResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -158,7 +158,7 @@ export type DefaultBlockConfigResponse = {
export type WorkflowResponse = {
conversation_variables: Array<WorkflowConversationVariableResponse>
created_at: number
created_by?: SimpleAccount | null
created_by?: SimpleAccountResponse | null
environment_variables: Array<WorkflowEnvironmentVariableResponse>
features: {
[key: string]: unknown
@ -173,7 +173,7 @@ export type WorkflowResponse = {
rag_pipeline_variables: Array<PipelineVariableResponse>
tool_published: boolean
updated_at: number
updated_by?: SimpleAccount | null
updated_by?: SimpleAccountResponse | null
version: string
}
@ -221,7 +221,7 @@ export type DatasourceVariablesPayload = {
export type WorkflowRunNodeExecutionResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -421,7 +421,7 @@ export type PluginDependency = {
export type WorkflowRunForListResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
elapsed_time?: number | null
exceptions_count?: number | null
finished_at?: number | null
@ -433,7 +433,7 @@ export type WorkflowRunForListResponse = {
version?: string | null
}
export type SimpleAccount = {
export type SimpleAccountResponse = {
email: string
id: string
name: string

View File

@ -322,9 +322,9 @@ export const zPipelineTemplateListResponse = z.object({
})
/**
* SimpleAccount
* SimpleAccountResponse
*/
export const zSimpleAccount = z.object({
export const zSimpleAccountResponse = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
@ -335,7 +335,7 @@ export const zSimpleAccount = z.object({
*/
export const zWorkflowRunForListResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
elapsed_time: z.number().nullish(),
exceptions_count: z.int().nullish(),
finished_at: z.int().nullish(),
@ -371,7 +371,7 @@ export const zSimpleEndUser = z.object({
*/
export const zWorkflowRunDetailResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -393,7 +393,7 @@ export const zWorkflowRunDetailResponse = z.object({
*/
export const zWorkflowRunNodeExecutionResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -471,7 +471,7 @@ export const zPipelineVariableResponse = z.object({
export const zWorkflowResponse = z.object({
conversation_variables: z.array(zWorkflowConversationVariableResponse),
created_at: z.int(),
created_by: zSimpleAccount.nullish(),
created_by: zSimpleAccountResponse.nullish(),
environment_variables: z.array(zWorkflowEnvironmentVariableResponse),
features: z.record(z.string(), z.unknown()),
graph: z.record(z.string(), z.unknown()),
@ -482,7 +482,7 @@ export const zWorkflowResponse = z.object({
rag_pipeline_variables: z.array(zPipelineVariableResponse),
tool_published: z.boolean(),
updated_at: z.int(),
updated_by: zSimpleAccount.nullish(),
updated_by: zSimpleAccountResponse.nullish(),
version: z.string(),
})

View File

@ -16,7 +16,7 @@ export type SimpleResultResponse = {
export type WorkflowRunDetailResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -51,7 +51,7 @@ export type DefaultBlockConfigsResponse = Array<{
export type SnippetWorkflowResponse = {
conversation_variables: Array<WorkflowConversationVariableResponse>
created_at: number
created_by?: SimpleAccount | null
created_by?: SimpleAccountResponse | null
environment_variables: Array<WorkflowEnvironmentVariableResponse>
features: {
[key: string]: unknown
@ -69,7 +69,7 @@ export type SnippetWorkflowResponse = {
rag_pipeline_variables: Array<PipelineVariableResponse>
tool_published: boolean
updated_at: number
updated_by?: SimpleAccount | null
updated_by?: SimpleAccountResponse | null
version: string
}
@ -120,7 +120,7 @@ export type SnippetLoopNodeRunPayload = {
export type WorkflowRunNodeExecutionResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
elapsed_time?: number | null
@ -201,6 +201,8 @@ export type PublishWorkflowPayload = {
knowledge_base_setting?: {
[key: string]: unknown
} | null
marked_comment?: string | null
marked_name?: string | null
}
export type WorkflowPublishResponse = {
@ -210,7 +212,7 @@ export type WorkflowPublishResponse = {
export type WorkflowRunForListResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
elapsed_time?: number | null
exceptions_count?: number | null
finished_at?: number | null
@ -222,7 +224,7 @@ export type WorkflowRunForListResponse = {
version?: string | null
}
export type SimpleAccount = {
export type SimpleAccountResponse = {
email: string
id: string
name: string

View File

@ -123,6 +123,8 @@ export const zWorkflowDraftVariableUpdatePayload = z.object({
*/
export const zPublishWorkflowPayload = z.object({
knowledge_base_setting: z.record(z.string(), z.unknown()).nullish(),
marked_comment: z.string().max(100).nullish(),
marked_name: z.string().max(20).nullish(),
})
/**
@ -134,9 +136,9 @@ export const zWorkflowPublishResponse = z.object({
})
/**
* SimpleAccount
* SimpleAccountResponse
*/
export const zSimpleAccount = z.object({
export const zSimpleAccountResponse = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
@ -147,7 +149,7 @@ export const zSimpleAccount = z.object({
*/
export const zWorkflowRunForListResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
elapsed_time: z.number().nullish(),
exceptions_count: z.int().nullish(),
finished_at: z.int().nullish(),
@ -183,7 +185,7 @@ export const zSimpleEndUser = z.object({
*/
export const zWorkflowRunDetailResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -205,7 +207,7 @@ export const zWorkflowRunDetailResponse = z.object({
*/
export const zWorkflowRunNodeExecutionResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
elapsed_time: z.number().nullish(),
@ -283,7 +285,7 @@ export const zPipelineVariableResponse = z.object({
export const zSnippetWorkflowResponse = z.object({
conversation_variables: z.array(zWorkflowConversationVariableResponse),
created_at: z.int(),
created_by: zSimpleAccount.nullish(),
created_by: zSimpleAccountResponse.nullish(),
environment_variables: z.array(zWorkflowEnvironmentVariableResponse),
features: z.record(z.string(), z.unknown()),
graph: z.record(z.string(), z.unknown()),
@ -295,7 +297,7 @@ export const zSnippetWorkflowResponse = z.object({
rag_pipeline_variables: z.array(zPipelineVariableResponse),
tool_published: z.boolean(),
updated_at: z.int(),
updated_by: zSimpleAccount.nullish(),
updated_by: zSimpleAccountResponse.nullish(),
version: z.string(),
})

View File

@ -31,12 +31,12 @@ export type AgentProviderListResponse = Array<{
[key: string]: unknown
}>
export type SnippetPagination = {
data?: Array<AnonymousInlineModel744Ff9Cc03E6>
has_more?: boolean
limit?: number
page?: number
total?: number
export type SnippetPaginationResponse = {
data: Array<SnippetListItemResponse>
has_more: boolean
limit: number
page: number
total: number
}
export type CreateSnippetPayload = {
@ -50,28 +50,28 @@ export type CreateSnippetPayload = {
type?: 'group' | 'node'
}
export type Snippet = {
created_at?: number
created_by?: AnonymousInlineModelB0Fd3F86D9D5
description?: string
export type SnippetResponse = {
created_at?: number | null
created_by?: SimpleAccountResponse | null
description?: string | null
graph?: {
[key: string]: unknown
}
} | null
icon_info?: {
[key: string]: unknown
}
id?: string
input_fields?: {
} | null
id: string
input_fields?: Array<{
[key: string]: unknown
}
is_published?: boolean
name?: string
tags?: Array<AnonymousInlineModel7B8B49Ca164e>
type?: string
updated_at?: number
updated_by?: AnonymousInlineModelB0Fd3F86D9D5
use_count?: number
version?: number
}> | null
is_published: boolean
name: string
tags?: Array<SnippetTagResponse>
type: string
updated_at?: number | null
updated_by?: SimpleAccountResponse | null
use_count: number
version: number
}
export type SnippetImportPayload = {
@ -83,8 +83,13 @@ export type SnippetImportPayload = {
yaml_url?: string | null
}
export type SnippetImportResponse = {
[key: string]: unknown
export type SnippetImportInfo = {
current_dsl_version?: string
error?: string
id: string
imported_dsl_version?: string
snippet_id?: string | null
status: ImportStatus
}
export type UpdateSnippetPayload = {
@ -93,19 +98,17 @@ export type UpdateSnippetPayload = {
name?: string | null
}
export type SnippetDependencyCheckResponse = {
[key: string]: unknown
export type CheckDependenciesResult = {
leaked_dependencies?: Array<PluginDependency>
}
export type TextFileResponse = string
export type SnippetUseCountResponse = {
export type SnippetUseCountIncrementResponse = {
result: string
use_count: number
}
export type AccountWithRoleList = {
accounts: Array<AccountWithRole>
export type AccountWithRoleListResponse = {
accounts: Array<AccountWithRoleResponse>
}
export type DefaultModelDataResponse = {
@ -872,23 +875,23 @@ export type WorkspaceCustomConfigResponse = {
replace_webapp_logo?: string | null
}
export type AnonymousInlineModel744Ff9Cc03E6 = {
author_name?: string
created_at?: number
created_by?: string
description?: string
export type SnippetListItemResponse = {
author_name?: string | null
created_at?: number | null
created_by?: string | null
description?: string | null
icon_info?: {
[key: string]: unknown
}
id?: string
is_published?: boolean
name?: string
tags?: Array<AnonymousInlineModel7B8B49Ca164e>
type?: string
updated_at?: number
updated_by?: string
use_count?: number
version?: number
} | null
id: string
is_published: boolean
name: string
tags?: Array<SnippetTagResponse>
type: string
updated_at?: number | null
updated_by?: string | null
use_count: number
version: number
}
export type IconInfo = {
@ -909,19 +912,27 @@ export type InputFieldDefinition = {
type?: string | null
}
export type AnonymousInlineModelB0Fd3F86D9D5 = {
email?: string
id?: string
name?: string
export type SimpleAccountResponse = {
email: string
id: string
name: string
}
export type AnonymousInlineModel7B8B49Ca164e = {
id?: string
name?: string
type?: string
export type SnippetTagResponse = {
id: string
name: string
type: string
}
export type AccountWithRole = {
export type ImportStatus = 'completed' | 'completed-with-warnings' | 'failed' | 'pending'
export type PluginDependency = {
current_identifier?: string | null
type: Type
value: Github | Marketplace | Package
}
export type AccountWithRoleResponse = {
avatar?: string | null
created_at?: number | null
email: string
@ -1198,6 +1209,25 @@ export type WorkflowToolParameterConfiguration = {
name: string
}
export type Type = 'github' | 'marketplace' | 'package'
export type Github = {
github_plugin_unique_identifier: string
package: string
repo: string
version: string
}
export type Marketplace = {
marketplace_plugin_unique_identifier: string
version?: string | null
}
export type Package = {
plugin_unique_identifier: string
version?: string | null
}
export type SimpleProviderEntityResponse = {
icon_small?: I18nObject | null
icon_small_dark?: I18nObject | null
@ -1583,7 +1613,7 @@ export type GetWorkspacesCurrentCustomizedSnippetsData = {
}
export type GetWorkspacesCurrentCustomizedSnippetsResponses = {
200: SnippetPagination
200: SnippetPaginationResponse
}
export type GetWorkspacesCurrentCustomizedSnippetsResponse
@ -1601,7 +1631,7 @@ export type PostWorkspacesCurrentCustomizedSnippetsErrors = {
}
export type PostWorkspacesCurrentCustomizedSnippetsResponses = {
201: Snippet
201: SnippetResponse
}
export type PostWorkspacesCurrentCustomizedSnippetsResponse
@ -1619,8 +1649,8 @@ export type PostWorkspacesCurrentCustomizedSnippetsImportsErrors = {
}
export type PostWorkspacesCurrentCustomizedSnippetsImportsResponses = {
200: SnippetImportResponse
202: SnippetImportResponse
200: SnippetImportInfo
202: SnippetImportInfo
}
export type PostWorkspacesCurrentCustomizedSnippetsImportsResponse
@ -1640,7 +1670,7 @@ export type PostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmError
}
export type PostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmResponses = {
200: SnippetImportResponse
200: SnippetImportInfo
}
export type PostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmResponse
@ -1680,7 +1710,7 @@ export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdErrors = {
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdResponses = {
200: Snippet
200: SnippetResponse
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse
@ -1701,7 +1731,7 @@ export type PatchWorkspacesCurrentCustomizedSnippetsBySnippetIdErrors = {
}
export type PatchWorkspacesCurrentCustomizedSnippetsBySnippetIdResponses = {
200: Snippet
200: SnippetResponse
}
export type PatchWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse
@ -1721,34 +1751,12 @@ export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesEr
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesResponses = {
200: SnippetDependencyCheckResponse
200: CheckDependenciesResult
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesResponse
= GetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesResponses[keyof GetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesResponses]
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportData = {
body?: never
path: {
snippet_id: string
}
query?: {
include_secret?: string
}
url: '/workspaces/current/customized-snippets/{snippet_id}/export'
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportErrors = {
404: unknown
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportResponses = {
200: TextFileResponse
}
export type GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportResponse
= GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportResponses[keyof GetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportResponses]
export type PostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementData = {
body?: never
path: {
@ -1763,7 +1771,7 @@ export type PostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementE
}
export type PostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementResponses = {
200: SnippetUseCountResponse
200: SnippetUseCountIncrementResponse
}
export type PostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementResponse
@ -1777,7 +1785,7 @@ export type GetWorkspacesCurrentDatasetOperatorsData = {
}
export type GetWorkspacesCurrentDatasetOperatorsResponses = {
200: AccountWithRoleList
200: AccountWithRoleListResponse
}
export type GetWorkspacesCurrentDatasetOperatorsResponse
@ -2004,7 +2012,7 @@ export type GetWorkspacesCurrentMembersData = {
}
export type GetWorkspacesCurrentMembersResponses = {
200: AccountWithRoleList
200: AccountWithRoleListResponse
}
export type GetWorkspacesCurrentMembersResponse

View File

@ -27,24 +27,9 @@ export const zSnippetImportPayload = z.object({
})
/**
* SnippetImportResponse
* SnippetUseCountIncrementResponse
*/
export const zSnippetImportResponse = z.record(z.string(), z.unknown())
/**
* SnippetDependencyCheckResponse
*/
export const zSnippetDependencyCheckResponse = z.record(z.string(), z.unknown())
/**
* TextFileResponse
*/
export const zTextFileResponse = z.string()
/**
* SnippetUseCountResponse
*/
export const zSnippetUseCountResponse = z.object({
export const zSnippetUseCountIncrementResponse = z.object({
result: z.string(),
use_count: z.int(),
})
@ -801,97 +786,97 @@ export const zCreateSnippetPayload = z.object({
type: z.enum(['group', 'node']).optional().default('node'),
})
export const zAnonymousInlineModelB0Fd3F86D9D5 = z.object({
email: z.string().optional(),
id: z.string().optional(),
name: z.string().optional(),
})
export const zAnonymousInlineModel7B8B49Ca164e = z.object({
id: z.string().optional(),
name: z.string().optional(),
type: z.string().optional(),
})
export const zSnippet = z.object({
created_at: z.coerce
.bigint()
.min(BigInt('-9223372036854775808'), {
error: 'Invalid value: Expected int64 to be >= -9223372036854775808',
})
.max(BigInt('9223372036854775807'), {
error: 'Invalid value: Expected int64 to be <= 9223372036854775807',
})
.optional(),
created_by: zAnonymousInlineModelB0Fd3F86D9D5.optional(),
description: z.string().optional(),
graph: z.record(z.string(), z.unknown()).optional(),
icon_info: z.record(z.string(), z.unknown()).optional(),
id: z.string().optional(),
input_fields: z.record(z.string(), z.unknown()).optional(),
is_published: z.boolean().optional(),
name: z.string().optional(),
tags: z.array(zAnonymousInlineModel7B8B49Ca164e).optional(),
type: z.string().optional(),
updated_at: z.coerce
.bigint()
.min(BigInt('-9223372036854775808'), {
error: 'Invalid value: Expected int64 to be >= -9223372036854775808',
})
.max(BigInt('9223372036854775807'), {
error: 'Invalid value: Expected int64 to be <= 9223372036854775807',
})
.optional(),
updated_by: zAnonymousInlineModelB0Fd3F86D9D5.optional(),
use_count: z.int().optional(),
version: z.int().optional(),
})
export const zAnonymousInlineModel744Ff9Cc03E6 = z.object({
author_name: z.string().optional(),
created_at: z.coerce
.bigint()
.min(BigInt('-9223372036854775808'), {
error: 'Invalid value: Expected int64 to be >= -9223372036854775808',
})
.max(BigInt('9223372036854775807'), {
error: 'Invalid value: Expected int64 to be <= 9223372036854775807',
})
.optional(),
created_by: z.string().optional(),
description: z.string().optional(),
icon_info: z.record(z.string(), z.unknown()).optional(),
id: z.string().optional(),
is_published: z.boolean().optional(),
name: z.string().optional(),
tags: z.array(zAnonymousInlineModel7B8B49Ca164e).optional(),
type: z.string().optional(),
updated_at: z.coerce
.bigint()
.min(BigInt('-9223372036854775808'), {
error: 'Invalid value: Expected int64 to be >= -9223372036854775808',
})
.max(BigInt('9223372036854775807'), {
error: 'Invalid value: Expected int64 to be <= 9223372036854775807',
})
.optional(),
updated_by: z.string().optional(),
use_count: z.int().optional(),
version: z.int().optional(),
})
export const zSnippetPagination = z.object({
data: z.array(zAnonymousInlineModel744Ff9Cc03E6).optional(),
has_more: z.boolean().optional(),
limit: z.int().optional(),
page: z.int().optional(),
total: z.int().optional(),
/**
* SimpleAccountResponse
*/
export const zSimpleAccountResponse = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
})
/**
* AccountWithRole
* SnippetTagResponse
*/
export const zAccountWithRole = z.object({
export const zSnippetTagResponse = z.object({
id: z.string(),
name: z.string(),
type: z.string(),
})
/**
* SnippetResponse
*/
export const zSnippetResponse = z.object({
created_at: z.int().nullish(),
created_by: zSimpleAccountResponse.nullish(),
description: z.string().nullish(),
graph: z.record(z.string(), z.unknown()).nullish(),
icon_info: z.record(z.string(), z.unknown()).nullish(),
id: z.string(),
input_fields: z.array(z.record(z.string(), z.unknown())).nullish(),
is_published: z.boolean(),
name: z.string(),
tags: z.array(zSnippetTagResponse).optional(),
type: z.string(),
updated_at: z.int().nullish(),
updated_by: zSimpleAccountResponse.nullish(),
use_count: z.int(),
version: z.int(),
})
/**
* SnippetListItemResponse
*/
export const zSnippetListItemResponse = z.object({
author_name: z.string().nullish(),
created_at: z.int().nullish(),
created_by: z.string().nullish(),
description: z.string().nullish(),
icon_info: z.record(z.string(), z.unknown()).nullish(),
id: z.string(),
is_published: z.boolean(),
name: z.string(),
tags: z.array(zSnippetTagResponse).optional(),
type: z.string(),
updated_at: z.int().nullish(),
updated_by: z.string().nullish(),
use_count: z.int(),
version: z.int(),
})
/**
* SnippetPaginationResponse
*/
export const zSnippetPaginationResponse = z.object({
data: z.array(zSnippetListItemResponse),
has_more: z.boolean(),
limit: z.int(),
page: z.int(),
total: z.int(),
})
/**
* ImportStatus
*/
export const zImportStatus = z.enum(['completed', 'completed-with-warnings', 'failed', 'pending'])
/**
* SnippetImportInfo
*/
export const zSnippetImportInfo = z.object({
current_dsl_version: z.string().optional().default('0.1.0'),
error: z.string().optional().default(''),
id: z.string(),
imported_dsl_version: z.string().optional().default(''),
snippet_id: z.string().nullish(),
status: zImportStatus,
})
/**
* AccountWithRoleResponse
*/
export const zAccountWithRoleResponse = z.object({
avatar: z.string().nullish(),
created_at: z.int().nullish(),
email: z.string(),
@ -905,10 +890,10 @@ export const zAccountWithRole = z.object({
})
/**
* AccountWithRoleList
* AccountWithRoleListResponse
*/
export const zAccountWithRoleList = z.object({
accounts: z.array(zAccountWithRole),
export const zAccountWithRoleListResponse = z.object({
accounts: z.array(zAccountWithRoleResponse),
})
/**
@ -1374,6 +1359,53 @@ export const zMcpProviderUpdatePayload = z.object({
server_url: z.string(),
})
/**
* Type
*/
export const zType = z.enum(['github', 'marketplace', 'package'])
/**
* Github
*/
export const zGithub = z.object({
github_plugin_unique_identifier: z.string(),
package: z.string(),
repo: z.string(),
version: z.string(),
})
/**
* Marketplace
*/
export const zMarketplace = z.object({
marketplace_plugin_unique_identifier: z.string(),
version: z.string().nullish(),
})
/**
* Package
*/
export const zPackage = z.object({
plugin_unique_identifier: z.string(),
version: z.string().nullish(),
})
/**
* PluginDependency
*/
export const zPluginDependency = z.object({
current_identifier: z.string().nullish(),
type: zType,
value: z.union([zGithub, zMarketplace, zPackage]),
})
/**
* CheckDependenciesResult
*/
export const zCheckDependenciesResult = z.object({
leaked_dependencies: z.array(zPluginDependency).optional(),
})
/**
* ConfigurateMethod
*
@ -2183,21 +2215,21 @@ export const zGetWorkspacesCurrentCustomizedSnippetsQuery = z.object({
/**
* Snippets retrieved successfully
*/
export const zGetWorkspacesCurrentCustomizedSnippetsResponse = zSnippetPagination
export const zGetWorkspacesCurrentCustomizedSnippetsResponse = zSnippetPaginationResponse
export const zPostWorkspacesCurrentCustomizedSnippetsBody = zCreateSnippetPayload
/**
* Snippet created successfully
*/
export const zPostWorkspacesCurrentCustomizedSnippetsResponse = zSnippet
export const zPostWorkspacesCurrentCustomizedSnippetsResponse = zSnippetResponse
export const zPostWorkspacesCurrentCustomizedSnippetsImportsBody = zSnippetImportPayload
/**
* Snippet imported successfully
*/
export const zPostWorkspacesCurrentCustomizedSnippetsImportsResponse = zSnippetImportResponse
export const zPostWorkspacesCurrentCustomizedSnippetsImportsResponse = zSnippetImportInfo
export const zPostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmPath = z.object({
import_id: z.string(),
@ -2207,7 +2239,7 @@ export const zPostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmPat
* Import confirmed successfully
*/
export const zPostWorkspacesCurrentCustomizedSnippetsImportsByImportIdConfirmResponse
= zSnippetImportResponse
= zSnippetImportInfo
export const zDeleteWorkspacesCurrentCustomizedSnippetsBySnippetIdPath = z.object({
snippet_id: z.uuid(),
@ -2225,7 +2257,7 @@ export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdPath = z.object({
/**
* Snippet retrieved successfully
*/
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse = zSnippet
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse = zSnippetResponse
export const zPatchWorkspacesCurrentCustomizedSnippetsBySnippetIdBody = zUpdateSnippetPayload
@ -2236,7 +2268,7 @@ export const zPatchWorkspacesCurrentCustomizedSnippetsBySnippetIdPath = z.object
/**
* Snippet updated successfully
*/
export const zPatchWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse = zSnippet
export const zPatchWorkspacesCurrentCustomizedSnippetsBySnippetIdResponse = zSnippetResponse
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesPath = z.object({
snippet_id: z.uuid(),
@ -2246,20 +2278,7 @@ export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependencies
* Dependencies checked successfully
*/
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdCheckDependenciesResponse
= zSnippetDependencyCheckResponse
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportPath = z.object({
snippet_id: z.uuid(),
})
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportQuery = z.object({
include_secret: z.string().optional().default('false'),
})
/**
* Snippet exported successfully
*/
export const zGetWorkspacesCurrentCustomizedSnippetsBySnippetIdExportResponse = zTextFileResponse
= zCheckDependenciesResult
export const zPostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementPath = z.object({
snippet_id: z.uuid(),
@ -2269,12 +2288,12 @@ export const zPostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncremen
* Use count incremented successfully
*/
export const zPostWorkspacesCurrentCustomizedSnippetsBySnippetIdUseCountIncrementResponse
= zSnippetUseCountResponse
= zSnippetUseCountIncrementResponse
/**
* Success
*/
export const zGetWorkspacesCurrentDatasetOperatorsResponse = zAccountWithRoleList
export const zGetWorkspacesCurrentDatasetOperatorsResponse = zAccountWithRoleListResponse
export const zGetWorkspacesCurrentDefaultModelQuery = z.object({
model_type: z.enum(['llm', 'moderation', 'rerank', 'speech2text', 'text-embedding', 'tts']),
@ -2378,7 +2397,7 @@ export const zPatchWorkspacesCurrentEndpointsByIdResponse = zEndpointUpdateRespo
/**
* Success
*/
export const zGetWorkspacesCurrentMembersResponse = zAccountWithRoleList
export const zGetWorkspacesCurrentMembersResponse = zAccountWithRoleListResponse
export const zPostWorkspacesCurrentMembersInviteEmailBody = zMemberInvitePayload

View File

@ -1414,7 +1414,7 @@ export type SelectInputConfig = {
type?: 'select'
}
export type SimpleAccount = {
export type SimpleAccountResponse = {
email: string
id: string
name: string
@ -1572,7 +1572,7 @@ export type WorkflowAppLogPaginationResponse = {
export type WorkflowAppLogPartialResponse = {
created_at?: number | null
created_by_account?: SimpleAccount | null
created_by_account?: SimpleAccountResponse | null
created_by_end_user?: SimpleEndUser | null
created_by_role?: string | null
created_from?: string | null

View File

@ -1676,9 +1676,9 @@ export const zProcessRule = z.object({
})
/**
* SimpleAccount
* SimpleAccountResponse
*/
export const zSimpleAccount = z.object({
export const zSimpleAccountResponse = z.object({
email: z.string(),
id: z.string(),
name: z.string(),
@ -2196,7 +2196,7 @@ export const zWorkflowRunForLogResponse = z.object({
*/
export const zWorkflowAppLogPartialResponse = z.object({
created_at: z.int().nullish(),
created_by_account: zSimpleAccount.nullish(),
created_by_account: zSimpleAccountResponse.nullish(),
created_by_end_user: zSimpleEndUser.nullish(),
created_by_role: z.string().nullish(),
created_from: z.string().nullish(),

View File

@ -10,13 +10,21 @@ type SwaggerSchema = JsonObject & {
$ref?: string
}
type OpenApiMediaType = JsonObject & {
schema?: SwaggerSchema
}
type OpenApiResponse = JsonObject & {
content?: Record<string, OpenApiMediaType>
}
type OpenApiComponents = JsonObject & {
schemas?: Record<string, SwaggerSchema>
}
type SwaggerOperation = JsonObject & {
operationId?: string
responses?: Record<string, unknown>
responses?: Record<string, OpenApiResponse>
}
type SwaggerDocument = JsonObject & {
@ -52,6 +60,17 @@ const currentDir = path.dirname(fileURLToPath(import.meta.url))
const apiOpenApiDir = path.resolve(currentDir, 'openapi')
const operationMethods = new Set(['delete', 'get', 'patch', 'post', 'put'])
const pydanticDecimalStringPattern = '^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$'
const codegenSafeDecimalStringPattern = '^(?![-+.]*$)[+-]?0*\\d*\\.?\\d*$'
const opaqueJsonContent = (): Record<string, OpenApiMediaType> => ({
'application/json': {
schema: {
additionalProperties: true,
type: 'object',
},
},
})
const apiSpecs: ApiSpec[] = [
{ filename: 'console-openapi.json', name: 'console' },
@ -182,6 +201,46 @@ const addOperationIds = (document: SwaggerDocument) => {
}
}
const isOpaqueContractResponse = (response: OpenApiResponse) => {
const content = response.content
if (!isObject(content))
return false
return Object.entries(content).some(([mediaType, media]) => {
if (!isObject(media))
return false
return (mediaType === 'application/json' || mediaType === 'text/event-stream') && !('schema' in media)
})
}
const hasOpaqueContractSuccessResponse = (operation: SwaggerOperation) => {
return Object.entries(operation.responses ?? {}).some(([status, response]) => {
return /^2\d\d$/.test(status) && isObject(response) && isOpaqueContractResponse(response)
})
}
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()
})
}
}
}
const hasSuccessResponse = (operation: SwaggerOperation) => {
return Object.entries(operation.responses ?? {}).some(([status, response]) => {
if (!/^2\d\d$/.test(status))
@ -215,6 +274,7 @@ const filterContractOperations = (document: SwaggerDocument) => {
}
const normalizeApiSwagger = (document: SwaggerDocument) => {
normalizeOpaqueContractResponses(document)
filterContractOperations(document)
addOperationIds(document)
@ -380,10 +440,20 @@ const createApiConfig = (job: ApiJob): UserConfig => ({
'name': 'zod',
'~resolvers': {
string: (ctx) => {
if (ctx.schema.format !== 'binary')
return undefined
if (ctx.schema.format === 'binary')
return $(ctx.symbols.z).attr('custom').call().generic($.type.or($.type('Blob'), $.type('File')))
return $(ctx.symbols.z).attr('custom').call().generic($.type.or($.type('Blob'), $.type('File')))
if (ctx.schema.pattern === pydanticDecimalStringPattern) {
// the pydantic generated regex will emit error like
// regexp/no-useless-assertions, so patch the regex here
return $(ctx.symbols.z)
.attr('string')
.call()
.attr('regex')
.call($.regexp(codegenSafeDecimalStringPattern))
}
return undefined
},
},
},