@oxy.so/contracts 4.9.0 → 4.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -75,7 +75,48 @@ function decisionInputBudget(payload) {
|
|
|
75
75
|
function decisionFitsGateway(payload) {
|
|
76
76
|
return decisionInputBudget(payload).gateway <= 32000;
|
|
77
77
|
}
|
|
78
|
+
/** JSON permits escaped lone UTF-16 units; Go replaces them after decoding. */
|
|
79
|
+
function hasUnpairedSurrogate(value) {
|
|
80
|
+
for (let i = 0; i < value.length; i++) {
|
|
81
|
+
const unit = value.charCodeAt(i);
|
|
82
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
83
|
+
const next = value.charCodeAt(i + 1);
|
|
84
|
+
if (!(next >= 0xdc00 && next <= 0xdfff))
|
|
85
|
+
return true;
|
|
86
|
+
i++;
|
|
87
|
+
}
|
|
88
|
+
else if (unit >= 0xdc00 && unit <= 0xdfff)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
78
93
|
function validateInput(payload, ctx) {
|
|
94
|
+
const fields = [
|
|
95
|
+
{ value: payload.state, path: ["state"] },
|
|
96
|
+
{ value: payload.instructions, path: ["instructions"] },
|
|
97
|
+
];
|
|
98
|
+
for (const [index, question] of payload.questions.entries()) {
|
|
99
|
+
for (const field of ["id", "question", "criteria"]) {
|
|
100
|
+
fields.push({ value: question[field], path: ["questions", index, field] });
|
|
101
|
+
}
|
|
102
|
+
if (question.kind === "choice" || question.kind === "score") {
|
|
103
|
+
const field = question.kind === "choice" ? "options" : "levels";
|
|
104
|
+
const labels = question.kind === "choice" ? question.options : question.levels;
|
|
105
|
+
for (const [labelIndex, value] of labels.entries()) {
|
|
106
|
+
fields.push({ value, path: ["questions", index, field, labelIndex] });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
let invalidUnicode = false;
|
|
111
|
+
for (const { value, path } of fields) {
|
|
112
|
+
if (value !== undefined && hasUnpairedSurrogate(value)) {
|
|
113
|
+
invalidUnicode = true;
|
|
114
|
+
ctx.addIssue({ code: "custom", path, message: "Decisions require paired UTF-16 surrogates." });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Reject before measuring/reserving text that the execution runtime would change.
|
|
118
|
+
if (invalidUnicode)
|
|
119
|
+
return;
|
|
79
120
|
if (new Set(payload.questions.map((q) => q.id)).size !==
|
|
80
121
|
payload.questions.length)
|
|
81
122
|
ctx.addIssue({
|