mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
fix(server): schema preflight for tool call (#15172)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import {
|
||||
type LlmBackendConfig,
|
||||
llmDispatchToolLoopStream,
|
||||
@@ -63,7 +65,7 @@ export function createToolExecutionCallback(
|
||||
};
|
||||
}
|
||||
|
||||
async function executeToolCall(
|
||||
export async function executeToolCall(
|
||||
tools: CopilotToolSet,
|
||||
request: LlmToolCallbackRequest,
|
||||
options: CopilotToolExecuteOptions
|
||||
@@ -103,7 +105,11 @@ async function executeToolCall(
|
||||
}
|
||||
|
||||
try {
|
||||
const output = await tool.execute(request.args, options);
|
||||
const args =
|
||||
tool.inputSchema instanceof z.ZodType
|
||||
? tool.inputSchema.parse(request.args)
|
||||
: request.args;
|
||||
const output = await tool.execute(args, options);
|
||||
return {
|
||||
callId: request.callId,
|
||||
name: request.name,
|
||||
@@ -173,3 +179,7 @@ export function createToolLoopBridge(
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
// re-export for test consumers
|
||||
export type { LlmToolCallbackRequest } from '../../../../native';
|
||||
export type { CopilotToolSet, CopilotToolExecuteOptions } from '../../tools';
|
||||
|
||||
Reference in New Issue
Block a user