Page Definition | AIUI | Rokid

Define an AIUI Page in one .ink file. Put JSON configuration in <script def>, state and handlers in <script setup>, markup in <page>, and styles in <style>.

Page Definition

Define an AIUI Page in one .ink file. Put JSON configuration in <script def>, state and handlers in <script setup>, markup in <page>, and styles in <style>.

Complete Page Example

In your project, add pages/index/index to pages in app.json or keep the entry if it already exists. Save this example as pages/index/index.ink.

<script type="application/json" def>
{
  "navigationBarTitleText": "Status"
}
</script>

<script setup>
export default {
  data: { status: 'Waiting' },
  markReady() {
    this.setData({ status: 'Ready' });
  }
};
</script>

<page>
  <view class="panel">
    <text>{{ status }}</text>
    <button bindtap="markReady">Mark ready</button>
  </view>
</page>

<style>
.panel {
  padding: 16px;
}
</style>
aix preview .

Preview the page from the project root with the AIX CLI. Open the URL printed in the terminal. The page shows Waiting. Select Mark ready and check that it shows Ready. Press Ctrl+C to stop the preview.

The same Page can be split into matching .json, .wxml, .wxss, and .js or .ts files. In that form, .json is equivalent to <script def>, and the script default-exports the Page logic. For .ts, use the supported TypeScript syntax. Do not mix both forms for the same route.

<script def> Page Configuration

<script def> must contain a valid JSON object. It cannot contain comments, functions, variables, or trailing commas. Keeping type="application/json" is recommended because it makes the content type explicit.

Common Fields

FieldTypeRequiredPurpose
navigationBarTitleTextstringNoSets the title used when the page displays a navigation bar
descriptionstringRecommended for conversational PagesExplains to the model what the Page does and when to use it; describe observable capability rather than a generic title
schemaObjectNoDescribes inputs accepted when opening the Page. Define them in schema.data.
usingComponentsObjectNoRegisters custom components used by this Page; each key is a template tag name and each value is a component path or package export
disableScrollbooleanNoDisables default scrolling on the Page root; defaults to false

Together, description and schema.data describe a Page as a callable UI tool. An immersive agent commonly enters the first Page registered in app.json, so that Page does not always need to be exposed as an independent tool. A conversational card Page should define both fields precisely.

schema.data

schema.data uses JSON Schema to describe data passed into the Page. Common fields include:

FieldTypePurpose
typestringRoot data type; Page input normally uses object
propertiesObjectDefines each input field, including its type, meaning, and constraints
requiredstring[]Lists fields that must be supplied; fields not listed are optional
properties.<name>.typestringField type, such as string, number, integer, boolean, object, or array
properties.<name>.descriptionstringTells the model the field's meaning, format, unit, and value requirements
properties.<name>.enumany[]Restricts the field to a set of values
properties.<name>.itemsObjectDescribes array elements when the field type is array
properties.<name>.defaultanyDescribes a suggested default; Page logic should still handle a missing field

Use schema.data to describe the inputs accepted when opening a Page. Use data in the Page logic object for the initial render state. Read supplied inputs in onLoad(query) and call setData() with the values the interface needs.

{
  "description": "Displays weather for a city and date.",
  "schema": {
    "data": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string",
          "minLength": 1,
          "description": "City name, for example Hangzhou."
        },
        "date": {
          "type": "string",
          "description": "Query date in YYYY-MM-DD format."
        },
        "unit": {
          "type": "string",
          "enum": ["celsius", "fahrenheit"],
          "default": "celsius",
          "description": "Temperature unit."
        }
      },
      "required": ["city"]
    }
  }
}

Other Compatibility Fields

The Page configuration parser also accepts mini-app-style window, background, renderer, and host extension fields, including navigationBarBackgroundColor, navigationBarTextStyle, navigationStyle, homeButton, backgroundColor, backgroundColorContent, backgroundTextStyle, backgroundColorTop, backgroundColorBottom, enablePullDownRefresh, onReachBottomDistance, pageOrientation, viewport, style, initialRenderingCache, singlePage, restartStrategy, handleWebviewPreload, visualEffectInBackground, enablePassiveEvent, renderer, rendererOptions, and componentFramework.

The parser accepts these fields for compatibility. Use the common fields above for documented behavior and put rules for the page content in <style>.

<script setup> Page Logic

Page logic default-exports an object. Its fields become the current Page instance's state, lifecycle callbacks, and event handlers.

FieldTypeRequiredPurpose
dataObjectNoInitial render state; values must be JSON-serializable
onLoadfunctionNoRuns once when the Page loads and receives route or tool invocation parameters
onShowfunctionNoRuns when the Page appears or returns to the foreground
onReadyfunctionNoRuns once after the first frame with the initial view is presented
onHidefunctionNoRuns when the Page is hidden or enters the background
onUnloadfunctionNoRuns when the Page is unloaded; release timers, listeners, and other resources here
onKeyDownfunctionNoRuns when a key is pressed; read its code from event.code
onKeyUpfunctionNoRuns when a key is released; event.preventDefault() can suppress supported default key actions
onVoiceWakeupfunctionNoRuns for voice or touch wakeup events; use event.keyword when the source must be distinguished
Custom methodsfunctionNoHandle template events or share Page logic; access the Page instance through this
Custom fieldsanyNoStore members that do not participate in rendering; values that drive the UI should live in data

Do not use options here as a standard Page field. Parameters used to open a Page are received by onLoad(query), while custom component configuration belongs in usingComponents inside <script def>.

Page Instance

Inside Page callbacks and custom methods, this refers to the current Page instance.

this.data

Reads the current Page state. Do not rely on direct this.data mutation to update the UI; use this.setData() for values bound by the template.

this.setData(Object patch, Function? callback)

Asynchronously sends an update to the view layer while updating this.data. patch supports path keys such as 'user.name': 'Rokid'. The optional callback runs after this view update completes.

this.setData({
  status: 'ready',
  'user.name': 'Rokid'
}, () => {
  console.log('view updated');
});

this.finish()

Call this.finish() when the user completes the current task. A Cut agent typically closes its current presentation and returns focus. A Scene agent typically ends the current interaction. Use a navigation API for ordinary back navigation.

Lifecycle and Events

When a new Page reaches its first frame, the callbacks run in order: onLoad → onShow → onReady. Covering a Page triggers onHide, showing it again triggers another onShow, and destroying it triggers onUnload.

For default key and wakeup behavior, event fields, and interception, see Events. For the full lifecycle, see Lifecycle.

Recommended Reading

  • Page Overview
  • Lifecycle
  • Events
  • Components