@cossistant/core 0.0.26 → 0.0.29

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/client.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { CreateConversationRequestBody, CreateConversationResponseBody, GetConversationRequest, GetConversationResponse, ListConversationsRequest, ListConversationsResponse, MarkConversationSeenRequestBody, MarkConversationSeenResponseBody, SetConversationTypingResponseBody } from "./conversation.js";
2
2
  import { GetConversationTimelineItemsRequest, GetConversationTimelineItemsResponse, SendTimelineItemRequest, SendTimelineItemResponse, TimelineItem } from "./timeline-item.js";
3
- import { Conversation as Conversation$1 } from "./schemas.js";
3
+ import { Conversation } from "./schemas.js";
4
+ import { types_d_exports } from "./types.js";
5
+ import { CossistantRestClient } from "./rest-client.js";
4
6
  import { ConversationsStore } from "./store/conversations-store.js";
5
7
  import { TimelineItemsStore } from "./store/timeline-items-store.js";
6
8
  import { WebsiteStore } from "./store/website-store.js";
7
- import { types_d_exports } from "./types.js";
8
- import { AnyRealtimeEvent, DefaultMessage, IdentifyContactResponse } from "@cossistant/types";
9
+ import { AnyRealtimeEvent, DefaultMessage, IdentifyContactResponse, RealtimeEvent } from "@cossistant/types";
9
10
 
10
11
  //#region src/client.d.ts
11
12
  type InitiateConversationParams = {
@@ -13,12 +14,12 @@ type InitiateConversationParams = {
13
14
  visitorId?: string | null;
14
15
  websiteId?: string | null;
15
16
  title?: string;
16
- status?: Conversation$1["status"];
17
+ status?: Conversation["status"];
17
18
  defaultTimelineItems?: Array<DefaultMessage | TimelineItem>;
18
19
  };
19
20
  type InitiateConversationResult = {
20
21
  conversationId: string;
21
- conversation: Conversation$1;
22
+ conversation: Conversation;
22
23
  defaultTimelineItems: TimelineItem[];
23
24
  };
24
25
  declare class CossistantClient {
@@ -82,11 +83,52 @@ declare class CossistantClient {
82
83
  sendMessage(params: SendTimelineItemRequest & {
83
84
  createIfPending?: boolean;
84
85
  }): Promise<SendTimelineItemResponse & {
85
- conversation?: Conversation$1;
86
+ conversation?: Conversation;
86
87
  initialTimelineItems?: TimelineItem[];
87
88
  wasConversationCreated?: boolean;
88
89
  }>;
89
90
  handleRealtimeEvent(event: AnyRealtimeEvent): void;
91
+ /**
92
+ * Extract conversation status from an event timeline item.
93
+ * Returns the new status if this is a status-changing event, otherwise null.
94
+ */
95
+ private extractStatusFromEventTimelineItem;
96
+ /**
97
+ * Handle conversationUpdated event from realtime
98
+ * Updates conversation with new title (sentiment and escalation are dashboard-only)
99
+ */
100
+ handleConversationUpdated(event: RealtimeEvent<"conversationUpdated">): void;
101
+ /**
102
+ * Generate a presigned URL for uploading a file to S3.
103
+ */
104
+ generateUploadUrl(params: Omit<Parameters<CossistantRestClient["generateUploadUrl"]>[0], "websiteId">): Promise<{
105
+ uploadUrl: string;
106
+ key: string;
107
+ bucket: string;
108
+ expiresAt: string;
109
+ contentType: string;
110
+ publicUrl: string;
111
+ }>;
112
+ /**
113
+ * Upload a file to S3 using a presigned URL.
114
+ */
115
+ uploadFile(file: File, uploadUrl: string, contentType: string): Promise<void>;
116
+ /**
117
+ * Upload multiple files for a conversation message.
118
+ */
119
+ uploadFilesForMessage(files: File[], conversationId: string): Promise<({
120
+ type: "image";
121
+ url: string;
122
+ mediaType: string;
123
+ fileName?: string;
124
+ size?: number;
125
+ } | {
126
+ type: "file";
127
+ url: string;
128
+ mediaType: string;
129
+ fileName?: string;
130
+ size?: number;
131
+ })[]>;
90
132
  destroy(): void;
91
133
  }
92
134
  //#endregion
package/client.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;KA2DK,0BAAA;;EAAA,SAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EAKK,SAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EACoB,KAAA,CAAA,EAAA,MAAA;EAAiB,MAAA,CAAA,EADrC,cACqC,CAAA,QAAA,CAAA;EAAvB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A,EAAA,MAAA,GAAA,IAAA;IA4BpB,CAAA,EAAA;EAAX,CAAA,CAAA;EADO,gBAAA,CAAA,MAAA,EAAA;IAGP,cAAA,EAAA,MAAA;IAQqB,QAAA,EAAA,OAAA;IAA4C,cAAA,CAAA,EAAA,MAAA,GAAA,IAAA;IAOhC,SAAA,CAAA,EAAA,MAAA;EAA8B,CAAA,CAAA,EArQ7D,OAqQ6D,CArQrD,iCAqQqD,CAAA;EAAA,4BAAA,CAAA,MAAA,EA9PxD,mCA8PwD,GAAA;;MA7P9D,QAAQ;sBAWF;;MACN,QACF;mBACgB;2BACQ;;;6BAmHE;;;;;;;;;;mCA8EM;;;;4BA2BxB,KACP,WAAW,8DAEX;;;;;;;;;;;mBAQqB,+CAA4C;;;;+BAOhC,iCAA8B"}
package/client.js CHANGED
@@ -218,15 +218,64 @@ var CossistantClient = class {
218
218
  const timelineItem = this.timelineItemsStore.ingestRealtimeTimelineItem(event);
219
219
  const existingConversation = this.conversationsStore.getState().byId[timelineItem.conversationId];
220
220
  if (existingConversation) {
221
+ const newStatus = this.extractStatusFromEventTimelineItem(timelineItem);
221
222
  const nextConversation = {
222
223
  ...existingConversation,
223
224
  updatedAt: timelineItem.createdAt,
224
- lastTimelineItem: timelineItem
225
+ lastTimelineItem: timelineItem,
226
+ ...newStatus && { status: newStatus }
225
227
  };
226
228
  this.conversationsStore.ingestConversation(nextConversation);
227
229
  }
228
230
  }
229
231
  }
232
+ /**
233
+ * Extract conversation status from an event timeline item.
234
+ * Returns the new status if this is a status-changing event, otherwise null.
235
+ */
236
+ extractStatusFromEventTimelineItem(timelineItem) {
237
+ if (timelineItem.type !== ConversationTimelineType.EVENT) return null;
238
+ const eventPart = timelineItem.parts?.find((part) => typeof part === "object" && part !== null && "type" in part && part.type === "event");
239
+ if (!eventPart || typeof eventPart !== "object" || !("eventType" in eventPart)) return null;
240
+ switch (eventPart.eventType) {
241
+ case "resolved": return ConversationStatus.RESOLVED;
242
+ case "reopened": return ConversationStatus.OPEN;
243
+ default: return null;
244
+ }
245
+ }
246
+ /**
247
+ * Handle conversationUpdated event from realtime
248
+ * Updates conversation with new title (sentiment and escalation are dashboard-only)
249
+ */
250
+ handleConversationUpdated(event) {
251
+ const { conversationId, updates } = event.payload;
252
+ const existingConversation = this.conversationsStore.getState().byId[conversationId];
253
+ if (!existingConversation) return;
254
+ const nextConversation = {
255
+ ...existingConversation,
256
+ ...updates.title !== void 0 && { title: updates.title ?? void 0 },
257
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
258
+ };
259
+ this.conversationsStore.ingestConversation(nextConversation);
260
+ }
261
+ /**
262
+ * Generate a presigned URL for uploading a file to S3.
263
+ */
264
+ async generateUploadUrl(params) {
265
+ return this.restClient.generateUploadUrl(params);
266
+ }
267
+ /**
268
+ * Upload a file to S3 using a presigned URL.
269
+ */
270
+ async uploadFile(file, uploadUrl, contentType) {
271
+ return this.restClient.uploadFile(file, uploadUrl, contentType);
272
+ }
273
+ /**
274
+ * Upload multiple files for a conversation message.
275
+ */
276
+ async uploadFilesForMessage(files, conversationId) {
277
+ return this.restClient.uploadFilesForMessage(files, conversationId);
278
+ }
230
279
  destroy() {}
231
280
  };
232
281
  function normalizeBootstrapTimelineItem(conversationId, item) {
package/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["current: WebsiteState","conversation: Conversation","optimisticTimelineItem: TimelineItem","payload: SendTimelineItemRequest","createdAt"],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype AnyRealtimeEvent,\n\ttype DefaultMessage,\n\tgetEventPayload,\n\ttype IdentifyContactResponse,\n\ttype RealtimeEvent,\n} from \"@cossistant/types\";\nimport type {\n\tCreateConversationRequestBody,\n\tCreateConversationResponseBody,\n\tGetConversationRequest,\n\tGetConversationResponse,\n\tListConversationsRequest,\n\tListConversationsResponse,\n\tMarkConversationSeenRequestBody,\n\tMarkConversationSeenResponseBody,\n\tSetConversationTypingResponseBody,\n} from \"@cossistant/types/api/conversation\";\nimport type {\n\tGetConversationTimelineItemsRequest,\n\tGetConversationTimelineItemsResponse,\n\tSendTimelineItemRequest,\n\tSendTimelineItemResponse,\n\tTimelineItem,\n} from \"@cossistant/types/api/timeline-item\";\nimport {\n\tConversationStatus,\n\tConversationTimelineType,\n\tSenderType,\n\tTimelineItemVisibility,\n} from \"@cossistant/types/enums\";\nimport type { Conversation } from \"@cossistant/types/schemas\";\nimport { CossistantRestClient } from \"./rest-client\";\nimport {\n\ttype ConversationsStore,\n\tcreateConversationsStore,\n} from \"./store/conversations-store\";\nimport {\n\tcreateTimelineItemsStore,\n\ttype TimelineItemsStore,\n} from \"./store/timeline-items-store\";\nimport {\n\tcreateWebsiteStore,\n\ttype WebsiteState,\n\ttype WebsiteStore,\n} from \"./store/website-store\";\nimport type {\n\tCossistantConfig,\n\tPublicWebsiteResponse,\n\tVisitorMetadata,\n\tVisitorResponse,\n} from \"./types\";\nimport { generateConversationId, generateMessageId } from \"./utils\";\n\ntype PendingConversation = {\n\tconversation: Conversation;\n\tinitialTimelineItems: TimelineItem[];\n};\n\ntype InitiateConversationParams = {\n\tconversationId?: string;\n\tvisitorId?: string | null;\n\twebsiteId?: string | null;\n\ttitle?: string;\n\tstatus?: Conversation[\"status\"];\n\tdefaultTimelineItems?: Array<DefaultMessage | TimelineItem>;\n};\n\ntype InitiateConversationResult = {\n\tconversationId: string;\n\tconversation: Conversation;\n\tdefaultTimelineItems: TimelineItem[];\n};\n\nexport class CossistantClient {\n\tprivate restClient: CossistantRestClient;\n\tprivate config: CossistantConfig;\n\tprivate pendingConversations = new Map<string, PendingConversation>();\n\tprivate websiteRequest: Promise<PublicWebsiteResponse> | null = null;\n\treadonly conversationsStore: ConversationsStore;\n\treadonly timelineItemsStore: TimelineItemsStore;\n\treadonly websiteStore: WebsiteStore;\n\n\tconstructor(config: CossistantConfig) {\n\t\tthis.config = config;\n\t\tthis.restClient = new CossistantRestClient(config);\n\t\tthis.conversationsStore = createConversationsStore();\n\t\tthis.timelineItemsStore = createTimelineItemsStore();\n\t\tthis.websiteStore = createWebsiteStore();\n\t}\n\n\t// Configuration updates\n\tupdateConfiguration(config: Partial<CossistantConfig>): void {\n\t\tthis.config = { ...this.config, ...config };\n\t\tthis.restClient.updateConfiguration(config);\n\t}\n\n\t// Utility methods\n\tgetConfiguration(): CossistantConfig {\n\t\treturn { ...this.config };\n\t}\n\n\t// Website information\n\tasync fetchWebsite(\n\t\tparams: { force?: boolean } = {}\n\t): Promise<PublicWebsiteResponse> {\n\t\tconst { force = false } = params;\n\t\tconst current: WebsiteState = this.websiteStore.getState();\n\n\t\tif (!force) {\n\t\t\tif (current.status === \"success\" && current.website) {\n\t\t\t\treturn current.website;\n\t\t\t}\n\t\t\tif (this.websiteRequest) {\n\t\t\t\treturn this.websiteRequest;\n\t\t\t}\n\t\t}\n\n\t\tthis.websiteStore.setLoading();\n\n\t\tconst request = this.restClient\n\t\t\t.getWebsite()\n\t\t\t.then((website) => {\n\t\t\t\tthis.websiteStore.setWebsite(website);\n\t\t\t\treturn website;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.websiteStore.setError(error);\n\t\t\t\tthrow error;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.websiteRequest === request) {\n\t\t\t\t\tthis.websiteRequest = null;\n\t\t\t\t}\n\t\t\t});\n\n\t\tthis.websiteRequest = request;\n\n\t\treturn request;\n\t}\n\n\tasync getWebsite(): Promise<PublicWebsiteResponse> {\n\t\treturn this.fetchWebsite({ force: true });\n\t}\n\n\tsetWebsiteContext(websiteId: string, visitorId?: string): void {\n\t\tthis.restClient.setWebsiteContext(websiteId, visitorId);\n\t}\n\n\tsetVisitorBlocked(isBlocked: boolean): void {\n\t\tthis.restClient.setVisitorBlocked(isBlocked);\n\t}\n\n\tasync updateVisitorMetadata(\n\t\tmetadata: VisitorMetadata\n\t): Promise<VisitorResponse> {\n\t\treturn this.restClient.updateVisitorMetadata(metadata);\n\t}\n\n\tasync identify(params: {\n\t\texternalId?: string;\n\t\temail?: string;\n\t\tname?: string;\n\t\timage?: string;\n\t\tmetadata?: Record<string, unknown>;\n\t\tcontactOrganizationId?: string;\n\t}): Promise<IdentifyContactResponse> {\n\t\treturn this.restClient.identify(params);\n\t}\n\n\tasync updateContactMetadata(\n\t\tmetadata: Record<string, unknown>\n\t): Promise<VisitorResponse> {\n\t\treturn this.restClient.updateContactMetadata(metadata);\n\t}\n\n\t// Conversation management\n\tinitiateConversation(\n\t\tparams: InitiateConversationParams = {}\n\t): InitiateConversationResult {\n\t\tconst conversationId = params.conversationId ?? generateConversationId();\n\t\tconst now = typeof window !== \"undefined\" ? new Date().toISOString() : \"\";\n\t\tconst timelineItems = (params.defaultTimelineItems ?? []).map((item) =>\n\t\t\tnormalizeBootstrapTimelineItem(conversationId, item)\n\t\t);\n\t\tconst existing = this.conversationsStore.getState().byId[conversationId];\n\t\tconst baseVisitorId =\n\t\t\tparams.visitorId ?? this.restClient.getCurrentVisitorId() ?? \"\";\n\t\tconst baseWebsiteId =\n\t\t\tparams.websiteId ?? this.restClient.getCurrentWebsiteId() ?? \"\";\n\n\t\tconst conversation: Conversation = existing\n\t\t\t? {\n\t\t\t\t\t...existing,\n\t\t\t\t\ttitle: params.title ?? existing.title,\n\t\t\t\t\tstatus: params.status ?? existing.status,\n\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\tlastTimelineItem: timelineItems.at(-1) ?? existing.lastTimelineItem,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tid: conversationId,\n\t\t\t\t\ttitle: params.title,\n\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\tvisitorId: baseVisitorId,\n\t\t\t\t\twebsiteId: baseWebsiteId,\n\t\t\t\t\tstatus: params.status ?? ConversationStatus.OPEN,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\tlastTimelineItem: timelineItems.at(-1),\n\t\t\t\t};\n\n\t\tthis.conversationsStore.ingestConversation(conversation);\n\n\t\tif (timelineItems.length > 0) {\n\t\t\tthis.timelineItemsStore.ingestPage(conversationId, {\n\t\t\t\titems: timelineItems,\n\t\t\t\thasNextPage: false,\n\t\t\t\tnextCursor: undefined,\n\t\t\t});\n\t\t}\n\n\t\tif (!existing || this.pendingConversations.has(conversationId)) {\n\t\t\tthis.pendingConversations.set(conversationId, {\n\t\t\t\tconversation,\n\t\t\t\tinitialTimelineItems: timelineItems,\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tconversationId,\n\t\t\tconversation,\n\t\t\tdefaultTimelineItems: timelineItems,\n\t\t};\n\t}\n\n\tasync createConversation(\n\t\tparams?: Partial<CreateConversationRequestBody>\n\t): Promise<CreateConversationResponseBody> {\n\t\tconst response = await this.restClient.createConversation(params);\n\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\treturn response;\n\t}\n\n\tasync listConversations(\n\t\tparams?: Partial<ListConversationsRequest>\n\t): Promise<ListConversationsResponse> {\n\t\tconst response = await this.restClient.listConversations(params);\n\t\tthis.conversationsStore.ingestList(response);\n\t\treturn response;\n\t}\n\n\tasync getConversation(\n\t\tparams: GetConversationRequest\n\t): Promise<GetConversationResponse> {\n\t\tconst response = await this.restClient.getConversation(params);\n\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\treturn response;\n\t}\n\n\tasync markConversationSeen(\n\t\tparams: {\n\t\t\tconversationId: string;\n\t\t} & Partial<MarkConversationSeenRequestBody>\n\t): Promise<MarkConversationSeenResponseBody> {\n\t\treturn this.restClient.markConversationSeen(params);\n\t}\n\n\tasync getConversationSeenData(params: { conversationId: string }) {\n\t\treturn this.restClient.getConversationSeenData(params);\n\t}\n\n\tasync setVisitorTyping(params: {\n\t\tconversationId: string;\n\t\tisTyping: boolean;\n\t\tvisitorPreview?: string | null;\n\t\tvisitorId?: string;\n\t}): Promise<SetConversationTypingResponseBody> {\n\t\treturn this.restClient.setConversationTyping(params);\n\t}\n\n\t// Timeline items management\n\n\tasync getConversationTimelineItems(\n\t\tparams: GetConversationTimelineItemsRequest & { conversationId: string }\n\t): Promise<GetConversationTimelineItemsResponse> {\n\t\tconst response = await this.restClient.getConversationTimelineItems(params);\n\t\tthis.timelineItemsStore.ingestPage(params.conversationId, {\n\t\t\titems: response.items,\n\t\t\thasNextPage: response.hasNextPage,\n\t\t\tnextCursor: response.nextCursor ?? undefined,\n\t\t});\n\t\treturn response;\n\t}\n\n\tasync sendMessage(\n\t\tparams: SendTimelineItemRequest & { createIfPending?: boolean }\n\t): Promise<\n\t\tSendTimelineItemResponse & {\n\t\t\tconversation?: Conversation;\n\t\t\tinitialTimelineItems?: TimelineItem[];\n\t\t\twasConversationCreated?: boolean;\n\t\t}\n\t> {\n\t\tconst { createIfPending, ...rest } = params;\n\t\tconst optimisticId = rest.item.id ?? generateMessageId();\n\t\tconst createdAt = rest.item.createdAt\n\t\t\t? rest.item.createdAt\n\t\t\t: typeof window !== \"undefined\"\n\t\t\t\t? new Date().toISOString()\n\t\t\t\t: \"\";\n\n\t\t// Add optimistic timeline item\n\t\tconst optimisticTimelineItem: TimelineItem = {\n\t\t\tid: optimisticId,\n\t\t\tconversationId: rest.conversationId,\n\t\t\torganizationId: \"\", // Not available yet\n\t\t\tvisibility: rest.item.visibility ?? TimelineItemVisibility.PUBLIC,\n\t\t\ttype: rest.item.type ?? ConversationTimelineType.MESSAGE,\n\t\t\ttext: rest.item.text,\n\t\t\ttool: rest.item.tool ?? null,\n\t\t\tparts:\n\t\t\t\trest.item.parts && rest.item.parts.length > 0\n\t\t\t\t\t? rest.item.parts\n\t\t\t\t\t: rest.item.text\n\t\t\t\t\t\t? [{ type: \"text\" as const, text: rest.item.text }]\n\t\t\t\t\t\t: [],\n\t\t\tuserId: rest.item.userId ?? null,\n\t\t\tvisitorId: rest.item.visitorId ?? null,\n\t\t\taiAgentId: rest.item.aiAgentId ?? null,\n\t\t\tcreatedAt,\n\t\t\tdeletedAt: null,\n\t\t};\n\n\t\tthis.timelineItemsStore.ingestTimelineItem(optimisticTimelineItem);\n\n\t\tconst pending = this.pendingConversations.get(rest.conversationId);\n\n\t\tif (pending && createIfPending !== false) {\n\t\t\ttry {\n\t\t\t\tconst response = await this.restClient.createConversation({\n\t\t\t\t\tconversationId: rest.conversationId,\n\t\t\t\t\tdefaultTimelineItems: [\n\t\t\t\t\t\t...pending.initialTimelineItems,\n\t\t\t\t\t\toptimisticTimelineItem,\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\t\trest.conversationId,\n\t\t\t\t\toptimisticId\n\t\t\t\t);\n\t\t\t\tthis.timelineItemsStore.clearConversation(rest.conversationId);\n\n\t\t\t\tthis.timelineItemsStore.ingestPage(rest.conversationId, {\n\t\t\t\t\titems: response.initialTimelineItems,\n\t\t\t\t\thasNextPage: false,\n\t\t\t\t\tnextCursor: undefined,\n\t\t\t\t});\n\n\t\t\t\tthis.pendingConversations.delete(rest.conversationId);\n\n\t\t\t\tconst item =\n\t\t\t\t\tresponse.initialTimelineItems.at(-1) ??\n\t\t\t\t\tresponse.initialTimelineItems[0];\n\n\t\t\t\treturn {\n\t\t\t\t\titem: item as TimelineItem,\n\t\t\t\t\tconversation: response.conversation,\n\t\t\t\t\tinitialTimelineItems: response.initialTimelineItems,\n\t\t\t\t\twasConversationCreated: true,\n\t\t\t\t} satisfies SendTimelineItemResponse & {\n\t\t\t\t\tconversation: Conversation;\n\t\t\t\t\tinitialTimelineItems: TimelineItem[];\n\t\t\t\t\twasConversationCreated: true;\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\t\trest.conversationId,\n\t\t\t\t\toptimisticId\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tconst { createdAt: _createdAt, ...restItem } = rest.item;\n\n\t\tconst payload: SendTimelineItemRequest = {\n\t\t\t...rest,\n\t\t\titem: {\n\t\t\t\t...restItem,\n\t\t\t\tid: optimisticId,\n\t\t\t},\n\t\t};\n\n\t\ttry {\n\t\t\tconst response = await this.restClient.sendMessage(payload);\n\n\t\t\t// Finalize the timeline item\n\t\t\tthis.timelineItemsStore.finalizeTimelineItem(\n\t\t\t\trest.conversationId,\n\t\t\t\toptimisticId,\n\t\t\t\tresponse.item\n\t\t\t);\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\trest.conversationId,\n\t\t\t\toptimisticId\n\t\t\t);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\thandleRealtimeEvent(event: AnyRealtimeEvent): void {\n\t\tif (event.type === \"conversationCreated\") {\n\t\t\tconst { conversation, header } = event.payload;\n\n\t\t\tthis.conversationsStore.ingestConversation({\n\t\t\t\t...conversation,\n\t\t\t\tlastTimelineItem: conversation.lastTimelineItem ?? undefined,\n\t\t\t});\n\t\t} else if (event.type === \"timelineItemCreated\") {\n\t\t\t// Ingest timeline item into store\n\t\t\tconst timelineItem =\n\t\t\t\tthis.timelineItemsStore.ingestRealtimeTimelineItem(event);\n\n\t\t\t// Update conversation with last timeline item\n\t\t\tconst existingConversation =\n\t\t\t\tthis.conversationsStore.getState().byId[timelineItem.conversationId];\n\n\t\t\tif (existingConversation) {\n\t\t\t\tconst nextConversation = {\n\t\t\t\t\t...existingConversation,\n\t\t\t\t\tupdatedAt: timelineItem.createdAt,\n\t\t\t\t\tlastTimelineItem: timelineItem,\n\t\t\t\t};\n\n\t\t\t\tthis.conversationsStore.ingestConversation(nextConversation);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Cleanup method\n\tdestroy(): void {\n\t\t// No cleanup needed for REST client\n\t}\n}\n\nfunction normalizeBootstrapTimelineItem(\n\tconversationId: string,\n\titem: DefaultMessage | TimelineItem\n): TimelineItem {\n\tif (isDefaultMessage(item)) {\n\t\tconst createdAt =\n\t\t\ttypeof window !== \"undefined\" ? new Date().toISOString() : \"\";\n\n\t\treturn {\n\t\t\tid: generateMessageId(),\n\t\t\tconversationId,\n\t\t\torganizationId: \"\", // Not available at this point\n\t\t\ttype: ConversationTimelineType.MESSAGE,\n\t\t\ttext: item.content,\n\t\t\tparts: [{ type: \"text\" as const, text: item.content }],\n\t\t\tvisibility: TimelineItemVisibility.PUBLIC,\n\t\t\tuserId:\n\t\t\t\titem.senderType === SenderType.TEAM_MEMBER\n\t\t\t\t\t? (item.senderId ?? null)\n\t\t\t\t\t: null,\n\t\t\taiAgentId:\n\t\t\t\titem.senderType === SenderType.AI ? (item.senderId ?? null) : null,\n\t\t\tvisitorId:\n\t\t\t\titem.senderType === SenderType.VISITOR ? (item.senderId ?? null) : null,\n\t\t\tcreatedAt,\n\t\t\tdeletedAt: null,\n\t\t} satisfies TimelineItem;\n\t}\n\n\tconst createdAt = item.createdAt\n\t\t? item.createdAt\n\t\t: typeof window !== \"undefined\"\n\t\t\t? new Date().toISOString()\n\t\t\t: \"\";\n\n\treturn {\n\t\t...item,\n\t\tid: item.id ?? generateMessageId(),\n\t\tconversationId,\n\t\torganizationId: item.organizationId || \"\",\n\t\ttype: item.type ?? ConversationTimelineType.MESSAGE,\n\t\ttool: item.tool ?? null,\n\t\tcreatedAt,\n\t\tdeletedAt: item.deletedAt ?? null,\n\t\tuserId: item.userId ?? null,\n\t\taiAgentId: item.aiAgentId ?? null,\n\t\tvisitorId: item.visitorId ?? null,\n\t\tvisibility: item.visibility ?? TimelineItemVisibility.PUBLIC,\n\t} satisfies TimelineItem;\n}\n\nfunction isDefaultMessage(\n\titem: DefaultMessage | TimelineItem\n): item is DefaultMessage {\n\treturn (item as DefaultMessage).content !== undefined;\n}\n"],"mappings":";;;;;;;;AA0EA,IAAa,mBAAb,MAA8B;CAC7B,AAAQ;CACR,AAAQ;CACR,AAAQ,uCAAuB,IAAI,KAAkC;CACrE,AAAQ,iBAAwD;CAChE,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAA0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Conversation","optimisticTimelineItem: TimelineItem","payload: SendTimelineItemRequest","createdAt"],"sources":["../src/client.ts"],"sourcesContent":["import {\n\ttype AnyRealtimeEvent,\n\ttype DefaultMessage,\n\tgetEventPayload,\n\ttype IdentifyContactResponse,\n\ttype RealtimeEvent,\n} from \"@cossistant/types\";\nimport type {\n\tCreateConversationRequestBody,\n\tCreateConversationResponseBody,\n\tGetConversationRequest,\n\tGetConversationResponse,\n\tListConversationsRequest,\n\tListConversationsResponse,\n\tMarkConversationSeenRequestBody,\n\tMarkConversationSeenResponseBody,\n\tSetConversationTypingResponseBody,\n} from \"@cossistant/types/api/conversation\";\nimport type {\n\tGetConversationTimelineItemsRequest,\n\tGetConversationTimelineItemsResponse,\n\tSendTimelineItemRequest,\n\tSendTimelineItemResponse,\n\tTimelineItem,\n} from \"@cossistant/types/api/timeline-item\";\nimport {\n\tConversationStatus,\n\tConversationTimelineType,\n\tSenderType,\n\tTimelineItemVisibility,\n} from \"@cossistant/types/enums\";\nimport type { Conversation } from \"@cossistant/types/schemas\";\nimport { CossistantRestClient } from \"./rest-client\";\nimport {\n\ttype ConversationsStore,\n\tcreateConversationsStore,\n} from \"./store/conversations-store\";\nimport {\n\tcreateTimelineItemsStore,\n\ttype TimelineItemsStore,\n} from \"./store/timeline-items-store\";\nimport {\n\tcreateWebsiteStore,\n\ttype WebsiteState,\n\ttype WebsiteStore,\n} from \"./store/website-store\";\nimport type {\n\tCossistantConfig,\n\tPublicWebsiteResponse,\n\tVisitorMetadata,\n\tVisitorResponse,\n} from \"./types\";\nimport { generateConversationId, generateMessageId } from \"./utils\";\n\ntype PendingConversation = {\n\tconversation: Conversation;\n\tinitialTimelineItems: TimelineItem[];\n};\n\ntype InitiateConversationParams = {\n\tconversationId?: string;\n\tvisitorId?: string | null;\n\twebsiteId?: string | null;\n\ttitle?: string;\n\tstatus?: Conversation[\"status\"];\n\tdefaultTimelineItems?: Array<DefaultMessage | TimelineItem>;\n};\n\ntype InitiateConversationResult = {\n\tconversationId: string;\n\tconversation: Conversation;\n\tdefaultTimelineItems: TimelineItem[];\n};\n\nexport class CossistantClient {\n\tprivate restClient: CossistantRestClient;\n\tprivate config: CossistantConfig;\n\tprivate pendingConversations = new Map<string, PendingConversation>();\n\tprivate websiteRequest: Promise<PublicWebsiteResponse> | null = null;\n\treadonly conversationsStore: ConversationsStore;\n\treadonly timelineItemsStore: TimelineItemsStore;\n\treadonly websiteStore: WebsiteStore;\n\n\tconstructor(config: CossistantConfig) {\n\t\tthis.config = config;\n\t\tthis.restClient = new CossistantRestClient(config);\n\t\tthis.conversationsStore = createConversationsStore();\n\t\tthis.timelineItemsStore = createTimelineItemsStore();\n\t\tthis.websiteStore = createWebsiteStore();\n\t}\n\n\t// Configuration updates\n\tupdateConfiguration(config: Partial<CossistantConfig>): void {\n\t\tthis.config = { ...this.config, ...config };\n\t\tthis.restClient.updateConfiguration(config);\n\t}\n\n\t// Utility methods\n\tgetConfiguration(): CossistantConfig {\n\t\treturn { ...this.config };\n\t}\n\n\t// Website information\n\tasync fetchWebsite(\n\t\tparams: { force?: boolean } = {}\n\t): Promise<PublicWebsiteResponse> {\n\t\tconst { force = false } = params;\n\t\tconst current: WebsiteState = this.websiteStore.getState();\n\n\t\tif (!force) {\n\t\t\tif (current.status === \"success\" && current.website) {\n\t\t\t\treturn current.website;\n\t\t\t}\n\t\t\tif (this.websiteRequest) {\n\t\t\t\treturn this.websiteRequest;\n\t\t\t}\n\t\t}\n\n\t\tthis.websiteStore.setLoading();\n\n\t\tconst request = this.restClient\n\t\t\t.getWebsite()\n\t\t\t.then((website) => {\n\t\t\t\tthis.websiteStore.setWebsite(website);\n\t\t\t\treturn website;\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tthis.websiteStore.setError(error);\n\t\t\t\tthrow error;\n\t\t\t})\n\t\t\t.finally(() => {\n\t\t\t\tif (this.websiteRequest === request) {\n\t\t\t\t\tthis.websiteRequest = null;\n\t\t\t\t}\n\t\t\t});\n\n\t\tthis.websiteRequest = request;\n\n\t\treturn request;\n\t}\n\n\tasync getWebsite(): Promise<PublicWebsiteResponse> {\n\t\treturn this.fetchWebsite({ force: true });\n\t}\n\n\tsetWebsiteContext(websiteId: string, visitorId?: string): void {\n\t\tthis.restClient.setWebsiteContext(websiteId, visitorId);\n\t}\n\n\tsetVisitorBlocked(isBlocked: boolean): void {\n\t\tthis.restClient.setVisitorBlocked(isBlocked);\n\t}\n\n\tasync updateVisitorMetadata(\n\t\tmetadata: VisitorMetadata\n\t): Promise<VisitorResponse> {\n\t\treturn this.restClient.updateVisitorMetadata(metadata);\n\t}\n\n\tasync identify(params: {\n\t\texternalId?: string;\n\t\temail?: string;\n\t\tname?: string;\n\t\timage?: string;\n\t\tmetadata?: Record<string, unknown>;\n\t\tcontactOrganizationId?: string;\n\t}): Promise<IdentifyContactResponse> {\n\t\treturn this.restClient.identify(params);\n\t}\n\n\tasync updateContactMetadata(\n\t\tmetadata: Record<string, unknown>\n\t): Promise<VisitorResponse> {\n\t\treturn this.restClient.updateContactMetadata(metadata);\n\t}\n\n\t// Conversation management\n\tinitiateConversation(\n\t\tparams: InitiateConversationParams = {}\n\t): InitiateConversationResult {\n\t\tconst conversationId = params.conversationId ?? generateConversationId();\n\t\tconst now = typeof window !== \"undefined\" ? new Date().toISOString() : \"\";\n\t\tconst timelineItems = (params.defaultTimelineItems ?? []).map((item) =>\n\t\t\tnormalizeBootstrapTimelineItem(conversationId, item)\n\t\t);\n\t\tconst existing = this.conversationsStore.getState().byId[conversationId];\n\t\tconst baseVisitorId =\n\t\t\tparams.visitorId ?? this.restClient.getCurrentVisitorId() ?? \"\";\n\t\tconst baseWebsiteId =\n\t\t\tparams.websiteId ?? this.restClient.getCurrentWebsiteId() ?? \"\";\n\n\t\tconst conversation: Conversation = existing\n\t\t\t? {\n\t\t\t\t\t...existing,\n\t\t\t\t\ttitle: params.title ?? existing.title,\n\t\t\t\t\tstatus: params.status ?? existing.status,\n\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\tlastTimelineItem: timelineItems.at(-1) ?? existing.lastTimelineItem,\n\t\t\t\t}\n\t\t\t: {\n\t\t\t\t\tid: conversationId,\n\t\t\t\t\ttitle: params.title,\n\t\t\t\t\tcreatedAt: now,\n\t\t\t\t\tupdatedAt: now,\n\t\t\t\t\tvisitorId: baseVisitorId,\n\t\t\t\t\twebsiteId: baseWebsiteId,\n\t\t\t\t\tstatus: params.status ?? ConversationStatus.OPEN,\n\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\tlastTimelineItem: timelineItems.at(-1),\n\t\t\t\t};\n\n\t\tthis.conversationsStore.ingestConversation(conversation);\n\n\t\tif (timelineItems.length > 0) {\n\t\t\tthis.timelineItemsStore.ingestPage(conversationId, {\n\t\t\t\titems: timelineItems,\n\t\t\t\thasNextPage: false,\n\t\t\t\tnextCursor: undefined,\n\t\t\t});\n\t\t}\n\n\t\tif (!existing || this.pendingConversations.has(conversationId)) {\n\t\t\tthis.pendingConversations.set(conversationId, {\n\t\t\t\tconversation,\n\t\t\t\tinitialTimelineItems: timelineItems,\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tconversationId,\n\t\t\tconversation,\n\t\t\tdefaultTimelineItems: timelineItems,\n\t\t};\n\t}\n\n\tasync createConversation(\n\t\tparams?: Partial<CreateConversationRequestBody>\n\t): Promise<CreateConversationResponseBody> {\n\t\tconst response = await this.restClient.createConversation(params);\n\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\treturn response;\n\t}\n\n\tasync listConversations(\n\t\tparams?: Partial<ListConversationsRequest>\n\t): Promise<ListConversationsResponse> {\n\t\tconst response = await this.restClient.listConversations(params);\n\t\tthis.conversationsStore.ingestList(response);\n\t\treturn response;\n\t}\n\n\tasync getConversation(\n\t\tparams: GetConversationRequest\n\t): Promise<GetConversationResponse> {\n\t\tconst response = await this.restClient.getConversation(params);\n\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\treturn response;\n\t}\n\n\tasync markConversationSeen(\n\t\tparams: {\n\t\t\tconversationId: string;\n\t\t} & Partial<MarkConversationSeenRequestBody>\n\t): Promise<MarkConversationSeenResponseBody> {\n\t\treturn this.restClient.markConversationSeen(params);\n\t}\n\n\tasync getConversationSeenData(params: { conversationId: string }) {\n\t\treturn this.restClient.getConversationSeenData(params);\n\t}\n\n\tasync setVisitorTyping(params: {\n\t\tconversationId: string;\n\t\tisTyping: boolean;\n\t\tvisitorPreview?: string | null;\n\t\tvisitorId?: string;\n\t}): Promise<SetConversationTypingResponseBody> {\n\t\treturn this.restClient.setConversationTyping(params);\n\t}\n\n\t// Timeline items management\n\n\tasync getConversationTimelineItems(\n\t\tparams: GetConversationTimelineItemsRequest & { conversationId: string }\n\t): Promise<GetConversationTimelineItemsResponse> {\n\t\tconst response = await this.restClient.getConversationTimelineItems(params);\n\t\tthis.timelineItemsStore.ingestPage(params.conversationId, {\n\t\t\titems: response.items,\n\t\t\thasNextPage: response.hasNextPage,\n\t\t\tnextCursor: response.nextCursor ?? undefined,\n\t\t});\n\t\treturn response;\n\t}\n\n\tasync sendMessage(\n\t\tparams: SendTimelineItemRequest & { createIfPending?: boolean }\n\t): Promise<\n\t\tSendTimelineItemResponse & {\n\t\t\tconversation?: Conversation;\n\t\t\tinitialTimelineItems?: TimelineItem[];\n\t\t\twasConversationCreated?: boolean;\n\t\t}\n\t> {\n\t\tconst { createIfPending, ...rest } = params;\n\t\tconst optimisticId = rest.item.id ?? generateMessageId();\n\t\tconst createdAt = rest.item.createdAt\n\t\t\t? rest.item.createdAt\n\t\t\t: typeof window !== \"undefined\"\n\t\t\t\t? new Date().toISOString()\n\t\t\t\t: \"\";\n\n\t\t// Add optimistic timeline item\n\t\tconst optimisticTimelineItem: TimelineItem = {\n\t\t\tid: optimisticId,\n\t\t\tconversationId: rest.conversationId,\n\t\t\torganizationId: \"\", // Not available yet\n\t\t\tvisibility: rest.item.visibility ?? TimelineItemVisibility.PUBLIC,\n\t\t\ttype: rest.item.type ?? ConversationTimelineType.MESSAGE,\n\t\t\ttext: rest.item.text,\n\t\t\ttool: rest.item.tool ?? null,\n\t\t\tparts:\n\t\t\t\trest.item.parts && rest.item.parts.length > 0\n\t\t\t\t\t? rest.item.parts\n\t\t\t\t\t: rest.item.text\n\t\t\t\t\t\t? [{ type: \"text\" as const, text: rest.item.text }]\n\t\t\t\t\t\t: [],\n\t\t\tuserId: rest.item.userId ?? null,\n\t\t\tvisitorId: rest.item.visitorId ?? null,\n\t\t\taiAgentId: rest.item.aiAgentId ?? null,\n\t\t\tcreatedAt,\n\t\t\tdeletedAt: null,\n\t\t};\n\n\t\tthis.timelineItemsStore.ingestTimelineItem(optimisticTimelineItem);\n\n\t\tconst pending = this.pendingConversations.get(rest.conversationId);\n\n\t\tif (pending && createIfPending !== false) {\n\t\t\ttry {\n\t\t\t\tconst response = await this.restClient.createConversation({\n\t\t\t\t\tconversationId: rest.conversationId,\n\t\t\t\t\tdefaultTimelineItems: [\n\t\t\t\t\t\t...pending.initialTimelineItems,\n\t\t\t\t\t\toptimisticTimelineItem,\n\t\t\t\t\t],\n\t\t\t\t});\n\n\t\t\t\tthis.conversationsStore.ingestConversation(response.conversation);\n\t\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\t\trest.conversationId,\n\t\t\t\t\toptimisticId\n\t\t\t\t);\n\t\t\t\tthis.timelineItemsStore.clearConversation(rest.conversationId);\n\n\t\t\t\tthis.timelineItemsStore.ingestPage(rest.conversationId, {\n\t\t\t\t\titems: response.initialTimelineItems,\n\t\t\t\t\thasNextPage: false,\n\t\t\t\t\tnextCursor: undefined,\n\t\t\t\t});\n\n\t\t\t\tthis.pendingConversations.delete(rest.conversationId);\n\n\t\t\t\tconst item =\n\t\t\t\t\tresponse.initialTimelineItems.at(-1) ??\n\t\t\t\t\tresponse.initialTimelineItems[0];\n\n\t\t\t\treturn {\n\t\t\t\t\titem: item as TimelineItem,\n\t\t\t\t\tconversation: response.conversation,\n\t\t\t\t\tinitialTimelineItems: response.initialTimelineItems,\n\t\t\t\t\twasConversationCreated: true,\n\t\t\t\t} satisfies SendTimelineItemResponse & {\n\t\t\t\t\tconversation: Conversation;\n\t\t\t\t\tinitialTimelineItems: TimelineItem[];\n\t\t\t\t\twasConversationCreated: true;\n\t\t\t\t};\n\t\t\t} catch (error) {\n\t\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\t\trest.conversationId,\n\t\t\t\t\toptimisticId\n\t\t\t\t);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\n\t\tconst { createdAt: _createdAt, ...restItem } = rest.item;\n\n\t\tconst payload: SendTimelineItemRequest = {\n\t\t\t...rest,\n\t\t\titem: {\n\t\t\t\t...restItem,\n\t\t\t\tid: optimisticId,\n\t\t\t},\n\t\t};\n\n\t\ttry {\n\t\t\tconst response = await this.restClient.sendMessage(payload);\n\n\t\t\t// Finalize the timeline item\n\t\t\tthis.timelineItemsStore.finalizeTimelineItem(\n\t\t\t\trest.conversationId,\n\t\t\t\toptimisticId,\n\t\t\t\tresponse.item\n\t\t\t);\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tthis.timelineItemsStore.removeTimelineItem(\n\t\t\t\trest.conversationId,\n\t\t\t\toptimisticId\n\t\t\t);\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\thandleRealtimeEvent(event: AnyRealtimeEvent): void {\n\t\tif (event.type === \"conversationCreated\") {\n\t\t\tconst { conversation, header } = event.payload;\n\n\t\t\tthis.conversationsStore.ingestConversation({\n\t\t\t\t...conversation,\n\t\t\t\tlastTimelineItem: conversation.lastTimelineItem ?? undefined,\n\t\t\t});\n\t\t} else if (event.type === \"timelineItemCreated\") {\n\t\t\t// Ingest timeline item into store\n\t\t\tconst timelineItem =\n\t\t\t\tthis.timelineItemsStore.ingestRealtimeTimelineItem(event);\n\n\t\t\t// Update conversation with last timeline item\n\t\t\tconst existingConversation =\n\t\t\t\tthis.conversationsStore.getState().byId[timelineItem.conversationId];\n\n\t\t\tif (existingConversation) {\n\t\t\t\t// Check if this is a status-changing event timeline item\n\t\t\t\tconst newStatus = this.extractStatusFromEventTimelineItem(timelineItem);\n\n\t\t\t\tconst nextConversation = {\n\t\t\t\t\t...existingConversation,\n\t\t\t\t\tupdatedAt: timelineItem.createdAt,\n\t\t\t\t\tlastTimelineItem: timelineItem,\n\t\t\t\t\t...(newStatus && { status: newStatus }),\n\t\t\t\t};\n\n\t\t\t\tthis.conversationsStore.ingestConversation(nextConversation);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Extract conversation status from an event timeline item.\n\t * Returns the new status if this is a status-changing event, otherwise null.\n\t */\n\tprivate extractStatusFromEventTimelineItem(\n\t\ttimelineItem: TimelineItem\n\t): ConversationStatus | null {\n\t\tif (timelineItem.type !== ConversationTimelineType.EVENT) {\n\t\t\treturn null;\n\t\t}\n\n\t\t// Find the event part in the timeline item\n\t\tconst eventPart = timelineItem.parts?.find(\n\t\t\t(part) =>\n\t\t\t\ttypeof part === \"object\" &&\n\t\t\t\tpart !== null &&\n\t\t\t\t\"type\" in part &&\n\t\t\t\tpart.type === \"event\"\n\t\t);\n\n\t\tif (\n\t\t\t!eventPart ||\n\t\t\ttypeof eventPart !== \"object\" ||\n\t\t\t!(\"eventType\" in eventPart)\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst eventType = (eventPart as { eventType: string }).eventType;\n\n\t\t// Map event types to conversation status\n\t\tswitch (eventType) {\n\t\t\tcase \"resolved\":\n\t\t\t\treturn ConversationStatus.RESOLVED;\n\t\t\tcase \"reopened\":\n\t\t\t\treturn ConversationStatus.OPEN;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t}\n\n\t/**\n\t * Handle conversationUpdated event from realtime\n\t * Updates conversation with new title (sentiment and escalation are dashboard-only)\n\t */\n\thandleConversationUpdated(event: RealtimeEvent<\"conversationUpdated\">): void {\n\t\tconst { conversationId, updates } = event.payload;\n\n\t\tconst existingConversation =\n\t\t\tthis.conversationsStore.getState().byId[conversationId];\n\n\t\tif (!existingConversation) {\n\t\t\t// Conversation not in store, ignore update\n\t\t\treturn;\n\t\t}\n\n\t\t// Build the updated conversation with only the title field\n\t\t// (sentiment and escalation are dashboard-only fields)\n\t\tconst nextConversation = {\n\t\t\t...existingConversation,\n\t\t\t...(updates.title !== undefined && { title: updates.title ?? undefined }),\n\t\t\tupdatedAt: new Date().toISOString(),\n\t\t};\n\n\t\tthis.conversationsStore.ingestConversation(nextConversation);\n\t}\n\n\t// File upload methods\n\t/**\n\t * Generate a presigned URL for uploading a file to S3.\n\t */\n\tasync generateUploadUrl(\n\t\tparams: Omit<\n\t\t\tParameters<CossistantRestClient[\"generateUploadUrl\"]>[0],\n\t\t\t\"websiteId\"\n\t\t>\n\t) {\n\t\treturn this.restClient.generateUploadUrl(params);\n\t}\n\n\t/**\n\t * Upload a file to S3 using a presigned URL.\n\t */\n\tasync uploadFile(file: File, uploadUrl: string, contentType: string) {\n\t\treturn this.restClient.uploadFile(file, uploadUrl, contentType);\n\t}\n\n\t/**\n\t * Upload multiple files for a conversation message.\n\t */\n\tasync uploadFilesForMessage(files: File[], conversationId: string) {\n\t\treturn this.restClient.uploadFilesForMessage(files, conversationId);\n\t}\n\n\t// Cleanup method\n\tdestroy(): void {\n\t\t// No cleanup needed for REST client\n\t}\n}\n\nfunction normalizeBootstrapTimelineItem(\n\tconversationId: string,\n\titem: DefaultMessage | TimelineItem\n): TimelineItem {\n\tif (isDefaultMessage(item)) {\n\t\tconst createdAt =\n\t\t\ttypeof window !== \"undefined\" ? new Date().toISOString() : \"\";\n\n\t\treturn {\n\t\t\tid: generateMessageId(),\n\t\t\tconversationId,\n\t\t\torganizationId: \"\", // Not available at this point\n\t\t\ttype: ConversationTimelineType.MESSAGE,\n\t\t\ttext: item.content,\n\t\t\tparts: [{ type: \"text\" as const, text: item.content }],\n\t\t\tvisibility: TimelineItemVisibility.PUBLIC,\n\t\t\tuserId:\n\t\t\t\titem.senderType === SenderType.TEAM_MEMBER\n\t\t\t\t\t? (item.senderId ?? null)\n\t\t\t\t\t: null,\n\t\t\taiAgentId:\n\t\t\t\titem.senderType === SenderType.AI ? (item.senderId ?? null) : null,\n\t\t\tvisitorId:\n\t\t\t\titem.senderType === SenderType.VISITOR ? (item.senderId ?? null) : null,\n\t\t\tcreatedAt,\n\t\t\tdeletedAt: null,\n\t\t} satisfies TimelineItem;\n\t}\n\n\tconst createdAt = item.createdAt\n\t\t? item.createdAt\n\t\t: typeof window !== \"undefined\"\n\t\t\t? new Date().toISOString()\n\t\t\t: \"\";\n\n\treturn {\n\t\t...item,\n\t\tid: item.id ?? generateMessageId(),\n\t\tconversationId,\n\t\torganizationId: item.organizationId || \"\",\n\t\ttype: item.type ?? ConversationTimelineType.MESSAGE,\n\t\ttool: item.tool ?? null,\n\t\tcreatedAt,\n\t\tdeletedAt: item.deletedAt ?? null,\n\t\tuserId: item.userId ?? null,\n\t\taiAgentId: item.aiAgentId ?? null,\n\t\tvisitorId: item.visitorId ?? null,\n\t\tvisibility: item.visibility ?? TimelineItemVisibility.PUBLIC,\n\t} satisfies TimelineItem;\n}\n\nfunction isDefaultMessage(\n\titem: DefaultMessage | TimelineItem\n): item is DefaultMessage {\n\treturn (item as DefaultMessage).content !== undefined;\n}\n"],"mappings":";;;;;;;;AA0EA,IAAa,mBAAb,MAA8B;CAC7B,AAAQ;CACR,AAAQ;CACR,AAAQ,uCAAuB,IAAI,KAAkC;CACrE,AAAQ,iBAAwD;CAChE,AAAS;CACT,AAAS;CACT,AAAS;CAET,YAAY,QAA0B;AACrC,OAAK,SAAS;AACd,OAAK,aAAa,IAAI,qBAAqB,OAAO;AAClD,OAAK,qBAAqB,0BAA0B;AACpD,OAAK,qBAAqB,0BAA0B;AACpD,OAAK,eAAe,oBAAoB;;CAIzC,oBAAoB,QAAyC;AAC5D,OAAK,SAAS;GAAE,GAAG,KAAK;GAAQ,GAAG;GAAQ;AAC3C,OAAK,WAAW,oBAAoB,OAAO;;CAI5C,mBAAqC;AACpC,SAAO,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MAAM,KAAK;IAAS,CAAC;GACtD,YAAY,uBAAuB;GACnC,QACC,KAAK,eAAe,WAAW,cAC3B,KAAK,YAAY,OAClB;GACJ,WACC,KAAK,eAAe,WAAW,KAAM,KAAK,YAAY,OAAQ;GAC/D,WACC,KAAK,eAAe,WAAW,UAAW,KAAK,YAAY,OAAQ;GACpE;GACA,WAAW;GACX;;CAGF,MAAM,YAAY,KAAK,YACpB,KAAK,YACL,OAAO,WAAW,+BACjB,IAAI,MAAM,EAAC,aAAa,GACxB;AAEJ,QAAO;EACN,GAAG;EACH,IAAI,KAAK,MAAM,mBAAmB;EAClC;EACA,gBAAgB,KAAK,kBAAkB;EACvC,MAAM,KAAK,QAAQ,yBAAyB;EAC5C,MAAM,KAAK,QAAQ;EACnB;EACA,WAAW,KAAK,aAAa;EAC7B,QAAQ,KAAK,UAAU;EACvB,WAAW,KAAK,aAAa;EAC7B,WAAW,KAAK,aAAa;EAC7B,YAAY,KAAK,cAAc,uBAAuB;EACtD;;AAGF,SAAS,iBACR,MACyB;AACzB,QAAQ,KAAwB,YAAY"}
package/conversation.d.ts CHANGED
@@ -159,6 +159,7 @@ declare const createConversationResponseSchema: z.ZodObject<{
159
159
  spam: "spam";
160
160
  }>>;
161
161
  deletedAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
162
+ visitorLastSeenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
162
163
  lastTimelineItem: z.ZodOptional<z.ZodObject<{
163
164
  id: z.ZodOptional<z.ZodString>;
164
165
  conversationId: z.ZodString;
@@ -263,6 +264,7 @@ declare const listConversationsResponseSchema: z.ZodObject<{
263
264
  spam: "spam";
264
265
  }>>;
265
266
  deletedAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
267
+ visitorLastSeenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
266
268
  lastTimelineItem: z.ZodOptional<z.ZodObject<{
267
269
  id: z.ZodOptional<z.ZodString>;
268
270
  conversationId: z.ZodString;
@@ -360,6 +362,7 @@ declare const getConversationResponseSchema: z.ZodObject<{
360
362
  spam: "spam";
361
363
  }>>;
362
364
  deletedAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
365
+ visitorLastSeenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
363
366
  lastTimelineItem: z.ZodOptional<z.ZodObject<{
364
367
  id: z.ZodOptional<z.ZodString>;
365
368
  conversationId: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"conversation.d.ts","names":[],"sources":["../../types/src/api/conversation.ts"],"sourcesContent":[],"mappings":";;;cAIa,iCAA+B,CAAA,CAAA;;EAA/B,cAAA,eAAA,YAoBV,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAES,6BAAA,GAAgC,CAAA,CAAE,aACtC;cAGK,kCAAgC,CAAA,CAAA;;;;;;MA1BD,MAAA,EAAA,QAAA;MAAA,OAAA,EAAA,SAAA;IAsBhC,CAAA,CAAA;IAIC,IAAA,WAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KASD,8BAAA,GAAiC,CAAA,CAAE,aACvC;cAGK,gCAA8B,CAAA,CAAA;;;;;;;;;;;;EAbE,KAAA,cAAA,UAAA,CAAA;IAAA,GAAA,EAAA,KAAA;IASjC,IAAA,EAAA,MAAA;EAIC,CAAA,CAAA,CAAA;;KA6BD,wBAAA,GAA2B,CAAA,CAAE,aACjC;cAGK,iCAA+B,CAAA,CAAA;;;;;;;;;;;MAjCD,IAAA,EAAA,MAAA;IAAA,CAAA,CAAA,CAAA;IA6B/B,SAAA,cAAwB,cAC5B,YAAA,CAAA,CAAA;IAGK,gBAAA,eAaV,YAAA,CAAA;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAQD,uBAAA,GAA0B,CAAA,CAAE,aAChC;cAGK,mCAAiC,CAAA,CAAA;;;KAYlC,+BAAA,GAAkC,CAAA,CAAE,aACxC;cAGK,oCAAkC,CAAA,CAAA;;;;KAcnC,gCAAA,GAAmC,CAAA,CAAE,aACzC;cA0BK,qCAAmC,CAAA,CAAA;;;;;;KAoBpC,iCAAA,GAAoC,CAAA,CAAE,aAC1C;cAGK,uCAAqC,CAAA,CAAA;;;;;;IA7FR,SAAA,eAAA,YAAA,CAAA;IAAA,UAAA,aAAA;IAQ9B,SAAA,aAAuB;IAItB,SAAA,aAAA;;;;AAAiC,KAwHlC,+BAAA,GAAkC,CAAA,CAAE,KAxHF,CAAA,OAyHtC,qCAzHsC,CAAA"}
package/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
- import { ConversationPagination, ConversationsState, ConversationsStore, createConversationsStore, getConversationById, getConversationPagination, getConversations } from "./store/conversations-store.js";
1
+ import { CossistantAPIError } from "./types.js";
2
+ import { CossistantRestClient } from "./rest-client.js";
3
+ import { ConversationPagination, ConversationWithSeen, ConversationsState, ConversationsStore, createConversationsStore, getConversationById, getConversationPagination, getConversations } from "./store/conversations-store.js";
2
4
  import { ConversationTimelineItemsState, TimelineItemsState, TimelineItemsStore, createTimelineItemsStore, getConversationTimelineItems } from "./store/timeline-items-store.js";
3
5
  import { WebsiteError, WebsiteState, WebsiteStatus, WebsiteStore, createWebsiteStore, getWebsiteState } from "./store/website-store.js";
4
- import { CossistantAPIError } from "./types.js";
5
6
  import { CossistantClient } from "./client.js";
6
7
  import { normalizeLocale } from "./locale-utils.js";
7
- import { CossistantRestClient } from "./rest-client.js";
8
8
  import { ConversationSeenState, SeenActorType, SeenEntry, SeenState, SeenStore, applyConversationSeenEvent, createSeenStore, hydrateConversationSeen, upsertConversationSeen } from "./store/seen-store.js";
9
9
  import { DefaultRoutes, NavigationState, RouteRegistry, SUPPORT_PAGES, SupportConfig, SupportNavigation, SupportPage, SupportStore, SupportStoreActions, SupportStoreOptions, SupportStoreState, SupportStoreStorage, createSupportStore } from "./store/support-store.js";
10
10
  import { ConversationTypingState, TypingActorType, TypingEntry, TypingState, TypingStore, TypingStoreDependencies, applyConversationTypingEvent, clearTypingFromTimelineItem, clearTypingState, createTypingStore, getConversationTyping, setTypingState } from "./store/typing-store.js";
11
+ import { TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, TypingReporter, TypingReporterConfig, createTypingReporter } from "./typing-reporter.js";
12
+ import { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, formatFileSize, isAllowedMimeType, isImageMimeType, validateFile, validateFiles } from "./upload-constants.js";
11
13
  import { generateConversationId, generateMessageId } from "./utils.js";
12
14
  import { VisitorData, collectVisitorData } from "./visitor-data.js";
13
15
  import { generateVisitorName, getVisitorNameWithFallback } from "./visitor-name.js";
14
16
  import { clearAllVisitorIds, clearVisitorId, getVisitorId, setVisitorId } from "./visitor-tracker.js";
15
17
  import { CossistantConfig, CossistantError } from "@cossistant/types";
16
- export { type ConversationPagination, type ConversationSeenState, type ConversationTimelineItemsState, type ConversationTypingState, type ConversationsState, type ConversationsStore, CossistantAPIError, CossistantClient, type CossistantConfig, type CossistantError, CossistantRestClient, type DefaultRoutes, type NavigationState, type RouteRegistry, type SUPPORT_PAGES, type SeenActorType, type SeenEntry, type SeenState, type SeenStore, type SupportConfig, type SupportNavigation, type SupportPage, type SupportStore, type SupportStoreActions, type SupportStoreOptions, type SupportStoreState, type SupportStoreStorage, type TimelineItemsState, type TimelineItemsStore, type TypingActorType, type TypingEntry, type TypingState, type TypingStore, type TypingStoreDependencies, type VisitorData, type WebsiteError, type WebsiteState, type WebsiteStatus, type WebsiteStore, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingStore, createWebsiteStore, CossistantClient as default, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hydrateConversationSeen, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen };
18
+ export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, type ConversationPagination, type ConversationSeenState, type ConversationTimelineItemsState, type ConversationTypingState, type ConversationWithSeen, type ConversationsState, type ConversationsStore, CossistantAPIError, CossistantClient, type CossistantConfig, type CossistantError, CossistantRestClient, type DefaultRoutes, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, type NavigationState, type RouteRegistry, type SUPPORT_PAGES, type SeenActorType, type SeenEntry, type SeenState, type SeenStore, type SupportConfig, type SupportNavigation, type SupportPage, type SupportStore, type SupportStoreActions, type SupportStoreOptions, type SupportStoreState, type SupportStoreStorage, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, type TimelineItemsState, type TimelineItemsStore, type TypingActorType, type TypingEntry, type TypingReporter, type TypingReporterConfig, type TypingState, type TypingStore, type TypingStoreDependencies, type VisitorData, type WebsiteError, type WebsiteState, type WebsiteStatus, type WebsiteStore, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, formatFileSize, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hydrateConversationSeen, isAllowedMimeType, isImageMimeType, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen, validateFile, validateFiles };
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { CossistantAPIError } from "./types.js";
2
+ import { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, formatFileSize, isAllowedMimeType, isImageMimeType, validateFile, validateFiles } from "./upload-constants.js";
2
3
  import { generateConversationId, generateMessageId } from "./utils.js";
3
4
  import { collectVisitorData } from "./visitor-data.js";
4
5
  import { clearAllVisitorIds, clearVisitorId, getVisitorId, setVisitorId } from "./visitor-tracker.js";
@@ -11,6 +12,7 @@ import { normalizeLocale } from "./locale-utils.js";
11
12
  import { applyConversationSeenEvent, createSeenStore, hydrateConversationSeen, upsertConversationSeen } from "./store/seen-store.js";
12
13
  import { createSupportStore } from "./store/support-store.js";
13
14
  import { applyConversationTypingEvent, clearTypingFromTimelineItem, clearTypingState, createTypingStore, getConversationTyping, setTypingState } from "./store/typing-store.js";
15
+ import { TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, createTypingReporter } from "./typing-reporter.js";
14
16
  import { generateVisitorName, getVisitorNameWithFallback } from "./visitor-name.js";
15
17
 
16
- export { CossistantAPIError, CossistantClient, CossistantRestClient, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingStore, createWebsiteStore, CossistantClient as default, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hydrateConversationSeen, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen };
18
+ export { ALLOWED_FILE_TYPES_DESCRIPTION, ALLOWED_MIME_TYPES, CossistantAPIError, CossistantClient, CossistantRestClient, FILE_INPUT_ACCEPT, MAX_FILES_PER_MESSAGE, MAX_FILE_SIZE, TYPING_KEEP_ALIVE_MS, TYPING_PREVIEW_MAX_LENGTH, TYPING_SEND_INTERVAL_MS, TYPING_STOP_DELAY_MS, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingReporter, createTypingStore, createWebsiteStore, CossistantClient as default, formatFileSize, generateConversationId, generateMessageId, generateVisitorName, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getVisitorNameWithFallback, getWebsiteState, hydrateConversationSeen, isAllowedMimeType, isImageMimeType, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen, validateFile, validateFiles };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cossistant/core",
3
3
  "type": "module",
4
- "version": "0.0.26",
4
+ "version": "0.0.29",
5
5
  "private": false,
6
6
  "author": "Cossistant Team",
7
7
  "description": "Core library for connecting to Cossistant API and managing data fetching",
@@ -114,6 +114,7 @@ declare const realtimeSchema: {
114
114
  spam: "spam";
115
115
  }>>;
116
116
  deletedAt: z.ZodDefault<z.ZodNullable<z.ZodString>>;
117
+ visitorLastSeenAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
117
118
  lastTimelineItem: z.ZodOptional<z.ZodObject<{
118
119
  id: z.ZodOptional<z.ZodString>;
119
120
  conversationId: z.ZodString;
@@ -222,6 +223,12 @@ declare const realtimeSchema: {
222
223
  resolvedAt: z.ZodNullable<z.ZodString>;
223
224
  resolvedByUserId: z.ZodNullable<z.ZodString>;
224
225
  resolvedByAiAgentId: z.ZodNullable<z.ZodString>;
226
+ escalatedAt: z.ZodNullable<z.ZodString>;
227
+ escalatedByAiAgentId: z.ZodNullable<z.ZodString>;
228
+ escalationReason: z.ZodNullable<z.ZodString>;
229
+ escalationHandledAt: z.ZodNullable<z.ZodString>;
230
+ escalationHandledByUserId: z.ZodNullable<z.ZodString>;
231
+ aiPausedUntil: z.ZodNullable<z.ZodString>;
225
232
  createdAt: z.ZodString;
226
233
  updatedAt: z.ZodString;
227
234
  deletedAt: z.ZodNullable<z.ZodString>;
@@ -427,6 +434,162 @@ declare const realtimeSchema: {
427
434
  }, z.core.$strip>>;
428
435
  }, z.core.$strip>;
429
436
  }, z.core.$strip>;
437
+ readonly conversationEventCreated: z.ZodObject<{
438
+ websiteId: z.ZodString;
439
+ organizationId: z.ZodString;
440
+ visitorId: z.ZodNullable<z.ZodString>;
441
+ userId: z.ZodNullable<z.ZodString>;
442
+ conversationId: z.ZodString;
443
+ aiAgentId: z.ZodNullable<z.ZodString>;
444
+ event: z.ZodObject<{
445
+ id: z.ZodString;
446
+ conversationId: z.ZodString;
447
+ organizationId: z.ZodString;
448
+ type: z.ZodEnum<{
449
+ assigned: "assigned";
450
+ unassigned: "unassigned";
451
+ participant_requested: "participant_requested";
452
+ participant_joined: "participant_joined";
453
+ participant_left: "participant_left";
454
+ status_changed: "status_changed";
455
+ priority_changed: "priority_changed";
456
+ tag_added: "tag_added";
457
+ tag_removed: "tag_removed";
458
+ resolved: "resolved";
459
+ reopened: "reopened";
460
+ visitor_blocked: "visitor_blocked";
461
+ visitor_unblocked: "visitor_unblocked";
462
+ visitor_identified: "visitor_identified";
463
+ }>;
464
+ actorUserId: z.ZodNullable<z.ZodString>;
465
+ actorAiAgentId: z.ZodNullable<z.ZodString>;
466
+ targetUserId: z.ZodNullable<z.ZodString>;
467
+ targetAiAgentId: z.ZodNullable<z.ZodString>;
468
+ message: z.ZodNullable<z.ZodString>;
469
+ metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
470
+ createdAt: z.ZodString;
471
+ updatedAt: z.ZodString;
472
+ deletedAt: z.ZodNullable<z.ZodString>;
473
+ }, z.core.$strip>;
474
+ }, z.core.$strip>;
475
+ readonly conversationUpdated: z.ZodObject<{
476
+ websiteId: z.ZodString;
477
+ organizationId: z.ZodString;
478
+ visitorId: z.ZodNullable<z.ZodString>;
479
+ userId: z.ZodNullable<z.ZodString>;
480
+ conversationId: z.ZodString;
481
+ updates: z.ZodObject<{
482
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
483
+ sentiment: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
484
+ positive: "positive";
485
+ negative: "negative";
486
+ neutral: "neutral";
487
+ }>>>;
488
+ sentimentConfidence: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
489
+ escalatedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
490
+ escalationReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
491
+ }, z.core.$strip>;
492
+ aiAgentId: z.ZodNullable<z.ZodString>;
493
+ }, z.core.$strip>;
494
+ readonly crawlStarted: z.ZodObject<{
495
+ websiteId: z.ZodString;
496
+ organizationId: z.ZodString;
497
+ visitorId: z.ZodNullable<z.ZodString>;
498
+ userId: z.ZodNullable<z.ZodString>;
499
+ linkSourceId: z.ZodString;
500
+ url: z.ZodString;
501
+ discoveredPages: z.ZodArray<z.ZodObject<{
502
+ url: z.ZodString;
503
+ title: z.ZodNullable<z.ZodString>;
504
+ depth: z.ZodNumber;
505
+ }, z.core.$strip>>;
506
+ totalPagesCount: z.ZodNumber;
507
+ }, z.core.$strip>;
508
+ readonly crawlProgress: z.ZodObject<{
509
+ websiteId: z.ZodString;
510
+ organizationId: z.ZodString;
511
+ visitorId: z.ZodNullable<z.ZodString>;
512
+ userId: z.ZodNullable<z.ZodString>;
513
+ linkSourceId: z.ZodString;
514
+ url: z.ZodString;
515
+ page: z.ZodObject<{
516
+ url: z.ZodString;
517
+ title: z.ZodNullable<z.ZodString>;
518
+ status: z.ZodEnum<{
519
+ pending: "pending";
520
+ crawling: "crawling";
521
+ completed: "completed";
522
+ failed: "failed";
523
+ }>;
524
+ sizeBytes: z.ZodOptional<z.ZodNumber>;
525
+ error: z.ZodOptional<z.ZodNullable<z.ZodString>>;
526
+ }, z.core.$strip>;
527
+ completedCount: z.ZodNumber;
528
+ totalCount: z.ZodNumber;
529
+ }, z.core.$strip>;
530
+ readonly crawlCompleted: z.ZodObject<{
531
+ websiteId: z.ZodString;
532
+ organizationId: z.ZodString;
533
+ visitorId: z.ZodNullable<z.ZodString>;
534
+ userId: z.ZodNullable<z.ZodString>;
535
+ linkSourceId: z.ZodString;
536
+ url: z.ZodString;
537
+ crawledPagesCount: z.ZodNumber;
538
+ totalSizeBytes: z.ZodNumber;
539
+ failedPagesCount: z.ZodNumber;
540
+ }, z.core.$strip>;
541
+ readonly crawlFailed: z.ZodObject<{
542
+ websiteId: z.ZodString;
543
+ organizationId: z.ZodString;
544
+ visitorId: z.ZodNullable<z.ZodString>;
545
+ userId: z.ZodNullable<z.ZodString>;
546
+ linkSourceId: z.ZodString;
547
+ url: z.ZodString;
548
+ error: z.ZodString;
549
+ }, z.core.$strip>;
550
+ readonly linkSourceUpdated: z.ZodObject<{
551
+ websiteId: z.ZodString;
552
+ organizationId: z.ZodString;
553
+ visitorId: z.ZodNullable<z.ZodString>;
554
+ userId: z.ZodNullable<z.ZodString>;
555
+ linkSourceId: z.ZodString;
556
+ status: z.ZodEnum<{
557
+ pending: "pending";
558
+ crawling: "crawling";
559
+ completed: "completed";
560
+ failed: "failed";
561
+ mapping: "mapping";
562
+ }>;
563
+ discoveredPagesCount: z.ZodOptional<z.ZodNumber>;
564
+ crawledPagesCount: z.ZodOptional<z.ZodNumber>;
565
+ totalSizeBytes: z.ZodOptional<z.ZodNumber>;
566
+ errorMessage: z.ZodOptional<z.ZodNullable<z.ZodString>>;
567
+ }, z.core.$strip>;
568
+ readonly crawlPagesDiscovered: z.ZodObject<{
569
+ websiteId: z.ZodString;
570
+ organizationId: z.ZodString;
571
+ visitorId: z.ZodNullable<z.ZodString>;
572
+ userId: z.ZodNullable<z.ZodString>;
573
+ linkSourceId: z.ZodString;
574
+ pages: z.ZodArray<z.ZodObject<{
575
+ url: z.ZodString;
576
+ path: z.ZodString;
577
+ depth: z.ZodNumber;
578
+ }, z.core.$strip>>;
579
+ }, z.core.$strip>;
580
+ readonly crawlPageCompleted: z.ZodObject<{
581
+ websiteId: z.ZodString;
582
+ organizationId: z.ZodString;
583
+ visitorId: z.ZodNullable<z.ZodString>;
584
+ userId: z.ZodNullable<z.ZodString>;
585
+ linkSourceId: z.ZodString;
586
+ page: z.ZodObject<{
587
+ url: z.ZodString;
588
+ title: z.ZodNullable<z.ZodString>;
589
+ sizeBytes: z.ZodNumber;
590
+ knowledgeId: z.ZodString;
591
+ }, z.core.$strip>;
592
+ }, z.core.$strip>;
430
593
  };
431
594
  type RealtimeEventType = keyof typeof realtimeSchema;
432
595
  type RealtimeEventPayload<T extends RealtimeEventType> = z.infer<(typeof realtimeSchema)[T]>;
@@ -1 +1 @@
1
- {"version":3,"file":"realtime-events.d.ts","names":[],"sources":["../../types/src/realtime-events.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAiBa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmED,iBAAA,gBAAiC;KAEjC,+BAA+B,qBAAqB,CAAA,CAAE,cACzD,gBAAgB;KAGb,wBAAwB;QAC7B;WACG,qBAAqB"}
1
+ {"version":3,"file":"realtime-events.d.ts","names":[],"sources":["../../types/src/realtime-events.ts"],"sourcesContent":[],"mappings":";;;;;;;;cAqBa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAwLD,iBAAA,gBAAiC;KAEjC,+BAA+B,qBAAqB,CAAA,CAAE,cACzD,gBAAgB;KAGb,wBAAwB;QAC7B;WACG,qBAAqB"}
package/rest-client.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { CreateConversationRequestBody, CreateConversationResponseBody, GetConversationRequest, GetConversationResponse, GetConversationSeenDataResponse, ListConversationsRequest, ListConversationsResponse, MarkConversationSeenRequestBody, MarkConversationSeenResponseBody, SetConversationTypingResponseBody } from "./conversation.js";
2
2
  import { GetConversationTimelineItemsRequest, GetConversationTimelineItemsResponse, SendTimelineItemRequest, SendTimelineItemResponse } from "./timeline-item.js";
3
- import { types_d_exports } from "./types.js";
4
3
  import { IdentifyContactResponse } from "./contact.js";
4
+ import { GenerateUploadUrlRequest, GenerateUploadUrlResponse } from "./upload.js";
5
+ import { types_d_exports } from "./types.js";
5
6
 
6
7
  //#region src/rest-client.d.ts
7
8
  declare class CossistantRestClient {
@@ -59,6 +60,36 @@ declare class CossistantRestClient {
59
60
  getConversationTimelineItems(params: GetConversationTimelineItemsRequest & {
60
61
  conversationId: string;
61
62
  }): Promise<GetConversationTimelineItemsResponse>;
63
+ /**
64
+ * Generate a presigned URL for uploading a file to S3.
65
+ * The URL can be used to PUT a file directly to S3.
66
+ */
67
+ generateUploadUrl(params: Omit<GenerateUploadUrlRequest, "websiteId" | "scope"> & {
68
+ conversationId: string;
69
+ }): Promise<GenerateUploadUrlResponse>;
70
+ /**
71
+ * Upload a file to S3 using a presigned URL.
72
+ * @returns The public URL of the uploaded file
73
+ */
74
+ uploadFile(file: File, uploadUrl: string, contentType: string): Promise<void>;
75
+ /**
76
+ * Upload multiple files for a conversation message.
77
+ * Files are uploaded in parallel and the function returns timeline parts
78
+ * that can be included in a message.
79
+ */
80
+ uploadFilesForMessage(files: File[], conversationId: string): Promise<Array<{
81
+ type: "image";
82
+ url: string;
83
+ mediaType: string;
84
+ fileName?: string;
85
+ size?: number;
86
+ } | {
87
+ type: "file";
88
+ url: string;
89
+ mediaType: string;
90
+ fileName?: string;
91
+ size?: number;
92
+ }>>;
62
93
  }
63
94
  //#endregion
64
95
  export { CossistantRestClient };
@@ -1 +1 @@
1
- {"version":3,"file":"rest-client.d.ts","names":[],"sources":["../src/rest-client.ts"],"sourcesContent":[],"mappings":";;;;;;cAqCa,oBAAA;;EAAA,QAAA,WAAA;EAQQ,QAAA,SAAA;EA8LQ,QAAA,SAAA;EAAR,QAAA,SAAA;EA6ET,QAAA,cAAA;EACA,WAAA,CAAA,MAAA,EA5QS,eA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