HOST
PHP
与框架无关的 PHP。Factory::factory() → embed()->createToken()。页面只收到 origin 与 token。
PHP
与框架无关的 PHP。Factory::factory() → embed()->createToken()。页面只收到 origin 与 token。
安装 sveda-ai/php-sdk,mint POST /sveda/embed/token,POST /sveda/session,打开 JS 或 iframe。
AGENT PROMPT
Paste into Cursor
Copy this into Cursor, Claude Code, or any coding agent. It installs Sveda against this stack using public packages.
Install Sveda into this PHP project.
Read:
- https://sveda.dev/docs/hosts/php
- https://sveda.dev/docs/client
- https://sveda.dev/docs/deploy
- https://sveda.dev/llms.txt
Follow the numbered steps on the PHP page. If unsure which frontend this repo uses, ask the user. 1. Run sveda-server
Same sidecar as every other host: pull
ghcr.io/neresson/sveda-server:latest
with Postgres and Redis. CORS must list the PHP origin.
# ghcr.io/neresson/sveda-server:latest
# curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.yaml -o compose.yaml && curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.env -o .env && # Edit .env: a model key, SVEDA_EMBED_HOST_API_KEY, SVEDA_CORS_ORIGINS && && docker compose up -d && curl -s http://127.0.0.1:8787/sveda/ready
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: sveda
POSTGRES_PASSWORD: sveda
POSTGRES_DB: sveda
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sveda -d sveda"]
interval: 5s
timeout: 3s
retries: 10
volumes:
- sveda-postgres:/var/lib/postgresql/data
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
sveda-server:
image: ghcr.io/neresson/sveda-server:latest
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8787:8787"
environment:
SVEDA_BIND: 0.0.0.0:8787
SVEDA_EMBED_ENABLED: "true"
SVEDA_DATABASE_URL: postgres://sveda:sveda@postgres:5432/sveda
SVEDA_REDIS_URL: redis://redis:6379
SVEDA_APP_KEY: ${SVEDA_APP_KEY:-dev-app-key-change-me}
SVEDA_ADMIN_API_KEY: ${SVEDA_ADMIN_API_KEY:-dev-admin-key-change-me}
SVEDA_EMBED_HOST_API_KEY: ${SVEDA_EMBED_HOST_API_KEY:-dev-host-key-change-me}
SVEDA_CORS_ORIGINS: ${SVEDA_CORS_ORIGINS:-*}
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
volumes:
sveda-postgres:# ghcr.io/neresson/sveda-server:latest
# curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.yaml -o compose.yaml && curl -fsSL https://raw.githubusercontent.com/neresson/sveda/main/deploy/compose.env -o .env && # Edit .env: a model key, SVEDA_EMBED_HOST_API_KEY, SVEDA_CORS_ORIGINS && && docker compose up -d && curl -s http://127.0.0.1:8787/sveda/ready
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_USER: sveda
POSTGRES_PASSWORD: sveda
POSTGRES_DB: sveda
healthcheck:
test: ["CMD-SHELL", "pg_isready -U sveda -d sveda"]
interval: 5s
timeout: 3s
retries: 10
volumes:
- sveda-postgres:/var/lib/postgresql/data
redis:
image: redis:7-alpine
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 10
sveda-server:
image: ghcr.io/neresson/sveda-server:latest
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
ports:
- "8787:8787"
environment:
SVEDA_BIND: 0.0.0.0:8787
SVEDA_EMBED_ENABLED: "true"
SVEDA_DATABASE_URL: postgres://sveda:sveda@postgres:5432/sveda
SVEDA_REDIS_URL: redis://redis:6379
SVEDA_APP_KEY: ${SVEDA_APP_KEY:-dev-app-key-change-me}
SVEDA_ADMIN_API_KEY: ${SVEDA_ADMIN_API_KEY:-dev-admin-key-change-me}
SVEDA_EMBED_HOST_API_KEY: ${SVEDA_EMBED_HOST_API_KEY:-dev-host-key-change-me}
SVEDA_CORS_ORIGINS: ${SVEDA_CORS_ORIGINS:-*}
DEEPSEEK_API_KEY: ${DEEPSEEK_API_KEY:-}
volumes:
sveda-postgres: 2. Install sveda-ai/php-sdk
No Laravel. No Symfony. The package talks HTTP to
POST /sveda/embed/token
with
Authorization: Bearer.
composer require sveda-ai/php-sdkcomposer require sveda-ai/php-sdk
3. Host env
The second value must match
SVEDA_EMBED_HOST_API_KEY
on the sidecar. If either is empty, return 503 from the session route.
SVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787
SVEDA_CLIENT_HOST_API_KEY=replace-meSVEDA_CLIENT_BASE_URL=http://127.0.0.1:8787 SVEDA_CLIENT_HOST_API_KEY=replace-me
4. POST /sveda/session
Mint on the server. Optional
host_mcp_url
(and matching token) may ride on
createToken.
Pass optional
policy
(and tighten-only
grants)
when you map the signed-in user to a named policy — see
embed policies.
Empty token → error, do not return 200.
use Sveda\Client\Factory;
$client = Factory::factory()
->withBaseUri(getenv('SVEDA_CLIENT_BASE_URL'))
->withHostApiKey(getenv('SVEDA_CLIENT_HOST_API_KEY'))
->make();
$response = $client->embed()->createToken([
'visitor_id' => 'php-host',
]);
header('content-type: application/json');
echo json_encode([
'origin' => rtrim(getenv('SVEDA_CLIENT_BASE_URL'), '/'),
'token' => $response->token,
'expires_in' => $response->expiresIn,
'appearance' => $response->appearance,
]);use Sveda\Client\Factory;
$client = Factory::factory()
->withBaseUri(getenv('SVEDA_CLIENT_BASE_URL'))
->withHostApiKey(getenv('SVEDA_CLIENT_HOST_API_KEY'))
->make();
$response = $client->embed()->createToken([
'visitor_id' => 'php-host',
]);
header('content-type: application/json');
echo json_encode([
'origin' => rtrim(getenv('SVEDA_CLIENT_BASE_URL'), '/'),
'token' => $response->token,
'expires_in' => $response->expiresIn,
'appearance' => $response->appearance,
]); {
"origin": "http://127.0.0.1:8787",
"token": "sveda_embed_…",
"expires_in": 3600,
"appearance": null
}{
"origin": "http://127.0.0.1:8787",
"token": "sveda_embed_…",
"expires_in": 3600,
"appearance": null
} 5. Page markup
Set origin and session attributes only when the base URL is configured. Serve
sveda-host.js
as a module. Buttons:
data-sveda-open="js"
and
data-sveda-open="iframe".
<html
lang="en"
data-sveda-origin="http://127.0.0.1:8787"
data-sveda-session="/sveda/session"
>
<body>
<button type="button" data-sveda-open="js">Open JS chat</button>
<button type="button" data-sveda-open="iframe">Open iframe chat</button>
<script type="module" src="/sveda-host.js"></script>
</body>
</html><html
lang="en"
data-sveda-origin="http://127.0.0.1:8787"
data-sveda-session="/sveda/session"
>
<body>
<button type="button" data-sveda-open="js">Open JS chat</button>
<button type="button" data-sveda-open="iframe">Open iframe chat</button>
<script type="module" src="/sveda-host.js"></script>
</body>
</html>