11import { Command } from "commander" ;
2- import { request } from "../api .js" ;
2+ import { search , type SearchOptions } from "../sdk .js" ;
33import { printSearchResults , printJson } from "../output.js" ;
44
55const SEARCH_SERVICES = [
66 "google" , "bing" , "duckduckgo" , "yahoo" , "x" , "reddit" ,
77 "github" , "youtube" , "arxiv" , "wechat" , "bilibili" , "imdb" , "wikipedia" ,
88] ;
99
10- interface SearchResponse {
11- results : Array < {
12- title : string ;
13- link : string ;
14- snippet : string ;
15- content ?: string ;
16- } > ;
17- }
18-
1910export function registerSearchCommand ( program : Command ) : void {
2011 program
2112 . command ( "search <query>" )
@@ -28,17 +19,16 @@ export function registerSearchCommand(program: Command): void {
2819 . option ( "-t, --time <range>" , "time range: day, month, year" )
2920 . option ( "--json" , "output raw JSON" )
3021 . action ( async ( query : string , opts ) => {
31- const body : Record < string , unknown > = {
32- query,
33- max_results : parseInt ( opts . maxResults ) ,
34- search_service : opts . service ,
35- crawl_results : parseInt ( opts . crawl ) ,
22+ const options : SearchOptions = {
23+ maxResults : parseInt ( opts . maxResults ) ,
24+ searchService : opts . service ,
25+ crawlResults : parseInt ( opts . crawl ) ,
3626 } ;
37- if ( opts . include ) body . include_sites = opts . include ;
38- if ( opts . exclude ) body . exclude_sites = opts . exclude ;
39- if ( opts . time ) body . time_range = opts . time ;
27+ if ( opts . include ) options . includeSites = opts . include ;
28+ if ( opts . exclude ) options . excludeSites = opts . exclude ;
29+ if ( opts . time ) options . timeRange = opts . time ;
4030
41- const data = await request < SearchResponse > ( "/ search" , body ) ;
31+ const data = await search ( query , options ) ;
4232
4333 if ( opts . json ) {
4434 printJson ( data ) ;
0 commit comments