@nocobase/plugin-flow-engine 2.2.0-beta.5 → 2.2.0-beta.6
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/client/index.js +1 -1
- package/dist/externalVersion.js +9 -9
- package/dist/node_modules/@ant-design/icons-svg/package.json +1 -1
- package/dist/node_modules/acorn/package.json +1 -1
- package/dist/node_modules/acorn-jsx/package.json +1 -1
- package/dist/node_modules/acorn-walk/package.json +1 -1
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/flow-surfaces/authoring-validation.js +23 -7
- package/dist/server/flow-surfaces/planning/key-registry.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/rules.js +0 -2
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.d.ts +0 -1
- package/dist/server/flow-surfaces/runjs-authoring/runtime/constants.js +11 -19
- package/dist/server/flow-surfaces/runjs-authoring/runtime/types.d.ts +0 -12
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.d.ts +0 -14
- package/dist/server/flow-surfaces/runjs-authoring/scan/index.js +1 -7
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.d.ts +0 -14
- package/dist/server/flow-surfaces/runjs-authoring/scan/source-patterns.js +18 -73
- package/dist/server/flow-surfaces/runjs-authoring/types.d.ts +1 -1
- package/dist/server/flow-surfaces/runjs-authoring/validators/index.js +9 -53
- package/dist/server/flow-surfaces/service.d.ts +18 -0
- package/dist/server/flow-surfaces/service.js +419 -66
- package/package.json +2 -2
- package/dist/server/flow-surfaces/runjs-authoring/blocked-global-stop/index.d.ts +0 -10
- package/dist/server/flow-surfaces/runjs-authoring/blocked-global-stop/index.js +0 -40
|
@@ -689,6 +689,7 @@ function assertNoFlowSurfaceIdTitleFieldSettings(value, options = {}) {
|
|
|
689
689
|
};
|
|
690
690
|
visit(value, options.basePath || []);
|
|
691
691
|
}
|
|
692
|
+
const DEFAULT_ADMIN_UI_LAYOUT_UID = "admin-layout-model";
|
|
692
693
|
class FlowSurfacesService {
|
|
693
694
|
constructor(plugin) {
|
|
694
695
|
this.plugin = plugin;
|
|
@@ -1030,6 +1031,101 @@ class FlowSurfacesService {
|
|
|
1030
1031
|
...extras
|
|
1031
1032
|
};
|
|
1032
1033
|
}
|
|
1034
|
+
hasDesktopRouteUiLayoutsRelation() {
|
|
1035
|
+
var _a, _b;
|
|
1036
|
+
try {
|
|
1037
|
+
return !!this.db.getCollection("uiLayouts") && !!((_b = (_a = this.db.getCollection("desktopRoutes")) == null ? void 0 : _a.getField) == null ? void 0 : _b.call(_a, "uiLayouts"));
|
|
1038
|
+
} catch (error) {
|
|
1039
|
+
return false;
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
normalizeDesktopRouteRelationId(routeId) {
|
|
1043
|
+
return import_lodash.default.isNil(routeId) ? void 0 : routeId;
|
|
1044
|
+
}
|
|
1045
|
+
async readDesktopRouteUiLayoutUids(routeId, transaction) {
|
|
1046
|
+
const relationRouteId = this.normalizeDesktopRouteRelationId(routeId);
|
|
1047
|
+
if (import_lodash.default.isUndefined(relationRouteId) || !this.hasDesktopRouteUiLayoutsRelation()) {
|
|
1048
|
+
return [];
|
|
1049
|
+
}
|
|
1050
|
+
const uiLayouts = await this.db.getRepository("desktopRoutes.uiLayouts", relationRouteId).find({
|
|
1051
|
+
fields: ["uid"],
|
|
1052
|
+
transaction
|
|
1053
|
+
});
|
|
1054
|
+
return import_lodash.default.uniq(
|
|
1055
|
+
uiLayouts.map((uiLayout) => {
|
|
1056
|
+
var _a;
|
|
1057
|
+
return String(((_a = uiLayout == null ? void 0 : uiLayout.get) == null ? void 0 : _a.call(uiLayout, "uid")) || (uiLayout == null ? void 0 : uiLayout.uid) || "").trim();
|
|
1058
|
+
}).filter(Boolean)
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
async resolveDefaultDesktopRouteUiLayoutUids(transaction) {
|
|
1062
|
+
if (!this.hasDesktopRouteUiLayoutsRelation()) {
|
|
1063
|
+
return [];
|
|
1064
|
+
}
|
|
1065
|
+
const defaultLayout = await this.db.getRepository("uiLayouts").findOne({
|
|
1066
|
+
filter: {
|
|
1067
|
+
uid: DEFAULT_ADMIN_UI_LAYOUT_UID,
|
|
1068
|
+
enabled: true
|
|
1069
|
+
},
|
|
1070
|
+
transaction
|
|
1071
|
+
});
|
|
1072
|
+
return defaultLayout ? [DEFAULT_ADMIN_UI_LAYOUT_UID] : [];
|
|
1073
|
+
}
|
|
1074
|
+
async resolveInheritedDesktopRouteUiLayoutUids(parentRoute, transaction) {
|
|
1075
|
+
const parentRouteId = this.readRouteField(parentRoute, "id");
|
|
1076
|
+
if (!import_lodash.default.isNil(parentRouteId)) {
|
|
1077
|
+
const parentLayoutUids = await this.readDesktopRouteUiLayoutUids(parentRouteId, transaction);
|
|
1078
|
+
if (parentLayoutUids.length) {
|
|
1079
|
+
return parentLayoutUids;
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
return this.resolveDefaultDesktopRouteUiLayoutUids(transaction);
|
|
1083
|
+
}
|
|
1084
|
+
async setDesktopRouteUiLayouts(routeId, uiLayoutUids, transaction) {
|
|
1085
|
+
const relationRouteId = this.normalizeDesktopRouteRelationId(routeId);
|
|
1086
|
+
if (import_lodash.default.isUndefined(relationRouteId) || !uiLayoutUids.length || !this.hasDesktopRouteUiLayoutsRelation()) {
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
await this.db.getRepository("desktopRoutes.uiLayouts", relationRouteId).set({
|
|
1090
|
+
tk: uiLayoutUids,
|
|
1091
|
+
transaction
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
async attachDesktopRouteUiLayoutsToRouteAndChildren(routeId, uiLayoutUids, transaction) {
|
|
1095
|
+
if (import_lodash.default.isNil(routeId) || !uiLayoutUids.length || !this.hasDesktopRouteUiLayoutsRelation()) {
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
await this.setDesktopRouteUiLayouts(routeId, uiLayoutUids, transaction);
|
|
1099
|
+
const children = await this.db.getRepository("desktopRoutes").find({
|
|
1100
|
+
fields: ["id"],
|
|
1101
|
+
filter: {
|
|
1102
|
+
parentId: routeId
|
|
1103
|
+
},
|
|
1104
|
+
transaction
|
|
1105
|
+
});
|
|
1106
|
+
for (const child of children) {
|
|
1107
|
+
await this.attachDesktopRouteUiLayoutsToRouteAndChildren(
|
|
1108
|
+
this.readRouteField(child, "id"),
|
|
1109
|
+
uiLayoutUids,
|
|
1110
|
+
transaction
|
|
1111
|
+
);
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
async ensureDesktopRouteUiLayouts(route, transaction) {
|
|
1115
|
+
const routeId = this.readRouteField(route, "id");
|
|
1116
|
+
if (import_lodash.default.isNil(routeId) || !this.hasDesktopRouteUiLayoutsRelation()) {
|
|
1117
|
+
return [];
|
|
1118
|
+
}
|
|
1119
|
+
const existingLayoutUids = await this.readDesktopRouteUiLayoutUids(routeId, transaction);
|
|
1120
|
+
if (existingLayoutUids.length) {
|
|
1121
|
+
return existingLayoutUids;
|
|
1122
|
+
}
|
|
1123
|
+
const parentRouteId = this.readRouteField(route, "parentId");
|
|
1124
|
+
const parentRoute = import_lodash.default.isNil(parentRouteId) ? null : await this.findMenuRouteById(parentRouteId, transaction);
|
|
1125
|
+
const inheritedLayoutUids = await this.resolveInheritedDesktopRouteUiLayoutUids(parentRoute, transaction);
|
|
1126
|
+
await this.setDesktopRouteUiLayouts(routeId, inheritedLayoutUids, transaction);
|
|
1127
|
+
return inheritedLayoutUids;
|
|
1128
|
+
}
|
|
1033
1129
|
isValidMenuIconName(value) {
|
|
1034
1130
|
const normalized = String(value || "").trim();
|
|
1035
1131
|
return !!normalized && ANT_DESIGN_ICON_NAMES.has(normalized);
|
|
@@ -1111,7 +1207,7 @@ class FlowSurfacesService {
|
|
|
1111
1207
|
this.assertVisibleNavigationIcon("createMenu", "values", values);
|
|
1112
1208
|
const schemaUid = values.schemaUid || (0, import_utils.uid)();
|
|
1113
1209
|
const desktopRoutes = this.db.getRepository("desktopRoutes");
|
|
1114
|
-
await desktopRoutes.create({
|
|
1210
|
+
const route = await desktopRoutes.create({
|
|
1115
1211
|
values: {
|
|
1116
1212
|
type: "group",
|
|
1117
1213
|
sort: this.allocateRouteSortValue(),
|
|
@@ -1124,10 +1220,11 @@ class FlowSurfacesService {
|
|
|
1124
1220
|
},
|
|
1125
1221
|
transaction
|
|
1126
1222
|
});
|
|
1127
|
-
|
|
1128
|
-
|
|
1223
|
+
await this.attachDesktopRouteUiLayoutsToRouteAndChildren(
|
|
1224
|
+
this.readRouteField(route, "id"),
|
|
1225
|
+
await this.resolveInheritedDesktopRouteUiLayoutUids(parentRoute, transaction),
|
|
1129
1226
|
transaction
|
|
1130
|
-
|
|
1227
|
+
);
|
|
1131
1228
|
return this.buildMenuResult(route);
|
|
1132
1229
|
}
|
|
1133
1230
|
async createFlowMenuItem(values, transaction) {
|
|
@@ -1142,7 +1239,7 @@ class FlowSurfacesService {
|
|
|
1142
1239
|
const title = values.title || pageSchemaUid;
|
|
1143
1240
|
const tabTitle = values.tabTitle || "Untitled";
|
|
1144
1241
|
const desktopRoutes = this.db.getRepository("desktopRoutes");
|
|
1145
|
-
await desktopRoutes.create({
|
|
1242
|
+
const createdRoute = await desktopRoutes.create({
|
|
1146
1243
|
values: {
|
|
1147
1244
|
type: "flowPage",
|
|
1148
1245
|
sort: this.allocateRouteSortValue(),
|
|
@@ -1177,6 +1274,11 @@ class FlowSurfacesService {
|
|
|
1177
1274
|
},
|
|
1178
1275
|
transaction
|
|
1179
1276
|
});
|
|
1277
|
+
await this.attachDesktopRouteUiLayoutsToRouteAndChildren(
|
|
1278
|
+
this.readRouteField(createdRoute, "id"),
|
|
1279
|
+
await this.resolveInheritedDesktopRouteUiLayoutUids(parentRoute, transaction),
|
|
1280
|
+
transaction
|
|
1281
|
+
);
|
|
1180
1282
|
const route = await desktopRoutes.findOne({
|
|
1181
1283
|
filter: { schemaUid: pageSchemaUid },
|
|
1182
1284
|
appends: ["children"],
|
|
@@ -5879,7 +5981,7 @@ class FlowSurfacesService {
|
|
|
5879
5981
|
(0, import_errors.throwBadRequest)("flowSurfaces updateMenu requires menuRouteId");
|
|
5880
5982
|
}
|
|
5881
5983
|
const route = await this.assertMenuRouteUpdatable(menuRouteId, options.transaction);
|
|
5882
|
-
await this.assertMenuParentIsGroup(values.parentMenuRouteId, options.transaction);
|
|
5984
|
+
const nextParentRoute = await this.assertMenuParentIsGroup(values.parentMenuRouteId, options.transaction);
|
|
5883
5985
|
await this.assertMenuParentNotSelfOrDescendant(route, values.parentMenuRouteId, options.transaction);
|
|
5884
5986
|
const nextOptions = { ...this.readRouteOptions(route) };
|
|
5885
5987
|
const updateValues = {};
|
|
@@ -5910,6 +6012,13 @@ class FlowSurfacesService {
|
|
|
5910
6012
|
});
|
|
5911
6013
|
}
|
|
5912
6014
|
const updated = await this.findMenuRouteById(menuRouteId, options.transaction);
|
|
6015
|
+
if (updated && Object.prototype.hasOwnProperty.call(values, "parentMenuRouteId")) {
|
|
6016
|
+
await this.attachDesktopRouteUiLayoutsToRouteAndChildren(
|
|
6017
|
+
this.readRouteField(updated, "id"),
|
|
6018
|
+
await this.resolveInheritedDesktopRouteUiLayoutUids(nextParentRoute, options.transaction),
|
|
6019
|
+
options.transaction
|
|
6020
|
+
);
|
|
6021
|
+
}
|
|
5913
6022
|
return this.buildMenuResult(updated);
|
|
5914
6023
|
}
|
|
5915
6024
|
async initializeFlowPageForRoute(route, values, transaction) {
|
|
@@ -5917,6 +6026,7 @@ class FlowSurfacesService {
|
|
|
5917
6026
|
const pageSchemaUid = this.readRouteField(route, "schemaUid");
|
|
5918
6027
|
const structure = await this.loadRouteBackedPageStructure(route, transaction);
|
|
5919
6028
|
let tabRoute = structure.tabRoutes[0];
|
|
6029
|
+
const routeUiLayoutUids = await this.ensureDesktopRouteUiLayouts(route, transaction);
|
|
5920
6030
|
const routeOptions = this.readRouteOptions(route);
|
|
5921
6031
|
if (!routeOptions[FLOW_SURFACE_MENU_BINDABLE_OPTION_KEY]) {
|
|
5922
6032
|
(0, import_errors.throwBadRequest)(`flowSurfaces createPage only accepts a bindable menu route created by createMenu(type="item")`);
|
|
@@ -5938,7 +6048,7 @@ class FlowSurfacesService {
|
|
|
5938
6048
|
const tabSchemaUid2 = values.tabSchemaUid || (0, import_utils.uid)();
|
|
5939
6049
|
const tabSchemaName2 = values.tabSchemaName || (0, import_utils.uid)();
|
|
5940
6050
|
const tabTitle = values.tabTitle || "Untitled";
|
|
5941
|
-
await this.db.getRepository("desktopRoutes").create({
|
|
6051
|
+
tabRoute = await this.db.getRepository("desktopRoutes").create({
|
|
5942
6052
|
values: {
|
|
5943
6053
|
type: "tabs",
|
|
5944
6054
|
sort: this.allocateRouteSortValue(1),
|
|
@@ -5955,10 +6065,7 @@ class FlowSurfacesService {
|
|
|
5955
6065
|
},
|
|
5956
6066
|
transaction
|
|
5957
6067
|
});
|
|
5958
|
-
|
|
5959
|
-
filter: { schemaUid: tabSchemaUid2 },
|
|
5960
|
-
transaction
|
|
5961
|
-
});
|
|
6068
|
+
await this.setDesktopRouteUiLayouts(this.readRouteField(tabRoute, "id"), routeUiLayoutUids, transaction);
|
|
5962
6069
|
} else {
|
|
5963
6070
|
await this.db.getRepository("desktopRoutes").update({
|
|
5964
6071
|
filterByTk: String(this.readRouteField(tabRoute, "id")),
|
|
@@ -5982,6 +6089,9 @@ class FlowSurfacesService {
|
|
|
5982
6089
|
transaction
|
|
5983
6090
|
});
|
|
5984
6091
|
}
|
|
6092
|
+
if (tabRoute) {
|
|
6093
|
+
await this.setDesktopRouteUiLayouts(this.readRouteField(tabRoute, "id"), routeUiLayoutUids, transaction);
|
|
6094
|
+
}
|
|
5985
6095
|
await this.ensureFlowRoutePageSchemaShell(pageSchemaUid, transaction);
|
|
5986
6096
|
await this.db.getRepository("desktopRoutes").update({
|
|
5987
6097
|
filterByTk: String(routeId),
|
|
@@ -6121,6 +6231,11 @@ class FlowSurfacesService {
|
|
|
6121
6231
|
},
|
|
6122
6232
|
transaction: options.transaction
|
|
6123
6233
|
});
|
|
6234
|
+
await this.setDesktopRouteUiLayouts(
|
|
6235
|
+
route.get("id"),
|
|
6236
|
+
await this.ensureDesktopRouteUiLayouts(pageRoute, options.transaction),
|
|
6237
|
+
options.transaction
|
|
6238
|
+
);
|
|
6124
6239
|
const gridUid = await this.ensureGridChild(tabSchemaUid, "BlockGridModel", options.transaction);
|
|
6125
6240
|
const result = {
|
|
6126
6241
|
pageUid: pageTarget.uid,
|
|
@@ -11524,6 +11639,7 @@ class FlowSurfacesService {
|
|
|
11524
11639
|
}
|
|
11525
11640
|
if (this.isAIEmployeeActionUse(current == null ? void 0 : current.use) && this.hasAIEmployeePublicSettings(normalizedValues)) {
|
|
11526
11641
|
const enabledPackages = await this.resolveEnabledPluginPackages(options);
|
|
11642
|
+
const hasRawAIEmployeeStepTasks = import_lodash.default.has(normalizedValues, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH]);
|
|
11527
11643
|
const aiEmployeeSettingsPayload = await this.normalizeAIEmployeeActionPublicSettings(
|
|
11528
11644
|
"updateSettings",
|
|
11529
11645
|
import_lodash.default.pick(normalizedValues, AI_EMPLOYEE_PUBLIC_SETTING_KEYS),
|
|
@@ -11536,7 +11652,8 @@ class FlowSurfacesService {
|
|
|
11536
11652
|
promptContext: {
|
|
11537
11653
|
kind: "target",
|
|
11538
11654
|
targetUid: (current == null ? void 0 : current.uid) || writeTarget.uid
|
|
11539
|
-
}
|
|
11655
|
+
},
|
|
11656
|
+
skipExistingTaskWorkContextRebase: hasRawAIEmployeeStepTasks
|
|
11540
11657
|
}
|
|
11541
11658
|
);
|
|
11542
11659
|
AI_EMPLOYEE_PUBLIC_SETTING_KEYS.forEach((key) => {
|
|
@@ -11670,6 +11787,12 @@ class FlowSurfacesService {
|
|
|
11670
11787
|
if (Object.keys(nextPayload).length === 1) {
|
|
11671
11788
|
return { uid: current.uid };
|
|
11672
11789
|
}
|
|
11790
|
+
await this.assertNoDuplicateAIEmployeeActionForUpdateSettings(
|
|
11791
|
+
options.openViewActionName || "updateSettings",
|
|
11792
|
+
current,
|
|
11793
|
+
effectiveNode,
|
|
11794
|
+
options.transaction
|
|
11795
|
+
);
|
|
11673
11796
|
if (target.kind === "tab" && target.tabRoute) {
|
|
11674
11797
|
await this.routeSync.persistTabSettings(target, current, nextPayload, options.transaction);
|
|
11675
11798
|
return {
|
|
@@ -17709,19 +17832,21 @@ class FlowSurfacesService {
|
|
|
17709
17832
|
}
|
|
17710
17833
|
return JSON.stringify(value);
|
|
17711
17834
|
}
|
|
17712
|
-
buildAIEmployeeActionDedupIdentity(values) {
|
|
17835
|
+
buildAIEmployeeActionDedupIdentity(values, defaultActionWorkContext) {
|
|
17713
17836
|
var _a, _b, _c, _d, _e, _f;
|
|
17714
17837
|
const username = String(((_b = (_a = values == null ? void 0 : values.props) == null ? void 0 : _a.aiEmployee) == null ? void 0 : _b.username) || "").trim();
|
|
17715
17838
|
if (!username) {
|
|
17716
17839
|
return "";
|
|
17717
17840
|
}
|
|
17841
|
+
const workContext = this.normalizeAIEmployeeActionWorkContextForDedupIdentity(
|
|
17842
|
+
(_d = (_c = values == null ? void 0 : values.props) == null ? void 0 : _c.context) == null ? void 0 : _d.workContext,
|
|
17843
|
+
defaultActionWorkContext
|
|
17844
|
+
);
|
|
17718
17845
|
return this.stableSerializeAIEmployeeValue({
|
|
17719
17846
|
username,
|
|
17720
|
-
auto: typeof ((
|
|
17721
|
-
workContext
|
|
17722
|
-
tasks: this.normalizeAIEmployeeTasksForDedupIdentity(
|
|
17723
|
-
import_lodash.default.get(values, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH])
|
|
17724
|
-
),
|
|
17847
|
+
auto: typeof ((_e = values == null ? void 0 : values.props) == null ? void 0 : _e.auto) === "boolean" ? values.props.auto : false,
|
|
17848
|
+
workContext,
|
|
17849
|
+
tasks: this.normalizeAIEmployeeTasksForDedupIdentity(this.readAIEmployeePersistedTasks(values), workContext),
|
|
17725
17850
|
style: {
|
|
17726
17851
|
...AI_EMPLOYEE_DEFAULT_STYLE,
|
|
17727
17852
|
...import_lodash.default.isPlainObject((_f = values == null ? void 0 : values.props) == null ? void 0 : _f.style) ? import_lodash.default.pick(values.props.style, AI_EMPLOYEE_STYLE_PUBLIC_KEYS) : {}
|
|
@@ -17729,11 +17854,35 @@ class FlowSurfacesService {
|
|
|
17729
17854
|
});
|
|
17730
17855
|
}
|
|
17731
17856
|
normalizeAIEmployeeWorkContextForDedupIdentity(value) {
|
|
17732
|
-
return import_lodash.default.castArray(value || []).map(
|
|
17733
|
-
(
|
|
17734
|
-
|
|
17857
|
+
return import_lodash.default.castArray(value || []).map((item) => {
|
|
17858
|
+
if (!import_lodash.default.isPlainObject(item)) {
|
|
17859
|
+
return item;
|
|
17860
|
+
}
|
|
17861
|
+
const output = import_lodash.default.pick(item, AI_EMPLOYEE_WORK_CONTEXT_PUBLIC_KEYS);
|
|
17862
|
+
if (!Object.prototype.hasOwnProperty.call(output, "type") || import_lodash.default.isUndefined(output.type) || output.type === null) {
|
|
17863
|
+
output.type = "flow-model";
|
|
17864
|
+
}
|
|
17865
|
+
return output;
|
|
17866
|
+
});
|
|
17867
|
+
}
|
|
17868
|
+
normalizeAIEmployeeActionWorkContextForDedupIdentity(value, defaultWorkContext) {
|
|
17869
|
+
if (!Array.isArray(value)) {
|
|
17870
|
+
return import_lodash.default.cloneDeep(defaultWorkContext || []);
|
|
17871
|
+
}
|
|
17872
|
+
return this.normalizeAIEmployeeWorkContextForDedupIdentity(value);
|
|
17735
17873
|
}
|
|
17736
|
-
|
|
17874
|
+
normalizeAIEmployeeDefaultActionWorkContextForSelfUid(selfUid) {
|
|
17875
|
+
const uid2 = String(selfUid || "").trim();
|
|
17876
|
+
return uid2 ? [{ type: "flow-model", uid: uid2 }] : [];
|
|
17877
|
+
}
|
|
17878
|
+
normalizeAIEmployeeTaskWorkContextForDedupIdentity(value, defaultWorkContext) {
|
|
17879
|
+
const normalized = this.normalizeAIEmployeeWorkContextForDedupIdentity(value);
|
|
17880
|
+
if (Array.isArray(defaultWorkContext) && !normalized.length) {
|
|
17881
|
+
return import_lodash.default.cloneDeep(defaultWorkContext);
|
|
17882
|
+
}
|
|
17883
|
+
return normalized;
|
|
17884
|
+
}
|
|
17885
|
+
normalizeAIEmployeeTasksForDedupIdentity(value, defaultWorkContext) {
|
|
17737
17886
|
return import_lodash.default.castArray(value || []).map((task) => {
|
|
17738
17887
|
if (!import_lodash.default.isPlainObject(task)) {
|
|
17739
17888
|
return task;
|
|
@@ -17742,9 +17891,19 @@ class FlowSurfacesService {
|
|
|
17742
17891
|
if (import_lodash.default.isPlainObject(output.message)) {
|
|
17743
17892
|
output.message = import_lodash.default.pick(output.message, AI_EMPLOYEE_TASK_MESSAGE_PUBLIC_KEYS);
|
|
17744
17893
|
if (Object.prototype.hasOwnProperty.call(output.message, "workContext")) {
|
|
17745
|
-
output.message.workContext = this.
|
|
17894
|
+
output.message.workContext = this.normalizeAIEmployeeTaskWorkContextForDedupIdentity(
|
|
17895
|
+
output.message.workContext,
|
|
17896
|
+
defaultWorkContext
|
|
17897
|
+
);
|
|
17746
17898
|
}
|
|
17747
17899
|
}
|
|
17900
|
+
if (!import_lodash.default.isPlainObject(output.message) && Array.isArray(defaultWorkContext)) {
|
|
17901
|
+
output.message = {
|
|
17902
|
+
workContext: import_lodash.default.cloneDeep(defaultWorkContext)
|
|
17903
|
+
};
|
|
17904
|
+
} else if (import_lodash.default.isPlainObject(output.message) && !Object.prototype.hasOwnProperty.call(output.message, "workContext")) {
|
|
17905
|
+
output.message.workContext = import_lodash.default.cloneDeep(defaultWorkContext || []);
|
|
17906
|
+
}
|
|
17748
17907
|
if (import_lodash.default.isPlainObject(output.model)) {
|
|
17749
17908
|
output.model = import_lodash.default.pick(output.model, AI_EMPLOYEE_TASK_MODEL_PUBLIC_KEYS);
|
|
17750
17909
|
}
|
|
@@ -17754,25 +17913,38 @@ class FlowSurfacesService {
|
|
|
17754
17913
|
return output;
|
|
17755
17914
|
});
|
|
17756
17915
|
}
|
|
17757
|
-
async assertNoDuplicateAIEmployeeAction(actionName, parentUid, values, transaction) {
|
|
17916
|
+
async assertNoDuplicateAIEmployeeAction(actionName, parentUid, values, transaction, excludeUid) {
|
|
17758
17917
|
var _a;
|
|
17759
|
-
const identity = this.buildAIEmployeeActionDedupIdentity(values);
|
|
17760
|
-
if (!identity) {
|
|
17761
|
-
return;
|
|
17762
|
-
}
|
|
17763
17918
|
const parentNode = await this.repository.findModelById(parentUid, {
|
|
17764
17919
|
transaction,
|
|
17765
17920
|
includeAsyncNode: true
|
|
17766
17921
|
});
|
|
17767
|
-
const
|
|
17922
|
+
const defaultActionWorkContext = this.normalizeAIEmployeeDefaultActionWorkContextForSelfUid(
|
|
17923
|
+
await this.resolveAIEmployeeActionSelfUidFromParentNode(parentNode, transaction)
|
|
17924
|
+
);
|
|
17925
|
+
const identity = this.buildAIEmployeeActionDedupIdentity(values, defaultActionWorkContext);
|
|
17926
|
+
if (!identity) {
|
|
17927
|
+
return;
|
|
17928
|
+
}
|
|
17929
|
+
let duplicate;
|
|
17930
|
+
for (const action of import_lodash.default.castArray(((_a = parentNode == null ? void 0 : parentNode.subModels) == null ? void 0 : _a.actions) || [])) {
|
|
17768
17931
|
if (!this.isAIEmployeeActionUse(action == null ? void 0 : action.use)) {
|
|
17769
|
-
|
|
17932
|
+
continue;
|
|
17770
17933
|
}
|
|
17771
|
-
|
|
17772
|
-
|
|
17773
|
-
|
|
17774
|
-
|
|
17775
|
-
|
|
17934
|
+
if (excludeUid && String((action == null ? void 0 : action.uid) || "") === excludeUid) {
|
|
17935
|
+
continue;
|
|
17936
|
+
}
|
|
17937
|
+
if (this.buildAIEmployeeActionDedupIdentity(
|
|
17938
|
+
{
|
|
17939
|
+
props: action.props,
|
|
17940
|
+
stepParams: action.stepParams
|
|
17941
|
+
},
|
|
17942
|
+
defaultActionWorkContext
|
|
17943
|
+
) === identity) {
|
|
17944
|
+
duplicate = action;
|
|
17945
|
+
break;
|
|
17946
|
+
}
|
|
17947
|
+
}
|
|
17776
17948
|
if (!(duplicate == null ? void 0 : duplicate.uid)) {
|
|
17777
17949
|
return;
|
|
17778
17950
|
}
|
|
@@ -17787,6 +17959,25 @@ class FlowSurfacesService {
|
|
|
17787
17959
|
}
|
|
17788
17960
|
);
|
|
17789
17961
|
}
|
|
17962
|
+
async assertNoDuplicateAIEmployeeActionForUpdateSettings(actionName, current, effectiveNode, transaction) {
|
|
17963
|
+
if (!this.isAIEmployeeActionUse(current == null ? void 0 : current.use)) {
|
|
17964
|
+
return;
|
|
17965
|
+
}
|
|
17966
|
+
const parentUid = String((current == null ? void 0 : current.parentId) || "").trim() || ((current == null ? void 0 : current.uid) ? await this.locator.findParentUid(current.uid, transaction).catch(() => "") : "");
|
|
17967
|
+
if (!parentUid) {
|
|
17968
|
+
return;
|
|
17969
|
+
}
|
|
17970
|
+
await this.assertNoDuplicateAIEmployeeAction(
|
|
17971
|
+
actionName,
|
|
17972
|
+
parentUid,
|
|
17973
|
+
{
|
|
17974
|
+
props: effectiveNode == null ? void 0 : effectiveNode.props,
|
|
17975
|
+
stepParams: effectiveNode == null ? void 0 : effectiveNode.stepParams
|
|
17976
|
+
},
|
|
17977
|
+
transaction,
|
|
17978
|
+
String((current == null ? void 0 : current.uid) || "")
|
|
17979
|
+
);
|
|
17980
|
+
}
|
|
17790
17981
|
hasAIEmployeePublicSettings(settings) {
|
|
17791
17982
|
return import_lodash.default.isPlainObject(settings) && AI_EMPLOYEE_PUBLIC_SETTING_KEYS.some((key) => Object.prototype.hasOwnProperty.call(settings, key));
|
|
17792
17983
|
}
|
|
@@ -17841,11 +18032,24 @@ class FlowSurfacesService {
|
|
|
17841
18032
|
var _a;
|
|
17842
18033
|
const stepTasks = import_lodash.default.get(current, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH]);
|
|
17843
18034
|
if (Array.isArray(stepTasks)) {
|
|
17844
|
-
return stepTasks;
|
|
18035
|
+
return this.normalizeAIEmployeeLegacyInheritedTaskWorkContext(stepTasks);
|
|
17845
18036
|
}
|
|
17846
|
-
const legacyPropsTasks = (_a = current == null ? void 0 : current.props) == null ? void 0 : _a.tasks;
|
|
18037
|
+
const legacyPropsTasks = this.normalizeAIEmployeeLegacyInheritedTaskWorkContext((_a = current == null ? void 0 : current.props) == null ? void 0 : _a.tasks);
|
|
17847
18038
|
return Array.isArray(legacyPropsTasks) ? legacyPropsTasks : [];
|
|
17848
18039
|
}
|
|
18040
|
+
normalizeAIEmployeeLegacyInheritedTaskWorkContext(tasks) {
|
|
18041
|
+
if (!Array.isArray(tasks)) {
|
|
18042
|
+
return tasks;
|
|
18043
|
+
}
|
|
18044
|
+
return tasks.map((task) => {
|
|
18045
|
+
if (!import_lodash.default.isPlainObject(task) || !import_lodash.default.isPlainObject(task.message) || task.message.workContext !== null) {
|
|
18046
|
+
return task;
|
|
18047
|
+
}
|
|
18048
|
+
const nextTask = import_lodash.default.cloneDeep(task);
|
|
18049
|
+
delete nextTask.message.workContext;
|
|
18050
|
+
return nextTask;
|
|
18051
|
+
});
|
|
18052
|
+
}
|
|
17849
18053
|
buildAIEmployeeTaskStepParams(tasks) {
|
|
17850
18054
|
const stepParams = {};
|
|
17851
18055
|
import_lodash.default.set(stepParams, AI_EMPLOYEE_TASK_STEP_PARAMS_PATH, import_lodash.default.cloneDeep(tasks));
|
|
@@ -17874,7 +18078,7 @@ class FlowSurfacesService {
|
|
|
17874
18078
|
if (!this.isAIEmployeeActionUse(current == null ? void 0 : current.use)) {
|
|
17875
18079
|
return;
|
|
17876
18080
|
}
|
|
17877
|
-
const legacyPropsTasks = (_a = current == null ? void 0 : current.props) == null ? void 0 : _a.tasks;
|
|
18081
|
+
const legacyPropsTasks = this.normalizeAIEmployeeLegacyInheritedTaskWorkContext((_a = current == null ? void 0 : current.props) == null ? void 0 : _a.tasks);
|
|
17878
18082
|
const hasLegacyPropsTasks = Array.isArray(legacyPropsTasks);
|
|
17879
18083
|
const hasNextStepTasks = import_lodash.default.has(nextPayload, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH]);
|
|
17880
18084
|
const currentStepTasks = import_lodash.default.get(current, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH]);
|
|
@@ -18046,6 +18250,20 @@ class FlowSurfacesService {
|
|
|
18046
18250
|
};
|
|
18047
18251
|
});
|
|
18048
18252
|
}
|
|
18253
|
+
normalizeAIEmployeeEffectiveActionWorkContext(actionName, settings, currentProps, options) {
|
|
18254
|
+
var _a;
|
|
18255
|
+
const hasSettingsWorkContext = Object.prototype.hasOwnProperty.call(settings, "workContext");
|
|
18256
|
+
const currentWorkContext = (_a = currentProps == null ? void 0 : currentProps.context) == null ? void 0 : _a.workContext;
|
|
18257
|
+
if (!hasSettingsWorkContext && !Array.isArray(currentWorkContext) && !options.requireUsername && !options.selfUid) {
|
|
18258
|
+
return void 0;
|
|
18259
|
+
}
|
|
18260
|
+
const rawWorkContext = hasSettingsWorkContext ? settings.workContext : Array.isArray(currentWorkContext) ? currentWorkContext : [{ type: "flow-model", target: "self" }];
|
|
18261
|
+
return this.normalizeAIEmployeeWorkContext(actionName, rawWorkContext, {
|
|
18262
|
+
selfUid: options.selfUid,
|
|
18263
|
+
keyMap: options.keyMap,
|
|
18264
|
+
path: "settings.workContext"
|
|
18265
|
+
});
|
|
18266
|
+
}
|
|
18049
18267
|
normalizeAIEmployeeTaskModel(actionName, path, value) {
|
|
18050
18268
|
if (import_lodash.default.isUndefined(value) || value === null) {
|
|
18051
18269
|
return value;
|
|
@@ -18361,6 +18579,7 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18361
18579
|
);
|
|
18362
18580
|
}
|
|
18363
18581
|
async normalizeAIEmployeeStepParamTasksForUpdateSettings(current, nextPayload, writeTarget, options) {
|
|
18582
|
+
var _a, _b, _c, _d;
|
|
18364
18583
|
if (!this.isAIEmployeeActionUse(current == null ? void 0 : current.use) || !import_lodash.default.has(nextPayload, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH])) {
|
|
18365
18584
|
return;
|
|
18366
18585
|
}
|
|
@@ -18369,15 +18588,63 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18369
18588
|
return;
|
|
18370
18589
|
}
|
|
18371
18590
|
const actionName = options.openViewActionName || "updateSettings";
|
|
18372
|
-
const
|
|
18591
|
+
const selfUid = await this.resolveAIEmployeeActionSelfUid(current || { uid: writeTarget.uid }, options.transaction);
|
|
18592
|
+
const currentPropsForDefault = import_lodash.default.mergeWith(
|
|
18593
|
+
{},
|
|
18594
|
+
import_lodash.default.isPlainObject(current == null ? void 0 : current.props) ? current.props : {},
|
|
18595
|
+
import_lodash.default.isPlainObject(nextPayload.props) ? nextPayload.props : {},
|
|
18596
|
+
(_currentValue, nextValue) => {
|
|
18597
|
+
if (Array.isArray(nextValue)) {
|
|
18598
|
+
return import_lodash.default.cloneDeep(nextValue);
|
|
18599
|
+
}
|
|
18600
|
+
return void 0;
|
|
18601
|
+
}
|
|
18602
|
+
);
|
|
18603
|
+
const defaultWorkContext = this.normalizeAIEmployeeEffectiveActionWorkContext(
|
|
18373
18604
|
actionName,
|
|
18374
|
-
|
|
18375
|
-
|
|
18605
|
+
{},
|
|
18606
|
+
currentPropsForDefault,
|
|
18376
18607
|
{
|
|
18377
|
-
selfUid
|
|
18378
|
-
|
|
18608
|
+
selfUid,
|
|
18609
|
+
requireUsername: true
|
|
18379
18610
|
}
|
|
18380
18611
|
);
|
|
18612
|
+
const currentTasks = this.readAIEmployeePersistedTasks(current);
|
|
18613
|
+
const previousActionWorkContext = this.normalizeAIEmployeeActionWorkContextForDedupIdentity(
|
|
18614
|
+
(_b = (_a = current == null ? void 0 : current.props) == null ? void 0 : _a.context) == null ? void 0 : _b.workContext,
|
|
18615
|
+
this.normalizeAIEmployeeDefaultActionWorkContextForSelfUid(selfUid)
|
|
18616
|
+
);
|
|
18617
|
+
const nextActionWorkContext = this.normalizeAIEmployeeActionWorkContextForDedupIdentity(
|
|
18618
|
+
(_c = currentPropsForDefault == null ? void 0 : currentPropsForDefault.context) == null ? void 0 : _c.workContext,
|
|
18619
|
+
defaultWorkContext
|
|
18620
|
+
);
|
|
18621
|
+
if (Array.isArray(defaultWorkContext) && !import_lodash.default.isEqual((_d = currentPropsForDefault == null ? void 0 : currentPropsForDefault.context) == null ? void 0 : _d.workContext, defaultWorkContext)) {
|
|
18622
|
+
nextPayload.props = import_lodash.default.mergeWith(
|
|
18623
|
+
{},
|
|
18624
|
+
currentPropsForDefault,
|
|
18625
|
+
{
|
|
18626
|
+
context: {
|
|
18627
|
+
workContext: import_lodash.default.cloneDeep(defaultWorkContext)
|
|
18628
|
+
}
|
|
18629
|
+
},
|
|
18630
|
+
(_currentValue, nextValue) => {
|
|
18631
|
+
if (Array.isArray(nextValue)) {
|
|
18632
|
+
return import_lodash.default.cloneDeep(nextValue);
|
|
18633
|
+
}
|
|
18634
|
+
return void 0;
|
|
18635
|
+
}
|
|
18636
|
+
);
|
|
18637
|
+
}
|
|
18638
|
+
const currentTasksForNormalization = this.rebaseAIEmployeeInheritedTaskWorkContext(
|
|
18639
|
+
currentTasks,
|
|
18640
|
+
previousActionWorkContext,
|
|
18641
|
+
nextActionWorkContext
|
|
18642
|
+
);
|
|
18643
|
+
const normalizedTasks = this.normalizeAIEmployeeTasks(actionName, tasks, currentTasksForNormalization, {
|
|
18644
|
+
selfUid,
|
|
18645
|
+
defaultWorkContext,
|
|
18646
|
+
path: "stepParams.shortcutSettings.editTasks.tasks"
|
|
18647
|
+
});
|
|
18381
18648
|
import_lodash.default.set(nextPayload, ["stepParams", ...AI_EMPLOYEE_TASK_STEP_PARAMS_PATH], normalizedTasks);
|
|
18382
18649
|
}
|
|
18383
18650
|
normalizeAIEmployeeTaskMessage(actionName, path, value, existing, options) {
|
|
@@ -18406,13 +18673,18 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18406
18673
|
if (Object.prototype.hasOwnProperty.call(nextMessage, "user") && typeof nextMessage.user !== "string") {
|
|
18407
18674
|
(0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} ${path}.user must be a string`);
|
|
18408
18675
|
}
|
|
18409
|
-
if (
|
|
18676
|
+
if (value.workContext === null) {
|
|
18677
|
+
delete nextMessage.workContext;
|
|
18678
|
+
} else if (Object.prototype.hasOwnProperty.call(value, "workContext")) {
|
|
18410
18679
|
nextMessage.workContext = this.normalizeAIEmployeeWorkContext(actionName, value.workContext, {
|
|
18411
18680
|
selfUid: options.selfUid,
|
|
18412
18681
|
keyMap: options.keyMap,
|
|
18413
18682
|
path: `${path}.workContext`
|
|
18414
18683
|
});
|
|
18415
18684
|
}
|
|
18685
|
+
if (!Object.prototype.hasOwnProperty.call(nextMessage, "workContext") && this.shouldMaterializeAIEmployeeTaskDefaultWorkContext(options.defaultWorkContext)) {
|
|
18686
|
+
nextMessage.workContext = import_lodash.default.cloneDeep(options.defaultWorkContext);
|
|
18687
|
+
}
|
|
18416
18688
|
return nextMessage;
|
|
18417
18689
|
}
|
|
18418
18690
|
normalizeAIEmployeeTaskPatch(actionName, patch, existing, options) {
|
|
@@ -18436,7 +18708,8 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18436
18708
|
if (key === "message") {
|
|
18437
18709
|
next.message = this.normalizeAIEmployeeTaskMessage(actionName, `${options.path}.message`, value, next.message, {
|
|
18438
18710
|
selfUid: options.selfUid,
|
|
18439
|
-
keyMap: options.keyMap
|
|
18711
|
+
keyMap: options.keyMap,
|
|
18712
|
+
defaultWorkContext: options.defaultWorkContext
|
|
18440
18713
|
});
|
|
18441
18714
|
return;
|
|
18442
18715
|
}
|
|
@@ -18486,6 +18759,9 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18486
18759
|
if (!import_lodash.default.isPlainObject(next.message)) {
|
|
18487
18760
|
next.message = {};
|
|
18488
18761
|
}
|
|
18762
|
+
if (!Object.prototype.hasOwnProperty.call(next.message, "workContext") && this.shouldMaterializeAIEmployeeTaskDefaultWorkContext(options.defaultWorkContext)) {
|
|
18763
|
+
next.message.workContext = import_lodash.default.cloneDeep(options.defaultWorkContext);
|
|
18764
|
+
}
|
|
18489
18765
|
if (import_lodash.default.isPlainObject(next.skillSettings)) {
|
|
18490
18766
|
if (Array.isArray(next.skillSettings.skills) && !Object.prototype.hasOwnProperty.call(next.skillSettings, "skillsVersion")) {
|
|
18491
18767
|
next.skillSettings.skillsVersion = 2;
|
|
@@ -18512,10 +18788,52 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18512
18788
|
nextTasks[index] = this.normalizeAIEmployeeTaskPatch(actionName, task, existingTasks[index], {
|
|
18513
18789
|
selfUid: options.selfUid,
|
|
18514
18790
|
keyMap: options.keyMap,
|
|
18515
|
-
path: `${options.path}[${index}]
|
|
18791
|
+
path: `${options.path}[${index}]`,
|
|
18792
|
+
defaultWorkContext: options.defaultWorkContext
|
|
18516
18793
|
});
|
|
18517
18794
|
});
|
|
18518
|
-
return nextTasks;
|
|
18795
|
+
return this.withAIEmployeeTaskDefaultWorkContext(nextTasks, options.defaultWorkContext);
|
|
18796
|
+
}
|
|
18797
|
+
withAIEmployeeTaskDefaultWorkContext(tasks, defaultWorkContext) {
|
|
18798
|
+
const nextTasks = Array.isArray(tasks) ? import_lodash.default.cloneDeep(tasks) : [];
|
|
18799
|
+
if (!this.shouldMaterializeAIEmployeeTaskDefaultWorkContext(defaultWorkContext)) {
|
|
18800
|
+
return nextTasks;
|
|
18801
|
+
}
|
|
18802
|
+
return nextTasks.map((task) => {
|
|
18803
|
+
if (!import_lodash.default.isPlainObject(task)) {
|
|
18804
|
+
return task;
|
|
18805
|
+
}
|
|
18806
|
+
const nextTask = import_lodash.default.cloneDeep(task);
|
|
18807
|
+
if (!import_lodash.default.isPlainObject(nextTask.message)) {
|
|
18808
|
+
nextTask.message = {
|
|
18809
|
+
workContext: import_lodash.default.cloneDeep(defaultWorkContext)
|
|
18810
|
+
};
|
|
18811
|
+
} else if (!Object.prototype.hasOwnProperty.call(nextTask.message, "workContext")) {
|
|
18812
|
+
nextTask.message.workContext = import_lodash.default.cloneDeep(defaultWorkContext);
|
|
18813
|
+
}
|
|
18814
|
+
return nextTask;
|
|
18815
|
+
});
|
|
18816
|
+
}
|
|
18817
|
+
shouldMaterializeAIEmployeeTaskDefaultWorkContext(defaultWorkContext) {
|
|
18818
|
+
return Array.isArray(defaultWorkContext) && defaultWorkContext.length > 0;
|
|
18819
|
+
}
|
|
18820
|
+
rebaseAIEmployeeInheritedTaskWorkContext(currentTasks, previousActionWorkContext, nextActionWorkContext) {
|
|
18821
|
+
const tasks = this.normalizeAIEmployeeLegacyInheritedTaskWorkContext(currentTasks) || [];
|
|
18822
|
+
if (!previousActionWorkContext.length || import_lodash.default.isEqual(previousActionWorkContext, nextActionWorkContext)) {
|
|
18823
|
+
return tasks;
|
|
18824
|
+
}
|
|
18825
|
+
return tasks.map((task) => {
|
|
18826
|
+
const nextTask = import_lodash.default.cloneDeep(task);
|
|
18827
|
+
if (import_lodash.default.isPlainObject(nextTask == null ? void 0 : nextTask.message)) {
|
|
18828
|
+
const currentTaskWorkContext = this.normalizeAIEmployeeWorkContextForDedupIdentity(
|
|
18829
|
+
nextTask.message.workContext
|
|
18830
|
+
);
|
|
18831
|
+
if (import_lodash.default.isEqual(currentTaskWorkContext, previousActionWorkContext)) {
|
|
18832
|
+
delete nextTask.message.workContext;
|
|
18833
|
+
}
|
|
18834
|
+
}
|
|
18835
|
+
return nextTask;
|
|
18836
|
+
});
|
|
18519
18837
|
}
|
|
18520
18838
|
normalizeAIEmployeeActionSettingsReferences(actionName, settings, options) {
|
|
18521
18839
|
if (!this.hasAIEmployeePublicSettings(settings)) {
|
|
@@ -18529,15 +18847,22 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18529
18847
|
});
|
|
18530
18848
|
}
|
|
18531
18849
|
if (Object.prototype.hasOwnProperty.call(nextSettings, "tasks")) {
|
|
18850
|
+
const defaultWorkContext = this.normalizeAIEmployeeEffectiveActionWorkContext(
|
|
18851
|
+
actionName,
|
|
18852
|
+
nextSettings,
|
|
18853
|
+
{},
|
|
18854
|
+
options
|
|
18855
|
+
);
|
|
18532
18856
|
nextSettings.tasks = this.normalizeAIEmployeeTasks(actionName, nextSettings.tasks, [], {
|
|
18533
18857
|
...options,
|
|
18534
|
-
path: "settings.tasks"
|
|
18858
|
+
path: "settings.tasks",
|
|
18859
|
+
defaultWorkContext
|
|
18535
18860
|
});
|
|
18536
18861
|
}
|
|
18537
18862
|
return nextSettings;
|
|
18538
18863
|
}
|
|
18539
18864
|
async normalizeAIEmployeeActionPublicSettings(actionName, settings, options) {
|
|
18540
|
-
var _a, _b;
|
|
18865
|
+
var _a, _b, _c, _d;
|
|
18541
18866
|
this.assertAIEmployeePluginEnabled(actionName, options.enabledPackages);
|
|
18542
18867
|
if (!import_lodash.default.isPlainObject(settings)) {
|
|
18543
18868
|
(0, import_errors.throwBadRequest)(`flowSurfaces ${actionName} AI employee settings must be an object`);
|
|
@@ -18557,6 +18882,17 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18557
18882
|
}
|
|
18558
18883
|
const props = {};
|
|
18559
18884
|
const stepParams = {};
|
|
18885
|
+
const effectiveActionWorkContext = this.normalizeAIEmployeeEffectiveActionWorkContext(
|
|
18886
|
+
actionName,
|
|
18887
|
+
settings,
|
|
18888
|
+
currentProps,
|
|
18889
|
+
options
|
|
18890
|
+
);
|
|
18891
|
+
const previousActionWorkContext = this.normalizeAIEmployeeActionWorkContextForDedupIdentity(
|
|
18892
|
+
(_c = currentProps == null ? void 0 : currentProps.context) == null ? void 0 : _c.workContext,
|
|
18893
|
+
this.normalizeAIEmployeeDefaultActionWorkContextForSelfUid(options.selfUid)
|
|
18894
|
+
);
|
|
18895
|
+
const nextActionWorkContext = this.normalizeAIEmployeeWorkContextForDedupIdentity(effectiveActionWorkContext);
|
|
18560
18896
|
if (effectiveUsername && (hasUsername || options.requireUsername)) {
|
|
18561
18897
|
props.aiEmployee = {
|
|
18562
18898
|
...import_lodash.default.isPlainObject(currentProps.aiEmployee) ? import_lodash.default.cloneDeep(currentProps.aiEmployee) : {},
|
|
@@ -18570,28 +18906,25 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18570
18906
|
}
|
|
18571
18907
|
props.auto = auto;
|
|
18572
18908
|
}
|
|
18573
|
-
if (Object.prototype.hasOwnProperty.call(settings, "workContext") || options.requireUsername) {
|
|
18574
|
-
const rawWorkContext = Object.prototype.hasOwnProperty.call(settings, "workContext") ? settings.workContext : [{ type: "flow-model", target: "self" }];
|
|
18909
|
+
if (Array.isArray(effectiveActionWorkContext) && (Object.prototype.hasOwnProperty.call(settings, "workContext") || options.requireUsername || !import_lodash.default.isEqual((_d = currentProps == null ? void 0 : currentProps.context) == null ? void 0 : _d.workContext, effectiveActionWorkContext))) {
|
|
18575
18910
|
props.context = {
|
|
18576
18911
|
...import_lodash.default.isPlainObject(currentProps.context) ? import_lodash.default.cloneDeep(currentProps.context) : {},
|
|
18577
|
-
workContext:
|
|
18578
|
-
selfUid: options.selfUid,
|
|
18579
|
-
keyMap: options.keyMap,
|
|
18580
|
-
path: "settings.workContext"
|
|
18581
|
-
})
|
|
18912
|
+
workContext: import_lodash.default.cloneDeep(effectiveActionWorkContext)
|
|
18582
18913
|
};
|
|
18583
18914
|
}
|
|
18584
18915
|
if (Object.prototype.hasOwnProperty.call(settings, "tasks")) {
|
|
18585
|
-
const
|
|
18586
|
-
|
|
18587
|
-
|
|
18588
|
-
|
|
18589
|
-
|
|
18590
|
-
selfUid: options.selfUid,
|
|
18591
|
-
keyMap: options.keyMap,
|
|
18592
|
-
path: "settings.tasks"
|
|
18593
|
-
}
|
|
18916
|
+
const currentTasks = this.readAIEmployeePersistedTasks(options.current);
|
|
18917
|
+
const currentTasksForNormalization = this.rebaseAIEmployeeInheritedTaskWorkContext(
|
|
18918
|
+
currentTasks,
|
|
18919
|
+
previousActionWorkContext,
|
|
18920
|
+
nextActionWorkContext
|
|
18594
18921
|
);
|
|
18922
|
+
const normalizedTasks = this.normalizeAIEmployeeTasks(actionName, settings.tasks, currentTasksForNormalization, {
|
|
18923
|
+
selfUid: options.selfUid,
|
|
18924
|
+
keyMap: options.keyMap,
|
|
18925
|
+
path: "settings.tasks",
|
|
18926
|
+
defaultWorkContext: effectiveActionWorkContext
|
|
18927
|
+
});
|
|
18595
18928
|
const validation = options.promptContext && normalizedTasks.length ? await this.buildAIEmployeePromptValidationContext(
|
|
18596
18929
|
actionName,
|
|
18597
18930
|
[
|
|
@@ -18612,6 +18945,17 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18612
18945
|
const tasks = this.appendAIEmployeeCurrentRecordPromptVariableToTasks(normalizedTasks, validation);
|
|
18613
18946
|
this.assertAIEmployeeTaskPromptVariablesAllowed(actionName, tasks, validation);
|
|
18614
18947
|
import_lodash.default.merge(stepParams, this.buildAIEmployeeTaskStepParams(tasks));
|
|
18948
|
+
} else if (!options.skipExistingTaskWorkContextRebase && Object.prototype.hasOwnProperty.call(settings, "workContext") && !import_lodash.default.isEqual(previousActionWorkContext, nextActionWorkContext)) {
|
|
18949
|
+
const currentTasks = this.readAIEmployeePersistedTasks(options.current);
|
|
18950
|
+
const rebasedTasks = this.rebaseAIEmployeeInheritedTaskWorkContext(
|
|
18951
|
+
currentTasks,
|
|
18952
|
+
previousActionWorkContext,
|
|
18953
|
+
nextActionWorkContext
|
|
18954
|
+
);
|
|
18955
|
+
const tasks = this.withAIEmployeeTaskDefaultWorkContext(rebasedTasks, effectiveActionWorkContext);
|
|
18956
|
+
if (tasks.length) {
|
|
18957
|
+
import_lodash.default.merge(stepParams, this.buildAIEmployeeTaskStepParams(tasks));
|
|
18958
|
+
}
|
|
18615
18959
|
}
|
|
18616
18960
|
if (Object.prototype.hasOwnProperty.call(settings, "style") || options.requireUsername) {
|
|
18617
18961
|
const style = Object.prototype.hasOwnProperty.call(settings, "style") ? settings.style : {};
|
|
@@ -18653,7 +18997,16 @@ ${AI_EMPLOYEE_CURRENT_RECORD_PROMPT_VARIABLE}` : AI_EMPLOYEE_CURRENT_RECORD_PROM
|
|
|
18653
18997
|
transaction,
|
|
18654
18998
|
includeAsyncNode: true
|
|
18655
18999
|
});
|
|
18656
|
-
|
|
19000
|
+
return await this.resolveAIEmployeeActionSelfUidFromParentNode(parentNode, transaction) || parentUid;
|
|
19001
|
+
}
|
|
19002
|
+
async resolveAIEmployeeActionSelfUidFromParentNode(parentNode, transaction) {
|
|
19003
|
+
const parentUid = String((parentNode == null ? void 0 : parentNode.uid) || "").trim();
|
|
19004
|
+
if (!parentUid) {
|
|
19005
|
+
return "";
|
|
19006
|
+
}
|
|
19007
|
+
if (["TableActionsColumnModel", "ListItemModel", "GridCardItemModel", "CommentItemModel"].includes(
|
|
19008
|
+
String((parentNode == null ? void 0 : parentNode.use) || "")
|
|
19009
|
+
)) {
|
|
18657
19010
|
const ownerUid = String((parentNode == null ? void 0 : parentNode.parentId) || "").trim() || ((parentNode == null ? void 0 : parentNode.uid) ? await this.locator.findParentUid(parentNode.uid, transaction).catch(() => "") : "");
|
|
18658
19011
|
return ownerUid || parentUid;
|
|
18659
19012
|
}
|