@botbotgo/agent-harness 0.0.184 → 0.0.186

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,17 @@
47
47
  - **Extend:** drop `tool({...})` modules and SKILL trees under `resources/`, wire shared tools and MCP in catalogs, and let agents whitelist what they use.
48
48
  - **Built into the runtime:** persisted `requests`, `sessions`, `approvals`, and `events`; recovery and queueing; streaming listeners; MCP in/out; LangChain v1 and DeepAgents adapters—so you do not rebuild that layer per app.
49
49
 
50
+ ## Current Public Surface
51
+
52
+ The repository now ships more than a thin runtime bootstrap. The public surface is already broad enough that the homepage and docs need to describe it as a product runtime with external protocol boundaries, not only as YAML plus tools.
53
+
54
+ - **Core runtime API:** `createAgentHarness`, `request`, `subscribe`, `resolveApproval`, inspection helpers, and stable persisted runtime records for `requests`, `sessions`, `approvals`, `events`, and artifacts.
55
+ - **Runtime memory and evidence:** `memorize`, `recall`, `listMemories`, memory policy hooks, `listArtifacts`, `getArtifact`, `exportEvaluationBundle`, `replayEvaluationBundle`, and request/session evidence export helpers.
56
+ - **Protocol and transport surfaces:** `createAcpServer`, `serveAcpStdio`, `serveAcpHttp`, `serveA2aHttp`, `serveAgUiHttp`, and `createRuntimeMcpServer` / `serveRuntimeMcpOverStdio`.
57
+ - **Governed workspace runtime:** YAML-owned routing, concurrency, maintenance, MCP policy, runtime governance bundles, and approval defaults for sensitive memory or write-like MCP side effects.
58
+
59
+ `deepagents-acp` is part of the current public story, not only a direction hidden in planning notes: `agent-harness` is moving toward a standard runtime boundary that external clients can talk to directly while the harness keeps persistence, recovery, approvals, and operator control runtime-owned.
60
+
50
61
  ## What Problem We Solve
51
62
 
52
63
  In one line: `agent-harness` productizes the runtime work that usually appears after the demo.
@@ -127,13 +138,13 @@ The runtime provides:
127
138
  - YAML-defined workspace assembly for routing, models, tools, stores, backends, MCP, recovery, and maintenance
128
139
  - backend-adapted execution with current LangChain v1 and DeepAgents adapters
129
140
  - local `resources/tools/` `tool({...})` modules and `resources/skills/` discovery
130
- - persisted threads, runs, approvals, events, queue state, and recovery metadata
141
+ - persisted sessions, requests, approvals, events, queue state, and recovery metadata
131
142
 
132
143
  In practice, the harness exists for the parts that are expensive and repetitive to rebuild inside every agent app:
133
144
 
134
145
  - approval inboxes and human decision flow
135
- - persisted runs, threads, and inspectable event history
136
- - run correlation, continuity, and recovery inspection that still works after a stream fallback or restart
146
+ - persisted requests, sessions, and inspectable event history
147
+ - request correlation, continuity, and recovery inspection that still works after a stream fallback or restart
137
148
  - runtime-managed recovery after interrupts, failures, or process restart
138
149
  - queueing, concurrency, maintenance, and operational policy
139
150
  - stable runtime records that stay usable even if the backend changes
@@ -189,17 +200,17 @@ Most agent tooling stops at execution. Production software does not.
189
200
 
190
201
  Real products need a runtime that can answer harder questions:
191
202
 
192
- - Where do runs live?
203
+ - Where do requests live?
193
204
  - How are approvals resolved?
194
205
  - What survives process restart?
195
- - How do you inspect threads and events without exposing raw backend state?
206
+ - How do you inspect sessions and events without exposing raw backend state?
196
207
  - How do you swap backend implementations without rewriting the product model?
197
208
 
198
209
  `agent-harness` is the layer that answers those questions without turning your application API into a mirror of LangChain v1 or DeepAgents.
199
210
 
200
211
  ## What Makes It Different
201
212
 
202
- - It treats `runs`, `threads`, `approvals`, `events`, and recovery as first-class product records
213
+ - It treats `requests`, `sessions`, `approvals`, `events`, and recovery as first-class product records
203
214
  - It gives operators a runtime control surface instead of exposing raw backend internals
204
215
  - It keeps observability and governance runtime-owned with trace correlation, continuity metadata, and approval defaults for sensitive side effects
205
216
  - It keeps checkpoint resume system-managed instead of promoting checkpoint internals into the primary API
@@ -211,7 +222,7 @@ Real products need a runtime that can answer harder questions:
211
222
  Use `agent-harness` when:
212
223
 
213
224
  - you already know your product needs agents, tools, prompts, or MCP access, but the missing layer is runtime operations
214
- - you need approvals, restart recovery, queueing, or inspectable run records as part of the shipped product
225
+ - you need approvals, restart recovery, queueing, or inspectable request records as part of the shipped product
215
226
  - you want one workspace-shaped assembly model instead of hand-written runtime bootstrapping in every app
216
227
  - you want to keep backend execution semantics upstream while holding the product contract stable
217
228
 
@@ -300,9 +311,9 @@ If you want the shortest possible mental model:
300
311
  - LangChain v1 and DeepAgents backend adaptation
301
312
  - Auto-discovered local `tool({...})` tools and SKILL packages
302
313
  - provider-native tools, MCP tools, and workspace-local tool modules
303
- - persisted threads, runs, approvals, lifecycle events, and queued runs
314
+ - persisted sessions, requests, approvals, lifecycle events, and queued requests
304
315
  - runtime-managed recovery and checkpoint maintenance
305
- - structured output and multimodal content preservation in run results
316
+ - structured output and multimodal content preservation in request results
306
317
  - MCP bridge support for agent-declared MCP servers
307
318
  - MCP server support for exposing harness tools outward
308
319
  - optional `mem0` semantic recall augmentation over canonical SQLite durable memory
@@ -658,7 +669,7 @@ Important fields:
658
669
  `maintenance.checkpoints` and `maintenance.records` are separate retention layers:
659
670
 
660
671
  - `maintenance.checkpoints` trims backend checkpoint state used for resume/recovery
661
- - `maintenance.records` trims harness-owned terminal thread/run records stored in `runtime.sqlite`
672
+ - `maintenance.records` trims harness-owned terminal session/request records stored in `runtime.sqlite`
662
673
 
663
674
  Example:
664
675
 
@@ -845,7 +856,7 @@ spec:
845
856
  systemPrompt: Answer simple requests directly.
846
857
  ```
847
858
 
848
- When `config.filesystem.sessionStorage.enabled: true` is set for a LangChain binding, the runtime keeps one filesystem root per persisted session/thread and reuses the same runnable cache entry for repeated work on that session instead of collapsing every run onto one shared workspace directory.
859
+ When `config.filesystem.sessionStorage.enabled: true` is set for a LangChain binding, the runtime keeps one filesystem root per persisted session and reuses the same runnable cache entry for repeated work on that session instead of collapsing every request onto one shared workspace directory.
849
860
 
850
861
  Example orchestra host:
851
862
 
package/README.zh.md CHANGED
@@ -47,6 +47,17 @@
47
47
  - **扩展:** 在 `resources/` 下放置 `tool({...})` 模块与 SKILL 目录,在目录里声明共享工具与 MCP,再由各 agent 按名字白名单启用。
48
48
  - **内建运行时:** 持久化 `requests`、`sessions`、`approvals` 与 `events`;恢复与排队;流式监听;MCP 接入与对外暴露;LangChain v1 与 DeepAgents 适配——避免每个应用重复造这一层。
49
49
 
50
+ ## 当前公开能力面
51
+
52
+ 这个仓库现在公开交付的已经不只是一个很薄的 runtime bootstrap。对外能力已经足够大,首页和文档也应该把它描述成一个带外部协议边界的产品级 runtime,而不只是 “YAML + tools”。
53
+
54
+ - **核心 runtime API:** `createAgentHarness`、`request`、`subscribe`、`resolveApproval`、各类 inspection helper,以及稳定持久化的 `requests`、`sessions`、`approvals`、`events` 和 artifacts 记录。
55
+ - **运行时 memory 与证据能力:** `memorize`、`recall`、`listMemories`、memory policy hooks、`listArtifacts`、`getArtifact`、`exportEvaluationBundle`、`replayEvaluationBundle`,以及 request / session 级证据导出 helper。
56
+ - **协议与传输接面:** `createAcpServer`、`serveAcpStdio`、`serveAcpHttp`、`serveA2aHttp`、`serveAgUiHttp`、以及 `createRuntimeMcpServer` / `serveRuntimeMcpOverStdio`。
57
+ - **受治理的工作区运行时:** 由 YAML 持有的路由、并发、维护、MCP 策略、runtime governance bundles,以及针对敏感 memory 或写类 MCP 副作用的默认审批门槛。
58
+
59
+ `deepagents-acp` 已不应该只藏在规划文档里。它已经是当前公开产品叙事的一部分:`agent-harness` 正在朝一个可被外部客户端直接接入的标准 runtime boundary 演进,同时继续把持久化、恢复、审批和 operator control 保持为 harness 自有职责。
60
+
50
61
  ## 我们解决什么问题
51
62
 
52
63
  一句话概括:`agent-harness` 把通常在 demo 之后才暴露出来的运行时工作,提前做成产品 runtime 的一部分。
@@ -127,13 +138,13 @@ AI 让 agent 逻辑、工具调用和工作流代码更容易生成,真正更
127
138
  - 以 YAML 描述的工作区装配:路由、模型、工具、存储、后端、MCP、恢复与维护等
128
139
  - 通过适配器对接当前的 LangChain v1 与 DeepAgents 执行
129
140
  - 本地 `resources/tools/` 中 `tool({...})` 工具模块与 `resources/skills/` 的发现
130
- - 持久化的线程、运行、审批、事件、队列状态与恢复元数据
141
+ - 持久化的会话、请求、审批、事件、队列状态与恢复元数据
131
142
 
132
143
  落到实际系统里,harness 主要解决那些每个 agent 应用都不应该重复造一遍的运行时难题:
133
144
 
134
145
  - 审批收件箱与人工决策流
135
- - 持久化的 runsthreads 与可查询事件历史
136
- - 即使发生 stream fallback 或进程重启也还能成立的 run 关联、连续性与恢复观测
146
+ - 持久化的 requestssessions 与可查询事件历史
147
+ - 即使发生 stream fallback 或进程重启也还能成立的 request 关联、连续性与恢复观测
137
148
  - 中断、失败或进程重启后的运行时托管恢复
138
149
  - 队列、并发、维护与运维策略
139
150
  - 即使后端变更也保持稳定的运行时记录模型
@@ -186,17 +197,17 @@ AI 让 agent 逻辑、工具调用和工作流代码更容易生成,真正更
186
197
 
187
198
  真实产品需要能回答更难问题的运行时:
188
199
 
189
- - 运行(runs)存在哪里?
200
+ - 请求(requests)存在哪里?
190
201
  - 审批如何闭环?
191
202
  - 进程重启后什么还在?
192
- - 如何在不暴露原始后端状态的前提下检查线程与事件?
203
+ - 如何在不暴露原始后端状态的前提下检查会话与事件?
193
204
  - 如何在不大改产品模型的前提下替换后端实现?
194
205
 
195
206
  `agent-harness` 在不把应用 API 做成 LangChain v1 / DeepAgents 翻版的前提下,回答这些问题。
196
207
 
197
208
  ## 有何不同
198
209
 
199
- - 将 `runs`、`threads`、`approvals`、`events` 与恢复视为一等产品记录
210
+ - 将 `requests`、`sessions`、`approvals`、`events` 与恢复视为一等产品记录
200
211
  - 给运维侧提供运行时控制面,而不是暴露原始后端内部结构
201
212
  - 将可观测性与治理留在运行时:包括 trace correlation、continuity metadata,以及高风险副作用的默认审批
202
213
  - 将 checkpoint 恢复作为系统管理的行为,而不是把 checkpoint 细节抬成主 API
@@ -208,7 +219,7 @@ AI 让 agent 逻辑、工具调用和工作流代码更容易生成,真正更
208
219
  下面这些场景适合用 `agent-harness`:
209
220
 
210
221
  - 你已经确定产品需要 agents、tools、prompts 或 MCP,但真正缺的是运行时运维层
211
- - 你需要把审批、重启恢复、排队调度或可查询运行记录一起作为产品能力交付出去
222
+ - 你需要把审批、重启恢复、排队调度或可查询请求记录一起作为产品能力交付出去
212
223
  - 你希望用一个 workspace 形态的装配模型取代每个应用各写一套启动和运行时胶水
213
224
  - 你想把 backend 的执行语义留在上游,同时把产品契约稳定下来
214
225
 
@@ -297,7 +308,7 @@ try {
297
308
  - LangChain v1 与 DeepAgents 后端适配
298
309
  - 自动发现本地工具与 SKILL 包
299
310
  - 原生 provider 工具、MCP 工具与工作区本地工具模块
300
- - 持久化线程、运行、审批、生命周期事件与排队运行
311
+ - 持久化会话、请求、审批、生命周期事件与排队请求
301
312
  - 运行时管理的恢复与 checkpoint 维护
302
313
  - 运行结果中的结构化输出与多模态内容保留
303
314
  - 将 agent 声明的 MCP 服务桥接进来
@@ -618,7 +629,7 @@ await stop(runtime);
618
629
  `maintenance.checkpoints` 与 `maintenance.records` 是两层独立的保留策略:
619
630
 
620
631
  - `maintenance.checkpoints` 清理后端用于 resume/recovery 的 checkpoint 状态
621
- - `maintenance.records` 清理 harness 自己保存在 `runtime.sqlite` 中、已结束的 thread/run 记录
632
+ - `maintenance.records` 清理 harness 自己保存在 `runtime.sqlite` 中、已结束的 session/request 记录
622
633
 
623
634
  示例:
624
635
 
@@ -804,7 +815,7 @@ spec:
804
815
  systemPrompt: Answer simple requests directly.
805
816
  ```
806
817
 
807
- 当 LangChain 绑定启用 `config.filesystem.sessionStorage.enabled: true` 时,runtime 会为每个持久化 session/thread 维护独立的 filesystem 根目录,并按 session 复用 runnable cache,而不是把所有运行都压到同一个共享工作目录里。
818
+ 当 LangChain 绑定启用 `config.filesystem.sessionStorage.enabled: true` 时,runtime 会为每个持久化 session 维护独立的 filesystem 根目录,并按 session 复用 runnable cache,而不是把所有请求都压到同一个共享工作目录里。
808
819
 
809
820
  orchestra 主机示例:
810
821
 
package/dist/api.d.ts CHANGED
@@ -77,21 +77,22 @@ type PublicApprovalFilter = {
77
77
  sessionId?: string;
78
78
  requestId?: string;
79
79
  };
80
- type PublicRunStartOptions = Omit<RunStartOptions, "threadId" | "listeners"> & {
80
+ type PublicRequestStartOptions = Omit<RunStartOptions, "threadId" | "listeners"> & {
81
81
  sessionId?: string;
82
82
  listeners?: PublicRunListeners;
83
83
  };
84
- type PublicRunDecisionOptions = Omit<RunDecisionOptions, "threadId" | "runId" | "listeners"> & {
84
+ type PublicRequestDecisionOptions = Omit<RunDecisionOptions, "threadId" | "runId" | "listeners"> & {
85
85
  sessionId: string;
86
86
  requestId?: string;
87
87
  listeners?: PublicRunListeners;
88
88
  };
89
- type PublicRunOptions = PublicRunStartOptions | PublicRunDecisionOptions;
90
- type PublicRunResult = Omit<RunResult, "threadId" | "runId"> & {
89
+ type PublicRequestOptions = PublicRequestStartOptions | PublicRequestDecisionOptions;
90
+ type PublicRequestResult = Omit<RunResult, "threadId" | "runId"> & {
91
91
  sessionId: string;
92
92
  requestId: string;
93
93
  };
94
- export type RequestResult = PublicRunResult;
94
+ type PublicRunResult = PublicRequestResult;
95
+ export type RequestResult = PublicRequestResult;
95
96
  export type UserChatMessage = {
96
97
  role: "user";
97
98
  content: MessageContent;
@@ -111,14 +112,14 @@ type CreateAgentHarnessOptions = {
111
112
  export declare function createAgentHarness(): Promise<AgentHarnessRuntime>;
112
113
  export declare function createAgentHarness(workspaceRoot: string, options?: CreateAgentHarnessOptions): Promise<AgentHarnessRuntime>;
113
114
  export declare function normalizeUserChatInput(input: UserChatInput, options?: NormalizeUserChatInputOptions): Pick<RunStartOptions, "input" | "invocation">;
114
- export declare function request(runtime: AgentHarnessRuntime, options: PublicRunOptions): Promise<PublicRunResult>;
115
+ export declare function request(runtime: AgentHarnessRuntime, options: PublicRequestOptions): Promise<PublicRequestResult>;
115
116
  export declare function memorize(runtime: AgentHarnessRuntime, input: MemorizeInput): Promise<MemorizeResult>;
116
117
  export declare function recall(runtime: AgentHarnessRuntime, input: RecallInput): Promise<RecallResult>;
117
118
  export declare function listMemories(runtime: AgentHarnessRuntime, input?: ListMemoriesInput): Promise<ListMemoriesResult>;
118
119
  export declare function updateMemory(runtime: AgentHarnessRuntime, input: UpdateMemoryInput): Promise<MemoryRecord>;
119
120
  export declare function removeMemory(runtime: AgentHarnessRuntime, input: RemoveMemoryInput): Promise<MemoryRecord>;
120
121
  export declare function subscribe(runtime: AgentHarnessRuntime, listener: (event: RequestEvent) => void | Promise<void>): () => void;
121
- export declare function listSessions(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listThreads"]>[0]): Promise<SessionSummary[]>;
122
+ export declare function listSessions(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listSessions"]>[0]): Promise<SessionSummary[]>;
122
123
  export declare function listRequests(runtime: AgentHarnessRuntime, filter?: {
123
124
  agentId?: string;
124
125
  sessionId?: string;
package/dist/api.js CHANGED
@@ -9,54 +9,6 @@ export { AgentHarnessAcpServer, createAcpServer } from "./acp.js";
9
9
  export { AgentHarnessRuntime } from "./runtime/harness.js";
10
10
  export { buildFlowGraph, exportFlowGraphToMermaid, exportFlowGraphToSequenceMermaid } from "./flow/index.js";
11
11
  export { createUpstreamTimelineReducer } from "./upstream-events.js";
12
- function toSessionSummary(summary) {
13
- return {
14
- agentId: summary.agentId,
15
- sessionId: summary.threadId,
16
- latestRequestId: summary.latestRunId,
17
- createdAt: summary.createdAt,
18
- updatedAt: summary.updatedAt,
19
- status: summary.status,
20
- currentAgentId: summary.currentAgentId,
21
- };
22
- }
23
- function toRequestSummary(summary) {
24
- return {
25
- requestId: summary.runId,
26
- sessionId: summary.threadId,
27
- agentId: summary.agentId,
28
- executionMode: summary.executionMode,
29
- adapterKind: summary.adapterKind,
30
- createdAt: summary.createdAt,
31
- updatedAt: summary.updatedAt,
32
- state: summary.state,
33
- checkpointRef: summary.checkpointRef,
34
- resumable: summary.resumable,
35
- startedAt: summary.startedAt,
36
- endedAt: summary.endedAt,
37
- lastActivityAt: summary.lastActivityAt,
38
- currentAgentId: summary.currentAgentId,
39
- delegationChain: summary.delegationChain,
40
- runtimeSnapshot: summary.runtimeSnapshot,
41
- };
42
- }
43
- function toSessionRecord(record) {
44
- return {
45
- sessionId: record.threadId,
46
- entryAgentId: record.entryAgentId,
47
- currentAgentId: record.currentAgentId,
48
- currentState: record.currentState,
49
- latestRequestId: record.latestRunId,
50
- createdAt: record.createdAt,
51
- updatedAt: record.updatedAt,
52
- messages: record.messages,
53
- requests: record.runs.map(toRequestSummary),
54
- pendingDecision: record.pendingDecision,
55
- };
56
- }
57
- function toRequestRecord(record) {
58
- return toRequestSummary(record);
59
- }
60
12
  function toApprovalRecord(record) {
61
13
  return {
62
14
  approvalId: record.approvalId,
@@ -218,25 +170,19 @@ export function subscribe(runtime, listener) {
218
170
  });
219
171
  }
220
172
  export async function listSessions(runtime, filter) {
221
- return (await runtime.listThreads(filter)).map(toSessionSummary);
173
+ return runtime.listSessions(filter);
222
174
  }
223
175
  export async function listRequests(runtime, filter) {
224
- return (await runtime.listRuns({
225
- agentId: filter?.agentId,
226
- state: filter?.state,
227
- threadId: filter?.sessionId,
228
- })).map(toRequestSummary);
176
+ return runtime.listRequests(filter);
229
177
  }
230
178
  export async function getSession(runtime, sessionId) {
231
- const record = await runtime.getThread(sessionId);
232
- return record ? toSessionRecord(record) : null;
179
+ return runtime.getSessionRecord(sessionId);
233
180
  }
234
181
  export async function getRequest(runtime, requestId) {
235
- const record = await runtime.getRun(requestId);
236
- return record ? toRequestRecord(record) : null;
182
+ return runtime.getRequest(requestId);
237
183
  }
238
184
  export async function deleteSession(runtime, sessionId) {
239
- return runtime.deleteThread(sessionId);
185
+ return runtime.deleteSession(sessionId);
240
186
  }
241
187
  export async function listApprovals(runtime, filter) {
242
188
  return (await runtime.listApprovals({
@@ -256,13 +202,13 @@ export async function getArtifact(runtime, input) {
256
202
  return runtime.readArtifact(input.sessionId, input.requestId, input.artifactPath);
257
203
  }
258
204
  export async function listRequestEvents(runtime, input) {
259
- return (await runtime.listRunEvents(input.sessionId, input.requestId)).map(toPublicEvent);
205
+ return (await runtime.listRequestEvents(input.sessionId, input.requestId)).map(toPublicEvent);
260
206
  }
261
207
  export async function getHealth(runtime) {
262
208
  return runtime.getHealth();
263
209
  }
264
210
  export async function exportRequestPackage(runtime, input) {
265
- return toRequestPackage(await runtime.exportRunPackage(input));
211
+ return toRequestPackage(await runtime.exportRequestPackage(input));
266
212
  }
267
213
  export async function exportSessionPackage(runtime, input) {
268
214
  return runtime.exportSessionPackage(input);
@@ -1,22 +1,24 @@
1
1
  import type { RunState } from "./core.js";
2
2
  import type { CompiledAgentBinding, CompiledModel, CompiledTool, ParsedAgentObject, ParsedToolObject, WorkspaceBundle } from "./workspace.js";
3
3
  /**
4
- * Persisted runtime summary for an inspectable conversation thread.
5
- * This projects upstream session/thread execution state into a stable runtime
6
- * inspection surface.
4
+ * Persisted runtime summary for an inspectable conversation session.
5
+ * This is the canonical runtime-facing conversation record.
7
6
  */
8
- export type ThreadSummary = {
7
+ export type SessionSummary = {
9
8
  agentId: string;
10
- threadId: string;
11
- latestRunId: string;
9
+ sessionId: string;
10
+ latestRequestId: string;
12
11
  createdAt: string;
13
12
  updatedAt: string;
14
13
  status: RunState;
15
14
  currentAgentId?: string;
16
15
  };
17
- export type SessionSummary = Omit<ThreadSummary, "threadId" | "latestRunId"> & {
18
- sessionId: string;
19
- latestRequestId: string;
16
+ /**
17
+ * Backward-compatible alias for older thread/run terminology.
18
+ */
19
+ export type ThreadSummary = Omit<SessionSummary, "sessionId" | "latestRequestId"> & {
20
+ threadId: string;
21
+ latestRunId: string;
20
22
  };
21
23
  export type KnownHarnessEventType = "run.created" | "run.queued" | "run.dequeued" | "run.state.changed" | "run.resumed" | "approval.requested" | "approval.resolved" | "artifact.created" | "output.delta" | "runtime.health.changed" | "runtime.synthetic_fallback";
22
24
  export type HarnessEventType = KnownHarnessEventType | (string & {});
@@ -192,6 +194,8 @@ export type MemorizeInputRecord = {
192
194
  };
193
195
  export type MemorizeInput = {
194
196
  records: MemorizeInputRecord[];
197
+ sessionId?: string;
198
+ requestId?: string;
195
199
  threadId?: string;
196
200
  runId?: string;
197
201
  agentId?: string;
@@ -209,6 +213,7 @@ export type RecallInput = {
209
213
  kinds?: MemoryKind[];
210
214
  topK?: number;
211
215
  includeStale?: boolean;
216
+ sessionId?: string;
212
217
  threadId?: string;
213
218
  agentId?: string;
214
219
  workspaceId?: string;
@@ -222,6 +227,7 @@ export type ListMemoriesInput = {
222
227
  scopes?: MemoryScope[];
223
228
  kinds?: MemoryKind[];
224
229
  status?: MemoryRecordStatus[];
230
+ sessionId?: string;
225
231
  threadId?: string;
226
232
  agentId?: string;
227
233
  workspaceId?: string;
@@ -418,29 +424,36 @@ export type ThreadRunRecord = {
418
424
  runtimeSnapshot?: RuntimeSnapshot;
419
425
  };
420
426
  /**
421
- * Persisted run summary projected from upstream execution state plus runtime lifecycle metadata.
427
+ * Persisted request summary projected from upstream execution state plus runtime lifecycle metadata.
428
+ * This is the canonical runtime-facing execution record.
422
429
  */
423
- export type RunSummary = ThreadRunRecord;
424
- export type RunRecord = RunSummary;
425
- export type RequestSummary = Omit<RunSummary, "threadId" | "runId"> & {
430
+ export type RequestSummary = Omit<ThreadRunRecord, "threadId" | "runId"> & {
426
431
  sessionId: string;
427
432
  requestId: string;
428
433
  };
429
434
  export type RequestRecord = RequestSummary;
430
435
  /**
431
- * Persisted thread inspection record assembled from runtime records.
432
- * This is an inspectable projection, not a second thread semantic model.
436
+ * Backward-compatible alias for older thread/run terminology.
433
437
  */
434
- export type ThreadRecord = {
438
+ export type RunSummary = Omit<RequestSummary, "sessionId" | "requestId"> & {
435
439
  threadId: string;
440
+ runId: string;
441
+ };
442
+ export type RunRecord = RunSummary;
443
+ /**
444
+ * Persisted session inspection record assembled from runtime records.
445
+ * This is an inspectable projection, not a second session semantic model.
446
+ */
447
+ export type SessionRecord = {
448
+ sessionId: string;
436
449
  entryAgentId: string;
437
450
  currentAgentId?: string;
438
451
  currentState: RunState;
439
- latestRunId: string;
452
+ latestRequestId: string;
440
453
  createdAt: string;
441
454
  updatedAt: string;
442
455
  messages: TranscriptMessage[];
443
- runs: ThreadRunRecord[];
456
+ requests: RequestSummary[];
444
457
  pendingDecision?: {
445
458
  approvalId: string;
446
459
  pendingActionId: string;
@@ -449,10 +462,13 @@ export type ThreadRecord = {
449
462
  requestedAt: string;
450
463
  };
451
464
  };
452
- export type SessionRecord = Omit<ThreadRecord, "threadId" | "latestRunId" | "runs"> & {
453
- sessionId: string;
454
- latestRequestId: string;
455
- requests: RequestSummary[];
465
+ /**
466
+ * Backward-compatible alias for older thread/run terminology.
467
+ */
468
+ export type ThreadRecord = Omit<SessionRecord, "sessionId" | "latestRequestId" | "requests"> & {
469
+ threadId: string;
470
+ latestRunId: string;
471
+ runs: RunSummary[];
456
472
  };
457
473
  export type ResumeOptions = {
458
474
  threadId?: string;
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { ApprovalRecord, ArtifactListing, CompiledTool, HarnessEvent, ParsedToolObject, RunResult, RunState, RunSummary, RuntimeSessionPackage, RuntimeSessionPackageInput, ThreadRecord, ThreadSummary } from "./contracts/types.js";
2
+ import type { ApprovalRecord, ArtifactListing, CompiledTool, HarnessEvent, ParsedToolObject, RequestRecord, RunResult, RunState, RequestSummary, RuntimeSessionPackage, RuntimeSessionPackageInput, SessionRecord, SessionSummary } from "./contracts/types.js";
3
3
  export type ToolMcpServerOptions = {
4
4
  agentId: string;
5
5
  serverInfo?: {
@@ -20,16 +20,16 @@ export type RuntimeMcpServerOptions = {
20
20
  };
21
21
  };
22
22
  type RuntimeMcpRuntime = {
23
- listThreads: (filter?: {
23
+ listSessions: (filter?: {
24
24
  agentId?: string;
25
- }) => Promise<ThreadSummary[]>;
26
- getThread: (threadId: string) => Promise<ThreadRecord | null>;
27
- listRuns: (filter?: {
25
+ }) => Promise<SessionSummary[]>;
26
+ getSessionRecord: (sessionId: string) => Promise<SessionRecord | null>;
27
+ listRequests: (filter?: {
28
28
  agentId?: string;
29
- threadId?: string;
29
+ sessionId?: string;
30
30
  state?: RunState;
31
- }) => Promise<RunSummary[]>;
32
- getRun: (runId: string) => Promise<RunSummary | null>;
31
+ }) => Promise<RequestSummary[]>;
32
+ getRequest: (requestId: string) => Promise<RequestRecord | null>;
33
33
  listApprovals: (filter?: {
34
34
  status?: ApprovalRecord["status"];
35
35
  threadId?: string;
@@ -43,10 +43,10 @@ type RuntimeMcpRuntime = {
43
43
  decision?: "approve" | "edit" | "reject";
44
44
  editedInput?: Record<string, unknown>;
45
45
  }) => Promise<RunResult>;
46
- listArtifacts: (threadId: string, runId: string) => Promise<ArtifactListing>;
47
- readArtifact: (threadId: string, runId: string, artifactPath: string) => Promise<unknown>;
48
- listRunEvents: (sessionId: string, requestId: string) => Promise<HarnessEvent[]>;
49
- exportRunPackage: (input: {
46
+ listArtifacts: (sessionId: string, requestId: string) => Promise<ArtifactListing>;
47
+ readArtifact: (sessionId: string, requestId: string, artifactPath: string) => Promise<unknown>;
48
+ listRequestEvents: (sessionId: string, requestId: string) => Promise<HarnessEvent[]>;
49
+ exportRequestPackage: (input: {
50
50
  sessionId: string;
51
51
  requestId: string;
52
52
  includeArtifacts?: boolean;
package/dist/mcp.js CHANGED
@@ -120,7 +120,7 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
120
120
  }, async (input) => ({
121
121
  content: [{
122
122
  type: "text",
123
- text: renderToolOutput(await runtime.listThreads(input.agentId ? { agentId: input.agentId } : undefined)),
123
+ text: renderToolOutput(await runtime.listSessions(input.agentId ? { agentId: input.agentId } : undefined)),
124
124
  }],
125
125
  }));
126
126
  server.tool("get_session", "Get one persisted runtime session by id.", {
@@ -128,7 +128,7 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
128
128
  }, async (input) => ({
129
129
  content: [{
130
130
  type: "text",
131
- text: renderToolOutput(await runtime.getThread(input.sessionId)),
131
+ text: renderToolOutput(await runtime.getSessionRecord(input.sessionId)),
132
132
  }],
133
133
  }));
134
134
  server.tool("list_requests", "List persisted runtime requests.", {
@@ -138,9 +138,9 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
138
138
  }, async (input) => ({
139
139
  content: [{
140
140
  type: "text",
141
- text: renderToolOutput(await runtime.listRuns({
141
+ text: renderToolOutput(await runtime.listRequests({
142
142
  ...(input.agentId ? { agentId: input.agentId } : {}),
143
- ...(input.sessionId ? { threadId: input.sessionId } : {}),
143
+ ...(input.sessionId ? { sessionId: input.sessionId } : {}),
144
144
  ...(input.state ? { state: input.state } : {}),
145
145
  })),
146
146
  }],
@@ -150,7 +150,7 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
150
150
  }, async (input) => ({
151
151
  content: [{
152
152
  type: "text",
153
- text: renderToolOutput(await runtime.getRun(input.requestId)),
153
+ text: renderToolOutput(await runtime.getRequest(input.requestId)),
154
154
  }],
155
155
  }));
156
156
  server.tool("list_approvals", "List runtime approvals.", {
@@ -218,7 +218,7 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
218
218
  }, async (input) => ({
219
219
  content: [{
220
220
  type: "text",
221
- text: renderToolOutput(await runtime.listRunEvents(input.sessionId, input.requestId)),
221
+ text: renderToolOutput(await runtime.listRequestEvents(input.sessionId, input.requestId)),
222
222
  }],
223
223
  }));
224
224
  server.tool("export_request_package", "Export a stable runtime request package for one request.", {
@@ -230,7 +230,7 @@ export async function createRuntimeMcpServer(runtime, options = {}) {
230
230
  }, async (input) => ({
231
231
  content: [{
232
232
  type: "text",
233
- text: renderToolOutput(await runtime.exportRunPackage(input)),
233
+ text: renderToolOutput(await runtime.exportRequestPackage(input)),
234
234
  }],
235
235
  }));
236
236
  server.tool("export_session_package", "Export a stable runtime session package.", {
@@ -1 +1 @@
1
- export declare const AGENT_HARNESS_VERSION = "0.0.183";
1
+ export declare const AGENT_HARNESS_VERSION = "0.0.185";
@@ -1 +1 @@
1
- export const AGENT_HARNESS_VERSION = "0.0.183";
1
+ export const AGENT_HARNESS_VERSION = "0.0.185";
@@ -1,5 +1,9 @@
1
- import type { ApprovalRecord, ThreadRecord, ThreadSummary } from "../../../contracts/types.js";
1
+ import type { ApprovalRecord, SessionRecord, SessionSummary, ThreadRecord, ThreadSummary } from "../../../contracts/types.js";
2
2
  import type { RuntimePersistence } from "../../../persistence/types.js";
3
+ export declare function buildSessionInspectionRecord(input: {
4
+ persistence: RuntimePersistence;
5
+ getSession: (sessionId: string) => Promise<SessionSummary | null>;
6
+ }, sessionId: string): Promise<SessionRecord | null>;
3
7
  export declare function buildThreadInspectionRecord(input: {
4
8
  persistence: RuntimePersistence;
5
9
  getSession: (threadId: string) => Promise<ThreadSummary | null>;
@@ -19,3 +23,8 @@ export declare function deleteThreadRecord(input: {
19
23
  deleteThread: (threadId: string) => Promise<boolean>;
20
24
  deleteThreadCheckpoints: (threadId: string) => Promise<void>;
21
25
  }, threadId: string): Promise<boolean>;
26
+ export declare function deleteSessionRecord(input: {
27
+ getSession: (sessionId: string) => Promise<SessionRecord | null>;
28
+ deleteSession: (sessionId: string) => Promise<boolean>;
29
+ deleteSessionCheckpoints: (sessionId: string) => Promise<void>;
30
+ }, sessionId: string): Promise<boolean>;
@@ -4,29 +4,46 @@ function selectLatestPendingApproval(approvals) {
4
4
  .filter((approval) => approval.status === "pending")
5
5
  .sort((left, right) => right.requestedAt.localeCompare(left.requestedAt))[0];
6
6
  }
7
- export async function buildThreadInspectionRecord(input, threadId) {
8
- const [threadSummary, meta, messages, runs] = await Promise.all([
9
- input.getSession(threadId),
10
- input.persistence.getThreadMeta(threadId),
11
- input.persistence.listThreadMessages(threadId, 200),
12
- input.persistence.listThreadRuns(threadId),
7
+ export async function buildSessionInspectionRecord(input, sessionId) {
8
+ const [sessionSummary, meta, messages, requests] = await Promise.all([
9
+ input.getSession(sessionId),
10
+ input.persistence.getThreadMeta(sessionId),
11
+ input.persistence.listThreadMessages(sessionId, 200),
12
+ input.persistence.listThreadRuns(sessionId),
13
13
  ]);
14
- if (!threadSummary || !meta) {
14
+ if (!sessionSummary || !meta) {
15
15
  return null;
16
16
  }
17
- const latestRunId = threadSummary.latestRunId;
18
- const latestApprovals = await input.persistence.getRunApprovals(threadId, latestRunId);
17
+ const latestRequestId = sessionSummary.latestRequestId;
18
+ const latestApprovals = await input.persistence.getRunApprovals(sessionId, latestRequestId);
19
19
  const pendingApproval = selectLatestPendingApproval(latestApprovals);
20
20
  return {
21
- threadId,
21
+ sessionId,
22
22
  entryAgentId: meta.entryAgentId,
23
- currentAgentId: threadSummary.currentAgentId,
24
- currentState: threadSummary.status,
25
- latestRunId,
23
+ currentAgentId: sessionSummary.currentAgentId,
24
+ currentState: sessionSummary.status,
25
+ latestRequestId,
26
26
  createdAt: meta.createdAt,
27
- updatedAt: threadSummary.updatedAt,
27
+ updatedAt: sessionSummary.updatedAt,
28
28
  messages,
29
- runs,
29
+ requests: requests.map((request) => ({
30
+ requestId: request.runId,
31
+ sessionId: request.threadId,
32
+ agentId: request.agentId,
33
+ executionMode: request.executionMode,
34
+ adapterKind: request.adapterKind,
35
+ createdAt: request.createdAt,
36
+ updatedAt: request.updatedAt,
37
+ state: request.state,
38
+ checkpointRef: request.checkpointRef,
39
+ resumable: request.resumable,
40
+ startedAt: request.startedAt,
41
+ endedAt: request.endedAt,
42
+ lastActivityAt: request.lastActivityAt,
43
+ currentAgentId: request.currentAgentId,
44
+ delegationChain: request.delegationChain,
45
+ runtimeSnapshot: request.runtimeSnapshot,
46
+ })),
30
47
  pendingDecision: pendingApproval
31
48
  ? {
32
49
  approvalId: pendingApproval.approvalId,
@@ -38,6 +55,56 @@ export async function buildThreadInspectionRecord(input, threadId) {
38
55
  : undefined,
39
56
  };
40
57
  }
58
+ export async function buildThreadInspectionRecord(input, threadId) {
59
+ const session = await buildSessionInspectionRecord({
60
+ persistence: input.persistence,
61
+ getSession: async (sessionId) => {
62
+ const summary = await input.getSession(sessionId);
63
+ return summary
64
+ ? {
65
+ agentId: summary.agentId,
66
+ sessionId: summary.threadId,
67
+ latestRequestId: summary.latestRunId,
68
+ createdAt: summary.createdAt,
69
+ updatedAt: summary.updatedAt,
70
+ status: summary.status,
71
+ currentAgentId: summary.currentAgentId,
72
+ }
73
+ : null;
74
+ },
75
+ }, threadId);
76
+ return session
77
+ ? {
78
+ threadId: session.sessionId,
79
+ entryAgentId: session.entryAgentId,
80
+ currentAgentId: session.currentAgentId,
81
+ currentState: session.currentState,
82
+ latestRunId: session.latestRequestId,
83
+ createdAt: session.createdAt,
84
+ updatedAt: session.updatedAt,
85
+ messages: session.messages,
86
+ runs: session.requests.map((request) => ({
87
+ runId: request.requestId,
88
+ threadId: request.sessionId,
89
+ agentId: request.agentId,
90
+ executionMode: request.executionMode,
91
+ adapterKind: request.adapterKind,
92
+ createdAt: request.createdAt,
93
+ updatedAt: request.updatedAt,
94
+ state: request.state,
95
+ checkpointRef: request.checkpointRef,
96
+ resumable: request.resumable,
97
+ startedAt: request.startedAt,
98
+ endedAt: request.endedAt,
99
+ lastActivityAt: request.lastActivityAt,
100
+ currentAgentId: request.currentAgentId,
101
+ delegationChain: request.delegationChain,
102
+ runtimeSnapshot: request.runtimeSnapshot,
103
+ })),
104
+ pendingDecision: session.pendingDecision,
105
+ }
106
+ : null;
107
+ }
41
108
  export async function listPublicApprovals(input, filter) {
42
109
  const approvals = await input.persistence.listApprovals(filter);
43
110
  return approvals.map((approval) => toInspectableApprovalRecord(approval));
@@ -61,3 +128,18 @@ export async function deleteThreadRecord(input, threadId) {
61
128
  }
62
129
  return deleted;
63
130
  }
131
+ export async function deleteSessionRecord(input, sessionId) {
132
+ const session = await input.getSession(sessionId);
133
+ if (!session) {
134
+ return false;
135
+ }
136
+ const activeRequest = session.requests.find((request) => !isTerminalRunState(request.state));
137
+ if (activeRequest) {
138
+ throw new Error(`Cannot delete session ${sessionId} while request ${activeRequest.requestId} is ${activeRequest.state}`);
139
+ }
140
+ const deleted = await input.deleteSession(sessionId);
141
+ if (deleted) {
142
+ await input.deleteSessionCheckpoints(sessionId);
143
+ }
144
+ return deleted;
145
+ }
@@ -1,4 +1,4 @@
1
- import type { ApprovalRecord, ArtifactListing, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, ListMemoriesInput, ListMemoriesResult, MessageContent, RemoveMemoryInput, RunRecord, RunStartOptions, RestartConversationOptions, RuntimeAdapterOptions, RuntimeEvaluationExport, RuntimeEvaluationExportInput, RuntimeEvaluationReplayInput, RuntimeEvaluationReplayResult, RuntimeRunPackage, RuntimeRunPackageInput, RuntimeSessionPackage, RuntimeSessionPackageInput, ResumeOptions, RunOptions, RunResult, RunSummary, MemoryRecord, MemorizeInput, MemorizeResult, RecallInput, RecallResult, UpdateMemoryInput, ThreadSummary, ThreadRecord, WorkspaceBundle } from "../contracts/types.js";
1
+ import type { ApprovalRecord, ArtifactListing, CancelOptions, HarnessEvent, HarnessStreamItem, RuntimeHealthSnapshot, ListMemoriesInput, ListMemoriesResult, MessageContent, RemoveMemoryInput, RunRecord, RunStartOptions, RestartConversationOptions, RuntimeAdapterOptions, RuntimeEvaluationExport, RuntimeEvaluationExportInput, RuntimeEvaluationReplayInput, RuntimeEvaluationReplayResult, RuntimeRunPackage, RuntimeRunPackageInput, RuntimeSessionPackage, RuntimeSessionPackageInput, ResumeOptions, RunOptions, RunResult, RunSummary, MemoryRecord, MemorizeInput, MemorizeResult, RecallInput, RecallResult, UpdateMemoryInput, SessionSummary, ThreadSummary, ThreadRecord, SessionRecord, RequestRecord, RequestSummary, WorkspaceBundle } from "../contracts/types.js";
2
2
  import { type RuntimeMcpServerOptions, type ToolMcpServerOptions } from "../mcp.js";
3
3
  import { type InventoryAgentRecord, type InventorySkillRecord } from "./harness/system/inventory.js";
4
4
  import type { RequirementAssessmentOptions } from "./harness/system/skill-requirements.js";
@@ -60,9 +60,17 @@ export declare class AgentHarnessRuntime {
60
60
  initialize(): Promise<void>;
61
61
  subscribe(listener: (event: HarnessEvent) => void): () => void;
62
62
  getHealth(): Promise<RuntimeHealthSnapshot>;
63
+ listSessions(filter?: {
64
+ agentId?: string;
65
+ }): Promise<SessionSummary[]>;
63
66
  listThreads(filter?: {
64
67
  agentId?: string;
65
68
  }): Promise<ThreadSummary[]>;
69
+ listRequests(filter?: {
70
+ agentId?: string;
71
+ sessionId?: string;
72
+ state?: RequestSummary["state"];
73
+ }): Promise<RequestSummary[]>;
66
74
  listRuns(filter?: {
67
75
  agentId?: string;
68
76
  threadId?: string;
@@ -73,8 +81,11 @@ export declare class AgentHarnessRuntime {
73
81
  listMemories(input?: ListMemoriesInput): Promise<ListMemoriesResult>;
74
82
  updateMemory(input: UpdateMemoryInput): Promise<MemoryRecord>;
75
83
  removeMemory(input: RemoveMemoryInput): Promise<MemoryRecord>;
84
+ getRequest(requestId: string): Promise<RequestRecord | null>;
76
85
  getRun(runId: string): Promise<RunRecord | null>;
86
+ private getSessionSummary;
77
87
  private getSession;
88
+ getSessionRecord(sessionId: string): Promise<SessionRecord | null>;
78
89
  getThread(threadId: string): Promise<ThreadRecord | null>;
79
90
  listApprovals(filter?: {
80
91
  status?: ApprovalRecord["status"];
@@ -84,7 +95,9 @@ export declare class AgentHarnessRuntime {
84
95
  getApproval(approvalId: string): Promise<ApprovalRecord | null>;
85
96
  listArtifacts(threadId: string, runId: string): Promise<ArtifactListing>;
86
97
  readArtifact(threadId: string, runId: string, artifactPath: string): Promise<unknown>;
98
+ listRequestEvents(sessionId: string, requestId: string): Promise<HarnessEvent[]>;
87
99
  listRunEvents(threadId: string, runId: string): Promise<HarnessEvent[]>;
100
+ exportRequestPackage(input: RuntimeRunPackageInput): Promise<RuntimeRunPackage>;
88
101
  exportRunPackage(input: RuntimeRunPackageInput): Promise<RuntimeRunPackage>;
89
102
  exportSessionPackage(input: RuntimeSessionPackageInput): Promise<RuntimeSessionPackage>;
90
103
  exportEvaluationBundle(input: RuntimeEvaluationExportInput): Promise<RuntimeEvaluationExport>;
@@ -96,7 +109,9 @@ export declare class AgentHarnessRuntime {
96
109
  agents: InventoryAgentRecord[];
97
110
  };
98
111
  private deleteThreadCheckpoints;
112
+ deleteSession(sessionId: string): Promise<boolean>;
99
113
  deleteThread(threadId: string): Promise<boolean>;
114
+ deleteThreadLegacy(threadId: string): Promise<boolean>;
100
115
  createToolMcpServer(options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
101
116
  serveToolsOverStdio(options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
102
117
  createRuntimeMcpServer(options?: RuntimeMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
@@ -38,7 +38,7 @@ import { resolveRuntimeAdapterOptions } from "./support/runtime-adapter-options.
38
38
  import { initializeHarnessRuntime, reclaimExpiredClaimedRuns as reclaimHarnessExpiredClaimedRuns, recoverStartupRuns as recoverHarnessStartupRuns, isStaleRunningRun as isHarnessStaleRunningRun, } from "./harness/run/startup-runtime.js";
39
39
  import { streamHarnessRun } from "./harness/run/stream-run.js";
40
40
  import { defaultRequestedAgentId, prepareRunStart } from "./harness/run/start-run.js";
41
- import { buildThreadInspectionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
41
+ import { buildSessionInspectionRecord, deleteSessionRecord, deleteThreadRecord, getPublicApproval, listPublicApprovals, } from "./harness/run/thread-records.js";
42
42
  export class AgentHarnessRuntime {
43
43
  workspace;
44
44
  runtimeAdapterOptions;
@@ -286,11 +286,79 @@ export class AgentHarnessRuntime {
286
286
  }
287
287
  return createDefaultHealthSnapshot(this.activeRunSlots, this.pendingRunSlots.length);
288
288
  }
289
+ async listSessions(filter) {
290
+ const sessions = await this.persistence.listSessions(filter);
291
+ return sessions.map((session) => ({
292
+ agentId: session.agentId,
293
+ sessionId: session.threadId,
294
+ latestRequestId: session.latestRunId,
295
+ createdAt: session.createdAt,
296
+ updatedAt: session.updatedAt,
297
+ status: session.status,
298
+ currentAgentId: session.currentAgentId,
299
+ }));
300
+ }
289
301
  async listThreads(filter) {
290
- return this.persistence.listSessions(filter);
302
+ const sessions = await this.listSessions(filter);
303
+ return sessions.map((session) => ({
304
+ agentId: session.agentId,
305
+ threadId: session.sessionId,
306
+ latestRunId: session.latestRequestId,
307
+ createdAt: session.createdAt,
308
+ updatedAt: session.updatedAt,
309
+ status: session.status,
310
+ currentAgentId: session.currentAgentId,
311
+ }));
312
+ }
313
+ async listRequests(filter) {
314
+ const requests = await this.persistence.listRuns({
315
+ agentId: filter?.agentId,
316
+ threadId: filter?.sessionId,
317
+ state: filter?.state,
318
+ });
319
+ return requests.map((request) => ({
320
+ requestId: request.runId,
321
+ sessionId: request.threadId,
322
+ agentId: request.agentId,
323
+ executionMode: request.executionMode,
324
+ adapterKind: request.adapterKind,
325
+ createdAt: request.createdAt,
326
+ updatedAt: request.updatedAt,
327
+ state: request.state,
328
+ checkpointRef: request.checkpointRef,
329
+ resumable: request.resumable,
330
+ startedAt: request.startedAt,
331
+ endedAt: request.endedAt,
332
+ lastActivityAt: request.lastActivityAt,
333
+ currentAgentId: request.currentAgentId,
334
+ delegationChain: request.delegationChain,
335
+ runtimeSnapshot: request.runtimeSnapshot,
336
+ }));
291
337
  }
292
338
  async listRuns(filter) {
293
- return this.persistence.listRuns(filter);
339
+ const requests = await this.listRequests({
340
+ agentId: filter?.agentId,
341
+ sessionId: filter?.threadId,
342
+ state: filter?.state,
343
+ });
344
+ return requests.map((request) => ({
345
+ runId: request.requestId,
346
+ threadId: request.sessionId,
347
+ agentId: request.agentId,
348
+ executionMode: request.executionMode,
349
+ adapterKind: request.adapterKind,
350
+ createdAt: request.createdAt,
351
+ updatedAt: request.updatedAt,
352
+ state: request.state,
353
+ checkpointRef: request.checkpointRef,
354
+ resumable: request.resumable,
355
+ startedAt: request.startedAt,
356
+ endedAt: request.endedAt,
357
+ lastActivityAt: request.lastActivityAt,
358
+ currentAgentId: request.currentAgentId,
359
+ delegationChain: request.delegationChain,
360
+ runtimeSnapshot: request.runtimeSnapshot,
361
+ }));
294
362
  }
295
363
  async memorize(input) {
296
364
  const binding = this.defaultRuntimeEntryBinding;
@@ -309,12 +377,14 @@ export class AgentHarnessRuntime {
309
377
  if (candidates.some((record) => typeof record.content !== "string" || record.content.trim().length === 0)) {
310
378
  throw new Error("memorize requires every record to include non-empty content.");
311
379
  }
312
- if (candidates.some((record) => (record.scope ?? "thread") === "thread") && !input.threadId) {
313
- throw new Error("memorize requires threadId when storing thread-scoped memory.");
380
+ const sessionId = input.sessionId ?? input.threadId;
381
+ const requestId = input.requestId ?? input.runId;
382
+ if (candidates.some((record) => (record.scope ?? "thread") === "thread") && !sessionId) {
383
+ throw new Error("memorize requires sessionId (or legacy threadId) when storing thread-scoped memory.");
314
384
  }
315
385
  const recordedAt = input.recordedAt ?? new Date().toISOString();
316
- const runId = input.runId ?? createPersistentId(new Date(recordedAt));
317
- const threadId = input.threadId ?? `memory-api-${runId}`;
386
+ const runId = requestId ?? createPersistentId(new Date(recordedAt));
387
+ const threadId = sessionId ?? `memory-api-${runId}`;
318
388
  return this.persistStructuredMemoryCandidates(binding, {
319
389
  candidates: candidates.map((record) => ({ ...record, content: record.content.trim() })),
320
390
  threadId,
@@ -334,6 +404,7 @@ export class AgentHarnessRuntime {
334
404
  if (typeof input.query !== "string" || input.query.trim().length === 0) {
335
405
  throw new Error("recall requires a non-empty query.");
336
406
  }
407
+ const sessionId = input.sessionId ?? input.threadId;
337
408
  const workspaceId = this.getWorkspaceId(binding);
338
409
  const agentId = input.agentId ?? binding.agent.id;
339
410
  const userId = input.userId ?? "default";
@@ -350,7 +421,7 @@ export class AgentHarnessRuntime {
350
421
  topK,
351
422
  includeStale: input.includeStale === true,
352
423
  filters: {
353
- threadId: input.threadId,
424
+ threadId: sessionId,
354
425
  agentId,
355
426
  workspaceId: input.workspaceId ?? workspaceId,
356
427
  userId,
@@ -366,6 +437,7 @@ export class AgentHarnessRuntime {
366
437
  if (!binding) {
367
438
  throw new Error("listMemories requires a runtime entry binding.");
368
439
  }
440
+ const sessionId = input.sessionId ?? input.threadId;
369
441
  const workspaceId = this.getWorkspaceId(binding);
370
442
  const scopes = Array.isArray(input.scopes) && input.scopes.length > 0
371
443
  ? Array.from(new Set(input.scopes))
@@ -379,7 +451,7 @@ export class AgentHarnessRuntime {
379
451
  .filter((record) => statuses.has(record.status))
380
452
  .filter((record) => !kinds || kinds.has(record.kind))
381
453
  .filter((record) => this.matchesMemoryFilters(record, {
382
- threadId: input.threadId,
454
+ threadId: sessionId,
383
455
  agentId: input.agentId,
384
456
  workspaceId: input.workspaceId ?? workspaceId,
385
457
  userId: input.userId,
@@ -453,17 +525,119 @@ export class AgentHarnessRuntime {
453
525
  await this.refreshStructuredMemoryScope(binding, existing);
454
526
  return existing;
455
527
  }
528
+ async getRequest(requestId) {
529
+ const request = await this.persistence.getRun(requestId);
530
+ return request
531
+ ? {
532
+ requestId: request.runId,
533
+ sessionId: request.threadId,
534
+ agentId: request.agentId,
535
+ executionMode: request.executionMode,
536
+ adapterKind: request.adapterKind,
537
+ createdAt: request.createdAt,
538
+ updatedAt: request.updatedAt,
539
+ state: request.state,
540
+ checkpointRef: request.checkpointRef,
541
+ resumable: request.resumable,
542
+ startedAt: request.startedAt,
543
+ endedAt: request.endedAt,
544
+ lastActivityAt: request.lastActivityAt,
545
+ currentAgentId: request.currentAgentId,
546
+ delegationChain: request.delegationChain,
547
+ runtimeSnapshot: request.runtimeSnapshot,
548
+ }
549
+ : null;
550
+ }
456
551
  async getRun(runId) {
457
- return this.persistence.getRun(runId);
552
+ const request = await this.getRequest(runId);
553
+ return request
554
+ ? {
555
+ runId: request.requestId,
556
+ threadId: request.sessionId,
557
+ agentId: request.agentId,
558
+ executionMode: request.executionMode,
559
+ adapterKind: request.adapterKind,
560
+ createdAt: request.createdAt,
561
+ updatedAt: request.updatedAt,
562
+ state: request.state,
563
+ checkpointRef: request.checkpointRef,
564
+ resumable: request.resumable,
565
+ startedAt: request.startedAt,
566
+ endedAt: request.endedAt,
567
+ lastActivityAt: request.lastActivityAt,
568
+ currentAgentId: request.currentAgentId,
569
+ delegationChain: request.delegationChain,
570
+ runtimeSnapshot: request.runtimeSnapshot,
571
+ }
572
+ : null;
573
+ }
574
+ async getSessionSummary(sessionId) {
575
+ const session = await this.persistence.getSession(sessionId);
576
+ return session
577
+ ? {
578
+ agentId: session.agentId,
579
+ sessionId: session.threadId,
580
+ latestRequestId: session.latestRunId,
581
+ createdAt: session.createdAt,
582
+ updatedAt: session.updatedAt,
583
+ status: session.status,
584
+ currentAgentId: session.currentAgentId,
585
+ }
586
+ : null;
458
587
  }
459
588
  async getSession(threadId) {
460
- return this.persistence.getSession(threadId);
589
+ const session = await this.getSessionSummary(threadId);
590
+ return session
591
+ ? {
592
+ agentId: session.agentId,
593
+ threadId: session.sessionId,
594
+ latestRunId: session.latestRequestId,
595
+ createdAt: session.createdAt,
596
+ updatedAt: session.updatedAt,
597
+ status: session.status,
598
+ currentAgentId: session.currentAgentId,
599
+ }
600
+ : null;
461
601
  }
462
- async getThread(threadId) {
463
- return buildThreadInspectionRecord({
602
+ async getSessionRecord(sessionId) {
603
+ return buildSessionInspectionRecord({
464
604
  persistence: this.persistence,
465
- getSession: (currentThreadId) => this.getSession(currentThreadId),
466
- }, threadId);
605
+ getSession: (currentSessionId) => this.getSessionSummary(currentSessionId),
606
+ }, sessionId);
607
+ }
608
+ async getThread(threadId) {
609
+ const session = await this.getSessionRecord(threadId);
610
+ return session
611
+ ? {
612
+ threadId: session.sessionId,
613
+ entryAgentId: session.entryAgentId,
614
+ currentAgentId: session.currentAgentId,
615
+ currentState: session.currentState,
616
+ latestRunId: session.latestRequestId,
617
+ createdAt: session.createdAt,
618
+ updatedAt: session.updatedAt,
619
+ messages: session.messages,
620
+ runs: session.requests.map((request) => ({
621
+ runId: request.requestId,
622
+ threadId: request.sessionId,
623
+ agentId: request.agentId,
624
+ executionMode: request.executionMode,
625
+ adapterKind: request.adapterKind,
626
+ createdAt: request.createdAt,
627
+ updatedAt: request.updatedAt,
628
+ state: request.state,
629
+ checkpointRef: request.checkpointRef,
630
+ resumable: request.resumable,
631
+ startedAt: request.startedAt,
632
+ endedAt: request.endedAt,
633
+ lastActivityAt: request.lastActivityAt,
634
+ currentAgentId: request.currentAgentId,
635
+ delegationChain: request.delegationChain,
636
+ runtimeSnapshot: request.runtimeSnapshot,
637
+ })),
638
+ pendingDecision: session.pendingDecision,
639
+ }
640
+ : null;
467
641
  }
468
642
  async listApprovals(filter) {
469
643
  return listPublicApprovals({
@@ -481,15 +655,18 @@ export class AgentHarnessRuntime {
481
655
  async readArtifact(threadId, runId, artifactPath) {
482
656
  return this.persistence.readArtifact(threadId, runId, artifactPath);
483
657
  }
658
+ async listRequestEvents(sessionId, requestId) {
659
+ return this.persistence.listRunEvents(sessionId, requestId);
660
+ }
484
661
  async listRunEvents(threadId, runId) {
485
- return this.persistence.listRunEvents(threadId, runId);
662
+ return this.listRequestEvents(threadId, runId);
486
663
  }
487
- async exportRunPackage(input) {
488
- const thread = await this.getThread(input.sessionId);
489
- const run = await this.getRun(input.requestId);
664
+ async exportRequestPackage(input) {
665
+ const session = await this.getSessionRecord(input.sessionId);
666
+ const request = await this.getRequest(input.requestId);
490
667
  const approvals = await this.listApprovals({ threadId: input.sessionId, runId: input.requestId });
491
668
  const transcript = await this.persistence.listThreadMessages(input.sessionId, 500);
492
- const events = await this.persistence.listRunEvents(input.sessionId, input.requestId);
669
+ const events = await this.listRequestEvents(input.sessionId, input.requestId);
493
670
  const artifactsListing = input.includeArtifacts === false
494
671
  ? { items: [] }
495
672
  : await this.persistence.listArtifacts(input.sessionId, input.requestId);
@@ -500,8 +677,8 @@ export class AgentHarnessRuntime {
500
677
  : {}),
501
678
  })));
502
679
  return {
503
- session: thread ? toSessionRecord(thread) : null,
504
- request: run ? toRequestRecord(run) : null,
680
+ session,
681
+ request,
505
682
  approvals,
506
683
  transcript,
507
684
  events,
@@ -509,10 +686,13 @@ export class AgentHarnessRuntime {
509
686
  ...(input.includeRuntimeHealth === false ? {} : { runtimeHealth: await this.getHealth() }),
510
687
  };
511
688
  }
689
+ async exportRunPackage(input) {
690
+ return this.exportRequestPackage(input);
691
+ }
512
692
  async exportSessionPackage(input) {
513
- const thread = await this.getThread(input.sessionId);
514
- const runIds = Array.from(new Set((thread?.runs ?? []).map((item) => item.runId)));
515
- const runs = await Promise.all(runIds.map((requestId) => this.exportRunPackage({
693
+ const session = await this.getSessionRecord(input.sessionId);
694
+ const requestIds = Array.from(new Set((session?.requests ?? []).map((item) => item.requestId)));
695
+ const runs = await Promise.all(requestIds.map((requestId) => this.exportRequestPackage({
516
696
  sessionId: input.sessionId,
517
697
  requestId,
518
698
  includeArtifacts: input.includeArtifacts,
@@ -520,7 +700,7 @@ export class AgentHarnessRuntime {
520
700
  includeRuntimeHealth: false,
521
701
  })));
522
702
  return {
523
- session: thread ? toSessionRecord(thread) : null,
703
+ session,
524
704
  requests: runs.map((item) => item.request).filter((item) => Boolean(item)),
525
705
  approvals: await this.listApprovals({ threadId: input.sessionId }),
526
706
  transcript: await this.persistence.listThreadMessages(input.sessionId, 500),
@@ -638,7 +818,17 @@ export class AgentHarnessRuntime {
638
818
  }
639
819
  }
640
820
  }
821
+ async deleteSession(sessionId) {
822
+ return deleteSessionRecord({
823
+ getSession: (currentSessionId) => this.getSessionRecord(currentSessionId),
824
+ deleteSession: (currentSessionId) => this.persistence.deleteThread(currentSessionId),
825
+ deleteSessionCheckpoints: (currentSessionId) => this.deleteThreadCheckpoints(currentSessionId),
826
+ }, sessionId);
827
+ }
641
828
  async deleteThread(threadId) {
829
+ return this.deleteSession(threadId);
830
+ }
831
+ async deleteThreadLegacy(threadId) {
642
832
  return deleteThreadRecord({
643
833
  getThread: (currentThreadId) => this.getThread(currentThreadId),
644
834
  deleteThread: (currentThreadId) => this.persistence.deleteThread(currentThreadId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/agent-harness",
3
- "version": "0.0.184",
3
+ "version": "0.0.186",
4
4
  "description": "Workspace runtime for multi-agent applications",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.9.2",