@harapter/core 0.1.1 → 0.1.2
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.ja.md +137 -0
- package/README.md +56 -11
- package/README.zh-CN.md +135 -0
- package/package.json +5 -3
package/README.ja.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/core</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>Harapter の Provider 非依存ライフサイクルとレジストリ。</strong></p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="./README.md">English</a> · <a href="./README.zh-CN.md">简体中文</a> · <a href="./README.ja.md">日本語</a> · <a href="../../README.ja.md">Harapter</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/v/%40harapter%2Fcore/next?style=flat-square&label=npm%20next" alt="npm next バージョン"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/dm/%40harapter%2Fcore?style=flat-square" alt="npm ダウンロード数"></a>
|
|
14
|
+
<a href="https://github.com/yunfeizhu/harapter/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/yunfeizhu/harapter/ci.yml?branch=main&style=flat-square&label=ci" alt="CI ステータス"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-%3E%3D24-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js 24 以上">
|
|
16
|
+
<a href="../../LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0B7285?style=flat-square" alt="Apache-2.0 ライセンス"></a>
|
|
17
|
+
<img src="https://img.shields.io/badge/status-pre--alpha-EA580C?style=flat-square" alt="Pre-alpha ステータス">
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<!-- markdownlint-enable MD033 -->
|
|
21
|
+
|
|
22
|
+
`@harapter/core` は複数の Agent Harness を同じ TypeScript
|
|
23
|
+
API で扱うための中心パッケージです。Client、Session、Run、イベント、終端結果、Capability、Error、Interaction、Provider 拡張を定義しますが、Provider
|
|
24
|
+
SDK を import せず、名前から機能を推測しません。
|
|
25
|
+
|
|
26
|
+
## このパッケージが適するケース
|
|
27
|
+
|
|
28
|
+
- Codex、OpenCode、その他の Adapter を切り替えてもアプリの流れを保ちたい;
|
|
29
|
+
- Provider 名ではなく、接続先で観測した Capability によってルーティングしたい;
|
|
30
|
+
- Provider Adapter を実装し、標準契約・所有権検証・Native Escape Hatch が必要。
|
|
31
|
+
|
|
32
|
+
## インストール
|
|
33
|
+
|
|
34
|
+
プレリリースは `next` タグで配布されます。
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @harapter/core@next
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
次の Provider-free example では test package も追加します。
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add -D @harapter/conformance@next
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Node.js 24 以上が必要です。Core は Harness Runtime の導入や認証を行いません。
|
|
47
|
+
|
|
48
|
+
## 30 秒クイックスタート
|
|
49
|
+
|
|
50
|
+
次の例は `@harapter/conformance` の Fake
|
|
51
|
+
Provider を使うため、認証情報も実 Runtime も不要です。
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { HarnessRegistry } from '@harapter/core';
|
|
55
|
+
import {
|
|
56
|
+
createFakeProfile,
|
|
57
|
+
createFakeProviderFactory,
|
|
58
|
+
} from '@harapter/conformance';
|
|
59
|
+
|
|
60
|
+
const registry = new HarnessRegistry();
|
|
61
|
+
registry.register(createFakeProviderFactory());
|
|
62
|
+
|
|
63
|
+
const client = await registry.connect(createFakeProfile());
|
|
64
|
+
const session = await client.createSession();
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const run = await session.start({
|
|
68
|
+
parts: [{ type: 'text', text: 'synthetic input' }],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for await (const event of run.events()) {
|
|
72
|
+
console.log(event.type);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = await run.result();
|
|
76
|
+
console.log(result.status);
|
|
77
|
+
} finally {
|
|
78
|
+
try {
|
|
79
|
+
await session.close();
|
|
80
|
+
} finally {
|
|
81
|
+
await client.close();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
実際のアプリでは Fake Provider を [実装済み Adapter](../../providers/README.md)
|
|
87
|
+
に置き換え、Runtime の導入・設定・認証はホストが行います。
|
|
88
|
+
|
|
89
|
+
## よくある使い方
|
|
90
|
+
|
|
91
|
+
### 接続前に必要な Capability を宣言する
|
|
92
|
+
|
|
93
|
+
`requiredCapabilities` は既定で `native`
|
|
94
|
+
だけを受け入れます。弱いモードを許可する場合はホストが明示します。
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const client = await registry.connect({
|
|
98
|
+
...profile,
|
|
99
|
+
requiredCapabilities: [
|
|
100
|
+
{ name: 'input.text' },
|
|
101
|
+
{ name: 'run.stream', acceptedModes: ['native', 'adapter_controlled'] },
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 終端結果を区別する
|
|
107
|
+
|
|
108
|
+
`run.result()` が権威ある結果です。`completed`、`cancelled`、`failed`、
|
|
109
|
+
`connection_aborted` は別の状態であり、プロセス終了は native
|
|
110
|
+
cancellation の証拠ではありません。
|
|
111
|
+
|
|
112
|
+
### Session を保存・再開する
|
|
113
|
+
|
|
114
|
+
Capability が許す場合だけ `session.ref()`
|
|
115
|
+
を保存します。参照は作成元と同じ Provider と Profile に戻す必要があり、Harapter は checkpoint を Provider 間で移動しません。
|
|
116
|
+
|
|
117
|
+
## 主なエクスポート
|
|
118
|
+
|
|
119
|
+
- `HarnessRegistry`:Adapter Factory の登録と Profile 接続;
|
|
120
|
+
- `HarnessClient`、`HarnessSession`、`HarnessRun`:可搬ライフサイクル;
|
|
121
|
+
- `HarnessEvent`、`RunResult`:順序付きイベントと一つの終端結果;
|
|
122
|
+
- `CapabilityManifest`:native、emulated、Adapter 制御、unsupported、unknown;
|
|
123
|
+
- `HarnessError`:安定した分類と明示的な `retryable`;
|
|
124
|
+
- `ExtensionRegistry`、`native()`:Provider に束縛された拡張境界;
|
|
125
|
+
- 所有権と互換性を確認する Session 検証関数。
|
|
126
|
+
|
|
127
|
+
## セキュリティと制限
|
|
128
|
+
|
|
129
|
+
- Core は `providerState`
|
|
130
|
+
を解釈せず、認証情報、Runtime、プロセス、永続化を管理しません;
|
|
131
|
+
- raw
|
|
132
|
+
Event、`providerState`、`providerResult`、Prompt、認証情報を既定で記録しないでください;
|
|
133
|
+
- resume、cancel、interaction、artifact、usage は現在の Capability に依存します;
|
|
134
|
+
- API は pre-alpha で、1.0 以前に破壊的変更が入る可能性があります。
|
|
135
|
+
|
|
136
|
+
正確な契約は[英語の詳細ドキュメント](./README.md)と
|
|
137
|
+
[API 設計](../../docs/design/api-design.ja.md)を参照してください。
|
package/README.md
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/core</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>The provider-agnostic lifecycle and registry at the center of Harapter.</strong></p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="./README.md">English</a> · <a href="./README.zh-CN.md">简体中文</a> · <a href="./README.ja.md">日本語</a> · <a href="../../README.md">Harapter</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/v/%40harapter%2Fcore/next?style=flat-square&label=npm%20next" alt="npm next version"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/dm/%40harapter%2Fcore?style=flat-square" alt="npm downloads"></a>
|
|
14
|
+
<a href="https://github.com/yunfeizhu/harapter/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/yunfeizhu/harapter/ci.yml?branch=main&style=flat-square&label=ci" alt="CI status"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-%3E%3D24-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js 24 or newer">
|
|
16
|
+
<a href="../../LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0B7285?style=flat-square" alt="Apache-2.0 license"></a>
|
|
17
|
+
<img src="https://img.shields.io/badge/status-pre--alpha-EA580C?style=flat-square" alt="Pre-alpha status">
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<!-- markdownlint-enable MD033 -->
|
|
2
21
|
|
|
3
22
|
`@harapter/core` is the provider-agnostic TypeScript API for Harapter. It owns
|
|
4
23
|
portable contracts and the runtime checks that can be applied without knowing a
|
|
5
24
|
Provider identity.
|
|
6
25
|
|
|
26
|
+
## Use this package when
|
|
27
|
+
|
|
28
|
+
- your application needs one Client → Session → Run lifecycle across several
|
|
29
|
+
agent harnesses;
|
|
30
|
+
- you need capability-based routing without branching on Provider names; or
|
|
31
|
+
- you are implementing an Adapter and need the canonical contracts, errors,
|
|
32
|
+
ownership checks, extensions, and native escape hatch.
|
|
33
|
+
|
|
7
34
|
## Installation
|
|
8
35
|
|
|
9
36
|
```bash
|
|
10
37
|
pnpm add @harapter/core@next
|
|
11
38
|
```
|
|
12
39
|
|
|
40
|
+
The Provider-free example below also uses the deterministic test package:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add -D @harapter/conformance@next
|
|
44
|
+
```
|
|
45
|
+
|
|
13
46
|
## Public entrypoints
|
|
14
47
|
|
|
15
48
|
- `HarnessRegistry` dynamically registers Adapter factories and connects host
|
|
@@ -65,7 +98,7 @@ Profiles carry Secret references, not credential values. Credential resolution,
|
|
|
65
98
|
runtime installation, authentication, process policy, and product persistence
|
|
66
99
|
remain host or Provider responsibilities.
|
|
67
100
|
|
|
68
|
-
##
|
|
101
|
+
## Quick start
|
|
69
102
|
|
|
70
103
|
The deterministic Fake Provider gives the Core flow executable evidence without
|
|
71
104
|
introducing a Provider dependency:
|
|
@@ -82,19 +115,31 @@ registry.register(createFakeProviderFactory());
|
|
|
82
115
|
|
|
83
116
|
const client = await registry.connect(createFakeProfile());
|
|
84
117
|
const session = await client.createSession();
|
|
85
|
-
const run = await session.start({
|
|
86
|
-
parts: [{ type: 'text', text: 'synthetic input' }],
|
|
87
|
-
});
|
|
88
118
|
|
|
89
|
-
|
|
90
|
-
|
|
119
|
+
try {
|
|
120
|
+
const run = await session.start({
|
|
121
|
+
parts: [{ type: 'text', text: 'synthetic input' }],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
for await (const event of run.events()) {
|
|
125
|
+
console.log(event.type);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const result = await run.result();
|
|
129
|
+
console.log(result.status);
|
|
130
|
+
} finally {
|
|
131
|
+
try {
|
|
132
|
+
await session.close();
|
|
133
|
+
} finally {
|
|
134
|
+
await client.close();
|
|
135
|
+
}
|
|
91
136
|
}
|
|
92
|
-
|
|
93
|
-
const result = await run.result();
|
|
94
|
-
await session.close();
|
|
95
|
-
await client.close();
|
|
96
137
|
```
|
|
97
138
|
|
|
139
|
+
Replace the Fake Provider with an
|
|
140
|
+
[implemented Adapter](../../providers/README.md) in an application. The
|
|
141
|
+
Registry, Client, Session, Run, Event, and Result flow stays the same.
|
|
142
|
+
|
|
98
143
|
## Limitations
|
|
99
144
|
|
|
100
145
|
- No Provider Adapter, transport, canonical wire schema, persistence layer, or
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/core</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>Harapter 的 Provider 无关生命周期与注册中心。</strong></p>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="./README.md">English</a> · <a href="./README.zh-CN.md">简体中文</a> · <a href="./README.ja.md">日本語</a> · <a href="../../README.zh-CN.md">Harapter</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/v/%40harapter%2Fcore/next?style=flat-square&label=npm%20next" alt="npm next 版本"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/core"><img src="https://img.shields.io/npm/dm/%40harapter%2Fcore?style=flat-square" alt="npm 下载量"></a>
|
|
14
|
+
<a href="https://github.com/yunfeizhu/harapter/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/yunfeizhu/harapter/ci.yml?branch=main&style=flat-square&label=ci" alt="CI 状态"></a>
|
|
15
|
+
<img src="https://img.shields.io/badge/node-%3E%3D24-339933?style=flat-square&logo=nodedotjs&logoColor=white" alt="Node.js 24 或更高版本">
|
|
16
|
+
<a href="../../LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0B7285?style=flat-square" alt="Apache-2.0 许可证"></a>
|
|
17
|
+
<img src="https://img.shields.io/badge/status-pre--alpha-EA580C?style=flat-square" alt="Pre-alpha 状态">
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
<!-- markdownlint-enable MD033 -->
|
|
21
|
+
|
|
22
|
+
`@harapter/core` 为多个 Agent Harness 提供同一套 TypeScript
|
|
23
|
+
API。它定义 Client、Session、Run、事件流、终态、能力、错误、交互和 Provider 扩展,但不导入任何 Provider
|
|
24
|
+
SDK,也不会根据 Provider 名称推断行为。
|
|
25
|
+
|
|
26
|
+
## 适合什么场景
|
|
27
|
+
|
|
28
|
+
- 应用需要在 Codex、OpenCode 或其他 Adapter 之间切换,而业务流程保持不变;
|
|
29
|
+
- 需要按运行时实际能力选路,而不是在代码里判断 Provider 名称;
|
|
30
|
+
- 正在实现 Provider Adapter,需要标准契约、所有权校验和 Native Escape Hatch。
|
|
31
|
+
|
|
32
|
+
## 安装
|
|
33
|
+
|
|
34
|
+
预发布版本使用 `next` 标签:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pnpm add @harapter/core@next
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
下面不依赖 Provider 的示例还需要测试包:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm add -D @harapter/conformance@next
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Node.js 需要 24 或更高版本。Core 不会安装或登录任何 Harness Runtime。
|
|
47
|
+
|
|
48
|
+
## 30 秒上手
|
|
49
|
+
|
|
50
|
+
下面使用 `@harapter/conformance` 的 Fake
|
|
51
|
+
Provider,因此不需要凭据或真实 Runtime:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { HarnessRegistry } from '@harapter/core';
|
|
55
|
+
import {
|
|
56
|
+
createFakeProfile,
|
|
57
|
+
createFakeProviderFactory,
|
|
58
|
+
} from '@harapter/conformance';
|
|
59
|
+
|
|
60
|
+
const registry = new HarnessRegistry();
|
|
61
|
+
registry.register(createFakeProviderFactory());
|
|
62
|
+
|
|
63
|
+
const client = await registry.connect(createFakeProfile());
|
|
64
|
+
const session = await client.createSession();
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const run = await session.start({
|
|
68
|
+
parts: [{ type: 'text', text: 'synthetic input' }],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for await (const event of run.events()) {
|
|
72
|
+
console.log(event.type);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = await run.result();
|
|
76
|
+
console.log(result.status);
|
|
77
|
+
} finally {
|
|
78
|
+
try {
|
|
79
|
+
await session.close();
|
|
80
|
+
} finally {
|
|
81
|
+
await client.close();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
实际项目需要把 Fake Provider 换成一个
|
|
87
|
+
[已实现 Adapter](../../providers/README.md),并由宿主安装、配置和认证对应 Runtime。
|
|
88
|
+
|
|
89
|
+
## 常见用法
|
|
90
|
+
|
|
91
|
+
### 在连接前声明必需能力
|
|
92
|
+
|
|
93
|
+
Profile 的 `requiredCapabilities` 默认只接受
|
|
94
|
+
`native`。如果宿主接受较弱模式,必须显式列出:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const client = await registry.connect({
|
|
98
|
+
...profile,
|
|
99
|
+
requiredCapabilities: [
|
|
100
|
+
{ name: 'input.text' },
|
|
101
|
+
{ name: 'run.stream', acceptedModes: ['native', 'adapter_controlled'] },
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 正确区分终态
|
|
107
|
+
|
|
108
|
+
`run.result()` 是权威结果。`completed`、`cancelled`、`failed` 和
|
|
109
|
+
`connection_aborted` 不能互相替代;进程退出或连接中断不等于原生取消。
|
|
110
|
+
|
|
111
|
+
### 保存并恢复 Session
|
|
112
|
+
|
|
113
|
+
仅在能力清单允许时持久化
|
|
114
|
+
`session.ref()`。引用必须继续交给创建它的同一 Provider 和 Profile;Harapter 不提供跨 Provider
|
|
115
|
+
checkpoint 迁移。
|
|
116
|
+
|
|
117
|
+
## 主要导出
|
|
118
|
+
|
|
119
|
+
- `HarnessRegistry`:注册 Adapter Factory 并连接 Profile;
|
|
120
|
+
- `HarnessClient`、`HarnessSession`、`HarnessRun`:可移植生命周期;
|
|
121
|
+
- `HarnessEvent`、`RunResult`:有序事件和唯一终态;
|
|
122
|
+
- `CapabilityManifest`:区分原生、模拟、Adapter 控制、不支持和未知;
|
|
123
|
+
- `HarnessError`:稳定错误类别与明确的 `retryable`;
|
|
124
|
+
- `ExtensionRegistry`、`native()`:Provider 绑定的扩展边界;
|
|
125
|
+
- `assertSessionOwnership()`、`assertSessionCompatibility()`:恢复前校验所有权和兼容性。
|
|
126
|
+
|
|
127
|
+
## 安全与限制
|
|
128
|
+
|
|
129
|
+
- Core 不解析 `providerState`,也不负责凭据、Runtime 安装、进程策略或持久化;
|
|
130
|
+
- 不应默认记录 Provider 原始事件、`providerState`、`providerResult`、提示词或凭据;
|
|
131
|
+
- 可选的 resume、cancel、interaction、artifact 和 usage 行为取决于当前能力清单;
|
|
132
|
+
- API 仍处于 pre-alpha,1.0 前可能发生破坏性调整。
|
|
133
|
+
|
|
134
|
+
完整字段、生命周期与错误契约见[英文详细文档](./README.md)和
|
|
135
|
+
[API 设计](../../docs/design/api-design.zh-CN.md)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harapter/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Provider-agnostic portable contracts and registry for Harapter.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/yunfeizhu/harapter/issues"
|
|
19
19
|
},
|
|
20
|
-
"homepage": "https://github.com/yunfeizhu/harapter#readme",
|
|
20
|
+
"homepage": "https://github.com/yunfeizhu/harapter/tree/main/packages/core#readme",
|
|
21
21
|
"type": "module",
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"files": [
|
|
24
|
-
"dist"
|
|
24
|
+
"dist",
|
|
25
|
+
"README.zh-CN.md",
|
|
26
|
+
"README.ja.md"
|
|
25
27
|
],
|
|
26
28
|
"main": "./dist/index.js",
|
|
27
29
|
"types": "./dist/index.d.ts",
|