Skip to content

[Fix] avoid chat prompt injection warning#880

Merged
dingyi222666 merged 2 commits into
v1-devfrom
fix/chatluna-inject-warning
May 26, 2026
Merged

[Fix] avoid chat prompt injection warning#880
dingyi222666 merged 2 commits into
v1-devfrom
fix/chatluna-inject-warning

Conversation

@dingyi222666
Copy link
Copy Markdown
Member

This pr fixes a ChatLuna prompt construction warning by avoiding the helper path that injects prompt dependencies through context.

New Features

None

Bug fixes

  • Construct ChatLunaChatPrompt directly when creating an agent prompt.
  • Pass token counter, send token limit, context manager, and prompt renderer explicitly.

Other Changes

  • Validation: yarn lint-fix completed with no errors. Existing max-len warnings remain in read_chat_message.ts.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e43d3339-1e72-467e-b502-370850e82652

📥 Commits

Reviewing files that changed from the base of the PR and between 5d23e50 and 083c189.

⛔ Files ignored due to path filters (27)
  • packages/adapter-azure-openai/package.json is excluded by !**/*.json
  • packages/adapter-claude/package.json is excluded by !**/*.json
  • packages/adapter-deepseek/package.json is excluded by !**/*.json
  • packages/adapter-dify/package.json is excluded by !**/*.json
  • packages/adapter-doubao/package.json is excluded by !**/*.json
  • packages/adapter-gemini/package.json is excluded by !**/*.json
  • packages/adapter-hunyuan/package.json is excluded by !**/*.json
  • packages/adapter-ollama/package.json is excluded by !**/*.json
  • packages/adapter-openai-like/package.json is excluded by !**/*.json
  • packages/adapter-openai/package.json is excluded by !**/*.json
  • packages/adapter-qwen/package.json is excluded by !**/*.json
  • packages/adapter-rwkv/package.json is excluded by !**/*.json
  • packages/adapter-spark/package.json is excluded by !**/*.json
  • packages/adapter-wenxin/package.json is excluded by !**/*.json
  • packages/adapter-zhipu/package.json is excluded by !**/*.json
  • packages/core/package.json is excluded by !**/*.json
  • packages/extension-agent/package.json is excluded by !**/*.json
  • packages/extension-long-memory/package.json is excluded by !**/*.json
  • packages/extension-tools/package.json is excluded by !**/*.json
  • packages/extension-usage/package.json is excluded by !**/*.json
  • packages/extension-variable/package.json is excluded by !**/*.json
  • packages/renderer-image/package.json is excluded by !**/*.json
  • packages/service-embeddings/package.json is excluded by !**/*.json
  • packages/service-multimodal/package.json is excluded by !**/*.json
  • packages/service-search/package.json is excluded by !**/*.json
  • packages/service-vector-store/package.json is excluded by !**/*.json
  • packages/shared-adapter/package.json is excluded by !**/*.json
📒 Files selected for processing (1)
  • packages/core/src/services/chat.ts

高级概览

在 ChatLunaService 中,默认聊天提示的构建实现从函数调用改为类实例化,通过注入模型令牌处理方法、上下文管理器和渲染服务来增强提示配置。

变更说明

提示构建实现迁移

层 / 文件 说明
ChatLunaChatPrompt 实例化与令牌处理
packages/core/src/services/chat.ts
导入语句从 createChatPrompt 改为 ChatLunaChatPrompt。在 createAgent 中,当 options.prompt 未提供时,直接实例化 ChatLunaChatPrompt,配置 preset、基于 model.getNumTokenstokenCounter、按 maxTokenLimit 或回退到 getModelMaxContextSize 计算的 sendTokenLimit,以及注入 contextManagerpromptRenderService

评估代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

庆祝诗

🐰 提示的构造换新装,
从函数调用到类的殿堂,
令牌计数更精妙,
上下文注入显威力,
ChatLuna 的对话更闪亮✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确描述了主要变更:通过直接实例化ChatLunaChatPrompt而非使用辅助函数来避免提示注入警告。
Description check ✅ Passed 描述与变更集相关,清楚地说明了修复内容:避免使用通过上下文注入依赖的辅助路径,直接构建ChatLunaChatPrompt并显式传递必要参数。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/chatluna-inject-warning

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request bumps the peer dependency of koishi-plugin-chatluna to ^1.4.0-alpha.19 across multiple packages and refactors the prompt creation in chat.ts to instantiate ChatLunaChatPrompt directly. The review feedback highlights a critical issue where evaluating llm.value immediately at agent creation can cause crashes if the model is not yet loaded, or lead to stale closures when the model updates. It is recommended to make the token counter and limit dynamic by subclassing ChatLunaChatPrompt inline.

Comment thread packages/core/src/services/chat.ts
@dingyi222666 dingyi222666 merged commit 90a781b into v1-dev May 26, 2026
4 of 5 checks passed
@dingyi222666 dingyi222666 deleted the fix/chatluna-inject-warning branch May 26, 2026 17:18
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