Skip to content

[feat] Unify async DKG Publisher setup, management, and runtime fixes#43

Open
Jurij89 wants to merge 10 commits intofix/publisher-plugin-error-messagefrom
feat/publisher-consolidation
Open

[feat] Unify async DKG Publisher setup, management, and runtime fixes#43
Jurij89 wants to merge 10 commits intofix/publisher-plugin-error-messagefrom
feat/publisher-consolidation

Conversation

@Jurij89
Copy link
Contributor

@Jurij89 Jurij89 commented Mar 5, 2026

Summary

  • Unified async publishing setup in Agent
    The main Agent setup flow now optionally enables the DKG Publisher plugin (recommended path), reuses Engine-provided MySQL credentials, applies sane MySQL/Redis defaults, and avoids duplicate Publisher setup questions.

  • Publisher runtime gating + single env source
    Publisher is loaded conditionally via ASYNC_PUBLISHING_ENABLED=true, with consolidated config sourced from apps/agent/.env (legacy .env.publisher fallback remains for compatibility where relevant).

  • Publisher management command (post-setup)
    Added a dedicated script:publisher management flow in Agent for updating async publishing config, managing wallets, and running fresh setup/reset behavior.

  • MCP tool clarity + publish input improvements
    Publisher MCP descriptions were clarified to avoid sync/async ambiguity with Essentials. knowledge-asset-publish now uses canonical publishOptions input (privacy, priority, epochs, maxAttempts) and defaults privacy to private if omitted.

  • Publisher runtime stability fixes
    Fixed ESM import/runtime issues by switching Bull Board adapter import to @bull-board/api/bullMQAdapter.js and enabling tsup --shims for Publisher build/dev scripts.

  • Legacy setup cleanup
    Removed the old packages/plugin-dkg-publisher/setup.js path and related script references so Agent setup/management is the single supported setup surface.

  • Additional consistency updates
    Updated document-to-markdown endpoint to /api/document-to-markdown and set Publisher default epochs to 12 when not explicitly provided.

Files changed

File What
apps/agent/src/server/scripts/setup.ts Unified setup flow for async publishing enablement, defaults, and provisioning behavior
apps/agent/src/server/scripts/publisher.ts New Publisher management command (update config/manage wallets/fresh setup)
apps/agent/src/server/setupPublisher.ts Shared setup/management helpers for Publisher DB/config/wallet workflows
apps/agent/src/server/index.ts Conditional Publisher plugin loading via ASYNC_PUBLISHING_ENABLED
packages/plugin-dkg-publisher/src/config.ts Consolidated runtime config resolution and env fallback logic
packages/plugin-dkg-publisher/src/index.ts Publisher plugin startup/runtime behavior aligned with consolidated config
packages/plugin-dkg-publisher/src/mcp/tools.ts Async MCP description clarity + canonical publishOptions support
packages/plugin-dkg-publisher/src/services/QueueService.ts ESM-safe Bull Board adapter import (bullMQAdapter.js)
packages/plugin-dkg-publisher/src/services/DkgService.ts Publisher DKG client/runtime config alignment (including optional custom RPC flow)
packages/plugin-dkg-publisher/src/services/AssetService.ts Default publish epochs updated to 12
packages/plugin-dkg-publisher/src/database/schema.ts Schema default epochs updated to 12
packages/plugin-dkg-publisher/package.json Enabled tsup --shims for ESM/CJS runtime compatibility
packages/plugin-dkg-publisher/setup.js Removed legacy Publisher setup entrypoint
packages/plugin-dkg-essentials/src/plugins/dkg-tools.ts Clarified sync publish tool semantics and retrieval API exposure adjustments
packages/plugin-dkg-essentials/src/plugins/document-to-markdown/index.ts Route path updated to /api/document-to-markdown

Test plan

  • Run cd apps/agent && npm run script:setup and verify async publishing opt-in prompt and consolidated flow
  • Verify Engine password reuse path works and no duplicate Publisher setup questions appear
  • Verify Publisher is loaded only when ASYNC_PUBLISHING_ENABLED=true
  • Run cd apps/agent && npm run script:publisher and validate:
  • Update config mode
  • Wallet management mode
  • Fresh setup/reset mode
  • Call Publisher MCP knowledge-asset-publish with publishOptions and verify queuing succeeds
  • Verify knowledge-asset-publish defaults to privacy=private when omitted
  • Verify default epochs are 12 when publishOptions.epochs is not provided
  • Verify Publisher startup no longer fails on:
  • missing bullMQAdapter ESM import suffix
  • __dirname in ESM runtime
  • Verify /api/document-to-markdown works end-to-end and old non-/api path is not used in clients/tests
  • Verify migration/bootstrap behavior remains automatic on Publisher initialization

Jurij Skornik added 9 commits March 4, 2026 15:30
Introduce script:publisher for DKG Publisher plugin config updates, wallet management, and fresh setup reset.

Unify setup messaging around async publishing + DKG Publisher plugin and add helper/unit-test coverage for env/config handling.
…publishOptions input

Align Publisher vs Essentials tool descriptions to reduce sync/async ambiguity.

Expand knowledge-asset-publish controls via publishOptions (privacy/priority/epochs/maxAttempts) without retrieval-tool behavior changes.
Delete packages/plugin-dkg-publisher/setup.js and remove setup entrypoints from plugin package scripts.

Keep Agent-owned setup/management as the only supported flow and update legacy bootstrap wording.
Use @bull-board/api/bullMQAdapter.js so async publisher loads under ESM.

Align document-to-markdown REST endpoint to /api/document-to-markdown for route consistency.
Add --shims to publisher dev/build scripts so __dirname is defined in dist/*.mjs.

Prevents __dirname runtime crashes when async publisher is loaded via ESM imports.
Set runtime default epochs to 12 when publishOptions.epochs is not provided.

Align assets table schema default for epochs to 12 for consistency.
@Jurij89 Jurij89 changed the title [feat] Unify Agent setup + DKG Publisher async runtime and management [feat] Unify async DKG Publisher setup, management, and runtime fixes Mar 5, 2026
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds substantial async publisher setup and migrates DKG retrieval/query HTTP routes into plugin-dkg-essentials, but it introduces API compatibility blockers. The MCP publish tool contract now drops legacy top-level publish controls, and the HTTP API changes remove/alter previously accepted request shapes without a migration path. Maintainability in touched setup code also worsens due to a new multi-responsibility 500+ line module.

})
.optional(),
privacy: z.enum(["private", "public"]).optional(),
publishOptions: z
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Moving publish controls under publishOptions without a backward-compatible alias breaks existing MCP clients that still send top-level privacy/priority/epochs/maxAttempts; those inputs are now ignored and can silently change behavior (e.g., defaulting to private). Accept legacy fields (or fail fast with a clear validation error) before applying defaults.

body: z.object({
query: z.string().min(1, "Query cannot be empty"),
queryType: z
.enum(["SELECT", "CONSTRUCT"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Restricting queryType to SELECT | CONSTRUCT drops ASK/DESCRIBE support from the previous /api/dkg/query contract, so existing clients now get 400s. Keep prior query types for compatibility or version this endpoint and document migration.

);

api.get(
"/api/dkg/get",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Introducing /api/dkg/get without preserving the previous retrieval route (/api/dkg/assets?ual=...) is a breaking HTTP API change for existing consumers. Add a deprecated compatibility alias returning the same response shape or version the API.

@@ -0,0 +1,553 @@
import path from "path";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Issue: This new file is 500+ lines and mixes env parsing, provisioning, wallet administration, and reset logic, which increases coupling and violates the repo’s DoD guidance for file size/scope. Split it into focused modules (env/config, DB provisioning, wallet operations) and keep this entrypoint orchestration-only.

…te file

Expose sync publish over HTTP with the same create logic as dkg-create MCP (including blob id support).

Remove accidentally committed apps/agent/original_dkg_node file and add API coverage tests.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes substantial setup/runtime improvements for async publishing, but it introduces multiple API-contract regressions that are likely to break existing clients. The largest issues are endpoint path changes without compatibility aliases and MCP/HTTP schema narrowing that removes previously accepted inputs. There is also a status-code correctness issue where user-input errors are returned as 500s. Maintainability in touched areas is mixed: configuration centralization improved, but contract drift across plugins worsened due unversioned interface changes.

})
.optional(),
privacy: z.enum(["private", "public"]).optional(),
publishOptions: z
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This changes the knowledge-asset-publish input contract from top-level privacy/priority/epochs/maxAttempts to nested publishOptions, which breaks existing MCP callers. Keep backward compatibility by accepting both shapes (old + new) and mapping old fields into publishOptions with deprecation messaging.

// REST endpoint for document-to-markdown conversion
api.post(
"/document-to-markdown",
"/api/document-to-markdown",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Renaming the route to /api/document-to-markdown removes the previous /document-to-markdown path with no compatibility alias, which is an API breaking change for existing clients. Add a backward-compatible alias route (or versioned migration) before removing the old path.

body: z.object({
query: z.string().min(1, "Query cannot be empty"),
queryType: z
.enum(["SELECT", "CONSTRUCT"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Restricting queryType to SELECT | CONSTRUCT is a breaking change for callers that previously used ASK/DESCRIBE on /api/dkg/query. Preserve prior accepted values (or introduce a versioned endpoint) to avoid contract breakage.

);

api.get(
"/api/dkg/get",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: Introducing GET /api/dkg/get while removing the prior GET /api/dkg/assets endpoint breaks existing HTTP consumers that query assets by UAL. Add a compatibility handler for the old path (or keep both paths during migration).

} catch (error) {
const errorMessage =
error instanceof Error ? error.message : String(error);
return res.status(500).json({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Bug: This catch-all returns 500 for input-originated errors (e.g., invalid/missing blob id from resolveJsonLdInput), which misclassifies client errors as server failures. Map validation/input failures to 4xx (400/404) and reserve 500 for unexpected internal errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant