From 9396c57b634636bd4e93a5416c6c5d8f191372e2 Mon Sep 17 00:00:00 2001 From: David Ibia Date: Sun, 9 Nov 2025 14:20:35 +0100 Subject: [PATCH] feat(websearch.ts): add PerplexitySearch plugin for quick and deep research capabilities --- .config/opencode/plugin/websearch.ts | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .config/opencode/plugin/websearch.ts diff --git a/.config/opencode/plugin/websearch.ts b/.config/opencode/plugin/websearch.ts new file mode 100644 index 0000000..653c1e1 --- /dev/null +++ b/.config/opencode/plugin/websearch.ts @@ -0,0 +1,73 @@ +import { type Plugin, tool } from "@opencode-ai/plugin"; + +export const PerplexitySearch: Plugin = async (ctx) => { + return { + tool: { + search: tool({ + description: + "Run a quick search query to search the internet for results using Perplexity AI. Use this for quick lookups, latest information, and documentation.", + args: { + query: tool.schema.string().describe("Search query to execute"), + }, + execute: async (args) => { + const url = "https://api.perplexity.ai/chat/completions"; + const response = await fetch(url, { + method: "POST", + headers: { + Authorization: "Bearer " + process.env.PERPLEXITY_API_KEY, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + model: "sonar", + messages: [ + { + role: "user", + content: args.query, + }, + ], + }), + }); + const data = await response.json(); + return JSON.stringify({ + answer: data.choices?.[0]?.message?.content, + citations: data.citations || [], + sources: data.search_results || [], + }); + }, + }), + + deepResearch: tool({ + description: + "Conduct an in-depth research using Perplexity's deep research model. Use this for exhaustive research, detailed analysis, comprehensive reports, or complex multi-source synthesis.", + args: { + query: tool.schema.string().describe("Research query or topic for exhaustive analysis"), + }, + execute: async (args) => { + const url = "https://api.perplexity.ai/chat/completions"; + const response = await fetch(url, { + method: "POST", + headers: { + Authorization: "Bearer " + process.env.PERPLEXITY_API_KEY, + "Content-Type": "application/json", + }, + body: JSON.stringify({ + model: "sonar-deep-research", + messages: [ + { + role: "user", + content: args.query, + }, + ], + }), + }); + const data = await response.json(); + return JSON.stringify({ + report: data.choices?.[0]?.message?.content, + citations: data.citations || [], + sources: data.search_results || [], + }); + }, + }), + }, + }; +};