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

spawn-info.ts

34 lines · 1.6 KB · TypeScript
import { buildPromptSection, envNames } from '../core/prompts.ts'
import { createInvites, roomStatus } from '../core/rooms.ts'
import { handle, params } from '../runtime.ts'
import { actor, roomAuthFields } from './shared.ts'

/**
 * Plain-data spawn helper for any spawner (other orgs cannot import this
 * package, so pass the result along). Mints one join code for one child.
 * `promptSection` names env vars only; put `env` values in the child's
 * secrets or environment, never in prompt text.
 *
 * @param input.room - Room id.
 * @param input.token - Creator token (optional for the creating Kody user).
 * @param input.nameHint - Label for the invite (for your records).
 * @returns `{ status: 'ok', id, promptSection, env: { KODY_ROOM_ID, KODY_ROOM_JOIN_CODE, KODY_ROOM_URL }, expiresAt }`
 * @example
 * import spawnInfo from 'kody:@kody/rooms/spawn-info'
 * const { promptSection, env } = await spawnInfo({ room: 'room_…', nameHint: 'devin-child' })
 */
export default async function spawnInfo(input: unknown) {
	return handle(async () => {
		const p = params(input, [...roomAuthFields, 'nameHint'])
		const { ctx, room, member } = await actor(p)
		const [invite] = await createInvites(ctx, room, member, { count: 1, nameHint: p.nameHint as string | null })
		const { room: info } = await roomStatus(ctx, room, null)
		return {
			status: 'ok' as const,
			id: room.id,
			promptSection: buildPromptSection({ roomId: room.id, appUrl: info.appUrl, purpose: info.purpose, viewUrl: info.viewUrl }),
			env: { [envNames.roomId]: room.id, [envNames.joinCode]: invite!.code, [envNames.appUrl]: info.appUrl ?? '' },
			expiresAt: invite!.expiresAt,
		}
	})
}