Skip to main content
This page documents the JSON schema infrastructure and the automated pipeline for generating and validating protocol stubs across multiple languages. Palyra uses a combination of Protobuf for high-performance RPC and JSON schemas for structured message envelopes, configuration exports, and UI patches.

JSON Envelope Schemas

The schemas/json/ directory contains the formal definitions for non-gRPC data structures. These schemas ensure consistency between the Rust-based daemon, the React web console, and external connectors.

Key Schema Categories

Schema TypePurposeKey Entities
Message EnvelopeDefines the structure for inter-agent and connector messaging.Message, Payload, Metadata
A2UI EnvelopeHandles Agent-to-User Interface JSON Patches.A2UIPatch, CanvasState
Config Export/ImportGoverns the serialization of daemon configuration for portability.RootFileConfig, VaultExport
Webhook EnvelopeDefines the payload structure for inbound webhooks.WebhookEvent, Signature
Common PrimitivesShared types like ULIDs, Timestamps, and URI formats.Ulid, IsoDateTime
Sources: schemas/json/ (Directory reference)

Protocol Validation and Stub Generation

To maintain type safety across the monorepo and for external consumers, Palyra employs a “Schema-First” approach. Protobuf definitions in schemas/proto/ are validated and then used to generate stubs for Rust, Kotlin, and Swift.

Validation Pipeline

The validation process ensures that all .proto files are syntactically correct and can be compiled into a descriptor set.
  1. validate-proto.ps1: This script locates the protoc compiler and attempts to generate a descriptor set (palyra-protocol.pb) from all files in schemas/proto/ scripts/protocol/validate-proto.ps1#9-66.
  2. Stub Generation: Once validated, generate-stubs.ps1 is invoked to produce language-specific source files in schemas/generated/.

Language-Specific Stub Validation

After generation, each stub file undergoes a “smoke compile” to ensure the generated code is valid in its target language:

Stub Coherence Flow

The following diagram illustrates the relationship between the raw schemas, the generation scripts, and the validation checks. Diagram: Schema-to-Stub Pipeline Sources: scripts/protocol/validate-proto.ps1#48-71, scripts/protocol/validate-rust-stubs.ps1#7-29, scripts/protocol/validate-kotlin-stubs.ps1#7-29, scripts/protocol/validate-swift-stubs.sh#5-21

CI/CD Integration

The protocol integrity is enforced by the CI pipeline to prevent “drift” between the schemas and the generated code.

Coherence Checks

The check-generated-stubs.ps1 script (run in CI) ensures that the stubs currently committed to the repository match exactly what would be generated from the current schemas. If a developer modifies a .proto file but forgets to run the generation script, the CI will fail.

CI Workflow Steps

The ci.yml workflow executes these checks as part of the quality and build-and-test jobs:
  1. Protocol Contract Validation: Ensures schemas are valid scripts/protocol/validate-proto.ps1#71.
  2. Stub Coherence: Verifies generated code is up-to-date.
  3. Cross-Platform Compilation: The build-and-test job compiles the workspace on Ubuntu, macOS, and Windows to ensure the Rust stubs work across all targets /.github/workflows/ci.yml#17-23.
Diagram: CI Security and Quality Gates Sources: /.github/workflows/ci.yml#172-212, /.github/workflows/security.yml#12-130

Implementation Details

Tooling Requirements

To run the full validation suite locally, the following tools must be present in the system PATH:

File Locations

  • Protobuf Source: schemas/proto/palyra/v1/
  • JSON Source: schemas/json/
  • Rust Stubs: schemas/generated/rust/protocol_stubs.rs
  • Kotlin Stubs: schemas/generated/kotlin/ProtocolStubs.kt
  • Swift Stubs: schemas/generated/swift/ProtocolStubs.swift
Sources: scripts/protocol/validate-proto.ps1#7-8, scripts/protocol/validate-rust-stubs.ps1#7, scripts/protocol/validate-kotlin-stubs.ps1#7, scripts/protocol/validate-swift-stubs.sh#5