Repository navigation
feat(kit): support runtime tool providers - #365
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
Walkthrough
ChangesRuntime Tool Provisioning and toolSource Tracking
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/src/tools/message.md`:
- Around line 256-257: Update the type signatures in the options table for both
getTools and callTool methods to match the actual plugin contract. For getTools,
add the BasePluginContext parameter to the function signature and change the
return type from Promise<Array<Tool | RuntimeTool>> to
MaybePromise<ToolProviderItem[]> to correctly indicate that it can return either
a synchronous or asynchronous result. For callTool, update the return type to
reflect that it can return either a synchronous value (string | Record<string,
any>) or an async/streaming value, rather than only showing the async variant.
These changes will ensure the documentation accurately represents what the
actual plugin implementation expects and returns.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4530f256-4fdc-43db-821b-fbe8351c3f94
📒 Files selected for processing (10)
docs/src/tools/message.mdpackages/kit/src/message/core/engine.tspackages/kit/src/message/plugins/index.tspackages/kit/src/message/plugins/toolPlugin.tspackages/kit/src/message/test/mockResponseProvider.tspackages/kit/src/message/test/toolPlugin.test.tspackages/kit/src/message/types.tspackages/kit/src/message/utils.tspackages/kit/src/vue/message/mockResponseProvider.tspackages/kit/src/vue/message/plugins/toolPlugin.ts
📦 Package Previewpnpm add https://pkg.pr.new/@opentiny/tiny-robot@380e550 pnpm add https://pkg.pr.new/@opentiny/tiny-robot-kit@380e550 pnpm add https://pkg.pr.new/@opentiny/tiny-robot-svgs@380e550 commit: 380e550 |
…syncStreamableResult types
|
问题 1:runtime tool 解析两次,执行映射可能不一致 涉及文件:
问题点:
风险:
实际场景:
验证方法: 在 it('keeps runtime tool handlers stable for the tool list sent to the model', async () => {
const runtimeCall = vi.fn(() => 'runtime result')
const fallbackCall = vi.fn(() => 'fallback result')
const runtimeTool: RuntimeTool = {
tool: {
type: 'function',
function: {
name: 'volatile_runtime_tool',
description: 'Runtime tool that is only available during request preparation',
},
},
handler: runtimeCall,
}
let getToolsCalls = 0
const engine = createTestMessageEngine({
plugins: [
...silentDefaultPlugins,
toolPlugin({
getTools: async () => {
getToolsCalls++
return getToolsCalls === 1 ? [runtimeTool] : []
},
callTool: fallbackCall,
}),
],
responseProvider,
})
await engine.sendMessage('call volatile tool')
expect(runtimeCall).toHaveBeenCalledOnce()
expect(fallbackCall).not.toHaveBeenCalled()
})当前结果:
建议修复方向:
问题 2:OpenAI tool 类型被收窄,custom tool 会类型不兼容且运行时报错 涉及文件:
问题点:
tools?: Array<ChatCompletionFunctionTool>但 OpenAI 类型实际是: ChatCompletionTool = ChatCompletionFunctionTool | ChatCompletionCustomTool
tools?: Array<ChatCompletionTool>
tool.function.namecustom tool 没有 验证方法 1:类型验证 在测试中构造合法 const customTool = {
type: 'custom',
custom: {
name: 'custom_formatter',
description: 'Format with custom grammar',
format: {
type: 'grammar',
grammar: {
syntax: 'lark',
definition: 'start: "ok"',
},
},
},
} satisfies ChatCompletionTool然后赋值: context.requestBody.tools = [customTool]运行: pnpm.cmd -F @opentiny/tiny-robot-kit exec tsc --noEmit当前结果: 验证方法 2:运行时验证 添加测试: it('keeps custom tools already present on the request body', async () => {
const customTool = {
type: 'custom',
custom: {
name: 'custom_formatter',
description: 'Format with custom grammar',
format: {
type: 'grammar',
grammar: {
syntax: 'lark',
definition: 'start: "ok"',
},
},
},
} satisfies ChatCompletionTool
const engine = createTestMessageEngine({
plugins: [
...silentDefaultPlugins,
{
name: 'custom-tool-plugin',
onBeforeRequest: (context) => {
context.requestBody.tools = [customTool]
},
},
toolPlugin({
getTools: async () => [],
callTool: async () => 'fallback',
}),
],
responseProvider,
})
await engine.sendMessage('use custom tool')
})当前结果: 定位: 建议修复方向:
|
… adjust related logic
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
🧹 Preview Cleaned UpThe preview deployment has been removed. |

PR 描述
为 message 工具调用增加 runtime tool provider 能力,让插件可以在请求前动态提供工具 schema,并可选绑定本地 handler 直接处理对应 tool call。
主要改动:
toolPlugin支持RuntimeTool,通过function.name路由到对应 handler。provideTools(context)暴露工具,由toolPlugin统一收集。toolSource,标记工具来自toolPlugin、外部 provider 或未知来源。tools,并检测重复工具名。toolPlugin关键流程测试。验证:
pnpm -F @opentiny/tiny-robot-kit test -- --run src/message/test/toolPlugin.test.ts pnpm buildSummary by CodeRabbit
Summary by CodeRabbit
Release Notes