Skip to content

HostInjectedInput ​

Type, in @jr2/orchestrator/src/vocabulary.ts. It is an export of @jr2/orchestrator, on the Authoring surface page, in Machine and events.

ts
type HostInjectedInput = { instanceId: string };

The fields that jr2 adds to the input of the Machine that a run starts, beside the input that the caller sent. Today it is one field: instanceId, an id that jr2 makes for the run.

Add it to the type of your root Machine's input when the Machine reads it: HostInjectedInput & RunInput. Do not put it in the input schema that a run starts with. No caller sends it. jr2 writes it over any value that a caller sends.

Only the root Machine of a run gets it. A Machine that another Machine invokes gets the input that its parent gives it. A workspace() passes its input to its body, so the body of a root workspace() gets it too: Workspaced<HostInjectedInput & RunInput, "app">.

The spec of a root workspace() also gets it, and the type of its input shows it: spec: ({ input }) => ({ branch: `fix/${input.instanceId}` }).

It is not the run id. Use it, for example, to give each run a branch of its own.

Fields

  • instanceId: string

Example

ts
import { z } from "zod";
import { jr2Setup, type HostInjectedInput } from "@jr2/orchestrator";

const runInput = z.object({ ticket: z.string() });
type Input = HostInjectedInput & z.infer<typeof runInput>;

export const machine = jr2Setup({
  types: {} as { input: Input; context: Input; output: { run: string; ticket: string } },
}).createMachine({
  id: "ticket",
  input: runInput,
  context: ({ input }) => input,
  initial: "done",
  states: { done: { type: "final" } },
  output: ({ context }) => ({ run: context.instanceId, ticket: context.ticket }),
});

See also

The docs of Kit version 0.5.1. Each page is also at its .md URL.