Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions rivetkit-typescript/packages/rivetkit/src/manager/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import invariant from "invariant";
import { z } from "zod";
import { Forbidden, RestrictedFeature } from "@/actor/errors";

import { serializeActorKey } from "@/actor/keys";
import { deserializeActorKey, serializeActorKey } from "@/actor/keys";

import type { Encoding } from "@/client/mod";
import {
Expand Down Expand Up @@ -171,7 +171,7 @@ export function buildManagerRouter(
const actorOutput = await managerDriver.getWithKey({
c,
name,
key: [key], // Convert string to ActorKey array
key: deserializeActorKey(key),
});
if (actorOutput) {
actors.push(actorOutput);
Expand Down Expand Up @@ -242,10 +242,11 @@ export function buildManagerRouter(
const body = c.req.valid("json");

// Check if actor already exists
const actorKey = deserializeActorKey(body.key);
const existingActor = await managerDriver.getWithKey({
c,
name: body.name,
key: [body.key], // Convert string to ActorKey array
key: actorKey,
});

if (existingActor) {
Expand All @@ -259,7 +260,7 @@ export function buildManagerRouter(
const newActor = await managerDriver.getOrCreateWithKey({
c,
name: body.name,
key: [body.key], // Convert string to ActorKey array
key: actorKey,
input: body.input
? cbor.decode(Buffer.from(body.input, "base64"))
: undefined,
Expand Down Expand Up @@ -288,10 +289,14 @@ export function buildManagerRouter(
const body = c.req.valid("json");

// Create actor using the driver
const key =
body.key === undefined || body.key === null
? [crypto.randomUUID()]
: deserializeActorKey(body.key);
const actorOutput = await managerDriver.createActor({
c,
name: body.name,
key: [body.key || crypto.randomUUID()], // Generate key if not provided, convert to ActorKey array
key,
input: body.input
? cbor.decode(Buffer.from(body.input, "base64"))
: undefined,
Expand Down
Loading