@xpert-ai/chatkit-types 0.19.1 → 0.20.0

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.
package/dist/index.d.ts CHANGED
@@ -2083,6 +2083,8 @@ export declare function isHITLRequest(value: unknown): value is HITLRequest;
2083
2083
 
2084
2084
  export declare function isHITLReviewDisplay(value: unknown): value is HITLReviewDisplay;
2085
2085
 
2086
+ export declare function isInputDate(value: unknown): value is string;
2087
+
2086
2088
  export declare function isInterruptRequest(value: unknown): value is InterruptRequest;
2087
2089
 
2088
2090
  export declare function isLangGraphInterrupt(value: unknown): value is LangGraphInterrupt;
@@ -2091,6 +2093,8 @@ export declare function isLangGraphInterruptPayload(value: unknown): value is La
2091
2093
 
2092
2094
  export declare function isLangGraphInterruptTask(value: unknown): value is LangGraphInterruptTask;
2093
2095
 
2096
+ export declare function isRequestUserInputForm(value: unknown): value is RequestUserInputForm;
2097
+
2094
2098
  export declare function isResourceCardContent(value: unknown): boolean;
2095
2099
 
2096
2100
  export declare function isToolCallInterrupt(value: unknown): value is ToolCallInterrupt;
@@ -2436,6 +2440,16 @@ export declare interface RequestUserInputAnswer {
2436
2440
 
2437
2441
  export declare type RequestUserInputAnswerType = 'option' | 'other';
2438
2442
 
2443
+ export declare interface RequestUserInputForm {
2444
+ schemaVersion: 1;
2445
+ mode: UserInputMode;
2446
+ purpose: 'clarification';
2447
+ title: string;
2448
+ description?: string;
2449
+ fields: UserInputField[];
2450
+ questions?: never;
2451
+ }
2452
+
2439
2453
  export declare interface RequestUserInputOption {
2440
2454
  label: string;
2441
2455
  description: string;
@@ -2456,13 +2470,18 @@ export declare interface RequestUserInputResult {
2456
2470
  type: RequestUserInputResultType;
2457
2471
  purpose: RequestUserInputResultPurpose;
2458
2472
  answers: RequestUserInputAnswer[];
2473
+ status?: 'submitted' | 'cancelled';
2474
+ schemaVersion?: 1;
2475
+ requestId?: string;
2476
+ values?: UserInputValues;
2477
+ form?: RequestUserInputForm;
2459
2478
  }
2460
2479
 
2461
- export declare type RequestUserInputResultPurpose = typeof REQUEST_USER_INPUT_RESULT_PURPOSE_PLAN_CLARIFICATION | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_IMPLEMENTATION_CONFIRMATION;
2480
+ export declare type RequestUserInputResultPurpose = 'clarification' | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_PLAN_CLARIFICATION | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_IMPLEMENTATION_CONFIRMATION;
2462
2481
 
2463
2482
  export declare type RequestUserInputResultType = typeof REQUEST_USER_INPUT_RESULT_TYPE;
2464
2483
 
2465
- export declare type RequestUserInputToolArgs = RequestUserInputParams;
2484
+ export declare type RequestUserInputToolArgs = RequestUserInputParams | RequestUserInputForm;
2466
2485
 
2467
2486
  export declare type RequestUserInputToolCall = ToolCall & {
2468
2487
  name: RequestUserInputToolName;
@@ -3371,8 +3390,175 @@ export declare function upsertFileActivityContent<T>(content: T[], receipt: TMes
3371
3390
  /** Identity is local to one reply. Repeat emissions replace the snapshot in place. */
3372
3391
  export declare function upsertResourceCardContent<T>(parts: T[], card: TMessageContentResourceCard): (T | TMessageContentResourceCard)[];
3373
3392
 
3393
+ export declare const USER_INPUT_FORM_SCHEMA: {
3394
+ readonly type: "object";
3395
+ readonly additionalProperties: false;
3396
+ readonly required: readonly ["schemaVersion", "mode", "purpose", "title", "fields"];
3397
+ readonly properties: {
3398
+ readonly schemaVersion: {
3399
+ readonly type: "integer";
3400
+ readonly const: 1;
3401
+ };
3402
+ readonly mode: {
3403
+ readonly type: "string";
3404
+ readonly enum: readonly ["blocking"];
3405
+ };
3406
+ readonly purpose: {
3407
+ readonly type: "string";
3408
+ readonly const: "clarification";
3409
+ };
3410
+ readonly title: {
3411
+ readonly type: "string";
3412
+ readonly minLength: 1;
3413
+ readonly maxLength: 160;
3414
+ };
3415
+ readonly description: {
3416
+ readonly type: "string";
3417
+ readonly maxLength: 2000;
3418
+ };
3419
+ readonly fields: {
3420
+ readonly type: "array";
3421
+ readonly minItems: 1;
3422
+ readonly maxItems: 12;
3423
+ readonly items: {
3424
+ readonly type: "object";
3425
+ readonly additionalProperties: false;
3426
+ readonly required: readonly ["id", "type", "label"];
3427
+ readonly properties: {
3428
+ readonly id: {
3429
+ readonly type: "string";
3430
+ readonly pattern: "^[a-zA-Z][a-zA-Z0-9_]{0,63}$";
3431
+ };
3432
+ readonly type: {
3433
+ readonly type: "string";
3434
+ readonly enum: readonly ["text", "textarea", "number", "select", "multiselect", "boolean", "date", "date_range"];
3435
+ };
3436
+ readonly label: {
3437
+ readonly type: "string";
3438
+ readonly minLength: 1;
3439
+ readonly maxLength: 160;
3440
+ };
3441
+ readonly description: {
3442
+ readonly type: "string";
3443
+ readonly maxLength: 2000;
3444
+ };
3445
+ readonly required: {
3446
+ readonly type: "boolean";
3447
+ };
3448
+ readonly options: {
3449
+ readonly type: "array";
3450
+ readonly minItems: 1;
3451
+ readonly maxItems: 100;
3452
+ readonly items: {
3453
+ readonly type: "object";
3454
+ readonly additionalProperties: false;
3455
+ readonly required: readonly ["value", "label"];
3456
+ readonly properties: {
3457
+ readonly value: {
3458
+ readonly type: "string";
3459
+ readonly minLength: 1;
3460
+ readonly maxLength: 160;
3461
+ };
3462
+ readonly label: {
3463
+ readonly type: "string";
3464
+ readonly minLength: 1;
3465
+ readonly maxLength: 160;
3466
+ };
3467
+ };
3468
+ };
3469
+ };
3470
+ readonly min: {
3471
+ readonly type: "number";
3472
+ };
3473
+ readonly max: {
3474
+ readonly type: "number";
3475
+ };
3476
+ readonly minLength: {
3477
+ readonly type: "integer";
3478
+ readonly minimum: 0;
3479
+ readonly maximum: 100000;
3480
+ };
3481
+ readonly maxLength: {
3482
+ readonly type: "integer";
3483
+ readonly minimum: 0;
3484
+ readonly maximum: 100000;
3485
+ };
3486
+ readonly minItems: {
3487
+ readonly type: "integer";
3488
+ readonly minimum: 0;
3489
+ readonly maximum: 100;
3490
+ };
3491
+ readonly maxItems: {
3492
+ readonly type: "integer";
3493
+ readonly minimum: 0;
3494
+ readonly maximum: 100;
3495
+ };
3496
+ };
3497
+ };
3498
+ };
3499
+ };
3500
+ };
3501
+
3502
+ export declare const USER_INPUT_SUPPORTED_MODES: readonly UserInputMode[];
3503
+
3504
+ export declare type UserInputAnswerDeliveryStatus = 'queued' | 'applied' | 'failed';
3505
+
3506
+ export declare interface UserInputField {
3507
+ id: string;
3508
+ type: 'text' | 'textarea' | 'number' | 'select' | 'multiselect' | 'boolean' | 'date' | 'date_range';
3509
+ label: string;
3510
+ description?: string;
3511
+ required?: boolean;
3512
+ options?: {
3513
+ value: string;
3514
+ label: string;
3515
+ }[];
3516
+ min?: number;
3517
+ max?: number;
3518
+ minLength?: number;
3519
+ maxLength?: number;
3520
+ minItems?: number;
3521
+ maxItems?: number;
3522
+ }
3523
+
3524
+ /** Versioned input collection. Non-blocking delivery is reserved, not enabled. */
3525
+ export declare type UserInputMode = 'blocking' | 'non_blocking';
3526
+
3527
+ export declare type UserInputRequestStatus = 'pending' | 'answered' | 'cancelled' | 'superseded' | 'expired';
3528
+
3529
+ /** Future async replies are human messages, never a second tool result. */
3530
+ export declare interface UserInputResponseMetadata {
3531
+ kind: 'user_input_response';
3532
+ requestId: string;
3533
+ schemaVersion: 1;
3534
+ answers: UserInputValues;
3535
+ }
3536
+
3537
+ export declare type UserInputValidation = {
3538
+ valid: true;
3539
+ values: UserInputValues;
3540
+ } | {
3541
+ valid: false;
3542
+ errors: {
3543
+ [fieldId: string]: UserInputValidationError;
3544
+ };
3545
+ };
3546
+
3547
+ export declare type UserInputValidationError = 'required' | 'type' | 'range' | 'choice' | 'length' | 'date' | 'unknown';
3548
+
3549
+ export declare type UserInputValue = string | number | boolean | string[] | {
3550
+ start: string;
3551
+ end: string;
3552
+ };
3553
+
3554
+ export declare type UserInputValues = {
3555
+ [fieldId: string]: UserInputValue;
3556
+ };
3557
+
3374
3558
  export declare type UserMessageContent = unknown;
3375
3559
 
3560
+ export declare function validateUserInputValues(form: RequestUserInputForm, input: unknown): UserInputValidation;
3561
+
3376
3562
  export declare type WidgetComponent = TextComponent | Title | Caption | Badge | Markdown | Box | Row | Col | Divider | Icon | Image_2 | Button | Checkbox | Spacer | Select | DatePicker | Form | Input | Label | RadioGroup | Textarea | Transition;
3377
3563
 
3378
3564
  export declare type WidgetIcon = 'agent' | 'analytics' | 'atom' | 'batch' | 'bolt' | 'book-open' | 'book-closed' | 'book-clock' | 'bug' | 'calendar' | 'chart' | 'check' | 'check-circle' | 'check-circle-filled' | 'chevron-left' | 'chevron-right' | 'circle-question' | 'compass' | 'confetti' | 'cube' | 'desktop' | 'document' | 'dot' | 'dots-horizontal' | 'dots-vertical' | 'empty-circle' | 'external-link' | 'globe' | 'keys' | 'lab' | 'images' | 'info' | 'lifesaver' | 'lightbulb' | 'mail' | 'map-pin' | 'maps' | 'mobile' | 'name' | 'notebook' | 'notebook-pencil' | 'page-blank' | 'phone' | 'play' | 'plus' | 'profile' | 'profile-card' | 'reload' | 'star' | 'star-filled' | 'search' | 'sparkle' | 'sparkle-double' | 'square-code' | 'square-image' | 'square-text' | 'suitcase' | 'settings-slider' | 'user' | 'wreath' | 'write' | 'write-alt' | 'write-alt2';
package/dist/index.js CHANGED
@@ -241,6 +241,195 @@ function isHITLReviewDisplay(value) {
241
241
  }
242
242
  });
243
243
  }
244
+ const USER_INPUT_SUPPORTED_MODES = [
245
+ "blocking"
246
+ ];
247
+ const USER_INPUT_FORM_SCHEMA = {
248
+ type: "object",
249
+ additionalProperties: false,
250
+ required: ["schemaVersion", "mode", "purpose", "title", "fields"],
251
+ properties: {
252
+ schemaVersion: { type: "integer", const: 1 },
253
+ mode: { type: "string", enum: ["blocking"] },
254
+ purpose: { type: "string", const: "clarification" },
255
+ title: { type: "string", minLength: 1, maxLength: 160 },
256
+ description: { type: "string", maxLength: 2e3 },
257
+ fields: {
258
+ type: "array",
259
+ minItems: 1,
260
+ maxItems: 12,
261
+ items: {
262
+ type: "object",
263
+ additionalProperties: false,
264
+ required: ["id", "type", "label"],
265
+ properties: {
266
+ id: { type: "string", pattern: "^[a-zA-Z][a-zA-Z0-9_]{0,63}$" },
267
+ type: {
268
+ type: "string",
269
+ enum: [
270
+ "text",
271
+ "textarea",
272
+ "number",
273
+ "select",
274
+ "multiselect",
275
+ "boolean",
276
+ "date",
277
+ "date_range"
278
+ ]
279
+ },
280
+ label: { type: "string", minLength: 1, maxLength: 160 },
281
+ description: { type: "string", maxLength: 2e3 },
282
+ required: { type: "boolean" },
283
+ options: {
284
+ type: "array",
285
+ minItems: 1,
286
+ maxItems: 100,
287
+ items: {
288
+ type: "object",
289
+ additionalProperties: false,
290
+ required: ["value", "label"],
291
+ properties: {
292
+ value: { type: "string", minLength: 1, maxLength: 160 },
293
+ label: { type: "string", minLength: 1, maxLength: 160 }
294
+ }
295
+ }
296
+ },
297
+ min: { type: "number" },
298
+ max: { type: "number" },
299
+ minLength: { type: "integer", minimum: 0, maximum: 1e5 },
300
+ maxLength: { type: "integer", minimum: 0, maximum: 1e5 },
301
+ minItems: { type: "integer", minimum: 0, maximum: 100 },
302
+ maxItems: { type: "integer", minimum: 0, maximum: 100 }
303
+ }
304
+ }
305
+ }
306
+ }
307
+ };
308
+ function boundedText(value, max) {
309
+ return typeof value === "string" && value.trim().length > 0 && value.length <= max;
310
+ }
311
+ function isOption(value) {
312
+ return typeof value === "object" && value !== null && "value" in value && boundedText(value.value, 160) && "label" in value && boundedText(value.label, 160) && Object.keys(value).every((key) => key === "value" || key === "label");
313
+ }
314
+ function isField(value) {
315
+ if (!value || typeof value !== "object" || !("id" in value) || typeof value.id !== "string" || !/^[a-zA-Z][a-zA-Z0-9_]{0,63}$/.test(value.id) || ["constructor", "prototype", "__proto__"].includes(value.id) || !("type" in value) || typeof value.type !== "string" || ![
316
+ "text",
317
+ "textarea",
318
+ "number",
319
+ "select",
320
+ "multiselect",
321
+ "boolean",
322
+ "date",
323
+ "date_range"
324
+ ].includes(value.type) || !("label" in value) || !boundedText(value.label, 160))
325
+ return false;
326
+ if (Object.keys(value).some(
327
+ (key) => !Object.hasOwn(
328
+ USER_INPUT_FORM_SCHEMA.properties.fields.items.properties,
329
+ key
330
+ )
331
+ ))
332
+ return false;
333
+ if ("description" in value && (typeof value.description !== "string" || value.description.length > 2e3))
334
+ return false;
335
+ if ("required" in value && typeof value.required !== "boolean") return false;
336
+ if ("options" in value && (!Array.isArray(value.options) || value.options.length < 1 || value.options.length > 100 || !value.options.every(isOption) || new Set(value.options.map((option) => option.value)).size !== value.options.length))
337
+ return false;
338
+ if ((value.type === "select" || value.type === "multiselect") !== "options" in value)
339
+ return false;
340
+ for (const [key, limit] of [
341
+ ["minLength", 1e5],
342
+ ["maxLength", 1e5],
343
+ ["minItems", 100],
344
+ ["maxItems", 100]
345
+ ]) {
346
+ if (key in value) {
347
+ const bound = Reflect.get(value, key);
348
+ if (typeof bound !== "number" || !Number.isInteger(bound) || bound < 0 || bound > limit)
349
+ return false;
350
+ if (key === "minItems" || key === "maxItems" ? value.type !== "multiselect" : !["text", "textarea"].includes(value.type))
351
+ return false;
352
+ }
353
+ }
354
+ for (const key of ["min", "max"]) {
355
+ if (key in value && (value.type !== "number" || typeof Reflect.get(value, key) !== "number" || !Number.isFinite(Reflect.get(value, key))))
356
+ return false;
357
+ }
358
+ for (const [min, max] of [
359
+ ["min", "max"],
360
+ ["minLength", "maxLength"],
361
+ ["minItems", "maxItems"]
362
+ ]) {
363
+ if (min in value && max in value && Reflect.get(value, min) > Reflect.get(value, max))
364
+ return false;
365
+ }
366
+ return true;
367
+ }
368
+ function isRequestUserInputForm(value) {
369
+ return !!value && typeof value === "object" && "schemaVersion" in value && value.schemaVersion === 1 && "mode" in value && (value.mode === "blocking" || value.mode === "non_blocking") && "purpose" in value && value.purpose === "clarification" && "title" in value && boundedText(value.title, 160) && (!("description" in value) || typeof value.description === "string" && value.description.length <= 2e3) && "fields" in value && Array.isArray(value.fields) && value.fields.length > 0 && value.fields.length <= 12 && value.fields.every(isField) && new Set(value.fields.map((field) => field.id)).size === value.fields.length && Object.keys(value).every(
370
+ (key) => Object.hasOwn(USER_INPUT_FORM_SCHEMA.properties, key)
371
+ );
372
+ }
373
+ function isInputDate(value) {
374
+ if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value))
375
+ return false;
376
+ const date = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
377
+ return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value;
378
+ }
379
+ function validateField(field, value) {
380
+ var _a;
381
+ if (value === void 0 || value === "")
382
+ return field.required ? "required" : null;
383
+ if (Array.isArray(value) && value.length === 0 && field.required)
384
+ return "required";
385
+ switch (field.type) {
386
+ case "text":
387
+ case "textarea":
388
+ if (typeof value !== "string") return "type";
389
+ if (field.required && !value.trim()) return "required";
390
+ return value.length < (field.minLength ?? 0) || value.length > (field.maxLength ?? 1e5) ? "length" : null;
391
+ case "number":
392
+ if (typeof value !== "number" || !Number.isFinite(value)) return "type";
393
+ return value < (field.min ?? -Infinity) || value > (field.max ?? Infinity) ? "range" : null;
394
+ case "boolean":
395
+ return typeof value === "boolean" ? null : "type";
396
+ case "select":
397
+ return typeof value === "string" && ((_a = field.options) == null ? void 0 : _a.some((option) => option.value === value)) ? null : "choice";
398
+ case "multiselect":
399
+ if (!Array.isArray(value) || value.some(
400
+ (item) => {
401
+ var _a2;
402
+ return typeof item !== "string" || !((_a2 = field.options) == null ? void 0 : _a2.some((option) => option.value === item));
403
+ }
404
+ ) || new Set(value).size !== value.length)
405
+ return "choice";
406
+ return value.length < (field.minItems ?? 0) || value.length > (field.maxItems ?? 100) ? "length" : null;
407
+ case "date":
408
+ return isInputDate(value) ? null : "date";
409
+ case "date_range":
410
+ if (!value || typeof value !== "object" || !("start" in value) || !("end" in value) || !isInputDate(value.start) || !isInputDate(value.end) || Object.keys(value).some((key) => key !== "start" && key !== "end"))
411
+ return "date";
412
+ return value.start <= value.end ? null : "range";
413
+ }
414
+ }
415
+ function validateUserInputValues(form, input) {
416
+ if (!input || typeof input !== "object" || Array.isArray(input))
417
+ return { valid: false, errors: { _form: "type" } };
418
+ const errors = {};
419
+ const values = {};
420
+ for (const key of Object.keys(input)) {
421
+ if (!form.fields.some((field) => field.id === key))
422
+ return { valid: false, errors: { _form: "unknown" } };
423
+ }
424
+ for (const field of form.fields) {
425
+ const value = Object.hasOwn(input, field.id) ? Reflect.get(input, field.id) : void 0;
426
+ const error = validateField(field, value);
427
+ if (error) errors[field.id] = error;
428
+ else if (value !== void 0 && value !== "")
429
+ values[field.id] = value;
430
+ }
431
+ return Object.keys(errors).length ? { valid: false, errors } : { valid: true, values };
432
+ }
244
433
  const REQUEST_USER_INPUT_TOOL_NAME = "request_user_input";
245
434
  const REQUEST_USER_INPUT_RESULT_TYPE = "request_user_input_result";
246
435
  const REQUEST_USER_INPUT_RESULT_PURPOSE_PLAN_CLARIFICATION = "plan_clarification";
@@ -1253,6 +1442,8 @@ export {
1253
1442
  STATE_VARIABLE_HUMAN,
1254
1443
  TOOL_OUTPUT_PRESENTATION_TYPE,
1255
1444
  TOOL_OUTPUT_PRESENTATION_VERSION,
1445
+ USER_INPUT_FORM_SCHEMA,
1446
+ USER_INPUT_SUPPORTED_MODES,
1256
1447
  chatSkillUsageKey,
1257
1448
  clampPetPosition,
1258
1449
  countFileChangeLines,
@@ -1279,10 +1470,12 @@ export {
1279
1470
  isHITLInterruptTask,
1280
1471
  isHITLRequest,
1281
1472
  isHITLReviewDisplay,
1473
+ isInputDate,
1282
1474
  isInterruptRequest,
1283
1475
  isLangGraphInterrupt,
1284
1476
  isLangGraphInterruptPayload,
1285
1477
  isLangGraphInterruptTask,
1478
+ isRequestUserInputForm,
1286
1479
  isResourceCardContent,
1287
1480
  isToolCallInterrupt,
1288
1481
  isToolCallInterruptPayload,
@@ -1311,6 +1504,7 @@ export {
1311
1504
  resolvePetCharacter,
1312
1505
  resourceCardId,
1313
1506
  upsertFileActivityContent,
1314
- upsertResourceCardContent
1507
+ upsertResourceCardContent,
1508
+ validateUserInputValues
1315
1509
  };
1316
1510
  //# sourceMappingURL=index.js.map