Bugfix/Gsuite tool params (#5189)
* fix gsuite tool params * custom assistant only check for mandatory fields for visible params * azure chat openai fix for gpt5 * return raw from executeJavaScriptCode * add json5 for parsing * azure chatopenai use maxCompletionTokens
This commit is contained in:
parent
32bf030924
commit
6fb9bb559f
|
|
@ -1723,9 +1723,20 @@ class Agent_Agentflow implements INode {
|
|||
}
|
||||
|
||||
console.error('Error invoking tool:', e)
|
||||
const errMsg = getErrorMessage(e)
|
||||
let toolInput = toolCall.args
|
||||
if (typeof errMsg === 'string' && errMsg.includes(TOOL_ARGS_PREFIX)) {
|
||||
const [_, args] = errMsg.split(TOOL_ARGS_PREFIX)
|
||||
try {
|
||||
toolInput = JSON.parse(args)
|
||||
} catch (e) {
|
||||
console.error('Error parsing tool input from tool:', e)
|
||||
}
|
||||
}
|
||||
|
||||
usedTools.push({
|
||||
tool: selectedTool.name,
|
||||
toolInput: toolCall.args,
|
||||
toolInput,
|
||||
toolOutput: '',
|
||||
error: getErrorMessage(e)
|
||||
})
|
||||
|
|
@ -1995,9 +2006,20 @@ class Agent_Agentflow implements INode {
|
|||
}
|
||||
|
||||
console.error('Error invoking tool:', e)
|
||||
const errMsg = getErrorMessage(e)
|
||||
let toolInput = toolCall.args
|
||||
if (typeof errMsg === 'string' && errMsg.includes(TOOL_ARGS_PREFIX)) {
|
||||
const [_, args] = errMsg.split(TOOL_ARGS_PREFIX)
|
||||
try {
|
||||
toolInput = JSON.parse(args)
|
||||
} catch (e) {
|
||||
console.error('Error parsing tool input from tool:', e)
|
||||
}
|
||||
}
|
||||
|
||||
usedTools.push({
|
||||
tool: selectedTool.name,
|
||||
toolInput: toolCall.args,
|
||||
toolInput,
|
||||
toolOutput: '',
|
||||
error: getErrorMessage(e)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -273,10 +273,9 @@ class AzureChatOpenAI_ChatModels implements INode {
|
|||
console.error('Error parsing base options', exception)
|
||||
}
|
||||
}
|
||||
if (modelName === 'o3-mini' || modelName.includes('o1')) {
|
||||
if (modelName.includes('o1') || modelName.includes('o3') || modelName.includes('gpt-5')) {
|
||||
delete obj.temperature
|
||||
}
|
||||
if (modelName.includes('o1') || modelName.includes('o3')) {
|
||||
delete obj.stop
|
||||
const reasoning: OpenAIClient.Reasoning = {}
|
||||
if (reasoningEffort) {
|
||||
reasoning.effort = reasoningEffort
|
||||
|
|
@ -285,6 +284,11 @@ class AzureChatOpenAI_ChatModels implements INode {
|
|||
reasoning.summary = reasoningSummary
|
||||
}
|
||||
obj.reasoning = reasoning
|
||||
|
||||
if (maxTokens) {
|
||||
delete obj.maxTokens
|
||||
obj.maxCompletionTokens = parseInt(maxTokens, 10)
|
||||
}
|
||||
}
|
||||
|
||||
const multiModalOption: IMultiModalOption = {
|
||||
|
|
|
|||
|
|
@ -362,11 +362,15 @@ try {
|
|||
|
||||
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
||||
|
||||
const response = await executeJavaScriptCode(code, sandbox, {
|
||||
let response = await executeJavaScriptCode(code, sandbox, {
|
||||
useSandbox: false,
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (typeof response === 'object') {
|
||||
response = JSON.stringify(response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,11 +370,15 @@ try {
|
|||
|
||||
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
||||
|
||||
const response = await executeJavaScriptCode(code, sandbox, {
|
||||
let response = await executeJavaScriptCode(code, sandbox, {
|
||||
useSandbox: false,
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (typeof response === 'object') {
|
||||
response = JSON.stringify(response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,10 +124,14 @@ export class DynamicStructuredTool<
|
|||
|
||||
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
||||
|
||||
const response = await executeJavaScriptCode(this.code, sandbox, {
|
||||
let response = await executeJavaScriptCode(this.code, sandbox, {
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (typeof response === 'object') {
|
||||
response = JSON.stringify(response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Gmail API for managing drafts, messages, labels, and threads`
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class ListDraftsTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing drafts: ${error}`
|
||||
return formatToolError(`Error listing drafts: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ class CreateDraftTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', draftData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating draft: ${error}`
|
||||
return formatToolError(`Error creating draft: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ class GetDraftTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const draftId = params.id || params.draftId
|
||||
const draftId = params.draftId || params.id
|
||||
|
||||
if (!draftId) {
|
||||
return 'Error: Draft ID is required'
|
||||
|
|
@ -210,7 +210,7 @@ class GetDraftTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting draft: ${error}`
|
||||
return formatToolError(`Error getting draft: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +233,7 @@ class UpdateDraftTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const draftId = params.id || params.draftId
|
||||
const draftId = params.draftId || params.id
|
||||
|
||||
if (!draftId) {
|
||||
return 'Error: Draft ID is required'
|
||||
|
|
@ -251,7 +251,7 @@ class UpdateDraftTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'PUT', draftData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating draft: ${error}`
|
||||
return formatToolError(`Error updating draft: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ class SendDraftTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const draftId = params.id || params.draftId
|
||||
const draftId = params.draftId || params.id
|
||||
|
||||
if (!draftId) {
|
||||
return 'Error: Draft ID is required'
|
||||
|
|
@ -285,7 +285,7 @@ class SendDraftTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', { id: draftId }, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error sending draft: ${error}`
|
||||
return formatToolError(`Error sending draft: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -308,7 +308,7 @@ class DeleteDraftTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const draftId = params.id || params.draftId
|
||||
const draftId = params.draftId || params.id
|
||||
|
||||
if (!draftId) {
|
||||
return 'Error: Draft ID is required'
|
||||
|
|
@ -319,7 +319,7 @@ class DeleteDraftTool extends BaseGmailTool {
|
|||
await this.makeGmailRequest(url, 'DELETE', undefined, params)
|
||||
return `Draft ${draftId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting draft: ${error}`
|
||||
return formatToolError(`Error deleting draft: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ class ListMessagesTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing messages: ${error}`
|
||||
return formatToolError(`Error listing messages: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -377,7 +377,7 @@ class GetMessageTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const messageId = params.id || params.messageId
|
||||
const messageId = params.messageId || params.id
|
||||
|
||||
if (!messageId) {
|
||||
return 'Error: Message ID is required'
|
||||
|
|
@ -388,7 +388,7 @@ class GetMessageTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting message: ${error}`
|
||||
return formatToolError(`Error getting message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -422,7 +422,7 @@ class SendMessageTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', messageData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error sending message: ${error}`
|
||||
return formatToolError(`Error sending message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -445,7 +445,7 @@ class ModifyMessageTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const messageId = params.id || params.messageId
|
||||
const messageId = params.messageId || params.id
|
||||
|
||||
if (!messageId) {
|
||||
return 'Error: Message ID is required'
|
||||
|
|
@ -464,7 +464,7 @@ class ModifyMessageTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', modifyData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error modifying message: ${error}`
|
||||
return formatToolError(`Error modifying message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -487,7 +487,7 @@ class TrashMessageTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const messageId = params.id || params.messageId
|
||||
const messageId = params.messageId || params.id
|
||||
|
||||
if (!messageId) {
|
||||
return 'Error: Message ID is required'
|
||||
|
|
@ -498,7 +498,7 @@ class TrashMessageTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error moving message to trash: ${error}`
|
||||
return formatToolError(`Error moving message to trash: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -521,7 +521,7 @@ class UntrashMessageTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const messageId = params.id || params.messageId
|
||||
const messageId = params.messageId || params.id
|
||||
|
||||
if (!messageId) {
|
||||
return 'Error: Message ID is required'
|
||||
|
|
@ -532,7 +532,7 @@ class UntrashMessageTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error removing message from trash: ${error}`
|
||||
return formatToolError(`Error removing message from trash: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -555,7 +555,7 @@ class DeleteMessageTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const messageId = params.id || params.messageId
|
||||
const messageId = params.messageId || params.id
|
||||
|
||||
if (!messageId) {
|
||||
return 'Error: Message ID is required'
|
||||
|
|
@ -566,7 +566,7 @@ class DeleteMessageTool extends BaseGmailTool {
|
|||
await this.makeGmailRequest(url, 'DELETE', undefined, params)
|
||||
return `Message ${messageId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting message: ${error}`
|
||||
return formatToolError(`Error deleting message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -594,7 +594,7 @@ class ListLabelsTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, {})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing labels: ${error}`
|
||||
return formatToolError(`Error listing labels: ${error}`, {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -617,7 +617,7 @@ class GetLabelTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const labelId = params.id || params.labelId
|
||||
const labelId = params.labelId || params.id
|
||||
|
||||
if (!labelId) {
|
||||
return 'Error: Label ID is required'
|
||||
|
|
@ -628,7 +628,7 @@ class GetLabelTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting label: ${error}`
|
||||
return formatToolError(`Error getting label: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -673,7 +673,7 @@ class CreateLabelTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', labelData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating label: ${error}`
|
||||
return formatToolError(`Error creating label: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -696,7 +696,7 @@ class UpdateLabelTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const labelId = params.labelId
|
||||
const labelId = params.labelId || params.id
|
||||
|
||||
if (!labelId) {
|
||||
return 'Error: Label ID is required'
|
||||
|
|
@ -717,7 +717,7 @@ class UpdateLabelTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'PUT', labelData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating label: ${error}`
|
||||
return formatToolError(`Error updating label: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -740,7 +740,7 @@ class DeleteLabelTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const labelId = params.id || params.labelId
|
||||
const labelId = params.labelId || params.id
|
||||
|
||||
if (!labelId) {
|
||||
return 'Error: Label ID is required'
|
||||
|
|
@ -751,7 +751,7 @@ class DeleteLabelTool extends BaseGmailTool {
|
|||
await this.makeGmailRequest(url, 'DELETE', undefined, params)
|
||||
return `Label ${labelId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting label: ${error}`
|
||||
return formatToolError(`Error deleting label: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -786,7 +786,7 @@ class ListThreadsTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing threads: ${error}`
|
||||
return formatToolError(`Error listing threads: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -809,7 +809,7 @@ class GetThreadTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const threadId = params.id || params.threadId
|
||||
const threadId = params.threadId || params.id
|
||||
|
||||
if (!threadId) {
|
||||
return 'Error: Thread ID is required'
|
||||
|
|
@ -820,7 +820,7 @@ class GetThreadTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting thread: ${error}`
|
||||
return formatToolError(`Error getting thread: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -843,7 +843,7 @@ class ModifyThreadTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const threadId = params.id || params.threadId
|
||||
const threadId = params.threadId || params.id
|
||||
|
||||
if (!threadId) {
|
||||
return 'Error: Thread ID is required'
|
||||
|
|
@ -862,7 +862,7 @@ class ModifyThreadTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', modifyData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error modifying thread: ${error}`
|
||||
return formatToolError(`Error modifying thread: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -885,7 +885,7 @@ class TrashThreadTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const threadId = params.id || params.threadId
|
||||
const threadId = params.threadId || params.id
|
||||
|
||||
if (!threadId) {
|
||||
return 'Error: Thread ID is required'
|
||||
|
|
@ -896,7 +896,7 @@ class TrashThreadTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error moving thread to trash: ${error}`
|
||||
return formatToolError(`Error moving thread to trash: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -919,7 +919,7 @@ class UntrashThreadTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const threadId = params.id || params.threadId
|
||||
const threadId = params.threadId || params.id
|
||||
|
||||
if (!threadId) {
|
||||
return 'Error: Thread ID is required'
|
||||
|
|
@ -930,7 +930,7 @@ class UntrashThreadTool extends BaseGmailTool {
|
|||
const response = await this.makeGmailRequest(url, 'POST', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error removing thread from trash: ${error}`
|
||||
return formatToolError(`Error removing thread from trash: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -953,7 +953,7 @@ class DeleteThreadTool extends BaseGmailTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const threadId = params.id || params.threadId
|
||||
const threadId = params.threadId || params.id
|
||||
|
||||
if (!threadId) {
|
||||
return 'Error: Thread ID is required'
|
||||
|
|
@ -964,7 +964,7 @@ class DeleteThreadTool extends BaseGmailTool {
|
|||
await this.makeGmailRequest(url, 'DELETE', undefined, params)
|
||||
return `Thread ${threadId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting thread: ${error}`
|
||||
return formatToolError(`Error deleting thread: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -977,222 +977,102 @@ export const createGmailTools = (args?: RequestParameters): DynamicStructuredToo
|
|||
|
||||
// Draft tools
|
||||
if (actions.includes('listDrafts')) {
|
||||
tools.push(
|
||||
new ListDraftsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listDrafts
|
||||
})
|
||||
)
|
||||
tools.push(new ListDraftsTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('createDraft')) {
|
||||
tools.push(
|
||||
new CreateDraftTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createDraft
|
||||
})
|
||||
)
|
||||
tools.push(new CreateDraftTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getDraft')) {
|
||||
tools.push(
|
||||
new GetDraftTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getDraft
|
||||
})
|
||||
)
|
||||
tools.push(new GetDraftTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('updateDraft')) {
|
||||
tools.push(
|
||||
new UpdateDraftTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateDraft
|
||||
})
|
||||
)
|
||||
tools.push(new UpdateDraftTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('sendDraft')) {
|
||||
tools.push(
|
||||
new SendDraftTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.sendDraft
|
||||
})
|
||||
)
|
||||
tools.push(new SendDraftTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteDraft')) {
|
||||
tools.push(
|
||||
new DeleteDraftTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteDraft
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteDraftTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
// Message tools
|
||||
if (actions.includes('listMessages')) {
|
||||
tools.push(
|
||||
new ListMessagesTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listMessages
|
||||
})
|
||||
)
|
||||
tools.push(new ListMessagesTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getMessage')) {
|
||||
tools.push(
|
||||
new GetMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getMessage
|
||||
})
|
||||
)
|
||||
tools.push(new GetMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('sendMessage')) {
|
||||
tools.push(
|
||||
new SendMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.sendMessage
|
||||
})
|
||||
)
|
||||
tools.push(new SendMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('modifyMessage')) {
|
||||
tools.push(
|
||||
new ModifyMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.modifyMessage
|
||||
})
|
||||
)
|
||||
tools.push(new ModifyMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('trashMessage')) {
|
||||
tools.push(
|
||||
new TrashMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.trashMessage
|
||||
})
|
||||
)
|
||||
tools.push(new TrashMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('untrashMessage')) {
|
||||
tools.push(
|
||||
new UntrashMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.untrashMessage
|
||||
})
|
||||
)
|
||||
tools.push(new UntrashMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteMessage')) {
|
||||
tools.push(
|
||||
new DeleteMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteMessage
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteMessageTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
// Label tools
|
||||
if (actions.includes('listLabels')) {
|
||||
tools.push(
|
||||
new ListLabelsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listLabels
|
||||
})
|
||||
)
|
||||
tools.push(new ListLabelsTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getLabel')) {
|
||||
tools.push(
|
||||
new GetLabelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getLabel
|
||||
})
|
||||
)
|
||||
tools.push(new GetLabelTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('createLabel')) {
|
||||
tools.push(
|
||||
new CreateLabelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createLabel
|
||||
})
|
||||
)
|
||||
tools.push(new CreateLabelTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('updateLabel')) {
|
||||
tools.push(
|
||||
new UpdateLabelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateLabel
|
||||
})
|
||||
)
|
||||
tools.push(new UpdateLabelTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteLabel')) {
|
||||
tools.push(
|
||||
new DeleteLabelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteLabel
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteLabelTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
// Thread tools
|
||||
if (actions.includes('listThreads')) {
|
||||
tools.push(
|
||||
new ListThreadsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listThreads
|
||||
})
|
||||
)
|
||||
tools.push(new ListThreadsTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getThread')) {
|
||||
tools.push(
|
||||
new GetThreadTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getThread
|
||||
})
|
||||
)
|
||||
tools.push(new GetThreadTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('modifyThread')) {
|
||||
tools.push(
|
||||
new ModifyThreadTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.modifyThread
|
||||
})
|
||||
)
|
||||
tools.push(new ModifyThreadTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('trashThread')) {
|
||||
tools.push(
|
||||
new TrashThreadTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.trashThread
|
||||
})
|
||||
)
|
||||
tools.push(new TrashThreadTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('untrashThread')) {
|
||||
tools.push(
|
||||
new UntrashThreadTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.untrashThread
|
||||
})
|
||||
)
|
||||
tools.push(new UntrashThreadTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteThread')) {
|
||||
tools.push(
|
||||
new DeleteThreadTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteThread
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteThreadTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
return tools
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Google Calendar API for managing events and calendars`
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ class ListEventsTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing events: ${error}`
|
||||
return formatToolError(`Error listing events: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -291,7 +291,7 @@ class CreateEventTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: eventData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating event: ${error}`
|
||||
return formatToolError(`Error creating event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -323,7 +323,7 @@ class GetEventTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting event: ${error}`
|
||||
return formatToolError(`Error getting event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -400,7 +400,7 @@ class UpdateEventTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'PUT', body: updateData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating event: ${error}`
|
||||
return formatToolError(`Error updating event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -432,7 +432,7 @@ class DeleteEventTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'DELETE', params })
|
||||
return response || 'Event deleted successfully'
|
||||
} catch (error) {
|
||||
return `Error deleting event: ${error}`
|
||||
return formatToolError(`Error deleting event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -467,7 +467,7 @@ class QuickAddEventTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error quick adding event: ${error}`
|
||||
return formatToolError(`Error quick adding event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -505,7 +505,7 @@ class ListCalendarsTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing calendars: ${error}`
|
||||
return formatToolError(`Error listing calendars: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -545,7 +545,7 @@ class CreateCalendarTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: calendarData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating calendar: ${error}`
|
||||
return formatToolError(`Error creating calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -577,7 +577,7 @@ class GetCalendarTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting calendar: ${error}`
|
||||
return formatToolError(`Error getting calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -616,7 +616,7 @@ class UpdateCalendarTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'PUT', body: updateData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating calendar: ${error}`
|
||||
return formatToolError(`Error updating calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -648,7 +648,7 @@ class DeleteCalendarTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'DELETE', params })
|
||||
return response || 'Calendar deleted successfully'
|
||||
} catch (error) {
|
||||
return `Error deleting calendar: ${error}`
|
||||
return formatToolError(`Error deleting calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -680,7 +680,7 @@ class ClearCalendarTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', params })
|
||||
return response || 'Calendar cleared successfully'
|
||||
} catch (error) {
|
||||
return `Error clearing calendar: ${error}`
|
||||
return formatToolError(`Error clearing calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -729,7 +729,7 @@ class QueryFreebusyTool extends BaseGoogleCalendarTool {
|
|||
const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: freebusyData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error querying freebusy: ${error}`
|
||||
return formatToolError(`Error querying freebusy: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -742,122 +742,57 @@ export const createGoogleCalendarTools = (args?: RequestParameters): DynamicStru
|
|||
|
||||
// Event tools
|
||||
if (actions.includes('listEvents')) {
|
||||
tools.push(
|
||||
new ListEventsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listEvents
|
||||
})
|
||||
)
|
||||
tools.push(new ListEventsTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('createEvent')) {
|
||||
tools.push(
|
||||
new CreateEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createEvent
|
||||
})
|
||||
)
|
||||
tools.push(new CreateEventTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getEvent')) {
|
||||
tools.push(
|
||||
new GetEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getEvent
|
||||
})
|
||||
)
|
||||
tools.push(new GetEventTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('updateEvent')) {
|
||||
tools.push(
|
||||
new UpdateEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateEvent
|
||||
})
|
||||
)
|
||||
tools.push(new UpdateEventTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteEvent')) {
|
||||
tools.push(
|
||||
new DeleteEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteEvent
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteEventTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('quickAddEvent')) {
|
||||
tools.push(
|
||||
new QuickAddEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.quickAddEvent
|
||||
})
|
||||
)
|
||||
tools.push(new QuickAddEventTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
// Calendar tools
|
||||
if (actions.includes('listCalendars')) {
|
||||
tools.push(
|
||||
new ListCalendarsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listCalendars
|
||||
})
|
||||
)
|
||||
tools.push(new ListCalendarsTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('createCalendar')) {
|
||||
tools.push(
|
||||
new CreateCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createCalendar
|
||||
})
|
||||
)
|
||||
tools.push(new CreateCalendarTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('getCalendar')) {
|
||||
tools.push(
|
||||
new GetCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getCalendar
|
||||
})
|
||||
)
|
||||
tools.push(new GetCalendarTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('updateCalendar')) {
|
||||
tools.push(
|
||||
new UpdateCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateCalendar
|
||||
})
|
||||
)
|
||||
tools.push(new UpdateCalendarTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('deleteCalendar')) {
|
||||
tools.push(
|
||||
new DeleteCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteCalendar
|
||||
})
|
||||
)
|
||||
tools.push(new DeleteCalendarTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
if (actions.includes('clearCalendar')) {
|
||||
tools.push(
|
||||
new ClearCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.clearCalendar
|
||||
})
|
||||
)
|
||||
tools.push(new ClearCalendarTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
// Freebusy tools
|
||||
if (actions.includes('queryFreebusy')) {
|
||||
tools.push(
|
||||
new QueryFreebusyTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.queryFreebusy
|
||||
})
|
||||
)
|
||||
tools.push(new QueryFreebusyTool({ accessToken, defaultParams }))
|
||||
}
|
||||
|
||||
return tools
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Google Docs API for managing documents`
|
||||
|
||||
|
|
@ -256,7 +256,7 @@ class CreateDocumentTool extends BaseGoogleDocsTool {
|
|||
|
||||
return createResponse
|
||||
} catch (error) {
|
||||
return `Error creating document: ${error}`
|
||||
return formatToolError(`Error creating document: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -288,7 +288,7 @@ class GetDocumentTool extends BaseGoogleDocsTool {
|
|||
const response = await this.makeGoogleDocsRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting document: ${error}`
|
||||
return formatToolError(`Error getting document: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -381,7 +381,7 @@ class UpdateDocumentTool extends BaseGoogleDocsTool {
|
|||
return `No updates specified` + TOOL_ARGS_PREFIX + JSON.stringify(params)
|
||||
}
|
||||
} catch (error) {
|
||||
return `Error updating document: ${error}`
|
||||
return formatToolError(`Error updating document: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -429,7 +429,7 @@ class InsertTextTool extends BaseGoogleDocsTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error inserting text: ${error}`
|
||||
return formatToolError(`Error inserting text: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -478,7 +478,7 @@ class ReplaceTextTool extends BaseGoogleDocsTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error replacing text: ${error}`
|
||||
return formatToolError(`Error replacing text: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -534,7 +534,7 @@ class AppendTextTool extends BaseGoogleDocsTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error appending text: ${error}`
|
||||
return formatToolError(`Error appending text: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -583,7 +583,7 @@ class GetTextContentTool extends BaseGoogleDocsTool {
|
|||
|
||||
return JSON.stringify({ textContent }) + TOOL_ARGS_PREFIX + JSON.stringify(params)
|
||||
} catch (error) {
|
||||
return `Error getting text content: ${error}`
|
||||
return formatToolError(`Error getting text content: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -631,7 +631,7 @@ class InsertImageTool extends BaseGoogleDocsTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error inserting image: ${error}`
|
||||
return formatToolError(`Error inserting image: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -680,7 +680,7 @@ class CreateTableTool extends BaseGoogleDocsTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating table: ${error}`
|
||||
return formatToolError(`Error creating table: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Google Drive API for managing files and folders`
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ class ListFilesTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing files: ${error}`
|
||||
return formatToolError(`Error listing files: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -240,7 +240,7 @@ class GetFileTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting file: ${error}`
|
||||
return formatToolError(`Error getting file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -323,7 +323,7 @@ class CreateFileTool extends BaseGoogleDriveTool {
|
|||
}
|
||||
}
|
||||
} catch (error) {
|
||||
return `Error creating file: ${error}`
|
||||
return formatToolError(`Error creating file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -452,7 +452,7 @@ class UpdateFileTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating file: ${error}`
|
||||
return formatToolError(`Error updating file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -492,7 +492,7 @@ class DeleteFileTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return `File deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting file: ${error}`
|
||||
return formatToolError(`Error deleting file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -541,7 +541,7 @@ class CopyFileTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error copying file: ${error}`
|
||||
return formatToolError(`Error copying file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -579,7 +579,7 @@ class DownloadFileTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error downloading file: ${error}`
|
||||
return formatToolError(`Error downloading file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -630,7 +630,7 @@ class CreateFolderTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating folder: ${error}`
|
||||
return formatToolError(`Error creating folder: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -671,7 +671,7 @@ class SearchFilesTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error searching files: ${error}`
|
||||
return formatToolError(`Error searching files: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -724,7 +724,7 @@ class ShareFileTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error sharing file: ${error}`
|
||||
return formatToolError(`Error sharing file: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -774,7 +774,7 @@ class ListFolderContentsTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing folder contents: ${error}`
|
||||
return formatToolError(`Error listing folder contents: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -820,7 +820,7 @@ class DeleteFolderTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return `Folder deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting folder: ${error}`
|
||||
return formatToolError(`Error deleting folder: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -862,7 +862,7 @@ class GetPermissionsTool extends BaseGoogleDriveTool {
|
|||
const response = await this.makeGoogleDriveRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting permissions: ${error}`
|
||||
return formatToolError(`Error getting permissions: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -911,7 +911,7 @@ class RemovePermissionTool extends BaseGoogleDriveTool {
|
|||
})
|
||||
return `Permission removed successfully`
|
||||
} catch (error) {
|
||||
return `Error removing permission: ${error}`
|
||||
return formatToolError(`Error removing permission: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Google Sheets API for managing spreadsheets and values`
|
||||
|
||||
|
|
@ -183,33 +183,37 @@ class CreateSpreadsheetTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const body: any = {
|
||||
properties: {
|
||||
title: params.title
|
||||
try {
|
||||
const body: any = {
|
||||
properties: {
|
||||
title: params.title
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (params.locale) body.properties.locale = params.locale
|
||||
if (params.timeZone) body.properties.timeZone = params.timeZone
|
||||
if (params.locale) body.properties.locale = params.locale
|
||||
if (params.timeZone) body.properties.timeZone = params.timeZone
|
||||
|
||||
// Add sheets if specified
|
||||
if (params.sheetCount && params.sheetCount > 1) {
|
||||
body.sheets = []
|
||||
for (let i = 0; i < params.sheetCount; i++) {
|
||||
body.sheets.push({
|
||||
properties: {
|
||||
title: i === 0 ? 'Sheet1' : `Sheet${i + 1}`
|
||||
}
|
||||
})
|
||||
// Add sheets if specified
|
||||
if (params.sheetCount && params.sheetCount > 1) {
|
||||
body.sheets = []
|
||||
for (let i = 0; i < params.sheetCount; i++) {
|
||||
body.sheets.push({
|
||||
properties: {
|
||||
title: i === 0 ? 'Sheet1' : `Sheet${i + 1}`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: 'spreadsheets',
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: 'spreadsheets',
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error creating spreadsheet: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -234,23 +238,28 @@ class GetSpreadsheetTool extends BaseGoogleSheetsTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.ranges) {
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
try {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.ranges) {
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
})
|
||||
}
|
||||
if (params.includeGridData) queryParams.append('includeGridData', 'true')
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}${queryString ? `?${queryString}` : ''}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error getting spreadsheet: ${error}`, params)
|
||||
}
|
||||
if (params.includeGridData) queryParams.append('includeGridData', 'true')
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}${queryString ? `?${queryString}` : ''}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,29 +285,33 @@ class UpdateSpreadsheetTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const requests = []
|
||||
if (params.title || params.locale || params.timeZone) {
|
||||
const updateProperties: any = {}
|
||||
if (params.title) updateProperties.title = params.title
|
||||
if (params.locale) updateProperties.locale = params.locale
|
||||
if (params.timeZone) updateProperties.timeZone = params.timeZone
|
||||
try {
|
||||
const requests = []
|
||||
if (params.title || params.locale || params.timeZone) {
|
||||
const updateProperties: any = {}
|
||||
if (params.title) updateProperties.title = params.title
|
||||
if (params.locale) updateProperties.locale = params.locale
|
||||
if (params.timeZone) updateProperties.timeZone = params.timeZone
|
||||
|
||||
requests.push({
|
||||
updateSpreadsheetProperties: {
|
||||
properties: updateProperties,
|
||||
fields: Object.keys(updateProperties).join(',')
|
||||
}
|
||||
requests.push({
|
||||
updateSpreadsheetProperties: {
|
||||
properties: updateProperties,
|
||||
fields: Object.keys(updateProperties).join(',')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const body = { requests }
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: `spreadsheets/${params.spreadsheetId}:batchUpdate`,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error updating spreadsheet: ${error}`, params)
|
||||
}
|
||||
|
||||
const body = { requests }
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint: `spreadsheets/${params.spreadsheetId}:batchUpdate`,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -324,21 +337,26 @@ class GetValuesTool extends BaseGoogleSheetsTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
try {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}${queryString ? `?${queryString}` : ''}`
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
const queryString = queryParams.toString()
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}${queryString ? `?${queryString}` : ''}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error getting values: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -364,30 +382,34 @@ class UpdateValuesTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'PUT',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
return formatToolError(`Error updating values: ${error}`, params)
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'PUT',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -413,31 +435,35 @@ class AppendValuesTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
let values
|
||||
try {
|
||||
values = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
queryParams.append('insertDataOption', params.insertDataOption || 'OVERWRITE')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:append?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array')
|
||||
return formatToolError(`Error appending values: ${error}`, params)
|
||||
}
|
||||
|
||||
const body = {
|
||||
values,
|
||||
majorDimension: params.majorDimension || 'ROWS'
|
||||
}
|
||||
|
||||
const queryParams = new URLSearchParams()
|
||||
queryParams.append('valueInputOption', params.valueInputOption || 'USER_ENTERED')
|
||||
queryParams.append('insertDataOption', params.insertDataOption || 'OVERWRITE')
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:append?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -463,15 +489,19 @@ class ClearValuesTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:clear`
|
||||
try {
|
||||
const encodedRange = encodeURIComponent(params.range)
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:clear`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body: {},
|
||||
params
|
||||
})
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body: {},
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error clearing values: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,24 +526,29 @@ class BatchGetValuesTool extends BaseGoogleSheetsTool {
|
|||
|
||||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
// Add ranges
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
})
|
||||
try {
|
||||
const queryParams = new URLSearchParams()
|
||||
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
// Add ranges
|
||||
params.ranges.split(',').forEach((range: string) => {
|
||||
queryParams.append('ranges', range.trim())
|
||||
})
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchGet?${queryParams.toString()}`
|
||||
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
|
||||
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
|
||||
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchGet?${queryParams.toString()}`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error batch getting values: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -539,27 +574,31 @@ class BatchUpdateValuesTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
let valueRanges
|
||||
try {
|
||||
valueRanges = JSON.parse(params.values)
|
||||
let valueRanges
|
||||
try {
|
||||
valueRanges = JSON.parse(params.values)
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array of value ranges')
|
||||
}
|
||||
|
||||
const body = {
|
||||
valueInputOption: params.valueInputOption || 'USER_ENTERED',
|
||||
data: valueRanges,
|
||||
includeValuesInResponse: params.includeValuesInResponse || false
|
||||
}
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchUpdate`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error('Values must be a valid JSON array of value ranges')
|
||||
return formatToolError(`Error batch updating values: ${error}`, params)
|
||||
}
|
||||
|
||||
const body = {
|
||||
valueInputOption: params.valueInputOption || 'USER_ENTERED',
|
||||
data: valueRanges,
|
||||
includeValuesInResponse: params.includeValuesInResponse || false
|
||||
}
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchUpdate`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -585,17 +624,21 @@ class BatchClearValuesTool extends BaseGoogleSheetsTool {
|
|||
async _call(arg: any): Promise<string> {
|
||||
const params = { ...arg, ...this.defaultParams }
|
||||
|
||||
const ranges = params.ranges.split(',').map((range: string) => range.trim())
|
||||
const body = { ranges }
|
||||
try {
|
||||
const ranges = params.ranges.split(',').map((range: string) => range.trim())
|
||||
const body = { ranges }
|
||||
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchClear`
|
||||
const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchClear`
|
||||
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
return await this.makeGoogleSheetsRequest({
|
||||
endpoint,
|
||||
method: 'POST',
|
||||
body,
|
||||
params
|
||||
})
|
||||
} catch (error) {
|
||||
return formatToolError(`Error batch clearing values: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Jira API for managing issues, comments, and users`
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ class ListIssuesTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing issues: ${error}`
|
||||
return formatToolError(`Error listing issues: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -302,7 +302,7 @@ class CreateIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint: 'issue', method: 'POST', body: issueData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating issue: ${error}`
|
||||
return formatToolError(`Error creating issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -337,7 +337,7 @@ class GetIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting issue: ${error}`
|
||||
return formatToolError(`Error getting issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -405,7 +405,7 @@ class UpdateIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: updateData, params })
|
||||
return response || 'Issue updated successfully'
|
||||
} catch (error) {
|
||||
return `Error updating issue: ${error}`
|
||||
return formatToolError(`Error updating issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,7 +440,7 @@ class DeleteIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
|
||||
return response || 'Issue deleted successfully'
|
||||
} catch (error) {
|
||||
return `Error deleting issue: ${error}`
|
||||
return formatToolError(`Error deleting issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -479,7 +479,7 @@ class AssignIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: assignData, params })
|
||||
return response || 'Issue assigned successfully'
|
||||
} catch (error) {
|
||||
return `Error assigning issue: ${error}`
|
||||
return formatToolError(`Error assigning issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -520,7 +520,7 @@ class TransitionIssueTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: transitionData, params })
|
||||
return response || 'Issue transitioned successfully'
|
||||
} catch (error) {
|
||||
return `Error transitioning issue: ${error}`
|
||||
return formatToolError(`Error transitioning issue: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -561,7 +561,7 @@ class ListCommentsTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing comments: ${error}`
|
||||
return formatToolError(`Error listing comments: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -618,7 +618,7 @@ class CreateCommentTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: commentData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating comment: ${error}`
|
||||
return formatToolError(`Error creating comment: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -653,7 +653,7 @@ class GetCommentTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting comment: ${error}`
|
||||
return formatToolError(`Error getting comment: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -706,7 +706,7 @@ class UpdateCommentTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: commentData, params })
|
||||
return response || 'Comment updated successfully'
|
||||
} catch (error) {
|
||||
return `Error updating comment: ${error}`
|
||||
return formatToolError(`Error updating comment: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -741,7 +741,7 @@ class DeleteCommentTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
|
||||
return response || 'Comment deleted successfully'
|
||||
} catch (error) {
|
||||
return `Error deleting comment: ${error}`
|
||||
return formatToolError(`Error deleting comment: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -783,7 +783,7 @@ class SearchUsersTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error searching users: ${error}`
|
||||
return formatToolError(`Error searching users: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -822,7 +822,7 @@ class GetUserTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting user: ${error}`
|
||||
return formatToolError(`Error getting user: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -866,7 +866,7 @@ class CreateUserTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: userData, params })
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating user: ${error}`
|
||||
return formatToolError(`Error creating user: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -909,7 +909,7 @@ class UpdateUserTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: userData, params })
|
||||
return response || 'User updated successfully'
|
||||
} catch (error) {
|
||||
return `Error updating user: ${error}`
|
||||
return formatToolError(`Error updating user: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -947,7 +947,7 @@ class DeleteUserTool extends BaseJiraTool {
|
|||
const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
|
||||
return response || 'User deleted successfully'
|
||||
} catch (error) {
|
||||
return `Error deleting user: ${error}`
|
||||
return formatToolError(`Error deleting user: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -969,7 +969,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.listIssues
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -981,7 +981,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.createIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -993,7 +993,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.getIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1005,7 +1005,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.updateIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1017,7 +1017,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.deleteIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1029,7 +1029,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.assignIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1041,7 +1041,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.transitionIssue
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1054,7 +1054,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.listComments
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1066,7 +1066,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.createComment
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1078,7 +1078,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.getComment
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1090,7 +1090,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.updateComment
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1102,7 +1102,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.deleteComment
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1115,7 +1115,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.searchUsers
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1127,7 +1127,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.getUser
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1139,7 +1139,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.createUser
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1151,7 +1151,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.updateUser
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
@ -1163,7 +1163,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
|
|||
accessToken,
|
||||
jiraHost,
|
||||
maxOutputLength,
|
||||
defaultParams: defaultParams.deleteUser
|
||||
defaultParams
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod'
|
||||
import fetch from 'node-fetch'
|
||||
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
|
||||
import { TOOL_ARGS_PREFIX } from '../../../src/agents'
|
||||
import { TOOL_ARGS_PREFIX, formatToolError } from '../../../src/agents'
|
||||
|
||||
export const desc = `Use this when you want to access Microsoft Outlook API for managing calendars, events, and messages`
|
||||
|
||||
|
|
@ -201,7 +201,7 @@ class ListCalendarsTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing calendars: ${error}`
|
||||
return formatToolError(`Error listing calendars: ${error}`, {})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -230,7 +230,7 @@ class GetCalendarTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting calendar: ${error}`
|
||||
return formatToolError(`Error getting calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ class CreateCalendarTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'POST', calendarData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating calendar: ${error}`
|
||||
return formatToolError(`Error creating calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ class UpdateCalendarTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'PATCH', calendarData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating calendar: ${error}`
|
||||
return formatToolError(`Error updating calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -325,7 +325,7 @@ class DeleteCalendarTool extends BaseOutlookTool {
|
|||
await this.makeGraphRequest(url, 'DELETE', undefined, params)
|
||||
return `Calendar ${params.calendarId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting calendar: ${error}`
|
||||
return formatToolError(`Error deleting calendar: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -372,7 +372,7 @@ class ListEventsTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing events: ${error}`
|
||||
return formatToolError(`Error listing events: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -401,7 +401,7 @@ class GetEventTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting event: ${error}`
|
||||
return formatToolError(`Error getting event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -452,7 +452,7 @@ class CreateEventTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'POST', eventData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating event: ${error}`
|
||||
return formatToolError(`Error creating event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -484,7 +484,7 @@ class UpdateEventTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'PATCH', eventData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating event: ${error}`
|
||||
return formatToolError(`Error updating event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -513,7 +513,7 @@ class DeleteEventTool extends BaseOutlookTool {
|
|||
await this.makeGraphRequest(url, 'DELETE', undefined, params)
|
||||
return `Event ${params.eventId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting event: ${error}`
|
||||
return formatToolError(`Error deleting event: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -548,7 +548,7 @@ class ListMessagesTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error listing messages: ${error}`
|
||||
return formatToolError(`Error listing messages: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -577,7 +577,7 @@ class GetMessageTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'GET', undefined, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error getting message: ${error}`
|
||||
return formatToolError(`Error getting message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -617,7 +617,7 @@ class CreateDraftMessageTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'POST', messageData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error creating draft message: ${error}`
|
||||
return formatToolError(`Error creating draft message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -658,7 +658,7 @@ class SendMessageTool extends BaseOutlookTool {
|
|||
await this.makeGraphRequest(url, 'POST', messageData, params)
|
||||
return 'Message sent successfully'
|
||||
} catch (error) {
|
||||
return `Error sending message: ${error}`
|
||||
return formatToolError(`Error sending message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -690,7 +690,7 @@ class UpdateMessageTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'PATCH', messageData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error updating message: ${error}`
|
||||
return formatToolError(`Error updating message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -719,7 +719,7 @@ class DeleteMessageTool extends BaseOutlookTool {
|
|||
await this.makeGraphRequest(url, 'DELETE', undefined, params)
|
||||
return `Message ${params.messageId} deleted successfully`
|
||||
} catch (error) {
|
||||
return `Error deleting message: ${error}`
|
||||
return formatToolError(`Error deleting message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -752,7 +752,7 @@ class CopyMessageTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'POST', copyData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error copying message: ${error}`
|
||||
return formatToolError(`Error copying message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -785,7 +785,7 @@ class MoveMessageTool extends BaseOutlookTool {
|
|||
const response = await this.makeGraphRequest(url, 'POST', moveData, params)
|
||||
return response
|
||||
} catch (error) {
|
||||
return `Error moving message: ${error}`
|
||||
return formatToolError(`Error moving message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -818,7 +818,7 @@ class ReplyMessageTool extends BaseOutlookTool {
|
|||
await this.makeGraphRequest(url, 'POST', replyData, params)
|
||||
return 'Reply sent successfully'
|
||||
} catch (error) {
|
||||
return `Error replying to message: ${error}`
|
||||
return formatToolError(`Error replying to message: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -865,163 +865,103 @@ export const createOutlookTools = (args?: RequestParameters): DynamicStructuredT
|
|||
|
||||
// Calendar tools
|
||||
if (actions.includes('listCalendars')) {
|
||||
const listTool = new ListCalendarsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listCalendars
|
||||
})
|
||||
const listTool = new ListCalendarsTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getCalendar')) {
|
||||
const getTool = new GetCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getCalendar
|
||||
})
|
||||
const getTool = new GetCalendarTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('createCalendar')) {
|
||||
const createTool = new CreateCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createCalendar
|
||||
})
|
||||
const createTool = new CreateCalendarTool({ accessToken, defaultParams })
|
||||
tools.push(createTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateCalendar')) {
|
||||
const updateTool = new UpdateCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateCalendar
|
||||
})
|
||||
const updateTool = new UpdateCalendarTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteCalendar')) {
|
||||
const deleteTool = new DeleteCalendarTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteCalendar
|
||||
})
|
||||
const deleteTool = new DeleteCalendarTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
if (actions.includes('listEvents')) {
|
||||
const listTool = new ListEventsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listEvents
|
||||
})
|
||||
const listTool = new ListEventsTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getEvent')) {
|
||||
const getTool = new GetEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getEvent
|
||||
})
|
||||
const getTool = new GetEventTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('createEvent')) {
|
||||
const createTool = new CreateEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createEvent
|
||||
})
|
||||
const createTool = new CreateEventTool({ accessToken, defaultParams })
|
||||
tools.push(createTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateEvent')) {
|
||||
const updateTool = new UpdateEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateEvent
|
||||
})
|
||||
const updateTool = new UpdateEventTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteEvent')) {
|
||||
const deleteTool = new DeleteEventTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteEvent
|
||||
})
|
||||
const deleteTool = new DeleteEventTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
// Message tools
|
||||
if (actions.includes('listMessages')) {
|
||||
const listTool = new ListMessagesTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listMessages
|
||||
})
|
||||
const listTool = new ListMessagesTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getMessage')) {
|
||||
const getTool = new GetMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getMessage
|
||||
})
|
||||
const getTool = new GetMessageTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('createDraftMessage')) {
|
||||
const createTool = new CreateDraftMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createDraftMessage
|
||||
})
|
||||
const createTool = new CreateDraftMessageTool({ accessToken, defaultParams })
|
||||
tools.push(createTool)
|
||||
}
|
||||
|
||||
if (actions.includes('sendMessage')) {
|
||||
const sendTool = new SendMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.sendMessage
|
||||
})
|
||||
const sendTool = new SendMessageTool({ accessToken, defaultParams })
|
||||
tools.push(sendTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateMessage')) {
|
||||
const updateTool = new UpdateMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateMessage
|
||||
})
|
||||
const updateTool = new UpdateMessageTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteMessage')) {
|
||||
const deleteTool = new DeleteMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteMessage
|
||||
})
|
||||
const deleteTool = new DeleteMessageTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
if (actions.includes('copyMessage')) {
|
||||
const copyTool = new CopyMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.copyMessage
|
||||
})
|
||||
const copyTool = new CopyMessageTool({ accessToken, defaultParams })
|
||||
tools.push(copyTool)
|
||||
}
|
||||
|
||||
if (actions.includes('moveMessage')) {
|
||||
const moveTool = new MoveMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.moveMessage
|
||||
})
|
||||
const moveTool = new MoveMessageTool({ accessToken, defaultParams })
|
||||
tools.push(moveTool)
|
||||
}
|
||||
|
||||
if (actions.includes('replyMessage')) {
|
||||
const replyTool = new ReplyMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.replyMessage
|
||||
})
|
||||
const replyTool = new ReplyMessageTool({ accessToken, defaultParams })
|
||||
tools.push(replyTool)
|
||||
}
|
||||
|
||||
if (actions.includes('forwardMessage')) {
|
||||
const forwardTool = new ForwardMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.forwardMessage
|
||||
})
|
||||
const forwardTool = new ForwardMessageTool({ accessToken, defaultParams })
|
||||
tools.push(forwardTool)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class ListChannelsTool extends BaseTeamsTool {
|
|||
|
||||
return this.formatResponse(responseData, params)
|
||||
} catch (error) {
|
||||
return `Error listing channels: ${error}`
|
||||
return this.formatResponse(`Error listing channels: ${error}`, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1519,236 +1519,149 @@ export function createTeamsTools(options: TeamsToolOptions): DynamicStructuredTo
|
|||
|
||||
// Channel tools
|
||||
if (actions.includes('listChannels')) {
|
||||
const listTool = new ListChannelsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listChannels
|
||||
})
|
||||
const listTool = new ListChannelsTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getChannel')) {
|
||||
const getTool = new GetChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getChannel
|
||||
})
|
||||
const getTool = new GetChannelTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('createChannel')) {
|
||||
const createTool = new CreateChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createChannel
|
||||
})
|
||||
const createTool = new CreateChannelTool({ accessToken, defaultParams })
|
||||
tools.push(createTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateChannel')) {
|
||||
const updateTool = new UpdateChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateChannel
|
||||
})
|
||||
const updateTool = new UpdateChannelTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteChannel')) {
|
||||
const deleteTool = new DeleteChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteChannel
|
||||
})
|
||||
const deleteTool = new DeleteChannelTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
if (actions.includes('archiveChannel')) {
|
||||
const archiveTool = new ArchiveChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.archiveChannel
|
||||
})
|
||||
const archiveTool = new ArchiveChannelTool({ accessToken, defaultParams })
|
||||
tools.push(archiveTool)
|
||||
}
|
||||
|
||||
if (actions.includes('unarchiveChannel')) {
|
||||
const unarchiveTool = new UnarchiveChannelTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.unarchiveChannel
|
||||
})
|
||||
const unarchiveTool = new UnarchiveChannelTool({ accessToken, defaultParams })
|
||||
tools.push(unarchiveTool)
|
||||
}
|
||||
|
||||
if (actions.includes('listChannelMembers')) {
|
||||
const listMembersTool = new ListChannelMembersTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listChannelMembers
|
||||
})
|
||||
const listMembersTool = new ListChannelMembersTool({ accessToken, defaultParams })
|
||||
tools.push(listMembersTool)
|
||||
}
|
||||
|
||||
if (actions.includes('addChannelMember')) {
|
||||
const addMemberTool = new AddChannelMemberTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.addChannelMember
|
||||
})
|
||||
const addMemberTool = new AddChannelMemberTool({ accessToken, defaultParams })
|
||||
tools.push(addMemberTool)
|
||||
}
|
||||
|
||||
if (actions.includes('removeChannelMember')) {
|
||||
const removeMemberTool = new RemoveChannelMemberTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.removeChannelMember
|
||||
})
|
||||
const removeMemberTool = new RemoveChannelMemberTool({ accessToken, defaultParams })
|
||||
tools.push(removeMemberTool)
|
||||
}
|
||||
|
||||
// Chat tools
|
||||
if (actions.includes('listChats')) {
|
||||
const listTool = new ListChatsTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listChats
|
||||
})
|
||||
const listTool = new ListChatsTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getChat')) {
|
||||
const getTool = new GetChatTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getChat
|
||||
})
|
||||
const getTool = new GetChatTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('createChat')) {
|
||||
const createTool = new CreateChatTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.createChat
|
||||
})
|
||||
const createTool = new CreateChatTool({ accessToken, defaultParams })
|
||||
tools.push(createTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateChat')) {
|
||||
const updateTool = new UpdateChatTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateChat
|
||||
})
|
||||
const updateTool = new UpdateChatTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteChat')) {
|
||||
const deleteTool = new DeleteChatTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteChat
|
||||
})
|
||||
const deleteTool = new DeleteChatTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
if (actions.includes('listChatMembers')) {
|
||||
const listMembersTool = new ListChatMembersTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listChatMembers
|
||||
})
|
||||
const listMembersTool = new ListChatMembersTool({ accessToken, defaultParams })
|
||||
tools.push(listMembersTool)
|
||||
}
|
||||
|
||||
if (actions.includes('addChatMember')) {
|
||||
const addMemberTool = new AddChatMemberTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.addChatMember
|
||||
})
|
||||
const addMemberTool = new AddChatMemberTool({ accessToken, defaultParams })
|
||||
tools.push(addMemberTool)
|
||||
}
|
||||
|
||||
if (actions.includes('removeChatMember')) {
|
||||
const removeMemberTool = new RemoveChatMemberTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.removeChatMember
|
||||
})
|
||||
const removeMemberTool = new RemoveChatMemberTool({ accessToken, defaultParams })
|
||||
tools.push(removeMemberTool)
|
||||
}
|
||||
|
||||
if (actions.includes('pinMessage')) {
|
||||
const pinTool = new PinMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.pinMessage
|
||||
})
|
||||
const pinTool = new PinMessageTool({ accessToken, defaultParams })
|
||||
tools.push(pinTool)
|
||||
}
|
||||
|
||||
if (actions.includes('unpinMessage')) {
|
||||
const unpinTool = new UnpinMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.unpinMessage
|
||||
})
|
||||
const unpinTool = new UnpinMessageTool({ accessToken, defaultParams })
|
||||
tools.push(unpinTool)
|
||||
}
|
||||
|
||||
// Chat message tools
|
||||
if (actions.includes('listMessages')) {
|
||||
const listTool = new ListMessagesTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.listMessages
|
||||
})
|
||||
const listTool = new ListMessagesTool({ accessToken, defaultParams })
|
||||
tools.push(listTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getMessage')) {
|
||||
const getTool = new GetMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getMessage
|
||||
})
|
||||
const getTool = new GetMessageTool({ accessToken, defaultParams })
|
||||
tools.push(getTool)
|
||||
}
|
||||
|
||||
if (actions.includes('sendMessage')) {
|
||||
const sendTool = new SendMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.sendMessage
|
||||
})
|
||||
const sendTool = new SendMessageTool({ accessToken, defaultParams })
|
||||
tools.push(sendTool)
|
||||
}
|
||||
|
||||
if (actions.includes('updateMessage')) {
|
||||
const updateTool = new UpdateMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.updateMessage
|
||||
})
|
||||
const updateTool = new UpdateMessageTool({ accessToken, defaultParams })
|
||||
tools.push(updateTool)
|
||||
}
|
||||
|
||||
if (actions.includes('deleteMessage')) {
|
||||
const deleteTool = new DeleteMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.deleteMessage
|
||||
})
|
||||
const deleteTool = new DeleteMessageTool({ accessToken, defaultParams })
|
||||
tools.push(deleteTool)
|
||||
}
|
||||
|
||||
if (actions.includes('replyToMessage')) {
|
||||
const replyTool = new ReplyToMessageTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.replyToMessage
|
||||
})
|
||||
const replyTool = new ReplyToMessageTool({ accessToken, defaultParams })
|
||||
tools.push(replyTool)
|
||||
}
|
||||
|
||||
if (actions.includes('setReaction')) {
|
||||
const reactionTool = new SetReactionTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.setReaction
|
||||
})
|
||||
const reactionTool = new SetReactionTool({ accessToken, defaultParams })
|
||||
tools.push(reactionTool)
|
||||
}
|
||||
|
||||
if (actions.includes('unsetReaction')) {
|
||||
const unsetReactionTool = new UnsetReactionTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.unsetReaction
|
||||
})
|
||||
const unsetReactionTool = new UnsetReactionTool({ accessToken, defaultParams })
|
||||
tools.push(unsetReactionTool)
|
||||
}
|
||||
|
||||
if (actions.includes('getAllMessages')) {
|
||||
const getAllTool = new GetAllMessagesTool({
|
||||
accessToken,
|
||||
defaultParams: defaultParams.getAllMessages
|
||||
})
|
||||
const getAllTool = new GetAllMessagesTool({ accessToken, defaultParams })
|
||||
tools.push(getAllTool)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -253,10 +253,14 @@ export class DynamicStructuredTool<
|
|||
|
||||
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
||||
|
||||
const response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox, {
|
||||
let response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox, {
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
if (typeof response === 'object') {
|
||||
response = JSON.stringify(response)
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@
|
|||
"ioredis": "^5.3.2",
|
||||
"ipaddr.js": "^2.2.0",
|
||||
"jsdom": "^22.1.0",
|
||||
"json5": "2.2.3",
|
||||
"jsonpointer": "^5.0.1",
|
||||
"jsonrepair": "^3.11.1",
|
||||
"langchain": "^0.3.5",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,16 @@ export const SOURCE_DOCUMENTS_PREFIX = '\n\n----FLOWISE_SOURCE_DOCUMENTS----\n\n
|
|||
export const ARTIFACTS_PREFIX = '\n\n----FLOWISE_ARTIFACTS----\n\n'
|
||||
export const TOOL_ARGS_PREFIX = '\n\n----FLOWISE_TOOL_ARGS----\n\n'
|
||||
|
||||
/**
|
||||
* Utility function to format tool error messages with parameters for debugging
|
||||
* @param errorMessage - The base error message
|
||||
* @param params - The parameters that were passed to the tool
|
||||
* @returns Formatted error message with tool arguments appended
|
||||
*/
|
||||
export const formatToolError = (errorMessage: string, params: any): string => {
|
||||
return errorMessage + TOOL_ARGS_PREFIX + JSON.stringify(params)
|
||||
}
|
||||
|
||||
export type AgentFinish = {
|
||||
returnValues: Record<string, any>
|
||||
log: string
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import { TextSplitter } from 'langchain/text_splitter'
|
|||
import { DocumentLoader } from 'langchain/document_loaders/base'
|
||||
import { NodeVM } from '@flowiseai/nodevm'
|
||||
import { Sandbox } from '@e2b/code-interpreter'
|
||||
import JSON5 from 'json5'
|
||||
|
||||
export const numberOrExpressionRegex = '^(\\d+\\.?\\d*|{{.*}})$' //return true if string consists only numbers OR expression {{}}
|
||||
export const notEmptyRegex = '(.|\\s)*\\S(.|\\s)*' //return true if string is not empty or blank
|
||||
|
|
@ -1382,6 +1383,39 @@ const convertRequireToImport = (requireLine: string): string | null => {
|
|||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse output if it's a stringified JSON or array
|
||||
* @param {any} output - The output to parse
|
||||
* @returns {any} - The parsed output or original output if not parseable
|
||||
*/
|
||||
const parseOutput = (output: any): any => {
|
||||
// If output is not a string, return as-is
|
||||
if (typeof output !== 'string') {
|
||||
return output
|
||||
}
|
||||
|
||||
// Trim whitespace
|
||||
const trimmedOutput = output.trim()
|
||||
|
||||
// Check if it's an empty string
|
||||
if (!trimmedOutput) {
|
||||
return output
|
||||
}
|
||||
|
||||
// Check if it looks like JSON (starts with { or [)
|
||||
if ((trimmedOutput.startsWith('{') && trimmedOutput.endsWith('}')) || (trimmedOutput.startsWith('[') && trimmedOutput.endsWith(']'))) {
|
||||
try {
|
||||
const parsedOutput = JSON5.parse(trimmedOutput)
|
||||
return parsedOutput
|
||||
} catch (e) {
|
||||
return output
|
||||
}
|
||||
}
|
||||
|
||||
// Return the original string if it doesn't look like JSON
|
||||
return output
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute JavaScript code using either Sandbox or NodeVM
|
||||
* @param {string} code - The JavaScript code to execute
|
||||
|
|
@ -1497,7 +1531,7 @@ export const executeJavaScriptCode = async (
|
|||
// Clean up sandbox
|
||||
sbx.kill()
|
||||
|
||||
return output
|
||||
return parseOutput(output)
|
||||
} catch (e) {
|
||||
throw new Error(`Sandbox Execution Error: ${e}`)
|
||||
}
|
||||
|
|
@ -1529,16 +1563,17 @@ export const executeJavaScriptCode = async (
|
|||
const response = await vm.run(`module.exports = async function() {${code}}()`, __dirname)
|
||||
|
||||
let finalOutput = response
|
||||
if (typeof response === 'object') {
|
||||
finalOutput = JSON.stringify(response, null, 2)
|
||||
}
|
||||
|
||||
// Stream output if streaming function provided
|
||||
if (streamOutput && finalOutput) {
|
||||
streamOutput(finalOutput)
|
||||
let streamOutputString = finalOutput
|
||||
if (typeof response === 'object') {
|
||||
streamOutputString = JSON.stringify(finalOutput, null, 2)
|
||||
}
|
||||
streamOutput(streamOutputString)
|
||||
}
|
||||
|
||||
return finalOutput
|
||||
return parseOutput(finalOutput)
|
||||
} catch (e) {
|
||||
throw new Error(`NodeVM Execution Error: ${e}`)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,9 +167,10 @@ const CustomAssistantConfigurePreview = () => {
|
|||
|
||||
const checkInputParamsMandatory = () => {
|
||||
let canSubmit = true
|
||||
|
||||
const inputParams = (selectedChatModel.inputParams ?? []).filter((inputParam) => !inputParam.hidden)
|
||||
for (const inputParam of inputParams) {
|
||||
const visibleInputParams = showHideInputParams(selectedChatModel).filter(
|
||||
(inputParam) => !inputParam.hidden && inputParam.display !== false
|
||||
)
|
||||
for (const inputParam of visibleInputParams) {
|
||||
if (!inputParam.optional && (!selectedChatModel.inputs[inputParam.name] || !selectedChatModel.credential)) {
|
||||
if (inputParam.type === 'credential' && !selectedChatModel.credential) {
|
||||
canSubmit = false
|
||||
|
|
@ -184,8 +185,10 @@ const CustomAssistantConfigurePreview = () => {
|
|||
if (selectedTools.length > 0) {
|
||||
for (let i = 0; i < selectedTools.length; i++) {
|
||||
const tool = selectedTools[i]
|
||||
const inputParams = (tool.inputParams ?? []).filter((inputParam) => !inputParam.hidden)
|
||||
for (const inputParam of inputParams) {
|
||||
const visibleInputParams = showHideInputParams(tool).filter(
|
||||
(inputParam) => !inputParam.hidden && inputParam.display !== false
|
||||
)
|
||||
for (const inputParam of visibleInputParams) {
|
||||
if (!inputParam.optional && (!tool.inputs[inputParam.name] || !tool.credential)) {
|
||||
if (inputParam.type === 'credential' && !tool.credential) {
|
||||
canSubmit = false
|
||||
|
|
|
|||
|
|
@ -375,6 +375,9 @@ importers:
|
|||
jsdom:
|
||||
specifier: ^22.1.0
|
||||
version: 22.1.0(bufferutil@4.0.8)(canvas@2.11.2(encoding@0.1.13))(utf-8-validate@6.0.4)
|
||||
json5:
|
||||
specifier: 2.2.3
|
||||
version: 2.2.3
|
||||
jsonpointer:
|
||||
specifier: ^5.0.1
|
||||
version: 5.0.1
|
||||
|
|
|
|||
Loading…
Reference in New Issue