diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da66c3..106d0ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 2.2.0 - 2026-11-03 + +Adds `s1 maps ""` and a `maps()` SDK helper for `POST /maps`: one Google Maps page of up to 20 places with category, rating, address, phone, website, open state and Maps link. Options: `-n/--max-results`, `--near `, `--zoom`, `-p/--page` (page 2+ needs `--near`), `--country`, `-l/--lang`, `--json`. 3 credits per completed page. The agent skill routes "where is / nearby / list of businesses" requests to it. + ## 2.1.2 - 2026-10-29 When a command fails, `s1` prints a one-line hint under the error pointing to `s1 feedback`, so agents know they can report the problem. Updates the Agentback SDK to 0.3.0. No other behavior changes. diff --git a/README.md b/README.md index e8cf85b..8ff86d6 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,27 @@ s1 ask "recent papers on speculative decoding" --json Use `search` when you already know which engine and keywords you want. +### maps + +Find businesses and places on Google Maps. Each place shows its category, +rating, address, phone, website, open state, and Google Maps link. Each +completed page of up to 20 places costs 3 credits. + +```bash +s1 maps "ramen in Shibuya" +s1 maps "coffee shops" --near 40.7455,-74.0083 --zoom 15 -n 5 +s1 maps "coffee shops" --near 40.7455,-74.0083 --page 2 --json +``` + +| Option | Description | +|---|---| +| `-n, --max-results` | Places to return from the page (1-20); fewer places do not lower the price | +| `--near ` | Search around a point; required for page 2 and later | +| `--zoom` | Map zoom with `--near` (3-30, default 14) | +| `-p, --page` | Google Maps page (1-6); each page is billed separately | +| `--country` | Two-letter country code (default `us`) | +| `-l, --lang` | Result language such as `en`, `de`, `zh-CN` (default `en`) | + ### news Search for news articles. diff --git a/package-lock.json b/package-lock.json index 355bc94..cc60e5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "search1api-cli", - "version": "2.1.2", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "search1api-cli", - "version": "2.1.2", + "version": "2.2.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index bb1f460..7b0f7ae 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "search1api-cli", - "version": "2.1.2", - "description": "CLI tool for Search1API - web search, news, crawl, sitemap, and trending", + "version": "2.2.0", + "description": "CLI tool for Search1API - web search, maps, news, crawl, sitemap, and trending", "type": "module", "exports": { ".": { diff --git a/skills/search1api/SKILL.md b/skills/search1api/SKILL.md index 335e5ed..cb7271d 100644 --- a/skills/search1api/SKILL.md +++ b/skills/search1api/SKILL.md @@ -1,7 +1,7 @@ --- name: search1api description: > - Live web search, agentic search, page retrieval, news, sitemap discovery, trending topics, and turning a URL into a reusable Agent Skill — all through the Search1API CLI (`s1`). Use this skill whenever the user wants to search the web, look something up, research a topic, read or summarize a URL, check current news, explore a site's links, see trending topics, check API balance, or teach an agent a URL so it can be used later. Trigger on phrases like "search for", "look up", "find out about", "what's happening with", "any news on", "what does this link say", "read this page", "summarize this URL", "trending on GitHub", "learn this URL", "learn this site", "turn these docs into a skill", "记住这个链接", "学会这个文档", or when the user shares a bare URL. + Live web search, agentic search, Google Maps place search, page retrieval, news, sitemap discovery, trending topics, and turning a URL into a reusable Agent Skill — all through the Search1API CLI (`s1`). Use this skill whenever the user wants to search the web, look something up, research a topic, read or summarize a URL, check current news, find businesses or places on a map, explore a site's links, see trending topics, check API balance, or teach an agent a URL so it can be used later. Trigger on phrases like "search for", "look up", "find out about", "what's happening with", "any news on", "coffee shops near", "restaurants in", "what does this link say", "read this page", "summarize this URL", "trending on GitHub", "learn this URL", "learn this site", "turn these docs into a skill", "记住这个链接", "学会这个文档", or when the user shares a bare URL. --- # Search1API @@ -70,6 +70,7 @@ error. | Asks a question that spans sources, unsure where to look | `s1 ask ""` | | Wants the full page behind a search result | `s1 crawl ` | | Wants news | `s1 news ""` | +| Wants businesses or places on a map (where is, nearby, a list of shops) | `s1 maps ""` | | Wants to explore a site's links | `s1 sitemap ` | | Wants trending topics | `s1 trending ` | | Wants to check remaining credits | `s1 balance` | @@ -162,6 +163,19 @@ like "this week", and returns at most 10 relevant results with their source engine and relevance score. The first line of the output shows which engines and window were used. Costs 5 credits per completed request. +### maps + +```bash +s1 maps "" [-n 1-20] [--near ] [--zoom 3-30] [-p 1-6] [--country ] [-l ] [--json] +``` + +Finds businesses and places on Google Maps: name, category, rating, address, +phone, website, open state, and a Google Maps link. Put the area in the query +("ramen in Shibuya") or pass `--near` for a point; page 2 and later need +`--near`. Costs 3 credits per page of up to 20 places, however many you show, +so don't page further than the user needs. `crawl` a place's website for more +detail. + ### crawl ```bash diff --git a/src/commands/maps.ts b/src/commands/maps.ts new file mode 100644 index 0000000..d47b37f --- /dev/null +++ b/src/commands/maps.ts @@ -0,0 +1,57 @@ +import { Command } from "commander"; +import { maps, type MapsOptions } from "../sdk.js"; +import { printMapsResults, printJson } from "../output.js"; + +function parseNumber(value: string, name: string): number { + const parsed = Number(value); + if (!Number.isFinite(parsed)) { + throw new Error(`${name} must be a number`); + } + return parsed; +} + +/** `--near 40.7455,-74.0083` → `{ latitude, longitude }`. */ +function parseNear(value: string): { latitude: number; longitude: number } { + const parts = value.split(",").map((part) => part.trim()); + if (parts.length !== 2) { + throw new Error('--near must be "latitude,longitude", e.g. 40.7455,-74.0083'); + } + return { + latitude: parseNumber(parts[0], "latitude"), + longitude: parseNumber(parts[1], "longitude"), + }; +} + +export function registerMapsCommand(program: Command): void { + program + .command("maps ") + .description("Find businesses and places on Google Maps (3 credits per page of up to 20)") + .option("-n, --max-results ", "places to return from the page (1-20)") + .option("--near ", "search around this point, e.g. 40.7455,-74.0083") + .option("--zoom ", "map zoom with --near (3-30, default 14)") + .option("-p, --page ", "Google Maps page (1-6); page 2+ needs --near") + .option("--country ", "two-letter country code (default us)") + .option("-l, --lang ", "result language, e.g. en, de, zh-CN (default en)") + .option("--json", "output raw JSON") + .action(async (query: string, opts) => { + const options: MapsOptions = {}; + if (opts.maxResults) options.maxResults = parseInt(opts.maxResults); + if (opts.page) options.page = parseInt(opts.page); + if (opts.country) options.country = opts.country; + if (opts.lang) options.language = opts.lang; + if (opts.near) { + options.location = parseNear(opts.near); + if (opts.zoom) options.location.zoom = parseNumber(opts.zoom, "zoom"); + } else if (opts.zoom) { + throw new Error("--zoom needs --near"); + } + + const data = await maps(query, options); + + if (opts.json) { + printJson(data); + } else { + printMapsResults(data.results); + } + }); +} diff --git a/src/index.ts b/src/index.ts index 4f74ae2..fa0b626 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ if (isBinary && notifier.update) { } import { registerNewsCommand } from "./commands/news.js"; import { registerAskCommand } from "./commands/ask.js"; +import { registerMapsCommand } from "./commands/maps.js"; import { registerCrawlCommand } from "./commands/crawl.js"; import { registerSitemapCommand } from "./commands/sitemap.js"; import { registerLearnCommand } from "./commands/learn.js"; @@ -45,12 +46,13 @@ const program = new Command(); program .name("search1api") - .description("CLI for Search1API - search, ask, news, crawl, sitemap, learn & trending") + .description("CLI for Search1API - search, ask, maps, news, crawl, sitemap, learn & trending") .version(pkg.version); registerSearchCommand(program); registerNewsCommand(program); registerAskCommand(program); +registerMapsCommand(program); registerCrawlCommand(program); registerSitemapCommand(program); registerLearnCommand(program); @@ -69,6 +71,7 @@ if (process.argv.length <= 2) { ${chalk.bold("Quick start:")} ${chalk.blue("s1 search")} ${chalk.dim('"your query"')} Search the web ${chalk.blue("s1 ask")} ${chalk.dim('"your question"')} Let Search1API pick the sources + ${chalk.blue("s1 maps")} ${chalk.dim('"coffee shops"')} Find places on Google Maps ${chalk.blue("s1 news")} ${chalk.dim('"your query"')} Search for news ${chalk.blue("s1 crawl")} ${chalk.dim("")} Extract content from a URL ${chalk.blue("s1 learn")} ${chalk.dim("")} Turn a URL into an Agent Skill diff --git a/src/output.ts b/src/output.ts index 80c24c7..a402f6c 100644 --- a/src/output.ts +++ b/src/output.ts @@ -71,6 +71,42 @@ export function printAskResults(data: AskResponse): void { } } +interface MapsPlace { + name: string; + maps_url: string; + address?: string; + phone?: string; + website?: string; + category?: string; + rating?: number; + review_count?: number; + open_state?: string; + price?: string; +} + +export function printMapsResults(results: MapsPlace[]): void { + if (!results.length) { + console.log(chalk.yellow("No places found.")); + return; + } + + for (let i = 0; i < results.length; i++) { + const p = results[i]; + console.log(chalk.bold.blue(`${i + 1}. ${p.name}`)); + const rating = + p.rating !== undefined + ? `${p.rating}★${p.review_count !== undefined ? ` (${p.review_count})` : ""}` + : undefined; + const summary = [p.category, rating, p.price, p.open_state].filter(Boolean).join(" · "); + if (summary) console.log(summary); + if (p.address) console.log(p.address); + const contact = [p.phone, p.website].filter(Boolean).join(" · "); + if (contact) console.log(contact); + console.log(chalk.dim(p.maps_url)); + console.log(); + } +} + export function printTrendingResults(results: TrendingResult[]): void { if (!results.length) { console.log(chalk.yellow("No trending results.")); diff --git a/src/sdk.ts b/src/sdk.ts index 56775c7..5ce885d 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -135,6 +135,51 @@ export interface AskResponse { errors: Array<{ source: string; message: string }>; } +export interface MapsLocation { + latitude: number; + longitude: number; + /** Map zoom, 3-30. The API defaults to 14. */ + zoom?: number; +} + +export interface MapsOptions extends RequestOptions { + /** Two-letter country code. The API defaults to `us`. */ + country?: string; + /** Result language such as `en` or `zh-CN`. The API defaults to `en`. */ + language?: string; + /** Search around this point. Required for page 2 and later. */ + location?: MapsLocation; + /** Google Maps page, 1-6. Each page is billed separately. */ + page?: number; + /** Places to return from the page, 1-20. Fewer places do not lower the price. */ + maxResults?: number; +} + +export interface MapsPlace { + position: number; + name: string; + place_id: string; + maps_url: string; + address?: string; + phone?: string; + website?: string; + thumbnail?: string; + category?: string; + categories?: string[]; + rating?: number; + review_count?: number; + coordinates?: { latitude: number; longitude: number }; + opening_hours?: Partial>; + open_state?: string; + price?: string; + description?: string; +} + +export interface MapsResponse { + searchParameters: Record; + results: MapsPlace[]; +} + export interface TrendingOptions extends RequestOptions { maxResults?: number; } @@ -190,6 +235,23 @@ export async function ask( return request("/ask", { query }, options); } +/** + * Google Maps place search: one page of up to 20 businesses and places. + * 3 credits per completed page. + */ +export async function maps( + query: string, + options: MapsOptions = {} +): Promise { + const body: Record = { query }; + if (options.country) body.country = options.country; + if (options.language) body.language = options.language; + if (options.location) body.location = options.location; + if (options.page !== undefined) body.page = options.page; + if (options.maxResults !== undefined) body.max_results = options.maxResults; + return request("/maps", body, options); +} + export async function crawl( url: string, options: RequestOptions = {} diff --git a/tests/commands.test.mjs b/tests/commands.test.mjs index f1b462c..41cbe43 100644 --- a/tests/commands.test.mjs +++ b/tests/commands.test.mjs @@ -44,6 +44,23 @@ test("exposes ask and the new search options", () => { assert.match(searchHelp.stdout, /day, week, month, year/); }); +test("exposes maps with location options", () => { + const help = runCli("--help"); + assert.equal(help.status, 0, help.stderr); + assert.match(help.stdout, /maps \[options\] /); + + const mapsHelp = runCli("maps", "--help"); + assert.equal(mapsHelp.status, 0, mapsHelp.stderr); + assert.match(mapsHelp.stdout, /--near /); + assert.match(mapsHelp.stdout, /--page /); +}); + +test("maps rejects a malformed --near before calling the API", () => { + const result = runCli("maps", "coffee", "--near", "40.7"); + assert.equal(result.status, 1); + assert.match(result.stderr, /--near must be "latitude,longitude"/); +}); + test("points agents at s1 feedback when a command fails", () => { const configDir = mkdtempSync(join(tmpdir(), "s1-config-")); const { SEARCH1API_KEY: _key, ...env } = process.env; diff --git a/tests/sdk.test.mjs b/tests/sdk.test.mjs index 8faf6c6..13b87a9 100644 --- a/tests/sdk.test.mjs +++ b/tests/sdk.test.mjs @@ -4,7 +4,7 @@ import test from "node:test"; process.env.SEARCH1API_KEY = "test-key"; process.env.SEARCH1API_API_BASE = "https://api.example.test"; -const { ask, crawl, news, search, sitemap, trending } = await import("../dist/sdk.js"); +const { ask, crawl, maps, news, search, sitemap, trending } = await import("../dist/sdk.js"); async function captureRequest(run, response) { const originalFetch = globalThis.fetch; @@ -131,3 +131,29 @@ test("ask sends only the query to /ask", async () => { query: "recent papers on speculative decoding", }); }); + +test("maps sends only the options that were set to /maps", async () => { + const response = { searchParameters: { query: "coffee shops" }, results: [] }; + const { captured, result } = await captureRequest( + () => + maps("coffee shops", { + location: { latitude: 40.7455, longitude: -74.0083, zoom: 15 }, + page: 2, + maxResults: 5, + country: "us", + }), + response + ); + assert.deepEqual(result, response); + assert.equal(captured.input, "https://api.example.test/maps"); + assert.deepEqual(JSON.parse(captured.init.body), { + query: "coffee shops", + country: "us", + location: { latitude: 40.7455, longitude: -74.0083, zoom: 15 }, + page: 2, + max_results: 5, + }); + + const minimal = await captureRequest(() => maps("ramen in Shibuya"), response); + assert.deepEqual(JSON.parse(minimal.captured.init.body), { query: "ramen in Shibuya" }); +});