@botbotgo/agent-harness 0.0.125 → 0.0.126

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
@@ -281,9 +281,9 @@ const result = await run(runtime, {
281
281
  });
282
282
  ```
283
283
 
284
- `run(runtime, { ... })` creates or continues a persisted thread and returns `threadId`, `runId`, `state`, and compact text `output`. Richer upstream result shapes stay available through `outputContent`, `contentBlocks`, and `structuredResponse`.
284
+ `run(runtime, { ... })` creates or continues a persisted session and returns `sessionId`, `requestId`, `state`, and compact text `output`. Richer upstream result shapes stay available through `outputContent`, `contentBlocks`, and `structuredResponse`.
285
285
 
286
- Use `listRuns(runtime)` and `getRun(runtime, runId)` when a product needs a run-centric operations surface such as a review queue or execution dashboard.
286
+ Use `listRequests(runtime)` and `getRequest(runtime, requestId)` when a product needs a request-centric operations surface such as a review queue or execution dashboard.
287
287
 
288
288
  Use `invocation` as the runtime-facing request envelope:
289
289
 
@@ -334,19 +334,19 @@ The runtime event stream includes:
334
334
  - `approval.resolved`
335
335
  - `output.delta`
336
336
 
337
- ### Inspect Threads And Approvals
337
+ ### Inspect Sessions And Approvals
338
338
 
339
339
  ```ts
340
340
  import {
341
+ getSession,
341
342
  getApproval,
342
- getThread,
343
+ listSessions,
343
344
  listApprovals,
344
- listThreads,
345
345
  resolveApproval,
346
346
  } from "@botbotgo/agent-harness";
347
347
 
348
- const threads = await listThreads(runtime);
349
- const thread = await getThread(runtime, threads[0]!.threadId);
348
+ const sessions = await listSessions(runtime);
349
+ const session = await getSession(runtime, sessions[0]!.sessionId);
350
350
  const approvals = await listApprovals(runtime, { status: "pending" });
351
351
  const approval = approvals[0] ? await getApproval(runtime, approvals[0].approvalId) : null;
352
352
 
@@ -690,11 +690,11 @@ Primary exports:
690
690
  - `run`
691
691
  - `resolveApproval`
692
692
  - `subscribe`
693
- - `listRuns`
694
- - `getRun`
695
- - `listThreads`
696
- - `getThread`
697
- - `deleteThread`
693
+ - `listRequests`
694
+ - `getRequest`
695
+ - `listSessions`
696
+ - `getSession`
697
+ - `deleteSession`
698
698
  - `listApprovals`
699
699
  - `getApproval`
700
700
  - `createToolMcpServer`
package/README.zh.md CHANGED
@@ -281,9 +281,9 @@ const result = await run(runtime, {
281
281
  });
282
282
  ```
283
283
 
284
- `run(runtime, { ... })` 会创建或延续持久化线程,并返回 `threadId`、`runId`、`state` 以及紧凑文本 `output`。更丰富的上游结果形态仍可通过 `outputContent`、`contentBlocks`、`structuredResponse` 等获得。
284
+ `run(runtime, { ... })` 会创建或延续持久化会话,并返回 `sessionId`、`requestId`、`state` 以及紧凑文本 `output`。更丰富的上游结果形态仍可通过 `outputContent`、`contentBlocks`、`structuredResponse` 等获得。
285
285
 
286
- 如果产品需要 run 视角的操作界面,例如 review queue 或执行看板,可使用 `listRuns(runtime)` 与 `getRun(runtime, runId)`。
286
+ 如果产品需要 request 视角的操作界面,例如 review queue 或执行看板,可使用 `listRequests(runtime)` 与 `getRequest(runtime, requestId)`。
287
287
 
288
288
  将 `invocation` 作为面向运行时的请求信封:
289
289
 
@@ -339,14 +339,14 @@ const result = await run(runtime, {
339
339
  ```ts
340
340
  import {
341
341
  getApproval,
342
- getThread,
342
+ getSession,
343
343
  listApprovals,
344
- listThreads,
344
+ listSessions,
345
345
  resolveApproval,
346
346
  } from "@botbotgo/agent-harness";
347
347
 
348
- const threads = await listThreads(runtime);
349
- const thread = await getThread(runtime, threads[0]!.threadId);
348
+ const sessions = await listSessions(runtime);
349
+ const session = await getSession(runtime, sessions[0]!.sessionId);
350
350
  const approvals = await listApprovals(runtime, { status: "pending" });
351
351
  const approval = approvals[0] ? await getApproval(runtime, approvals[0].approvalId) : null;
352
352
 
@@ -687,11 +687,11 @@ spec:
687
687
  - `run`
688
688
  - `resolveApproval`
689
689
  - `subscribe`
690
- - `listRuns`
691
- - `getRun`
692
- - `listThreads`
693
- - `getThread`
694
- - `deleteThread`
690
+ - `listRequests`
691
+ - `getRequest`
692
+ - `listSessions`
693
+ - `getSession`
694
+ - `deleteSession`
695
695
  - `listApprovals`
696
696
  - `getApproval`
697
697
  - `createToolMcpServer`
package/dist/api.d.ts CHANGED
@@ -1,10 +1,39 @@
1
- import type { ApprovalRecord, CancelOptions, RunRecord, RunOptions, RunSummary, ResumeOptions, RuntimeHealthSnapshot, RuntimeAdapterOptions, ThreadSummary, ThreadRecord, WorkspaceLoadOptions } from "./contracts/types.js";
1
+ import type { CancelOptions, RequestRecord, RequestSummary, ResumeOptions, RunDecisionOptions, RunResult, RunStartOptions, RuntimeHealthSnapshot, RuntimeAdapterOptions, SessionRecord, SessionSummary, WorkspaceLoadOptions } from "./contracts/types.js";
2
2
  import { AgentHarnessRuntime } from "./runtime/harness.js";
3
3
  import type { InventoryAgentRecord, InventorySkillRecord } from "./runtime/harness/system/inventory.js";
4
4
  import type { RequirementAssessmentOptions } from "./runtime/harness/system/skill-requirements.js";
5
5
  import type { ToolMcpServerOptions } from "./mcp.js";
6
6
  export { AgentHarnessRuntime } from "./runtime/harness.js";
7
7
  export { createUpstreamTimelineReducer } from "./upstream-events.js";
8
+ type PublicApprovalRecord = {
9
+ approvalId: string;
10
+ pendingActionId: string;
11
+ sessionId: string;
12
+ requestId: string;
13
+ toolName: string;
14
+ status: "pending" | "approved" | "edited" | "rejected" | "expired";
15
+ requestedAt: string;
16
+ resolvedAt: string | null;
17
+ allowedDecisions: Array<"approve" | "edit" | "reject">;
18
+ inputPreview: Record<string, unknown>;
19
+ };
20
+ type PublicApprovalFilter = {
21
+ status?: PublicApprovalRecord["status"];
22
+ sessionId?: string;
23
+ requestId?: string;
24
+ };
25
+ type PublicRunStartOptions = Omit<RunStartOptions, "threadId"> & {
26
+ sessionId?: string;
27
+ };
28
+ type PublicRunDecisionOptions = Omit<RunDecisionOptions, "threadId" | "runId"> & {
29
+ sessionId: string;
30
+ requestId?: string;
31
+ };
32
+ type PublicRunOptions = PublicRunStartOptions | PublicRunDecisionOptions;
33
+ type PublicRunResult = Omit<RunResult, "threadId" | "runId"> & {
34
+ sessionId: string;
35
+ requestId: string;
36
+ };
8
37
  type CreateAgentHarnessOptions = {
9
38
  /**
10
39
  * Workspace loading behavior.
@@ -15,23 +44,32 @@ type CreateAgentHarnessOptions = {
15
44
  };
16
45
  export declare function createAgentHarness(): Promise<AgentHarnessRuntime>;
17
46
  export declare function createAgentHarness(workspaceRoot: string, options?: CreateAgentHarnessOptions): Promise<AgentHarnessRuntime>;
18
- export declare function run(runtime: AgentHarnessRuntime, options: RunOptions): Promise<import("./contracts/runtime.js").RunResult>;
47
+ export declare function run(runtime: AgentHarnessRuntime, options: PublicRunOptions): Promise<PublicRunResult>;
19
48
  export declare function subscribe(runtime: AgentHarnessRuntime, listener: Parameters<AgentHarnessRuntime["subscribe"]>[0]): () => void;
20
- export declare function listThreads(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listThreads"]>[0]): Promise<ThreadSummary[]>;
21
- export declare function listRuns(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listRuns"]>[0]): Promise<RunSummary[]>;
22
- export declare function getThread(runtime: AgentHarnessRuntime, threadId: string): Promise<ThreadRecord | null>;
23
- export declare function getRun(runtime: AgentHarnessRuntime, runId: string): Promise<RunRecord | null>;
24
- export declare function deleteThread(runtime: AgentHarnessRuntime, threadId: string): Promise<boolean>;
25
- export declare function listApprovals(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listApprovals"]>[0]): Promise<ApprovalRecord[]>;
26
- export declare function getApproval(runtime: AgentHarnessRuntime, approvalId: string): Promise<ApprovalRecord | null>;
49
+ export declare function listSessions(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listThreads"]>[0]): Promise<SessionSummary[]>;
50
+ export declare function listRequests(runtime: AgentHarnessRuntime, filter?: {
51
+ agentId?: string;
52
+ sessionId?: string;
53
+ state?: RequestSummary["state"];
54
+ }): Promise<RequestSummary[]>;
55
+ export declare function getSession(runtime: AgentHarnessRuntime, sessionId: string): Promise<SessionRecord | null>;
56
+ export declare function getRequest(runtime: AgentHarnessRuntime, requestId: string): Promise<RequestRecord | null>;
57
+ export declare function deleteSession(runtime: AgentHarnessRuntime, sessionId: string): Promise<boolean>;
58
+ export declare function listApprovals(runtime: AgentHarnessRuntime, filter?: PublicApprovalFilter): Promise<PublicApprovalRecord[]>;
59
+ export declare function getApproval(runtime: AgentHarnessRuntime, approvalId: string): Promise<PublicApprovalRecord | null>;
27
60
  export declare function getHealth(runtime: AgentHarnessRuntime): Promise<RuntimeHealthSnapshot>;
28
61
  export declare function listAgentSkills(runtime: AgentHarnessRuntime, agentId: string, options?: RequirementAssessmentOptions): InventorySkillRecord[];
29
62
  export declare function describeInventory(runtime: AgentHarnessRuntime, options?: RequirementAssessmentOptions): {
30
63
  workspaceRoot: string;
31
64
  agents: InventoryAgentRecord[];
32
65
  };
33
- export declare function resolveApproval(runtime: AgentHarnessRuntime, options: ResumeOptions): Promise<import("./contracts/runtime.js").RunResult>;
34
- export declare function cancelRun(runtime: AgentHarnessRuntime, options: CancelOptions): Promise<import("./contracts/runtime.js").RunResult>;
66
+ export declare function resolveApproval(runtime: AgentHarnessRuntime, options: ResumeOptions & {
67
+ sessionId?: string;
68
+ requestId?: string;
69
+ }): Promise<PublicRunResult>;
70
+ export declare function cancelRun(runtime: AgentHarnessRuntime, options: CancelOptions & {
71
+ requestId?: string;
72
+ }): Promise<RunResult>;
35
73
  export declare function stop(runtime: AgentHarnessRuntime): Promise<void>;
36
74
  export declare function createToolMcpServer(runtime: AgentHarnessRuntime, options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
37
75
  export declare function serveToolsOverStdio(runtime: AgentHarnessRuntime, options: ToolMcpServerOptions): Promise<import("@modelcontextprotocol/sdk/server/mcp.js").McpServer>;
package/dist/api.js CHANGED
@@ -2,6 +2,108 @@ import { AgentHarnessRuntime } from "./runtime/harness.js";
2
2
  import { loadWorkspace } from "./workspace/compile.js";
3
3
  export { AgentHarnessRuntime } from "./runtime/harness.js";
4
4
  export { createUpstreamTimelineReducer } from "./upstream-events.js";
5
+ function toSessionSummary(summary) {
6
+ return {
7
+ agentId: summary.agentId,
8
+ sessionId: summary.threadId,
9
+ latestRequestId: summary.latestRunId,
10
+ createdAt: summary.createdAt,
11
+ updatedAt: summary.updatedAt,
12
+ status: summary.status,
13
+ };
14
+ }
15
+ function toRequestSummary(summary) {
16
+ return {
17
+ requestId: summary.runId,
18
+ sessionId: summary.threadId,
19
+ agentId: summary.agentId,
20
+ executionMode: summary.executionMode,
21
+ adapterKind: summary.adapterKind,
22
+ createdAt: summary.createdAt,
23
+ updatedAt: summary.updatedAt,
24
+ state: summary.state,
25
+ checkpointRef: summary.checkpointRef,
26
+ resumable: summary.resumable,
27
+ };
28
+ }
29
+ function toSessionRecord(record) {
30
+ return {
31
+ sessionId: record.threadId,
32
+ entryAgentId: record.entryAgentId,
33
+ currentState: record.currentState,
34
+ latestRequestId: record.latestRunId,
35
+ createdAt: record.createdAt,
36
+ updatedAt: record.updatedAt,
37
+ messages: record.messages,
38
+ requests: record.runs.map(toRequestSummary),
39
+ pendingDecision: record.pendingDecision,
40
+ };
41
+ }
42
+ function toRequestRecord(record) {
43
+ return toRequestSummary(record);
44
+ }
45
+ function toApprovalRecord(record) {
46
+ return {
47
+ approvalId: record.approvalId,
48
+ pendingActionId: record.pendingActionId,
49
+ sessionId: record.threadId,
50
+ requestId: record.runId,
51
+ toolName: record.toolName,
52
+ status: record.status,
53
+ requestedAt: record.requestedAt,
54
+ resolvedAt: record.resolvedAt,
55
+ allowedDecisions: record.allowedDecisions,
56
+ inputPreview: record.inputPreview,
57
+ };
58
+ }
59
+ function toPublicRunResult(result) {
60
+ return {
61
+ sessionId: result.threadId,
62
+ requestId: result.runId,
63
+ state: result.state,
64
+ output: result.output,
65
+ finalMessageText: result.finalMessageText,
66
+ outputContent: result.outputContent,
67
+ contentBlocks: result.contentBlocks,
68
+ structuredResponse: result.structuredResponse,
69
+ interruptContent: result.interruptContent,
70
+ agentId: result.agentId,
71
+ approvalId: result.approvalId,
72
+ pendingActionId: result.pendingActionId,
73
+ delegationId: result.delegationId,
74
+ artifacts: result.artifacts,
75
+ metadata: result.metadata,
76
+ };
77
+ }
78
+ function toInternalRunOptions(options) {
79
+ if ("decision" in options) {
80
+ return {
81
+ approvalId: options.approvalId,
82
+ decision: options.decision,
83
+ editedInput: options.editedInput,
84
+ listeners: options.listeners,
85
+ runId: options.requestId,
86
+ threadId: options.sessionId,
87
+ };
88
+ }
89
+ return {
90
+ agentId: options.agentId,
91
+ input: options.input,
92
+ invocation: options.invocation,
93
+ listeners: options.listeners,
94
+ priority: options.priority,
95
+ threadId: options.sessionId,
96
+ };
97
+ }
98
+ function toInternalResumeOptions(options) {
99
+ return {
100
+ approvalId: options.approvalId,
101
+ decision: options.decision,
102
+ editedInput: options.editedInput,
103
+ runId: options.requestId ?? options.runId,
104
+ threadId: options.sessionId ?? options.threadId,
105
+ };
106
+ }
5
107
  export async function createAgentHarness(workspaceRoot = process.cwd(), options = {}) {
6
108
  const workspace = await loadWorkspace(workspaceRoot, options.load ?? {});
7
109
  const harness = new AgentHarnessRuntime(workspace, options.adapter ?? {});
@@ -9,31 +111,42 @@ export async function createAgentHarness(workspaceRoot = process.cwd(), options
9
111
  return harness;
10
112
  }
11
113
  export async function run(runtime, options) {
12
- return runtime.run(options);
114
+ return toPublicRunResult(await runtime.run(toInternalRunOptions(options)));
13
115
  }
14
116
  export function subscribe(runtime, listener) {
15
117
  return runtime.subscribe(listener);
16
118
  }
17
- export async function listThreads(runtime, filter) {
18
- return runtime.listThreads(filter);
119
+ export async function listSessions(runtime, filter) {
120
+ return (await runtime.listThreads(filter)).map(toSessionSummary);
19
121
  }
20
- export async function listRuns(runtime, filter) {
21
- return runtime.listRuns(filter);
122
+ export async function listRequests(runtime, filter) {
123
+ return (await runtime.listRuns({
124
+ agentId: filter?.agentId,
125
+ state: filter?.state,
126
+ threadId: filter?.sessionId,
127
+ })).map(toRequestSummary);
22
128
  }
23
- export async function getThread(runtime, threadId) {
24
- return runtime.getThread(threadId);
129
+ export async function getSession(runtime, sessionId) {
130
+ const record = await runtime.getThread(sessionId);
131
+ return record ? toSessionRecord(record) : null;
25
132
  }
26
- export async function getRun(runtime, runId) {
27
- return runtime.getRun(runId);
133
+ export async function getRequest(runtime, requestId) {
134
+ const record = await runtime.getRun(requestId);
135
+ return record ? toRequestRecord(record) : null;
28
136
  }
29
- export async function deleteThread(runtime, threadId) {
30
- return runtime.deleteThread(threadId);
137
+ export async function deleteSession(runtime, sessionId) {
138
+ return runtime.deleteThread(sessionId);
31
139
  }
32
140
  export async function listApprovals(runtime, filter) {
33
- return runtime.listApprovals(filter);
141
+ return (await runtime.listApprovals({
142
+ runId: filter?.requestId,
143
+ status: filter?.status,
144
+ threadId: filter?.sessionId,
145
+ })).map(toApprovalRecord);
34
146
  }
35
147
  export async function getApproval(runtime, approvalId) {
36
- return runtime.getApproval(approvalId);
148
+ const record = await runtime.getApproval(approvalId);
149
+ return record ? toApprovalRecord(record) : null;
37
150
  }
38
151
  export async function getHealth(runtime) {
39
152
  return runtime.getHealth();
@@ -45,10 +158,13 @@ export function describeInventory(runtime, options) {
45
158
  return runtime.describeWorkspaceInventory(options);
46
159
  }
47
160
  export async function resolveApproval(runtime, options) {
48
- return runtime.resume(options);
161
+ return toPublicRunResult(await runtime.resume(toInternalResumeOptions(options)));
49
162
  }
50
163
  export async function cancelRun(runtime, options) {
51
- return runtime.cancelRun(options);
164
+ return runtime.cancelRun({
165
+ ...options,
166
+ runId: options.requestId ?? options.runId,
167
+ });
52
168
  }
53
169
  export async function stop(runtime) {
54
170
  return runtime.stop();
@@ -13,7 +13,10 @@ export type ThreadSummary = {
13
13
  updatedAt: string;
14
14
  status: RunState;
15
15
  };
16
- export type SessionRecord = ThreadSummary;
16
+ export type SessionSummary = Omit<ThreadSummary, "threadId" | "latestRunId"> & {
17
+ sessionId: string;
18
+ latestRequestId: string;
19
+ };
17
20
  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";
18
21
  export type HarnessEventType = KnownHarnessEventType | (string & {});
19
22
  /**
@@ -172,6 +175,11 @@ export type ThreadRunRecord = {
172
175
  */
173
176
  export type RunSummary = ThreadRunRecord;
174
177
  export type RunRecord = RunSummary;
178
+ export type RequestSummary = Omit<RunSummary, "threadId" | "runId"> & {
179
+ sessionId: string;
180
+ requestId: string;
181
+ };
182
+ export type RequestRecord = RequestSummary;
175
183
  /**
176
184
  * Persisted thread inspection record assembled from runtime records.
177
185
  * This is an inspectable projection, not a second thread semantic model.
@@ -193,6 +201,11 @@ export type ThreadRecord = {
193
201
  requestedAt: string;
194
202
  };
195
203
  };
204
+ export type SessionRecord = Omit<ThreadRecord, "threadId" | "latestRunId" | "runs"> & {
205
+ sessionId: string;
206
+ latestRequestId: string;
207
+ requests: RequestSummary[];
208
+ };
196
209
  export type ResumeOptions = {
197
210
  threadId?: string;
198
211
  runId?: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { AgentHarnessRuntime, cancelRun, createAgentHarness, createUpstreamTimelineReducer, createToolMcpServer, deleteThread, describeInventory, getApproval, getHealth, getRun, getThread, listAgentSkills, listApprovals, listRuns, listThreads, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
1
+ export { AgentHarnessRuntime, cancelRun, createAgentHarness, createUpstreamTimelineReducer, createToolMcpServer, deleteSession, describeInventory, getApproval, getRequest, getHealth, getSession, listAgentSkills, listApprovals, listRequests, listSessions, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
2
2
  export type { ToolMcpServerOptions } from "./mcp.js";
3
3
  export { tool } from "./tools.js";
4
4
  export type { UpstreamTimelineProjection, UpstreamTimelineReducer } from "./upstream-events.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { AgentHarnessRuntime, cancelRun, createAgentHarness, createUpstreamTimelineReducer, createToolMcpServer, deleteThread, describeInventory, getApproval, getHealth, getRun, getThread, listAgentSkills, listApprovals, listRuns, listThreads, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
1
+ export { AgentHarnessRuntime, cancelRun, createAgentHarness, createUpstreamTimelineReducer, createToolMcpServer, deleteSession, describeInventory, getApproval, getRequest, getHealth, getSession, listAgentSkills, listApprovals, listRequests, listSessions, resolveApproval, run, serveToolsOverStdio, subscribe, stop, } from "./api.js";
2
2
  export { tool } from "./tools.js";
@@ -1 +1 @@
1
- export declare const AGENT_HARNESS_VERSION = "0.0.124";
1
+ export declare const AGENT_HARNESS_VERSION = "0.0.125";
@@ -1 +1 @@
1
- export const AGENT_HARNESS_VERSION = "0.0.124";
1
+ export const AGENT_HARNESS_VERSION = "0.0.125";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/agent-harness",
3
- "version": "0.0.125",
3
+ "version": "0.0.126",
4
4
  "description": "Workspace runtime for multi-agent applications",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.9.2",