webseek 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +153 -0
- package/dist/cli/index.cjs +217 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +218 -0
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +177 -0
- package/dist/index.d.mts +177 -0
- package/dist/index.mjs +2 -0
- package/dist/tools-CCqL3Phx.mjs +550 -0
- package/dist/tools-Cd93c2_h.cjs +615 -0
- package/package.json +98 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/config/env.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolves provider credentials and configuration from environment variables.
|
|
6
|
+
*
|
|
7
|
+
* API keys are read from the environment only (never from CLI flags/args) so
|
|
8
|
+
* they don't leak into shell history or process listings.
|
|
9
|
+
*
|
|
10
|
+
* Each provider's base URL can be overridden via an environment variable. This
|
|
11
|
+
* keeps the defaults pointed at the real services while letting tests (and
|
|
12
|
+
* proxies) redirect traffic to a local endpoint.
|
|
13
|
+
*/
|
|
14
|
+
interface Env {
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
type GeminiBackend = "gemini-api" | "vertex-express";
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/providers/provider.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Shared types and the provider interface for the webseek CLI.
|
|
22
|
+
*
|
|
23
|
+
* Web search providers fall into two categories that this schema normalizes:
|
|
24
|
+
* - SERP-style providers (e.g. Google Custom Search) return a ranked list of
|
|
25
|
+
* links in `results`.
|
|
26
|
+
* - LLM-grounded providers (e.g. OpenAI web search, Gemini grounding) return a
|
|
27
|
+
* synthesized `answer` plus `citations` and the underlying `searchQueries`.
|
|
28
|
+
*/
|
|
29
|
+
type ProviderName = "openai" | "google" | "gemini";
|
|
30
|
+
/** A single SERP-style result (one link). */
|
|
31
|
+
interface SearchResultItem {
|
|
32
|
+
title: string;
|
|
33
|
+
url: string;
|
|
34
|
+
snippet: string;
|
|
35
|
+
displayLink?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A single source citation backing a grounded answer. */
|
|
38
|
+
interface Citation {
|
|
39
|
+
url: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
/** Character offsets into `answer` that this citation supports, if known. */
|
|
42
|
+
startIndex?: number;
|
|
43
|
+
endIndex?: number;
|
|
44
|
+
}
|
|
45
|
+
/** The normalized result shape returned by every provider. */
|
|
46
|
+
interface NormalizedSearchResult {
|
|
47
|
+
provider: ProviderName;
|
|
48
|
+
query: string;
|
|
49
|
+
/** SERP-style results (empty for grounded providers). */
|
|
50
|
+
results: SearchResultItem[];
|
|
51
|
+
/** Grounded answer text, if the provider synthesizes one. */
|
|
52
|
+
answer?: string;
|
|
53
|
+
/** Sources backing the answer (grounded providers). */
|
|
54
|
+
citations: Citation[];
|
|
55
|
+
/** Queries the provider actually ran (grounded providers). */
|
|
56
|
+
searchQueries: string[];
|
|
57
|
+
/** The provider's raw response, included only when requested. */
|
|
58
|
+
raw?: unknown;
|
|
59
|
+
}
|
|
60
|
+
/** Options shared by every provider's `search` call. */
|
|
61
|
+
interface SearchParams {
|
|
62
|
+
query: string;
|
|
63
|
+
/** Desired number of results; best-effort for grounded providers. */
|
|
64
|
+
maxResults?: number;
|
|
65
|
+
/** Model override for LLM-backed providers. */
|
|
66
|
+
model?: string;
|
|
67
|
+
/** Include the provider's raw response in the result. */
|
|
68
|
+
includeRaw?: boolean;
|
|
69
|
+
/** Injectable fetch for testing; defaults to the global `fetch`. */
|
|
70
|
+
fetchImpl?: typeof fetch;
|
|
71
|
+
}
|
|
72
|
+
/** A web search provider. Implementations are stateless given their config. */
|
|
73
|
+
interface SearchProvider {
|
|
74
|
+
readonly name: ProviderName;
|
|
75
|
+
search(params: SearchParams): Promise<NormalizedSearchResult>;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/lib/search.d.ts
|
|
79
|
+
declare const PROVIDER_NAMES: readonly ["openai", "google", "gemini"];
|
|
80
|
+
declare const GEMINI_BACKENDS: readonly ["gemini-api", "vertex-express"];
|
|
81
|
+
interface RunSearchParams {
|
|
82
|
+
provider: ProviderName;
|
|
83
|
+
query: string;
|
|
84
|
+
maxResults?: number;
|
|
85
|
+
model?: string;
|
|
86
|
+
includeRaw?: boolean;
|
|
87
|
+
geminiBackend?: GeminiBackend;
|
|
88
|
+
env?: Env;
|
|
89
|
+
fetchImpl?: typeof fetch;
|
|
90
|
+
}
|
|
91
|
+
declare function runSearch(params: RunSearchParams): Promise<NormalizedSearchResult>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/error.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Consistent error formatting for the CLI.
|
|
96
|
+
*
|
|
97
|
+
* Provider calls fail in predictable ways (missing credentials, auth rejected,
|
|
98
|
+
* quota exhausted, malformed responses). `WebseekError` carries a stable
|
|
99
|
+
* `code` so the CLI can map failures to exit codes and a clear message, while
|
|
100
|
+
* `formatError` renders any thrown value into a single human-readable string.
|
|
101
|
+
*/
|
|
102
|
+
type WebseekErrorCode = "missing_config" | "auth_failed" | "rate_limited" | "provider_error" | "invalid_response" | "invalid_usage";
|
|
103
|
+
interface WebseekErrorOptions {
|
|
104
|
+
code: WebseekErrorCode;
|
|
105
|
+
message: string;
|
|
106
|
+
cause?: unknown;
|
|
107
|
+
}
|
|
108
|
+
declare class WebseekError extends Error {
|
|
109
|
+
readonly code: WebseekErrorCode;
|
|
110
|
+
constructor(options: WebseekErrorOptions);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Map a thrown value to a process exit code: `2` for usage mistakes, `1` for
|
|
114
|
+
* any other failure.
|
|
115
|
+
*/
|
|
116
|
+
declare function errorExitCode(error: unknown): number;
|
|
117
|
+
/** Render any thrown value into a single-line, user-facing message. */
|
|
118
|
+
declare function formatError(error: unknown): string;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/mcp/tools.d.ts
|
|
121
|
+
declare const webSearchInputShape: {
|
|
122
|
+
query: z.ZodString;
|
|
123
|
+
provider: z.ZodEnum<{
|
|
124
|
+
openai: "openai";
|
|
125
|
+
google: "google";
|
|
126
|
+
gemini: "gemini";
|
|
127
|
+
}>;
|
|
128
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
model: z.ZodOptional<z.ZodString>;
|
|
130
|
+
geminiBackend: z.ZodOptional<z.ZodEnum<{
|
|
131
|
+
"gemini-api": "gemini-api";
|
|
132
|
+
"vertex-express": "vertex-express";
|
|
133
|
+
}>>;
|
|
134
|
+
includeRaw: z.ZodOptional<z.ZodBoolean>;
|
|
135
|
+
};
|
|
136
|
+
declare const webSearchArgsSchema: z.ZodObject<{
|
|
137
|
+
query: z.ZodString;
|
|
138
|
+
provider: z.ZodEnum<{
|
|
139
|
+
openai: "openai";
|
|
140
|
+
google: "google";
|
|
141
|
+
gemini: "gemini";
|
|
142
|
+
}>;
|
|
143
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
model: z.ZodOptional<z.ZodString>;
|
|
145
|
+
geminiBackend: z.ZodOptional<z.ZodEnum<{
|
|
146
|
+
"gemini-api": "gemini-api";
|
|
147
|
+
"vertex-express": "vertex-express";
|
|
148
|
+
}>>;
|
|
149
|
+
includeRaw: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
type WebSearchArgs = z.infer<typeof webSearchArgsSchema>;
|
|
152
|
+
interface ToolResult {
|
|
153
|
+
content: {
|
|
154
|
+
type: "text";
|
|
155
|
+
text: string;
|
|
156
|
+
}[];
|
|
157
|
+
isError?: boolean;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
interface CreateWebSearchToolParams {
|
|
161
|
+
/** Injectable for tests; defaults to the process environment. */
|
|
162
|
+
env?: Env;
|
|
163
|
+
/** Injectable for tests; defaults to the global fetch. */
|
|
164
|
+
fetchImpl?: typeof fetch;
|
|
165
|
+
}
|
|
166
|
+
interface WebSearchTool {
|
|
167
|
+
name: string;
|
|
168
|
+
config: {
|
|
169
|
+
title: string;
|
|
170
|
+
description: string;
|
|
171
|
+
inputSchema: typeof webSearchInputShape;
|
|
172
|
+
};
|
|
173
|
+
handler: (args: WebSearchArgs) => Promise<ToolResult>;
|
|
174
|
+
}
|
|
175
|
+
declare function createWebSearchTool(params?: CreateWebSearchToolParams): WebSearchTool;
|
|
176
|
+
//#endregion
|
|
177
|
+
export { type Citation, type CreateWebSearchToolParams, type Env, GEMINI_BACKENDS, type GeminiBackend, type NormalizedSearchResult, PROVIDER_NAMES, type ProviderName, type RunSearchParams, type SearchParams, type SearchProvider, type SearchResultItem, type ToolResult, type WebSearchArgs, type WebSearchTool, WebseekError, type WebseekErrorCode, type WebseekErrorOptions, createWebSearchTool, errorExitCode, formatError, runSearch, webSearchInputShape };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/config/env.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Resolves provider credentials and configuration from environment variables.
|
|
6
|
+
*
|
|
7
|
+
* API keys are read from the environment only (never from CLI flags/args) so
|
|
8
|
+
* they don't leak into shell history or process listings.
|
|
9
|
+
*
|
|
10
|
+
* Each provider's base URL can be overridden via an environment variable. This
|
|
11
|
+
* keeps the defaults pointed at the real services while letting tests (and
|
|
12
|
+
* proxies) redirect traffic to a local endpoint.
|
|
13
|
+
*/
|
|
14
|
+
interface Env {
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
type GeminiBackend = "gemini-api" | "vertex-express";
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/providers/provider.d.ts
|
|
20
|
+
/**
|
|
21
|
+
* Shared types and the provider interface for the webseek CLI.
|
|
22
|
+
*
|
|
23
|
+
* Web search providers fall into two categories that this schema normalizes:
|
|
24
|
+
* - SERP-style providers (e.g. Google Custom Search) return a ranked list of
|
|
25
|
+
* links in `results`.
|
|
26
|
+
* - LLM-grounded providers (e.g. OpenAI web search, Gemini grounding) return a
|
|
27
|
+
* synthesized `answer` plus `citations` and the underlying `searchQueries`.
|
|
28
|
+
*/
|
|
29
|
+
type ProviderName = "openai" | "google" | "gemini";
|
|
30
|
+
/** A single SERP-style result (one link). */
|
|
31
|
+
interface SearchResultItem {
|
|
32
|
+
title: string;
|
|
33
|
+
url: string;
|
|
34
|
+
snippet: string;
|
|
35
|
+
displayLink?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A single source citation backing a grounded answer. */
|
|
38
|
+
interface Citation {
|
|
39
|
+
url: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
/** Character offsets into `answer` that this citation supports, if known. */
|
|
42
|
+
startIndex?: number;
|
|
43
|
+
endIndex?: number;
|
|
44
|
+
}
|
|
45
|
+
/** The normalized result shape returned by every provider. */
|
|
46
|
+
interface NormalizedSearchResult {
|
|
47
|
+
provider: ProviderName;
|
|
48
|
+
query: string;
|
|
49
|
+
/** SERP-style results (empty for grounded providers). */
|
|
50
|
+
results: SearchResultItem[];
|
|
51
|
+
/** Grounded answer text, if the provider synthesizes one. */
|
|
52
|
+
answer?: string;
|
|
53
|
+
/** Sources backing the answer (grounded providers). */
|
|
54
|
+
citations: Citation[];
|
|
55
|
+
/** Queries the provider actually ran (grounded providers). */
|
|
56
|
+
searchQueries: string[];
|
|
57
|
+
/** The provider's raw response, included only when requested. */
|
|
58
|
+
raw?: unknown;
|
|
59
|
+
}
|
|
60
|
+
/** Options shared by every provider's `search` call. */
|
|
61
|
+
interface SearchParams {
|
|
62
|
+
query: string;
|
|
63
|
+
/** Desired number of results; best-effort for grounded providers. */
|
|
64
|
+
maxResults?: number;
|
|
65
|
+
/** Model override for LLM-backed providers. */
|
|
66
|
+
model?: string;
|
|
67
|
+
/** Include the provider's raw response in the result. */
|
|
68
|
+
includeRaw?: boolean;
|
|
69
|
+
/** Injectable fetch for testing; defaults to the global `fetch`. */
|
|
70
|
+
fetchImpl?: typeof fetch;
|
|
71
|
+
}
|
|
72
|
+
/** A web search provider. Implementations are stateless given their config. */
|
|
73
|
+
interface SearchProvider {
|
|
74
|
+
readonly name: ProviderName;
|
|
75
|
+
search(params: SearchParams): Promise<NormalizedSearchResult>;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/lib/search.d.ts
|
|
79
|
+
declare const PROVIDER_NAMES: readonly ["openai", "google", "gemini"];
|
|
80
|
+
declare const GEMINI_BACKENDS: readonly ["gemini-api", "vertex-express"];
|
|
81
|
+
interface RunSearchParams {
|
|
82
|
+
provider: ProviderName;
|
|
83
|
+
query: string;
|
|
84
|
+
maxResults?: number;
|
|
85
|
+
model?: string;
|
|
86
|
+
includeRaw?: boolean;
|
|
87
|
+
geminiBackend?: GeminiBackend;
|
|
88
|
+
env?: Env;
|
|
89
|
+
fetchImpl?: typeof fetch;
|
|
90
|
+
}
|
|
91
|
+
declare function runSearch(params: RunSearchParams): Promise<NormalizedSearchResult>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/error.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* Consistent error formatting for the CLI.
|
|
96
|
+
*
|
|
97
|
+
* Provider calls fail in predictable ways (missing credentials, auth rejected,
|
|
98
|
+
* quota exhausted, malformed responses). `WebseekError` carries a stable
|
|
99
|
+
* `code` so the CLI can map failures to exit codes and a clear message, while
|
|
100
|
+
* `formatError` renders any thrown value into a single human-readable string.
|
|
101
|
+
*/
|
|
102
|
+
type WebseekErrorCode = "missing_config" | "auth_failed" | "rate_limited" | "provider_error" | "invalid_response" | "invalid_usage";
|
|
103
|
+
interface WebseekErrorOptions {
|
|
104
|
+
code: WebseekErrorCode;
|
|
105
|
+
message: string;
|
|
106
|
+
cause?: unknown;
|
|
107
|
+
}
|
|
108
|
+
declare class WebseekError extends Error {
|
|
109
|
+
readonly code: WebseekErrorCode;
|
|
110
|
+
constructor(options: WebseekErrorOptions);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Map a thrown value to a process exit code: `2` for usage mistakes, `1` for
|
|
114
|
+
* any other failure.
|
|
115
|
+
*/
|
|
116
|
+
declare function errorExitCode(error: unknown): number;
|
|
117
|
+
/** Render any thrown value into a single-line, user-facing message. */
|
|
118
|
+
declare function formatError(error: unknown): string;
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region src/mcp/tools.d.ts
|
|
121
|
+
declare const webSearchInputShape: {
|
|
122
|
+
query: z.ZodString;
|
|
123
|
+
provider: z.ZodEnum<{
|
|
124
|
+
openai: "openai";
|
|
125
|
+
google: "google";
|
|
126
|
+
gemini: "gemini";
|
|
127
|
+
}>;
|
|
128
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
129
|
+
model: z.ZodOptional<z.ZodString>;
|
|
130
|
+
geminiBackend: z.ZodOptional<z.ZodEnum<{
|
|
131
|
+
"gemini-api": "gemini-api";
|
|
132
|
+
"vertex-express": "vertex-express";
|
|
133
|
+
}>>;
|
|
134
|
+
includeRaw: z.ZodOptional<z.ZodBoolean>;
|
|
135
|
+
};
|
|
136
|
+
declare const webSearchArgsSchema: z.ZodObject<{
|
|
137
|
+
query: z.ZodString;
|
|
138
|
+
provider: z.ZodEnum<{
|
|
139
|
+
openai: "openai";
|
|
140
|
+
google: "google";
|
|
141
|
+
gemini: "gemini";
|
|
142
|
+
}>;
|
|
143
|
+
maxResults: z.ZodOptional<z.ZodNumber>;
|
|
144
|
+
model: z.ZodOptional<z.ZodString>;
|
|
145
|
+
geminiBackend: z.ZodOptional<z.ZodEnum<{
|
|
146
|
+
"gemini-api": "gemini-api";
|
|
147
|
+
"vertex-express": "vertex-express";
|
|
148
|
+
}>>;
|
|
149
|
+
includeRaw: z.ZodOptional<z.ZodBoolean>;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
type WebSearchArgs = z.infer<typeof webSearchArgsSchema>;
|
|
152
|
+
interface ToolResult {
|
|
153
|
+
content: {
|
|
154
|
+
type: "text";
|
|
155
|
+
text: string;
|
|
156
|
+
}[];
|
|
157
|
+
isError?: boolean;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
}
|
|
160
|
+
interface CreateWebSearchToolParams {
|
|
161
|
+
/** Injectable for tests; defaults to the process environment. */
|
|
162
|
+
env?: Env;
|
|
163
|
+
/** Injectable for tests; defaults to the global fetch. */
|
|
164
|
+
fetchImpl?: typeof fetch;
|
|
165
|
+
}
|
|
166
|
+
interface WebSearchTool {
|
|
167
|
+
name: string;
|
|
168
|
+
config: {
|
|
169
|
+
title: string;
|
|
170
|
+
description: string;
|
|
171
|
+
inputSchema: typeof webSearchInputShape;
|
|
172
|
+
};
|
|
173
|
+
handler: (args: WebSearchArgs) => Promise<ToolResult>;
|
|
174
|
+
}
|
|
175
|
+
declare function createWebSearchTool(params?: CreateWebSearchToolParams): WebSearchTool;
|
|
176
|
+
//#endregion
|
|
177
|
+
export { type Citation, type CreateWebSearchToolParams, type Env, GEMINI_BACKENDS, type GeminiBackend, type NormalizedSearchResult, PROVIDER_NAMES, type ProviderName, type RunSearchParams, type SearchParams, type SearchProvider, type SearchResultItem, type ToolResult, type WebSearchArgs, type WebSearchTool, WebseekError, type WebseekErrorCode, type WebseekErrorOptions, createWebSearchTool, errorExitCode, formatError, runSearch, webSearchInputShape };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { c as runSearch, d as formatError, i as PROVIDER_NAMES, l as WebseekError, n as webSearchInputShape, r as GEMINI_BACKENDS, t as createWebSearchTool, u as errorExitCode } from "./tools-CCqL3Phx.mjs";
|
|
2
|
+
export { GEMINI_BACKENDS, PROVIDER_NAMES, WebseekError, createWebSearchTool, errorExitCode, formatError, runSearch, webSearchInputShape };
|