Skip to content

[ISSUE #14848] Add download Prompt version as Markdown feature#15057

Merged
KomachiSion merged 1 commit into
alibaba:developfrom
grllll:feature/issue-14848-prompt-md-download
May 9, 2026
Merged

[ISSUE #14848] Add download Prompt version as Markdown feature#15057
KomachiSion merged 1 commit into
alibaba:developfrom
grllll:feature/issue-14848-prompt-md-download

Conversation

@grllll

@grllll grllll commented May 7, 2026

Copy link
Copy Markdown
Contributor

What is the purpose of the change

Fix #14848

Currently the Nacos console only supports viewing the content of a Prompt version inline, but there is no way for users to export or persist a Prompt version locally. This PR adds a feature that allows users to download any version of a Prompt as a Markdown file from the console, and tracks the download counts of each prompt / prompt version so that users can observe the popularity of prompts. The implementation is fully aligned with the existing Skill download feature for consistency.

Brief changelog

Backend

  • Add PromptMarkdownBuilder utility to render a PromptVersionInfo (including metadata, variables, template, and examples) into a well-formatted Markdown document.
  • Add a new Console API GET /v3/console/ai/prompt/version/markdown in ConsolePromptController, returning the markdown content with Content-Disposition: attachment so that browsers trigger a file download.
  • Add the full handler chain for the new API: PromptHandler / PromptInnerHandler / PromptRemoteHandler / PromptNoopHandler / PromptProxy.
  • Add downloadPromptVersion in PromptOperationService / PromptOperationServiceImpl, which fetches the version detail and publishes a PromptDownloadEvent.
  • Add PromptDownloadEvent (new event) and PromptDownloadCountManager (new SmartSubscriber) to accumulate download counts in memory and flush them to DB every 10 seconds using atomic SQL (download_count = download_count + N), keeping the counting logic isolated from the existing SkillDownloadCountManager.
  • Add downloadCount field to PromptMetaSummary and PromptVersionSummary, and populate it in listPrompts / listPromptVersions / getPromptDetail.

Frontend (console-ui-next)

  • Add downloadPromptVersionMarkdown API call in src/api/prompt.ts.
  • In the Prompt detail page, add a download button using the existing CliCommandCard component on the right sidebar (aligned with Skill detail page).
  • Display the total download count and per-version download count as InfoCell entries inside the Basic Info card.
  • Update TypeScript types in types/prompt.ts (downloadCount: number | null).
  • Add i18n keys prompt.downloadCount, prompt.downloads, prompt.versionDownloads in both en-US.json and zh-CN.json.

Verifying this change

Unit tests

  • Add PromptMarkdownBuilderTest covering header/metadata rendering, variables section, template section, examples section, and null/empty edge cases.

Manual tests (with MySQL datasource, standalone mode)

  1. Open the Nacos console and enter the Prompt detail page.
  2. Click the download icon inside the CLI Command card on the right sidebar — a .md file named {promptKey}-{version}.md is downloaded.
  3. Open the downloaded file and verify the Markdown content contains the prompt metadata, variables, template, and examples.
  4. Refresh the page (wait > 10s to let the counter flush to DB). Verify that the Downloads and Version Downloads values in the Basic Info card increase correctly.
  5. Download different versions of the same prompt, and confirm that only the corresponding version's counter increments while the total count increments as expected.

Checks

  • mvn -B clean package apache-rat:check spotbugs:check -DskipTests — passed
  • mvn clean install -DskipITs — passed

@CLAassistant

CLAassistant commented May 7, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

⚠️ Commit Author Verification Failed

The following commits have author emails not linked to any GitHub account.
This will prevent CLA signing and block your PR from being merged.

Commit Author Email
541f7e8 Linyu gengruilin.grl@alibaba-inc.com

How to fix:

  1. Add your commit email to your GitHub account: https://github.com/settings/emails
  2. Or update your local git config to use an email already linked to GitHub:
    git config user.name "Your GitHub Username"
    git config user.email "your-github-email@example.com"
    
  3. Amend your commits and force-push:
    git rebase -i HEAD~1 # mark commits as "edit" and amend author
    git push --force-with-lease
    

This check will re-run automatically after you push.

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Thanks for your this PR. 🙏
Please check again for your PR changes whether contains any usage/api/configuration change such as Add new API , Add new configuration, Change default value of configuration.
If so, please add or update documents(markdown type) in docs/next/ for repository nacos-group/nacos-group.github.io


感谢您提交的PR。 🙏
请再次查看您的PR内容,确认是否包含任何使用方式/API/配置参数的变更,如:新增API新增配置参数修改默认配置等操作。
如果是,请确保在提交之前,在仓库nacos-group/nacos-group.github.io中的docs/next/目录下添加或更新文档(markdown格式)。

@grllll
grllll force-pushed the feature/issue-14848-prompt-md-download branch from 541f7e8 to 523a028 Compare May 7, 2026 02:06
@KomachiSion

Copy link
Copy Markdown
Collaborator

@Sunrisea Please help to review

@Sunrisea

Sunrisea commented May 7, 2026

Copy link
Copy Markdown
Contributor

LGTM

@grllll
grllll force-pushed the feature/issue-14848-prompt-md-download branch from 523a028 to e9b4bbc Compare May 8, 2026 02:15
@shiyiyue1102

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. The main feature direction looks aligned with #14848, and the Markdown builder already has focused unit coverage.

Before moving this forward, could you add coverage for the new download-count path as well? In particular, PromptDownloadCountManager is the core state-changing part of this PR, but the current patch coverage shows it is not covered. It would be helpful to lock down event accumulation and the DB increment/flush behavior.

One more thing to confirm: PromptRemoteHandler.downloadPromptVersion() currently delegates to getVersionDetail(), while the download event is published by PromptOperationServiceImpl.downloadPromptVersion(). Please confirm whether download counts are expected to increase in remote console mode, or add/update the implementation and tests if needed.

Also, the linked issue discussion mentioned promptKey_version.md, while this PR currently uses promptKey-version.md. Please confirm the intended filename format.


感谢贡献。这个功能方向和 #14848 是对齐的,Markdown builder 也已经有比较聚焦的单测覆盖。

继续推进前,建议再补一下新增下载量统计链路的测试。尤其是 PromptDownloadCountManager 是这个 PR 里真正会改变状态的核心逻辑,但当前 patch coverage 显示这部分还没有覆盖。建议把事件累计、DB 增量 flush 行为锁定下来。

另外有一点需要确认:PromptRemoteHandler.downloadPromptVersion() 当前只是委托到 getVersionDetail(),而下载事件是在 PromptOperationServiceImpl.downloadPromptVersion() 中发布的。请确认 remote console 模式下下载量是否预期会增长;如果需要增长,请补充对应实现和测试。

还有一个小点:关联 issue 里讨论的文件名是 promptKey_version.md,当前 PR 使用的是 promptKey-version.md。请确认最终希望采用哪种文件名格式。

KomachiSion
KomachiSion previously approved these changes May 8, 2026
@KomachiSion

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. The main feature direction looks aligned with #14848, and the Markdown builder already has focused unit coverage.

Before moving this forward, could you add coverage for the new download-count path as well? In particular, PromptDownloadCountManager is the core state-changing part of this PR, but the current patch coverage shows it is not covered. It would be helpful to lock down event accumulation and the DB increment/flush behavior.

One more thing to confirm: PromptRemoteHandler.downloadPromptVersion() currently delegates to getVersionDetail(), while the download event is published by PromptOperationServiceImpl.downloadPromptVersion(). Please confirm whether download counts are expected to increase in remote console mode, or add/update the implementation and tests if needed.

Also, the linked issue discussion mentioned promptKey_version.md, while this PR currently uses promptKey-version.md. Please confirm the intended filename format.

感谢贡献。这个功能方向和 #14848 是对齐的,Markdown builder 也已经有比较聚焦的单测覆盖。

继续推进前,建议再补一下新增下载量统计链路的测试。尤其是 PromptDownloadCountManager 是这个 PR 里真正会改变状态的核心逻辑,但当前 patch coverage 显示这部分还没有覆盖。建议把事件累计、DB 增量 flush 行为锁定下来。

另外有一点需要确认:PromptRemoteHandler.downloadPromptVersion() 当前只是委托到 getVersionDetail(),而下载事件是在 PromptOperationServiceImpl.downloadPromptVersion() 中发布的。请确认 remote console 模式下下载量是否预期会增长;如果需要增长,请补充对应实现和测试。

还有一个小点:关联 issue 里讨论的文件名是 promptKey_version.md,当前 PR 使用的是 promptKey-version.md。请确认最终希望采用哪种文件名格式。

@grllll 请帮忙确认一下上述review的问题。

@grllll
grllll force-pushed the feature/issue-14848-prompt-md-download branch 2 times, most recently from 3a6f883 to f24d993 Compare May 9, 2026 03:52
@grllll

grllll commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution. The main feature direction looks aligned with #14848, and the Markdown builder already has focused unit coverage.
Before moving this forward, could you add coverage for the new download-count path as well? In particular, PromptDownloadCountManager is the core state-changing part of this PR, but the current patch coverage shows it is not covered. It would be helpful to lock down event accumulation and the DB increment/flush behavior.
One more thing to confirm: PromptRemoteHandler.downloadPromptVersion() currently delegates to getVersionDetail(), while the download event is published by PromptOperationServiceImpl.downloadPromptVersion(). Please confirm whether download counts are expected to increase in remote console mode, or add/update the implementation and tests if needed.
Also, the linked issue discussion mentioned promptKey_version.md, while this PR currently uses promptKey-version.md. Please confirm the intended filename format.
感谢贡献。这个功能方向和 #14848 是对齐的,Markdown builder 也已经有比较聚焦的单测覆盖。
继续推进前,建议再补一下新增下载量统计链路的测试。尤其是 PromptDownloadCountManager 是这个 PR 里真正会改变状态的核心逻辑,但当前 patch coverage 显示这部分还没有覆盖。建议把事件累计、DB 增量 flush 行为锁定下来。
另外有一点需要确认:PromptRemoteHandler.downloadPromptVersion() 当前只是委托到 getVersionDetail(),而下载事件是在 PromptOperationServiceImpl.downloadPromptVersion() 中发布的。请确认 remote console 模式下下载量是否预期会增长;如果需要增长,请补充对应实现和测试。
还有一个小点:关联 issue 里讨论的文件名是 promptKey_version.md,当前 PR 使用的是 promptKey-version.md。请确认最终希望采用哪种文件名格式。

@grllll 请帮忙确认一下上述review的问题。

Thanks @shiyiyue1102 @KomachiSion! Updated accordingly:

  1. Filename: switched the separator from - to _ as suggested in the issue
    (promptKey_version.md).

  2. Download-count coverage: extended the unit tests to lock down event accumulation,
    scheduled flush, zero-count cleanup, and put-back retry on DB failure.

  3. PromptRemoteHandler delegating to getVersionDetail: intentional, aligned with the
    existing SkillRemoteHandler behavior — maintainer-client doesn't expose a dedicated
    download method yet.

- Add PromptMarkdownBuilder to convert prompt version content to Markdown format
- Add download API endpoint (GET /v3/console/ai/prompt/version/markdown) in ConsolePromptController
- Add PromptDownloadEvent and PromptDownloadCountManager for download counting
- Add downloadCount field to PromptMetaSummary and PromptVersionSummary
- Frontend: add download button in CliCommandCard and download count display in Basic Info Card
- Add unit tests for PromptMarkdownBuilder, PromptDownloadEvent, PromptDownloadCountManager, ConsolePromptController and PromptOperationServiceImpl#downloadPromptVersion

Assisted-by: Qoder
@grllll
grllll force-pushed the feature/issue-14848-prompt-md-download branch from f24d993 to f1362c4 Compare May 9, 2026 06:57
@KomachiSion
KomachiSion merged commit df256a0 into alibaba:develop May 9, 2026
4 checks passed
@KomachiSion KomachiSion added this to the 3.2.2 milestone May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.2.1版本,提示词可以新增下载功能吗,下载一个md文档

6 participants