@sema-agent/core
Version:
Stateless, task-oriented AI agent core
37 lines (36 loc) • 1.6 kB
JavaScript
import { resolveToolSubset } from "../../agents/tool-filter.js";
const TOOL_CONTENT_ORIGIN_SET = { external: true, execution: true, local: true };
export const TOOL_CONTENT_ORIGINS = Object.keys(TOOL_CONTENT_ORIGIN_SET);
export function isToolContentOrigin(value) {
return typeof value === "string" && Object.prototype.hasOwnProperty.call(TOOL_CONTENT_ORIGIN_SET, value);
}
export function classifyToolContentOrigin(input) {
if (input.declared !== undefined)
return isToolContentOrigin(input.declared) ? input.declared : "external";
if (input.trusted)
return "local";
if (input.isProtocolTool)
return "external";
if (input.isCallerTool)
return "external";
return "local";
}
export function withContentOrigin(tool, origin) {
return Object.assign(tool, { contentOrigin: origin });
}
export function delegationCallIsExternal(input) {
if (input.faces === undefined || input.pool === undefined)
return true;
const face = input.requestedType === undefined ? undefined : input.faces.find((f) => f.name === input.requestedType);
if (face === undefined)
return true;
const selectedFor = (f) => resolveToolSubset(input.pool, f.allowTools, f.denyTools);
if (selectedFor(face).some((t) => input.isPolluting(t)))
return true;
if (face.canRedelegate === true && input.faces.some((f) => selectedFor(f).some((t) => input.isPolluting(t))))
return true;
return false;
}
export function contentOriginPollutes(origin, strict) {
return origin === "external" || (strict && origin === "execution");
}