mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2026-06-15 23:20:32 +03:00
Agent support for @agent default agent inside workspace chat (#1093)
V1 of agent support via built-in `@agent` that can be invoked alongside normal workspace RAG chat.
This commit is contained in:
95
server/models/workspaceAgentInvocation.js
Normal file
95
server/models/workspaceAgentInvocation.js
Normal file
@@ -0,0 +1,95 @@
|
||||
const prisma = require("../utils/prisma");
|
||||
const { v4: uuidv4 } = require("uuid");
|
||||
|
||||
const WorkspaceAgentInvocation = {
|
||||
// returns array of strings with their @ handle.
|
||||
parseAgents: function (promptString) {
|
||||
return promptString.split(/\s+/).filter((v) => v.startsWith("@"));
|
||||
},
|
||||
|
||||
close: async function (uuid) {
|
||||
if (!uuid) return;
|
||||
try {
|
||||
await prisma.workspace_agent_invocations.update({
|
||||
where: { uuid: String(uuid) },
|
||||
data: { closed: true },
|
||||
});
|
||||
} catch {}
|
||||
},
|
||||
|
||||
new: async function ({ prompt, workspace, user = null, thread = null }) {
|
||||
try {
|
||||
const invocation = await prisma.workspace_agent_invocations.create({
|
||||
data: {
|
||||
uuid: uuidv4(),
|
||||
workspace_id: workspace.id,
|
||||
prompt: String(prompt),
|
||||
user_id: user?.id,
|
||||
thread_id: thread?.id,
|
||||
},
|
||||
});
|
||||
|
||||
return { invocation, message: null };
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return { invocation: null, message: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
get: async function (clause = {}) {
|
||||
try {
|
||||
const invocation = await prisma.workspace_agent_invocations.findFirst({
|
||||
where: clause,
|
||||
});
|
||||
|
||||
return invocation || null;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
getWithWorkspace: async function (clause = {}) {
|
||||
try {
|
||||
const invocation = await prisma.workspace_agent_invocations.findFirst({
|
||||
where: clause,
|
||||
include: {
|
||||
workspace: true,
|
||||
},
|
||||
});
|
||||
|
||||
return invocation || null;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
delete: async function (clause = {}) {
|
||||
try {
|
||||
await prisma.workspace_agent_invocations.delete({
|
||||
where: clause,
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
where: async function (clause = {}, limit = null, orderBy = null) {
|
||||
try {
|
||||
const results = await prisma.workspace_agent_invocations.findMany({
|
||||
where: clause,
|
||||
...(limit !== null ? { take: limit } : {}),
|
||||
...(orderBy !== null ? { orderBy } : {}),
|
||||
});
|
||||
return results;
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = { WorkspaceAgentInvocation };
|
||||
Reference in New Issue
Block a user