|
| 1 | +# FreeStyle |
| 2 | + |
| 3 | +Deploy Rivet Actors to [FreeStyle.sh](https://docs.freestyle.sh/), a cloud platform for running AI-generated code with built-in security and scalability. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +<Steps> |
| 8 | +<Step title="Install packages"> |
| 9 | + |
| 10 | +Install RivetKit and create your registry: |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install rivetkit |
| 14 | +``` |
| 15 | + |
| 16 | +</Step> |
| 17 | + |
| 18 | +<Step title="Create namespace"> |
| 19 | + |
| 20 | +Create a namespace on Rivet Cloud to manage your FreeStyle actors. This will be used to isolate your actors and manage permissions. |
| 21 | + |
| 22 | +</Step> |
| 23 | + |
| 24 | +<Step title="Configure serverless driver"> |
| 25 | + |
| 26 | +Update your server code to use the serverless engine driver: |
| 27 | + |
| 28 | +```typescript {{"title":"server.ts"}} |
| 29 | +import { registry } from "./registry"; |
| 30 | +import { createEngineDriver } from "rivetkit/engine"; |
| 31 | + |
| 32 | +registry.startServerless({ |
| 33 | + driver: createEngineDriver({ |
| 34 | + endpoint: "api.rivet.gg", |
| 35 | + // For self-hosted instances: |
| 36 | + // endpoint: "http://127.0.0.1:6420", |
| 37 | + runnerName: "freestyle-runner", |
| 38 | + namespace: process.env.RIVET_NAMESPACE_NAME, |
| 39 | + }), |
| 40 | + inspector: { |
| 41 | + enabled: true, |
| 42 | + }, |
| 43 | +}); |
| 44 | + |
| 45 | +// FreeStyle uses Deno under the hood for web deployments |
| 46 | +// @ts-ignore |
| 47 | +Deno.serve(app.fetch); |
| 48 | +``` |
| 49 | + |
| 50 | +**Configuration Requirements:** |
| 51 | + |
| 52 | +- `endpoint` - Rivet API endpoint (use "api.rivet.gg" for Rivet Cloud) |
| 53 | +- `namespace` - Your Rivet namespace for actor isolation |
| 54 | +- `inspector.enabled` - Enable debugging and monitoring |
| 55 | + |
| 56 | +</Step> |
| 57 | + |
| 58 | +<Step title="Deploy to FreeStyle"> |
| 59 | + |
| 60 | +Deploy your application to FreeStyle with the correct configuration. Create a deployment script or add this to your existing deployment process: |
| 61 | + |
| 62 | +```typescript |
| 63 | +const res = await freestyle.deployWeb(buildDir, { |
| 64 | + timeout: 120, // Increases max request lifetime on the runner |
| 65 | + entrypoint: "server.ts", // File which starts serverless runner |
| 66 | + domains: [process.env.FREESTYLE_DOMAIN], |
| 67 | + build: false, |
| 68 | +}); |
| 69 | +``` |
| 70 | + |
| 71 | +It's important to keep `timeout` set to `120`. Details on `buildDir` and other settings are available on [FreeStyle docs](https://docs.freestyle.sh/web/web). |
| 72 | + |
| 73 | +Run this deployment script to push your application to FreeStyle. |
| 74 | + |
| 75 | +**Deployment Configuration:** |
| 76 | + |
| 77 | +- `timeout: 120` - Set timeout to 120 seconds for actor operations |
| 78 | +- `entrypoint: "server.ts"` - Entry point file with your serverless setup |
| 79 | +- `domains` - Your FreeStyle domain(s) |
| 80 | +- `build: false` - Disable build if you're pre-building your assets |
| 81 | + |
| 82 | +</Step> |
| 83 | + |
| 84 | +<Step title="Configure runner"> |
| 85 | + |
| 86 | +Update the runner configuration on the Rivet side to connect with your FreeStyle deployment. Create a configuration script and run it after your FreeStyle deployment is live: |
| 87 | + |
| 88 | +```typescript |
| 89 | +import { RivetClient } from "rivetkit"; |
| 90 | + |
| 91 | +const rivet = new RivetClient({ |
| 92 | + endpoint: "api.rivet.gg", |
| 93 | + token: process.env.RIVET_API_TOKEN, |
| 94 | +}); |
| 95 | + |
| 96 | +await rivet.runnerConfigs.upsert(process.env.RIVET_RUNNER_NAME, { |
| 97 | + serverless: { |
| 98 | + url: `https://${process.env.FREESTYLE_DOMAIN}/start`, |
| 99 | + runnersMargin: 1, |
| 100 | + minRunners: 1, |
| 101 | + maxRunners: 1, |
| 102 | + slotsPerRunner: 1, |
| 103 | + requestLifespan: 110, |
| 104 | + }, |
| 105 | + namespace: process.env.RIVET_NAMESPACE_NAME, |
| 106 | +}); |
| 107 | +``` |
| 108 | + |
| 109 | +Execute this configuration script to register your FreeStyle deployment with Rivet. |
| 110 | + |
| 111 | +**Runner Configuration:** |
| 112 | + |
| 113 | +- `url` - FreeStyle deployment URL with `/start` endpoint |
| 114 | +- `runnersMargin` - Buffer of runners to maintain |
| 115 | +- `minRunners/maxRunners` - Scaling limits |
| 116 | +- `slotsPerRunner` - Concurrent actors per runner |
| 117 | +- `requestLifespan` - Request timeout (slightly less than FreeStyle timeout) |
| 118 | + |
| 119 | +</Step> |
| 120 | +</Steps> |
| 121 | + |
| 122 | +## Examples |
| 123 | + |
| 124 | +<CardGroup> |
| 125 | +<Card title="FreeStyle + Rivet" href="https://github.com/rivet-dev/rivetkit/tree/main/examples/freestyle" target="_blank"> |
| 126 | +Complete example of deploying Rivet actors to FreeStyle.sh. |
| 127 | +</Card> |
| 128 | +</CardGroup> |
| 129 | + |
| 130 | +<Note> |
| 131 | +FreeStyle provides built-in security for running untrusted AI-generated code, making it ideal for AI agent applications and workflow engines. |
| 132 | +</Note> |
| 133 | + |
| 134 | +## Advanced |
| 135 | + |
| 136 | +### Debugging |
| 137 | + |
| 138 | +Enable the inspector for debugging your actors: |
| 139 | + |
| 140 | +```typescript |
| 141 | +registry.startServerless({ |
| 142 | + inspector: { |
| 143 | + enabled: true |
| 144 | + }, |
| 145 | + // ... other options |
| 146 | +}); |
| 147 | +``` |
| 148 | + |
| 149 | +Access the inspector on the Rivet cloud or Rivet instance. |
| 150 | + |
0 commit comments