fix(types): support both 'name' and 'exportName' for backward compatibility

The TpmjsToolDefinitionSchema now accepts either 'name' (new) or 'exportName'
(legacy) to ensure existing published packages continue to work.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ajax Davis 2025-12-17 14:56:56 +10:00
parent aadd304ca5
commit 3b77f74d4b

View file

@ -90,17 +90,28 @@ export type TpmjsAiAgent = z.infer<typeof TpmjsAiAgentSchema>;
* - returns: Tool return type - auto-extracted from tool
* - aiAgent: AI agent guidance - auto-extracted from tool
*/
export const TpmjsToolDefinitionSchema = z.object({
name: z.string().min(1, 'Tool name is required'),
// Optional - auto-extracted from tool if not provided
description: z.string().min(20, 'Description must be at least 20 characters').max(500).optional(),
// @deprecated - now auto-extracted from tool's inputSchema
parameters: z.array(TpmjsParameterSchema).optional(),
// @deprecated - now auto-extracted from tool
returns: TpmjsReturnsSchema.optional(),
// @deprecated - now auto-extracted from tool
aiAgent: TpmjsAiAgentSchema.optional(),
});
export const TpmjsToolDefinitionSchema = z
.object({
// New field name (preferred)
name: z.string().min(1).optional(),
// @deprecated - use 'name' instead. Kept for backward compatibility.
exportName: z.string().min(1).optional(),
// Optional - auto-extracted from tool if not provided
description: z
.string()
.min(20, 'Description must be at least 20 characters')
.max(500)
.optional(),
// @deprecated - now auto-extracted from tool's inputSchema
parameters: z.array(TpmjsParameterSchema).optional(),
// @deprecated - now auto-extracted from tool
returns: TpmjsReturnsSchema.optional(),
// @deprecated - now auto-extracted from tool
aiAgent: TpmjsAiAgentSchema.optional(),
})
.refine((data) => data.name || data.exportName, {
message: 'Either name or exportName is required',
});
export type TpmjsToolDefinition = z.infer<typeof TpmjsToolDefinitionSchema>;