@telemai/sdk 0.5.0 → 0.6.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
@@ -392,6 +392,12 @@ try {
392
392
  | Other 4xx | `TelemError` with the status and the code from the server, not retried |
393
393
  | Attempt longer than `timeoutMs` | `TimeoutError`, not retried |
394
394
 
395
+ `monitors.create` sends an `Idempotency-Key` header, a new one per call unless you
396
+ pass `idempotencyKey`. It retries a 429, a 409 `idempotency_in_progress`, a network
397
+ failure and a timeout for up to about 2 minutes, with the same key. For 24 hours, a
398
+ retry with the same key returns the first monitor instead of creating a second one.
399
+ A different API key makes a new monitor. A 5xx is not retried.
400
+
395
401
  See [Resources → Errors](https://docs.telem.ai/resources/errors/) for how the plugins show a failed call.
396
402
 
397
403
  ## Embedding and edge runtimes
@@ -22,6 +22,7 @@ var TimeoutError = class extends TelemError {
22
22
  var MAX_DELAY_MS = 3e4;
23
23
  var MAX_TIMEOUT_MS = 2 ** 31 - 1;
24
24
  var BASE_DELAY_MS = 500;
25
+ var MAX_IDEMPOTENT_BACKOFF_MS = 1e4;
25
26
  function isObject(value) {
26
27
  return typeof value === "object" && value !== null && !Array.isArray(value);
27
28
  }
@@ -100,6 +101,11 @@ function connectionError(url, cause) {
100
101
  function isRetryable(status) {
101
102
  return status >= 500 || status === 429;
102
103
  }
104
+ function shouldRetry(mode, status, body) {
105
+ if (mode === "all") return isRetryable(status);
106
+ if (status === 429) return true;
107
+ return mode === "idempotent" && status === 409 && codeFromBody(body) === "idempotency_in_progress";
108
+ }
103
109
  function backoff(attempt) {
104
110
  return Math.min(BASE_DELAY_MS * 2 ** attempt, MAX_DELAY_MS);
105
111
  }
@@ -109,9 +115,20 @@ function retryDelay(retryAfter, attempt) {
109
115
  }
110
116
  return backoff(attempt);
111
117
  }
112
- async function request(config, method, path, body, abort, retry = "all") {
118
+ function jittered(ms) {
119
+ return ms + Math.random() * Math.max(1e3, ms / 2);
120
+ }
121
+ function idempotentDelay(retryAfter, attempt) {
122
+ if (retryAfter !== null && /^\s*\d+\s*$/.test(retryAfter)) return jittered(Number(retryAfter) * 1e3);
123
+ return Math.min(jittered(BASE_DELAY_MS * 2 ** attempt), MAX_IDEMPOTENT_BACKOFF_MS);
124
+ }
125
+ async function request(config, method, path, body, abort, retry = "all", extra = {}) {
113
126
  const url = `${config.baseUrl}/${path.replace(/^\/+/, "")}`;
114
- const headers = { "User-Agent": config.userAgent };
127
+ const maxRetries = extra.maxRetries ?? config.maxRetries;
128
+ const started = Date.now();
129
+ const fits = (ms) => Date.now() - started + ms <= (extra.budgetMs ?? Infinity);
130
+ const delay = (retryAfter, attempt) => retry === "idempotent" ? idempotentDelay(retryAfter, attempt) : retryDelay(retryAfter, attempt);
131
+ const headers = { ...extra.headers, "User-Agent": config.userAgent };
115
132
  if (config.apiKey) headers.Authorization = `Bearer ${config.apiKey}`;
116
133
  const init = { method, headers };
117
134
  if (body !== void 0) {
@@ -171,20 +188,27 @@ async function request(config, method, path, body, abort, retry = "all") {
171
188
  });
172
189
  }
173
190
  if (abort?.aborted) throw abort.reason ?? cause;
191
+ const wait = delay(null, attempt);
174
192
  if (signal?.aborted) {
193
+ if (retry === "idempotent" && attempt < maxRetries && fits(wait)) {
194
+ await pause(wait);
195
+ continue;
196
+ }
175
197
  throw new TimeoutError(`request to ${url} timed out after ${config.timeoutMs}ms`, cause);
176
198
  }
177
- if (retry === "rate_limit" || attempt >= config.maxRetries) throw connectionError(url, cause);
178
- await pause(backoff(attempt));
199
+ if (retry === "rate_limit" || attempt >= maxRetries || !fits(wait)) throw connectionError(url, cause);
200
+ await pause(wait);
179
201
  continue;
180
202
  } finally {
181
203
  signal?.removeEventListener("abort", onAbort2);
182
204
  }
183
205
  if (received.status >= 200 && received.status < 300) return received.body;
184
- const retryable = retry === "rate_limit" ? received.status === 429 : isRetryable(received.status);
185
- if (retryable && attempt < config.maxRetries) {
186
- await pause(retryDelay(received.retryAfter, attempt));
187
- continue;
206
+ if (shouldRetry(retry, received.status, received.body) && attempt < maxRetries) {
207
+ const wait = delay(received.retryAfter, attempt);
208
+ if (fits(wait)) {
209
+ await pause(wait);
210
+ continue;
211
+ }
188
212
  }
189
213
  throw statusError(received.status, received.body);
190
214
  }
package/dist/index.cjs CHANGED
@@ -60,12 +60,14 @@ var TimeoutError = class extends TelemError {
60
60
  };
61
61
 
62
62
  // src/version.ts
63
- var VERSION = "0.5.0";
63
+ var VERSION = "0.6.0";
64
64
 
65
65
  // src/config.ts
66
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
67
67
  var DEFAULT_TIMEOUT_MS = 6e4;
68
68
  var DEFAULT_MAX_RETRIES = 2;
69
+ var CREATE_RETRY_BUDGET_MS = 12e4;
70
+ var DEFAULT_CREATE_MAX_RETRIES = 60;
69
71
  var BLANK = /^[ \t\n\r\v\f\u00a0\ufeff\u3000]+|[ \t\n\r\v\f\u00a0\ufeff\u3000]+$/g;
70
72
  function trimBlank(value) {
71
73
  return value.replace(BLANK, "");
@@ -128,6 +130,12 @@ function resolveConfig(options) {
128
130
  apiKey = apiKey ?? credentials.apiKey;
129
131
  baseUrl = baseUrl ?? credentials.baseUrl;
130
132
  }
133
+ if (opts.defaultVertical !== void 0 && opts.vertical !== void 0 && opts.defaultVertical !== opts.vertical) {
134
+ throw invalidOption(
135
+ `vertical ${JSON.stringify(opts.vertical)} and defaultVertical ${JSON.stringify(opts.defaultVertical)} are the same option; pass one of them`
136
+ );
137
+ }
138
+ const vertical = opts.defaultVertical ?? opts.vertical ?? (trimBlank(env.TELEM_VERTICAL ?? "") || void 0);
131
139
  const resolvedBaseUrl = (baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
132
140
  let scheme;
133
141
  try {
@@ -143,6 +151,7 @@ function resolveConfig(options) {
143
151
  baseUrl: resolvedBaseUrl,
144
152
  timeoutMs,
145
153
  maxRetries,
154
+ createMaxRetries: opts.maxRetries ?? DEFAULT_CREATE_MAX_RETRIES,
146
155
  userAgent: opts.userAgent || `telem-sdk-js/${VERSION}`,
147
156
  fetch: send,
148
157
  sleep: opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))),
@@ -158,7 +167,8 @@ function resolveConfig(options) {
158
167
  includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0),
159
168
  autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
160
169
  maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
161
- topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
170
+ topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0),
171
+ vertical
162
172
  },
163
173
  // Fetch defaults: env var only, parsed as the shared option table parses it (CSV,
164
174
  // a trimmed name, a "1"-only flag); the tier is lowercased, as the agent plugins
@@ -175,6 +185,7 @@ function resolveConfig(options) {
175
185
  var MAX_DELAY_MS = 3e4;
176
186
  var MAX_TIMEOUT_MS = 2 ** 31 - 1;
177
187
  var BASE_DELAY_MS = 500;
188
+ var MAX_IDEMPOTENT_BACKOFF_MS = 1e4;
178
189
  function isObject(value) {
179
190
  return typeof value === "object" && value !== null && !Array.isArray(value);
180
191
  }
@@ -253,6 +264,11 @@ function connectionError(url, cause) {
253
264
  function isRetryable(status) {
254
265
  return status >= 500 || status === 429;
255
266
  }
267
+ function shouldRetry(mode, status, body) {
268
+ if (mode === "all") return isRetryable(status);
269
+ if (status === 429) return true;
270
+ return mode === "idempotent" && status === 409 && codeFromBody(body) === "idempotency_in_progress";
271
+ }
256
272
  function backoff(attempt) {
257
273
  return Math.min(BASE_DELAY_MS * 2 ** attempt, MAX_DELAY_MS);
258
274
  }
@@ -262,9 +278,20 @@ function retryDelay(retryAfter, attempt) {
262
278
  }
263
279
  return backoff(attempt);
264
280
  }
265
- async function request(config, method, path, body, abort, retry = "all") {
281
+ function jittered(ms) {
282
+ return ms + Math.random() * Math.max(1e3, ms / 2);
283
+ }
284
+ function idempotentDelay(retryAfter, attempt) {
285
+ if (retryAfter !== null && /^\s*\d+\s*$/.test(retryAfter)) return jittered(Number(retryAfter) * 1e3);
286
+ return Math.min(jittered(BASE_DELAY_MS * 2 ** attempt), MAX_IDEMPOTENT_BACKOFF_MS);
287
+ }
288
+ async function request(config, method, path, body, abort, retry = "all", extra = {}) {
266
289
  const url = `${config.baseUrl}/${path.replace(/^\/+/, "")}`;
267
- const headers = { "User-Agent": config.userAgent };
290
+ const maxRetries = extra.maxRetries ?? config.maxRetries;
291
+ const started = Date.now();
292
+ const fits = (ms) => Date.now() - started + ms <= (extra.budgetMs ?? Infinity);
293
+ const delay = (retryAfter, attempt) => retry === "idempotent" ? idempotentDelay(retryAfter, attempt) : retryDelay(retryAfter, attempt);
294
+ const headers = { ...extra.headers, "User-Agent": config.userAgent };
268
295
  if (config.apiKey) headers.Authorization = `Bearer ${config.apiKey}`;
269
296
  const init = { method, headers };
270
297
  if (body !== void 0) {
@@ -324,20 +351,27 @@ async function request(config, method, path, body, abort, retry = "all") {
324
351
  });
325
352
  }
326
353
  if (abort?.aborted) throw abort.reason ?? cause;
354
+ const wait = delay(null, attempt);
327
355
  if (signal?.aborted) {
356
+ if (retry === "idempotent" && attempt < maxRetries && fits(wait)) {
357
+ await pause(wait);
358
+ continue;
359
+ }
328
360
  throw new TimeoutError(`request to ${url} timed out after ${config.timeoutMs}ms`, cause);
329
361
  }
330
- if (retry === "rate_limit" || attempt >= config.maxRetries) throw connectionError(url, cause);
331
- await pause(backoff(attempt));
362
+ if (retry === "rate_limit" || attempt >= maxRetries || !fits(wait)) throw connectionError(url, cause);
363
+ await pause(wait);
332
364
  continue;
333
365
  } finally {
334
366
  signal?.removeEventListener("abort", onAbort2);
335
367
  }
336
368
  if (received.status >= 200 && received.status < 300) return received.body;
337
- const retryable = retry === "rate_limit" ? received.status === 429 : isRetryable(received.status);
338
- if (retryable && attempt < config.maxRetries) {
339
- await pause(retryDelay(received.retryAfter, attempt));
340
- continue;
369
+ if (shouldRetry(retry, received.status, received.body) && attempt < maxRetries) {
370
+ const wait = delay(received.retryAfter, attempt);
371
+ if (fits(wait)) {
372
+ await pause(wait);
373
+ continue;
374
+ }
341
375
  }
342
376
  throw statusError(received.status, received.body);
343
377
  }
@@ -616,6 +650,8 @@ function searchBlock(defaults, options) {
616
650
  if (options.publishedAfter !== void 0) block.published_after = isoDate(options.publishedAfter);
617
651
  if (options.publishedBefore !== void 0) block.published_before = isoDate(options.publishedBefore);
618
652
  if (options.includeDomains !== void 0) block.include_domains = options.includeDomains;
653
+ const vertical = options.vertical ?? defaults.vertical;
654
+ if (vertical !== void 0) block.vertical = vertical;
619
655
  return block;
620
656
  }
621
657
  function isoDate(value) {
@@ -727,6 +763,8 @@ async function search(config, query, options) {
727
763
 
728
764
  // src/methods/monitors.ts
729
765
  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.';
766
+ var NEEDS_TTL_INPUTS = 'A monitor with inputs must end: pass ttl, such as ttl: "30d" (at most 365 days).';
767
+ var IDEMPOTENCY_KEY = /^[\x21-\x7e]{1,255}$/;
730
768
  var POLL_DEPRECATED = "@telemai/sdk: monitors.poll() is deprecated: read what the monitor agent finds with monitors.iterateChanges() or monitors.changes().";
731
769
  var pollWarned = false;
732
770
  function warnPollDeprecated() {
@@ -764,6 +802,7 @@ function monitorFrom(body) {
764
802
  webhookUrl: data.webhook_url ?? null,
765
803
  webhookSecret: data.webhook_secret ?? null,
766
804
  agentNote: typeof data.agent_note === "string" ? data.agent_note : null,
805
+ tags: asArray(data.tags).map(String),
767
806
  raw: data
768
807
  };
769
808
  if (data.agent_state !== void 0) {
@@ -809,10 +848,116 @@ function changesPageFrom(body) {
809
848
  watermark: Number(data.watermark ?? 0)
810
849
  };
811
850
  }
851
+ function monitorsChangesPageFrom(body) {
852
+ const data = asObject(body);
853
+ return {
854
+ changes: asArray(data.changes).filter(isObject).map(changeRecordFrom),
855
+ nextCursor: typeof data.next_cursor === "string" ? data.next_cursor : "",
856
+ more: data.more === true,
857
+ monitors: asArray(data.monitors).map(String),
858
+ pending: asArray(data.pending).map(String),
859
+ skipped: asArray(data.skipped).map(String)
860
+ };
861
+ }
862
+ var stringOrNull = (value) => typeof value === "string" ? value : null;
863
+ var countOf = (value) => Array.isArray(value) ? value.length : typeof value === "number" ? value : 0;
864
+ function setFields(fields) {
865
+ return Object.fromEntries(Object.entries(fields).filter(([key, value]) => key !== "signal" && value != null));
866
+ }
867
+ function exampleFrom(data) {
868
+ if (!isObject(data)) return null;
869
+ return { name: stringOrNull(data.name), quote: stringOrNull(data.quote), url: stringOrNull(data.url) };
870
+ }
871
+ function candidateFrom(entry) {
872
+ return {
873
+ id: String(entry.id ?? ""),
874
+ what: stringOrNull(entry.what),
875
+ label: String(entry.label ?? ""),
876
+ mappedTo: stringOrNull(entry.mapped_to),
877
+ isNew: entry.is_new === true,
878
+ count: countOf(entry.count),
879
+ origins: countOf(entry.origins),
880
+ example: exampleFrom(entry.example),
881
+ raw: entry
882
+ };
883
+ }
884
+ function companySheetFrom(data) {
885
+ return {
886
+ companyId: stringOrNull(data.company_id),
887
+ pages: countOf(data.pages),
888
+ candidates: asArray(data.candidates).filter(isObject).map(candidateFrom),
889
+ note: stringOrNull(data.note),
890
+ raw: data
891
+ };
892
+ }
893
+ function onboardingCompanyFrom(entry) {
894
+ return {
895
+ companyId: String(entry.company_id ?? ""),
896
+ status: String(entry.status ?? ""),
897
+ runId: stringOrNull(entry.run_id),
898
+ sheet: isObject(entry.sheet) ? companySheetFrom(entry.sheet) : null,
899
+ marks: isObject(entry.marks) ? entry.marks : null,
900
+ at: stringOrNull(entry.at),
901
+ appliedAt: stringOrNull(entry.applied_at),
902
+ raw: entry
903
+ };
904
+ }
905
+ function onboardingSheetFrom(body) {
906
+ const data = asObject(body);
907
+ return {
908
+ monitorId: stringOrNull(data.monitor_id),
909
+ companies: asArray(data.companies).filter(isObject).map(onboardingCompanyFrom),
910
+ raw: data
911
+ };
912
+ }
913
+ function applyResultFrom(body) {
914
+ const data = asObject(body);
915
+ return { jobId: String(data.job_id ?? ""), raw: data };
916
+ }
917
+ function expansionFrom(entry) {
918
+ return {
919
+ id: String(entry.id ?? ""),
920
+ kind: String(entry.kind ?? ""),
921
+ target: String(entry.target ?? ""),
922
+ status: String(entry.status ?? ""),
923
+ reason: asObject(entry.reason),
924
+ delta: asObject(entry.delta),
925
+ counts: asObject(entry.counts),
926
+ note: stringOrNull(entry.note),
927
+ runId: stringOrNull(entry.run_id),
928
+ createdAt: stringOrNull(entry.created_at),
929
+ updatedAt: stringOrNull(entry.updated_at),
930
+ raw: entry
931
+ };
932
+ }
933
+ function expansionsPageFrom(body) {
934
+ const data = asObject(body);
935
+ return {
936
+ expansions: asArray(data.expansions).filter(isObject).map(expansionFrom),
937
+ nextCursor: stringOrNull(data.next_cursor)
938
+ };
939
+ }
940
+ function feedbackResultFrom(body) {
941
+ const data = asObject(body);
942
+ return { status: String(data.status ?? ""), jobId: stringOrNull(data.job_id), raw: data };
943
+ }
944
+ function dataMapFrom(body) {
945
+ const data = asObject(body);
946
+ return {
947
+ // A kind named bare, as a monitor created without inputs may have it.
948
+ kinds: asArray(data.kinds).map((kind) => typeof kind === "string" ? { kind } : kind).filter(isObject),
949
+ categories: asArray(data.categories).filter(isObject),
950
+ inducedCategories: asArray(data.induced_categories).filter(isObject),
951
+ people: asObject(data.people),
952
+ note: stringOrNull(data.note),
953
+ raw: data
954
+ };
955
+ }
812
956
  function listQuery(options) {
813
957
  const params = new URLSearchParams();
814
958
  if (options.limit !== void 0) params.set("limit", String(options.limit));
815
959
  if (options.cursor !== void 0) params.set("cursor", options.cursor);
960
+ if (options.tag !== void 0) params.set("tag", options.tag);
816
961
  const query = params.toString();
817
962
  return query ? `?${query}` : "";
818
963
  }
@@ -824,12 +969,28 @@ function sinceParam(since) {
824
969
  function changesQuery(options) {
825
970
  const params = new URLSearchParams();
826
971
  if (options.cursor !== void 0) params.set("cursor", String(options.cursor));
972
+ return readQuery(params, options);
973
+ }
974
+ function readQuery(params, options) {
827
975
  if (options.since !== void 0) params.set("since", sinceParam(options.since));
828
976
  if (options.kinds !== void 0) params.set("kinds", options.kinds.join(","));
829
977
  if (options.limit !== void 0) params.set("limit", String(options.limit));
830
978
  const query = params.toString();
831
979
  return query ? `?${query}` : "";
832
980
  }
981
+ function acrossQuery(scope, options) {
982
+ const { tag, ids } = asObject(scope);
983
+ if (tag == null === (ids == null)) throw invalidRequest("send tag or ids, one of them");
984
+ const params = new URLSearchParams();
985
+ if (tag != null) params.set("tag", String(tag));
986
+ else {
987
+ const named = typeof ids === "string" ? ids : asArray(ids).join(",");
988
+ if (!named) throw invalidRequest("ids needs at least one monitor id");
989
+ params.set("ids", named);
990
+ }
991
+ if (options.cursor !== void 0) params.set("cursor", options.cursor);
992
+ return readQuery(params, options);
993
+ }
833
994
  function createMonitors(config) {
834
995
  const path = (monitorId, suffix = "") => {
835
996
  if (!monitorId || /^\.+$/.test(monitorId)) throw invalidRequest("a monitor id is required");
@@ -845,12 +1006,25 @@ function createMonitors(config) {
845
1006
  const route = `${path(monitorId, "/agent/changes")}${changesQuery(options)}`;
846
1007
  return changesPageFrom(await request(config, "GET", route, void 0, options.signal));
847
1008
  };
1009
+ const changesAcross = async (scope, options = {}) => {
1010
+ const route = `/v1/monitors/changes${acrossQuery(scope, options)}`;
1011
+ return monitorsChangesPageFrom(await request(config, "GET", route, void 0, options.signal));
1012
+ };
1013
+ const expansionPath = (monitorId, expansionId, action) => {
1014
+ if (!expansionId || /^\.+$/.test(expansionId)) throw invalidRequest("an expansion id is required");
1015
+ return path(monitorId, `/agent/expansions/${encodeURIComponent(expansionId)}:${action}`);
1016
+ };
1017
+ const write = async (route, body, signal) => request(config, "POST", route, body, signal, "rate_limit");
848
1018
  return {
849
1019
  /** Create a monitor. Telem runs `query` on the schedule, and its agent keeps what matches. */
850
1020
  async create(query, options) {
851
1021
  const given = options ?? {};
852
1022
  const agent = given.agent == null ? true : Boolean(given.agent);
853
- if (agent && !given.ttl) throw invalidRequest(NEEDS_TTL);
1023
+ if (agent && !given.ttl) throw invalidRequest(given.inputs == null ? NEEDS_TTL : NEEDS_TTL_INPUTS);
1024
+ const key = given.idempotencyKey ?? globalThis.crypto.randomUUID();
1025
+ if (typeof key !== "string" || !IDEMPOTENCY_KEY.test(key)) {
1026
+ throw invalidRequest("idempotencyKey must be 1 to 255 visible ASCII characters");
1027
+ }
854
1028
  const monitorOptions = {};
855
1029
  if (given.frequency !== void 0) monitorOptions.frequency = given.frequency;
856
1030
  if (given.includeDomains !== void 0) {
@@ -861,8 +1035,22 @@ function createMonitors(config) {
861
1035
  if (given.metadata !== void 0) body.metadata = given.metadata;
862
1036
  if (given.webhookUrl !== void 0) body.webhook_url = given.webhookUrl;
863
1037
  if (given.ttl !== void 0) body.ttl = given.ttl;
1038
+ if (given.inputs != null) {
1039
+ body.inputs = given.inputs;
1040
+ const vertical = config.defaults.vertical;
1041
+ if (vertical !== void 0 && !("vertical" in given.inputs)) {
1042
+ body.inputs = { ...given.inputs, vertical };
1043
+ }
1044
+ }
864
1045
  body.agent = agent;
865
- const data = await request(config, "POST", "/v1/monitors", body, given.signal, "rate_limit").catch(
1046
+ if (given.preset != null) body.preset = given.preset;
1047
+ if (given.tags != null) body.tags = given.tags;
1048
+ const extra = {
1049
+ headers: { "Idempotency-Key": key },
1050
+ maxRetries: config.createMaxRetries,
1051
+ budgetMs: CREATE_RETRY_BUDGET_MS
1052
+ };
1053
+ const data = await request(config, "POST", "/v1/monitors", body, given.signal, "idempotent", extra).catch(
866
1054
  (error) => {
867
1055
  if (error instanceof TimeoutError) {
868
1056
  throw new TimeoutError(
@@ -891,6 +1079,7 @@ function createMonitors(config) {
891
1079
  if (options.frequency !== void 0) body.frequency = options.frequency;
892
1080
  if (options.ttl !== void 0) body.ttl = options.ttl;
893
1081
  if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl || null;
1082
+ if (options.tags != null) body.tags = options.tags;
894
1083
  const route = path(monitorId);
895
1084
  return monitorFrom(await request(config, "PATCH", route, body, options.signal));
896
1085
  },
@@ -925,6 +1114,58 @@ function createMonitors(config) {
925
1114
  if (!page.changes.length || page.nextCursor <= cursor || page.nextCursor >= page.watermark) return;
926
1115
  cursor = page.nextCursor;
927
1116
  }
1117
+ },
1118
+ /** One page of the changes of up to 100 monitors. Keep `nextCursor` and pass it back as `cursor`. */
1119
+ changesAcross,
1120
+ /** The changes of up to 100 monitors, page by page while `more` is true. `since` goes
1121
+ * with the first page only; the scope, `kinds` and `limit` with every page. */
1122
+ async *iterateChangesAcross(scope, options = {}) {
1123
+ let { cursor, since } = options;
1124
+ for (; ; ) {
1125
+ const page = await changesAcross(scope, { ...options, cursor, since });
1126
+ for (const change of page.changes) yield change;
1127
+ if (!page.more || !page.changes.length || page.nextCursor === cursor) return;
1128
+ cursor = page.nextCursor;
1129
+ since = void 0;
1130
+ }
1131
+ },
1132
+ /** Label one fact of the monitor; with `category`, file a refuted fact there. */
1133
+ async feedback(monitorId, options) {
1134
+ const body = { fact_id: options.factId, verdict: options.verdict };
1135
+ if (options.category != null) body.category = options.category;
1136
+ return feedbackResultFrom(await write(path(monitorId, "/agent/feedback"), body, options.signal));
1137
+ },
1138
+ /** The onboarding sheet of each company of a monitor created with `inputs`. */
1139
+ async onboarding(monitorId, options = {}) {
1140
+ const route = path(monitorId, "/agent/onboarding");
1141
+ return onboardingSheetFrom(await request(config, "GET", route, void 0, options.signal));
1142
+ },
1143
+ /** Apply your review of one company's sheet: `companyId` goes as `company_id`. */
1144
+ async applyOnboarding(monitorId, marks) {
1145
+ const { companyId, ...rest } = marks;
1146
+ const body = setFields({ company_id: companyId, ...rest });
1147
+ return applyResultFrom(await write(path(monitorId, "/agent/onboarding:apply"), body, marks.signal));
1148
+ },
1149
+ /** What the monitor proposes to add, or added; `status` filters. */
1150
+ async expansions(monitorId, options = {}) {
1151
+ const query = options.status !== void 0 ? `?${new URLSearchParams({ status: options.status })}` : "";
1152
+ const route = `${path(monitorId, "/agent/expansions")}${query}`;
1153
+ return expansionsPageFrom(await request(config, "GET", route, void 0, options.signal));
1154
+ },
1155
+ /** Use a proposed addition. */
1156
+ async confirmExpansion(monitorId, expansionId, fields = {}) {
1157
+ const route = expansionPath(monitorId, expansionId, "confirm");
1158
+ return applyResultFrom(await write(route, setFields(fields), fields.signal));
1159
+ },
1160
+ /** Remove an addition. */
1161
+ async revertExpansion(monitorId, expansionId, options = {}) {
1162
+ const route = expansionPath(monitorId, expansionId, "revert");
1163
+ return applyResultFrom(await write(route, {}, options.signal));
1164
+ },
1165
+ /** Every kind and category the monitor collects. */
1166
+ async dataMap(monitorId, options = {}) {
1167
+ const route = path(monitorId, "/agent/data-map");
1168
+ return dataMapFrom(await request(config, "GET", route, void 0, options.signal));
928
1169
  }
929
1170
  };
930
1171
  }
@@ -1028,7 +1269,10 @@ var Telem = class {
1028
1269
  /** The session read surface: `list` and `results(id)`. */
1029
1270
  sessions;
1030
1271
  /** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
1031
- * `agent`, `changes` and `iterateChanges`, and the deprecated `poll`. */
1272
+ * `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
1273
+ * `iterateChangesAcross`, `feedback`, what a monitor created with
1274
+ * `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
1275
+ * `revertExpansion`, `dataMap`), and the deprecated `poll`. */
1032
1276
  monitors;
1033
1277
  #config;
1034
1278
  /**