Context Layer

State Bridge

10-Second Overview

Context Layer accepts natural language strings as input. State Bridge is an optional utility that converts structured data from any external system into a natural language string for invokeCL().

When to Use It

Use State Bridge when your workflow receives structured output from an external system before calling invokeCL(). Examples include UI state checks, database query results, API responses, file system checks, and form validation results.

Standard text-based workflows do not need State Bridge.

Installation

State Bridge ships as cl-state-bridge.js. Copy it into your project alongside flow-wrapper.js when you provision a Flow project from the console.

buildCLMessage

Converts structured data into a natural language string for invokeCL().

stepDescription

String describing the current workflow step. Required.

stateData

Any structured data from an external system. Accepts booleans, strings, numbers, objects, arrays, and nested structures.

options

Optional object. You may set constraint and context on this object.

constraint

String describing what must be true to proceed.

context

String providing additional context about the state.

Output

A single string combining the step description, state summary, and optional constraint. Pass this string directly to invokeCL().

Example

const { buildCLMessage } = require("./cl-state-bridge");
const { invokeCL } = require("./flow-wrapper");

const msg = buildCLMessage(
  "Proceed with form submission.",
  { submitButton: { visible: true }, formFields: { complete: true } },
  { constraint: "Submit button must be visible before proceeding." }
);

const res = await invokeCL(msg);

assertCLResult

Validates that the Context Layer response contains expected outcomes.

clResponse

The object returned by invokeCL().

expectedOutcomes

Array of strings that must appear in the output.

Behavior

Throws a descriptive error if any expected outcome is missing from the response. Skip assertCLResult if no outcome check is needed.

Example

assertCLResult(res, ["form submitted", "confirmation number"]);

Non-Claims

State Bridge converts data formats. It does not modify how Context Layer enforces constraints or verifies outputs.

Execution Receipts

Describes per-step execution artifacts including verification results.

Verification

Documents how Context Layer verifies outputs against owned context.

Runtime Contract

Documents the behavioral guarantees enforced during execution.