@telemai/sdk 0.3.2 → 0.3.3

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
@@ -167,6 +167,13 @@ const page = await telem.fetch("https://example.com/article", {
167
167
  const { status, content } = page.results[0]
168
168
  ```
169
169
 
170
+ `providers` pins the fetch providers, in order; `tier` picks the fetch tier; and
171
+ `noCache: true` reads the page live instead of from the shared cache. If you leave
172
+ one out, the client uses its environment variable: `TELEM_FETCH_PROVIDERS` (comma
173
+ separated), `TELEM_FETCH_TIER` (lowercased) or `TELEM_FETCH_NO_CACHE` (`1` turns it
174
+ on). The client reads them when you create it. An option you pass wins, so
175
+ `noCache: false` turns off `TELEM_FETCH_NO_CACHE=1` for that call.
176
+
170
177
  A URL that failed still returns a result. Check `result.status` and `result.error`.
171
178
  Do not expect a shorter list. The options are on the
172
179
  [fetch parameters](https://docs.telem.ai/resources/fetch-parameters/) page.
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.3.2";
63
+ var VERSION = "0.3.3";
64
64
 
65
65
  // src/config.ts
66
66
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -158,6 +158,14 @@ function resolveConfig(options) {
158
158
  autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
159
159
  maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
160
160
  topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
161
+ },
162
+ // Fetch defaults: env var only, parsed as the shared option table parses it (CSV,
163
+ // a trimmed name, a "1"-only flag); the tier is lowercased, as the agent plugins
164
+ // send it. No constructor option, and no config file, as above.
165
+ fetchDefaults: {
166
+ providers: csvEnv(env.TELEM_FETCH_PROVIDERS),
167
+ tier: trimBlank(env.TELEM_FETCH_TIER ?? "").toLowerCase() || void 0,
168
+ noCache: env.TELEM_FETCH_NO_CACHE === "1" || void 0
161
169
  }
162
170
  };
163
171
  }
@@ -492,7 +500,7 @@ function wireMetadata(options, kind) {
492
500
  }
493
501
 
494
502
  // src/methods/fetch.ts
495
- function fetchBody(url, options) {
503
+ function fetchBody(url, options, defaults) {
496
504
  const urls = stringList(
497
505
  typeof url === "string" ? [url] : url,
498
506
  "fetch() requires at least one URL",
@@ -500,11 +508,16 @@ function fetchBody(url, options) {
500
508
  );
501
509
  const { metadata, sessionId } = wireMetadata(options, "fetch");
502
510
  const body = { urls, metadata };
511
+ const providers2 = options.providers ?? defaults.providers;
512
+ const tier = options.tier ?? defaults.tier;
513
+ const noCache = options.noCache ?? defaults.noCache;
503
514
  const block = {};
504
- if (options.providers !== void 0) block.providers = options.providers;
515
+ if (providers2 !== void 0) block.providers = providers2;
505
516
  if (options.inlineContent !== void 0) block.inline_content = options.inlineContent;
506
517
  if (options.inlineMaxChars !== void 0) block.inline_max_chars = options.inlineMaxChars;
507
518
  if (options.contentFormat !== void 0) block.content_format = options.contentFormat;
519
+ if (tier !== void 0) block.tier = tier;
520
+ if (noCache !== void 0) block.no_cache = noCache;
508
521
  if (Object.keys(block).length) body.options = block;
509
522
  if (sessionId !== void 0) body.session_id = sessionId;
510
523
  return body;
@@ -545,12 +558,17 @@ function buildFetchResponse(interaction) {
545
558
  };
546
559
  }
547
560
  async function fetchUrls(config, url, options) {
548
- const body = fetchBody(url, options);
561
+ const body = fetchBody(url, options, config.fetchDefaults);
549
562
  return buildFetchResponse(await request(config, "POST", "/v1/fetch", body, options.signal));
550
563
  }
551
564
 
552
565
  // src/methods/search.ts
553
566
  var MIN_SCHEMA_VERSION = 2;
567
+ function providersRefusal(include, includeFromCall, excludeFromCall) {
568
+ const where = (half, env, fromCall) => fromCall ? `the ${half} search() option` : `the client's ${half} or ${env}`;
569
+ const names = include.join(", ");
570
+ return `providersExclude removes every provider in providersInclude (${names}), so no provider is left and no search was sent. Remove ${names} from providersInclude (set by ${where("providersInclude", "TELEM_PROVIDERS_INCLUDE", includeFromCall)}) or from providersExclude (set by ${where("providersExclude", "TELEM_PROVIDERS_EXCLUDE", excludeFromCall)}).`;
571
+ }
554
572
  function searchBlock(defaults, options) {
555
573
  const fromCallTier = options.tier !== void 0;
556
574
  const fromCallFields = options.fields !== void 0;
@@ -564,7 +582,13 @@ function searchBlock(defaults, options) {
564
582
  let exclude = options.providersExclude ?? defaults.providersExclude;
565
583
  if (include !== void 0 && exclude !== void 0) {
566
584
  const excluded = new Set(exclude);
567
- include = include.filter((name) => !excluded.has(name));
585
+ const kept = include.filter((name) => !excluded.has(name));
586
+ if (include.length && !kept.length) {
587
+ throw invalidRequest(
588
+ providersRefusal(include, options.providersInclude !== void 0, options.providersExclude !== void 0)
589
+ );
590
+ }
591
+ include = kept;
568
592
  exclude = void 0;
569
593
  }
570
594
  const includeFullContent = options.includeFullContent ?? defaults.includeFullContent;
@@ -798,7 +822,8 @@ async function providers(config) {
798
822
  method: entry.method ?? null,
799
823
  url: entry.url ?? null,
800
824
  normalized: entry.normalized ?? false,
801
- tiers: asArray(entry.tiers)
825
+ tiers: asArray(entry.tiers),
826
+ autoRouted: entry.auto_routed ?? null
802
827
  }));
803
828
  }
804
829
 
package/dist/index.d.cts CHANGED
@@ -96,10 +96,17 @@ type SearchOptions = {
96
96
  * `numResults`/`includeRaw`/`rerank`/`providerOverrides` are per-call intent only. */
97
97
  type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent" | "autoRouting" | "maxRoutingProviders" | "topic">;
98
98
  type FetchOptions = {
99
+ /** Fetch provider chain, in order. Defaults to `TELEM_FETCH_PROVIDERS`. */
99
100
  providers?: string[];
100
101
  inlineContent?: boolean;
101
102
  inlineMaxChars?: number;
102
103
  contentFormat?: string;
104
+ /** Fetch tier: `minimalist`, `default`, `extended` or `max`. Sent as given; the
105
+ * server rejects an unknown one. Defaults to `TELEM_FETCH_TIER`, lowercased. */
106
+ tier?: string;
107
+ /** `true` reads every page live and skips the shared fetch cache. Defaults to
108
+ * `TELEM_FETCH_NO_CACHE` (on with exactly `"1"`); `false` overrides it. */
109
+ noCache?: boolean;
103
110
  session?: string;
104
111
  /** Abort this call: the request stops, no retry follows, and the call rejects
105
112
  * with the signal's reason. Merged with the per-attempt timeout. */
@@ -200,6 +207,8 @@ type ProviderInfo = {
200
207
  url: string | null;
201
208
  normalized: boolean;
202
209
  tiers: string[];
210
+ /** Whether auto-routing can pick it for a ranked topic; `null` from a router that does not say. */
211
+ autoRouted: boolean | null;
203
212
  };
204
213
  /** One session as `sessions.list` reports it. */
205
214
  type SessionSummary = {
package/dist/index.d.ts CHANGED
@@ -96,10 +96,17 @@ type SearchOptions = {
96
96
  * `numResults`/`includeRaw`/`rerank`/`providerOverrides` are per-call intent only. */
97
97
  type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent" | "autoRouting" | "maxRoutingProviders" | "topic">;
98
98
  type FetchOptions = {
99
+ /** Fetch provider chain, in order. Defaults to `TELEM_FETCH_PROVIDERS`. */
99
100
  providers?: string[];
100
101
  inlineContent?: boolean;
101
102
  inlineMaxChars?: number;
102
103
  contentFormat?: string;
104
+ /** Fetch tier: `minimalist`, `default`, `extended` or `max`. Sent as given; the
105
+ * server rejects an unknown one. Defaults to `TELEM_FETCH_TIER`, lowercased. */
106
+ tier?: string;
107
+ /** `true` reads every page live and skips the shared fetch cache. Defaults to
108
+ * `TELEM_FETCH_NO_CACHE` (on with exactly `"1"`); `false` overrides it. */
109
+ noCache?: boolean;
103
110
  session?: string;
104
111
  /** Abort this call: the request stops, no retry follows, and the call rejects
105
112
  * with the signal's reason. Merged with the per-attempt timeout. */
@@ -200,6 +207,8 @@ type ProviderInfo = {
200
207
  url: string | null;
201
208
  normalized: boolean;
202
209
  tiers: string[];
210
+ /** Whether auto-routing can pick it for a ranked topic; `null` from a router that does not say. */
211
+ autoRouted: boolean | null;
203
212
  };
204
213
  /** One session as `sessions.list` reports it. */
205
214
  type SessionSummary = {
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.3.2";
25
+ var VERSION = "0.3.3";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -120,12 +120,20 @@ function resolveConfig(options) {
120
120
  autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
121
121
  maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
122
122
  topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
123
+ },
124
+ // Fetch defaults: env var only, parsed as the shared option table parses it (CSV,
125
+ // a trimmed name, a "1"-only flag); the tier is lowercased, as the agent plugins
126
+ // send it. No constructor option, and no config file, as above.
127
+ fetchDefaults: {
128
+ providers: csvEnv(env.TELEM_FETCH_PROVIDERS),
129
+ tier: trimBlank(env.TELEM_FETCH_TIER ?? "").toLowerCase() || void 0,
130
+ noCache: env.TELEM_FETCH_NO_CACHE === "1" || void 0
123
131
  }
124
132
  };
125
133
  }
126
134
 
127
135
  // src/methods/fetch.ts
128
- function fetchBody(url, options) {
136
+ function fetchBody(url, options, defaults) {
129
137
  const urls = stringList(
130
138
  typeof url === "string" ? [url] : url,
131
139
  "fetch() requires at least one URL",
@@ -133,11 +141,16 @@ function fetchBody(url, options) {
133
141
  );
134
142
  const { metadata, sessionId } = wireMetadata(options, "fetch");
135
143
  const body = { urls, metadata };
144
+ const providers2 = options.providers ?? defaults.providers;
145
+ const tier = options.tier ?? defaults.tier;
146
+ const noCache = options.noCache ?? defaults.noCache;
136
147
  const block = {};
137
- if (options.providers !== void 0) block.providers = options.providers;
148
+ if (providers2 !== void 0) block.providers = providers2;
138
149
  if (options.inlineContent !== void 0) block.inline_content = options.inlineContent;
139
150
  if (options.inlineMaxChars !== void 0) block.inline_max_chars = options.inlineMaxChars;
140
151
  if (options.contentFormat !== void 0) block.content_format = options.contentFormat;
152
+ if (tier !== void 0) block.tier = tier;
153
+ if (noCache !== void 0) block.no_cache = noCache;
141
154
  if (Object.keys(block).length) body.options = block;
142
155
  if (sessionId !== void 0) body.session_id = sessionId;
143
156
  return body;
@@ -178,12 +191,17 @@ function buildFetchResponse(interaction) {
178
191
  };
179
192
  }
180
193
  async function fetchUrls(config, url, options) {
181
- const body = fetchBody(url, options);
194
+ const body = fetchBody(url, options, config.fetchDefaults);
182
195
  return buildFetchResponse(await request(config, "POST", "/v1/fetch", body, options.signal));
183
196
  }
184
197
 
185
198
  // src/methods/search.ts
186
199
  var MIN_SCHEMA_VERSION = 2;
200
+ function providersRefusal(include, includeFromCall, excludeFromCall) {
201
+ const where = (half, env, fromCall) => fromCall ? `the ${half} search() option` : `the client's ${half} or ${env}`;
202
+ const names = include.join(", ");
203
+ return `providersExclude removes every provider in providersInclude (${names}), so no provider is left and no search was sent. Remove ${names} from providersInclude (set by ${where("providersInclude", "TELEM_PROVIDERS_INCLUDE", includeFromCall)}) or from providersExclude (set by ${where("providersExclude", "TELEM_PROVIDERS_EXCLUDE", excludeFromCall)}).`;
204
+ }
187
205
  function searchBlock(defaults, options) {
188
206
  const fromCallTier = options.tier !== void 0;
189
207
  const fromCallFields = options.fields !== void 0;
@@ -197,7 +215,13 @@ function searchBlock(defaults, options) {
197
215
  let exclude = options.providersExclude ?? defaults.providersExclude;
198
216
  if (include !== void 0 && exclude !== void 0) {
199
217
  const excluded = new Set(exclude);
200
- include = include.filter((name) => !excluded.has(name));
218
+ const kept = include.filter((name) => !excluded.has(name));
219
+ if (include.length && !kept.length) {
220
+ throw invalidRequest(
221
+ providersRefusal(include, options.providersInclude !== void 0, options.providersExclude !== void 0)
222
+ );
223
+ }
224
+ include = kept;
201
225
  exclude = void 0;
202
226
  }
203
227
  const includeFullContent = options.includeFullContent ?? defaults.includeFullContent;
@@ -431,7 +455,8 @@ async function providers(config) {
431
455
  method: entry.method ?? null,
432
456
  url: entry.url ?? null,
433
457
  normalized: entry.normalized ?? false,
434
- tiers: asArray(entry.tiers)
458
+ tiers: asArray(entry.tiers),
459
+ autoRouted: entry.auto_routed ?? null
435
460
  }));
436
461
  }
437
462
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",