@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,60 @@
1
+ import { createStore } from "./create-store.js";
2
+
3
+ //#region src/store/website-store.ts
4
+ const INITIAL_STATE = {
5
+ website: null,
6
+ status: "idle",
7
+ error: null
8
+ };
9
+ function normalizeError(error) {
10
+ if (error instanceof Error) return { message: error.message };
11
+ if (error && typeof error === "object" && "message" in error && typeof error.message === "string") return { message: error.message };
12
+ return { message: "Unknown error" };
13
+ }
14
+ function createWebsiteStore(initialState = INITIAL_STATE) {
15
+ const store = createStore(initialState);
16
+ return {
17
+ ...store,
18
+ setLoading() {
19
+ store.setState((state) => {
20
+ if (state.status === "loading") return state;
21
+ return {
22
+ website: state.website,
23
+ status: "loading",
24
+ error: null
25
+ };
26
+ });
27
+ },
28
+ setWebsite(website) {
29
+ store.setState((state) => {
30
+ if (state.website === website && state.status === "success" && state.error === null) return state;
31
+ return {
32
+ website,
33
+ status: "success",
34
+ error: null
35
+ };
36
+ });
37
+ },
38
+ setError(error) {
39
+ const normalized = normalizeError(error);
40
+ store.setState((state) => {
41
+ if (state.status === "error" && state.error?.message === normalized.message) return state;
42
+ return {
43
+ website: state.website,
44
+ status: "error",
45
+ error: normalized
46
+ };
47
+ });
48
+ },
49
+ reset() {
50
+ store.setState(() => INITIAL_STATE);
51
+ }
52
+ };
53
+ }
54
+ function getWebsiteState(store) {
55
+ return store.getState();
56
+ }
57
+
58
+ //#endregion
59
+ export { createWebsiteStore, getWebsiteState };
60
+ //# sourceMappingURL=website-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"website-store.js","names":["INITIAL_STATE: WebsiteState"],"sources":["../../src/store/website-store.ts"],"sourcesContent":["import type { PublicWebsiteResponse } from \"@cossistant/types\";\nimport { createStore, type Store } from \"./create-store\";\n\nexport type WebsiteStatus = \"idle\" | \"loading\" | \"success\" | \"error\";\n\nexport type WebsiteError = {\n\tmessage: string;\n};\n\nexport type WebsiteState = {\n\twebsite: PublicWebsiteResponse | null;\n\tstatus: WebsiteStatus;\n\terror: WebsiteError | null;\n};\n\nconst INITIAL_STATE: WebsiteState = {\n\twebsite: null,\n\tstatus: \"idle\",\n\terror: null,\n};\n\nfunction normalizeError(error: unknown): WebsiteError {\n\tif (error instanceof Error) {\n\t\treturn { message: error.message };\n\t}\n\n\tif (\n\t\terror &&\n\t\ttypeof error === \"object\" &&\n\t\t\"message\" in error &&\n\t\ttypeof (error as { message: unknown }).message === \"string\"\n\t) {\n\t\treturn { message: (error as { message: string }).message };\n\t}\n\n\treturn { message: \"Unknown error\" };\n}\n\nexport type WebsiteStore = Store<WebsiteState> & {\n\tsetLoading(): void;\n\tsetWebsite(website: PublicWebsiteResponse): void;\n\tsetError(error: unknown): void;\n\treset(): void;\n};\n\nexport function createWebsiteStore(\n\tinitialState: WebsiteState = INITIAL_STATE\n): WebsiteStore {\n\tconst store = createStore<WebsiteState>(initialState);\n\n\treturn {\n\t\t...store,\n\t\tsetLoading() {\n\t\t\tstore.setState((state) => {\n\t\t\t\tif (state.status === \"loading\") {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\twebsite: state.website,\n\t\t\t\t\tstatus: \"loading\",\n\t\t\t\t\terror: null,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tsetWebsite(website) {\n\t\t\tstore.setState((state) => {\n\t\t\t\tif (\n\t\t\t\t\tstate.website === website &&\n\t\t\t\t\tstate.status === \"success\" &&\n\t\t\t\t\tstate.error === null\n\t\t\t\t) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\twebsite,\n\t\t\t\t\tstatus: \"success\",\n\t\t\t\t\terror: null,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\tsetError(error) {\n\t\t\tconst normalized = normalizeError(error);\n\n\t\t\tstore.setState((state) => {\n\t\t\t\tif (\n\t\t\t\t\tstate.status === \"error\" &&\n\t\t\t\t\tstate.error?.message === normalized.message\n\t\t\t\t) {\n\t\t\t\t\treturn state;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\twebsite: state.website,\n\t\t\t\t\tstatus: \"error\",\n\t\t\t\t\terror: normalized,\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\treset() {\n\t\t\tstore.setState(() => INITIAL_STATE);\n\t\t},\n\t};\n}\n\nexport function getWebsiteState(store: Store<WebsiteState>): WebsiteState {\n\treturn store.getState();\n}\n"],"mappings":";;;AAeA,MAAMA,gBAA8B;CACnC,SAAS;CACT,QAAQ;CACR,OAAO;CACP;AAED,SAAS,eAAe,OAA8B;AACrD,KAAI,iBAAiB,MACpB,QAAO,EAAE,SAAS,MAAM,SAAS;AAGlC,KACC,SACA,OAAO,UAAU,YACjB,aAAa,SACb,OAAQ,MAA+B,YAAY,SAEnD,QAAO,EAAE,SAAU,MAA8B,SAAS;AAG3D,QAAO,EAAE,SAAS,iBAAiB;;AAUpC,SAAgB,mBACf,eAA6B,eACd;CACf,MAAM,QAAQ,YAA0B,aAAa;AAErD,QAAO;EACN,GAAG;EACH,aAAa;AACZ,SAAM,UAAU,UAAU;AACzB,QAAI,MAAM,WAAW,UACpB,QAAO;AAGR,WAAO;KACN,SAAS,MAAM;KACf,QAAQ;KACR,OAAO;KACP;KACA;;EAEH,WAAW,SAAS;AACnB,SAAM,UAAU,UAAU;AACzB,QACC,MAAM,YAAY,WAClB,MAAM,WAAW,aACjB,MAAM,UAAU,KAEhB,QAAO;AAGR,WAAO;KACN;KACA,QAAQ;KACR,OAAO;KACP;KACA;;EAEH,SAAS,OAAO;GACf,MAAM,aAAa,eAAe,MAAM;AAExC,SAAM,UAAU,UAAU;AACzB,QACC,MAAM,WAAW,WACjB,MAAM,OAAO,YAAY,WAAW,QAEpC,QAAO;AAGR,WAAO;KACN,SAAS,MAAM;KACf,QAAQ;KACR,OAAO;KACP;KACA;;EAEH,QAAQ;AACP,SAAM,eAAe,cAAc;;EAEpC;;AAGF,SAAgB,gBAAgB,OAA0C;AACzE,QAAO,MAAM,UAAU"}
@@ -0,0 +1,207 @@
1
+ import { z } from "@hono/zod-openapi";
2
+
3
+ //#region ../types/src/api/timeline-item.d.ts
4
+
5
+ declare const timelineItemSchema: z.ZodObject<{
6
+ id: z.ZodOptional<z.ZodString>;
7
+ conversationId: z.ZodString;
8
+ organizationId: z.ZodString;
9
+ visibility: z.ZodEnum<{
10
+ [x: string]: any;
11
+ }>;
12
+ type: z.ZodEnum<{
13
+ [x: string]: any;
14
+ }>;
15
+ text: z.ZodNullable<z.ZodString>;
16
+ tool: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
18
+ type: z.ZodLiteral<"text">;
19
+ text: z.ZodString;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ type: z.ZodLiteral<"event">;
22
+ eventType: z.ZodEnum<{
23
+ [x: string]: any;
24
+ }>;
25
+ actorUserId: z.ZodNullable<z.ZodString>;
26
+ actorAiAgentId: z.ZodNullable<z.ZodString>;
27
+ targetUserId: z.ZodNullable<z.ZodString>;
28
+ targetAiAgentId: z.ZodNullable<z.ZodString>;
29
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ type: z.ZodLiteral<"image">;
32
+ url: z.ZodString;
33
+ mediaType: z.ZodString;
34
+ fileName: z.ZodOptional<z.ZodString>;
35
+ size: z.ZodOptional<z.ZodNumber>;
36
+ width: z.ZodOptional<z.ZodNumber>;
37
+ height: z.ZodOptional<z.ZodNumber>;
38
+ }, z.core.$strip>, z.ZodObject<{
39
+ type: z.ZodLiteral<"file">;
40
+ url: z.ZodString;
41
+ mediaType: z.ZodString;
42
+ fileName: z.ZodOptional<z.ZodString>;
43
+ size: z.ZodOptional<z.ZodNumber>;
44
+ }, z.core.$strip>]>>;
45
+ userId: z.ZodNullable<z.ZodString>;
46
+ aiAgentId: z.ZodNullable<z.ZodString>;
47
+ visitorId: z.ZodNullable<z.ZodString>;
48
+ createdAt: z.ZodString;
49
+ deletedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
+ }, z.core.$strip>;
51
+ type timelineItemSchema = z.infer<typeof timelineItemSchema>;
52
+ type TimelineItem = z.infer<typeof timelineItemSchema>;
53
+ declare const getConversationTimelineItemsRequestSchema: z.ZodObject<{
54
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
55
+ cursor: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ }, z.core.$strip>;
57
+ type GetConversationTimelineItemsRequest = z.infer<typeof getConversationTimelineItemsRequestSchema>;
58
+ declare const getConversationTimelineItemsResponseSchema: z.ZodObject<{
59
+ items: z.ZodArray<z.ZodObject<{
60
+ id: z.ZodOptional<z.ZodString>;
61
+ conversationId: z.ZodString;
62
+ organizationId: z.ZodString;
63
+ visibility: z.ZodEnum<{
64
+ [x: string]: any;
65
+ }>;
66
+ type: z.ZodEnum<{
67
+ [x: string]: any;
68
+ }>;
69
+ text: z.ZodNullable<z.ZodString>;
70
+ tool: z.ZodOptional<z.ZodNullable<z.ZodString>>;
71
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
72
+ type: z.ZodLiteral<"text">;
73
+ text: z.ZodString;
74
+ }, z.core.$strip>, z.ZodObject<{
75
+ type: z.ZodLiteral<"event">;
76
+ eventType: z.ZodEnum<{
77
+ [x: string]: any;
78
+ }>;
79
+ actorUserId: z.ZodNullable<z.ZodString>;
80
+ actorAiAgentId: z.ZodNullable<z.ZodString>;
81
+ targetUserId: z.ZodNullable<z.ZodString>;
82
+ targetAiAgentId: z.ZodNullable<z.ZodString>;
83
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
84
+ }, z.core.$strip>, z.ZodObject<{
85
+ type: z.ZodLiteral<"image">;
86
+ url: z.ZodString;
87
+ mediaType: z.ZodString;
88
+ fileName: z.ZodOptional<z.ZodString>;
89
+ size: z.ZodOptional<z.ZodNumber>;
90
+ width: z.ZodOptional<z.ZodNumber>;
91
+ height: z.ZodOptional<z.ZodNumber>;
92
+ }, z.core.$strip>, z.ZodObject<{
93
+ type: z.ZodLiteral<"file">;
94
+ url: z.ZodString;
95
+ mediaType: z.ZodString;
96
+ fileName: z.ZodOptional<z.ZodString>;
97
+ size: z.ZodOptional<z.ZodNumber>;
98
+ }, z.core.$strip>]>>;
99
+ userId: z.ZodNullable<z.ZodString>;
100
+ aiAgentId: z.ZodNullable<z.ZodString>;
101
+ visitorId: z.ZodNullable<z.ZodString>;
102
+ createdAt: z.ZodString;
103
+ deletedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
104
+ }, z.core.$strip>>;
105
+ nextCursor: z.ZodNullable<z.ZodString>;
106
+ hasNextPage: z.ZodBoolean;
107
+ }, z.core.$strip>;
108
+ type GetConversationTimelineItemsResponse = z.infer<typeof getConversationTimelineItemsResponseSchema>;
109
+ declare const sendTimelineItemRequestSchema: z.ZodObject<{
110
+ conversationId: z.ZodString;
111
+ item: z.ZodObject<{
112
+ id: z.ZodOptional<z.ZodString>;
113
+ type: z.ZodDefault<z.ZodEnum<{
114
+ [x: string]: any;
115
+ }>>;
116
+ text: z.ZodString;
117
+ parts: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
118
+ type: z.ZodLiteral<"text">;
119
+ text: z.ZodString;
120
+ }, z.core.$strip>, z.ZodObject<{
121
+ type: z.ZodLiteral<"event">;
122
+ eventType: z.ZodEnum<{
123
+ [x: string]: any;
124
+ }>;
125
+ actorUserId: z.ZodNullable<z.ZodString>;
126
+ actorAiAgentId: z.ZodNullable<z.ZodString>;
127
+ targetUserId: z.ZodNullable<z.ZodString>;
128
+ targetAiAgentId: z.ZodNullable<z.ZodString>;
129
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
130
+ }, z.core.$strip>, z.ZodObject<{
131
+ type: z.ZodLiteral<"image">;
132
+ url: z.ZodString;
133
+ mediaType: z.ZodString;
134
+ fileName: z.ZodOptional<z.ZodString>;
135
+ size: z.ZodOptional<z.ZodNumber>;
136
+ width: z.ZodOptional<z.ZodNumber>;
137
+ height: z.ZodOptional<z.ZodNumber>;
138
+ }, z.core.$strip>, z.ZodObject<{
139
+ type: z.ZodLiteral<"file">;
140
+ url: z.ZodString;
141
+ mediaType: z.ZodString;
142
+ fileName: z.ZodOptional<z.ZodString>;
143
+ size: z.ZodOptional<z.ZodNumber>;
144
+ }, z.core.$strip>]>>>;
145
+ visibility: z.ZodDefault<z.ZodEnum<{
146
+ [x: string]: any;
147
+ }>>;
148
+ tool: z.ZodOptional<z.ZodNullable<z.ZodString>>;
149
+ userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
150
+ aiAgentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
151
+ visitorId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
152
+ createdAt: z.ZodOptional<z.ZodString>;
153
+ }, z.core.$strip>;
154
+ }, z.core.$strip>;
155
+ type SendTimelineItemRequest = z.infer<typeof sendTimelineItemRequestSchema>;
156
+ declare const sendTimelineItemResponseSchema: z.ZodObject<{
157
+ item: z.ZodObject<{
158
+ id: z.ZodOptional<z.ZodString>;
159
+ conversationId: z.ZodString;
160
+ organizationId: z.ZodString;
161
+ visibility: z.ZodEnum<{
162
+ [x: string]: any;
163
+ }>;
164
+ type: z.ZodEnum<{
165
+ [x: string]: any;
166
+ }>;
167
+ text: z.ZodNullable<z.ZodString>;
168
+ tool: z.ZodOptional<z.ZodNullable<z.ZodString>>;
169
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
170
+ type: z.ZodLiteral<"text">;
171
+ text: z.ZodString;
172
+ }, z.core.$strip>, z.ZodObject<{
173
+ type: z.ZodLiteral<"event">;
174
+ eventType: z.ZodEnum<{
175
+ [x: string]: any;
176
+ }>;
177
+ actorUserId: z.ZodNullable<z.ZodString>;
178
+ actorAiAgentId: z.ZodNullable<z.ZodString>;
179
+ targetUserId: z.ZodNullable<z.ZodString>;
180
+ targetAiAgentId: z.ZodNullable<z.ZodString>;
181
+ message: z.ZodOptional<z.ZodNullable<z.ZodString>>;
182
+ }, z.core.$strip>, z.ZodObject<{
183
+ type: z.ZodLiteral<"image">;
184
+ url: z.ZodString;
185
+ mediaType: z.ZodString;
186
+ fileName: z.ZodOptional<z.ZodString>;
187
+ size: z.ZodOptional<z.ZodNumber>;
188
+ width: z.ZodOptional<z.ZodNumber>;
189
+ height: z.ZodOptional<z.ZodNumber>;
190
+ }, z.core.$strip>, z.ZodObject<{
191
+ type: z.ZodLiteral<"file">;
192
+ url: z.ZodString;
193
+ mediaType: z.ZodString;
194
+ fileName: z.ZodOptional<z.ZodString>;
195
+ size: z.ZodOptional<z.ZodNumber>;
196
+ }, z.core.$strip>]>>;
197
+ userId: z.ZodNullable<z.ZodString>;
198
+ aiAgentId: z.ZodNullable<z.ZodString>;
199
+ visitorId: z.ZodNullable<z.ZodString>;
200
+ createdAt: z.ZodString;
201
+ deletedAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
202
+ }, z.core.$strip>;
203
+ }, z.core.$strip>;
204
+ type SendTimelineItemResponse = z.infer<typeof sendTimelineItemResponseSchema>;
205
+ //#endregion
206
+ export { GetConversationTimelineItemsRequest, GetConversationTimelineItemsResponse, SendTimelineItemRequest, SendTimelineItemResponse, TimelineItem };
207
+ //# sourceMappingURL=timeline-item.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline-item.d.ts","names":[],"sources":["../../types/src/api/timeline-item.ts"],"sourcesContent":[],"mappings":";;;;cAkHa,oBAAkB,CAAA,CAAA;;;;;;;;;EAAA,CAAA,CAAA;EAAA,IAAA,eAAA,YAAA,CAAA;EAoDnB,IAAA,eAAA,cAAoC,YAAA,CAAA,CAAA;EAEpC,KAAA,YAAY,WAAkB,CAAA,SAAA,YAAb,CAAA;IAShB,IAAA,cAAA,CAAA,MAAA,CAAA;;;;;;;IAAyC,WAAA,eAAA,YAAA,CAAA;IAAA,cAAA,eAAA,YAAA,CAAA;IAe1C,YAAA,eAAA,YAAmC,CAAA;IAIlC,eAAA,eAAA,YAeV,CAAA;;;;;;;;;;;;;;;;;;;;;;;KA7CS,kBAAA,GAAqB,CAAA,CAAE,aAAa;KAEpC,YAAA,GAAe,CAAA,CAAE,aAAa;cAS7B,2CAAyC,CAAA,CAAA;;;;KAe1C,mCAAA,GAAsC,CAAA,CAAE,aAC5C;cAGK,4CAA0C,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAAA,SAAA,aAAA;MAAA,QAAA,eAAA,YAAA,CAAA;MAiB3C,IAAA,eAAA,YAAoC,CAAA;IAKnC,CAAA,eAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;KALD,oCAAA,GAAuC,CAAA,CAAE,aAC7C;cAIK,+BAA6B,CAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAoD9B,uBAAA,GAA0B,CAAA,CAAE,aAChC;cAGK,gCAA8B,CAAA,CAAA;;;;;;;;;;;;IAxDD,IAAA,eAAA,cAAA,YAAA,CAAA,CAAA;IAAA,KAAA,YAAA,WAAA,CAAA,SAAA,YAAA,CAAA;MAoD9B,IAAA,cAAuB,CAAA,MAAA,CAAA;MAItB,IAAA,aAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAUD,wBAAA,GAA2B,CAAA,CAAE,aACjC"}
@@ -0,0 +1,24 @@
1
+ //#region ../types/src/enums.ts
2
+ const SenderType = {
3
+ VISITOR: "visitor",
4
+ TEAM_MEMBER: "team_member",
5
+ AI: "ai"
6
+ };
7
+ const ConversationStatus = {
8
+ OPEN: "open",
9
+ RESOLVED: "resolved",
10
+ SPAM: "spam"
11
+ };
12
+ const TimelineItemVisibility = {
13
+ PUBLIC: "public",
14
+ PRIVATE: "private"
15
+ };
16
+ const ConversationTimelineType = {
17
+ MESSAGE: "message",
18
+ EVENT: "event",
19
+ IDENTIFICATION: "identification"
20
+ };
21
+
22
+ //#endregion
23
+ export { ConversationStatus, ConversationTimelineType, SenderType, TimelineItemVisibility };
24
+ //# sourceMappingURL=enums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enums.js","names":[],"sources":["../../../../types/src/enums.ts"],"sourcesContent":["export const SenderType = {\n\tVISITOR: \"visitor\",\n\tTEAM_MEMBER: \"team_member\",\n\tAI: \"ai\",\n} as const;\n\nexport type SenderType = (typeof SenderType)[keyof typeof SenderType];\n\nexport const ConversationStatus = {\n\tOPEN: \"open\",\n\tRESOLVED: \"resolved\",\n\tSPAM: \"spam\",\n} as const;\n\nexport type ConversationStatus =\n\t(typeof ConversationStatus)[keyof typeof ConversationStatus];\n\nexport const ConversationPriority = {\n\tLOW: \"low\",\n\tNORMAL: \"normal\",\n\tHIGH: \"high\",\n\tURGENT: \"urgent\",\n} as const;\n\nexport const TimelineItemVisibility = {\n\tPUBLIC: \"public\",\n\tPRIVATE: \"private\",\n} as const;\n\nexport const ConversationTimelineType = {\n\tMESSAGE: \"message\",\n\tEVENT: \"event\",\n\tIDENTIFICATION: \"identification\",\n} as const;\n\nexport type ConversationTimelineType =\n\t(typeof ConversationTimelineType)[keyof typeof ConversationTimelineType];\n\nexport const ConversationEventType = {\n\tASSIGNED: \"assigned\",\n\tUNASSIGNED: \"unassigned\",\n\tPARTICIPANT_REQUESTED: \"participant_requested\",\n\tPARTICIPANT_JOINED: \"participant_joined\",\n\tPARTICIPANT_LEFT: \"participant_left\",\n\tSTATUS_CHANGED: \"status_changed\",\n\tPRIORITY_CHANGED: \"priority_changed\",\n\tTAG_ADDED: \"tag_added\",\n\tTAG_REMOVED: \"tag_removed\",\n\tRESOLVED: \"resolved\",\n\tREOPENED: \"reopened\",\n\tVISITOR_BLOCKED: \"visitor_blocked\",\n\tVISITOR_UNBLOCKED: \"visitor_unblocked\",\n\tVISITOR_IDENTIFIED: \"visitor_identified\",\n} as const;\n\nexport const ConversationParticipationStatus = {\n\tREQUESTED: \"requested\",\n\tACTIVE: \"active\",\n\tLEFT: \"left\",\n\tDECLINED: \"declined\",\n} as const;\n\nexport const ConversationSentiment = {\n\tPOSITIVE: \"positive\",\n\tNEGATIVE: \"negative\",\n\tNEUTRAL: \"neutral\",\n} as const;\n\nexport type ConversationSentiment =\n\t(typeof ConversationSentiment)[keyof typeof ConversationSentiment];\n\nexport type ConversationParticipationStatus =\n\t(typeof ConversationParticipationStatus)[keyof typeof ConversationParticipationStatus];\n\nexport type ConversationEventType =\n\t(typeof ConversationEventType)[keyof typeof ConversationEventType];\n\nexport type TimelineItemVisibility =\n\t(typeof TimelineItemVisibility)[keyof typeof TimelineItemVisibility];\n\nexport type ConversationPriority =\n\t(typeof ConversationPriority)[keyof typeof ConversationPriority];\n\nexport const WebsiteInstallationTarget = {\n\tNEXTJS: \"nextjs\",\n\tREACT: \"react\",\n} as const;\n\nexport const WebsiteStatus = {\n\tACTIVE: \"active\",\n\tINACTIVE: \"inactive\",\n} as const;\n\nexport type WebsiteStatus = (typeof WebsiteStatus)[keyof typeof WebsiteStatus];\n\nexport type WebsiteInstallationTarget =\n\t(typeof WebsiteInstallationTarget)[keyof typeof WebsiteInstallationTarget];\n\nexport const APIKeyType = {\n\tPRIVATE: \"private\",\n\tPUBLIC: \"public\",\n} as const;\n\nexport type APIKeyType = (typeof APIKeyType)[keyof typeof APIKeyType];\n"],"mappings":";AAAA,MAAa,aAAa;CACzB,SAAS;CACT,aAAa;CACb,IAAI;CACJ;AAID,MAAa,qBAAqB;CACjC,MAAM;CACN,UAAU;CACV,MAAM;CACN;AAYD,MAAa,yBAAyB;CACrC,QAAQ;CACR,SAAS;CACT;AAED,MAAa,2BAA2B;CACvC,SAAS;CACT,OAAO;CACP,gBAAgB;CAChB"}
@@ -0,0 +1,17 @@
1
+ import { __export, __reExport } from "./_virtual/rolldown_runtime.js";
2
+ import { CossistantError } from "@cossistant/types";
3
+ export * from "@cossistant/types";
4
+
5
+ //#region src/types.d.ts
6
+ declare namespace types_d_exports {
7
+ export { CossistantAPIError };
8
+ }
9
+ import * as import___cossistant_types from "@cossistant/types";
10
+ declare class CossistantAPIError extends Error {
11
+ code: string;
12
+ details?: Record<string, unknown>;
13
+ constructor(error: CossistantError);
14
+ }
15
+ //#endregion
16
+ export { CossistantAPIError, types_d_exports };
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;cAOa,kBAAA,SAA2B,KAAA;;YAE7B;qBAES"}
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ export * from "@cossistant/types"
2
+
3
+ //#region src/types.ts
4
+ var CossistantAPIError = class extends Error {
5
+ code;
6
+ details;
7
+ constructor(error) {
8
+ super(error.message);
9
+ this.name = "CossistantAPIError";
10
+ this.code = error.code;
11
+ this.details = error.details;
12
+ }
13
+ };
14
+
15
+ //#endregion
16
+ export { CossistantAPIError };
17
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["// Re-export all types from the shared types package\nexport * from \"@cossistant/types\";\n\n// Import the error interface for the error class\nimport type { CossistantError } from \"@cossistant/types\";\n\n// Core-specific error class (runtime code)\nexport class CossistantAPIError extends Error {\n\tcode: string;\n\tdetails?: Record<string, unknown>;\n\n\tconstructor(error: CossistantError) {\n\t\tsuper(error.message);\n\t\tthis.name = \"CossistantAPIError\";\n\t\tthis.code = error.code;\n\t\tthis.details = error.details;\n\t}\n}\n"],"mappings":";;;AAOA,IAAa,qBAAb,cAAwC,MAAM;CAC7C;CACA;CAEA,YAAY,OAAwB;AACnC,QAAM,MAAM,QAAQ;AACpB,OAAK,OAAO;AACZ,OAAK,OAAO,MAAM;AAClB,OAAK,UAAU,MAAM"}
@@ -0,0 +1,8 @@
1
+ //#region src/utils.d.ts
2
+ declare const ULID_REGEX: RegExp;
3
+ declare function isValidULID(ulid: string): boolean;
4
+ declare const generateConversationId: () => string;
5
+ declare const generateMessageId: () => string;
6
+ //#endregion
7
+ export { ULID_REGEX, generateConversationId, generateMessageId, isValidULID };
8
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","names":[],"sources":["../src/utils.ts"],"sourcesContent":[],"mappings":";cAGa,YAAU;AAAV,iBAEG,WAAA,CAFoC,IAAA,EAAA,MAAA,CAAA,EAAA,OAAA;AAEpC,cAOH,sBAPc,EAAA,GAAA,GAAA,MAAA;AAOd,cAKA,iBAFZ,EAAA,GAAA,GAAA,MAAA"}
package/dist/utils.js ADDED
@@ -0,0 +1,20 @@
1
+ import { customAlphabet } from "nanoid";
2
+ import { ulid } from "ulid";
3
+
4
+ //#region src/utils.ts
5
+ const ULID_REGEX = /^[0-9A-HJKMNP-TV-Z]{26}$/;
6
+ function isValidULID(ulid$1) {
7
+ return ULID_REGEX.test(ulid$1);
8
+ }
9
+ const NANOID_ALPHABET = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
10
+ const NANOID_LENGTH = 16;
11
+ const generateConversationId = () => {
12
+ return `CO${customAlphabet(NANOID_ALPHABET, NANOID_LENGTH)()}`;
13
+ };
14
+ const generateMessageId = () => {
15
+ return ulid();
16
+ };
17
+
18
+ //#endregion
19
+ export { ULID_REGEX, generateConversationId, generateMessageId, isValidULID };
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["ulid","ulidGenerator"],"sources":["../src/utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nimport { ulid as ulidGenerator } from \"ulid\";\n\nexport const ULID_REGEX = /^[0-9A-HJKMNP-TV-Z]{26}$/;\n\nexport function isValidULID(ulid: string): boolean {\n\treturn ULID_REGEX.test(ulid);\n}\n\nconst NANOID_ALPHABET = \"123456789ABCDEFGHIJKLMNPQRSTUVWXYZ\";\nconst NANOID_LENGTH = 16;\n\nexport const generateConversationId = (): string => {\n\tconst nanoid = customAlphabet(NANOID_ALPHABET, NANOID_LENGTH);\n\treturn `CO${nanoid()}`; // e.g. \"CO4GKT9QZ2BJKXMVR\"\n};\n\nexport const generateMessageId = (): string => {\n\treturn ulidGenerator(); // e.g. \"01J3400000000000000000000\"\n};\n"],"mappings":";;;;AAGA,MAAa,aAAa;AAE1B,SAAgB,YAAY,QAAuB;AAClD,QAAO,WAAW,KAAKA,OAAK;;AAG7B,MAAM,kBAAkB;AACxB,MAAM,gBAAgB;AAEtB,MAAa,+BAAuC;AAEnD,QAAO,KADQ,eAAe,iBAAiB,cAAc,EACzC;;AAGrB,MAAa,0BAAkC;AAC9C,QAAOC,MAAe"}
@@ -0,0 +1,33 @@
1
+ //#region src/visitor-data.d.ts
2
+ /**
3
+ * Utilities for collecting visitor data including browser, device, and location information
4
+ * Moved from packages/react for better separation of concerns
5
+ */
6
+ /** biome-ignore-all lint/complexity/useOptionalChain: ok */
7
+ type VisitorData = {
8
+ browser: string | null;
9
+ browserVersion: string | null;
10
+ os: string | null;
11
+ osVersion: string | null;
12
+ device: string | null;
13
+ deviceType: "desktop" | "mobile" | "tablet" | "unknown";
14
+ language: string | null;
15
+ timezone: string | null;
16
+ screenResolution: string | null;
17
+ viewport: string | null;
18
+ ip: string | null;
19
+ city: string | null;
20
+ region: string | null;
21
+ country: string | null;
22
+ countryCode: string | null;
23
+ latitude: number | null;
24
+ longitude: number | null;
25
+ };
26
+ /**
27
+ * Collect visitor data from the browser environment
28
+ * Returns null if not in browser environment
29
+ */
30
+ declare function collectVisitorData(): Promise<VisitorData | null>;
31
+ //#endregion
32
+ export { type VisitorData, collectVisitorData };
33
+ //# sourceMappingURL=visitor-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor-data.d.ts","names":[],"sources":["../src/visitor-data.ts"],"sourcesContent":[],"mappings":";;;AAkNA;;;KA5MK,WAAA;;;;;;;;;;;;;;;;;;;;;;;iBA4MiB,kBAAA,CAAA,GAAsB,QAAQ"}
@@ -0,0 +1,212 @@
1
+ //#region src/visitor-data.ts
2
+ const EDGE_PATTERN = /Edg\/([0-9.]+)/;
3
+ const CHROME_PATTERN = /Chrome\/([0-9.]+)/;
4
+ const SAFARI_PATTERN = /Version\/([0-9.]+).*Safari/;
5
+ const FIREFOX_PATTERN = /Firefox\/([0-9.]+)/;
6
+ const OPERA_PATTERN = /OPR\/([0-9.]+)/;
7
+ /**
8
+ * Parse user agent to extract browser information
9
+ */
10
+ function parseBrowser(userAgent) {
11
+ const browsers = [
12
+ {
13
+ name: "Edge",
14
+ pattern: EDGE_PATTERN
15
+ },
16
+ {
17
+ name: "Chrome",
18
+ pattern: CHROME_PATTERN
19
+ },
20
+ {
21
+ name: "Safari",
22
+ pattern: SAFARI_PATTERN
23
+ },
24
+ {
25
+ name: "Firefox",
26
+ pattern: FIREFOX_PATTERN
27
+ },
28
+ {
29
+ name: "Opera",
30
+ pattern: OPERA_PATTERN
31
+ }
32
+ ];
33
+ for (const { name, pattern } of browsers) {
34
+ const match = userAgent.match(pattern);
35
+ if (match) return {
36
+ browser: name,
37
+ version: match[1] || null
38
+ };
39
+ }
40
+ return {
41
+ browser: null,
42
+ version: null
43
+ };
44
+ }
45
+ const WINDOWS_PATTERN = /Windows NT ([0-9.]+)/;
46
+ const MACOS_PATTERN = /Mac OS X ([0-9_]+)/;
47
+ const IOS_PATTERN = /OS ([0-9_]+) like Mac OS X/;
48
+ const ANDROID_PATTERN = /Android ([0-9.]+)/;
49
+ const LINUX_PATTERN = /Linux/;
50
+ const WINDOWS_VERSION_MAP = {
51
+ "10.0": "10",
52
+ "6.3": "8.1",
53
+ "6.2": "8",
54
+ "6.1": "7"
55
+ };
56
+ /**
57
+ * Transform version string by replacing underscores with dots
58
+ */
59
+ function transformVersion(version) {
60
+ return version.replace(/_/g, ".");
61
+ }
62
+ /**
63
+ * Parse user agent to extract OS information
64
+ */
65
+ function parseOS(userAgent) {
66
+ const windowsMatch = userAgent.match(WINDOWS_PATTERN);
67
+ if (windowsMatch) {
68
+ const rawVersion = windowsMatch[1];
69
+ let version = null;
70
+ if (rawVersion) version = WINDOWS_VERSION_MAP[rawVersion] || rawVersion;
71
+ return {
72
+ os: "Windows",
73
+ version
74
+ };
75
+ }
76
+ const macMatch = userAgent.match(MACOS_PATTERN);
77
+ if (macMatch) return {
78
+ os: "macOS",
79
+ version: macMatch[1] ? transformVersion(macMatch[1]) : null
80
+ };
81
+ const iosMatch = userAgent.match(IOS_PATTERN);
82
+ if (iosMatch) return {
83
+ os: "iOS",
84
+ version: iosMatch[1] ? transformVersion(iosMatch[1]) : null
85
+ };
86
+ const androidMatch = userAgent.match(ANDROID_PATTERN);
87
+ if (androidMatch) return {
88
+ os: "Android",
89
+ version: androidMatch[1] || null
90
+ };
91
+ if (LINUX_PATTERN.test(userAgent)) return {
92
+ os: "Linux",
93
+ version: null
94
+ };
95
+ return {
96
+ os: null,
97
+ version: null
98
+ };
99
+ }
100
+ const MOBILE_PATTERN = /Mobile|Android|iPhone|iPod/i;
101
+ const TABLET_PATTERN = /iPad|Tablet|Tab/i;
102
+ const IPHONE_PATTERN = /iPhone/;
103
+ const IPAD_PATTERN = /iPad/;
104
+ const IPOD_PATTERN = /iPod/;
105
+ const ANDROID_MOBILE_PATTERN = /Android.*Mobile/;
106
+ const ANDROID_TABLET_PATTERN = /Android.*Tablet/;
107
+ const WINDOWS_PHONE_PATTERN = /Windows Phone/;
108
+ const MACINTOSH_PATTERN = /Macintosh/;
109
+ const WINDOWS_PATTERN_DEVICE = /Windows/;
110
+ const LINUX_PATTERN_DEVICE = /Linux/;
111
+ /**
112
+ * Detect device type from user agent
113
+ */
114
+ function detectDeviceType(userAgent) {
115
+ const isMobile = MOBILE_PATTERN.test(userAgent);
116
+ if (TABLET_PATTERN.test(userAgent)) return "tablet";
117
+ if (isMobile) return "mobile";
118
+ if (userAgent.includes("Windows") || userAgent.includes("Mac") || userAgent.includes("Linux")) return "desktop";
119
+ return "unknown";
120
+ }
121
+ /**
122
+ * Get device name from user agent
123
+ */
124
+ function getDeviceName(userAgent) {
125
+ const devices = [
126
+ {
127
+ pattern: IPHONE_PATTERN,
128
+ name: "iPhone"
129
+ },
130
+ {
131
+ pattern: IPAD_PATTERN,
132
+ name: "iPad"
133
+ },
134
+ {
135
+ pattern: IPOD_PATTERN,
136
+ name: "iPod"
137
+ },
138
+ {
139
+ pattern: ANDROID_MOBILE_PATTERN,
140
+ name: "Android Phone"
141
+ },
142
+ {
143
+ pattern: ANDROID_TABLET_PATTERN,
144
+ name: "Android Tablet"
145
+ },
146
+ {
147
+ pattern: WINDOWS_PHONE_PATTERN,
148
+ name: "Windows Phone"
149
+ },
150
+ {
151
+ pattern: MACINTOSH_PATTERN,
152
+ name: "Mac"
153
+ },
154
+ {
155
+ pattern: WINDOWS_PATTERN_DEVICE,
156
+ name: "Windows PC"
157
+ },
158
+ {
159
+ pattern: LINUX_PATTERN_DEVICE,
160
+ name: "Linux PC"
161
+ }
162
+ ];
163
+ for (const { pattern, name } of devices) if (pattern.test(userAgent)) return name;
164
+ return null;
165
+ }
166
+ /**
167
+ * Check if we're running in a browser environment
168
+ */
169
+ function isBrowser() {
170
+ return typeof window !== "undefined" && typeof navigator !== "undefined";
171
+ }
172
+ function inferCityFromTimezone(timezone) {
173
+ if (!timezone?.includes("/")) return null;
174
+ const [, city] = timezone.split("/");
175
+ return city ? city.replace(/_/g, " ") : null;
176
+ }
177
+ /**
178
+ * Collect visitor data from the browser environment
179
+ * Returns null if not in browser environment
180
+ */
181
+ async function collectVisitorData() {
182
+ if (!isBrowser()) return null;
183
+ const userAgent = navigator.userAgent || "";
184
+ const { browser, version: browserVersion } = parseBrowser(userAgent);
185
+ const { os, version: osVersion } = parseOS(userAgent);
186
+ const language = navigator.language || null;
187
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || null;
188
+ const inferredCity = inferCityFromTimezone(timezone);
189
+ return {
190
+ browser,
191
+ browserVersion,
192
+ os,
193
+ osVersion,
194
+ device: getDeviceName(userAgent),
195
+ deviceType: detectDeviceType(userAgent),
196
+ language,
197
+ timezone,
198
+ screenResolution: typeof window !== "undefined" && window.screen ? `${window.screen.width}x${window.screen.height}` : null,
199
+ viewport: typeof window !== "undefined" ? `${window.innerWidth}x${window.innerHeight}` : null,
200
+ ip: null,
201
+ city: inferredCity,
202
+ region: null,
203
+ country: null,
204
+ countryCode: null,
205
+ latitude: null,
206
+ longitude: null
207
+ };
208
+ }
209
+
210
+ //#endregion
211
+ export { collectVisitorData };
212
+ //# sourceMappingURL=visitor-data.js.map