@avakado.ai/schemas 1.0.0 → 1.1.1
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/README.md +43 -13
- package/package.json +1 -1
- package/src/index.js +1 -0
- package/src/models/Action.js +19 -0
- package/src/models/Agent.js +219 -0
- package/src/models/BillingLogs.js +131 -0
- package/src/models/CallSessions.js +34 -0
- package/src/models/Channels.js +268 -0
- package/src/models/Collection.js +189 -0
- package/src/models/Data.js +35 -0
- package/src/models/Demonstarations.js +23 -0
- package/src/models/Document.js +15 -0
- package/src/models/ExternalServiceProviders.js +104 -0
- package/src/models/InbuiltNodes.js +19 -0
- package/src/models/Integrations.js +36 -0
- package/src/models/Job.js +117 -0
- package/src/models/Leads.js +84 -0
- package/src/models/Log.js +32 -0
- package/src/models/Messages.js +46 -0
- package/src/models/Plans.js +37 -0
- package/src/models/Tickets.js +50 -0
- package/src/models/User.js +473 -0
- package/src/models/Workflow.js +44 -0
- package/src/models/WorkflowLogs.js +22 -0
- package/src/models/apiAuthenticator.js +197 -0
- package/src/models/index.js +24 -0
- package/src/models/market.js +66 -0
- package/src/models/notifications.js +15 -0
- package/src/runtime.js +4 -0
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
|
|
4
|
+
const Capability = new Schema({
|
|
5
|
+
key: String,
|
|
6
|
+
enabled: { type: Boolean, default: false },
|
|
7
|
+
label: String,
|
|
8
|
+
description: String,
|
|
9
|
+
}, { _id: false });
|
|
10
|
+
|
|
11
|
+
export const ChannelCapabilityDefaults = {
|
|
12
|
+
whatsapp: [
|
|
13
|
+
{
|
|
14
|
+
key: "text",
|
|
15
|
+
enabled: true,
|
|
16
|
+
label: "Text",
|
|
17
|
+
description: "Plain text messages. Supports basic formatting like bold, italic, and emojis.",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
key: "button",
|
|
21
|
+
enabled: true,
|
|
22
|
+
label: "Quick Reply Buttons",
|
|
23
|
+
description: "Up to 3 tappable reply buttons below a message. Best for simple yes/no or multi-choice responses."
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
key: "list",
|
|
27
|
+
enabled: false,
|
|
28
|
+
label: "List Menu",
|
|
29
|
+
description: "A scrollable menu with up to 10 rows grouped into sections. Best for support categories, product options, or multi-step flows."
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
key: "cta_url",
|
|
33
|
+
enabled: false,
|
|
34
|
+
label: "CTA URL Button",
|
|
35
|
+
description: "A button that opens a URL in the user's browser when tapped."
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "voice_call",
|
|
39
|
+
enabled: false,
|
|
40
|
+
label: "Voice Call Button",
|
|
41
|
+
description: "A button that opens the user's phone app to make a voice call when tapped."
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "location",
|
|
45
|
+
enabled: false,
|
|
46
|
+
label: "Location Request",
|
|
47
|
+
description: "A button that opens the user's phone app to send their location when tapped."
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: "image",
|
|
51
|
+
enabled: false,
|
|
52
|
+
label: "Image",
|
|
53
|
+
description: "Send images (JPEG/PNG) with an optional caption. Useful for product visuals, receipts, or guides."
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
key: "template",
|
|
57
|
+
enabled: false,
|
|
58
|
+
label: "Template",
|
|
59
|
+
description: "Pre-approved message templates required for first outbound messages or notifications outside the 24-hour window."
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
key: "document",
|
|
63
|
+
enabled: false,
|
|
64
|
+
label: "Document",
|
|
65
|
+
description: "Send files such as PDFs, invoices, or manuals. Supports most common document formats."
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "video",
|
|
69
|
+
enabled: false,
|
|
70
|
+
label: "Video",
|
|
71
|
+
description: "Send MP4 video files with an optional caption. Useful for tutorials or product demos."
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "audio",
|
|
75
|
+
enabled: false,
|
|
76
|
+
label: "Audio",
|
|
77
|
+
description: "Send voice notes or audio clips. Useful for spoken instructions or announcements."
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "sticker",
|
|
81
|
+
enabled: false,
|
|
82
|
+
label: "Sticker",
|
|
83
|
+
description: "Send WhatsApp-compatible WebP stickers. Mostly used for casual or expressive interactions."
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
telegram: [
|
|
87
|
+
{
|
|
88
|
+
key: "text",
|
|
89
|
+
enabled: true,
|
|
90
|
+
label: "Text",
|
|
91
|
+
description: "Plain or Markdown-formatted text messages. Supports bold, italic, code blocks, and links."
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "interactive_button",
|
|
95
|
+
enabled: true,
|
|
96
|
+
label: "Inline Buttons",
|
|
97
|
+
description: "Inline keyboard buttons attached to a message. Each button carries a callback_data payload sent back on tap."
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
key: "image",
|
|
101
|
+
enabled: false,
|
|
102
|
+
label: "Image",
|
|
103
|
+
description: "Send photos with an optional caption. Supports JPEG and PNG formats."
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
key: "video",
|
|
107
|
+
enabled: false,
|
|
108
|
+
label: "Video",
|
|
109
|
+
description: "Send MP4 video files with an optional caption."
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: "audio",
|
|
113
|
+
enabled: false,
|
|
114
|
+
label: "Audio",
|
|
115
|
+
description: "Send audio files or voice messages. Displayed as a playable audio player in chat."
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "document",
|
|
119
|
+
enabled: false,
|
|
120
|
+
label: "Document",
|
|
121
|
+
description: "Send any file type as a document. Useful for sharing PDFs, spreadsheets, or archives."
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "sticker",
|
|
125
|
+
enabled: false,
|
|
126
|
+
label: "Sticker",
|
|
127
|
+
description: "Send Telegram-compatible WebP or TGS animated stickers."
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
sms: [
|
|
131
|
+
{
|
|
132
|
+
key: "text",
|
|
133
|
+
enabled: true,
|
|
134
|
+
label: "Text",
|
|
135
|
+
description: "Plain text SMS. Maximum 160 characters per segment. No formatting, links, or media supported natively."
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
email: [
|
|
139
|
+
{
|
|
140
|
+
key: "text",
|
|
141
|
+
enabled: true,
|
|
142
|
+
label: "Text / HTML",
|
|
143
|
+
description: "Plain text or HTML-formatted email body. Supports rich layout, headings, and styled content."
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
key: "image",
|
|
147
|
+
enabled: false,
|
|
148
|
+
label: "Inline Image",
|
|
149
|
+
description: "Embed images directly in the email body or include them as attachments."
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
key: "document",
|
|
153
|
+
enabled: false,
|
|
154
|
+
label: "Attachment",
|
|
155
|
+
description: "Attach files such as PDFs, invoices, or reports to the email."
|
|
156
|
+
},
|
|
157
|
+
],
|
|
158
|
+
web: [
|
|
159
|
+
{
|
|
160
|
+
key: "text",
|
|
161
|
+
enabled: true,
|
|
162
|
+
label: "Text",
|
|
163
|
+
description: "Plain text chat bubble rendered in the web widget. Supports basic markdown."
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
key: "interactive_button",
|
|
167
|
+
enabled: true,
|
|
168
|
+
label: "Quick Reply Buttons",
|
|
169
|
+
description: "Clickable option buttons rendered below a message. Ideal for guided flows and FAQs."
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
key: "interactive_list",
|
|
173
|
+
enabled: false,
|
|
174
|
+
label: "List Menu",
|
|
175
|
+
description: "A dropdown or scrollable list of options. Best for longer option sets like categories or topics."
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
key: "image",
|
|
179
|
+
enabled: false,
|
|
180
|
+
label: "Image",
|
|
181
|
+
description: "Display images inside the chat widget with an optional caption."
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "card",
|
|
185
|
+
enabled: false,
|
|
186
|
+
label: "Card",
|
|
187
|
+
description: "A rich card with a title, subtitle, image, and action buttons. Useful for product listings or recommendations."
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
instagram: [
|
|
191
|
+
{
|
|
192
|
+
key: "text",
|
|
193
|
+
enabled: true,
|
|
194
|
+
label: "Text",
|
|
195
|
+
description: "Plain text DM. Supports emojis but no rich formatting."
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "interactive_button",
|
|
199
|
+
enabled: true,
|
|
200
|
+
label: "Quick Reply Buttons",
|
|
201
|
+
description: "Predefined reply chips shown below a message. User taps one to send a reply. Limited to Instagram's supported button types."
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
key: "image",
|
|
205
|
+
enabled: false,
|
|
206
|
+
label: "Image",
|
|
207
|
+
description: "Send images directly in the DM. Useful for product previews or visual confirmations."
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
key: "sticker",
|
|
211
|
+
enabled: false,
|
|
212
|
+
label: "Sticker / Reaction",
|
|
213
|
+
description: "Send Instagram stickers or emoji reactions within the DM thread."
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
phone: [
|
|
217
|
+
{
|
|
218
|
+
key: "voice",
|
|
219
|
+
enabled: true,
|
|
220
|
+
label: "Voice / TTS",
|
|
221
|
+
description: "Text-to-speech voice response read aloud to the caller. Supports plain text or SSML for tone and pacing control."
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const ChannelBaseSchema = new Schema(
|
|
227
|
+
{
|
|
228
|
+
name: { type: String, required: true, trim: true },
|
|
229
|
+
business: { type: Schema.Types.ObjectId, ref: 'Businesses', required: true },
|
|
230
|
+
provider: { type: Schema.Types.ObjectId, ref: 'Providers' },
|
|
231
|
+
apiAuthenticator: { type: Schema.Types.ObjectId, ref: 'ApiAuthenticators' },
|
|
232
|
+
type: { type: String, enum: ["whatsapp", "telegram", "website", "web", "phone", "instagram", "sms", "email"] },
|
|
233
|
+
runtime: { type: String, enum: ['TURN_BASED', 'REALTIME'], default: 'TURN_BASED' },
|
|
234
|
+
config: { type: Schema.Types.Mixed, default: {} },
|
|
235
|
+
externalId: String,
|
|
236
|
+
status: { type: String, default: 'disabled' }, // enabled | disabled | error
|
|
237
|
+
webhookUrl: String,
|
|
238
|
+
systemPrompt: String,
|
|
239
|
+
isPublic: { type: Boolean, default: false },
|
|
240
|
+
UIElements: Schema.Types.Mixed,
|
|
241
|
+
settings: {
|
|
242
|
+
// defaultTemplate for leades created using this channel
|
|
243
|
+
// snoozTime: Date,
|
|
244
|
+
// Notification:Schema.Types.Mixed,
|
|
245
|
+
// iceBreaker: template
|
|
246
|
+
responseFormatCapabilities: [Capability],
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
},
|
|
250
|
+
{ timestamps: true }
|
|
251
|
+
);
|
|
252
|
+
ChannelBaseSchema.methods.updateStatus = function (status) {
|
|
253
|
+
this.status = status;
|
|
254
|
+
return this.save();
|
|
255
|
+
};
|
|
256
|
+
ChannelBaseSchema.pre("save", function (next) {
|
|
257
|
+
if (this.isNew && !this.settings?.responseFormatCapabilities?.length) {
|
|
258
|
+
const defaults = ChannelCapabilityDefaults[this.type] || [
|
|
259
|
+
{ key: "text", enabled: true, label: "Text", description: "Plain text messages. Supports basic formatting like bold, italic, and emojis." } // fallback
|
|
260
|
+
];
|
|
261
|
+
this.settings = {
|
|
262
|
+
...this.settings,
|
|
263
|
+
responseFormatCapabilities: defaults
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
next();
|
|
267
|
+
});
|
|
268
|
+
export const Channel = defineModel('Channel', ChannelBaseSchema, 'Channel');
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
const metaData = new Schema({
|
|
4
|
+
webcrawler: {
|
|
5
|
+
options: Object,
|
|
6
|
+
jobId: String,
|
|
7
|
+
lastUpdate: Schema.Types.Mixed,
|
|
8
|
+
urls: [String]
|
|
9
|
+
},
|
|
10
|
+
chunkingDetails: {
|
|
11
|
+
strategy: { type: String, enum: ["recursiveStructural", "recursiveSemantic"], default: 'recursiveStructural' },
|
|
12
|
+
tunables: {
|
|
13
|
+
MIN_TOKENS: { type: Number, default: 30 },
|
|
14
|
+
MAX_TOKENS: { type: Number, default: 512 },
|
|
15
|
+
OVERLAP_TOKENS: { type: Number, default: 50 },
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
parserDetails: {
|
|
19
|
+
tier: { type: String, enum: ['fast', 'cost_effective', 'agentic', "agentic_plus"], default: 'cost_effective' },
|
|
20
|
+
expand: { type: [String], enum: ['text', 'items', "markdown", 'metadata', 'images_content_metadata', 'xlsx_content_metadata', 'output_pdf_content_metadata'], default: ['items', "markdown", 'metadata', 'images_content_metadata'] },
|
|
21
|
+
version: { type: String, enum: ['latest'], default: 'latest' },
|
|
22
|
+
source_url: String,
|
|
23
|
+
advancedOptions: {
|
|
24
|
+
page_ranges: {
|
|
25
|
+
target_pages: String,
|
|
26
|
+
max_pages: Number,
|
|
27
|
+
},
|
|
28
|
+
disable_cache: Boolean,
|
|
29
|
+
agentic_options: {
|
|
30
|
+
custom_prompt: String
|
|
31
|
+
},
|
|
32
|
+
output_options: {
|
|
33
|
+
extract_printed_page_number: Boolean,
|
|
34
|
+
images_to_save: { type: [String], enum: ["screenshot", "embedded", "layout"] },
|
|
35
|
+
markdown: {
|
|
36
|
+
annotate_links: Boolean,
|
|
37
|
+
inline_images: Boolean,
|
|
38
|
+
tables: {
|
|
39
|
+
compact_markdown_tables: Boolean,
|
|
40
|
+
markdown_table_multiline_separator: String,
|
|
41
|
+
merge_continued_tables: Boolean,
|
|
42
|
+
output_tables_as_markdown: Boolean,
|
|
43
|
+
},
|
|
44
|
+
spatial_text: {
|
|
45
|
+
do_not_unroll_columns: Boolean,
|
|
46
|
+
preserve_layout_alignment_across_pages: Boolean,
|
|
47
|
+
preserve_very_small_text: Boolean,
|
|
48
|
+
},
|
|
49
|
+
tables_as_spreadsheet: {
|
|
50
|
+
enable: Boolean,
|
|
51
|
+
guess_sheet_name: Boolean,
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
input_options: {
|
|
56
|
+
html: {
|
|
57
|
+
make_all_elements_visible: Boolean,
|
|
58
|
+
remove_fixed_elements: Boolean,
|
|
59
|
+
remove_navigation_elements: Boolean,
|
|
60
|
+
},
|
|
61
|
+
presentation: {
|
|
62
|
+
out_of_bounds_content: Boolean,
|
|
63
|
+
skip_embedded_data: Boolean,
|
|
64
|
+
},
|
|
65
|
+
spreadsheet: {
|
|
66
|
+
detect_sub_tables_in_sheets: Boolean,
|
|
67
|
+
force_formula_computation_in_sheets: Boolean,
|
|
68
|
+
include_hidden_sheets: Boolean,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
processing_options: {
|
|
72
|
+
aggressive_table_extraction: Boolean,
|
|
73
|
+
cost_optimizer: {
|
|
74
|
+
enable: Boolean,
|
|
75
|
+
},
|
|
76
|
+
disable_heuristics: Boolean,
|
|
77
|
+
ignore: {
|
|
78
|
+
ignore_diagonal_text: Boolean,
|
|
79
|
+
ignore_text_in_image: Boolean,
|
|
80
|
+
ignore_hidden_text: Boolean,
|
|
81
|
+
},
|
|
82
|
+
ocr_parameters: {
|
|
83
|
+
languages: { type: [String], enum: ["en", "fr", "de", "es", "it", "pt", "ru", "zh"] },
|
|
84
|
+
},
|
|
85
|
+
specialized_chart_parsing: { type: String, enum: ["agentic_plus", "agentic", "efficient"] }
|
|
86
|
+
},
|
|
87
|
+
// webhook_configurations: {
|
|
88
|
+
// webhook_events: { type: [String], enum: ["parsing_completed", "parsing_failed", "parsing_progress"] },
|
|
89
|
+
// webhook_headers: { type: Object },
|
|
90
|
+
// webhook_url: { type: String },
|
|
91
|
+
// },
|
|
92
|
+
processing_control: {
|
|
93
|
+
job_failure_conditions: {
|
|
94
|
+
allowed_page_failure_ratio: Number,
|
|
95
|
+
fail_on_buggy_font: Boolean,
|
|
96
|
+
fail_on_image_extraction_error: Boolean,
|
|
97
|
+
fail_on_image_ocr_error: Boolean,
|
|
98
|
+
fail_on_markdown_reconstruction_error: Boolean,
|
|
99
|
+
},
|
|
100
|
+
timeouts: {
|
|
101
|
+
base_in_seconds: Number,
|
|
102
|
+
extra_time_per_page_in_seconds: Number,
|
|
103
|
+
},
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
jobId: String,
|
|
107
|
+
lastUpdate: Schema.Types.Mixed,
|
|
108
|
+
},
|
|
109
|
+
progressStages: [{
|
|
110
|
+
name: { type: String, enum: ['webcrawler', 'embed and upsert', 'Chunking', 'Parsing'] },
|
|
111
|
+
accomplished: { type: Boolean, default: false },
|
|
112
|
+
status: { type: String, default: "PENDING", enum: ["PENDING", "RUNNING", "COMPLETED", "FAILED", "CANCELLED"] },
|
|
113
|
+
error: { type: String },
|
|
114
|
+
startedAt: { type: Date, default: Date.now },
|
|
115
|
+
completedAt: { type: Date },
|
|
116
|
+
failedAt: { type: Date },
|
|
117
|
+
moreInfo: { type: Schema.Types.Mixed }
|
|
118
|
+
}],
|
|
119
|
+
}, { _id: false });
|
|
120
|
+
const CollectionSchema = new Schema({
|
|
121
|
+
name: { type: String, required: true, },
|
|
122
|
+
source: { type: String, enum: ['website', 'youtube', 'file', 'text'] },
|
|
123
|
+
status: { type: String, default: "loading", enum: ["active", "loading", "failed", "cancelled"] },
|
|
124
|
+
error: { type: String },
|
|
125
|
+
metaData: metaData,
|
|
126
|
+
description: { type: String },
|
|
127
|
+
tags: [String],
|
|
128
|
+
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
129
|
+
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' },
|
|
130
|
+
isPublic: { type: Boolean, default: false },
|
|
131
|
+
isFeatured: { type: Boolean, default: false }
|
|
132
|
+
}, {
|
|
133
|
+
timestamps: true
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
CollectionSchema.statics.updateStage = async function (collectionId, stageName, updates) {
|
|
137
|
+
return this.findOneAndUpdate({ _id: collectionId, 'metaData.progressStages.name': stageName }, { $set: updates }, { new: true });
|
|
138
|
+
};
|
|
139
|
+
CollectionSchema.statics.startStage = function (collectionId, stageName, moreInfo) {
|
|
140
|
+
return this.updateStage(collectionId, stageName, {
|
|
141
|
+
'metaData.progressStages.$.status': 'RUNNING',
|
|
142
|
+
'metaData.progressStages.$.startedAt': new Date(),
|
|
143
|
+
'metaData.progressStages.$.error': null,
|
|
144
|
+
'metaData.progressStages.$.moreInfo': moreInfo
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
CollectionSchema.statics.cancelStage = function (collectionId, stageName, moreInfo) {
|
|
148
|
+
return this.updateStage(collectionId, stageName, {
|
|
149
|
+
'metaData.progressStages.$.status': 'CANCELLED',
|
|
150
|
+
'metaData.progressStages.$.completedAt': new Date(),
|
|
151
|
+
'metaData.progressStages.$.error': 'Cancelled by user',
|
|
152
|
+
'metaData.progressStages.$.moreInfo': moreInfo
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
CollectionSchema.statics.pendingStage = function (collectionId, stageName, moreInfo) {
|
|
156
|
+
return this.updateStage(collectionId, stageName, {
|
|
157
|
+
'metaData.progressStages.$.status': 'PENDING',
|
|
158
|
+
'metaData.progressStages.$.startedAt': null,
|
|
159
|
+
'metaData.progressStages.$.completedAt': null,
|
|
160
|
+
'metaData.progressStages.$.failedAt': null,
|
|
161
|
+
'metaData.progressStages.$.error': null,
|
|
162
|
+
'metaData.progressStages.$.moreInfo': moreInfo
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
CollectionSchema.statics.completeStage = function (collectionId, stageName, moreInfo) {
|
|
166
|
+
return this.updateStage(collectionId, stageName, {
|
|
167
|
+
'metaData.progressStages.$.accomplished': true,
|
|
168
|
+
'metaData.progressStages.$.status': 'COMPLETED',
|
|
169
|
+
'metaData.progressStages.$.completedAt': new Date(),
|
|
170
|
+
'metaData.progressStages.$.error': null,
|
|
171
|
+
'metaData.progressStages.$.moreInfo': moreInfo
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
CollectionSchema.statics.failStage = function (collectionId, stageName, error, moreInfo) {
|
|
175
|
+
return this.updateStage(collectionId, stageName, {
|
|
176
|
+
'metaData.progressStages.$.accomplished': false,
|
|
177
|
+
'metaData.progressStages.$.status': 'FAILED',
|
|
178
|
+
'metaData.progressStages.$.failedAt': new Date(),
|
|
179
|
+
'metaData.progressStages.$.error': error?.message || error,
|
|
180
|
+
'metaData.progressStages.$.moreInfo': moreInfo
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
CollectionSchema.statics.updateMetadata = async function (collectionId, updates) {
|
|
184
|
+
return await this.findOneAndUpdate({ _id: collectionId, 'metaData': { $exists: true } }, { $set: updates }, { new: true });
|
|
185
|
+
};
|
|
186
|
+
CollectionSchema.statics.updateStatus = async function (collectionId, status, error) {
|
|
187
|
+
return await this.findOneAndUpdate({ _id: collectionId }, { $set: { status, error: error?.message || error } }, { new: true });
|
|
188
|
+
};
|
|
189
|
+
export const Collection = defineModel('Collection', CollectionSchema, "Collection");
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
|
|
4
|
+
const DataSchema = new Schema({
|
|
5
|
+
collection: { type: Schema.Types.ObjectId, ref: "Collection" },
|
|
6
|
+
content: String,
|
|
7
|
+
chunkNumber: Number,
|
|
8
|
+
summary: String,
|
|
9
|
+
embeddingVector: [Number],
|
|
10
|
+
newTopics: [String],
|
|
11
|
+
metadata: {
|
|
12
|
+
tokensUsed: Number,
|
|
13
|
+
chunkSize: Number, // length of content
|
|
14
|
+
createdAt: { type: Date, default: Date.now }, // time of creation
|
|
15
|
+
url: String,
|
|
16
|
+
tokenUsage: {
|
|
17
|
+
embeddingTokens: Number,
|
|
18
|
+
embeddingModel: String,
|
|
19
|
+
summarizationInputTokens: Number,
|
|
20
|
+
summarizationOutputTokens: Number,
|
|
21
|
+
summarizationTotalTokens: Number,
|
|
22
|
+
summarizationModel: String
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, {
|
|
26
|
+
timestamps: true,
|
|
27
|
+
suppressReservedKeysWarning: true,
|
|
28
|
+
});
|
|
29
|
+
DataSchema.pre('save', function (next) {
|
|
30
|
+
if (this.content) {
|
|
31
|
+
this.metadata.chunkSize = this.content.length;
|
|
32
|
+
}
|
|
33
|
+
next();
|
|
34
|
+
});
|
|
35
|
+
export const Data = defineModel('Data', DataSchema, "Data");
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
|
|
4
|
+
const DemonstrationSchema = new Schema({
|
|
5
|
+
lead: {
|
|
6
|
+
name: String,
|
|
7
|
+
email: String,
|
|
8
|
+
phone: String,
|
|
9
|
+
department: String,
|
|
10
|
+
source: String,
|
|
11
|
+
},
|
|
12
|
+
organization: {
|
|
13
|
+
id: String,
|
|
14
|
+
name: String,
|
|
15
|
+
industry: String,
|
|
16
|
+
},
|
|
17
|
+
transcripts: Schema.Types.Mixed,
|
|
18
|
+
miscellaneous: Schema.Types.Mixed,
|
|
19
|
+
kind: String,
|
|
20
|
+
demoEndedAt: Date,
|
|
21
|
+
}, { timestamps: true });
|
|
22
|
+
|
|
23
|
+
export const DemonstrationModel = defineModel('Demonstrations', DemonstrationSchema, "Demonstrations");
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const documentSchema = Schema({
|
|
6
|
+
name: String,
|
|
7
|
+
data: { FileName: String, resource_id: String, mimetype: String, originalname: String, fileIdentifier: String, preview_url: String, download_url: String },
|
|
8
|
+
contentType: String,
|
|
9
|
+
user: { type: Schema.Types.ObjectId, ref: "Users" },
|
|
10
|
+
viewers: [{ type: Schema.Types.ObjectId, ref: "Users" }],
|
|
11
|
+
type: String
|
|
12
|
+
}, { timestamps: true });
|
|
13
|
+
const Document = defineModel('document', documentSchema);
|
|
14
|
+
export { Document };
|
|
15
|
+
export default Document
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
const ApiSchema = new Schema({
|
|
4
|
+
provider: { type: Schema.Types.ObjectId, ref: 'Providers' },
|
|
5
|
+
title: String, // <Provider>.<Resource>.<Action> excel.table.list excel.range.update
|
|
6
|
+
description: String, // description of the api in human readable format
|
|
7
|
+
version: String, // version of the api
|
|
8
|
+
schemas: {
|
|
9
|
+
input: Schema.Types.Mixed, // JSON schema for the input
|
|
10
|
+
config: Schema.Types.Mixed, // JSON schema for the config
|
|
11
|
+
output: Schema.Types.Mixed, // JSON schema for the output
|
|
12
|
+
error: Schema.Types.Mixed, // JSON schema for the error
|
|
13
|
+
auth: { type: String, enum: ['oauth2', 'apiKey', 'basic', 'bearer', 'jwt', 'hmac', 'customHeader', 'mtls', 'cookie', 'none'] } // auth type for now only oauth2 is supported
|
|
14
|
+
},
|
|
15
|
+
requestTemplate: {
|
|
16
|
+
method: String, // GET, POST, PUT, DELETE, PATCH, etc.
|
|
17
|
+
url: {
|
|
18
|
+
base: String, // base url of the api
|
|
19
|
+
path: String, // path of the api
|
|
20
|
+
params: Schema.Types.Mixed // query params of the api
|
|
21
|
+
},
|
|
22
|
+
headers: Schema.Types.Mixed, // headers of the api
|
|
23
|
+
body: Schema.Types.Mixed // body of the api
|
|
24
|
+
},
|
|
25
|
+
requiredScopes: [String], // scopes required for the api
|
|
26
|
+
metadata: {
|
|
27
|
+
category: String,
|
|
28
|
+
feature: String
|
|
29
|
+
}
|
|
30
|
+
}, { timestamps: true });
|
|
31
|
+
|
|
32
|
+
ApiSchema.methods.evaluateExpressions = function (context = { input, config, auth }) {
|
|
33
|
+
const EXPR_REGEX = /\{\{\{([\s\S]*?)\}\}\}|\{\{([\s\S]*?)\}\}/g;
|
|
34
|
+
function evalExpression(expr) {
|
|
35
|
+
try {
|
|
36
|
+
const fn = new Function(
|
|
37
|
+
"input",
|
|
38
|
+
"config",
|
|
39
|
+
"auth",
|
|
40
|
+
"context",
|
|
41
|
+
`return (${expr})`
|
|
42
|
+
);
|
|
43
|
+
return fn(context.input, context.config, context.auth, context);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error("Expression error:", expr, err);
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function process(value) {
|
|
51
|
+
if (typeof value === "string") {
|
|
52
|
+
const matches = [...value.matchAll(EXPR_REGEX)];
|
|
53
|
+
//entire string is a single expression → return real type
|
|
54
|
+
if (
|
|
55
|
+
matches.length === 1 &&
|
|
56
|
+
matches[0][0].length === value.length
|
|
57
|
+
) {
|
|
58
|
+
const expr = matches[0][1] || matches[0][2];
|
|
59
|
+
return evalExpression(expr);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
//string with mixed content → interpolate
|
|
63
|
+
return value.replace(EXPR_REGEX, (_, expr1, expr2) => {
|
|
64
|
+
const result = evalExpression(expr1 || expr2);
|
|
65
|
+
|
|
66
|
+
if (result === undefined || result === null) return "";
|
|
67
|
+
if (typeof result === "object") return JSON.stringify(result);
|
|
68
|
+
|
|
69
|
+
return String(result);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//Array
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return value.map(process);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Object
|
|
79
|
+
if (typeof value === "object" && value !== null) {
|
|
80
|
+
const result = {};
|
|
81
|
+
for (const key in value) {
|
|
82
|
+
result[key] = process(value[key]);
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
// Pimitive (number, boolean, etc.)
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
return process(this.requestTemplate);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// { method: String, url: { base: String, path: String, params: object }, headers: object, body: object }
|
|
93
|
+
const ProvidersSchema = new Schema({
|
|
94
|
+
name: String,
|
|
95
|
+
description: String,
|
|
96
|
+
icon: String, // url
|
|
97
|
+
color: String,
|
|
98
|
+
basicScopes: [String],
|
|
99
|
+
apiFilters: Schema.Types.Mixed,
|
|
100
|
+
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' }
|
|
101
|
+
}, { timestamps: true });
|
|
102
|
+
|
|
103
|
+
export const Api = defineModel('Api', ApiSchema, 'Api');
|
|
104
|
+
export const Providers = defineModel('Providers', ProvidersSchema, 'Providers');
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Schema } from "mongoose";
|
|
2
|
+
import { defineModel } from "../runtime.js";
|
|
3
|
+
const NodeSchema = new Schema(
|
|
4
|
+
{
|
|
5
|
+
type: { type: String, required: true, enum: ['trigger', 'task', 'conditional'] },
|
|
6
|
+
core: {
|
|
7
|
+
inputMapper: String,
|
|
8
|
+
inputSchema: Schema.Types.Mixed,
|
|
9
|
+
outputSchema: Schema.Types.Mixed,
|
|
10
|
+
configSchema: Schema.Types.Mixed,
|
|
11
|
+
handlerFunction: { type: String, required: true },
|
|
12
|
+
errorFunction: { type: String }
|
|
13
|
+
},
|
|
14
|
+
meta: { label: String }
|
|
15
|
+
},
|
|
16
|
+
{ timestamps: true }
|
|
17
|
+
);
|
|
18
|
+
export const NodeModel = defineModel('Node', NodeSchema, 'Nodes');
|
|
19
|
+
export const Node = NodeModel;
|