Use correct schema for client sampling validation when tools are present (#1347)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
This commit is contained in:
parent
8bf13e4569
commit
2edbe8c82e
1 changed files with 131 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ import {
|
|||
CompleteResultSchema,
|
||||
CreateMessageRequestSchema,
|
||||
CreateMessageResultSchema,
|
||||
CreateMessageResultWithToolsSchema,
|
||||
CreateTaskResultSchema,
|
||||
ElicitRequestSchema,
|
||||
ElicitResultSchema,
|
||||
|
|
@ -458,8 +459,10 @@ export class Client<
|
|||
return taskValidationResult.data;
|
||||
}
|
||||
|
||||
// For non-task requests, validate against CreateMessageResultSchema
|
||||
const validationResult = safeParse(CreateMessageResultSchema, result);
|
||||
// For non-task requests, validate against appropriate schema based on tools presence
|
||||
const hasTools = params.tools || params.toolChoice;
|
||||
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
||||
const validationResult = safeParse(resultSchema, result);
|
||||
if (!validationResult.success) {
|
||||
const errorMessage =
|
||||
validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue