@sema-agent/core
Version:
Stateless, task-oriented AI agent core
25 lines (24 loc) • 1.22 kB
JavaScript
import { randomBytes } from "node:crypto";
import { adoptYieldedBackgroundWork, legAdoptionOf } from "../../agents/yield-adoption.js";
import { resumedWorkflowCallOf, workflowParksContributor } from "../../orchestration/workflow-park-adoption.js";
import { RUN_WORKFLOW_TOOL_NAME } from "../../orchestration/run-workflow-tool.js";
export function prepareLegAdoption(input) {
const resumedCall = resumedWorkflowCallOf(input.resume?.pendingCall, input.resume?.outcome, RUN_WORKFLOW_TOOL_NAME);
const workflowParks = workflowParksContributor({
decisions: input.decisions,
adopter: input.adopter,
gate: input.gate,
mintCallId: () => `wfc-${randomBytes(8).toString("hex")}`,
ctxOf: (toolCallId) => input.enrich({ toolCallId }),
toolName: RUN_WORKFLOW_TOOL_NAME,
...(resumedCall !== undefined ? { resumedCall } : {}),
deliver: input.deliver,
say: input.say,
});
return {
legAdoption: legAdoptionOf({
yielded: () => adoptYieldedBackgroundWork(input.tools, input.enrich, { resumed: input.resume !== undefined }, input.onError),
...(workflowParks !== undefined ? { workflowParks } : {}),
}),
};
}