Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

Name session store input contracts.

debajyoti-truefoundrya8bfe2297e95
diff --git a/packages/harness/src/agentSession/SessionHandle.ts b/packages/harness/src/agentSession/SessionHandle.ts
index e7b9323fc..0988453d7 100644
--- a/packages/harness/src/agentSession/SessionHandle.ts
+++ b/packages/harness/src/agentSession/SessionHandle.ts
@@ -18,7 +18,7 @@ import { builtinsFromSpec } from './builtinsFromSpec';
import type { ITurnResourceResolver } from './ITurnResourceResolver';
import type { SessionRecord } from './models/SessionRecord';
import { MAIN_THREAD_ID, type TurnRecord } from './models/TurnRecord';
-import type { TurnCreatedEvent, TurnDoneEvent, TurnEvent } from './schemas/events';
+import type { SessionEventItem } from './schemas/events';
import type { TokenPagination } from './schemas/pagination';
import type { TurnInputItem } from './schemas/turn';
import type { ISessionStore } from './store/ISessionStore';
@@ -279,7 +279,7 @@ export class SessionHandle<
page_token?: string | undefined;
last_turn_id?: string | undefined;
}): Promise<{
- data: { turn_id: string; event: TurnCreatedEvent | TurnDoneEvent | TurnEvent }[];
+ data: SessionEventItem[];
pagination: TokenPagination;
}> {
return this.store.listSessionEvents({
diff --git a/packages/harness/src/agentSession/Sessions.ts b/packages/harness/src/agentSession/Sessions.ts
index 1d9d94daa..635233559 100644
--- a/packages/harness/src/agentSession/Sessions.ts
+++ b/packages/harness/src/agentSession/Sessions.ts
@@ -2,9 +2,8 @@
* Storage-only session collection: create / get. Behavior arrives per run via
* the resolver on {@link SessionHandle.run}.
*/
-import type { AgentSpec } from './schemas/agentSpec';
import { SessionHandle } from './SessionHandle';
-import type { ISessionStore } from './store/ISessionStore';
+import type { CreateSessionInput, GetSessionInput, ISessionStore } from './store/ISessionStore';
export class Sessions<
TSessionCustom extends object = Record<string, never>,
@@ -20,12 +19,7 @@ export class Sessions<
* Creates and persists a new session. `agent_spec` is the fully hydrated
* spec; the store may internally persist a blob and/or a uri/id.
*/
- async create(input: {
- tenant_name: string;
- session_id: string;
- agent_spec: AgentSpec;
- custom?: TSessionCustom | undefined;
- }): Promise<SessionHandle<TSessionCustom, TTurnCustom>> {
+ async create(input: CreateSessionInput<TSessionCustom>): Promise<SessionHandle<TSessionCustom, TTurnCustom>> {
await this.store.createSession(input);
const record = await this.store.getSession({
tenant_name: input.tenant_name,
@@ -46,10 +40,7 @@ export class Sessions<
* only a uri/id), or undefined if not found. Read-only: does not bump
* last_activity_timestamp_ms.
*/
- async get(input: {
- tenant_name: string;
- session_id: string;
- }): Promise<SessionHandle<TSessionCustom, TTurnCustom> | undefined> {
+ async get(input: GetSessionInput): Promise<SessionHandle<TSessionCustom, TTurnCustom> | undefined> {
const record = await this.store.getSession(input);
if (!record) {
return undefined;
diff --git a/packages/harness/src/agentSession/index.ts b/packages/harness/src/agentSession/index.ts
index 58ac109bc..5f98262a8 100644
--- a/packages/harness/src/agentSession/index.ts
+++ b/packages/harness/src/agentSession/index.ts
@@ -41,7 +41,27 @@ export { MAIN_THREAD_ID } from './models/TurnRecord';
export type { TurnRecord, TurnSnapshot } from './models/TurnRecord';
export { InMemorySessionStore } from './store/InMemorySessionStore';
-export type { ISessionStore } from './store/ISessionStore';
+export type {
+ AddThreadsInput,
+ AppendToEventsInput,
+ AppendToThreadContextInput,
+ CreateSessionInput,
+ CreateTurnInput,
+ GetSessionInput,
+ GetTurnInput,
+ ISessionStore,
+ ListSessionEventsInput,
+ ListSessionsInput,
+ ListTurnEventsInput,
+ ListTurnsInput,
+ OverwriteThreadContextInput,
+ PatchMCPServersInput,
+ PatchSandboxInfoInput,
+ PatchThreadCapabilityStateInput,
+ RemoveThreadsInput,
+ UpdateSessionInput,
+ UpdateTurnStateInput,
+} from './store/ISessionStore';
export { SessionStoreConflictError, SessionStoreNotFoundError } from './store/SessionStoreErrors';
export type { ITurnResourceResolver } from './ITurnResourceResolver';
diff --git a/packages/harness/src/agentSession/store/ISessionStore.ts b/packages/harness/src/agentSession/store/ISessionStore.ts
index 465dc56df..361ef89e7 100644
--- a/packages/harness/src/agentSession/store/ISessionStore.ts
+++ b/packages/harness/src/agentSession/store/ISessionStore.ts
@@ -9,11 +9,139 @@ import type {
import type { SandboxInfo } from '../../core/sandbox/Sandbox';
import type { SessionRecord } from '../models/SessionRecord';
import type { TurnRecord } from '../models/TurnRecord';
-import type { AgentSpec } from '../schemas/agentSpec';
-import type { TurnCreatedEvent, TurnDoneEvent, TurnEvent } from '../schemas/events';
+import type { SessionEventItem, TurnCreatedEvent, TurnDoneEvent, TurnEvent } from '../schemas/events';
import type { TokenPagination } from '../schemas/pagination';
import type { TerminalTurnState } from '../schemas/turn';
+/** Caller-supplied fields for creating a session; the store owns timestamps and tip state. */
+export type CreateSessionInput<TSessionCustom extends object = Record<string, never>> = {
+ tenant_name: string;
+} & Pick<SessionRecord<TSessionCustom>, 'session_id' | 'agent_spec' | 'custom'>;
+
+/** PATCH fields for an existing session; omitted keys are left unchanged. */
+export type UpdateSessionInput<TSessionCustom extends object = Record<string, never>> = {
+ tenant_name: string;
+} & Pick<SessionRecord<TSessionCustom>, 'session_id'> &
+ Partial<Pick<SessionRecord<TSessionCustom>, 'agent_spec' | 'title'>>;
+
+export type GetSessionInput = {
+ tenant_name: string;
+ session_id: string;
+};
+
+export type ListSessionsInput = {
+ tenant_name: string;
+ limit: number;
+ page_token?: string | undefined;
+ order?: 'asc' | 'desc' | undefined;
+ start_timestamp?: string | undefined;
+ end_timestamp?: string | undefined;
+};
+
+export type CreateTurnInput<TTurnCustom extends object = Record<string, never>> = {
+ tenant_name: string;
+ turn: TurnRecord<TTurnCustom>;
+ update_session_title_if_not_exist?: string | undefined;
+};
+
+export type GetTurnInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+};
+
+export type ListTurnsInput = {
+ tenant_name: string;
+ session_id: string;
+ limit: number;
+ page_token?: string | undefined;
+};
+
+export type UpdateTurnStateInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ state: TerminalTurnState;
+};
+
+export type AppendToEventsInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ events: WithRegisteredPassthrough<TurnEvent | TurnCreatedEvent | TurnDoneEvent>[];
+};
+
+export type AddThreadsInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ threads: AgentThreadSnapshot[];
+};
+
+export type RemoveThreadsInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ thread_ids: string[];
+};
+
+export type AppendToThreadContextInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ thread_id: string;
+ context: ContextMessage[];
+ current_context_usage?: CompletionUsage | undefined;
+ completion?: SubAgentCompletionMarker | undefined;
+};
+
+export type OverwriteThreadContextInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ event: ThreadOverwriteContextEvent;
+};
+
+export type PatchMCPServersInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ mcp_servers: MCPServerInitInfo[];
+};
+
+export type PatchSandboxInfoInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ sandbox_info: SandboxInfo;
+};
+
+export type PatchThreadCapabilityStateInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ thread_id: string;
+ key: string;
+ state: unknown;
+};
+
+export type ListTurnEventsInput = {
+ tenant_name: string;
+ session_id: string;
+ turn_id: string;
+ limit: number;
+ page_token?: string | undefined;
+ order?: 'asc' | 'desc' | undefined;
+};
+
+export type ListSessionEventsInput = {
+ tenant_name: string;
+ session_id: string;
+ limit: number;
+ page_token?: string | undefined;
+ last_turn_id?: string | undefined;
+};
+
/**
* Session/turn persistence contract. Pure durability: no streaming, SSE, or
* subscription members. Turn-scoped ops take session_id (membership check).
@@ -30,12 +158,7 @@ export interface ISessionStore<
* from it — callers do not pass a bare pointer through this API.
* Sets `last_activity_timestamp_ms` (= now) on create.
*/
- createSession(input: {
- tenant_name: string;
- session_id: string;
- agent_spec: AgentSpec;
- custom?: TSessionCustom | undefined;
- }): Promise<void>;
+ createSession(input: CreateSessionInput<TSessionCustom>): Promise<void>;
/**
* MUST return SessionRecord with `agent_spec` fully hydrated, even if the backend
@@ -43,7 +166,7 @@ export interface ISessionStore<
* and SessionHandle.run never resolve agents themselves.
* Does **not** bump `last_activity_timestamp_ms` (read path).
*/
- getSession(input: { tenant_name: string; session_id: string }): Promise<SessionRecord<TSessionCustom> | undefined>;
+ getSession(input: GetSessionInput): Promise<SessionRecord<TSessionCustom> | undefined>;
/**
* PATCH semantics — update only the provided fields:
@@ -52,12 +175,7 @@ export interface ISessionStore<
* Bumps `last_activity_timestamp_ms` (= now). Same liveness rule applies to any
* future session-update fields: update session ⇒ touch activity.
*/
- updateSession(input: {
- tenant_name: string;
- session_id: string;
- agent_spec?: AgentSpec | undefined;
- title?: string | undefined;
- }): Promise<void>;
+ updateSession(input: UpdateSessionInput<TSessionCustom>): Promise<void>;
/**
* Paginated list of the tenant's sessions ordered by `created_at`
@@ -65,14 +183,9 @@ export interface ISessionStore<
* inclusive ISO-8601 bounds on `created_at`.
* Does **not** bump `last_activity_timestamp_ms` (read path).
*/
- listSessions(input: {
- tenant_name: string;
- limit: number;
- page_token?: string | undefined;
- order?: 'asc' | 'desc' | undefined;
- start_timestamp?: string | undefined;
- end_timestamp?: string | undefined;
- }): Promise<{ data: SessionRecord<TSessionCustom>[]; pagination: TokenPagination }>;
+ listSessions(
+ input: ListSessionsInput,
+ ): Promise<{ data: SessionRecord<TSessionCustom>[]; pagination: TokenPagination }>;
/**
* Creates the turn AND advances `session.last_turn_id`.
@@ -97,26 +210,13 @@ export interface ISessionStore<
* overwritten (first write wins). The caller derives the value; the store
* only conditionally sets it.
*/
- createTurn(input: {
- tenant_name: string;
- turn: TurnRecord<TTurnCustom>;
- update_session_title_if_not_exist?: string | undefined;
- }): Promise<void>;
+ createTurn(input: CreateTurnInput<TTurnCustom>): Promise<void>;
/** Returns the turn record, or undefined if not found in this session. */
- getTurn(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- }): Promise<TurnRecord<TTurnCustom> | undefined>;
+ getTurn(input: GetTurnInput): Promise<TurnRecord<TTurnCustom> | undefined>;
/** Paginated list of the session's turn records, stable ordering. */
- listTurns(input: {
- tenant_name: string;
- session_id: string;
- limit: number;
- page_token?: string | undefined;
- }): Promise<{ data: TurnRecord<TTurnCustom>[]; pagination: TokenPagination }>;
+ listTurns(input: ListTurnsInput): Promise<{ data: TurnRecord<TTurnCustom>[]; pagination: TokenPagination }>;
/**
* Writes the terminal state. Store contract — **first terminal write wins**:
@@ -128,12 +228,7 @@ export interface ISessionStore<
* Check under the same concurrency control as other turn mutations (lock/CAS) —
* not a racy read-then-write outside the critical section.
*/
- updateTurnState(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- state: TerminalTurnState;
- }): Promise<void>;
+ updateTurnState(input: UpdateTurnStateInput): Promise<void>;
/**
* Durable event log for the turn. MUST include lifecycle rows: a
@@ -142,83 +237,31 @@ export interface ISessionStore<
* API persists lifecycle in the stream — implementations never synthesize
* missing created/done rows on read.
*/
- appendToEvents(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- events: WithRegisteredPassthrough<TurnEvent | TurnCreatedEvent | TurnDoneEvent>[];
- }): Promise<void>;
+ appendToEvents(input: AppendToEventsInput): Promise<void>;
/** Adds thread snapshots to the turn (sub-agent spawns). */
- addThreads(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- threads: AgentThreadSnapshot[];
- }): Promise<void>;
+ addThreads(input: AddThreadsInput): Promise<void>;
/** Removes threads from the turn by id. */
- removeThreads(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_ids: string[];
- }): Promise<void>;
+ removeThreads(input: RemoveThreadsInput): Promise<void>;
/** Appends messages to a thread's context; optionally updates usage / completion marker. */
- appendToThreadContext(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_id: string;
- context: ContextMessage[];
- current_context_usage?: CompletionUsage | undefined;
- completion?: SubAgentCompletionMarker | undefined;
- }): Promise<void>;
+ appendToThreadContext(input: AppendToThreadContextInput): Promise<void>;
/** Replaces a thread's context wholesale (context-overwrite event). */
- overwriteThreadContext(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- event: ThreadOverwriteContextEvent;
- }): Promise<void>;
+ overwriteThreadContext(input: OverwriteThreadContextInput): Promise<void>;
/** Patches the turn snapshot's MCP server init info (by source id). */
- patchMCPServers(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- mcp_servers: MCPServerInitInfo[];
- }): Promise<void>;
+ patchMCPServers(input: PatchMCPServersInput): Promise<void>;
/** Patches the turn snapshot's sandbox info (id for cross-turn reattach). */
- patchSandboxInfo(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- sandbox_info: SandboxInfo;
- }): Promise<void>;
+ patchSandboxInfo(input: PatchSandboxInfoInput): Promise<void>;
/** Generic capability KV — store has zero Plan/feature knowledge. */
- patchThreadCapabilityState(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_id: string;
- key: string;
- state: unknown;
- }): Promise<void>;
+ patchThreadCapabilityState(input: PatchThreadCapabilityStateInput): Promise<void>;
/** Paginated read of one turn's persisted events, insertion order (asc default). */
- listTurnEvents(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- limit: number;
- page_token?: string | undefined;
- order?: 'asc' | 'desc' | undefined;
- }): Promise<{
+ listTurnEvents(input: ListTurnEventsInput): Promise<{
data: WithRegisteredPassthrough<TurnEvent | TurnCreatedEvent | TurnDoneEvent>[];
pagination: TokenPagination;
}>;
@@ -235,14 +278,8 @@ export interface ISessionStore<
* spill through older turns' own `ancestor_ids`. Sibling branches from forks
* are excluded; omit `last_turn_id` to use the full session turn list.
*/
- listSessionEvents(input: {
- tenant_name: string;
- session_id: string;
- limit: number;
- page_token?: string | undefined;
- last_turn_id?: string | undefined;
- }): Promise<{
- data: { turn_id: string; event: TurnCreatedEvent | TurnDoneEvent | TurnEvent }[];
+ listSessionEvents(input: ListSessionEventsInput): Promise<{
+ data: SessionEventItem[];
pagination: TokenPagination;
}>;
}
diff --git a/packages/harness/src/agentSession/store/InMemorySessionStore.ts b/packages/harness/src/agentSession/store/InMemorySessionStore.ts
index c3257c0ee..b120bb6fd 100644
--- a/packages/harness/src/agentSession/store/InMemorySessionStore.ts
+++ b/packages/harness/src/agentSession/store/InMemorySessionStore.ts
@@ -1,19 +1,29 @@
-import type { MCPServerInitInfo, ThreadOverwriteContextEvent } from '../../core/events/eventSchemas';
import type { WithRegisteredPassthrough } from '../../core/events/PassthroughEvents';
-import type { CompletionUsage } from '../../core/llm/LLMTypes';
-import type {
- AgentThreadSnapshot,
- ContextMessage,
- SubAgentCompletionMarker,
-} from '../../core/runtime/AgentThread.types';
-import type { SandboxInfo } from '../../core/sandbox/Sandbox';
import type { SessionRecord } from '../models/SessionRecord';
import type { TurnRecord } from '../models/TurnRecord';
-import type { AgentSpec } from '../schemas/agentSpec';
-import type { TurnCreatedEvent, TurnDoneEvent, TurnEvent } from '../schemas/events';
+import type { SessionEventItem, TurnCreatedEvent, TurnDoneEvent, TurnEvent } from '../schemas/events';
import type { TokenPagination } from '../schemas/pagination';
-import type { TerminalTurnState } from '../schemas/turn';
-import type { ISessionStore } from './ISessionStore';
+import type {
+ AddThreadsInput,
+ AppendToEventsInput,
+ AppendToThreadContextInput,
+ CreateSessionInput,
+ CreateTurnInput,
+ GetSessionInput,
+ GetTurnInput,
+ ISessionStore,
+ ListSessionEventsInput,
+ ListSessionsInput,
+ ListTurnEventsInput,
+ ListTurnsInput,
+ OverwriteThreadContextInput,
+ PatchMCPServersInput,
+ PatchSandboxInfoInput,
+ PatchThreadCapabilityStateInput,
+ RemoveThreadsInput,
+ UpdateSessionInput,
+ UpdateTurnStateInput,
+} from './ISessionStore';
import { SessionStoreConflictError, SessionStoreNotFoundError } from './SessionStoreErrors';
/* eslint-disable @typescript-eslint/require-await -- in-memory store is synchronous; methods stay async so thrown SessionStore*Error reject as Promises for ISessionStore callers */
@@ -75,12 +85,7 @@ export class InMemorySessionStore<
private readonly turns = new Map<string, TurnRecord<TTurnCustom>>();
private readonly events = new Map<string, StoredEvent[]>();
- async createSession(input: {
- tenant_name: string;
- session_id: string;
- agent_spec: AgentSpec;
- custom?: TSessionCustom | undefined;
- }): Promise<void> {
+ async createSession(input: CreateSessionInput<TSessionCustom>): Promise<void> {
const key = sessionKey(input.tenant_name, input.session_id);
if (this.sessions.has(key)) {
throw new SessionStoreConflictError(`Session already exists: ${input.session_id}`);
@@ -99,20 +104,12 @@ export class InMemorySessionStore<
return;
}
- async getSession(input: {
- tenant_name: string;
- session_id: string;
- }): Promise<SessionRecord<TSessionCustom> | undefined> {
+ async getSession(input: GetSessionInput): Promise<SessionRecord<TSessionCustom> | undefined> {
const stored = this.sessions.get(sessionKey(input.tenant_name, input.session_id));
return stored ? deepCopy(stored.record) : undefined;
}
- async updateSession(input: {
- tenant_name: string;
- session_id: string;
- agent_spec?: AgentSpec | undefined;
- title?: string | undefined;
- }): Promise<void> {
+ async updateSession(input: UpdateSessionInput<TSessionCustom>): Promise<void> {
const key = sessionKey(input.tenant_name, input.session_id);
const stored = this.sessions.get(key);
if (!stored) {
@@ -129,14 +126,9 @@ export class InMemorySessionStore<
return;
}
- async listSessions(input: {
- tenant_name: string;
- limit: number;
- page_token?: string | undefined;
- order?: 'asc' | 'desc' | undefined;
- start_timestamp?: string | undefined;
- end_timestamp?: string | undefined;
- }): Promise<{ data: SessionRecord<TSessionCustom>[]; pagination: TokenPagination }> {
+ async listSessions(
+ input: ListSessionsInput,
+ ): Promise<{ data: SessionRecord<TSessionCustom>[]; pagination: TokenPagination }> {
const prefix = `${input.tenant_name}:`;
const records: SessionRecord<TSessionCustom>[] = [];
for (const [key, stored] of this.sessions) {
@@ -153,11 +145,7 @@ export class InMemorySessionStore<
return { data: deepCopy(page.data), pagination: page.pagination };
}
- async createTurn(input: {
- tenant_name: string;
- turn: TurnRecord<TTurnCustom>;
- update_session_title_if_not_exist?: string | undefined;
- }): Promise<void> {
+ async createTurn(input: CreateTurnInput<TTurnCustom>): Promise<void> {
// Atomicity is free here: this body is fully synchronous, so Node's
// run-to-completion guarantees it. Real backends must still use their own
// locking/transactions to satisfy the ISessionStore createTurn contract.
@@ -191,21 +179,12 @@ export class InMemorySessionStore<
}
}
- async getTurn(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- }): Promise<TurnRecord<TTurnCustom> | undefined> {
+ async getTurn(input: GetTurnInput): Promise<TurnRecord<TTurnCustom> | undefined> {
const turn = this.turns.get(turnKey(input.tenant_name, input.session_id, input.turn_id));
return turn ? deepCopy(turn) : undefined;
}
- async listTurns(input: {
- tenant_name: string;
- session_id: string;
- limit: number;
- page_token?: string | undefined;
- }): Promise<{ data: TurnRecord<TTurnCustom>[]; pagination: TokenPagination }> {
+ async listTurns(input: ListTurnsInput): Promise<{ data: TurnRecord<TTurnCustom>[]; pagination: TokenPagination }> {
const stored = this.sessions.get(sessionKey(input.tenant_name, input.session_id));
if (!stored) {
throw new SessionStoreNotFoundError(`Session not found: ${input.session_id}`);
@@ -220,12 +199,7 @@ export class InMemorySessionStore<
return paginate(records, input.limit, input.page_token);
}
- async updateTurnState(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- state: TerminalTurnState;
- }): Promise<void> {
+ async updateTurnState(input: UpdateTurnStateInput): Promise<void> {
// Same as createTurn: synchronous body ⇒ atomic under run-to-completion.
const tKey = turnKey(input.tenant_name, input.session_id, input.turn_id);
const turn = this.turns.get(tKey);
@@ -241,12 +215,7 @@ export class InMemorySessionStore<
turn.updated_at = new Date().toISOString();
}
- async appendToEvents(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- events: WithRegisteredPassthrough<TurnEvent | TurnCreatedEvent | TurnDoneEvent>[];
- }): Promise<void> {
+ async appendToEvents(input: AppendToEventsInput): Promise<void> {
const tKey = turnKey(input.tenant_name, input.session_id, input.turn_id);
const list = this.events.get(tKey);
if (!list) {
@@ -264,12 +233,7 @@ export class InMemorySessionStore<
return turn;
}
- async addThreads(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- threads: AgentThreadSnapshot[];
- }): Promise<void> {
+ async addThreads(input: AddThreadsInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
for (const thread of input.threads) {
turn.snapshot.threads[thread.thread_id] = deepCopy(thread);
@@ -278,12 +242,7 @@ export class InMemorySessionStore<
return;
}
- async removeThreads(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_ids: string[];
- }): Promise<void> {
+ async removeThreads(input: RemoveThreadsInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
for (const id of input.thread_ids) {
Reflect.deleteProperty(turn.snapshot.threads, id);
@@ -292,15 +251,7 @@ export class InMemorySessionStore<
return;
}
- async appendToThreadContext(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_id: string;
- context: ContextMessage[];
- current_context_usage?: CompletionUsage | undefined;
- completion?: SubAgentCompletionMarker | undefined;
- }): Promise<void> {
+ async appendToThreadContext(input: AppendToThreadContextInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
const thread = turn.snapshot.threads[input.thread_id];
if (!thread) {
@@ -317,12 +268,7 @@ export class InMemorySessionStore<
return;
}
- async overwriteThreadContext(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- event: ThreadOverwriteContextEvent;
- }): Promise<void> {
+ async overwriteThreadContext(input: OverwriteThreadContextInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
const threadId = input.event.thread_id;
const thread = turn.snapshot.threads[threadId];
@@ -335,12 +281,7 @@ export class InMemorySessionStore<
return;
}
- async patchMCPServers(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- mcp_servers: MCPServerInitInfo[];
- }): Promise<void> {
+ async patchMCPServers(input: PatchMCPServersInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
turn.snapshot.mcp_servers ??= {};
for (const server of input.mcp_servers) {
@@ -350,26 +291,14 @@ export class InMemorySessionStore<
return;
}
- async patchSandboxInfo(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- sandbox_info: SandboxInfo;
- }): Promise<void> {
+ async patchSandboxInfo(input: PatchSandboxInfoInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
turn.snapshot.sandbox_info = deepCopy(input.sandbox_info);
turn.updated_at = new Date().toISOString();
return;
}
- async patchThreadCapabilityState(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- thread_id: string;
- key: string;
- state: unknown;
- }): Promise<void> {
+ async patchThreadCapabilityState(input: PatchThreadCapabilityStateInput): Promise<void> {
const turn = this.requireTurn(input.tenant_name, input.session_id, input.turn_id);
const thread = turn.snapshot.threads[input.thread_id];
if (!thread) {
@@ -381,14 +310,7 @@ export class InMemorySessionStore<
return;
}
- async listTurnEvents(input: {
- tenant_name: string;
- session_id: string;
- turn_id: string;
- limit: number;
- page_token?: string | undefined;
- order?: 'asc' | 'desc' | undefined;
- }): Promise<{
+ async listTurnEvents(input: ListTurnEventsInput): Promise<{
data: WithRegisteredPassthrough<TurnEvent | TurnCreatedEvent | TurnDoneEvent>[];
pagination: TokenPagination;
}> {
@@ -401,14 +323,8 @@ export class InMemorySessionStore<
return { data: deepCopy(page.data), pagination: page.pagination };
}
- async listSessionEvents(input: {
- tenant_name: string;
- session_id: string;
- limit: number;
- page_token?: string | undefined;
- last_turn_id?: string | undefined;
- }): Promise<{
- data: { turn_id: string; event: TurnCreatedEvent | TurnDoneEvent | TurnEvent }[];
+ async listSessionEvents(input: ListSessionEventsInput): Promise<{
+ data: SessionEventItem[];
pagination: TokenPagination;
}> {
const stored = this.sessions.get(sessionKey(input.tenant_name, input.session_id));
@@ -423,7 +339,7 @@ export class InMemorySessionStore<
}
turnIds = this.resolveAncestorChain(input.tenant_name, input.session_id, anchor);
}
- const flattened: { turn_id: string; event: TurnCreatedEvent | TurnDoneEvent | TurnEvent }[] = [];
+ const flattened: SessionEventItem[] = [];
for (const turnId of turnIds) {
const evts = this.events.get(turnKey(input.tenant_name, input.session_id, turnId)) ?? [];
for (const event of evts) {