fix: sanitize npm package names for OpenAI tool names and update lockfile
Problem: OpenAI tool names must match ^[a-zA-Z0-9_-]+ but npm package names like @tpmjs/createblogpost contain @ and / Solution: Add sanitizeToolName() function and update pnpm-lock.yaml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
fdfc721d40
commit
8f3c6a2910
2 changed files with 11 additions and 9 deletions
|
|
@ -159,6 +159,15 @@ export function calculateTokenBreakdown(
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize npm package name to valid OpenAI tool name
|
||||
* OpenAI tool names must match: ^[a-zA-Z0-9_-]+
|
||||
* Converts: @tpmjs/createblogpost -> tpmjs-createblogpost
|
||||
*/
|
||||
function sanitizeToolName(npmPackageName: string): string {
|
||||
return npmPackageName.replace(/[@/]/g, '-').replace(/^-+/, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute tool with AI agent and streaming
|
||||
*/
|
||||
|
|
@ -169,6 +178,7 @@ export async function executeToolWithAgent(
|
|||
onTokenUpdate?: (tokens: Partial<TokenBreakdown>) => void
|
||||
) {
|
||||
const toolDef = createToolDefinition(tool);
|
||||
const sanitizedToolName = sanitizeToolName(tool.npmPackageName);
|
||||
const messages: CoreMessage[] = [
|
||||
{
|
||||
role: 'user',
|
||||
|
|
@ -183,7 +193,7 @@ export async function executeToolWithAgent(
|
|||
model: openai('gpt-4-turbo'),
|
||||
messages,
|
||||
tools: {
|
||||
[tool.npmPackageName]: toolDef,
|
||||
[sanitizedToolName]: toolDef,
|
||||
},
|
||||
// biome-ignore lint/suspicious/noExplicitAny: AI SDK v5 chunk type compatibility
|
||||
onChunk: ({ chunk }: { chunk: any }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue