-
Notifications
You must be signed in to change notification settings - Fork 139
docs: clean up separation between actors/containers/functions #2394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { Icon, faTs } from "@rivet-gg/icons"; | ||
| import { Icon, faTs, faFunction, faServer, faActors } from "@rivet-gg/icons"; | ||
| import { motion } from "framer-motion"; | ||
| import type { ComponentProps } from "react"; | ||
| import { Button } from "../ui/button"; | ||
|
|
@@ -15,8 +15,20 @@ export function ActorsResources() { | |
| </CardHeader> | ||
| <CardContent className="grid md:grid-cols-2 gap-4"> | ||
| <ExampleLink | ||
| href="docs/quickstart/typescript" | ||
| title="TypeScript" | ||
| href="docs/actors" | ||
| title="Rivet Actors" | ||
| size="md" | ||
| icon={faActors} | ||
| /> | ||
| <ExampleLink | ||
| href="docs/containers" | ||
| title="Rivet Containers" | ||
| size="md" | ||
| icon={faServer} | ||
| /> | ||
| <ExampleLink | ||
| href="docs/functions" | ||
| title="Rivet Functions" | ||
| size="md" | ||
| icon={faTs} | ||
| /> | ||
|
Comment on lines
17
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: grid layout with 3 items in 2 columns will result in uneven distribution - consider adjusting grid-cols-2 to grid-cols-3 or grid-cols-1 |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| # JavaScript Runtime | ||
| # Rivet Actors | ||
|
|
||
| The Rivet JavaScript runtime is built on lightweight JavaScript containers called V8 isolates, providing a high-performance, secure environment for your actor code. | ||
|
|
||
| It's designed to be widely compatible with Node.js and NPM dependencies, making it easy to use familiar libraries and tools. | ||
| Rivet Actors allows you to deploy resilient, stateful services that maintain their state between requests. Use them for websocket servers, game backends, real-time collaboration services, and more. | ||
|
|
||
| <Tip title="Get Started Faster With ActorCore"> | ||
| For getting started quickly using JavaScript, we recommend trying [ActorCore](https://actorcore.org) – our full-stack framework for working with Rivet Actors. | ||
| </Tip> | ||
|
|
||
| ## Basic Setup | ||
| ## What are actors good for? | ||
|
|
||
| - **Stateful Services**: Applications where maintaining state across interactions is critical. For example, **Collaborative Apps** with shared editing and automatic persistence. | ||
| - **Realtime Systems**: Applications requiring fast, in-memory state modifications or push updates to connected clients. For example, **Multiplayer Games** with game rooms and player state. | ||
| - **Long-Running Processes**: Tasks that execute over extended periods or in multiple steps. For example, **AI Agents** with ongoing conversations and stateful tool calls. | ||
| - **Durability**: Processes that must survive crashes and restarts without data loss. For example, **Durable Execution** workflows that continue after system restarts. | ||
| - **Horizontal Scalability**: Systems that need to scale by distributing load across many instances. For example, **Realtime Stream Processing** for stateful event handling. | ||
| - **Local-First Architecture**: Systems that synchronize state between offline clients. For example, **Local-First Sync** between devices. | ||
|
|
||
| ## Quickstart | ||
|
|
||
| ### Step 1: Writing an actor | ||
|
|
||
|
|
@@ -26,22 +33,20 @@ Every actor must export a default object with an async `start` function. Here's | |
|
|
||
| ```ts {{"file": "src/index.ts"}} | ||
| import type { ActorContext } from "@rivet-gg/actor"; | ||
| import * as http from "http"; | ||
| import { Hono } from "hono"; | ||
|
|
||
| export default { | ||
| async start(ctx: ActorContext) { | ||
| // Get the port from environment variables or use a default | ||
| const port = parseInt(process.env.PORT_HTTP || "8080"); | ||
| const port = parseInt(Deno.env.get("PORT_HTTP") || "8080"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Using Deno.env.get() but npm installing @rivet-gg/actor - need to clarify if this is a Deno or Node.js environment |
||
| console.log(`HTTP server running on port ${port}`); | ||
|
|
||
| // Create an HTTP server | ||
| const server = http.createServer((req, res) => { | ||
| res.writeHead(200, { "Content-Type": "text/plain" }); | ||
| res.end(`Hello from Rivet Actor ${ctx.metadata.actor.id} running in ${ctx.metadata.region.id}!`); | ||
| const app = new Hono(); | ||
|
|
||
| app.get("/", (c) => { | ||
| return c.text(`Hello from Rivet Actor ${ctx.metadata.actor.id} running in ${ctx.metadata.region.id}!`); | ||
| }); | ||
|
|
||
| // Start listening on the specified port | ||
| server.listen(port); | ||
| Deno.serve({ port }, app.fetch); | ||
|
|
||
| // Keep the actor running until explicitly destroyed | ||
| await new Promise((resolve) => {}); | ||
|
|
@@ -50,8 +55,8 @@ export default { | |
| ``` | ||
|
|
||
| What this code does: | ||
| - Sets up a simple HTTP server using Node.js's built-in http module | ||
| - Creates a response that includes the actor ID and region information | ||
| - Creates a simple HTTP server using Hono with Deno | ||
| - Sets up a route that returns the actor ID and region information | ||
| - Keeps the actor running indefinitely by returning a promise that never resolves | ||
|
|
||
| <Tip title="Using classes"> | ||
|
|
@@ -74,7 +79,7 @@ Specify the script in your `rivet.json`: | |
|
|
||
| ```json {{ "title": "rivet.json" }} | ||
| { | ||
| "builds": { | ||
| "actors": { | ||
| "my-actor": { | ||
| "script": "./src/index.ts" | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||
| {/* This file is auto-generated by `generateApi.js`. | ||||||||||||||
| * | ||||||||||||||
| * Do not edit this file directly. | ||||||||||||||
| */} | ||||||||||||||
|
|
||||||||||||||
| import { JsonSchemaPreview, PropertyLabel } from '@/components/JsonSchemaPreview'; | ||||||||||||||
| import API_SCHEMA from './../spec.json'; | ||||||||||||||
|
|
||||||||||||||
| # routes.delete | ||||||||||||||
|
|
||||||||||||||
| ## Description | ||||||||||||||
| Deletes a route. | ||||||||||||||
|
|
||||||||||||||
| ## Code Examples | ||||||||||||||
|
|
||||||||||||||
| <CodeGroup title='Request' tag='DELETE' label='https://api.rivet.gg/routes/{id}'> | ||||||||||||||
|
|
||||||||||||||
| ```bash {{ "title": "cURL" }} | ||||||||||||||
| curl -X DELETE 'https://api.rivet.gg/routes/{id}' | ||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| ```ts | ||||||||||||||
| // Create Rivet client | ||||||||||||||
| import { RivetClient } from '@rivet-gg/api'; | ||||||||||||||
| const RIVET = new RivetClient({ token: '[YOUR TOKEN HERE]' }); | ||||||||||||||
|
|
||||||||||||||
| // Make request | ||||||||||||||
| await RIVET.routes.delete({ | ||||||||||||||
| // Add your request body here | ||||||||||||||
| }); | ||||||||||||||
|
Comment on lines
+28
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Example code is missing required 'id' parameter which is marked as required in schema
Suggested change
|
||||||||||||||
| ``` | ||||||||||||||
|
|
||||||||||||||
| </CodeGroup> | ||||||||||||||
|
|
||||||||||||||
| ## Schema | ||||||||||||||
| <JsonSchemaPreview className='not-prose mt-4' title='Request Parameters' schema={{"type":"object","properties":{"id":{"in":"path","type":"string"},"project":{"in":"query","type":"string"},"environment":{"in":"query","type":"string"}},"required":["id"]}} defs={API_SCHEMA.definitions}/> | ||||||||||||||
| <JsonSchemaPreview className='not-prose mt-4' title='Response' schema={{"$ref":"#/components/schemas/RoutesDeleteRouteResponse"}} defs={API_SCHEMA.definitions}/> | ||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| {/* This file is auto-generated by `generateApi.js`. | ||||||
| * | ||||||
| * Do not edit this file directly. | ||||||
| */} | ||||||
|
|
||||||
| import { JsonSchemaPreview, PropertyLabel } from '@/components/JsonSchemaPreview'; | ||||||
| import API_SCHEMA from './../spec.json'; | ||||||
|
|
||||||
| # routes.list | ||||||
|
|
||||||
| ## Description | ||||||
| Lists all routes of the given environment. | ||||||
|
|
||||||
| ## Code Examples | ||||||
|
|
||||||
| <CodeGroup title='Request' tag='GET' label='https://api.rivet.gg/routes'> | ||||||
|
|
||||||
| ```bash {{ "title": "cURL" }} | ||||||
| curl -X GET 'https://api.rivet.gg/routes' | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Missing project and environment query parameters in cURL example |
||||||
| ``` | ||||||
|
|
||||||
| ```ts | ||||||
| // Create Rivet client | ||||||
| import { RivetClient } from '@rivet-gg/api'; | ||||||
| const RIVET = new RivetClient({ token: '[YOUR TOKEN HERE]' }); | ||||||
|
|
||||||
| // Make request | ||||||
| await RIVET.routes.list({ | ||||||
| // Add your request body here | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Example request body should be removed since this GET endpoint doesn't accept a request body
Suggested change
|
||||||
| }); | ||||||
| ``` | ||||||
|
|
||||||
| </CodeGroup> | ||||||
|
|
||||||
| ## Schema | ||||||
| <JsonSchemaPreview className='not-prose mt-4' title='Request Parameters' schema={{"type":"object","properties":{"project":{"in":"query","type":"string"},"environment":{"in":"query","type":"string"}},"required":[]}} defs={API_SCHEMA.definitions}/> | ||||||
| <JsonSchemaPreview className='not-prose mt-4' title='Response' schema={{"$ref":"#/components/schemas/RoutesListRoutesResponse"}} defs={API_SCHEMA.definitions}/> | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {/* This file is auto-generated by `generateApi.js`. | ||
| * | ||
| * Do not edit this file directly. | ||
| */} | ||
|
|
||
| import { JsonSchemaPreview, PropertyLabel } from '@/components/JsonSchemaPreview'; | ||
| import API_SCHEMA from './../spec.json'; | ||
|
|
||
| # routes.update | ||
|
|
||
| ## Description | ||
| Creates or updates a route. | ||
|
|
||
| ## Code Examples | ||
|
|
||
| <CodeGroup title='Request' tag='PUT' label='https://api.rivet.gg/routes/{id}'> | ||
|
|
||
| ```bash {{ "title": "cURL" }} | ||
| # Write the request body to body.json before running | ||
| curl -X PUT -d '@body.json' 'https://api.rivet.gg/routes/{id}' | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ```ts | ||
| // Create Rivet client | ||
| import { RivetClient } from '@rivet-gg/api'; | ||
| const RIVET = new RivetClient({ token: '[YOUR TOKEN HERE]' }); | ||
|
|
||
| // Make request | ||
| await RIVET.routes.update({ | ||
| // Add your request body here | ||
| }); | ||
| ``` | ||
|
|
||
| </CodeGroup> | ||
|
|
||
| ## Schema | ||
| <JsonSchemaPreview className='not-prose mt-4' title='Request Parameters' schema={{"type":"object","properties":{"id":{"in":"path","type":"string"},"project":{"in":"query","type":"string"},"environment":{"in":"query","type":"string"}},"required":["id"]}} defs={API_SCHEMA.definitions}/> | ||
| <JsonSchemaPreview className='not-prose mt-4' title='Request' schema={{"$ref":"#/components/schemas/RoutesUpdateRouteBody"}} defs={API_SCHEMA.definitions}/> | ||
| <JsonSchemaPreview className='not-prose mt-4' title='Response' schema={{"$ref":"#/components/schemas/RoutesUpdateRouteResponse"}} defs={API_SCHEMA.definitions}/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: using faTs icon for Functions section seems incorrect - should use faFunction icon instead