@tabsystems/onechat 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,380 @@
1
+ import { z } from 'zod';
2
+
3
+ declare const API_CHANNEL_PATH: {
4
+ readonly messages: "/api/v1/conversations/messages";
5
+ readonly handover: "/api/v1/conversations/handover";
6
+ };
7
+ declare const API_CHANNEL_LIMIT: {
8
+ readonly idMaxLength: 128;
9
+ readonly textMaxLength: 2000;
10
+ readonly payloadMaxLength: 1000;
11
+ readonly userNameMaxLength: 100;
12
+ readonly duplicateWindowDays: 30;
13
+ };
14
+ declare const WEBHOOK_HEADER: {
15
+ readonly eventId: "x-onechat-event-id";
16
+ readonly timestamp: "x-onechat-timestamp";
17
+ readonly signature: "x-onechat-signature";
18
+ };
19
+ declare const WEBHOOK_TOLERANCE_SECONDS = 300;
20
+ declare const UNKNOWN_WEBHOOK_EVENT: {
21
+ readonly type: "unknown";
22
+ };
23
+ declare const WEBHOOK_EVENT_TYPE: {
24
+ readonly messageCreated: "message.created";
25
+ readonly messageFailed: "message.failed";
26
+ readonly handedToStaff: "conversation.handed_to_staff";
27
+ readonly returnedToBot: "conversation.returned_to_bot";
28
+ readonly webhookTest: "webhook.test";
29
+ };
30
+ declare const MESSAGE_FROM: {
31
+ readonly bot: "bot";
32
+ readonly staff: "staff";
33
+ readonly system: "system";
34
+ };
35
+ declare const MESSAGE_FAILED_REASON: {
36
+ readonly aiError: "ai_error";
37
+ readonly expired: "expired";
38
+ };
39
+ declare const HANDOVER_REASON: {
40
+ readonly humanRequest: "human_request";
41
+ readonly tenantRequest: "tenant_request";
42
+ readonly agentDecision: "agent_decision";
43
+ readonly aiError: "ai_error";
44
+ readonly limitReached: "limit_reached";
45
+ readonly noModel: "no_model";
46
+ readonly staff: "staff";
47
+ };
48
+ declare const RETURNED_TO_BOT_REASON: {
49
+ readonly staff: "staff";
50
+ readonly user: "user";
51
+ readonly timeout: "timeout";
52
+ };
53
+
54
+ type OpenValue<T extends Record<string, string>> = T[keyof T] | (string & Record<never, never>);
55
+ declare const sendMessageRequestSchema: z.ZodObject<{
56
+ messageId: z.ZodString;
57
+ userId: z.ZodString;
58
+ text: z.ZodString;
59
+ payload: z.ZodOptional<z.ZodString>;
60
+ userName: z.ZodOptional<z.ZodString>;
61
+ }, z.core.$strip>;
62
+ declare const handoverRequestSchema: z.ZodObject<{
63
+ userId: z.ZodString;
64
+ }, z.core.$strip>;
65
+ declare const quickReplySchema: z.ZodObject<{
66
+ title: z.ZodString;
67
+ payload: z.ZodString;
68
+ }, z.core.$strip>;
69
+ declare const buttonSchema: z.ZodObject<{
70
+ type: z.ZodEnum<{
71
+ postback: "postback";
72
+ url: "url";
73
+ }>;
74
+ title: z.ZodString;
75
+ payload: z.ZodOptional<z.ZodString>;
76
+ url: z.ZodOptional<z.ZodString>;
77
+ }, z.core.$strip>;
78
+ declare const attachmentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
79
+ kind: z.ZodLiteral<"buttons">;
80
+ text: z.ZodString;
81
+ buttons: z.ZodPipe<z.ZodArray<z.ZodUnknown>, z.ZodTransform<{
82
+ type: "postback" | "url";
83
+ title: string;
84
+ payload?: string | undefined;
85
+ url?: string | undefined;
86
+ }[], unknown[]>>;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ kind: z.ZodLiteral<"image">;
89
+ url: z.ZodString;
90
+ }, z.core.$strip>, z.ZodObject<{
91
+ kind: z.ZodLiteral<"generic">;
92
+ elements: z.ZodArray<z.ZodObject<{
93
+ title: z.ZodString;
94
+ subtitle: z.ZodOptional<z.ZodString>;
95
+ imageUrl: z.ZodOptional<z.ZodString>;
96
+ defaultUrl: z.ZodOptional<z.ZodString>;
97
+ buttons: z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodUnknown>, z.ZodTransform<{
98
+ type: "postback" | "url";
99
+ title: string;
100
+ payload?: string | undefined;
101
+ url?: string | undefined;
102
+ }[], unknown[]>>>;
103
+ }, z.core.$strip>>;
104
+ }, z.core.$strip>], "kind">;
105
+ declare const messageCreatedEventSchema: z.ZodObject<{
106
+ type: z.ZodLiteral<"message.created">;
107
+ data: z.ZodObject<{
108
+ userId: z.ZodString;
109
+ message: z.ZodObject<{
110
+ from: z.ZodCustom<OpenValue<{
111
+ readonly bot: "bot";
112
+ readonly staff: "staff";
113
+ readonly system: "system";
114
+ }>, OpenValue<{
115
+ readonly bot: "bot";
116
+ readonly staff: "staff";
117
+ readonly system: "system";
118
+ }>>;
119
+ text: z.ZodString;
120
+ quickReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
121
+ title: z.ZodString;
122
+ payload: z.ZodString;
123
+ }, z.core.$strip>>>;
124
+ attachments: z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodUnknown>, z.ZodTransform<({
125
+ kind: "buttons";
126
+ text: string;
127
+ buttons: {
128
+ type: "postback" | "url";
129
+ title: string;
130
+ payload?: string | undefined;
131
+ url?: string | undefined;
132
+ }[];
133
+ } | {
134
+ kind: "image";
135
+ url: string;
136
+ } | {
137
+ kind: "generic";
138
+ elements: {
139
+ title: string;
140
+ subtitle?: string | undefined;
141
+ imageUrl?: string | undefined;
142
+ defaultUrl?: string | undefined;
143
+ buttons?: {
144
+ type: "postback" | "url";
145
+ title: string;
146
+ payload?: string | undefined;
147
+ url?: string | undefined;
148
+ }[] | undefined;
149
+ }[];
150
+ })[], unknown[]>>>;
151
+ inReplyTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
152
+ }, z.core.$strip>;
153
+ }, z.core.$strip>;
154
+ sequence: z.ZodNumber;
155
+ id: z.ZodString;
156
+ createdAt: z.ZodISODateTime;
157
+ }, z.core.$strip>;
158
+ declare const messageFailedEventSchema: z.ZodObject<{
159
+ type: z.ZodLiteral<"message.failed">;
160
+ data: z.ZodObject<{
161
+ userId: z.ZodString;
162
+ inReplyTo: z.ZodArray<z.ZodString>;
163
+ reason: z.ZodCustom<OpenValue<{
164
+ readonly aiError: "ai_error";
165
+ readonly expired: "expired";
166
+ }>, OpenValue<{
167
+ readonly aiError: "ai_error";
168
+ readonly expired: "expired";
169
+ }>>;
170
+ }, z.core.$strip>;
171
+ sequence: z.ZodNumber;
172
+ id: z.ZodString;
173
+ createdAt: z.ZodISODateTime;
174
+ }, z.core.$strip>;
175
+ declare const handedToStaffEventSchema: z.ZodObject<{
176
+ type: z.ZodLiteral<"conversation.handed_to_staff">;
177
+ data: z.ZodObject<{
178
+ userId: z.ZodString;
179
+ reason: z.ZodCustom<OpenValue<{
180
+ readonly humanRequest: "human_request";
181
+ readonly tenantRequest: "tenant_request";
182
+ readonly agentDecision: "agent_decision";
183
+ readonly aiError: "ai_error";
184
+ readonly limitReached: "limit_reached";
185
+ readonly noModel: "no_model";
186
+ readonly staff: "staff";
187
+ }>, OpenValue<{
188
+ readonly humanRequest: "human_request";
189
+ readonly tenantRequest: "tenant_request";
190
+ readonly agentDecision: "agent_decision";
191
+ readonly aiError: "ai_error";
192
+ readonly limitReached: "limit_reached";
193
+ readonly noModel: "no_model";
194
+ readonly staff: "staff";
195
+ }>>;
196
+ }, z.core.$strip>;
197
+ sequence: z.ZodNumber;
198
+ id: z.ZodString;
199
+ createdAt: z.ZodISODateTime;
200
+ }, z.core.$strip>;
201
+ declare const returnedToBotEventSchema: z.ZodObject<{
202
+ type: z.ZodLiteral<"conversation.returned_to_bot">;
203
+ data: z.ZodObject<{
204
+ userId: z.ZodString;
205
+ reason: z.ZodCustom<OpenValue<{
206
+ readonly staff: "staff";
207
+ readonly user: "user";
208
+ readonly timeout: "timeout";
209
+ }>, OpenValue<{
210
+ readonly staff: "staff";
211
+ readonly user: "user";
212
+ readonly timeout: "timeout";
213
+ }>>;
214
+ }, z.core.$strip>;
215
+ sequence: z.ZodNumber;
216
+ id: z.ZodString;
217
+ createdAt: z.ZodISODateTime;
218
+ }, z.core.$strip>;
219
+ declare const webhookTestEventSchema: z.ZodObject<{
220
+ type: z.ZodLiteral<"webhook.test">;
221
+ data: z.ZodObject<{}, z.core.$strip>;
222
+ id: z.ZodString;
223
+ createdAt: z.ZodISODateTime;
224
+ }, z.core.$strip>;
225
+ declare const webhookEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
226
+ type: z.ZodLiteral<"message.created">;
227
+ data: z.ZodObject<{
228
+ userId: z.ZodString;
229
+ message: z.ZodObject<{
230
+ from: z.ZodCustom<OpenValue<{
231
+ readonly bot: "bot";
232
+ readonly staff: "staff";
233
+ readonly system: "system";
234
+ }>, OpenValue<{
235
+ readonly bot: "bot";
236
+ readonly staff: "staff";
237
+ readonly system: "system";
238
+ }>>;
239
+ text: z.ZodString;
240
+ quickReplies: z.ZodOptional<z.ZodArray<z.ZodObject<{
241
+ title: z.ZodString;
242
+ payload: z.ZodString;
243
+ }, z.core.$strip>>>;
244
+ attachments: z.ZodOptional<z.ZodPipe<z.ZodArray<z.ZodUnknown>, z.ZodTransform<({
245
+ kind: "buttons";
246
+ text: string;
247
+ buttons: {
248
+ type: "postback" | "url";
249
+ title: string;
250
+ payload?: string | undefined;
251
+ url?: string | undefined;
252
+ }[];
253
+ } | {
254
+ kind: "image";
255
+ url: string;
256
+ } | {
257
+ kind: "generic";
258
+ elements: {
259
+ title: string;
260
+ subtitle?: string | undefined;
261
+ imageUrl?: string | undefined;
262
+ defaultUrl?: string | undefined;
263
+ buttons?: {
264
+ type: "postback" | "url";
265
+ title: string;
266
+ payload?: string | undefined;
267
+ url?: string | undefined;
268
+ }[] | undefined;
269
+ }[];
270
+ })[], unknown[]>>>;
271
+ inReplyTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
272
+ }, z.core.$strip>;
273
+ }, z.core.$strip>;
274
+ sequence: z.ZodNumber;
275
+ id: z.ZodString;
276
+ createdAt: z.ZodISODateTime;
277
+ }, z.core.$strip>, z.ZodObject<{
278
+ type: z.ZodLiteral<"message.failed">;
279
+ data: z.ZodObject<{
280
+ userId: z.ZodString;
281
+ inReplyTo: z.ZodArray<z.ZodString>;
282
+ reason: z.ZodCustom<OpenValue<{
283
+ readonly aiError: "ai_error";
284
+ readonly expired: "expired";
285
+ }>, OpenValue<{
286
+ readonly aiError: "ai_error";
287
+ readonly expired: "expired";
288
+ }>>;
289
+ }, z.core.$strip>;
290
+ sequence: z.ZodNumber;
291
+ id: z.ZodString;
292
+ createdAt: z.ZodISODateTime;
293
+ }, z.core.$strip>, z.ZodObject<{
294
+ type: z.ZodLiteral<"conversation.handed_to_staff">;
295
+ data: z.ZodObject<{
296
+ userId: z.ZodString;
297
+ reason: z.ZodCustom<OpenValue<{
298
+ readonly humanRequest: "human_request";
299
+ readonly tenantRequest: "tenant_request";
300
+ readonly agentDecision: "agent_decision";
301
+ readonly aiError: "ai_error";
302
+ readonly limitReached: "limit_reached";
303
+ readonly noModel: "no_model";
304
+ readonly staff: "staff";
305
+ }>, OpenValue<{
306
+ readonly humanRequest: "human_request";
307
+ readonly tenantRequest: "tenant_request";
308
+ readonly agentDecision: "agent_decision";
309
+ readonly aiError: "ai_error";
310
+ readonly limitReached: "limit_reached";
311
+ readonly noModel: "no_model";
312
+ readonly staff: "staff";
313
+ }>>;
314
+ }, z.core.$strip>;
315
+ sequence: z.ZodNumber;
316
+ id: z.ZodString;
317
+ createdAt: z.ZodISODateTime;
318
+ }, z.core.$strip>, z.ZodObject<{
319
+ type: z.ZodLiteral<"conversation.returned_to_bot">;
320
+ data: z.ZodObject<{
321
+ userId: z.ZodString;
322
+ reason: z.ZodCustom<OpenValue<{
323
+ readonly staff: "staff";
324
+ readonly user: "user";
325
+ readonly timeout: "timeout";
326
+ }>, OpenValue<{
327
+ readonly staff: "staff";
328
+ readonly user: "user";
329
+ readonly timeout: "timeout";
330
+ }>>;
331
+ }, z.core.$strip>;
332
+ sequence: z.ZodNumber;
333
+ id: z.ZodString;
334
+ createdAt: z.ZodISODateTime;
335
+ }, z.core.$strip>, z.ZodObject<{
336
+ type: z.ZodLiteral<"webhook.test">;
337
+ data: z.ZodObject<{}, z.core.$strip>;
338
+ id: z.ZodString;
339
+ createdAt: z.ZodISODateTime;
340
+ }, z.core.$strip>], "type">;
341
+ declare const unknownWebhookEventSchema: z.ZodPipe<z.ZodObject<{
342
+ id: z.ZodString;
343
+ type: z.ZodString;
344
+ createdAt: z.ZodOptional<z.ZodString>;
345
+ data: z.ZodOptional<z.ZodUnknown>;
346
+ }, z.core.$loose>, z.ZodTransform<{
347
+ id: string;
348
+ type: "unknown";
349
+ originalType: string;
350
+ payload: {
351
+ [x: string]: unknown;
352
+ id: string;
353
+ type: string;
354
+ createdAt?: string | undefined;
355
+ data?: unknown;
356
+ };
357
+ }, {
358
+ [x: string]: unknown;
359
+ id: string;
360
+ type: string;
361
+ createdAt?: string | undefined;
362
+ data?: unknown;
363
+ }>>;
364
+
365
+ type SendMessageRequest = z.infer<typeof sendMessageRequestSchema>;
366
+ type HandoverRequest = z.infer<typeof handoverRequestSchema>;
367
+ type ApiChannelAttachment = z.infer<typeof attachmentSchema>;
368
+ type ApiChannelQuickReply = z.infer<typeof quickReplySchema>;
369
+ type MessageCreatedEvent = z.infer<typeof messageCreatedEventSchema>;
370
+ type MessageFailedEvent = z.infer<typeof messageFailedEventSchema>;
371
+ type HandedToStaffEvent = z.infer<typeof handedToStaffEventSchema>;
372
+ type ReturnedToBotEvent = z.infer<typeof returnedToBotEventSchema>;
373
+ type WebhookTestEvent = z.infer<typeof webhookTestEventSchema>;
374
+ type UnknownWebhookEvent = z.infer<typeof unknownWebhookEventSchema>;
375
+ type WebhookEvent = z.infer<typeof webhookEventSchema>;
376
+
377
+ type ReceivedWebhookEvent = WebhookEvent | UnknownWebhookEvent;
378
+
379
+ export { API_CHANNEL_LIMIT, API_CHANNEL_PATH, HANDOVER_REASON, MESSAGE_FAILED_REASON, MESSAGE_FROM, RETURNED_TO_BOT_REASON, UNKNOWN_WEBHOOK_EVENT, WEBHOOK_EVENT_TYPE, WEBHOOK_HEADER, WEBHOOK_TOLERANCE_SECONDS, attachmentSchema, buttonSchema, handedToStaffEventSchema, handoverRequestSchema, messageCreatedEventSchema, messageFailedEventSchema, quickReplySchema, returnedToBotEventSchema, sendMessageRequestSchema, unknownWebhookEventSchema, webhookEventSchema, webhookTestEventSchema };
380
+ export type { ApiChannelAttachment, ApiChannelQuickReply, HandedToStaffEvent, HandoverRequest, MessageCreatedEvent, MessageFailedEvent, ReceivedWebhookEvent, ReturnedToBotEvent, SendMessageRequest, UnknownWebhookEvent, WebhookEvent, WebhookTestEvent };
@@ -0,0 +1,25 @@
1
+ import { A, a, H, M, b, R, U, W, c, d, e, f, h, g, m, i, q, r, s, u, w, j } from "./protocol-oujowiFb.js";
2
+ export {
3
+ A as API_CHANNEL_LIMIT,
4
+ a as API_CHANNEL_PATH,
5
+ H as HANDOVER_REASON,
6
+ M as MESSAGE_FAILED_REASON,
7
+ b as MESSAGE_FROM,
8
+ R as RETURNED_TO_BOT_REASON,
9
+ U as UNKNOWN_WEBHOOK_EVENT,
10
+ W as WEBHOOK_EVENT_TYPE,
11
+ c as WEBHOOK_HEADER,
12
+ d as WEBHOOK_TOLERANCE_SECONDS,
13
+ e as attachmentSchema,
14
+ f as buttonSchema,
15
+ h as handedToStaffEventSchema,
16
+ g as handoverRequestSchema,
17
+ m as messageCreatedEventSchema,
18
+ i as messageFailedEventSchema,
19
+ q as quickReplySchema,
20
+ r as returnedToBotEventSchema,
21
+ s as sendMessageRequestSchema,
22
+ u as unknownWebhookEventSchema,
23
+ w as webhookEventSchema,
24
+ j as webhookTestEventSchema
25
+ };
package/package.json CHANGED
@@ -1,6 +1,95 @@
1
1
  {
2
2
  "name": "@tabsystems/onechat",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Node.js SDK for the OneChat API channel: send your users' messages to your OneChat AI agent and verify the signed webhooks that bring its replies back.",
5
+ "keywords": [
6
+ "onechat",
7
+ "chatbot",
8
+ "ai-agent",
9
+ "webhook",
10
+ "sdk",
11
+ "mongolia"
12
+ ],
13
+ "homepage": "https://onechat.tabsystems.tech/docs/api-channel",
14
+ "license": "MIT",
15
+ "type": "module",
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "sideEffects": false,
20
+ "module": "./dist-npm/index.js",
21
+ "exports": {
22
+ ".": {
23
+ "import": {
24
+ "types": "./dist-npm/index.d.ts",
25
+ "default": "./dist-npm/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist-npm/index.d.cts",
29
+ "default": "./dist-npm/index.cjs"
30
+ }
31
+ },
32
+ "./protocol": {
33
+ "import": {
34
+ "types": "./dist-npm/protocol.d.ts",
35
+ "default": "./dist-npm/protocol.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist-npm/protocol.d.cts",
39
+ "default": "./dist-npm/protocol.cjs"
40
+ }
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "files": [
45
+ "dist-npm",
46
+ "README.md",
47
+ "CHANGELOG.md",
48
+ "LICENSE"
49
+ ],
50
+ "publishConfig": {
51
+ "main": "./dist-npm/index.cjs",
52
+ "module": "./dist-npm/index.js",
53
+ "types": "./dist-npm/index.d.ts",
54
+ "exports": {
55
+ ".": {
56
+ "import": {
57
+ "types": "./dist-npm/index.d.ts",
58
+ "default": "./dist-npm/index.js"
59
+ },
60
+ "require": {
61
+ "types": "./dist-npm/index.d.cts",
62
+ "default": "./dist-npm/index.cjs"
63
+ }
64
+ },
65
+ "./protocol": {
66
+ "import": {
67
+ "types": "./dist-npm/protocol.d.ts",
68
+ "default": "./dist-npm/protocol.js"
69
+ },
70
+ "require": {
71
+ "types": "./dist-npm/protocol.d.cts",
72
+ "default": "./dist-npm/protocol.cjs"
73
+ }
74
+ },
75
+ "./package.json": "./package.json"
76
+ }
77
+ },
78
+ "scripts": {
79
+ "build:npm": "rm -rf dist-npm .types && vite build && tsc -p tsconfig.build.json && rollup -c rollup.dts.config.mjs && cp dist-npm/index.d.ts dist-npm/index.d.cts && cp dist-npm/protocol.d.ts dist-npm/protocol.d.cts && rm -rf .types",
80
+ "prepack": "yarn build:npm",
81
+ "prepublishOnly": "echo 'Publish the packed tarball: yarn pack, then npm publish package.tgz (see .github/workflows/publish-sdk.yml).' && exit 1",
82
+ "test": "yarn g:vitest run"
83
+ },
84
+ "dependencies": {
85
+ "zod": "^4.4.3"
86
+ },
87
+ "devDependencies": {
88
+ "rollup": "^4.60.2",
89
+ "rollup-plugin-dts": "6.5.1",
90
+ "typescript": "^6.0.3",
91
+ "vite": "^7.3.3"
92
+ },
93
+ "main": "./dist-npm/index.cjs",
94
+ "types": "./dist-npm/index.d.ts"
6
95
  }