Add parameter schema and defaults to ToolResource model and schemas. Implement runtime tool resolution in assistants and tools routers, ensuring proper handling of tool parameters. Update tests to validate new functionality and ensure correct integration of parameter handling in the API.

This commit is contained in:
Xin Wang
2026-02-27 14:44:28 +08:00
parent d942c85eff
commit 5f768edf68
13 changed files with 397 additions and 9 deletions

View File

@@ -123,6 +123,8 @@ const mapTool = (raw: AnyRecord): Tool => ({
httpUrl: readField(raw, ['httpUrl', 'http_url'], ''),
httpHeaders: readField(raw, ['httpHeaders', 'http_headers'], {}),
httpTimeoutMs: Number(readField(raw, ['httpTimeoutMs', 'http_timeout_ms'], 10000)),
parameterSchema: readField(raw, ['parameterSchema', 'parameter_schema'], {}),
parameterDefaults: readField(raw, ['parameterDefaults', 'parameter_defaults'], {}),
isSystem: Boolean(readField(raw, ['isSystem', 'is_system'], false)),
enabled: Boolean(readField(raw, ['enabled'], true)),
isCustom: !Boolean(readField(raw, ['isSystem', 'is_system'], false)),
@@ -567,6 +569,8 @@ export const createTool = async (data: Partial<Tool>): Promise<Tool> => {
http_url: data.httpUrl || null,
http_headers: data.httpHeaders || {},
http_timeout_ms: data.httpTimeoutMs ?? 10000,
parameter_schema: data.parameterSchema || {},
parameter_defaults: data.parameterDefaults || {},
enabled: data.enabled ?? true,
};
const response = await apiRequest<AnyRecord>('/tools/resources', { method: 'POST', body: payload });
@@ -583,6 +587,8 @@ export const updateTool = async (id: string, data: Partial<Tool>): Promise<Tool>
http_url: data.httpUrl,
http_headers: data.httpHeaders,
http_timeout_ms: data.httpTimeoutMs,
parameter_schema: data.parameterSchema,
parameter_defaults: data.parameterDefaults,
enabled: data.enabled,
};
const response = await apiRequest<AnyRecord>(`/tools/resources/${id}`, { method: 'PUT', body: payload });