# @compass/variables

This package provides functionalities to interact with the automation context in Compass. It allows you to retrieve and set variables within the context.

### Usage

```javascript
import variables from "@compass/variables";
```

### API Reference

#### `variables.get(key: string, scope?: string)`

Retrieve a variable from the automation context.

* `key` (required, string): The key of the variable to retrieve.
* `scope` (optional, string): The scope of the variable to retrieve.

Returns the value of the variable. Returns null if the variable does not exist.

#### `variables.set(key: string, value: any, scope?: string)`

Set a variable in the automation context.

* `key` (required, string): The key of the variable to set.
* `value` (required, any): The value of the variable to set.
* `scope` (optional, string): The scope of the variable to set.

Returns the value of the variable.

### Examples

To retrieve a variable from the automation context:

```javascript
import variables from "@compass/variables";

export default async function() {
    const key = 'variableKey';
    const scope = 'local';
    const value = variables.get(key, scope);
    return { value };
}
```

To set a variable in the automation context:

```javascript
import variables from "@compass/variables";

export default async function() {
    const key = 'variableKey';
    const value = 'Hello, World!';
    const scope = 'local';
    const setValue = variables.set(key, value, scope);
    return { setValue };
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.compass.art/automations/custom-actions/compass-variables.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
