feat(workflow): 规范化 HTTP 节点请求方法与连接器授权模型

- 在 models/nodes/http.ts 中收敛请求方法为 HttpMethodSchema 严格枚举(GET/POST/PUT/PATCH/DELETE)
- 补齐 HttpBodyTypeSchema(none/raw/from-data/form-urlencoded)与 HttpContentTypeSchema 枚举
- 更新 specs/workflow-schema.json 保证单测校验与 Schema 一致
- 扩充 models/nodes/README.nodes.md 详细记录 HTTP 节点的请求方式、连接器筛选与授权联动契约
- 纳管 .workbuddy 本地记忆文档(2026-11-02.md 与 MEMORY.md)
This commit is contained in:
gitea committed 2026-11-02 23:06:51 +08:00
1 parent 2371ae0bf1
commit 6a06c53566
5 files changed
+309 -24

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
# 2026-11-02 工作记录
## 1. 任务背景与目标
- **目标企业**: CSM (`Cxa3oOtQi2eS$g`)
- **操作员工身份约束**: 严格绑定「**李志财**」(`2HQbkGx2DgnM00`),严禁使用其他账号(如缪梦婷)。
- **目标工作流**: `881196955148578838`(商机台账单据事件流)
- **核心问题定位**:
- `action_agree_normal` 在未超标单据执行时报错:`HTTP 400 缺少accessToken参数`。
- 根因:HTTP 节点原本漏填了 `appId`(连接器)与 `authId`(授权),合思开放平台需要由 Piper 自动根据连接器授权换取 accessToken 并注入 URL。
- 本地模型与校验问题:原本 `BaseTaskSchema` 和 `HttpTaskSchema` 缺少 `.passthrough()` 与 `appId`/`authId` 显式字段定义,导致 `hose-use workflow node edit` 序列化时自动吞掉这些关键属性。
## 2. 节点原子化重构成果
- 创建 `src/domains/platform/workflow/models/nodes/` 子目录,将原庞大的单文件节点拆为 13 个独立模块:
- `common.ts`: `BaseTaskSchema.passthrough()`, `WorkflowTask`
- `http.ts`: `HttpTaskSchema`(支持 `authId`, `appId`, `HttpMethodSchema`, `HttpBodyTypeSchema`, `HttpContentTypeSchema`)
- `delay.ts`, `code.ts`, `webhook.ts`, `stop.ts`, `flow.ts`, `datalink.ts`, `condition.ts`, `every.ts`, `unknown.ts`, `index.ts`
- `README.nodes.md`: 完整架构与节点规范文档
- 同步生成 `specs/workflow-schema.json`。
## 3. Piper 连接器、授权与 HTTP 请求方法深度调研结论
通过 Kimi WebBridge 挂载 CDP 探针并逆向 Piper 生产前端 bundle 与 Sourcemap,明确了以下底层契约:
### 3.1 连接器 (`appId`)
- **查询接口**: `POST /api/easo/dsl/task-openapi/select/appId`,Body: `{ $platformId: platformId }`
- **平台预置全量清单(共 7 个)**:
1. `4`: `费控原生`(`ekuaibao_app`,通过 openapi key/secret 自动向 `https://app.ekuaibao.com/api/openapi/v1/auth/getAccessToken` 换票并自动注入 `?accessToken=...`)
2. `5`: `费控钉钉`
3. `9`: `纷享销客`
4. `11`: `ai应用`
5. `14`: `招商银行商务卡查询`
6. `15`: `费控企微`
7. `16`: `开放平台`
### 3.2 授权 (`authId`)
- **查询接口**: `POST /api/easo/corpApp/getAuthList`,Body: `{ appId: "<appId>", size: 100 }`,Header: `Authorization: Bearer <jwtToken>`
- **配置详情/元数据接口**: `GET /api/easo/app/getInfo?id=<appId>`(含 `authConfig.dslConfig` 表单结构与 `tokenSendParam`)
- **保存新授权接口**: `POST /api/easo/corpApp/saveAuthInfo`
- **CSM 企业实测现状**:
- `appId: 4`(费控原生):拥有 1 个可用授权实例:`id: 157`,名称 `费控原生#202512150`。
- 其他连接器(5、9、11、14、15、16):在当前 CSM 企业下 `totalItems: 0`,未配置授权实例。
### 3.3 HTTP 节点请求方法 (`method`)
- **严格枚举(5 种)**:
- `GET`
- `POST`
- `PUT`
- `PATCH`
- `DELETE`
- **联动行为(Reactions)**:
- 选定 `POST`、`PUT`、`PATCH` 时,表单显示 `bodyType` 及其输入区;
- 选定 `GET`、`DELETE` 时,表单隐藏请求体区域(`x-display: none`)。
### 3.4 配套请求体类型 (`bodyType`) 与 Content-Type
- **`bodyType` 枚举**:
- `none`: 无请求体
- `raw`: 原生字符串/JSON(默认,支持 `@{choose(...)}` 变量插值)
- `from-data`: multipart/form-data 键值对(前端枚举值为 `from-data`)
- `form-urlencoded`: x-www-form-urlencoded 键值对
- **`contentType`(raw 模式下)**:
- `application/json`(默认)
- `text/plain`
- `application/javascript`
- `text/html`
- `application/xml`
+18
View File
@@ -15,3 +15,21 @@
## 已知基础设施
- New API 端点已从 Sealos 的 `sealosgzg.site` 迁移至 `api.ying-qing.cn`;代码里残留的 `*.sealosgzg.site` 硬编码属于待清理项(workflow 灰度开通网关)。
## 工作流与 Piper 核心契约(2026-11-02 固化)
- **工作流节点原子模型**: 位于 `src/domains/platform/workflow/models/nodes/`,包含 13 个独立模块与 `README.nodes.md`。
- **连接器 (`appId`)**:
- 查询接口: `POST /api/easo/dsl/task-openapi/select/appId`,Body: `{ $platformId: platformId }`
- 完整 7 种枚举: `4` (费控原生), `5` (费控钉钉), `9` (纷享销客), `11` (ai应用), `14` (招商银行商务卡查询), `15` (费控企微), `16` (开放平台)。
- **授权 (`authId`)**:
- 查询接口: `POST /api/easo/corpApp/getAuthList`,Body: `{ appId, size: 100 }`,Header: `Authorization: Bearer <jwtToken>`。
- 元数据接口: `GET /api/easo/app/getInfo?id=<appId>`(含 `tokenSendParam`,`appId: 4` 时自动注入 `?accessToken=...`)。
- **HTTP 节点请求方法 (`method`)**:
- 严格 5 种枚举: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`。
- `POST`, `PUT`, `PATCH` 时显示请求体;`GET`, `DELETE` 时收起隐藏。
- **请求体类型 (`bodyType`)**:
- 4 种枚举: `none`, `raw` (默认), `from-data`, `form-urlencoded`。
- **Content-Type**:
- 5 种枚举: `application/json` (默认), `text/plain`, `application/javascript`, `text/html`, `application/xml`。
+174 -21
View File
@@ -488,20 +488,71 @@
"type": "string"
},
"method": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
]
},
{
"type": "string"
}
]
},
"url": {
"type": "string"
},
"bodyType": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"none",
"raw",
"from-data",
"form-urlencoded"
]
},
{
"type": "string"
}
]
},
"bodyRaw": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
]
},
"contentType": {
"anyOf": [
{
"type": "string",
"enum": [
"application/json",
"text/plain",
"application/javascript",
"text/html",
"application/xml"
]
},
{
"type": "string"
}
]
},
"header": {
"type": "array",
@@ -1613,20 +1664,71 @@
"type": "string"
},
"method": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
]
},
{
"type": "string"
}
]
},
"url": {
"type": "string"
},
"bodyType": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"none",
"raw",
"from-data",
"form-urlencoded"
]
},
{
"type": "string"
}
]
},
"bodyRaw": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
]
},
"contentType": {
"anyOf": [
{
"type": "string",
"enum": [
"application/json",
"text/plain",
"application/javascript",
"text/html",
"application/xml"
]
},
{
"type": "string"
}
]
},
"header": {
"type": "array",
@@ -2813,20 +2915,71 @@
"type": "string"
},
"method": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"PATCH",
"DELETE"
]
},
{
"type": "string"
}
]
},
"url": {
"type": "string"
},
"bodyType": {
"type": "string"
"anyOf": [
{
"type": "string",
"enum": [
"none",
"raw",
"from-data",
"form-urlencoded"
]
},
{
"type": "string"
}
]
},
"bodyRaw": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
"anyOf": [
{
"type": "string"
},
{
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
]
},
"contentType": {
"anyOf": [
{
"type": "string",
"enum": [
"application/json",
"text/plain",
"application/javascript",
"text/html",
"application/xml"
]
},
{
"type": "string"
}
]
},
"header": {
"type": "array",
@@ -18,3 +18,35 @@
| [every.ts](./every.ts) | 依次执行循环控制节点工厂(`createEveryTaskSchema`) |
| [unknown.ts](./unknown.ts) | 兜底节点模型(未知节点类型全透传) |
| [index.ts](./index.ts) | 实例化递归容器节点、聚合统一 `WorkflowTaskSchema` 并集中导出 |
## 核心节点规范详情
### HTTP 请求节点 (`http.ts`)
HTTP 动作节点用于调用外部 API 或合思原生 OpenAPI。主要字段如下:
1. **请求方法 (`method`)**:
- 严格枚举:`GET`、`POST`、`PUT`、`PATCH`、`DELETE`
- 当为 `POST`、`PUT`、`PATCH` 时显示并支持请求体;为 `GET`、`DELETE` 时不传递请求体。
2. **连接器与授权联动 (`appId` 与 `authId`)**:
- **连接器 (`appId`)**:决定 API 调用的预置鉴权通道与目标服务类型。
- 获取接口:`POST /api/easo/dsl/task-openapi/select/appId`
- 常见预置连接器代码:
- `4`: **费控原生**(`ekuaibao_app`,合思开放平台鉴权,Piper 自动换取并注入 `?accessToken=...`)
- `5`: **费控钉钉**
- `9`: **纷享销客**
- `11`: **ai应用**
- `14`: **招商银行商务卡查询**
- `15`: **费控企微**
- `16`: **开放平台**
- **授权实例 (`authId`)**:连接器具体的授权账户或凭据实例。
- 获取接口:`POST /api/easo/corpApp/getAuthList`,参数 `{ appId, size: 100 }`
- 需携带 Piper `Authorization: Bearer <jwtToken>`。
- 必须与选定的 `appId` 配对。如未配置或传错,调用合思开放平台接口时将因缺少凭证报错 `400 缺少accessToken参数`。
3. **请求体与格式 (`bodyType` / `bodyRaw` / `contentType`)**:
- `bodyType` 枚举:`none`、`raw`、`from-data`、`form-urlencoded`(默认 `raw`)
- `contentType` 枚举(当 `raw` 时):`application/json`(默认)、`text/plain`、`application/javascript`、`text/html`、`application/xml`
- `bodyRaw`:支持直接入参对象或字符串,兼容合思变量插值模板(`@{choose(...)}`)。
@@ -1,14 +1,32 @@
import { z } from "zod";
import { BaseTaskSchema } from "./common.js";
// ── HTTP 请求方法与请求体枚举 ──────────────────────────────────────────────────
export const HttpMethodSchema = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
export type HttpMethod = z.infer<typeof HttpMethodSchema>;
export const HttpBodyTypeSchema = z.enum(["none", "raw", "from-data", "form-urlencoded"]);
export type HttpBodyType = z.infer<typeof HttpBodyTypeSchema>;
export const HttpContentTypeSchema = z.enum([
"application/json",
"text/plain",
"application/javascript",
"text/html",
"application/xml",
]);
export type HttpContentType = z.infer<typeof HttpContentTypeSchema>;
// ── HTTP 请求动作节点 ─────────────────────────────────────────────────────────
export const HttpTaskSchema = BaseTaskSchema.extend({
type: z.literal("http"),
method: z.string(),
method: z.union([HttpMethodSchema, z.string()]),
url: z.string(),
bodyType: z.string().optional(),
bodyRaw: z.record(z.string(), z.any()).optional(),
bodyType: z.union([HttpBodyTypeSchema, z.string()]).optional(),
bodyRaw: z.union([z.string(), z.record(z.string(), z.any())]).optional(),
contentType: z.union([HttpContentTypeSchema, z.string()]).optional(),
header: z.array(z.any()),
params: z.array(z.object({ key: z.string(), value: z.string() })),
successCode: z.array(z.string()),