Commit b3aa49b
authored
feat(n8n): clarification roundtrip route + types (#7316)
Closes the half-built clarification loop on the host side. Previously
the plugin populated _meta.requiresClarification, the LLM was told to
emit it, but the host route ignored it and the UI never rendered it.
POST /api/n8n/workflows/generate now inspects the draft for
clarifications before deploying. When non-empty, the route
short-circuits and returns:
{
status: "needs_clarification",
draft,
clarifications: ClarificationRequest[],
catalog: TargetGroup[],
}
where `catalog` is a snapshot of the connector-target-catalog scoped
to the platforms the clarifications reference. The draft itself is
returned verbatim so the client can post it back unchanged.
POST /api/n8n/workflows/resolve-clarification (new) accepts
{ draft, resolutions: { paramPath, value }[] }. It applies the
resolutions to the draft via a small recursive dot-path setter,
prunes the now-resolved structured clarifications from
_meta.requiresClarification, and either deploys (when the list is
empty) or returns the next pending clarification + updated draft so
the UI can chain a second picker (server-then-channel etc.).
The path setter (n8n-clarification.ts) supports dot identifiers,
bracketed string keys (`nodes["Discord Send"].parameters.channelId`),
and numeric indices (`nodes[0].parameters.guildId`). It rejects
malformed paths and never overwrites a non-object intermediate. The
setter is intentionally tiny — about 30 lines — to avoid pulling
lodash into app-core for one feature.
Folds in P6: client-types-chat.ts adds N8nClarificationRequest,
N8nClarificationTargetGroup, N8nWorkflowNeedsClarificationResponse,
N8nWorkflowResolveClarificationRequest, the type-guard
isNeedsClarificationResponse, and widens
N8nWorkflowGenerateResponse to the three-arm union. The clarification
types mirror the plugin's ClarificationRequest shape but live in the
host so client code does not import from plugin internals.
AutomationsView gets a one-line narrowing branch on
isNeedsClarificationResponse so the wider union typechecks cleanly;
the actual UI render lands in the next PR in the stack (P5).
Tests cover both the helpers and the route handlers:
- n8n-clarification.test.ts: 28 cases for coerceClarifications,
parseParamPath, setByDotPath, applyResolutions,
pruneResolvedClarifications, buildCatalogSnapshot.
- n8n-routes.test.ts: appended needs_clarification short-circuit,
legacy-string clarification coercion, missing-catalog fallback,
resolve happy path, empty-resolutions rejection, malformed-path
rejection (with paramPath echo), chained-pending-clarification
return path, and missing-draft rejection.
Note: the n8n-routes.test.ts file fails to load locally due to a
pre-existing missing package (@elizaos/plugin-browser-bridge) in the
agent runtime import chain — same failure mode is observable on the
unmodified file. The new route cases run cleanly once that dep is
restored.1 parent e4f02fa commit b3aa49b
5 files changed
Lines changed: 1271 additions & 36 deletions
File tree
- packages/app-core/src/api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
462 | 526 | | |
463 | 527 | | |
464 | | - | |
| 528 | + | |
| 529 | + | |
465 | 530 | | |
466 | 531 | | |
467 | 532 | | |
| |||
473 | 538 | | |
474 | 539 | | |
475 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
476 | 554 | | |
477 | 555 | | |
478 | 556 | | |
| |||
0 commit comments