Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/rooms

Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.

FollowForkOpen app

Files

shared.ts

16 lines · 742 B · TypeScript
import { invalid } from '../core/errors.ts'
import { resolveMember } from '../core/rooms.ts'
import { currentUserId, kodyCtx, optionalString } from '../runtime.ts'

/** Fields every room-scoped export accepts. */
export const roomAuthFields = ['room', 'token']

/** Resolve `{ room, token }` (or the room creator's Kody identity) to a member. */
export async function actor(p: Record<string, unknown>) {
	const ctx = kodyCtx()
	const room = optionalString(p.room, 'room')
	if (!room) invalid('room is required (the room id, for example from $KODY_ROOM_ID).')
	const token = optionalString(p.token, 'token')
	const kodyUserId = token ? null : await currentUserId()
	return { ctx, ...(await resolveMember(ctx, room, { token, kodyUserId })) }
}