|
@@ -2,6 +2,8 @@ import { z } from "zod"
|
|
|
import { Tool } from "./tool"
|
|
import { Tool } from "./tool"
|
|
|
import TurndownService from "turndown"
|
|
import TurndownService from "turndown"
|
|
|
import DESCRIPTION from "./webfetch.txt"
|
|
import DESCRIPTION from "./webfetch.txt"
|
|
|
|
|
+import { Config } from "../config/config"
|
|
|
|
|
+import { Permission } from "../permission"
|
|
|
|
|
|
|
|
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024 // 5MB
|
|
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024 // 5MB
|
|
|
const DEFAULT_TIMEOUT = 30 * 1000 // 30 seconds
|
|
const DEFAULT_TIMEOUT = 30 * 1000 // 30 seconds
|
|
@@ -22,6 +24,21 @@ export const WebFetchTool = Tool.define("webfetch", {
|
|
|
throw new Error("URL must start with http:// or https://")
|
|
throw new Error("URL must start with http:// or https://")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ const cfg = await Config.get()
|
|
|
|
|
+ if (cfg.permission?.webfetch === "ask")
|
|
|
|
|
+ await Permission.ask({
|
|
|
|
|
+ type: "webfetch",
|
|
|
|
|
+ sessionID: ctx.sessionID,
|
|
|
|
|
+ messageID: ctx.messageID,
|
|
|
|
|
+ callID: ctx.callID,
|
|
|
|
|
+ title: "Fetch content from: " + params.url,
|
|
|
|
|
+ metadata: {
|
|
|
|
|
+ url: params.url,
|
|
|
|
|
+ format: params.format,
|
|
|
|
|
+ timeout: params.timeout,
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
const timeout = Math.min((params.timeout ?? DEFAULT_TIMEOUT / 1000) * 1000, MAX_TIMEOUT)
|
|
const timeout = Math.min((params.timeout ?? DEFAULT_TIMEOUT / 1000) * 1000, MAX_TIMEOUT)
|
|
|
|
|
|
|
|
const controller = new AbortController()
|
|
const controller = new AbortController()
|