Skip to content
Documentation

Architecture

GAS turns a score into requests for a music model, and streams the model’s audio back to your application:

score → language → timeline → session → connector → connection → model

Your application creates a connector for the model, with its provider access, and passes it to a session. The session schedules the score’s intent against a clock. Each Play opens a new connection through the connector, and the intent goes to the model over it. Audio comes back the same way to the playback engine: Web Audio in a browser, or whatever output your application supplies.

Runtime boundaries

Component Responsibility
Language Parse, validate, and compile a score into a timeline
Protocol Shared payload types and schemas
Core Validate commands and derive effective state through the cascade
API The session: loading, commands, events, scheduling against a clock, and a connection for each Play
Connector Translate intent into one model’s requests, and stream its audio back over a connection
Browser session Combine the session with Web Audio playback and an audible position

Everything model-specific lives in the connector. The score, timeline, and session describe intent the same way whichever model plays it.

Core works from input state alone, with no clock, network, or model. You can test commands and layering without generating audio.

Dependencies point toward the shared contracts. Protocol and highlight depend on nothing else in GAS. Language, Core, notation, and each connector depend on protocol. The API uses language, Core, and notation. Nothing depends on a connector: your application creates one and passes it in.

Packages and imports

Install the package, and the connector for the model you use:

bash
npm install --save-exact @luna-estelar/gas@0.4.0 @luna-estelar/gas-lyria-rt@0.4.0
Import Contents
@luna-estelar/gas Sessions, source helpers, errors, and version
@luna-estelar/gas/language Parser, compiler, live commands, and editor helpers: compile, highlight, and preview live input
@luna-estelar/gas/browser Browser session, Web Audio playback, capture, timeline views, and effective-state inspection
@luna-estelar/gas/protocol Shared types and ConnectorError, for writing a connector
@luna-estelar/gas/protocol/validation Precompiled timeline payload validation
@luna-estelar/gas/highlight Syntax-presentation helpers and token classes, without the parser
@luna-estelar/gas-lyria-rt The Lyria RealTime connector, its capabilities, and configuration helpers
@luna-estelar/gas-magenta-rt2 The Magenta RealTime 2 connector, for a model that runs locally
@luna-estelar/gas-connector-test Checks a connector against the connector contract

The connector is versioned with the package, and accepts any @luna-estelar/gas from 0.4.0 up to 1.0 (>=0.4.0 <1.0). Keep the two on the same version.

The package also supplies the gas compile command:

bash
npx @luna-estelar/gas@0.4.0 compile song.gas --out song.timeline.json

Use the scoped name; npx gas fetches an unrelated package. Diagnostics describes its error output.

Everything is ESM, with bundled TypeScript declarations, and requires Node 22. Browser applications need a bundler; there is no script-tag build.

Imports only load what they need. Only /language loads the parser directly; the session loads it on demand when it compiles source or live text, and loadTimeline never needs it. Only @luna-estelar/gas-lyria-rt loads Google’s SDK, so import it only where you create the connector.

Connector interface

A connector translates effective state into model requests, streams audio chunks back, and declares how it handles each kind of intent. It does not parse scores or schedule events. GAS owns Play, Stop, rests, and failures, so a connector only opens connections.

The Connector interface in /protocol has:

Member Responsibility
description Identify the model, audio format, capabilities, configuration schema, and defaults
connect(options) Open one connection for one Play, and resolve once audio can flow
validateConfig?(config) Optional configuration validation

connect() receives the configuration, the effective state at bar 1, the timing, an AbortSignal for a Stop during start-up, and callbacks for audio, warnings, and errors. It resolves with a Connection:

Method Responsibility
update(update, requested) Apply intent and resolve with the position where it takes effect
pause() Stop the provider generating
resume() Start generating again
close() Close the transport

A startup failure rejects connect(). A later failure calls onError once. Both are a ConnectorError.

A connector’s capabilities table rates every intent as supported, approximated, or unsupported. The session warns when a score uses intent the model will approximate or ignore. Only the session can produce these warnings; the compiler doesn’t know which model will play the score.

Connector failures are classified as auth, network, quota, provider, or internal, with the raw WebSocket close code when there is one. Connectors sanitise provider error text before passing it on. Close codes from 4000 to 4999 belong to whoever operates the endpoint, so your application interprets them.

The interface is in-process TypeScript and can still change before 1.0. @luna-estelar/gas-connector-test checks a connector against the contract in your own vitest suite. The Lyria connector is the reference implementation, and Supported models describes how it behaves. To discuss a connector for another model, get in touch.

What stays the same between plays

The timeline is the same every time a score compiles: the same tracks, section spans, and intent at the same musical positions. The audio is not. The model chooses the notes, phrasing, and sound, so each Play is a new performance, and GAS has no model-independent way to repeat one. To keep a performance, record it with PcmCapture and encodeWave from /browser.

Test your application’s commands and musical structure separately from the audio a model produces.

Versions and stability

The 0.x APIs can change in a minor release. Pin @luna-estelar/gas and its connector to the same version and commit your lockfile.

The data schemas, such as the timeline’s, have their own format version, currently 1.0, separate from the package versions. Timeline format covers the schema.

FMOD integration and C++ or Python ports are not released or scheduled. If a model or host matters to your project, tell us what you need.

Terms

Term Meaning
Score, document GAS text containing globals, tracks, sections, and calls
Arrangement The section calls in playback order; a reprise is a repeated call
Layer, build A track’s contribution; a build introduces layers or density over time
Timeline Compiled intent placed in musical time
Effective state Values and track activation derived for a position
App value, cascade A value your application set, and the precedence used to resolve it
App track A track your application added
Session The application interface for loading, playback, commands, and events
Connector, capabilities A model adapter, and its declared support for each kind of intent
Connection One open link to the provider; each Play opens one