|
|
@@ -26,9 +26,10 @@ async function withFetch(fetch: (req: Request) => Response | Promise<Response>,
|
|
|
await fn(server.url)
|
|
|
}
|
|
|
|
|
|
-function initTool() {
|
|
|
+function exec(args: { url: string; format: "text" | "markdown" | "html" }) {
|
|
|
return WebFetchTool.pipe(
|
|
|
Effect.flatMap((info) => info.init()),
|
|
|
+ Effect.flatMap((tool) => tool.execute(args, ctx)),
|
|
|
Effect.provide(Layer.mergeAll(FetchHttpClient.layer, Truncate.defaultLayer, Agent.defaultLayer)),
|
|
|
Effect.runPromise,
|
|
|
)
|
|
|
@@ -43,10 +44,7 @@ describe("tool.webfetch", () => {
|
|
|
await Instance.provide({
|
|
|
directory: projectRoot,
|
|
|
fn: async () => {
|
|
|
- const webfetch = await initTool()
|
|
|
- const result = await Effect.runPromise(
|
|
|
- webfetch.execute({ url: new URL("/image.png", url).toString(), format: "markdown" }, ctx),
|
|
|
- )
|
|
|
+ const result = await exec({ url: new URL("/image.png", url).toString(), format: "markdown" })
|
|
|
expect(result.output).toBe("Image fetched successfully")
|
|
|
expect(result.attachments).toBeDefined()
|
|
|
expect(result.attachments?.length).toBe(1)
|
|
|
@@ -74,10 +72,7 @@ describe("tool.webfetch", () => {
|
|
|
await Instance.provide({
|
|
|
directory: projectRoot,
|
|
|
fn: async () => {
|
|
|
- const webfetch = await initTool()
|
|
|
- const result = await Effect.runPromise(
|
|
|
- webfetch.execute({ url: new URL("/image.svg", url).toString(), format: "html" }, ctx),
|
|
|
- )
|
|
|
+ const result = await exec({ url: new URL("/image.svg", url).toString(), format: "html" })
|
|
|
expect(result.output).toContain("<svg")
|
|
|
expect(result.attachments).toBeUndefined()
|
|
|
},
|
|
|
@@ -97,10 +92,7 @@ describe("tool.webfetch", () => {
|
|
|
await Instance.provide({
|
|
|
directory: projectRoot,
|
|
|
fn: async () => {
|
|
|
- const webfetch = await initTool()
|
|
|
- const result = await Effect.runPromise(
|
|
|
- webfetch.execute({ url: new URL("/file.txt", url).toString(), format: "text" }, ctx),
|
|
|
- )
|
|
|
+ const result = await exec({ url: new URL("/file.txt", url).toString(), format: "text" })
|
|
|
expect(result.output).toBe("hello from webfetch")
|
|
|
expect(result.attachments).toBeUndefined()
|
|
|
},
|