refactor(websearch): rename search domain
This commit is contained in:
parent
97aa6713b5
commit
c86f4e9b9b
51 changed files with 478 additions and 462 deletions
|
|
@ -20,7 +20,7 @@ import { QuestionHandler } from "./handlers/question"
|
|||
import { ReferenceHandler } from "./handlers/reference"
|
||||
import { LocationHandler } from "./handlers/location"
|
||||
import { IntegrationHandler } from "./handlers/integration"
|
||||
import { SearchHandler } from "./handlers/search"
|
||||
import { WebSearchHandler } from "./handlers/websearch"
|
||||
import { McpHandler } from "./handlers/mcp"
|
||||
import { CredentialHandler } from "./handlers/credential"
|
||||
import { ProjectHandler } from "./handlers/project"
|
||||
|
|
@ -39,7 +39,7 @@ export const handlers = Layer.mergeAll(
|
|||
GenerateHandler,
|
||||
ProviderHandler,
|
||||
IntegrationHandler,
|
||||
SearchHandler,
|
||||
WebSearchHandler,
|
||||
McpHandler,
|
||||
CredentialHandler,
|
||||
ProjectHandler,
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor"
|
||||
import { Search } from "@opencode-ai/core/search"
|
||||
import { InvalidRequestError, ServiceUnavailableError } from "@opencode-ai/protocol/errors"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
import { response } from "../location"
|
||||
|
||||
export const SearchHandler = HttpApiBuilder.group(Api, "server.search", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
const awaitPlugins = Effect.fn("server.search.awaitPlugins")(function* () {
|
||||
const plugins = yield* PluginSupervisor.Service
|
||||
yield* plugins.ready.pipe(
|
||||
Effect.timeoutOrElse({
|
||||
duration: "5 seconds",
|
||||
orElse: () =>
|
||||
Effect.fail(
|
||||
new ServiceUnavailableError({
|
||||
message: "Search integration initialization timed out",
|
||||
service: "search",
|
||||
}),
|
||||
),
|
||||
}),
|
||||
)
|
||||
})
|
||||
return handlers
|
||||
.handle(
|
||||
"search.provider.get",
|
||||
Effect.fn("server.search.provider.get")(function* () {
|
||||
const search = yield* Search.Service
|
||||
return yield* response(search.selected())
|
||||
}),
|
||||
)
|
||||
.handle(
|
||||
"search.provider.select",
|
||||
Effect.fn("server.search.provider.select")(function* (request) {
|
||||
yield* awaitPlugins()
|
||||
const search = yield* Search.Service
|
||||
yield* search.select(request.payload.providerID).pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Search provider not found: ${error.providerID}`,
|
||||
kind: "search_provider_not_found",
|
||||
field: "providerID",
|
||||
}),
|
||||
),
|
||||
)
|
||||
return HttpApiSchema.NoContent.make()
|
||||
}),
|
||||
)
|
||||
.handle(
|
||||
"search.query",
|
||||
Effect.fn("server.search.query")(function* (request) {
|
||||
yield* awaitPlugins()
|
||||
const search = yield* Search.Service
|
||||
return yield* response(
|
||||
search.query(request.payload).pipe(
|
||||
Effect.catchTags({
|
||||
"Search.ProviderRequired": () =>
|
||||
new InvalidRequestError({
|
||||
message: "Search provider is required",
|
||||
kind: "search_provider_required",
|
||||
field: "providerID",
|
||||
}),
|
||||
"Search.ProviderNotFound": (error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Search provider not found: ${error.providerID}`,
|
||||
kind: "search_provider_not_found",
|
||||
field: "providerID",
|
||||
}),
|
||||
"Search.ConnectionRequired": (error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Search provider requires a connection: ${error.providerID}`,
|
||||
kind: "search_connection_required",
|
||||
field: "providerID",
|
||||
}),
|
||||
"Search.Cancelled": () =>
|
||||
new InvalidRequestError({ message: "Search cancelled", kind: "search_cancelled" }),
|
||||
"Search.Request": (error) =>
|
||||
new ServiceUnavailableError({
|
||||
message: `Search request failed: ${error.providerID}`,
|
||||
service: error.providerID,
|
||||
}),
|
||||
}),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
91
packages/server/src/handlers/websearch.ts
Normal file
91
packages/server/src/handlers/websearch.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
import { PluginSupervisor } from "@opencode-ai/core/plugin/supervisor"
|
||||
import { WebSearch } from "@opencode-ai/core/websearch"
|
||||
import { InvalidRequestError, ServiceUnavailableError } from "@opencode-ai/protocol/errors"
|
||||
import { Effect } from "effect"
|
||||
import { HttpApiBuilder, HttpApiSchema } from "effect/unstable/httpapi"
|
||||
import { Api } from "../api"
|
||||
import { response } from "../location"
|
||||
|
||||
export const WebSearchHandler = HttpApiBuilder.group(Api, "server.websearch", (handlers) =>
|
||||
Effect.gen(function* () {
|
||||
const awaitPlugins = Effect.fn("server.websearch.awaitPlugins")(function* () {
|
||||
const plugins = yield* PluginSupervisor.Service
|
||||
yield* plugins.ready.pipe(
|
||||
Effect.timeoutOrElse({
|
||||
duration: "5 seconds",
|
||||
orElse: () =>
|
||||
Effect.fail(
|
||||
new ServiceUnavailableError({
|
||||
message: "Web search integration initialization timed out",
|
||||
service: "websearch",
|
||||
}),
|
||||
),
|
||||
}),
|
||||
)
|
||||
})
|
||||
return handlers
|
||||
.handle(
|
||||
"websearch.provider.get",
|
||||
Effect.fn("server.websearch.provider.get")(function* () {
|
||||
const websearch = yield* WebSearch.Service
|
||||
return yield* response(websearch.selected())
|
||||
}),
|
||||
)
|
||||
.handle(
|
||||
"websearch.provider.select",
|
||||
Effect.fn("server.websearch.provider.select")(function* (request) {
|
||||
yield* awaitPlugins()
|
||||
const websearch = yield* WebSearch.Service
|
||||
yield* websearch.select(request.payload.providerID).pipe(
|
||||
Effect.mapError(
|
||||
(error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Web search provider not found: ${error.providerID}`,
|
||||
kind: "websearch_provider_not_found",
|
||||
field: "providerID",
|
||||
}),
|
||||
),
|
||||
)
|
||||
return HttpApiSchema.NoContent.make()
|
||||
}),
|
||||
)
|
||||
.handle(
|
||||
"websearch.query",
|
||||
Effect.fn("server.websearch.query")(function* (request) {
|
||||
yield* awaitPlugins()
|
||||
const websearch = yield* WebSearch.Service
|
||||
return yield* response(
|
||||
websearch.query(request.payload).pipe(
|
||||
Effect.catchTags({
|
||||
"WebSearch.ProviderRequired": () =>
|
||||
new InvalidRequestError({
|
||||
message: "Web search provider is required",
|
||||
kind: "websearch_provider_required",
|
||||
field: "providerID",
|
||||
}),
|
||||
"WebSearch.ProviderNotFound": (error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Web search provider not found: ${error.providerID}`,
|
||||
kind: "websearch_provider_not_found",
|
||||
field: "providerID",
|
||||
}),
|
||||
"WebSearch.ConnectionRequired": (error) =>
|
||||
new InvalidRequestError({
|
||||
message: `Web search provider requires a connection: ${error.providerID}`,
|
||||
kind: "websearch_connection_required",
|
||||
field: "providerID",
|
||||
}),
|
||||
"WebSearch.Cancelled": () =>
|
||||
new InvalidRequestError({ message: "Web search cancelled", kind: "websearch_cancelled" }),
|
||||
"WebSearch.Request": (error) =>
|
||||
new ServiceUnavailableError({
|
||||
message: `Web search request failed: ${error.providerID}`,
|
||||
service: error.providerID,
|
||||
}),
|
||||
}),
|
||||
),
|
||||
)
|
||||
}),
|
||||
)
|
||||
}),
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue