Compare commits

...
Author SHA1 Message Date
Kit Langton ec21ffef44 refactor(core): call web search service directly 2026-09-03 14:55:55 -04:00
2 changed files with 10 additions and 16 deletions
+8 -9
View File
@@ -50,21 +50,20 @@ export const Plugin = {
agent: context.agent,
source: { type: "tool", messageID: context.messageID, id: context.id },
})
const search = (): Effect.Effect<Effect.Success<ReturnType<typeof ctx.websearch.query>>, unknown> =>
const search = (): Effect.Effect<WebSearch.Response, unknown> =>
websearch.default().pipe(
Effect.flatMap((provider) => {
if (!provider) return ctx.websearch.query(input)
if (!provider) return websearch.query(input)
return context
.progress({ provider: provider.id })
.pipe(Effect.andThen(ctx.websearch.query({ ...input, providerID: provider.id })))
.pipe(Effect.andThen(websearch.query({ ...input, providerID: provider.id })))
}),
Effect.catch((error) => {
if (!Schema.is(WebSearch.ProviderRequiredError)(error)) return Effect.fail(error)
Effect.catchTag("WebSearch.ProviderRequired", () => {
return providerSelectionLock
.withPermit(
Effect.gen(function* () {
if (yield* websearch.default()) return
const providers = (yield* ctx.websearch.providers()).data
const providers = yield* websearch.providers()
const defaultProvider = providers[0]
if (!defaultProvider) return yield* new WebSearch.ProviderRequiredError()
const response = yield* forms.ask({
@@ -141,15 +140,15 @@ export const Plugin = {
if (!providerID) return Effect.suspend(search)
return context
.progress({ provider: providerID })
.pipe(Effect.andThen(ctx.websearch.query({ ...input, providerID })))
.pipe(Effect.andThen(websearch.query({ ...input, providerID })))
}),
)
}),
)
const result = yield* search()
const output = {
provider: result.data.providerID,
results: result.data.results,
provider: result.providerID,
results: result.results,
}
const content = output.results.length
? output.results
+2 -7
View File
@@ -17,17 +17,11 @@ import { testEffect } from "./lib/effect"
import { imagePassthrough } from "./lib/image"
import { permissionLayer } from "./lib/permission"
import { toolIdentity, executeTool, registerToolPlugin, toolDefinitions } from "./lib/tool"
import { webSearchHost } from "./plugin/host"
import { TestWebSearch } from "./lib/websearch"
const webSearchToolNode = makeLocationNode({
name: "test/websearch-tool-plugin",
layer: Layer.effectDiscard(
Effect.gen(function* () {
const websearch = yield* WebSearch.Service
yield* registerToolPlugin(WebSearchTool.Plugin, { websearch: webSearchHost(websearch) })
}),
),
layer: Layer.effectDiscard(registerToolPlugin(WebSearchTool.Plugin)),
deps: [Tool.node, Permission.node, WebSearch.node, Form.node],
})
@@ -393,6 +387,7 @@ describe("WebSearchTool registration", () => {
}),
{ discard: true },
)
expect(fixture.formRequests).toEqual([])
}),
)
})