[PR #276] [MERGED] feat(generate): add dry-run as flexible endpoint for extension creators #4542

Closed
opened 2026-10-22 04:08:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/276
Author: @Xelvanis
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @SpicyMarinara

Base: main ← Head: feature/dryRun


📝 Commits (2)

  • bee4ba1 feat(generate): add dry-run endpoint for extension prompt inspection
  • 417498d Merge branch 'main' into feature/dryRun

📊 Changes

3 files changed (+1430 additions, -0 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/routes/generate.routes.ts (+2 -0)
➕ packages/server/src/routes/generate/dry-run-route.ts (+1427 -0)

📄 Description

Linked issue

Screenshot 2026-04-28 172723

Resolves #280 / lack of extension suitable endpoint so I can make my Silent Impersonate button a reality.

Why this change

Extensions currently have no way to send a generation request, or inspect/preview the generation pipeline, without side effects (e.g. triggering agents, firing webhooks, persisting/appending messages into chat history). Extensions are currently limited in what endpoints they can call to run requests, with sidecar/local being the only option for side effect free generation; this means API connections are rendered inaccessible for this purpose.

This adds a stopgap non-persisting endpoint that runs the full prompt assembly and LLM generation pipeline without any durable side effects — giving extensions a clean "what-if" surface until a proper extension API is designed.

What changed

  • New file: packages/server/src/routes/generate/dry-run-route.ts — self-contained route registration with two endpoints:
    • POST /api/generate/dryRun — runs the generation pipeline without side effects
    • POST /api/generate/dryRun/abort — aborts an in-flight dry run by runId
  • Modified: packages/server/src/routes/generate.routes.ts — imports and registers the dry-run route
  • Updated: CHANGELOG.md — entry under [Unreleased] / ### Added

Key capabilities

Feature How to use
Preview a "what if I said this" message POST /dryRun with { chatId, userMessage }
Impersonate the user's next line without appending to chat { chatId, impersonate: true, userMessage?: "direction" }
Inspect the assembled prompt without calling the LLM { ..., returnPrompt: true } → returns { prompt, parameters }
Inject lorebook entries { ..., injectLorebook: true }
Inject game tracker state { ..., injectTrackers: true }
Inject chat summary { ..., injectChatSummary: true }
Override the prompt preset { ..., presetId: "..." } or { ..., presetText: "..." }
Override the connection { ..., connectionId: "..." }
Fine-grained prompt assembly { ..., promptParts: { includePersona, includeCharacters, order: [...], ... } }
SSE streaming { ..., streaming: true }
Abort an in-flight run POST /dryRun/abort with { runId }

What is NOT affected

  • No messages, swipes, generation info, or prompt caches are persisted
  • No agents or tools are resolved or invoked
  • No Discord webhooks fire
  • No existing endpoints are modified

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Verify that I, a human, ticked the above boxes, not the AI
  • pnpm check (TypeScript + ESLint + full build): 0 errors, 0 new warnings
  • No container changes in this PR — Docker/Podman checkbox is N/A
  • No UI changes — this is a server-only API endpoint
  • Logging follows Pino conventions (format specifiers, error-first, no console.* in server code)
  • Route registration follows the same registerXRoute(app) async pattern as registerRetryAgentsRoute
  • Parameter normalization mirrors the main /api/generate route (Claude sampling restrictions, reasoning effort resolution, context fitting)
  • TODO: manual API testing with a running server before merge
    • POST /dryRun with a real chatId returns generated content
    • POST /dryRun with returnPrompt: true returns assembled prompt without calling LLM
    • No messages persisted to the chat after dry run
    • 400 on missing chatId, 404 on nonexistent chat
    • Streaming mode + abort via POST /dryRun/abort; extensions can wire in button that emits abort request and cancels generation, successful in user testing
    • Contemplated what I'm doing with my life on day 3
    • Built JSON file extension extensively testing capabilities of the dryRun endpoint, including presetId + connectionId overrides, full custom prompt assembly with promptParts mode, returnPrompt enabling a UI panel to review prompts before sending, presetText and extensionBlocks to further customize extension prompts, and tested dryRun generation with multiple API connections. Ensured all optional injection flags trigger correct behaviors. (Said example extension can be provided on request)
    • Added temporary logic to handle cases where the last chat message is from assistant instead of user (last user message still wraps with <last_message>, if last assistant message is present, wraps with <last_assistant_message>. User open to alternative suggestions, but this should only apply to edge cases with extensions.)

Docs and release impact

  • CHANGELOG.md updated — entry under [Unreleased] / ### Added
  • No version bump — this targets the next unreleased version
  • No docs changes needed — this is a stopgap extension API; the inline JSDoc on the route handler documents the contract. Stable extension API documentation should be added when that layer is formally designed.

UI evidence (if applicable)

Summary by CodeRabbit

  • New Features
    • Added a dry-run generation endpoint to preview the full generation pipeline without persisting messages or invoking agents/tools/webhooks.
    • Supports impersonation, optional injections (lorebook/trackers/chat summary), preset/connection overrides, and returning the assembled prompt.
    • Offers both non-streaming JSON and SSE streaming responses with abort support and connection cleanup.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/276 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 4/28/2026 **Status:** ✅ Merged **Merged:** 4/28/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `feature/dryRun` --- ### 📝 Commits (2) - [`bee4ba1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bee4ba10e2ba3af70e63aa755d9d02366002d066) feat(generate): add dry-run endpoint for extension prompt inspection - [`417498d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/417498d98b392dfa49c742dd96204c21105f8623) Merge branch 'main' into feature/dryRun ### 📊 Changes **3 files changed** (+1430 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+2 -0) ➕ `packages/server/src/routes/generate/dry-run-route.ts` (+1427 -0) </details> ### 📄 Description ## Linked issue <img width="1105" height="85" alt="Screenshot 2026-04-28 172723" src="https://github.com/user-attachments/assets/d96fe194-ecd1-4473-b2ee-a51b1cf3b4af" /> Resolves #280 / lack of extension suitable endpoint so I can make my Silent Impersonate button a reality. ## Why this change Extensions currently have no way to send a generation request, or inspect/preview the generation pipeline, without side effects (e.g. triggering agents, firing webhooks, persisting/appending messages into chat history). Extensions are currently limited in what endpoints they can call to run requests, with sidecar/local being the only option for side effect free generation; this means API connections are rendered inaccessible for this purpose. This adds a **stopgap** non-persisting endpoint that runs the full prompt assembly and LLM generation pipeline without any durable side effects — giving extensions a clean "what-if" surface until a proper extension API is designed. ## What changed - **New file:** `packages/server/src/routes/generate/dry-run-route.ts` — self-contained route registration with two endpoints: - `POST /api/generate/dryRun` — runs the generation pipeline without side effects - `POST /api/generate/dryRun/abort` — aborts an in-flight dry run by `runId` - **Modified:** `packages/server/src/routes/generate.routes.ts` — imports and registers the dry-run route - **Updated:** `CHANGELOG.md` — entry under `[Unreleased] / ### Added` ### Key capabilities | Feature | How to use | |---|---| | Preview a "what if I said this" message | `POST /dryRun` with `{ chatId, userMessage }` | | Impersonate the user's next line without appending to chat | `{ chatId, impersonate: true, userMessage?: "direction" }` | | Inspect the assembled prompt without calling the LLM | `{ ..., returnPrompt: true }` → returns `{ prompt, parameters }` | | Inject lorebook entries | `{ ..., injectLorebook: true }` | | Inject game tracker state | `{ ..., injectTrackers: true }` | | Inject chat summary | `{ ..., injectChatSummary: true }` | | Override the prompt preset | `{ ..., presetId: "..." }` or `{ ..., presetText: "..." }` | | Override the connection | `{ ..., connectionId: "..." }` | | Fine-grained prompt assembly | `{ ..., promptParts: { includePersona, includeCharacters, order: [...], ... } }` | | SSE streaming | `{ ..., streaming: true }` | | Abort an in-flight run | `POST /dryRun/abort` with `{ runId }` | ### What is NOT affected - No messages, swipes, generation info, or prompt caches are persisted - No agents or tools are resolved or invoked - No Discord webhooks fire - No existing endpoints are modified ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [X] Ran the app, clicked through the changes manually - [X] Checked edge cases (empty states, error paths) - [X] Above manual verification completed (describe below) - [X] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Verify that I, a human, ticked the above boxes, not the AI - `pnpm check` (TypeScript + ESLint + full build): 0 errors, 0 new warnings - No container changes in this PR — Docker/Podman checkbox is N/A - No UI changes — this is a server-only API endpoint - Logging follows Pino conventions (format specifiers, error-first, no `console.*` in server code) - Route registration follows the same `registerXRoute(app)` async pattern as `registerRetryAgentsRoute` - Parameter normalization mirrors the main `/api/generate` route (Claude sampling restrictions, reasoning effort resolution, context fitting) - TODO: manual API testing with a running server before merge - [X] `POST /dryRun` with a real `chatId` returns generated content - [X] `POST /dryRun` with `returnPrompt: true` returns assembled prompt without calling LLM - [X] No messages persisted to the chat after dry run - [X] `400` on missing `chatId`, `404` on nonexistent chat - [X] Streaming mode + abort via `POST /dryRun/abort`; extensions can wire in button that emits abort request and cancels generation, successful in user testing - [X] Contemplated what I'm doing with my life on day 3 - [X] Built JSON file extension extensively testing capabilities of the dryRun endpoint, including presetId + connectionId overrides, full custom prompt assembly with promptParts mode, returnPrompt enabling a UI panel to review prompts before sending, presetText and extensionBlocks to further customize extension prompts, and tested dryRun generation with multiple API connections. Ensured all optional injection flags trigger correct behaviors. (Said example extension can be provided on request) - [X] Added temporary logic to handle cases where the last chat message is from assistant instead of user (last user message still wraps with <last_message>, if last assistant message is present, wraps with <last_assistant_message>. User open to alternative suggestions, but this should only apply to edge cases with extensions.) ## Docs and release impact - **CHANGELOG.md updated** — entry under `[Unreleased] / ### Added` - **No version bump** — this targets the next unreleased version - **No docs changes needed** — this is a stopgap extension API; the inline JSDoc on the route handler documents the contract. Stable extension API documentation should be added when that layer is formally designed. ## UI evidence (if applicable) <!-- No UI changes — server-only endpoint --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a dry-run generation endpoint to preview the full generation pipeline without persisting messages or invoking agents/tools/webhooks. * Supports impersonation, optional injections (lorebook/trackers/chat summary), preset/connection overrides, and returning the assembled prompt. * Offers both non-streaming JSON and SSE streaming responses with abort support and connection cleanup. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:34 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4542
No description provided.