@telemai/sdk 0.5.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/README.md +6 -0
- package/dist/{chunk-SQ3ZZA72.js → chunk-TST6J3VA.js} +32 -8
- package/dist/index.cjs +315 -22
- package/dist/index.d.cts +335 -7
- package/dist/index.d.ts +335 -7
- package/dist/index.js +284 -15
- package/dist/vercel/index.cjs +10 -4
- package/dist/vercel/index.d.cts +6 -1
- package/dist/vercel/index.d.ts +6 -1
- package/dist/vercel/index.js +11 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,15 +19,17 @@ import {
|
|
|
19
19
|
windowAnchor,
|
|
20
20
|
wireMetadata,
|
|
21
21
|
withTrajectory
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-TST6J3VA.js";
|
|
23
23
|
|
|
24
24
|
// src/version.ts
|
|
25
|
-
var VERSION = "0.
|
|
25
|
+
var VERSION = "0.7.0";
|
|
26
26
|
|
|
27
27
|
// src/config.ts
|
|
28
28
|
var DEFAULT_BASE_URL = "https://router.telem.ai";
|
|
29
29
|
var DEFAULT_TIMEOUT_MS = 6e4;
|
|
30
30
|
var DEFAULT_MAX_RETRIES = 2;
|
|
31
|
+
var CREATE_RETRY_BUDGET_MS = 12e4;
|
|
32
|
+
var DEFAULT_CREATE_MAX_RETRIES = 60;
|
|
31
33
|
var BLANK = /^[ \t\n\r\v\f\u00a0\ufeff\u3000]+|[ \t\n\r\v\f\u00a0\ufeff\u3000]+$/g;
|
|
32
34
|
function trimBlank(value) {
|
|
33
35
|
return value.replace(BLANK, "");
|
|
@@ -90,6 +92,12 @@ function resolveConfig(options) {
|
|
|
90
92
|
apiKey = apiKey ?? credentials.apiKey;
|
|
91
93
|
baseUrl = baseUrl ?? credentials.baseUrl;
|
|
92
94
|
}
|
|
95
|
+
if (opts.defaultVertical !== void 0 && opts.vertical !== void 0 && opts.defaultVertical !== opts.vertical) {
|
|
96
|
+
throw invalidOption(
|
|
97
|
+
`vertical ${JSON.stringify(opts.vertical)} and defaultVertical ${JSON.stringify(opts.defaultVertical)} are the same option; pass one of them`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const vertical = opts.defaultVertical ?? opts.vertical ?? (trimBlank(env.TELEM_VERTICAL ?? "") || void 0);
|
|
93
101
|
const resolvedBaseUrl = (baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
94
102
|
let scheme;
|
|
95
103
|
try {
|
|
@@ -105,6 +113,7 @@ function resolveConfig(options) {
|
|
|
105
113
|
baseUrl: resolvedBaseUrl,
|
|
106
114
|
timeoutMs,
|
|
107
115
|
maxRetries,
|
|
116
|
+
createMaxRetries: opts.maxRetries ?? DEFAULT_CREATE_MAX_RETRIES,
|
|
108
117
|
userAgent: opts.userAgent || `telem-sdk-js/${VERSION}`,
|
|
109
118
|
fetch: send,
|
|
110
119
|
sleep: opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))),
|
|
@@ -120,7 +129,8 @@ function resolveConfig(options) {
|
|
|
120
129
|
includeFullContent: opts.includeFullContent ?? (env.TELEM_FULL_CONTENT === "1" || void 0),
|
|
121
130
|
autoRouting: opts.autoRouting ?? (trimBlank(env.TELEM_AUTO_ROUTING ?? "") || void 0),
|
|
122
131
|
maxRoutingProviders: opts.maxRoutingProviders ?? intEnv(env.TELEM_MAX_ROUTING_PROVIDERS),
|
|
123
|
-
topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0)
|
|
132
|
+
topic: opts.topic ?? (trimBlank(env.TELEM_TOPIC ?? "") || void 0),
|
|
133
|
+
vertical
|
|
124
134
|
},
|
|
125
135
|
// Fetch defaults: env var only, parsed as the shared option table parses it (CSV,
|
|
126
136
|
// a trimmed name, a "1"-only flag); the tier is lowercased, as the agent plugins
|
|
@@ -247,6 +257,8 @@ function searchBlock(defaults, options) {
|
|
|
247
257
|
if (options.publishedAfter !== void 0) block.published_after = isoDate(options.publishedAfter);
|
|
248
258
|
if (options.publishedBefore !== void 0) block.published_before = isoDate(options.publishedBefore);
|
|
249
259
|
if (options.includeDomains !== void 0) block.include_domains = options.includeDomains;
|
|
260
|
+
const vertical = options.vertical ?? defaults.vertical;
|
|
261
|
+
if (vertical !== void 0) block.vertical = vertical;
|
|
250
262
|
return block;
|
|
251
263
|
}
|
|
252
264
|
function isoDate(value) {
|
|
@@ -305,6 +317,9 @@ function searchResults(envelope, provider) {
|
|
|
305
317
|
source: row.source ?? null,
|
|
306
318
|
enrichments: row.enrichments ?? null,
|
|
307
319
|
fetchMeta: row.fetch_meta ?? null,
|
|
320
|
+
imageUrl: row.image_url ?? null,
|
|
321
|
+
imageWidth: row.image_width ?? null,
|
|
322
|
+
imageHeight: row.image_height ?? null,
|
|
308
323
|
provider,
|
|
309
324
|
raw: row
|
|
310
325
|
}));
|
|
@@ -358,6 +373,8 @@ async function search(config, query, options) {
|
|
|
358
373
|
|
|
359
374
|
// src/methods/monitors.ts
|
|
360
375
|
var NEEDS_TTL = 'A monitor with an agent must end: pass ttl, such as ttl: "30d" (at most 30 days), or agent: false for a monitor without an agent.';
|
|
376
|
+
var NEEDS_TTL_INPUTS = 'A monitor with inputs must end: pass ttl, such as ttl: "30d" (at most 365 days).';
|
|
377
|
+
var IDEMPOTENCY_KEY = /^[\x21-\x7e]{1,255}$/;
|
|
361
378
|
var POLL_DEPRECATED = "@telemai/sdk: monitors.poll() is deprecated: read what the monitor agent finds with monitors.iterateChanges() or monitors.changes().";
|
|
362
379
|
var pollWarned = false;
|
|
363
380
|
function warnPollDeprecated() {
|
|
@@ -395,6 +412,7 @@ function monitorFrom(body) {
|
|
|
395
412
|
webhookUrl: data.webhook_url ?? null,
|
|
396
413
|
webhookSecret: data.webhook_secret ?? null,
|
|
397
414
|
agentNote: typeof data.agent_note === "string" ? data.agent_note : null,
|
|
415
|
+
tags: asArray(data.tags).map(String),
|
|
398
416
|
raw: data
|
|
399
417
|
};
|
|
400
418
|
if (data.agent_state !== void 0) {
|
|
@@ -440,10 +458,151 @@ function changesPageFrom(body) {
|
|
|
440
458
|
watermark: Number(data.watermark ?? 0)
|
|
441
459
|
};
|
|
442
460
|
}
|
|
461
|
+
function monitorsChangesPageFrom(body) {
|
|
462
|
+
const data = asObject(body);
|
|
463
|
+
return {
|
|
464
|
+
changes: asArray(data.changes).filter(isObject).map(changeRecordFrom),
|
|
465
|
+
nextCursor: typeof data.next_cursor === "string" ? data.next_cursor : "",
|
|
466
|
+
more: data.more === true,
|
|
467
|
+
monitors: asArray(data.monitors).map(String),
|
|
468
|
+
pending: asArray(data.pending).map(String),
|
|
469
|
+
skipped: asArray(data.skipped).map(String)
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
var stringOrNull = (value) => typeof value === "string" ? value : null;
|
|
473
|
+
var countOf = (value) => Array.isArray(value) ? value.length : typeof value === "number" ? value : 0;
|
|
474
|
+
function setFields(fields) {
|
|
475
|
+
return Object.fromEntries(Object.entries(fields).filter(([key, value]) => key !== "signal" && value != null));
|
|
476
|
+
}
|
|
477
|
+
function exampleFrom(data) {
|
|
478
|
+
if (!isObject(data)) return null;
|
|
479
|
+
return { name: stringOrNull(data.name), quote: stringOrNull(data.quote), url: stringOrNull(data.url) };
|
|
480
|
+
}
|
|
481
|
+
function candidateFrom(entry) {
|
|
482
|
+
return {
|
|
483
|
+
id: String(entry.id ?? ""),
|
|
484
|
+
what: stringOrNull(entry.what),
|
|
485
|
+
label: String(entry.label ?? ""),
|
|
486
|
+
mappedTo: stringOrNull(entry.mapped_to),
|
|
487
|
+
isNew: entry.is_new === true,
|
|
488
|
+
count: countOf(entry.count),
|
|
489
|
+
origins: countOf(entry.origins),
|
|
490
|
+
example: exampleFrom(entry.example),
|
|
491
|
+
raw: entry
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
function companySheetFrom(data) {
|
|
495
|
+
return {
|
|
496
|
+
companyId: stringOrNull(data.company_id),
|
|
497
|
+
pages: countOf(data.pages),
|
|
498
|
+
candidates: asArray(data.candidates).filter(isObject).map(candidateFrom),
|
|
499
|
+
note: stringOrNull(data.note),
|
|
500
|
+
raw: data
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function onboardingCompanyFrom(entry) {
|
|
504
|
+
return {
|
|
505
|
+
companyId: String(entry.company_id ?? ""),
|
|
506
|
+
status: String(entry.status ?? ""),
|
|
507
|
+
runId: stringOrNull(entry.run_id),
|
|
508
|
+
sheet: isObject(entry.sheet) ? companySheetFrom(entry.sheet) : null,
|
|
509
|
+
marks: isObject(entry.marks) ? entry.marks : null,
|
|
510
|
+
at: stringOrNull(entry.at),
|
|
511
|
+
appliedAt: stringOrNull(entry.applied_at),
|
|
512
|
+
raw: entry
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function onboardingSheetFrom(body) {
|
|
516
|
+
const data = asObject(body);
|
|
517
|
+
return {
|
|
518
|
+
monitorId: stringOrNull(data.monitor_id),
|
|
519
|
+
companies: asArray(data.companies).filter(isObject).map(onboardingCompanyFrom),
|
|
520
|
+
raw: data
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function applyResultFrom(body) {
|
|
524
|
+
const data = asObject(body);
|
|
525
|
+
return { jobId: String(data.job_id ?? ""), raw: data };
|
|
526
|
+
}
|
|
527
|
+
function expansionFrom(entry) {
|
|
528
|
+
return {
|
|
529
|
+
id: String(entry.id ?? ""),
|
|
530
|
+
kind: String(entry.kind ?? ""),
|
|
531
|
+
target: String(entry.target ?? ""),
|
|
532
|
+
status: String(entry.status ?? ""),
|
|
533
|
+
reason: asObject(entry.reason),
|
|
534
|
+
delta: asObject(entry.delta),
|
|
535
|
+
counts: asObject(entry.counts),
|
|
536
|
+
note: stringOrNull(entry.note),
|
|
537
|
+
runId: stringOrNull(entry.run_id),
|
|
538
|
+
createdAt: stringOrNull(entry.created_at),
|
|
539
|
+
updatedAt: stringOrNull(entry.updated_at),
|
|
540
|
+
raw: entry
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
function expansionsPageFrom(body) {
|
|
544
|
+
const data = asObject(body);
|
|
545
|
+
return {
|
|
546
|
+
expansions: asArray(data.expansions).filter(isObject).map(expansionFrom),
|
|
547
|
+
nextCursor: stringOrNull(data.next_cursor)
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
function feedbackResultFrom(body) {
|
|
551
|
+
const data = asObject(body);
|
|
552
|
+
return { status: String(data.status ?? ""), jobId: stringOrNull(data.job_id), raw: data };
|
|
553
|
+
}
|
|
554
|
+
function dataMapFrom(body) {
|
|
555
|
+
const data = asObject(body);
|
|
556
|
+
return {
|
|
557
|
+
// A kind named bare, as a monitor created without inputs may have it.
|
|
558
|
+
kinds: asArray(data.kinds).map((kind) => typeof kind === "string" ? { kind } : kind).filter(isObject),
|
|
559
|
+
categories: asArray(data.categories).filter(isObject),
|
|
560
|
+
inducedCategories: asArray(data.induced_categories).filter(isObject),
|
|
561
|
+
people: asObject(data.people),
|
|
562
|
+
note: stringOrNull(data.note),
|
|
563
|
+
raw: data
|
|
564
|
+
};
|
|
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
|
+
}
|
|
443
601
|
function listQuery(options) {
|
|
444
602
|
const params = new URLSearchParams();
|
|
445
603
|
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
446
604
|
if (options.cursor !== void 0) params.set("cursor", options.cursor);
|
|
605
|
+
if (options.tag !== void 0) params.set("tag", options.tag);
|
|
447
606
|
const query = params.toString();
|
|
448
607
|
return query ? `?${query}` : "";
|
|
449
608
|
}
|
|
@@ -455,12 +614,28 @@ function sinceParam(since) {
|
|
|
455
614
|
function changesQuery(options) {
|
|
456
615
|
const params = new URLSearchParams();
|
|
457
616
|
if (options.cursor !== void 0) params.set("cursor", String(options.cursor));
|
|
617
|
+
return readQuery(params, options);
|
|
618
|
+
}
|
|
619
|
+
function readQuery(params, options) {
|
|
458
620
|
if (options.since !== void 0) params.set("since", sinceParam(options.since));
|
|
459
621
|
if (options.kinds !== void 0) params.set("kinds", options.kinds.join(","));
|
|
460
622
|
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
461
623
|
const query = params.toString();
|
|
462
624
|
return query ? `?${query}` : "";
|
|
463
625
|
}
|
|
626
|
+
function acrossQuery(scope, options) {
|
|
627
|
+
const { tag, ids } = asObject(scope);
|
|
628
|
+
if (tag == null === (ids == null)) throw invalidRequest("send tag or ids, one of them");
|
|
629
|
+
const params = new URLSearchParams();
|
|
630
|
+
if (tag != null) params.set("tag", String(tag));
|
|
631
|
+
else {
|
|
632
|
+
const named = typeof ids === "string" ? ids : asArray(ids).join(",");
|
|
633
|
+
if (!named) throw invalidRequest("ids needs at least one monitor id");
|
|
634
|
+
params.set("ids", named);
|
|
635
|
+
}
|
|
636
|
+
if (options.cursor !== void 0) params.set("cursor", options.cursor);
|
|
637
|
+
return readQuery(params, options);
|
|
638
|
+
}
|
|
464
639
|
function createMonitors(config) {
|
|
465
640
|
const path = (monitorId, suffix = "") => {
|
|
466
641
|
if (!monitorId || /^\.+$/.test(monitorId)) throw invalidRequest("a monitor id is required");
|
|
@@ -476,12 +651,25 @@ function createMonitors(config) {
|
|
|
476
651
|
const route = `${path(monitorId, "/agent/changes")}${changesQuery(options)}`;
|
|
477
652
|
return changesPageFrom(await request(config, "GET", route, void 0, options.signal));
|
|
478
653
|
};
|
|
654
|
+
const changesAcross = async (scope, options = {}) => {
|
|
655
|
+
const route = `/v1/monitors/changes${acrossQuery(scope, options)}`;
|
|
656
|
+
return monitorsChangesPageFrom(await request(config, "GET", route, void 0, options.signal));
|
|
657
|
+
};
|
|
658
|
+
const expansionPath = (monitorId, expansionId, action) => {
|
|
659
|
+
if (!expansionId || /^\.+$/.test(expansionId)) throw invalidRequest("an expansion id is required");
|
|
660
|
+
return path(monitorId, `/agent/expansions/${encodeURIComponent(expansionId)}:${action}`);
|
|
661
|
+
};
|
|
662
|
+
const write = async (route, body, signal) => request(config, "POST", route, body, signal, "rate_limit");
|
|
479
663
|
return {
|
|
480
664
|
/** Create a monitor. Telem runs `query` on the schedule, and its agent keeps what matches. */
|
|
481
665
|
async create(query, options) {
|
|
482
666
|
const given = options ?? {};
|
|
483
667
|
const agent = given.agent == null ? true : Boolean(given.agent);
|
|
484
|
-
if (agent && !given.ttl) throw invalidRequest(NEEDS_TTL);
|
|
668
|
+
if (agent && !given.ttl) throw invalidRequest(given.inputs == null ? NEEDS_TTL : NEEDS_TTL_INPUTS);
|
|
669
|
+
const key = given.idempotencyKey ?? globalThis.crypto.randomUUID();
|
|
670
|
+
if (typeof key !== "string" || !IDEMPOTENCY_KEY.test(key)) {
|
|
671
|
+
throw invalidRequest("idempotencyKey must be 1 to 255 visible ASCII characters");
|
|
672
|
+
}
|
|
485
673
|
const monitorOptions = {};
|
|
486
674
|
if (given.frequency !== void 0) monitorOptions.frequency = given.frequency;
|
|
487
675
|
if (given.includeDomains !== void 0) {
|
|
@@ -492,8 +680,22 @@ function createMonitors(config) {
|
|
|
492
680
|
if (given.metadata !== void 0) body.metadata = given.metadata;
|
|
493
681
|
if (given.webhookUrl !== void 0) body.webhook_url = given.webhookUrl;
|
|
494
682
|
if (given.ttl !== void 0) body.ttl = given.ttl;
|
|
683
|
+
if (given.inputs != null) {
|
|
684
|
+
body.inputs = given.inputs;
|
|
685
|
+
const vertical = config.defaults.vertical;
|
|
686
|
+
if (vertical !== void 0 && !("vertical" in given.inputs)) {
|
|
687
|
+
body.inputs = { ...given.inputs, vertical };
|
|
688
|
+
}
|
|
689
|
+
}
|
|
495
690
|
body.agent = agent;
|
|
496
|
-
|
|
691
|
+
if (given.preset != null) body.preset = given.preset;
|
|
692
|
+
if (given.tags != null) body.tags = given.tags;
|
|
693
|
+
const extra = {
|
|
694
|
+
headers: { "Idempotency-Key": key },
|
|
695
|
+
maxRetries: config.createMaxRetries,
|
|
696
|
+
budgetMs: CREATE_RETRY_BUDGET_MS
|
|
697
|
+
};
|
|
698
|
+
const data = await request(config, "POST", "/v1/monitors", body, given.signal, "idempotent", extra).catch(
|
|
497
699
|
(error) => {
|
|
498
700
|
if (error instanceof TimeoutError) {
|
|
499
701
|
throw new TimeoutError(
|
|
@@ -522,6 +724,7 @@ function createMonitors(config) {
|
|
|
522
724
|
if (options.frequency !== void 0) body.frequency = options.frequency;
|
|
523
725
|
if (options.ttl !== void 0) body.ttl = options.ttl;
|
|
524
726
|
if (options.webhookUrl !== void 0) body.webhook_url = options.webhookUrl || null;
|
|
727
|
+
if (options.tags != null) body.tags = options.tags;
|
|
525
728
|
const route = path(monitorId);
|
|
526
729
|
return monitorFrom(await request(config, "PATCH", route, body, options.signal));
|
|
527
730
|
},
|
|
@@ -556,25 +759,88 @@ function createMonitors(config) {
|
|
|
556
759
|
if (!page.changes.length || page.nextCursor <= cursor || page.nextCursor >= page.watermark) return;
|
|
557
760
|
cursor = page.nextCursor;
|
|
558
761
|
}
|
|
762
|
+
},
|
|
763
|
+
/** One page of the changes of up to 100 monitors. Keep `nextCursor` and pass it back as `cursor`. */
|
|
764
|
+
changesAcross,
|
|
765
|
+
/** The changes of up to 100 monitors, page by page while `more` is true. `since` goes
|
|
766
|
+
* with the first page only; the scope, `kinds` and `limit` with every page. */
|
|
767
|
+
async *iterateChangesAcross(scope, options = {}) {
|
|
768
|
+
let { cursor, since } = options;
|
|
769
|
+
for (; ; ) {
|
|
770
|
+
const page = await changesAcross(scope, { ...options, cursor, since });
|
|
771
|
+
for (const change of page.changes) yield change;
|
|
772
|
+
if (!page.more || !page.changes.length || page.nextCursor === cursor) return;
|
|
773
|
+
cursor = page.nextCursor;
|
|
774
|
+
since = void 0;
|
|
775
|
+
}
|
|
776
|
+
},
|
|
777
|
+
/** Label one fact of the monitor; with `category`, file a refuted fact there. */
|
|
778
|
+
async feedback(monitorId, options) {
|
|
779
|
+
const body = { fact_id: options.factId, verdict: options.verdict };
|
|
780
|
+
if (options.category != null) body.category = options.category;
|
|
781
|
+
return feedbackResultFrom(await write(path(monitorId, "/agent/feedback"), body, options.signal));
|
|
782
|
+
},
|
|
783
|
+
/** The onboarding sheet of each company of a monitor created with `inputs`. */
|
|
784
|
+
async onboarding(monitorId, options = {}) {
|
|
785
|
+
const route = path(monitorId, "/agent/onboarding");
|
|
786
|
+
return onboardingSheetFrom(await request(config, "GET", route, void 0, options.signal));
|
|
787
|
+
},
|
|
788
|
+
/** Apply your review of one company's sheet: `companyId` goes as `company_id`. */
|
|
789
|
+
async applyOnboarding(monitorId, marks) {
|
|
790
|
+
const { companyId, ...rest } = marks;
|
|
791
|
+
const body = setFields({ company_id: companyId, ...rest });
|
|
792
|
+
return applyResultFrom(await write(path(monitorId, "/agent/onboarding:apply"), body, marks.signal));
|
|
793
|
+
},
|
|
794
|
+
/** What the monitor proposes to add, or added; `status` filters. */
|
|
795
|
+
async expansions(monitorId, options = {}) {
|
|
796
|
+
const query = options.status !== void 0 ? `?${new URLSearchParams({ status: options.status })}` : "";
|
|
797
|
+
const route = `${path(monitorId, "/agent/expansions")}${query}`;
|
|
798
|
+
return expansionsPageFrom(await request(config, "GET", route, void 0, options.signal));
|
|
799
|
+
},
|
|
800
|
+
/** Use a proposed addition. */
|
|
801
|
+
async confirmExpansion(monitorId, expansionId, fields = {}) {
|
|
802
|
+
const route = expansionPath(monitorId, expansionId, "confirm");
|
|
803
|
+
return applyResultFrom(await write(route, setFields(fields), fields.signal));
|
|
804
|
+
},
|
|
805
|
+
/** Remove an addition. */
|
|
806
|
+
async revertExpansion(monitorId, expansionId, options = {}) {
|
|
807
|
+
const route = expansionPath(monitorId, expansionId, "revert");
|
|
808
|
+
return applyResultFrom(await write(route, {}, options.signal));
|
|
809
|
+
},
|
|
810
|
+
/** Every kind and category the monitor collects. */
|
|
811
|
+
async dataMap(monitorId, options = {}) {
|
|
812
|
+
const route = path(monitorId, "/agent/data-map");
|
|
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));
|
|
559
819
|
}
|
|
560
820
|
};
|
|
561
821
|
}
|
|
562
822
|
async function verifyWebhook(body, header, secret, toleranceSeconds = 300) {
|
|
563
|
-
const parts =
|
|
564
|
-
|
|
565
|
-
);
|
|
566
|
-
|
|
567
|
-
const
|
|
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];
|
|
568
828
|
if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1e3 - Number(t)) > toleranceSeconds) return false;
|
|
569
|
-
if (!/^([0-9a-f]{2})+$/.test(v1)) return false;
|
|
570
829
|
const encoder = new TextEncoder();
|
|
571
830
|
const raw = typeof body === "string" ? encoder.encode(body) : body;
|
|
572
831
|
const signed = new Uint8Array([...encoder.encode(`${t}.`), ...raw]);
|
|
573
832
|
const key = await crypto.subtle.importKey("raw", encoder.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, [
|
|
574
|
-
"
|
|
833
|
+
"sign"
|
|
575
834
|
]);
|
|
576
|
-
const
|
|
577
|
-
|
|
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;
|
|
578
844
|
}
|
|
579
845
|
|
|
580
846
|
// src/methods/providers.ts
|
|
@@ -659,7 +925,10 @@ var Telem = class {
|
|
|
659
925
|
/** The session read surface: `list` and `results(id)`. */
|
|
660
926
|
sessions;
|
|
661
927
|
/** Monitors: `create`, `list`, `listPage`, `get`, `update` and `delete`, the agent reads
|
|
662
|
-
* `agent`, `changes` and `iterateChanges`,
|
|
928
|
+
* `agent`, `changes` and `iterateChanges`, the read across monitors `changesAcross` and
|
|
929
|
+
* `iterateChangesAcross`, `feedback`, what a monitor created with
|
|
930
|
+
* `inputs` collects (`onboarding`, `applyOnboarding`, `expansions`, `confirmExpansion`,
|
|
931
|
+
* `revertExpansion`, `dataMap`, `companies`), and the deprecated `poll`. */
|
|
663
932
|
monitors;
|
|
664
933
|
#config;
|
|
665
934
|
/**
|
package/dist/vercel/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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;
|
package/dist/vercel/index.d.cts
CHANGED
|
@@ -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 = {
|
package/dist/vercel/index.d.ts
CHANGED
|
@@ -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 = {
|
package/dist/vercel/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
toolMarker,
|
|
10
10
|
windowAnchor,
|
|
11
11
|
withTrajectory
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-TST6J3VA.js";
|
|
13
13
|
|
|
14
14
|
// src/vercel/index.ts
|
|
15
15
|
import { jsonSchema } from "ai";
|
|
@@ -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
|
-
|
|
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
|
|
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;
|