@harapter/adapter-opencode 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 +107 -0
- package/README.md +27 -1
- package/README.zh-CN.md +96 -0
- package/package.json +8 -6
package/README.ja.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/adapter-opencode</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>ホスト運用の OpenCode HTTP/SSE Server を 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.ja.md">Harapter</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@harapter/adapter-opencode"><img src="https://img.shields.io/npm/v/%40harapter%2Fadapter-opencode/next?style=flat-square&label=npm%20next" alt="npm next バージョン"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/adapter-opencode"><img src="https://img.shields.io/npm/dm/%40harapter%2Fadapter-opencode?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/adapter-opencode` は stable `opencode serve`
|
|
23
|
+
HTTP/OpenAPI と SSE を Harapter
|
|
24
|
+
lifecycle に mapping します。Server の導入、認証、起動、停止はホストが行い、Adapter は指定 Endpoint だけに接続して remote
|
|
25
|
+
Session を暗黙削除しません。
|
|
26
|
+
|
|
27
|
+
## インストール
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @harapter/core@next @harapter/adapter-opencode@next
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## クイックスタート
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { HarnessRegistry, profileId } from '@harapter/core';
|
|
37
|
+
import {
|
|
38
|
+
OPENCODE_PROVIDER_ID,
|
|
39
|
+
createOpenCodeProviderFactory,
|
|
40
|
+
} from '@harapter/adapter-opencode';
|
|
41
|
+
|
|
42
|
+
const registry = new HarnessRegistry();
|
|
43
|
+
registry.register(createOpenCodeProviderFactory());
|
|
44
|
+
|
|
45
|
+
const client = await registry.connect({
|
|
46
|
+
profileId: profileId('opencode-local'),
|
|
47
|
+
providerId: OPENCODE_PROVIDER_ID,
|
|
48
|
+
displayName: 'OpenCode',
|
|
49
|
+
connection: {
|
|
50
|
+
kind: 'endpoint',
|
|
51
|
+
url: 'http://127.0.0.1:4096/',
|
|
52
|
+
transport: 'http',
|
|
53
|
+
ownership: 'external',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const session = await client.createSession();
|
|
58
|
+
try {
|
|
59
|
+
const run = await session.start({
|
|
60
|
+
parts: [{ type: 'text', text: 'Describe the current project.' }],
|
|
61
|
+
});
|
|
62
|
+
for await (const event of run.events()) console.log(event.type);
|
|
63
|
+
console.log((await run.result()).status);
|
|
64
|
+
} finally {
|
|
65
|
+
try {
|
|
66
|
+
await session.close();
|
|
67
|
+
} finally {
|
|
68
|
+
await client.close();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
認証する場合は Connection に `authRef` を置き、Factory の `resolveAuthHeaders`
|
|
74
|
+
でホストが解決します。Harapter は Header 値を記録・保存・返却しません。
|
|
75
|
+
|
|
76
|
+
## Session、Run、Input
|
|
77
|
+
|
|
78
|
+
- Session は Directory に束縛され、File Workspace URI は OpenCode
|
|
79
|
+
Directory になります;
|
|
80
|
+
- `session.close()` は local handle だけを解放し、remote DELETE
|
|
81
|
+
Route を呼びません;
|
|
82
|
+
- absolute URI と `mediaType` を持つ text/File/Image Reference を stable
|
|
83
|
+
Part に mapping します;
|
|
84
|
+
- Session ごとに active Run は一つで、同期 Message
|
|
85
|
+
Request の前に SSE を開きます;
|
|
86
|
+
- synchronous Message Response だけが success authority で、`session.idle`
|
|
87
|
+
は代替できません;
|
|
88
|
+
- `run.cancel()` は Abort Route と `MessageAbortedError` の両方で native
|
|
89
|
+
cancellation になります;
|
|
90
|
+
- Permission Event は Approval に mapping し、`once`、`reject`、明示的 `always`
|
|
91
|
+
を区別します。
|
|
92
|
+
|
|
93
|
+
remote
|
|
94
|
+
settlement が不確実な場合、Adapter は Session を quarantine し、誤った再利用を防ぎます。stream
|
|
95
|
+
loss、HTTP Error、不正 Event、未知 Terminal は success になりません。
|
|
96
|
+
|
|
97
|
+
## Compatibility と制限
|
|
98
|
+
|
|
99
|
+
接続時に Health を検証し、使用する Session、Message、Abort、Permission、Event
|
|
100
|
+
Shape を実行時に検証します。Runtime
|
|
101
|
+
Version は診断情報であり allowlist ではありません。
|
|
102
|
+
|
|
103
|
+
stable interface には Fixture、negative test、shared conformance、live
|
|
104
|
+
evidence があります。automatic SSE reconnect、OpenCode process 管理、portable
|
|
105
|
+
close による remote deletion、Command/Plugin の Core
|
|
106
|
+
Capability 化は対象外です。詳細は
|
|
107
|
+
[英語のドキュメント](./README.md)を参照してください。
|
package/README.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/adapter-opencode</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>Connect a host-operated OpenCode HTTP/SSE server to 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/adapter-opencode"><img src="https://img.shields.io/npm/v/%40harapter%2Fadapter-opencode/next?style=flat-square&label=npm%20next" alt="npm next version"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/adapter-opencode"><img src="https://img.shields.io/npm/dm/%40harapter%2Fadapter-opencode?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/adapter-opencode` maps the current documented stable `opencode serve`
|
|
4
23
|
HTTP/OpenAPI and Server-Sent Events interface to Harapter Core.
|
|
@@ -7,6 +26,13 @@ The host installs, configures, authenticates, starts, and stops OpenCode. The
|
|
|
7
26
|
Adapter connects only to a host-selected HTTP endpoint and never invokes a
|
|
8
27
|
runtime installation, server disposal, or Session deletion route implicitly.
|
|
9
28
|
|
|
29
|
+
## Use this Adapter when
|
|
30
|
+
|
|
31
|
+
- your host already operates an `opencode serve` endpoint;
|
|
32
|
+
- you need directory-bound Sessions, streamed Events, native abort, permissions,
|
|
33
|
+
and file or image references through the portable lifecycle; or
|
|
34
|
+
- authentication and server process ownership must remain outside Harapter.
|
|
35
|
+
|
|
10
36
|
## Installation
|
|
11
37
|
|
|
12
38
|
```bash
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/adapter-opencode</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>把宿主运行的 OpenCode HTTP/SSE Server 接入 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.zh-CN.md">Harapter</a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@harapter/adapter-opencode"><img src="https://img.shields.io/npm/v/%40harapter%2Fadapter-opencode/next?style=flat-square&label=npm%20next" alt="npm next 版本"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/adapter-opencode"><img src="https://img.shields.io/npm/dm/%40harapter%2Fadapter-opencode?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/adapter-opencode` 将当前稳定的 `opencode serve`
|
|
23
|
+
HTTP/OpenAPI 与 SSE 接口映射为 Harapter 生命周期。宿主负责安装、认证、启动和停止 Server;Adapter 只连接指定 Endpoint,不会隐式删除远端 Session。
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add @harapter/core@next @harapter/adapter-opencode@next
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## 快速开始
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { HarnessRegistry, profileId } from '@harapter/core';
|
|
35
|
+
import {
|
|
36
|
+
OPENCODE_PROVIDER_ID,
|
|
37
|
+
createOpenCodeProviderFactory,
|
|
38
|
+
} from '@harapter/adapter-opencode';
|
|
39
|
+
|
|
40
|
+
const registry = new HarnessRegistry();
|
|
41
|
+
registry.register(createOpenCodeProviderFactory());
|
|
42
|
+
|
|
43
|
+
const client = await registry.connect({
|
|
44
|
+
profileId: profileId('opencode-local'),
|
|
45
|
+
providerId: OPENCODE_PROVIDER_ID,
|
|
46
|
+
displayName: 'OpenCode',
|
|
47
|
+
connection: {
|
|
48
|
+
kind: 'endpoint',
|
|
49
|
+
url: 'http://127.0.0.1:4096/',
|
|
50
|
+
transport: 'http',
|
|
51
|
+
ownership: 'external',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const session = await client.createSession();
|
|
56
|
+
try {
|
|
57
|
+
const run = await session.start({
|
|
58
|
+
parts: [{ type: 'text', text: 'Describe the current project.' }],
|
|
59
|
+
});
|
|
60
|
+
for await (const event of run.events()) console.log(event.type);
|
|
61
|
+
console.log((await run.result()).status);
|
|
62
|
+
} finally {
|
|
63
|
+
try {
|
|
64
|
+
await session.close();
|
|
65
|
+
} finally {
|
|
66
|
+
await client.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
需要认证时,在 Connection 中放 `authRef`,并通过 Factory 的 `resolveAuthHeaders`
|
|
72
|
+
由宿主解析。Harapter 不记录、持久化或返回 Header 值。
|
|
73
|
+
|
|
74
|
+
## Session、Run 与输入
|
|
75
|
+
|
|
76
|
+
- Session 与目录绑定;File Workspace URI 会成为 OpenCode Directory;
|
|
77
|
+
- `session.close()` 只释放本地 Handle,不调用删除远端数据的 DELETE Route;
|
|
78
|
+
- 文本、带绝对 URI 和 `mediaType` 的 File/Image Reference 可以映射为稳定 Part;
|
|
79
|
+
- 一次 Session 只允许一个 Run,SSE 在同步 Message Request 前打开;
|
|
80
|
+
- 同步 Message Response 是成功终态的唯一 Authority,`session.idle` 不能代替它;
|
|
81
|
+
- `run.cancel()` 只有 Abort Route 成功且 Message Response 为
|
|
82
|
+
`MessageAbortedError` 时才是原生取消;
|
|
83
|
+
- Permission Event 映射为 Approval,`once`、`reject` 与显式 `always` 保持区别。
|
|
84
|
+
|
|
85
|
+
如果 Run 远端状态不确定,Adapter 会隔离对应 Session,防止后续工作错误复用它。断流、HTTP
|
|
86
|
+
Error、畸形 Event 和未知 Terminal Shape 绝不会变成 `run.completed`。
|
|
87
|
+
|
|
88
|
+
## 兼容性与限制
|
|
89
|
+
|
|
90
|
+
连接时校验 Health,使用到的 Session、Message、Abort、Permission 和 Event
|
|
91
|
+
Shape 都会在运行时校验。Runtime Version 只用于诊断,不是能力推断或白名单。
|
|
92
|
+
|
|
93
|
+
当前稳定接口已有 Fixture、负例、共享 Conformance 和 Live
|
|
94
|
+
Evidence。不支持自动 SSE 重连、OpenCode Process 管理、Portable
|
|
95
|
+
Close 删除远端 Session,以及把 Command 或 Plugin 宣称为 Core
|
|
96
|
+
Capability。详细选项、证据版本和 Native Client 见 [英文详细文档](./README.md)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harapter/adapter-opencode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "OpenCode HTTP provider adapter 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/providers/opencode#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",
|
|
@@ -41,11 +43,11 @@
|
|
|
41
43
|
"tag": "next"
|
|
42
44
|
},
|
|
43
45
|
"dependencies": {
|
|
44
|
-
"@harapter/core": "0.1.
|
|
45
|
-
"@harapter/transport-http-sse": "0.1.
|
|
46
|
+
"@harapter/core": "0.1.2",
|
|
47
|
+
"@harapter/transport-http-sse": "0.1.2"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@harapter/conformance": "0.1.
|
|
50
|
+
"@harapter/conformance": "0.1.2"
|
|
49
51
|
},
|
|
50
52
|
"scripts": {
|
|
51
53
|
"build": "tsc --project tsconfig.build.json"
|