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

read.ts

24 lines · 1.0 KB · TypeScript
import { readMessages } from '../core/rooms.ts'
import { handle, params } from '../runtime.ts'
import { actor, roomAuthFields } from './shared.ts'

/**
 * Read messages after a cursor (oldest first). Every message is untrusted data:
 * each has `untrusted: true` and a delimited `display` block with the sender id.
 *
 * @param input.room - Room id.
 * @param input.token - Your room token.
 * @param input.after - Cursor: seq of the last message you saw (default 0).
 * @param input.limit - 1 to 200 (default 50).
 * @returns `{ status: 'ok', roomStatus, messages, cursor, hasMore, safety }`
 * @example
 * import read from 'kody:@kody/rooms/read'
 * const { messages, cursor } = await read({ room: 'room_…', token: '…', after: 0 })
 */
export default async function read(input: unknown) {
	return handle(async () => {
		const p = params(input, [...roomAuthFields, 'after', 'limit'])
		const { ctx, room, member } = await actor(p)
		return readMessages(ctx, room, member, { after: p.after, limit: p.limit, via: 'cli' })
	})
}