@telemai/sdk 0.2.5 → 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 CHANGED
@@ -204,17 +204,14 @@ A monitor runs a query on a schedule. Poll it to get the results that are new si
204
204
  your last poll. `poll` returns a `SearchResponse`:
205
205
 
206
206
  ```ts
207
- const monitor = await telem.monitors.create("Nvidia files a new 8-K with the SEC", {
208
- providers: ["exa", "parallel"],
209
- frequency: "1h",
210
- })
207
+ const monitor = await telem.monitors.create("Nvidia files a new 8-K with the SEC", { frequency: "1h" })
211
208
  const response = await telem.monitors.poll(monitor.id)
212
209
  await telem.monitors.update(monitor.id, { status: "paused" })
213
210
  await telem.monitors.delete(monitor.id)
214
211
  ```
215
212
 
216
213
  `telem.monitors` also has `get` and `list`. See [Monitors](https://docs.telem.ai/resources/monitors/)
217
- for the fields, the costs and the errors.
214
+ for the fields and the errors.
218
215
 
219
216
  ## Vercel AI SDK
220
217
 
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  sessionKey: () => sessionKey,
34
34
  snapshotNodeKey: () => snapshotNodeKey,
35
35
  toolMarker: () => toolMarker,
36
+ verifyWebhook: () => verifyWebhook,
36
37
  windowAnchor: () => windowAnchor,
37
38
  withTrajectory: () => withTrajectory
38
39
  });
@@ -59,7 +60,7 @@ var TimeoutError = class extends TelemError {
59
60
  };
60
61
 
61
62
  // src/version.ts
62
- var VERSION = "0.2.5";
63
+ var VERSION = "0.3.0";
63
64
 
64
65
  // src/config.ts
65
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -702,10 +703,12 @@ function monitorFrom(body) {
702
703
  id: String(data.id ?? ""),
703
704
  query: data.query ?? "",
704
705
  frequency: data.frequency ?? "",
705
- providers: asArray(data.providers).filter(isObject).map((p) => ({ name: String(p.name ?? ""), status: String(p.status ?? "") })),
706
+ status: String(data.status ?? ""),
706
707
  sessionId: String(data.session_id ?? ""),
707
708
  createdAt: data.created_at ?? "",
708
709
  lastPolledAt: data.last_polled_at ?? null,
710
+ webhookUrl: data.webhook_url ?? null,
711
+ webhookSecret: data.webhook_secret ?? null,
709
712
  raw: data
710
713
  };
711
714
  }
@@ -715,16 +718,11 @@ function createMonitors(config) {
715
718
  return `/v1/monitors/${encodeURIComponent(monitorId)}${suffix}`;
716
719
  };
717
720
  return {
718
- /** Create a monitor. Each provider runs `query` on the schedule. */
721
+ /** Create a monitor. Telem runs `query` on the schedule. */
719
722
  async create(query, options) {
720
- const body = {
721
- query,
722
- options: { providers: { include: options.providers }, frequency: options.frequency }
723
- };
724
- if (options.providerOverrides !== void 0) {
725
- body.options.provider_overrides = options.providerOverrides;
726
- }
723
+ const body = { query, options: { frequency: options.frequency } };
727
724
  if (options.metadata !== void 0) body.metadata = options.metadata;
725
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
728
726
  const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit");
729
727
  return monitorFrom(data);
730
728
  },
@@ -743,7 +741,7 @@ function createMonitors(config) {
743
741
  const body = {};
744
742
  if (options.status !== void 0) body.status = options.status;
745
743
  if (options.frequency !== void 0) body.frequency = options.frequency;
746
- if (options.providerOverrides !== void 0) body.provider_overrides = options.providerOverrides;
744
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
747
745
  const route = path(monitorId);
748
746
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
749
747
  },
@@ -762,6 +760,23 @@ function createMonitors(config) {
762
760
  }
763
761
  };
764
762
  }
763
+ async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
764
+ const parts = Object.fromEntries(
765
+ header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
766
+ );
767
+ const t = parts.t ?? "";
768
+ const v1 = parts.v1 ?? "";
769
+ if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
770
+ if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
771
+ const encoder = new TextEncoder();
772
+ const raw = typeof body === "string" ? encoder.encode(body) : body;
773
+ const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
774
+ const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
775
+ "verify"
776
+ ]);
777
+ const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
778
+ return crypto.subtle.verify("HMAC", key, signature, signed);
779
+ }
765
780
 
766
781
  // src/methods/providers.ts
767
782
  async function providers(config) {
@@ -906,6 +921,7 @@ var index_default = Telem;
906
921
  sessionKey,
907
922
  snapshotNodeKey,
908
923
  toolMarker,
924
+ verifyWebhook,
909
925
  windowAnchor,
910
926
  withTrajectory
911
927
  });
package/dist/index.d.cts CHANGED
@@ -224,23 +224,21 @@ type SessionsResource = {
224
224
  };
225
225
  /** Options for `monitors.create`. */
226
226
  type MonitorCreateOptions = {
227
- /** One or more provider names, for example `["exa", "parallel"]`. */
228
- providers: string[];
229
227
  /** `"1h"`, `"6h"`, `"1d"` or `"7d"`. */
230
228
  frequency: string;
231
- /** Per-provider create fields, keyed by provider name. */
232
- providerOverrides?: Record<string, Json>;
233
229
  /** Request metadata (query lineage keys), sent as given. */
234
230
  metadata?: Json;
231
+ /** An `https` URL that receives the new results. */
232
+ webhookUrl?: string;
235
233
  signal?: AbortSignal;
236
234
  };
237
- /** Options for `monitors.update`. Send at least one of the three fields. */
235
+ /** Options for `monitors.update`. Send at least one field. */
238
236
  type MonitorUpdateOptions = {
239
237
  /** `"paused"` or `"active"`. */
240
238
  status?: string;
241
239
  frequency?: string;
242
- /** New overrides for the providers named. They replace the ones sent before. */
243
- providerOverrides?: Record<string, Json>;
240
+ /** A new webhook URL, with a new `webhookSecret` in the response. `null` removes it. */
241
+ webhookUrl?: string | null;
244
242
  signal?: AbortSignal;
245
243
  };
246
244
  /** Options for `monitors.poll`. */
@@ -251,21 +249,19 @@ type MonitorPollOptions = {
251
249
  metadata?: Json;
252
250
  signal?: AbortSignal;
253
251
  };
254
- /** One provider of a monitor. `status` is `active`, `paused` (you paused it) or
255
- * `idle` (paused because nobody polled; the next poll resumes it). */
256
- type MonitorProvider = {
257
- name: string;
258
- status: string;
259
- };
260
- /** A monitor: a query that providers run on a schedule. */
252
+ /** A monitor: a query that Telem runs on a schedule. */
261
253
  type Monitor = {
262
254
  id: string;
263
255
  query: string;
264
256
  frequency: string;
265
- providers: MonitorProvider[];
257
+ /** `active` or `paused` (you paused it). */
258
+ status: string;
266
259
  sessionId: string;
267
260
  createdAt: string;
268
261
  lastPolledAt: string | null;
262
+ webhookUrl: string | null;
263
+ /** Signs the webhook deliveries. Only in the response that set `webhookUrl`. */
264
+ webhookSecret: string | null;
269
265
  raw: Json;
270
266
  };
271
267
  /** The `telem.monitors` namespace. */
@@ -323,6 +319,12 @@ declare class TimeoutError extends TelemError {
323
319
  constructor(message: string, cause?: unknown);
324
320
  }
325
321
 
322
+ /**
323
+ * Check a monitor webhook: the `Telem-Signature` header against the raw body.
324
+ * True when the signature is correct and not older than `toleranceSeconds`.
325
+ */
326
+ declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
327
+
326
328
  /** Metadata keys the trajectory payload owns. A caller-supplied value for any of
327
329
  * these is dropped rather than allowed to forge identity. */
328
330
  declare const RESERVED_METADATA: ReadonlySet<string>;
@@ -453,4 +455,4 @@ declare class Telem {
453
455
  providers(): Promise<ProviderInfo[]>;
454
456
  }
455
457
 
456
- export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, windowAnchor, withTrajectory };
458
+ export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, verifyWebhook, windowAnchor, withTrajectory };
package/dist/index.d.ts CHANGED
@@ -224,23 +224,21 @@ type SessionsResource = {
224
224
  };
225
225
  /** Options for `monitors.create`. */
226
226
  type MonitorCreateOptions = {
227
- /** One or more provider names, for example `["exa", "parallel"]`. */
228
- providers: string[];
229
227
  /** `"1h"`, `"6h"`, `"1d"` or `"7d"`. */
230
228
  frequency: string;
231
- /** Per-provider create fields, keyed by provider name. */
232
- providerOverrides?: Record<string, Json>;
233
229
  /** Request metadata (query lineage keys), sent as given. */
234
230
  metadata?: Json;
231
+ /** An `https` URL that receives the new results. */
232
+ webhookUrl?: string;
235
233
  signal?: AbortSignal;
236
234
  };
237
- /** Options for `monitors.update`. Send at least one of the three fields. */
235
+ /** Options for `monitors.update`. Send at least one field. */
238
236
  type MonitorUpdateOptions = {
239
237
  /** `"paused"` or `"active"`. */
240
238
  status?: string;
241
239
  frequency?: string;
242
- /** New overrides for the providers named. They replace the ones sent before. */
243
- providerOverrides?: Record<string, Json>;
240
+ /** A new webhook URL, with a new `webhookSecret` in the response. `null` removes it. */
241
+ webhookUrl?: string | null;
244
242
  signal?: AbortSignal;
245
243
  };
246
244
  /** Options for `monitors.poll`. */
@@ -251,21 +249,19 @@ type MonitorPollOptions = {
251
249
  metadata?: Json;
252
250
  signal?: AbortSignal;
253
251
  };
254
- /** One provider of a monitor. `status` is `active`, `paused` (you paused it) or
255
- * `idle` (paused because nobody polled; the next poll resumes it). */
256
- type MonitorProvider = {
257
- name: string;
258
- status: string;
259
- };
260
- /** A monitor: a query that providers run on a schedule. */
252
+ /** A monitor: a query that Telem runs on a schedule. */
261
253
  type Monitor = {
262
254
  id: string;
263
255
  query: string;
264
256
  frequency: string;
265
- providers: MonitorProvider[];
257
+ /** `active` or `paused` (you paused it). */
258
+ status: string;
266
259
  sessionId: string;
267
260
  createdAt: string;
268
261
  lastPolledAt: string | null;
262
+ webhookUrl: string | null;
263
+ /** Signs the webhook deliveries. Only in the response that set `webhookUrl`. */
264
+ webhookSecret: string | null;
269
265
  raw: Json;
270
266
  };
271
267
  /** The `telem.monitors` namespace. */
@@ -323,6 +319,12 @@ declare class TimeoutError extends TelemError {
323
319
  constructor(message: string, cause?: unknown);
324
320
  }
325
321
 
322
+ /**
323
+ * Check a monitor webhook: the `Telem-Signature` header against the raw body.
324
+ * True when the signature is correct and not older than `toleranceSeconds`.
325
+ */
326
+ declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
327
+
326
328
  /** Metadata keys the trajectory payload owns. A caller-supplied value for any of
327
329
  * these is dropped rather than allowed to forge identity. */
328
330
  declare const RESERVED_METADATA: ReadonlySet<string>;
@@ -453,4 +455,4 @@ declare class Telem {
453
455
  providers(): Promise<ProviderInfo[]>;
454
456
  }
455
457
 
456
- export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorProvider, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, windowAnchor, withTrajectory };
458
+ export { type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorCreateOptions, type MonitorPollOptions, type MonitorUpdateOptions, type MonitorsResource, type ProviderInfo, type ProviderRun, RESERVED_METADATA, type SearchDefaults, type SearchOptions, type SearchResponse, type SearchResult, type SessionResults, type SessionSummary, type SessionsResource, type SnapshotArgs, Telem, type TelemClientErrorCode, TelemError, type TelemErrorOptions, type TelemOptions, TimeoutError, type TrajectoryArgs, type TrajectoryEnvelope, type TrajectorySnapshot, buildMetadata, buildSnapshot, contentAnchor, Telem as default, eventNodeKey, fingerprint, sessionKey, snapshotNodeKey, toolMarker, verifyWebhook, windowAnchor, withTrajectory };
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-DKTEG7EY.js";
23
23
 
24
24
  // src/version.ts
25
- var VERSION = "0.2.5";
25
+ var VERSION = "0.3.0";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -336,10 +336,12 @@ function monitorFrom(body) {
336
336
  id: String(data.id ?? ""),
337
337
  query: data.query ?? "",
338
338
  frequency: data.frequency ?? "",
339
- providers: asArray(data.providers).filter(isObject).map((p) => ({ name: String(p.name ?? ""), status: String(p.status ?? "") })),
339
+ status: String(data.status ?? ""),
340
340
  sessionId: String(data.session_id ?? ""),
341
341
  createdAt: data.created_at ?? "",
342
342
  lastPolledAt: data.last_polled_at ?? null,
343
+ webhookUrl: data.webhook_url ?? null,
344
+ webhookSecret: data.webhook_secret ?? null,
343
345
  raw: data
344
346
  };
345
347
  }
@@ -349,16 +351,11 @@ function createMonitors(config) {
349
351
  return `/v1/monitors/${encodeURIComponent(monitorId)}${suffix}`;
350
352
  };
351
353
  return {
352
- /** Create a monitor. Each provider runs `query` on the schedule. */
354
+ /** Create a monitor. Telem runs `query` on the schedule. */
353
355
  async create(query, options) {
354
- const body = {
355
- query,
356
- options: { providers: { include: options.providers }, frequency: options.frequency }
357
- };
358
- if (options.providerOverrides !== void 0) {
359
- body.options.provider_overrides = options.providerOverrides;
360
- }
356
+ const body = { query, options: { frequency: options.frequency } };
361
357
  if (options.metadata !== void 0) body.metadata = options.metadata;
358
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
362
359
  const data = await request(config, "POST", "/v1/monitors", body, options.signal, "rate_limit");
363
360
  return monitorFrom(data);
364
361
  },
@@ -377,7 +374,7 @@ function createMonitors(config) {
377
374
  const body = {};
378
375
  if (options.status !== void 0) body.status = options.status;
379
376
  if (options.frequency !== void 0) body.frequency = options.frequency;
380
- if (options.providerOverrides !== void 0) body.provider_overrides = options.providerOverrides;
377
+ if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl;
381
378
  const route = path(monitorId);
382
379
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
383
380
  },
@@ -396,6 +393,23 @@ function createMonitors(config) {
396
393
  }
397
394
  };
398
395
  }
396
+ async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
397
+ const parts = Object.fromEntries(
398
+ header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
399
+ );
400
+ const t = parts.t ?? "";
401
+ const v1 = parts.v1 ?? "";
402
+ if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
403
+ if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
404
+ const encoder = new TextEncoder();
405
+ const raw = typeof body === "string" ? encoder.encode(body) : body;
406
+ const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
407
+ const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
408
+ "verify"
409
+ ]);
410
+ const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
411
+ return crypto.subtle.verify("HMAC", key, signature, signed);
412
+ }
399
413
 
400
414
  // src/methods/providers.ts
401
415
  async function providers(config) {
@@ -540,6 +554,7 @@ export {
540
554
  sessionKey,
541
555
  snapshotNodeKey,
542
556
  toolMarker,
557
+ verifyWebhook,
543
558
  windowAnchor,
544
559
  withTrajectory
545
560
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",