@tbox.cn/app-provider-custom 0.2.1 → 0.2.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/AGENTS.md +140 -2
- package/package.json +4 -4
package/AGENTS.md
CHANGED
|
@@ -26,6 +26,118 @@
|
|
|
26
26
|
用不同 provider 名分键。adapter 内取凭据值(如自签名):`input.credential()` 惰性 getter
|
|
27
27
|
(返回 `{ scope, type, value }`;未配 credentialRef → undefined)。
|
|
28
28
|
|
|
29
|
+
## 声明形态 ⇔ 实现落点(先选对形态再动手)
|
|
30
|
+
|
|
31
|
+
| 声明形态(services.<slot>.provider) | adapter 落点 | 失配信号 |
|
|
32
|
+
|---|---|---|
|
|
33
|
+
| 内联对象 `{ provider, credentialType }` | **本包**(provider-custom) | 未注册 → `PROVIDER_NOT_IMPLEMENTED` |
|
|
34
|
+
| 字符串厂商名(如 `"mall-demo"`) | 对应正式 provider 包(catalog 来源;`packages/provider-mock` 为样例) | catalog 无此厂商 → **`PROVIDER_NOT_FOUND`** |
|
|
35
|
+
|
|
36
|
+
**本包 adapter 禁止配字符串声明**:本包零贡献(manifest 无
|
|
37
|
+
`declare.providers.slots`),永不进 provider catalog——字符串声明运行时按
|
|
38
|
+
catalog 查表,必报 `PROVIDER_NOT_FOUND`(错误文案「provider 未命中
|
|
39
|
+
catalog」≠ 名字拼错,是**形态落错**)。
|
|
40
|
+
|
|
41
|
+
## 内联声明 JSON 片段(可复制形态)
|
|
42
|
+
|
|
43
|
+
`config/integrations.json` 槽级写法(`provider` 对象与 `implementation`
|
|
44
|
+
是**兄弟键**——implementation 不在对象内;省略 `instances` = 通配激活):
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"services": {
|
|
49
|
+
"parking.query": {
|
|
50
|
+
"provider": { "provider": "my-api", "credentialType": "static-headers-v1" },
|
|
51
|
+
"implementation": "my-api@1",
|
|
52
|
+
"config": { "baseUrl": "https://api.example.com" },
|
|
53
|
+
"credentialRef": "secret://my-api-parking.query"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**错误形态对照**:
|
|
60
|
+
|
|
61
|
+
| ❌ 错误 | 原因 |
|
|
62
|
+
|---|---|
|
|
63
|
+
| `"provider": { "provider": "my-api", "implementation": "my-api@1" }` | `implementation` 不是内联对象字段(zod 拒) |
|
|
64
|
+
| `"provider": "my-api"` 而 adapter 在本包 | catalog 查表失配 → `PROVIDER_NOT_FOUND`(见上节) |
|
|
65
|
+
| `"instances": {}` | 零激活(省略 = 通配激活) |
|
|
66
|
+
|
|
67
|
+
实参(config 值 / 凭据 stem / 槽名)按用户 API 文档填;凭据真值只进
|
|
68
|
+
`config/credentials/<stem>.json` 嵌套形(格式见「认证与凭据」)。
|
|
69
|
+
|
|
70
|
+
## 最小代码骨架
|
|
71
|
+
|
|
72
|
+
类型 import 双源(全部 `import type`——typecheck 首祸排除):
|
|
73
|
+
|
|
74
|
+
- `ServiceAdapterFactory` / `ServerContext` ← `@tbox.cn/app-agent-sdk-server`
|
|
75
|
+
- Port 接口 ← 服务域契约包(mall 域 = `@app/contracts-mall`;消费模块
|
|
76
|
+
`src/server/ports.ts` 的 import 行可反查正确来源——如 `parking.query` 的
|
|
77
|
+
供给接口 `ParkingQueryPort`;本包 `package.json` 按需补该依赖)
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
// packages/provider-custom/src/server/my-api.ts
|
|
81
|
+
import type { ServiceAdapterFactory } from '@tbox.cn/app-agent-sdk-server';
|
|
82
|
+
import type { ParkingQueryPort } from '@app/contracts-mall';
|
|
83
|
+
|
|
84
|
+
export const myApiFactory: ServiceAdapterFactory = (input) => {
|
|
85
|
+
const impl: ParkingQueryPort = {
|
|
86
|
+
async queryFee(q, req) {
|
|
87
|
+
// input.transport:HTTP 通道(baseUrl/认证/熔断/HTTPS 强制内建)
|
|
88
|
+
const res = await input.transport.request({
|
|
89
|
+
path: '/v1/parking/fee',
|
|
90
|
+
method: 'POST',
|
|
91
|
+
body: { plateNo: req.plateNo },
|
|
92
|
+
});
|
|
93
|
+
return mapFee(res);
|
|
94
|
+
},
|
|
95
|
+
// ...Port 其余方法签名照抄接口定义
|
|
96
|
+
};
|
|
97
|
+
return impl;
|
|
98
|
+
};
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
**Port 形状检索工作法(零猜测)**:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
rg "export (interface|type) .*Port" packages/<消费模块>/src/server/ports.ts
|
|
105
|
+
rg "<接口名>" packages/contracts-mall/src/
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- Port 方法签名 = 实现清单——逐个照抄(参数/返回值与工具语义一一对应);
|
|
109
|
+
- 厂商响应 → contracts 结构转换后返回,不透传厂商字段名。
|
|
110
|
+
|
|
111
|
+
注册(`src/server/index.ts` 的 `register(ctx)` 内):
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
115
|
+
import { myApiFactory } from './my-api';
|
|
116
|
+
|
|
117
|
+
// register(ctx) 内:
|
|
118
|
+
ctx.integrations?.registerAdapter('my-api', 'inline', myApiFactory);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
单 factory 多服务:按 `input.service` 分支返回不同 Port 实现(服务清单见
|
|
122
|
+
消费模块 `tbox.module.json` `declare.owns`);或每服务独立 provider 名
|
|
123
|
+
分键注册。`input` 字段全集见 `src/server/index.ts` 签名示例注释。
|
|
124
|
+
|
|
125
|
+
## provider 名三处一致
|
|
126
|
+
|
|
127
|
+
取的 provider 名必须下三处同名(任一处失配则运行时报 `PROVIDER_NOT_IMPLEMENTED`——
|
|
128
|
+
resolveService 惰性查表查不到对应 adapter):
|
|
129
|
+
|
|
130
|
+
1. **声明侧**:`config/integrations.json` 中 `services.<slot>.provider.provider` 字段
|
|
131
|
+
(内联声明对象内的 `provider` 键;若声明是字符串厂商则该键名直接是名字)
|
|
132
|
+
2. **注册侧**:`packages/provider-custom/src/server/index.ts` 中
|
|
133
|
+
`ctx.integrations?.registerAdapter('<同名>', 'inline', factory)` 第一参
|
|
134
|
+
3. **凭据侧**:`config/credentials/${provider名}-${service}.json` 的 stem 前缀
|
|
135
|
+
(服务级);共享 stem = `${provider名}-global`;实例差异化另见
|
|
136
|
+
`${provider名}-${instanceId}-${domain}` 形(凭据文件嵌套形格式见下节)
|
|
137
|
+
|
|
138
|
+
> 多服务单键只是注册侧共享,三处同名规则不放宽——同一 provider 名的全部服务 stem 仍各自
|
|
139
|
+
> 含 `-<service>` 段;只有注册键(registerAdapter 第一参)一次("单键")。
|
|
140
|
+
|
|
29
141
|
## 认证与凭据
|
|
30
142
|
|
|
31
143
|
| 认证形态 | credentialType(声明与凭据文件一致) | 机制 |
|
|
@@ -45,11 +157,37 @@
|
|
|
45
157
|
- 槽 `instances` 省略 = 通配激活(**勿写空对象 `{}`** = 零激活);已绑字符串厂商的槽整组
|
|
46
158
|
替换前先向用户确认。
|
|
47
159
|
|
|
160
|
+
### config 与 configSchema 的区别
|
|
161
|
+
|
|
162
|
+
| 字段 | 落点 | 类型 | 内容形态 |
|
|
163
|
+
|---|---|---|---|
|
|
164
|
+
| `services[slot].config` / `modules[].config` / root `config` / `instances[].config` 等所有 `config*` 字段 | `config/integrations.json` | `Record<string, unknown>` 真实值 | **明文连接参数**——baseUrl / 路径前缀 / 超时 / 重试等。直接进 integrations.json(可见、非密钥) |
|
|
165
|
+
| `services[slot].provider.configSchema`(内联声明中的可选字段) | `integrations.json` 写路径字符串,文件本体在 `config/<路径>.json` | `string` 路径 + 开发者自写文件 | **可选 schema 制品**——相对应用 `config/` 的路径;当前无强制 schema 格式;写则 doctor 谓词可消费校验,不写则不校验 |
|
|
166
|
+
|
|
167
|
+
**`config` 不替代凭据**:嵌在 `config.*` 字段里的值是"可见的连接配置",不是"凭据真值"。任何形式
|
|
168
|
+
的密钥(API key / token / 签名 secret / OAuth secret)经 `credentialRef: "secret://<stem>"`
|
|
169
|
+
引用,真值只进 `config/credentials/<stem>.json`(嵌套形)或平台 env——**禁**直接进 `config.*`
|
|
170
|
+
字段明文,也禁进 prompt、代码、入库文档。
|
|
171
|
+
|
|
172
|
+
**`configSchema` 不强制**:framework 不要求每条内联声明都配 schema 文件,schema 形态由开发者自选
|
|
173
|
+
(推荐自身可读、可校验的 JSON schema 或自定义格式)。doctor 谓词对存在 `configSchema` 的声明做受
|
|
174
|
+
控子集校验;不存在则跳过。AI 接自定义集成任务不要因为没 schema 而拒绝落声明。
|
|
175
|
+
|
|
176
|
+
### 配置值与凭据真值的可见性边界
|
|
177
|
+
|
|
178
|
+
| 数据 | 落点 | 是否进 prompt / 代码 / 入库文档 |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| `*.config` 字段(baseUrl / 超时 / 路径前缀等连接参数) | `config/integrations.json` 明文 | ⚠ 可见(明文即设计意图),但不应成"密钥代用品" |
|
|
181
|
+
| 凭据真值(API key / token / 签名 secret / OAuth secret 等) | `config/credentials/<stem>.json` 嵌套形 或 平台 env | ❌ 禁入 prompt / 代码 / integrations.json / 入库文档 |
|
|
182
|
+
| `credentialRef: "secret://<stem>"` 引用本身 | `config/integrations.json` 明文 | ✅ 可见(非真值,仅 stem 引用) |
|
|
183
|
+
| AGENTS.md / 模板出厂文档 | 仓库 | ❌ 不含 `secret://` 真值(仅描述引用形态) |
|
|
184
|
+
|
|
48
185
|
## 完成判据
|
|
49
186
|
|
|
50
187
|
- `pnpm typecheck && pnpm build` 通过;
|
|
51
|
-
-
|
|
52
|
-
|
|
188
|
+
- 对话或 curl 触发一次该服务的工具调用,确认正常出结果(typecheck/build 与 doctor
|
|
189
|
+
均不触运行时——resolveService 惰性,调用时才判 `PROVIDER_NOT_IMPLEMENTED`);
|
|
190
|
+
- 通配槽下 doctor 不检查凭据,运行时为最终裁判。
|
|
53
191
|
|
|
54
192
|
## 真实厂商接入
|
|
55
193
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-provider-custom",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "自定义厂商实施落点空包(中立空壳):内联声明(自定义 API)的 adapter 代码落点——AI 按 AGENTS.md 指引实施,registerAdapter 命中即转 ok。单包多厂商。",
|
|
6
6
|
"exports": {
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tbox.cn/app-contracts": "0.12.
|
|
18
|
-
"@tbox.cn/app-agent-sdk-client": "0.1.
|
|
19
|
-
"@tbox.cn/app-agent-sdk-server": "0.1.
|
|
17
|
+
"@tbox.cn/app-contracts": "0.12.3",
|
|
18
|
+
"@tbox.cn/app-agent-sdk-client": "0.1.3",
|
|
19
|
+
"@tbox.cn/app-agent-sdk-server": "0.1.4"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "24.13.3",
|