Chore/Update issue templates and add new tools (#4687)

* Enhancement: Update issue templates and add new tools

- Updated bug report template to include a default label of 'bug'.
- Updated feature request template to include a default label of 'enhancement'.
- Added new credential class for Agentflow API.
- Enhanced Agent and HTTP nodes to improve tool management and error handling.
- Added deprecation badges to several agent and chain classes.
- Introduced new tools for handling requests (GET, POST, DELETE, PUT) with improved error handling.
- Added new chatflows and agentflows for various use cases, including document QnA and translation.
- Updated UI components for better handling of agent flows and marketplace interactions.
- Refactored utility functions for improved functionality and clarity.

* Refactor: Remove beta badge and streamline template title assignment

- Removed the 'BETA' badge from the ExtractMetadataRetriever class.
- Simplified the title assignment in the agentflowv2 generator by using a variable instead of inline string manipulation.
This commit is contained in:
Henry Heng
2025-06-19 18:11:24 +01:00
committed by GitHub
parent 15dd28356b
commit a107aa7a77
86 changed files with 9942 additions and 12634 deletions
@@ -1,12 +1,8 @@
import { Tool } from '@langchain/core/tools'
import { z } from 'zod'
import fetch from 'node-fetch'
import { DynamicStructuredTool } from '../OpenAPIToolkit/core'
export const desc = `Use this when you want to POST to a website.
Input should be a json string with two keys: "url" and "data".
The value of "url" should be a string, and the value of "data" should be a dictionary of
key-value pairs you want to POST to the url as a JSON body.
Be careful to always use double quotes for strings in the json string
The output will be the text response of the POST request.`
export const desc = `Use this when you want to execute a POST request to create or update a resource.`
export interface Headers {
[key: string]: string
@@ -21,52 +17,129 @@ export interface RequestParameters {
body?: Body
url?: string
description?: string
name?: string
bodySchema?: string
maxOutputLength?: number
}
export class RequestsPostTool extends Tool {
name = 'requests_post'
// Base schema for POST request
const createRequestsPostSchema = (bodySchema?: string) => {
// If bodySchema is provided, parse it and add dynamic body params
if (bodySchema) {
try {
const parsedSchema = JSON.parse(bodySchema)
const bodyParamsObject: Record<string, z.ZodTypeAny> = {}
Object.entries(parsedSchema).forEach(([key, config]: [string, any]) => {
let zodType: z.ZodTypeAny = z.string()
// Handle different types
if (config.type === 'number') {
zodType = z.number()
} else if (config.type === 'boolean') {
zodType = z.boolean()
} else if (config.type === 'object') {
zodType = z.record(z.any())
} else if (config.type === 'array') {
zodType = z.array(z.any())
}
// Add description
if (config.description) {
zodType = zodType.describe(config.description)
}
// Make optional if not required
if (!config.required) {
zodType = zodType.optional()
}
bodyParamsObject[key] = zodType
})
if (Object.keys(bodyParamsObject).length > 0) {
return z.object({
body: z.object(bodyParamsObject).describe('Request body parameters')
})
}
} catch (error) {
console.warn('Failed to parse bodySchema:', error)
}
}
// Fallback to generic body
return z.object({
body: z.record(z.any()).optional().describe('Optional body data to include in the request')
})
}
export class RequestsPostTool extends DynamicStructuredTool {
url = ''
description = desc
maxOutputLength = Infinity
headers = {}
body = {}
bodySchema?: string
constructor(args?: RequestParameters) {
super()
const schema = createRequestsPostSchema(args?.bodySchema)
const toolInput = {
name: args?.name || 'requests_post',
description: args?.description || desc,
schema: schema,
baseUrl: '',
method: 'POST',
headers: args?.headers || {}
}
super(toolInput)
this.url = args?.url ?? this.url
this.headers = args?.headers ?? this.headers
this.body = args?.body ?? this.body
this.description = args?.description ?? this.description
this.maxOutputLength = args?.maxOutputLength ?? this.maxOutputLength
this.bodySchema = args?.bodySchema
}
/** @ignore */
async _call(input: string) {
async _call(arg: any): Promise<string> {
const params = { ...arg }
try {
let inputUrl = ''
let inputBody = {}
if (Object.keys(this.body).length || this.url) {
if (this.url) inputUrl = this.url
if (Object.keys(this.body).length) inputBody = this.body
} else {
const { url, data } = JSON.parse(input)
inputUrl = url
inputBody = data
const inputUrl = this.url
if (!inputUrl) {
throw new Error('URL is required for POST request')
}
if (process.env.DEBUG === 'true') console.info(`Making POST API call to ${inputUrl} with body ${JSON.stringify(inputBody)}`)
let inputBody = {
...this.body
}
if (this.bodySchema && params.body && Object.keys(params.body).length > 0) {
inputBody = {
...inputBody,
...params.body
}
}
const requestHeaders = {
'Content-Type': 'application/json',
...(params.headers || {}),
...this.headers
}
const res = await fetch(inputUrl, {
method: 'POST',
headers: this.headers,
headers: requestHeaders,
body: JSON.stringify(inputBody)
})
if (!res.ok) {
throw new Error(`HTTP Error ${res.status}: ${res.statusText}`)
}
const text = await res.text()
return text.slice(0, this.maxOutputLength)
} catch (error) {
return `${error}`
throw new Error(`Failed to make POST request: ${error instanceof Error ? error.message : 'Unknown error'}`)
}
}
}