Compare commits

...

6 Commits

Author SHA1 Message Date
Henry c6f8e365f1 azure chatopenai use maxCompletionTokens 2025-09-11 19:01:01 +01:00
Henry 8fd7b9350f add json5 for parsing 2025-09-11 17:36:17 +01:00
Henry bb7c1f62cb return raw from executeJavaScriptCode 2025-09-11 01:30:01 +01:00
Henry f1afdfa256 azure chat openai fix for gpt5 2025-09-11 01:04:57 +01:00
Henry e9cf0478b6 custom assistant only check for mandatory fields for visible params 2025-09-11 00:57:29 +01:00
Henry 5c034199bc fix gsuite tool params 2025-09-10 21:26:28 +01:00
19 changed files with 541 additions and 736 deletions

View File

@ -1723,9 +1723,20 @@ class Agent_Agentflow implements INode {
} }
console.error('Error invoking tool:', e) 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({ usedTools.push({
tool: selectedTool.name, tool: selectedTool.name,
toolInput: toolCall.args, toolInput,
toolOutput: '', toolOutput: '',
error: getErrorMessage(e) error: getErrorMessage(e)
}) })
@ -1995,9 +2006,20 @@ class Agent_Agentflow implements INode {
} }
console.error('Error invoking tool:', e) 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({ usedTools.push({
tool: selectedTool.name, tool: selectedTool.name,
toolInput: toolCall.args, toolInput,
toolOutput: '', toolOutput: '',
error: getErrorMessage(e) error: getErrorMessage(e)
}) })

View File

@ -273,10 +273,9 @@ class AzureChatOpenAI_ChatModels implements INode {
console.error('Error parsing base options', exception) 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 delete obj.temperature
} delete obj.stop
if (modelName.includes('o1') || modelName.includes('o3')) {
const reasoning: OpenAIClient.Reasoning = {} const reasoning: OpenAIClient.Reasoning = {}
if (reasoningEffort) { if (reasoningEffort) {
reasoning.effort = reasoningEffort reasoning.effort = reasoningEffort
@ -285,6 +284,11 @@ class AzureChatOpenAI_ChatModels implements INode {
reasoning.summary = reasoningSummary reasoning.summary = reasoningSummary
} }
obj.reasoning = reasoning obj.reasoning = reasoning
if (maxTokens) {
delete obj.maxTokens
obj.maxCompletionTokens = parseInt(maxTokens, 10)
}
} }
const multiModalOption: IMultiModalOption = { const multiModalOption: IMultiModalOption = {

View File

@ -362,11 +362,15 @@ try {
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox) const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
const response = await executeJavaScriptCode(code, sandbox, { let response = await executeJavaScriptCode(code, sandbox, {
useSandbox: false, useSandbox: false,
timeout: 10000 timeout: 10000
}) })
if (typeof response === 'object') {
response = JSON.stringify(response)
}
return response return response
} }
} }

View File

@ -370,11 +370,15 @@ try {
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox) const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
const response = await executeJavaScriptCode(code, sandbox, { let response = await executeJavaScriptCode(code, sandbox, {
useSandbox: false, useSandbox: false,
timeout: 10000 timeout: 10000
}) })
if (typeof response === 'object') {
response = JSON.stringify(response)
}
return response return response
} }
} }

View File

@ -124,10 +124,14 @@ export class DynamicStructuredTool<
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox) const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
const response = await executeJavaScriptCode(this.code, sandbox, { let response = await executeJavaScriptCode(this.code, sandbox, {
timeout: 10000 timeout: 10000
}) })
if (typeof response === 'object') {
response = JSON.stringify(response)
}
return response return response
} }

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGmailRequest(url, 'POST', draftData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const draftId = params.id || params.draftId const draftId = params.draftId || params.id
if (!draftId) { if (!draftId) {
return 'Error: Draft ID is required' return 'Error: Draft ID is required'
@ -210,7 +210,7 @@ class GetDraftTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'GET', undefined, params) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const draftId = params.id || params.draftId const draftId = params.draftId || params.id
if (!draftId) { if (!draftId) {
return 'Error: Draft ID is required' return 'Error: Draft ID is required'
@ -251,7 +251,7 @@ class UpdateDraftTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'PUT', draftData, params) const response = await this.makeGmailRequest(url, 'PUT', draftData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const draftId = params.id || params.draftId const draftId = params.draftId || params.id
if (!draftId) { if (!draftId) {
return 'Error: Draft ID is required' return 'Error: Draft ID is required'
@ -285,7 +285,7 @@ class SendDraftTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', { id: draftId }, params) const response = await this.makeGmailRequest(url, 'POST', { id: draftId }, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const draftId = params.id || params.draftId const draftId = params.draftId || params.id
if (!draftId) { if (!draftId) {
return 'Error: Draft ID is required' return 'Error: Draft ID is required'
@ -319,7 +319,7 @@ class DeleteDraftTool extends BaseGmailTool {
await this.makeGmailRequest(url, 'DELETE', undefined, params) await this.makeGmailRequest(url, 'DELETE', undefined, params)
return `Draft ${draftId} deleted successfully` return `Draft ${draftId} deleted successfully`
} catch (error) { } 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) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const messageId = params.id || params.messageId const messageId = params.messageId || params.id
if (!messageId) { if (!messageId) {
return 'Error: Message ID is required' return 'Error: Message ID is required'
@ -388,7 +388,7 @@ class GetMessageTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'GET', undefined, params) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGmailRequest(url, 'POST', messageData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const messageId = params.id || params.messageId const messageId = params.messageId || params.id
if (!messageId) { if (!messageId) {
return 'Error: Message ID is required' return 'Error: Message ID is required'
@ -464,7 +464,7 @@ class ModifyMessageTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', modifyData, params) const response = await this.makeGmailRequest(url, 'POST', modifyData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const messageId = params.id || params.messageId const messageId = params.messageId || params.id
if (!messageId) { if (!messageId) {
return 'Error: Message ID is required' return 'Error: Message ID is required'
@ -498,7 +498,7 @@ class TrashMessageTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', undefined, params) const response = await this.makeGmailRequest(url, 'POST', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const messageId = params.id || params.messageId const messageId = params.messageId || params.id
if (!messageId) { if (!messageId) {
return 'Error: Message ID is required' return 'Error: Message ID is required'
@ -532,7 +532,7 @@ class UntrashMessageTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', undefined, params) const response = await this.makeGmailRequest(url, 'POST', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const messageId = params.id || params.messageId const messageId = params.messageId || params.id
if (!messageId) { if (!messageId) {
return 'Error: Message ID is required' return 'Error: Message ID is required'
@ -566,7 +566,7 @@ class DeleteMessageTool extends BaseGmailTool {
await this.makeGmailRequest(url, 'DELETE', undefined, params) await this.makeGmailRequest(url, 'DELETE', undefined, params)
return `Message ${messageId} deleted successfully` return `Message ${messageId} deleted successfully`
} catch (error) { } 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, {}) const response = await this.makeGmailRequest(url, 'GET', undefined, {})
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const labelId = params.id || params.labelId const labelId = params.labelId || params.id
if (!labelId) { if (!labelId) {
return 'Error: Label ID is required' return 'Error: Label ID is required'
@ -628,7 +628,7 @@ class GetLabelTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'GET', undefined, params) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGmailRequest(url, 'POST', labelData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const labelId = params.labelId const labelId = params.labelId || params.id
if (!labelId) { if (!labelId) {
return 'Error: Label ID is required' return 'Error: Label ID is required'
@ -717,7 +717,7 @@ class UpdateLabelTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'PUT', labelData, params) const response = await this.makeGmailRequest(url, 'PUT', labelData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const labelId = params.id || params.labelId const labelId = params.labelId || params.id
if (!labelId) { if (!labelId) {
return 'Error: Label ID is required' return 'Error: Label ID is required'
@ -751,7 +751,7 @@ class DeleteLabelTool extends BaseGmailTool {
await this.makeGmailRequest(url, 'DELETE', undefined, params) await this.makeGmailRequest(url, 'DELETE', undefined, params)
return `Label ${labelId} deleted successfully` return `Label ${labelId} deleted successfully`
} catch (error) { } 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) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const threadId = params.id || params.threadId const threadId = params.threadId || params.id
if (!threadId) { if (!threadId) {
return 'Error: Thread ID is required' return 'Error: Thread ID is required'
@ -820,7 +820,7 @@ class GetThreadTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'GET', undefined, params) const response = await this.makeGmailRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const threadId = params.id || params.threadId const threadId = params.threadId || params.id
if (!threadId) { if (!threadId) {
return 'Error: Thread ID is required' return 'Error: Thread ID is required'
@ -862,7 +862,7 @@ class ModifyThreadTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', modifyData, params) const response = await this.makeGmailRequest(url, 'POST', modifyData, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const threadId = params.id || params.threadId const threadId = params.threadId || params.id
if (!threadId) { if (!threadId) {
return 'Error: Thread ID is required' return 'Error: Thread ID is required'
@ -896,7 +896,7 @@ class TrashThreadTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', undefined, params) const response = await this.makeGmailRequest(url, 'POST', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const threadId = params.id || params.threadId const threadId = params.threadId || params.id
if (!threadId) { if (!threadId) {
return 'Error: Thread ID is required' return 'Error: Thread ID is required'
@ -930,7 +930,7 @@ class UntrashThreadTool extends BaseGmailTool {
const response = await this.makeGmailRequest(url, 'POST', undefined, params) const response = await this.makeGmailRequest(url, 'POST', undefined, params)
return response return response
} catch (error) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const threadId = params.id || params.threadId const threadId = params.threadId || params.id
if (!threadId) { if (!threadId) {
return 'Error: Thread ID is required' return 'Error: Thread ID is required'
@ -964,7 +964,7 @@ class DeleteThreadTool extends BaseGmailTool {
await this.makeGmailRequest(url, 'DELETE', undefined, params) await this.makeGmailRequest(url, 'DELETE', undefined, params)
return `Thread ${threadId} deleted successfully` return `Thread ${threadId} deleted successfully`
} catch (error) { } 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 // Draft tools
if (actions.includes('listDrafts')) { if (actions.includes('listDrafts')) {
tools.push( tools.push(new ListDraftsTool({ accessToken, defaultParams }))
new ListDraftsTool({
accessToken,
defaultParams: defaultParams.listDrafts
})
)
} }
if (actions.includes('createDraft')) { if (actions.includes('createDraft')) {
tools.push( tools.push(new CreateDraftTool({ accessToken, defaultParams }))
new CreateDraftTool({
accessToken,
defaultParams: defaultParams.createDraft
})
)
} }
if (actions.includes('getDraft')) { if (actions.includes('getDraft')) {
tools.push( tools.push(new GetDraftTool({ accessToken, defaultParams }))
new GetDraftTool({
accessToken,
defaultParams: defaultParams.getDraft
})
)
} }
if (actions.includes('updateDraft')) { if (actions.includes('updateDraft')) {
tools.push( tools.push(new UpdateDraftTool({ accessToken, defaultParams }))
new UpdateDraftTool({
accessToken,
defaultParams: defaultParams.updateDraft
})
)
} }
if (actions.includes('sendDraft')) { if (actions.includes('sendDraft')) {
tools.push( tools.push(new SendDraftTool({ accessToken, defaultParams }))
new SendDraftTool({
accessToken,
defaultParams: defaultParams.sendDraft
})
)
} }
if (actions.includes('deleteDraft')) { if (actions.includes('deleteDraft')) {
tools.push( tools.push(new DeleteDraftTool({ accessToken, defaultParams }))
new DeleteDraftTool({
accessToken,
defaultParams: defaultParams.deleteDraft
})
)
} }
// Message tools // Message tools
if (actions.includes('listMessages')) { if (actions.includes('listMessages')) {
tools.push( tools.push(new ListMessagesTool({ accessToken, defaultParams }))
new ListMessagesTool({
accessToken,
defaultParams: defaultParams.listMessages
})
)
} }
if (actions.includes('getMessage')) { if (actions.includes('getMessage')) {
tools.push( tools.push(new GetMessageTool({ accessToken, defaultParams }))
new GetMessageTool({
accessToken,
defaultParams: defaultParams.getMessage
})
)
} }
if (actions.includes('sendMessage')) { if (actions.includes('sendMessage')) {
tools.push( tools.push(new SendMessageTool({ accessToken, defaultParams }))
new SendMessageTool({
accessToken,
defaultParams: defaultParams.sendMessage
})
)
} }
if (actions.includes('modifyMessage')) { if (actions.includes('modifyMessage')) {
tools.push( tools.push(new ModifyMessageTool({ accessToken, defaultParams }))
new ModifyMessageTool({
accessToken,
defaultParams: defaultParams.modifyMessage
})
)
} }
if (actions.includes('trashMessage')) { if (actions.includes('trashMessage')) {
tools.push( tools.push(new TrashMessageTool({ accessToken, defaultParams }))
new TrashMessageTool({
accessToken,
defaultParams: defaultParams.trashMessage
})
)
} }
if (actions.includes('untrashMessage')) { if (actions.includes('untrashMessage')) {
tools.push( tools.push(new UntrashMessageTool({ accessToken, defaultParams }))
new UntrashMessageTool({
accessToken,
defaultParams: defaultParams.untrashMessage
})
)
} }
if (actions.includes('deleteMessage')) { if (actions.includes('deleteMessage')) {
tools.push( tools.push(new DeleteMessageTool({ accessToken, defaultParams }))
new DeleteMessageTool({
accessToken,
defaultParams: defaultParams.deleteMessage
})
)
} }
// Label tools // Label tools
if (actions.includes('listLabels')) { if (actions.includes('listLabels')) {
tools.push( tools.push(new ListLabelsTool({ accessToken, defaultParams }))
new ListLabelsTool({
accessToken,
defaultParams: defaultParams.listLabels
})
)
} }
if (actions.includes('getLabel')) { if (actions.includes('getLabel')) {
tools.push( tools.push(new GetLabelTool({ accessToken, defaultParams }))
new GetLabelTool({
accessToken,
defaultParams: defaultParams.getLabel
})
)
} }
if (actions.includes('createLabel')) { if (actions.includes('createLabel')) {
tools.push( tools.push(new CreateLabelTool({ accessToken, defaultParams }))
new CreateLabelTool({
accessToken,
defaultParams: defaultParams.createLabel
})
)
} }
if (actions.includes('updateLabel')) { if (actions.includes('updateLabel')) {
tools.push( tools.push(new UpdateLabelTool({ accessToken, defaultParams }))
new UpdateLabelTool({
accessToken,
defaultParams: defaultParams.updateLabel
})
)
} }
if (actions.includes('deleteLabel')) { if (actions.includes('deleteLabel')) {
tools.push( tools.push(new DeleteLabelTool({ accessToken, defaultParams }))
new DeleteLabelTool({
accessToken,
defaultParams: defaultParams.deleteLabel
})
)
} }
// Thread tools // Thread tools
if (actions.includes('listThreads')) { if (actions.includes('listThreads')) {
tools.push( tools.push(new ListThreadsTool({ accessToken, defaultParams }))
new ListThreadsTool({
accessToken,
defaultParams: defaultParams.listThreads
})
)
} }
if (actions.includes('getThread')) { if (actions.includes('getThread')) {
tools.push( tools.push(new GetThreadTool({ accessToken, defaultParams }))
new GetThreadTool({
accessToken,
defaultParams: defaultParams.getThread
})
)
} }
if (actions.includes('modifyThread')) { if (actions.includes('modifyThread')) {
tools.push( tools.push(new ModifyThreadTool({ accessToken, defaultParams }))
new ModifyThreadTool({
accessToken,
defaultParams: defaultParams.modifyThread
})
)
} }
if (actions.includes('trashThread')) { if (actions.includes('trashThread')) {
tools.push( tools.push(new TrashThreadTool({ accessToken, defaultParams }))
new TrashThreadTool({
accessToken,
defaultParams: defaultParams.trashThread
})
)
} }
if (actions.includes('untrashThread')) { if (actions.includes('untrashThread')) {
tools.push( tools.push(new UntrashThreadTool({ accessToken, defaultParams }))
new UntrashThreadTool({
accessToken,
defaultParams: defaultParams.untrashThread
})
)
} }
if (actions.includes('deleteThread')) { if (actions.includes('deleteThread')) {
tools.push( tools.push(new DeleteThreadTool({ accessToken, defaultParams }))
new DeleteThreadTool({
accessToken,
defaultParams: defaultParams.deleteThread
})
)
} }
return tools return tools

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: eventData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'PUT', body: updateData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'DELETE', params })
return response || 'Event deleted successfully' return response || 'Event deleted successfully'
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: calendarData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'PUT', body: updateData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'DELETE', params })
return response || 'Calendar deleted successfully' return response || 'Calendar deleted successfully'
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', params })
return response || 'Calendar cleared successfully' return response || 'Calendar cleared successfully'
} catch (error) { } 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 }) const response = await this.makeGoogleCalendarRequest({ endpoint, method: 'POST', body: freebusyData, params })
return response return response
} catch (error) { } 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 // Event tools
if (actions.includes('listEvents')) { if (actions.includes('listEvents')) {
tools.push( tools.push(new ListEventsTool({ accessToken, defaultParams }))
new ListEventsTool({
accessToken,
defaultParams: defaultParams.listEvents
})
)
} }
if (actions.includes('createEvent')) { if (actions.includes('createEvent')) {
tools.push( tools.push(new CreateEventTool({ accessToken, defaultParams }))
new CreateEventTool({
accessToken,
defaultParams: defaultParams.createEvent
})
)
} }
if (actions.includes('getEvent')) { if (actions.includes('getEvent')) {
tools.push( tools.push(new GetEventTool({ accessToken, defaultParams }))
new GetEventTool({
accessToken,
defaultParams: defaultParams.getEvent
})
)
} }
if (actions.includes('updateEvent')) { if (actions.includes('updateEvent')) {
tools.push( tools.push(new UpdateEventTool({ accessToken, defaultParams }))
new UpdateEventTool({
accessToken,
defaultParams: defaultParams.updateEvent
})
)
} }
if (actions.includes('deleteEvent')) { if (actions.includes('deleteEvent')) {
tools.push( tools.push(new DeleteEventTool({ accessToken, defaultParams }))
new DeleteEventTool({
accessToken,
defaultParams: defaultParams.deleteEvent
})
)
} }
if (actions.includes('quickAddEvent')) { if (actions.includes('quickAddEvent')) {
tools.push( tools.push(new QuickAddEventTool({ accessToken, defaultParams }))
new QuickAddEventTool({
accessToken,
defaultParams: defaultParams.quickAddEvent
})
)
} }
// Calendar tools // Calendar tools
if (actions.includes('listCalendars')) { if (actions.includes('listCalendars')) {
tools.push( tools.push(new ListCalendarsTool({ accessToken, defaultParams }))
new ListCalendarsTool({
accessToken,
defaultParams: defaultParams.listCalendars
})
)
} }
if (actions.includes('createCalendar')) { if (actions.includes('createCalendar')) {
tools.push( tools.push(new CreateCalendarTool({ accessToken, defaultParams }))
new CreateCalendarTool({
accessToken,
defaultParams: defaultParams.createCalendar
})
)
} }
if (actions.includes('getCalendar')) { if (actions.includes('getCalendar')) {
tools.push( tools.push(new GetCalendarTool({ accessToken, defaultParams }))
new GetCalendarTool({
accessToken,
defaultParams: defaultParams.getCalendar
})
)
} }
if (actions.includes('updateCalendar')) { if (actions.includes('updateCalendar')) {
tools.push( tools.push(new UpdateCalendarTool({ accessToken, defaultParams }))
new UpdateCalendarTool({
accessToken,
defaultParams: defaultParams.updateCalendar
})
)
} }
if (actions.includes('deleteCalendar')) { if (actions.includes('deleteCalendar')) {
tools.push( tools.push(new DeleteCalendarTool({ accessToken, defaultParams }))
new DeleteCalendarTool({
accessToken,
defaultParams: defaultParams.deleteCalendar
})
)
} }
if (actions.includes('clearCalendar')) { if (actions.includes('clearCalendar')) {
tools.push( tools.push(new ClearCalendarTool({ accessToken, defaultParams }))
new ClearCalendarTool({
accessToken,
defaultParams: defaultParams.clearCalendar
})
)
} }
// Freebusy tools // Freebusy tools
if (actions.includes('queryFreebusy')) { if (actions.includes('queryFreebusy')) {
tools.push( tools.push(new QueryFreebusyTool({ accessToken, defaultParams }))
new QueryFreebusyTool({
accessToken,
defaultParams: defaultParams.queryFreebusy
})
)
} }
return tools return tools

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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 return createResponse
} catch (error) { } 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 }) const response = await this.makeGoogleDocsRequest({ endpoint, params })
return response return response
} catch (error) { } 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) return `No updates specified` + TOOL_ARGS_PREFIX + JSON.stringify(params)
} }
} catch (error) { } catch (error) {
return `Error updating document: ${error}` return formatToolError(`Error updating document: ${error}`, params)
} }
} }
} }
@ -429,7 +429,7 @@ class InsertTextTool extends BaseGoogleDocsTool {
}) })
return response return response
} catch (error) { } catch (error) {
return `Error inserting text: ${error}` return formatToolError(`Error inserting text: ${error}`, params)
} }
} }
} }
@ -478,7 +478,7 @@ class ReplaceTextTool extends BaseGoogleDocsTool {
}) })
return response return response
} catch (error) { } catch (error) {
return `Error replacing text: ${error}` return formatToolError(`Error replacing text: ${error}`, params)
} }
} }
} }
@ -534,7 +534,7 @@ class AppendTextTool extends BaseGoogleDocsTool {
}) })
return response return response
} catch (error) { } 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) return JSON.stringify({ textContent }) + TOOL_ARGS_PREFIX + JSON.stringify(params)
} catch (error) { } 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 return response
} catch (error) { } catch (error) {
return `Error inserting image: ${error}` return formatToolError(`Error inserting image: ${error}`, params)
} }
} }
} }
@ -680,7 +680,7 @@ class CreateTableTool extends BaseGoogleDocsTool {
}) })
return response return response
} catch (error) { } catch (error) {
return `Error creating table: ${error}` return formatToolError(`Error creating table: ${error}`, params)
} }
} }
} }

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } catch (error) {
return `Error getting file: ${error}` return formatToolError(`Error getting file: ${error}`, params)
} }
} }
} }
@ -323,7 +323,7 @@ class CreateFileTool extends BaseGoogleDriveTool {
} }
} }
} catch (error) { } catch (error) {
return `Error creating file: ${error}` return formatToolError(`Error creating file: ${error}`, params)
} }
} }
@ -452,7 +452,7 @@ class UpdateFileTool extends BaseGoogleDriveTool {
}) })
return response return response
} catch (error) { } 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` return `File deleted successfully`
} catch (error) { } catch (error) {
return `Error deleting file: ${error}` return formatToolError(`Error deleting file: ${error}`, params)
} }
} }
} }
@ -541,7 +541,7 @@ class CopyFileTool extends BaseGoogleDriveTool {
}) })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } catch (error) {
return `Error downloading file: ${error}` return formatToolError(`Error downloading file: ${error}`, params)
} }
} }
} }
@ -630,7 +630,7 @@ class CreateFolderTool extends BaseGoogleDriveTool {
}) })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } catch (error) {
return `Error searching files: ${error}` return formatToolError(`Error searching files: ${error}`, params)
} }
} }
} }
@ -724,7 +724,7 @@ class ShareFileTool extends BaseGoogleDriveTool {
}) })
return response return response
} catch (error) { } 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } 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` return `Folder deleted successfully`
} catch (error) { } 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 }) const response = await this.makeGoogleDriveRequest({ endpoint, params })
return response return response
} catch (error) { } 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` return `Permission removed successfully`
} catch (error) { } catch (error) {
return `Error removing permission: ${error}` return formatToolError(`Error removing permission: ${error}`, params)
} }
} }
} }

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const body: any = { try {
properties: { const body: any = {
title: params.title properties: {
title: params.title
}
} }
}
if (params.locale) body.properties.locale = params.locale if (params.locale) body.properties.locale = params.locale
if (params.timeZone) body.properties.timeZone = params.timeZone if (params.timeZone) body.properties.timeZone = params.timeZone
// Add sheets if specified // Add sheets if specified
if (params.sheetCount && params.sheetCount > 1) { if (params.sheetCount && params.sheetCount > 1) {
body.sheets = [] body.sheets = []
for (let i = 0; i < params.sheetCount; i++) { for (let i = 0; i < params.sheetCount; i++) {
body.sheets.push({ body.sheets.push({
properties: { properties: {
title: i === 0 ? 'Sheet1' : `Sheet${i + 1}` title: i === 0 ? 'Sheet1' : `Sheet${i + 1}`
} }
}) })
}
} }
}
return await this.makeGoogleSheetsRequest({ return await this.makeGoogleSheetsRequest({
endpoint: 'spreadsheets', endpoint: 'spreadsheets',
method: 'POST', method: 'POST',
body, body,
params params
}) })
} catch (error) {
return formatToolError(`Error creating spreadsheet: ${error}`, params)
}
} }
} }
@ -234,23 +238,28 @@ class GetSpreadsheetTool extends BaseGoogleSheetsTool {
async _call(arg: any): Promise<string> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const queryParams = new URLSearchParams()
if (params.ranges) { try {
params.ranges.split(',').forEach((range: string) => { const queryParams = new URLSearchParams()
queryParams.append('ranges', range.trim())
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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const requests = [] try {
if (params.title || params.locale || params.timeZone) { const requests = []
const updateProperties: any = {} if (params.title || params.locale || params.timeZone) {
if (params.title) updateProperties.title = params.title const updateProperties: any = {}
if (params.locale) updateProperties.locale = params.locale if (params.title) updateProperties.title = params.title
if (params.timeZone) updateProperties.timeZone = params.timeZone if (params.locale) updateProperties.locale = params.locale
if (params.timeZone) updateProperties.timeZone = params.timeZone
requests.push({ requests.push({
updateSpreadsheetProperties: { updateSpreadsheetProperties: {
properties: updateProperties, properties: updateProperties,
fields: Object.keys(updateProperties).join(',') 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const queryParams = new URLSearchParams()
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption) try {
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption) const queryParams = new URLSearchParams()
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
const queryString = queryParams.toString() if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption)
const encodedRange = encodeURIComponent(params.range) if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption)
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}${queryString ? `?${queryString}` : ''}` if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension)
return await this.makeGoogleSheetsRequest({ const queryString = queryParams.toString()
endpoint, const encodedRange = encodeURIComponent(params.range)
method: 'GET', const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}${queryString ? `?${queryString}` : ''}`
params
}) 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
let values
try { 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) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
let values
try { 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) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const encodedRange = encodeURIComponent(params.range) try {
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:clear` const encodedRange = encodeURIComponent(params.range)
const endpoint = `spreadsheets/${params.spreadsheetId}/values/${encodedRange}:clear`
return await this.makeGoogleSheetsRequest({ return await this.makeGoogleSheetsRequest({
endpoint, endpoint,
method: 'POST', method: 'POST',
body: {}, body: {},
params params
}) })
} catch (error) {
return formatToolError(`Error clearing values: ${error}`, params)
}
} }
} }
@ -496,24 +526,29 @@ class BatchGetValuesTool extends BaseGoogleSheetsTool {
async _call(arg: any): Promise<string> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const queryParams = new URLSearchParams()
// Add ranges try {
params.ranges.split(',').forEach((range: string) => { const queryParams = new URLSearchParams()
queryParams.append('ranges', range.trim())
})
if (params.valueRenderOption) queryParams.append('valueRenderOption', params.valueRenderOption) // Add ranges
if (params.dateTimeRenderOption) queryParams.append('dateTimeRenderOption', params.dateTimeRenderOption) params.ranges.split(',').forEach((range: string) => {
if (params.majorDimension) queryParams.append('majorDimension', params.majorDimension) 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({ const endpoint = `spreadsheets/${params.spreadsheetId}/values:batchGet?${queryParams.toString()}`
endpoint,
method: 'GET', return await this.makeGoogleSheetsRequest({
params 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
let valueRanges
try { 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) { } 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> { async _call(arg: any): Promise<string> {
const params = { ...arg, ...this.defaultParams } const params = { ...arg, ...this.defaultParams }
const ranges = params.ranges.split(',').map((range: string) => range.trim()) try {
const body = { ranges } 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({ return await this.makeGoogleSheetsRequest({
endpoint, endpoint,
method: 'POST', method: 'POST',
body, body,
params params
}) })
} catch (error) {
return formatToolError(`Error batch clearing values: ${error}`, params)
}
} }
} }

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint: 'issue', method: 'POST', body: issueData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: updateData, params })
return response || 'Issue updated successfully' return response || 'Issue updated successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
return response || 'Issue deleted successfully' return response || 'Issue deleted successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: assignData, params })
return response || 'Issue assigned successfully' return response || 'Issue assigned successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: transitionData, params })
return response || 'Issue transitioned successfully' return response || 'Issue transitioned successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: commentData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: commentData, params })
return response || 'Comment updated successfully' return response || 'Comment updated successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
return response || 'Comment deleted successfully' return response || 'Comment deleted successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'POST', body: userData, params })
return response return response
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'PUT', body: userData, params })
return response || 'User updated successfully' return response || 'User updated successfully'
} catch (error) { } 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 }) const response = await this.makeJiraRequest({ endpoint, method: 'DELETE', params })
return response || 'User deleted successfully' return response || 'User deleted successfully'
} catch (error) { } 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, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.listIssues defaultParams
}) })
) )
} }
@ -981,7 +981,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.createIssue defaultParams
}) })
) )
} }
@ -993,7 +993,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.getIssue defaultParams
}) })
) )
} }
@ -1005,7 +1005,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.updateIssue defaultParams
}) })
) )
} }
@ -1017,7 +1017,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.deleteIssue defaultParams
}) })
) )
} }
@ -1029,7 +1029,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.assignIssue defaultParams
}) })
) )
} }
@ -1041,7 +1041,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.transitionIssue defaultParams
}) })
) )
} }
@ -1054,7 +1054,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.listComments defaultParams
}) })
) )
} }
@ -1066,7 +1066,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.createComment defaultParams
}) })
) )
} }
@ -1078,7 +1078,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.getComment defaultParams
}) })
) )
} }
@ -1090,7 +1090,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.updateComment defaultParams
}) })
) )
} }
@ -1102,7 +1102,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.deleteComment defaultParams
}) })
) )
} }
@ -1115,7 +1115,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.searchUsers defaultParams
}) })
) )
} }
@ -1127,7 +1127,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.getUser defaultParams
}) })
) )
} }
@ -1139,7 +1139,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.createUser defaultParams
}) })
) )
} }
@ -1151,7 +1151,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.updateUser defaultParams
}) })
) )
} }
@ -1163,7 +1163,7 @@ export const createJiraTools = (args?: RequestParameters): DynamicStructuredTool
accessToken, accessToken,
jiraHost, jiraHost,
maxOutputLength, maxOutputLength,
defaultParams: defaultParams.deleteUser defaultParams
}) })
) )
} }

View File

@ -1,7 +1,7 @@
import { z } from 'zod' import { z } from 'zod'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core' 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` 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'POST', calendarData, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'PATCH', calendarData, params)
return response return response
} catch (error) { } 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) await this.makeGraphRequest(url, 'DELETE', undefined, params)
return `Calendar ${params.calendarId} deleted successfully` return `Calendar ${params.calendarId} deleted successfully`
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'POST', eventData, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'PATCH', eventData, params)
return response return response
} catch (error) { } 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) await this.makeGraphRequest(url, 'DELETE', undefined, params)
return `Event ${params.eventId} deleted successfully` return `Event ${params.eventId} deleted successfully`
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'GET', undefined, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'POST', messageData, params)
return response return response
} catch (error) { } 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) await this.makeGraphRequest(url, 'POST', messageData, params)
return 'Message sent successfully' return 'Message sent successfully'
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'PATCH', messageData, params)
return response return response
} catch (error) { } 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) await this.makeGraphRequest(url, 'DELETE', undefined, params)
return `Message ${params.messageId} deleted successfully` return `Message ${params.messageId} deleted successfully`
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'POST', copyData, params)
return response return response
} catch (error) { } 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) const response = await this.makeGraphRequest(url, 'POST', moveData, params)
return response return response
} catch (error) { } 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) await this.makeGraphRequest(url, 'POST', replyData, params)
return 'Reply sent successfully' return 'Reply sent successfully'
} catch (error) { } 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 // Calendar tools
if (actions.includes('listCalendars')) { if (actions.includes('listCalendars')) {
const listTool = new ListCalendarsTool({ const listTool = new ListCalendarsTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listCalendars
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getCalendar')) { if (actions.includes('getCalendar')) {
const getTool = new GetCalendarTool({ const getTool = new GetCalendarTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getCalendar
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('createCalendar')) { if (actions.includes('createCalendar')) {
const createTool = new CreateCalendarTool({ const createTool = new CreateCalendarTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.createCalendar
})
tools.push(createTool) tools.push(createTool)
} }
if (actions.includes('updateCalendar')) { if (actions.includes('updateCalendar')) {
const updateTool = new UpdateCalendarTool({ const updateTool = new UpdateCalendarTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateCalendar
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteCalendar')) { if (actions.includes('deleteCalendar')) {
const deleteTool = new DeleteCalendarTool({ const deleteTool = new DeleteCalendarTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteCalendar
})
tools.push(deleteTool) tools.push(deleteTool)
} }
if (actions.includes('listEvents')) { if (actions.includes('listEvents')) {
const listTool = new ListEventsTool({ const listTool = new ListEventsTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listEvents
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getEvent')) { if (actions.includes('getEvent')) {
const getTool = new GetEventTool({ const getTool = new GetEventTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getEvent
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('createEvent')) { if (actions.includes('createEvent')) {
const createTool = new CreateEventTool({ const createTool = new CreateEventTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.createEvent
})
tools.push(createTool) tools.push(createTool)
} }
if (actions.includes('updateEvent')) { if (actions.includes('updateEvent')) {
const updateTool = new UpdateEventTool({ const updateTool = new UpdateEventTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateEvent
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteEvent')) { if (actions.includes('deleteEvent')) {
const deleteTool = new DeleteEventTool({ const deleteTool = new DeleteEventTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteEvent
})
tools.push(deleteTool) tools.push(deleteTool)
} }
// Message tools // Message tools
if (actions.includes('listMessages')) { if (actions.includes('listMessages')) {
const listTool = new ListMessagesTool({ const listTool = new ListMessagesTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listMessages
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getMessage')) { if (actions.includes('getMessage')) {
const getTool = new GetMessageTool({ const getTool = new GetMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getMessage
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('createDraftMessage')) { if (actions.includes('createDraftMessage')) {
const createTool = new CreateDraftMessageTool({ const createTool = new CreateDraftMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.createDraftMessage
})
tools.push(createTool) tools.push(createTool)
} }
if (actions.includes('sendMessage')) { if (actions.includes('sendMessage')) {
const sendTool = new SendMessageTool({ const sendTool = new SendMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.sendMessage
})
tools.push(sendTool) tools.push(sendTool)
} }
if (actions.includes('updateMessage')) { if (actions.includes('updateMessage')) {
const updateTool = new UpdateMessageTool({ const updateTool = new UpdateMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateMessage
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteMessage')) { if (actions.includes('deleteMessage')) {
const deleteTool = new DeleteMessageTool({ const deleteTool = new DeleteMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteMessage
})
tools.push(deleteTool) tools.push(deleteTool)
} }
if (actions.includes('copyMessage')) { if (actions.includes('copyMessage')) {
const copyTool = new CopyMessageTool({ const copyTool = new CopyMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.copyMessage
})
tools.push(copyTool) tools.push(copyTool)
} }
if (actions.includes('moveMessage')) { if (actions.includes('moveMessage')) {
const moveTool = new MoveMessageTool({ const moveTool = new MoveMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.moveMessage
})
tools.push(moveTool) tools.push(moveTool)
} }
if (actions.includes('replyMessage')) { if (actions.includes('replyMessage')) {
const replyTool = new ReplyMessageTool({ const replyTool = new ReplyMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.replyMessage
})
tools.push(replyTool) tools.push(replyTool)
} }
if (actions.includes('forwardMessage')) { if (actions.includes('forwardMessage')) {
const forwardTool = new ForwardMessageTool({ const forwardTool = new ForwardMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.forwardMessage
})
tools.push(forwardTool) tools.push(forwardTool)
} }

View File

@ -119,7 +119,7 @@ class ListChannelsTool extends BaseTeamsTool {
return this.formatResponse(responseData, params) return this.formatResponse(responseData, params)
} catch (error) { } 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 // Channel tools
if (actions.includes('listChannels')) { if (actions.includes('listChannels')) {
const listTool = new ListChannelsTool({ const listTool = new ListChannelsTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listChannels
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getChannel')) { if (actions.includes('getChannel')) {
const getTool = new GetChannelTool({ const getTool = new GetChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getChannel
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('createChannel')) { if (actions.includes('createChannel')) {
const createTool = new CreateChannelTool({ const createTool = new CreateChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.createChannel
})
tools.push(createTool) tools.push(createTool)
} }
if (actions.includes('updateChannel')) { if (actions.includes('updateChannel')) {
const updateTool = new UpdateChannelTool({ const updateTool = new UpdateChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateChannel
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteChannel')) { if (actions.includes('deleteChannel')) {
const deleteTool = new DeleteChannelTool({ const deleteTool = new DeleteChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteChannel
})
tools.push(deleteTool) tools.push(deleteTool)
} }
if (actions.includes('archiveChannel')) { if (actions.includes('archiveChannel')) {
const archiveTool = new ArchiveChannelTool({ const archiveTool = new ArchiveChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.archiveChannel
})
tools.push(archiveTool) tools.push(archiveTool)
} }
if (actions.includes('unarchiveChannel')) { if (actions.includes('unarchiveChannel')) {
const unarchiveTool = new UnarchiveChannelTool({ const unarchiveTool = new UnarchiveChannelTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.unarchiveChannel
})
tools.push(unarchiveTool) tools.push(unarchiveTool)
} }
if (actions.includes('listChannelMembers')) { if (actions.includes('listChannelMembers')) {
const listMembersTool = new ListChannelMembersTool({ const listMembersTool = new ListChannelMembersTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listChannelMembers
})
tools.push(listMembersTool) tools.push(listMembersTool)
} }
if (actions.includes('addChannelMember')) { if (actions.includes('addChannelMember')) {
const addMemberTool = new AddChannelMemberTool({ const addMemberTool = new AddChannelMemberTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.addChannelMember
})
tools.push(addMemberTool) tools.push(addMemberTool)
} }
if (actions.includes('removeChannelMember')) { if (actions.includes('removeChannelMember')) {
const removeMemberTool = new RemoveChannelMemberTool({ const removeMemberTool = new RemoveChannelMemberTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.removeChannelMember
})
tools.push(removeMemberTool) tools.push(removeMemberTool)
} }
// Chat tools // Chat tools
if (actions.includes('listChats')) { if (actions.includes('listChats')) {
const listTool = new ListChatsTool({ const listTool = new ListChatsTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listChats
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getChat')) { if (actions.includes('getChat')) {
const getTool = new GetChatTool({ const getTool = new GetChatTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getChat
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('createChat')) { if (actions.includes('createChat')) {
const createTool = new CreateChatTool({ const createTool = new CreateChatTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.createChat
})
tools.push(createTool) tools.push(createTool)
} }
if (actions.includes('updateChat')) { if (actions.includes('updateChat')) {
const updateTool = new UpdateChatTool({ const updateTool = new UpdateChatTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateChat
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteChat')) { if (actions.includes('deleteChat')) {
const deleteTool = new DeleteChatTool({ const deleteTool = new DeleteChatTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteChat
})
tools.push(deleteTool) tools.push(deleteTool)
} }
if (actions.includes('listChatMembers')) { if (actions.includes('listChatMembers')) {
const listMembersTool = new ListChatMembersTool({ const listMembersTool = new ListChatMembersTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listChatMembers
})
tools.push(listMembersTool) tools.push(listMembersTool)
} }
if (actions.includes('addChatMember')) { if (actions.includes('addChatMember')) {
const addMemberTool = new AddChatMemberTool({ const addMemberTool = new AddChatMemberTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.addChatMember
})
tools.push(addMemberTool) tools.push(addMemberTool)
} }
if (actions.includes('removeChatMember')) { if (actions.includes('removeChatMember')) {
const removeMemberTool = new RemoveChatMemberTool({ const removeMemberTool = new RemoveChatMemberTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.removeChatMember
})
tools.push(removeMemberTool) tools.push(removeMemberTool)
} }
if (actions.includes('pinMessage')) { if (actions.includes('pinMessage')) {
const pinTool = new PinMessageTool({ const pinTool = new PinMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.pinMessage
})
tools.push(pinTool) tools.push(pinTool)
} }
if (actions.includes('unpinMessage')) { if (actions.includes('unpinMessage')) {
const unpinTool = new UnpinMessageTool({ const unpinTool = new UnpinMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.unpinMessage
})
tools.push(unpinTool) tools.push(unpinTool)
} }
// Chat message tools // Chat message tools
if (actions.includes('listMessages')) { if (actions.includes('listMessages')) {
const listTool = new ListMessagesTool({ const listTool = new ListMessagesTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.listMessages
})
tools.push(listTool) tools.push(listTool)
} }
if (actions.includes('getMessage')) { if (actions.includes('getMessage')) {
const getTool = new GetMessageTool({ const getTool = new GetMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getMessage
})
tools.push(getTool) tools.push(getTool)
} }
if (actions.includes('sendMessage')) { if (actions.includes('sendMessage')) {
const sendTool = new SendMessageTool({ const sendTool = new SendMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.sendMessage
})
tools.push(sendTool) tools.push(sendTool)
} }
if (actions.includes('updateMessage')) { if (actions.includes('updateMessage')) {
const updateTool = new UpdateMessageTool({ const updateTool = new UpdateMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.updateMessage
})
tools.push(updateTool) tools.push(updateTool)
} }
if (actions.includes('deleteMessage')) { if (actions.includes('deleteMessage')) {
const deleteTool = new DeleteMessageTool({ const deleteTool = new DeleteMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.deleteMessage
})
tools.push(deleteTool) tools.push(deleteTool)
} }
if (actions.includes('replyToMessage')) { if (actions.includes('replyToMessage')) {
const replyTool = new ReplyToMessageTool({ const replyTool = new ReplyToMessageTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.replyToMessage
})
tools.push(replyTool) tools.push(replyTool)
} }
if (actions.includes('setReaction')) { if (actions.includes('setReaction')) {
const reactionTool = new SetReactionTool({ const reactionTool = new SetReactionTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.setReaction
})
tools.push(reactionTool) tools.push(reactionTool)
} }
if (actions.includes('unsetReaction')) { if (actions.includes('unsetReaction')) {
const unsetReactionTool = new UnsetReactionTool({ const unsetReactionTool = new UnsetReactionTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.unsetReaction
})
tools.push(unsetReactionTool) tools.push(unsetReactionTool)
} }
if (actions.includes('getAllMessages')) { if (actions.includes('getAllMessages')) {
const getAllTool = new GetAllMessagesTool({ const getAllTool = new GetAllMessagesTool({ accessToken, defaultParams })
accessToken,
defaultParams: defaultParams.getAllMessages
})
tools.push(getAllTool) tools.push(getAllTool)
} }

View File

@ -253,10 +253,14 @@ export class DynamicStructuredTool<
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox) 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 timeout: 10000
}) })
if (typeof response === 'object') {
response = JSON.stringify(response)
}
return response return response
} }

View File

@ -105,6 +105,7 @@
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"ipaddr.js": "^2.2.0", "ipaddr.js": "^2.2.0",
"jsdom": "^22.1.0", "jsdom": "^22.1.0",
"json5": "2.2.3",
"jsonpointer": "^5.0.1", "jsonpointer": "^5.0.1",
"jsonrepair": "^3.11.1", "jsonrepair": "^3.11.1",
"langchain": "^0.3.5", "langchain": "^0.3.5",

View File

@ -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 ARTIFACTS_PREFIX = '\n\n----FLOWISE_ARTIFACTS----\n\n'
export const TOOL_ARGS_PREFIX = '\n\n----FLOWISE_TOOL_ARGS----\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 = { export type AgentFinish = {
returnValues: Record<string, any> returnValues: Record<string, any>
log: string log: string

View File

@ -18,6 +18,7 @@ import { TextSplitter } from 'langchain/text_splitter'
import { DocumentLoader } from 'langchain/document_loaders/base' import { DocumentLoader } from 'langchain/document_loaders/base'
import { NodeVM } from '@flowiseai/nodevm' import { NodeVM } from '@flowiseai/nodevm'
import { Sandbox } from '@e2b/code-interpreter' 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 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 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 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 * Execute JavaScript code using either Sandbox or NodeVM
* @param {string} code - The JavaScript code to execute * @param {string} code - The JavaScript code to execute
@ -1497,7 +1531,7 @@ export const executeJavaScriptCode = async (
// Clean up sandbox // Clean up sandbox
sbx.kill() sbx.kill()
return output return parseOutput(output)
} catch (e) { } catch (e) {
throw new Error(`Sandbox Execution Error: ${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) const response = await vm.run(`module.exports = async function() {${code}}()`, __dirname)
let finalOutput = response let finalOutput = response
if (typeof response === 'object') {
finalOutput = JSON.stringify(response, null, 2)
}
// Stream output if streaming function provided // Stream output if streaming function provided
if (streamOutput && finalOutput) { 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) { } catch (e) {
throw new Error(`NodeVM Execution Error: ${e}`) throw new Error(`NodeVM Execution Error: ${e}`)
} }

View File

@ -167,9 +167,10 @@ const CustomAssistantConfigurePreview = () => {
const checkInputParamsMandatory = () => { const checkInputParamsMandatory = () => {
let canSubmit = true let canSubmit = true
const visibleInputParams = showHideInputParams(selectedChatModel).filter(
const inputParams = (selectedChatModel.inputParams ?? []).filter((inputParam) => !inputParam.hidden) (inputParam) => !inputParam.hidden && inputParam.display !== false
for (const inputParam of inputParams) { )
for (const inputParam of visibleInputParams) {
if (!inputParam.optional && (!selectedChatModel.inputs[inputParam.name] || !selectedChatModel.credential)) { if (!inputParam.optional && (!selectedChatModel.inputs[inputParam.name] || !selectedChatModel.credential)) {
if (inputParam.type === 'credential' && !selectedChatModel.credential) { if (inputParam.type === 'credential' && !selectedChatModel.credential) {
canSubmit = false canSubmit = false
@ -184,8 +185,10 @@ const CustomAssistantConfigurePreview = () => {
if (selectedTools.length > 0) { if (selectedTools.length > 0) {
for (let i = 0; i < selectedTools.length; i++) { for (let i = 0; i < selectedTools.length; i++) {
const tool = selectedTools[i] const tool = selectedTools[i]
const inputParams = (tool.inputParams ?? []).filter((inputParam) => !inputParam.hidden) const visibleInputParams = showHideInputParams(tool).filter(
for (const inputParam of inputParams) { (inputParam) => !inputParam.hidden && inputParam.display !== false
)
for (const inputParam of visibleInputParams) {
if (!inputParam.optional && (!tool.inputs[inputParam.name] || !tool.credential)) { if (!inputParam.optional && (!tool.inputs[inputParam.name] || !tool.credential)) {
if (inputParam.type === 'credential' && !tool.credential) { if (inputParam.type === 'credential' && !tool.credential) {
canSubmit = false canSubmit = false

View File

@ -375,6 +375,9 @@ importers:
jsdom: jsdom:
specifier: ^22.1.0 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) 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: jsonpointer:
specifier: ^5.0.1 specifier: ^5.0.1
version: 5.0.1 version: 5.0.1