# Pipeline State

TypeScript source: `services/pipeline-state.ts`

## Types

### GPSTTimingsType

Source: `services/pipeline-state.ts:164`

Average node timing breakdown in microseconds.

#### Remarks

`G` is time spent getting inputs, `P` is processing time, `S` is time spent sending outputs, and `T` is the total main-loop time.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `G` | `number` | Average time spent getting inputs. |
| `P` | `number` | Average processing time. |
| `S` | `number` | Average time spent sending outputs. |
| `T` | `number` | Average total main-loop time. |

### IONodeState

Source: `services/pipeline-state.ts:18`

```ts
0 | 1 | 2
```

Raw IO state value reported for a node input or output.

#### Remarks

`0` maps to green, `1` maps to yellow, `2` maps to red, and any missing or unknown value maps to gray.

### IOStates

Source: `services/pipeline-state.ts:23`

```ts
{ [key: string]: { dotColor?: PipelineStateDotColor; numQueued: number; state?: IONodeState; timing: TimingWithFps } }
```

Runtime state indexed by input or output handle name.

### NodeExtras

Source: `services/pipeline-state.ts:186`

Additional runtime metadata attached to a parsed pipeline node.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `gpstTimings?` | `GPSTTimingsType` | Parsed timing breakdown for the node. |
| `stateInfo?` | `{ label: string; letter: string; state: NodeState }` | Parsed node execution state and display labels. |

### NodeState

Source: `services/pipeline-state.ts:103`

```ts
"IDLE" | "GETTING_INPUTS" | "PROCESSING" | "SENDING_OUTPUTS"
```

Normalized node state label used by parsed pipeline state.

### NodeStateRaw

Source: `services/pipeline-state.ts:98`

```ts
0 | 1 | 2 | 3
```

Raw node state value reported by the runtime.

#### Remarks

`0` is idle, `1` is getting inputs, `2` is processing, and `3` is sending outputs.

### PipelineState

Source: `services/pipeline-state.ts:213`

```ts
{ id: number; inputs: IOStates; outputs: IOStates } & NodeExtras
```

Parsed runtime state for one pipeline node.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `id` | `number` | Numeric node id matching the raw pipeline node id. |
| `inputs` | `IOStates` | Parsed input handle states. |
| `outputs` | `IOStates` | Parsed output handle states. |

### PipelineStateDotColor

Source: `services/pipeline-state.ts:155`

```ts
"gray" | "green" | "yellow" | "red"
```

Dot color used by the canvas legend and node handles.

### RawPipelineState

Source: `services/pipeline-state.ts:108`

```ts
[number, { events: unknown[]; inputsGetTiming: TimingWithFps; inputStates: IOStates; mainLoopTiming: TimingWithFps; otherTimings: object; outputsSendTiming: TimingWithFps; ... }]
```

Raw runtime-state tuple for one pipeline node.

### RawPipelineStatePayload

Source: `services/pipeline-state.ts:4`

Top-level raw runtime-state payload accepted by parsePipelineState.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `nodeStates` | `RawPipelineState[]` | Raw state tuples keyed by node id. |

### Timing

Source: `services/pipeline-state.ts:47`

Duration statistics reported in microseconds.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `averageMicrosRecent` | `number` | Recent average duration in microseconds. |
| `maxMicros` | `number` | Maximum duration across the observed window in microseconds. |
| `maxMicrosRecent` | `number` | Recent maximum duration in microseconds. |
| `medianMicrosRecent` | `number` | Recent median duration in microseconds. |
| `minMicros` | `number` | Minimum duration across the observed window in microseconds. |
| `minMicrosRecent` | `number` | Recent minimum duration in microseconds. |
| `stdDevMicrosRecent` | `number` | Recent duration standard deviation in microseconds. |

### TimingWithFps

Source: `services/pipeline-state.ts:81`

Timing statistics with the observed frames-per-second value.

#### Members

| Name | Type | Description |
| --- | --- | --- |
| `durationStats` | `Timing` | Duration statistics for this timing bucket. |
| `fps` | `number` | Frames-per-second rate reported for this timing bucket. |

## Functions

### parsePipelineState

Source: `services/pipeline-state.ts:283`

```ts
(rawPayload: RawPipelineStatePayload) => PipelineState[]
```

Converts raw runtime-state payloads into canvas-friendly node state.

#### Remarks

Timing values are kept in microseconds so the renderer can decide how to format them.

#### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `rawPayload` | `RawPipelineStatePayload` | Runtime-state payload returned by the backend pipeline service. |

#### Returns

Parsed node states with handle colors, timing breakdowns, and state labels.

#### Example

```ts
const pipelineState = parsePipelineState(rawPipelineStatePayload);
```
