Client methods
Call the API from the host
Use these methods when the host owns the screen. They return the server payload. They do not update a ChatController.
Conversations
const chats = client.chats();
const page = await chats.list({ page: 1, rowsPerPage: 20 });
const history = await chats.history(0, 20);
const saved = await chats.saved();
const workspace = await chats.get(id);
await chats.update(id, { title: 'Staff engineers' });
await chats.write({ id, title, payload });
await chats.delete(id);
const restored = await chats.restore(legacySessionId);
const retried = await chats.restore(legacySessionId, true);
list pages GET /chats by page number and returns { data, count }. history calls the same endpoint with an offset and returns the server page: chats, total, offset, limit, has_more. Page size defaults to 20 and is capped at 100. Offset is capped at 100000.
saved reads GET /searches and accepts either an array or { searches }. get reads one workspace and throws on 404. chat(id).workspace() parses that payload and returns null on 404.
update reads the saved workspace and posts that payload back with the new title. write posts the { id, title, payload } you pass and does not read first. restore posts { session_id, retry? } to /searches/restore and returns { search, active }.
Older stored messages, separate from the in-memory window:
const transcript = await client.chat(id).transcript(earliestMessageId);
GET /searches/transcript returns 50 messages, plus has_more, total_messages, and restorable. Omit before for the first page. Pass the id of the earliest message already shown to read the page before it.
Turns
const session = client.chat(id);
for await (const event of session.interact({
message: 'Add Austin',
turnId,
stateVersion,
requirements,
})) {
// includes the closing event: outline `result`, or agent `done` / `new_search`
}
await session.cancel(turnId);
for await (const snapshot of session.follow(signal)) {
// snapshot.chat, snapshot.payload, snapshot.active
}
interact requires a non-empty message. An error event throws SourcingError with code turn and stops the generator. A stream that closes early throws code stream. follow reads GET /chat/progress. A 404 ends the loop. Other HTTP errors throw.
A host that must handle an error frame as data, instead of a thrown error, posts the turn through client.http.send and reads decodeSse:
import { decodeSse } from '@search-engine-sdk/core';
const response = await client.http.send({
path: '/agent/stream',
method: 'POST',
body: { message, session_id: id, turn_id: turnId, requirements },
signal,
});
for await (const frame of decodeSse(response, signal)) {
// `error`, `done`, and `new_search` arrive as frames
}
http.send accepts keepalive: true for a small body that should finish if the page unloads. Leave it unset for a large body.
Candidates
const people = session.candidates;
const filterSetId = await people.prepare(requirements, title);
const ranked = await people.search(filterSetId, {
page: 1,
rowsPerPage: 25,
sortKeys: [{ group: 'Go', mode: 'strict' }],
});
const hydrated = await people.list(filterSetId, { page: 1, rowsPerPage: 25 });
const profiles = await people.profiles(ranked.rows?.map((row) => row.id) ?? []);
const one = await people.get(candidateId);
const evaluation = await people.evaluate(filterSetId, [candidateId]);
prepare posts /filterset and returns the filter-set id. Pass a signal and then an existing id when the host is updating one: prepare(requirements, title, signal, filterSetId). The id is omitted from the body when it is empty.
search posts /search and returns the page: rows, total, scored, page, per_page, criteria, questions, notes, took_ms, and the rest of SearchPage. rowsPerPage defaults to 10 and is capped at 200. A sort key is { group, mode } with mode soft or strict. group is the column name the search expects. sortKeys is sent only when the array has entries. An empty list keeps score order.
list calls search, then /candidates, and returns { data, count, result }. count is scored, or total when scored is absent. Each item spreads the profile and sets rank to the search row, which carries why, marks, points, and score. result is the raw page. profiles is the /candidates call on its own.
evaluate posts /evaluate with { id, candidates }. Pass ask as Record<candidateId, questionId[]> to limit which questions are read. The result is verdicts, passages, and verified.
Requirement tree
const tree = session.requirements;
const forms = await tree.forms();
const preview = await tree.preview(forms.version, edits);
const saved = await tree.update(forms.version, edits, undefined, 'Tightened the location');
const entries = await tree.lookup(node, param, query);
const values = await tree.suggest(node, param, action, exclude);
forms is GET /tree/forms?session_id=…. preview counts the edits and returns the forms as they would be saved, including refused. update posts the edits and an optional comment. lookup returns { value, count }[]. suggest returns the values array from the server. exclude is what the field already holds. Pass value only when the button needs one: the fifth argument, before the signal.
TreeEdit is { node, params?, level?, rank_only?, remove? }.
Counts
const flags = await client.search.classify('staff Go engineers in Austin');
const counts = await client.search.countMany(plans);
classify posts { text } and returns the boolean flags (title, location, years, industry, skills, company, education, semantic, any). countMany posts each plan as { plan }, in order, and returns one count per plan. -1 means that plan was not counted. A missing counts field becomes [].