Skip to content

feat(workflow-generator): enhance the AI auto-creation flow end-to-end#38175

Open
crazywoola wants to merge 6 commits into
mainfrom
feat/enhance-dsl-generation
Open

feat(workflow-generator): enhance the AI auto-creation flow end-to-end#38175
crazywoola wants to merge 6 commits into
mainfrom
feat/enhance-dsl-generation

Conversation

@crazywoola

Copy link
Copy Markdown
Member

Summary

Enhances the AI auto-creation flow — the ⌘K/create and /refine workflow/chatflow generator (behind ENABLE_FEATURE_PREVIEW) — end-to-end, implementing the stage 1–5 program tracked in #38174. Also folds in the two concrete refinements that started this work: dropping the low-value "Ideal output" field and replacing the static example chips with AI-generated, workspace-grounded suggestions.

Closes #38174 (item 3.1 intentionally dropped; see Deferred below).

What changed

Backend (api/)

  • POST /workflow-generate/suggestions — returns a few short, buildable example instructions for the generator's "ideas" chips, grounded in the tenant's real knowledge bases + installed tools. Runs on the tenant default model (works before the user picks one) and soft-fails to { "suggestions": [] } so the UI silently falls back.
  • POST /workflow-generate/stream (SSE) — plan-first generation: emits a plan event the moment the planner finishes, then a result event after the builder + validation. Reuses the existing planner/builder/validate stages through one shared generator, so the streamed result provably equals the blocking /workflow-generate return (parity test included).
  • mode: "auto" on both generate endpoints — a tiny classifier resolves Workflow vs Chatflow before planning; the concrete mode is echoed back as mode and never leaks "auto".
  • The existing /workflow-generate is unchanged except its response now also carries mode.

Frontend (web/)

Stage 1 — entry & input

  • Remove the "Ideal output" field (optional backend param; the shared component stays for the prompt generator).
  • AI suggestion chips replace the static list — fetched on open (session-cached per mode), with a ↻ refresh and a silent static fallback when generation is unavailable.
  • ⌘/Ctrl+Enter to generate and autofocus on the instruction box.
  • Palette inline capture: /create workflow summarize a URL pre-fills the modal; "Auto" submenu option opens auto-mode.

Stage 2 — generation

  • Plan-first streaming view: "Planning…" → the real node outline → the graph, replacing the guessed phase timer. Uses an isolated sseGeneratorPost consumer that reuses the cookie-auth/CSRF/abort setup without touching the shared handleStream. Falls back to the single-shot endpoint if the stream can't start.

Stage 3 — review (3.1 dropped)

  • 3.2 planner metadata header (icon + app name).
  • 3.4 / 3.5 an actionable error panel: localized message + affected node, with Regenerate and (for UNKNOWN_TOOL) Install tools.

Stage 4 — apply

  • 4.1 /refine diff summary (added / removed / changed) computed client-side from the base vs. generated graph.
  • 4.2 post-apply nudge toward ⌘K → /refine.

Stage 5 — history

  • 5.1 last-instruction resume across opens (persisted), so reopening isn't a blank box.

i18n

New keys added across all 23 locales (workflow.json + app.json); en-US authoritative, zh-Hans/zh-Hant translated, others English pending the translate bot.

Tests

  • Backend: 112 generator unit tests pass (suggestions method + route, streaming event sequence + parity, auto-mode resolution).
  • Frontend: 53 pass — new coverage for the suggestions component (fetch → fallback → refresh → select), the graph-diff util, and the updated /create command (inline capture + auto option + threading).
  • type-check clean; eslint --quiet (CI posture) reports no new errors.

Deferred (follow-ups, tracked in #38174)

  • 3.1 inspectable per-node preview — dropped per request.
  • 1.1 "✨ Generate with AI" entry in the Create-App dialog — while the feature is behind ENABLE_FEATURE_PREVIEW the cmd+k entry suffices; lands with GA.
  • 5.1 full "recent generations" gallery — shipped as last-instruction resume for now.

Notes

  • The suggestions endpoint is one cheap default-model call per session per mode (cached); ↻ is the only extra call. No default model → empty → static fallback (no regression).
  • Streaming can't be exercised against a live model in CI; correctness rests on the shared-stage parity test plus the non-streaming fallback.

🤖 Generated with Claude Code

Implements the stage 1–5 program from #38174 (3.1 dropped per request).

Backend (api/)
- New POST /workflow-generate/suggestions: short, workspace-grounded example
  instructions generated on the tenant default model; soft-fails to {suggestions: []}.
- New POST /workflow-generate/stream: SSE plan-first generation that emits the
  planner result (plan) then the built graph (result), reusing the existing
  planner/builder/validate stages — the streamed result provably equals the
  blocking /workflow-generate return.
- mode:"auto" on both generate endpoints; a lightweight classifier resolves the
  concrete mode before planning and it is echoed back as `mode`.

Frontend (web/)
- Remove the low-value "Ideal output" field from the modal.
- Replace the static example chips with AI-generated, workspace-grounded
  suggestions (cached per session per mode, ↻ refresh, silent static fallback).
- Plan-first streaming: show the planner outline as it lands, then the graph
  (replaces the guessed phase timer) via an isolated SSE consumer that reuses
  the existing cookie-auth/CSRF/abort setup without touching handleStream.
- Review stage: planner metadata header (icon + name), an actionable error panel
  (Regenerate / Install tools / affected node), a /refine diff summary, and a
  post-apply nudge toward cmd+k /refine.
- Entry & input: ⌘/Ctrl+Enter to generate, autofocus, palette inline capture
  (`/create workflow <text>`), an "Auto" submenu option, and last-instruction
  resume across opens.

i18n keys added across all 23 locales. New tests cover the suggestions component
(fetch → fallback → refresh), the graph diff util, and the updated /create command.

Refs #38174

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 29, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 51.50% 51.54% +0.05%
Strict coverage 51.01% 51.06% +0.05%
Typed symbols 30,849 30,916 +67
Untyped symbols 29,332 29,342 +10
Modules 2931 2931 0

@github-actions

github-actions Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-06-30 01:34:09.175636287 +0000
+++ /tmp/pyrefly_pr.txt	2026-06-30 01:33:53.273610741 +0000
@@ -5585,6 +5585,10 @@
     --> tests/unit_tests/core/workflow/generator/test_runner.py:2438:16
 ERROR Cannot index into `str` [bad-index]
     --> tests/unit_tests/core/workflow/generator/test_runner.py:2439:16
+ERROR Argument `str` is not assignable to parameter `mode` with type `Literal['advanced-chat', 'workflow']` in function `core.workflow.generator.runner.WorkflowGenerator.generate_workflow_graph_stream` [bad-argument-type]
+    --> tests/unit_tests/core/workflow/generator/test_runner.py:3064:111
+ERROR Argument `str` is not assignable to parameter `mode` with type `Literal['advanced-chat', 'workflow']` in function `core.workflow.generator.runner.WorkflowGenerator.generate_workflow_graph` [bad-argument-type]
+    --> tests/unit_tests/core/workflow/generator/test_runner.py:3066:103
 ERROR Argument `None` is not assignable to parameter `plugin_id` with type `str` in function `_make_plugin_provider` [bad-argument-type]
    --> tests/unit_tests/core/workflow/generator/test_tool_catalogue.py:344:55
 ERROR Default `str` is not assignable to parameter `node_type` with type `BuiltinNodeTypes` [bad-function-definition]

@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.94587% with 109 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.30%. Comparing base (49a92f0) to head (b5a5fb7).

Files with missing lines Patch % Lines
api/core/llm_generator/llm_generator.py 48.93% 44 Missing and 4 partials ⚠️
web/service/base.ts 2.22% 44 Missing ⚠️
web/service/debug.ts 20.00% 8 Missing ⚠️
api/controllers/console/app/generator.py 93.22% 2 Missing and 2 partials ⚠️
...ts/workflow/workflow-generator/example-prompts.tsx 92.85% 3 Missing ⚠️
api/core/workflow/generator/runner.py 93.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #38175      +/-   ##
==========================================
- Coverage   85.32%   85.30%   -0.03%     
==========================================
  Files        4967     4968       +1     
  Lines      258518   258819     +301     
  Branches    49059    49110      +51     
==========================================
+ Hits       220593   220790     +197     
- Misses      33632    33731      +99     
- Partials     4293     4298       +5     
Flag Coverage Δ
api 85.44% <73.65%> (-0.02%) ⬇️
dify-ui 94.93% <ø> (ø)
web 85.01% <62.32%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

autofix-ci Bot and others added 5 commits June 29, 2026 16:38
pyrefly rejected flask.stream_with_context called with a generator
(constrained AnyStr overload — "no-matching-overload"), failing the
Python type-check CI. Switch the streaming endpoint to the repo's
established SSE helper compact_generate_response (which wraps
_stream_with_request_context), so it type-checks and still preserves
request context during iteration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- jsonc/sort-keys (CI TS Common): the new i18n keys were appended at the end;
  re-sort them into ascending order across all locales via eslint --fix.
- knip (CI Web Style): WorkflowGenPlanNode / WorkflowGenPlanInput are only used
  inside debug.ts, so stop exporting them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a render test for GenerationPlan (planning state vs. plan outline +
building state), covering the previously-untested new component and
improving patch coverage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance the AI auto-creation (⌘K /create & /refine) flow end-to-end

1 participant