@specstream/ai-sdk 0.3.0 → 0.4.1
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/README.md +31 -1
- package/dist/client.d.ts +79 -2
- package/dist/client.js +99 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/tools.d.ts +1926 -1
- package/dist/tools.js +117 -3
- package/package.json +3 -1
package/dist/tools.js
CHANGED
|
@@ -21,9 +21,13 @@ const getListResultsInput = z.object({
|
|
|
21
21
|
const webSearchInput = z.object({
|
|
22
22
|
q: z.string().min(1).max(2000).describe("The search question or request in everyday words (1 to 2,000 characters). Quoted phrases are searched as phrases."),
|
|
23
23
|
passages: z.boolean().optional().describe("Set true to include the main text passages of the top matching pages in the response."),
|
|
24
|
+
speed: z
|
|
25
|
+
.enum(["fast", "default"])
|
|
26
|
+
.optional()
|
|
27
|
+
.describe('"fast" returns the first ranked results in about a second for $1 per 1,000 searches; "default" adds the answer read from the pages, for $5 per 1,000. Left out, the default search runs.'),
|
|
24
28
|
});
|
|
25
29
|
const extractPagesInput = z.object({
|
|
26
|
-
urls: z.array(z.string().min(1)).min(1).max(20).describe("1 to 20 http or https URLs (web pages, PDF, Word, Excel) to read live."),
|
|
30
|
+
urls: z.array(z.string().min(1)).min(1).max(20).describe("1 to 20 http or https URLs (web pages, PDF, Word, Excel) to read live, or from SpecStream's own dated copy when a page is slow or refuses."),
|
|
27
31
|
format: z.enum(["markdown", "text"]).optional().describe('Output format: "markdown" (default) or "text".'),
|
|
28
32
|
});
|
|
29
33
|
const monitorListInput = z.object({
|
|
@@ -58,10 +62,10 @@ function baseTools(client, options) {
|
|
|
58
62
|
const { maxPriceUsd } = options;
|
|
59
63
|
return {
|
|
60
64
|
specstream_web_search: tool({
|
|
61
|
-
description: "Search the live web in seconds with the SpecStream Search API (GET /v1/web-search, $5 per 1,000 searches of up to 10 results,
|
|
65
|
+
description: "Search the live web in seconds with the SpecStream Search API (GET /v1/web-search, $5 per 1,000 searches of up to 10 results, no quote needed; speed 'fast' costs $1 per 1,000 and returns ranked results in about a second). " +
|
|
62
66
|
"Returns JSON with kind ('fact' or 'list'), answer (value, page and seen_at), matching rows, ranked sources and optional passages.",
|
|
63
67
|
inputSchema: webSearchInput,
|
|
64
|
-
execute: async ({ q, passages }, { abortSignal }) => client.webSearch(q, { passages, abortSignal }),
|
|
68
|
+
execute: async ({ q, passages, speed }, { abortSignal }) => client.webSearch(q, { passages, speed, abortSignal }),
|
|
65
69
|
}),
|
|
66
70
|
specstream_extract_pages: tool({
|
|
67
71
|
description: "Read the main text, title and published date of 1 to 20 web pages, PDFs, Word or Excel files live with the SpecStream Extract API " +
|
|
@@ -119,3 +123,113 @@ export function specstreamTools(options) {
|
|
|
119
123
|
return tools;
|
|
120
124
|
return { ...tools, ...monitorTools(client, monitorMax, options.monitorMaxPricePerMonthUsd) };
|
|
121
125
|
}
|
|
126
|
+
const sessionId = z.string().min(1).describe("The session_id returned by specstream_open_browser.");
|
|
127
|
+
const TARGET = "The element's reference from the last specstream_browser_snapshot (such as e12), or a unique selector.";
|
|
128
|
+
const CLOSE_HINT = "Call specstream_close_browser with this session_id when the work is done.";
|
|
129
|
+
const OPEN_BROWSER_DESCRIPTION = [
|
|
130
|
+
"Open a real browser in the cloud and get its session_id.",
|
|
131
|
+
"Use it when a page needs clicks, typed text, a sign-in the user gave you, or JavaScript before its content shows;",
|
|
132
|
+
"for the plain text of a known page, specstream_extract_pages is cheaper.",
|
|
133
|
+
"The browser costs money while it is open ($0.10 an hour by the second, and $0.001 a step),",
|
|
134
|
+
"so call specstream_close_browser with the session_id as soon as the work is done.",
|
|
135
|
+
].join(" ");
|
|
136
|
+
/**
|
|
137
|
+
* Tools that open a real browser at SpecStream and drive it step by step: open, go to a page, read it,
|
|
138
|
+
* list its elements, click, type, any other Playwright MCP step, and close.
|
|
139
|
+
*
|
|
140
|
+
* How long a browser may run, and so its highest price, is set here, in code, and is not a tool input.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const { text } = await generateText({
|
|
144
|
+
* model,
|
|
145
|
+
* tools: specstreamBrowserTools({ timeoutSeconds: 300, allowedDomains: ["example.com"] }),
|
|
146
|
+
* stopWhen: stepCountIs(12),
|
|
147
|
+
* prompt: "Open example.com, accept the cookie banner and read the pricing table.",
|
|
148
|
+
* });
|
|
149
|
+
*/
|
|
150
|
+
export function specstreamBrowserTools(options = {}) {
|
|
151
|
+
const client = new SpecStreamClient({ apiKey: options.apiKey, baseUrl: options.baseUrl ?? DEFAULT_BASE_URL, fetch: options.fetch });
|
|
152
|
+
if (!client.hasKey)
|
|
153
|
+
throw new Error(MISSING_KEY_MESSAGE);
|
|
154
|
+
const timeout = options.timeoutSeconds ?? 300;
|
|
155
|
+
if (!Number.isInteger(timeout) || timeout < 60 || timeout > 3600)
|
|
156
|
+
throw new Error("timeoutSeconds must be a whole number from 60 to 3600.");
|
|
157
|
+
const idle = options.idleTimeoutSeconds ?? 120;
|
|
158
|
+
if (!Number.isInteger(idle) || idle < 10 || idle > 600)
|
|
159
|
+
throw new Error("idleTimeoutSeconds must be a whole number from 10 to 600.");
|
|
160
|
+
return {
|
|
161
|
+
specstream_open_browser: tool({
|
|
162
|
+
description: OPEN_BROWSER_DESCRIPTION,
|
|
163
|
+
inputSchema: z.object({ url: z.string().optional().describe("A page to open first, as an http or https address.") }),
|
|
164
|
+
execute: async ({ url }, { abortSignal }) => {
|
|
165
|
+
const session = await client.openBrowser({
|
|
166
|
+
timeoutSeconds: timeout,
|
|
167
|
+
idleTimeoutSeconds: idle,
|
|
168
|
+
allowedDomains: options.allowedDomains,
|
|
169
|
+
blockMedia: options.blockMedia,
|
|
170
|
+
headless: options.headless,
|
|
171
|
+
metadata: options.metadata,
|
|
172
|
+
abortSignal,
|
|
173
|
+
});
|
|
174
|
+
const first = (url ?? "").trim();
|
|
175
|
+
if (first && session.session_id) {
|
|
176
|
+
session.page = await client.browserStep(session.session_id, "browser_navigate", { url: first }, abortSignal);
|
|
177
|
+
}
|
|
178
|
+
session.message = CLOSE_HINT;
|
|
179
|
+
return session;
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
specstream_browser_navigate: tool({
|
|
183
|
+
description: "Open an address in the session's browser. Returns the page's address and title after it loaded. One step, $0.001.",
|
|
184
|
+
inputSchema: z.object({ session_id: sessionId, url: z.string().min(1).describe("The http or https address to open.") }),
|
|
185
|
+
execute: async ({ session_id, url }, { abortSignal }) => client.browserStep(session_id, "browser_navigate", { url: url.trim() }, abortSignal),
|
|
186
|
+
}),
|
|
187
|
+
specstream_browser_read: tool({
|
|
188
|
+
description: "Read the text of the page the browser shows, as it stands after its JavaScript ran, in Markdown or plain text. One step, $0.001.",
|
|
189
|
+
inputSchema: z.object({ session_id: sessionId, format: z.enum(["markdown", "text"]).optional().describe('"markdown" (default) or "text".') }),
|
|
190
|
+
execute: async ({ session_id, format }, { abortSignal }) => client.browserStep(session_id, "browser_read", { format: format === "text" ? "text" : "markdown" }, abortSignal),
|
|
191
|
+
}),
|
|
192
|
+
specstream_browser_snapshot: tool({
|
|
193
|
+
description: "List the page's links, buttons and fields, each with a reference such as e12. Call it before a click or typed text, and again after the page changed. One step, $0.001.",
|
|
194
|
+
inputSchema: z.object({ session_id: sessionId }),
|
|
195
|
+
execute: async ({ session_id }, { abortSignal }) => client.browserStep(session_id, "browser_snapshot", {}, abortSignal),
|
|
196
|
+
}),
|
|
197
|
+
specstream_browser_click: tool({
|
|
198
|
+
description: "Click an element of the page by its reference from the last snapshot. One step, $0.001.",
|
|
199
|
+
inputSchema: z.object({
|
|
200
|
+
session_id: sessionId,
|
|
201
|
+
target: z.string().min(1).describe(TARGET),
|
|
202
|
+
element: z.string().optional().describe("What the element is, in a few words."),
|
|
203
|
+
}),
|
|
204
|
+
execute: async ({ session_id, target, element }, { abortSignal }) => client.browserStep(session_id, "browser_click", { target, element }, abortSignal),
|
|
205
|
+
}),
|
|
206
|
+
specstream_browser_type: tool({
|
|
207
|
+
description: "Type text into a field of the page by its reference from the last snapshot. One step, $0.001.",
|
|
208
|
+
inputSchema: z.object({
|
|
209
|
+
session_id: sessionId,
|
|
210
|
+
target: z.string().min(1).describe(TARGET),
|
|
211
|
+
text: z.string().describe("The text to type into the element."),
|
|
212
|
+
submit: z.boolean().optional().describe("Press Enter after the text."),
|
|
213
|
+
}),
|
|
214
|
+
execute: async ({ session_id, target, text, submit }, { abortSignal }) => client.browserStep(session_id, "browser_type", { target, text, submit: submit ? true : undefined }, abortSignal),
|
|
215
|
+
}),
|
|
216
|
+
specstream_browser_action: tool({
|
|
217
|
+
description: "Run any other step in the session's browser: browser_press_key, browser_select_option, browser_fill_form, browser_hover, " +
|
|
218
|
+
"browser_wait_for, browser_navigate_back, browser_tabs, browser_handle_dialog, browser_take_screenshot or another Playwright MCP tool name. One step, $0.001.",
|
|
219
|
+
inputSchema: z.object({
|
|
220
|
+
session_id: sessionId,
|
|
221
|
+
tool: z
|
|
222
|
+
.string()
|
|
223
|
+
.regex(/^browser_[a-z][a-z0-9_]{0,62}$/)
|
|
224
|
+
.describe("The step's name, such as browser_press_key."),
|
|
225
|
+
arguments: z.record(z.string(), z.unknown()).optional().describe("The step's arguments, as Playwright MCP names them."),
|
|
226
|
+
}),
|
|
227
|
+
execute: async ({ session_id, tool: step, arguments: args }, { abortSignal }) => client.browserStep(session_id, step, args ?? {}, abortSignal),
|
|
228
|
+
}),
|
|
229
|
+
specstream_close_browser: tool({
|
|
230
|
+
description: "Close the browser so its time stops being charged. Returns the seconds it ran, its steps and what the session cost. Free.",
|
|
231
|
+
inputSchema: z.object({ session_id: sessionId }),
|
|
232
|
+
execute: async ({ session_id }, { abortSignal }) => client.closeBrowser(session_id, abortSignal),
|
|
233
|
+
}),
|
|
234
|
+
};
|
|
235
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specstream/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "The live web data engine for the Vercel AI SDK: Search API ($5 per 1,000 searches of up to 10 results, or $1 on the fast tier), Extract API ($0.80 per 1,000 pages) and Deep Search.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -46,6 +46,8 @@
|
|
|
46
46
|
"agents",
|
|
47
47
|
"specstream",
|
|
48
48
|
"web-data",
|
|
49
|
+
"browser",
|
|
50
|
+
"browser-automation",
|
|
49
51
|
"live-web",
|
|
50
52
|
"lead-lists",
|
|
51
53
|
"enrichment",
|