@xpert-ai/chatkit-types 0.11.2 → 0.12.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.
- package/dist/index.cjs +107 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +74 -4
- package/dist/index.js +107 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -514,6 +514,25 @@ export declare interface ChatkitMessage {
|
|
|
514
514
|
visibleAt?: string | Date | null;
|
|
515
515
|
}
|
|
516
516
|
|
|
517
|
+
/**
|
|
518
|
+
* A Web Component that serves as the entry point for a ChatKit integration.
|
|
519
|
+
* * @noInheritDoc
|
|
520
|
+
*/
|
|
521
|
+
export declare type ChatKitMessageFocusRequest = {
|
|
522
|
+
conversationId: string;
|
|
523
|
+
threadId: string;
|
|
524
|
+
messageId: string;
|
|
525
|
+
};
|
|
526
|
+
|
|
527
|
+
export declare type ChatKitMessageFocusResult = {
|
|
528
|
+
success: true;
|
|
529
|
+
status: 'opened';
|
|
530
|
+
} | {
|
|
531
|
+
success: false;
|
|
532
|
+
code: string;
|
|
533
|
+
message?: string;
|
|
534
|
+
};
|
|
535
|
+
|
|
517
536
|
export declare type ChatKitMessageNavigationOptions = {
|
|
518
537
|
/**
|
|
519
538
|
* Whether to show the message quick navigation rail.
|
|
@@ -1088,6 +1107,12 @@ export declare type ChatKitThreadReference = {
|
|
|
1088
1107
|
};
|
|
1089
1108
|
|
|
1090
1109
|
export declare type ChatKitWorkbenchClientCommandRequest = {
|
|
1110
|
+
/**
|
|
1111
|
+
* Browser activation snapshot taken by the ChatKit shell, never from plugin input.
|
|
1112
|
+
* Hosts still validate command permissions and payloads; this is not authorization.
|
|
1113
|
+
* Absent when an older shell does not provide activation context.
|
|
1114
|
+
*/
|
|
1115
|
+
userActivated?: boolean;
|
|
1091
1116
|
/** User-clicked persisted resource; hosts resolve its canonical target from message history. */
|
|
1092
1117
|
resourceCard?: {
|
|
1093
1118
|
messageId: string;
|
|
@@ -1479,6 +1504,8 @@ export declare interface ConversationResourceCard {
|
|
|
1479
1504
|
title: string;
|
|
1480
1505
|
description?: string;
|
|
1481
1506
|
icon?: IconDefinition;
|
|
1507
|
+
/** Ordered content blocks; unknown kinds degrade to the base resource card. */
|
|
1508
|
+
content?: ResourceCardContent[];
|
|
1482
1509
|
open: ResourceCardOpenTarget;
|
|
1483
1510
|
}
|
|
1484
1511
|
|
|
@@ -2380,8 +2407,48 @@ export declare function resolveLocalizedText(value: unknown, language?: string):
|
|
|
2380
2407
|
|
|
2381
2408
|
export declare function resolvePetCharacter(character: ChatKitPetCharacter): ResolvedPetCharacter | null;
|
|
2382
2409
|
|
|
2410
|
+
/** Ordered presentation blocks, independent of the business resource's type. */
|
|
2411
|
+
export declare type ResourceCardContent = {
|
|
2412
|
+
title?: string;
|
|
2413
|
+
} & ({
|
|
2414
|
+
kind: 'image-gallery';
|
|
2415
|
+
images: ResourceCardImage[];
|
|
2416
|
+
} | {
|
|
2417
|
+
kind: 'file-list';
|
|
2418
|
+
files: ResourceCardFile[];
|
|
2419
|
+
} | {
|
|
2420
|
+
kind: 'fields';
|
|
2421
|
+
fields: ResourceCardField[];
|
|
2422
|
+
});
|
|
2423
|
+
|
|
2424
|
+
export declare interface ResourceCardField {
|
|
2425
|
+
label: string;
|
|
2426
|
+
value: string;
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
export declare interface ResourceCardFile {
|
|
2430
|
+
id: string;
|
|
2431
|
+
title: string;
|
|
2432
|
+
description?: string;
|
|
2433
|
+
file: ResourceCardFileReference;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
/** Stable provider references; credentials, temporary URLs and bytes never enter messages. */
|
|
2437
|
+
export declare interface ResourceCardFileReference {
|
|
2438
|
+
viewKey: string;
|
|
2439
|
+
fileKey: string;
|
|
2440
|
+
targetId: string;
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2383
2443
|
export declare function resourceCardId(card: ConversationResourceCard): string;
|
|
2384
2444
|
|
|
2445
|
+
export declare interface ResourceCardImage {
|
|
2446
|
+
id: string;
|
|
2447
|
+
title: string;
|
|
2448
|
+
alt?: string;
|
|
2449
|
+
file: ResourceCardFileReference;
|
|
2450
|
+
}
|
|
2451
|
+
|
|
2385
2452
|
export declare type ResourceCardOpenTarget = {
|
|
2386
2453
|
viewKey: string;
|
|
2387
2454
|
selectionId?: string;
|
|
@@ -2391,6 +2458,11 @@ export declare type ResourceCardOpenTarget = {
|
|
|
2391
2458
|
} | {
|
|
2392
2459
|
target: 'assistant.project';
|
|
2393
2460
|
projectId: string;
|
|
2461
|
+
} | {
|
|
2462
|
+
target: 'workbench.file';
|
|
2463
|
+
fileKey: string;
|
|
2464
|
+
targetId: string;
|
|
2465
|
+
previewFile?: ResourceCardFileReference;
|
|
2394
2466
|
});
|
|
2395
2467
|
|
|
2396
2468
|
export declare type ResourceCardScalar = string | number | boolean | null;
|
|
@@ -3276,10 +3348,6 @@ export declare type WorkspaceConnectorConnectResult = {
|
|
|
3276
3348
|
status: 'connected' | 'cancelled';
|
|
3277
3349
|
};
|
|
3278
3350
|
|
|
3279
|
-
/**
|
|
3280
|
-
* A Web Component that serves as the entry point for a ChatKit integration.
|
|
3281
|
-
* * @noInheritDoc
|
|
3282
|
-
*/
|
|
3283
3351
|
export declare interface XpertAIChatKit extends HTMLElement {
|
|
3284
3352
|
/**
|
|
3285
3353
|
* Applies configuration options to the ChatKit instance.
|
|
@@ -3291,6 +3359,8 @@ export declare interface XpertAIChatKit extends HTMLElement {
|
|
|
3291
3359
|
focusComposer(): Promise<void>;
|
|
3292
3360
|
/** Changes the active thread. Pass `null` to switch to a new thread. */
|
|
3293
3361
|
setThreadId(threadId: string | null): Promise<void>;
|
|
3362
|
+
/** Locate an authorized message in the active branch, loading older history when necessary. */
|
|
3363
|
+
focusMessage(request: ChatKitMessageFocusRequest): Promise<ChatKitMessageFocusResult>;
|
|
3294
3364
|
/**
|
|
3295
3365
|
* Sends a custom application-defined action to your backend.
|
|
3296
3366
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,88 @@
|
|
|
1
1
|
import { CHAT_EVENT_TYPE_FOLLOW_UP_CONSUMED, ChatMessageEventTypeEnum, ChatMessageStepCategory, ChatMessageTypeEnum, STATE_VARIABLE_HUMAN } from "./constants.js";
|
|
2
2
|
import "@langchain/core/messages/tool";
|
|
3
|
+
function nonempty$1(value) {
|
|
4
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
5
|
+
}
|
|
6
|
+
function parseFileReference(value) {
|
|
7
|
+
if (!value || typeof value !== "object" || !("viewKey" in value) || !nonempty$1(value.viewKey) || !("fileKey" in value) || !nonempty$1(value.fileKey) || !("targetId" in value) || !nonempty$1(value.targetId) || Object.keys(value).some(
|
|
8
|
+
(key) => !["viewKey", "fileKey", "targetId"].includes(key)
|
|
9
|
+
))
|
|
10
|
+
return null;
|
|
11
|
+
return {
|
|
12
|
+
viewKey: value.viewKey,
|
|
13
|
+
fileKey: value.fileKey,
|
|
14
|
+
targetId: value.targetId
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function parseFile(value) {
|
|
18
|
+
if (!value || typeof value !== "object" || !("id" in value) || !nonempty$1(value.id) || !("title" in value) || !nonempty$1(value.title) || !("file" in value) || "description" in value && typeof value.description !== "string")
|
|
19
|
+
return null;
|
|
20
|
+
const file = parseFileReference(value.file);
|
|
21
|
+
if (!file) return null;
|
|
22
|
+
return {
|
|
23
|
+
id: value.id,
|
|
24
|
+
title: value.title,
|
|
25
|
+
file,
|
|
26
|
+
..."description" in value && typeof value.description === "string" ? { description: value.description } : {}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function parseImage(value) {
|
|
30
|
+
const item = parseFile(value);
|
|
31
|
+
if (!item || !value || typeof value !== "object" || "alt" in value && typeof value.alt !== "string")
|
|
32
|
+
return null;
|
|
33
|
+
return {
|
|
34
|
+
id: item.id,
|
|
35
|
+
title: item.title,
|
|
36
|
+
file: item.file,
|
|
37
|
+
..."alt" in value && typeof value.alt === "string" ? { alt: value.alt } : {}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function parseField(value) {
|
|
41
|
+
if (!value || typeof value !== "object" || !("label" in value) || !nonempty$1(value.label) || !("value" in value) || typeof value.value !== "string")
|
|
42
|
+
return null;
|
|
43
|
+
return { label: value.label, value: value.value };
|
|
44
|
+
}
|
|
45
|
+
function parseItems(value, parse) {
|
|
46
|
+
if (!Array.isArray(value) || value.length > 100) return null;
|
|
47
|
+
const items = [];
|
|
48
|
+
for (const raw of value) {
|
|
49
|
+
const item = parse(raw);
|
|
50
|
+
if (!item) return null;
|
|
51
|
+
items.push(item);
|
|
52
|
+
}
|
|
53
|
+
return items;
|
|
54
|
+
}
|
|
55
|
+
function distinctIds(items) {
|
|
56
|
+
return new Set(items.map((item) => item.id)).size === items.length;
|
|
57
|
+
}
|
|
58
|
+
function parseBlock(value) {
|
|
59
|
+
if (!value || typeof value !== "object" || !("kind" in value) || "title" in value && typeof value.title !== "string")
|
|
60
|
+
return null;
|
|
61
|
+
const title = "title" in value && typeof value.title === "string" ? { title: value.title } : {};
|
|
62
|
+
switch (value.kind) {
|
|
63
|
+
case "image-gallery": {
|
|
64
|
+
const images = "images" in value ? parseItems(value.images, parseImage) : null;
|
|
65
|
+
return (images == null ? void 0 : images.length) && distinctIds(images) ? { kind: "image-gallery", ...title, images } : null;
|
|
66
|
+
}
|
|
67
|
+
case "file-list": {
|
|
68
|
+
const files = "files" in value ? parseItems(value.files, parseFile) : null;
|
|
69
|
+
return (files == null ? void 0 : files.length) && distinctIds(files) ? { kind: "file-list", ...title, files } : null;
|
|
70
|
+
}
|
|
71
|
+
case "fields": {
|
|
72
|
+
const fields = "fields" in value ? parseItems(value.fields, parseField) : null;
|
|
73
|
+
return (fields == null ? void 0 : fields.length) ? { kind: "fields", ...title, fields } : null;
|
|
74
|
+
}
|
|
75
|
+
default:
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function parseResourceCardBlocks(value) {
|
|
80
|
+
if (!Array.isArray(value)) return [];
|
|
81
|
+
return value.slice(0, 32).flatMap((item) => {
|
|
82
|
+
const block = parseBlock(item);
|
|
83
|
+
return block ? [block] : [];
|
|
84
|
+
});
|
|
85
|
+
}
|
|
3
86
|
function resourceCardId(card) {
|
|
4
87
|
return JSON.stringify([
|
|
5
88
|
card.resource.namespace,
|
|
@@ -21,7 +104,7 @@ function parseResourceCard(value) {
|
|
|
21
104
|
return null;
|
|
22
105
|
if ("artifactId" in resource && !nonempty(resource.artifactId)) return null;
|
|
23
106
|
const open = value.open;
|
|
24
|
-
if (!open || typeof open !== "object" || !("target" in open) || open.target !== "workbench.view" && open.target !== "assistant.project" || !("viewKey" in open) || !nonempty(open.viewKey))
|
|
107
|
+
if (!open || typeof open !== "object" || !("target" in open) || open.target !== "workbench.view" && open.target !== "assistant.project" && open.target !== "workbench.file" || !("viewKey" in open) || !nonempty(open.viewKey))
|
|
25
108
|
return null;
|
|
26
109
|
if (Object.keys(open).some(
|
|
27
110
|
(key) => ![
|
|
@@ -29,7 +112,10 @@ function parseResourceCard(value) {
|
|
|
29
112
|
"viewKey",
|
|
30
113
|
"selectionId",
|
|
31
114
|
"parameters",
|
|
32
|
-
"projectId"
|
|
115
|
+
"projectId",
|
|
116
|
+
"fileKey",
|
|
117
|
+
"targetId",
|
|
118
|
+
"previewFile"
|
|
33
119
|
].includes(key)
|
|
34
120
|
))
|
|
35
121
|
return null;
|
|
@@ -52,7 +138,21 @@ function parseResourceCard(value) {
|
|
|
52
138
|
..."parameters" in open ? { parameters } : {}
|
|
53
139
|
};
|
|
54
140
|
let target;
|
|
55
|
-
if (open.target === "
|
|
141
|
+
if (open.target === "workbench.file") {
|
|
142
|
+
if ("projectId" in open || "selectionId" in open || "parameters" in open || !("fileKey" in open) || !nonempty(open.fileKey) || !("targetId" in open) || !nonempty(open.targetId))
|
|
143
|
+
return null;
|
|
144
|
+
const previewFile = "previewFile" in open ? parseFileReference(open.previewFile) : void 0;
|
|
145
|
+
if (previewFile === null) return null;
|
|
146
|
+
target = {
|
|
147
|
+
viewKey: open.viewKey,
|
|
148
|
+
target: "workbench.file",
|
|
149
|
+
fileKey: open.fileKey,
|
|
150
|
+
targetId: open.targetId,
|
|
151
|
+
...previewFile ? { previewFile } : {}
|
|
152
|
+
};
|
|
153
|
+
} else if ("fileKey" in open || "targetId" in open || "previewFile" in open) {
|
|
154
|
+
return null;
|
|
155
|
+
} else if (open.target === "assistant.project") {
|
|
56
156
|
if (!("projectId" in open) || !nonempty(open.projectId)) return null;
|
|
57
157
|
target = {
|
|
58
158
|
...common,
|
|
@@ -65,6 +165,9 @@ function parseResourceCard(value) {
|
|
|
65
165
|
}
|
|
66
166
|
if ("description" in value && typeof value.description !== "string")
|
|
67
167
|
return null;
|
|
168
|
+
const content = parseResourceCardBlocks(
|
|
169
|
+
"content" in value ? value.content : "images" in value ? [{ kind: "image-gallery", images: value.images }] : []
|
|
170
|
+
);
|
|
68
171
|
let icon;
|
|
69
172
|
if ("icon" in value) {
|
|
70
173
|
const candidate = value.icon;
|
|
@@ -84,6 +187,7 @@ function parseResourceCard(value) {
|
|
|
84
187
|
title: value.title,
|
|
85
188
|
..."description" in value ? { description: value.description } : {},
|
|
86
189
|
...icon ? { icon } : {},
|
|
190
|
+
...content.length ? { content } : {},
|
|
87
191
|
open: target
|
|
88
192
|
};
|
|
89
193
|
}
|