UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

52 lines (51 loc) • 5.13 kB
import type { RunInternals } from "../core/runner/contracts.js"; import type { TaskResult, TaskSpec } from "../core/types.js"; /** * Where a composition entry places the legs it drives after the first — a cascade's rungs after the first it drives, a * verification gate's verifier and fix legs. They are ONE piece of work, so each later leg is placed where the FIRST leg ran, on * both axes a target-bound env factory reads: * · the tree's fixed point (`RunInternals.placementRoot`): every later leg lands where the first leg landed — the first leg's * own report of the fixed point its prepare resolved (`TaskResult.placementRoot`). It is minted into the copy unless the * caller's object already resolves there by prepare's fold (`placementRoot`, else `rootSessionId`); on a fresh entry it * always does whenever the caller carries a fixed point, so that caller's object rides unchanged. A fresh entry whose caller * carries none, over a task that names a host session, gives its first leg that session as the fixed point (the one value * the first leg's own prepare would otherwise take from the leg it runs in, which is a session of its own when the entry * strips the host's): the work is placed where a plain run of the same task would have been, and every later leg and every * card reads it back from the first leg's report. A resume entry gives none — its card records the fixed point. The first leg is the one * the entry drove first: a resume entry's resumed leg reports the fixed point its parked row recorded, which outranks a * supplied `rootSessionId` there, so a caller whose `rootSessionId` names another session still sees every leg after it land * where the composition's work was placed, not at that session or the resumed leg's own. A first leg that reported none (a * result no run assembled) mints none — the same law as the target below; * · the target (`RunInternals.placementTarget`): what the first leg's environment reported as its workspace settled, learned * through the trusted `onWorkspaceResolved` seat — the first leg is dispatched with a shallow copy whose sink records it * before handing the payload to the caller's own sink, if any. A later leg whose env does not name the device the first leg's * did is refused (`config.placement_not_honored`): a re-bind mid-composition moves no later leg onto another device. A first * leg that reported no target leaves the caller's own `placementTarget` (if any) riding by reference; * · the identity (`TaskSpec.principal`, `TaskSpec.isolationScope`): every later leg runs as the first leg was admitted, learned * through the trusted `reportAdmittedIdentity` seat on the same copy ({@link CompositionPlacement.laterIdentity}). A resumed * first leg runs as its parked row's identity wherever the resume config omitted a member, so the later legs built from that * config — a verifier, a fix leg, an escalated rung — run as that person in that scope, not as nobody; before the first leg * reports, every leg runs as the identity the entry was called with (read once there). * Every other field of the caller's object rides every leg by the caller's reference; the caller's object is never mutated, and * a later leg with nothing to gain on either axis is dispatched with the caller's object itself. */ export interface CompositionPlacement { /** The internals the first leg is dispatched with: a copy whose `onWorkspaceResolved` records the leg's own target and whose * `reportAdmittedIdentity` records the identity it was admitted under. */ readonly firstLeg: RunInternals; /** The internals a later leg is dispatched with, given the first leg's result (its self-reported fixed point). */ laterLeg(firstLeg: Pick<TaskResult, "placementRoot">): RunInternals | undefined; /** * `spec` (the spec a leg is built from) re-seated on the identity the composition runs as — the third axis of the same rule: EXACTLY * the members the first leg was admitted under, a member it was admitted without absent whatever `spec` (a rung's overrides, a later * edit of the caller's object) says. A resumed first leg was admitted under what its parked row restored where the resume config * omitted it, so a later leg built from that config does not run as nobody. Until the first leg reports (and when it never does: it * never reached its prepare, or no first leg was dispatched) every leg runs as the identity the entry was called with, read once at * the entry as stated — a value that names no one reaches the door that refuses it. */ laterIdentity<S extends IdentityMembers>(spec: S): Omit<S, keyof IdentityMembers> & IdentityMembers; } type IdentityMembers = Readonly<Pick<TaskSpec, "principal" | "isolationScope">>; /** `calledAs` is the identity the entry was called with (`identityMembersOf` of its spec, read once there). */ export declare function compositionPlacement(internals: RunInternals | undefined, calledAs: IdentityMembers, hostSessionId?: string): CompositionPlacement; export {};