@xpert-ai/chatkit-types 0.19.1 → 0.20.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.
- package/dist/index.cjs +194 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +203 -2
- package/dist/index.js +195 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -418,8 +418,18 @@ export declare type ChatKitEvents = {
|
|
|
418
418
|
threadId: string;
|
|
419
419
|
}>;
|
|
420
420
|
/** Emitted when ChatKit finished loading a thread. */
|
|
421
|
+
/** Metadata for the loaded branch; excludes messages, resources and execution internals. */
|
|
421
422
|
'chatkit.thread.load.end': CustomEvent<{
|
|
422
423
|
threadId: string;
|
|
424
|
+
conversation?: {
|
|
425
|
+
id: string;
|
|
426
|
+
threadId: string;
|
|
427
|
+
title?: string;
|
|
428
|
+
projectId?: string;
|
|
429
|
+
xpertId?: string;
|
|
430
|
+
from?: string;
|
|
431
|
+
status?: 'idle' | 'busy' | 'pausing' | 'paused' | 'interrupted' | 'error';
|
|
432
|
+
};
|
|
423
433
|
}>;
|
|
424
434
|
/** Diagnostic events that can be used for logging/analytics. */
|
|
425
435
|
'chatkit.log': CustomEvent<{
|
|
@@ -696,6 +706,11 @@ export declare type ChatKitOptions = {
|
|
|
696
706
|
*/
|
|
697
707
|
header?: {
|
|
698
708
|
enabled?: boolean;
|
|
709
|
+
/** Inline avatar, title, and status block. Hidden by default; separate from the centered character. */
|
|
710
|
+
identity?: {
|
|
711
|
+
/** Show the identity block when the centered character is not displayed. Defaults to false. */
|
|
712
|
+
enabled?: boolean;
|
|
713
|
+
};
|
|
699
714
|
/** Center the published Assistant character in bubble mode. Defaults to true. */
|
|
700
715
|
character?: {
|
|
701
716
|
enabled?: boolean;
|
|
@@ -2083,6 +2098,8 @@ export declare function isHITLRequest(value: unknown): value is HITLRequest;
|
|
|
2083
2098
|
|
|
2084
2099
|
export declare function isHITLReviewDisplay(value: unknown): value is HITLReviewDisplay;
|
|
2085
2100
|
|
|
2101
|
+
export declare function isInputDate(value: unknown): value is string;
|
|
2102
|
+
|
|
2086
2103
|
export declare function isInterruptRequest(value: unknown): value is InterruptRequest;
|
|
2087
2104
|
|
|
2088
2105
|
export declare function isLangGraphInterrupt(value: unknown): value is LangGraphInterrupt;
|
|
@@ -2091,6 +2108,8 @@ export declare function isLangGraphInterruptPayload(value: unknown): value is La
|
|
|
2091
2108
|
|
|
2092
2109
|
export declare function isLangGraphInterruptTask(value: unknown): value is LangGraphInterruptTask;
|
|
2093
2110
|
|
|
2111
|
+
export declare function isRequestUserInputForm(value: unknown): value is RequestUserInputForm;
|
|
2112
|
+
|
|
2094
2113
|
export declare function isResourceCardContent(value: unknown): boolean;
|
|
2095
2114
|
|
|
2096
2115
|
export declare function isToolCallInterrupt(value: unknown): value is ToolCallInterrupt;
|
|
@@ -2436,6 +2455,16 @@ export declare interface RequestUserInputAnswer {
|
|
|
2436
2455
|
|
|
2437
2456
|
export declare type RequestUserInputAnswerType = 'option' | 'other';
|
|
2438
2457
|
|
|
2458
|
+
export declare interface RequestUserInputForm {
|
|
2459
|
+
schemaVersion: 1;
|
|
2460
|
+
mode: UserInputMode;
|
|
2461
|
+
purpose: 'clarification';
|
|
2462
|
+
title: string;
|
|
2463
|
+
description?: string;
|
|
2464
|
+
fields: UserInputField[];
|
|
2465
|
+
questions?: never;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2439
2468
|
export declare interface RequestUserInputOption {
|
|
2440
2469
|
label: string;
|
|
2441
2470
|
description: string;
|
|
@@ -2456,13 +2485,18 @@ export declare interface RequestUserInputResult {
|
|
|
2456
2485
|
type: RequestUserInputResultType;
|
|
2457
2486
|
purpose: RequestUserInputResultPurpose;
|
|
2458
2487
|
answers: RequestUserInputAnswer[];
|
|
2488
|
+
status?: 'submitted' | 'cancelled';
|
|
2489
|
+
schemaVersion?: 1;
|
|
2490
|
+
requestId?: string;
|
|
2491
|
+
values?: UserInputValues;
|
|
2492
|
+
form?: RequestUserInputForm;
|
|
2459
2493
|
}
|
|
2460
2494
|
|
|
2461
|
-
export declare type RequestUserInputResultPurpose = typeof REQUEST_USER_INPUT_RESULT_PURPOSE_PLAN_CLARIFICATION | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_IMPLEMENTATION_CONFIRMATION;
|
|
2495
|
+
export declare type RequestUserInputResultPurpose = 'clarification' | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_PLAN_CLARIFICATION | typeof REQUEST_USER_INPUT_RESULT_PURPOSE_IMPLEMENTATION_CONFIRMATION;
|
|
2462
2496
|
|
|
2463
2497
|
export declare type RequestUserInputResultType = typeof REQUEST_USER_INPUT_RESULT_TYPE;
|
|
2464
2498
|
|
|
2465
|
-
export declare type RequestUserInputToolArgs = RequestUserInputParams;
|
|
2499
|
+
export declare type RequestUserInputToolArgs = RequestUserInputParams | RequestUserInputForm;
|
|
2466
2500
|
|
|
2467
2501
|
export declare type RequestUserInputToolCall = ToolCall & {
|
|
2468
2502
|
name: RequestUserInputToolName;
|
|
@@ -3371,8 +3405,175 @@ export declare function upsertFileActivityContent<T>(content: T[], receipt: TMes
|
|
|
3371
3405
|
/** Identity is local to one reply. Repeat emissions replace the snapshot in place. */
|
|
3372
3406
|
export declare function upsertResourceCardContent<T>(parts: T[], card: TMessageContentResourceCard): (T | TMessageContentResourceCard)[];
|
|
3373
3407
|
|
|
3408
|
+
export declare const USER_INPUT_FORM_SCHEMA: {
|
|
3409
|
+
readonly type: "object";
|
|
3410
|
+
readonly additionalProperties: false;
|
|
3411
|
+
readonly required: readonly ["schemaVersion", "mode", "purpose", "title", "fields"];
|
|
3412
|
+
readonly properties: {
|
|
3413
|
+
readonly schemaVersion: {
|
|
3414
|
+
readonly type: "integer";
|
|
3415
|
+
readonly const: 1;
|
|
3416
|
+
};
|
|
3417
|
+
readonly mode: {
|
|
3418
|
+
readonly type: "string";
|
|
3419
|
+
readonly enum: readonly ["blocking"];
|
|
3420
|
+
};
|
|
3421
|
+
readonly purpose: {
|
|
3422
|
+
readonly type: "string";
|
|
3423
|
+
readonly const: "clarification";
|
|
3424
|
+
};
|
|
3425
|
+
readonly title: {
|
|
3426
|
+
readonly type: "string";
|
|
3427
|
+
readonly minLength: 1;
|
|
3428
|
+
readonly maxLength: 160;
|
|
3429
|
+
};
|
|
3430
|
+
readonly description: {
|
|
3431
|
+
readonly type: "string";
|
|
3432
|
+
readonly maxLength: 2000;
|
|
3433
|
+
};
|
|
3434
|
+
readonly fields: {
|
|
3435
|
+
readonly type: "array";
|
|
3436
|
+
readonly minItems: 1;
|
|
3437
|
+
readonly maxItems: 12;
|
|
3438
|
+
readonly items: {
|
|
3439
|
+
readonly type: "object";
|
|
3440
|
+
readonly additionalProperties: false;
|
|
3441
|
+
readonly required: readonly ["id", "type", "label"];
|
|
3442
|
+
readonly properties: {
|
|
3443
|
+
readonly id: {
|
|
3444
|
+
readonly type: "string";
|
|
3445
|
+
readonly pattern: "^[a-zA-Z][a-zA-Z0-9_]{0,63}$";
|
|
3446
|
+
};
|
|
3447
|
+
readonly type: {
|
|
3448
|
+
readonly type: "string";
|
|
3449
|
+
readonly enum: readonly ["text", "textarea", "number", "select", "multiselect", "boolean", "date", "date_range"];
|
|
3450
|
+
};
|
|
3451
|
+
readonly label: {
|
|
3452
|
+
readonly type: "string";
|
|
3453
|
+
readonly minLength: 1;
|
|
3454
|
+
readonly maxLength: 160;
|
|
3455
|
+
};
|
|
3456
|
+
readonly description: {
|
|
3457
|
+
readonly type: "string";
|
|
3458
|
+
readonly maxLength: 2000;
|
|
3459
|
+
};
|
|
3460
|
+
readonly required: {
|
|
3461
|
+
readonly type: "boolean";
|
|
3462
|
+
};
|
|
3463
|
+
readonly options: {
|
|
3464
|
+
readonly type: "array";
|
|
3465
|
+
readonly minItems: 1;
|
|
3466
|
+
readonly maxItems: 100;
|
|
3467
|
+
readonly items: {
|
|
3468
|
+
readonly type: "object";
|
|
3469
|
+
readonly additionalProperties: false;
|
|
3470
|
+
readonly required: readonly ["value", "label"];
|
|
3471
|
+
readonly properties: {
|
|
3472
|
+
readonly value: {
|
|
3473
|
+
readonly type: "string";
|
|
3474
|
+
readonly minLength: 1;
|
|
3475
|
+
readonly maxLength: 160;
|
|
3476
|
+
};
|
|
3477
|
+
readonly label: {
|
|
3478
|
+
readonly type: "string";
|
|
3479
|
+
readonly minLength: 1;
|
|
3480
|
+
readonly maxLength: 160;
|
|
3481
|
+
};
|
|
3482
|
+
};
|
|
3483
|
+
};
|
|
3484
|
+
};
|
|
3485
|
+
readonly min: {
|
|
3486
|
+
readonly type: "number";
|
|
3487
|
+
};
|
|
3488
|
+
readonly max: {
|
|
3489
|
+
readonly type: "number";
|
|
3490
|
+
};
|
|
3491
|
+
readonly minLength: {
|
|
3492
|
+
readonly type: "integer";
|
|
3493
|
+
readonly minimum: 0;
|
|
3494
|
+
readonly maximum: 100000;
|
|
3495
|
+
};
|
|
3496
|
+
readonly maxLength: {
|
|
3497
|
+
readonly type: "integer";
|
|
3498
|
+
readonly minimum: 0;
|
|
3499
|
+
readonly maximum: 100000;
|
|
3500
|
+
};
|
|
3501
|
+
readonly minItems: {
|
|
3502
|
+
readonly type: "integer";
|
|
3503
|
+
readonly minimum: 0;
|
|
3504
|
+
readonly maximum: 100;
|
|
3505
|
+
};
|
|
3506
|
+
readonly maxItems: {
|
|
3507
|
+
readonly type: "integer";
|
|
3508
|
+
readonly minimum: 0;
|
|
3509
|
+
readonly maximum: 100;
|
|
3510
|
+
};
|
|
3511
|
+
};
|
|
3512
|
+
};
|
|
3513
|
+
};
|
|
3514
|
+
};
|
|
3515
|
+
};
|
|
3516
|
+
|
|
3517
|
+
export declare const USER_INPUT_SUPPORTED_MODES: readonly UserInputMode[];
|
|
3518
|
+
|
|
3519
|
+
export declare type UserInputAnswerDeliveryStatus = 'queued' | 'applied' | 'failed';
|
|
3520
|
+
|
|
3521
|
+
export declare interface UserInputField {
|
|
3522
|
+
id: string;
|
|
3523
|
+
type: 'text' | 'textarea' | 'number' | 'select' | 'multiselect' | 'boolean' | 'date' | 'date_range';
|
|
3524
|
+
label: string;
|
|
3525
|
+
description?: string;
|
|
3526
|
+
required?: boolean;
|
|
3527
|
+
options?: {
|
|
3528
|
+
value: string;
|
|
3529
|
+
label: string;
|
|
3530
|
+
}[];
|
|
3531
|
+
min?: number;
|
|
3532
|
+
max?: number;
|
|
3533
|
+
minLength?: number;
|
|
3534
|
+
maxLength?: number;
|
|
3535
|
+
minItems?: number;
|
|
3536
|
+
maxItems?: number;
|
|
3537
|
+
}
|
|
3538
|
+
|
|
3539
|
+
/** Versioned input collection. Non-blocking delivery is reserved, not enabled. */
|
|
3540
|
+
export declare type UserInputMode = 'blocking' | 'non_blocking';
|
|
3541
|
+
|
|
3542
|
+
export declare type UserInputRequestStatus = 'pending' | 'answered' | 'cancelled' | 'superseded' | 'expired';
|
|
3543
|
+
|
|
3544
|
+
/** Future async replies are human messages, never a second tool result. */
|
|
3545
|
+
export declare interface UserInputResponseMetadata {
|
|
3546
|
+
kind: 'user_input_response';
|
|
3547
|
+
requestId: string;
|
|
3548
|
+
schemaVersion: 1;
|
|
3549
|
+
answers: UserInputValues;
|
|
3550
|
+
}
|
|
3551
|
+
|
|
3552
|
+
export declare type UserInputValidation = {
|
|
3553
|
+
valid: true;
|
|
3554
|
+
values: UserInputValues;
|
|
3555
|
+
} | {
|
|
3556
|
+
valid: false;
|
|
3557
|
+
errors: {
|
|
3558
|
+
[fieldId: string]: UserInputValidationError;
|
|
3559
|
+
};
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3562
|
+
export declare type UserInputValidationError = 'required' | 'type' | 'range' | 'choice' | 'length' | 'date' | 'unknown';
|
|
3563
|
+
|
|
3564
|
+
export declare type UserInputValue = string | number | boolean | string[] | {
|
|
3565
|
+
start: string;
|
|
3566
|
+
end: string;
|
|
3567
|
+
};
|
|
3568
|
+
|
|
3569
|
+
export declare type UserInputValues = {
|
|
3570
|
+
[fieldId: string]: UserInputValue;
|
|
3571
|
+
};
|
|
3572
|
+
|
|
3374
3573
|
export declare type UserMessageContent = unknown;
|
|
3375
3574
|
|
|
3575
|
+
export declare function validateUserInputValues(form: RequestUserInputForm, input: unknown): UserInputValidation;
|
|
3576
|
+
|
|
3376
3577
|
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
3578
|
|
|
3378
3579
|
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
|