@avakado.ai/schemas 1.1.6 → 1.1.9
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/package.json +2 -2
- package/src/models/Conversations.js +10 -12
- package/src/models/TriggersTemplate.js +1 -2
- package/src/models/index.js +2 -5
- package/src/models/Integrations.js +0 -36
- package/src/models/Job.js +0 -117
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avakado.ai/schemas",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Canonical Mongo schemas, models, enums and index declarations shared by the Avakado services.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"mongoose": "^8.19.2"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"test": "node
|
|
29
|
+
"test": "node ../../scripts/check-imports.mjs ."
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { Schema } from "mongoose";
|
|
2
2
|
import { defineModel, requireDep } from "../runtime.js";
|
|
3
3
|
import { CONVERSATION_PRIORITY, CONVERSATION_STATUS } from "../enums/index.js";
|
|
4
|
-
import { Trigger } from "./Triggers.js";
|
|
5
|
-
|
|
6
4
|
const ConversationSchema = new Schema({
|
|
7
5
|
agent: { type: Schema.Types.ObjectId, ref: 'Agent' }, // the AI agent
|
|
8
6
|
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
@@ -79,16 +77,16 @@ ConversationSchema.methods.updateStatus = async function (status) {
|
|
|
79
77
|
});
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
if (businessId) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
80
|
+
// if (businessId) {
|
|
81
|
+
// const trigger = await Trigger.findOne({ business: businessId, name: "conversationStatusUpdated", type: status });
|
|
82
|
+
// for (const workflow of trigger?.workflows ?? []) {
|
|
83
|
+
// await sendKafkaMessage({
|
|
84
|
+
// topic: 'workflow-execution-trigger',
|
|
85
|
+
// message: { key: workflow.toString(), value: JSON.stringify({ conversationId }) },
|
|
86
|
+
// acks: -1
|
|
87
|
+
// });
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
92
90
|
|
|
93
91
|
return saved;
|
|
94
92
|
};
|
|
@@ -2,12 +2,11 @@ import { Schema } from "mongoose";
|
|
|
2
2
|
import { defineModel } from "../runtime.js";
|
|
3
3
|
|
|
4
4
|
const TriggerTemplateSchema = new Schema({
|
|
5
|
-
name: { type: String, required: true, unique: true }, // convers
|
|
5
|
+
name: { type: String, required: true, unique: true, index: true }, // convers
|
|
6
6
|
description: String,
|
|
7
7
|
type: String,
|
|
8
8
|
payload: Schema.Types.Mixed,
|
|
9
9
|
}, {
|
|
10
10
|
timestamps: true,
|
|
11
11
|
});
|
|
12
|
-
TriggerTemplateSchema.index({ name: 1 });
|
|
13
12
|
export const TriggerTemplate = defineModel("TriggerTemplate", TriggerTemplateSchema, "TriggerTemplate");
|
package/src/models/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { Subscription, SubscriptionSchema } from "./Subscriptions.js";
|
|
|
4
4
|
export { UsageLog, UsageLogSchema } from "./UsageLogs.js";
|
|
5
5
|
export { Conversation, ConversationSchema } from "./Conversations.js";
|
|
6
6
|
export { Campaign, CampaignSchema, Task, TaskSchema } from "./Campaign.js";
|
|
7
|
-
export {
|
|
7
|
+
export { TriggerTemplate } from "./TriggersTemplate.js";
|
|
8
8
|
export { User, ScopesEnum, RoleScopes } from "./User.js";
|
|
9
9
|
export { AgentModel } from "./Agent.js";
|
|
10
10
|
export { Channel, ChannelCapabilityDefaults } from "./Channels.js";
|
|
@@ -20,13 +20,10 @@ export { ApiAuthenticators, ApiAuthenticationSchema } from "./apiAuthenticator.j
|
|
|
20
20
|
export { DemonstrationModel } from "./Demonstarations.js";
|
|
21
21
|
export { Action } from "./Action.js";
|
|
22
22
|
export { Collection } from "./Collection.js";
|
|
23
|
-
export { Node, NodeModel } from "./InbuiltNodes.js";
|
|
24
|
-
export { Integration } from "./Integrations.js";
|
|
25
|
-
export { Job } from "./Job.js";
|
|
26
23
|
export { Notification } from "./notifications.js";
|
|
27
24
|
export { Ticket } from "./Tickets.js";
|
|
28
25
|
export { Document } from "./Document.js";
|
|
29
26
|
export { Data } from "./Data.js";
|
|
30
|
-
export { Workflow
|
|
27
|
+
export { Workflow } from "./Workflow.js";
|
|
31
28
|
export { WorkflowLogs } from "./WorkflowLogs.js";
|
|
32
29
|
export { OAuthClient, OAuthAuthorizationCode, OAuthRefreshToken, OAuthRevokedJti } from "./OAuth.js";
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
2
|
-
import { defineModel } from "../runtime.js";
|
|
3
|
-
|
|
4
|
-
const IntegrationSchema = new Schema({
|
|
5
|
-
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
6
|
-
metaData: {
|
|
7
|
-
name: String,
|
|
8
|
-
description: String,
|
|
9
|
-
icon: String,
|
|
10
|
-
color: String,
|
|
11
|
-
purpose: Schema.Types.Mixed,
|
|
12
|
-
type: { type: String, enum: ['zoho', 'twilio', 'exotel','tataTele','whatsapp'], required: true },
|
|
13
|
-
},
|
|
14
|
-
secrets: {
|
|
15
|
-
tokenType: String,
|
|
16
|
-
accessToken: String,
|
|
17
|
-
refreshToken: String,
|
|
18
|
-
apiKey: String,
|
|
19
|
-
apiToken: String,
|
|
20
|
-
},
|
|
21
|
-
config: {
|
|
22
|
-
AccountSid: String,
|
|
23
|
-
state: String,
|
|
24
|
-
apiDomainUrl: String,
|
|
25
|
-
domain: String,
|
|
26
|
-
scope: String,
|
|
27
|
-
expiresAt: Date,
|
|
28
|
-
region:String
|
|
29
|
-
},
|
|
30
|
-
accountDetails: Schema.Types.Mixed,
|
|
31
|
-
isActive: { type: Boolean, default: true },
|
|
32
|
-
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' },
|
|
33
|
-
}, {
|
|
34
|
-
timestamps: true
|
|
35
|
-
});
|
|
36
|
-
export const Integration = defineModel('Integration', IntegrationSchema, "Integration");
|
package/src/models/Job.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { Schema } from "mongoose";
|
|
2
|
-
import { defineModel } from "../runtime.js";
|
|
3
|
-
const jobStatusEnum = ["scheduled", "active", "completed", "failed", "canceled", "delayed", "waiting", "stalled"];
|
|
4
|
-
const backoff = new Schema({
|
|
5
|
-
type: { type: String, enum: ["exponential", "fixed"], required: true },
|
|
6
|
-
delay_ms: { type: Number, required: true },
|
|
7
|
-
attempts: { max: Number, made: Number, reason: String },
|
|
8
|
-
}, { _id: false })
|
|
9
|
-
|
|
10
|
-
const logEntry = new Schema({
|
|
11
|
-
level: { type: String, enum: ["info", "warn", "error", "debug"], required: true },
|
|
12
|
-
message: String,
|
|
13
|
-
timestamp: { type: Date, default: Date.now },
|
|
14
|
-
data: Schema.Types.Mixed
|
|
15
|
-
}, { _id: false });
|
|
16
|
-
/* ───────────────────────────── Base Job ───────────────────────────── */
|
|
17
|
-
const JobSchema = new Schema({
|
|
18
|
-
name: String,
|
|
19
|
-
campaign: { type: Schema.Types.ObjectId, ref: "Campaign" },
|
|
20
|
-
description: String,
|
|
21
|
-
status: { type: String, enum: jobStatusEnum, default: 'waiting' },
|
|
22
|
-
priority: Number, // 1 (highest) .. 10 (lowest)
|
|
23
|
-
schedule: {
|
|
24
|
-
type: { type: String, enum: ["once", "cron"], default: "once" },
|
|
25
|
-
run_at: Date, // for one-off
|
|
26
|
-
cron: String, // for recurring
|
|
27
|
-
timezone: String,
|
|
28
|
-
backoff: { type: backoff, default: undefined },
|
|
29
|
-
cancel_requested: { type: Boolean, default: false },
|
|
30
|
-
},
|
|
31
|
-
jobType: { type: String, enum: ["outboundCall"], default: "outboundCall" },
|
|
32
|
-
result_ref: Schema.Types.Mixed,
|
|
33
|
-
error_ref: Schema.Types.Mixed,
|
|
34
|
-
log: [logEntry],
|
|
35
|
-
tags: [String],
|
|
36
|
-
createdBy: { type: Schema.Types.ObjectId, ref: 'Users' },
|
|
37
|
-
business: { type: Schema.Types.ObjectId, ref: 'Businesses' },
|
|
38
|
-
}, {
|
|
39
|
-
discriminatorKey: 'jobType', timestamps: true, index: [
|
|
40
|
-
{ status: 1, 'schedule.run_at': 1 },
|
|
41
|
-
{ business: 1, status: 1 },
|
|
42
|
-
{ 'schedule.type': 1, 'schedule.run_at': 1 }
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
// Pre-save middleware for validation
|
|
46
|
-
JobSchema.pre('save', function (next) {
|
|
47
|
-
// Validate schedule based on type
|
|
48
|
-
if (this.schedule.type === 'once' && !this.schedule.run_at) {
|
|
49
|
-
return next(new Error('run_at is required for one-time jobs'));
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (this.schedule.type === 'cron' && !this.schedule.cron) {
|
|
53
|
-
return next(new Error('cron expression is required for recurring jobs'));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Validate priority
|
|
57
|
-
if (this.priority < 1 || this.priority > 10) {
|
|
58
|
-
return next(new Error('Priority must be between 1 and 10'));
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
next();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// Instance methods
|
|
65
|
-
JobSchema.methods.addLog = function (level, message, data = {}) {
|
|
66
|
-
this.log.push({
|
|
67
|
-
level,
|
|
68
|
-
message,
|
|
69
|
-
data,
|
|
70
|
-
timestamp: new Date()
|
|
71
|
-
});
|
|
72
|
-
return this.save();
|
|
73
|
-
};
|
|
74
|
-
JobSchema.methods.markAsStarted = function () {
|
|
75
|
-
this.status = 'active';
|
|
76
|
-
this.lastExecutedAt = new Date();
|
|
77
|
-
this.executionCount += 1;
|
|
78
|
-
return this.save();
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
JobSchema.methods.markAsCompleted = function (result = null, duration = null) {
|
|
82
|
-
this.status = 'completed';
|
|
83
|
-
this.result_ref = result;
|
|
84
|
-
if (duration) this.actualDuration = duration;
|
|
85
|
-
return this.save();
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
JobSchema.methods.markAsFailed = function (error, duration = null) {
|
|
89
|
-
this.status = 'failed';
|
|
90
|
-
this.error_ref = {
|
|
91
|
-
message: error.message,
|
|
92
|
-
stack: error.stack,
|
|
93
|
-
timestamp: new Date()
|
|
94
|
-
};
|
|
95
|
-
if (duration) this.actualDuration = duration;
|
|
96
|
-
return this.save();
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
// if schedule is updated then trigger sync
|
|
100
|
-
|
|
101
|
-
// channelId, to, agentId, PreContext
|
|
102
|
-
|
|
103
|
-
export const Job = defineModel('Job', JobSchema, 'Job');
|
|
104
|
-
const outboundCallPayload = new Schema({
|
|
105
|
-
channel: { type: Schema.Types.ObjectId, ref: "Channel" },
|
|
106
|
-
agent: { type: Schema.Types.ObjectId, ref: "Agent" },
|
|
107
|
-
to: { type: String, required: true },
|
|
108
|
-
accessToken: { type: String, required: true },
|
|
109
|
-
PreContext: String,
|
|
110
|
-
expectedDuration: Number,
|
|
111
|
-
maxRetries: { type: Number, default: 3 },
|
|
112
|
-
callbackUrl: String,
|
|
113
|
-
cps: Number,
|
|
114
|
-
conversationId: { type: Schema.Types.ObjectId, ref: 'conversation' }
|
|
115
|
-
}, { _id: false })
|
|
116
|
-
/* ───────────────────────────── Outbound Call Job ──────────────────────────── */
|
|
117
|
-
Job.discriminator('outboundCall', new Schema({ payload: outboundCallPayload }, { timestamps: true, discriminatorKey: 'jobType' }));
|