@telemai/sdk 0.2.0 → 0.2.1

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
@@ -42,7 +42,7 @@ See [Authentication](https://docs.telem.ai/authentication/) for the full rules.
42
42
 
43
43
  ```ts
44
44
 
45
- const telem = new Telem() // environment, then ~/.telem/credentials.json
45
+ const telem = new Telem // environment, then ~/.telem/credentials.json
46
46
  const telem = new Telem("tlm_...") // just a key
47
47
  const telem = new Telem({
48
48
  apiKey: "tlm_...",
@@ -176,7 +176,7 @@ Do not expect a shorter list. The options are on the
176
176
  List the providers the deployment can run:
177
177
 
178
178
  ```ts
179
- for (const provider of await telem.providers()) {
179
+ for (const provider of await telem.providers) {
180
180
  console.log(provider.name, provider.activeByDefault, provider.tiers)
181
181
  }
182
182
  ```
@@ -187,7 +187,7 @@ Every search belongs to a session. The response carries its id as `sessionId`. R
187
187
  your sessions back to see what an agent searched for. Both methods require an API key:
188
188
 
189
189
  ```ts
190
- for (const session of await telem.sessions.list()) {
190
+ for (const session of await telem.sessions.list) {
191
191
  console.log(session.id, session.interactionCount, session.latestInteractionAt)
192
192
  }
193
193
 
@@ -210,7 +210,7 @@ import { generateText } from "ai"
210
210
  import Telem from "@telemai/sdk"
211
211
  import { createTelemVercelTools } from "@telemai/sdk/vercel"
212
212
 
213
- const telem = new Telem()
213
+ const telem = new Telem
214
214
  const tools = createTelemVercelTools({ telem, harness: "my-app" })
215
215
 
216
216
  const result = await generateText({ model, tools, prompt: "Is the Nintendo Museum open over New Year?" })
@@ -222,7 +222,7 @@ then appear in the console under the tool call that started it. `ai` version 5
222
222
  or later is an optional peer dependency, used by this subpath only. The full
223
223
  guide, subagents, your own tools, and the options, is on the
224
224
  [Vercel AI SDK page](https://docs.telem.ai/integrations/vercel-ai/). The runnable example is `examples/vercel-ai-agents.mjs`
225
- in the SDK source, first in the [examples list](https://github.com/TelemAI/TelemSDK/tree/main/js-sdk/examples).
225
+ in the SDK source, first in the [examples list](https://github.com/TelemAI/telem-js-sdk/tree/main/examples).
226
226
 
227
227
  ## Query lineage
228
228
 
@@ -251,8 +251,8 @@ Node SDK, where the completion id is the turn and each tool call has its own id:
251
251
 
252
252
  ```ts
253
253
 
254
- const telem = new Telem()
255
- const openai = new OpenAI()
254
+ const telem = new Telem
255
+ const openai = new OpenAI
256
256
  const messages = [{ role: "user" as const, content: "Is the Nintendo Museum open over New Year?" }]
257
257
  const tools = [
258
258
  {
@@ -269,7 +269,7 @@ const tools = [
269
269
  },
270
270
  ]
271
271
 
272
- const conversationId = crypto.randomUUID() // once, when the conversation starts
272
+ const conversationId = crypto.randomUUID // once, when the conversation starts
273
273
  const windowId = await windowAnchor(messages) // once, from the first message
274
274
 
275
275
  const completion = await openai.chat.completions.create({ model: "gpt-4o", messages, tools })
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.1";
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) {
@@ -755,7 +767,7 @@ var Telem = class {
755
767
  timeoutMs;
756
768
  /** Resolved retry budget (attempts after the first). */
757
769
  maxRetries;
758
- /** The session read surface: `list()` and `results(id)`. */
770
+ /** The session read surface: `list` and `results(id)`. */
759
771
  sessions;
760
772
  #config;
761
773
  /**
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;
@@ -187,7 +190,7 @@ type ProviderInfo = {
187
190
  normalized: boolean;
188
191
  tiers: string[];
189
192
  };
190
- /** One session as `sessions.list()` reports it. */
193
+ /** One session as `sessions.list` reports it. */
191
194
  type SessionSummary = {
192
195
  id: string;
193
196
  createdAt: string | null;
@@ -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
@@ -330,7 +333,7 @@ declare function withTrajectory(options: FetchOptions, envelope: TrajectoryEnvel
330
333
  *
331
334
  * @example
332
335
  * ```ts
333
- * const telem = new Telem() // env / credentials-file resolution
336
+ * const telem = new Telem // env / credentials-file resolution
334
337
  * const telem = new Telem("tlm_...") // bare API-key shorthand
335
338
  * const telem = new Telem({ apiKey, baseUrl, tier: "max" })
336
339
  * ```
@@ -345,7 +348,7 @@ declare class Telem {
345
348
  readonly timeoutMs: number;
346
349
  /** Resolved retry budget (attempts after the first). */
347
350
  readonly maxRetries: number;
348
- /** The session read surface: `list()` and `results(id)`. */
351
+ /** The session read surface: `list` and `results(id)`. */
349
352
  readonly sessions: SessionsResource;
350
353
  /**
351
354
  * @param options - An API key string, or an options object. Anything left unset
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;
@@ -187,7 +190,7 @@ type ProviderInfo = {
187
190
  normalized: boolean;
188
191
  tiers: string[];
189
192
  };
190
- /** One session as `sessions.list()` reports it. */
193
+ /** One session as `sessions.list` reports it. */
191
194
  type SessionSummary = {
192
195
  id: string;
193
196
  createdAt: string | null;
@@ -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
@@ -330,7 +333,7 @@ declare function withTrajectory(options: FetchOptions, envelope: TrajectoryEnvel
330
333
  *
331
334
  * @example
332
335
  * ```ts
333
- * const telem = new Telem() // env / credentials-file resolution
336
+ * const telem = new Telem // env / credentials-file resolution
334
337
  * const telem = new Telem("tlm_...") // bare API-key shorthand
335
338
  * const telem = new Telem({ apiKey, baseUrl, tier: "max" })
336
339
  * ```
@@ -345,7 +348,7 @@ declare class Telem {
345
348
  readonly timeoutMs: number;
346
349
  /** Resolved retry budget (attempts after the first). */
347
350
  readonly maxRetries: number;
348
- /** The session read surface: `list()` and `results(id)`. */
351
+ /** The session read surface: `list` and `results(id)`. */
349
352
  readonly sessions: SessionsResource;
350
353
  /**
351
354
  * @param options - An API key string, or an options object. Anything left unset
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.1";
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) {
@@ -390,7 +402,7 @@ var Telem = class {
390
402
  timeoutMs;
391
403
  /** Resolved retry budget (attempts after the first). */
392
404
  maxRetries;
393
- /** The session read surface: `list()` and `results(id)`. */
405
+ /** The session read surface: `list` and `results(id)`. */
394
406
  sessions;
395
407
  #config;
396
408
  /**
@@ -121,7 +121,7 @@ type TelemVercelAgentOptions = {
121
121
  * several HTTP requests must pass a stable id (the chat id), or every request
122
122
  * becomes its own session. */
123
123
  conversationId?: string;
124
- /** The root-first chain this agent hangs under; `child()` fills it. */
124
+ /** The root-first chain this agent hangs under; `child` fills it. */
125
125
  ancestors?: readonly TrajectorySnapshot[];
126
126
  /** `ancestors` (phase 1, the default), `history` (both phases) or `off`.
127
127
  * Unset reads `TELEM_INCREMENTAL` per call. */
@@ -133,7 +133,7 @@ type TelemVercelAgentOptions = {
133
133
  * without replacing a tool. A throw or a rejection here is swallowed; it
134
134
  * never fails the call. */
135
135
  onResponse?: (event: TelemVercelCallEvent) => void | Promise<void>;
136
- /** Advanced: the ledgers to share. `child()` passes its parent's, so a child
136
+ /** Advanced: the ledgers to share. `child` passes its parent's, so a child
137
137
  * never re-sends what the parent already proved delivered. */
138
138
  incrementalState?: IncrementalState;
139
139
  };
@@ -238,11 +238,7 @@ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & Telem
238
238
  *
239
239
  * @example
240
240
  * ```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
- * })
241
+ * // `delegate` is a tool of yours whose execute starts another generateText with the same `tools`.
246
242
  * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
243
  * await generateText({ model, tools, prompt })
248
244
  * ```
@@ -121,7 +121,7 @@ type TelemVercelAgentOptions = {
121
121
  * several HTTP requests must pass a stable id (the chat id), or every request
122
122
  * becomes its own session. */
123
123
  conversationId?: string;
124
- /** The root-first chain this agent hangs under; `child()` fills it. */
124
+ /** The root-first chain this agent hangs under; `child` fills it. */
125
125
  ancestors?: readonly TrajectorySnapshot[];
126
126
  /** `ancestors` (phase 1, the default), `history` (both phases) or `off`.
127
127
  * Unset reads `TELEM_INCREMENTAL` per call. */
@@ -133,7 +133,7 @@ type TelemVercelAgentOptions = {
133
133
  * without replacing a tool. A throw or a rejection here is swallowed; it
134
134
  * never fails the call. */
135
135
  onResponse?: (event: TelemVercelCallEvent) => void | Promise<void>;
136
- /** Advanced: the ledgers to share. `child()` passes its parent's, so a child
136
+ /** Advanced: the ledgers to share. `child` passes its parent's, so a child
137
137
  * never re-sends what the parent already proved delivered. */
138
138
  incrementalState?: IncrementalState;
139
139
  };
@@ -238,11 +238,7 @@ type TelemVercelTools<T extends Record<string, TelemVercelToolLike>> = T & Telem
238
238
  *
239
239
  * @example
240
240
  * ```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
- * })
241
+ * // `delegate` is a tool of yours whose execute starts another generateText with the same `tools`.
246
242
  * const tools = createTelemVercelTools({ telem, harness: "my-app", tools: { delegate } })
247
243
  * await generateText({ model, tools, prompt })
248
244
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telemai/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Telem web search and fetch for JavaScript and TypeScript.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -42,14 +42,10 @@
42
42
  "node": ">=20.16"
43
43
  },
44
44
  "scripts": {
45
- "pretest": "npm run build",
46
- "test": "node --test 'test/**/*.test.ts'",
47
- "typecheck": "tsc --noEmit",
48
- "gen-version": "node scripts/gen-version.mjs",
49
- "prebuild": "node scripts/gen-version.mjs",
50
45
  "build": "tsup",
46
+ "typecheck": "tsc --noEmit",
51
47
  "prepack": "npm run build",
52
- "smoke:vercel": "node scripts/vercel-live.mjs"
48
+ "test": "node scripts/smoke.mjs"
53
49
  },
54
50
  "devDependencies": {
55
51
  "@types/node": "^22.20.1",
@@ -71,5 +67,13 @@
71
67
  "./dist/vercel/index.d.ts"
72
68
  ]
73
69
  }
70
+ },
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "git+https://github.com/TelemAI/telem-js-sdk.git"
74
+ },
75
+ "homepage": "https://docs.telem.ai/sdks/javascript/",
76
+ "bugs": {
77
+ "url": "https://github.com/TelemAI/telem-js-sdk/issues"
74
78
  }
75
79
  }