Skip to content

thread.session

The small facts of the thread’s pi session (id, file, model, state, usage) without starting the thread host (DMN-1067).

/** Params naming one thread. */
export type ThreadRef = {
threadId: string;
};
/**
* `thread.session` result: what the daemon knows of a thread's pi session; it never starts the thread host. Absent
* fields are unknown: `sessionId` and `sessionFile` before the session was loaded or written, and `messageCount`,
* `model`, `thinkingLevel` and `usage` while the thread host does not run (they come from its running session).
*/
export type ThreadSession = {
/** The thread's approval mode (DMN-952); this daemon leaves it out: the thread summary carries it (PRT-450). */
approvalMode?: ApprovalMode | null;
/** The session's working directory: the workspace folder. */
cwd: string;
/** Messages of the session's current branch, pi's `system` messages left out; absent while the host does not run. */
messageCount?: number | null;
/** `provider/id` of the running session's model; absent while the host does not run or without a model. */
model?: string | null;
/** Interactive requests are waiting for an answer. */
needsAttention: boolean;
/** The `ProcessState` (`@omfp/core`), as on the thread summary. */
process: unknown;
/** The session's folder roots: pi has no per-session roots, so the workspace folder only. */
roots: string[];
/** The thread's own pi session directory (`<data>/threads/<id>/sessions`). */
sessionDir: string;
/** The session's `.jsonl` file in `sessionDir`; absent while pi has not written it. */
sessionFile?: string | null;
/** pi's session id; absent before the session was first loaded. */
sessionId?: string | null;
/** Idle with nothing queued or pending (pi's `agent_settled`); `false` while the agent works. */
settled: boolean;
/** The running session's thinking level; absent while the host does not run. */
thinkingLevel?: string | null;
threadId: string;
/** What the session used so far, from the thread's running session; absent while the host does not run. */
usage?: SessionUsage | null;
workspaceId: string;
};
/**
* A thread's approval mode: which tool calls the thread's host asks the user to approve before they run (DMN-952,
* DMN-953). Read-only tools run without asking in every mode; any other value is `bad_request`.
*/
export type ApprovalMode =
/** Runs read-only tools; asks before every other tool, file edits included. */
| "always-ask"
/**
* Like `always-ask`, but the question can allow the tool (for `omfp_call`, that method) for the rest of the
* thread host's session (DMN-954).
*/
| "always-ask-cached"
/** Runs read-only tools and file edits (`edit`, `write`); asks before the rest (the shell, evals, …). */
| "write"
/** Runs every tool without asking (the default). */
| "yolo";
/** A session's cost and tokens, from the thread's running pi session. */
export type SessionUsage = {
/** How full the model's context window is; absent when pi cannot tell. */
context?: ContextUsage | null;
/** Cost of the session's model calls so far, in US dollars. */
cost: number;
tokens: SessionTokens;
};
/** The context window's use by the session's current branch. */
export type ContextUsage = {
contextWindow: number;
/** `tokens` as a percentage of `contextWindow`. */
percent: number;
tokens: number;
};
/** Tokens of a session's model calls so far. */
export type SessionTokens = {
cacheRead: number;
cacheWrite: number;
input: number;
output: number;
total: number;
};