@yrpri/api 9.0.99 → 9.0.101
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/agents/assistants/baseAssistant.js +24 -9
- package/agents/assistants/modes/agentDirectConnection.js +2 -17
- package/agents/assistants/modes/agentSelectionMode.js +5 -8
- package/agents/assistants/modes/tools/agentConnectionTools.js +326 -0
- package/agents/assistants/modes/tools/agentTools.js +3 -1
- package/agents/assistants/modes/tools/loginTools.js +1 -1
- package/agents/assistants/modes/tools/models/subscriptions.js +23 -4
- package/agents/assistants/modes/tools/navigationTools.js +95 -21
- package/agents/assistants/modes/tools/subscriptionTools.js +1 -4
- package/agents/assistants/modes/tools/workflowConversationTools.js +326 -0
- package/agents/assistants/modes/tools/workflowConverstationTools.js +112 -0
- package/agents/assistants/modes/tools/workflowTools.js +112 -0
- package/agents/assistants/voiceAssistant.js +3 -3
- package/agents/controllers/assistantsController.js +60 -2
- package/agents/managers/newAiModelSetup.js +63 -0
- package/agents/managers/notificationAgentQueueManager.js +6 -1
- package/agents/managers/workflowConversationManager.js +79 -0
- package/agents/managers/workflowManager.js +76 -0
- package/agents/models/agentProduct.js +37 -24
- package/agents/models/agentProductRun.js +9 -0
- package/agents/models/testData/setupEvolyAgentProductConfig.js +41 -40
- package/agents/models/workflow.js +53 -0
- package/agents/models/workflowConversation.js +53 -0
- package/agents/models/workflowConverstation.js +53 -0
- package/controllers/users.cjs +1 -0
- package/migrations/zzzzzzz_create_trees.cjs +81 -0
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ export class NavigationTools extends BaseAssistantTools {
|
|
|
18
18
|
get connectDirectlyToAgent() {
|
|
19
19
|
return {
|
|
20
20
|
name: "connect_directly_to_one_of_the_agents",
|
|
21
|
-
description: "Select an agent to work with
|
|
21
|
+
description: "Select an agent to work with. The user needs to be logged in to use this tool.",
|
|
22
22
|
type: "function",
|
|
23
23
|
parameters: {
|
|
24
24
|
type: "object",
|
|
@@ -40,36 +40,30 @@ export class NavigationTools extends BaseAssistantTools {
|
|
|
40
40
|
if (!plan?.AgentProduct) {
|
|
41
41
|
throw new Error(`Agent product with id ${params.subscriptionPlanId} not found`);
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const result = await this.subscriptionModels.subscribeToAgentPlan(
|
|
46
|
-
plan.AgentProduct!.id,
|
|
47
|
-
plan.id
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (!result.success || !result.subscription || !result.plan) {
|
|
43
|
+
const result = await this.subscriptionModels.subscribeToAgentPlan(plan.AgentProduct.id, plan.id, true);
|
|
44
|
+
if (!result.success || !result.subscription || !result.plan) {
|
|
51
45
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
success: false,
|
|
47
|
+
error: result.error || "Failed to subscribe to agent plan",
|
|
54
48
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
}*/
|
|
49
|
+
}
|
|
50
|
+
plan = result.plan;
|
|
51
|
+
subscription = result.subscription;
|
|
60
52
|
console.log(`Loading: ${plan?.AgentProduct?.name} ${subscription?.id}`);
|
|
61
|
-
await this.updateCurrentAgentProductPlan(plan, subscription
|
|
62
|
-
sendEvent: false,
|
|
63
|
-
});
|
|
53
|
+
await this.updateCurrentAgentProductPlan(plan, subscription);
|
|
64
54
|
await this.assistant.handleModeSwitch("agent_direct_connection_mode", `Directly connected to agent: ${plan?.AgentProduct?.name}`, params);
|
|
65
|
-
const html = `<div class="agent-chips"><yp-agent-chip
|
|
55
|
+
const html = `<div class="agent-chips"><yp-agent-chip-simple
|
|
66
56
|
isSelected
|
|
57
|
+
isSubscribed="1"
|
|
67
58
|
agentProductId="${plan?.AgentProduct?.id}"
|
|
68
59
|
subscriptionId="${subscription?.id}"
|
|
69
60
|
agentName="${plan?.name}"
|
|
70
61
|
agentDescription="${plan?.AgentProduct?.description}"
|
|
71
62
|
agentImageUrl="${plan?.AgentProduct?.configuration.avatar?.imageUrl}"
|
|
72
|
-
></yp-agent-chip></div>`;
|
|
63
|
+
></yp-agent-chip-simple></div>`;
|
|
64
|
+
if (plan?.AgentProduct?.configuration.avatar?.imageUrl) {
|
|
65
|
+
this.assistant.sendAvatarUrlChange(plan?.AgentProduct?.configuration.avatar?.imageUrl, plan?.AgentProduct?.name);
|
|
66
|
+
}
|
|
73
67
|
this.assistant.triggerResponseIfNeeded("Agent selected");
|
|
74
68
|
return {
|
|
75
69
|
success: true,
|
|
@@ -89,4 +83,84 @@ export class NavigationTools extends BaseAssistantTools {
|
|
|
89
83
|
};
|
|
90
84
|
}
|
|
91
85
|
}
|
|
86
|
+
get listAllAgentsAvailableForConnection() {
|
|
87
|
+
return {
|
|
88
|
+
name: "list_all_agents_available_for_connection",
|
|
89
|
+
description: "List all agent workflows available connecting to",
|
|
90
|
+
type: "function",
|
|
91
|
+
parameters: {
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {},
|
|
94
|
+
},
|
|
95
|
+
handler: this.listAllAgentsAvailableForConnectionsHandler.bind(this),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async listAllAgentsAvailableForConnectionsHandler(params) {
|
|
99
|
+
params = this.assistant.getCleanedParams(params);
|
|
100
|
+
console.log(`handler: list_all_agents_available_for_connections: ${JSON.stringify(params, null, 2)}`);
|
|
101
|
+
try {
|
|
102
|
+
const status = await this.subscriptionModels.loadAgentSubscriptionPlans();
|
|
103
|
+
if (this.assistant.DEBUG) {
|
|
104
|
+
console.log(`list_all_agents_available_for_purchase: ${JSON.stringify(status, null, 2)}`);
|
|
105
|
+
}
|
|
106
|
+
let agentChips = "";
|
|
107
|
+
function planTypePriority(type) {
|
|
108
|
+
switch (type) {
|
|
109
|
+
case "coming_soon":
|
|
110
|
+
return 0;
|
|
111
|
+
case "paid":
|
|
112
|
+
return 1;
|
|
113
|
+
case "free_trial":
|
|
114
|
+
return 2;
|
|
115
|
+
default:
|
|
116
|
+
return 999;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// 2) Custom sort function
|
|
120
|
+
const sortedPlans = [...status.availablePlans].sort((a, b) => {
|
|
121
|
+
// Compare by type priority first
|
|
122
|
+
const typeComparison = planTypePriority(a.type) - planTypePriority(b.type);
|
|
123
|
+
if (typeComparison !== 0) {
|
|
124
|
+
// If types differ, that decides the order
|
|
125
|
+
return typeComparison;
|
|
126
|
+
}
|
|
127
|
+
// If both are the same type and it's "paid", sort by price descending
|
|
128
|
+
if (b.price && a.price && a.type === "paid" && b.type === "paid") {
|
|
129
|
+
return b.price - a.price;
|
|
130
|
+
}
|
|
131
|
+
// Otherwise keep them in the same order if they're not "paid"
|
|
132
|
+
return 0;
|
|
133
|
+
});
|
|
134
|
+
for (const agent of sortedPlans) {
|
|
135
|
+
agentChips += `<yp-agent-chip-simple
|
|
136
|
+
subscriptionPlanId="${agent.subscriptionPlanId}"
|
|
137
|
+
type="${agent.type}"
|
|
138
|
+
agentName="${agent.name}"
|
|
139
|
+
agentDescription="${agent.description}"
|
|
140
|
+
agentImageUrl="${agent.imageUrl}"
|
|
141
|
+
></yp-agent-chip-simple>`;
|
|
142
|
+
}
|
|
143
|
+
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
144
|
+
return {
|
|
145
|
+
success: true,
|
|
146
|
+
data: {
|
|
147
|
+
messageToAssistant: "You have shown the user the available agents for connection with a UI widget, now the user needs to choose which one to connect to",
|
|
148
|
+
status,
|
|
149
|
+
},
|
|
150
|
+
html,
|
|
151
|
+
metadata: {
|
|
152
|
+
timestamp: new Date().toISOString(),
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
catch (error) {
|
|
157
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to load agent status";
|
|
158
|
+
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
159
|
+
return {
|
|
160
|
+
success: false,
|
|
161
|
+
data: errorMessage,
|
|
162
|
+
error: errorMessage,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
92
166
|
}
|
|
@@ -109,7 +109,7 @@ export class SubscriptionTools extends BaseAssistantTools {
|
|
|
109
109
|
return typeComparison;
|
|
110
110
|
}
|
|
111
111
|
// If both are the same type and it's "paid", sort by price descending
|
|
112
|
-
if (a.type === "paid" && b.type === "paid") {
|
|
112
|
+
if (b.price && a.price && a.type === "paid" && b.type === "paid") {
|
|
113
113
|
return b.price - a.price;
|
|
114
114
|
}
|
|
115
115
|
// Otherwise keep them in the same order if they're not "paid"
|
|
@@ -122,9 +122,6 @@ export class SubscriptionTools extends BaseAssistantTools {
|
|
|
122
122
|
agentName="${agent.name}"
|
|
123
123
|
agentDescription="${agent.description}"
|
|
124
124
|
agentImageUrl="${agent.imageUrl}"
|
|
125
|
-
price="${agent.price}"
|
|
126
|
-
currency="${agent.currency}"
|
|
127
|
-
maxRunsPerCycle="${agent.maxRunsPerCycle}"
|
|
128
125
|
></yp-agent-chip-for-purchase>`;
|
|
129
126
|
}
|
|
130
127
|
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// commonTools.ts
|
|
2
|
+
import { SubscriptionModels } from "./models/subscriptions.js";
|
|
3
|
+
import { BaseAssistantTools } from "./baseTools.js";
|
|
4
|
+
export class SubscriptionTools extends BaseAssistantTools {
|
|
5
|
+
constructor(assistant) {
|
|
6
|
+
super(assistant);
|
|
7
|
+
this.subscriptionModels = new SubscriptionModels(assistant);
|
|
8
|
+
}
|
|
9
|
+
get listMyAgentSubscriptions() {
|
|
10
|
+
return {
|
|
11
|
+
name: "list_my_agent_subscriptions",
|
|
12
|
+
description: "List all agent subscriptions for the current user.",
|
|
13
|
+
type: "function",
|
|
14
|
+
parameters: {
|
|
15
|
+
type: "object",
|
|
16
|
+
properties: {},
|
|
17
|
+
},
|
|
18
|
+
handler: this.listMyAgentSubscriptionsHandler.bind(this),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async listMyAgentSubscriptionsHandler(params) {
|
|
22
|
+
params = this.assistant.getCleanedParams(params);
|
|
23
|
+
console.log(`handler: list_my_agent_subscriptions: ${JSON.stringify(params, null, 2)}`);
|
|
24
|
+
try {
|
|
25
|
+
const status = await this.subscriptionModels.loadUserAgentSubscriptions();
|
|
26
|
+
if (this.assistant.DEBUG) {
|
|
27
|
+
console.log(`list_my_agent_subscriptions: ${JSON.stringify(status, null, 2)}`);
|
|
28
|
+
}
|
|
29
|
+
let agentChips = "";
|
|
30
|
+
for (const subscription of status.availableSubscriptions) {
|
|
31
|
+
agentChips += `<div class="agent-chips"><yp-agent-chip-for-purchase
|
|
32
|
+
isSubscribed="${true}"
|
|
33
|
+
type="${subscription.Plan?.configuration.type}"
|
|
34
|
+
agentProductId="${subscription.Plan?.AgentProduct?.id}"
|
|
35
|
+
subscriptionPlanId="${subscription.Plan?.id}"
|
|
36
|
+
agentName="${subscription.Plan?.AgentProduct?.name}"
|
|
37
|
+
agentDescription="${subscription.Plan?.AgentProduct?.description}"
|
|
38
|
+
agentImageUrl="${subscription.Plan?.AgentProduct?.configuration.avatar?.imageUrl}"
|
|
39
|
+
price="${subscription.Plan?.configuration.amount}"
|
|
40
|
+
currency="${subscription.Plan?.configuration.currency}"
|
|
41
|
+
maxRunsPerCycle="${subscription.Plan?.configuration.max_runs_per_cycle}"
|
|
42
|
+
></yp-agent-chip-for-purchase></div>`;
|
|
43
|
+
}
|
|
44
|
+
let html;
|
|
45
|
+
if (status.availableSubscriptions.length > 0) {
|
|
46
|
+
html = `<div class="agent-chips">${agentChips}</div>`;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.assistant.triggerResponseIfNeeded("The user is not subscribed to any agents, offer to show available agents for purchase");
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
success: true,
|
|
53
|
+
data: status,
|
|
54
|
+
html,
|
|
55
|
+
metadata: {
|
|
56
|
+
timestamp: new Date().toISOString(),
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to load agent status";
|
|
62
|
+
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
63
|
+
return {
|
|
64
|
+
success: false,
|
|
65
|
+
data: errorMessage,
|
|
66
|
+
error: errorMessage,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
get listAllAgentsAvailableForSubscription() {
|
|
71
|
+
return {
|
|
72
|
+
name: "list_all_agents_available_for_subscription",
|
|
73
|
+
description: "List all agent subscriptions available for purchase",
|
|
74
|
+
type: "function",
|
|
75
|
+
parameters: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {},
|
|
78
|
+
},
|
|
79
|
+
handler: this.listAllAgentsAvailableForSubscriptionHandler.bind(this),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
async listAllAgentsAvailableForSubscriptionHandler(params) {
|
|
83
|
+
params = this.assistant.getCleanedParams(params);
|
|
84
|
+
console.log(`handler: list_all_agents_available_for_purchase: ${JSON.stringify(params, null, 2)}`);
|
|
85
|
+
try {
|
|
86
|
+
const status = await this.subscriptionModels.loadAgentSubscriptionPlans();
|
|
87
|
+
if (this.assistant.DEBUG) {
|
|
88
|
+
console.log(`list_all_agents_available_for_purchase: ${JSON.stringify(status, null, 2)}`);
|
|
89
|
+
}
|
|
90
|
+
let agentChips = "";
|
|
91
|
+
function planTypePriority(type) {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case "coming_soon":
|
|
94
|
+
return 0;
|
|
95
|
+
case "paid":
|
|
96
|
+
return 1;
|
|
97
|
+
case "free_trial":
|
|
98
|
+
return 2;
|
|
99
|
+
default:
|
|
100
|
+
return 999;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// 2) Custom sort function
|
|
104
|
+
const sortedPlans = [...status.availablePlans].sort((a, b) => {
|
|
105
|
+
// Compare by type priority first
|
|
106
|
+
const typeComparison = planTypePriority(a.type) - planTypePriority(b.type);
|
|
107
|
+
if (typeComparison !== 0) {
|
|
108
|
+
// If types differ, that decides the order
|
|
109
|
+
return typeComparison;
|
|
110
|
+
}
|
|
111
|
+
// If both are the same type and it's "paid", sort by price descending
|
|
112
|
+
if (a.type === "paid" && b.type === "paid") {
|
|
113
|
+
return b.price - a.price;
|
|
114
|
+
}
|
|
115
|
+
// Otherwise keep them in the same order if they're not "paid"
|
|
116
|
+
return 0;
|
|
117
|
+
});
|
|
118
|
+
for (const agent of sortedPlans) {
|
|
119
|
+
agentChips += `<yp-agent-chip-for-purchase
|
|
120
|
+
subscriptionPlanId="${agent.subscriptionPlanId}"
|
|
121
|
+
type="${agent.type}"
|
|
122
|
+
agentName="${agent.name}"
|
|
123
|
+
agentDescription="${agent.description}"
|
|
124
|
+
agentImageUrl="${agent.imageUrl}"
|
|
125
|
+
price="${agent.price}"
|
|
126
|
+
currency="${agent.currency}"
|
|
127
|
+
maxRunsPerCycle="${agent.maxRunsPerCycle}"
|
|
128
|
+
></yp-agent-chip-for-purchase>`;
|
|
129
|
+
}
|
|
130
|
+
const html = `<div class="agent-chips">${agentChips}</div>`;
|
|
131
|
+
return {
|
|
132
|
+
success: true,
|
|
133
|
+
data: {
|
|
134
|
+
messageToAssistant: "You have shown the user the available agents for purchase with a UI widget, now the user needs to choose which one to connect to then subscribe to",
|
|
135
|
+
status,
|
|
136
|
+
},
|
|
137
|
+
html,
|
|
138
|
+
metadata: {
|
|
139
|
+
timestamp: new Date().toISOString(),
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to load agent status";
|
|
145
|
+
console.error(`Failed to load agent status: ${errorMessage}`);
|
|
146
|
+
return {
|
|
147
|
+
success: false,
|
|
148
|
+
data: errorMessage,
|
|
149
|
+
error: errorMessage,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
get subscribeToCurrentAgentPlan() {
|
|
154
|
+
return {
|
|
155
|
+
name: "subscribe_to_current_agent_plan",
|
|
156
|
+
description: "Subscribe to the current agent plan. User must confirm subscription with the agent name before proceeding. The user needs to subscribe to the agent before it can be used so make sure to offer it to the user.",
|
|
157
|
+
type: "function",
|
|
158
|
+
parameters: {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: {
|
|
161
|
+
useHasVerballyConfirmedSubscribeWithTheAgentName: {
|
|
162
|
+
type: "boolean",
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
required: [
|
|
166
|
+
"useHasVerballyConfirmedSubscribeWithTheAgentName",
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
handler: this.subscribeToCurrentAgentPlanHandler.bind(this),
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
async subscribeToCurrentAgentPlanHandler(params) {
|
|
173
|
+
params = this.assistant.getCleanedParams(params);
|
|
174
|
+
console.log(`handler: subscribe_to_current_agent_plan: ${JSON.stringify(params, null, 2)}`);
|
|
175
|
+
try {
|
|
176
|
+
if (!params.useHasVerballyConfirmedSubscribeWithTheAgentName) {
|
|
177
|
+
return {
|
|
178
|
+
success: false,
|
|
179
|
+
error: "User must confirm subscription with the agent name before proceeding",
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
console.log(`-------> ${JSON.stringify(this.assistant.memory.currentAgentStatus, null, 2)}`);
|
|
183
|
+
const subscriptionPlan = await this.assistant.getCurrentSubscriptionPlan();
|
|
184
|
+
if (!subscriptionPlan) {
|
|
185
|
+
throw new Error("No subscription plan found");
|
|
186
|
+
}
|
|
187
|
+
if (!subscriptionPlan) {
|
|
188
|
+
return {
|
|
189
|
+
success: false,
|
|
190
|
+
data: "No current agent selected",
|
|
191
|
+
error: "No current agent selected",
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
const result = await this.subscriptionModels.subscribeToAgentPlan(subscriptionPlan.AgentProduct.id, subscriptionPlan.id);
|
|
195
|
+
if (!result.success || !result.subscription || !result.plan) {
|
|
196
|
+
return {
|
|
197
|
+
success: false,
|
|
198
|
+
error: result.error || "Failed to subscribe to agent plan",
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
await this.updateCurrentAgentProductPlan(result.plan, result.subscription);
|
|
202
|
+
let html;
|
|
203
|
+
if (result.plan?.AgentProduct) {
|
|
204
|
+
html = `<div class="agent-chips"><yp-agent-chip-for-purchase
|
|
205
|
+
isSubscribed="${true}"
|
|
206
|
+
agentProductId="${result.plan.AgentProduct.id}"
|
|
207
|
+
subscriptionPlanId="${result.plan.id}"
|
|
208
|
+
agentName="${result.plan.AgentProduct.configuration.displayName}"
|
|
209
|
+
agentDescription="${result.plan.AgentProduct.description}"
|
|
210
|
+
agentImageUrl="${result.plan.AgentProduct.configuration.avatar?.imageUrl}"
|
|
211
|
+
price="${result.plan.configuration.amount}"
|
|
212
|
+
currency="${result.plan.configuration.currency}"
|
|
213
|
+
maxRunsPerCycle="${result.plan.configuration.max_runs_per_cycle}"
|
|
214
|
+
></yp-agent-chip-for-purchase></div>`;
|
|
215
|
+
}
|
|
216
|
+
this.assistant.emit("update-ai-model-session", "Successfully subscribed to agent plan, now offer to show the configuration input tool/widget to configure the agent");
|
|
217
|
+
return {
|
|
218
|
+
success: true,
|
|
219
|
+
html,
|
|
220
|
+
data: {
|
|
221
|
+
message: "Successfully subscribed to agent plan, now offer to show the configuration input tool/widget to configure the agent",
|
|
222
|
+
subscription: result.subscription,
|
|
223
|
+
subscriptionPlan: result.plan,
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to subscribe to agent";
|
|
229
|
+
console.error(`Failed to subscribe to agent: ${errorMessage}`);
|
|
230
|
+
return {
|
|
231
|
+
success: false,
|
|
232
|
+
error: errorMessage,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
get unsubscribeFromCurrentAgentSubscription() {
|
|
237
|
+
return {
|
|
238
|
+
name: "unsubscribe_from_current_agent_subscription",
|
|
239
|
+
description: "Unsubscribe from an existing agent subscription the user is subscribed to. User must verbally confirm unsubscription with the agent name before proceeding.",
|
|
240
|
+
type: "function",
|
|
241
|
+
parameters: {
|
|
242
|
+
type: "object",
|
|
243
|
+
properties: {
|
|
244
|
+
useHasVerballyConfirmedUnsubscribeWithTheAgentName: {
|
|
245
|
+
type: "boolean",
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
required: [
|
|
249
|
+
"useHasVerballyConfirmedUnsubscribeWithTheAgentName",
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
handler: this.unsubscribeFromCurrentAgentSubscriptionHandler.bind(this),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
async unsubscribeFromCurrentAgentSubscriptionHandler(params) {
|
|
256
|
+
params = this.assistant.getCleanedParams(params);
|
|
257
|
+
console.log(`handler: unsubscribe_from_current_agent_subscription: ${JSON.stringify(params, null, 2)}`);
|
|
258
|
+
try {
|
|
259
|
+
if (!params.useHasVerballyConfirmedUnsubscribeWithTheAgentName) {
|
|
260
|
+
return {
|
|
261
|
+
success: false,
|
|
262
|
+
error: "User must verbally confirm unsubscription with the agent name before proceeding",
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const subscriptionPlan = await this.assistant.getCurrentSubscriptionPlan();
|
|
266
|
+
if (!subscriptionPlan) {
|
|
267
|
+
return {
|
|
268
|
+
success: false,
|
|
269
|
+
data: "No current agent selected",
|
|
270
|
+
error: "No current agent selected",
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const { plan, subscription } = await this.subscriptionModels.loadAgentProductPlanAndSubscription(subscriptionPlan.id);
|
|
274
|
+
if (!subscription) {
|
|
275
|
+
return {
|
|
276
|
+
success: false,
|
|
277
|
+
data: "No subscription found",
|
|
278
|
+
error: "No subscription found",
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
if (!plan) {
|
|
282
|
+
return {
|
|
283
|
+
success: false,
|
|
284
|
+
data: "No subscription plan found",
|
|
285
|
+
error: "No subscription plan found",
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const result = await this.subscriptionModels.unsubscribeFromAgentPlan(subscription.id);
|
|
289
|
+
if (!result.success) {
|
|
290
|
+
return {
|
|
291
|
+
success: false,
|
|
292
|
+
error: result.error,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
await this.updateCurrentAgentProductPlan(plan, subscription);
|
|
296
|
+
const html = `<div class="agent-chips"><yp-agent-chip
|
|
297
|
+
isUnsubscribed="${true}"
|
|
298
|
+
agentProductId="${plan.AgentProduct?.id}"
|
|
299
|
+
subscriptionId="${subscription.id}"
|
|
300
|
+
agentName="${plan.AgentProduct?.name}"
|
|
301
|
+
agentDescription="${plan.AgentProduct?.description}"
|
|
302
|
+
agentImageUrl="${plan.AgentProduct?.configuration.avatar?.imageUrl}"
|
|
303
|
+
></yp-agent-chip></div>`;
|
|
304
|
+
this.assistant.emit("update-ai-model-session", "Successfully unsubscribed from agent subscription");
|
|
305
|
+
return {
|
|
306
|
+
success: true,
|
|
307
|
+
html,
|
|
308
|
+
data: {
|
|
309
|
+
message: "Successfully unsubscribed from agent subscription",
|
|
310
|
+
subscriptionId: result.subscriptionId,
|
|
311
|
+
subscriptionPlan: plan,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
catch (error) {
|
|
316
|
+
const errorMessage = error instanceof Error
|
|
317
|
+
? error.message
|
|
318
|
+
: "Failed to unsubscribe from agent";
|
|
319
|
+
console.error(`Failed to unsubscribe from agent: ${errorMessage}`);
|
|
320
|
+
return {
|
|
321
|
+
success: false,
|
|
322
|
+
error: errorMessage,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BaseAssistantTools } from "./baseTools.js";
|
|
2
|
+
export class WorkflowConversationTools extends BaseAssistantTools {
|
|
3
|
+
constructor(assistant) {
|
|
4
|
+
super(assistant);
|
|
5
|
+
}
|
|
6
|
+
get show_running_workflow_conversations() {
|
|
7
|
+
return {
|
|
8
|
+
name: "show_running_workflow_conversations",
|
|
9
|
+
description: "Display running workflow conversations",
|
|
10
|
+
type: "function",
|
|
11
|
+
parameters: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: {},
|
|
14
|
+
required: []
|
|
15
|
+
},
|
|
16
|
+
handler: this.showRunningWorkflowsHandler.bind(this)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async showRunningWorkflowsHandler(params) {
|
|
20
|
+
params = this.assistant.getCleanedParams(params);
|
|
21
|
+
console.log(`handler: show_running_workflows: ${JSON.stringify(params, null, 2)}`);
|
|
22
|
+
try {
|
|
23
|
+
const html = `<yp-workflow-widget-small running="true"></yp-workflow-widget-small>`;
|
|
24
|
+
return {
|
|
25
|
+
success: true,
|
|
26
|
+
html,
|
|
27
|
+
uniqueToken: "runningWorkflows",
|
|
28
|
+
data: { message: "Running workflows displayed successfully" },
|
|
29
|
+
metadata: { timestamp: new Date().toISOString() }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const errorMessage = error instanceof Error ? error.message : "Error displaying running workflows";
|
|
34
|
+
console.error(`Error in show_running_workflows: ${errorMessage}`);
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
error: errorMessage
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
get show_all_workflow_conversations() {
|
|
42
|
+
return {
|
|
43
|
+
name: "show_all_workflow_conversations",
|
|
44
|
+
description: "Display all workflow conversations",
|
|
45
|
+
type: "function",
|
|
46
|
+
parameters: {
|
|
47
|
+
type: "object",
|
|
48
|
+
properties: {},
|
|
49
|
+
required: []
|
|
50
|
+
},
|
|
51
|
+
handler: this.showAllWorkflowsHandler.bind(this)
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async showAllWorkflowsHandler(params) {
|
|
55
|
+
params = this.assistant.getCleanedParams(params);
|
|
56
|
+
console.log(`handler: show_all_workflows: ${JSON.stringify(params, null, 2)}`);
|
|
57
|
+
try {
|
|
58
|
+
const html = `<yp-workflow-widget-small all="true"></yp-workflow-widget-small>`;
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
html,
|
|
62
|
+
uniqueToken: "allWorkflows",
|
|
63
|
+
data: { message: "All workflows displayed successfully" },
|
|
64
|
+
metadata: { timestamp: new Date().toISOString() }
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
const errorMessage = error instanceof Error ? error.message : "Error displaying all workflows";
|
|
69
|
+
console.error(`Error in show_all_workflows: ${errorMessage}`);
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
error: errorMessage
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
get connect_to_workflow_conversation() {
|
|
77
|
+
return {
|
|
78
|
+
name: "connect_to_workflow_conversation",
|
|
79
|
+
description: "Connect to an existing workflow conversation",
|
|
80
|
+
type: "function",
|
|
81
|
+
parameters: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
workflowId: { type: "number" }
|
|
85
|
+
},
|
|
86
|
+
required: ["workflowId"]
|
|
87
|
+
},
|
|
88
|
+
handler: this.connectToWorkflowHandler.bind(this)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async connectToWorkflowHandler(params) {
|
|
92
|
+
params = this.assistant.getCleanedParams(params);
|
|
93
|
+
console.log(`handler: connect_to_workflow: ${JSON.stringify(params, null, 2)}`);
|
|
94
|
+
try {
|
|
95
|
+
const { workflowId } = params;
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
data: { message: `Connected to workflow ${workflowId} successfully` },
|
|
99
|
+
uniqueToken: `connectWorkflow_${workflowId}`,
|
|
100
|
+
metadata: { timestamp: new Date().toISOString() }
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
const errorMessage = error instanceof Error ? error.message : "Error connecting to workflow conversation";
|
|
105
|
+
console.error(`Error in connect_to_workflow_conversation: ${errorMessage}`);
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: errorMessage
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|