@cossistant/core 0.0.7

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.
Files changed (76) hide show
  1. package/dist/_virtual/rolldown_runtime.js +33 -0
  2. package/dist/client.d.ts +82 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +275 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/contact.d.ts +28 -0
  7. package/dist/contact.d.ts.map +1 -0
  8. package/dist/conversation.d.ts +85 -0
  9. package/dist/conversation.d.ts.map +1 -0
  10. package/dist/index.d.ts +15 -0
  11. package/dist/index.js +16 -0
  12. package/dist/locale-utils.d.ts +17 -0
  13. package/dist/locale-utils.d.ts.map +1 -0
  14. package/dist/locale-utils.js +22 -0
  15. package/dist/locale-utils.js.map +1 -0
  16. package/dist/logger.d.ts +11 -0
  17. package/dist/logger.d.ts.map +1 -0
  18. package/dist/logger.js +22 -0
  19. package/dist/logger.js.map +1 -0
  20. package/dist/realtime-events.d.ts +120 -0
  21. package/dist/realtime-events.d.ts.map +1 -0
  22. package/dist/rest-client.d.ts +65 -0
  23. package/dist/rest-client.d.ts.map +1 -0
  24. package/dist/rest-client.js +367 -0
  25. package/dist/rest-client.js.map +1 -0
  26. package/dist/schemas.d.ts +33 -0
  27. package/dist/schemas.d.ts.map +1 -0
  28. package/dist/store/conversations-store.d.ts +22 -0
  29. package/dist/store/conversations-store.d.ts.map +1 -0
  30. package/dist/store/conversations-store.js +108 -0
  31. package/dist/store/conversations-store.js.map +1 -0
  32. package/dist/store/create-store.d.ts +14 -0
  33. package/dist/store/create-store.d.ts.map +1 -0
  34. package/dist/store/create-store.js +47 -0
  35. package/dist/store/create-store.js.map +1 -0
  36. package/dist/store/seen-store.d.ts +37 -0
  37. package/dist/store/seen-store.d.ts.map +1 -0
  38. package/dist/store/seen-store.js +131 -0
  39. package/dist/store/seen-store.js.map +1 -0
  40. package/dist/store/support-store.d.ts +63 -0
  41. package/dist/store/support-store.d.ts.map +1 -0
  42. package/dist/store/support-store.js +170 -0
  43. package/dist/store/support-store.js.map +1 -0
  44. package/dist/store/timeline-items-store.d.ts +27 -0
  45. package/dist/store/timeline-items-store.d.ts.map +1 -0
  46. package/dist/store/timeline-items-store.js +142 -0
  47. package/dist/store/timeline-items-store.js.map +1 -0
  48. package/dist/store/typing-store.d.ts +50 -0
  49. package/dist/store/typing-store.d.ts.map +1 -0
  50. package/dist/store/typing-store.js +149 -0
  51. package/dist/store/typing-store.js.map +1 -0
  52. package/dist/store/website-store.d.ts +24 -0
  53. package/dist/store/website-store.d.ts.map +1 -0
  54. package/dist/store/website-store.js +60 -0
  55. package/dist/store/website-store.js.map +1 -0
  56. package/dist/timeline-item.d.ts +207 -0
  57. package/dist/timeline-item.d.ts.map +1 -0
  58. package/dist/types/src/enums.js +24 -0
  59. package/dist/types/src/enums.js.map +1 -0
  60. package/dist/types.d.ts +17 -0
  61. package/dist/types.d.ts.map +1 -0
  62. package/dist/types.js +17 -0
  63. package/dist/types.js.map +1 -0
  64. package/dist/utils.d.ts +8 -0
  65. package/dist/utils.d.ts.map +1 -0
  66. package/dist/utils.js +20 -0
  67. package/dist/utils.js.map +1 -0
  68. package/dist/visitor-data.d.ts +33 -0
  69. package/dist/visitor-data.d.ts.map +1 -0
  70. package/dist/visitor-data.js +212 -0
  71. package/dist/visitor-data.js.map +1 -0
  72. package/dist/visitor-tracker.d.ts +31 -0
  73. package/dist/visitor-tracker.d.ts.map +1 -0
  74. package/dist/visitor-tracker.js +109 -0
  75. package/dist/visitor-tracker.js.map +1 -0
  76. package/package.json +48 -0
@@ -0,0 +1,33 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (all) => {
9
+ let target = {};
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
+ return target;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
18
+ key = keys[i];
19
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
20
+ get: ((k) => from[k]).bind(null, key),
21
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
22
+ });
23
+ }
24
+ return to;
25
+ };
26
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
28
+ value: mod,
29
+ enumerable: true
30
+ }) : target, mod));
31
+
32
+ //#endregion
33
+ export { __export, __reExport };
@@ -0,0 +1,82 @@
1
+ import { CreateConversationRequestBody, CreateConversationResponseBody, GetConversationRequest, GetConversationResponse, ListConversationsRequest, ListConversationsResponse, MarkConversationSeenRequestBody, MarkConversationSeenResponseBody, SetConversationTypingResponseBody } from "./conversation.js";
2
+ import { GetConversationTimelineItemsRequest, GetConversationTimelineItemsResponse, SendTimelineItemRequest, SendTimelineItemResponse, TimelineItem } from "./timeline-item.js";
3
+ import { Conversation as Conversation$1 } from "./schemas.js";
4
+ import { ConversationsStore } from "./store/conversations-store.js";
5
+ import { TimelineItemsStore } from "./store/timeline-items-store.js";
6
+ import { WebsiteStore } from "./store/website-store.js";
7
+ import { types_d_exports } from "./types.js";
8
+ import { AnyRealtimeEvent, DefaultMessage, IdentifyContactResponse } from "@cossistant/types";
9
+
10
+ //#region src/client.d.ts
11
+ type InitiateConversationParams = {
12
+ conversationId?: string;
13
+ visitorId?: string | null;
14
+ websiteId?: string | null;
15
+ title?: string;
16
+ status?: Conversation$1["status"];
17
+ defaultTimelineItems?: Array<DefaultMessage | TimelineItem>;
18
+ };
19
+ type InitiateConversationResult = {
20
+ conversationId: string;
21
+ conversation: Conversation$1;
22
+ defaultTimelineItems: TimelineItem[];
23
+ };
24
+ declare class CossistantClient {
25
+ private restClient;
26
+ private config;
27
+ private pendingConversations;
28
+ private websiteRequest;
29
+ readonly conversationsStore: ConversationsStore;
30
+ readonly timelineItemsStore: TimelineItemsStore;
31
+ readonly websiteStore: WebsiteStore;
32
+ constructor(config: types_d_exports.CossistantConfig);
33
+ updateConfiguration(config: Partial<types_d_exports.CossistantConfig>): void;
34
+ getConfiguration(): types_d_exports.CossistantConfig;
35
+ fetchWebsite(params?: {
36
+ force?: boolean;
37
+ }): Promise<types_d_exports.PublicWebsiteResponse>;
38
+ getWebsite(): Promise<types_d_exports.PublicWebsiteResponse>;
39
+ setWebsiteContext(websiteId: string, visitorId?: string): void;
40
+ setVisitorBlocked(isBlocked: boolean): void;
41
+ updateVisitorMetadata(metadata: types_d_exports.VisitorMetadata): Promise<types_d_exports.VisitorResponse>;
42
+ identify(params: {
43
+ externalId?: string;
44
+ email?: string;
45
+ name?: string;
46
+ image?: string;
47
+ metadata?: Record<string, unknown>;
48
+ contactOrganizationId?: string;
49
+ }): Promise<IdentifyContactResponse>;
50
+ updateContactMetadata(metadata: Record<string, unknown>): Promise<types_d_exports.VisitorResponse>;
51
+ initiateConversation(params?: InitiateConversationParams): InitiateConversationResult;
52
+ createConversation(params?: Partial<CreateConversationRequestBody>): Promise<CreateConversationResponseBody>;
53
+ listConversations(params?: Partial<ListConversationsRequest>): Promise<ListConversationsResponse>;
54
+ getConversation(params: GetConversationRequest): Promise<GetConversationResponse>;
55
+ markConversationSeen(params: {
56
+ conversationId: string;
57
+ } & Partial<MarkConversationSeenRequestBody>): Promise<MarkConversationSeenResponseBody>;
58
+ getConversationSeenData(params: {
59
+ conversationId: string;
60
+ }): Promise<any>;
61
+ setVisitorTyping(params: {
62
+ conversationId: string;
63
+ isTyping: boolean;
64
+ visitorPreview?: string | null;
65
+ visitorId?: string;
66
+ }): Promise<SetConversationTypingResponseBody>;
67
+ getConversationTimelineItems(params: GetConversationTimelineItemsRequest & {
68
+ conversationId: string;
69
+ }): Promise<GetConversationTimelineItemsResponse>;
70
+ sendMessage(params: SendTimelineItemRequest & {
71
+ createIfPending?: boolean;
72
+ }): Promise<SendTimelineItemResponse & {
73
+ conversation?: Conversation$1;
74
+ initialTimelineItems?: TimelineItem[];
75
+ wasConversationCreated?: boolean;
76
+ }>;
77
+ handleRealtimeEvent(event: AnyRealtimeEvent): void;
78
+ destroy(): void;
79
+ }
80
+ //#endregion
81
+ export { CossistantClient };
82
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +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,oBAAA,CAAA,EAAA,KAAA,CAAM,cAAN,GAAuB,YAAvB,CAAA;CAAK;AAAA,KAGxB,0BAAA,GAA0B;EAMlB,cAAA,EAAA,MAAgB;EAKC,YAAA,EATf,cASe;EACA,oBAAA,EATP,YASO,EAAA;CACN;AAEH,cATR,gBAAA,CASQ;EASgB,QAAA,UAAA;EAAR,QAAA,MAAA;EAMR,QAAA,oBAAA;EAOT,QAAA,cAAA;EAAR,SAAA,kBAAA,EA1B0B,kBA0B1B;EAoCyB,SAAA,kBAAA,EA7DC,kBA6DD;EAAR,SAAA,YAAA,EA5DG,YA4DH;EAaT,WAAA,CAAA,MAAA,EAvES,eAAA,CAAA,gBAuET;EACA,mBAAA,CAAA,MAAA,EA/DiB,OA+DjB,CA/DyB,eAAA,CAAA,gBA+DzB,CA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AA,MAAA,EAVJ,sBAUI,CAAA,EATV,OASU,CATF,uBASE,CAAA;EAAR,oBAAA,CAAA,MAAA,EAAA;IACM,cAAA,EAAA,MAAA;EAAR,CAAA,GADE,OACF,CADU,+BACV,CAAA,CAAA,EAAA,OAAA,CAAQ,gCAAR,CAAA;EAI6D,uBAAA,CAAA,MAAA,EAAA;IASpD,cAAA,EAAA,MAAA;EAAR,CAAA,CAAA,EAT4D,OAS5D,CAAA,GAAA,CAAA;EAOK,gBAAA,CAAA,MAAA,EAAA;IACE,cAAA,EAAA,MAAA;IAAR,QAAA,EAAA,OAAA;IAWM,cAAA,CAAA,EAAA,MAAA,GAAA,IAAA;IAER,SAAA,CAAA,EAAA,MAAA;EACgB,CAAA,CAAA,EAtBb,OAsBa,CAtBL,iCAsBK,CAAA;EACQ,4BAAA,CAAA,MAAA,EAhBhB,mCAgBgB,GAAA;IAHtB,cAAA,EAAA,MAAA;EAoHwB,CAAA,CAAA,EAhIxB,OAgIwB,CAhIhB,oCAgIgB,CAAA;EAAgB,WAAA,CAAA,MAAA,EArHlC,uBAqHkC,GAAA;;MApHxC,QACF;mBACgB;2BACQ;;;6BAiHE"}
package/dist/client.js ADDED
@@ -0,0 +1,275 @@
1
+ import { ConversationStatus, ConversationTimelineType, SenderType, TimelineItemVisibility } from "./types/src/enums.js";
2
+ import { generateConversationId, generateMessageId } from "./utils.js";
3
+ import { CossistantRestClient } from "./rest-client.js";
4
+ import { createConversationsStore } from "./store/conversations-store.js";
5
+ import { createTimelineItemsStore } from "./store/timeline-items-store.js";
6
+ import { createWebsiteStore } from "./store/website-store.js";
7
+
8
+ //#region src/client.ts
9
+ var CossistantClient = class {
10
+ restClient;
11
+ config;
12
+ pendingConversations = /* @__PURE__ */ new Map();
13
+ websiteRequest = null;
14
+ conversationsStore;
15
+ timelineItemsStore;
16
+ websiteStore;
17
+ constructor(config) {
18
+ this.config = config;
19
+ this.restClient = new CossistantRestClient(config);
20
+ this.conversationsStore = createConversationsStore();
21
+ this.timelineItemsStore = createTimelineItemsStore();
22
+ this.websiteStore = createWebsiteStore();
23
+ }
24
+ updateConfiguration(config) {
25
+ this.config = {
26
+ ...this.config,
27
+ ...config
28
+ };
29
+ this.restClient.updateConfiguration(config);
30
+ }
31
+ getConfiguration() {
32
+ return { ...this.config };
33
+ }
34
+ async fetchWebsite(params = {}) {
35
+ const { force = false } = params;
36
+ const current = this.websiteStore.getState();
37
+ if (!force) {
38
+ if (current.status === "success" && current.website) return current.website;
39
+ if (this.websiteRequest) return this.websiteRequest;
40
+ }
41
+ this.websiteStore.setLoading();
42
+ const request = this.restClient.getWebsite().then((website) => {
43
+ this.websiteStore.setWebsite(website);
44
+ return website;
45
+ }).catch((error) => {
46
+ this.websiteStore.setError(error);
47
+ throw error;
48
+ }).finally(() => {
49
+ if (this.websiteRequest === request) this.websiteRequest = null;
50
+ });
51
+ this.websiteRequest = request;
52
+ return request;
53
+ }
54
+ async getWebsite() {
55
+ return this.fetchWebsite({ force: true });
56
+ }
57
+ setWebsiteContext(websiteId, visitorId) {
58
+ this.restClient.setWebsiteContext(websiteId, visitorId);
59
+ }
60
+ setVisitorBlocked(isBlocked) {
61
+ this.restClient.setVisitorBlocked(isBlocked);
62
+ }
63
+ async updateVisitorMetadata(metadata) {
64
+ return this.restClient.updateVisitorMetadata(metadata);
65
+ }
66
+ async identify(params) {
67
+ return this.restClient.identify(params);
68
+ }
69
+ async updateContactMetadata(metadata) {
70
+ return this.restClient.updateContactMetadata(metadata);
71
+ }
72
+ initiateConversation(params = {}) {
73
+ const conversationId = params.conversationId ?? generateConversationId();
74
+ const now = (/* @__PURE__ */ new Date()).toISOString();
75
+ const timelineItems = (params.defaultTimelineItems ?? []).map((item) => normalizeBootstrapTimelineItem(conversationId, item));
76
+ const existing = this.conversationsStore.getState().byId[conversationId];
77
+ const baseVisitorId = params.visitorId ?? this.restClient.getCurrentVisitorId() ?? "";
78
+ const baseWebsiteId = params.websiteId ?? this.restClient.getCurrentWebsiteId() ?? "";
79
+ const conversation = existing ? {
80
+ ...existing,
81
+ title: params.title ?? existing.title,
82
+ status: params.status ?? existing.status,
83
+ updatedAt: now,
84
+ lastTimelineItem: timelineItems.at(-1) ?? existing.lastTimelineItem
85
+ } : {
86
+ id: conversationId,
87
+ title: params.title,
88
+ createdAt: now,
89
+ updatedAt: now,
90
+ visitorId: baseVisitorId,
91
+ websiteId: baseWebsiteId,
92
+ status: params.status ?? ConversationStatus.OPEN,
93
+ deletedAt: null,
94
+ lastTimelineItem: timelineItems.at(-1)
95
+ };
96
+ this.conversationsStore.ingestConversation(conversation);
97
+ if (timelineItems.length > 0) this.timelineItemsStore.ingestPage(conversationId, {
98
+ items: timelineItems,
99
+ hasNextPage: false,
100
+ nextCursor: void 0
101
+ });
102
+ if (!existing || this.pendingConversations.has(conversationId)) this.pendingConversations.set(conversationId, {
103
+ conversation,
104
+ initialTimelineItems: timelineItems
105
+ });
106
+ return {
107
+ conversationId,
108
+ conversation,
109
+ defaultTimelineItems: timelineItems
110
+ };
111
+ }
112
+ async createConversation(params) {
113
+ const response = await this.restClient.createConversation(params);
114
+ this.conversationsStore.ingestConversation(response.conversation);
115
+ return response;
116
+ }
117
+ async listConversations(params) {
118
+ const response = await this.restClient.listConversations(params);
119
+ this.conversationsStore.ingestList(response);
120
+ return response;
121
+ }
122
+ async getConversation(params) {
123
+ const response = await this.restClient.getConversation(params);
124
+ this.conversationsStore.ingestConversation(response.conversation);
125
+ return response;
126
+ }
127
+ async markConversationSeen(params) {
128
+ return this.restClient.markConversationSeen(params);
129
+ }
130
+ async getConversationSeenData(params) {
131
+ return this.restClient.getConversationSeenData(params);
132
+ }
133
+ async setVisitorTyping(params) {
134
+ return this.restClient.setConversationTyping(params);
135
+ }
136
+ async getConversationTimelineItems(params) {
137
+ const response = await this.restClient.getConversationTimelineItems(params);
138
+ this.timelineItemsStore.ingestPage(params.conversationId, {
139
+ items: response.items,
140
+ hasNextPage: response.hasNextPage,
141
+ nextCursor: response.nextCursor ?? void 0
142
+ });
143
+ return response;
144
+ }
145
+ async sendMessage(params) {
146
+ const { createIfPending,...rest } = params;
147
+ const optimisticId = rest.item.id ?? generateMessageId();
148
+ const createdAt = rest.item.createdAt ? rest.item.createdAt : (/* @__PURE__ */ new Date()).toISOString();
149
+ const optimisticTimelineItem = {
150
+ id: optimisticId,
151
+ conversationId: rest.conversationId,
152
+ organizationId: "",
153
+ visibility: rest.item.visibility ?? TimelineItemVisibility.PUBLIC,
154
+ type: rest.item.type ?? ConversationTimelineType.MESSAGE,
155
+ text: rest.item.text,
156
+ tool: rest.item.tool ?? null,
157
+ parts: rest.item.parts && rest.item.parts.length > 0 ? rest.item.parts : rest.item.text ? [{
158
+ type: "text",
159
+ text: rest.item.text
160
+ }] : [],
161
+ userId: rest.item.userId ?? null,
162
+ visitorId: rest.item.visitorId ?? null,
163
+ aiAgentId: rest.item.aiAgentId ?? null,
164
+ createdAt,
165
+ deletedAt: null
166
+ };
167
+ this.timelineItemsStore.ingestTimelineItem(optimisticTimelineItem);
168
+ const pending = this.pendingConversations.get(rest.conversationId);
169
+ if (pending && createIfPending !== false) try {
170
+ const response = await this.restClient.createConversation({
171
+ conversationId: rest.conversationId,
172
+ defaultTimelineItems: [...pending.initialTimelineItems, optimisticTimelineItem]
173
+ });
174
+ this.conversationsStore.ingestConversation(response.conversation);
175
+ this.timelineItemsStore.removeTimelineItem(rest.conversationId, optimisticId);
176
+ this.timelineItemsStore.clearConversation(rest.conversationId);
177
+ this.timelineItemsStore.ingestPage(rest.conversationId, {
178
+ items: response.initialTimelineItems,
179
+ hasNextPage: false,
180
+ nextCursor: void 0
181
+ });
182
+ this.pendingConversations.delete(rest.conversationId);
183
+ return {
184
+ item: response.initialTimelineItems.at(-1) ?? response.initialTimelineItems[0],
185
+ conversation: response.conversation,
186
+ initialTimelineItems: response.initialTimelineItems,
187
+ wasConversationCreated: true
188
+ };
189
+ } catch (error) {
190
+ this.timelineItemsStore.removeTimelineItem(rest.conversationId, optimisticId);
191
+ throw error;
192
+ }
193
+ const { createdAt: _createdAt,...restItem } = rest.item;
194
+ const payload = {
195
+ ...rest,
196
+ item: {
197
+ ...restItem,
198
+ id: optimisticId
199
+ }
200
+ };
201
+ try {
202
+ const response = await this.restClient.sendMessage(payload);
203
+ this.timelineItemsStore.finalizeTimelineItem(rest.conversationId, optimisticId, response.item);
204
+ return response;
205
+ } catch (error) {
206
+ this.timelineItemsStore.removeTimelineItem(rest.conversationId, optimisticId);
207
+ throw error;
208
+ }
209
+ }
210
+ handleRealtimeEvent(event) {
211
+ if (event.type === "conversationCreated") {
212
+ const { conversation, header } = event.payload;
213
+ this.conversationsStore.ingestConversation({
214
+ ...conversation,
215
+ lastTimelineItem: conversation.lastTimelineItem ?? void 0
216
+ });
217
+ } else if (event.type === "timelineItemCreated") {
218
+ const timelineItem = this.timelineItemsStore.ingestRealtimeTimelineItem(event);
219
+ const existingConversation = this.conversationsStore.getState().byId[timelineItem.conversationId];
220
+ if (existingConversation) {
221
+ const nextConversation = {
222
+ ...existingConversation,
223
+ updatedAt: timelineItem.createdAt,
224
+ lastTimelineItem: timelineItem
225
+ };
226
+ this.conversationsStore.ingestConversation(nextConversation);
227
+ }
228
+ }
229
+ }
230
+ destroy() {}
231
+ };
232
+ function normalizeBootstrapTimelineItem(conversationId, item) {
233
+ if (isDefaultMessage(item)) {
234
+ const createdAt$1 = (/* @__PURE__ */ new Date()).toISOString();
235
+ return {
236
+ id: generateMessageId(),
237
+ conversationId,
238
+ organizationId: "",
239
+ type: ConversationTimelineType.MESSAGE,
240
+ text: item.content,
241
+ parts: [{
242
+ type: "text",
243
+ text: item.content
244
+ }],
245
+ visibility: TimelineItemVisibility.PUBLIC,
246
+ userId: item.senderType === SenderType.TEAM_MEMBER ? item.senderId ?? null : null,
247
+ aiAgentId: item.senderType === SenderType.AI ? item.senderId ?? null : null,
248
+ visitorId: item.senderType === SenderType.VISITOR ? item.senderId ?? null : null,
249
+ createdAt: createdAt$1,
250
+ deletedAt: null
251
+ };
252
+ }
253
+ const createdAt = item.createdAt ? item.createdAt : (/* @__PURE__ */ new Date()).toISOString();
254
+ return {
255
+ ...item,
256
+ id: item.id ?? generateMessageId(),
257
+ conversationId,
258
+ organizationId: item.organizationId || "",
259
+ type: item.type ?? ConversationTimelineType.MESSAGE,
260
+ tool: item.tool ?? null,
261
+ createdAt,
262
+ deletedAt: item.deletedAt ?? null,
263
+ userId: item.userId ?? null,
264
+ aiAgentId: item.aiAgentId ?? null,
265
+ visitorId: item.visitorId ?? null,
266
+ visibility: item.visibility ?? TimelineItemVisibility.PUBLIC
267
+ };
268
+ }
269
+ function isDefaultMessage(item) {
270
+ return item.content !== void 0;
271
+ }
272
+
273
+ //#endregion
274
+ export { CossistantClient };
275
+ //# sourceMappingURL=client.js.map
@@ -0,0 +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 = 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: new Date().toISOString();\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 = 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 ? item.createdAt : new Date().toISOString();\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,EAAE,GAAG,KAAK,QAAQ;;CAI1B,MAAM,aACL,SAA8B,EAAE,EACC;EACjC,MAAM,EAAE,QAAQ,UAAU;EAC1B,MAAMA,UAAwB,KAAK,aAAa,UAAU;AAE1D,MAAI,CAAC,OAAO;AACX,OAAI,QAAQ,WAAW,a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AAC;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,YAAY,KAAK,6BAAY,IAAI,MAAM,EAAC,aAAa;AAE5E,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"}
@@ -0,0 +1,28 @@
1
+ import { z } from "@hono/zod-openapi";
2
+
3
+ //#region ../types/src/api/contact.d.ts
4
+
5
+ /**
6
+ * Identify contact response schema
7
+ */
8
+ declare const identifyContactResponseSchema: z.ZodObject<{
9
+ contact: z.ZodObject<{
10
+ id: z.ZodULID;
11
+ externalId: z.ZodNullable<z.ZodString>;
12
+ name: z.ZodNullable<z.ZodString>;
13
+ email: z.ZodNullable<z.ZodEmail>;
14
+ image: z.ZodNullable<z.ZodURL>;
15
+ metadata: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>>>;
16
+ contactOrganizationId: z.ZodNullable<z.ZodULID>;
17
+ websiteId: z.ZodULID;
18
+ organizationId: z.ZodULID;
19
+ userId: z.ZodNullable<z.ZodULID>;
20
+ createdAt: z.ZodString;
21
+ updatedAt: z.ZodString;
22
+ }, z.core.$strip>;
23
+ visitorId: z.ZodULID;
24
+ }, z.core.$strip>;
25
+ type IdentifyContactResponse = z.infer<typeof identifyContactResponseSchema>;
26
+ //#endregion
27
+ export { IdentifyContactResponse };
28
+ //# sourceMappingURL=contact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact.d.ts","names":[],"sources":["../../types/src/api/contact.ts"],"sourcesContent":[],"mappings":";;;;;;;cAmQa,+BAA6B,CAAA,CAAA;;;;;;;;;;;;;;;;;KAQ9B,uBAAA,GAA0B,CAAA,CAAE,aAChC"}
@@ -0,0 +1,85 @@
1
+ import { z } from "@hono/zod-openapi";
2
+
3
+ //#region ../types/src/api/conversation.d.ts
4
+ declare const createConversationRequestSchema: z.ZodObject<{
5
+ visitorId: z.ZodOptional<z.ZodString>;
6
+ conversationId: z.ZodOptional<z.ZodString>;
7
+ defaultTimelineItems: z.ZodArray<any>;
8
+ channel: z.ZodDefault<z.ZodString>;
9
+ }, z.core.$strip>;
10
+ type CreateConversationRequestBody = z.infer<typeof createConversationRequestSchema>;
11
+ declare const createConversationResponseSchema: z.ZodObject<{
12
+ initialTimelineItems: z.ZodArray<any>;
13
+ conversation: any;
14
+ }, z.core.$strip>;
15
+ type CreateConversationResponseBody = z.infer<typeof createConversationResponseSchema>;
16
+ declare const listConversationsRequestSchema: z.ZodObject<{
17
+ visitorId: z.ZodOptional<z.ZodString>;
18
+ page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
19
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
20
+ status: z.ZodOptional<z.ZodEnum<{
21
+ open: "open";
22
+ closed: "closed";
23
+ }>>;
24
+ orderBy: z.ZodDefault<z.ZodEnum<{
25
+ createdAt: "createdAt";
26
+ updatedAt: "updatedAt";
27
+ }>>;
28
+ order: z.ZodDefault<z.ZodEnum<{
29
+ asc: "asc";
30
+ desc: "desc";
31
+ }>>;
32
+ }, z.core.$strip>;
33
+ type ListConversationsRequest = z.infer<typeof listConversationsRequestSchema>;
34
+ declare const listConversationsResponseSchema: z.ZodObject<{
35
+ conversations: z.ZodArray<any>;
36
+ pagination: z.ZodObject<{
37
+ page: z.ZodNumber;
38
+ limit: z.ZodNumber;
39
+ total: z.ZodNumber;
40
+ totalPages: z.ZodNumber;
41
+ hasMore: z.ZodBoolean;
42
+ }, z.core.$strip>;
43
+ }, z.core.$strip>;
44
+ type ListConversationsResponse = z.infer<typeof listConversationsResponseSchema>;
45
+ declare const getConversationRequestSchema: z.ZodObject<{
46
+ conversationId: z.ZodString;
47
+ }, z.core.$strip>;
48
+ type GetConversationRequest = z.infer<typeof getConversationRequestSchema>;
49
+ declare const getConversationResponseSchema: z.ZodObject<{
50
+ conversation: any;
51
+ }, z.core.$strip>;
52
+ type GetConversationResponse = z.infer<typeof getConversationResponseSchema>;
53
+ declare const markConversationSeenRequestSchema: z.ZodObject<{
54
+ visitorId: z.ZodOptional<z.ZodString>;
55
+ }, z.core.$strip>;
56
+ type MarkConversationSeenRequestBody = z.infer<typeof markConversationSeenRequestSchema>;
57
+ declare const markConversationSeenResponseSchema: z.ZodObject<{
58
+ conversationId: z.ZodString;
59
+ lastSeenAt: z.ZodString;
60
+ }, z.core.$strip>;
61
+ type MarkConversationSeenResponseBody = z.infer<typeof markConversationSeenResponseSchema>;
62
+ declare const setConversationTypingResponseSchema: z.ZodObject<{
63
+ conversationId: z.ZodString;
64
+ isTyping: z.ZodBoolean;
65
+ visitorPreview: z.ZodNullable<z.ZodString>;
66
+ sentAt: z.ZodString;
67
+ }, z.core.$strip>;
68
+ type SetConversationTypingResponseBody = z.infer<typeof setConversationTypingResponseSchema>;
69
+ declare const getConversationSeenDataResponseSchema: z.ZodObject<{
70
+ seenData: z.ZodArray<z.ZodObject<{
71
+ id: z.ZodString;
72
+ conversationId: z.ZodString;
73
+ userId: z.ZodNullable<z.ZodString>;
74
+ visitorId: z.ZodNullable<z.ZodString>;
75
+ aiAgentId: z.ZodNullable<z.ZodString>;
76
+ lastSeenAt: z.ZodString;
77
+ createdAt: z.ZodString;
78
+ updatedAt: z.ZodString;
79
+ deletedAt: z.ZodNullable<z.ZodString>;
80
+ }, z.core.$strip>>;
81
+ }, z.core.$strip>;
82
+ type GetConversationSeenDataResponse = z.infer<typeof getConversationSeenDataResponseSchema>;
83
+ //#endregion
84
+ export { CreateConversationRequestBody, CreateConversationResponseBody, GetConversationRequest, GetConversationResponse, GetConversationSeenDataResponse, ListConversationsRequest, ListConversationsResponse, MarkConversationSeenRequestBody, MarkConversationSeenResponseBody, SetConversationTypingResponseBody };
85
+ //# sourceMappingURL=conversation.d.ts.map
@@ -0,0 +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;;;;AA1BD,KAmChC,8BAAA,GAAiC,CAAA,CAAE,KAnCH,CAAA,OAoCpC,gCApCoC,CAAA;AAAA,cAuC/B,8BAvC+B,EAuCD,CAAA,CAAA,SAvCC,CAAA;EAsBhC,SAAA,eAAA,YAA6B,CAAA;EAI5B,IAAA,cAAA,mBAOV,CAAA,OAAA,CAAA,CAAA;;;IAP0C,IAAA,EAAA,MAAA;IAAA,MAAA,EAAA,QAAA;EASjC,CAAA,CAAA,CAAA;EAIC,OAAA,cAAA,UAAA,CAAA;;;;;;;;;KA6BD,wBAAA,GAA2B,CAAA,CAAE,aACjC;cAGK,iCAA+B,CAAA,CAAA;;;;IAjCD,KAAA,aAAA;IAAA,KAAA,aAAA;IA6B/B,UAAA,aAAwB;IAIvB,OAAA,cAAA;;;KAeD,yBAAA,GAA4B,CAAA,CAAE,aAClC;cAGK,8BAA4B,CAAA,CAAA;;;KAU7B,sBAAA,GAAyB,CAAA,CAAE,aAC/B;cAGK,+BAA6B,CAAA,CAAA;;CAjCE,EAuCzC,CAAA,CAAA,IAAA,CAAA,MAvCyC,CAAA;AAAA,KAyChC,uBAAA,GAA0B,CAAA,CAAE,KAzCI,CAAA,OA0CpC,6BA1CoC,CAAA;AAehC,cA8BC,iCA7BL,EA6BsC,CAAA,CAAA,SA7BtC,CAAA;EAGK,SAAA,eAAA,YAQV,CAAA;;KA8BS,+BAAA,GAAkC,CAAA,CAAE,aACxC;AAvCiC,cA0C5B,kCA1C4B,EA0CM,CAAA,CAAA,SA1CN,CAAA;EAAA,cAAA,aAAA;EAU7B,UAAA,aAAA;AAIZ,CAAA,eAAa,CAAA;AAQD,KAkCA,gCAAA,GAAmC,CAAA,CAAE,KAjCzC,CAAA,OAkCA,kCAnCqC,CAAA;AAgBjC,cA6CC,mCA5CL,EA4CwC,CAAA,CAAA,SA5CxC,CAAA;EAGK,cAAA,aAAA;;;;CAAkC,eAAA,CAAA;AAAA,KA6DnC,iCAAA,GAAoC,CAAA,CAAE,KA7DH,CAAA,OA8DvC,mCA9DuC,CAAA;AAcnC,cAmDC,qCAlDL,EAkD0C,CAAA,CAAA,SAlD1C,CAAA;EA0BK,QAAA,YAAA,YAAA,CAAA;;;;;;;IAAmC,SAAA,aAAA;IAAA,SAAA,aAAA;IAoBpC,SAAA,eAAA,YAAiC,CAAA;EAIhC,CAAA,eAAA,CAAA,CAAA;;KAuCD,+BAAA,GAAkC,CAAA,CAAE,aACxC"}
@@ -0,0 +1,15 @@
1
+ import { ConversationPagination, ConversationsState, ConversationsStore, createConversationsStore, getConversationById, getConversationPagination, getConversations } from "./store/conversations-store.js";
2
+ import { ConversationTimelineItemsState, TimelineItemsState, TimelineItemsStore, createTimelineItemsStore, getConversationTimelineItems } from "./store/timeline-items-store.js";
3
+ import { WebsiteError, WebsiteState, WebsiteStatus, WebsiteStore, createWebsiteStore, getWebsiteState } from "./store/website-store.js";
4
+ import { CossistantAPIError } from "./types.js";
5
+ import { CossistantClient } from "./client.js";
6
+ import { normalizeLocale } from "./locale-utils.js";
7
+ import { CossistantRestClient } from "./rest-client.js";
8
+ import { ConversationSeenState, SeenActorType, SeenEntry, SeenState, SeenStore, applyConversationSeenEvent, createSeenStore, hydrateConversationSeen, upsertConversationSeen } from "./store/seen-store.js";
9
+ import { NavigationState, SUPPORT_PAGES, SupportConfig, SupportNavigation, SupportStore, SupportStoreActions, SupportStoreOptions, SupportStoreState, SupportStoreStorage, createSupportStore } from "./store/support-store.js";
10
+ import { ConversationTypingState, TypingActorType, TypingEntry, TypingState, TypingStore, TypingStoreDependencies, applyConversationTypingEvent, clearTypingFromTimelineItem, clearTypingState, createTypingStore, getConversationTyping, setTypingState } from "./store/typing-store.js";
11
+ import { generateConversationId, generateMessageId } from "./utils.js";
12
+ import { VisitorData, collectVisitorData } from "./visitor-data.js";
13
+ import { clearAllVisitorIds, clearVisitorId, getVisitorId, setVisitorId } from "./visitor-tracker.js";
14
+ import { CossistantConfig, CossistantError, Message, PublicWebsiteResponse, conversationSchema } from "@cossistant/types";
15
+ export { type ConversationPagination, type ConversationSeenState, type ConversationTimelineItemsState, type ConversationTypingState, type ConversationsState, type ConversationsStore, CossistantAPIError, CossistantClient, type CossistantConfig, type CossistantError, CossistantRestClient, type Message, type NavigationState, type PublicWebsiteResponse, type SUPPORT_PAGES, type SeenActorType, type SeenEntry, type SeenState, type SeenStore, type SupportConfig, type SupportNavigation, 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, conversationSchema, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingStore, createWebsiteStore, CossistantClient as default, generateConversationId, generateMessageId, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getWebsiteState, hydrateConversationSeen, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen };
package/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ import { CossistantAPIError } from "./types.js";
2
+ import { generateConversationId, generateMessageId } from "./utils.js";
3
+ import { collectVisitorData } from "./visitor-data.js";
4
+ import { clearAllVisitorIds, clearVisitorId, getVisitorId, setVisitorId } from "./visitor-tracker.js";
5
+ import { CossistantRestClient } from "./rest-client.js";
6
+ import { createConversationsStore, getConversationById, getConversationPagination, getConversations } from "./store/conversations-store.js";
7
+ import { createTimelineItemsStore, getConversationTimelineItems } from "./store/timeline-items-store.js";
8
+ import { createWebsiteStore, getWebsiteState } from "./store/website-store.js";
9
+ import { CossistantClient } from "./client.js";
10
+ import { normalizeLocale } from "./locale-utils.js";
11
+ import { applyConversationSeenEvent, createSeenStore, hydrateConversationSeen, upsertConversationSeen } from "./store/seen-store.js";
12
+ import { createSupportStore } from "./store/support-store.js";
13
+ import { applyConversationTypingEvent, clearTypingFromTimelineItem, clearTypingState, createTypingStore, getConversationTyping, setTypingState } from "./store/typing-store.js";
14
+ import { conversationSchema } from "@cossistant/types";
15
+
16
+ export { CossistantAPIError, CossistantClient, CossistantRestClient, applyConversationSeenEvent, applyConversationTypingEvent, clearAllVisitorIds, clearTypingFromTimelineItem, clearTypingState, clearVisitorId, collectVisitorData, conversationSchema, createConversationsStore, createSeenStore, createSupportStore, createTimelineItemsStore, createTypingStore, createWebsiteStore, CossistantClient as default, generateConversationId, generateMessageId, getConversationById, getConversationPagination, getConversationTimelineItems, getConversationTyping, getConversations, getVisitorId, getWebsiteState, hydrateConversationSeen, normalizeLocale, setTypingState, setVisitorId, upsertConversationSeen };
@@ -0,0 +1,17 @@
1
+ //#region src/locale-utils.d.ts
2
+ /**
3
+ * Normalize a locale string to its base language code
4
+ * Examples:
5
+ * - "en-US" -> "en"
6
+ * - "en-GB" -> "en"
7
+ * - "fr-FR" -> "fr"
8
+ * - "es-ES" -> "es"
9
+ * - null -> null
10
+ *
11
+ * @param locale - The locale string to normalize (e.g., "en-US", "fr-FR")
12
+ * @returns The normalized base language code (e.g., "en", "fr") or null if input is null/undefined
13
+ */
14
+ declare function normalizeLocale(locale: string | null | undefined): string | null;
15
+ //#endregion
16
+ export { normalizeLocale };
17
+ //# sourceMappingURL=locale-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-utils.d.ts","names":[],"sources":["../src/locale-utils.ts"],"sourcesContent":[],"mappings":";;AAYA;;;;;;;;;;;iBAAgB,eAAA"}
@@ -0,0 +1,22 @@
1
+ //#region src/locale-utils.ts
2
+ /**
3
+ * Normalize a locale string to its base language code
4
+ * Examples:
5
+ * - "en-US" -> "en"
6
+ * - "en-GB" -> "en"
7
+ * - "fr-FR" -> "fr"
8
+ * - "es-ES" -> "es"
9
+ * - null -> null
10
+ *
11
+ * @param locale - The locale string to normalize (e.g., "en-US", "fr-FR")
12
+ * @returns The normalized base language code (e.g., "en", "fr") or null if input is null/undefined
13
+ */
14
+ function normalizeLocale(locale) {
15
+ if (!locale) return null;
16
+ const [base] = locale.toLowerCase().split("-");
17
+ return base || null;
18
+ }
19
+
20
+ //#endregion
21
+ export { normalizeLocale };
22
+ //# sourceMappingURL=locale-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-utils.js","names":[],"sources":["../src/locale-utils.ts"],"sourcesContent":["/**\n * Normalize a locale string to its base language code\n * Examples:\n * - \"en-US\" -> \"en\"\n * - \"en-GB\" -> \"en\"\n * - \"fr-FR\" -> \"fr\"\n * - \"es-ES\" -> \"es\"\n * - null -> null\n *\n * @param locale - The locale string to normalize (e.g., \"en-US\", \"fr-FR\")\n * @returns The normalized base language code (e.g., \"en\", \"fr\") or null if input is null/undefined\n */\nexport function normalizeLocale(\n\tlocale: string | null | undefined\n): string | null {\n\tif (!locale) {\n\t\treturn null;\n\t}\n\n\t// Convert to lowercase and extract base language code\n\tconst normalized = locale.toLowerCase();\n\tconst [base] = normalized.split(\"-\");\n\n\treturn base || null;\n}\n"],"mappings":";;;;;;;;;;;;;AAYA,SAAgB,gBACf,QACgB;AAChB,KAAI,CAAC,OACJ,QAAO;CAKR,MAAM,CAAC,QADY,OAAO,aAAa,CACb,MAAM,IAAI;AAEpC,QAAO,QAAQ"}