@telemai/sdk 0.4.0 → 0.5.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 CHANGED
@@ -207,30 +207,35 @@ results of each search step.
207
207
 
208
208
  ## Monitors
209
209
 
210
- A monitor runs a query on a schedule. Poll it to get the results that are new since
211
- your last poll. `poll` returns a `SearchResponse`:
210
+ A monitor runs a query on a schedule, and its agent checks every result against the
211
+ query and keeps the ones that match. A monitor has the agent unless you create it with
212
+ `agent: false`, and a monitor with the agent needs a `ttl`, at most `"30d"`: without
213
+ one, `create` throws a `TelemError` with the code `invalid_request`.
212
214
 
213
215
  ```ts
214
- const monitor = await telem.monitors.create("Nvidia files a new 8-K with the SEC", { frequency: "1h", ttl: "7d" })
215
- const response = await telem.monitors.poll(monitor.id)
216
+ const monitor = await telem.monitors.create("Nvidia files a new 8-K with the SEC", { frequency: "1h", ttl: "30d" })
217
+ console.log(monitor.agentState?.status) // what its agent does: compiling, then ready
216
218
  for await (const change of telem.monitors.iterateChanges(monitor.id)) {
217
219
  console.log(change.seq, change.kind, change.subject.name)
218
220
  }
221
+ const agent = await telem.monitors.agent(monitor.id)
219
222
  await telem.monitors.update(monitor.id, { status: "paused" })
223
+ await telem.monitors.update(monitor.id, { ttl: "30d" }) // renew: it ends 30 days from now
220
224
  await telem.monitors.delete(monitor.id)
221
225
  ```
222
226
 
223
- A monitor has an agent unless you create it with `agent: false`. The agent checks every
224
- result against the query and keeps the ones that match. `iterateChanges` reads what it
225
- kept, oldest first, until you are caught up, and then stops. Keep the `seq` of the last
226
- change you handled and pass it as `cursor` next time: no change comes twice, and none
227
- is skipped. `changes` returns one page (`nextCursor`, `watermark`) and takes
228
- `cursor`, `since`, `kinds` and `limit`. `agent` returns the agent itself: its status,
229
- query, frequency and plan version. `monitor.agentState` shows it on the monitor. Read
230
- `iterateChanges` with `for await`.
227
+ `iterateChanges` reads what the agent kept, oldest first, until you are caught up,
228
+ and then stops. Keep the `seq` of the last change you handled and pass it as `cursor`
229
+ next time: no change comes twice, and none is skipped. `changes` returns one page
230
+ (`nextCursor`, `watermark`) and takes `cursor`, `since`, `kinds` and `limit`. `agent`
231
+ returns the agent itself: its status, query, frequency and plan version.
232
+ `monitor.agentState` shows it on the monitor; when the agent did not start, the
233
+ create's `monitor.agentNote` says why. Read `iterateChanges` with `for await`.
231
234
 
232
- `telem.monitors` also has `get` and `list`. See [Monitors](https://docs.telem.ai/resources/monitors/)
233
- for the fields and the errors.
235
+ `telem.monitors` also has `get` and `list`. `poll` is deprecated and warns once:
236
+ read the agent's changes with `iterateChanges` instead.
237
+ See [Monitors](https://docs.telem.ai/resources/monitors/) for the fields, the errors and
238
+ the older reads.
234
239
 
235
240
  ## Vercel AI SDK
236
241
 
@@ -381,7 +386,7 @@ try {
381
386
 
382
387
  | Situation | Result |
383
388
  |---|---|
384
- | Bad input (empty query, empty URL list) | `TelemError`, `code: "invalid_request"`, nothing sent |
389
+ | Bad input (empty query, empty URL list, a monitor with an agent and no `ttl`) | `TelemError`, `code: "invalid_request"`, nothing sent |
385
390
  | Network failure | `TelemError`, `code: "connection_error"`, after the retries |
386
391
  | 5xx or 429 | Retried with backoff (`Retry-After` applies), then `TelemError` with the status |
387
392
  | Other 4xx | `TelemError` with the status and the code from the server, not retried |
package/dist/index.cjs CHANGED
@@ -60,7 +60,7 @@ var TimeoutError = class extends TelemError {
60
60
  };
61
61
 
62
62
  // src/version.ts
63
- var VERSION = "0.4.0";
63
+ var VERSION = "0.5.0";
64
64
 
65
65
  // src/config.ts
66
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -726,6 +726,14 @@ async function search(config, query, options) {
726
726
  }
727
727
 
728
728
  // src/methods/monitors.ts
729
+ var NEEDS_TTL = 'A monitor with an agent must end: pass ttl, such as ttl: "30d" (at most 30 days), or agent: false for a monitor without an agent.';
730
+ var POLL_DEPRECATED = "@telemai/sdk: monitors.poll() is deprecated: read what the monitor agent finds with monitors.iterateChanges() or monitors.changes().";
731
+ var pollWarned = false;
732
+ function warnPollDeprecated() {
733
+ if (pollWarned) return;
734
+ pollWarned = true;
735
+ console.warn(POLL_DEPRECATED);
736
+ }
729
737
  function agentStateFrom(data) {
730
738
  return {
731
739
  engine: String(data.engine ?? ""),
@@ -755,6 +763,7 @@ function monitorFrom(body) {
755
763
  expiresAt: data.expires_at ?? null,
756
764
  webhookUrl: data.webhook_url ?? null,
757
765
  webhookSecret: data.webhook_secret ?? null,
766
+ agentNote: typeof data.agent_note === "string" ? data.agent_note : null,
758
767
  raw: data
759
768
  };
760
769
  if (data.agent_state !== void 0) {
@@ -837,20 +846,23 @@ function createMonitors(config) {
837
846
  return changesPageFrom(await request(config, "GET", route, void 0, options.signal));
838
847
  };
839
848
  return {
840
- /** Create a monitor. Telem runs `query` on the schedule. */
841
- async create(query, options = {}) {
849
+ /** Create a monitor. Telem runs `query` on the schedule, and its agent keeps what matches. */
850
+ async create(query, options) {
851
+ const given = options ?? {};
852
+ const agent = given.agent == null ? true : Boolean(given.agent);
853
+ if (agent && !given.ttl) throw invalidRequest(NEEDS_TTL);
842
854
  const monitorOptions = {};
843
- if (options.frequency !== void 0) monitorOptions.frequency = options.frequency;
844
- if (options.includeDomains !== void 0) {
845
- monitorOptions.include_domains = options.includeDomains;
855
+ if (given.frequency !== void 0) monitorOptions.frequency = given.frequency;
856
+ if (given.includeDomains !== void 0) {
857
+ monitorOptions.include_domains = given.includeDomains;
846
858
  }
847
- if (options.search !== void 0) monitorOptions.search = searchBlock({}, options.search);
859
+ if (given.search !== void 0) monitorOptions.search = searchBlock({}, given.search);
848
860
  const body = { query, options: monitorOptions };
849
- if (options.metadata !== void 0) body.metadata = options.metadata;
850
- if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
851
- if (options.ttl !== void 0) body.ttl = options.ttl;
852
- if (options.agent !== void 0) body.agent = options.agent;
853
- const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit").catch(
861
+ if (given.metadata !== void 0) body.metadata = given.metadata;
862
+ if (given.webhookUrl !== void 0) body.webhook_url = given.webhookUrl;
863
+ if (given.ttl !== void 0) body.ttl = given.ttl;
864
+ body.agent = agent;
865
+ const data = await request(config, "POST", "/v1/monitors", body, given.signal, "rate_limit").catch(
854
866
  (error) => {
855
867
  if (error instanceof TimeoutError) {
856
868
  throw new TimeoutError(
@@ -872,17 +884,20 @@ function createMonitors(config) {
872
884
  async get(monitorId, options = {}) {
873
885
  return monitorFrom(await request(config, "GET", path(monitorId), void 0, options.signal));
874
886
  },
875
- /** Pause, resume or change a monitor. Only the fields given are sent. */
887
+ /** Pause, resume, renew or change a monitor. Only the fields given are sent. */
876
888
  async update(monitorId, options) {
877
889
  const body = {};
878
890
  if (options.status !== void 0) body.status = options.status;
879
891
  if (options.frequency !== void 0) body.frequency = options.frequency;
892
+ if (options.ttl !== void 0) body.ttl = options.ttl;
880
893
  if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl || null;
881
894
  const route = path(monitorId);
882
895
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
883
896
  },
884
- /** Get the results that are new since the last poll. */
897
+ /** Get the monitor's own results that are new since the last poll. Deprecated: it
898
+ * warns once per process. */
885
899
  async poll(monitorId, options = {}) {
900
+ warnPollDeprecated();
886
901
  const body = {};
887
902
  if (options.session !== void 0) body.session_id = options.session;
888
903
  if (options.metadata !== void 0) body.metadata = options.metadata;
@@ -1012,8 +1027,8 @@ var Telem = class {
1012
1027
  maxRetries;
1013
1028
  /** The session read surface: `list` and `results(id)`. */
1014
1029
  sessions;
1015
- /** Monitors: `create`, `list`, `listPage`, `get`, `update`, `poll`, `delete`, and the
1016
- * agent reads `agent`, `changes` and `iterateChanges`. */
1030
+ /** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
1031
+ * `agent`, `changes` and `iterateChanges`, and the deprecated `poll`. */
1017
1032
  monitors;
1018
1033
  #config;
1019
1034
  /**
package/dist/index.d.cts CHANGED
@@ -238,28 +238,41 @@ type SessionsResource = {
238
238
  };
239
239
  /** The search options a monitor can run on its schedule (`MonitorCreateOptions.search`). */
240
240
  type MonitorSearchOptions = Pick<SearchOptions, "tier" | "numResults">;
241
- /** Options for `monitors.create`. */
242
- type MonitorCreateOptions = {
241
+ /** The options of `monitors.create` that a monitor takes with the agent or without. */
242
+ type MonitorCreateCommonOptions = {
243
243
  /** `"1h"`, `"6h"`, `"12h"`, `"1d"` or `"7d"`. If you leave it out, the monitor runs once a day. */
244
244
  frequency?: string;
245
245
  /** Also run a web search for the query on the schedule, with these options. `{}`
246
- * uses the defaults. Client search defaults do not apply. */
246
+ * uses the defaults. Client search defaults do not apply. It adds to what a poll returns. */
247
247
  search?: MonitorSearchOptions;
248
- /** Only results from these sites and their subdomains, such as `["sec.gov"]`,
249
- * from every source of the monitor. */
248
+ /** Only results from these sites and their subdomains, such as `["sec.gov"]`, in what
249
+ * a poll returns. */
250
250
  includeDomains?: string[];
251
- /** Request metadata (query lineage keys), sent as given. */
251
+ /** Query lineage keys, sent as given. They choose the session that records the polls of
252
+ * the monitor. */
252
253
  metadata?: Json;
253
254
  /** An `https` URL that receives the new results. */
254
255
  webhookUrl?: string;
255
- /** Delete the monitor after this long, such as `"12h"` or `"7d"` (at most `"30d"`). Without it, the monitor never expires. */
256
- ttl?: string;
257
- /** Start the monitor agent with the monitor: it checks every result against the query
258
- * and keeps the ones that match. Telem turns it on when you leave this out; `false`
259
- * creates the monitor without one. Read what the agent keeps with `monitors.changes`. */
260
- agent?: boolean;
261
256
  signal?: AbortSignal;
262
257
  };
258
+ /** Options for `monitors.create`. A monitor has the agent unless `agent` is `false`,
259
+ * and a monitor with the agent must end: then `ttl` is required. */
260
+ type MonitorCreateOptions = MonitorCreateCommonOptions & ({
261
+ /** `false` creates a monitor without an agent, which you read with the deprecated
262
+ * `monitors.poll`. */
263
+ agent: false;
264
+ /** End the monitor after this long, such as `"7d"` or `"30d"` (at most `"30d"`).
265
+ * Without it, a monitor without an agent never ends. */
266
+ ttl?: string;
267
+ } | {
268
+ /** Start the monitor agent with the monitor, the default: it checks every result
269
+ * against the query and keeps the ones that match. Read what it keeps with
270
+ * `monitors.iterateChanges` or `monitors.changes`. */
271
+ agent?: true;
272
+ /** End the monitor after this long, such as `"7d"` or `"30d"` (at most `"30d"`).
273
+ * Required with the agent. */
274
+ ttl: string;
275
+ });
263
276
  /** Options for `monitors.update`. Send at least one field. */
264
277
  type MonitorUpdateOptions = {
265
278
  /** `"paused"` or `"active"`. */
@@ -267,9 +280,13 @@ type MonitorUpdateOptions = {
267
280
  frequency?: string;
268
281
  /** A new webhook URL, with a new `webhookSecret` in the response. `null` or `""` removes it. */
269
282
  webhookUrl?: string | null;
283
+ /** A new end, this long from now, such as `"30d"` (at most `"30d"`). It renews a monitor
284
+ * before it ends; an ended monitor cannot be renewed. */
285
+ ttl?: string;
270
286
  signal?: AbortSignal;
271
287
  };
272
- /** Options for `monitors.poll`. */
288
+ /** Options for `monitors.poll`.
289
+ * @deprecated `poll` is deprecated: read the agent with `monitors.iterateChanges`. */
273
290
  type MonitorPollOptions = {
274
291
  /** Record this poll in another session (default: the monitor's own). */
275
292
  session?: string;
@@ -295,6 +312,9 @@ type Monitor = {
295
312
  /** The monitor agent's state. `null`: the monitor has no agent. Absent when the router
296
313
  * sends none, as a router from before the agent reads does. */
297
314
  agentState?: AgentState | null;
315
+ /** Only in the answer to a create: why the monitor agent did not start, or not yet.
316
+ * `null` when it started, and in every other answer. */
317
+ agentNote: string | null;
298
318
  raw: Json;
299
319
  };
300
320
  /** The latest compile of an agent's plan (`AgentState.compile`). */
@@ -417,13 +437,19 @@ type MonitorPage = {
417
437
  };
418
438
  /** The `telem.monitors` namespace. */
419
439
  type MonitorsResource = {
420
- create(query: string, options?: MonitorCreateOptions): Promise<Monitor>;
440
+ /** Create a monitor. It has the agent unless `agent` is `false`, and with the agent
441
+ * `ttl` is required: a create without it throws a `TelemError` (`invalid_request`)
442
+ * before anything is sent. */
443
+ create(query: string, options: MonitorCreateOptions): Promise<Monitor>;
421
444
  list(options?: MonitorListOptions): Promise<Monitor[]>;
422
445
  listPage(options?: MonitorListOptions): Promise<MonitorPage>;
423
446
  get(monitorId: string, options?: {
424
447
  signal?: AbortSignal;
425
448
  }): Promise<Monitor>;
426
449
  update(monitorId: string, options: MonitorUpdateOptions): Promise<Monitor>;
450
+ /** Get the monitor's own results that are new since the last poll.
451
+ * @deprecated Read what the monitor agent finds with `iterateChanges` or `changes`.
452
+ * A poll still works, and warns once per process with `console.warn`. */
427
453
  poll(monitorId: string, options?: MonitorPollOptions): Promise<SearchResponse>;
428
454
  delete(monitorId: string, options?: {
429
455
  signal?: AbortSignal;
@@ -579,8 +605,8 @@ declare class Telem {
579
605
  readonly maxRetries: number;
580
606
  /** The session read surface: `list` and `results(id)`. */
581
607
  readonly sessions: SessionsResource;
582
- /** Monitors: `create`, `list`, `listPage`, `get`, `update`, `poll`, `delete`, and the
583
- * agent reads `agent`, `changes` and `iterateChanges`. */
608
+ /** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
609
+ * `agent`, `changes` and `iterateChanges`, and the deprecated `poll`. */
584
610
  readonly monitors: MonitorsResource;
585
611
  /**
586
612
  * @param options - An API key string, or an options object. Anything left unset
package/dist/index.d.ts CHANGED
@@ -238,28 +238,41 @@ type SessionsResource = {
238
238
  };
239
239
  /** The search options a monitor can run on its schedule (`MonitorCreateOptions.search`). */
240
240
  type MonitorSearchOptions = Pick<SearchOptions, "tier" | "numResults">;
241
- /** Options for `monitors.create`. */
242
- type MonitorCreateOptions = {
241
+ /** The options of `monitors.create` that a monitor takes with the agent or without. */
242
+ type MonitorCreateCommonOptions = {
243
243
  /** `"1h"`, `"6h"`, `"12h"`, `"1d"` or `"7d"`. If you leave it out, the monitor runs once a day. */
244
244
  frequency?: string;
245
245
  /** Also run a web search for the query on the schedule, with these options. `{}`
246
- * uses the defaults. Client search defaults do not apply. */
246
+ * uses the defaults. Client search defaults do not apply. It adds to what a poll returns. */
247
247
  search?: MonitorSearchOptions;
248
- /** Only results from these sites and their subdomains, such as `["sec.gov"]`,
249
- * from every source of the monitor. */
248
+ /** Only results from these sites and their subdomains, such as `["sec.gov"]`, in what
249
+ * a poll returns. */
250
250
  includeDomains?: string[];
251
- /** Request metadata (query lineage keys), sent as given. */
251
+ /** Query lineage keys, sent as given. They choose the session that records the polls of
252
+ * the monitor. */
252
253
  metadata?: Json;
253
254
  /** An `https` URL that receives the new results. */
254
255
  webhookUrl?: string;
255
- /** Delete the monitor after this long, such as `"12h"` or `"7d"` (at most `"30d"`). Without it, the monitor never expires. */
256
- ttl?: string;
257
- /** Start the monitor agent with the monitor: it checks every result against the query
258
- * and keeps the ones that match. Telem turns it on when you leave this out; `false`
259
- * creates the monitor without one. Read what the agent keeps with `monitors.changes`. */
260
- agent?: boolean;
261
256
  signal?: AbortSignal;
262
257
  };
258
+ /** Options for `monitors.create`. A monitor has the agent unless `agent` is `false`,
259
+ * and a monitor with the agent must end: then `ttl` is required. */
260
+ type MonitorCreateOptions = MonitorCreateCommonOptions & ({
261
+ /** `false` creates a monitor without an agent, which you read with the deprecated
262
+ * `monitors.poll`. */
263
+ agent: false;
264
+ /** End the monitor after this long, such as `"7d"` or `"30d"` (at most `"30d"`).
265
+ * Without it, a monitor without an agent never ends. */
266
+ ttl?: string;
267
+ } | {
268
+ /** Start the monitor agent with the monitor, the default: it checks every result
269
+ * against the query and keeps the ones that match. Read what it keeps with
270
+ * `monitors.iterateChanges` or `monitors.changes`. */
271
+ agent?: true;
272
+ /** End the monitor after this long, such as `"7d"` or `"30d"` (at most `"30d"`).
273
+ * Required with the agent. */
274
+ ttl: string;
275
+ });
263
276
  /** Options for `monitors.update`. Send at least one field. */
264
277
  type MonitorUpdateOptions = {
265
278
  /** `"paused"` or `"active"`. */
@@ -267,9 +280,13 @@ type MonitorUpdateOptions = {
267
280
  frequency?: string;
268
281
  /** A new webhook URL, with a new `webhookSecret` in the response. `null` or `""` removes it. */
269
282
  webhookUrl?: string | null;
283
+ /** A new end, this long from now, such as `"30d"` (at most `"30d"`). It renews a monitor
284
+ * before it ends; an ended monitor cannot be renewed. */
285
+ ttl?: string;
270
286
  signal?: AbortSignal;
271
287
  };
272
- /** Options for `monitors.poll`. */
288
+ /** Options for `monitors.poll`.
289
+ * @deprecated `poll` is deprecated: read the agent with `monitors.iterateChanges`. */
273
290
  type MonitorPollOptions = {
274
291
  /** Record this poll in another session (default: the monitor's own). */
275
292
  session?: string;
@@ -295,6 +312,9 @@ type Monitor = {
295
312
  /** The monitor agent's state. `null`: the monitor has no agent. Absent when the router
296
313
  * sends none, as a router from before the agent reads does. */
297
314
  agentState?: AgentState | null;
315
+ /** Only in the answer to a create: why the monitor agent did not start, or not yet.
316
+ * `null` when it started, and in every other answer. */
317
+ agentNote: string | null;
298
318
  raw: Json;
299
319
  };
300
320
  /** The latest compile of an agent's plan (`AgentState.compile`). */
@@ -417,13 +437,19 @@ type MonitorPage = {
417
437
  };
418
438
  /** The `telem.monitors` namespace. */
419
439
  type MonitorsResource = {
420
- create(query: string, options?: MonitorCreateOptions): Promise<Monitor>;
440
+ /** Create a monitor. It has the agent unless `agent` is `false`, and with the agent
441
+ * `ttl` is required: a create without it throws a `TelemError` (`invalid_request`)
442
+ * before anything is sent. */
443
+ create(query: string, options: MonitorCreateOptions): Promise<Monitor>;
421
444
  list(options?: MonitorListOptions): Promise<Monitor[]>;
422
445
  listPage(options?: MonitorListOptions): Promise<MonitorPage>;
423
446
  get(monitorId: string, options?: {
424
447
  signal?: AbortSignal;
425
448
  }): Promise<Monitor>;
426
449
  update(monitorId: string, options: MonitorUpdateOptions): Promise<Monitor>;
450
+ /** Get the monitor's own results that are new since the last poll.
451
+ * @deprecated Read what the monitor agent finds with `iterateChanges` or `changes`.
452
+ * A poll still works, and warns once per process with `console.warn`. */
427
453
  poll(monitorId: string, options?: MonitorPollOptions): Promise<SearchResponse>;
428
454
  delete(monitorId: string, options?: {
429
455
  signal?: AbortSignal;
@@ -579,8 +605,8 @@ declare class Telem {
579
605
  readonly maxRetries: number;
580
606
  /** The session read surface: `list` and `results(id)`. */
581
607
  readonly sessions: SessionsResource;
582
- /** Monitors: `create`, `list`, `listPage`, `get`, `update`, `poll`, `delete`, and the
583
- * agent reads `agent`, `changes` and `iterateChanges`. */
608
+ /** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
609
+ * `agent`, `changes` and `iterateChanges`, and the deprecated `poll`. */
584
610
  readonly monitors: MonitorsResource;
585
611
  /**
586
612
  * @param options - An API key string, or an options object. Anything left unset
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-SQ3ZZA72.js";
23
23
 
24
24
  // src/version.ts
25
- var VERSION = "0.4.0";
25
+ var VERSION = "0.5.0";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -357,6 +357,14 @@ async function search(config, query, options) {
357
357
  }
358
358
 
359
359
  // src/methods/monitors.ts
360
+ var NEEDS_TTL = 'A monitor with an agent must end: pass ttl, such as ttl: "30d" (at most 30 days), or agent: false for a monitor without an agent.';
361
+ var POLL_DEPRECATED = "@telemai/sdk: monitors.poll() is deprecated: read what the monitor agent finds with monitors.iterateChanges() or monitors.changes().";
362
+ var pollWarned = false;
363
+ function warnPollDeprecated() {
364
+ if (pollWarned) return;
365
+ pollWarned = true;
366
+ console.warn(POLL_DEPRECATED);
367
+ }
360
368
  function agentStateFrom(data) {
361
369
  return {
362
370
  engine: String(data.engine ?? ""),
@@ -386,6 +394,7 @@ function monitorFrom(body) {
386
394
  expiresAt: data.expires_at ?? null,
387
395
  webhookUrl: data.webhook_url ?? null,
388
396
  webhookSecret: data.webhook_secret ?? null,
397
+ agentNote: typeof data.agent_note === "string" ? data.agent_note : null,
389
398
  raw: data
390
399
  };
391
400
  if (data.agent_state !== void 0) {
@@ -468,20 +477,23 @@ function createMonitors(config) {
468
477
  return changesPageFrom(await request(config, "GET", route, void 0, options.signal));
469
478
  };
470
479
  return {
471
- /** Create a monitor. Telem runs `query` on the schedule. */
472
- async create(query, options = {}) {
480
+ /** Create a monitor. Telem runs `query` on the schedule, and its agent keeps what matches. */
481
+ async create(query, options) {
482
+ const given = options ?? {};
483
+ const agent = given.agent == null ? true : Boolean(given.agent);
484
+ if (agent && !given.ttl) throw invalidRequest(NEEDS_TTL);
473
485
  const monitorOptions = {};
474
- if (options.frequency !== void 0) monitorOptions.frequency = options.frequency;
475
- if (options.includeDomains !== void 0) {
476
- monitorOptions.include_domains = options.includeDomains;
486
+ if (given.frequency !== void 0) monitorOptions.frequency = given.frequency;
487
+ if (given.includeDomains !== void 0) {
488
+ monitorOptions.include_domains = given.includeDomains;
477
489
  }
478
- if (options.search !== void 0) monitorOptions.search = searchBlock({}, options.search);
490
+ if (given.search !== void 0) monitorOptions.search = searchBlock({}, given.search);
479
491
  const body = { query, options: monitorOptions };
480
- if (options.metadata !== void 0) body.metadata = options.metadata;
481
- if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
482
- if (options.ttl !== void 0) body.ttl = options.ttl;
483
- if (options.agent !== void 0) body.agent = options.agent;
484
- const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit").catch(
492
+ if (given.metadata !== void 0) body.metadata = given.metadata;
493
+ if (given.webhookUrl !== void 0) body.webhook_url = given.webhookUrl;
494
+ if (given.ttl !== void 0) body.ttl = given.ttl;
495
+ body.agent = agent;
496
+ const data = await request(config, "POST", "/v1/monitors", body, given.signal, "rate_limit").catch(
485
497
  (error) => {
486
498
  if (error instanceof TimeoutError) {
487
499
  throw new TimeoutError(
@@ -503,17 +515,20 @@ function createMonitors(config) {
503
515
  async get(monitorId, options = {}) {
504
516
  return monitorFrom(await request(config, "GET", path(monitorId), void 0, options.signal));
505
517
  },
506
- /** Pause, resume or change a monitor. Only the fields given are sent. */
518
+ /** Pause, resume, renew or change a monitor. Only the fields given are sent. */
507
519
  async update(monitorId, options) {
508
520
  const body = {};
509
521
  if (options.status !== void 0) body.status = options.status;
510
522
  if (options.frequency !== void 0) body.frequency = options.frequency;
523
+ if (options.ttl !== void 0) body.ttl = options.ttl;
511
524
  if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl || null;
512
525
  const route = path(monitorId);
513
526
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
514
527
  },
515
- /** Get the results that are new since the last poll. */
528
+ /** Get the monitor's own results that are new since the last poll. Deprecated: it
529
+ * warns once per process. */
516
530
  async poll(monitorId, options = {}) {
531
+ warnPollDeprecated();
517
532
  const body = {};
518
533
  if (options.session !== void 0) body.session_id = options.session;
519
534
  if (options.metadata !== void 0) body.metadata = options.metadata;
@@ -643,8 +658,8 @@ var Telem = class {
643
658
  maxRetries;
644
659
  /** The session read surface: `list` and `results(id)`. */
645
660
  sessions;
646
- /** Monitors: `create`, `list`, `listPage`, `get`, `update`, `poll`, `delete`, and the
647
- * agent reads `agent`, `changes` and `iterateChanges`. */
661
+ /** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
662
+ * `agent`, `changes` and `iterateChanges`, and the deprecated `poll`. */
648
663
  monitors;
649
664
  #config;
650
665
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",