Skip to content

Commit

Permalink
Add 'required' to tool call parameters
Browse files Browse the repository at this point in the history
fixed #14672
  • Loading branch information
JonasHelming committed Dec 24, 2024
1 parent e4ca643 commit e6ca7ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/ai-core/src/common/language-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export const isLanguageModelRequestMessage = (obj: unknown): obj is LanguageMode
export type ToolRequestParametersProperties = Record<string, { type: string, [key: string]: unknown }>;
export interface ToolRequestParameters {
type?: 'object';
properties: ToolRequestParametersProperties
properties: ToolRequestParametersProperties;
required?: string[];
}
export interface ToolRequest {
id: string;
Expand All @@ -62,7 +63,8 @@ export namespace ToolRequest {
export function isToolRequestParameters(obj: unknown): obj is ToolRequestParameters {
return !!obj && typeof obj === 'object' &&
(!('type' in obj) || obj.type === 'object') &&
'properties' in obj && isToolRequestParametersProperties(obj.properties);
'properties' in obj && isToolRequestParametersProperties(obj.properties) &&
(!('required' in obj) || (Array.isArray(obj.required) && obj.required.every(prop => typeof prop === 'string')));
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/ai-mcp/src/browser/mcp-command-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export class MCPCommandContribution implements CommandContribution {
parameters: ToolRequest.isToolRequestParameters(tool.inputSchema) ? {
type: tool.inputSchema.type,
properties: tool.inputSchema.properties,
required: tool.inputSchema.required
} : undefined,
description: tool.description,
handler: async (arg_string: string) => {
Expand Down
6 changes: 4 additions & 2 deletions packages/ai-workspace-agent/src/browser/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export class FileContentFunction implements ToolProvider {
description: `Return the content of a specified file within the workspace. The file path must be provided relative to the workspace root. Only files within
workspace boundaries are accessible; attempting to access files outside the workspace will return an error.`,
}
}
},
required: ['file']
},
handler: (arg_string: string) => {
const file = this.parseArg(arg_string);
Expand Down Expand Up @@ -249,7 +250,8 @@ export class GetWorkspaceFileList implements ToolProvider {
description: `Optional relative path to a directory within the workspace. If no path is specified, the function lists contents directly in the workspace
root. Paths are resolved within workspace boundaries only; paths outside the workspace or unvalidated paths will result in an error.`
}
}
},
required: ['path']
},
description: `List files and directories within a specified workspace directory. Paths are relative to the workspace root, and only workspace-contained paths are
allowed. If no path is provided, the root contents are listed. Paths outside the workspace will result in an error.`,
Expand Down

0 comments on commit e6ca7ad

Please sign in to comment.