mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 11:04:27 +08:00
query snippet published history
This commit is contained in:
parent
459a12cd9d
commit
cf7320be8d
@ -78,6 +78,13 @@ class SnippetDraftSyncPayload(BaseModel):
|
|||||||
input_fields: list[dict[str, Any]] | None = None
|
input_fields: list[dict[str, Any]] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
class SnippetWorkflowListQuery(BaseModel):
|
||||||
|
"""Query parameters for listing snippet published workflows."""
|
||||||
|
|
||||||
|
page: int = Field(default=1, ge=1, le=99999)
|
||||||
|
limit: int = Field(default=10, ge=1, le=100)
|
||||||
|
|
||||||
|
|
||||||
class WorkflowRunQuery(BaseModel):
|
class WorkflowRunQuery(BaseModel):
|
||||||
"""Query parameters for workflow runs."""
|
"""Query parameters for workflow runs."""
|
||||||
|
|
||||||
|
|||||||
@ -4,14 +4,14 @@ from functools import wraps
|
|||||||
from typing import ParamSpec, TypeVar
|
from typing import ParamSpec, TypeVar
|
||||||
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask_restx import Resource, fields, marshal_with
|
from flask_restx import Resource, fields, marshal, marshal_with
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from werkzeug.exceptions import InternalServerError, NotFound
|
from werkzeug.exceptions import InternalServerError, NotFound
|
||||||
|
|
||||||
from controllers.common.schema import register_schema_models
|
from controllers.common.schema import register_schema_models
|
||||||
from controllers.console import console_ns
|
from controllers.console import console_ns
|
||||||
from controllers.console.app.error import DraftWorkflowNotExist, DraftWorkflowNotSync
|
from controllers.console.app.error import DraftWorkflowNotExist, DraftWorkflowNotSync
|
||||||
from controllers.console.app.workflow import workflow_model
|
from controllers.console.app.workflow import workflow_model, workflow_pagination_model
|
||||||
from controllers.console.app.workflow_run import (
|
from controllers.console.app.workflow_run import (
|
||||||
workflow_run_detail_model,
|
workflow_run_detail_model,
|
||||||
workflow_run_node_execution_list_model,
|
workflow_run_node_execution_list_model,
|
||||||
@ -25,6 +25,7 @@ from controllers.console.snippets.payloads import (
|
|||||||
SnippetDraftSyncPayload,
|
SnippetDraftSyncPayload,
|
||||||
SnippetIterationNodeRunPayload,
|
SnippetIterationNodeRunPayload,
|
||||||
SnippetLoopNodeRunPayload,
|
SnippetLoopNodeRunPayload,
|
||||||
|
SnippetWorkflowListQuery,
|
||||||
WorkflowRunQuery,
|
WorkflowRunQuery,
|
||||||
)
|
)
|
||||||
from controllers.console.wraps import (
|
from controllers.console.wraps import (
|
||||||
@ -58,6 +59,7 @@ register_schema_models(
|
|||||||
SnippetDraftRunPayload,
|
SnippetDraftRunPayload,
|
||||||
SnippetIterationNodeRunPayload,
|
SnippetIterationNodeRunPayload,
|
||||||
SnippetLoopNodeRunPayload,
|
SnippetLoopNodeRunPayload,
|
||||||
|
SnippetWorkflowListQuery,
|
||||||
WorkflowRunQuery,
|
WorkflowRunQuery,
|
||||||
PublishWorkflowPayload,
|
PublishWorkflowPayload,
|
||||||
)
|
)
|
||||||
@ -250,6 +252,40 @@ class SnippetDefaultBlockConfigsApi(Resource):
|
|||||||
return snippet_service.get_default_block_configs()
|
return snippet_service.get_default_block_configs()
|
||||||
|
|
||||||
|
|
||||||
|
@console_ns.route("/snippets/<uuid:snippet_id>/workflows")
|
||||||
|
class SnippetPublishedAllWorkflowApi(Resource):
|
||||||
|
@console_ns.expect(console_ns.models[SnippetWorkflowListQuery.__name__])
|
||||||
|
@console_ns.doc("get_all_snippet_published_workflows")
|
||||||
|
@console_ns.doc(description="Get all published workflows for a snippet")
|
||||||
|
@console_ns.doc(params={"snippet_id": "Snippet ID"})
|
||||||
|
@console_ns.response(200, "Published workflows retrieved successfully", workflow_pagination_model)
|
||||||
|
@setup_required
|
||||||
|
@login_required
|
||||||
|
@account_initialization_required
|
||||||
|
@get_snippet
|
||||||
|
@edit_permission_required
|
||||||
|
def get(self, snippet: CustomizedSnippet):
|
||||||
|
"""Get all published workflow versions for snippet."""
|
||||||
|
args = SnippetWorkflowListQuery.model_validate(request.args.to_dict(flat=True))
|
||||||
|
|
||||||
|
snippet_service = SnippetService()
|
||||||
|
with Session(db.engine) as session:
|
||||||
|
workflows, has_more = snippet_service.get_all_published_workflows(
|
||||||
|
session=session,
|
||||||
|
snippet=snippet,
|
||||||
|
page=args.page,
|
||||||
|
limit=args.limit,
|
||||||
|
)
|
||||||
|
serialized_workflows = marshal(workflows, workflow_model)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"items": serialized_workflows,
|
||||||
|
"page": args.page,
|
||||||
|
"limit": args.limit,
|
||||||
|
"has_more": has_more,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@console_ns.route("/snippets/<uuid:snippet_id>/workflow-runs")
|
@console_ns.route("/snippets/<uuid:snippet_id>/workflow-runs")
|
||||||
class SnippetWorkflowRunsApi(Resource):
|
class SnippetWorkflowRunsApi(Resource):
|
||||||
@console_ns.doc("list_snippet_workflow_runs")
|
@console_ns.doc("list_snippet_workflow_runs")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user