@absolutejs/ai 0.6.0 → 0.6.2

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.
@@ -277,6 +277,11 @@ var parseFormField = (raw) => {
277
277
  if (!name || !label || !type)
278
278
  return null;
279
279
  const field = { label, name, type };
280
+ if (raw.valueType !== undefined) {
281
+ if (!["string", "number", "integer", "boolean"].includes(String(raw.valueType)))
282
+ return null;
283
+ field.valueType = raw.valueType;
284
+ }
280
285
  const placeholder = cleanString(raw.placeholder, LABEL_MAX_CHARS);
281
286
  if (placeholder)
282
287
  field.placeholder = placeholder;
@@ -648,6 +653,11 @@ var formCard = {
648
653
  items: { type: "string" },
649
654
  type: "array"
650
655
  },
656
+ valueType: {
657
+ enum: ["string", "number", "integer", "boolean"],
658
+ type: "string",
659
+ description: "Submitted scalar type, especially integer for numeric select options"
660
+ },
651
661
  placeholder: { type: "string" },
652
662
  required: { type: "boolean" },
653
663
  type: { enum: [...FORM_FIELD_TYPES], type: "string" },
@@ -1154,6 +1164,68 @@ var renderChartSvg = (spec, options = {}) => {
1154
1164
  const body = spec.type === "donut" ? donutSvg(spec, frame) : cartesianSvg(spec, frame);
1155
1165
  return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" role="img" aria-label="${escapeXml(spec.title)}" font-family="${FONT}"><rect width="${width}" height="${height}" fill="${theme.surface}" rx="12"/>${spec.type === "donut" ? headerSvg({ ...spec, series: [] }, frame) : headerSvg(spec, frame)}${body}</svg>`;
1156
1166
  };
1167
+ // src/ai/ui/formSubmission.ts
1168
+ var prepareFormSubmission = (form, values) => {
1169
+ const input = { ...form.submit.input };
1170
+ const errors = {};
1171
+ for (const field of form.fields) {
1172
+ if (["__proto__", "constructor", "prototype"].includes(field.name)) {
1173
+ errors.form = "Invalid field name";
1174
+ continue;
1175
+ }
1176
+ const raw = values[field.name];
1177
+ if (raw === undefined || raw === null || typeof raw === "string" && !raw.trim()) {
1178
+ if (field.required)
1179
+ errors[field.name] = "This field is required";
1180
+ continue;
1181
+ }
1182
+ if (field.type === "select" && !field.options?.includes(String(raw))) {
1183
+ errors[field.name] = "Choose one of the available options";
1184
+ continue;
1185
+ }
1186
+ const type = field.valueType ?? (field.type === "number" ? "number" : field.type === "checkbox" ? "boolean" : "string");
1187
+ let value = raw;
1188
+ if (type === "number" || type === "integer") {
1189
+ value = typeof raw === "number" ? raw : typeof raw === "string" && /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/iu.test(raw.trim()) ? Number(raw) : NaN;
1190
+ if (typeof value !== "number" || !Number.isFinite(value) || type === "integer" && !Number.isSafeInteger(value)) {
1191
+ errors[field.name] = type === "integer" ? "Enter a whole number" : "Enter a number";
1192
+ continue;
1193
+ }
1194
+ } else if (type === "boolean") {
1195
+ if (![true, false, "true", "false"].includes(raw)) {
1196
+ errors[field.name] = "Choose yes or no";
1197
+ continue;
1198
+ }
1199
+ value = raw === true || raw === "true";
1200
+ if (field.type === "checkbox" && field.required && !value) {
1201
+ errors[field.name] = "This field is required";
1202
+ continue;
1203
+ }
1204
+ } else {
1205
+ if (typeof raw !== "string") {
1206
+ errors[field.name] = "Enter text";
1207
+ continue;
1208
+ }
1209
+ value = field.type === "password" ? raw : raw.trim();
1210
+ }
1211
+ input[field.name] = value;
1212
+ }
1213
+ return Object.keys(errors).length ? { ok: false, errors } : { ok: true, input };
1214
+ };
1215
+ // src/ai/ui/backgroundWork.ts
1216
+ var backgroundWorkNextAction = (work) => {
1217
+ if (!work.workId || !Number.isSafeInteger(work.totalSteps) || work.totalSteps < 1 || !Number.isSafeInteger(work.completedSteps) || work.completedSteps < 0 || work.completedSteps > work.totalSteps)
1218
+ throw new Error("Invalid background work progress");
1219
+ if (work.status === "completed")
1220
+ return { kind: "view_results", label: "View results" };
1221
+ if (work.status === "paused" && work.pauseReason === "funding")
1222
+ return work.fundingConfirmed ? { kind: "continue", label: "Continue research" } : { kind: "top_up", label: "Add credits" };
1223
+ if (work.status === "unknown")
1224
+ return { kind: "check_status", label: "Check status" };
1225
+ if (work.hasResults)
1226
+ return { kind: "view_results", label: "View saved results" };
1227
+ return { kind: "check_status", label: "Check status" };
1228
+ };
1157
1229
  export {
1158
1230
  BUILTIN_UI_CARDS,
1159
1231
  CARD_ID_MAX_CHARS,
@@ -1180,6 +1252,7 @@ export {
1180
1252
  TABLE_MAX_ROWS,
1181
1253
  UI_ACTIONS_MAX,
1182
1254
  UiCardValidationError,
1255
+ backgroundWorkNextAction,
1183
1256
  chartCard,
1184
1257
  choiceCard,
1185
1258
  confirmCard,
@@ -1198,10 +1271,11 @@ export {
1198
1271
  parseTableSpec,
1199
1272
  parseUiActions,
1200
1273
  planCard,
1274
+ prepareFormSubmission,
1201
1275
  renderChartSvg,
1202
1276
  statTilesCard,
1203
1277
  tableCard
1204
1278
  };
1205
1279
 
1206
- //# debugId=5FA77A0F06ADA10F64756E2164756E21
1280
+ //# debugId=4626F73FCA286A7B64756E2164756E21
1207
1281
  //# sourceMappingURL=index.js.map