Function: instantiateTemplate()
function instantiateTemplate(
store: PlanStore,
tpl: PlanTemplate,
args: Record<string, EncodableValue>,
actorId: string,
): Promise<InstantiateResult>;Defined in: src/batteries/orchestration/templates.ts:437
Instantiate a template into a fresh, ordinary editable plan.
Parameters
| Parameter | Type | Description |
|---|---|---|
store | PlanStore | The plan store to write into. |
tpl | PlanTemplate | The registered template to materialise. |
args | Record<string, EncodableValue> | The concrete values, keyed by declared param path, to substitute for holes. |
actorId | string | The identity under which the minted ops are authored. |
Returns
Promise<InstantiateResult>
The instantiation result.
Remarks
A template holds op inputs without identity: a PlanOp requires opId/actorId/lamport/ at, and no static literal can carry those — the same reason bounds are a fold seed rather than an implied op. So instantiation mints that identity here, under the passed actorId, with a monotonic lamport.
The steps, in order:
- Validate
argsagainstparams— types (plusmaxByteson strings) and enum membership. On failure it returns{ok: false, reason: 'invalid_args', detail}naming the offending param and what was expected, rather than minting a broken plan. store.createPlan(planId, {provenance: {kind: 'template', template: tpl.id, args}})— the provenance is persisted by the store and returned byreadProvenance, for the renderer and for audit. It is not a taint mechanism (see the module TSDoc).- Substitute every
ParamRefwith the corresponding argument value, then appendadd_node/add_edge/set_boundsops.
The result is an ordinary editable plan: no inherited approval, no special state, nothing downstream needs to know it came from a template. Two instantiations of one template yield independent plans with different ids and digests.
planId is minted (not a parameter), because a fresh plan needs a fresh id — a caller does not pre-choose one. If the mint races a duplicate, an error is thrown rather than returning a broken or mislabelled result.