@xpert-ai/chatkit-types 0.11.2 → 0.12.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.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.
@@ -1479,6 +1498,8 @@ export declare interface ConversationResourceCard {
1479
1498
  title: string;
1480
1499
  description?: string;
1481
1500
  icon?: IconDefinition;
1501
+ /** Ordered content blocks; unknown kinds degrade to the base resource card. */
1502
+ content?: ResourceCardContent[];
1482
1503
  open: ResourceCardOpenTarget;
1483
1504
  }
1484
1505
 
@@ -2380,8 +2401,48 @@ export declare function resolveLocalizedText(value: unknown, language?: string):
2380
2401
 
2381
2402
  export declare function resolvePetCharacter(character: ChatKitPetCharacter): ResolvedPetCharacter | null;
2382
2403
 
2404
+ /** Ordered presentation blocks, independent of the business resource's type. */
2405
+ export declare type ResourceCardContent = {
2406
+ title?: string;
2407
+ } & ({
2408
+ kind: 'image-gallery';
2409
+ images: ResourceCardImage[];
2410
+ } | {
2411
+ kind: 'file-list';
2412
+ files: ResourceCardFile[];
2413
+ } | {
2414
+ kind: 'fields';
2415
+ fields: ResourceCardField[];
2416
+ });
2417
+
2418
+ export declare interface ResourceCardField {
2419
+ label: string;
2420
+ value: string;
2421
+ }
2422
+
2423
+ export declare interface ResourceCardFile {
2424
+ id: string;
2425
+ title: string;
2426
+ description?: string;
2427
+ file: ResourceCardFileReference;
2428
+ }
2429
+
2430
+ /** Stable provider references; credentials, temporary URLs and bytes never enter messages. */
2431
+ export declare interface ResourceCardFileReference {
2432
+ viewKey: string;
2433
+ fileKey: string;
2434
+ targetId: string;
2435
+ }
2436
+
2383
2437
  export declare function resourceCardId(card: ConversationResourceCard): string;
2384
2438
 
2439
+ export declare interface ResourceCardImage {
2440
+ id: string;
2441
+ title: string;
2442
+ alt?: string;
2443
+ file: ResourceCardFileReference;
2444
+ }
2445
+
2385
2446
  export declare type ResourceCardOpenTarget = {
2386
2447
  viewKey: string;
2387
2448
  selectionId?: string;
@@ -2391,6 +2452,11 @@ export declare type ResourceCardOpenTarget = {
2391
2452
  } | {
2392
2453
  target: 'assistant.project';
2393
2454
  projectId: string;
2455
+ } | {
2456
+ target: 'workbench.file';
2457
+ fileKey: string;
2458
+ targetId: string;
2459
+ previewFile?: ResourceCardFileReference;
2394
2460
  });
2395
2461
 
2396
2462
  export declare type ResourceCardScalar = string | number | boolean | null;
@@ -3276,10 +3342,6 @@ export declare type WorkspaceConnectorConnectResult = {
3276
3342
  status: 'connected' | 'cancelled';
3277
3343
  };
3278
3344
 
3279
- /**
3280
- * A Web Component that serves as the entry point for a ChatKit integration.
3281
- * * @noInheritDoc
3282
- */
3283
3345
  export declare interface XpertAIChatKit extends HTMLElement {
3284
3346
  /**
3285
3347
  * Applies configuration options to the ChatKit instance.
@@ -3291,6 +3353,8 @@ export declare interface XpertAIChatKit extends HTMLElement {
3291
3353
  focusComposer(): Promise<void>;
3292
3354
  /** Changes the active thread. Pass `null` to switch to a new thread. */
3293
3355
  setThreadId(threadId: string | null): Promise<void>;
3356
+ /** Locate an authorized message in the active branch, loading older history when necessary. */
3357
+ focusMessage(request: ChatKitMessageFocusRequest): Promise<ChatKitMessageFocusResult>;
3294
3358
  /**
3295
3359
  * Sends a custom application-defined action to your backend.
3296
3360
  */
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 === "assistant.project") {
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
  }