@hcmai/sdk 0.4.10 → 0.4.12
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/dist/index.d.ts +10 -0
- package/dist/index.js +51 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -247,6 +247,16 @@ interface ModelDescription {
|
|
|
247
247
|
fields: FieldMeta[];
|
|
248
248
|
actions: ActionMeta[];
|
|
249
249
|
relations: RelationMeta[];
|
|
250
|
+
/**
|
|
251
|
+
* 脚本 / CodeFlow Action 是否已并入 {@link actions}。
|
|
252
|
+
*
|
|
253
|
+
* 🔴 `false` 表示 `actions` **只有注解 action**,YAML 里声明的脚本 Action 一个都不在里面——
|
|
254
|
+
* 此时「列表里没有」不等于「这个 Action 不存在」。不允许静默降级:
|
|
255
|
+
* 降级了就必须把 {@link effectiveActionsNote} 打出来。
|
|
256
|
+
*/
|
|
257
|
+
effectiveActionsAvailable: boolean;
|
|
258
|
+
/** 降级原因;`effectiveActionsAvailable === false` 时必有值。 */
|
|
259
|
+
effectiveActionsNote?: string;
|
|
250
260
|
}
|
|
251
261
|
interface DescribeOpts {
|
|
252
262
|
verbose?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1122,7 +1122,10 @@ function normalizeActionParams(action3) {
|
|
|
1122
1122
|
}));
|
|
1123
1123
|
}
|
|
1124
1124
|
async function describe(http, model, _opts = {}) {
|
|
1125
|
-
const metaResp = await
|
|
1125
|
+
const [metaResp, effective] = await Promise.all([
|
|
1126
|
+
http.get(`/api/models/${model}/meta`),
|
|
1127
|
+
fetchEffectiveActions(http, model)
|
|
1128
|
+
]);
|
|
1126
1129
|
const meta = metaResp.data;
|
|
1127
1130
|
const fields = (meta.fields ?? []).map((f) => ({
|
|
1128
1131
|
name: f.key ?? f.name ?? "",
|
|
@@ -1150,10 +1153,55 @@ async function describe(http, model, _opts = {}) {
|
|
|
1150
1153
|
model: meta.name ?? model,
|
|
1151
1154
|
labels: meta.labels ?? {},
|
|
1152
1155
|
fields,
|
|
1153
|
-
actions,
|
|
1154
|
-
relations: meta.relations ?? []
|
|
1156
|
+
actions: mergeEffectiveActions(actions, effective),
|
|
1157
|
+
relations: meta.relations ?? [],
|
|
1158
|
+
effectiveActionsAvailable: effective.available,
|
|
1159
|
+
...effective.available ? {} : { effectiveActionsNote: effective.note }
|
|
1155
1160
|
};
|
|
1156
1161
|
}
|
|
1162
|
+
async function fetchEffectiveActions(http, model) {
|
|
1163
|
+
try {
|
|
1164
|
+
const resp = await http.get(`/api/models/${model}/actions`);
|
|
1165
|
+
const rows = resp.data?.actions;
|
|
1166
|
+
if (!Array.isArray(rows)) {
|
|
1167
|
+
return {
|
|
1168
|
+
available: false,
|
|
1169
|
+
rows: [],
|
|
1170
|
+
note: `GET /api/models/${model}/actions \u6CA1\u6709\u8FD4\u56DE actions \u6570\u7EC4\uFF0C\u811A\u672C Action \u672A\u7EB3\u5165`
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
return { available: true, rows };
|
|
1174
|
+
} catch (e) {
|
|
1175
|
+
const err = e;
|
|
1176
|
+
const status = err?.response?.status;
|
|
1177
|
+
const detail = status ? `HTTP ${status}` : err?.message ?? String(e);
|
|
1178
|
+
return {
|
|
1179
|
+
available: false,
|
|
1180
|
+
rows: [],
|
|
1181
|
+
note: `GET /api/models/${model}/actions \u4E0D\u53EF\u7528\uFF08${detail}\uFF09\uFF0C\u811A\u672C Action \u672A\u7EB3\u5165`
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
function mergeEffectiveActions(fromMeta, effective) {
|
|
1186
|
+
if (!effective.available) return fromMeta;
|
|
1187
|
+
const known = new Set(fromMeta.map((a) => a.name));
|
|
1188
|
+
const extra = [];
|
|
1189
|
+
for (const row of effective.rows) {
|
|
1190
|
+
const name = row.key ?? "";
|
|
1191
|
+
if (!name || known.has(name)) continue;
|
|
1192
|
+
known.add(name);
|
|
1193
|
+
const candidate = row.candidates?.[0];
|
|
1194
|
+
extra.push({
|
|
1195
|
+
name,
|
|
1196
|
+
label: row.label,
|
|
1197
|
+
scope: candidate?.scope,
|
|
1198
|
+
httpMethod: "POST",
|
|
1199
|
+
readOnly: row.readOnly,
|
|
1200
|
+
source: candidate?.source
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
return [...fromMeta, ...extra];
|
|
1204
|
+
}
|
|
1157
1205
|
|
|
1158
1206
|
// src/fde/fingerprint.ts
|
|
1159
1207
|
import { createHash } from "crypto";
|