Skip to content

Commit e27e4d4

Browse files
authored
Add 'required' to tool call parameters (#14673)
fixed #14672
1 parent c89f3dc commit e27e4d4

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

packages/ai-core/src/common/language-model.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ export const isLanguageModelRequestMessage = (obj: unknown): obj is LanguageMode
3535
export type ToolRequestParametersProperties = Record<string, { type: string, [key: string]: unknown }>;
3636
export interface ToolRequestParameters {
3737
type?: 'object';
38-
properties: ToolRequestParametersProperties
38+
properties: ToolRequestParametersProperties;
39+
required?: string[];
3940
}
4041
export interface ToolRequest {
4142
id: string;
@@ -62,7 +63,8 @@ export namespace ToolRequest {
6263
export function isToolRequestParameters(obj: unknown): obj is ToolRequestParameters {
6364
return !!obj && typeof obj === 'object' &&
6465
(!('type' in obj) || obj.type === 'object') &&
65-
'properties' in obj && isToolRequestParametersProperties(obj.properties);
66+
'properties' in obj && isToolRequestParametersProperties(obj.properties) &&
67+
(!('required' in obj) || (Array.isArray(obj.required) && obj.required.every(prop => typeof prop === 'string')));
6668
}
6769
}
6870

packages/ai-mcp/src/browser/mcp-command-contribution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export class MCPCommandContribution implements CommandContribution {
126126
parameters: ToolRequest.isToolRequestParameters(tool.inputSchema) ? {
127127
type: tool.inputSchema.type,
128128
properties: tool.inputSchema.properties,
129+
required: tool.inputSchema.required
129130
} : undefined,
130131
description: tool.description,
131132
handler: async (arg_string: string) => {

packages/ai-workspace-agent/src/browser/functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ export class FileContentFunction implements ToolProvider {
186186
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
187187
workspace boundaries are accessible; attempting to access files outside the workspace will return an error.`,
188188
}
189-
}
189+
},
190+
required: ['file']
190191
},
191192
handler: (arg_string: string) => {
192193
const file = this.parseArg(arg_string);
@@ -249,7 +250,8 @@ export class GetWorkspaceFileList implements ToolProvider {
249250
description: `Optional relative path to a directory within the workspace. If no path is specified, the function lists contents directly in the workspace
250251
root. Paths are resolved within workspace boundaries only; paths outside the workspace or unvalidated paths will result in an error.`
251252
}
252-
}
253+
},
254+
required: ['path']
253255
},
254256
description: `List files and directories within a specified workspace directory. Paths are relative to the workspace root, and only workspace-contained paths are
255257
allowed. If no path is provided, the root contents are listed. Paths outside the workspace will result in an error.`,

0 commit comments

Comments
 (0)