@xpert-ai/chatkit-types 0.7.0 → 0.9.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
@@ -460,6 +460,14 @@ export declare type ChatKitMessageNavigationOptions = {
460
460
  enabled?: boolean;
461
461
  };
462
462
 
463
+ /** Rendering policy only; never changes messages, execution or model context. */
464
+ export declare type ChatKitMessagePresentationOptions = {
465
+ /** Defaults to the existing transcript presentation. */
466
+ mode?: 'transcript' | 'bubbles';
467
+ /** Collapse the process before the final answer. Only applies to transcript. */
468
+ collapseProcess?: boolean;
469
+ };
470
+
463
471
  export declare type ChatKitOptions = {
464
472
  /**
465
473
  * ChatKit iframe URL for web component integrations.
@@ -513,10 +521,7 @@ export declare type ChatKitOptions = {
513
521
  */
514
522
  messageNavigation?: ChatKitMessageNavigationOptions;
515
523
  /** Message presentation only; never changes stored messages or model context. */
516
- messagePresentation?: {
517
- /** Collapse the process preceding each final assistant answer. Default: false. */
518
- collapseProcess?: boolean;
519
- };
524
+ messagePresentation?: ChatKitMessagePresentationOptions;
520
525
  /**
521
526
  * Optional Xpert Remote Views workbench.
522
527
  *
@@ -1005,6 +1010,11 @@ export declare type ChatKitThreadReference = {
1005
1010
  };
1006
1011
 
1007
1012
  export declare type ChatKitWorkbenchClientCommandRequest = {
1013
+ /** User-clicked persisted resource; hosts resolve its canonical target from message history. */
1014
+ resourceCard?: {
1015
+ messageId: string;
1016
+ id: string;
1017
+ };
1008
1018
  commandKey: string;
1009
1019
  payload?: unknown;
1010
1020
  hostType: 'agent';
@@ -1034,9 +1044,8 @@ export declare type ChatKitWorkbenchOptions = {
1034
1044
  */
1035
1045
  enabled?: boolean;
1036
1046
  /**
1037
- * Show a vertical strip of available remote-view icons at the right edge of
1038
- * chat while the workbench is closed. Clicking an icon opens that view.
1039
- * Requires `workbench.enabled`. Disabled by default.
1047
+ * @deprecated Views now open from the stacked-tabs button in the chat header.
1048
+ * This option is retained for compatibility and no longer renders a view rail.
1040
1049
  */
1041
1050
  viewRail?: {
1042
1051
  enabled?: boolean;
@@ -1375,9 +1384,25 @@ declare type ControlSize = '3xs' | '2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2
1375
1384
 
1376
1385
  declare type ControlVariant = 'solid' | 'soft' | 'outline' | 'ghost';
1377
1386
 
1387
+ /** Presentation of a committed business resource; distinct from versioned file Artifacts. */
1388
+ export declare interface ConversationResourceCard {
1389
+ resource: {
1390
+ namespace: string;
1391
+ type: string;
1392
+ id: string;
1393
+ artifactId?: string;
1394
+ };
1395
+ title: string;
1396
+ description?: string;
1397
+ icon?: IconDefinition;
1398
+ open: ResourceCardOpenTarget;
1399
+ }
1400
+
1378
1401
  /** Exact line LCS with bounded CPU/memory. Unknown text never becomes zero changes. */
1379
1402
  export declare function countFileChangeLines(report: FileChangeReport): FileChangeLineStats;
1380
1403
 
1404
+ export declare function createResourceCardContent(card: ConversationResourceCard): TMessageContentResourceCard;
1405
+
1381
1406
  declare type CustomApiConfig = {
1382
1407
  /**
1383
1408
  * The URL (relative or absolute) of the ChatKit API. The configured endpoint
@@ -1871,6 +1896,8 @@ export declare function isLangGraphInterruptPayload(value: unknown): value is La
1871
1896
 
1872
1897
  export declare function isLangGraphInterruptTask(value: unknown): value is LangGraphInterruptTask;
1873
1898
 
1899
+ export declare function isResourceCardContent(value: unknown): boolean;
1900
+
1874
1901
  export declare function isToolCallInterrupt(value: unknown): value is ToolCallInterrupt;
1875
1902
 
1876
1903
  export declare function isToolCallInterruptPayload(value: unknown): value is ToolCallInterruptPayload;
@@ -2023,6 +2050,11 @@ export declare function parseFileActivityContent(value: unknown): TMessageConten
2023
2050
 
2024
2051
  export declare function parseFileChangeReport(value: unknown): FileChangeReport | null;
2025
2052
 
2053
+ /** JSON boundary: copy only supported fields, never executable commands or host URLs. */
2054
+ export declare function parseResourceCard(value: unknown): ConversationResourceCard | null;
2055
+
2056
+ export declare function parseResourceCardContent(value: unknown): TMessageContentResourceCard | null;
2057
+
2026
2058
  export declare const PET_ANIMATION_NAMES: readonly ["idle", "running-right", "running-left", "waving", "jumping", "failed", "waiting", "running", "review"];
2027
2059
 
2028
2060
  export declare type PetFrameAnimationDefinition = {
@@ -2207,6 +2239,21 @@ export declare function resolveLocalizedText(value: unknown, language?: string):
2207
2239
 
2208
2240
  export declare function resolvePetCharacter(character: ChatKitPetCharacter): ResolvedPetCharacter | null;
2209
2241
 
2242
+ export declare function resourceCardId(card: ConversationResourceCard): string;
2243
+
2244
+ export declare type ResourceCardOpenTarget = {
2245
+ viewKey: string;
2246
+ selectionId?: string;
2247
+ parameters?: Record<string, ResourceCardScalar | ResourceCardScalar[]>;
2248
+ } & ({
2249
+ target: 'workbench.view';
2250
+ } | {
2251
+ target: 'assistant.project';
2252
+ projectId: string;
2253
+ });
2254
+
2255
+ export declare type ResourceCardScalar = string | number | boolean | null;
2256
+
2210
2257
  export declare type Row = {
2211
2258
  type: 'Row';
2212
2259
  key?: string;
@@ -2727,7 +2774,7 @@ export declare type TMessageContent = string | TMessageContentComplex[];
2727
2774
  /**
2728
2775
  * Enhance {@link MessageContentComplex} in Langchain.js
2729
2776
  */
2730
- export declare type TMessageContentComplex = (TMessageContentText | TMessageContentReasoning | MessageContentImageUrl | TMessageContentComponent | TMessageContentFileActivity | TMessageContentMemory | (Record<string, any> & {
2777
+ export declare type TMessageContentComplex = (TMessageContentText | TMessageContentReasoning | MessageContentImageUrl | TMessageContentComponent | TMessageContentFileActivity | TMessageContentResourceCard | TMessageContentMemory | (Record<string, any> & {
2731
2778
  type?: 'text' | 'image_url' | string;
2732
2779
  }) | (Record<string, any> & {
2733
2780
  type?: never;
@@ -2790,6 +2837,15 @@ export declare type TMessageContentReasoning = {
2790
2837
  text: string;
2791
2838
  };
2792
2839
 
2840
+ export declare interface TMessageContentResourceCard {
2841
+ type: 'resource_card';
2842
+ id: string;
2843
+ data: ConversationResourceCard;
2844
+ /** Bound by the server, never supplied by an emitting plugin. */
2845
+ messageId?: string;
2846
+ executionId?: string;
2847
+ }
2848
+
2793
2849
  export declare type TMessageContentText = {
2794
2850
  id?: string;
2795
2851
  xpertName?: string;
@@ -2900,7 +2956,7 @@ export declare type ToolOutputImageAttachment = {
2900
2956
 
2901
2957
  export declare type ToolOutputImageMimeType = 'image/png' | 'image/jpeg' | 'image/webp';
2902
2958
 
2903
- export declare type ToolOutputImageSource = 'knowledge-document' | 'sandbox';
2959
+ export declare type ToolOutputImageSource = 'knowledge-document' | 'sandbox' | 'tool';
2904
2960
 
2905
2961
  /**
2906
2962
  * UI-only ToolMessage artifact. ToolMessage content remains the compact
@@ -2992,6 +3048,9 @@ export declare type TXpertChatTarget = {
2992
3048
  /** Receipts are immutable terminal facts; replay replaces by identity, never appends a second operation. */
2993
3049
  export declare function upsertFileActivityContent<T>(content: T[], receipt: TMessageContentFileActivity): (T | TMessageContentFileActivity)[];
2994
3050
 
3051
+ /** Identity is local to one reply. Repeat emissions replace the snapshot in place. */
3052
+ export declare function upsertResourceCardContent<T>(parts: T[], card: TMessageContentResourceCard): (T | TMessageContentResourceCard)[];
3053
+
2995
3054
  export declare type UserMessageContent = unknown;
2996
3055
 
2997
3056
  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;
package/dist/index.js CHANGED
@@ -1,5 +1,120 @@
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 resourceCardId(card) {
4
+ return JSON.stringify([
5
+ card.resource.namespace,
6
+ card.resource.type,
7
+ card.resource.id
8
+ ]);
9
+ }
10
+ function nonempty(value) {
11
+ return typeof value === "string" && value.trim().length > 0;
12
+ }
13
+ function scalar(value) {
14
+ return value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
15
+ }
16
+ function parseResourceCard(value) {
17
+ if (!value || typeof value !== "object" || !("resource" in value) || !("title" in value) || !nonempty(value.title) || !("open" in value))
18
+ return null;
19
+ const resource = value.resource;
20
+ if (!resource || typeof resource !== "object" || !("namespace" in resource) || !nonempty(resource.namespace) || !("type" in resource) || !nonempty(resource.type) || !("id" in resource) || !nonempty(resource.id))
21
+ return null;
22
+ if ("artifactId" in resource && !nonempty(resource.artifactId)) return null;
23
+ 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))
25
+ return null;
26
+ if (Object.keys(open).some(
27
+ (key) => ![
28
+ "target",
29
+ "viewKey",
30
+ "selectionId",
31
+ "parameters",
32
+ "projectId"
33
+ ].includes(key)
34
+ ))
35
+ return null;
36
+ if ("selectionId" in open && !nonempty(open.selectionId)) return null;
37
+ const parameters = {};
38
+ if ("parameters" in open) {
39
+ if (!open.parameters || typeof open.parameters !== "object" || Array.isArray(open.parameters))
40
+ return null;
41
+ for (const [key, item] of Object.entries(open.parameters)) {
42
+ if (["__proto__", "constructor", "prototype"].includes(key)) return null;
43
+ if (scalar(item)) parameters[key] = item;
44
+ else if (Array.isArray(item) && item.every(scalar))
45
+ parameters[key] = item;
46
+ else return null;
47
+ }
48
+ }
49
+ const common = {
50
+ viewKey: open.viewKey,
51
+ ..."selectionId" in open && nonempty(open.selectionId) ? { selectionId: open.selectionId } : {},
52
+ ..."parameters" in open ? { parameters } : {}
53
+ };
54
+ let target;
55
+ if (open.target === "assistant.project") {
56
+ if (!("projectId" in open) || !nonempty(open.projectId)) return null;
57
+ target = {
58
+ ...common,
59
+ target: "assistant.project",
60
+ projectId: open.projectId
61
+ };
62
+ } else {
63
+ if ("projectId" in open) return null;
64
+ target = { ...common, target: "workbench.view" };
65
+ }
66
+ if ("description" in value && typeof value.description !== "string")
67
+ return null;
68
+ let icon;
69
+ if ("icon" in value) {
70
+ const candidate = value.icon;
71
+ if (!candidate || typeof candidate !== "object" || !("type" in candidate) || !("value" in candidate) || !nonempty(candidate.value))
72
+ return null;
73
+ if (candidate.type !== "svg" && candidate.type !== "emoji" && candidate.type !== "font")
74
+ return null;
75
+ icon = { type: candidate.type, value: candidate.value };
76
+ }
77
+ return {
78
+ resource: {
79
+ namespace: resource.namespace,
80
+ type: resource.type,
81
+ id: resource.id,
82
+ ..."artifactId" in resource && nonempty(resource.artifactId) ? { artifactId: resource.artifactId } : {}
83
+ },
84
+ title: value.title,
85
+ ..."description" in value ? { description: value.description } : {},
86
+ ...icon ? { icon } : {},
87
+ open: target
88
+ };
89
+ }
90
+ function createResourceCardContent(card) {
91
+ const data = parseResourceCard(card);
92
+ if (!data) throw new Error("Invalid resource card");
93
+ return { type: "resource_card", id: resourceCardId(data), data };
94
+ }
95
+ function isResourceCardContent(value) {
96
+ return !!value && typeof value === "object" && "type" in value && value.type === "resource_card";
97
+ }
98
+ function parseResourceCardContent(value) {
99
+ if (!value || typeof value !== "object" || !("type" in value) || value.type !== "resource_card" || !("data" in value))
100
+ return null;
101
+ const card = parseResourceCard(value.data);
102
+ if (!card) return null;
103
+ return {
104
+ ...createResourceCardContent(card),
105
+ ..."messageId" in value && nonempty(value.messageId) ? { messageId: value.messageId } : {},
106
+ ..."executionId" in value && nonempty(value.executionId) ? { executionId: value.executionId } : {}
107
+ };
108
+ }
109
+ function upsertResourceCardContent(parts, card) {
110
+ const index = parts.findIndex(
111
+ (part) => {
112
+ var _a;
113
+ return ((_a = parseResourceCardContent(part)) == null ? void 0 : _a.id) === card.id;
114
+ }
115
+ );
116
+ return index < 0 ? [...parts, card] : parts.map((part, i) => i === index ? card : part);
117
+ }
3
118
  function isApprovalHostReference(value) {
4
119
  return !!value && typeof value === "object" && "kind" in value && typeof value.kind === "string" && value.kind.length > 0 && "id" in value && typeof value.id === "string" && value.id.length > 0 && "expiresAt" in value && typeof value.expiresAt === "number" && Number.isFinite(value.expiresAt);
5
120
  }
@@ -848,6 +963,7 @@ export {
848
963
  chatSkillUsageKey,
849
964
  clampPetPosition,
850
965
  countFileChangeLines,
966
+ createResourceCardContent,
851
967
  fileChangeRangeKey,
852
968
  getFileActivityContribution,
853
969
  getLegacyFileActivityContribution,
@@ -869,6 +985,7 @@ export {
869
985
  isLangGraphInterrupt,
870
986
  isLangGraphInterruptPayload,
871
987
  isLangGraphInterruptTask,
988
+ isResourceCardContent,
872
989
  isToolCallInterrupt,
873
990
  isToolCallInterruptPayload,
874
991
  isToolCallInterruptTask,
@@ -886,10 +1003,14 @@ export {
886
1003
  normalizeThreadReference,
887
1004
  parseFileActivityContent,
888
1005
  parseFileChangeReport,
1006
+ parseResourceCard,
1007
+ parseResourceCardContent,
889
1008
  petSpriteAtlas,
890
1009
  projectMessageFileActivity,
891
1010
  resolveLocalizedText,
892
1011
  resolvePetCharacter,
893
- upsertFileActivityContent
1012
+ resourceCardId,
1013
+ upsertFileActivityContent,
1014
+ upsertResourceCardContent
894
1015
  };
895
1016
  //# sourceMappingURL=index.js.map