docs: 补充detectInterfaceType实现说明
This commit is contained in:
@@ -384,6 +384,7 @@ interface ProtocolAdapter {
|
||||
supportsPassthrough(): Boolean // 同协议透传开关,默认 true
|
||||
|
||||
// HTTP 级别
|
||||
detectInterfaceType(nativePath: String): InterfaceType // 根据协议的 URL 路径识别接口类型
|
||||
buildUrl(nativePath: String, interfaceType: InterfaceType): String // 始终返回有效 URL;未知接口返回 nativePath
|
||||
buildHeaders(provider: TargetProvider): Map<String, String>
|
||||
supportsInterface(interfaceType: InterfaceType): Boolean
|
||||
@@ -477,7 +478,6 @@ class ConversionEngine {
|
||||
// 非流式请求转换
|
||||
convertHttpRequest(request, clientProtocol, providerProtocol, provider): HttpRequest {
|
||||
nativePath = request.url
|
||||
interfaceType = detectInterfaceType(nativePath)
|
||||
|
||||
if isPassthrough(clientProtocol, providerProtocol):
|
||||
providerAdapter = registry.get(providerProtocol)
|
||||
@@ -487,6 +487,9 @@ class ConversionEngine {
|
||||
clientAdapter = registry.get(clientProtocol)
|
||||
providerAdapter = registry.get(providerProtocol)
|
||||
|
||||
// 使用 clientAdapter 识别接口类型
|
||||
interfaceType = clientAdapter.detectInterfaceType(nativePath)
|
||||
|
||||
providerUrl = providerAdapter.buildUrl(nativePath, interfaceType)
|
||||
providerHeaders = providerAdapter.buildHeaders(provider)
|
||||
providerBody = convertBody(interfaceType, clientAdapter, providerAdapter, provider, request.body)
|
||||
@@ -840,7 +843,7 @@ TargetProvider
|
||||
// ─── 协议适配器 ───
|
||||
ProtocolAdapter
|
||||
.protocolName() / .protocolVersion() / .supportsPassthrough()
|
||||
.buildUrl(nativePath, type) / .buildHeaders(provider) / .supportsInterface(type)
|
||||
.detectInterfaceType(nativePath) / .buildUrl(nativePath, type) / .buildHeaders(provider) / .supportsInterface(type)
|
||||
.decodeRequest(raw) / .encodeRequest(canonical, provider)
|
||||
.decodeResponse(raw) / .encodeResponse(canonical)
|
||||
.createStreamDecoder() / .createStreamEncoder()
|
||||
@@ -932,10 +935,14 @@ Canonical Model 是**活的公共契约**,不是固定不变的。其字段集
|
||||
|
||||
| 项目 | 说明 |
|
||||
|------|------|
|
||||
| URL 路径模式 | 列出所有接口的 URL 路径和对应的 InterfaceType |
|
||||
| URL 路径模式 | 列出所有接口的 URL 路径和对应的 InterfaceType,由 `detectInterfaceType` 实现 |
|
||||
| 接口能力矩阵 | 每种 InterfaceType 的支持状态(`supportsInterface`) |
|
||||
| URL 映射表 | 每种 InterfaceType 的目标 URL 路径(`buildUrl`) |
|
||||
|
||||
**重要**:`detectInterfaceType` 由各协议 Adapter 实现,因为不同协议有不同的 URL 路径约定。例如:
|
||||
- OpenAI: `/v1/chat/completions` → CHAT
|
||||
- Anthropic: `/v1/messages` → CHAT
|
||||
|
||||
### D.3 请求头构建
|
||||
|
||||
| 项目 | 说明 |
|
||||
@@ -1049,6 +1056,7 @@ Canonical Model 是**活的公共契约**,不是固定不变的。其字段集
|
||||
|
||||
| 章节 | 检查项 |
|
||||
|------|--------|
|
||||
| D.2 | [ ] `detectInterfaceType(nativePath)` 已实现,所有已知路径已覆盖 |
|
||||
| D.2 | [ ] 所有 InterfaceType 的 `supportsInterface` 返回值已确定 |
|
||||
| D.2 | [ ] 所有 InterfaceType 的 `buildUrl` 映射已确定 |
|
||||
| D.3 | [ ] `buildHeaders(provider)` 已实现,adapter_config 契约已文档化 |
|
||||
|
||||
Reference in New Issue
Block a user