@telemai/sdk 0.6.0 → 0.7.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/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.6.0";
63
+ var VERSION = "0.7.0";
64
64
 
65
65
  // src/config.ts
66
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -710,6 +710,9 @@ function searchResults(envelope, provider) {
710
710
  source: row.source ?? null,
711
711
  enrichments: row.enrichments ?? null,
712
712
  fetchMeta: row.fetch_meta ?? null,
713
+ imageUrl: row.image_url ?? null,
714
+ imageWidth: row.image_width ?? null,
715
+ imageHeight: row.image_height ?? null,
713
716
  provider,
714
717
  raw: row
715
718
  }));
@@ -953,6 +956,41 @@ function dataMapFrom(body) {
953
956
  raw: data
954
957
  };
955
958
  }
959
+ function companyFrom(entry) {
960
+ return {
961
+ companyId: String(entry.company_id ?? ""),
962
+ name: String(entry.name ?? ""),
963
+ domain: String(entry.domain ?? ""),
964
+ priority: entry.priority === true,
965
+ aliases: asArray(entry.aliases).map(String),
966
+ ticker: String(entry.ticker ?? ""),
967
+ xHandle: String(entry.x_handle ?? ""),
968
+ newsroomUrl: String(entry.newsroom_url ?? ""),
969
+ teamPage: String(entry.team_page ?? ""),
970
+ tier: String(entry.tier ?? ""),
971
+ rank: Number(entry.rank ?? 0),
972
+ raw: entry
973
+ };
974
+ }
975
+ function companyListFrom(body) {
976
+ const data = asObject(body);
977
+ return {
978
+ total: Number(data.total ?? 0),
979
+ priorityCount: Number(data.priority_count ?? 0),
980
+ offset: Number(data.offset ?? 0),
981
+ limit: Number(data.limit ?? 0),
982
+ nextOffset: typeof data.next_offset === "number" ? data.next_offset : null,
983
+ companies: asArray(data.companies).filter(isObject).map(companyFrom),
984
+ raw: data
985
+ };
986
+ }
987
+ function companiesQuery(options) {
988
+ const params = new URLSearchParams();
989
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
990
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
991
+ const query = params.toString();
992
+ return query ? `?${query}` : "";
993
+ }
956
994
  function listQuery(options) {
957
995
  const params = new URLSearchParams();
958
996
  if (options.limit !== void 0) params.set("limit", String(options.limit));
@@ -1166,25 +1204,36 @@ function createMonitors(config) {
1166
1204
  async dataMap(monitorId, options = {}) {
1167
1205
  const route = path(monitorId, "/agent/data-map");
1168
1206
  return dataMapFrom(await request(config, "GET", route, void 0, options.signal));
1207
+ },
1208
+ /** One page of the monitor's companies, in rank order. */
1209
+ async companies(monitorId, options = {}) {
1210
+ const route = `${path(monitorId, "/agent/companies")}${companiesQuery(options)}`;
1211
+ return companyListFrom(await request(config, "GET", route, void 0, options.signal));
1169
1212
  }
1170
1213
  };
1171
1214
  }
1172
1215
  async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
1173
- const parts = Object.fromEntries(
1174
- header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
1175
- );
1176
- const t = parts.t ?? "";
1177
- const v1 = parts.v1 ?? "";
1216
+ const parts = header.split(",").map((item) => item.trim()).filter((item) => item.includes("=")).map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)]);
1217
+ const timestamps = parts.filter(([name]) => name === "t").map(([, value]) => value);
1218
+ const signatures = parts.filter(([name, value]) => name === "v1" && /^[0-9a-f]{64}$/.test(value)).map(([, value]) => value);
1219
+ if (timestamps.length !== 1 || signatures.length === 0) return false;
1220
+ const t = timestamps[0];
1178
1221
  if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
1179
- if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
1180
1222
  const encoder = new TextEncoder();
1181
1223
  const raw = typeof body === "string" ? encoder.encode(body) : body;
1182
1224
  const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
1183
1225
  const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
1184
- "verify"
1226
+ "sign"
1185
1227
  ]);
1186
- const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
1187
- return crypto.subtle.verify("HMAC", key, signature, signed);
1228
+ const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, signed));
1229
+ const expected = Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("");
1230
+ return signatures.some((signature) => sameText(signature, expected));
1231
+ }
1232
+ function sameText(a, b) {
1233
+ if (a.length !== b.length) return false;
1234
+ let diff = 0;
1235
+ for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
1236
+ return diff === 0;
1188
1237
  }
1189
1238
 
1190
1239
  // src/methods/providers.ts
@@ -1272,7 +1321,7 @@ var Telem = class {
1272
1321
  * `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
1273
1322
  * `iterateChangesAcross`, `feedback`, what a monitor created with
1274
1323
  * `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
1275
- * `revertExpansion`, `dataMap`), and the deprecated `poll`. */
1324
+ * `revertExpansion`, `dataMap`, `companies`), and the deprecated `poll`. */
1276
1325
  monitors;
1277
1326
  #config;
1278
1327
  /**
package/dist/index.d.cts CHANGED
@@ -63,6 +63,8 @@ type SearchOptions = {
63
63
  includeFullContent?: boolean;
64
64
  autoRouting?: string;
65
65
  maxRoutingProviders?: number;
66
+ /** `"images"`: an image search on brave only; each result adds `imageUrl`, `imageWidth`
67
+ * and `imageHeight`. */
66
68
  topic?: string;
67
69
  vertical?: string;
68
70
  /** Only results published on or after this date or date-time: an ISO 8601 string
@@ -141,6 +143,10 @@ type SearchResult = {
141
143
  source: Json | null;
142
144
  enrichments: Json | null;
143
145
  fetchMeta: Json | null;
146
+ /** Image searches (`topic: "images"`) only: the original image, its width and height. */
147
+ imageUrl: string | null;
148
+ imageWidth: number | null;
149
+ imageHeight: number | null;
144
150
  provider: string;
145
151
  raw: Json;
146
152
  };
@@ -681,6 +687,45 @@ type DataMap = {
681
687
  note: string | null;
682
688
  raw: Json;
683
689
  };
690
+ /** One company of `monitors.companies`. */
691
+ type CompanyListRow = {
692
+ companyId: string;
693
+ name: string;
694
+ domain: string;
695
+ /** Whether the company is marked priority: it is checked on every routine run. */
696
+ priority: boolean;
697
+ aliases: string[];
698
+ ticker: string;
699
+ xHandle: string;
700
+ newsroomUrl: string;
701
+ teamPage: string;
702
+ /** `daily`, `weekly` or `off`, as you gave it; empty when its rank decides. */
703
+ tier: string;
704
+ /** Its place among the monitor's companies, from 1. */
705
+ rank: number;
706
+ raw: Json;
707
+ };
708
+ /** One page of `monitors.companies`, in rank order. */
709
+ type CompanyList = {
710
+ /** All the companies the monitor follows. */
711
+ total: number;
712
+ /** How many of them are marked priority. */
713
+ priorityCount: number;
714
+ offset: number;
715
+ limit: number;
716
+ /** Pass it as `offset` for the next page; `null` on the last page. */
717
+ nextOffset: number | null;
718
+ companies: CompanyListRow[];
719
+ raw: Json;
720
+ };
721
+ /** Options for `monitors.companies`. */
722
+ type MonitorCompaniesOptions = {
723
+ /** How many companies to skip, from the top (server default 0). */
724
+ offset?: number;
725
+ /** How many companies to return (server default 100, maximum 1,000). */
726
+ limit?: number;
727
+ signal?: AbortSignal;
728
+ };
684
729
  /** The `telem.monitors` namespace. */
685
730
  type MonitorsResource = {
686
731
  /** Create a monitor. It has the agent unless `agent` is `false`, and with the agent
@@ -736,6 +781,10 @@ type MonitorsResource = {
736
781
  dataMap(monitorId: string, options?: {
737
782
  signal?: AbortSignal;
738
783
  }): Promise<DataMap>;
784
+ /** One page of the companies a monitor created with `inputs` follows, in rank order. A
785
+ * monitor created without `inputs` answers 409 (`not_an_engine_monitor`), and one created
786
+ * with `agent: false` answers 404. */
787
+ companies(monitorId: string, options?: MonitorCompaniesOptions): Promise<CompanyList>;
739
788
  };
740
789
 
741
790
  /**
@@ -778,7 +827,9 @@ declare class TimeoutError extends TelemError {
778
827
 
779
828
  /**
780
829
  * Check a monitor webhook: the `Telem-Signature` header against the raw body.
781
- * True when the signature is correct and not older than `toleranceSeconds`.
830
+ * True when any `v1` signature is correct and not older than `toleranceSeconds`.
831
+ * A header can carry several: during a secret's rotation, one for each secret.
832
+ * A header with no `t`, or more than one, is false.
782
833
  */
783
834
  declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
784
835
 
@@ -883,7 +934,7 @@ declare class Telem {
883
934
  * `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
884
935
  * `iterateChangesAcross`, `feedback`, what a monitor created with
885
936
  * `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
886
- * `revertExpansion`, `dataMap`), and the deprecated `poll`. */
937
+ * `revertExpansion`, `dataMap`, `companies`), and the deprecated `poll`. */
887
938
  readonly monitors: MonitorsResource;
888
939
  /**
889
940
  * @param options - An API key string, or an options object. Anything left unset
@@ -916,4 +967,4 @@ declare class Telem {
916
967
  providers(): Promise<ProviderInfo[]>;
917
968
  }
918
969
 
919
- export { type AgentCompileState, type AgentDocument, type AgentState, type ApplyResult, type ChangeRecord, type ChangeSubject, type ChangesPage, type CompanySheet, type DataMap, type ExpansionConfirmFields, type ExpansionRecord, type ExpansionsPage, type FeedbackResult, type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorChangesAcrossOptions, type MonitorChangesAcrossScope, type MonitorChangesOptions, type MonitorCreateOptions, type MonitorExpansionsOptions, type MonitorFeedbackOptions, type MonitorInputs, type MonitorIterateChangesOptions, type MonitorListOptions, type MonitorPage, type MonitorPollOptions, type MonitorPreset, type MonitorUpdateOptions, type MonitorsChangesPage, type MonitorsResource, type OnboardingCandidate, type OnboardingCompany, type OnboardingExample, type OnboardingMarks, type OnboardingSheet, 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 };
970
+ export { type AgentCompileState, type AgentDocument, type AgentState, type ApplyResult, type ChangeRecord, type ChangeSubject, type ChangesPage, type CompanyList, type CompanyListRow, type CompanySheet, type DataMap, type ExpansionConfirmFields, type ExpansionRecord, type ExpansionsPage, type FeedbackResult, type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorChangesAcrossOptions, type MonitorChangesAcrossScope, type MonitorChangesOptions, type MonitorCompaniesOptions, type MonitorCreateOptions, type MonitorExpansionsOptions, type MonitorFeedbackOptions, type MonitorInputs, type MonitorIterateChangesOptions, type MonitorListOptions, type MonitorPage, type MonitorPollOptions, type MonitorPreset, type MonitorUpdateOptions, type MonitorsChangesPage, type MonitorsResource, type OnboardingCandidate, type OnboardingCompany, type OnboardingExample, type OnboardingMarks, type OnboardingSheet, 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
@@ -63,6 +63,8 @@ type SearchOptions = {
63
63
  includeFullContent?: boolean;
64
64
  autoRouting?: string;
65
65
  maxRoutingProviders?: number;
66
+ /** `"images"`: an image search on brave only; each result adds `imageUrl`, `imageWidth`
67
+ * and `imageHeight`. */
66
68
  topic?: string;
67
69
  vertical?: string;
68
70
  /** Only results published on or after this date or date-time: an ISO 8601 string
@@ -141,6 +143,10 @@ type SearchResult = {
141
143
  source: Json | null;
142
144
  enrichments: Json | null;
143
145
  fetchMeta: Json | null;
146
+ /** Image searches (`topic: "images"`) only: the original image, its width and height. */
147
+ imageUrl: string | null;
148
+ imageWidth: number | null;
149
+ imageHeight: number | null;
144
150
  provider: string;
145
151
  raw: Json;
146
152
  };
@@ -681,6 +687,45 @@ type DataMap = {
681
687
  note: string | null;
682
688
  raw: Json;
683
689
  };
690
+ /** One company of `monitors.companies`. */
691
+ type CompanyListRow = {
692
+ companyId: string;
693
+ name: string;
694
+ domain: string;
695
+ /** Whether the company is marked priority: it is checked on every routine run. */
696
+ priority: boolean;
697
+ aliases: string[];
698
+ ticker: string;
699
+ xHandle: string;
700
+ newsroomUrl: string;
701
+ teamPage: string;
702
+ /** `daily`, `weekly` or `off`, as you gave it; empty when its rank decides. */
703
+ tier: string;
704
+ /** Its place among the monitor's companies, from 1. */
705
+ rank: number;
706
+ raw: Json;
707
+ };
708
+ /** One page of `monitors.companies`, in rank order. */
709
+ type CompanyList = {
710
+ /** All the companies the monitor follows. */
711
+ total: number;
712
+ /** How many of them are marked priority. */
713
+ priorityCount: number;
714
+ offset: number;
715
+ limit: number;
716
+ /** Pass it as `offset` for the next page; `null` on the last page. */
717
+ nextOffset: number | null;
718
+ companies: CompanyListRow[];
719
+ raw: Json;
720
+ };
721
+ /** Options for `monitors.companies`. */
722
+ type MonitorCompaniesOptions = {
723
+ /** How many companies to skip, from the top (server default 0). */
724
+ offset?: number;
725
+ /** How many companies to return (server default 100, maximum 1,000). */
726
+ limit?: number;
727
+ signal?: AbortSignal;
728
+ };
684
729
  /** The `telem.monitors` namespace. */
685
730
  type MonitorsResource = {
686
731
  /** Create a monitor. It has the agent unless `agent` is `false`, and with the agent
@@ -736,6 +781,10 @@ type MonitorsResource = {
736
781
  dataMap(monitorId: string, options?: {
737
782
  signal?: AbortSignal;
738
783
  }): Promise<DataMap>;
784
+ /** One page of the companies a monitor created with `inputs` follows, in rank order. A
785
+ * monitor created without `inputs` answers 409 (`not_an_engine_monitor`), and one created
786
+ * with `agent: false` answers 404. */
787
+ companies(monitorId: string, options?: MonitorCompaniesOptions): Promise<CompanyList>;
739
788
  };
740
789
 
741
790
  /**
@@ -778,7 +827,9 @@ declare class TimeoutError extends TelemError {
778
827
 
779
828
  /**
780
829
  * Check a monitor webhook: the `Telem-Signature` header against the raw body.
781
- * True when the signature is correct and not older than `toleranceSeconds`.
830
+ * True when any `v1` signature is correct and not older than `toleranceSeconds`.
831
+ * A header can carry several: during a secret's rotation, one for each secret.
832
+ * A header with no `t`, or more than one, is false.
782
833
  */
783
834
  declare function verifyWebhook(body: string | Uint8Array, header: string, secret: string, toleranceSeconds?: number): Promise<boolean>;
784
835
 
@@ -883,7 +934,7 @@ declare class Telem {
883
934
  * `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
884
935
  * `iterateChangesAcross`, `feedback`, what a monitor created with
885
936
  * `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
886
- * `revertExpansion`, `dataMap`), and the deprecated `poll`. */
937
+ * `revertExpansion`, `dataMap`, `companies`), and the deprecated `poll`. */
887
938
  readonly monitors: MonitorsResource;
888
939
  /**
889
940
  * @param options - An API key string, or an options object. Anything left unset
@@ -916,4 +967,4 @@ declare class Telem {
916
967
  providers(): Promise<ProviderInfo[]>;
917
968
  }
918
969
 
919
- export { type AgentCompileState, type AgentDocument, type AgentState, type ApplyResult, type ChangeRecord, type ChangeSubject, type ChangesPage, type CompanySheet, type DataMap, type ExpansionConfirmFields, type ExpansionRecord, type ExpansionsPage, type FeedbackResult, type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorChangesAcrossOptions, type MonitorChangesAcrossScope, type MonitorChangesOptions, type MonitorCreateOptions, type MonitorExpansionsOptions, type MonitorFeedbackOptions, type MonitorInputs, type MonitorIterateChangesOptions, type MonitorListOptions, type MonitorPage, type MonitorPollOptions, type MonitorPreset, type MonitorUpdateOptions, type MonitorsChangesPage, type MonitorsResource, type OnboardingCandidate, type OnboardingCompany, type OnboardingExample, type OnboardingMarks, type OnboardingSheet, 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 };
970
+ export { type AgentCompileState, type AgentDocument, type AgentState, type ApplyResult, type ChangeRecord, type ChangeSubject, type ChangesPage, type CompanyList, type CompanyListRow, type CompanySheet, type DataMap, type ExpansionConfirmFields, type ExpansionRecord, type ExpansionsPage, type FeedbackResult, type FetchOptions, type FetchResponse, type FetchResult, type Json, type Monitor, type MonitorChangesAcrossOptions, type MonitorChangesAcrossScope, type MonitorChangesOptions, type MonitorCompaniesOptions, type MonitorCreateOptions, type MonitorExpansionsOptions, type MonitorFeedbackOptions, type MonitorInputs, type MonitorIterateChangesOptions, type MonitorListOptions, type MonitorPage, type MonitorPollOptions, type MonitorPreset, type MonitorUpdateOptions, type MonitorsChangesPage, type MonitorsResource, type OnboardingCandidate, type OnboardingCompany, type OnboardingExample, type OnboardingMarks, type OnboardingSheet, 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-TST6J3VA.js";
23
23
 
24
24
  // src/version.ts
25
- var VERSION = "0.6.0";
25
+ var VERSION = "0.7.0";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -317,6 +317,9 @@ function searchResults(envelope, provider) {
317
317
  source: row.source ?? null,
318
318
  enrichments: row.enrichments ?? null,
319
319
  fetchMeta: row.fetch_meta ?? null,
320
+ imageUrl: row.image_url ?? null,
321
+ imageWidth: row.image_width ?? null,
322
+ imageHeight: row.image_height ?? null,
320
323
  provider,
321
324
  raw: row
322
325
  }));
@@ -560,6 +563,41 @@ function dataMapFrom(body) {
560
563
  raw: data
561
564
  };
562
565
  }
566
+ function companyFrom(entry) {
567
+ return {
568
+ companyId: String(entry.company_id ?? ""),
569
+ name: String(entry.name ?? ""),
570
+ domain: String(entry.domain ?? ""),
571
+ priority: entry.priority === true,
572
+ aliases: asArray(entry.aliases).map(String),
573
+ ticker: String(entry.ticker ?? ""),
574
+ xHandle: String(entry.x_handle ?? ""),
575
+ newsroomUrl: String(entry.newsroom_url ?? ""),
576
+ teamPage: String(entry.team_page ?? ""),
577
+ tier: String(entry.tier ?? ""),
578
+ rank: Number(entry.rank ?? 0),
579
+ raw: entry
580
+ };
581
+ }
582
+ function companyListFrom(body) {
583
+ const data = asObject(body);
584
+ return {
585
+ total: Number(data.total ?? 0),
586
+ priorityCount: Number(data.priority_count ?? 0),
587
+ offset: Number(data.offset ?? 0),
588
+ limit: Number(data.limit ?? 0),
589
+ nextOffset: typeof data.next_offset === "number" ? data.next_offset : null,
590
+ companies: asArray(data.companies).filter(isObject).map(companyFrom),
591
+ raw: data
592
+ };
593
+ }
594
+ function companiesQuery(options) {
595
+ const params = new URLSearchParams();
596
+ if (options.offset !== void 0) params.set("offset", String(options.offset));
597
+ if (options.limit !== void 0) params.set("limit", String(options.limit));
598
+ const query = params.toString();
599
+ return query ? `?${query}` : "";
600
+ }
563
601
  function listQuery(options) {
564
602
  const params = new URLSearchParams();
565
603
  if (options.limit !== void 0) params.set("limit", String(options.limit));
@@ -773,25 +811,36 @@ function createMonitors(config) {
773
811
  async dataMap(monitorId, options = {}) {
774
812
  const route = path(monitorId, "/agent/data-map");
775
813
  return dataMapFrom(await request(config, "GET", route, void 0, options.signal));
814
+ },
815
+ /** One page of the monitor's companies, in rank order. */
816
+ async companies(monitorId, options = {}) {
817
+ const route = `${path(monitorId, "/agent/companies")}${companiesQuery(options)}`;
818
+ return companyListFrom(await request(config, "GET", route, void 0, options.signal));
776
819
  }
777
820
  };
778
821
  }
779
822
  async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
780
- const parts = Object.fromEntries(
781
- header.split(",").map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)])
782
- );
783
- const t = parts.t ?? "";
784
- const v1 = parts.v1 ?? "";
823
+ const parts = header.split(",").map((item) => item.trim()).filter((item) => item.includes("=")).map((item) => [item.slice(0, item.indexOf("=")), item.slice(item.indexOf("=") + 1)]);
824
+ const timestamps = parts.filter(([name]) => name === "t").map(([, value]) => value);
825
+ const signatures = parts.filter(([name, value]) => name === "v1" && /^[0-9a-f]{64}$/.test(value)).map(([, value]) => value);
826
+ if (timestamps.length !== 1 || signatures.length === 0) return false;
827
+ const t = timestamps[0];
785
828
  if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
786
- if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
787
829
  const encoder = new TextEncoder();
788
830
  const raw = typeof body === "string" ? encoder.encode(body) : body;
789
831
  const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
790
832
  const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
791
- "verify"
833
+ "sign"
792
834
  ]);
793
- const signature = new Uint8Array(v1.match(/../g).map((byte) => parseInt(byte, 16)));
794
- return crypto.subtle.verify("HMAC", key, signature, signed);
835
+ const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, signed));
836
+ const expected = Array.from(mac, (byte) => byte.toString(16).padStart(2, "0")).join("");
837
+ return signatures.some((signature) => sameText(signature, expected));
838
+ }
839
+ function sameText(a, b) {
840
+ if (a.length !== b.length) return false;
841
+ let diff = 0;
842
+ for (let i = 0; i < a.length; i++) diff |= a.charCodeAt(i) ^ b.charCodeAt(i);
843
+ return diff === 0;
795
844
  }
796
845
 
797
846
  // src/methods/providers.ts
@@ -879,7 +928,7 @@ var Telem = class {
879
928
  * `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
880
929
  * `iterateChangesAcross`, `feedback`, what a monitor created with
881
930
  * `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
882
- * `revertExpansion`, `dataMap`), and the deprecated `poll`. */
931
+ * `revertExpansion`, `dataMap`, `companies`), and the deprecated `poll`. */
883
932
  monitors;
884
933
  #config;
885
934
  /**
@@ -452,9 +452,15 @@ async function turnAnchor(messages, windowId) {
452
452
  return await contentAnchor(String(messages.length), windowId, text);
453
453
  }
454
454
  function compact(response) {
455
- return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate }) => {
455
+ return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate, imageUrl, imageWidth, imageHeight }) => {
456
456
  const published = publishDate?.trim();
457
- return published ? { provider, title, url, summary, published } : { provider, title, url, summary };
457
+ const row = published ? { provider, title, url, summary, published } : { provider, title, url, summary };
458
+ const image = typeof imageUrl === "string" ? imageUrl.trim() : "";
459
+ if (image) {
460
+ const whole = (n) => Number.isInteger(n) && n > 0;
461
+ row.image = whole(imageWidth) && whole(imageHeight) ? { url: image, width: imageWidth, height: imageHeight } : { url: image };
462
+ }
463
+ return row;
458
464
  });
459
465
  }
460
466
  function page(response) {
@@ -479,7 +485,7 @@ var SEARCH_SCHEMA = (0, import_ai.jsonSchema)({
479
485
  },
480
486
  topic: {
481
487
  type: "string",
482
- description: "Optional. Set it only when the answer must come from one site: linkedin, reddit, or x (twitter is also accepted). Leave it unset otherwise."
488
+ description: "Optional. Set it to linkedin, reddit or x (twitter is also accepted) only when the answer must come from that site, or to images for an image search: at most 20 results, no published_after or published_before, and each result adds the image URL and its size. Leave it unset otherwise."
483
489
  },
484
490
  published_after: {
485
491
  type: "string",
@@ -642,7 +648,7 @@ function createTelemVercelAgent(options) {
642
648
  }
643
649
  const tools = {
644
650
  telem_search: {
645
- description: "Search the public web. One query per call; returns the top results with provider, title, url, summary and, when known, publication date. Use telem_fetch to read a page in full.",
651
+ description: "Search the public web. One query per call; returns the top results with provider, title, url, summary and, when known, publication date (and an image search's image). Use telem_fetch to read a page in full.",
646
652
  inputSchema: SEARCH_SCHEMA,
647
653
  execute: async (input, execution) => {
648
654
  const topic = input.topic?.trim() || void 0;
@@ -150,13 +150,18 @@ type TelemVercelFetchInput = {
150
150
  goal?: string;
151
151
  };
152
152
  /** The default `render.search`: the top results, compact. `published` is there only
153
- * when the result has a publication date. */
153
+ * when the result has a publication date, `image` only on an image search's row. */
154
154
  type TelemVercelSearchOutput = Array<{
155
155
  provider: string;
156
156
  title: string;
157
157
  url: string;
158
158
  summary: string | null;
159
159
  published?: string;
160
+ image?: {
161
+ url: string;
162
+ width?: number;
163
+ height?: number;
164
+ };
160
165
  }>;
161
166
  /** The default `render.fetch`: one page's status, error and text. */
162
167
  type TelemVercelFetchOutput = {
@@ -150,13 +150,18 @@ type TelemVercelFetchInput = {
150
150
  goal?: string;
151
151
  };
152
152
  /** The default `render.search`: the top results, compact. `published` is there only
153
- * when the result has a publication date. */
153
+ * when the result has a publication date, `image` only on an image search's row. */
154
154
  type TelemVercelSearchOutput = Array<{
155
155
  provider: string;
156
156
  title: string;
157
157
  url: string;
158
158
  summary: string | null;
159
159
  published?: string;
160
+ image?: {
161
+ url: string;
162
+ width?: number;
163
+ height?: number;
164
+ };
160
165
  }>;
161
166
  /** The default `render.fetch`: one page's status, error and text. */
162
167
  type TelemVercelFetchOutput = {
@@ -290,9 +290,15 @@ async function turnAnchor(messages, windowId) {
290
290
  return await contentAnchor(String(messages.length), windowId, text);
291
291
  }
292
292
  function compact(response) {
293
- return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate }) => {
293
+ return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate, imageUrl, imageWidth, imageHeight }) => {
294
294
  const published = publishDate?.trim();
295
- return published ? { provider, title, url, summary, published } : { provider, title, url, summary };
295
+ const row = published ? { provider, title, url, summary, published } : { provider, title, url, summary };
296
+ const image = typeof imageUrl === "string" ? imageUrl.trim() : "";
297
+ if (image) {
298
+ const whole = (n) => Number.isInteger(n) && n > 0;
299
+ row.image = whole(imageWidth) && whole(imageHeight) ? { url: image, width: imageWidth, height: imageHeight } : { url: image };
300
+ }
301
+ return row;
296
302
  });
297
303
  }
298
304
  function page(response) {
@@ -317,7 +323,7 @@ var SEARCH_SCHEMA = jsonSchema({
317
323
  },
318
324
  topic: {
319
325
  type: "string",
320
- description: "Optional. Set it only when the answer must come from one site: linkedin, reddit, or x (twitter is also accepted). Leave it unset otherwise."
326
+ description: "Optional. Set it to linkedin, reddit or x (twitter is also accepted) only when the answer must come from that site, or to images for an image search: at most 20 results, no published_after or published_before, and each result adds the image URL and its size. Leave it unset otherwise."
321
327
  },
322
328
  published_after: {
323
329
  type: "string",
@@ -480,7 +486,7 @@ function createTelemVercelAgent(options) {
480
486
  }
481
487
  const tools = {
482
488
  telem_search: {
483
- description: "Search the public web. One query per call; returns the top results with provider, title, url, summary and, when known, publication date. Use telem_fetch to read a page in full.",
489
+ description: "Search the public web. One query per call; returns the top results with provider, title, url, summary and, when known, publication date (and an image search's image). Use telem_fetch to read a page in full.",
484
490
  inputSchema: SEARCH_SCHEMA,
485
491
  execute: async (input, execution) => {
486
492
  const topic = input.topic?.trim() || void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",