Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): send ACP boolean and number form answers as typed values #31107

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

Showing 2 changed files with 91 additions and 9 deletions.

x
0 of 2 viewed, 2 left
36 additions and 9 deletionspackages/provider-acp/src/server/adapter.tsModified
View file
@@ -1292,17 +1292,47 @@
-function elicitationContent(
+function elicitationArrayValue(
+ values: ReadonlyArray<unknown>,
+ schema: Record<string, unknown> | undefined,
+): ReadonlyArray<string> {
+ const allowed = unknownRecord(schema?.items)?.enum;
+ const strings = values.filter((entry): entry is string => typeof entry === "string");
+ return Array.isArray(allowed) ? strings.filter((entry) => allowed.includes(entry)) : strings;
+​
+function elicitationAnswerValue(
+ answer: string,
+ schema: Record<string, unknown> | undefined,
+): EffectAcpSchema.ElicitationContentValue {
+ if (schema?.type === "array") {
+ return elicitationArrayValue([answer], schema);
+ }
+ if (schema?.type === "boolean") {
+ return answer === "true" ? true : answer === "false" ? false : answer;
+ }
Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)
+ if (schema?.type === "number" || schema?.type === "integer") {
+ const parsed = answer.trim() === "" ? Number.NaN : Number(answer);
+ const valid =
+ schema.type === "integer" ? Number.isSafeInteger(parsed) : Number.isFinite(parsed);
+ return valid ? parsed : answer;