mirror of
https://github.com/langgenius/dify.git
synced 2026-09-24 23:22:26 +08:00
feat(workflow-generator): enhance the AI auto-creation flow end-to-end (#38175)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
autofix-ci[bot]
Copilot
parent
3ad06bebd9
commit
8809cc036d
@@ -3,12 +3,57 @@
|
||||
import { oc } from '@orpc/contract'
|
||||
import * as z from 'zod'
|
||||
|
||||
import { zPostWorkflowGenerateBody, zPostWorkflowGenerateResponse } from './zod.gen'
|
||||
import {
|
||||
zPostWorkflowGenerateBody,
|
||||
zPostWorkflowGenerateResponse,
|
||||
zPostWorkflowGenerateStreamBody,
|
||||
zPostWorkflowGenerateStreamResponse,
|
||||
zPostWorkflowGenerateSuggestionsBody,
|
||||
zPostWorkflowGenerateSuggestionsResponse,
|
||||
} from './zod.gen'
|
||||
|
||||
/**
|
||||
* Stream a Dify workflow graph (plan then result) via SSE
|
||||
*/
|
||||
export const post = oc
|
||||
.route({
|
||||
description: 'Stream a Dify workflow graph (plan then result) via SSE',
|
||||
inputStructure: 'detailed',
|
||||
method: 'POST',
|
||||
operationId: 'postWorkflowGenerateStream',
|
||||
path: '/workflow-generate/stream',
|
||||
tags: ['console'],
|
||||
})
|
||||
.input(z.object({ body: zPostWorkflowGenerateStreamBody }))
|
||||
.output(zPostWorkflowGenerateStreamResponse)
|
||||
|
||||
export const stream = {
|
||||
post,
|
||||
}
|
||||
|
||||
/**
|
||||
* Suggest example workflow-generator instructions for the tenant
|
||||
*/
|
||||
export const post2 = oc
|
||||
.route({
|
||||
description: 'Suggest example workflow-generator instructions for the tenant',
|
||||
inputStructure: 'detailed',
|
||||
method: 'POST',
|
||||
operationId: 'postWorkflowGenerateSuggestions',
|
||||
path: '/workflow-generate/suggestions',
|
||||
tags: ['console'],
|
||||
})
|
||||
.input(z.object({ body: zPostWorkflowGenerateSuggestionsBody }))
|
||||
.output(zPostWorkflowGenerateSuggestionsResponse)
|
||||
|
||||
export const suggestions = {
|
||||
post: post2,
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a Dify workflow graph from natural language
|
||||
*/
|
||||
export const post = oc
|
||||
export const post3 = oc
|
||||
.route({
|
||||
description: 'Generate a Dify workflow graph from natural language',
|
||||
inputStructure: 'detailed',
|
||||
@@ -21,7 +66,9 @@ export const post = oc
|
||||
.output(zPostWorkflowGenerateResponse)
|
||||
|
||||
export const workflowGenerate = {
|
||||
post,
|
||||
post: post3,
|
||||
stream,
|
||||
suggestions,
|
||||
}
|
||||
|
||||
export const contract = {
|
||||
|
||||
@@ -10,12 +10,18 @@ export type WorkflowGeneratePayload = {
|
||||
} | null
|
||||
ideal_output?: string
|
||||
instruction: string
|
||||
mode: 'advanced-chat' | 'workflow'
|
||||
mode: 'advanced-chat' | 'auto' | 'workflow'
|
||||
model_config: ModelConfig
|
||||
}
|
||||
|
||||
export type GeneratorResponse = unknown
|
||||
|
||||
export type WorkflowInstructionSuggestionsPayload = {
|
||||
count?: number
|
||||
language?: string | null
|
||||
mode: 'advanced-chat' | 'workflow'
|
||||
}
|
||||
|
||||
export type ModelConfig = {
|
||||
completion_params?: {
|
||||
[key: string]: unknown
|
||||
@@ -45,3 +51,41 @@ export type PostWorkflowGenerateResponses = {
|
||||
|
||||
export type PostWorkflowGenerateResponse
|
||||
= PostWorkflowGenerateResponses[keyof PostWorkflowGenerateResponses]
|
||||
|
||||
export type PostWorkflowGenerateStreamData = {
|
||||
body: WorkflowGeneratePayload
|
||||
path?: never
|
||||
query?: never
|
||||
url: '/workflow-generate/stream'
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateStreamErrors = {
|
||||
400: unknown
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateStreamResponses = {
|
||||
200: {
|
||||
[key: string]: unknown
|
||||
}
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateStreamResponse
|
||||
= PostWorkflowGenerateStreamResponses[keyof PostWorkflowGenerateStreamResponses]
|
||||
|
||||
export type PostWorkflowGenerateSuggestionsData = {
|
||||
body: WorkflowInstructionSuggestionsPayload
|
||||
path?: never
|
||||
query?: never
|
||||
url: '/workflow-generate/suggestions'
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateSuggestionsErrors = {
|
||||
400: unknown
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateSuggestionsResponses = {
|
||||
200: GeneratorResponse
|
||||
}
|
||||
|
||||
export type PostWorkflowGenerateSuggestionsResponse
|
||||
= PostWorkflowGenerateSuggestionsResponses[keyof PostWorkflowGenerateSuggestionsResponses]
|
||||
|
||||
@@ -7,6 +7,21 @@ import * as z from 'zod'
|
||||
*/
|
||||
export const zGeneratorResponse = z.unknown()
|
||||
|
||||
/**
|
||||
* WorkflowInstructionSuggestionsPayload
|
||||
*
|
||||
* Payload for the workflow-generator instruction-suggestions endpoint.
|
||||
*
|
||||
* Runs before the user picks a model, so the suggestions come from the
|
||||
* tenant's default model. The underlying generator never raises — an empty
|
||||
* ``suggestions`` list is a valid 200 (soft-fail).
|
||||
*/
|
||||
export const zWorkflowInstructionSuggestionsPayload = z.object({
|
||||
count: z.int().gte(1).lte(6).optional().default(4),
|
||||
language: z.string().nullish(),
|
||||
mode: z.enum(['advanced-chat', 'workflow']),
|
||||
})
|
||||
|
||||
/**
|
||||
* LLMMode
|
||||
*
|
||||
@@ -37,7 +52,7 @@ export const zWorkflowGeneratePayload = z.object({
|
||||
current_graph: z.record(z.string(), z.unknown()).nullish(),
|
||||
ideal_output: z.string().optional().default(''),
|
||||
instruction: z.string(),
|
||||
mode: z.enum(['advanced-chat', 'workflow']),
|
||||
mode: z.enum(['advanced-chat', 'auto', 'workflow']),
|
||||
model_config: zModelConfig,
|
||||
})
|
||||
|
||||
@@ -47,3 +62,17 @@ export const zPostWorkflowGenerateBody = zWorkflowGeneratePayload
|
||||
* Workflow graph generated successfully
|
||||
*/
|
||||
export const zPostWorkflowGenerateResponse = zGeneratorResponse
|
||||
|
||||
export const zPostWorkflowGenerateStreamBody = zWorkflowGeneratePayload
|
||||
|
||||
/**
|
||||
* Server-Sent Events stream of plan/result events
|
||||
*/
|
||||
export const zPostWorkflowGenerateStreamResponse = z.record(z.string(), z.unknown())
|
||||
|
||||
export const zPostWorkflowGenerateSuggestionsBody = zWorkflowInstructionSuggestionsPayload
|
||||
|
||||
/**
|
||||
* Suggestions generated successfully
|
||||
*/
|
||||
export const zPostWorkflowGenerateSuggestionsResponse = zGeneratorResponse
|
||||
|
||||
Reference in New Issue
Block a user