fix: add backwards compatibility for exportName in tpmjs schema
The TpmjsToolDefinitionSchema now accepts both 'name' and 'exportName' fields, transforming exportName to name for backward compatibility with published packages that still use the old field name. Also fix type errors in sync routes for auto-discovered tools.
This commit is contained in:
parent
e84eda7525
commit
861e8c2b7e
3 changed files with 42 additions and 12 deletions
|
|
@ -152,6 +152,9 @@ export async function POST(request: NextRequest) {
|
|||
.map((t) => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
parameters: undefined,
|
||||
returns: undefined,
|
||||
aiAgent: undefined,
|
||||
}));
|
||||
toolDiscoverySource = 'auto';
|
||||
console.log(
|
||||
|
|
|
|||
|
|
@ -166,6 +166,9 @@ export async function POST(request: NextRequest) {
|
|||
.map((t) => ({
|
||||
name: t.name,
|
||||
description: t.description,
|
||||
parameters: undefined,
|
||||
returns: undefined,
|
||||
aiAgent: undefined,
|
||||
}));
|
||||
toolDiscoverySource = 'auto';
|
||||
console.log(
|
||||
|
|
|
|||
|
|
@ -89,19 +89,40 @@ export type TpmjsAiAgent = z.infer<typeof TpmjsAiAgentSchema>;
|
|||
* - parameters: Tool input parameters - auto-extracted from inputSchema
|
||||
* - returns: Tool return type - auto-extracted from tool
|
||||
* - aiAgent: AI agent guidance - auto-extracted from tool
|
||||
* - exportName: Renamed to 'name' - kept for backward compatibility with published packages
|
||||
*/
|
||||
export const TpmjsToolDefinitionSchema = z.object({
|
||||
// Required: The export name of the tool from the package
|
||||
name: z.string().min(1),
|
||||
// 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({
|
||||
// Required: The export name of the tool from the package
|
||||
// Accepts both 'name' and legacy 'exportName' field
|
||||
name: z.string().min(1).optional(),
|
||||
// @deprecated - renamed to 'name', 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(),
|
||||
})
|
||||
.transform((data) => ({
|
||||
// Transform exportName to name for backward compatibility
|
||||
name: data.name || data.exportName || '',
|
||||
description: data.description,
|
||||
parameters: data.parameters,
|
||||
returns: data.returns,
|
||||
aiAgent: data.aiAgent,
|
||||
}))
|
||||
.refine((data) => data.name.length > 0, {
|
||||
message: 'Either name or exportName is required',
|
||||
path: ['name'],
|
||||
});
|
||||
|
||||
export type TpmjsToolDefinition = z.infer<typeof TpmjsToolDefinitionSchema>;
|
||||
|
||||
|
|
@ -268,6 +289,9 @@ export function validateTpmjsField(tpmjs: unknown): ValidationResult {
|
|||
const tool: TpmjsToolDefinition = {
|
||||
name: 'default',
|
||||
description: minimalResult.data.description,
|
||||
parameters: undefined,
|
||||
returns: undefined,
|
||||
aiAgent: undefined,
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue