← Public packages
@kody/agent-mail
AgentMail inboxes for agents: create/list inboxes, messages, threads, and Svix webhook ingress.
src/get-thread.ts
36 lines · 1.1 KB · TypeScriptimport { agentMailRequest, clean, encodePathSegment } from './core.ts'
export type GetThreadInput = {
threadId: string
/** When set, fetch via inbox-scoped path. */
inboxId?: string
}
/**
* Get one AgentMail thread by id.
* Read-only; uses GET /v0/inboxes/{inbox_id}/threads/{thread_id} or GET /v0/threads/{thread_id}.
*
* @param input.threadId - Thread id (required)
* @param input.inboxId - Optional inbox id for the inbox-scoped path
* @returns Thread object from AgentMail
*
* @example
* import getThread from 'kody:@kody/agent-mail/get-thread'
* const { thread } = await getThread({ threadId: 'thd_123' })
*/
export default async function getThread(input: GetThreadInput) {
const threadId = encodePathSegment(input.threadId, 'threadId')
const path = clean(input.inboxId)
? `/v0/inboxes/${encodePathSegment(input.inboxId, 'inboxId')}/threads/${threadId}`
: `/v0/threads/${threadId}`
const thread = await agentMailRequest({
path,
label: 'AgentMail get thread',
})
return {
inboxId: clean(input.inboxId) || null,
threadId: clean(input.threadId),
thread,
}
}