Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ The plugin's integrations depend on the OpenCode version:

- **OpenCode 2** registers the hosted SerpApi MCP server at
`https://mcp.serpapi.com/mcp`, using `SERPAPI_API_KEY` as its bearer header
when available. It also registers SerpApi as a native web-search provider
without changing OpenCode's provider selection, plus a direct HTTPS tool named
`serpapi_rest_search`. Existing user-defined MCP configuration is preserved.
when available. It also registers SerpApi as a native web-search provider and
uses it by default when `SERPAPI_API_KEY` is set and no provider is selected.
Existing provider selections, disabled web search, and user-defined MCP
configuration are preserved. The direct HTTPS tool is `serpapi_rest_search`.
- **OpenCode 1** registers the direct HTTPS tool as `serpapi_search` and adds
the bundled skill path. It does not automatically register the hosted MCP
server or a native web-search provider.
Expand Down
24 changes: 22 additions & 2 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ describe("V1 configuration", () => {
})

describe("OpenCode V2 adapter", () => {
it.each([
["an existing provider", "exa", "test-key"],
["disabled web search", false, "test-key"],
["missing credentials", undefined, undefined],
] as const)("does not set a default with %s", async (_label, selection, key) => {
if (key) process.env.SERPAPI_API_KEY = key
else delete process.env.SERPAPI_API_KEY

const editor = { add: vi.fn(), default: { get: () => selection, set: vi.fn() } }
await SerpApiV2Plugin.setup({
mcp: { transform: vi.fn() },
tool: { transform: vi.fn() },
skill: { transform: vi.fn() },
websearch: { transform: async (transform: (value: typeof editor) => void) => transform(editor) },
} as unknown as V2Context)

expect(editor.add).toHaveBeenCalledOnce()
expect(editor.default.set).not.toHaveBeenCalled()
})

it("registers the native search tool and provider, remote MCP server, and bundled skill", async () => {
const tools: Array<{ name: string; execute: (input: unknown, context: { signal: AbortSignal }) => Promise<{ content: string }> }> = []
const servers: Record<string, unknown> = {}
Expand Down Expand Up @@ -143,7 +163,7 @@ describe("OpenCode V2 adapter", () => {
expect(tools.map(({ name }) => name)).not.toContain("serpapi_search")
expect(providers.map(({ id }) => id)).toContain("serpapi")
expect(providers[0].name).toBe("SerpApi")
expect(defaultProvider).toBeUndefined()
expect(defaultProvider).toBe("serpapi")
expect(servers.serpapi).toMatchObject({
type: "remote",
url: "https://mcp.serpapi.com/mcp",
Expand Down Expand Up @@ -173,4 +193,4 @@ describe("OpenCode V2 adapter", () => {
await expect(providers[0].execute({ query: "headphones" }, { signal: new AbortController().signal }))
.rejects.toThrow("SerpApi web search failed: Failed to fetch https://serpapi.com/search.json?api_key=[REDACTED]")
})
})
})
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ export const SerpApiV2Plugin: V2Plugin = {
return executeWebSearch(query, toolContext.signal)
},
})
if (process.env.SERPAPI_API_KEY && editor.default.get() === undefined) {
editor.default.set("serpapi")
}
})

await context.skill.transform((editor) => {
Expand Down