# UncageStore

<!-- https://uncage.vercel.app/docs/api/react/interfaces/uncagestore/ -->

Defined in: react/src/store.ts:43

## Properties

| Property | Modifier | Type | Description | Defined in |
| ------ | ------ | ------ | ------ | ------ |
| <a id="property-actions"></a> `actions` | `public` | `object` | - | react/src/store.ts:46 |
| `actions.addAttachments` | `public` | (`files`) => `void` | Validates files client-side (same rules as the server, using the target runtime's capabilities) and uploads accepted ones to the active session, or queues them in a draft. Refused files are listed in `attachments.rejected`. Takes browser `File`s or, in React Native, picked file references (`{ uri, name, type, size? }`, see [AttachmentFile](https://uncage.vercel.app/docs/api/react/type-aliases/attachmentfile.md)). | react/src/store.ts:90 |
| `actions.cancelRun` | `public` | () => `Promise`\<`void`\> | - | react/src/store.ts:58 |
| `actions.clearAttachments` | `public` | () => `void` | - | react/src/store.ts:92 |
| `actions.closeDraft` | `public` | () => `void` | Leaves draft mode; with an open session, the draft's settings and queued files are discarded. | react/src/store.ts:73 |
| `actions.commitDraft` | `public` | (`b?`) => `Promise`\<`string`\> | Creates a session from the draft: on the draft runtime (unless `b.runtime` is given), applies the draft settings that differ from the new session's (before any run), starts uploading the queued files to it and closes the draft. Then `selectSession(id)` and `sendPrompt` (which waits for the uploads). Rejects, keeping the draft, if the session or its settings fail; a retry reuses a session already created. If the draft is replaced or left meanwhile (selectSession/openDraft/closeDraft), the created id is returned but the draft and the current attachments are left untouched. `createSession` in a draft delegates here. | react/src/store.ts:83 |
| `actions.createSession` | `public` | (`b`) => `Promise`\<`string`\> | In connected mode the session runs on `b.machineId`, else on the selected machine. | react/src/store.ts:50 |
| `actions.decide` | `public` | (`approvalId`, `d`, `reason?`) => `Promise`\<`void`\> | - | react/src/store.ts:59 |
| `actions.dismissError` | `public` | () => `void` | - | react/src/store.ts:60 |
| `actions.loadInstallInfo` | `public` | () => `Promise`\<`boolean`\> | Fetches the install/setup commands once into `machines.install`. Resolves `false` on failure (the error is in `machines.error`). | react/src/store.ts:119 |
| `actions.loadMachines` | `public` | () => `Promise`\<`void`\> | Connected mode: fetches the user's computers. The first answer decides `machines.mode` (a 404 means a local daemon: `'local'`, never probed again). Any other failure while the mode is unknown is retried after 2 s, 5 s, 10 s, then every 30 s. Failures go to `machines.error`, never `lastError`. | react/src/store.ts:106 |
| `actions.loadRuntimes` | `public` | () => `Promise`\<`void`\> | - | react/src/store.ts:47 |
| `actions.loadSessions` | `public` | () => `Promise`\<`void`\> | - | react/src/store.ts:48 |
| `actions.openDraft` | `public` | (`runtimeId?`) => `void` | Enters (or updates) draft mode for a new session on `runtimeId`. Changing the runtime resets the draft settings and re-validates queued files; attachments of an open session are dropped. | react/src/store.ts:71 |
| `actions.refreshActiveRuns` | `public` | () => `Promise`\<`void`\> | Fetches active runs across all sessions into `activeRuns` (errors are ignored). | react/src/store.ts:94 |
| `actions.removeAttachment` | `public` | (`localId`) => `void` | - | react/src/store.ts:91 |
| `actions.revokeMachine` | `public` | (`id`) => `Promise`\<`boolean`\> | Disconnects one of the user's computers. Resolves `false` (and records `lastError`) on failure. | react/src/store.ts:121 |
| `actions.selectMachine` | `public` | (`id`) => `void` | Chooses the computer new sessions run on (ignored unless listed). | react/src/store.ts:114 |
| `actions.selectSession` | `public` | (`id`) => `Promise`\<`void`\> | - | react/src/store.ts:51 |
| `actions.sendPrompt` | `public` | (`prompt`) => `Promise`\<`boolean`\> | Resolves `true` when a run was started; `false` when nothing was sent (busy, no session, an attachment failed to upload, or the request failed). Waits for in-flight uploads, sends the ready attachments' ids and clears them on success. | react/src/store.ts:57 |
| `actions.updateSettings` | `public` | (`patch`) => `Promise`\<`boolean`\> | Patches the settings the composer targets: the active session's (applies from its next run) or, in a draft, the draft's (validated against the draft runtime's capabilities like the server would, and applied by `commitDraft`). Resolves `false` and records `lastError` on failure. | react/src/store.ts:66 |
| `actions.watchActiveRuns` | `public` | () => () => `void` | Polls active runs every 3 s while the document is visible (and on local run events) until every returned stop function has been called. | react/src/store.ts:99 |
| `actions.watchMachines` | `public` | (`intervalMs?`) => () => `void` | Polls `loadMachines` while the document is visible, every `intervalMs` (default 3 s; the shortest of all watchers wins), until every returned stop function has been called. Stops by itself in Local Mode. | react/src/store.ts:112 |
| <a id="property-client"></a> `client` | `readonly` | `UncageClient` | The client this store drives (for headless hooks that call it directly). | react/src/store.ts:124 |

## Methods

### attachmentUrl()

```ts
attachmentUrl(attachmentId): string;
```

Defined in: react/src/store.ts:126

URL of an attachment's content (`client.attachmentUrl`).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `attachmentId` | `string` |

#### Returns

`string`

***

### dispose()

```ts
dispose(): void;
```

Defined in: react/src/store.ts:132

Closes the live subscription, stops active-run and machine polling, aborts uploads (dropping attachments
and revoking their previews) and drops in-flight async results. Other state (including
`activeSessionId`) is kept, so `selectSession(activeSessionId)` resumes.

#### Returns

`void`

***

### getState()

```ts
getState(): StoreState;
```

Defined in: react/src/store.ts:44

#### Returns

[`StoreState`](https://uncage.vercel.app/docs/api/react/interfaces/storestate.md)

***

### subscribe()

```ts
subscribe(fn): () => void;
```

Defined in: react/src/store.ts:45

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `fn` | () => `void` |

#### Returns

() => `void`
