Skip to content

Commit 1c836e5

Browse files
committed
correct support for array type
1 parent c8ffba6 commit 1c836e5

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ function Department(props: DepartmentProps): JSX.Element {
8585
name: "setEmployeesAsSelected",
8686
description: "Set the given employees as 'selected'",
8787
argumentAnnotations: [
88-
{name: "employeeIds", type: "array", description: "The IDs of employees to set as selected", required: true}
88+
{
89+
name: "employeeIds",
90+
type: "array", items: { type: "string" }
91+
description: "The IDs of employees to set as selected",
92+
required: true
93+
}
8994
],
9095
implementation: async (employeeIds) => setEmployeesAsSelected(employeeIds),
9196
},

examples/next-openai/src/app/components/destination-table.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ export function DestinationTable({
6060
}));
6161
};
6262

63+
const headingCamelCase = toCamelCase(heading);
64+
6365
useMakeCopilotActionable(
6466
{
65-
name: `setSelectedDestinations_${heading}`,
67+
name: `setSelectedDestinations_${headingCamelCase}`,
6668
description: `Set the given destinations as 'selected', on the ${heading} table`,
6769
argumentAnnotations: [
6870
{
6971
name: "destinationNames",
7072
type: "array",
73+
items: {
74+
type: "string",
75+
},
7176
description: "The names of the destinations to select",
7277
required: true,
7378
},
@@ -109,3 +114,11 @@ export function DestinationTable({
109114
</div>
110115
);
111116
}
117+
118+
function toCamelCase(str: string): string {
119+
return str
120+
.replace(/[-_ ](.)/g, (match, group1) => {
121+
return group1.toUpperCase();
122+
})
123+
.replace(/^(.)/, (match, group1) => group1.toLowerCase());
124+
}

examples/next-openai/src/app/components/example.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ function DepartmentComponent(props: DepartmentComponentProps): JSX.Element {
6060
{
6161
name: "employeeIds",
6262
type: "array",
63+
items: {
64+
type: "string",
65+
},
6366
description: "The IDs of employees to set as selected",
6467
required: true,
6568
},

packages/react-core/src/components/copilot-provider.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ function annotatedFunctionToChatCompletionFunction(
145145
// Create the parameters object based on the argumentAnnotations
146146
let parameters: { [key: string]: any } = {};
147147
for (let arg of annotatedFunction.argumentAnnotations) {
148-
parameters[arg.name] = { type: arg.type, description: arg.description };
148+
// isolate the args we should forward inline
149+
let { name, required, ...forwardedArgs } = arg;
150+
parameters[arg.name] = forwardedArgs;
149151
}
150152

151153
let requiredParameterNames: string[] = [];

packages/react-core/src/types/annotated-function.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
export interface AnnotatedFunctionArgument {
1+
export interface AnnotatedFunctionSimpleArgument {
22
name: string;
3-
type: string;
3+
type: "string" | "number" | "boolean" | "object"; // Add or change types according to your needs.
44
description: string;
5-
allowedValues?: any[];
65
required: boolean;
76
}
87

8+
export interface AnnotatedFunctionArrayArgument {
9+
name: string;
10+
type: "array";
11+
items: {
12+
type: string;
13+
};
14+
description: string;
15+
required: boolean;
16+
}
17+
18+
export type AnnotatedFunctionArgument =
19+
| AnnotatedFunctionSimpleArgument
20+
| AnnotatedFunctionArrayArgument;
21+
922
export interface AnnotatedFunction<Inputs extends any[]> {
1023
name: string;
1124
description: string;

0 commit comments

Comments
 (0)