@sema-agent/core
Version:
Stateless, task-oriented AI agent core
47 lines (46 loc) • 2.2 kB
JavaScript
import { engineTextFor } from "../prompt-assembly/engine-text.js";
import { capabilityHeld, capabilityOf } from "./model-capability.js";
import { emitBrainTelemetry, reportCapabilityWithheld } from "./status-sink.js";
export function imageWithholdOf(model) {
if (model === undefined)
return undefined;
const declared = capabilityOf(model, "image");
return declared === "declared_on" || capabilityHeld(model, "image") ? undefined : { modelId: model.id, cause: declared };
}
export function reportImagesWithheld(withhold, count) {
if (count === 0)
return;
emitBrainTelemetry({ kind: "vision_placeholder", count });
reportCapabilityWithheld({ modelId: withhold.modelId, capability: "image", cause: withhold.cause, count });
}
export const IMAGE_OMITTED_NO_VISION = "[image omitted: the serving model does not support image input]";
export const DOCUMENT_OMITTED = "[PDF document omitted: the serving model does not support PDF (document) input]";
export function imagesOmittedNoVisionNote(count) {
return count > 1 ? `[${count} images omitted: the serving model does not support image input]` : IMAGE_OMITTED_NO_VISION;
}
export function toolImagesPrefix(count, ids, locale) {
return engineTextFor(locale)(count > 1 ? "core/engine.image-prefix-many" : "core/engine.image-prefix-one", { ids });
}
export function sendableImages(blocks) {
const out = [];
for (const b of blocks) {
const c = b;
if (c.type === "image" && typeof c.data === "string" && typeof c.mimeType === "string") {
out.push({ type: "image", data: c.data, mimeType: c.mimeType });
}
}
return out;
}
function plural(count, noun) {
return `${count} ${noun}${count > 1 ? "s" : ""}`;
}
export function errorResultMediaNote(counts) {
const dropped = [];
if (counts.images > 0)
dropped.push(plural(counts.images, "image"));
if (counts.documents > 0)
dropped.push(plural(counts.documents, "document"));
if (dropped.length === 0)
return undefined;
return `[${dropped.join(" and ")} omitted — an error tool result must be text-only; re-run the tool successfully if you need the attachment]`;
}