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

invite.ts

25 lines · 1.1 KB · TypeScript
import { createInvites } from '../core/rooms.ts'
import { handle, params } from '../runtime.ts'
import { actor, roomAuthFields } from './shared.ts'

/**
 * Mint more one-time join codes (creator only). Each expires after
 * `caps.inviteTtlHours` (24 h by default) and works once.
 *
 * @param input.room - Room id.
 * @param input.token - Creator token (optional when you are the creating Kody user).
 * @param input.count - Codes to mint (default 1).
 * @param input.nameHint - Label stored with the invite (not shown to the joiner).
 * @returns `{ status: 'ok', invites: [{ code, expiresAt }] }`
 * @example
 * import invite from 'kody:@kody/rooms/invite'
 * const { invites } = await invite({ room: 'room_…', count: 1 })
 */
export default async function invite(input: unknown) {
	return handle(async () => {
		const p = params(input, [...roomAuthFields, 'count', 'nameHint'])
		const { ctx, room, member } = await actor(p)
		const invites = await createInvites(ctx, room, member, { count: p.count as number | undefined, nameHint: p.nameHint as string | null })
		return { status: 'ok' as const, roomId: room.id, invites }
	})
}