# API, home sharing and Discord — 0.7.0

Open **Connections** from the installing Windows account. No extra owner password is required.
The owner controls the listener, credentials, assigned profiles and models, and Discord settings.
These integrations are application features, not a replacement for Windows account security.

## Home browser access

1. On the host, connect a local engine and choose an installed model.
2. In Connections, create a separate access key for each device. Copy it when displayed;
   the app stores only the hash. Assign the intended profile and model, with request limits.
3. Choose an unused port (default 8765), enable home-network access and start sharing.
4. On a device on the same network, open `http://HOST-PC-IP:8765/`. Enter its key and chat.
   Find the host's private IPv4 address in Windows network properties. If Windows asks,
   allow the app only on your intended private network. The app does not add firewall rules.

The host and panel must stay running. Revocation takes effect on the next request.
No owner controls, project files, shell tools or private chat history are exposed by the family page.
The assigned local model receives the submitted conversation. The page keeps recent messages
in memory until cleared or closed. The server does not save external chat transcripts.

Plain HTTP does not encrypt prompts or keys in transit. Use only a trusted home network or
configure an HTTPS reverse proxy. Do not port-forward this HTTP listener to the public internet.
The listener is off until started by the owner and stops when the panel exits; start it again
after reopening the app. Saved settings are retained, but the bot and listener do not autostart.

## FiveM / RedM and other scripts

The release implements a **text chat subset** of the OpenAI-shaped API:

- `GET /v1/models` — returns the one model assigned to the key.
- `POST /v1/chat/completions` — text messages; `stream:false`; no external tools.
- `Authorization: Bearer YOUR_DEVICE_OR_SCRIPT_KEY`.
- `model` can be the assigned model name or `assigned`.
- Up to 24 messages, 12,000 total text characters, 64 KB request bodies;
  output is limited by host settings and capped at 1,024 tokens.
- `max_tokens` can reduce the output budget. Streaming, image input, audio, embeddings,
  tool calls and provider-specific endpoint extensions are not implemented by this API.
- Daily quotas count attempted authenticated requests and use UTC; a failed inference can
  consume a request. Rate limits are request limits, not provider billing or token accounting.

Example server-side Lua (adapt to your script rather than replacing its source blindly):

```lua
-- Keep the key in a non-replicated server convar, never client/shared/NUI code.
local base = GetConvar('ag_ai_base', 'http://127.0.0.1:8765')
local key = GetConvar('ag_ai_key', '')
PerformHttpRequest(base .. '/v1/chat/completions', function(status, body)
    if status ~= 200 then
        print(('AI request needs attention: HTTP %s'):format(status))
        return
    end
    local ok, result = pcall(json.decode, body)
    if ok and result.choices and result.choices[1] then
        print(result.choices[1].message.content)
    end
end, 'POST', json.encode({
    model = 'assigned', stream = false,
    messages = {{role = 'user', content = 'Write a short roleplay greeting.'}}
}), {['Content-Type'] = 'application/json', ['Authorization'] = 'Bearer ' .. key})
```

On Nitrado, `127.0.0.1` means the hosted server, not your home PC. A separately configured,
authenticated secure network route/proxy is required. Script compatibility must be checked
against its configurable URL, request format, endpoint and response expectations.
An app-issued key cannot replace a script license or an outside provider's key.

## Credential vault

Provider tokens are encrypted using Windows DPAPI for the signed-in Windows account.
They cannot be revealed in the UI; replace or remove them there. Copying the vault to a
different Windows account/computer may make credentials unreadable. Re-enter them instead.
Do not include private-data in public ZIPs or website deployments. Outside provider entries
are storage only in this release: a saved OpenAI/Anthropic/Google key does not add cloud inference.
Discord uses its saved token only when the owner explicitly starts the bot.

## Discord setup

1. Create a bot in the Discord Developer Portal. Save its bot token as the `discord` credential.
2. Invite it to your test server with `bot` and `applications.commands` scopes. The portal's
   OAuth2 URL generator can create the invitation. The panel also shows an invite link after
   a successful bot login, including when guild command synchronization fails.
3. Copy the server/guild ID and allowed AI text-channel IDs (Developer Mode enables Copy ID).
4. Choose the bot profile, local model, assistant, and optional allowed users/roles.
   Both a user allowlist and role allowlist must match if both are configured.
5. Enable online mode for the bot profile and allow owner internet access. Save settings,
   then Start bot. Refresh status after it connects. Slash commands are registered only in
   the configured server. This does not modify other guilds or create accounts.
6. Try `/ask` in an allowed channel. Prompts are at most 4,000 characters, responses are
   truncated to 1,900 characters, and each user/channel has a ten-second cooldown.

The bot uses outbound Discord Gateway connections; it does not need an inbound public port.
Discord transports its messages; local inference runs on your host. No Message Content intent
is required for these slash commands. Welcome messages require enabling Server Members Intent
in both the Developer Portal and the panel. Voice, music playback, slash-command image/audio
generation, reaction roles, automod filters, scheduled events and provider plugins are not
implemented by this release. The assistant roles are not copies of hosted model weights.

### Administration commands

Moderation is off until enabled by the panel owner. Discord also controls permissions and
role hierarchy. Grant only permissions for features you enable. The bot role must be above
the target member/role. Owner/self/equal-or-higher targets are protected.

- `/warn`, `/timeout`, `/untimeout`: require Moderate Members.
- `/kick`, `/ban`: require their corresponding permissions and `confirm:true`.
  Ban keeps existing message history.
- `/purge`: requires Manage Messages, deletes at most 50 messages, `confirm:true`.
- `/role_add`, `/role_remove`: require Manage Roles. Managed/default/privileged admin
  roles are protected. Hierarchy and both member/bot permissions are checked.
- `/lock`, `/unlock`: require Manage Channels. Change only @everyone's send_messages
  overwrite and save/restore its previous value. Other role overrides can still allow access.
- `/slowmode`: requires Manage Channels, 0–21600 seconds.
- `/ticket`: creates one private text channel per requester, visible to the requester,
  bot and Discord administrators. Other support roles are not automatically added.
- `/close_ticket`: requires Manage Channels and confirmation inside a bot-created ticket;
  channel deletion is permanent.
- `/setup_community`: requires Manage Channels, invoking Manage Server and confirmation.
  Creates missing rules/announcements/ai-chat/support text channels, retaining existing names.
  It does not set up Discord's Community onboarding system or overwrite your server layout.

Actions are recorded in private `discord-audit.jsonl`, rotated to one previous file at 2 MB;
an optional Discord log channel receives action notices. A warning record does not guarantee
that a user's direct messages were open. AI text never runs moderation commands automatically.
Conversation memory is optional, per user/channel, limited to recent messages in process memory,
and cleared when stopped. Bot authentication failures do not trigger repeated login attempts.
Live permissions, invitation and moderation results still require a real test-server check.
