@specstream/ai-sdk 0.2.2 → 0.3.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/README.md +49 -2
- package/dist/client.d.ts +73 -2
- package/dist/client.js +157 -2
- package/dist/index.d.ts +2 -2
- package/dist/tools.d.ts +414 -15
- package/dist/tools.js +47 -21
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ The tool's result wraps the rows with `status`, `list_id`, `list_link`, `row_cou
|
|
|
54
54
|
|
|
55
55
|
| Tool | The model gives | What happens | Cost |
|
|
56
56
|
| --- | --- | --- | --- |
|
|
57
|
-
| `specstream_web_search` | `q`, `passages` | Calls `GET /v1/web-search` and returns the answer, matching rows, ranked sources and optional page passages | $5 per 1,000 searches |
|
|
57
|
+
| `specstream_web_search` | `q`, `passages` | Calls `GET /v1/web-search` and returns the answer, matching rows, ranked sources and optional page passages | $5 per 1,000 searches of up to 10 results, $1 per 1,000 with `speed=fast` |
|
|
58
58
|
| `specstream_extract_pages` | `urls`, `format` | Calls `POST /v1/extract` and returns the clean main text, title and published date of 1 to 20 web pages, PDFs, Word or Excel files | $0.80 per 1,000 pages (empty pages free) |
|
|
59
59
|
| `specstream_find_list` | `request`, `maxResults` (1 to 1000, default 25) | Reads the request, prices it, starts it only within `maxPriceUsd`, waits up to `waitSeconds` (7 minutes by default) and returns every row | Only delivered rows |
|
|
60
60
|
| `specstream_get_list_results` | `listId` | Every row found so far, for a list that was still running | Free |
|
|
@@ -72,6 +72,8 @@ Settings, all optional except the price:
|
|
|
72
72
|
| `locale` | `en-US` | The language and region the request is written in |
|
|
73
73
|
| `baseUrl` | `https://api.specstream.ai` | The SpecStream API address |
|
|
74
74
|
| `fetch` | global `fetch` | Your own `fetch`, for a proxy or a test |
|
|
75
|
+
| `monitorMaxPricePerRunUsd` | not set | The most one check of a monitored list may cost. Set it to give the model the two monitor tools |
|
|
76
|
+
| `monitorMaxPricePerMonthUsd` | per check × checks in 31 days | The most one monitor may spend in a UTC calendar month |
|
|
75
77
|
|
|
76
78
|
Running on a serverless function? Set `waitSeconds` below the function's time limit. A list that's still running when the wait ends comes back with its `list_id`, and the agent reads the rest with `specstream_get_list_results`.
|
|
77
79
|
|
|
@@ -93,9 +95,54 @@ if ("rows" in list) console.log(list.row_count, list.rows[0].source_url);
|
|
|
93
95
|
else console.log(list.message); // "over_maximum" or "needs_edit": nothing ran
|
|
94
96
|
```
|
|
95
97
|
|
|
98
|
+
## Keep a list current on a schedule
|
|
99
|
+
|
|
100
|
+
A monitor checks a list again on the live web every hour, day, week or month.
|
|
101
|
+
Each check is a refresh: half the row rate for a row that changed or is new, and 1¢ for a row that comes back unchanged.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { SpecStreamClient } from "@specstream/ai-sdk";
|
|
105
|
+
|
|
106
|
+
const client = new SpecStreamClient();
|
|
107
|
+
|
|
108
|
+
const monitor = await client.monitorList("fnd_gk5y3d0r97bvyz0t08zzh75kr6", {
|
|
109
|
+
every: "week",
|
|
110
|
+
maxPricePerRunUsd: 2,
|
|
111
|
+
maxPricePerMonthUsd: 8,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (monitor.status === "saved") console.log(monitor.monitor_id, monitor.next_run_at);
|
|
115
|
+
else console.log(monitor.message); // "over_maximum": one check costs more than maxPricePerRunUsd, nothing was saved
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The client prices one check before it saves anything.
|
|
119
|
+
When one check can cost more than `maxPricePerRunUsd`, nothing is saved.
|
|
120
|
+
`maxPricePerMonthUsd` is the most the monitor spends in one UTC calendar month, checks run on demand included.
|
|
121
|
+
Without it, the limit is `maxPricePerRunUsd` times the checks in 31 days.
|
|
122
|
+
The first check runs one interval after the current hour began, and the monitor ends a year after it, unless you set `firstRunAt` and `until`.
|
|
123
|
+
|
|
124
|
+
| Call | What it does | Cost |
|
|
125
|
+
| --- | --- | --- |
|
|
126
|
+
| `monitorList(listId, options)` | Prices one check of the list and saves the schedule within your limits | Each check, within the limits |
|
|
127
|
+
| `monitors()` | Every monitor of the account, with its state, next check and last list | Free |
|
|
128
|
+
| `monitorRuns(monitorId)` | The recent checks, newest first: when, the outcome, the reason and the list each one made | Free |
|
|
129
|
+
| `runMonitorNow(monitorId)` | One check now, inside the monitor's limits. The regular times stay as they are | One check |
|
|
130
|
+
| `pauseMonitor(monitorId)`, `resumeMonitor(monitorId)` | Stops and starts the checks. A missed check is never bought later | Free |
|
|
131
|
+
| `deleteMonitor(monitorId)` | Ends the monitor. The lists it made stay yours | Free |
|
|
132
|
+
|
|
133
|
+
To let an agent start monitors, give the tools a maximum per check.
|
|
134
|
+
The model then gets `specstream_monitor_list` (it picks the list and how often) and `specstream_list_monitors`.
|
|
135
|
+
Without `monitorMaxPricePerRunUsd`, the model can't start recurring work.
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const tools = specstreamTools({ maxPriceUsd: 5, monitorMaxPricePerRunUsd: 2, monitorMaxPricePerMonthUsd: 20 });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Where each check's new and changed rows go (Slack, email, a sheet, a CRM or a webhook) is set on the monitor in your SpecStream workspace.
|
|
142
|
+
|
|
96
143
|
## Money, plainly
|
|
97
144
|
|
|
98
|
-
- `maxPriceUsd`
|
|
145
|
+
- `maxPriceUsd` and the monitor limits live in your code. The model never sees them and can't change them.
|
|
99
146
|
- You pay for rows that match. Candidates SpecStream couldn't confirm are left out and aren't billed.
|
|
100
147
|
- A retried step asking for the same list within the hour gets the list it already started, not a second bill. Agents retry. Your card shouldn't notice.
|
|
101
148
|
- Rates and plans: [specstream.ai/pricing](https://specstream.ai/pricing).
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The SpecStream REST calls the tools share: read a request, price it, start it within a maximum, read its rows. */
|
|
2
2
|
export declare const DEFAULT_BASE_URL = "https://api.specstream.ai";
|
|
3
|
-
export declare const USER_AGENT = "@specstream/ai-sdk/0.
|
|
3
|
+
export declare const USER_AGENT = "@specstream/ai-sdk/0.3.0";
|
|
4
4
|
/** A list runs for up to about five minutes, so the tools wait a little longer than that by default. */
|
|
5
5
|
export declare const DEFAULT_WAIT_SECONDS = 420;
|
|
6
6
|
export declare const DEFAULT_POLL_INTERVAL_SECONDS = 3;
|
|
@@ -106,7 +106,7 @@ export declare class SpecStreamClient {
|
|
|
106
106
|
constructor(options?: SpecStreamClientOptions);
|
|
107
107
|
get hasKey(): boolean;
|
|
108
108
|
private request;
|
|
109
|
-
/** Search the live web with GET /v1/web-search ($5 per 1,000 searches, no quote needed). */
|
|
109
|
+
/** Search the live web with GET /v1/web-search ($5 per 1,000 searches of up to 10 results, or $1 on the fast tier, no quote needed). */
|
|
110
110
|
webSearch(query: string, options?: {
|
|
111
111
|
passages?: boolean;
|
|
112
112
|
abortSignal?: AbortSignal;
|
|
@@ -120,5 +120,76 @@ export declare class SpecStreamClient {
|
|
|
120
120
|
results(findId: string, abortSignal?: AbortSignal): Promise<ListResults>;
|
|
121
121
|
/** Reads the request, prices it, and runs it only if the most it can cost is within `maxPriceUsd`. */
|
|
122
122
|
findList(request: string, options: FindListOptions): Promise<FindListResult>;
|
|
123
|
+
/**
|
|
124
|
+
* Checks a list again on a schedule. Each check reads the live web for the list's rows.
|
|
125
|
+
* Nothing is saved when one check can cost more than `maxPricePerRunUsd`.
|
|
126
|
+
*/
|
|
127
|
+
monitorList(listId: string, options: MonitorListOptions): Promise<MonitorListResult>;
|
|
128
|
+
/** Every monitor of the account, running, paused or ended. Reading is free. */
|
|
129
|
+
monitors(abortSignal?: AbortSignal): Promise<Monitor[]>;
|
|
130
|
+
/** A monitor's recent checks, newest first: each one's time, outcome, reason and the list it made. Reading is free. */
|
|
131
|
+
monitorRuns(monitorId: string, options?: {
|
|
132
|
+
limit?: number;
|
|
133
|
+
abortSignal?: AbortSignal;
|
|
134
|
+
}): Promise<MonitorRun[]>;
|
|
135
|
+
/** Checks the list once now, inside the monitor's own limits. Its regular times stay as they are. */
|
|
136
|
+
runMonitorNow(monitorId: string, abortSignal?: AbortSignal): Promise<{
|
|
137
|
+
monitor_id: string;
|
|
138
|
+
list_id: string;
|
|
139
|
+
started_at: string;
|
|
140
|
+
}>;
|
|
141
|
+
/** Stops the checks until `resumeMonitor`. Missed checks are never bought later. */
|
|
142
|
+
pauseMonitor(monitorId: string, abortSignal?: AbortSignal): Promise<Monitor>;
|
|
143
|
+
/** Starts the checks again from the next time due. */
|
|
144
|
+
resumeMonitor(monitorId: string, abortSignal?: AbortSignal): Promise<Monitor>;
|
|
145
|
+
/** Ends the monitor for good. The lists it made stay yours. */
|
|
146
|
+
deleteMonitor(monitorId: string, abortSignal?: AbortSignal): Promise<Monitor>;
|
|
147
|
+
private setMonitorState;
|
|
123
148
|
}
|
|
149
|
+
export type MonitorEvery = "hour" | "day" | "week" | "month";
|
|
150
|
+
export type MonitorListOptions = {
|
|
151
|
+
/** How often to check the list. "month" is every 30 days. Defaults to "day". */
|
|
152
|
+
every?: MonitorEvery;
|
|
153
|
+
/** The most one check may cost, in US dollars. Above it, nothing is saved. */
|
|
154
|
+
maxPricePerRunUsd: number;
|
|
155
|
+
/** The most the monitor may spend in one UTC calendar month, checks run on demand included. Defaults to the per-check maximum times the checks in 31 days. */
|
|
156
|
+
maxPricePerMonthUsd?: number;
|
|
157
|
+
/** The first check. Defaults to one interval after the current hour began. */
|
|
158
|
+
firstRunAt?: Date;
|
|
159
|
+
/** The monitor ends here. Defaults to one year after the first check. */
|
|
160
|
+
until?: Date;
|
|
161
|
+
abortSignal?: AbortSignal;
|
|
162
|
+
};
|
|
163
|
+
/** A saved monitor, as the API reports it. */
|
|
164
|
+
export type Monitor = {
|
|
165
|
+
status: "saved";
|
|
166
|
+
monitor_id: string;
|
|
167
|
+
list_id: string | null;
|
|
168
|
+
/** "active", "paused", "deleted" or another state the API reports, such as a monitor out of credit. */
|
|
169
|
+
state: string;
|
|
170
|
+
every_seconds: number;
|
|
171
|
+
next_run_at: string | null;
|
|
172
|
+
last_run_at: string | null;
|
|
173
|
+
last_list_id: string | null;
|
|
174
|
+
last_reason: string | null;
|
|
175
|
+
max_price_per_run_usd: number;
|
|
176
|
+
max_price_per_month_usd: number;
|
|
177
|
+
valid_until: string | null;
|
|
178
|
+
version: number;
|
|
179
|
+
list_link: string | null;
|
|
180
|
+
};
|
|
181
|
+
export type MonitorOverMaximum = {
|
|
182
|
+
status: "over_maximum";
|
|
183
|
+
list_id: string;
|
|
184
|
+
maximum_price_usd: number;
|
|
185
|
+
message: string;
|
|
186
|
+
};
|
|
187
|
+
export type MonitorListResult = Monitor | MonitorOverMaximum;
|
|
188
|
+
export type MonitorRun = {
|
|
189
|
+
due_at: string;
|
|
190
|
+
/** "started", "completed", "blocked", "missed" or another outcome the API reports. */
|
|
191
|
+
status: string;
|
|
192
|
+
reason: string | null;
|
|
193
|
+
list_id: string | null;
|
|
194
|
+
};
|
|
124
195
|
export {};
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The SpecStream REST calls the tools share: read a request, price it, start it within a maximum, read its rows. */
|
|
2
2
|
export const DEFAULT_BASE_URL = "https://api.specstream.ai";
|
|
3
|
-
export const USER_AGENT = "@specstream/ai-sdk/0.
|
|
3
|
+
export const USER_AGENT = "@specstream/ai-sdk/0.3.0";
|
|
4
4
|
/** A list runs for up to about five minutes, so the tools wait a little longer than that by default. */
|
|
5
5
|
export const DEFAULT_WAIT_SECONDS = 420;
|
|
6
6
|
export const DEFAULT_POLL_INTERVAL_SECONDS = 3;
|
|
@@ -150,7 +150,7 @@ export class SpecStreamClient {
|
|
|
150
150
|
throw new SpecStreamError("SpecStream returned a response this package couldn't read.");
|
|
151
151
|
return data;
|
|
152
152
|
}
|
|
153
|
-
/** Search the live web with GET /v1/web-search ($5 per 1,000 searches, no quote needed). */
|
|
153
|
+
/** Search the live web with GET /v1/web-search ($5 per 1,000 searches of up to 10 results, or $1 on the fast tier, no quote needed). */
|
|
154
154
|
async webSearch(query, options = {}) {
|
|
155
155
|
const q = (query ?? "").trim();
|
|
156
156
|
if (!q || q.length > 2000)
|
|
@@ -266,6 +266,161 @@ export class SpecStreamClient {
|
|
|
266
266
|
}
|
|
267
267
|
return found;
|
|
268
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Checks a list again on a schedule. Each check reads the live web for the list's rows.
|
|
271
|
+
* Nothing is saved when one check can cost more than `maxPricePerRunUsd`.
|
|
272
|
+
*/
|
|
273
|
+
async monitorList(listId, options) {
|
|
274
|
+
const findId = (listId ?? "").trim();
|
|
275
|
+
if (!findId)
|
|
276
|
+
throw new Error("Give the list_id of the list to monitor.");
|
|
277
|
+
const every = options.every ?? "day";
|
|
278
|
+
const cadenceSeconds = CADENCE_SECONDS[every];
|
|
279
|
+
if (!cadenceSeconds)
|
|
280
|
+
throw new Error('every must be "hour", "day", "week" or "month".');
|
|
281
|
+
const perRunCents = Math.round(Number(options.maxPricePerRunUsd) * 100);
|
|
282
|
+
if (!(perRunCents > 0))
|
|
283
|
+
throw new Error("maxPricePerRunUsd must be greater than 0.");
|
|
284
|
+
const periodCents = options.maxPricePerMonthUsd === undefined
|
|
285
|
+
? perRunCents * Math.ceil((31 * 86_400) / cadenceSeconds)
|
|
286
|
+
: Math.round(Number(options.maxPricePerMonthUsd) * 100);
|
|
287
|
+
if (!(periodCents >= perRunCents))
|
|
288
|
+
throw new Error("maxPricePerMonthUsd must cover at least one check.");
|
|
289
|
+
const { abortSignal } = options;
|
|
290
|
+
// Times come from the start of the hour, so a retried step sends the same schedule and gets the one it saved.
|
|
291
|
+
const hourStart = Math.floor(this.now() / 3_600_000) * 3_600_000;
|
|
292
|
+
const first = options.firstRunAt ? options.firstRunAt.getTime() : hourStart + cadenceSeconds * 1000;
|
|
293
|
+
const until = options.until ? options.until.getTime() : first + 365 * 86_400_000;
|
|
294
|
+
if (!Number.isFinite(first) || !Number.isFinite(until) || until <= first) {
|
|
295
|
+
throw new Error("until must come after the first check.");
|
|
296
|
+
}
|
|
297
|
+
const list = (await this.request("GET", `/v1/finds/${encodeURIComponent(findId)}`, undefined, { abortSignal })) ?? {};
|
|
298
|
+
if (typeof list.ast_hash !== "string" || !list.ast_hash) {
|
|
299
|
+
throw new SpecStreamError("SpecStream returned a response this package couldn't read.");
|
|
300
|
+
}
|
|
301
|
+
const units = Math.max(1, Math.min(Math.trunc(Number(list.requested_count)) || 25, 10_000));
|
|
302
|
+
// A list in a project is checked in that project; the API refuses any other.
|
|
303
|
+
const scope = {
|
|
304
|
+
ast_hash: list.ast_hash,
|
|
305
|
+
operation: "refresh",
|
|
306
|
+
parent_find_id: findId,
|
|
307
|
+
requested_units: units,
|
|
308
|
+
...(typeof list.project_id === "string" && list.project_id ? { project_id: list.project_id } : {}),
|
|
309
|
+
};
|
|
310
|
+
const quote = (await this.request("POST", "/v1/capacity/quotes", scope, { abortSignal })) ?? {};
|
|
311
|
+
const maximumCents = Math.trunc(Number(quote.maximum_cents)) || 0;
|
|
312
|
+
if (maximumCents > perRunCents) {
|
|
313
|
+
return {
|
|
314
|
+
status: "over_maximum",
|
|
315
|
+
list_id: findId,
|
|
316
|
+
maximum_price_usd: maximumCents / 100,
|
|
317
|
+
message: `Nothing was saved: one check of this list can cost up to ${dollars(maximumCents)}, above the maximum of ${dollars(perRunCents)} per check. Raise maxPricePerRunUsd.`,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
const firstDueAt = new Date(first).toISOString();
|
|
321
|
+
const validUntil = new Date(until).toISOString();
|
|
322
|
+
const digest = await sha256Hex(`${findId}|${cadenceSeconds}|${perRunCents}|${periodCents}|${firstDueAt}|${validUntil}`);
|
|
323
|
+
const schedule = (await this.request("POST", "/v1/capacity/schedules", {
|
|
324
|
+
idempotency_key: `${this.keyPrefix}-monitor-${digest.slice(0, 32)}`,
|
|
325
|
+
scope,
|
|
326
|
+
cadence_seconds: cadenceSeconds,
|
|
327
|
+
first_due_at: firstDueAt,
|
|
328
|
+
per_run_cents: perRunCents,
|
|
329
|
+
period_cents: periodCents,
|
|
330
|
+
valid_until: validUntil,
|
|
331
|
+
}, { abortSignal })) ?? {};
|
|
332
|
+
return monitorView(schedule);
|
|
333
|
+
}
|
|
334
|
+
/** Every monitor of the account, running, paused or ended. Reading is free. */
|
|
335
|
+
async monitors(abortSignal) {
|
|
336
|
+
const found = [];
|
|
337
|
+
let after = null;
|
|
338
|
+
for (;;) {
|
|
339
|
+
const query = new URLSearchParams({ limit: "100", ...(after ? { after } : {}) });
|
|
340
|
+
const page = (await this.request("GET", `/v1/capacity/schedules?${query}`, undefined, { abortSignal })) ?? {};
|
|
341
|
+
for (const item of Array.isArray(page.schedules) ? page.schedules : []) {
|
|
342
|
+
if (isObject(item))
|
|
343
|
+
found.push(monitorView(item));
|
|
344
|
+
}
|
|
345
|
+
const next = typeof page.next_after === "string" && page.next_after ? page.next_after : null;
|
|
346
|
+
if (!next || next === after)
|
|
347
|
+
break;
|
|
348
|
+
after = next;
|
|
349
|
+
}
|
|
350
|
+
return found;
|
|
351
|
+
}
|
|
352
|
+
/** A monitor's recent checks, newest first: each one's time, outcome, reason and the list it made. Reading is free. */
|
|
353
|
+
async monitorRuns(monitorId, options = {}) {
|
|
354
|
+
const limit = Math.max(1, Math.min(Math.trunc(Number(options.limit ?? 50)) || 50, 100));
|
|
355
|
+
const page = (await this.request("GET", `/v1/capacity/schedules/${encodeURIComponent(requireId(monitorId))}/occurrences?limit=${limit}`, undefined, { abortSignal: options.abortSignal })) ?? {};
|
|
356
|
+
return (Array.isArray(page.occurrences) ? page.occurrences : []).filter(isObject).map((item) => ({
|
|
357
|
+
due_at: String(item.due_at ?? ""),
|
|
358
|
+
status: String(item.status ?? ""),
|
|
359
|
+
reason: item.reason == null ? null : String(item.reason),
|
|
360
|
+
list_id: item.find_id == null ? null : String(item.find_id),
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
/** Checks the list once now, inside the monitor's own limits. Its regular times stay as they are. */
|
|
364
|
+
async runMonitorNow(monitorId, abortSignal) {
|
|
365
|
+
const id = requireId(monitorId);
|
|
366
|
+
const run = (await this.request("POST", `/v1/capacity/schedules/${encodeURIComponent(id)}/run`, undefined, { abortSignal })) ?? {};
|
|
367
|
+
if (!run.find_id)
|
|
368
|
+
throw new SpecStreamError("SpecStream returned a response this package couldn't read.");
|
|
369
|
+
return { monitor_id: id, list_id: String(run.find_id), started_at: String(run.started_at ?? "") };
|
|
370
|
+
}
|
|
371
|
+
/** Stops the checks until `resumeMonitor`. Missed checks are never bought later. */
|
|
372
|
+
pauseMonitor(monitorId, abortSignal) {
|
|
373
|
+
return this.setMonitorState(monitorId, "paused", abortSignal);
|
|
374
|
+
}
|
|
375
|
+
/** Starts the checks again from the next time due. */
|
|
376
|
+
resumeMonitor(monitorId, abortSignal) {
|
|
377
|
+
return this.setMonitorState(monitorId, "active", abortSignal);
|
|
378
|
+
}
|
|
379
|
+
/** Ends the monitor for good. The lists it made stay yours. */
|
|
380
|
+
deleteMonitor(monitorId, abortSignal) {
|
|
381
|
+
return this.setMonitorState(monitorId, "deleted", abortSignal);
|
|
382
|
+
}
|
|
383
|
+
async setMonitorState(monitorId, state, abortSignal) {
|
|
384
|
+
const id = requireId(monitorId);
|
|
385
|
+
const current = (await this.monitors(abortSignal)).find((monitor) => monitor.monitor_id === id);
|
|
386
|
+
if (!current)
|
|
387
|
+
throw new SpecStreamError(`No monitor ${id} on this account.`);
|
|
388
|
+
const changed = (await this.request("PATCH", `/v1/capacity/schedules/${encodeURIComponent(id)}`, { expected_version: current.version, state }, { abortSignal })) ?? {};
|
|
389
|
+
return monitorView(changed);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
const CADENCE_SECONDS = { hour: 3_600, day: 86_400, week: 604_800, month: 2_592_000 };
|
|
393
|
+
function requireId(monitorId) {
|
|
394
|
+
const id = (monitorId ?? "").trim();
|
|
395
|
+
if (!id)
|
|
396
|
+
throw new Error("Give the monitor_id.");
|
|
397
|
+
return id;
|
|
398
|
+
}
|
|
399
|
+
function optionalText(value) {
|
|
400
|
+
return typeof value === "string" && value ? value : null;
|
|
401
|
+
}
|
|
402
|
+
function monitorView(data) {
|
|
403
|
+
if (typeof data.schedule_id !== "string" || !data.schedule_id) {
|
|
404
|
+
throw new SpecStreamError("SpecStream returned a response this package couldn't read.");
|
|
405
|
+
}
|
|
406
|
+
const scope = isObject(data.scope) ? data.scope : {};
|
|
407
|
+
const listId = optionalText(scope.parent_find_id);
|
|
408
|
+
return {
|
|
409
|
+
status: "saved",
|
|
410
|
+
monitor_id: data.schedule_id,
|
|
411
|
+
list_id: listId,
|
|
412
|
+
state: String(data.state ?? ""),
|
|
413
|
+
every_seconds: Math.trunc(Number(data.cadence_seconds)) || 0,
|
|
414
|
+
next_run_at: optionalText(data.next_due_at),
|
|
415
|
+
last_run_at: optionalText(data.last_occurrence_at),
|
|
416
|
+
last_list_id: optionalText(data.last_find_id),
|
|
417
|
+
last_reason: optionalText(data.last_reason),
|
|
418
|
+
max_price_per_run_usd: (Math.trunc(Number(data.per_run_cents)) || 0) / 100,
|
|
419
|
+
max_price_per_month_usd: (Math.trunc(Number(data.monthly_maximum_cents ?? data.period_cents)) || 0) / 100,
|
|
420
|
+
valid_until: optionalText(data.valid_until),
|
|
421
|
+
version: Math.trunc(Number(data.version)) || 0,
|
|
422
|
+
list_link: listId ? listLink(listId) : null,
|
|
423
|
+
};
|
|
269
424
|
}
|
|
270
425
|
function isObject(value) {
|
|
271
426
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { specstreamTools, type SpecStreamToolsOptions } from "./tools.js";
|
|
2
|
-
export { SpecStreamClient, SpecStreamError, flattenRow, listLink, DEFAULT_BASE_URL, DEFAULT_WAIT_SECONDS, USER_AGENT, type FindListOptions, type FindListResult, type FoundList, type ListResults, type ListRow, type NeedsEdit, type OverMaximum, type SpecStreamClientOptions, } from "./client.js";
|
|
1
|
+
export { specstreamTools, type SpecStreamToolsOptions, type SpecStreamBaseTools, type SpecStreamMonitorTools } from "./tools.js";
|
|
2
|
+
export { SpecStreamClient, SpecStreamError, flattenRow, listLink, DEFAULT_BASE_URL, DEFAULT_WAIT_SECONDS, USER_AGENT, type FindListOptions, type FindListResult, type FoundList, type ListResults, type ListRow, type Monitor, type MonitorEvery, type MonitorListOptions, type MonitorListResult, type MonitorOverMaximum, type MonitorRun, type NeedsEdit, type OverMaximum, type SpecStreamClientOptions, } from "./client.js";
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FindListResult, type ListResults } from "./client.js";
|
|
1
|
+
import { SpecStreamClient, type FindListResult, type ListResults, type Monitor, type MonitorListResult } from "./client.js";
|
|
2
2
|
export type SpecStreamToolsOptions = {
|
|
3
3
|
/** The most one list may cost, in US dollars. Set in code; the model can't see it or raise it. Above it, nothing runs. */
|
|
4
4
|
maxPriceUsd: number;
|
|
@@ -14,21 +14,15 @@ export type SpecStreamToolsOptions = {
|
|
|
14
14
|
locale?: string;
|
|
15
15
|
/** Replaces the global fetch. */
|
|
16
16
|
fetch?: typeof fetch;
|
|
17
|
+
/**
|
|
18
|
+
* The most one check of a monitored list may cost, in US dollars. Set it to give the model
|
|
19
|
+
* `specstream_monitor_list` and `specstream_list_monitors`. Without it, the model can't start recurring work.
|
|
20
|
+
*/
|
|
21
|
+
monitorMaxPricePerRunUsd?: number;
|
|
22
|
+
/** The most one monitor may spend in a UTC calendar month. Defaults to the per-check maximum times the checks in 31 days. */
|
|
23
|
+
monitorMaxPricePerMonthUsd?: number;
|
|
17
24
|
};
|
|
18
|
-
|
|
19
|
-
* The two SpecStream tools for an AI SDK agent: find a list on the live web, and read a list's rows.
|
|
20
|
-
*
|
|
21
|
-
* The price cap is set here, in code, and is not a tool input, so the model can't raise it.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const { text } = await generateText({
|
|
25
|
-
* model,
|
|
26
|
-
* tools: specstreamTools({ maxPriceUsd: 5 }),
|
|
27
|
-
* stopWhen: stepCountIs(5),
|
|
28
|
-
* prompt: "Find dental clinics in Lisbon with online booking.",
|
|
29
|
-
* });
|
|
30
|
-
*/
|
|
31
|
-
export declare function specstreamTools(options: SpecStreamToolsOptions): {
|
|
25
|
+
declare function baseTools(client: SpecStreamClient, options: SpecStreamToolsOptions): {
|
|
32
26
|
specstream_web_search: ({
|
|
33
27
|
deferLoading?: boolean;
|
|
34
28
|
title?: string;
|
|
@@ -920,3 +914,408 @@ export declare function specstreamTools(options: SpecStreamToolsOptions): {
|
|
|
920
914
|
}, ListResults, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
921
915
|
});
|
|
922
916
|
};
|
|
917
|
+
declare function monitorTools(client: SpecStreamClient, maxPricePerRunUsd: number, maxPricePerMonthUsd: number | undefined): {
|
|
918
|
+
specstream_monitor_list: ({
|
|
919
|
+
deferLoading?: boolean;
|
|
920
|
+
title?: string;
|
|
921
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
922
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
923
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
924
|
+
listId: string;
|
|
925
|
+
every: "hour" | "day" | "week" | "month";
|
|
926
|
+
}>;
|
|
927
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
928
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
929
|
+
listId: string;
|
|
930
|
+
every: "hour" | "day" | "week" | "month";
|
|
931
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
932
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
933
|
+
onInputDelta?: ((options: {
|
|
934
|
+
inputTextDelta: string;
|
|
935
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
936
|
+
onInputAvailable?: ((options: {
|
|
937
|
+
input: {
|
|
938
|
+
listId: string;
|
|
939
|
+
every: "hour" | "day" | "week" | "month";
|
|
940
|
+
};
|
|
941
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
942
|
+
toModelOutput?: ((options: {
|
|
943
|
+
toolCallId: string;
|
|
944
|
+
input: {
|
|
945
|
+
listId: string;
|
|
946
|
+
every: "hour" | "day" | "week" | "month";
|
|
947
|
+
};
|
|
948
|
+
output: NoInfer<MonitorListResult>;
|
|
949
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
950
|
+
} & {
|
|
951
|
+
outputSchema?: import("ai").FlexibleSchema<MonitorListResult> | undefined;
|
|
952
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
953
|
+
listId: string;
|
|
954
|
+
every: "hour" | "day" | "week" | "month";
|
|
955
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
956
|
+
} & {
|
|
957
|
+
description?: string | ((options: {
|
|
958
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
959
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
960
|
+
}) => string) | undefined;
|
|
961
|
+
strict?: boolean;
|
|
962
|
+
inputExamples?: {
|
|
963
|
+
input: NoInfer<{
|
|
964
|
+
listId: string;
|
|
965
|
+
every: "hour" | "day" | "week" | "month";
|
|
966
|
+
}>;
|
|
967
|
+
}[] | undefined;
|
|
968
|
+
id?: never;
|
|
969
|
+
isProviderExecuted?: never;
|
|
970
|
+
args?: never;
|
|
971
|
+
supportsDeferredResults?: never;
|
|
972
|
+
} & {
|
|
973
|
+
type?: undefined | "function";
|
|
974
|
+
} & {
|
|
975
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
976
|
+
listId: string;
|
|
977
|
+
every: "hour" | "day" | "week" | "month";
|
|
978
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
979
|
+
}) | ({
|
|
980
|
+
deferLoading?: boolean;
|
|
981
|
+
title?: string;
|
|
982
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
983
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
984
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
985
|
+
listId: string;
|
|
986
|
+
every: "hour" | "day" | "week" | "month";
|
|
987
|
+
}>;
|
|
988
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
989
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
990
|
+
listId: string;
|
|
991
|
+
every: "hour" | "day" | "week" | "month";
|
|
992
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
993
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
994
|
+
onInputDelta?: ((options: {
|
|
995
|
+
inputTextDelta: string;
|
|
996
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
997
|
+
onInputAvailable?: ((options: {
|
|
998
|
+
input: {
|
|
999
|
+
listId: string;
|
|
1000
|
+
every: "hour" | "day" | "week" | "month";
|
|
1001
|
+
};
|
|
1002
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1003
|
+
toModelOutput?: ((options: {
|
|
1004
|
+
toolCallId: string;
|
|
1005
|
+
input: {
|
|
1006
|
+
listId: string;
|
|
1007
|
+
every: "hour" | "day" | "week" | "month";
|
|
1008
|
+
};
|
|
1009
|
+
output: NoInfer<MonitorListResult>;
|
|
1010
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1011
|
+
} & {
|
|
1012
|
+
outputSchema?: import("ai").FlexibleSchema<MonitorListResult> | undefined;
|
|
1013
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1014
|
+
listId: string;
|
|
1015
|
+
every: "hour" | "day" | "week" | "month";
|
|
1016
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1017
|
+
} & {
|
|
1018
|
+
description?: string | ((options: {
|
|
1019
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
1020
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
1021
|
+
}) => string) | undefined;
|
|
1022
|
+
strict?: boolean;
|
|
1023
|
+
inputExamples?: {
|
|
1024
|
+
input: NoInfer<{
|
|
1025
|
+
listId: string;
|
|
1026
|
+
every: "hour" | "day" | "week" | "month";
|
|
1027
|
+
}>;
|
|
1028
|
+
}[] | undefined;
|
|
1029
|
+
id?: never;
|
|
1030
|
+
isProviderExecuted?: never;
|
|
1031
|
+
args?: never;
|
|
1032
|
+
supportsDeferredResults?: never;
|
|
1033
|
+
} & {
|
|
1034
|
+
type: "dynamic";
|
|
1035
|
+
} & {
|
|
1036
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1037
|
+
listId: string;
|
|
1038
|
+
every: "hour" | "day" | "week" | "month";
|
|
1039
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1040
|
+
}) | ({
|
|
1041
|
+
deferLoading?: boolean;
|
|
1042
|
+
title?: string;
|
|
1043
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1044
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1045
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
1046
|
+
listId: string;
|
|
1047
|
+
every: "hour" | "day" | "week" | "month";
|
|
1048
|
+
}>;
|
|
1049
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1050
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
1051
|
+
listId: string;
|
|
1052
|
+
every: "hour" | "day" | "week" | "month";
|
|
1053
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1054
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1055
|
+
onInputDelta?: ((options: {
|
|
1056
|
+
inputTextDelta: string;
|
|
1057
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1058
|
+
onInputAvailable?: ((options: {
|
|
1059
|
+
input: {
|
|
1060
|
+
listId: string;
|
|
1061
|
+
every: "hour" | "day" | "week" | "month";
|
|
1062
|
+
};
|
|
1063
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1064
|
+
toModelOutput?: ((options: {
|
|
1065
|
+
toolCallId: string;
|
|
1066
|
+
input: {
|
|
1067
|
+
listId: string;
|
|
1068
|
+
every: "hour" | "day" | "week" | "month";
|
|
1069
|
+
};
|
|
1070
|
+
output: NoInfer<MonitorListResult>;
|
|
1071
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1072
|
+
} & {
|
|
1073
|
+
outputSchema?: import("ai").FlexibleSchema<MonitorListResult> | undefined;
|
|
1074
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1075
|
+
listId: string;
|
|
1076
|
+
every: "hour" | "day" | "week" | "month";
|
|
1077
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1078
|
+
} & {
|
|
1079
|
+
type: "provider";
|
|
1080
|
+
id: `${string}.${string}`;
|
|
1081
|
+
args: Record<string, unknown>;
|
|
1082
|
+
description?: never;
|
|
1083
|
+
strict?: never;
|
|
1084
|
+
inputExamples?: never;
|
|
1085
|
+
} & {
|
|
1086
|
+
isProviderExecuted: false;
|
|
1087
|
+
supportsDeferredResults?: never;
|
|
1088
|
+
} & {
|
|
1089
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1090
|
+
listId: string;
|
|
1091
|
+
every: "hour" | "day" | "week" | "month";
|
|
1092
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1093
|
+
}) | ({
|
|
1094
|
+
deferLoading?: boolean;
|
|
1095
|
+
title?: string;
|
|
1096
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1097
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1098
|
+
inputSchema: import("ai").FlexibleSchema<{
|
|
1099
|
+
listId: string;
|
|
1100
|
+
every: "hour" | "day" | "week" | "month";
|
|
1101
|
+
}>;
|
|
1102
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1103
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
1104
|
+
listId: string;
|
|
1105
|
+
every: "hour" | "day" | "week" | "month";
|
|
1106
|
+
}, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1107
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1108
|
+
onInputDelta?: ((options: {
|
|
1109
|
+
inputTextDelta: string;
|
|
1110
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1111
|
+
onInputAvailable?: ((options: {
|
|
1112
|
+
input: {
|
|
1113
|
+
listId: string;
|
|
1114
|
+
every: "hour" | "day" | "week" | "month";
|
|
1115
|
+
};
|
|
1116
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1117
|
+
toModelOutput?: ((options: {
|
|
1118
|
+
toolCallId: string;
|
|
1119
|
+
input: {
|
|
1120
|
+
listId: string;
|
|
1121
|
+
every: "hour" | "day" | "week" | "month";
|
|
1122
|
+
};
|
|
1123
|
+
output: NoInfer<MonitorListResult>;
|
|
1124
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1125
|
+
} & {
|
|
1126
|
+
outputSchema?: import("ai").FlexibleSchema<MonitorListResult> | undefined;
|
|
1127
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1128
|
+
listId: string;
|
|
1129
|
+
every: "hour" | "day" | "week" | "month";
|
|
1130
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1131
|
+
} & {
|
|
1132
|
+
type: "provider";
|
|
1133
|
+
id: `${string}.${string}`;
|
|
1134
|
+
args: Record<string, unknown>;
|
|
1135
|
+
description?: never;
|
|
1136
|
+
strict?: never;
|
|
1137
|
+
inputExamples?: never;
|
|
1138
|
+
} & {
|
|
1139
|
+
isProviderExecuted: true;
|
|
1140
|
+
supportsDeferredResults?: boolean;
|
|
1141
|
+
} & {
|
|
1142
|
+
execute: import("ai").ToolExecuteFunction<{
|
|
1143
|
+
listId: string;
|
|
1144
|
+
every: "hour" | "day" | "week" | "month";
|
|
1145
|
+
}, MonitorListResult, NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1146
|
+
});
|
|
1147
|
+
specstream_list_monitors: ({
|
|
1148
|
+
deferLoading?: boolean;
|
|
1149
|
+
title?: string;
|
|
1150
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1151
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1152
|
+
inputSchema: import("ai").FlexibleSchema<Record<string, never>>;
|
|
1153
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1154
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<Record<string, never>, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1155
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1156
|
+
onInputDelta?: ((options: {
|
|
1157
|
+
inputTextDelta: string;
|
|
1158
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1159
|
+
onInputAvailable?: ((options: {
|
|
1160
|
+
input: Record<string, never>;
|
|
1161
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1162
|
+
toModelOutput?: ((options: {
|
|
1163
|
+
toolCallId: string;
|
|
1164
|
+
input: Record<string, never>;
|
|
1165
|
+
output: NoInfer<Monitor[]>;
|
|
1166
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1167
|
+
} & {
|
|
1168
|
+
outputSchema?: import("ai").FlexibleSchema<Monitor[]> | undefined;
|
|
1169
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1170
|
+
} & {
|
|
1171
|
+
description?: string | ((options: {
|
|
1172
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
1173
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
1174
|
+
}) => string) | undefined;
|
|
1175
|
+
strict?: boolean;
|
|
1176
|
+
inputExamples?: {
|
|
1177
|
+
input: NoInfer<Record<string, never>>;
|
|
1178
|
+
}[] | undefined;
|
|
1179
|
+
id?: never;
|
|
1180
|
+
isProviderExecuted?: never;
|
|
1181
|
+
args?: never;
|
|
1182
|
+
supportsDeferredResults?: never;
|
|
1183
|
+
} & {
|
|
1184
|
+
type?: undefined | "function";
|
|
1185
|
+
} & {
|
|
1186
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1187
|
+
}) | ({
|
|
1188
|
+
deferLoading?: boolean;
|
|
1189
|
+
title?: string;
|
|
1190
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1191
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1192
|
+
inputSchema: import("ai").FlexibleSchema<Record<string, never>>;
|
|
1193
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1194
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<Record<string, never>, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1195
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1196
|
+
onInputDelta?: ((options: {
|
|
1197
|
+
inputTextDelta: string;
|
|
1198
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1199
|
+
onInputAvailable?: ((options: {
|
|
1200
|
+
input: Record<string, never>;
|
|
1201
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1202
|
+
toModelOutput?: ((options: {
|
|
1203
|
+
toolCallId: string;
|
|
1204
|
+
input: Record<string, never>;
|
|
1205
|
+
output: NoInfer<Monitor[]>;
|
|
1206
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1207
|
+
} & {
|
|
1208
|
+
outputSchema?: import("ai").FlexibleSchema<Monitor[]> | undefined;
|
|
1209
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1210
|
+
} & {
|
|
1211
|
+
description?: string | ((options: {
|
|
1212
|
+
context: NoInfer<import("@ai-sdk/provider-utils").Context>;
|
|
1213
|
+
experimental_sandbox?: import("ai").Experimental_SandboxSession;
|
|
1214
|
+
}) => string) | undefined;
|
|
1215
|
+
strict?: boolean;
|
|
1216
|
+
inputExamples?: {
|
|
1217
|
+
input: NoInfer<Record<string, never>>;
|
|
1218
|
+
}[] | undefined;
|
|
1219
|
+
id?: never;
|
|
1220
|
+
isProviderExecuted?: never;
|
|
1221
|
+
args?: never;
|
|
1222
|
+
supportsDeferredResults?: never;
|
|
1223
|
+
} & {
|
|
1224
|
+
type: "dynamic";
|
|
1225
|
+
} & {
|
|
1226
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1227
|
+
}) | ({
|
|
1228
|
+
deferLoading?: boolean;
|
|
1229
|
+
title?: string;
|
|
1230
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1231
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1232
|
+
inputSchema: import("ai").FlexibleSchema<Record<string, never>>;
|
|
1233
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1234
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<Record<string, never>, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1235
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1236
|
+
onInputDelta?: ((options: {
|
|
1237
|
+
inputTextDelta: string;
|
|
1238
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1239
|
+
onInputAvailable?: ((options: {
|
|
1240
|
+
input: Record<string, never>;
|
|
1241
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1242
|
+
toModelOutput?: ((options: {
|
|
1243
|
+
toolCallId: string;
|
|
1244
|
+
input: Record<string, never>;
|
|
1245
|
+
output: NoInfer<Monitor[]>;
|
|
1246
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1247
|
+
} & {
|
|
1248
|
+
outputSchema?: import("ai").FlexibleSchema<Monitor[]> | undefined;
|
|
1249
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1250
|
+
} & {
|
|
1251
|
+
type: "provider";
|
|
1252
|
+
id: `${string}.${string}`;
|
|
1253
|
+
args: Record<string, unknown>;
|
|
1254
|
+
description?: never;
|
|
1255
|
+
strict?: never;
|
|
1256
|
+
inputExamples?: never;
|
|
1257
|
+
} & {
|
|
1258
|
+
isProviderExecuted: false;
|
|
1259
|
+
supportsDeferredResults?: never;
|
|
1260
|
+
} & {
|
|
1261
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1262
|
+
}) | ({
|
|
1263
|
+
deferLoading?: boolean;
|
|
1264
|
+
title?: string;
|
|
1265
|
+
providerOptions?: import("@ai-sdk/provider-utils").ProviderOptions;
|
|
1266
|
+
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
1267
|
+
inputSchema: import("ai").FlexibleSchema<Record<string, never>>;
|
|
1268
|
+
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
1269
|
+
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<Record<string, never>, NoInfer<import("@ai-sdk/provider-utils").Context>> | undefined;
|
|
1270
|
+
onInputStart?: ((options: import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1271
|
+
onInputDelta?: ((options: {
|
|
1272
|
+
inputTextDelta: string;
|
|
1273
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1274
|
+
onInputAvailable?: ((options: {
|
|
1275
|
+
input: Record<string, never>;
|
|
1276
|
+
} & import("ai").ToolExecutionOptions<NoInfer<import("@ai-sdk/provider-utils").Context>>) => void | PromiseLike<void>) | undefined;
|
|
1277
|
+
toModelOutput?: ((options: {
|
|
1278
|
+
toolCallId: string;
|
|
1279
|
+
input: Record<string, never>;
|
|
1280
|
+
output: NoInfer<Monitor[]>;
|
|
1281
|
+
}) => import("@ai-sdk/provider-utils").ToolResultOutput | PromiseLike<import("@ai-sdk/provider-utils").ToolResultOutput>) | undefined;
|
|
1282
|
+
} & {
|
|
1283
|
+
outputSchema?: import("ai").FlexibleSchema<Monitor[]> | undefined;
|
|
1284
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1285
|
+
} & {
|
|
1286
|
+
type: "provider";
|
|
1287
|
+
id: `${string}.${string}`;
|
|
1288
|
+
args: Record<string, unknown>;
|
|
1289
|
+
description?: never;
|
|
1290
|
+
strict?: never;
|
|
1291
|
+
inputExamples?: never;
|
|
1292
|
+
} & {
|
|
1293
|
+
isProviderExecuted: true;
|
|
1294
|
+
supportsDeferredResults?: boolean;
|
|
1295
|
+
} & {
|
|
1296
|
+
execute: import("ai").ToolExecuteFunction<Record<string, never>, Monitor[], NoInfer<import("@ai-sdk/provider-utils").Context>>;
|
|
1297
|
+
});
|
|
1298
|
+
};
|
|
1299
|
+
/** The four tools every agent gets. */
|
|
1300
|
+
export type SpecStreamBaseTools = ReturnType<typeof baseTools>;
|
|
1301
|
+
/** The two monitor tools, there only when `monitorMaxPricePerRunUsd` is set. */
|
|
1302
|
+
export type SpecStreamMonitorTools = ReturnType<typeof monitorTools>;
|
|
1303
|
+
/**
|
|
1304
|
+
* The SpecStream tools for an AI SDK agent: search the web, read pages, find a list, read a list's rows,
|
|
1305
|
+
* and, with `monitorMaxPricePerRunUsd`, keep a list current on a schedule.
|
|
1306
|
+
*
|
|
1307
|
+
* Every price cap is set here, in code, and is not a tool input, so the model can't raise it.
|
|
1308
|
+
*
|
|
1309
|
+
* @example
|
|
1310
|
+
* const { text } = await generateText({
|
|
1311
|
+
* model,
|
|
1312
|
+
* tools: specstreamTools({ maxPriceUsd: 5 }),
|
|
1313
|
+
* stopWhen: stepCountIs(5),
|
|
1314
|
+
* prompt: "Find dental clinics in Lisbon with online booking.",
|
|
1315
|
+
* });
|
|
1316
|
+
*/
|
|
1317
|
+
export declare function specstreamTools(options: SpecStreamToolsOptions & {
|
|
1318
|
+
monitorMaxPricePerRunUsd: number;
|
|
1319
|
+
}): SpecStreamBaseTools & SpecStreamMonitorTools;
|
|
1320
|
+
export declare function specstreamTools(options: SpecStreamToolsOptions): SpecStreamBaseTools;
|
|
1321
|
+
export {};
|
package/dist/tools.js
CHANGED
|
@@ -26,6 +26,20 @@ const extractPagesInput = z.object({
|
|
|
26
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."),
|
|
27
27
|
format: z.enum(["markdown", "text"]).optional().describe('Output format: "markdown" (default) or "text".'),
|
|
28
28
|
});
|
|
29
|
+
const monitorListInput = z.object({
|
|
30
|
+
listId: z.string().min(1).describe('The list_id of the list to keep current, like "fnd_gk5y3d0r97bvyz0t08zzh75kr6".'),
|
|
31
|
+
every: z
|
|
32
|
+
.enum(["hour", "day", "week", "month"])
|
|
33
|
+
.default("day")
|
|
34
|
+
.describe('How often to check the list again: "hour", "day" (default), "week" or "month".'),
|
|
35
|
+
});
|
|
36
|
+
const MONITOR_LIST_DESCRIPTION = [
|
|
37
|
+
"Keep a SpecStream list current: check its rows again on the live web every hour, day, week or month.",
|
|
38
|
+
"Use it only when the user asks to watch or monitor a list. Each check is billed, within a maximum per check and per month set in code.",
|
|
39
|
+
'Returns JSON with status "saved", monitor_id, state and next_run_at.',
|
|
40
|
+
'status "over_maximum" means nothing was saved because one check costs more than the maximum: tell the user.',
|
|
41
|
+
].join(" ");
|
|
42
|
+
const LIST_MONITORS_DESCRIPTION = "List the account's SpecStream monitors: the list each one checks, its state, how often, the next check and the last list it made. Reading is free.";
|
|
29
43
|
const FIND_LIST_DESCRIPTION = [
|
|
30
44
|
"Find a list of real things on the live web and return every matching row, each with the page it was read from.",
|
|
31
45
|
"Use it when the answer is many things that meet conditions: companies in a city, local businesses with a service, funding filings, open grants, tenders, clinical trials, repositories, people in a role.",
|
|
@@ -40,30 +54,11 @@ const GET_LIST_RESULTS_DESCRIPTION = [
|
|
|
40
54
|
"Read every row found so far for a SpecStream list, such as one that was still running. Reading is free.",
|
|
41
55
|
"Returns JSON with status, list_id, list_link and rows, each with its columns, source_url and checked_at.",
|
|
42
56
|
].join(" ");
|
|
43
|
-
|
|
44
|
-
* The two SpecStream tools for an AI SDK agent: find a list on the live web, and read a list's rows.
|
|
45
|
-
*
|
|
46
|
-
* The price cap is set here, in code, and is not a tool input, so the model can't raise it.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* const { text } = await generateText({
|
|
50
|
-
* model,
|
|
51
|
-
* tools: specstreamTools({ maxPriceUsd: 5 }),
|
|
52
|
-
* stopWhen: stepCountIs(5),
|
|
53
|
-
* prompt: "Find dental clinics in Lisbon with online booking.",
|
|
54
|
-
* });
|
|
55
|
-
*/
|
|
56
|
-
export function specstreamTools(options) {
|
|
57
|
+
function baseTools(client, options) {
|
|
57
58
|
const { maxPriceUsd } = options;
|
|
58
|
-
if (typeof maxPriceUsd !== "number" || !Number.isFinite(maxPriceUsd) || maxPriceUsd <= 0) {
|
|
59
|
-
throw new Error("maxPriceUsd must be greater than 0.");
|
|
60
|
-
}
|
|
61
|
-
const client = new SpecStreamClient({ apiKey: options.apiKey, baseUrl: options.baseUrl ?? DEFAULT_BASE_URL, fetch: options.fetch });
|
|
62
|
-
if (!client.hasKey)
|
|
63
|
-
throw new Error(MISSING_KEY_MESSAGE);
|
|
64
59
|
return {
|
|
65
60
|
specstream_web_search: tool({
|
|
66
|
-
description: "Search the live web in seconds with the SpecStream Search API (GET /v1/web-search, $5 per 1,000 searches, no quote needed). " +
|
|
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, or $1 on the fast tier, no quote needed). " +
|
|
67
62
|
"Returns JSON with kind ('fact' or 'list'), answer (value, page and seen_at), matching rows, ranked sources and optional passages.",
|
|
68
63
|
inputSchema: webSearchInput,
|
|
69
64
|
execute: async ({ q, passages }, { abortSignal }) => client.webSearch(q, { passages, abortSignal }),
|
|
@@ -93,3 +88,34 @@ export function specstreamTools(options) {
|
|
|
93
88
|
}),
|
|
94
89
|
};
|
|
95
90
|
}
|
|
91
|
+
function monitorTools(client, maxPricePerRunUsd, maxPricePerMonthUsd) {
|
|
92
|
+
return {
|
|
93
|
+
specstream_monitor_list: tool({
|
|
94
|
+
description: MONITOR_LIST_DESCRIPTION,
|
|
95
|
+
inputSchema: monitorListInput,
|
|
96
|
+
execute: async ({ listId, every }, { abortSignal }) => client.monitorList(listId, { every: (every ?? "day"), maxPricePerRunUsd, maxPricePerMonthUsd, abortSignal }),
|
|
97
|
+
}),
|
|
98
|
+
specstream_list_monitors: tool({
|
|
99
|
+
description: LIST_MONITORS_DESCRIPTION,
|
|
100
|
+
inputSchema: z.object({}),
|
|
101
|
+
execute: async (_input, { abortSignal }) => client.monitors(abortSignal),
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function specstreamTools(options) {
|
|
106
|
+
const { maxPriceUsd } = options;
|
|
107
|
+
if (typeof maxPriceUsd !== "number" || !Number.isFinite(maxPriceUsd) || maxPriceUsd <= 0) {
|
|
108
|
+
throw new Error("maxPriceUsd must be greater than 0.");
|
|
109
|
+
}
|
|
110
|
+
const monitorMax = options.monitorMaxPricePerRunUsd;
|
|
111
|
+
if (monitorMax !== undefined && !(typeof monitorMax === "number" && Number.isFinite(monitorMax) && monitorMax > 0)) {
|
|
112
|
+
throw new Error("monitorMaxPricePerRunUsd must be greater than 0.");
|
|
113
|
+
}
|
|
114
|
+
const client = new SpecStreamClient({ apiKey: options.apiKey, baseUrl: options.baseUrl ?? DEFAULT_BASE_URL, fetch: options.fetch });
|
|
115
|
+
if (!client.hasKey)
|
|
116
|
+
throw new Error(MISSING_KEY_MESSAGE);
|
|
117
|
+
const tools = baseTools(client, options);
|
|
118
|
+
if (monitorMax === undefined)
|
|
119
|
+
return tools;
|
|
120
|
+
return { ...tools, ...monitorTools(client, monitorMax, options.monitorMaxPricePerMonthUsd) };
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@specstream/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "The live web data engine for the Vercel AI SDK: Search API ($5 per 1,000 searches), Extract API ($0.80 per 1,000 pages) and Deep Search.",
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
7
7
|
"types": "./dist/index.d.ts",
|