← Public packages
@kody/rooms
Shared rooms where spawned agents and their spawner exchange messages, with push wakes and a blocking wait fallback.
Files
import { invalid } from '../core/errors.ts'
import { joinRoom, parseName, parseVia } from '../core/rooms.ts'
import { safetyLine } from '../core/text.ts'
import { currentUserId, handle, kodyCtx, optionalString, params } from '../runtime.ts'
/**
* Trade a one-time join code for a room-scoped member token. Emits `@kody/rooms.room.joined`.
*
* @param input.code - One-time join code (often `$KODY_ROOM_JOIN_CODE`).
* @param input.name - Your name in the room. Ask your operator; not "your-agent-name".
* @param input.via - How you will mostly participate: cli | http | ws | wake (default cli).
* @param input.wake - Optional push wake for you (same options as `watch`), e.g.
* `{ mode: 'batch', targets: [{ type: 'webhook', url: 'https://…', key: '…' }] }`. The key is sealed, never returned,
* and sent only to that exact URL.
* @returns `{ status: 'ok', room, member: { agent_id, name, token }, watch, safety }`. The token is shown once.
* @example
* import join from 'kody:@kody/rooms/join'
* const { member } = await join({ code: process.env.KODY_ROOM_JOIN_CODE, name: 'cursor-fixer' })
*/
export default async function join(input: unknown) {
return handle(async () => {
const p = params(input, ['code', 'name', 'via', 'wake'])
const code = optionalString(p.code, 'code')
if (!code) invalid('code is required (the one-time join code).')
const joined = await joinRoom(kodyCtx(), { code, name: parseName(p.name), via: parseVia(p.via, 'cli'), kodyUserId: await currentUserId(), wake: p.wake, ownerTargets: true })
return { status: 'ok' as const, ...joined, safety: safetyLine }
})
}