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 }) => {
|
||||
|
|
|
|||
8
pnpm-lock.yaml
generated
8
pnpm-lock.yaml
generated
|
|
@ -101,9 +101,6 @@ importers:
|
|||
remark-gfm:
|
||||
specifier: ^4.0.1
|
||||
version: 4.0.1
|
||||
tiktoken:
|
||||
specifier: ^1.0.22
|
||||
version: 1.0.22
|
||||
zod:
|
||||
specifier: ^3.25.76
|
||||
version: 3.25.76
|
||||
|
|
@ -4627,9 +4624,6 @@ packages:
|
|||
thenify@3.3.1:
|
||||
resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==}
|
||||
|
||||
tiktoken@1.0.22:
|
||||
resolution: {integrity: sha512-PKvy1rVF1RibfF3JlXBSP0Jrcw2uq3yXdgcEXtKTYn3QJ/cBRBHDnrJ5jHky+MENZ6DIPwNUGWpkVx+7joCpNA==}
|
||||
|
||||
tiny-invariant@1.3.3:
|
||||
resolution: {integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==}
|
||||
|
||||
|
|
@ -9920,8 +9914,6 @@ snapshots:
|
|||
dependencies:
|
||||
any-promise: 1.3.0
|
||||
|
||||
tiktoken@1.0.22: {}
|
||||
|
||||
tiny-invariant@1.3.3: {}
|
||||
|
||||
tinybench@2.9.0: {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue