@harapter/transport-jsonrpc-stdio 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 +92 -0
- package/README.md +29 -2
- package/README.zh-CN.md +86 -0
- package/package.json +5 -3
package/README.ja.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/transport-jsonrpc-stdio</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>呼び出し側が所有する Node Stream 上の bounded bidirectional JSONL RPC。</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/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/v/%40harapter%2Ftransport-jsonrpc-stdio/next?style=flat-square&label=npm%20next" alt="npm next バージョン"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/dm/%40harapter%2Ftransport-jsonrpc-stdio?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
|
+
stdin/stdout などの Node Stream で、一行一 JSON object の RPC を扱う Provider
|
|
23
|
+
Adapter 向け transport です。framing、request
|
|
24
|
+
correlation、順序付き inbound、backpressure、timeout、cleanup を担いますが、Provider
|
|
25
|
+
method を解釈せず、Harapter の Session、Run、終端結果を生成しません。
|
|
26
|
+
|
|
27
|
+
## インストール
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @harapter/transport-jsonrpc-stdio@next
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## クイックスタート
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { JsonRpcStdioTransport } from '@harapter/transport-jsonrpc-stdio';
|
|
37
|
+
|
|
38
|
+
const transport = new JsonRpcStdioTransport({
|
|
39
|
+
readable: controlledProcess.stdout,
|
|
40
|
+
writable: controlledProcess.stdin,
|
|
41
|
+
cleanup: () => stopControlledProcess(controlledProcess),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const incoming = (async () => {
|
|
45
|
+
for await (const message of transport.incoming()) {
|
|
46
|
+
await validateAndMapProviderMessage(message);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
const initialized = await transport.request('initialize', {
|
|
51
|
+
clientInfo: { name: 'harapter-provider', version: 'current' },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await validateInitializeResult(initialized);
|
|
55
|
+
await transport.close();
|
|
56
|
+
await incoming;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## よくある使い方
|
|
60
|
+
|
|
61
|
+
- `request()` は対応する response を待ち、`notify()`
|
|
62
|
+
は notification だけを書きます;
|
|
63
|
+
- `incoming()` の consumer は一つだけです;
|
|
64
|
+
- 終端 response より前の Event 処理を待つ場合は `requestAfterInbound()`
|
|
65
|
+
を使います;
|
|
66
|
+
- Provider 側で解決済みの remote request は `abandonInboundRequest()`
|
|
67
|
+
で解放します;
|
|
68
|
+
- `getRemoteError()` は明示的 raw
|
|
69
|
+
data 境界で、Adapter による検証と redaction が必要です。
|
|
70
|
+
|
|
71
|
+
## 既定の境界
|
|
72
|
+
|
|
73
|
+
- message、未読 inbound、pending request、remote request、write は有限です;
|
|
74
|
+
- request timeout は既定で 30 秒、timer は Node の安全範囲に制限されます;
|
|
75
|
+
- 一つの JSON object を含む JSONL frame のみで、batch
|
|
76
|
+
array と複数行 frame は拒否します;
|
|
77
|
+
- JSON-RPC `"2.0"` の必須化・送信や整数 numeric ID の強制を選択できます。
|
|
78
|
+
|
|
79
|
+
Stream と process は呼び出し側が所有します。`close()`
|
|
80
|
+
は Stream を直接終了せず、logical connection を閉じ、任意の `cleanup`
|
|
81
|
+
を最大一回実行します。`AbortSignal` と timeout は local
|
|
82
|
+
wait だけを止め、Provider cancellation の証拠にはなりません。
|
|
83
|
+
|
|
84
|
+
## Error と機密データ
|
|
85
|
+
|
|
86
|
+
不正 JSON、無効 UTF-8、上限超過、重複 remote request ID、早期 EOF は fail
|
|
87
|
+
closed です。`JsonRpcTransportError` は frame、ID、Stream
|
|
88
|
+
Error を保持しません。remote error、`method`、`params` は untrusted Provider
|
|
89
|
+
data なので、記録や mapping の前に Adapter が検証・redact します。
|
|
90
|
+
|
|
91
|
+
このパッケージは process manager、Provider Adapter、retry layer、Agent
|
|
92
|
+
Loop ではありません。全設定と制限は[英語の詳細ドキュメント](./README.md)を参照してください。
|
package/README.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/transport-jsonrpc-stdio</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>Bounded bidirectional JSONL RPC over caller-owned Node streams.</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/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/v/%40harapter%2Ftransport-jsonrpc-stdio/next?style=flat-square&label=npm%20next" alt="npm next version"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/dm/%40harapter%2Ftransport-jsonrpc-stdio?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/transport-jsonrpc-stdio` is a bounded, bidirectional JSONL transport
|
|
4
23
|
for Provider Adapters whose official machine interface exchanges JSON-RPC-shaped
|
|
@@ -9,6 +28,14 @@ backpressure, local wait controls, and connection disposal. It does not import
|
|
|
9
28
|
Provider SDKs or assign portable Harapter meaning to Provider methods and
|
|
10
29
|
payloads.
|
|
11
30
|
|
|
31
|
+
## Use this package when
|
|
32
|
+
|
|
33
|
+
- an official harness interface speaks newline-delimited JSON-RPC-shaped
|
|
34
|
+
messages over stdin/stdout or equivalent streams;
|
|
35
|
+
- your Adapter needs bounded request correlation, backpressure, remote requests,
|
|
36
|
+
and deterministic cleanup; or
|
|
37
|
+
- you need strict transport errors without leaking frames or upstream messages.
|
|
38
|
+
|
|
12
39
|
## Installation
|
|
13
40
|
|
|
14
41
|
```bash
|
|
@@ -120,7 +147,7 @@ object itself through ordinary JSON serialization or Node inspection remains
|
|
|
120
147
|
content-free. Inbound `method` and `params` have the same Provider-owned
|
|
121
148
|
validation and redaction requirement.
|
|
122
149
|
|
|
123
|
-
##
|
|
150
|
+
## Quick start
|
|
124
151
|
|
|
125
152
|
```ts
|
|
126
153
|
import { JsonRpcStdioTransport } from '@harapter/transport-jsonrpc-stdio';
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
|
+
|
|
3
|
+
<h1 align="center"><code>@harapter/transport-jsonrpc-stdio</code></h1>
|
|
4
|
+
|
|
5
|
+
<p align="center"><strong>在调用方拥有的 Node Stream 上提供有界双向 JSONL RPC。</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/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/v/%40harapter%2Ftransport-jsonrpc-stdio/next?style=flat-square&label=npm%20next" alt="npm next 版本"></a>
|
|
13
|
+
<a href="https://www.npmjs.com/package/@harapter/transport-jsonrpc-stdio"><img src="https://img.shields.io/npm/dm/%40harapter%2Ftransport-jsonrpc-stdio?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
|
+
这个传输包面向通过 stdin/stdout 或等价 Node
|
|
23
|
+
Stream 交换一行一个 JSON 对象的 Provider
|
|
24
|
+
Adapter。它负责 framing、请求关联、有序入站消息、背压、超时和清理,但不解释 Provider 方法,也不生成 Harapter
|
|
25
|
+
Session、Run 或终态。
|
|
26
|
+
|
|
27
|
+
## 安装
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pnpm add @harapter/transport-jsonrpc-stdio@next
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 快速开始
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { JsonRpcStdioTransport } from '@harapter/transport-jsonrpc-stdio';
|
|
37
|
+
|
|
38
|
+
const transport = new JsonRpcStdioTransport({
|
|
39
|
+
readable: controlledProcess.stdout,
|
|
40
|
+
writable: controlledProcess.stdin,
|
|
41
|
+
cleanup: () => stopControlledProcess(controlledProcess),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const incoming = (async () => {
|
|
45
|
+
for await (const message of transport.incoming()) {
|
|
46
|
+
await validateAndMapProviderMessage(message);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
|
|
50
|
+
const initialized = await transport.request('initialize', {
|
|
51
|
+
clientInfo: { name: 'harapter-provider', version: 'current' },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await validateInitializeResult(initialized);
|
|
55
|
+
await transport.close();
|
|
56
|
+
await incoming;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 常见用法
|
|
60
|
+
|
|
61
|
+
- `request()` 发送请求并等待匹配响应;`notify()` 只写通知;
|
|
62
|
+
- `incoming()` 由唯一消费者处理远端请求与通知;
|
|
63
|
+
- 需要“终态响应之前的事件均已处理”时使用 `requestAfterInbound()`;
|
|
64
|
+
- Provider 已在别处权威解决远端请求时,用 `abandonInboundRequest()` 释放容量;
|
|
65
|
+
- `getRemoteError()` 是显式原始数据边界,返回值必须由 Adapter 校验和脱敏。
|
|
66
|
+
|
|
67
|
+
## 默认边界
|
|
68
|
+
|
|
69
|
+
- 单条消息、未读消息、待处理请求、入站请求和写操作均有有限上限;
|
|
70
|
+
- 默认请求等待 30 秒,所有 timer 值必须在 Node 可安全表示的范围内;
|
|
71
|
+
- 只接受单个 JSON 对象的 JSONL frame,不支持 batch array 或多行 frame;
|
|
72
|
+
- 可要求并发送精确的 JSON-RPC `"2.0"`,也可要求整数 numeric ID。
|
|
73
|
+
|
|
74
|
+
调用方拥有 Stream 和进程。`close()`
|
|
75
|
+
不会直接结束或销毁 Stream,只会关闭逻辑连接并最多调用一次可选
|
|
76
|
+
`cleanup`。`AbortSignal`
|
|
77
|
+
和 timeout 只终止本地等待,不会发送 Provider 取消,也不能证明远端工作已经停止。
|
|
78
|
+
|
|
79
|
+
## 错误与敏感数据
|
|
80
|
+
|
|
81
|
+
畸形 JSON、无效 UTF-8、超限消息、重复入站请求 ID 和提前 EOF 会 fail closed。
|
|
82
|
+
`JsonRpcTransportError` 不附带原始 frame、标识符或 Stream Error。远端 error、
|
|
83
|
+
`method` 和 `params` 仍是不可信 Provider 数据,Adapter 必须在记录或映射前脱敏。
|
|
84
|
+
|
|
85
|
+
该包不是进程管理器、Provider Adapter、重试层或通用 Agent
|
|
86
|
+
Loop。完整限制与所有配置项见[英文详细文档](./README.md)。
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@harapter/transport-jsonrpc-stdio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Bounded bidirectional JSONL RPC transport for Harapter providers.",
|
|
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/transport-jsonrpc-stdio#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",
|