UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

37 lines (36 loc) • 2.45 kB
import { CROSS_BOUNDARY_POSTURES, resolvePlaintextOrigins } from "@sema-agent/primitives"; import { stampConfigInput } from "./config-refusal-input.js"; import { describeRejectedValue } from "./tool-search-setting.js"; const DEPLOYMENT_PLAINTEXT_ORIGINS = Symbol("deployment plaintext origins"); function refusal(code, why) { const e = new Error(`${why} (refused at new Runner)`); e.code = code; stampConfigInput(e, "deps"); return e; } export function receivePlaintextOrigins(declared, posture) { if (posture !== undefined && !CROSS_BOUNDARY_POSTURES.some((w) => w === posture)) { throw refusal("config.cross_boundary_posture", `RunnerDeps.crossBoundaryPosture must be ${CROSS_BOUNDARY_POSTURES.map((w) => `"${w}"`).join(" or ")} when present (got ${describeRejectedValue(posture)}) — an unreadable posture is never read as either word`); } const read = resolvePlaintextOrigins({ declared: declared, crossBoundaryPosture: posture }); if (!read.ok) throw refusal("config.plaintext_origins_invalid", `RunnerDeps.plaintextOrigins does not read: ${read.problems.join("; ")} — a list that does not read is never read as the default`); return read.origins; } export function keepPlaintextOrigins(bag, origins) { return Object.defineProperty(bag, DEPLOYMENT_PLAINTEXT_ORIGINS, { value: origins, enumerable: true, writable: true, configurable: true }); } export function plaintextOriginsOf(deps) { return deps[DEPLOYMENT_PLAINTEXT_ORIGINS]; } export function plaintextOriginsAdmittedNotice(origins, posture, origin) { const postureDeclared = posture !== undefined; return { code: "config.plaintext_origins_admitted", message: `A request carrying a credential is being sent over plain http to ${origin}, admitted by the default list (${origins.entries.join(", ")}) — ` + `RunnerDeps.plaintextOrigins is not written${postureDeclared ? "" : ' and no RunnerDeps.crossBoundaryPosture is configured (read as "single_user")'}. ` + "Write plaintextOrigins: [] to admit only this machine, or the list you mean. " + "If the process sends through an outbound proxy and this origin is not on its direct list, a credential-carrying plain-http request reaches the proxy first (the dispatcher is the host's; the engine cannot see it).", detail: { origin, entries: [...origins.entries], source: origins.source, postureDeclared }, }; }