### Navigate and Start AIUI Agent Project
Source: https://github.com/jsar-project/aiui/blob/main/packages/create-aiui-agent/README.md
After creating the project, navigate into the directory, install dependencies, and start the development server.
```bash
cd my-agent
npm install
npm start
```
--------------------------------
### AIUI Single File Component (.ink) Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
A standard .ink file structure demonstrating the use of
{{ greeting }}
```
--------------------------------
### Install AIUI Developer Skill via CLI (Latest)
Source: https://github.com/jsar-project/aiui/blob/main/README.md
Install the AIUI developer skill into your project using the 'npx skills add' command to fetch the latest context files from the main branch.
```bash
npx skills add https://github.com/jsar-project/AIUI/tree/main/skills/aiui-dev
```
--------------------------------
### Install AIUI Developer Skill via CLI (Specific Version)
Source: https://github.com/jsar-project/aiui/blob/main/README.md
Install a specific released version of the AIUI developer skill by replacing 'main' with the desired tag name in the command.
```bash
npx skills add https://github.com/jsar-project/AIUI/tree/v0.1.0/skills/aiui-dev
```
--------------------------------
### Global Configuration Example (app.json)
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Sets up application page routes and global UI styles. The 'pages' field is mandatory for declaring navigation order.
```json
{
"pages": [
"pages/index/index"
],
"window": {
"navigationBarTitleText": "My AIUI Agent",
"viewport": {
"width": "device-width"
}
}
}
```
--------------------------------
### wx.speech.startRecognition
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-wx.md
Starts speech recognition. Requires an interactive call site and throws an error if the interaction gate check fails.
```APIDOC
## wx.speech.startRecognition()
### Description
Starts the speech recognition process.
### Method
`startRecognition`
### Parameters
None
### Return Behavior
- Returns a string.
### Error Behavior
- Throws when the interaction gate check fails, as it requires an interactive call site.
```
--------------------------------
### WXML Data Binding Examples
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Demonstrates basic WXML syntax for text binding, attribute binding, and expression binding using double curly braces {{ }}.
```html
{{ message }}{{ count + 1 }}
```
--------------------------------
### Prompting with Multimodal Input
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-ai.md
This example shows how to send a prompt that includes both text and an image. The image is provided as a base64 encoded data URL.
```javascript
const multimodalAnswer = await session.prompt([
{
role: 'user',
content: [
{ type: 'text', text: 'Describe this image in one sentence.' },
{
type: 'image_url',
image_url: {
url: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...',
},
},
],
},
]);
```
--------------------------------
### Agent Manifest Example (AGENTS.md)
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Defines an agent's identity, version, description, author, and capabilities including permissions and skills.
```markdown
# Agent Manifest
## Identity
- **Name**: My AIUI Agent
- **Version**: 1.0.0
- **Description**: A brief application description.
- **Author**: Developer Name
## Capabilities
- **Permissions**:
- camera
- microphone
- network
- audio
- **Skills**:
- weather-lookup
```
--------------------------------
### Application Registration Example (app.js)
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Registers the AIUI application using an ES module default export configuration object, including lifecycle hooks like onLaunch.
```javascript
export default {
onLaunch() {
console.log('App Launch');
},
globalData: {
userInfo: null
}
};
```
--------------------------------
### View Component Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/components.md
Use the view component as a base layout container for general composition. It supports standard WXML attributes and generic interaction handlers. Layout and styling are primarily controlled via WXSS.
```xml
{{ title }}
```
--------------------------------
### Access Bluetooth API
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Get the Bluetooth API object from the navigator. The Bluetooth API is mounted by the runtime.
```javascript
const bluetooth = navigator.bluetooth;
```
--------------------------------
### Use Web Speech API globally
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Utilize global objects for speech synthesis and recognition. This includes creating utterances, speaking them, and starting speech recognition.
```javascript
const utterance = new SpeechSynthesisUtterance('Hello Ink');
speechSynthesis.speak(utterance);
const recognition = new SpeechRecognition();
recognition.start();
```
--------------------------------
### RecorderManager
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-wx.md
Manages audio recording functionalities, including starting, stopping, pausing, and resuming recordings, along with various event callbacks.
```APIDOC
## RecorderManager
### Description
Manages audio recording operations, providing methods to control recording and listen to various recording events.
### Methods
- `start(options)`: Starts audio recording. Requires an interactive call site. Returns a Promise. Throws an error if the interaction gate check fails.
- `pause()`: Pauses the current audio recording. Returns a Promise. Rejects with a generic error if the operation fails.
- `resume()`: Resumes a paused audio recording. Returns a Promise. Rejects with a generic error if the operation fails.
- `stop()`: Stops the audio recording. Returns a Promise. Rejects with a generic error if the operation fails.
- `onStart(callback)`: Registers a callback function to be executed when recording starts. The callback receives no payload.
- `onResume(callback)`: Registers a callback function to be executed when recording resumes. The callback receives no payload.
- `onPause(callback)`: Registers a callback function to be executed when recording is paused. The callback receives no payload.
- `onStop(callback)`: Registers a callback function to be executed when recording stops. The callback receives an object with `tempFilePath`.
- `onHeader(callback)`: Registers a callback function to be executed when the recording header is received. The callback receives two positional arguments: `format` and `buffer`.
- `onFrameRecorded(callback)`: Registers a callback function to be executed when a frame of audio is recorded. The callback receives an object with `frameBuffer`.
- `onError(callback)`: Registers a callback function to be executed when an error occurs during recording. The callback receives an object with `errMsg`.
- `onInterruptionBegin(callback)`: Registers a callback function to be executed when an interruption begins. The callback receives no payload.
- `onInterruptionEnd(callback)`: Registers a callback function to be executed when an interruption ends. The callback receives no payload.
```
--------------------------------
### Image Component Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/components.md
Use the image component to display local or remote images. Specify the image source with 'src' and control scaling behavior with the 'mode' attribute, such as 'widthFix' or 'heightFix' to preserve aspect ratio.
```xml
```
--------------------------------
### Button Component Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/components.md
The button component serves as a clickable container for actions. It supports generic tap events like 'bindtap' and can be styled using 'class' and 'style'. Child nodes are rendered normally.
```xml
```
--------------------------------
### wx.media.getRecorderManager
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-wx.md
Gets an instance of the RecorderManager. Returns `undefined` if the current context does not provide the required media capability, in unsupported app lifecycle modes, or when recording capability is unavailable.
```APIDOC
## wx.media.getRecorderManager()
### Description
Retrieves the RecorderManager instance.
### Method
`getRecorderManager`
### Parameters
None
### Return Behavior
- Returns a `RecorderManager` instance or `undefined`.
- Returns `undefined` if the current context does not provide the required media capability.
- Returns `undefined` in unsupported app lifecycle modes.
- Returns `undefined` when recording capability is unavailable.
```
--------------------------------
### Importing External Stylesheets in WXSS
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Use the `@import` statement to include styles from other WXSS files. This example imports './common.wxss' and defines a basic box style.
```css
@import "./common.wxss";
.box {
width: 240px;
height: 100px;
background-color: #40FF5E;
}
```
--------------------------------
### Weather Card Page Schema Data Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Declares the input data contract for a weather card page using JSON Schema, specifying properties and required fields.
```json
{
"description": "Displays a weather summary for a city.",
"schema": {
"data": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "The city for which to display weather information."
},
"temperature": {
"type": "number",
"description": "The current temperature in Celsius."
},
"condition": {
"type": "string",
"description": "The current weather condition (e.g., 'Sunny', 'Cloudy')."
}
},
"required": ["city", "temperature", "condition"]
}
}
}
```
--------------------------------
### Canvas Component Example
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/components.md
The canvas component provides a native-backed 2D drawing surface. Set the 'width' and 'height' attributes to define the backing pixel dimensions. The rendered snapshot is displayed through the native view tree.
```xml
```
--------------------------------
### Create LanguageModel Session with Tools
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-ai.md
Demonstrates how to check LanguageModel availability and create a session with initial prompts and function tools. Ensure the LanguageModel is available before creating a session.
```javascript
import { LanguageModel } from 'language-model';
if ((await LanguageModel.availability()) !== 'available') {
throw new Error('LanguageModel is unavailable');
}
const session = await LanguageModel.create({
initialPrompts: [
{
role: 'system',
content: 'You are a concise travel assistant.',
},
],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Look up current weather by city name',
parameters: {
type: 'object',
properties: {
city: { type: 'string' },
},
required: ['city'],
},
},
},
],
});
```
--------------------------------
### Create a New AIUI Agent Project
Source: https://github.com/jsar-project/aiui/blob/main/README.md
Use the official npm CLI to quickly scaffold a new AIUI Agent project. Follow the prompts to set up a basic project structure.
```bash
npm create @yodaos-pkg/aiui-agent my-agent
```
--------------------------------
### Get canvas context from a page node
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Get the 2D rendering context for a canvas node specified by its ID on the current page. Returns null if the page, node, or canvas is not found.
```javascript
import wx from 'wx';
const ctx = wx.createCanvasContext('chartCanvas');
```
--------------------------------
### Script-owned Canvas
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Creating and getting the context for a script-owned canvas.
```APIDOC
## Script-owned Canvas
### Description
Allows creation of a canvas element directly in script and obtaining its 2D rendering context.
### Constructor
```javascript
const canvas = new Canvas(width, height);
```
### Get Context
```javascript
const ctx = canvas.getContext('2d');
```
### Notes
- `canvas.getContext(type)` only accepts `'2d'`. Any other value returns `null`.
```
--------------------------------
### Line Dash
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-canvas.md
Methods for setting and getting the line dash pattern.
```APIDOC
## setLineDash(dashArray)
### Description
Sets the line dash pattern for strokes.
### Parameters
- **dashArray** (Array) - An array of numbers specifying the lengths of alternating dashes and gaps.
## getLineDash()
### Description
Returns the current line dash pattern.
### Returns
- **Array** - The current line dash pattern.
```
--------------------------------
### wx canvas entry point
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Creates a 2D rendering context for a canvas element.
```APIDOC
## wx canvas entry point
### Description
Creates a 2D rendering context for a canvas element.
### Method
- `wx.createCanvasContext(canvasId)`: Creates a canvas rendering context for the specified canvas element.
```
--------------------------------
### Prompting for Text Response
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-ai.md
Use this snippet to get a single text response from the language model. Ensure a session is initialized before calling.
```javascript
const answer = await session.prompt('Plan a 2-day trip in Kyoto.');
console.log(answer);
```
--------------------------------
### Initialize sensors
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Create instances of Accelerometer, AbsoluteOrientationSensor, and Gyroscope with a specified frequency. These sensors are registered globally.
```javascript
const accelerometer = new Accelerometer({ frequency: 60 });
const orientation = new AbsoluteOrientationSensor({ frequency: 60 });
const gyroscope = new Gyroscope({ frequency: 60 });
```
--------------------------------
### Create and get context for a script-owned canvas
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Create a new canvas element and obtain its 2D rendering context. The getContext method only accepts '2d'.
```javascript
const canvas = new Canvas(300, 150);
const ctx = canvas.getContext('2d');
```
--------------------------------
### wx.media.createCameraContext
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-wx.md
Creates a CameraContext instance. Returns `undefined` if the current context does not provide the required media capability or in unsupported app lifecycle modes.
```APIDOC
## wx.media.createCameraContext()
### Description
Creates a CameraContext instance.
### Method
`createCameraContext`
### Parameters
None
### Return Behavior
- Returns a `CameraContext` instance or `undefined`.
- Returns `undefined` if the current context does not provide the required media capability.
- Returns `undefined` in unsupported app lifecycle modes.
```
--------------------------------
### Create New AIUI Agent Project
Source: https://github.com/jsar-project/aiui/blob/main/packages/create-aiui-agent/README.md
Use this command to scaffold a new AIUI Agent project with a given name.
```bash
npx @yodaos-pkg/create-aiui-agent my-agent
```
--------------------------------
### System Methods
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-wx.md
Methods for interacting with the mini-program system.
```APIDOC
## `wx.exitMiniProgram(options?)`
### Description
Exits the current mini-program.
### Parameters
#### Path Parameters
- **options** (Object) - Optional - Configuration options.
- **success** (Function) - Optional - Callback function when the operation is successful.
- **complete** (Function) - Optional - Callback function executed after the operation completes (success or fail).
### Behavior Notes
- Calls `success()` and `complete()` when present, then sends the app exit event.
```
--------------------------------
### Create Sound object globally
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Instantiate a Sound object using its global constructor, specifying the audio file path. The Sound object is also available as a named export from 'audio'.
```javascript
const click = new Sound('./click.wav');
```
--------------------------------
### SpeechRecognition
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-ai.md
Provides an interface for recognizing speech input from a microphone. It allows starting, stopping, and aborting the recognition process, and handles various events related to speech recognition.
```APIDOC
## `SpeechRecognition`
### Constructor
- `new SpeechRecognition()`
### Properties
- `lang` (string) - The language for speech recognition. Defaults to an empty string, letting the host choose.
- `continuous` (boolean) - Whether to continuously listen for speech. Defaults to false.
- `interimResults` (boolean) - Whether to provide interim results during recognition. Defaults to false.
- `maxAlternatives` (number) - The maximum number of alternative interpretations to return. Defaults to 1.
### Methods
- `start()` - Starts the speech recognition session.
- `stop()` - Stops the speech recognition session and finalizes the current result.
- `abort()` - Aborts the speech recognition session immediately.
### Event Behavior
- Inherits from `EventTarget`.
- Supported event names: `start`, `audiostart`, `soundstart`, `speechstart`, `result`, `nomatch`, `error`, `speechend`, `soundend`, `audioend`, `end`.
- Supported event handler properties: `onstart`, `onaudiostart`, `onsoundstart`, `onspeechstart`, `onresult`, `onnomatch`, `onerror`, `onspeechend`, `onsoundend`, `onaudioend`, `onend`.
- `result` events expose `resultIndex`, `results`, and `sessionId`.
- `error` events expose `error`, `message`, and `sessionId`.
### Behavior Notes
- Default values: `lang = ''`, `continuous = false`, `interimResults = false`, `maxAlternatives = 1`.
- If `lang` is empty, the host selects the default language.
- `start()` initiates a new recognition session.
- `stop()` requests the host to stop listening and finalize the session.
- `abort()` stops the session without finalizing.
- New `start()` calls require the owning InkView to be interactive.
### Error Behavior
- `start()` fails with `InvalidStateError` if the owning InkView is non-interactive.
```
--------------------------------
### Create AIUI Agent Project Locally
Source: https://github.com/jsar-project/aiui/blob/main/packages/create-aiui-agent/README.md
If the package is available locally, use this command to create a new AIUI Agent project.
```bash
npx create-aiui-agent my-agent
```
--------------------------------
### WXML List Rendering with ink:for
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/SKILL.md
Illustrates how to render lists of data in WXML using the ink:for directive. Use 'item' for the current element and 'index' for its position. A stable ink:key is recommended.
```html
{{item.name}}{{item.temperature}}
```
--------------------------------
### Gyroscope API
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis-device.md
Provides an interface to access the device's gyroscope sensor data. Users can start and stop the sensor, and listen for activation, reading, and error events.
```APIDOC
## Gyroscope
### Description
Provides an interface to access the device's gyroscope sensor data. Users can start and stop the sensor, and listen for activation, reading, and error events.
### Constructor
- `new Gyroscope(options?)`
- `options` (object) - Optional constructor options.
- `frequency` (number) - Optional hint for the desired sensor update frequency.
### Properties
- `x` (number | null) - The x-axis component of the gyroscope reading. Null until the first reading.
- `y` (number | null) - The y-axis component of the gyroscope reading. Null until the first reading.
- `z` (number | null) - The z-axis component of the gyroscope reading. Null until the first reading.
- `timestamp` (DOMHighResTimeStamp | null) - The high-resolution timestamp of the last reading. Null until the first reading.
- `activated` (boolean) - Indicates if the gyroscope sensor is currently active.
- `hasReading` (boolean) - Indicates if the gyroscope sensor has ever provided a reading.
### Methods
- `start()`: Activates the gyroscope sensor. If already active, this is a no-op.
- `stop()`: Deactivates the gyroscope sensor. The last reading is cached. If already inactive, this is a no-op.
### Event Behavior
- Inherits from `EventTarget`.
- Supported event names: `activate`, `reading`, `error`.
#### `activate` Event
- Exposes `sessionId`.
#### `reading` Event
- Exposes `sessionId`, `x`, `y`, `z`, and `timestamp`.
#### `error` Event
- Exposes `sessionId`, `error`, and `message`.
### Behavior Notes
- The `frequency` option is a best-effort hint to the host.
- Initially, `activated` and `hasReading` are `false`.
- `x`, `y`, `z`, and `timestamp` are `null` until the first reading.
- The first successful reading sets `activated` and `hasReading` to `true`.
- `stop()` sets `activated` to `false` but retains the last reading.
```
--------------------------------
### wx Module
Source: https://github.com/jsar-project/aiui/blob/main/skills/aiui-dev/apis.md
Import and usage of the wx module for canvas context creation.
```APIDOC
## wx Module
### Description
Provides access to canvas contexts on the current page.
### Import
```javascript
import wx from 'wx';
```
### Usage
```javascript
const ctx = wx.createCanvasContext('chartCanvas');
```
### Notes
- `wx.createCanvasContext(canvasId)` looks up a `