@botbotgo/agent-harness 0.0.155 → 0.0.157
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 +34 -6
- package/README.zh.md +34 -6
- package/dist/acp.d.ts +86 -0
- package/dist/acp.js +208 -0
- package/dist/api.d.ts +17 -2
- package/dist/api.js +19 -0
- package/dist/contracts/runtime.d.ts +79 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/persistence/file-store.d.ts +1 -0
- package/dist/persistence/file-store.js +10 -1
- package/dist/persistence/types.d.ts +2 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +5 -1
- package/dist/runtime/agent-runtime-adapter.js +61 -24
- package/dist/runtime/harness/run/governance.d.ts +2 -0
- package/dist/runtime/harness/run/governance.js +76 -0
- package/dist/runtime/harness/run/inspection.js +4 -0
- package/dist/runtime/harness/system/policy-engine.d.ts +2 -1
- package/dist/runtime/harness/system/policy-engine.js +5 -1
- package/dist/runtime/harness/system/runtime-memory-records.d.ts +3 -0
- package/dist/runtime/harness/system/runtime-memory-records.js +48 -2
- package/dist/runtime/harness.d.ts +11 -1
- package/dist/runtime/harness.js +221 -2
- package/dist/workspace/agent-binding-compiler.js +7 -1
- package/dist/workspace/object-loader.js +9 -44
- package/dist/workspace/yaml-object-reader.d.ts +0 -4
- package/dist/workspace/yaml-object-reader.js +4 -32
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@ That means:
|
|
|
118
118
|
|
|
119
119
|
The runtime provides:
|
|
120
120
|
|
|
121
|
-
- `createAgentHarness(workspaceRoot)`, `run(...)`, `memorize(...)`, `recall(...)`, `resolveApproval(...)`, `subscribe(...)`, inspection methods, and `stop(...)`
|
|
121
|
+
- `createAgentHarness(workspaceRoot)`, `run(...)`, `memorize(...)`, `recall(...)`, `listMemories(...)`, `updateMemory(...)`, `removeMemory(...)`, `resolveApproval(...)`, `subscribe(...)`, inspection methods, and `stop(...)`
|
|
122
122
|
- YAML-defined workspace assembly for routing, models, tools, stores, backends, MCP, recovery, and maintenance
|
|
123
123
|
- backend-adapted execution with current LangChain v1 and DeepAgents adapters
|
|
124
124
|
- local `resources/tools/` `tool({...})` modules and `resources/skills/` discovery
|
|
@@ -414,10 +414,13 @@ const recalled = await recall(runtime, {
|
|
|
414
414
|
});
|
|
415
415
|
```
|
|
416
416
|
|
|
417
|
-
Use `memorize(...)` and `
|
|
417
|
+
Use `memorize(...)`, `recall(...)`, `listMemories(...)`, `updateMemory(...)`, and `removeMemory(...)` when an application needs a stable public runtime memory surface without importing internal `runtime/harness/system/*` modules.
|
|
418
418
|
|
|
419
419
|
- `memorize(...)` returns stable `MemoryRecord` and `MemoryDecision` results while leaving merge, review, archive, and storage layout runtime-managed
|
|
420
420
|
- `recall(...)` returns ranked `MemoryRecord` items filtered by runtime memory scope and kind
|
|
421
|
+
- `listMemories(...)` returns stable `MemoryRecord` items for inspection and admin workflows, defaulting to `active` records unless status filters are provided
|
|
422
|
+
- `updateMemory(...)` edits one durable memory record by `memoryId` without exposing internal store namespaces
|
|
423
|
+
- `removeMemory(...)` deletes one durable memory record by `memoryId` and rebuilds runtime-managed projections
|
|
421
424
|
- app-specific knowledge taxonomy, review UI, and admin surfaces still belong in the application layer
|
|
422
425
|
|
|
423
426
|
### Let The Runtime Route
|
|
@@ -467,6 +470,7 @@ The runtime event stream includes:
|
|
|
467
470
|
|
|
468
471
|
```ts
|
|
469
472
|
import {
|
|
473
|
+
deleteSession,
|
|
470
474
|
getSession,
|
|
471
475
|
getApproval,
|
|
472
476
|
listSessions,
|
|
@@ -485,6 +489,10 @@ if (approval) {
|
|
|
485
489
|
decision: "approve",
|
|
486
490
|
});
|
|
487
491
|
}
|
|
492
|
+
|
|
493
|
+
if (session && session.currentState === "completed") {
|
|
494
|
+
await deleteSession(runtime, session.sessionId);
|
|
495
|
+
}
|
|
488
496
|
```
|
|
489
497
|
|
|
490
498
|
These methods return runtime-facing records, not raw checkpoint or backend objects.
|
|
@@ -548,6 +556,13 @@ Core workspace files:
|
|
|
548
556
|
- `resources/tools/`
|
|
549
557
|
- `resources/skills/`
|
|
550
558
|
|
|
559
|
+
Discovery rules:
|
|
560
|
+
|
|
561
|
+
- every YAML document under `config/**` is discovered recursively; filenames and subfolders are organizational only
|
|
562
|
+
- YAML object semantics come from `kind`, `metadata.name` or `id`, and object content rather than the file path
|
|
563
|
+
- local tools are auto-discovered from `resources/tools/**/*.js|*.mjs|*.cjs` when they export `tool({...})`
|
|
564
|
+
- skills are auto-discovered from `resources/skills/**/SKILL.md`
|
|
565
|
+
|
|
551
566
|
Workspace-local tool modules in `resources/tools/` should be exported with `tool({...})`.
|
|
552
567
|
Any other local module shape is not supported, and unsupported shapes are rejected at load time.
|
|
553
568
|
|
|
@@ -563,7 +578,7 @@ There are three main configuration layers:
|
|
|
563
578
|
|
|
564
579
|
- runtime policy in `config/runtime/workspace.yaml`
|
|
565
580
|
- reusable object catalogs in `config/catalogs/*.yaml`
|
|
566
|
-
- agent assembly in `config
|
|
581
|
+
- agent assembly in `config/**/*.yaml`
|
|
567
582
|
|
|
568
583
|
### Backend Guidance
|
|
569
584
|
|
|
@@ -633,7 +648,7 @@ Use this file for shared bootstrap memory loaded at agent construction time.
|
|
|
633
648
|
|
|
634
649
|
Keep stable project context here. Treat it as startup context, not mutable long-term memory.
|
|
635
650
|
|
|
636
|
-
### `config
|
|
651
|
+
### Models Catalogs In `config/**`
|
|
637
652
|
|
|
638
653
|
Use named chat-model presets:
|
|
639
654
|
|
|
@@ -649,7 +664,9 @@ spec:
|
|
|
649
664
|
|
|
650
665
|
These load as `model/default`.
|
|
651
666
|
|
|
652
|
-
|
|
667
|
+
You can place `kind: Models` catalogs anywhere under `config/`; `config/catalogs/models.yaml` is only the recommended layout.
|
|
668
|
+
|
|
669
|
+
### Embedding Model Catalogs In `config/**`
|
|
653
670
|
|
|
654
671
|
Use named embedding-model presets for retrieval-oriented tools.
|
|
655
672
|
|
|
@@ -740,10 +757,12 @@ spec:
|
|
|
740
757
|
|
|
741
758
|
`spec[].kind` can be omitted here; catalog entries default to `McpServer`.
|
|
742
759
|
|
|
743
|
-
### `config
|
|
760
|
+
### Agents In `config/**`
|
|
744
761
|
|
|
745
762
|
Agents always use `kind: Agent` plus `spec.backend`.
|
|
746
763
|
|
|
764
|
+
Agent YAML can live anywhere under `config/`; `config/agents/*.yaml` is the recommended layout, not a loader requirement.
|
|
765
|
+
|
|
747
766
|
Use two sections:
|
|
748
767
|
|
|
749
768
|
- `spec.runtime` for harness-owned runtime placement such as `spec.runtime.runRoot`
|
|
@@ -777,10 +796,15 @@ spec:
|
|
|
777
796
|
rootDir: .
|
|
778
797
|
virtualMode: true
|
|
779
798
|
maxFileSizeMb: 10
|
|
799
|
+
sessionStorage:
|
|
800
|
+
enabled: true
|
|
801
|
+
rootDir: "{runRoot}/threads/{threadId}/filesystem"
|
|
780
802
|
middleware: []
|
|
781
803
|
systemPrompt: Answer simple requests directly.
|
|
782
804
|
```
|
|
783
805
|
|
|
806
|
+
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.
|
|
807
|
+
|
|
784
808
|
Example orchestra host:
|
|
785
809
|
|
|
786
810
|
```yaml
|
|
@@ -841,6 +865,10 @@ Primary exports:
|
|
|
841
865
|
- `deleteSession`
|
|
842
866
|
- `listApprovals`
|
|
843
867
|
- `getApproval`
|
|
868
|
+
- `listArtifacts`
|
|
869
|
+
- `getArtifact`
|
|
870
|
+
- `exportEvaluationBundle`
|
|
871
|
+
- `createAcpServer`
|
|
844
872
|
- `createToolMcpServer`
|
|
845
873
|
- `serveToolsOverStdio`
|
|
846
874
|
- `stop`
|
package/README.zh.md
CHANGED
|
@@ -118,7 +118,7 @@ AI 让 agent 逻辑、工具调用和工作流代码更容易生成,真正更
|
|
|
118
118
|
|
|
119
119
|
运行时提供:
|
|
120
120
|
|
|
121
|
-
- `createAgentHarness(workspaceRoot)`、`run(...)`、`memorize(...)`、`recall(...)`、`resolveApproval(...)`、`subscribe(...)`、各类查询方法,以及 `stop(...)`
|
|
121
|
+
- `createAgentHarness(workspaceRoot)`、`run(...)`、`memorize(...)`、`recall(...)`、`listMemories(...)`、`updateMemory(...)`、`removeMemory(...)`、`resolveApproval(...)`、`subscribe(...)`、各类查询方法,以及 `stop(...)`
|
|
122
122
|
- 以 YAML 描述的工作区装配:路由、模型、工具、存储、后端、MCP、恢复与维护等
|
|
123
123
|
- 通过适配器对接当前的 LangChain v1 与 DeepAgents 执行
|
|
124
124
|
- 本地 `resources/tools/` 中 `tool({...})` 工具模块与 `resources/skills/` 的发现
|
|
@@ -386,10 +386,13 @@ const recalled = await recall(runtime, {
|
|
|
386
386
|
});
|
|
387
387
|
```
|
|
388
388
|
|
|
389
|
-
当应用需要稳定的公开 runtime memory 接口,而不想依赖内部 `runtime/harness/system/*` 模块时,使用 `memorize(...)` 与 `
|
|
389
|
+
当应用需要稳定的公开 runtime memory 接口,而不想依赖内部 `runtime/harness/system/*` 模块时,使用 `memorize(...)`、`recall(...)`、`listMemories(...)`、`updateMemory(...)` 与 `removeMemory(...)`。
|
|
390
390
|
|
|
391
391
|
- `memorize(...)` 返回稳定的 `MemoryRecord` 与 `MemoryDecision` 结果,而 merge、review、archive 与存储布局仍由 runtime 内部托管
|
|
392
392
|
- `recall(...)` 返回按相关性排序、并按 scope / kind 过滤后的 `MemoryRecord`
|
|
393
|
+
- `listMemories(...)` 返回稳定的 `MemoryRecord`,用于 inspection / admin 场景;如果不传 status 过滤器,默认只返回 `active`
|
|
394
|
+
- `updateMemory(...)` 通过 `memoryId` 更新单条 durable memory,而不暴露内部 store namespace
|
|
395
|
+
- `removeMemory(...)` 通过 `memoryId` 删除单条 durable memory,并重建运行时托管的 projection
|
|
393
396
|
- 业务知识分类、review UI 与管理后台仍应留在应用层
|
|
394
397
|
|
|
395
398
|
### 由运行时路由
|
|
@@ -439,6 +442,7 @@ const result = await run(runtime, {
|
|
|
439
442
|
|
|
440
443
|
```ts
|
|
441
444
|
import {
|
|
445
|
+
deleteSession,
|
|
442
446
|
getApproval,
|
|
443
447
|
getSession,
|
|
444
448
|
listApprovals,
|
|
@@ -457,6 +461,10 @@ if (approval) {
|
|
|
457
461
|
decision: "approve",
|
|
458
462
|
});
|
|
459
463
|
}
|
|
464
|
+
|
|
465
|
+
if (session && session.currentState === "completed") {
|
|
466
|
+
await deleteSession(runtime, session.sessionId);
|
|
467
|
+
}
|
|
460
468
|
```
|
|
461
469
|
|
|
462
470
|
这些方法返回面向运行时的记录,而非原始 checkpoint 或后端对象。
|
|
@@ -520,6 +528,13 @@ await stop(runtime);
|
|
|
520
528
|
- `resources/tools/`
|
|
521
529
|
- `resources/skills/`
|
|
522
530
|
|
|
531
|
+
发现规则:
|
|
532
|
+
|
|
533
|
+
- `config/**` 下的所有 YAML 文档都会被递归发现;文件名与子目录只用于组织,不参与语义
|
|
534
|
+
- YAML 对象语义由 `kind`、`metadata.name` 或 `id` 以及对象内容决定,而不是由文件路径决定
|
|
535
|
+
- 本地工具会从 `resources/tools/**/*.js|*.mjs|*.cjs` 中自动发现,前提是模块导出 `tool({...})`
|
|
536
|
+
- skills 会从 `resources/skills/**/SKILL.md` 自动发现
|
|
537
|
+
|
|
523
538
|
`resources/tools/` 下的工作区本地工具模块应统一用 `tool({...})` 导出。
|
|
524
539
|
不支持历史/兼容写法,任何不带该导出形式的工具模块都会在工作区加载时被拒绝。
|
|
525
540
|
|
|
@@ -529,7 +544,7 @@ await stop(runtime);
|
|
|
529
544
|
- agent 再按名字白名单选择 tools 与 skills
|
|
530
545
|
- `config/runtime/workspace.yaml` 中的运行时策略
|
|
531
546
|
- `config/catalogs/*.yaml` 中的可复用对象目录
|
|
532
|
-
- `config
|
|
547
|
+
- `config/**/*.yaml` 中的 agent 装配
|
|
533
548
|
|
|
534
549
|
### Backend 选择建议
|
|
535
550
|
|
|
@@ -602,7 +617,7 @@ spec:
|
|
|
602
617
|
|
|
603
618
|
在此放置稳定的项目上下文;视为启动上下文,而非可变长期记忆。
|
|
604
619
|
|
|
605
|
-
### `config
|
|
620
|
+
### `config/**` 下的 Models Catalog
|
|
606
621
|
|
|
607
622
|
命名聊天模型预设:
|
|
608
623
|
|
|
@@ -618,7 +633,9 @@ spec:
|
|
|
618
633
|
|
|
619
634
|
加载为 `model/default`。
|
|
620
635
|
|
|
621
|
-
|
|
636
|
+
`kind: Models` catalog 可以放在 `config/` 下任意位置;`config/catalogs/models.yaml` 只是推荐布局。
|
|
637
|
+
|
|
638
|
+
### `config/**` 下的 Embedding Model Catalog
|
|
622
639
|
|
|
623
640
|
面向检索类工具的命名嵌入模型预设。
|
|
624
641
|
|
|
@@ -707,10 +724,12 @@ spec:
|
|
|
707
724
|
|
|
708
725
|
这里可以省略 `spec[].kind`;catalog 项会默认按 `McpServer` 处理。
|
|
709
726
|
|
|
710
|
-
### `config
|
|
727
|
+
### `config/**` 下的 Agent YAML
|
|
711
728
|
|
|
712
729
|
Agent 始终使用 `kind: Agent` 以及 `spec.backend`。
|
|
713
730
|
|
|
731
|
+
Agent YAML 可以放在 `config/` 下任意位置;`config/agents/*.yaml` 是推荐布局,不是 loader 的硬性要求。
|
|
732
|
+
|
|
714
733
|
两个区块:
|
|
715
734
|
|
|
716
735
|
- `spec.runtime`:harness 侧运行时放置,例如 `spec.runtime.runRoot`
|
|
@@ -744,10 +763,15 @@ spec:
|
|
|
744
763
|
rootDir: .
|
|
745
764
|
virtualMode: true
|
|
746
765
|
maxFileSizeMb: 10
|
|
766
|
+
sessionStorage:
|
|
767
|
+
enabled: true
|
|
768
|
+
rootDir: "{runRoot}/threads/{threadId}/filesystem"
|
|
747
769
|
middleware: []
|
|
748
770
|
systemPrompt: Answer simple requests directly.
|
|
749
771
|
```
|
|
750
772
|
|
|
773
|
+
当 LangChain 绑定启用 `config.filesystem.sessionStorage.enabled: true` 时,runtime 会为每个持久化 session/thread 维护独立的 filesystem 根目录,并按 session 复用 runnable cache,而不是把所有运行都压到同一个共享工作目录里。
|
|
774
|
+
|
|
751
775
|
orchestra 主机示例:
|
|
752
776
|
|
|
753
777
|
```yaml
|
|
@@ -808,6 +832,10 @@ spec:
|
|
|
808
832
|
- `deleteSession`
|
|
809
833
|
- `listApprovals`
|
|
810
834
|
- `getApproval`
|
|
835
|
+
- `listArtifacts`
|
|
836
|
+
- `getArtifact`
|
|
837
|
+
- `exportEvaluationBundle`
|
|
838
|
+
- `createAcpServer`
|
|
811
839
|
- `createToolMcpServer`
|
|
812
840
|
- `serveToolsOverStdio`
|
|
813
841
|
- `stop`
|
package/dist/acp.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ArtifactRecord, HarnessEvent, RequestRecord, RunOptions, SessionRecord } from "./contracts/types.js";
|
|
2
|
+
import type { AgentHarnessRuntime } from "./runtime/harness.js";
|
|
3
|
+
import { getApproval } from "./api.js";
|
|
4
|
+
type JsonRpcId = string | number | null;
|
|
5
|
+
export type AcpJsonRpcRequest = {
|
|
6
|
+
jsonrpc?: "2.0";
|
|
7
|
+
id?: JsonRpcId;
|
|
8
|
+
method: string;
|
|
9
|
+
params?: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type AcpJsonRpcError = {
|
|
12
|
+
jsonrpc: "2.0";
|
|
13
|
+
id: JsonRpcId;
|
|
14
|
+
error: {
|
|
15
|
+
code: number;
|
|
16
|
+
message: string;
|
|
17
|
+
data?: unknown;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type AcpJsonRpcSuccess = {
|
|
21
|
+
jsonrpc: "2.0";
|
|
22
|
+
id: JsonRpcId;
|
|
23
|
+
result: unknown;
|
|
24
|
+
};
|
|
25
|
+
export type AcpJsonRpcResponse = AcpJsonRpcError | AcpJsonRpcSuccess;
|
|
26
|
+
export type AcpSessionRecord = SessionRecord;
|
|
27
|
+
export type AcpRequestRecord = RequestRecord;
|
|
28
|
+
export type AcpApproval = Awaited<ReturnType<typeof getApproval>> extends infer T ? Exclude<T, null> : never;
|
|
29
|
+
export type AcpArtifact = ArtifactRecord & {
|
|
30
|
+
content?: unknown;
|
|
31
|
+
};
|
|
32
|
+
export type AcpRunRequestParams = Omit<Extract<RunOptions, {
|
|
33
|
+
input: unknown;
|
|
34
|
+
}>, "threadId"> & {
|
|
35
|
+
sessionId?: string;
|
|
36
|
+
};
|
|
37
|
+
export type AcpServerCapabilities = {
|
|
38
|
+
sessions: {
|
|
39
|
+
list: true;
|
|
40
|
+
get: true;
|
|
41
|
+
};
|
|
42
|
+
requests: {
|
|
43
|
+
submit: true;
|
|
44
|
+
list: true;
|
|
45
|
+
get: true;
|
|
46
|
+
};
|
|
47
|
+
approvals: {
|
|
48
|
+
list: true;
|
|
49
|
+
get: true;
|
|
50
|
+
resolve: true;
|
|
51
|
+
};
|
|
52
|
+
artifacts: {
|
|
53
|
+
list: true;
|
|
54
|
+
read: true;
|
|
55
|
+
};
|
|
56
|
+
events: {
|
|
57
|
+
subscribe: true;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export type AcpEventNotification = {
|
|
61
|
+
jsonrpc: "2.0";
|
|
62
|
+
method: "events.runtime";
|
|
63
|
+
params: {
|
|
64
|
+
event: {
|
|
65
|
+
eventId: string;
|
|
66
|
+
eventType: string;
|
|
67
|
+
timestamp: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
requestId: string;
|
|
70
|
+
sequence: number;
|
|
71
|
+
source: HarnessEvent["source"];
|
|
72
|
+
payload: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
export declare class AgentHarnessAcpServer {
|
|
77
|
+
private readonly runtime;
|
|
78
|
+
constructor(runtime: AgentHarnessRuntime);
|
|
79
|
+
capabilities(): AcpServerCapabilities;
|
|
80
|
+
subscribe(listener: (notification: AcpEventNotification) => void): () => void;
|
|
81
|
+
handle(request: AcpJsonRpcRequest): Promise<AcpJsonRpcResponse | undefined>;
|
|
82
|
+
private methodExists;
|
|
83
|
+
private dispatch;
|
|
84
|
+
}
|
|
85
|
+
export declare function createAcpServer(runtime: AgentHarnessRuntime): AgentHarnessAcpServer;
|
|
86
|
+
export {};
|
package/dist/acp.js
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { getApproval, getArtifact, getRequest, getSession, listApprovals, listArtifacts, listRequests, listSessions, resolveApproval, run, } from "./api.js";
|
|
2
|
+
const CAPABILITIES = {
|
|
3
|
+
sessions: { list: true, get: true },
|
|
4
|
+
requests: { submit: true, list: true, get: true },
|
|
5
|
+
approvals: { list: true, get: true, resolve: true },
|
|
6
|
+
artifacts: { list: true, read: true },
|
|
7
|
+
events: { subscribe: true },
|
|
8
|
+
};
|
|
9
|
+
function asObject(value, method) {
|
|
10
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
11
|
+
throw new Error(`${method} requires an object params payload.`);
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function readOptionalString(value) {
|
|
16
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
17
|
+
}
|
|
18
|
+
function readRequiredString(value, field, method) {
|
|
19
|
+
const normalized = readOptionalString(value);
|
|
20
|
+
if (!normalized) {
|
|
21
|
+
throw new Error(`${method} requires ${field}.`);
|
|
22
|
+
}
|
|
23
|
+
return normalized;
|
|
24
|
+
}
|
|
25
|
+
function toNotification(event) {
|
|
26
|
+
return {
|
|
27
|
+
jsonrpc: "2.0",
|
|
28
|
+
method: "events.runtime",
|
|
29
|
+
params: {
|
|
30
|
+
event: {
|
|
31
|
+
eventId: event.eventId,
|
|
32
|
+
eventType: event.eventType,
|
|
33
|
+
timestamp: event.timestamp,
|
|
34
|
+
sessionId: event.threadId,
|
|
35
|
+
requestId: event.runId,
|
|
36
|
+
sequence: event.sequence,
|
|
37
|
+
source: event.source,
|
|
38
|
+
payload: event.payload,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function readArtifactContent(runtime, params) {
|
|
44
|
+
const method = "artifacts.read";
|
|
45
|
+
const sessionId = readRequiredString(params.sessionId, "sessionId", method);
|
|
46
|
+
const requestId = readRequiredString(params.requestId, "requestId", method);
|
|
47
|
+
const artifactPath = readRequiredString(params.artifactPath, "artifactPath", method);
|
|
48
|
+
const listing = await listArtifacts(runtime, { sessionId, requestId });
|
|
49
|
+
const artifact = listing.items.find((item) => item.path === artifactPath);
|
|
50
|
+
if (!artifact) {
|
|
51
|
+
throw new Error(`Artifact not found for ${requestId}: ${artifactPath}`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
...artifact,
|
|
55
|
+
content: await getArtifact(runtime, { sessionId, requestId, artifactPath }),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export class AgentHarnessAcpServer {
|
|
59
|
+
runtime;
|
|
60
|
+
constructor(runtime) {
|
|
61
|
+
this.runtime = runtime;
|
|
62
|
+
}
|
|
63
|
+
capabilities() {
|
|
64
|
+
return CAPABILITIES;
|
|
65
|
+
}
|
|
66
|
+
subscribe(listener) {
|
|
67
|
+
return this.runtime.subscribe((event) => {
|
|
68
|
+
listener(toNotification(event));
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
async handle(request) {
|
|
72
|
+
const id = request.id ?? null;
|
|
73
|
+
if (!request || typeof request !== "object" || typeof request.method !== "string" || request.method.trim().length === 0) {
|
|
74
|
+
return {
|
|
75
|
+
jsonrpc: "2.0",
|
|
76
|
+
id,
|
|
77
|
+
error: {
|
|
78
|
+
code: -32600,
|
|
79
|
+
message: "Invalid JSON-RPC request.",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (request.jsonrpc !== undefined && request.jsonrpc !== "2.0") {
|
|
84
|
+
return {
|
|
85
|
+
jsonrpc: "2.0",
|
|
86
|
+
id,
|
|
87
|
+
error: {
|
|
88
|
+
code: -32600,
|
|
89
|
+
message: "Only JSON-RPC 2.0 requests are supported.",
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const result = await this.dispatch(request.method, request.params);
|
|
95
|
+
if (request.id === undefined) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
jsonrpc: "2.0",
|
|
100
|
+
id,
|
|
101
|
+
result,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (request.id === undefined) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
jsonrpc: "2.0",
|
|
110
|
+
id,
|
|
111
|
+
error: {
|
|
112
|
+
code: this.methodExists(request.method) ? -32602 : -32601,
|
|
113
|
+
message: error instanceof Error ? error.message : "ACP request failed.",
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
methodExists(method) {
|
|
119
|
+
return new Set([
|
|
120
|
+
"capabilities.get",
|
|
121
|
+
"sessions.list",
|
|
122
|
+
"sessions.get",
|
|
123
|
+
"requests.submit",
|
|
124
|
+
"requests.list",
|
|
125
|
+
"requests.get",
|
|
126
|
+
"approvals.list",
|
|
127
|
+
"approvals.get",
|
|
128
|
+
"approvals.resolve",
|
|
129
|
+
"artifacts.list",
|
|
130
|
+
"artifacts.read",
|
|
131
|
+
]).has(method);
|
|
132
|
+
}
|
|
133
|
+
async dispatch(method, params) {
|
|
134
|
+
switch (method) {
|
|
135
|
+
case "capabilities.get":
|
|
136
|
+
return this.capabilities();
|
|
137
|
+
case "sessions.list": {
|
|
138
|
+
const payload = params === undefined ? {} : asObject(params, method);
|
|
139
|
+
return listSessions(this.runtime, {
|
|
140
|
+
agentId: readOptionalString(payload.agentId),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
case "sessions.get": {
|
|
144
|
+
const payload = asObject(params, method);
|
|
145
|
+
return getSession(this.runtime, readRequiredString(payload.sessionId, "sessionId", method));
|
|
146
|
+
}
|
|
147
|
+
case "requests.submit": {
|
|
148
|
+
const payload = asObject(params, method);
|
|
149
|
+
return run(this.runtime, {
|
|
150
|
+
agentId: readOptionalString(payload.agentId),
|
|
151
|
+
input: payload.input,
|
|
152
|
+
invocation: payload.invocation,
|
|
153
|
+
listeners: payload.listeners,
|
|
154
|
+
priority: typeof payload.priority === "number" ? payload.priority : undefined,
|
|
155
|
+
sessionId: readOptionalString(payload.sessionId),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
case "requests.list": {
|
|
159
|
+
const payload = params === undefined ? {} : asObject(params, method);
|
|
160
|
+
return listRequests(this.runtime, {
|
|
161
|
+
agentId: readOptionalString(payload.agentId),
|
|
162
|
+
sessionId: readOptionalString(payload.sessionId),
|
|
163
|
+
state: payload.state,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
case "requests.get": {
|
|
167
|
+
const payload = asObject(params, method);
|
|
168
|
+
return getRequest(this.runtime, readRequiredString(payload.requestId, "requestId", method));
|
|
169
|
+
}
|
|
170
|
+
case "approvals.list": {
|
|
171
|
+
const payload = params === undefined ? {} : asObject(params, method);
|
|
172
|
+
return listApprovals(this.runtime, {
|
|
173
|
+
status: payload.status,
|
|
174
|
+
sessionId: readOptionalString(payload.sessionId),
|
|
175
|
+
requestId: readOptionalString(payload.requestId),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
case "approvals.get": {
|
|
179
|
+
const payload = asObject(params, method);
|
|
180
|
+
return getApproval(this.runtime, readRequiredString(payload.approvalId, "approvalId", method));
|
|
181
|
+
}
|
|
182
|
+
case "approvals.resolve": {
|
|
183
|
+
const payload = asObject(params, method);
|
|
184
|
+
return resolveApproval(this.runtime, {
|
|
185
|
+
approvalId: readRequiredString(payload.approvalId, "approvalId", method),
|
|
186
|
+
decision: payload.decision,
|
|
187
|
+
editedInput: payload.editedInput,
|
|
188
|
+
requestId: readOptionalString(payload.requestId),
|
|
189
|
+
sessionId: readOptionalString(payload.sessionId),
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
case "artifacts.list": {
|
|
193
|
+
const payload = asObject(params, method);
|
|
194
|
+
return listArtifacts(this.runtime, {
|
|
195
|
+
sessionId: readRequiredString(payload.sessionId, "sessionId", method),
|
|
196
|
+
requestId: readRequiredString(payload.requestId, "requestId", method),
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
case "artifacts.read":
|
|
200
|
+
return readArtifactContent(this.runtime, asObject(params, method));
|
|
201
|
+
default:
|
|
202
|
+
throw new Error(`Unknown ACP method: ${method}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function createAcpServer(runtime) {
|
|
207
|
+
return new AgentHarnessAcpServer(runtime);
|
|
208
|
+
}
|
package/dist/api.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { CancelOptions, InvocationEnvelope, MemorizeInput, MemorizeResult, MessageContent, RecallInput, RecallResult, RequestRecord, RequestSummary, ResumeOptions, RunDecisionOptions, RunResult, RunStartOptions, RuntimeHealthSnapshot, RuntimeAdapterOptions, SessionRecord, SessionSummary, WorkspaceLoadOptions } from "./contracts/types.js";
|
|
1
|
+
import type { ArtifactListing, CancelOptions, InvocationEnvelope, ListMemoriesInput, ListMemoriesResult, MemoryRecord, MemorizeInput, MemorizeResult, MessageContent, RecallInput, RecallResult, RemoveMemoryInput, RequestRecord, RequestSummary, ResumeOptions, RunDecisionOptions, RunResult, RunStartOptions, RuntimeHealthSnapshot, RuntimeAdapterOptions, RuntimeEvaluationExport, RuntimeEvaluationExportInput, SessionRecord, SessionSummary, UpdateMemoryInput, 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
|
+
export { AgentHarnessAcpServer, createAcpServer } from "./acp.js";
|
|
7
|
+
export type { AcpApproval, AcpArtifact, AcpEventNotification, AcpJsonRpcError, AcpJsonRpcRequest, AcpJsonRpcResponse, AcpJsonRpcSuccess, AcpRequestRecord, AcpRunRequestParams, AcpServerCapabilities, AcpSessionRecord, } from "./acp.js";
|
|
6
8
|
export { AgentHarnessRuntime } from "./runtime/harness.js";
|
|
7
9
|
export { createUpstreamTimelineReducer } from "./upstream-events.js";
|
|
8
|
-
export type { MemoryDecision, MemoryKind, MemoryRecord, MemoryScope, MemorizeInput, MemorizeResult, RecallInput, RecallResult, } from "./contracts/types.js";
|
|
10
|
+
export type { ListMemoriesInput, ListMemoriesResult, MemoryDecision, MemoryKind, MemoryRecord, MemoryScope, MemorizeInput, MemorizeResult, RecallInput, RecallResult, RemoveMemoryInput, RuntimeEvaluationExport, RuntimeEvaluationExportInput, UpdateMemoryInput, } from "./contracts/types.js";
|
|
9
11
|
type PublicApprovalRecord = {
|
|
10
12
|
approvalId: string;
|
|
11
13
|
pendingActionId: string;
|
|
@@ -57,6 +59,9 @@ export declare function normalizeUserChatInput(input: UserChatInput, options?: N
|
|
|
57
59
|
export declare function run(runtime: AgentHarnessRuntime, options: PublicRunOptions): Promise<PublicRunResult>;
|
|
58
60
|
export declare function memorize(runtime: AgentHarnessRuntime, input: MemorizeInput): Promise<MemorizeResult>;
|
|
59
61
|
export declare function recall(runtime: AgentHarnessRuntime, input: RecallInput): Promise<RecallResult>;
|
|
62
|
+
export declare function listMemories(runtime: AgentHarnessRuntime, input?: ListMemoriesInput): Promise<ListMemoriesResult>;
|
|
63
|
+
export declare function updateMemory(runtime: AgentHarnessRuntime, input: UpdateMemoryInput): Promise<MemoryRecord>;
|
|
64
|
+
export declare function removeMemory(runtime: AgentHarnessRuntime, input: RemoveMemoryInput): Promise<MemoryRecord>;
|
|
60
65
|
export declare function subscribe(runtime: AgentHarnessRuntime, listener: Parameters<AgentHarnessRuntime["subscribe"]>[0]): () => void;
|
|
61
66
|
export declare function listSessions(runtime: AgentHarnessRuntime, filter?: Parameters<AgentHarnessRuntime["listThreads"]>[0]): Promise<SessionSummary[]>;
|
|
62
67
|
export declare function listRequests(runtime: AgentHarnessRuntime, filter?: {
|
|
@@ -69,7 +74,17 @@ export declare function getRequest(runtime: AgentHarnessRuntime, requestId: stri
|
|
|
69
74
|
export declare function deleteSession(runtime: AgentHarnessRuntime, sessionId: string): Promise<boolean>;
|
|
70
75
|
export declare function listApprovals(runtime: AgentHarnessRuntime, filter?: PublicApprovalFilter): Promise<PublicApprovalRecord[]>;
|
|
71
76
|
export declare function getApproval(runtime: AgentHarnessRuntime, approvalId: string): Promise<PublicApprovalRecord | null>;
|
|
77
|
+
export declare function listArtifacts(runtime: AgentHarnessRuntime, input: {
|
|
78
|
+
sessionId: string;
|
|
79
|
+
requestId: string;
|
|
80
|
+
}): Promise<ArtifactListing>;
|
|
81
|
+
export declare function getArtifact(runtime: AgentHarnessRuntime, input: {
|
|
82
|
+
sessionId: string;
|
|
83
|
+
requestId: string;
|
|
84
|
+
artifactPath: string;
|
|
85
|
+
}): Promise<unknown>;
|
|
72
86
|
export declare function getHealth(runtime: AgentHarnessRuntime): Promise<RuntimeHealthSnapshot>;
|
|
87
|
+
export declare function exportEvaluationBundle(runtime: AgentHarnessRuntime, input: RuntimeEvaluationExportInput): Promise<RuntimeEvaluationExport>;
|
|
73
88
|
export declare function listAgentSkills(runtime: AgentHarnessRuntime, agentId: string, options?: RequirementAssessmentOptions): InventorySkillRecord[];
|
|
74
89
|
export declare function getAgent(runtime: AgentHarnessRuntime, agentId: string, options?: RequirementAssessmentOptions): InventoryAgentRecord | null;
|
|
75
90
|
export declare function describeInventory(runtime: AgentHarnessRuntime, options?: RequirementAssessmentOptions): {
|
package/dist/api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AgentHarnessRuntime } from "./runtime/harness.js";
|
|
2
2
|
import { normalizeMessageContent } from "./utils/message-content.js";
|
|
3
3
|
import { loadWorkspace } from "./workspace/compile.js";
|
|
4
|
+
export { AgentHarnessAcpServer, createAcpServer } from "./acp.js";
|
|
4
5
|
export { AgentHarnessRuntime } from "./runtime/harness.js";
|
|
5
6
|
export { createUpstreamTimelineReducer } from "./upstream-events.js";
|
|
6
7
|
function toSessionSummary(summary) {
|
|
@@ -134,6 +135,15 @@ export async function memorize(runtime, input) {
|
|
|
134
135
|
export async function recall(runtime, input) {
|
|
135
136
|
return runtime.recall(input);
|
|
136
137
|
}
|
|
138
|
+
export async function listMemories(runtime, input = {}) {
|
|
139
|
+
return runtime.listMemories(input);
|
|
140
|
+
}
|
|
141
|
+
export async function updateMemory(runtime, input) {
|
|
142
|
+
return runtime.updateMemory(input);
|
|
143
|
+
}
|
|
144
|
+
export async function removeMemory(runtime, input) {
|
|
145
|
+
return runtime.removeMemory(input);
|
|
146
|
+
}
|
|
137
147
|
export function subscribe(runtime, listener) {
|
|
138
148
|
return runtime.subscribe(listener);
|
|
139
149
|
}
|
|
@@ -169,9 +179,18 @@ export async function getApproval(runtime, approvalId) {
|
|
|
169
179
|
const record = await runtime.getApproval(approvalId);
|
|
170
180
|
return record ? toApprovalRecord(record) : null;
|
|
171
181
|
}
|
|
182
|
+
export async function listArtifacts(runtime, input) {
|
|
183
|
+
return runtime.listArtifacts(input.sessionId, input.requestId);
|
|
184
|
+
}
|
|
185
|
+
export async function getArtifact(runtime, input) {
|
|
186
|
+
return runtime.readArtifact(input.sessionId, input.requestId, input.artifactPath);
|
|
187
|
+
}
|
|
172
188
|
export async function getHealth(runtime) {
|
|
173
189
|
return runtime.getHealth();
|
|
174
190
|
}
|
|
191
|
+
export async function exportEvaluationBundle(runtime, input) {
|
|
192
|
+
return runtime.exportEvaluationBundle(input);
|
|
193
|
+
}
|
|
175
194
|
export function listAgentSkills(runtime, agentId, options) {
|
|
176
195
|
return runtime.listAgentSkills(agentId, options);
|
|
177
196
|
}
|