| const { ToolCall } = require('~/db/models'); |
|
|
| |
| |
| |
| |
| |
| async function createToolCall(toolCallData) { |
| try { |
| return await ToolCall.create(toolCallData); |
| } catch (error) { |
| throw new Error(`Error creating tool call: ${error.message}`); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| async function getToolCallById(id) { |
| try { |
| return await ToolCall.findById(id).lean(); |
| } catch (error) { |
| throw new Error(`Error fetching tool call: ${error.message}`); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async function getToolCallsByMessage(messageId, userId) { |
| try { |
| return await ToolCall.find({ messageId, user: userId }).lean(); |
| } catch (error) { |
| throw new Error(`Error fetching tool calls: ${error.message}`); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async function getToolCallsByConvo(conversationId, userId) { |
| try { |
| return await ToolCall.find({ conversationId, user: userId }).lean(); |
| } catch (error) { |
| throw new Error(`Error fetching tool calls: ${error.message}`); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async function updateToolCall(id, updateData) { |
| try { |
| return await ToolCall.findByIdAndUpdate(id, updateData, { new: true }).lean(); |
| } catch (error) { |
| throw new Error(`Error updating tool call: ${error.message}`); |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| async function deleteToolCalls(userId, conversationId) { |
| try { |
| const query = { user: userId }; |
| if (conversationId) { |
| query.conversationId = conversationId; |
| } |
| return await ToolCall.deleteMany(query); |
| } catch (error) { |
| throw new Error(`Error deleting tool call: ${error.message}`); |
| } |
| } |
|
|
| module.exports = { |
| createToolCall, |
| updateToolCall, |
| deleteToolCalls, |
| getToolCallById, |
| getToolCallsByConvo, |
| getToolCallsByMessage, |
| }; |
|
|