chatifai 1.0.24 → 1.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.FullFileTextSchema = exports.PreDefinedQuerySchema = exports.ChunkSchema = exports.ContextSchema = exports.AgentSchema = exports.UserSchema = exports.OrganizationSchema = void 0;
17
+ exports.MessageSchema = exports.ThreadSchema = exports.FullFileTextSchema = exports.PreDefinedQuerySchema = exports.ChunkSchema = exports.ContextSchema = exports.AgentSchema = exports.UserSchema = exports.OrganizationSchema = void 0;
18
18
  // Export types for consumers
19
19
  __exportStar(require("./types"), exports);
20
20
  const mongoose_1 = require("mongoose");
@@ -147,16 +147,19 @@ exports.ChunkSchema = new mongoose_1.Schema({
147
147
  });
148
148
  exports.PreDefinedQuerySchema = new mongoose_1.Schema({
149
149
  organization_id: { type: String },
150
- title: { type: String, minlength: 1, maxlength: 100 },
150
+ query_name: { type: String, minlength: 1, maxlength: 100 },
151
+ query_hint: { type: String, minlength: 1, maxlength: 100 },
151
152
  query: { type: String, required: true },
152
- context_ids: { type: [String] },
153
+ instructions: { type: String },
154
+ contexts: { type: [Object] },
153
155
  status: {
154
156
  type: String,
155
157
  enum: ['active', 'inactive', 'archived'],
156
158
  default: 'active',
157
159
  required: true,
158
160
  },
159
- users_ids: { type: [String] },
161
+ users: { type: [Object] },
162
+ click_count: { type: Number },
160
163
  created_at: { type: Number },
161
164
  updated_at: { type: Number },
162
165
  }, {
@@ -179,3 +182,38 @@ exports.FullFileTextSchema = new mongoose_1.Schema({
179
182
  id: true,
180
183
  // encryptionType: 'csfle',
181
184
  });
185
+ exports.ThreadSchema = new mongoose_1.Schema({
186
+ organization_id: { type: String, required: true },
187
+ user_id: { type: String, required: true },
188
+ agent_id: { type: String, required: true },
189
+ title: { type: String, minlength: 1, maxlength: 200 },
190
+ description: { type: String },
191
+ query_id: { type: String },
192
+ messages_count: { type: Number, default: 0 },
193
+ created_at: { type: Number },
194
+ updated_at: { type: Number },
195
+ }, {
196
+ versionKey: false,
197
+ toJSON: { virtuals: true },
198
+ toObject: { virtuals: true },
199
+ timestamps: true,
200
+ id: true,
201
+ // encryptionType: 'csfle',
202
+ });
203
+ exports.MessageSchema = new mongoose_1.Schema({
204
+ thread_id: { type: String, required: true },
205
+ organization_id: { type: String, required: true },
206
+ user_id: { type: String },
207
+ agent_id: { type: String },
208
+ content: { type: String, required: true },
209
+ role: { type: String, enum: ['user', 'agent', 'system'], required: true },
210
+ created_at: { type: Number },
211
+ updated_at: { type: Number },
212
+ }, {
213
+ versionKey: false,
214
+ toJSON: { virtuals: true },
215
+ toObject: { virtuals: true },
216
+ timestamps: true,
217
+ id: true,
218
+ // encryptionType: 'csfle',
219
+ });
package/dist/types.d.ts CHANGED
@@ -321,33 +321,230 @@ export declare const zodFullTextSchema: z.ZodObject<{
321
321
  export declare const zodPreDefinedQuerySchema: z.ZodObject<{
322
322
  _id: z.ZodOptional<z.ZodString>;
323
323
  organization_id: z.ZodOptional<z.ZodString>;
324
- title: z.ZodOptional<z.ZodString>;
324
+ query_name: z.ZodOptional<z.ZodString>;
325
+ query_hint: z.ZodOptional<z.ZodString>;
325
326
  query: z.ZodString;
326
- context_ids: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
327
+ instructions: z.ZodOptional<z.ZodString>;
328
+ contexts: z.ZodOptional<z.ZodArray<z.ZodObject<{
329
+ _id: z.ZodOptional<z.ZodOptional<z.ZodString>>;
330
+ organization_id: z.ZodOptional<z.ZodOptional<z.ZodString>>;
331
+ title: z.ZodOptional<z.ZodString>;
332
+ ai_description: z.ZodOptional<z.ZodOptional<z.ZodString>>;
333
+ note: z.ZodOptional<z.ZodOptional<z.ZodString>>;
334
+ file_id: z.ZodOptional<z.ZodOptional<z.ZodString>>;
335
+ file_url: z.ZodOptional<z.ZodOptional<z.ZodString>>;
336
+ file_gcs_url: z.ZodOptional<z.ZodOptional<z.ZodString>>;
337
+ file_name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
338
+ type: z.ZodOptional<z.ZodOptional<z.ZodString>>;
339
+ size: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
340
+ tokens: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
341
+ is_active: z.ZodOptional<z.ZodOptional<z.ZodDefault<z.ZodBoolean>>>;
342
+ created_at: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
343
+ updated_at: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
344
+ uploaded_by: z.ZodOptional<z.ZodOptional<z.ZodObject<{
345
+ first_name: z.ZodOptional<z.ZodString>;
346
+ last_name: z.ZodOptional<z.ZodString>;
347
+ email: z.ZodOptional<z.ZodString>;
348
+ }, "strip", z.ZodTypeAny, {
349
+ email?: string | undefined;
350
+ first_name?: string | undefined;
351
+ last_name?: string | undefined;
352
+ }, {
353
+ email?: string | undefined;
354
+ first_name?: string | undefined;
355
+ last_name?: string | undefined;
356
+ }>>>;
357
+ bucket_name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
358
+ processing_status: z.ZodOptional<z.ZodOptional<z.ZodEnum<["pending", "processing", "completed", "failed"]>>>;
359
+ }, "strip", z.ZodTypeAny, {
360
+ _id?: string | undefined;
361
+ title?: string | undefined;
362
+ type?: string | undefined;
363
+ created_at?: number | undefined;
364
+ updated_at?: number | undefined;
365
+ organization_id?: string | undefined;
366
+ ai_description?: string | undefined;
367
+ note?: string | undefined;
368
+ file_id?: string | undefined;
369
+ file_url?: string | undefined;
370
+ file_gcs_url?: string | undefined;
371
+ file_name?: string | undefined;
372
+ size?: number | undefined;
373
+ tokens?: number | undefined;
374
+ is_active?: boolean | undefined;
375
+ uploaded_by?: {
376
+ email?: string | undefined;
377
+ first_name?: string | undefined;
378
+ last_name?: string | undefined;
379
+ } | undefined;
380
+ bucket_name?: string | undefined;
381
+ processing_status?: "pending" | "processing" | "completed" | "failed" | undefined;
382
+ }, {
383
+ _id?: string | undefined;
384
+ title?: string | undefined;
385
+ type?: string | undefined;
386
+ created_at?: number | undefined;
387
+ updated_at?: number | undefined;
388
+ organization_id?: string | undefined;
389
+ ai_description?: string | undefined;
390
+ note?: string | undefined;
391
+ file_id?: string | undefined;
392
+ file_url?: string | undefined;
393
+ file_gcs_url?: string | undefined;
394
+ file_name?: string | undefined;
395
+ size?: number | undefined;
396
+ tokens?: number | undefined;
397
+ is_active?: boolean | undefined;
398
+ uploaded_by?: {
399
+ email?: string | undefined;
400
+ first_name?: string | undefined;
401
+ last_name?: string | undefined;
402
+ } | undefined;
403
+ bucket_name?: string | undefined;
404
+ processing_status?: "pending" | "processing" | "completed" | "failed" | undefined;
405
+ }>, "many">>;
327
406
  status: z.ZodDefault<z.ZodEnum<["active", "inactive", "archived"]>>;
328
- users_ids: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
407
+ users: z.ZodOptional<z.ZodArray<z.ZodObject<{
408
+ _id: z.ZodOptional<z.ZodOptional<z.ZodString>>;
409
+ organization_memberships: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
410
+ clerk_user_id: z.ZodOptional<z.ZodString>;
411
+ email: z.ZodOptional<z.ZodString>;
412
+ first_name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
413
+ last_name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
414
+ active_until: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
415
+ notes: z.ZodOptional<z.ZodOptional<z.ZodString>>;
416
+ avatar: z.ZodOptional<z.ZodOptional<z.ZodString>>;
417
+ user_role: z.ZodOptional<z.ZodOptional<z.ZodDefault<z.ZodEnum<["admin", "member", "client"]>>>>;
418
+ created_at: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
419
+ updated_at: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
420
+ }, "strip", z.ZodTypeAny, {
421
+ _id?: string | undefined;
422
+ created_at?: number | undefined;
423
+ updated_at?: number | undefined;
424
+ organization_memberships?: string[] | undefined;
425
+ clerk_user_id?: string | undefined;
426
+ email?: string | undefined;
427
+ first_name?: string | undefined;
428
+ last_name?: string | undefined;
429
+ active_until?: number | undefined;
430
+ notes?: string | undefined;
431
+ avatar?: string | undefined;
432
+ user_role?: "admin" | "member" | "client" | undefined;
433
+ }, {
434
+ _id?: string | undefined;
435
+ created_at?: number | undefined;
436
+ updated_at?: number | undefined;
437
+ organization_memberships?: string[] | undefined;
438
+ clerk_user_id?: string | undefined;
439
+ email?: string | undefined;
440
+ first_name?: string | undefined;
441
+ last_name?: string | undefined;
442
+ active_until?: number | undefined;
443
+ notes?: string | undefined;
444
+ avatar?: string | undefined;
445
+ user_role?: "admin" | "member" | "client" | undefined;
446
+ }>, "many">>;
447
+ click_count: z.ZodOptional<z.ZodNumber>;
329
448
  created_at: z.ZodOptional<z.ZodNumber>;
330
449
  updated_at: z.ZodOptional<z.ZodNumber>;
331
450
  }, "strip", z.ZodTypeAny, {
332
451
  status: "active" | "inactive" | "archived";
333
452
  query: string;
334
453
  _id?: string | undefined;
335
- title?: string | undefined;
336
454
  created_at?: number | undefined;
337
455
  updated_at?: number | undefined;
338
456
  organization_id?: string | undefined;
339
- context_ids?: string[] | undefined;
340
- users_ids?: string[] | undefined;
457
+ instructions?: string | undefined;
458
+ query_name?: string | undefined;
459
+ query_hint?: string | undefined;
460
+ contexts?: {
461
+ _id?: string | undefined;
462
+ title?: string | undefined;
463
+ type?: string | undefined;
464
+ created_at?: number | undefined;
465
+ updated_at?: number | undefined;
466
+ organization_id?: string | undefined;
467
+ ai_description?: string | undefined;
468
+ note?: string | undefined;
469
+ file_id?: string | undefined;
470
+ file_url?: string | undefined;
471
+ file_gcs_url?: string | undefined;
472
+ file_name?: string | undefined;
473
+ size?: number | undefined;
474
+ tokens?: number | undefined;
475
+ is_active?: boolean | undefined;
476
+ uploaded_by?: {
477
+ email?: string | undefined;
478
+ first_name?: string | undefined;
479
+ last_name?: string | undefined;
480
+ } | undefined;
481
+ bucket_name?: string | undefined;
482
+ processing_status?: "pending" | "processing" | "completed" | "failed" | undefined;
483
+ }[] | undefined;
484
+ users?: {
485
+ _id?: string | undefined;
486
+ created_at?: number | undefined;
487
+ updated_at?: number | undefined;
488
+ organization_memberships?: string[] | undefined;
489
+ clerk_user_id?: string | undefined;
490
+ email?: string | undefined;
491
+ first_name?: string | undefined;
492
+ last_name?: string | undefined;
493
+ active_until?: number | undefined;
494
+ notes?: string | undefined;
495
+ avatar?: string | undefined;
496
+ user_role?: "admin" | "member" | "client" | undefined;
497
+ }[] | undefined;
498
+ click_count?: number | undefined;
341
499
  }, {
342
500
  query: string;
343
501
  _id?: string | undefined;
344
- title?: string | undefined;
345
502
  status?: "active" | "inactive" | "archived" | undefined;
346
503
  created_at?: number | undefined;
347
504
  updated_at?: number | undefined;
348
505
  organization_id?: string | undefined;
349
- context_ids?: string[] | undefined;
350
- users_ids?: string[] | undefined;
506
+ instructions?: string | undefined;
507
+ query_name?: string | undefined;
508
+ query_hint?: string | undefined;
509
+ contexts?: {
510
+ _id?: string | undefined;
511
+ title?: string | undefined;
512
+ type?: string | undefined;
513
+ created_at?: number | undefined;
514
+ updated_at?: number | undefined;
515
+ organization_id?: string | undefined;
516
+ ai_description?: string | undefined;
517
+ note?: string | undefined;
518
+ file_id?: string | undefined;
519
+ file_url?: string | undefined;
520
+ file_gcs_url?: string | undefined;
521
+ file_name?: string | undefined;
522
+ size?: number | undefined;
523
+ tokens?: number | undefined;
524
+ is_active?: boolean | undefined;
525
+ uploaded_by?: {
526
+ email?: string | undefined;
527
+ first_name?: string | undefined;
528
+ last_name?: string | undefined;
529
+ } | undefined;
530
+ bucket_name?: string | undefined;
531
+ processing_status?: "pending" | "processing" | "completed" | "failed" | undefined;
532
+ }[] | undefined;
533
+ users?: {
534
+ _id?: string | undefined;
535
+ created_at?: number | undefined;
536
+ updated_at?: number | undefined;
537
+ organization_memberships?: string[] | undefined;
538
+ clerk_user_id?: string | undefined;
539
+ email?: string | undefined;
540
+ first_name?: string | undefined;
541
+ last_name?: string | undefined;
542
+ active_until?: number | undefined;
543
+ notes?: string | undefined;
544
+ avatar?: string | undefined;
545
+ user_role?: "admin" | "member" | "client" | undefined;
546
+ }[] | undefined;
547
+ click_count?: number | undefined;
351
548
  }>;
352
549
  export declare const zodQuerySchema: z.ZodObject<{
353
550
  thread_id: z.ZodOptional<z.ZodString>;
@@ -355,21 +552,89 @@ export declare const zodQuerySchema: z.ZodObject<{
355
552
  organization_id: z.ZodString;
356
553
  user_id: z.ZodString;
357
554
  query: z.ZodString;
555
+ pre_defined_query_id: z.ZodOptional<z.ZodString>;
358
556
  timestamp: z.ZodNumber;
359
557
  }, "strip", z.ZodTypeAny, {
360
558
  organization_id: string;
361
559
  query: string;
362
560
  user_id: string;
363
561
  timestamp: number;
364
- context_ids?: string[] | undefined;
365
562
  thread_id?: string | undefined;
563
+ context_ids?: string[] | undefined;
564
+ pre_defined_query_id?: string | undefined;
366
565
  }, {
367
566
  organization_id: string;
368
567
  query: string;
369
568
  user_id: string;
370
569
  timestamp: number;
371
- context_ids?: string[] | undefined;
372
570
  thread_id?: string | undefined;
571
+ context_ids?: string[] | undefined;
572
+ pre_defined_query_id?: string | undefined;
573
+ }>;
574
+ export declare const zodThreadSchema: z.ZodObject<{
575
+ _id: z.ZodOptional<z.ZodString>;
576
+ organization_id: z.ZodString;
577
+ user_id: z.ZodString;
578
+ agent_id: z.ZodOptional<z.ZodString>;
579
+ title: z.ZodOptional<z.ZodString>;
580
+ description: z.ZodOptional<z.ZodString>;
581
+ created_at: z.ZodOptional<z.ZodNumber>;
582
+ updated_at: z.ZodOptional<z.ZodNumber>;
583
+ query_id: z.ZodOptional<z.ZodString>;
584
+ messages_count: z.ZodOptional<z.ZodNumber>;
585
+ }, "strip", z.ZodTypeAny, {
586
+ organization_id: string;
587
+ user_id: string;
588
+ _id?: string | undefined;
589
+ title?: string | undefined;
590
+ created_at?: number | undefined;
591
+ updated_at?: number | undefined;
592
+ description?: string | undefined;
593
+ agent_id?: string | undefined;
594
+ query_id?: string | undefined;
595
+ messages_count?: number | undefined;
596
+ }, {
597
+ organization_id: string;
598
+ user_id: string;
599
+ _id?: string | undefined;
600
+ title?: string | undefined;
601
+ created_at?: number | undefined;
602
+ updated_at?: number | undefined;
603
+ description?: string | undefined;
604
+ agent_id?: string | undefined;
605
+ query_id?: string | undefined;
606
+ messages_count?: number | undefined;
607
+ }>;
608
+ export declare const zodMessageSchema: z.ZodObject<{
609
+ _id: z.ZodOptional<z.ZodString>;
610
+ thread_id: z.ZodString;
611
+ organization_id: z.ZodString;
612
+ user_id: z.ZodOptional<z.ZodString>;
613
+ agent_id: z.ZodOptional<z.ZodString>;
614
+ role: z.ZodEnum<["user", "agent", "system"]>;
615
+ content: z.ZodString;
616
+ created_at: z.ZodOptional<z.ZodNumber>;
617
+ updated_at: z.ZodOptional<z.ZodNumber>;
618
+ }, "strip", z.ZodTypeAny, {
619
+ organization_id: string;
620
+ thread_id: string;
621
+ role: "user" | "agent" | "system";
622
+ content: string;
623
+ _id?: string | undefined;
624
+ created_at?: number | undefined;
625
+ updated_at?: number | undefined;
626
+ user_id?: string | undefined;
627
+ agent_id?: string | undefined;
628
+ }, {
629
+ organization_id: string;
630
+ thread_id: string;
631
+ role: "user" | "agent" | "system";
632
+ content: string;
633
+ _id?: string | undefined;
634
+ created_at?: number | undefined;
635
+ updated_at?: number | undefined;
636
+ user_id?: string | undefined;
637
+ agent_id?: string | undefined;
373
638
  }>;
374
639
  export type EventAttributeType = {
375
640
  http_request: {
@@ -396,6 +661,8 @@ export type ModelType = (typeof modelsList)[number];
396
661
  export type UserRoleType = (typeof userRoles)[number];
397
662
  export type FullFileTextType = z.infer<typeof zodFullTextSchema>;
398
663
  export type QueryType = z.infer<typeof zodQuerySchema>;
664
+ export type ThreadType = z.infer<typeof zodThreadSchema>;
665
+ export type MessageType = z.infer<typeof zodMessageSchema>;
399
666
  export declare enum FileType {
400
667
  PDF = "application/pdf",
401
668
  WORD = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
package/dist/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueuesList = exports.FileType = exports.zodQuerySchema = exports.zodPreDefinedQuerySchema = exports.zodFullTextSchema = exports.zodChunkSchema = exports.zodAgentSchema = exports.zodContextSchema = exports.zodUserSchema = exports.zodOrganizationSchema = exports.userRoles = exports.modelsList = void 0;
3
+ exports.QueuesList = exports.FileType = exports.zodMessageSchema = exports.zodThreadSchema = exports.zodQuerySchema = exports.zodPreDefinedQuerySchema = exports.zodFullTextSchema = exports.zodChunkSchema = exports.zodAgentSchema = exports.zodContextSchema = exports.zodUserSchema = exports.zodOrganizationSchema = exports.userRoles = exports.modelsList = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.modelsList = [
6
6
  'gemini-2.5-flash-lite',
@@ -122,22 +122,50 @@ exports.zodFullTextSchema = zod_1.z.object({
122
122
  exports.zodPreDefinedQuerySchema = zod_1.z.object({
123
123
  _id: zod_1.z.string().optional(),
124
124
  organization_id: zod_1.z.string().optional(),
125
- title: zod_1.z.string().min(1).max(100).optional(),
125
+ query_name: zod_1.z.string().min(1).max(100).optional(),
126
+ query_hint: zod_1.z.string().min(1).max(100).optional(),
126
127
  query: zod_1.z.string().min(1),
127
- context_ids: zod_1.z.array(zod_1.z.string()).optional(),
128
+ instructions: zod_1.z.string().optional(),
129
+ contexts: zod_1.z.array(exports.zodContextSchema.partial()).optional(),
128
130
  status: zod_1.z.enum(['active', 'inactive', 'archived']).default('active'),
129
- users_ids: zod_1.z.array(zod_1.z.string()).optional(),
131
+ users: zod_1.z.array(exports.zodUserSchema.partial()).optional(),
132
+ click_count: zod_1.z.number().optional(),
130
133
  created_at: zod_1.z.number().optional(),
131
134
  updated_at: zod_1.z.number().optional(),
132
135
  });
136
+ // Zod schema for handling user queries
133
137
  exports.zodQuerySchema = zod_1.z.object({
134
138
  thread_id: zod_1.z.string().optional(),
135
139
  context_ids: zod_1.z.array(zod_1.z.string()).optional(),
136
140
  organization_id: zod_1.z.string(),
137
141
  user_id: zod_1.z.string(),
138
142
  query: zod_1.z.string().min(1),
143
+ pre_defined_query_id: zod_1.z.string().optional(),
139
144
  timestamp: zod_1.z.number(),
140
145
  });
146
+ exports.zodThreadSchema = zod_1.z.object({
147
+ _id: zod_1.z.string().optional(),
148
+ organization_id: zod_1.z.string(),
149
+ user_id: zod_1.z.string(),
150
+ agent_id: zod_1.z.string().optional(),
151
+ title: zod_1.z.string().min(1).max(200).optional(),
152
+ description: zod_1.z.string().optional(),
153
+ created_at: zod_1.z.number().optional(),
154
+ updated_at: zod_1.z.number().optional(),
155
+ query_id: zod_1.z.string().optional(),
156
+ messages_count: zod_1.z.number().optional(),
157
+ });
158
+ exports.zodMessageSchema = zod_1.z.object({
159
+ _id: zod_1.z.string().optional(),
160
+ thread_id: zod_1.z.string(),
161
+ organization_id: zod_1.z.string(),
162
+ user_id: zod_1.z.string().optional(),
163
+ agent_id: zod_1.z.string().optional(),
164
+ role: zod_1.z.enum(['user', 'agent', 'system']),
165
+ content: zod_1.z.string(),
166
+ created_at: zod_1.z.number().optional(),
167
+ updated_at: zod_1.z.number().optional(),
168
+ });
141
169
  var FileType;
142
170
  (function (FileType) {
143
171
  FileType["PDF"] = "application/pdf";
package/index.ts CHANGED
@@ -153,16 +153,19 @@ export const ChunkSchema = new Schema(
153
153
  export const PreDefinedQuerySchema = new Schema(
154
154
  {
155
155
  organization_id: { type: String },
156
- title: { type: String, minlength: 1, maxlength: 100 },
156
+ query_name: { type: String, minlength: 1, maxlength: 100 },
157
+ query_hint: { type: String, minlength: 1, maxlength: 100 },
157
158
  query: { type: String, required: true },
158
- context_ids: { type: [String] },
159
+ instructions: { type: String },
160
+ contexts: { type: [Object] },
159
161
  status: {
160
162
  type: String,
161
163
  enum: ['active', 'inactive', 'archived'],
162
164
  default: 'active',
163
165
  required: true,
164
166
  },
165
- users_ids: { type: [String] },
167
+ users: { type: [Object] },
168
+ click_count: { type: Number },
166
169
  created_at: { type: Number },
167
170
  updated_at: { type: Number },
168
171
  },
@@ -190,4 +193,47 @@ export const FullFileTextSchema = new Schema(
190
193
  id: true,
191
194
  // encryptionType: 'csfle',
192
195
  }
196
+ );
197
+
198
+ export const ThreadSchema = new Schema(
199
+ {
200
+ organization_id: { type: String, required: true },
201
+ user_id: { type: String, required: true },
202
+ agent_id: { type: String, required: true },
203
+ title: { type: String, minlength: 1, maxlength: 200 },
204
+ description: { type: String },
205
+ query_id: { type: String },
206
+ messages_count: { type: Number, default: 0 },
207
+ created_at: { type: Number },
208
+ updated_at: { type: Number },
209
+ },
210
+ {
211
+ versionKey: false,
212
+ toJSON: { virtuals: true },
213
+ toObject: { virtuals: true },
214
+ timestamps: true,
215
+ id: true,
216
+ // encryptionType: 'csfle',
217
+ }
218
+ );
219
+
220
+ export const MessageSchema = new Schema(
221
+ {
222
+ thread_id: { type: String, required: true },
223
+ organization_id: { type: String, required: true },
224
+ user_id: { type: String },
225
+ agent_id: { type: String },
226
+ content: { type: String, required: true },
227
+ role: { type: String, enum: ['user', 'agent', 'system'], required: true },
228
+ created_at: { type: Number },
229
+ updated_at: { type: Number },
230
+ },
231
+ {
232
+ versionKey: false,
233
+ toJSON: { virtuals: true },
234
+ toObject: { virtuals: true },
235
+ timestamps: true,
236
+ id: true,
237
+ // encryptionType: 'csfle',
238
+ }
193
239
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatifai",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "SDK for interacting with the Chatifai API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/types.ts CHANGED
@@ -129,24 +129,54 @@ export const zodFullTextSchema = z.object({
129
129
  export const zodPreDefinedQuerySchema = z.object({
130
130
  _id: z.string().optional(),
131
131
  organization_id: z.string().optional(),
132
- title: z.string().min(1).max(100).optional(),
132
+ query_name: z.string().min(1).max(100).optional(),
133
+ query_hint: z.string().min(1).max(100).optional(), // A short hint to help users understand the purpose of the query
133
134
  query: z.string().min(1),
134
- context_ids: z.array(z.string()).optional(),
135
+ instructions: z.string().optional(),
136
+ contexts: z.array(zodContextSchema.partial()).optional(),
135
137
  status: z.enum(['active', 'inactive', 'archived']).default('active'),
136
- users_ids: z.array(z.string()).optional(),
138
+ users: z.array(zodUserSchema.partial()).optional(),
139
+ click_count: z.number().optional(),
137
140
  created_at: z.number().optional(),
138
141
  updated_at: z.number().optional(),
139
142
  });
140
143
 
144
+ // Zod schema for handling user queries
141
145
  export const zodQuerySchema = z.object({
142
146
  thread_id: z.string().optional(), // If there is not thread id provided, a new thread will be created
143
147
  context_ids: z.array(z.string()).optional(), // Run on all organization files unless specific file ids are provided
144
148
  organization_id: z.string(), // Will be used to fetch the agent, contexts, chunks, etc.
145
149
  user_id: z.string(),
146
150
  query: z.string().min(1),
151
+ pre_defined_query_id: z.string().optional(),
147
152
  timestamp: z.number(),
148
153
  })
149
154
 
155
+ export const zodThreadSchema = z.object({
156
+ _id: z.string().optional(),
157
+ organization_id: z.string(),
158
+ user_id: z.string(),
159
+ agent_id: z.string().optional(),
160
+ title: z.string().min(1).max(200).optional(),
161
+ description: z.string().optional(),
162
+ created_at: z.number().optional(),
163
+ updated_at: z.number().optional(),
164
+ query_id: z.string().optional(),
165
+ messages_count: z.number().optional(),
166
+ });
167
+
168
+ export const zodMessageSchema = z.object({
169
+ _id: z.string().optional(),
170
+ thread_id: z.string(),
171
+ organization_id: z.string(),
172
+ user_id: z.string().optional(), // If user_id is not provided, it means the message is from the agent
173
+ agent_id: z.string().optional(),
174
+ role: z.enum(['user', 'agent', 'system']),
175
+ content: z.string(),
176
+ created_at: z.number().optional(),
177
+ updated_at: z.number().optional(),
178
+ });
179
+
150
180
  export type EventAttributeType = {
151
181
  http_request: {
152
182
  client_ip?: string;
@@ -174,6 +204,8 @@ export type ModelType = (typeof modelsList)[number];
174
204
  export type UserRoleType = (typeof userRoles)[number];
175
205
  export type FullFileTextType = z.infer<typeof zodFullTextSchema>;
176
206
  export type QueryType = z.infer<typeof zodQuerySchema>;
207
+ export type ThreadType = z.infer<typeof zodThreadSchema>;
208
+ export type MessageType = z.infer<typeof zodMessageSchema>;
177
209
 
178
210
  export enum FileType {
179
211
  PDF = 'application/pdf',