mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-26 06:04:08 +00:00
fix(tools): treat inherited names as unknown tools in the OpenAI executor
Names like constructor, toString and __proto__ resolved Object.prototype members as schemas and threw on parameters.required, failing the whole tool batch. The schema lookup now uses Object.hasOwn, so they return the usual unknown-function error.
This commit is contained in:
parent
8fdb2d4779
commit
92508cc6d0
2 changed files with 19 additions and 2 deletions
|
|
@ -501,8 +501,10 @@ export function createToolCallExecutor(
|
|||
const args = parsed.value
|
||||
|
||||
// Blank arguments are only valid for tools with no required fields.
|
||||
const schema =
|
||||
memoryToolSchemas[functionName as keyof typeof memoryToolSchemas]
|
||||
// hasOwn so names like "constructor" fall through to the unknown-function error.
|
||||
const schema = Object.hasOwn(memoryToolSchemas, functionName)
|
||||
? memoryToolSchemas[functionName as keyof typeof memoryToolSchemas]
|
||||
: undefined
|
||||
const missing = schema?.parameters.required.filter(
|
||||
(field: string) =>
|
||||
typeof args[field] !== "string" || args[field].trim() === "",
|
||||
|
|
|
|||
|
|
@ -404,6 +404,21 @@ describe("openai executeToolCall argument parsing", () => {
|
|||
expect(sdk.add).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each([
|
||||
"constructor",
|
||||
"toString",
|
||||
"__proto__",
|
||||
])("reports inherited name %p as an unknown function", async (name) => {
|
||||
const execute = openAi.createToolCallExecutor(API_KEY)
|
||||
|
||||
const result = JSON.parse(await execute(toolCall(name, "{}")))
|
||||
|
||||
expect(result).toEqual({
|
||||
success: false,
|
||||
error: `Unknown function: ${name}`,
|
||||
})
|
||||
})
|
||||
|
||||
it("still reports malformed JSON as a tool error", async () => {
|
||||
const execute = openAi.createToolCallExecutor(API_KEY)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue