@telemai/sdk 0.2.0 → 0.2.2

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
@@ -59,7 +59,7 @@ var TimeoutError = class extends TelemError {
59
59
  };
60
60
 
61
61
  // src/version.ts
62
- var VERSION = "0.2.0";
62
+ var VERSION = "0.2.2";
63
63
 
64
64
  // src/config.ts
65
65
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -74,6 +74,9 @@ function csvEnv(raw) {
74
74
  const items = raw.split(",").map(trimBlank).filter((item) => item !== "");
75
75
  return items.length ? items : void 0;
76
76
  }
77
+ function intEnv(raw) {
78
+ return raw !== void 0 && /^\s*[+-]?\d+\s*$/.test(raw) ? Number(raw) : void 0;
79
+ }
77
80
  function readCredentials(env) {
78
81
  try {
79
82
  const proc = globalThis.process;
@@ -150,7 +153,10 @@ function resolveConfig(options) {
150
153
  fields: opts.fields ?? csvEnv(env.TELEM_FIELDS),
151
154
  providersInclude: opts.providersInclude ?? csvEnv(env.TELEM_PROVIDERS_INCLUDE),
152
155
  providersExclude: opts.providersExclude ?? csvEnv(env.TELEM_PROVIDERS_EXCLUDE),
153
- includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0)
156
+ includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0),
157
+ autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
158
+ maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
159
+ topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
154
160
  }
155
161
  };
156
162
  }
@@ -587,6 +593,12 @@ function searchBlock(defaults, options) {
587
593
  if (options.includeRaw !== void 0) block.include_raw = options.includeRaw;
588
594
  if (options.rerank !== void 0) block.rerank = options.rerank;
589
595
  if (includeFullContent !== void 0) block.include_full_content = includeFullContent;
596
+ const autoRouting = options.autoRouting ?? defaults.autoRouting;
597
+ if (autoRouting !== void 0) block.auto_routing = autoRouting;
598
+ const maxRoutingProviders = options.maxRoutingProviders ?? defaults.maxRoutingProviders;
599
+ if (maxRoutingProviders !== void 0) block.max_routing_providers = maxRoutingProviders;
600
+ const topic = options.topic ?? defaults.topic;
601
+ if (topic !== void 0) block.topic = topic;
590
602
  return block;
591
603
  }
592
604
  function userInput(query) {
package/dist/index.d.cts CHANGED
@@ -61,6 +61,9 @@ type SearchOptions = {
61
61
  numResults?: number;
62
62
  includeRaw?: boolean;
63
63
  includeFullContent?: boolean;
64
+ autoRouting?: string;
65
+ maxRoutingProviders?: number;
66
+ topic?: string;
64
67
  /** Opt this request into the server's rerank stage. It is the only path where
65
68
  * `context`, the reasoning on the last assistant entry of the lineage history
66
69
  * (that entry only), and `goal` change result ORDER (in that precedence) —
@@ -80,7 +83,7 @@ type SearchOptions = {
80
83
  };
81
84
  /** The subset of search options that may also be set as a client default.
82
85
  * `numResults`/`includeRaw`/`rerank`/`providerOverrides` are per-call intent only. */
83
- type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent">;
86
+ type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent" | "autoRouting" | "maxRoutingProviders" | "topic">;
84
87
  type FetchOptions = {
85
88
  providers?: string[];
86
89
  inlineContent?: boolean;
@@ -264,7 +267,7 @@ declare function snapshotNodeKey(harness: string, conversationId: string, messag
264
267
  /** Stable anchor id for content a host did not assign an id to.
265
268
  * Length-prefixed like every other key component, so concatenation stays injective. */
266
269
  declare function contentAnchor(...parts: string[]): Promise<string>;
267
- /** `tool_marker` from telem/integrations/_trajectory_v5.py: one tool call as the
270
+ /** `tool_marker` from the Python SDK's _trajectory_v5.py: one tool call as the
268
271
  * compact acting-trace marker every harness renders into history. The exporter
269
272
  * cuts goals on `[tool telem_search:`, so the text is a contract. Compact JSON,
270
273
  * key order kept, matches Python's `separators=(",", ":")`; an unserializable
package/dist/index.d.ts CHANGED
@@ -61,6 +61,9 @@ type SearchOptions = {
61
61
  numResults?: number;
62
62
  includeRaw?: boolean;
63
63
  includeFullContent?: boolean;
64
+ autoRouting?: string;
65
+ maxRoutingProviders?: number;
66
+ topic?: string;
64
67
  /** Opt this request into the server's rerank stage. It is the only path where
65
68
  * `context`, the reasoning on the last assistant entry of the lineage history
66
69
  * (that entry only), and `goal` change result ORDER (in that precedence) —
@@ -80,7 +83,7 @@ type SearchOptions = {
80
83
  };
81
84
  /** The subset of search options that may also be set as a client default.
82
85
  * `numResults`/`includeRaw`/`rerank`/`providerOverrides` are per-call intent only. */
83
- type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent">;
86
+ type SearchDefaults = Pick<SearchOptions, "tier" | "fields" | "providersInclude" | "providersExclude" | "includeFullContent" | "autoRouting" | "maxRoutingProviders" | "topic">;
84
87
  type FetchOptions = {
85
88
  providers?: string[];
86
89
  inlineContent?: boolean;
@@ -264,7 +267,7 @@ declare function snapshotNodeKey(harness: string, conversationId: string, messag
264
267
  /** Stable anchor id for content a host did not assign an id to.
265
268
  * Length-prefixed like every other key component, so concatenation stays injective. */
266
269
  declare function contentAnchor(...parts: string[]): Promise<string>;
267
- /** `tool_marker` from telem/integrations/_trajectory_v5.py: one tool call as the
270
+ /** `tool_marker` from the Python SDK's _trajectory_v5.py: one tool call as the
268
271
  * compact acting-trace marker every harness renders into history. The exporter
269
272
  * cuts goals on `[tool telem_search:`, so the text is a contract. Compact JSON,
270
273
  * key order kept, matches Python's `separators=(",", ":")`; an unserializable
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  } from "./chunk-RYY4S5LP.js";
23
23
 
24
24
  // src/version.ts
25
- var VERSION = "0.2.0";
25
+ var VERSION = "0.2.2";
26
26
 
27
27
  // src/config.ts
28
28
  var DEFAULT_BASE_URL = "https://router.telem.ai";
@@ -37,6 +37,9 @@ function csvEnv(raw) {
37
37
  const items = raw.split(",").map(trimBlank).filter((item) => item !== "");
38
38
  return items.length ? items : void 0;
39
39
  }
40
+ function intEnv(raw) {
41
+ return raw !== void 0 && /^\s*[+-]?\d+\s*$/.test(raw) ? Number(raw) : void 0;
42
+ }
40
43
  function readCredentials(env) {
41
44
  try {
42
45
  const proc = globalThis.process;
@@ -113,7 +116,10 @@ function resolveConfig(options) {
113
116
  fields: opts.fields ?? csvEnv(env.TELEM_FIELDS),
114
117
  providersInclude: opts.providersInclude ?? csvEnv(env.TELEM_PROVIDERS_INCLUDE),
115
118
  providersExclude: opts.providersExclude ?? csvEnv(env.TELEM_PROVIDERS_EXCLUDE),
116
- includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0)
119
+ includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0),
120
+ autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
121
+ maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
122
+ topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
117
123
  }
118
124
  };
119
125
  }
@@ -222,6 +228,12 @@ function searchBlock(defaults, options) {
222
228
  if (options.includeRaw !== void 0) block.include_raw = options.includeRaw;
223
229
  if (options.rerank !== void 0) block.rerank = options.rerank;
224
230
  if (includeFullContent !== void 0) block.include_full_content = includeFullContent;
231
+ const autoRouting = options.autoRouting ?? defaults.autoRouting;
232
+ if (autoRouting !== void 0) block.auto_routing = autoRouting;
233
+ const maxRoutingProviders = options.maxRoutingProviders ?? defaults.maxRoutingProviders;
234
+ if (maxRoutingProviders !== void 0) block.max_routing_providers = maxRoutingProviders;
235
+ const topic = options.topic ?? defaults.topic;
236
+ if (topic !== void 0) block.topic = topic;
225
237
  return block;
226
238
  }
227
239
  function userInput(query) {
@@ -473,6 +473,10 @@ var SEARCH_SCHEMA = (0, import_ai.jsonSchema)({
473
473
  context: {
474
474
  type: "string",
475
475
  description: "Two or three sentences of your reasoning: what you want to find out and why, given what you already know. Not a restatement of the query."
476
+ },
477
+ topic: {
478
+ type: "string",
479
+ 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."
476
480
  }
477
481
  },
478
482
  required: ["query"],
@@ -563,7 +567,7 @@ function createTelemVercelAgent(options) {
563
567
  const opts = { ...searchOptions ?? {}, signal: signalFor(execution, searchOptions?.signal) };
564
568
  const { envelope, plan } = await lineage(execution, {
565
569
  name: SEARCH_TOOL,
566
- input: { query, goal: opts.goal, context: opts.context }
570
+ input: { query, goal: opts.goal, context: opts.context, topic: opts.topic }
567
571
  });
568
572
  const response = await state.sendWithOmissionRetry(
569
573
  plan,
@@ -622,7 +626,12 @@ function createTelemVercelAgent(options) {
622
626
  telem_search: {
623
627
  description: "Search the public web. One query per call; returns the top results with provider, title, url and summary. Use telem_fetch to read a page in full.",
624
628
  inputSchema: SEARCH_SCHEMA,
625
- execute: async (input, execution) => renderSearch(await search(input.query, { goal: input.goal, context: input.context }, execution))
629
+ execute: async (input, execution) => {
630
+ const topic = input.topic?.trim() || void 0;
631
+ return renderSearch(
632
+ await search(input.query, { goal: input.goal, context: input.context, topic }, execution)
633
+ );
634
+ }
626
635
  },
627
636
  telem_fetch: {
628
637
  description: "Read the text of one web page by URL. telem_search returns snippets; this returns the page.",
@@ -141,6 +141,7 @@ type TelemVercelSearchInput = {
141
141
  query: string;
142
142
  goal?: string;
143
143
  context?: string;
144
+ topic?: string;
144
145
  };
145
146
  type TelemVercelFetchInput = {
146
147
  url: string;
@@ -238,11 +239,7 @@ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & Telem
238
239
  *
239
240
  * @example
240
241
  * ```ts
241
- * const delegate = tool({
242
- * description: "Research one question.",
243
- * inputSchema: z.object({ brief: z.string() }),
244
- * execute: async ({ brief }): Promise<string> => (await generateText({ model, tools, prompt: brief })).text,
245
- * })
242
+ * // `delegate` is a tool of yours whose execute starts another generateText with the same `tools`.
246
243
  * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
244
  * await generateText({ model, tools, prompt })
248
245
  * ```
@@ -141,6 +141,7 @@ type TelemVercelSearchInput = {
141
141
  query: string;
142
142
  goal?: string;
143
143
  context?: string;
144
+ topic?: string;
144
145
  };
145
146
  type TelemVercelFetchInput = {
146
147
  url: string;
@@ -238,11 +239,7 @@ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & Telem
238
239
  *
239
240
  * @example
240
241
  * ```ts
241
- * const delegate = tool({
242
- * description: "Research one question.",
243
- * inputSchema: z.object({ brief: z.string() }),
244
- * execute: async ({ brief }): Promise<string> => (await generateText({ model, tools, prompt: brief })).text,
245
- * })
242
+ * // `delegate` is a tool of yours whose execute starts another generateText with the same `tools`.
246
243
  * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
244
  * await generateText({ model, tools, prompt })
248
245
  * ```
@@ -311,6 +311,10 @@ var SEARCH_SCHEMA = jsonSchema({
311
311
  context: {
312
312
  type: "string",
313
313
  description: "Two or three sentences of your reasoning: what you want to find out and why, given what you already know. Not a restatement of the query."
314
+ },
315
+ topic: {
316
+ type: "string",
317
+ 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."
314
318
  }
315
319
  },
316
320
  required: ["query"],
@@ -401,7 +405,7 @@ function createTelemVercelAgent(options) {
401
405
  const opts = { ...searchOptions ?? {}, signal: signalFor(execution, searchOptions?.signal) };
402
406
  const { envelope, plan } = await lineage(execution, {
403
407
  name: SEARCH_TOOL,
404
- input: { query, goal: opts.goal, context: opts.context }
408
+ input: { query, goal: opts.goal, context: opts.context, topic: opts.topic }
405
409
  });
406
410
  const response = await state.sendWithOmissionRetry(
407
411
  plan,
@@ -460,7 +464,12 @@ function createTelemVercelAgent(options) {
460
464
  telem_search: {
461
465
  description: "Search the public web. One query per call; returns the top results with provider, title, url and summary. Use telem_fetch to read a page in full.",
462
466
  inputSchema: SEARCH_SCHEMA,
463
- execute: async (input, execution) => renderSearch(await search(input.query, { goal: input.goal, context: input.context }, execution))
467
+ execute: async (input, execution) => {
468
+ const topic = input.topic?.trim() || void 0;
469
+ return renderSearch(
470
+ await search(input.query, { goal: input.goal, context: input.context, topic }, execution)
471
+ );
472
+ }
464
473
  },
465
474
  telem_fetch: {
466
475
  description: "Read the text of one web page by URL. telem_search returns snippets; this returns the page.",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",