Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): offer ACP array enum form fields as multi-select questions #31081

ClosedHoneyPaptan(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromrefs/pull/31081/headopened View on GitHub

Showing 2 changed files with 129 additions and 22 deletions.

x
0 of 2 viewed, 2 left
46 additions and 22 deletionspackages/provider-acp/src/server/adapter.tsModified
View file
@@ -1308,6 +1308,50 @@
return content;
+function stringEnum(schema: Record<string, unknown> | undefined): ReadonlyArray<string> {
+ return Array.isArray(schema?.enum)
+ ? schema.enum.filter((value): value is string => typeof value === "string")
+ : [];
+​
+function enumOptions(values: ReadonlyArray<string>) {
+ const counts = new Map<string, number>();
+ for (const value of values) counts.set(value.trim(), (counts.get(value.trim()) ?? 0) + 1);
+ return values.map((value) => {
+ const plain = value.trim();
+ const unique = plain !== "" && counts.get(plain) === 1;
+ const label = unique ? plain : JSON.stringify(value);
+ return { label, description: label, ...(label === value ? {} : { value }) };
+ });
+​
+export function elicitationFormQuestion(
+ id: string,
+ property: unknown,
+ index: number,
+ message: string,
+): OrchestrationV2UserInputQuestion {
+ const record = unknownRecord(property);
+ const isArray = record?.type === "array";
+ const enumValues = stringEnum(isArray ? unknownRecord(record.items) : record);