@lark-apaas/coding-steering 0.1.87-alpha.20261108144422 → 0.1.87
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/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-steering",
|
|
3
|
-
"version": "0.1.87
|
|
3
|
+
"version": "0.1.87",
|
|
4
4
|
"description": "Stack-specific steering content for miaoda-coding templates",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"steering"
|
|
8
8
|
],
|
|
9
|
-
"scripts": {
|
|
10
|
-
"lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
|
|
11
|
-
},
|
|
12
9
|
"devDependencies": {
|
|
13
10
|
"markdownlint-cli": "^0.47.0"
|
|
14
11
|
},
|
|
@@ -20,5 +17,8 @@
|
|
|
20
17
|
"miaoda",
|
|
21
18
|
"coding-steering"
|
|
22
19
|
],
|
|
23
|
-
"license": "MIT"
|
|
24
|
-
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: anycross-forward
|
|
3
|
-
description: "Use when
|
|
3
|
+
description: "Use when generating client-side code that calls an internal / intranet HTTP API through the platform's built-in `/api/__platform__/http-forward` endpoint. 触发词:anycross, http-forward, http forwarder, 内网转发, 内网接口, 内网 API, 请求内网, 请求内网接口, 调用内网接口, 转发到内网, 请求内部接口"
|
|
4
4
|
steering: true
|
|
5
5
|
steering-topic: anycross_forward
|
|
6
6
|
steering-inclusion: manual
|
|
@@ -16,8 +16,6 @@ unavailable-agents:
|
|
|
16
16
|
|
|
17
17
|
# anycross-forward 内网请求转发指南
|
|
18
18
|
|
|
19
|
-
适用于客户内网和企业自建系统的通用 HTTP 转发。目标平台有专用的代理或身份接入指南时,先按该指南选择请求通路和鉴权方式。
|
|
20
|
-
|
|
21
19
|
通过平台内置的 http-forwarder 把请求转发到客户内网地址。后端 SDK 通过 `PlatformModule.forRoot()` **自动装配**,业务零接入。**默认在 node 侧用 `HttpForwarderService.fetch()` 调用**;前端 `axiosForBackend` 直调 `/api/__platform__/http-forward` 只用于"无凭证、只读、URL 可暴露"的例外场景。
|
|
22
20
|
|
|
23
21
|
> SDK 不感知代理 / 鉴权 / 隧道。实际通路由部署环境(沙箱 mihomo + iptables)处理,生成代码里**不要**拼 `proxy_group_id` / `jwtToken` / `anycross-host`。
|
|
@@ -26,9 +24,6 @@ unavailable-agents:
|
|
|
26
24
|
|
|
27
25
|
```text
|
|
28
26
|
需要请求一个 HTTP 接口?
|
|
29
|
-
│
|
|
30
|
-
├─ 目标平台已有专用代理或身份接入指南?
|
|
31
|
-
│ └─ 是 ──→ 按专用指南选择通路与鉴权
|
|
32
27
|
│
|
|
33
28
|
├─ 目标是平台内置 capability / Dataloom?
|
|
34
29
|
│ └─ 是 ──→ 用对应 SDK,不走 forwarder
|
|
@@ -112,13 +107,13 @@ export class CorpApiService {
|
|
|
112
107
|
- `fetch()` 返回 Web `Response`(`.json()` / `.text()` / `.arrayBuffer()`);上游 4xx/5xx 返回 `ok=false` **不抛**;forwarder 自身错(非法 URL / 上游不可达 / 超时 / 非法 header / 不支持的 body)抛 `HttpException`,`getResponse()` 为 `{ code, message }`。
|
|
113
108
|
- body 仅 `string` / JSON-able object / `null`;Buffer / FormData / URLSearchParams / Blob / 流会被拒绝为 400 `INVALID_REQUEST`。
|
|
114
109
|
- 不需要响应内容时 `await res.body?.cancel()`,否则连接占用到超时。
|
|
115
|
-
- **低层路径**:`forward(dto)` 返回 `{ status, headers, body: Readable }`,配 `toWebResponse(out)` 转成 Web `Response`。仅在自定义 controller 需要把上游流 pipe
|
|
110
|
+
- **低层路径**:`forward(dto)` 返回 `{ status, headers, body: Readable }`,配 `toWebResponse(out)` 转成 Web `Response`。仅在自定义 controller 需要把上游流 pipe 给下游等流式场景使用,普通业务一律 `fetch()`。
|
|
116
111
|
|
|
117
|
-
|
|
112
|
+
**禁止在 node 侧用裸 `fetch` / `axios` 打内网**,三个原因:
|
|
118
113
|
|
|
119
|
-
1.
|
|
120
|
-
2.
|
|
121
|
-
3.
|
|
114
|
+
1. Node 内置 fetch 不读 `HTTP_PROXY`,请求不会走出网代理;
|
|
115
|
+
2. 代理鉴权在首次 `forward()` / `fetch()` 才 lazy 初始化,绕过 SDK 就没有鉴权;
|
|
116
|
+
3. 不会带 `x-miaoda-ctx` 审计头,内网侧无法审计调用方。
|
|
122
117
|
|
|
123
118
|
## 四、前端直调(例外:无凭证、只读、URL 可暴露)
|
|
124
119
|
|
|
@@ -226,12 +221,12 @@ export async function safeForward(targetUrl: string) {
|
|
|
226
221
|
|
|
227
222
|
`user_id` 匿名访问为 `""`;trigger / 定时任务场景 `is_system_account` 为 `true`。内容是 **app 自述、SDK 不签名**,下游只用于审计("是哪个 app / 租户 / 用户发起的"),**权威 app 身份以代理层鉴权结果为准**,不要拿此 header 做授权决策。业务代码对它完全透明:不需要读、不能改。
|
|
228
223
|
|
|
229
|
-
##
|
|
224
|
+
## 七、生成代码必须遵守的 7 条
|
|
230
225
|
|
|
231
|
-
1.
|
|
226
|
+
1. **内网调用默认在 node 侧**:注入 `HttpForwarderService` 用 `fetch()`,URL 写死在 service、凭证只从 `process.env` 读;前端直调仅限无凭证只读接口。
|
|
232
227
|
2. **前端直调路径恒为 `/api/__platform__/http-forward`**,`targetUrl` 永远放 `params`,不要拼到 URL 字符串里、不要放 body、不要放 header。
|
|
233
228
|
3. **服务端零接入**——`PlatformModule.forRoot()` 已自动装配 `HttpForwarderModule` 并全局导出 service,**不要**在用户 `AppModule` 里再写 `HttpForwarderModule.forRoot()`。
|
|
234
|
-
4. **前端只用 `axiosForBackend`**,它已带 401 → `x-login-url`
|
|
229
|
+
4. **前端只用 `axiosForBackend`**,它已带 401 → `x-login-url` 自动跳转拦截器,**不要**再实现登录跳转;**node 侧只用 `HttpForwarderService`**,不要裸 `fetch` / `axios`。
|
|
235
230
|
5. **响应原样投射**:`res.status` / `res.headers` / `res.data` 都来自上游真实响应,上游 4xx/5xx 不是转发失败。forwarder 自身错在前端被模板 `GlobalExceptionFilter` 包成 `error.response.data.error`,业务码需从 `error.details`(JSON 字符串)里 parse 出来,详见第五节。
|
|
236
231
|
6. **headers 直接走 `headers: {...}`**,无需手剔 `host` / `content-length` / hop-by-hop,service 端会处理。
|
|
237
232
|
7. **不要手动设置 `x-miaoda-ctx`**,SDK 会无条件覆盖;也不要在业务代码里读它做授权。
|
|
@@ -240,7 +235,7 @@ export async function safeForward(targetUrl: string) {
|
|
|
240
235
|
|
|
241
236
|
| ❌ 错误 | ✅ 正确 |
|
|
242
237
|
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
|
243
|
-
|
|
|
238
|
+
| node 侧用裸 `fetch(url)` / `axios.get(url)` 打内网 | 注入 `HttpForwarderService` 用 `fetch()`(裸 fetch 不走代理、无鉴权、无审计头) |
|
|
244
239
|
| 前端直调带内网 API key / token,或让用户输入 `targetUrl` | 改 node 侧 `fetch()`:URL 写死在 service,凭证从 `process.env` 读 |
|
|
245
240
|
| `axiosForBackend.post('/api/__platform__/http-forward?targetUrl=...')` 手拼 query | `params: { targetUrl }`,让 axios 做 URL 编码 |
|
|
246
241
|
| `axiosForBackend.post(targetUrl, body)` 把 targetUrl 当路径 | 路径永远 `/api/__platform__/http-forward`,targetUrl 走 `params` |
|
|
@@ -178,11 +178,13 @@ await app.connect();
|
|
|
178
178
|
| `sendMessage({ role: 'user', content })` | 以用户身份发一条消息,触发模型回复 |
|
|
179
179
|
| `getHostContext()` / `onhostcontextchanged` | 主题、`displayMode`、`containerDimensions`、`locale`、`timeZone`、发起本次渲染的 `toolInfo` |
|
|
180
180
|
| `requestDisplayMode({ mode })` | 请求 inline / fullscreen 等展示模式,以 `availableDisplayModes` 为限 |
|
|
181
|
+
| `openLink({ url })` | 请宿主在浏览器打开外链;返回 `isError: true` 表示宿主拒绝 |
|
|
181
182
|
|
|
182
183
|
`useApp` 默认开自动调高(`autoResize`),内容变化不用手动发尺寸。
|
|
183
184
|
|
|
184
185
|
## 界面约束
|
|
185
186
|
|
|
187
|
+
- 打开外链用 `app.openLink({ url })`,不用 `<a target="_blank">` / `window.open`:iframe 的 sandbox 可能拦截,点击无反应。返回 `isError: true` 或抛错时,把原 URL 显示成可选中文本供手工复制。
|
|
186
188
|
- 不存凭证、不读 cookie / localStorage 里的登录态:iframe 是独立 origin,用户在业务系统的登录态带不进来。所有数据走 `callServerTool`,身份由宿主转发。
|
|
187
189
|
- 外部域名写进 `@McpUiResource` 的 `csp`:`connectDomains`(fetch / WebSocket)、`resourceDomains`(图片、脚本、样式)、`frameDomains`(内嵌 iframe)、`baseUriDomains`;默认全禁,漏写表现为资源静默加载失败。
|
|
188
190
|
- 业务返回值用 `textContent` 或 JSX 文本渲染,不拼 `innerHTML`。
|