@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
55 lines • 2.17 kB
JavaScript
import { requireSecureUrl } from './util.js';
export const LINKS_EXTENSION = 'links';
export const DISCLOSURES_EXTENSION = 'disclosures';
export const LINKS_VERSION = '1';
export const DISCLOSURES_VERSION = '1';
/** Extensions only Company messages carry: a Personal Agent never sends their content. */
export const COMPANY_ONLY_CONTENT = [LINKS_EXTENSION, DISCLOSURES_EXTENSION];
function itemsOf(company, message, name, version) {
if (!message || message.role === 'user')
return [];
if (company.declaredExtensions[name] !== version)
return [];
const content = message.extensions?.[name];
if (typeof content !== 'object' || content === null || Array.isArray(content))
return [];
const items = content.items;
return Array.isArray(items) ? items : [];
}
/**
* The links of a Company message (Links extension), in the order the message refers to them. A link
* whose `url` isn't HTTPS (or points to an internal address) is dropped. Each carries its `domain`:
* a `title` can name a page other than the one at its URL, so show the domain with it.
*/
export function linksOf(company, message) {
const out = [];
for (const raw of itemsOf(company, message, LINKS_EXTENSION, LINKS_VERSION)) {
if (typeof raw !== 'object' || raw === null)
continue;
const { url, title } = raw;
let parsed;
try {
parsed = requireSecureUrl(url, 'link url', company.security);
}
catch {
continue;
}
out.push({
url: parsed.toString(),
domain: parsed.host,
...(typeof title === 'string' && title !== '' ? { title } : {}),
});
}
return out;
}
/** The disclosures of a Company message (Disclosures extension): notices to show with it. */
export function disclosuresOf(company, message) {
const out = [];
for (const raw of itemsOf(company, message, DISCLOSURES_EXTENSION, DISCLOSURES_VERSION)) {
const text = raw?.text;
if (typeof text === 'string' && text !== '')
out.push({ text });
}
return out;
}
//# sourceMappingURL=message_extensions.js.map