New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

actor-core

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actor-core

npmnpm
Version
0.5.0
Version published
Maintainers
1
Created
Source

ActorCore

The Stateful Serverless Framework

Build AI agents, realtime apps, game servers, and more.

Supports Rivet, Cloudflare Workers, Bun, and Node.js.

Resources

  • Quickstart
  • Documentation
  • Examples

Getting Started

Step 1: Installation

# npm
npm add actor-core

# pnpm
pnpm add actor-core

# Yarn
yarn add actor-core

# Bun
bun add actor-core

Step 2: Create an Actor

import { Actor, type Rpc } from "actor-core";

export interface State {
    messages: { username: string; message: string }[];
}

export default class ChatRoom extends Actor<State> {
    // initialize this._state
    _onInitialize() {
        return { messages: [] };
    }

    // receive an remote procedure call from the client
    sendMessage(rpc: Rpc<ChatRoom>, username: string, message: string) {
        // save message to persistent storage
        this._state.messages.push({ username, message });

        // broadcast message to all clients
        this._broadcast("newMessage", username, message);
    }
}

Step 3: Connect to Actor

import { Client } from "actor-core/client";
import type ChatRoom from "../src/chat-room.ts";

const client = new Client(/* manager endpoint */);

// connect to chat room
const chatRoom = await client.get<ChatRoom>({ name: "chat" });

// listen for new messages
chatRoom.on("newMessage", (username: string, message: string) =>
    console.log(`Message from ${username}: ${message}`),
);

// send message to room
await chatRoom.sendMessage("william", "All the world's a stage.");

Step 4: Deploy

Deploy to your platform of choice:

Community & Support

License

Apache 2.0

FAQs

Package last updated on 02 Mar 2025

Related posts