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

watch.ts

36 lines · 2.1 KB · TypeScript
import { setWatch } from '../core/rooms.ts'
import { parseWatchConfig } from '../core/wake.ts'
import { handle, optionalString, params } from '../runtime.ts'
import { actor, roomAuthFields } from './shared.ts'

/**
 * Register (or replace) a push wake for a member: the preferred way to hear
 * about new messages. The creator may set one for any member (a spawner wiring
 * its child); others set their own.
 *
 * @param input.room - Room id.
 * @param input.token - Your room token (creator token to set another member's watch).
 * @param input.memberId - Whose watch (default: you).
 * @param input.mode - once | batch (default) | each.
 * @param input.minIntervalSeconds - Throttle between wakes (default 0).
 * @param input.rewakeAfterSeconds - batch only: wake again if no reply after this long (default 300; 0 disables).
 * @param input.includeSystem - Also wake on join/leave lines (default false).
 * @param input.skipFromNames - Sender names treated as your own.
 * @param input.note - Up to 1000 chars added to every wake prompt.
 * @param input.targets - 1 to 5 of: `{ type: 'webhook', url, key?, keyHeaders?, body? }` (your own key, sealed and
 *   sent only to that exact URL) or `{ type: 'job', jobId }` (Kody callers only). Rooms holds no vendor
 *   credentials: Devin, Cursor, and T3 spawner packages wake their children through a webhook they own. Jobs run as the
 *   package owner and are never available to public HTTP callers.
 * @returns `{ status: 'ok', memberId, mode, targets }` (targets described without secrets).
 * @example
 * import watch from 'kody:@kody/rooms/watch'
 * await watch({ room: 'room_…', memberId: 'mem_…', targets: [{ type: 'webhook', url: 'https://…', key: '…' }] })
 */
export default async function watch(input: unknown) {
	return handle(async () => {
		const p = params(input, [...roomAuthFields, 'memberId', 'mode', 'minIntervalSeconds', 'rewakeAfterSeconds', 'includeSystem', 'skipFromNames', 'note', 'targets'])
		const { ctx, room, member } = await actor(p)
		const config = parseWatchConfig(p, { ownerTargets: true })
		return setWatch(ctx, room, member, { memberId: optionalString(p.memberId, 'memberId'), config })
	})
}