@telemai/sdk 0.2.2 → 0.2.4
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 +8 -8
- package/dist/index.cjs +8 -3
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +8 -3
- package/dist/vercel/index.cjs +28 -4
- package/dist/vercel/index.d.cts +7 -3
- package/dist/vercel/index.d.ts +7 -3
- package/dist/vercel/index.js +28 -4
- package/package.json +11 -7
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
|
|
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/
|
|
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
|
|
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.
|
|
62
|
+
var VERSION = "0.2.4";
|
|
63
63
|
|
|
64
64
|
// src/config.ts
|
|
65
65
|
var DEFAULT_BASE_URL = "https://router.telem.ai";
|
|
@@ -594,13 +594,18 @@ function searchBlock(defaults, options) {
|
|
|
594
594
|
if (options.rerank !== void 0) block.rerank = options.rerank;
|
|
595
595
|
if (includeFullContent !== void 0) block.include_full_content = includeFullContent;
|
|
596
596
|
const autoRouting = options.autoRouting ?? defaults.autoRouting;
|
|
597
|
-
if (autoRouting !== void 0) block.auto_routing = autoRouting;
|
|
597
|
+
if (autoRouting !== void 0 && autoRouting.toLowerCase() !== "off") block.auto_routing = autoRouting;
|
|
598
598
|
const maxRoutingProviders = options.maxRoutingProviders ?? defaults.maxRoutingProviders;
|
|
599
599
|
if (maxRoutingProviders !== void 0) block.max_routing_providers = maxRoutingProviders;
|
|
600
600
|
const topic = options.topic ?? defaults.topic;
|
|
601
601
|
if (topic !== void 0) block.topic = topic;
|
|
602
|
+
if (options.publishedAfter !== void 0) block.published_after = isoDate(options.publishedAfter);
|
|
603
|
+
if (options.publishedBefore !== void 0) block.published_before = isoDate(options.publishedBefore);
|
|
602
604
|
return block;
|
|
603
605
|
}
|
|
606
|
+
function isoDate(value) {
|
|
607
|
+
return typeof value === "string" ? value : value.toISOString();
|
|
608
|
+
}
|
|
604
609
|
function userInput(query) {
|
|
605
610
|
if (typeof query === "string") {
|
|
606
611
|
if (query === "") throw invalidRequest("search() requires a non-empty query");
|
|
@@ -767,7 +772,7 @@ var Telem = class {
|
|
|
767
772
|
timeoutMs;
|
|
768
773
|
/** Resolved retry budget (attempts after the first). */
|
|
769
774
|
maxRetries;
|
|
770
|
-
/** The session read surface: `list
|
|
775
|
+
/** The session read surface: `list` and `results(id)`. */
|
|
771
776
|
sessions;
|
|
772
777
|
#config;
|
|
773
778
|
/**
|
package/dist/index.d.cts
CHANGED
|
@@ -64,6 +64,14 @@ type SearchOptions = {
|
|
|
64
64
|
autoRouting?: string;
|
|
65
65
|
maxRoutingProviders?: number;
|
|
66
66
|
topic?: string;
|
|
67
|
+
/** Only results published on or after this date or date-time: an ISO 8601 string
|
|
68
|
+
* (no time zone means UTC) or a `Date`. Results with no known date are kept.
|
|
69
|
+
* Per-call only, like the two below. */
|
|
70
|
+
publishedAfter?: string | Date;
|
|
71
|
+
/** Only results published before this date or date-time. A date with no time
|
|
72
|
+
* includes that whole day. A `Date` is an exact instant; pass a "YYYY-MM-DD"
|
|
73
|
+
* string to include the whole day. */
|
|
74
|
+
publishedBefore?: string | Date;
|
|
67
75
|
/** Opt this request into the server's rerank stage. It is the only path where
|
|
68
76
|
* `context`, the reasoning on the last assistant entry of the lineage history
|
|
69
77
|
* (that entry only), and `goal` change result ORDER (in that precedence) —
|
|
@@ -190,7 +198,7 @@ type ProviderInfo = {
|
|
|
190
198
|
normalized: boolean;
|
|
191
199
|
tiers: string[];
|
|
192
200
|
};
|
|
193
|
-
/** One session as `sessions.list
|
|
201
|
+
/** One session as `sessions.list` reports it. */
|
|
194
202
|
type SessionSummary = {
|
|
195
203
|
id: string;
|
|
196
204
|
createdAt: string | null;
|
|
@@ -333,7 +341,7 @@ declare function withTrajectory(options: FetchOptions, envelope: TrajectoryEnvel
|
|
|
333
341
|
*
|
|
334
342
|
* @example
|
|
335
343
|
* ```ts
|
|
336
|
-
* const telem = new Telem
|
|
344
|
+
* const telem = new Telem // env / credentials-file resolution
|
|
337
345
|
* const telem = new Telem("tlm_...") // bare API-key shorthand
|
|
338
346
|
* const telem = new Telem({ apiKey, baseUrl, tier: "max" })
|
|
339
347
|
* ```
|
|
@@ -348,7 +356,7 @@ declare class Telem {
|
|
|
348
356
|
readonly timeoutMs: number;
|
|
349
357
|
/** Resolved retry budget (attempts after the first). */
|
|
350
358
|
readonly maxRetries: number;
|
|
351
|
-
/** The session read surface: `list
|
|
359
|
+
/** The session read surface: `list` and `results(id)`. */
|
|
352
360
|
readonly sessions: SessionsResource;
|
|
353
361
|
/**
|
|
354
362
|
* @param options - An API key string, or an options object. Anything left unset
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,14 @@ type SearchOptions = {
|
|
|
64
64
|
autoRouting?: string;
|
|
65
65
|
maxRoutingProviders?: number;
|
|
66
66
|
topic?: string;
|
|
67
|
+
/** Only results published on or after this date or date-time: an ISO 8601 string
|
|
68
|
+
* (no time zone means UTC) or a `Date`. Results with no known date are kept.
|
|
69
|
+
* Per-call only, like the two below. */
|
|
70
|
+
publishedAfter?: string | Date;
|
|
71
|
+
/** Only results published before this date or date-time. A date with no time
|
|
72
|
+
* includes that whole day. A `Date` is an exact instant; pass a "YYYY-MM-DD"
|
|
73
|
+
* string to include the whole day. */
|
|
74
|
+
publishedBefore?: string | Date;
|
|
67
75
|
/** Opt this request into the server's rerank stage. It is the only path where
|
|
68
76
|
* `context`, the reasoning on the last assistant entry of the lineage history
|
|
69
77
|
* (that entry only), and `goal` change result ORDER (in that precedence) —
|
|
@@ -190,7 +198,7 @@ type ProviderInfo = {
|
|
|
190
198
|
normalized: boolean;
|
|
191
199
|
tiers: string[];
|
|
192
200
|
};
|
|
193
|
-
/** One session as `sessions.list
|
|
201
|
+
/** One session as `sessions.list` reports it. */
|
|
194
202
|
type SessionSummary = {
|
|
195
203
|
id: string;
|
|
196
204
|
createdAt: string | null;
|
|
@@ -333,7 +341,7 @@ declare function withTrajectory(options: FetchOptions, envelope: TrajectoryEnvel
|
|
|
333
341
|
*
|
|
334
342
|
* @example
|
|
335
343
|
* ```ts
|
|
336
|
-
* const telem = new Telem
|
|
344
|
+
* const telem = new Telem // env / credentials-file resolution
|
|
337
345
|
* const telem = new Telem("tlm_...") // bare API-key shorthand
|
|
338
346
|
* const telem = new Telem({ apiKey, baseUrl, tier: "max" })
|
|
339
347
|
* ```
|
|
@@ -348,7 +356,7 @@ declare class Telem {
|
|
|
348
356
|
readonly timeoutMs: number;
|
|
349
357
|
/** Resolved retry budget (attempts after the first). */
|
|
350
358
|
readonly maxRetries: number;
|
|
351
|
-
/** The session read surface: `list
|
|
359
|
+
/** The session read surface: `list` and `results(id)`. */
|
|
352
360
|
readonly sessions: SessionsResource;
|
|
353
361
|
/**
|
|
354
362
|
* @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.
|
|
25
|
+
var VERSION = "0.2.4";
|
|
26
26
|
|
|
27
27
|
// src/config.ts
|
|
28
28
|
var DEFAULT_BASE_URL = "https://router.telem.ai";
|
|
@@ -229,13 +229,18 @@ function searchBlock(defaults, options) {
|
|
|
229
229
|
if (options.rerank !== void 0) block.rerank = options.rerank;
|
|
230
230
|
if (includeFullContent !== void 0) block.include_full_content = includeFullContent;
|
|
231
231
|
const autoRouting = options.autoRouting ?? defaults.autoRouting;
|
|
232
|
-
if (autoRouting !== void 0) block.auto_routing = autoRouting;
|
|
232
|
+
if (autoRouting !== void 0 && autoRouting.toLowerCase() !== "off") block.auto_routing = autoRouting;
|
|
233
233
|
const maxRoutingProviders = options.maxRoutingProviders ?? defaults.maxRoutingProviders;
|
|
234
234
|
if (maxRoutingProviders !== void 0) block.max_routing_providers = maxRoutingProviders;
|
|
235
235
|
const topic = options.topic ?? defaults.topic;
|
|
236
236
|
if (topic !== void 0) block.topic = topic;
|
|
237
|
+
if (options.publishedAfter !== void 0) block.published_after = isoDate(options.publishedAfter);
|
|
238
|
+
if (options.publishedBefore !== void 0) block.published_before = isoDate(options.publishedBefore);
|
|
237
239
|
return block;
|
|
238
240
|
}
|
|
241
|
+
function isoDate(value) {
|
|
242
|
+
return typeof value === "string" ? value : value.toISOString();
|
|
243
|
+
}
|
|
239
244
|
function userInput(query) {
|
|
240
245
|
if (typeof query === "string") {
|
|
241
246
|
if (query === "") throw invalidRequest("search() requires a non-empty query");
|
|
@@ -402,7 +407,7 @@ var Telem = class {
|
|
|
402
407
|
timeoutMs;
|
|
403
408
|
/** Resolved retry budget (attempts after the first). */
|
|
404
409
|
maxRetries;
|
|
405
|
-
/** The session read surface: `list
|
|
410
|
+
/** The session read surface: `list` and `results(id)`. */
|
|
406
411
|
sessions;
|
|
407
412
|
#config;
|
|
408
413
|
/**
|
package/dist/vercel/index.cjs
CHANGED
|
@@ -452,7 +452,10 @@ 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 }) =>
|
|
455
|
+
return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate }) => {
|
|
456
|
+
const published = publishDate?.trim();
|
|
457
|
+
return published ? { provider, title, url, summary, published } : { provider, title, url, summary };
|
|
458
|
+
});
|
|
456
459
|
}
|
|
457
460
|
function page(response) {
|
|
458
461
|
const first = response.results[0];
|
|
@@ -477,6 +480,14 @@ var SEARCH_SCHEMA = (0, import_ai.jsonSchema)({
|
|
|
477
480
|
topic: {
|
|
478
481
|
type: "string",
|
|
479
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."
|
|
483
|
+
},
|
|
484
|
+
published_after: {
|
|
485
|
+
type: "string",
|
|
486
|
+
description: "Optional. Only return results published on or after this date or date-time, in ISO 8601 (for example 2026-10-01 or 2026-10-01T09:00:00Z). A value with no time zone is read as UTC. Results with no known publication date are kept. Set it only when the task needs sources from a time period; leave it unset otherwise."
|
|
487
|
+
},
|
|
488
|
+
published_before: {
|
|
489
|
+
type: "string",
|
|
490
|
+
description: "Optional. Only return results published before this date or date-time, in ISO 8601. A value with no time zone is read as UTC, and a date with no time includes that whole day. Results with no known publication date are kept. Set it only when the task needs sources from a time period; leave it unset otherwise."
|
|
480
491
|
}
|
|
481
492
|
},
|
|
482
493
|
required: ["query"],
|
|
@@ -567,7 +578,14 @@ function createTelemVercelAgent(options) {
|
|
|
567
578
|
const opts = { ...searchOptions ?? {}, signal: signalFor(execution, searchOptions?.signal) };
|
|
568
579
|
const { envelope, plan } = await lineage(execution, {
|
|
569
580
|
name: SEARCH_TOOL,
|
|
570
|
-
input: {
|
|
581
|
+
input: {
|
|
582
|
+
query,
|
|
583
|
+
goal: opts.goal,
|
|
584
|
+
context: opts.context,
|
|
585
|
+
topic: opts.topic,
|
|
586
|
+
published_after: opts.publishedAfter,
|
|
587
|
+
published_before: opts.publishedBefore
|
|
588
|
+
}
|
|
571
589
|
});
|
|
572
590
|
const response = await state.sendWithOmissionRetry(
|
|
573
591
|
plan,
|
|
@@ -624,12 +642,18 @@ function createTelemVercelAgent(options) {
|
|
|
624
642
|
}
|
|
625
643
|
const tools = {
|
|
626
644
|
telem_search: {
|
|
627
|
-
description: "Search the public web. One query per call; returns the top results with provider, title, url and
|
|
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.",
|
|
628
646
|
inputSchema: SEARCH_SCHEMA,
|
|
629
647
|
execute: async (input, execution) => {
|
|
630
648
|
const topic = input.topic?.trim() || void 0;
|
|
649
|
+
const publishedAfter = input.published_after?.trim() || void 0;
|
|
650
|
+
const publishedBefore = input.published_before?.trim() || void 0;
|
|
631
651
|
return renderSearch(
|
|
632
|
-
await search(
|
|
652
|
+
await search(
|
|
653
|
+
input.query,
|
|
654
|
+
{ goal: input.goal, context: input.context, topic, publishedAfter, publishedBefore },
|
|
655
|
+
execution
|
|
656
|
+
)
|
|
633
657
|
);
|
|
634
658
|
}
|
|
635
659
|
},
|
package/dist/vercel/index.d.cts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
};
|
|
@@ -142,17 +142,21 @@ type TelemVercelSearchInput = {
|
|
|
142
142
|
goal?: string;
|
|
143
143
|
context?: string;
|
|
144
144
|
topic?: string;
|
|
145
|
+
published_after?: string;
|
|
146
|
+
published_before?: string;
|
|
145
147
|
};
|
|
146
148
|
type TelemVercelFetchInput = {
|
|
147
149
|
url: string;
|
|
148
150
|
goal?: string;
|
|
149
151
|
};
|
|
150
|
-
/** The default `render.search`: the top results, compact.
|
|
152
|
+
/** The default `render.search`: the top results, compact. `published` is there only
|
|
153
|
+
* when the result has a publication date. */
|
|
151
154
|
type TelemVercelSearchOutput = Array<{
|
|
152
155
|
provider: string;
|
|
153
156
|
title: string;
|
|
154
157
|
url: string;
|
|
155
158
|
summary: string | null;
|
|
159
|
+
published?: string;
|
|
156
160
|
}>;
|
|
157
161
|
/** The default `render.fetch`: one page's status, error and text. */
|
|
158
162
|
type TelemVercelFetchOutput = {
|
package/dist/vercel/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
};
|
|
@@ -142,17 +142,21 @@ type TelemVercelSearchInput = {
|
|
|
142
142
|
goal?: string;
|
|
143
143
|
context?: string;
|
|
144
144
|
topic?: string;
|
|
145
|
+
published_after?: string;
|
|
146
|
+
published_before?: string;
|
|
145
147
|
};
|
|
146
148
|
type TelemVercelFetchInput = {
|
|
147
149
|
url: string;
|
|
148
150
|
goal?: string;
|
|
149
151
|
};
|
|
150
|
-
/** The default `render.search`: the top results, compact.
|
|
152
|
+
/** The default `render.search`: the top results, compact. `published` is there only
|
|
153
|
+
* when the result has a publication date. */
|
|
151
154
|
type TelemVercelSearchOutput = Array<{
|
|
152
155
|
provider: string;
|
|
153
156
|
title: string;
|
|
154
157
|
url: string;
|
|
155
158
|
summary: string | null;
|
|
159
|
+
published?: string;
|
|
156
160
|
}>;
|
|
157
161
|
/** The default `render.fetch`: one page's status, error and text. */
|
|
158
162
|
type TelemVercelFetchOutput = {
|
package/dist/vercel/index.js
CHANGED
|
@@ -290,7 +290,10 @@ 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 }) =>
|
|
293
|
+
return response.results.slice(0, RESULT_CAP).map(({ provider, title, url, summary, publishDate }) => {
|
|
294
|
+
const published = publishDate?.trim();
|
|
295
|
+
return published ? { provider, title, url, summary, published } : { provider, title, url, summary };
|
|
296
|
+
});
|
|
294
297
|
}
|
|
295
298
|
function page(response) {
|
|
296
299
|
const first = response.results[0];
|
|
@@ -315,6 +318,14 @@ var SEARCH_SCHEMA = jsonSchema({
|
|
|
315
318
|
topic: {
|
|
316
319
|
type: "string",
|
|
317
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."
|
|
321
|
+
},
|
|
322
|
+
published_after: {
|
|
323
|
+
type: "string",
|
|
324
|
+
description: "Optional. Only return results published on or after this date or date-time, in ISO 8601 (for example 2026-10-01 or 2026-10-01T09:00:00Z). A value with no time zone is read as UTC. Results with no known publication date are kept. Set it only when the task needs sources from a time period; leave it unset otherwise."
|
|
325
|
+
},
|
|
326
|
+
published_before: {
|
|
327
|
+
type: "string",
|
|
328
|
+
description: "Optional. Only return results published before this date or date-time, in ISO 8601. A value with no time zone is read as UTC, and a date with no time includes that whole day. Results with no known publication date are kept. Set it only when the task needs sources from a time period; leave it unset otherwise."
|
|
318
329
|
}
|
|
319
330
|
},
|
|
320
331
|
required: ["query"],
|
|
@@ -405,7 +416,14 @@ function createTelemVercelAgent(options) {
|
|
|
405
416
|
const opts = { ...searchOptions ?? {}, signal: signalFor(execution, searchOptions?.signal) };
|
|
406
417
|
const { envelope, plan } = await lineage(execution, {
|
|
407
418
|
name: SEARCH_TOOL,
|
|
408
|
-
input: {
|
|
419
|
+
input: {
|
|
420
|
+
query,
|
|
421
|
+
goal: opts.goal,
|
|
422
|
+
context: opts.context,
|
|
423
|
+
topic: opts.topic,
|
|
424
|
+
published_after: opts.publishedAfter,
|
|
425
|
+
published_before: opts.publishedBefore
|
|
426
|
+
}
|
|
409
427
|
});
|
|
410
428
|
const response = await state.sendWithOmissionRetry(
|
|
411
429
|
plan,
|
|
@@ -462,12 +480,18 @@ function createTelemVercelAgent(options) {
|
|
|
462
480
|
}
|
|
463
481
|
const tools = {
|
|
464
482
|
telem_search: {
|
|
465
|
-
description: "Search the public web. One query per call; returns the top results with provider, title, url and
|
|
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.",
|
|
466
484
|
inputSchema: SEARCH_SCHEMA,
|
|
467
485
|
execute: async (input, execution) => {
|
|
468
486
|
const topic = input.topic?.trim() || void 0;
|
|
487
|
+
const publishedAfter = input.published_after?.trim() || void 0;
|
|
488
|
+
const publishedBefore = input.published_before?.trim() || void 0;
|
|
469
489
|
return renderSearch(
|
|
470
|
-
await search(
|
|
490
|
+
await search(
|
|
491
|
+
input.query,
|
|
492
|
+
{ goal: input.goal, context: input.context, topic, publishedAfter, publishedBefore },
|
|
493
|
+
execution
|
|
494
|
+
)
|
|
471
495
|
);
|
|
472
496
|
}
|
|
473
497
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telemai/sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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
|
-
"
|
|
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
|
}
|