Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'required' to tool call parameters #14673

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading