Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langgenius Dify UseRunPublishedPipeline

From Leeroopedia
Revision as of 11:28, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Langgenius_Dify_UseRunPublishedPipeline.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources Dify
Domains RAG, Pipeline, Frontend
Last Updated 2026-02-12 00:00 GMT

Overview

Description

UseRunPublishedPipeline is a suite of React Query mutation and query hooks that provide the data-fetching layer for pipeline execution testing in Dify. These hooks enable the frontend to trigger pipeline runs, execute individual datasource nodes, and retrieve execution logs for debugging and validation.

The suite includes three primary hooks:

  • useRunPublishedPipeline -- A mutation hook that executes a published pipeline workflow. Sends a POST request to /rag/pipelines/{pipelineId}/workflows/published/run with the pipeline inputs, datasource configuration, and an is_preview flag. Returns either a PublishedPipelineRunPreviewResponse (for preview mode) or a PublishedPipelineRunResponse (for production mode).
  • useDatasourceSingleRun -- A mutation hook that executes a single datasource node from a draft pipeline for isolated testing. Sends a POST to /rag/pipelines/{pipelineId}/workflows/draft/datasource/variables-inspect.
  • usePipelineExecutionLog -- A query hook that retrieves execution log data for a specific document within a dataset. Fetches from /datasets/{dataset_id}/documents/{document_id}/pipeline-execution-log.

Usage

These hooks are consumed by pipeline testing panels, run dialogs, and document detail views in the Dify frontend. A typical testing workflow involves:

  1. Using useRunPublishedPipeline with is_preview: true to preview pipeline output on sample data.
  2. Reviewing the preview response to validate chunking, token counts, and processing metadata.
  3. Using useDatasourceSingleRun to debug datasource node issues in isolation.
  4. Using usePipelineExecutionLog to inspect historical execution details for indexed documents.

Code Reference

Source Location

web/service/use-pipeline.ts, lines 208--225 (run published), lines 336--345 (execution log), and lines 379--392 (datasource single run)

Signature

export const useRunPublishedPipeline = (
  mutationOptions: MutationOptions<
    PublishedPipelineRunPreviewResponse | PublishedPipelineRunResponse,
    Error,
    PublishedPipelineRunRequest
  > = {},
) => {
  return useMutation({
    mutationKey: [NAME_SPACE, 'run-published-pipeline'],
    mutationFn: (request: PublishedPipelineRunRequest) => {
      const { pipeline_id: pipelineId, is_preview, ...rest } = request
      return post<PublishedPipelineRunPreviewResponse | PublishedPipelineRunResponse>(
        `/rag/pipelines/${pipelineId}/workflows/published/run`,
        {
          body: {
            ...rest,
            is_preview,
            response_mode: 'blocking',
          },
        },
      )
    },
    ...mutationOptions,
  })
}

export const usePipelineExecutionLog = (params: PipelineExecutionLogRequest) => {
  const { dataset_id, document_id } = params
  return useQuery<PipelineExecutionLogResponse>({
    queryKey: [NAME_SPACE, 'pipeline-execution-log', dataset_id, document_id],
    queryFn: () => {
      return get<PipelineExecutionLogResponse>(
        `/datasets/${dataset_id}/documents/${document_id}/pipeline-execution-log`,
      )
    },
    staleTime: 0,
  })
}

export const useDatasourceSingleRun = (
  mutationOptions: MutationOptions<
    DatasourceNodeSingleRunResponse,
    Error,
    DatasourceNodeSingleRunRequest
  > = {},
) => {
  return useMutation({
    mutationKey: [NAME_SPACE, 'datasource-node-single-run'],
    mutationFn: (params: DatasourceNodeSingleRunRequest) => {
      const { pipeline_id: pipelineId, ...rest } = params
      return post<DatasourceNodeSingleRunResponse>(
        `/rag/pipelines/${pipelineId}/workflows/draft/datasource/variables-inspect`,
        { body: rest },
      )
    },
    ...mutationOptions,
  })
}

Import

import {
  useRunPublishedPipeline,
  usePipelineExecutionLog,
  useDatasourceSingleRun,
} from '@/service/use-pipeline'

I/O Contract

useRunPublishedPipeline

Inputs (mutation variables):

Parameter Type Required Description
pipeline_id string Yes The pipeline to execute
inputs Record<string, any> Yes Key-value map of pipeline input variables
start_node_id string Yes The node ID to begin execution from
datasource_type DatasourceType Yes Type of datasource: local_file, online_document, website_crawl, or online_drive
datasource_info_list Array<Record<string, any>> Yes Array of datasource-specific configuration objects
original_document_id string No ID of original document (for re-processing scenarios)
is_preview boolean Yes If true, returns preview response; if false, creates indexed documents

Outputs (Preview Mode):

Field Type Description
task_iod string Task identifier
workflow_run_id string Workflow execution run ID
data.id string Run identifier
data.status string Execution status
data.elapsed_time number Time taken in seconds
data.outputs FileIndexingEstimateResponse Preview of indexing estimates and chunk outputs
data.total_steps number Total processing steps executed
data.total_tokens number Total tokens consumed
data.error string Error message if execution failed

Outputs (Production Mode):

Field Type Description
batch string Batch identifier for the indexing operation
dataset object Dataset metadata including id, name, chunk_structure, description
documents InitialDocumentDetail[] Array of created document records with indexing status

useDatasourceSingleRun

Inputs (mutation variables):

Parameter Type Required Description
pipeline_id string Yes The pipeline containing the datasource node
start_node_id string Yes The datasource node ID to execute
start_node_title string Yes Display title of the datasource node
datasource_type DatasourceType Yes Type of datasource being tested
datasource_info Record<string, any> Yes Datasource-specific configuration

Outputs:

Field Type Description
data NodeRunResult Execution result of the single datasource node run

usePipelineExecutionLog

Inputs:

Parameter Type Required Description
params.dataset_id string Yes The dataset containing the document
params.document_id string Yes The document to retrieve execution logs for

Outputs:

Field Type Description
datasource_info Record<string, any> Configuration of the datasource used during execution
datasource_type DatasourceType Type of datasource that was used
input_data Record<string, any> Input data that was fed into the pipeline
datasource_node_id string ID of the datasource node that processed this document

Usage Examples

// Preview a pipeline run with a local file
const { mutateAsync: runPipeline } = useRunPublishedPipeline({
  onSuccess: (result) => {
    if ('data' in result) {
      // Preview mode response
      console.log('Estimated chunks:', result.data.outputs)
      console.log('Tokens used:', result.data.total_tokens)
    } else {
      // Production mode response
      console.log('Created documents:', result.documents.length)
    }
  },
})

await runPipeline({
  pipeline_id: 'pipeline-abc',
  inputs: { chunk_size: '512', overlap: '50' },
  start_node_id: 'datasource-node-1',
  datasource_type: DatasourceType.localFile,
  datasource_info_list: [{ file_id: 'file-xyz' }],
  is_preview: true,
})

// Test a datasource node in isolation
const { mutateAsync: singleRun } = useDatasourceSingleRun({
  onSuccess: (result) => {
    console.log('Node output:', result)
  },
})

await singleRun({
  pipeline_id: 'pipeline-abc',
  start_node_id: 'datasource-node-1',
  start_node_title: 'File Loader',
  datasource_type: DatasourceType.localFile,
  datasource_info: { file_id: 'file-xyz' },
})

// Retrieve execution logs for a processed document
const { data: executionLog } = usePipelineExecutionLog({
  dataset_id: 'dataset-123',
  document_id: 'doc-456',
})

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment