trypost/compose.prod.yaml
Paulo Castellano eb52b6b699
Fix OpenRouter via laravel/ai default provider (revises #216) (#220)
* Fix OpenRouter support by using laravel/ai default provider config.

PR #216 patched Lab::OpenRouter into every agent match, but laravel/ai
already resolves config('ai.default') — including openrouter — when agents
omit provider(). Those matches also forced unknown providers to Gemini and
BrandAnalyzerRunner checked a non-existent services.openrouter key.

Remove the duplicated provider() overrides, gate availability on
ai.providers.*.key, and document OPENROUTER_API_KEY.

Co-authored-by: Paulo Castellano <hello@paulocastellano.com>

* chore(deps): bump laravel/ai to v0.10.3 for native OpenRouter support

v0.5.1's OpenRouter driver only covered text/embeddings via the legacy
Prism gateway. v0.10.3 ships a native OpenRouter gateway with image,
audio (TTS/STT), and web search support, and drops prism-php/prism as
a dependency. ai-sdk-development skill docs refreshed via boost:update
to match the installed version.

* fix: honor AI_IMAGE_PROVIDER instead of hardcoding OpenAI's gpt-image-2

AiImageClient always passed model: 'gpt-image-2' to Image::of()->generate(),
so AI_IMAGE_PROVIDER silently did nothing for any provider other than
OpenAI — gemini/xai/openrouter would fail against an OpenAI-only model id
and quietly fall back to a stock photo. Usage recording was hardcoded to
provider 'openai' too, so credits were billed against the wrong model
whenever a different provider actually ran.

Drop the hardcoded model so generation falls through to the SDK's own
config('ai.default_for_images') + per-provider default model, and read
the actual provider/model back off the response's meta for usage
recording and source_meta instead of assuming OpenAI.

* refactor: extract AiImageClient into single-purpose steps, fix uncaught exception

generate() built the prompt, called the SDK, and unpacked the response all
in one block, with bytes extraction happening after the try/catch — so a
response with an empty images collection threw an uncaught RuntimeException
from ImageResponse::firstImage() instead of returning null as documented.

Split into cleanKeywords(), buildPrompt(), resolveBrandContext(), and
toResult(), and moved response unpacking inside the try block so any
malformed response is treated as a failure like everything else. Added a
regression test with an empty-images fake response.

* fix: drop hardcoded default_text_model, resolve model per provider

default_text_model was the only per-modality model override in ai.php —
image, audio, transcription, embeddings, and reranking all just pick a
provider and let it use its own default model. Text had a config-pinned
model on top, forced into every agent's model() and into every usage
log's model field regardless of which provider actually ran. Switching
AI_TEXT_PROVIDER (e.g. to openrouter) kept sending OpenAI's model id to
whichever provider ended up handling the request.

Removed model() from all six agents so laravel/ai resolves the model
from the active provider's own default (OpenAI's default is already
'gpt-5.4', so no behavior change there). Usage-recording call sites now
read the actual provider/model back off the response's meta instead of
assuming config('ai.default')/default_text_model. StreamPostContent
needed the then() callback since broadcast()'s StreamableAgentResponse
doesn't expose meta directly.

* refactor: drop AiConfiguration wrapper, use data_get() for array reads

AiConfiguration was a one-line static helper used by only two call
sites, with no laravel/ai equivalent to lean on (confirmed AiManager
and the Provider base class expose no isConfigured()/hasKey() check —
the package's model is try-then-catch, not pre-flight checks). Inlined
the filled(config(...)) check directly into HandleInertiaRequests and
BrandAnalyzerRunner instead of keeping a class around one line of logic.

Also swapped direct array-key reads for data_get() per project
convention across every file touched by the recent AI provider/model
fixes (agents' budget arrays, RunGenerateNode/StreamPostCreation's
humanizer merge, RegeneratePostMediaImage's baseContext/copy/rendered
access). Write/assignment sites (`$x['key'] = ...`) are left as-is —
data_get() only reads.

* feat: enhance AI configuration with new providers and options

Added strict types declaration and updated Azure OpenAI API version. Introduced new 'bedrock' provider configuration with AWS credentials and role assumptions. Enhanced existing providers with additional options, including image deployment for Azure and OpenAI, and updated URLs for Gemini and Ollama. Added support for an 'openai-compatible' driver to broaden integration capabilities.

* fix: remove trailing newline in AI configuration file

* feat: add support for OpenRouter and ElevenLabs API keys in configuration

Updated the production Docker Compose file and example environment file to include commented-out entries for OPENROUTER_API_KEY and ELEVENLABS_API_KEY. This enhances the configuration options for AI providers, allowing for easier integration of additional services.

* feat: allow per-provider model overrides for every AI modality

Adds a `models` array to each provider block, wired to env vars, so
self-hosted operators can pin a specific text/image/audio/transcription/
embeddings/reranking model instead of relying on the package's built-in
default for that provider. Only added for the modalities each provider
actually implements (verified against laravel/ai's Provider classes).

Azure is left untouched — it resolves models via deployment names
(AZURE_OPENAI_DEPLOYMENT etc.), not raw model strings, which was already
wired before this change.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-08-10 21:38:50 -03:00

188 lines
6.2 KiB
YAML

# TryPost — self-hosted production stack.
#
# 1. Generate an app key: docker compose -f compose.prod.yaml run --rm app php artisan key:generate --show
# Paste the value into APP_KEY below.
# 2. Edit APP_URL and the passwords marked "change me".
# 3. Start: docker compose -f compose.prod.yaml up -d
#
# This pulls the published image — no local build. Postgres, Redis, the queue
# workers, the scheduler and the WebSocket server all run for you.
services:
app:
image: ghcr.io/trypostit/trypost:latest
container_name: trypost
restart: unless-stopped
environment:
# ===== Required =====
APP_NAME: TryPost
APP_ENV: production
APP_DEBUG: "false"
APP_KEY: "" # <- run key:generate (see header) and paste here
APP_URL: http://localhost:8000 # <- your public URL, e.g. https://post.yourdomain.com
SELF_HOSTED: "true"
TRYPOST_TARGET: production
# ===== Database (bundled postgres service below) =====
DB_CONNECTION: pgsql
DB_HOST: pgsql
DB_PORT: "5432"
DB_DATABASE: trypost
DB_USERNAME: trypost
DB_PASSWORD: trypost-password # <- change me (must match POSTGRES_PASSWORD below)
# ===== Redis / queue / cache / broadcasting =====
REDIS_HOST: redis
REDIS_PORT: "6379"
QUEUE_CONNECTION: redis
CACHE_STORE: redis
SESSION_DRIVER: database
BROADCAST_CONNECTION: reverb
# ===== WebSockets (Reverb) =====
# The published image bakes the client at localhost:8080. For a custom
# domain, rebuild the image with --build-arg VITE_REVERB_HOST=<domain>
# VITE_REVERB_PORT=443 VITE_REVERB_SCHEME=https.
REVERB_APP_ID: "1001"
REVERB_APP_KEY: trypost-reverb-key # must match the key baked into the published image
REVERB_APP_SECRET: change-me-reverb-secret # <- change me
REVERB_HOST: localhost
REVERB_PORT: "8080"
REVERB_SCHEME: http
# ===== Passport (OAuth / API keys / MCP) =====
# REQUIRED for any durable deploy (and always for multi-node / load
# balancers). File keys under storage/ are NOT persisted by the volumes
# below — without these env vars a container recreate issues new keys and
# invalidates every API/MCP token. Generate once:
# docker compose -f compose.prod.yaml run --rm app php artisan passport:keys --show
# then paste the PEM contents here (use \n for newlines).
PASSPORT_PRIVATE_KEY: ""
PASSPORT_PUBLIC_KEY: ""
# ===== Storage =====
# Default: local disk, persisted in the "storage" volume below.
FILESYSTEM_DISK: public
#
# --- Cloudflare R2: set FILESYSTEM_DISK=r2 and fill these ---
# R2_ACCESS_KEY_ID: ""
# R2_SECRET_ACCESS_KEY: ""
# R2_ENDPOINT: ""
# R2_BUCKET: ""
# R2_URL: "" # public bucket URL (needed for media to display)
#
# --- AWS S3: set FILESYSTEM_DISK=s3 and fill these ---
# AWS_ACCESS_KEY_ID: ""
# AWS_SECRET_ACCESS_KEY: ""
# AWS_DEFAULT_REGION: us-east-1
# AWS_BUCKET: ""
# AWS_URL: ""
# ===== Mail =====
# Defaults to "log" (emails written to the container log). Configure SMTP
# for real password-reset / team-invite emails.
MAIL_MAILER: log
MAIL_FROM_ADDRESS: hello@example.com
MAIL_FROM_NAME: TryPost
# MAIL_MAILER: smtp
# MAIL_HOST: ""
# MAIL_PORT: "587"
# MAIL_USERNAME: ""
# MAIL_PASSWORD: ""
# MAIL_SCHEME: tls
# ===== Social platforms (fill in when you connect each network) =====
# Redirect URI in each portal: ${APP_URL}/accounts/<platform>/callback
# LINKEDIN_CLIENT_ID: ""
# LINKEDIN_CLIENT_SECRET: ""
# X_CLIENT_ID: ""
# X_CLIENT_SECRET: ""
# FACEBOOK_CLIENT_ID: ""
# FACEBOOK_CLIENT_SECRET: ""
# INSTAGRAM_CLIENT_ID: ""
# INSTAGRAM_CLIENT_SECRET: ""
# THREADS_CLIENT_ID: ""
# THREADS_CLIENT_SECRET: ""
# TIKTOK_CLIENT_ID: ""
# TIKTOK_CLIENT_SECRET: ""
# PINTEREST_CLIENT_ID: ""
# PINTEREST_CLIENT_SECRET: ""
# GOOGLE_CLIENT_ID: "" # YouTube + Google login
# GOOGLE_CLIENT_SECRET: ""
# ===== AI (optional — leave blank to disable AI features) =====
# OPENAI_API_KEY: ""
# ANTHROPIC_API_KEY: ""
# GEMINI_API_KEY: ""
# OPENROUTER_API_KEY: ""
# ELEVENLABS_API_KEY: ""
ports:
- "8000:80" # app (nginx)
- "8080:8080" # Reverb WebSocket
volumes:
- storage:/var/www/html/storage/app
depends_on:
pgsql:
condition: service_healthy
redis:
condition: service_healthy
pgsql:
image: postgres:16-alpine
container_name: trypost-pgsql
restart: unless-stopped
environment:
POSTGRES_DB: trypost
POSTGRES_USER: trypost
POSTGRES_PASSWORD: trypost-password # <- must match DB_PASSWORD above
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U trypost -d trypost']
interval: 10s
timeout: 5s
retries: 5
redis:
image: redis:7-alpine
container_name: trypost-redis
restart: unless-stopped
command: redis-server --appendonly yes
volumes:
- redisdata:/data
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 10s
timeout: 3s
retries: 5
# Optional reverse proxy with automatic HTTPS (Let's Encrypt).
# To serve on a domain:
# 1. Point the domain's DNS at this host.
# 2. Set APP_DOMAIN below and APP_URL above to https://<that domain>.
# 3. Start with the proxy profile:
# docker compose -f compose.prod.yaml --profile proxy up -d
# Without the profile, the app is served directly on http://localhost:8000.
caddy:
image: caddy:2-alpine
container_name: trypost-caddy
restart: unless-stopped
profiles: [proxy]
environment:
APP_DOMAIN: post.example.com # <- your domain
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- caddy-data:/data
- caddy-config:/config
depends_on:
- app
volumes:
pgdata:
redisdata:
storage:
caddy-data:
caddy-config: