@contractspec/example.workflow-system 3.7.5 → 3.7.7

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.js CHANGED
@@ -20,7 +20,7 @@ var ApprovalDecisionEnum = defineEnum("ApprovalDecision", [
20
20
 
21
21
  // src/approval/approval.event.ts
22
22
  import { defineEvent } from "@contractspec/lib.contracts-spec";
23
- import { ScalarTypeEnum, defineSchemaModel } from "@contractspec/lib.schema";
23
+ import { defineSchemaModel, ScalarTypeEnum } from "@contractspec/lib.schema";
24
24
  var ApprovalRequestedPayload = defineSchemaModel({
25
25
  name: "ApprovalRequestedEventPayload",
26
26
  description: "Payload when approval is requested",
@@ -911,398 +911,596 @@ function createWorkflowHandlers(db) {
911
911
  };
912
912
  }
913
913
 
914
- // src/workflow/workflow.enum.ts
914
+ // src/instance/instance.enum.ts
915
915
  import { defineEnum as defineEnum2 } from "@contractspec/lib.schema";
916
- var WorkflowStatusEnum = defineEnum2("WorkflowStatus", [
917
- "DRAFT",
918
- "ACTIVE",
919
- "DEPRECATED",
920
- "ARCHIVED"
921
- ]);
922
- var TriggerTypeEnum = defineEnum2("WorkflowTriggerType", [
923
- "MANUAL",
924
- "EVENT",
925
- "SCHEDULED",
926
- "API"
927
- ]);
928
- var StepTypeEnum = defineEnum2("StepType", [
929
- "START",
930
- "APPROVAL",
931
- "TASK",
932
- "CONDITION",
933
- "PARALLEL",
934
- "WAIT",
935
- "ACTION",
936
- "END"
937
- ]);
938
- var ApprovalModeEnum = defineEnum2("ApprovalMode", [
939
- "ANY",
940
- "ALL",
941
- "MAJORITY",
942
- "SEQUENTIAL"
916
+ var InstanceStatusEnum = defineEnum2("InstanceStatus", [
917
+ "PENDING",
918
+ "RUNNING",
919
+ "WAITING",
920
+ "PAUSED",
921
+ "COMPLETED",
922
+ "CANCELLED",
923
+ "FAILED",
924
+ "TIMEOUT"
943
925
  ]);
944
926
 
945
- // src/workflow/workflow.schema.ts
927
+ // src/instance/instance.event.ts
928
+ import { defineEvent as defineEvent2 } from "@contractspec/lib.contracts-spec";
946
929
  import { defineSchemaModel as defineSchemaModel4, ScalarTypeEnum as ScalarTypeEnum4 } from "@contractspec/lib.schema";
947
- var WorkflowStepModel = defineSchemaModel4({
948
- name: "WorkflowStepModel",
949
- description: "A step in a workflow definition",
950
- fields: {
951
- id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
952
- key: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
953
- name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
954
- description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
955
- type: { type: StepTypeEnum, isOptional: false },
956
- position: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
957
- transitions: { type: ScalarTypeEnum4.JSON(), isOptional: false },
958
- approvalMode: { type: ApprovalModeEnum, isOptional: true },
959
- approverRoles: {
960
- type: ScalarTypeEnum4.String_unsecure(),
961
- isArray: true,
962
- isOptional: true
963
- }
964
- }
965
- });
966
- var WorkflowDefinitionModel = defineSchemaModel4({
967
- name: "WorkflowDefinitionModel",
968
- description: "A workflow definition",
930
+ var InstanceEventPayload = defineSchemaModel4({
931
+ name: "InstanceEventPayload",
932
+ description: "Base payload for instance events",
969
933
  fields: {
970
- id: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
971
- name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
972
- key: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
973
- description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
974
- version: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
975
- status: { type: WorkflowStatusEnum, isOptional: false },
976
- triggerType: { type: TriggerTypeEnum, isOptional: false },
977
- initialStepId: {
978
- type: ScalarTypeEnum4.String_unsecure(),
979
- isOptional: true
980
- },
981
- featureFlagKey: {
934
+ instanceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
935
+ workflowId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
936
+ workflowKey: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
937
+ status: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
938
+ referenceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
939
+ referenceType: {
982
940
  type: ScalarTypeEnum4.String_unsecure(),
983
941
  isOptional: true
984
942
  },
943
+ triggeredBy: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
985
944
  organizationId: {
986
945
  type: ScalarTypeEnum4.String_unsecure(),
987
946
  isOptional: false
988
947
  },
989
- createdAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
990
- updatedAt: { type: ScalarTypeEnum4.DateTime(), isOptional: false },
991
- steps: { type: WorkflowStepModel, isArray: true, isOptional: true }
948
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
992
949
  }
993
950
  });
994
- var CreateWorkflowInputModel = defineSchemaModel4({
995
- name: "CreateWorkflowInput",
996
- description: "Input for creating a workflow definition",
951
+ var StepTransitionPayload = defineSchemaModel4({
952
+ name: "StepTransitionEventPayload",
953
+ description: "Payload for step transition events",
997
954
  fields: {
998
- name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
999
- key: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1000
- description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1001
- triggerType: { type: TriggerTypeEnum, isOptional: true },
1002
- triggerConfig: { type: ScalarTypeEnum4.JSON(), isOptional: true },
1003
- featureFlagKey: {
955
+ instanceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
956
+ workflowId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
957
+ fromStepKey: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
958
+ toStepKey: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
959
+ action: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
960
+ executedBy: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
961
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
962
+ }
963
+ });
964
+ var InstanceCompletedPayload = defineSchemaModel4({
965
+ name: "InstanceCompletedEventPayload",
966
+ description: "Payload when instance completes",
967
+ fields: {
968
+ instanceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
969
+ workflowId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
970
+ workflowKey: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
971
+ outcome: { type: ScalarTypeEnum4.String_unsecure(), isOptional: false },
972
+ referenceId: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
973
+ referenceType: {
1004
974
  type: ScalarTypeEnum4.String_unsecure(),
1005
975
  isOptional: true
1006
976
  },
1007
- settings: { type: ScalarTypeEnum4.JSON(), isOptional: true }
977
+ duration: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: false },
978
+ timestamp: { type: ScalarTypeEnum4.DateTime(), isOptional: false }
1008
979
  }
1009
980
  });
1010
- var UpdateWorkflowInputModel = defineSchemaModel4({
1011
- name: "UpdateWorkflowInput",
1012
- description: "Input for updating a workflow definition",
981
+ var InstanceStartedEvent = defineEvent2({
982
+ meta: {
983
+ key: "workflow.instance.started",
984
+ version: "1.0.0",
985
+ description: "A new workflow instance has been started.",
986
+ stability: "stable",
987
+ owners: ["@workflow-team"],
988
+ tags: ["workflow", "instance", "started"]
989
+ },
990
+ payload: InstanceEventPayload
991
+ });
992
+ var StepEnteredEvent = defineEvent2({
993
+ meta: {
994
+ key: "workflow.step.entered",
995
+ version: "1.0.0",
996
+ description: "A workflow instance has entered a new step.",
997
+ stability: "stable",
998
+ owners: ["@workflow-team"],
999
+ tags: ["workflow", "step", "entered"]
1000
+ },
1001
+ payload: StepTransitionPayload
1002
+ });
1003
+ var StepExitedEvent = defineEvent2({
1004
+ meta: {
1005
+ key: "workflow.step.exited",
1006
+ version: "1.0.0",
1007
+ description: "A workflow instance has exited a step.",
1008
+ stability: "stable",
1009
+ owners: ["@workflow-team"],
1010
+ tags: ["workflow", "step", "exited"]
1011
+ },
1012
+ payload: StepTransitionPayload
1013
+ });
1014
+ var InstanceCompletedEvent = defineEvent2({
1015
+ meta: {
1016
+ key: "workflow.instance.completed",
1017
+ version: "1.0.0",
1018
+ description: "A workflow instance has completed.",
1019
+ stability: "stable",
1020
+ owners: ["@workflow-team"],
1021
+ tags: ["workflow", "instance", "completed"]
1022
+ },
1023
+ payload: InstanceCompletedPayload
1024
+ });
1025
+ var InstanceCancelledEvent = defineEvent2({
1026
+ meta: {
1027
+ key: "workflow.instance.cancelled",
1028
+ version: "1.0.0",
1029
+ description: "A workflow instance has been cancelled.",
1030
+ stability: "stable",
1031
+ owners: ["@workflow-team"],
1032
+ tags: ["workflow", "instance", "cancelled"]
1033
+ },
1034
+ payload: InstanceEventPayload
1035
+ });
1036
+ var InstancePausedEvent = defineEvent2({
1037
+ meta: {
1038
+ key: "workflow.instance.paused",
1039
+ version: "1.0.0",
1040
+ description: "A workflow instance has been paused.",
1041
+ stability: "stable",
1042
+ owners: ["@workflow-team"],
1043
+ tags: ["workflow", "instance", "paused"]
1044
+ },
1045
+ payload: InstanceEventPayload
1046
+ });
1047
+ var InstanceResumedEvent = defineEvent2({
1048
+ meta: {
1049
+ key: "workflow.instance.resumed",
1050
+ version: "1.0.0",
1051
+ description: "A workflow instance has been resumed.",
1052
+ stability: "stable",
1053
+ owners: ["@workflow-team"],
1054
+ tags: ["workflow", "instance", "resumed"]
1055
+ },
1056
+ payload: InstanceEventPayload
1057
+ });
1058
+ var InstanceFailedEvent = defineEvent2({
1059
+ meta: {
1060
+ key: "workflow.instance.failed",
1061
+ version: "1.0.0",
1062
+ description: "A workflow instance has failed.",
1063
+ stability: "stable",
1064
+ owners: ["@workflow-team"],
1065
+ tags: ["workflow", "instance", "failed"]
1066
+ },
1067
+ payload: InstanceEventPayload
1068
+ });
1069
+ var InstanceTimedOutEvent = defineEvent2({
1070
+ meta: {
1071
+ key: "workflow.instance.timedOut",
1072
+ version: "1.0.0",
1073
+ description: "A workflow instance has timed out.",
1074
+ stability: "stable",
1075
+ owners: ["@workflow-team"],
1076
+ tags: ["workflow", "instance", "timeout"]
1077
+ },
1078
+ payload: InstanceEventPayload
1079
+ });
1080
+
1081
+ // src/instance/instance.schema.ts
1082
+ import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
1083
+ var WorkflowInstanceModel = defineSchemaModel5({
1084
+ name: "WorkflowInstanceModel",
1085
+ description: "A running workflow instance",
1013
1086
  fields: {
1014
- workflowId: {
1015
- type: ScalarTypeEnum4.String_unsecure(),
1087
+ id: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1088
+ workflowDefinitionId: {
1089
+ type: ScalarTypeEnum5.String_unsecure(),
1016
1090
  isOptional: false
1017
1091
  },
1018
- name: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1019
- description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1020
- triggerType: { type: TriggerTypeEnum, isOptional: true },
1021
- triggerConfig: { type: ScalarTypeEnum4.JSON(), isOptional: true },
1022
- featureFlagKey: {
1023
- type: ScalarTypeEnum4.String_unsecure(),
1092
+ referenceId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1093
+ referenceType: {
1094
+ type: ScalarTypeEnum5.String_unsecure(),
1095
+ isOptional: true
1096
+ },
1097
+ status: { type: InstanceStatusEnum, isOptional: false },
1098
+ currentStepId: {
1099
+ type: ScalarTypeEnum5.String_unsecure(),
1100
+ isOptional: true
1101
+ },
1102
+ contextData: { type: ScalarTypeEnum5.JSON(), isOptional: true },
1103
+ triggeredBy: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1104
+ organizationId: {
1105
+ type: ScalarTypeEnum5.String_unsecure(),
1106
+ isOptional: false
1107
+ },
1108
+ priority: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false },
1109
+ dueAt: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1110
+ outcome: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1111
+ resultData: { type: ScalarTypeEnum5.JSON(), isOptional: true },
1112
+ errorMessage: {
1113
+ type: ScalarTypeEnum5.String_unsecure(),
1024
1114
  isOptional: true
1025
1115
  },
1026
- settings: { type: ScalarTypeEnum4.JSON(), isOptional: true }
1116
+ createdAt: { type: ScalarTypeEnum5.DateTime(), isOptional: false },
1117
+ startedAt: { type: ScalarTypeEnum5.DateTime(), isOptional: true },
1118
+ completedAt: { type: ScalarTypeEnum5.DateTime(), isOptional: true }
1027
1119
  }
1028
1120
  });
1029
- var AddStepInputModel = defineSchemaModel4({
1030
- name: "AddStepInput",
1031
- description: "Input for adding a step to a workflow",
1121
+ var StartWorkflowInputModel = defineSchemaModel5({
1122
+ name: "StartWorkflowInput",
1123
+ description: "Input for starting a workflow",
1032
1124
  fields: {
1033
- workflowId: {
1034
- type: ScalarTypeEnum4.String_unsecure(),
1035
- isOptional: false
1125
+ workflowKey: { type: ScalarTypeEnum5.NonEmptyString(), isOptional: false },
1126
+ contextData: { type: ScalarTypeEnum5.JSON(), isOptional: true },
1127
+ referenceId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1128
+ referenceType: {
1129
+ type: ScalarTypeEnum5.String_unsecure(),
1130
+ isOptional: true
1036
1131
  },
1037
- key: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1038
- name: { type: ScalarTypeEnum4.NonEmptyString(), isOptional: false },
1039
- description: { type: ScalarTypeEnum4.String_unsecure(), isOptional: true },
1040
- type: { type: StepTypeEnum, isOptional: false },
1041
- position: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1042
- transitions: { type: ScalarTypeEnum4.JSON(), isOptional: false },
1043
- approvalMode: { type: ApprovalModeEnum, isOptional: true },
1044
- approverRoles: {
1045
- type: ScalarTypeEnum4.String_unsecure(),
1046
- isArray: true,
1132
+ priority: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: true },
1133
+ dueAt: { type: ScalarTypeEnum5.DateTime(), isOptional: true }
1134
+ }
1135
+ });
1136
+ var TransitionInputModel = defineSchemaModel5({
1137
+ name: "TransitionInput",
1138
+ description: "Input for transitioning a workflow",
1139
+ fields: {
1140
+ instanceId: { type: ScalarTypeEnum5.String_unsecure(), isOptional: false },
1141
+ action: { type: ScalarTypeEnum5.NonEmptyString(), isOptional: false },
1142
+ data: { type: ScalarTypeEnum5.JSON(), isOptional: true },
1143
+ comment: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
1144
+ }
1145
+ });
1146
+ var TransitionResultModel = defineSchemaModel5({
1147
+ name: "TransitionResult",
1148
+ description: "Result of a workflow transition",
1149
+ fields: {
1150
+ success: { type: ScalarTypeEnum5.Boolean(), isOptional: false },
1151
+ instance: { type: WorkflowInstanceModel, isOptional: false },
1152
+ previousStepKey: {
1153
+ type: ScalarTypeEnum5.String_unsecure(),
1047
1154
  isOptional: true
1048
1155
  },
1049
- approverUserIds: {
1050
- type: ScalarTypeEnum4.String_unsecure(),
1051
- isArray: true,
1156
+ currentStepKey: {
1157
+ type: ScalarTypeEnum5.String_unsecure(),
1052
1158
  isOptional: true
1053
1159
  },
1054
- timeoutSeconds: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true },
1055
- slaSeconds: { type: ScalarTypeEnum4.Int_unsecure(), isOptional: true }
1160
+ message: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true }
1056
1161
  }
1057
1162
  });
1058
1163
 
1059
- // src/workflow/workflow.operations.ts
1164
+ // src/instance/instance.operations.ts
1060
1165
  import {
1061
1166
  defineCommand as defineCommand2,
1062
1167
  defineQuery as defineQuery2
1063
1168
  } from "@contractspec/lib.contracts-spec/operations";
1064
- import { defineSchemaModel as defineSchemaModel5, ScalarTypeEnum as ScalarTypeEnum5 } from "@contractspec/lib.schema";
1169
+ import { defineSchemaModel as defineSchemaModel6, ScalarTypeEnum as ScalarTypeEnum6 } from "@contractspec/lib.schema";
1065
1170
  var OWNERS2 = ["@example.workflow-system"];
1066
- var CreateWorkflowContract = defineCommand2({
1171
+ var StartWorkflowContract = defineCommand2({
1067
1172
  meta: {
1068
- key: "workflow.definition.create",
1173
+ key: "workflow.instance.start",
1069
1174
  version: "1.0.0",
1070
1175
  stability: "stable",
1071
1176
  owners: [...OWNERS2],
1072
- tags: ["workflow", "definition", "create"],
1073
- description: "Create a new workflow definition.",
1074
- goal: "Allow users to define new workflow blueprints.",
1075
- context: "Workflow designer, admin panel."
1177
+ tags: ["workflow", "instance", "start"],
1178
+ description: "Start a new workflow instance.",
1179
+ goal: "Initiate a workflow for a business process.",
1180
+ context: "Order creation, request submission, etc."
1076
1181
  },
1077
1182
  io: {
1078
- input: CreateWorkflowInputModel,
1079
- output: WorkflowDefinitionModel
1183
+ input: StartWorkflowInputModel,
1184
+ output: WorkflowInstanceModel
1080
1185
  },
1081
1186
  policy: { auth: "user" },
1082
1187
  sideEffects: {
1083
1188
  emits: [
1084
1189
  {
1085
- key: "workflow.definition.created",
1190
+ key: "workflow.instance.started",
1086
1191
  version: "1.0.0",
1087
- when: "Workflow is created",
1088
- payload: WorkflowDefinitionModel
1192
+ when: "Workflow starts",
1193
+ payload: WorkflowInstanceModel
1194
+ },
1195
+ {
1196
+ key: "workflow.step.entered",
1197
+ version: "1.0.0",
1198
+ when: "First step entered",
1199
+ payload: WorkflowInstanceModel
1089
1200
  }
1090
1201
  ],
1091
- audit: ["workflow.definition.created"]
1202
+ audit: ["workflow.instance.started"]
1092
1203
  },
1093
1204
  acceptance: {
1094
1205
  scenarios: [
1095
1206
  {
1096
- key: "create-workflow-happy-path",
1097
- given: ["User is admin"],
1098
- when: ["User creates new workflow definition"],
1099
- then: [
1100
- "Definition is created",
1101
- "WorkflowDefinitionCreated event is emitted"
1102
- ]
1103
- }
1207
+ key: "start-workflow-happy-path",
1208
+ given: ["Workflow definition exists"],
1209
+ when: ["User starts workflow"],
1210
+ then: ["Instance is created and started"]
1211
+ }
1104
1212
  ],
1105
1213
  examples: [
1106
1214
  {
1107
- key: "create-onboarding",
1215
+ key: "start-onboarding",
1108
1216
  input: {
1109
- key: "onboarding-v1",
1110
- name: "Employee Onboarding",
1111
- version: "1.0.0"
1217
+ workflowKey: "onboarding-v1",
1218
+ context: { employeeId: "emp-123" }
1112
1219
  },
1113
- output: { id: "def-123", status: "draft" }
1220
+ output: { id: "inst-456", status: "running" }
1114
1221
  }
1115
1222
  ]
1116
1223
  }
1117
1224
  });
1118
- var UpdateWorkflowContract = defineCommand2({
1225
+ var TransitionWorkflowContract = defineCommand2({
1119
1226
  meta: {
1120
- key: "workflow.definition.update",
1227
+ key: "workflow.instance.transition",
1121
1228
  version: "1.0.0",
1122
1229
  stability: "stable",
1123
1230
  owners: [...OWNERS2],
1124
- tags: ["workflow", "definition", "update"],
1125
- description: "Update an existing workflow definition.",
1126
- goal: "Allow users to modify workflow blueprints.",
1127
- context: "Workflow designer."
1231
+ tags: ["workflow", "instance", "transition", "state-machine"],
1232
+ description: "Transition a workflow instance to the next step.",
1233
+ goal: "Move workflow forward based on action.",
1234
+ context: "Task completion, approval decisions."
1128
1235
  },
1129
1236
  io: {
1130
- input: UpdateWorkflowInputModel,
1131
- output: WorkflowDefinitionModel
1237
+ input: TransitionInputModel,
1238
+ output: TransitionResultModel
1132
1239
  },
1133
1240
  policy: { auth: "user" },
1134
1241
  sideEffects: {
1135
1242
  emits: [
1136
1243
  {
1137
- key: "workflow.definition.updated",
1244
+ key: "workflow.step.exited",
1138
1245
  version: "1.0.0",
1139
- when: "Workflow is updated",
1140
- payload: WorkflowDefinitionModel
1246
+ when: "Step is exited",
1247
+ payload: WorkflowInstanceModel
1248
+ },
1249
+ {
1250
+ key: "workflow.step.entered",
1251
+ version: "1.0.0",
1252
+ when: "New step is entered",
1253
+ payload: WorkflowInstanceModel
1254
+ },
1255
+ {
1256
+ key: "workflow.instance.completed",
1257
+ version: "1.0.0",
1258
+ when: "Workflow reaches end",
1259
+ payload: WorkflowInstanceModel
1141
1260
  }
1142
1261
  ],
1143
- audit: ["workflow.definition.updated"]
1262
+ audit: ["workflow.instance.transitioned"]
1144
1263
  },
1145
1264
  acceptance: {
1146
1265
  scenarios: [
1147
1266
  {
1148
- key: "update-workflow-happy-path",
1149
- given: ["Workflow definition exists"],
1150
- when: ["User updates definition"],
1151
- then: [
1152
- "Definition is updated",
1153
- "WorkflowDefinitionUpdated event is emitted"
1154
- ]
1267
+ key: "transition-workflow-happy-path",
1268
+ given: ["Workflow instance is waiting at step"],
1269
+ when: ["User provides input"],
1270
+ then: ["Instance moves to next step"]
1155
1271
  }
1156
1272
  ],
1157
1273
  examples: [
1158
1274
  {
1159
- key: "update-name",
1160
- input: { workflowId: "def-123", name: "New Employee Onboarding" },
1161
- output: { id: "def-123", name: "New Employee Onboarding" }
1275
+ key: "complete-task",
1276
+ input: {
1277
+ instanceId: "inst-456",
1278
+ action: "complete",
1279
+ data: { approved: true }
1280
+ },
1281
+ output: { success: true, nextStep: "notify-hr" }
1162
1282
  }
1163
1283
  ]
1164
1284
  }
1165
1285
  });
1166
- var AddStepContract = defineCommand2({
1286
+ var PauseWorkflowContract = defineCommand2({
1167
1287
  meta: {
1168
- key: "workflow.step.add",
1288
+ key: "workflow.instance.pause",
1169
1289
  version: "1.0.0",
1170
1290
  stability: "stable",
1171
1291
  owners: [...OWNERS2],
1172
- tags: ["workflow", "step", "add"],
1173
- description: "Add a step to a workflow definition.",
1174
- goal: "Build workflow structure step by step.",
1175
- context: "Workflow designer."
1292
+ tags: ["workflow", "instance", "pause"],
1293
+ description: "Pause a running workflow instance.",
1294
+ goal: "Temporarily halt workflow execution.",
1295
+ context: "Administrative action, emergency stop."
1176
1296
  },
1177
1297
  io: {
1178
- input: AddStepInputModel,
1179
- output: WorkflowStepModel
1298
+ input: defineSchemaModel6({
1299
+ name: "PauseResumeInput",
1300
+ fields: {
1301
+ instanceId: {
1302
+ type: ScalarTypeEnum6.String_unsecure(),
1303
+ isOptional: false
1304
+ },
1305
+ reason: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true }
1306
+ }
1307
+ }),
1308
+ output: WorkflowInstanceModel
1180
1309
  },
1181
1310
  policy: { auth: "user" },
1182
1311
  sideEffects: {
1183
1312
  emits: [
1184
1313
  {
1185
- key: "workflow.step.added",
1314
+ key: "workflow.instance.paused",
1186
1315
  version: "1.0.0",
1187
- when: "Step is added",
1188
- payload: WorkflowStepModel
1316
+ when: "Workflow is paused",
1317
+ payload: WorkflowInstanceModel
1189
1318
  }
1190
1319
  ],
1191
- audit: ["workflow.step.added"]
1320
+ audit: ["workflow.instance.paused"]
1192
1321
  },
1193
1322
  acceptance: {
1194
1323
  scenarios: [
1195
1324
  {
1196
- key: "add-step-happy-path",
1197
- given: ["Workflow definition exists"],
1198
- when: ["User adds a step"],
1199
- then: ["Step is added", "StepAdded event is emitted"]
1325
+ key: "pause-workflow-happy-path",
1326
+ given: ["Workflow is running"],
1327
+ when: ["Admin pauses workflow"],
1328
+ then: ["Instance status becomes PAUSED"]
1200
1329
  }
1201
1330
  ],
1202
1331
  examples: [
1203
1332
  {
1204
- key: "add-approval-step",
1205
- input: {
1206
- workflowId: "def-123",
1207
- stepKey: "approve-contract",
1208
- type: "approval"
1333
+ key: "pause-maintenance",
1334
+ input: { instanceId: "inst-456", reason: "System maintenance" },
1335
+ output: { id: "inst-456", status: "paused" }
1336
+ }
1337
+ ]
1338
+ }
1339
+ });
1340
+ var ResumeWorkflowContract = defineCommand2({
1341
+ meta: {
1342
+ key: "workflow.instance.resume",
1343
+ version: "1.0.0",
1344
+ stability: "stable",
1345
+ owners: [...OWNERS2],
1346
+ tags: ["workflow", "instance", "resume"],
1347
+ description: "Resume a paused workflow instance.",
1348
+ goal: "Continue workflow execution.",
1349
+ context: "Administrative action."
1350
+ },
1351
+ io: {
1352
+ input: defineSchemaModel6({
1353
+ name: "PauseResumeInput",
1354
+ fields: {
1355
+ instanceId: {
1356
+ type: ScalarTypeEnum6.String_unsecure(),
1357
+ isOptional: false
1209
1358
  },
1210
- output: { id: "step-456", key: "approve-contract" }
1359
+ reason: { type: ScalarTypeEnum6.String_unsecure(), isOptional: true }
1360
+ }
1361
+ }),
1362
+ output: WorkflowInstanceModel
1363
+ },
1364
+ policy: { auth: "user" },
1365
+ sideEffects: {
1366
+ emits: [
1367
+ {
1368
+ key: "workflow.instance.resumed",
1369
+ version: "1.0.0",
1370
+ when: "Workflow is resumed",
1371
+ payload: WorkflowInstanceModel
1372
+ }
1373
+ ],
1374
+ audit: ["workflow.instance.resumed"]
1375
+ },
1376
+ acceptance: {
1377
+ scenarios: [
1378
+ {
1379
+ key: "resume-workflow-happy-path",
1380
+ given: ["Workflow is paused"],
1381
+ when: ["Admin resumes workflow"],
1382
+ then: ["Instance status becomes RUNNING"]
1383
+ }
1384
+ ],
1385
+ examples: [
1386
+ {
1387
+ key: "resume-normal",
1388
+ input: { instanceId: "inst-456", reason: "Issue resolved" },
1389
+ output: { id: "inst-456", status: "running" }
1211
1390
  }
1212
1391
  ]
1213
1392
  }
1214
1393
  });
1215
- var PublishWorkflowContract = defineCommand2({
1394
+ var CancelWorkflowContract = defineCommand2({
1216
1395
  meta: {
1217
- key: "workflow.definition.publish",
1396
+ key: "workflow.instance.cancel",
1218
1397
  version: "1.0.0",
1219
1398
  stability: "stable",
1220
1399
  owners: [...OWNERS2],
1221
- tags: ["workflow", "definition", "publish"],
1222
- description: "Publish a workflow definition to make it available for use.",
1223
- goal: "Activate workflow for production use.",
1224
- context: "Workflow designer, deployment."
1400
+ tags: ["workflow", "instance", "cancel"],
1401
+ description: "Cancel a workflow instance.",
1402
+ goal: "Terminate workflow without completion.",
1403
+ context: "User request, system cancellation."
1225
1404
  },
1226
1405
  io: {
1227
- input: defineSchemaModel5({
1228
- name: "PublishWorkflowInput",
1406
+ input: defineSchemaModel6({
1407
+ name: "CancelWorkflowInput",
1229
1408
  fields: {
1230
- workflowId: {
1231
- type: ScalarTypeEnum5.String_unsecure(),
1409
+ instanceId: {
1410
+ type: ScalarTypeEnum6.String_unsecure(),
1411
+ isOptional: false
1412
+ },
1413
+ reason: {
1414
+ type: ScalarTypeEnum6.String_unsecure(),
1232
1415
  isOptional: false
1233
1416
  }
1234
1417
  }
1235
1418
  }),
1236
- output: WorkflowDefinitionModel
1419
+ output: WorkflowInstanceModel
1237
1420
  },
1238
1421
  policy: { auth: "user" },
1239
1422
  sideEffects: {
1240
1423
  emits: [
1241
1424
  {
1242
- key: "workflow.definition.published",
1425
+ key: "workflow.instance.cancelled",
1243
1426
  version: "1.0.0",
1244
- when: "Workflow is published",
1245
- payload: WorkflowDefinitionModel
1427
+ when: "Workflow is cancelled",
1428
+ payload: WorkflowInstanceModel
1246
1429
  }
1247
1430
  ],
1248
- audit: ["workflow.definition.published"]
1431
+ audit: ["workflow.instance.cancelled"]
1249
1432
  },
1250
1433
  acceptance: {
1251
1434
  scenarios: [
1252
1435
  {
1253
- key: "publish-workflow-happy-path",
1254
- given: ["Workflow definition is valid"],
1255
- when: ["User publishes workflow"],
1256
- then: ["Workflow becomes active", "WorkflowPublished event is emitted"]
1436
+ key: "cancel-workflow-happy-path",
1437
+ given: ["Workflow is running"],
1438
+ when: ["User cancels workflow"],
1439
+ then: ["Instance status becomes CANCELLED"]
1257
1440
  }
1258
1441
  ],
1259
1442
  examples: [
1260
1443
  {
1261
- key: "publish-onboarding",
1262
- input: { workflowId: "def-123" },
1263
- output: { id: "def-123", status: "published" }
1444
+ key: "cancel-mistake",
1445
+ input: { instanceId: "inst-456", reason: "Created by mistake" },
1446
+ output: { id: "inst-456", status: "cancelled" }
1264
1447
  }
1265
1448
  ]
1266
1449
  }
1267
1450
  });
1268
- var ListWorkflowsContract = defineQuery2({
1451
+ var ListInstancesContract = defineQuery2({
1269
1452
  meta: {
1270
- key: "workflow.definition.list",
1453
+ key: "workflow.instance.list",
1271
1454
  version: "1.0.0",
1272
1455
  stability: "stable",
1273
1456
  owners: [...OWNERS2],
1274
- tags: ["workflow", "definition", "list"],
1275
- description: "List workflow definitions with filtering.",
1276
- goal: "Browse and search available workflows.",
1277
- context: "Workflow list, search."
1457
+ tags: ["workflow", "instance", "list"],
1458
+ description: "List workflow instances with filtering.",
1459
+ goal: "Browse and search running workflows.",
1460
+ context: "Dashboard, monitoring."
1278
1461
  },
1279
1462
  io: {
1280
- input: defineSchemaModel5({
1281
- name: "ListWorkflowsInput",
1463
+ input: defineSchemaModel6({
1464
+ name: "ListInstancesInput",
1282
1465
  fields: {
1283
- status: { type: WorkflowStatusEnum, isOptional: true },
1284
- search: { type: ScalarTypeEnum5.String_unsecure(), isOptional: true },
1466
+ workflowKey: {
1467
+ type: ScalarTypeEnum6.String_unsecure(),
1468
+ isOptional: true
1469
+ },
1470
+ status: { type: InstanceStatusEnum, isOptional: true },
1471
+ referenceType: {
1472
+ type: ScalarTypeEnum6.String_unsecure(),
1473
+ isOptional: true
1474
+ },
1475
+ referenceId: {
1476
+ type: ScalarTypeEnum6.String_unsecure(),
1477
+ isOptional: true
1478
+ },
1479
+ triggeredBy: {
1480
+ type: ScalarTypeEnum6.String_unsecure(),
1481
+ isOptional: true
1482
+ },
1285
1483
  limit: {
1286
- type: ScalarTypeEnum5.Int_unsecure(),
1484
+ type: ScalarTypeEnum6.Int_unsecure(),
1287
1485
  isOptional: true,
1288
1486
  defaultValue: 20
1289
1487
  },
1290
1488
  offset: {
1291
- type: ScalarTypeEnum5.Int_unsecure(),
1489
+ type: ScalarTypeEnum6.Int_unsecure(),
1292
1490
  isOptional: true,
1293
1491
  defaultValue: 0
1294
1492
  }
1295
1493
  }
1296
1494
  }),
1297
- output: defineSchemaModel5({
1298
- name: "ListWorkflowsOutput",
1495
+ output: defineSchemaModel6({
1496
+ name: "ListInstancesOutput",
1299
1497
  fields: {
1300
- workflows: {
1301
- type: WorkflowDefinitionModel,
1498
+ instances: {
1499
+ type: WorkflowInstanceModel,
1302
1500
  isArray: true,
1303
1501
  isOptional: false
1304
1502
  },
1305
- total: { type: ScalarTypeEnum5.Int_unsecure(), isOptional: false }
1503
+ total: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: false }
1306
1504
  }
1307
1505
  })
1308
1506
  },
@@ -1310,1753 +1508,1553 @@ var ListWorkflowsContract = defineQuery2({
1310
1508
  acceptance: {
1311
1509
  scenarios: [
1312
1510
  {
1313
- key: "list-workflows-happy-path",
1314
- given: ["Workflow definitions exist"],
1315
- when: ["User lists workflows"],
1316
- then: ["List of workflows is returned"]
1511
+ key: "list-instances-happy-path",
1512
+ given: ["Workflow instances exist"],
1513
+ when: ["User lists instances"],
1514
+ then: ["List of instances is returned"]
1317
1515
  }
1318
1516
  ],
1319
1517
  examples: [
1320
1518
  {
1321
- key: "list-all",
1322
- input: { limit: 10 },
1323
- output: { workflows: [], total: 5 }
1519
+ key: "list-running",
1520
+ input: { status: "running", limit: 10 },
1521
+ output: { instances: [], total: 5 }
1324
1522
  }
1325
1523
  ]
1326
1524
  }
1327
1525
  });
1328
- var GetWorkflowContract = defineQuery2({
1526
+ var GetInstanceContract = defineQuery2({
1329
1527
  meta: {
1330
- key: "workflow.definition.get",
1528
+ key: "workflow.instance.get",
1331
1529
  version: "1.0.0",
1332
1530
  stability: "stable",
1333
1531
  owners: [...OWNERS2],
1334
- tags: ["workflow", "definition", "get"],
1335
- description: "Get a workflow definition with all steps.",
1336
- goal: "View workflow details.",
1337
- context: "Workflow designer, detail view."
1532
+ tags: ["workflow", "instance", "get"],
1533
+ description: "Get a workflow instance with details.",
1534
+ goal: "View workflow instance details.",
1535
+ context: "Instance detail view."
1338
1536
  },
1339
1537
  io: {
1340
- input: defineSchemaModel5({
1341
- name: "GetWorkflowInput",
1538
+ input: defineSchemaModel6({
1539
+ name: "GetInstanceInput",
1342
1540
  fields: {
1343
- workflowId: {
1344
- type: ScalarTypeEnum5.String_unsecure(),
1541
+ instanceId: {
1542
+ type: ScalarTypeEnum6.String_unsecure(),
1345
1543
  isOptional: false
1346
1544
  }
1347
1545
  }
1348
1546
  }),
1349
- output: WorkflowDefinitionModel
1547
+ output: WorkflowInstanceModel
1350
1548
  },
1351
1549
  policy: { auth: "user" },
1352
1550
  acceptance: {
1353
1551
  scenarios: [
1354
1552
  {
1355
- key: "get-workflow-happy-path",
1356
- given: ["Workflow definition exists"],
1357
- when: ["User requests workflow details"],
1358
- then: ["Workflow details are returned"]
1553
+ key: "get-instance-happy-path",
1554
+ given: ["Instance exists"],
1555
+ when: ["User requests instance details"],
1556
+ then: ["Instance details are returned"]
1359
1557
  }
1360
1558
  ],
1361
1559
  examples: [
1362
1560
  {
1363
1561
  key: "get-details",
1364
- input: { workflowId: "def-123" },
1365
- output: { id: "def-123", name: "Employee Onboarding" }
1562
+ input: { instanceId: "inst-456" },
1563
+ output: { id: "inst-456", workflowKey: "onboarding-v1" }
1366
1564
  }
1367
1565
  ]
1368
1566
  }
1369
1567
  });
1370
-
1371
- // src/workflow/workflow.event.ts
1372
- import { defineEvent as defineEvent2 } from "@contractspec/lib.contracts-spec";
1373
- import { ScalarTypeEnum as ScalarTypeEnum6, defineSchemaModel as defineSchemaModel6 } from "@contractspec/lib.schema";
1374
- var WorkflowDefinitionPayload = defineSchemaModel6({
1375
- name: "WorkflowDefinitionEventPayload",
1376
- description: "Payload for workflow definition events",
1377
- fields: {
1378
- workflowId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1379
- key: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1380
- name: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1381
- version: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1382
- organizationId: {
1383
- type: ScalarTypeEnum6.String_unsecure(),
1384
- isOptional: false
1385
- },
1386
- createdBy: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1387
- timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1388
- }
1389
- });
1390
- var StepAddedPayload = defineSchemaModel6({
1391
- name: "StepAddedEventPayload",
1392
- description: "Payload when a step is added",
1393
- fields: {
1394
- stepId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1395
- workflowId: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1396
- stepKey: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1397
- stepType: { type: ScalarTypeEnum6.String_unsecure(), isOptional: false },
1398
- position: { type: ScalarTypeEnum6.Int_unsecure(), isOptional: false },
1399
- timestamp: { type: ScalarTypeEnum6.DateTime(), isOptional: false }
1400
- }
1401
- });
1402
- var WorkflowCreatedEvent = defineEvent2({
1403
- meta: {
1404
- key: "workflow.definition.created",
1405
- version: "1.0.0",
1406
- description: "A new workflow definition has been created.",
1407
- stability: "stable",
1408
- owners: ["@workflow-team"],
1409
- tags: ["workflow", "definition", "created"]
1410
- },
1411
- payload: WorkflowDefinitionPayload
1412
- });
1413
- var WorkflowUpdatedEvent = defineEvent2({
1414
- meta: {
1415
- key: "workflow.definition.updated",
1416
- version: "1.0.0",
1417
- description: "A workflow definition has been updated.",
1418
- stability: "stable",
1419
- owners: ["@workflow-team"],
1420
- tags: ["workflow", "definition", "updated"]
1421
- },
1422
- payload: WorkflowDefinitionPayload
1423
- });
1424
- var WorkflowPublishedEvent = defineEvent2({
1425
- meta: {
1426
- key: "workflow.definition.published",
1427
- version: "1.0.0",
1428
- description: "A workflow definition has been published and is now active.",
1429
- stability: "stable",
1430
- owners: ["@workflow-team"],
1431
- tags: ["workflow", "definition", "published"]
1432
- },
1433
- payload: WorkflowDefinitionPayload
1434
- });
1435
- var StepAddedEvent = defineEvent2({
1436
- meta: {
1437
- key: "workflow.step.added",
1438
- version: "1.0.0",
1439
- description: "A step has been added to a workflow definition.",
1440
- stability: "stable",
1441
- owners: ["@workflow-team"],
1442
- tags: ["workflow", "step", "added"]
1443
- },
1444
- payload: StepAddedPayload
1445
- });
1446
- // src/instance/instance.enum.ts
1568
+ // src/workflow/workflow.enum.ts
1447
1569
  import { defineEnum as defineEnum3 } from "@contractspec/lib.schema";
1448
- var InstanceStatusEnum = defineEnum3("InstanceStatus", [
1449
- "PENDING",
1450
- "RUNNING",
1451
- "WAITING",
1452
- "PAUSED",
1453
- "COMPLETED",
1454
- "CANCELLED",
1455
- "FAILED",
1456
- "TIMEOUT"
1570
+ var WorkflowStatusEnum = defineEnum3("WorkflowStatus", [
1571
+ "DRAFT",
1572
+ "ACTIVE",
1573
+ "DEPRECATED",
1574
+ "ARCHIVED"
1575
+ ]);
1576
+ var TriggerTypeEnum = defineEnum3("WorkflowTriggerType", [
1577
+ "MANUAL",
1578
+ "EVENT",
1579
+ "SCHEDULED",
1580
+ "API"
1581
+ ]);
1582
+ var StepTypeEnum = defineEnum3("StepType", [
1583
+ "START",
1584
+ "APPROVAL",
1585
+ "TASK",
1586
+ "CONDITION",
1587
+ "PARALLEL",
1588
+ "WAIT",
1589
+ "ACTION",
1590
+ "END"
1591
+ ]);
1592
+ var ApprovalModeEnum = defineEnum3("ApprovalMode", [
1593
+ "ANY",
1594
+ "ALL",
1595
+ "MAJORITY",
1596
+ "SEQUENTIAL"
1457
1597
  ]);
1458
1598
 
1459
- // src/instance/instance.schema.ts
1599
+ // src/workflow/workflow.schema.ts
1460
1600
  import { defineSchemaModel as defineSchemaModel7, ScalarTypeEnum as ScalarTypeEnum7 } from "@contractspec/lib.schema";
1461
- var WorkflowInstanceModel = defineSchemaModel7({
1462
- name: "WorkflowInstanceModel",
1463
- description: "A running workflow instance",
1601
+ var WorkflowStepModel = defineSchemaModel7({
1602
+ name: "WorkflowStepModel",
1603
+ description: "A step in a workflow definition",
1464
1604
  fields: {
1465
1605
  id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1466
- workflowDefinitionId: {
1606
+ key: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1607
+ name: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1608
+ description: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1609
+ type: { type: StepTypeEnum, isOptional: false },
1610
+ position: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
1611
+ transitions: { type: ScalarTypeEnum7.JSON(), isOptional: false },
1612
+ approvalMode: { type: ApprovalModeEnum, isOptional: true },
1613
+ approverRoles: {
1467
1614
  type: ScalarTypeEnum7.String_unsecure(),
1468
- isOptional: false
1469
- },
1470
- referenceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1471
- referenceType: {
1615
+ isArray: true,
1616
+ isOptional: true
1617
+ }
1618
+ }
1619
+ });
1620
+ var WorkflowDefinitionModel = defineSchemaModel7({
1621
+ name: "WorkflowDefinitionModel",
1622
+ description: "A workflow definition",
1623
+ fields: {
1624
+ id: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1625
+ name: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1626
+ key: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1627
+ description: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1628
+ version: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1629
+ status: { type: WorkflowStatusEnum, isOptional: false },
1630
+ triggerType: { type: TriggerTypeEnum, isOptional: false },
1631
+ initialStepId: {
1472
1632
  type: ScalarTypeEnum7.String_unsecure(),
1473
1633
  isOptional: true
1474
1634
  },
1475
- status: { type: InstanceStatusEnum, isOptional: false },
1476
- currentStepId: {
1635
+ featureFlagKey: {
1477
1636
  type: ScalarTypeEnum7.String_unsecure(),
1478
1637
  isOptional: true
1479
1638
  },
1480
- contextData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1481
- triggeredBy: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1482
1639
  organizationId: {
1483
1640
  type: ScalarTypeEnum7.String_unsecure(),
1484
1641
  isOptional: false
1485
1642
  },
1486
- priority: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: false },
1487
- dueAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true },
1488
- outcome: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1489
- resultData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1490
- errorMessage: {
1491
- type: ScalarTypeEnum7.String_unsecure(),
1492
- isOptional: true
1493
- },
1494
1643
  createdAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
1495
- startedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true },
1496
- completedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true }
1644
+ updatedAt: { type: ScalarTypeEnum7.DateTime(), isOptional: false },
1645
+ steps: { type: WorkflowStepModel, isArray: true, isOptional: true }
1497
1646
  }
1498
1647
  });
1499
- var StartWorkflowInputModel = defineSchemaModel7({
1500
- name: "StartWorkflowInput",
1501
- description: "Input for starting a workflow",
1648
+ var CreateWorkflowInputModel = defineSchemaModel7({
1649
+ name: "CreateWorkflowInput",
1650
+ description: "Input for creating a workflow definition",
1502
1651
  fields: {
1503
- workflowKey: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1504
- contextData: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1505
- referenceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1506
- referenceType: {
1652
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1653
+ key: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1654
+ description: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1655
+ triggerType: { type: TriggerTypeEnum, isOptional: true },
1656
+ triggerConfig: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1657
+ featureFlagKey: {
1507
1658
  type: ScalarTypeEnum7.String_unsecure(),
1508
1659
  isOptional: true
1509
1660
  },
1510
- priority: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: true },
1511
- dueAt: { type: ScalarTypeEnum7.DateTime(), isOptional: true }
1661
+ settings: { type: ScalarTypeEnum7.JSON(), isOptional: true }
1512
1662
  }
1513
1663
  });
1514
- var TransitionInputModel = defineSchemaModel7({
1515
- name: "TransitionInput",
1516
- description: "Input for transitioning a workflow",
1664
+ var UpdateWorkflowInputModel = defineSchemaModel7({
1665
+ name: "UpdateWorkflowInput",
1666
+ description: "Input for updating a workflow definition",
1517
1667
  fields: {
1518
- instanceId: { type: ScalarTypeEnum7.String_unsecure(), isOptional: false },
1519
- action: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1520
- data: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1521
- comment: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true }
1668
+ workflowId: {
1669
+ type: ScalarTypeEnum7.String_unsecure(),
1670
+ isOptional: false
1671
+ },
1672
+ name: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1673
+ description: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1674
+ triggerType: { type: TriggerTypeEnum, isOptional: true },
1675
+ triggerConfig: { type: ScalarTypeEnum7.JSON(), isOptional: true },
1676
+ featureFlagKey: {
1677
+ type: ScalarTypeEnum7.String_unsecure(),
1678
+ isOptional: true
1679
+ },
1680
+ settings: { type: ScalarTypeEnum7.JSON(), isOptional: true }
1522
1681
  }
1523
1682
  });
1524
- var TransitionResultModel = defineSchemaModel7({
1525
- name: "TransitionResult",
1526
- description: "Result of a workflow transition",
1683
+ var AddStepInputModel = defineSchemaModel7({
1684
+ name: "AddStepInput",
1685
+ description: "Input for adding a step to a workflow",
1527
1686
  fields: {
1528
- success: { type: ScalarTypeEnum7.Boolean(), isOptional: false },
1529
- instance: { type: WorkflowInstanceModel, isOptional: false },
1530
- previousStepKey: {
1687
+ workflowId: {
1688
+ type: ScalarTypeEnum7.String_unsecure(),
1689
+ isOptional: false
1690
+ },
1691
+ key: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1692
+ name: { type: ScalarTypeEnum7.NonEmptyString(), isOptional: false },
1693
+ description: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true },
1694
+ type: { type: StepTypeEnum, isOptional: false },
1695
+ position: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: true },
1696
+ transitions: { type: ScalarTypeEnum7.JSON(), isOptional: false },
1697
+ approvalMode: { type: ApprovalModeEnum, isOptional: true },
1698
+ approverRoles: {
1531
1699
  type: ScalarTypeEnum7.String_unsecure(),
1700
+ isArray: true,
1532
1701
  isOptional: true
1533
1702
  },
1534
- currentStepKey: {
1703
+ approverUserIds: {
1535
1704
  type: ScalarTypeEnum7.String_unsecure(),
1705
+ isArray: true,
1536
1706
  isOptional: true
1537
1707
  },
1538
- message: { type: ScalarTypeEnum7.String_unsecure(), isOptional: true }
1708
+ timeoutSeconds: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: true },
1709
+ slaSeconds: { type: ScalarTypeEnum7.Int_unsecure(), isOptional: true }
1539
1710
  }
1540
1711
  });
1541
1712
 
1542
- // src/instance/instance.operations.ts
1713
+ // src/presentations/index.ts
1543
1714
  import {
1544
- defineCommand as defineCommand3,
1545
- defineQuery as defineQuery3
1546
- } from "@contractspec/lib.contracts-spec/operations";
1547
- import { defineSchemaModel as defineSchemaModel8, ScalarTypeEnum as ScalarTypeEnum8 } from "@contractspec/lib.schema";
1548
- var OWNERS3 = ["@example.workflow-system"];
1549
- var StartWorkflowContract = defineCommand3({
1715
+ definePresentation,
1716
+ StabilityEnum
1717
+ } from "@contractspec/lib.contracts-spec";
1718
+ var WorkflowDesignerPresentation = definePresentation({
1550
1719
  meta: {
1551
- key: "workflow.instance.start",
1720
+ key: "workflow.designer",
1552
1721
  version: "1.0.0",
1553
- stability: "stable",
1554
- owners: [...OWNERS3],
1555
- tags: ["workflow", "instance", "start"],
1556
- description: "Start a new workflow instance.",
1557
- goal: "Initiate a workflow for a business process.",
1558
- context: "Order creation, request submission, etc."
1559
- },
1560
- io: {
1561
- input: StartWorkflowInputModel,
1562
- output: WorkflowInstanceModel
1722
+ title: "Workflow Designer",
1723
+ description: "Visual workflow designer with drag-and-drop steps",
1724
+ domain: "workflow-system",
1725
+ owners: ["@workflow-team"],
1726
+ tags: ["workflow", "designer", "admin"],
1727
+ stability: StabilityEnum.Experimental,
1728
+ goal: "Building and modifying workflow definitions",
1729
+ context: "Workflow administration and setup"
1563
1730
  },
1564
- policy: { auth: "user" },
1565
- sideEffects: {
1566
- emits: [
1567
- {
1568
- key: "workflow.instance.started",
1569
- version: "1.0.0",
1570
- when: "Workflow starts",
1571
- payload: WorkflowInstanceModel
1572
- },
1573
- {
1574
- key: "workflow.step.entered",
1575
- version: "1.0.0",
1576
- when: "First step entered",
1577
- payload: WorkflowInstanceModel
1578
- }
1579
- ],
1580
- audit: ["workflow.instance.started"]
1731
+ source: {
1732
+ type: "component",
1733
+ framework: "react",
1734
+ componentKey: "WorkflowDesigner",
1735
+ props: WorkflowDefinitionModel
1581
1736
  },
1582
- acceptance: {
1583
- scenarios: [
1584
- {
1585
- key: "start-workflow-happy-path",
1586
- given: ["Workflow definition exists"],
1587
- when: ["User starts workflow"],
1588
- then: ["Instance is created and started"]
1589
- }
1590
- ],
1591
- examples: [
1592
- {
1593
- key: "start-onboarding",
1594
- input: {
1595
- workflowKey: "onboarding-v1",
1596
- context: { employeeId: "emp-123" }
1597
- },
1598
- output: { id: "inst-456", status: "running" }
1599
- }
1600
- ]
1737
+ targets: ["react"],
1738
+ policy: {
1739
+ flags: ["workflow.designer.enabled"]
1601
1740
  }
1602
1741
  });
1603
- var TransitionWorkflowContract = defineCommand3({
1742
+ var WorkflowListPresentation = definePresentation({
1604
1743
  meta: {
1605
- key: "workflow.instance.transition",
1744
+ key: "workflow.definition.viewList",
1606
1745
  version: "1.0.0",
1607
- stability: "stable",
1608
- owners: [...OWNERS3],
1609
- tags: ["workflow", "instance", "transition", "state-machine"],
1610
- description: "Transition a workflow instance to the next step.",
1611
- goal: "Move workflow forward based on action.",
1612
- context: "Task completion, approval decisions."
1613
- },
1614
- io: {
1615
- input: TransitionInputModel,
1616
- output: TransitionResultModel
1746
+ title: "Workflow List",
1747
+ description: "List of workflow definitions with status and actions",
1748
+ domain: "workflow-system",
1749
+ owners: ["@workflow-team"],
1750
+ tags: ["workflow", "list", "admin"],
1751
+ stability: StabilityEnum.Experimental,
1752
+ goal: "Overview of all defined workflows",
1753
+ context: "Workflow management dashboard"
1617
1754
  },
1618
- policy: { auth: "user" },
1619
- sideEffects: {
1620
- emits: [
1621
- {
1622
- key: "workflow.step.exited",
1623
- version: "1.0.0",
1624
- when: "Step is exited",
1625
- payload: WorkflowInstanceModel
1626
- },
1627
- {
1628
- key: "workflow.step.entered",
1629
- version: "1.0.0",
1630
- when: "New step is entered",
1631
- payload: WorkflowInstanceModel
1632
- },
1633
- {
1634
- key: "workflow.instance.completed",
1635
- version: "1.0.0",
1636
- when: "Workflow reaches end",
1637
- payload: WorkflowInstanceModel
1638
- }
1639
- ],
1640
- audit: ["workflow.instance.transitioned"]
1755
+ source: {
1756
+ type: "component",
1757
+ framework: "react",
1758
+ componentKey: "WorkflowDefinitionList",
1759
+ props: WorkflowDefinitionModel
1641
1760
  },
1642
- acceptance: {
1643
- scenarios: [
1644
- {
1645
- key: "transition-workflow-happy-path",
1646
- given: ["Workflow instance is waiting at step"],
1647
- when: ["User provides input"],
1648
- then: ["Instance moves to next step"]
1649
- }
1650
- ],
1651
- examples: [
1652
- {
1653
- key: "complete-task",
1654
- input: {
1655
- instanceId: "inst-456",
1656
- action: "complete",
1657
- data: { approved: true }
1658
- },
1659
- output: { success: true, nextStep: "notify-hr" }
1660
- }
1661
- ]
1761
+ targets: ["react", "markdown"],
1762
+ policy: {
1763
+ flags: ["workflow.enabled"]
1662
1764
  }
1663
1765
  });
1664
- var PauseWorkflowContract = defineCommand3({
1766
+ var WorkflowDetailPresentation = definePresentation({
1665
1767
  meta: {
1666
- key: "workflow.instance.pause",
1768
+ key: "workflow.definition.detail",
1667
1769
  version: "1.0.0",
1668
- stability: "stable",
1669
- owners: [...OWNERS3],
1670
- tags: ["workflow", "instance", "pause"],
1671
- description: "Pause a running workflow instance.",
1672
- goal: "Temporarily halt workflow execution.",
1673
- context: "Administrative action, emergency stop."
1674
- },
1675
- io: {
1676
- input: defineSchemaModel8({
1677
- name: "PauseResumeInput",
1678
- fields: {
1679
- instanceId: {
1680
- type: ScalarTypeEnum8.String_unsecure(),
1681
- isOptional: false
1682
- },
1683
- reason: { type: ScalarTypeEnum8.String_unsecure(), isOptional: true }
1684
- }
1685
- }),
1686
- output: WorkflowInstanceModel
1770
+ title: "Workflow Details",
1771
+ description: "Detailed view of a workflow definition with steps",
1772
+ domain: "workflow-system",
1773
+ owners: ["@workflow-team"],
1774
+ tags: ["workflow", "detail"],
1775
+ stability: StabilityEnum.Experimental,
1776
+ goal: "Viewing technical details of a workflow definition",
1777
+ context: "Workflow inspection and debugging"
1687
1778
  },
1688
- policy: { auth: "user" },
1689
- sideEffects: {
1690
- emits: [
1691
- {
1692
- key: "workflow.instance.paused",
1693
- version: "1.0.0",
1694
- when: "Workflow is paused",
1695
- payload: WorkflowInstanceModel
1696
- }
1697
- ],
1698
- audit: ["workflow.instance.paused"]
1779
+ source: {
1780
+ type: "component",
1781
+ framework: "react",
1782
+ componentKey: "WorkflowDefinitionDetail",
1783
+ props: WorkflowDefinitionModel
1699
1784
  },
1700
- acceptance: {
1701
- scenarios: [
1702
- {
1703
- key: "pause-workflow-happy-path",
1704
- given: ["Workflow is running"],
1705
- when: ["Admin pauses workflow"],
1706
- then: ["Instance status becomes PAUSED"]
1707
- }
1708
- ],
1709
- examples: [
1710
- {
1711
- key: "pause-maintenance",
1712
- input: { instanceId: "inst-456", reason: "System maintenance" },
1713
- output: { id: "inst-456", status: "paused" }
1714
- }
1715
- ]
1785
+ targets: ["react", "markdown"],
1786
+ policy: {
1787
+ flags: ["workflow.enabled"]
1716
1788
  }
1717
1789
  });
1718
- var ResumeWorkflowContract = defineCommand3({
1790
+ var InstanceListPresentation = definePresentation({
1719
1791
  meta: {
1720
- key: "workflow.instance.resume",
1792
+ key: "workflow.instance.viewList",
1721
1793
  version: "1.0.0",
1722
- stability: "stable",
1723
- owners: [...OWNERS3],
1724
- tags: ["workflow", "instance", "resume"],
1725
- description: "Resume a paused workflow instance.",
1726
- goal: "Continue workflow execution.",
1727
- context: "Administrative action."
1794
+ title: "Instance List",
1795
+ description: "List of workflow instances with status and progress",
1796
+ domain: "workflow-system",
1797
+ owners: ["@workflow-team"],
1798
+ tags: ["workflow", "instance", "list"],
1799
+ stability: StabilityEnum.Experimental,
1800
+ goal: "Monitoring active and past workflow executions",
1801
+ context: "Operations monitoring"
1728
1802
  },
1729
- io: {
1730
- input: defineSchemaModel8({
1731
- name: "PauseResumeInput",
1732
- fields: {
1733
- instanceId: {
1734
- type: ScalarTypeEnum8.String_unsecure(),
1735
- isOptional: false
1736
- },
1737
- reason: { type: ScalarTypeEnum8.String_unsecure(), isOptional: true }
1738
- }
1739
- }),
1740
- output: WorkflowInstanceModel
1803
+ source: {
1804
+ type: "component",
1805
+ framework: "react",
1806
+ componentKey: "WorkflowInstanceList",
1807
+ props: WorkflowInstanceModel
1741
1808
  },
1742
- policy: { auth: "user" },
1743
- sideEffects: {
1744
- emits: [
1745
- {
1746
- key: "workflow.instance.resumed",
1747
- version: "1.0.0",
1748
- when: "Workflow is resumed",
1749
- payload: WorkflowInstanceModel
1750
- }
1751
- ],
1752
- audit: ["workflow.instance.resumed"]
1809
+ targets: ["react", "markdown"],
1810
+ policy: {
1811
+ flags: ["workflow.enabled"]
1812
+ }
1813
+ });
1814
+ var InstanceDetailPresentation = definePresentation({
1815
+ meta: {
1816
+ key: "workflow.instance.detail",
1817
+ version: "1.0.0",
1818
+ title: "Instance Details",
1819
+ description: "Detailed view of a workflow instance with step timeline",
1820
+ domain: "workflow-system",
1821
+ owners: ["@workflow-team"],
1822
+ tags: ["workflow", "instance", "detail", "timeline"],
1823
+ stability: StabilityEnum.Experimental,
1824
+ goal: "Detailed inspection of a specific workflow instance",
1825
+ context: "Case management and troubleshooting"
1753
1826
  },
1754
- acceptance: {
1755
- scenarios: [
1756
- {
1757
- key: "resume-workflow-happy-path",
1758
- given: ["Workflow is paused"],
1759
- when: ["Admin resumes workflow"],
1760
- then: ["Instance status becomes RUNNING"]
1761
- }
1762
- ],
1763
- examples: [
1764
- {
1765
- key: "resume-normal",
1766
- input: { instanceId: "inst-456", reason: "Issue resolved" },
1767
- output: { id: "inst-456", status: "running" }
1768
- }
1769
- ]
1827
+ source: {
1828
+ type: "component",
1829
+ framework: "react",
1830
+ componentKey: "WorkflowInstanceDetail",
1831
+ props: WorkflowInstanceModel
1832
+ },
1833
+ targets: ["react", "markdown"],
1834
+ policy: {
1835
+ flags: ["workflow.enabled"]
1770
1836
  }
1771
1837
  });
1772
- var CancelWorkflowContract = defineCommand3({
1838
+ var ProgressTrackerPresentation = definePresentation({
1773
1839
  meta: {
1774
- key: "workflow.instance.cancel",
1840
+ key: "workflow.instance.progress",
1775
1841
  version: "1.0.0",
1776
- stability: "stable",
1777
- owners: [...OWNERS3],
1778
- tags: ["workflow", "instance", "cancel"],
1779
- description: "Cancel a workflow instance.",
1780
- goal: "Terminate workflow without completion.",
1781
- context: "User request, system cancellation."
1842
+ title: "Progress Tracker",
1843
+ description: "Visual progress tracker showing current step in workflow",
1844
+ domain: "workflow-system",
1845
+ owners: ["@workflow-team"],
1846
+ tags: ["workflow", "progress", "widget"],
1847
+ stability: StabilityEnum.Experimental,
1848
+ goal: "Quick view of current progress for a workflow",
1849
+ context: "Embedded progress indicator in entity views"
1782
1850
  },
1783
- io: {
1784
- input: defineSchemaModel8({
1785
- name: "CancelWorkflowInput",
1786
- fields: {
1787
- instanceId: {
1788
- type: ScalarTypeEnum8.String_unsecure(),
1789
- isOptional: false
1790
- },
1791
- reason: {
1792
- type: ScalarTypeEnum8.String_unsecure(),
1793
- isOptional: false
1794
- }
1795
- }
1796
- }),
1797
- output: WorkflowInstanceModel
1851
+ source: {
1852
+ type: "component",
1853
+ framework: "react",
1854
+ componentKey: "WorkflowProgressTracker",
1855
+ props: WorkflowInstanceModel
1798
1856
  },
1799
- policy: { auth: "user" },
1800
- sideEffects: {
1801
- emits: [
1802
- {
1803
- key: "workflow.instance.cancelled",
1804
- version: "1.0.0",
1805
- when: "Workflow is cancelled",
1806
- payload: WorkflowInstanceModel
1807
- }
1808
- ],
1809
- audit: ["workflow.instance.cancelled"]
1810
- },
1811
- acceptance: {
1812
- scenarios: [
1813
- {
1814
- key: "cancel-workflow-happy-path",
1815
- given: ["Workflow is running"],
1816
- when: ["User cancels workflow"],
1817
- then: ["Instance status becomes CANCELLED"]
1818
- }
1819
- ],
1820
- examples: [
1821
- {
1822
- key: "cancel-mistake",
1823
- input: { instanceId: "inst-456", reason: "Created by mistake" },
1824
- output: { id: "inst-456", status: "cancelled" }
1825
- }
1826
- ]
1857
+ targets: ["react"],
1858
+ policy: {
1859
+ flags: ["workflow.enabled"]
1827
1860
  }
1828
1861
  });
1829
- var ListInstancesContract = defineQuery3({
1862
+ var ApprovalInboxPresentation = definePresentation({
1830
1863
  meta: {
1831
- key: "workflow.instance.list",
1864
+ key: "workflow.approval.inbox",
1832
1865
  version: "1.0.0",
1833
- stability: "stable",
1834
- owners: [...OWNERS3],
1835
- tags: ["workflow", "instance", "list"],
1836
- description: "List workflow instances with filtering.",
1837
- goal: "Browse and search running workflows.",
1838
- context: "Dashboard, monitoring."
1866
+ title: "Approval Inbox",
1867
+ description: "Inbox showing pending approval requests for current user",
1868
+ domain: "workflow-system",
1869
+ owners: ["@workflow-team"],
1870
+ tags: ["workflow", "approval", "inbox"],
1871
+ stability: StabilityEnum.Experimental,
1872
+ goal: "Managing personal workload of approval requests",
1873
+ context: "Personal task management"
1839
1874
  },
1840
- io: {
1841
- input: defineSchemaModel8({
1842
- name: "ListInstancesInput",
1843
- fields: {
1844
- workflowKey: {
1845
- type: ScalarTypeEnum8.String_unsecure(),
1846
- isOptional: true
1847
- },
1848
- status: { type: InstanceStatusEnum, isOptional: true },
1849
- referenceType: {
1850
- type: ScalarTypeEnum8.String_unsecure(),
1851
- isOptional: true
1852
- },
1853
- referenceId: {
1854
- type: ScalarTypeEnum8.String_unsecure(),
1855
- isOptional: true
1856
- },
1857
- triggeredBy: {
1858
- type: ScalarTypeEnum8.String_unsecure(),
1859
- isOptional: true
1860
- },
1861
- limit: {
1862
- type: ScalarTypeEnum8.Int_unsecure(),
1863
- isOptional: true,
1864
- defaultValue: 20
1865
- },
1866
- offset: {
1867
- type: ScalarTypeEnum8.Int_unsecure(),
1868
- isOptional: true,
1869
- defaultValue: 0
1870
- }
1871
- }
1872
- }),
1873
- output: defineSchemaModel8({
1874
- name: "ListInstancesOutput",
1875
- fields: {
1876
- instances: {
1877
- type: WorkflowInstanceModel,
1878
- isArray: true,
1879
- isOptional: false
1880
- },
1881
- total: { type: ScalarTypeEnum8.Int_unsecure(), isOptional: false }
1882
- }
1883
- })
1875
+ source: {
1876
+ type: "component",
1877
+ framework: "react",
1878
+ componentKey: "ApprovalInbox",
1879
+ props: ApprovalRequestModel
1884
1880
  },
1885
- policy: { auth: "user" },
1886
- acceptance: {
1887
- scenarios: [
1888
- {
1889
- key: "list-instances-happy-path",
1890
- given: ["Workflow instances exist"],
1891
- when: ["User lists instances"],
1892
- then: ["List of instances is returned"]
1893
- }
1894
- ],
1895
- examples: [
1896
- {
1897
- key: "list-running",
1898
- input: { status: "running", limit: 10 },
1899
- output: { instances: [], total: 5 }
1900
- }
1901
- ]
1881
+ targets: ["react", "markdown"],
1882
+ policy: {
1883
+ flags: ["workflow.approvals.enabled"]
1902
1884
  }
1903
1885
  });
1904
- var GetInstanceContract = defineQuery3({
1886
+ var ApprovalDetailPresentation = definePresentation({
1905
1887
  meta: {
1906
- key: "workflow.instance.get",
1888
+ key: "workflow.approval.detail",
1907
1889
  version: "1.0.0",
1908
- stability: "stable",
1909
- owners: [...OWNERS3],
1910
- tags: ["workflow", "instance", "get"],
1911
- description: "Get a workflow instance with details.",
1912
- goal: "View workflow instance details.",
1913
- context: "Instance detail view."
1890
+ title: "Approval Details",
1891
+ description: "Detailed approval request view with context and actions",
1892
+ domain: "workflow-system",
1893
+ owners: ["@workflow-team"],
1894
+ tags: ["workflow", "approval", "detail"],
1895
+ stability: StabilityEnum.Experimental,
1896
+ goal: "Decision support for an approval request",
1897
+ context: "Specific approval action"
1914
1898
  },
1915
- io: {
1916
- input: defineSchemaModel8({
1917
- name: "GetInstanceInput",
1918
- fields: {
1919
- instanceId: {
1920
- type: ScalarTypeEnum8.String_unsecure(),
1921
- isOptional: false
1922
- }
1923
- }
1924
- }),
1925
- output: WorkflowInstanceModel
1899
+ source: {
1900
+ type: "component",
1901
+ framework: "react",
1902
+ componentKey: "ApprovalRequestDetail",
1903
+ props: ApprovalRequestModel
1926
1904
  },
1927
- policy: { auth: "user" },
1928
- acceptance: {
1929
- scenarios: [
1930
- {
1931
- key: "get-instance-happy-path",
1932
- given: ["Instance exists"],
1933
- when: ["User requests instance details"],
1934
- then: ["Instance details are returned"]
1935
- }
1936
- ],
1937
- examples: [
1938
- {
1939
- key: "get-details",
1940
- input: { instanceId: "inst-456" },
1941
- output: { id: "inst-456", workflowKey: "onboarding-v1" }
1942
- }
1943
- ]
1944
- }
1945
- });
1946
-
1947
- // src/instance/instance.event.ts
1948
- import { defineEvent as defineEvent3 } from "@contractspec/lib.contracts-spec";
1949
- import { ScalarTypeEnum as ScalarTypeEnum9, defineSchemaModel as defineSchemaModel9 } from "@contractspec/lib.schema";
1950
- var InstanceEventPayload = defineSchemaModel9({
1951
- name: "InstanceEventPayload",
1952
- description: "Base payload for instance events",
1953
- fields: {
1954
- instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1955
- workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1956
- workflowKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1957
- status: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1958
- referenceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1959
- referenceType: {
1960
- type: ScalarTypeEnum9.String_unsecure(),
1961
- isOptional: true
1962
- },
1963
- triggeredBy: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1964
- organizationId: {
1965
- type: ScalarTypeEnum9.String_unsecure(),
1966
- isOptional: false
1967
- },
1968
- timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1969
- }
1970
- });
1971
- var StepTransitionPayload = defineSchemaModel9({
1972
- name: "StepTransitionEventPayload",
1973
- description: "Payload for step transition events",
1974
- fields: {
1975
- instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1976
- workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1977
- fromStepKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1978
- toStepKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1979
- action: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1980
- executedBy: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1981
- timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1982
- }
1983
- });
1984
- var InstanceCompletedPayload = defineSchemaModel9({
1985
- name: "InstanceCompletedEventPayload",
1986
- description: "Payload when instance completes",
1987
- fields: {
1988
- instanceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1989
- workflowId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1990
- workflowKey: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1991
- outcome: { type: ScalarTypeEnum9.String_unsecure(), isOptional: false },
1992
- referenceId: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
1993
- referenceType: {
1994
- type: ScalarTypeEnum9.String_unsecure(),
1995
- isOptional: true
1996
- },
1997
- duration: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false },
1998
- timestamp: { type: ScalarTypeEnum9.DateTime(), isOptional: false }
1905
+ targets: ["react", "markdown"],
1906
+ policy: {
1907
+ flags: ["workflow.approvals.enabled"]
1999
1908
  }
2000
1909
  });
2001
- var InstanceStartedEvent = defineEvent3({
1910
+ var ApprovalFormPresentation = definePresentation({
2002
1911
  meta: {
2003
- key: "workflow.instance.started",
1912
+ key: "workflow.approval.form",
2004
1913
  version: "1.0.0",
2005
- description: "A new workflow instance has been started.",
2006
- stability: "stable",
1914
+ title: "Approval Form",
1915
+ description: "Form for submitting approval decisions",
1916
+ domain: "workflow-system",
2007
1917
  owners: ["@workflow-team"],
2008
- tags: ["workflow", "instance", "started"]
1918
+ tags: ["workflow", "approval", "form"],
1919
+ stability: StabilityEnum.Experimental,
1920
+ goal: "Submitting a decision on an approval request",
1921
+ context: "Approval decision dialog"
2009
1922
  },
2010
- payload: InstanceEventPayload
2011
- });
2012
- var StepEnteredEvent = defineEvent3({
2013
- meta: {
2014
- key: "workflow.step.entered",
2015
- version: "1.0.0",
2016
- description: "A workflow instance has entered a new step.",
2017
- stability: "stable",
2018
- owners: ["@workflow-team"],
2019
- tags: ["workflow", "step", "entered"]
1923
+ source: {
1924
+ type: "component",
1925
+ framework: "react",
1926
+ componentKey: "ApprovalDecisionForm"
2020
1927
  },
2021
- payload: StepTransitionPayload
1928
+ targets: ["react"],
1929
+ policy: {
1930
+ flags: ["workflow.approvals.enabled"]
1931
+ }
2022
1932
  });
2023
- var StepExitedEvent = defineEvent3({
1933
+ var PendingApprovalsBadgePresentation = definePresentation({
2024
1934
  meta: {
2025
- key: "workflow.step.exited",
1935
+ key: "workflow.approval.badge",
2026
1936
  version: "1.0.0",
2027
- description: "A workflow instance has exited a step.",
2028
- stability: "stable",
1937
+ title: "Pending Approvals Badge",
1938
+ description: "Badge showing count of pending approvals",
1939
+ domain: "workflow-system",
2029
1940
  owners: ["@workflow-team"],
2030
- tags: ["workflow", "step", "exited"]
1941
+ tags: ["workflow", "approval", "badge", "widget"],
1942
+ stability: StabilityEnum.Experimental,
1943
+ goal: "Visual notification of pending approvals",
1944
+ context: "Global navigation or sidebar"
2031
1945
  },
2032
- payload: StepTransitionPayload
2033
- });
2034
- var InstanceCompletedEvent = defineEvent3({
2035
- meta: {
2036
- key: "workflow.instance.completed",
2037
- version: "1.0.0",
2038
- description: "A workflow instance has completed.",
2039
- stability: "stable",
2040
- owners: ["@workflow-team"],
2041
- tags: ["workflow", "instance", "completed"]
1946
+ source: {
1947
+ type: "component",
1948
+ framework: "react",
1949
+ componentKey: "PendingApprovalsBadge"
2042
1950
  },
2043
- payload: InstanceCompletedPayload
1951
+ targets: ["react"],
1952
+ policy: {
1953
+ flags: ["workflow.approvals.enabled"]
1954
+ }
2044
1955
  });
2045
- var InstanceCancelledEvent = defineEvent3({
1956
+ var WorkflowMetricsPresentation = definePresentation({
2046
1957
  meta: {
2047
- key: "workflow.instance.cancelled",
1958
+ key: "workflow.metrics",
2048
1959
  version: "1.0.0",
2049
- description: "A workflow instance has been cancelled.",
2050
- stability: "stable",
1960
+ title: "Workflow Metrics",
1961
+ description: "Dashboard widget showing workflow metrics and statistics",
1962
+ domain: "workflow-system",
2051
1963
  owners: ["@workflow-team"],
2052
- tags: ["workflow", "instance", "cancelled"]
2053
- },
2054
- payload: InstanceEventPayload
2055
- });
2056
- var InstancePausedEvent = defineEvent3({
2057
- meta: {
2058
- key: "workflow.instance.paused",
2059
- version: "1.0.0",
2060
- description: "A workflow instance has been paused.",
2061
- stability: "stable",
2062
- owners: ["@workflow-team"],
2063
- tags: ["workflow", "instance", "paused"]
2064
- },
2065
- payload: InstanceEventPayload
2066
- });
2067
- var InstanceResumedEvent = defineEvent3({
2068
- meta: {
2069
- key: "workflow.instance.resumed",
2070
- version: "1.0.0",
2071
- description: "A workflow instance has been resumed.",
2072
- stability: "stable",
2073
- owners: ["@workflow-team"],
2074
- tags: ["workflow", "instance", "resumed"]
2075
- },
2076
- payload: InstanceEventPayload
2077
- });
2078
- var InstanceFailedEvent = defineEvent3({
2079
- meta: {
2080
- key: "workflow.instance.failed",
2081
- version: "1.0.0",
2082
- description: "A workflow instance has failed.",
2083
- stability: "stable",
2084
- owners: ["@workflow-team"],
2085
- tags: ["workflow", "instance", "failed"]
2086
- },
2087
- payload: InstanceEventPayload
2088
- });
2089
- var InstanceTimedOutEvent = defineEvent3({
2090
- meta: {
2091
- key: "workflow.instance.timedOut",
2092
- version: "1.0.0",
2093
- description: "A workflow instance has timed out.",
2094
- stability: "stable",
2095
- owners: ["@workflow-team"],
2096
- tags: ["workflow", "instance", "timeout"]
2097
- },
2098
- payload: InstanceEventPayload
2099
- });
2100
- // src/presentations/index.ts
2101
- import {
2102
- definePresentation,
2103
- StabilityEnum
2104
- } from "@contractspec/lib.contracts-spec";
2105
- var WorkflowDesignerPresentation = definePresentation({
2106
- meta: {
2107
- key: "workflow.designer",
2108
- version: "1.0.0",
2109
- title: "Workflow Designer",
2110
- description: "Visual workflow designer with drag-and-drop steps",
2111
- domain: "workflow-system",
2112
- owners: ["@workflow-team"],
2113
- tags: ["workflow", "designer", "admin"],
2114
- stability: StabilityEnum.Experimental,
2115
- goal: "Building and modifying workflow definitions",
2116
- context: "Workflow administration and setup"
2117
- },
2118
- source: {
2119
- type: "component",
2120
- framework: "react",
2121
- componentKey: "WorkflowDesigner",
2122
- props: WorkflowDefinitionModel
2123
- },
2124
- targets: ["react"],
2125
- policy: {
2126
- flags: ["workflow.designer.enabled"]
2127
- }
2128
- });
2129
- var WorkflowListPresentation = definePresentation({
2130
- meta: {
2131
- key: "workflow.definition.viewList",
2132
- version: "1.0.0",
2133
- title: "Workflow List",
2134
- description: "List of workflow definitions with status and actions",
2135
- domain: "workflow-system",
2136
- owners: ["@workflow-team"],
2137
- tags: ["workflow", "list", "admin"],
1964
+ tags: ["workflow", "metrics", "dashboard"],
2138
1965
  stability: StabilityEnum.Experimental,
2139
- goal: "Overview of all defined workflows",
2140
- context: "Workflow management dashboard"
1966
+ goal: "Monitoring throughput and bottlenecks",
1967
+ context: "System performance dashboard"
2141
1968
  },
2142
1969
  source: {
2143
1970
  type: "component",
2144
1971
  framework: "react",
2145
- componentKey: "WorkflowDefinitionList",
2146
- props: WorkflowDefinitionModel
1972
+ componentKey: "WorkflowMetricsDashboard"
2147
1973
  },
2148
1974
  targets: ["react", "markdown"],
2149
1975
  policy: {
2150
- flags: ["workflow.enabled"]
1976
+ flags: ["workflow.metrics.enabled"]
2151
1977
  }
2152
1978
  });
2153
- var WorkflowDetailPresentation = definePresentation({
2154
- meta: {
2155
- key: "workflow.definition.detail",
2156
- version: "1.0.0",
2157
- title: "Workflow Details",
2158
- description: "Detailed view of a workflow definition with steps",
2159
- domain: "workflow-system",
2160
- owners: ["@workflow-team"],
2161
- tags: ["workflow", "detail"],
2162
- stability: StabilityEnum.Experimental,
2163
- goal: "Viewing technical details of a workflow definition",
2164
- context: "Workflow inspection and debugging"
1979
+ var WorkflowSystemPresentations = {
1980
+ WorkflowDesignerPresentation,
1981
+ WorkflowListPresentation,
1982
+ WorkflowDetailPresentation,
1983
+ InstanceListPresentation,
1984
+ InstanceDetailPresentation,
1985
+ ProgressTrackerPresentation,
1986
+ ApprovalInboxPresentation,
1987
+ ApprovalDetailPresentation,
1988
+ ApprovalFormPresentation,
1989
+ PendingApprovalsBadgePresentation,
1990
+ WorkflowMetricsPresentation
1991
+ };
1992
+ // src/ui/hooks/useWorkflowList.ts
1993
+ import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
1994
+ import { useCallback, useEffect, useState } from "react";
1995
+ "use client";
1996
+ function useWorkflowList(projectId = "local-project") {
1997
+ const { handlers } = useTemplateRuntime();
1998
+ const workflow = handlers.workflow;
1999
+ const [definitions, setDefinitions] = useState([]);
2000
+ const [instances, setInstances] = useState([]);
2001
+ const [loading, setLoading] = useState(true);
2002
+ const [error, setError] = useState(null);
2003
+ const fetchData = useCallback(async () => {
2004
+ try {
2005
+ setLoading(true);
2006
+ setError(null);
2007
+ const [defResult, instResult] = await Promise.all([
2008
+ workflow.listDefinitions({ projectId, limit: 100 }),
2009
+ workflow.listInstances({ projectId, limit: 100 })
2010
+ ]);
2011
+ setDefinitions(defResult.definitions);
2012
+ setInstances(instResult.instances);
2013
+ } catch (err) {
2014
+ setError(err instanceof Error ? err : new Error("Failed to load workflows"));
2015
+ } finally {
2016
+ setLoading(false);
2017
+ }
2018
+ }, [handlers, projectId]);
2019
+ useEffect(() => {
2020
+ fetchData();
2021
+ }, [fetchData]);
2022
+ const stats = {
2023
+ totalDefinitions: definitions.length,
2024
+ activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
2025
+ totalInstances: instances.length,
2026
+ pendingInstances: instances.filter((i) => i.status === "PENDING").length,
2027
+ completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
2028
+ rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
2029
+ };
2030
+ return {
2031
+ definitions,
2032
+ instances,
2033
+ loading,
2034
+ error,
2035
+ stats,
2036
+ refetch: fetchData
2037
+ };
2038
+ }
2039
+
2040
+ // src/ui/hooks/index.ts
2041
+ "use client";
2042
+
2043
+ // src/ui/renderers/workflow.markdown.ts
2044
+ var mockWorkflowDefinitions = [
2045
+ {
2046
+ id: "wf-1",
2047
+ name: "Purchase Approval",
2048
+ type: "APPROVAL",
2049
+ steps: [
2050
+ {
2051
+ id: "s1",
2052
+ name: "Manager Review",
2053
+ order: 1,
2054
+ requiredRoles: ["manager"]
2055
+ },
2056
+ {
2057
+ id: "s2",
2058
+ name: "Finance Review",
2059
+ order: 2,
2060
+ requiredRoles: ["finance"]
2061
+ },
2062
+ { id: "s3", name: "Final Approval", order: 3, requiredRoles: ["admin"] }
2063
+ ],
2064
+ status: "ACTIVE"
2165
2065
  },
2166
- source: {
2167
- type: "component",
2168
- framework: "react",
2169
- componentKey: "WorkflowDefinitionDetail",
2170
- props: WorkflowDefinitionModel
2066
+ {
2067
+ id: "wf-2",
2068
+ name: "Leave Request",
2069
+ type: "APPROVAL",
2070
+ steps: [
2071
+ {
2072
+ id: "s1",
2073
+ name: "Supervisor Approval",
2074
+ order: 1,
2075
+ requiredRoles: ["supervisor"]
2076
+ },
2077
+ { id: "s2", name: "HR Review", order: 2, requiredRoles: ["hr"] }
2078
+ ],
2079
+ status: "ACTIVE"
2171
2080
  },
2172
- targets: ["react", "markdown"],
2173
- policy: {
2174
- flags: ["workflow.enabled"]
2081
+ {
2082
+ id: "wf-3",
2083
+ name: "Document Review",
2084
+ type: "SEQUENTIAL",
2085
+ steps: [
2086
+ { id: "s1", name: "Author Review", order: 1, requiredRoles: ["author"] },
2087
+ { id: "s2", name: "Peer Review", order: 2, requiredRoles: ["reviewer"] },
2088
+ { id: "s3", name: "Publish", order: 3, requiredRoles: ["publisher"] }
2089
+ ],
2090
+ status: "DRAFT"
2175
2091
  }
2176
- });
2177
- var InstanceListPresentation = definePresentation({
2178
- meta: {
2179
- key: "workflow.instance.viewList",
2180
- version: "1.0.0",
2181
- title: "Instance List",
2182
- description: "List of workflow instances with status and progress",
2183
- domain: "workflow-system",
2184
- owners: ["@workflow-team"],
2185
- tags: ["workflow", "instance", "list"],
2186
- stability: StabilityEnum.Experimental,
2187
- goal: "Monitoring active and past workflow executions",
2188
- context: "Operations monitoring"
2092
+ ];
2093
+ var mockWorkflowInstances = [
2094
+ {
2095
+ id: "inst-1",
2096
+ definitionId: "wf-1",
2097
+ definitionName: "Purchase Approval",
2098
+ status: "IN_PROGRESS",
2099
+ currentStepId: "s2",
2100
+ startedAt: "2024-01-15T10:00:00Z",
2101
+ requestedBy: "John Doe"
2189
2102
  },
2190
- source: {
2191
- type: "component",
2192
- framework: "react",
2193
- componentKey: "WorkflowInstanceList",
2194
- props: WorkflowInstanceModel
2103
+ {
2104
+ id: "inst-2",
2105
+ definitionId: "wf-1",
2106
+ definitionName: "Purchase Approval",
2107
+ status: "COMPLETED",
2108
+ currentStepId: null,
2109
+ startedAt: "2024-01-10T09:00:00Z",
2110
+ completedAt: "2024-01-12T14:00:00Z",
2111
+ requestedBy: "Jane Smith"
2195
2112
  },
2196
- targets: ["react", "markdown"],
2197
- policy: {
2198
- flags: ["workflow.enabled"]
2199
- }
2200
- });
2201
- var InstanceDetailPresentation = definePresentation({
2202
- meta: {
2203
- key: "workflow.instance.detail",
2204
- version: "1.0.0",
2205
- title: "Instance Details",
2206
- description: "Detailed view of a workflow instance with step timeline",
2207
- domain: "workflow-system",
2208
- owners: ["@workflow-team"],
2209
- tags: ["workflow", "instance", "detail", "timeline"],
2210
- stability: StabilityEnum.Experimental,
2211
- goal: "Detailed inspection of a specific workflow instance",
2212
- context: "Case management and troubleshooting"
2213
- },
2214
- source: {
2215
- type: "component",
2216
- framework: "react",
2217
- componentKey: "WorkflowInstanceDetail",
2218
- props: WorkflowInstanceModel
2219
- },
2220
- targets: ["react", "markdown"],
2221
- policy: {
2222
- flags: ["workflow.enabled"]
2113
+ {
2114
+ id: "inst-3",
2115
+ definitionId: "wf-2",
2116
+ definitionName: "Leave Request",
2117
+ status: "PENDING",
2118
+ currentStepId: "s1",
2119
+ startedAt: "2024-01-16T08:00:00Z",
2120
+ requestedBy: "Bob Wilson"
2223
2121
  }
2224
- });
2225
- var ProgressTrackerPresentation = definePresentation({
2226
- meta: {
2227
- key: "workflow.instance.progress",
2228
- version: "1.0.0",
2229
- title: "Progress Tracker",
2230
- description: "Visual progress tracker showing current step in workflow",
2231
- domain: "workflow-system",
2232
- owners: ["@workflow-team"],
2233
- tags: ["workflow", "progress", "widget"],
2234
- stability: StabilityEnum.Experimental,
2235
- goal: "Quick view of current progress for a workflow",
2236
- context: "Embedded progress indicator in entity views"
2237
- },
2238
- source: {
2239
- type: "component",
2240
- framework: "react",
2241
- componentKey: "WorkflowProgressTracker",
2242
- props: WorkflowInstanceModel
2243
- },
2244
- targets: ["react"],
2245
- policy: {
2246
- flags: ["workflow.enabled"]
2122
+ ];
2123
+ var workflowDashboardMarkdownRenderer = {
2124
+ target: "markdown",
2125
+ render: async (desc) => {
2126
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDashboard") {
2127
+ throw new Error("workflowDashboardMarkdownRenderer: not WorkflowDashboard");
2128
+ }
2129
+ const definitions = mockWorkflowDefinitions;
2130
+ const instances = mockWorkflowInstances;
2131
+ const activeDefinitions = definitions.filter((d) => d.status === "ACTIVE");
2132
+ const pendingInstances = instances.filter((i) => i.status === "PENDING");
2133
+ const inProgressInstances = instances.filter((i) => i.status === "IN_PROGRESS");
2134
+ const completedInstances = instances.filter((i) => i.status === "COMPLETED");
2135
+ const lines = [
2136
+ "# Workflow Dashboard",
2137
+ "",
2138
+ "> Workflow and approval management overview",
2139
+ "",
2140
+ "## Summary",
2141
+ "",
2142
+ "| Metric | Value |",
2143
+ "|--------|-------|",
2144
+ `| Active Workflows | ${activeDefinitions.length} |`,
2145
+ `| Pending Approvals | ${pendingInstances.length} |`,
2146
+ `| In Progress | ${inProgressInstances.length} |`,
2147
+ `| Completed | ${completedInstances.length} |`,
2148
+ "",
2149
+ "## Active Workflow Definitions",
2150
+ ""
2151
+ ];
2152
+ if (activeDefinitions.length === 0) {
2153
+ lines.push("_No active workflow definitions._");
2154
+ } else {
2155
+ lines.push("| Name | Type | Steps | Status |");
2156
+ lines.push("|------|------|-------|--------|");
2157
+ for (const def of activeDefinitions) {
2158
+ lines.push(`| ${def.name} | ${def.type} | ${def.steps.length} | ${def.status} |`);
2159
+ }
2160
+ }
2161
+ lines.push("");
2162
+ lines.push("## Recent Instances");
2163
+ lines.push("");
2164
+ if (instances.length === 0) {
2165
+ lines.push("_No workflow instances._");
2166
+ } else {
2167
+ lines.push("| Workflow | Requested By | Status | Started |");
2168
+ lines.push("|----------|--------------|--------|---------|");
2169
+ for (const inst of instances.slice(0, 10)) {
2170
+ const startedDate = new Date(inst.startedAt).toLocaleDateString();
2171
+ lines.push(`| ${inst.definitionName} | ${inst.requestedBy} | ${inst.status} | ${startedDate} |`);
2172
+ }
2173
+ }
2174
+ return {
2175
+ mimeType: "text/markdown",
2176
+ body: lines.join(`
2177
+ `)
2178
+ };
2247
2179
  }
2248
- });
2249
- var ApprovalInboxPresentation = definePresentation({
2250
- meta: {
2251
- key: "workflow.approval.inbox",
2252
- version: "1.0.0",
2253
- title: "Approval Inbox",
2254
- description: "Inbox showing pending approval requests for current user",
2255
- domain: "workflow-system",
2256
- owners: ["@workflow-team"],
2257
- tags: ["workflow", "approval", "inbox"],
2258
- stability: StabilityEnum.Experimental,
2259
- goal: "Managing personal workload of approval requests",
2260
- context: "Personal task management"
2261
- },
2262
- source: {
2263
- type: "component",
2264
- framework: "react",
2265
- componentKey: "ApprovalInbox",
2266
- props: ApprovalRequestModel
2267
- },
2268
- targets: ["react", "markdown"],
2269
- policy: {
2270
- flags: ["workflow.approvals.enabled"]
2180
+ };
2181
+ var workflowDefinitionListMarkdownRenderer = {
2182
+ target: "markdown",
2183
+ render: async (desc) => {
2184
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDefinitionList") {
2185
+ throw new Error("workflowDefinitionListMarkdownRenderer: not WorkflowDefinitionList");
2186
+ }
2187
+ const definitions = mockWorkflowDefinitions;
2188
+ const lines = [
2189
+ "# Workflow Definitions",
2190
+ "",
2191
+ "> Configure automated approval and process workflows",
2192
+ ""
2193
+ ];
2194
+ for (const def of definitions) {
2195
+ lines.push(`## ${def.name}`);
2196
+ lines.push("");
2197
+ lines.push(`**Type:** ${def.type} | **Status:** ${def.status}`);
2198
+ lines.push("");
2199
+ lines.push("### Steps");
2200
+ lines.push("");
2201
+ for (const step of def.steps) {
2202
+ lines.push(`${step.order}. **${step.name}** - Roles: ${step.requiredRoles.join(", ")}`);
2203
+ }
2204
+ lines.push("");
2205
+ }
2206
+ return {
2207
+ mimeType: "text/markdown",
2208
+ body: lines.join(`
2209
+ `)
2210
+ };
2271
2211
  }
2272
- });
2273
- var ApprovalDetailPresentation = definePresentation({
2274
- meta: {
2275
- key: "workflow.approval.detail",
2276
- version: "1.0.0",
2277
- title: "Approval Details",
2278
- description: "Detailed approval request view with context and actions",
2279
- domain: "workflow-system",
2280
- owners: ["@workflow-team"],
2281
- tags: ["workflow", "approval", "detail"],
2282
- stability: StabilityEnum.Experimental,
2283
- goal: "Decision support for an approval request",
2284
- context: "Specific approval action"
2285
- },
2286
- source: {
2287
- type: "component",
2288
- framework: "react",
2289
- componentKey: "ApprovalRequestDetail",
2290
- props: ApprovalRequestModel
2291
- },
2292
- targets: ["react", "markdown"],
2293
- policy: {
2294
- flags: ["workflow.approvals.enabled"]
2212
+ };
2213
+ var workflowInstanceDetailMarkdownRenderer = {
2214
+ target: "markdown",
2215
+ render: async (desc) => {
2216
+ if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowInstanceDetail") {
2217
+ throw new Error("workflowInstanceDetailMarkdownRenderer: not WorkflowInstanceDetail");
2218
+ }
2219
+ const instance = mockWorkflowInstances[0];
2220
+ if (!instance) {
2221
+ return {
2222
+ mimeType: "text/markdown",
2223
+ body: `# No Workflow Instances
2224
+
2225
+ No workflow instances available.`
2226
+ };
2227
+ }
2228
+ const definition = mockWorkflowDefinitions.find((d) => d.id === instance.definitionId);
2229
+ const lines = [
2230
+ `# Workflow: ${instance.definitionName}`,
2231
+ "",
2232
+ `**Instance ID:** ${instance.id}`,
2233
+ `**Status:** ${instance.status}`,
2234
+ `**Requested By:** ${instance.requestedBy}`,
2235
+ `**Started:** ${new Date(instance.startedAt).toLocaleString()}`,
2236
+ "",
2237
+ "## Steps Progress",
2238
+ ""
2239
+ ];
2240
+ if (definition) {
2241
+ for (const step of definition.steps) {
2242
+ const isCurrent = step.id === instance.currentStepId;
2243
+ const isCompleted = definition.steps.indexOf(step) < definition.steps.findIndex((s) => s.id === instance.currentStepId);
2244
+ let status = "\u2B1C Pending";
2245
+ if (isCompleted)
2246
+ status = "\u2705 Completed";
2247
+ if (isCurrent)
2248
+ status = "\uD83D\uDD04 In Progress";
2249
+ lines.push(`- ${status} **${step.name}**`);
2250
+ }
2251
+ }
2252
+ lines.push("");
2253
+ lines.push("## Actions");
2254
+ lines.push("");
2255
+ lines.push("- **Approve** - Move to next step");
2256
+ lines.push("- **Reject** - Reject and return");
2257
+ lines.push("- **Delegate** - Assign to another approver");
2258
+ return {
2259
+ mimeType: "text/markdown",
2260
+ body: lines.join(`
2261
+ `)
2262
+ };
2295
2263
  }
2296
- });
2297
- var ApprovalFormPresentation = definePresentation({
2298
- meta: {
2299
- key: "workflow.approval.form",
2300
- version: "1.0.0",
2301
- title: "Approval Form",
2302
- description: "Form for submitting approval decisions",
2303
- domain: "workflow-system",
2304
- owners: ["@workflow-team"],
2305
- tags: ["workflow", "approval", "form"],
2306
- stability: StabilityEnum.Experimental,
2307
- goal: "Submitting a decision on an approval request",
2308
- context: "Approval decision dialog"
2309
- },
2310
- source: {
2311
- type: "component",
2312
- framework: "react",
2313
- componentKey: "ApprovalDecisionForm"
2314
- },
2315
- targets: ["react"],
2316
- policy: {
2317
- flags: ["workflow.approvals.enabled"]
2318
- }
2319
- });
2320
- var PendingApprovalsBadgePresentation = definePresentation({
2321
- meta: {
2322
- key: "workflow.approval.badge",
2323
- version: "1.0.0",
2324
- title: "Pending Approvals Badge",
2325
- description: "Badge showing count of pending approvals",
2326
- domain: "workflow-system",
2327
- owners: ["@workflow-team"],
2328
- tags: ["workflow", "approval", "badge", "widget"],
2329
- stability: StabilityEnum.Experimental,
2330
- goal: "Visual notification of pending approvals",
2331
- context: "Global navigation or sidebar"
2332
- },
2333
- source: {
2334
- type: "component",
2335
- framework: "react",
2336
- componentKey: "PendingApprovalsBadge"
2337
- },
2338
- targets: ["react"],
2339
- policy: {
2340
- flags: ["workflow.approvals.enabled"]
2264
+ };
2265
+ // src/ui/WorkflowDashboard.tsx
2266
+ import {
2267
+ Button,
2268
+ ErrorState,
2269
+ LoaderBlock,
2270
+ StatCard,
2271
+ StatCardGroup
2272
+ } from "@contractspec/lib.design-system";
2273
+ import { useState as useState2 } from "react";
2274
+ import { jsxDEV } from "react/jsx-dev-runtime";
2275
+ "use client";
2276
+ var STATUS_COLORS = {
2277
+ ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2278
+ DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
2279
+ ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
2280
+ PENDING: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
2281
+ IN_PROGRESS: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
2282
+ COMPLETED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2283
+ REJECTED: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
2284
+ CANCELLED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
2285
+ };
2286
+ function WorkflowDashboard() {
2287
+ const [activeTab, setActiveTab] = useState2("definitions");
2288
+ const { definitions, instances, loading, error, stats, refetch } = useWorkflowList();
2289
+ const tabs = [
2290
+ { id: "definitions", label: "Definitions", icon: "\uD83D\uDCCB" },
2291
+ { id: "instances", label: "Instances", icon: "\uD83D\uDD04" }
2292
+ ];
2293
+ if (loading) {
2294
+ return /* @__PURE__ */ jsxDEV(LoaderBlock, {
2295
+ label: "Loading Workflows..."
2296
+ }, undefined, false, undefined, this);
2341
2297
  }
2342
- });
2343
- var WorkflowMetricsPresentation = definePresentation({
2344
- meta: {
2345
- key: "workflow.metrics",
2346
- version: "1.0.0",
2347
- title: "Workflow Metrics",
2348
- description: "Dashboard widget showing workflow metrics and statistics",
2349
- domain: "workflow-system",
2350
- owners: ["@workflow-team"],
2351
- tags: ["workflow", "metrics", "dashboard"],
2352
- stability: StabilityEnum.Experimental,
2353
- goal: "Monitoring throughput and bottlenecks",
2354
- context: "System performance dashboard"
2355
- },
2356
- source: {
2357
- type: "component",
2358
- framework: "react",
2359
- componentKey: "WorkflowMetricsDashboard"
2360
- },
2361
- targets: ["react", "markdown"],
2362
- policy: {
2363
- flags: ["workflow.metrics.enabled"]
2298
+ if (error) {
2299
+ return /* @__PURE__ */ jsxDEV(ErrorState, {
2300
+ title: "Failed to load Workflows",
2301
+ description: error.message,
2302
+ onRetry: refetch,
2303
+ retryLabel: "Retry"
2304
+ }, undefined, false, undefined, this);
2305
+ }
2306
+ return /* @__PURE__ */ jsxDEV("div", {
2307
+ className: "space-y-6",
2308
+ children: [
2309
+ /* @__PURE__ */ jsxDEV("div", {
2310
+ className: "flex items-center justify-between",
2311
+ children: [
2312
+ /* @__PURE__ */ jsxDEV("h2", {
2313
+ className: "font-bold text-2xl",
2314
+ children: "Workflow System"
2315
+ }, undefined, false, undefined, this),
2316
+ /* @__PURE__ */ jsxDEV(Button, {
2317
+ onClick: () => alert("Create workflow modal"),
2318
+ children: [
2319
+ /* @__PURE__ */ jsxDEV("span", {
2320
+ className: "mr-2",
2321
+ children: "+"
2322
+ }, undefined, false, undefined, this),
2323
+ " New Workflow"
2324
+ ]
2325
+ }, undefined, true, undefined, this)
2326
+ ]
2327
+ }, undefined, true, undefined, this),
2328
+ /* @__PURE__ */ jsxDEV(StatCardGroup, {
2329
+ children: [
2330
+ /* @__PURE__ */ jsxDEV(StatCard, {
2331
+ label: "Workflows",
2332
+ value: stats.totalDefinitions,
2333
+ hint: `${stats.activeDefinitions} active`
2334
+ }, undefined, false, undefined, this),
2335
+ /* @__PURE__ */ jsxDEV(StatCard, {
2336
+ label: "Instances",
2337
+ value: stats.totalInstances,
2338
+ hint: "total runs"
2339
+ }, undefined, false, undefined, this),
2340
+ /* @__PURE__ */ jsxDEV(StatCard, {
2341
+ label: "Pending",
2342
+ value: stats.pendingInstances,
2343
+ hint: "awaiting action"
2344
+ }, undefined, false, undefined, this),
2345
+ /* @__PURE__ */ jsxDEV(StatCard, {
2346
+ label: "Completed",
2347
+ value: stats.completedInstances,
2348
+ hint: "finished"
2349
+ }, undefined, false, undefined, this)
2350
+ ]
2351
+ }, undefined, true, undefined, this),
2352
+ /* @__PURE__ */ jsxDEV("nav", {
2353
+ className: "flex gap-1 rounded-lg bg-muted p-1",
2354
+ role: "tablist",
2355
+ children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
2356
+ type: "button",
2357
+ role: "tab",
2358
+ "aria-selected": activeTab === tab.id,
2359
+ onClick: () => setActiveTab(tab.id),
2360
+ className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 font-medium text-sm transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
2361
+ children: [
2362
+ /* @__PURE__ */ jsxDEV("span", {
2363
+ children: tab.icon
2364
+ }, undefined, false, undefined, this),
2365
+ tab.label
2366
+ ]
2367
+ }, tab.id, true, undefined, this))
2368
+ }, undefined, false, undefined, this),
2369
+ /* @__PURE__ */ jsxDEV("div", {
2370
+ className: "min-h-[400px]",
2371
+ role: "tabpanel",
2372
+ children: [
2373
+ activeTab === "definitions" && /* @__PURE__ */ jsxDEV("div", {
2374
+ className: "rounded-lg border border-border",
2375
+ children: /* @__PURE__ */ jsxDEV("table", {
2376
+ className: "w-full",
2377
+ children: [
2378
+ /* @__PURE__ */ jsxDEV("thead", {
2379
+ className: "border-border border-b bg-muted/30",
2380
+ children: /* @__PURE__ */ jsxDEV("tr", {
2381
+ children: [
2382
+ /* @__PURE__ */ jsxDEV("th", {
2383
+ className: "px-4 py-3 text-left font-medium text-sm",
2384
+ children: "Name"
2385
+ }, undefined, false, undefined, this),
2386
+ /* @__PURE__ */ jsxDEV("th", {
2387
+ className: "px-4 py-3 text-left font-medium text-sm",
2388
+ children: "Type"
2389
+ }, undefined, false, undefined, this),
2390
+ /* @__PURE__ */ jsxDEV("th", {
2391
+ className: "px-4 py-3 text-left font-medium text-sm",
2392
+ children: "Status"
2393
+ }, undefined, false, undefined, this),
2394
+ /* @__PURE__ */ jsxDEV("th", {
2395
+ className: "px-4 py-3 text-left font-medium text-sm",
2396
+ children: "Created"
2397
+ }, undefined, false, undefined, this)
2398
+ ]
2399
+ }, undefined, true, undefined, this)
2400
+ }, undefined, false, undefined, this),
2401
+ /* @__PURE__ */ jsxDEV("tbody", {
2402
+ className: "divide-y divide-border",
2403
+ children: [
2404
+ definitions.map((def) => /* @__PURE__ */ jsxDEV("tr", {
2405
+ className: "hover:bg-muted/50",
2406
+ children: [
2407
+ /* @__PURE__ */ jsxDEV("td", {
2408
+ className: "px-4 py-3",
2409
+ children: [
2410
+ /* @__PURE__ */ jsxDEV("div", {
2411
+ className: "font-medium",
2412
+ children: def.name
2413
+ }, undefined, false, undefined, this),
2414
+ /* @__PURE__ */ jsxDEV("div", {
2415
+ className: "text-muted-foreground text-sm",
2416
+ children: def.description
2417
+ }, undefined, false, undefined, this)
2418
+ ]
2419
+ }, undefined, true, undefined, this),
2420
+ /* @__PURE__ */ jsxDEV("td", {
2421
+ className: "px-4 py-3 font-mono text-sm",
2422
+ children: def.type
2423
+ }, undefined, false, undefined, this),
2424
+ /* @__PURE__ */ jsxDEV("td", {
2425
+ className: "px-4 py-3",
2426
+ children: /* @__PURE__ */ jsxDEV("span", {
2427
+ className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[def.status] ?? ""}`,
2428
+ children: def.status
2429
+ }, undefined, false, undefined, this)
2430
+ }, undefined, false, undefined, this),
2431
+ /* @__PURE__ */ jsxDEV("td", {
2432
+ className: "px-4 py-3 text-muted-foreground text-sm",
2433
+ children: def.createdAt.toLocaleDateString()
2434
+ }, undefined, false, undefined, this)
2435
+ ]
2436
+ }, def.id, true, undefined, this)),
2437
+ definitions.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
2438
+ children: /* @__PURE__ */ jsxDEV("td", {
2439
+ colSpan: 4,
2440
+ className: "px-4 py-8 text-center text-muted-foreground",
2441
+ children: "No workflow definitions found"
2442
+ }, undefined, false, undefined, this)
2443
+ }, undefined, false, undefined, this)
2444
+ ]
2445
+ }, undefined, true, undefined, this)
2446
+ ]
2447
+ }, undefined, true, undefined, this)
2448
+ }, undefined, false, undefined, this),
2449
+ activeTab === "instances" && /* @__PURE__ */ jsxDEV("div", {
2450
+ className: "rounded-lg border border-border",
2451
+ children: /* @__PURE__ */ jsxDEV("table", {
2452
+ className: "w-full",
2453
+ children: [
2454
+ /* @__PURE__ */ jsxDEV("thead", {
2455
+ className: "border-border border-b bg-muted/30",
2456
+ children: /* @__PURE__ */ jsxDEV("tr", {
2457
+ children: [
2458
+ /* @__PURE__ */ jsxDEV("th", {
2459
+ className: "px-4 py-3 text-left font-medium text-sm",
2460
+ children: "Instance ID"
2461
+ }, undefined, false, undefined, this),
2462
+ /* @__PURE__ */ jsxDEV("th", {
2463
+ className: "px-4 py-3 text-left font-medium text-sm",
2464
+ children: "Status"
2465
+ }, undefined, false, undefined, this),
2466
+ /* @__PURE__ */ jsxDEV("th", {
2467
+ className: "px-4 py-3 text-left font-medium text-sm",
2468
+ children: "Requested By"
2469
+ }, undefined, false, undefined, this),
2470
+ /* @__PURE__ */ jsxDEV("th", {
2471
+ className: "px-4 py-3 text-left font-medium text-sm",
2472
+ children: "Started"
2473
+ }, undefined, false, undefined, this)
2474
+ ]
2475
+ }, undefined, true, undefined, this)
2476
+ }, undefined, false, undefined, this),
2477
+ /* @__PURE__ */ jsxDEV("tbody", {
2478
+ className: "divide-y divide-border",
2479
+ children: [
2480
+ instances.map((inst) => /* @__PURE__ */ jsxDEV("tr", {
2481
+ className: "hover:bg-muted/50",
2482
+ children: [
2483
+ /* @__PURE__ */ jsxDEV("td", {
2484
+ className: "px-4 py-3 font-mono text-sm",
2485
+ children: inst.id
2486
+ }, undefined, false, undefined, this),
2487
+ /* @__PURE__ */ jsxDEV("td", {
2488
+ className: "px-4 py-3",
2489
+ children: /* @__PURE__ */ jsxDEV("span", {
2490
+ className: `inline-flex rounded-full px-2 py-0.5 font-medium text-xs ${STATUS_COLORS[inst.status] ?? ""}`,
2491
+ children: inst.status
2492
+ }, undefined, false, undefined, this)
2493
+ }, undefined, false, undefined, this),
2494
+ /* @__PURE__ */ jsxDEV("td", {
2495
+ className: "px-4 py-3 text-sm",
2496
+ children: inst.requestedBy
2497
+ }, undefined, false, undefined, this),
2498
+ /* @__PURE__ */ jsxDEV("td", {
2499
+ className: "px-4 py-3 text-muted-foreground text-sm",
2500
+ children: inst.startedAt.toLocaleDateString()
2501
+ }, undefined, false, undefined, this)
2502
+ ]
2503
+ }, inst.id, true, undefined, this)),
2504
+ instances.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
2505
+ children: /* @__PURE__ */ jsxDEV("td", {
2506
+ colSpan: 4,
2507
+ className: "px-4 py-8 text-center text-muted-foreground",
2508
+ children: "No workflow instances found"
2509
+ }, undefined, false, undefined, this)
2510
+ }, undefined, false, undefined, this)
2511
+ ]
2512
+ }, undefined, true, undefined, this)
2513
+ ]
2514
+ }, undefined, true, undefined, this)
2515
+ }, undefined, false, undefined, this)
2516
+ ]
2517
+ }, undefined, true, undefined, this)
2518
+ ]
2519
+ }, undefined, true, undefined, this);
2520
+ }
2521
+ // src/workflow/workflow.event.ts
2522
+ import { defineEvent as defineEvent3 } from "@contractspec/lib.contracts-spec";
2523
+ import { defineSchemaModel as defineSchemaModel8, ScalarTypeEnum as ScalarTypeEnum8 } from "@contractspec/lib.schema";
2524
+ var WorkflowDefinitionPayload = defineSchemaModel8({
2525
+ name: "WorkflowDefinitionEventPayload",
2526
+ description: "Payload for workflow definition events",
2527
+ fields: {
2528
+ workflowId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2529
+ key: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2530
+ name: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2531
+ version: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2532
+ organizationId: {
2533
+ type: ScalarTypeEnum8.String_unsecure(),
2534
+ isOptional: false
2535
+ },
2536
+ createdBy: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2537
+ timestamp: { type: ScalarTypeEnum8.DateTime(), isOptional: false }
2364
2538
  }
2365
2539
  });
2366
- var WorkflowSystemPresentations = {
2367
- WorkflowDesignerPresentation,
2368
- WorkflowListPresentation,
2369
- WorkflowDetailPresentation,
2370
- InstanceListPresentation,
2371
- InstanceDetailPresentation,
2372
- ProgressTrackerPresentation,
2373
- ApprovalInboxPresentation,
2374
- ApprovalDetailPresentation,
2375
- ApprovalFormPresentation,
2376
- PendingApprovalsBadgePresentation,
2377
- WorkflowMetricsPresentation
2378
- };
2379
-
2380
- // src/workflow-system.feature.ts
2381
- import { defineFeature } from "@contractspec/lib.contracts-spec";
2382
- var WorkflowSystemFeature = defineFeature({
2383
- meta: {
2384
- key: "workflow-system",
2385
- title: "Workflow & Approval System",
2386
- description: "State machine-based workflow engine with role-based approvals, delegation, and escalation",
2387
- domain: "workflow",
2388
- owners: ["@workflow-team"],
2389
- tags: ["workflow", "approval", "state-machine", "automation"],
2390
- stability: "experimental",
2391
- version: "1.0.0"
2392
- },
2393
- operations: [
2394
- { key: "workflow.definition.create", version: "1.0.0" },
2395
- { key: "workflow.definition.update", version: "1.0.0" },
2396
- { key: "workflow.step.add", version: "1.0.0" },
2397
- { key: "workflow.definition.publish", version: "1.0.0" },
2398
- { key: "workflow.definition.list", version: "1.0.0" },
2399
- { key: "workflow.definition.get", version: "1.0.0" },
2400
- { key: "workflow.instance.start", version: "1.0.0" },
2401
- { key: "workflow.instance.transition", version: "1.0.0" },
2402
- { key: "workflow.instance.pause", version: "1.0.0" },
2403
- { key: "workflow.instance.resume", version: "1.0.0" },
2404
- { key: "workflow.instance.cancel", version: "1.0.0" },
2405
- { key: "workflow.instance.list", version: "1.0.0" },
2406
- { key: "workflow.instance.get", version: "1.0.0" },
2407
- { key: "workflow.approval.decide", version: "1.0.0" },
2408
- { key: "workflow.approval.delegate", version: "1.0.0" },
2409
- { key: "workflow.approval.comment.add", version: "1.0.0" },
2410
- { key: "workflow.approval.list.mine", version: "1.0.0" },
2411
- { key: "workflow.approval.get", version: "1.0.0" }
2412
- ],
2413
- events: [
2414
- { key: "workflow.definition.created", version: "1.0.0" },
2415
- { key: "workflow.definition.updated", version: "1.0.0" },
2416
- { key: "workflow.definition.published", version: "1.0.0" },
2417
- { key: "workflow.step.added", version: "1.0.0" },
2418
- { key: "workflow.instance.started", version: "1.0.0" },
2419
- { key: "workflow.step.entered", version: "1.0.0" },
2420
- { key: "workflow.step.exited", version: "1.0.0" },
2421
- { key: "workflow.instance.completed", version: "1.0.0" },
2422
- { key: "workflow.instance.cancelled", version: "1.0.0" },
2423
- { key: "workflow.instance.paused", version: "1.0.0" },
2424
- { key: "workflow.instance.resumed", version: "1.0.0" },
2425
- { key: "workflow.instance.failed", version: "1.0.0" },
2426
- { key: "workflow.instance.timedOut", version: "1.0.0" },
2427
- { key: "workflow.approval.requested", version: "1.0.0" },
2428
- { key: "workflow.approval.decided", version: "1.0.0" },
2429
- { key: "workflow.approval.delegated", version: "1.0.0" },
2430
- { key: "workflow.approval.escalated", version: "1.0.0" }
2431
- ],
2432
- presentations: [
2433
- { key: "workflow.designer", version: "1.0.0" },
2434
- { key: "workflow.definition.viewList", version: "1.0.0" },
2435
- { key: "workflow.definition.detail", version: "1.0.0" },
2436
- { key: "workflow.instance.viewList", version: "1.0.0" },
2437
- { key: "workflow.instance.detail", version: "1.0.0" },
2438
- { key: "workflow.instance.progress", version: "1.0.0" },
2439
- { key: "workflow.approval.inbox", version: "1.0.0" },
2440
- { key: "workflow.approval.detail", version: "1.0.0" },
2441
- { key: "workflow.approval.form", version: "1.0.0" },
2442
- { key: "workflow.approval.badge", version: "1.0.0" },
2443
- { key: "workflow.metrics", version: "1.0.0" }
2444
- ],
2445
- opToPresentation: [
2446
- {
2447
- op: { key: "workflow.definition.list", version: "1.0.0" },
2448
- pres: { key: "workflow.definition.viewList", version: "1.0.0" }
2449
- },
2450
- {
2451
- op: { key: "workflow.instance.list", version: "1.0.0" },
2452
- pres: { key: "workflow.instance.viewList", version: "1.0.0" }
2453
- },
2454
- {
2455
- op: { key: "workflow.approval.list.mine", version: "1.0.0" },
2456
- pres: { key: "workflow.approval.inbox", version: "1.0.0" }
2457
- },
2458
- {
2459
- op: { key: "workflow.approval.decide", version: "1.0.0" },
2460
- pres: { key: "workflow.approval.form", version: "1.0.0" }
2461
- }
2462
- ],
2463
- presentationsTargets: [
2464
- { key: "workflow.designer", version: "1.0.0", targets: ["react"] },
2465
- {
2466
- key: "workflow.definition.viewList",
2467
- version: "1.0.0",
2468
- targets: ["react", "markdown"]
2469
- },
2470
- {
2471
- key: "workflow.definition.detail",
2472
- version: "1.0.0",
2473
- targets: ["react", "markdown"]
2474
- },
2475
- {
2476
- key: "workflow.instance.viewList",
2477
- version: "1.0.0",
2478
- targets: ["react", "markdown"]
2479
- },
2480
- {
2481
- key: "workflow.instance.detail",
2482
- version: "1.0.0",
2483
- targets: ["react", "markdown"]
2484
- },
2485
- { key: "workflow.instance.progress", version: "1.0.0", targets: ["react"] },
2486
- {
2487
- key: "workflow.approval.inbox",
2488
- version: "1.0.0",
2489
- targets: ["react", "markdown"]
2490
- },
2491
- {
2492
- key: "workflow.approval.detail",
2493
- version: "1.0.0",
2494
- targets: ["react", "markdown"]
2495
- },
2496
- {
2497
- key: "workflow.metrics",
2498
- version: "1.0.0",
2499
- targets: ["react", "markdown"]
2500
- }
2501
- ],
2502
- capabilities: {
2503
- requires: [
2504
- { key: "identity", version: "1.0.0" },
2505
- { key: "audit-trail", version: "1.0.0" },
2506
- { key: "notifications", version: "1.0.0" },
2507
- { key: "feature-flags", version: "1.0.0" }
2508
- ],
2509
- provides: [
2510
- { key: "workflow", version: "1.0.0" },
2511
- { key: "approval", version: "1.0.0" },
2512
- { key: "state-machine", version: "1.0.0" }
2513
- ]
2514
- },
2515
- workflows: [
2516
- { key: "workflow-system.workflow.approval-chain", version: "1.0.0" }
2517
- ],
2518
- telemetry: [{ key: "workflow-system.telemetry", version: "1.0.0" }],
2519
- jobs: [
2520
- { key: "workflow-system.job.instance-timeout", version: "1.0.0" },
2521
- { key: "workflow-system.job.escalation", version: "1.0.0" }
2522
- ],
2523
- docs: [
2524
- "docs.examples.workflow-system",
2525
- "docs.examples.workflow-system.goal",
2526
- "docs.examples.workflow-system.usage",
2527
- "docs.examples.workflow-system.constraints"
2528
- ]
2529
- });
2530
-
2531
- // src/ui/renderers/workflow.markdown.ts
2532
- var mockWorkflowDefinitions = [
2533
- {
2534
- id: "wf-1",
2535
- name: "Purchase Approval",
2536
- type: "APPROVAL",
2537
- steps: [
2538
- {
2539
- id: "s1",
2540
- name: "Manager Review",
2541
- order: 1,
2542
- requiredRoles: ["manager"]
2543
- },
2544
- {
2545
- id: "s2",
2546
- name: "Finance Review",
2547
- order: 2,
2548
- requiredRoles: ["finance"]
2549
- },
2550
- { id: "s3", name: "Final Approval", order: 3, requiredRoles: ["admin"] }
2551
- ],
2552
- status: "ACTIVE"
2553
- },
2554
- {
2555
- id: "wf-2",
2556
- name: "Leave Request",
2557
- type: "APPROVAL",
2558
- steps: [
2559
- {
2560
- id: "s1",
2561
- name: "Supervisor Approval",
2562
- order: 1,
2563
- requiredRoles: ["supervisor"]
2564
- },
2565
- { id: "s2", name: "HR Review", order: 2, requiredRoles: ["hr"] }
2566
- ],
2567
- status: "ACTIVE"
2568
- },
2569
- {
2570
- id: "wf-3",
2571
- name: "Document Review",
2572
- type: "SEQUENTIAL",
2573
- steps: [
2574
- { id: "s1", name: "Author Review", order: 1, requiredRoles: ["author"] },
2575
- { id: "s2", name: "Peer Review", order: 2, requiredRoles: ["reviewer"] },
2576
- { id: "s3", name: "Publish", order: 3, requiredRoles: ["publisher"] }
2577
- ],
2578
- status: "DRAFT"
2540
+ var StepAddedPayload = defineSchemaModel8({
2541
+ name: "StepAddedEventPayload",
2542
+ description: "Payload when a step is added",
2543
+ fields: {
2544
+ stepId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2545
+ workflowId: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2546
+ stepKey: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2547
+ stepType: { type: ScalarTypeEnum8.String_unsecure(), isOptional: false },
2548
+ position: { type: ScalarTypeEnum8.Int_unsecure(), isOptional: false },
2549
+ timestamp: { type: ScalarTypeEnum8.DateTime(), isOptional: false }
2579
2550
  }
2580
- ];
2581
- var mockWorkflowInstances = [
2582
- {
2583
- id: "inst-1",
2584
- definitionId: "wf-1",
2585
- definitionName: "Purchase Approval",
2586
- status: "IN_PROGRESS",
2587
- currentStepId: "s2",
2588
- startedAt: "2024-01-15T10:00:00Z",
2589
- requestedBy: "John Doe"
2551
+ });
2552
+ var WorkflowCreatedEvent = defineEvent3({
2553
+ meta: {
2554
+ key: "workflow.definition.created",
2555
+ version: "1.0.0",
2556
+ description: "A new workflow definition has been created.",
2557
+ stability: "stable",
2558
+ owners: ["@workflow-team"],
2559
+ tags: ["workflow", "definition", "created"]
2590
2560
  },
2591
- {
2592
- id: "inst-2",
2593
- definitionId: "wf-1",
2594
- definitionName: "Purchase Approval",
2595
- status: "COMPLETED",
2596
- currentStepId: null,
2597
- startedAt: "2024-01-10T09:00:00Z",
2598
- completedAt: "2024-01-12T14:00:00Z",
2599
- requestedBy: "Jane Smith"
2561
+ payload: WorkflowDefinitionPayload
2562
+ });
2563
+ var WorkflowUpdatedEvent = defineEvent3({
2564
+ meta: {
2565
+ key: "workflow.definition.updated",
2566
+ version: "1.0.0",
2567
+ description: "A workflow definition has been updated.",
2568
+ stability: "stable",
2569
+ owners: ["@workflow-team"],
2570
+ tags: ["workflow", "definition", "updated"]
2600
2571
  },
2601
- {
2602
- id: "inst-3",
2603
- definitionId: "wf-2",
2604
- definitionName: "Leave Request",
2605
- status: "PENDING",
2606
- currentStepId: "s1",
2607
- startedAt: "2024-01-16T08:00:00Z",
2608
- requestedBy: "Bob Wilson"
2609
- }
2610
- ];
2611
- var workflowDashboardMarkdownRenderer = {
2612
- target: "markdown",
2613
- render: async (desc) => {
2614
- if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDashboard") {
2615
- throw new Error("workflowDashboardMarkdownRenderer: not WorkflowDashboard");
2616
- }
2617
- const definitions = mockWorkflowDefinitions;
2618
- const instances = mockWorkflowInstances;
2619
- const activeDefinitions = definitions.filter((d) => d.status === "ACTIVE");
2620
- const pendingInstances = instances.filter((i) => i.status === "PENDING");
2621
- const inProgressInstances = instances.filter((i) => i.status === "IN_PROGRESS");
2622
- const completedInstances = instances.filter((i) => i.status === "COMPLETED");
2623
- const lines = [
2624
- "# Workflow Dashboard",
2625
- "",
2626
- "> Workflow and approval management overview",
2627
- "",
2628
- "## Summary",
2629
- "",
2630
- "| Metric | Value |",
2631
- "|--------|-------|",
2632
- `| Active Workflows | ${activeDefinitions.length} |`,
2633
- `| Pending Approvals | ${pendingInstances.length} |`,
2634
- `| In Progress | ${inProgressInstances.length} |`,
2635
- `| Completed | ${completedInstances.length} |`,
2636
- "",
2637
- "## Active Workflow Definitions",
2638
- ""
2639
- ];
2640
- if (activeDefinitions.length === 0) {
2641
- lines.push("_No active workflow definitions._");
2642
- } else {
2643
- lines.push("| Name | Type | Steps | Status |");
2644
- lines.push("|------|------|-------|--------|");
2645
- for (const def of activeDefinitions) {
2646
- lines.push(`| ${def.name} | ${def.type} | ${def.steps.length} | ${def.status} |`);
2572
+ payload: WorkflowDefinitionPayload
2573
+ });
2574
+ var WorkflowPublishedEvent = defineEvent3({
2575
+ meta: {
2576
+ key: "workflow.definition.published",
2577
+ version: "1.0.0",
2578
+ description: "A workflow definition has been published and is now active.",
2579
+ stability: "stable",
2580
+ owners: ["@workflow-team"],
2581
+ tags: ["workflow", "definition", "published"]
2582
+ },
2583
+ payload: WorkflowDefinitionPayload
2584
+ });
2585
+ var StepAddedEvent = defineEvent3({
2586
+ meta: {
2587
+ key: "workflow.step.added",
2588
+ version: "1.0.0",
2589
+ description: "A step has been added to a workflow definition.",
2590
+ stability: "stable",
2591
+ owners: ["@workflow-team"],
2592
+ tags: ["workflow", "step", "added"]
2593
+ },
2594
+ payload: StepAddedPayload
2595
+ });
2596
+
2597
+ // src/workflow/workflow.operations.ts
2598
+ import {
2599
+ defineCommand as defineCommand3,
2600
+ defineQuery as defineQuery3
2601
+ } from "@contractspec/lib.contracts-spec/operations";
2602
+ import { defineSchemaModel as defineSchemaModel9, ScalarTypeEnum as ScalarTypeEnum9 } from "@contractspec/lib.schema";
2603
+ var OWNERS3 = ["@example.workflow-system"];
2604
+ var CreateWorkflowContract = defineCommand3({
2605
+ meta: {
2606
+ key: "workflow.definition.create",
2607
+ version: "1.0.0",
2608
+ stability: "stable",
2609
+ owners: [...OWNERS3],
2610
+ tags: ["workflow", "definition", "create"],
2611
+ description: "Create a new workflow definition.",
2612
+ goal: "Allow users to define new workflow blueprints.",
2613
+ context: "Workflow designer, admin panel."
2614
+ },
2615
+ io: {
2616
+ input: CreateWorkflowInputModel,
2617
+ output: WorkflowDefinitionModel
2618
+ },
2619
+ policy: { auth: "user" },
2620
+ sideEffects: {
2621
+ emits: [
2622
+ {
2623
+ key: "workflow.definition.created",
2624
+ version: "1.0.0",
2625
+ when: "Workflow is created",
2626
+ payload: WorkflowDefinitionModel
2647
2627
  }
2648
- }
2649
- lines.push("");
2650
- lines.push("## Recent Instances");
2651
- lines.push("");
2652
- if (instances.length === 0) {
2653
- lines.push("_No workflow instances._");
2654
- } else {
2655
- lines.push("| Workflow | Requested By | Status | Started |");
2656
- lines.push("|----------|--------------|--------|---------|");
2657
- for (const inst of instances.slice(0, 10)) {
2658
- const startedDate = new Date(inst.startedAt).toLocaleDateString();
2659
- lines.push(`| ${inst.definitionName} | ${inst.requestedBy} | ${inst.status} | ${startedDate} |`);
2628
+ ],
2629
+ audit: ["workflow.definition.created"]
2630
+ },
2631
+ acceptance: {
2632
+ scenarios: [
2633
+ {
2634
+ key: "create-workflow-happy-path",
2635
+ given: ["User is admin"],
2636
+ when: ["User creates new workflow definition"],
2637
+ then: [
2638
+ "Definition is created",
2639
+ "WorkflowDefinitionCreated event is emitted"
2640
+ ]
2660
2641
  }
2661
- }
2662
- return {
2663
- mimeType: "text/markdown",
2664
- body: lines.join(`
2665
- `)
2666
- };
2642
+ ],
2643
+ examples: [
2644
+ {
2645
+ key: "create-onboarding",
2646
+ input: {
2647
+ key: "onboarding-v1",
2648
+ name: "Employee Onboarding",
2649
+ version: "1.0.0"
2650
+ },
2651
+ output: { id: "def-123", status: "draft" }
2652
+ }
2653
+ ]
2667
2654
  }
2668
- };
2669
- var workflowDefinitionListMarkdownRenderer = {
2670
- target: "markdown",
2671
- render: async (desc) => {
2672
- if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowDefinitionList") {
2673
- throw new Error("workflowDefinitionListMarkdownRenderer: not WorkflowDefinitionList");
2674
- }
2675
- const definitions = mockWorkflowDefinitions;
2676
- const lines = [
2677
- "# Workflow Definitions",
2678
- "",
2679
- "> Configure automated approval and process workflows",
2680
- ""
2681
- ];
2682
- for (const def of definitions) {
2683
- lines.push(`## ${def.name}`);
2684
- lines.push("");
2685
- lines.push(`**Type:** ${def.type} | **Status:** ${def.status}`);
2686
- lines.push("");
2687
- lines.push("### Steps");
2688
- lines.push("");
2689
- for (const step of def.steps) {
2690
- lines.push(`${step.order}. **${step.name}** - Roles: ${step.requiredRoles.join(", ")}`);
2655
+ });
2656
+ var UpdateWorkflowContract = defineCommand3({
2657
+ meta: {
2658
+ key: "workflow.definition.update",
2659
+ version: "1.0.0",
2660
+ stability: "stable",
2661
+ owners: [...OWNERS3],
2662
+ tags: ["workflow", "definition", "update"],
2663
+ description: "Update an existing workflow definition.",
2664
+ goal: "Allow users to modify workflow blueprints.",
2665
+ context: "Workflow designer."
2666
+ },
2667
+ io: {
2668
+ input: UpdateWorkflowInputModel,
2669
+ output: WorkflowDefinitionModel
2670
+ },
2671
+ policy: { auth: "user" },
2672
+ sideEffects: {
2673
+ emits: [
2674
+ {
2675
+ key: "workflow.definition.updated",
2676
+ version: "1.0.0",
2677
+ when: "Workflow is updated",
2678
+ payload: WorkflowDefinitionModel
2691
2679
  }
2692
- lines.push("");
2693
- }
2694
- return {
2695
- mimeType: "text/markdown",
2696
- body: lines.join(`
2697
- `)
2698
- };
2680
+ ],
2681
+ audit: ["workflow.definition.updated"]
2682
+ },
2683
+ acceptance: {
2684
+ scenarios: [
2685
+ {
2686
+ key: "update-workflow-happy-path",
2687
+ given: ["Workflow definition exists"],
2688
+ when: ["User updates definition"],
2689
+ then: [
2690
+ "Definition is updated",
2691
+ "WorkflowDefinitionUpdated event is emitted"
2692
+ ]
2693
+ }
2694
+ ],
2695
+ examples: [
2696
+ {
2697
+ key: "update-name",
2698
+ input: { workflowId: "def-123", name: "New Employee Onboarding" },
2699
+ output: { id: "def-123", name: "New Employee Onboarding" }
2700
+ }
2701
+ ]
2699
2702
  }
2700
- };
2701
- var workflowInstanceDetailMarkdownRenderer = {
2702
- target: "markdown",
2703
- render: async (desc) => {
2704
- if (desc.source.type !== "component" || desc.source.componentKey !== "WorkflowInstanceDetail") {
2705
- throw new Error("workflowInstanceDetailMarkdownRenderer: not WorkflowInstanceDetail");
2706
- }
2707
- const instance = mockWorkflowInstances[0];
2708
- if (!instance) {
2709
- return {
2710
- mimeType: "text/markdown",
2711
- body: `# No Workflow Instances
2712
-
2713
- No workflow instances available.`
2714
- };
2715
- }
2716
- const definition = mockWorkflowDefinitions.find((d) => d.id === instance.definitionId);
2717
- const lines = [
2718
- `# Workflow: ${instance.definitionName}`,
2719
- "",
2720
- `**Instance ID:** ${instance.id}`,
2721
- `**Status:** ${instance.status}`,
2722
- `**Requested By:** ${instance.requestedBy}`,
2723
- `**Started:** ${new Date(instance.startedAt).toLocaleString()}`,
2724
- "",
2725
- "## Steps Progress",
2726
- ""
2727
- ];
2728
- if (definition) {
2729
- for (const step of definition.steps) {
2730
- const isCurrent = step.id === instance.currentStepId;
2731
- const isCompleted = definition.steps.indexOf(step) < definition.steps.findIndex((s) => s.id === instance.currentStepId);
2732
- let status = "\u2B1C Pending";
2733
- if (isCompleted)
2734
- status = "\u2705 Completed";
2735
- if (isCurrent)
2736
- status = "\uD83D\uDD04 In Progress";
2737
- lines.push(`- ${status} **${step.name}**`);
2703
+ });
2704
+ var AddStepContract = defineCommand3({
2705
+ meta: {
2706
+ key: "workflow.step.add",
2707
+ version: "1.0.0",
2708
+ stability: "stable",
2709
+ owners: [...OWNERS3],
2710
+ tags: ["workflow", "step", "add"],
2711
+ description: "Add a step to a workflow definition.",
2712
+ goal: "Build workflow structure step by step.",
2713
+ context: "Workflow designer."
2714
+ },
2715
+ io: {
2716
+ input: AddStepInputModel,
2717
+ output: WorkflowStepModel
2718
+ },
2719
+ policy: { auth: "user" },
2720
+ sideEffects: {
2721
+ emits: [
2722
+ {
2723
+ key: "workflow.step.added",
2724
+ version: "1.0.0",
2725
+ when: "Step is added",
2726
+ payload: WorkflowStepModel
2738
2727
  }
2739
- }
2740
- lines.push("");
2741
- lines.push("## Actions");
2742
- lines.push("");
2743
- lines.push("- **Approve** - Move to next step");
2744
- lines.push("- **Reject** - Reject and return");
2745
- lines.push("- **Delegate** - Assign to another approver");
2746
- return {
2747
- mimeType: "text/markdown",
2748
- body: lines.join(`
2749
- `)
2750
- };
2751
- }
2752
- };
2753
- // src/ui/hooks/useWorkflowList.ts
2754
- import { useCallback, useEffect, useState } from "react";
2755
- import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
2756
- "use client";
2757
- function useWorkflowList(projectId = "local-project") {
2758
- const { handlers } = useTemplateRuntime();
2759
- const workflow = handlers.workflow;
2760
- const [definitions, setDefinitions] = useState([]);
2761
- const [instances, setInstances] = useState([]);
2762
- const [loading, setLoading] = useState(true);
2763
- const [error, setError] = useState(null);
2764
- const fetchData = useCallback(async () => {
2765
- try {
2766
- setLoading(true);
2767
- setError(null);
2768
- const [defResult, instResult] = await Promise.all([
2769
- workflow.listDefinitions({ projectId, limit: 100 }),
2770
- workflow.listInstances({ projectId, limit: 100 })
2771
- ]);
2772
- setDefinitions(defResult.definitions);
2773
- setInstances(instResult.instances);
2774
- } catch (err) {
2775
- setError(err instanceof Error ? err : new Error("Failed to load workflows"));
2776
- } finally {
2777
- setLoading(false);
2778
- }
2779
- }, [handlers, projectId]);
2780
- useEffect(() => {
2781
- fetchData();
2782
- }, [fetchData]);
2783
- const stats = {
2784
- totalDefinitions: definitions.length,
2785
- activeDefinitions: definitions.filter((d) => d.status === "ACTIVE").length,
2786
- totalInstances: instances.length,
2787
- pendingInstances: instances.filter((i) => i.status === "PENDING").length,
2788
- completedInstances: instances.filter((i) => i.status === "COMPLETED").length,
2789
- rejectedInstances: instances.filter((i) => i.status === "REJECTED").length
2790
- };
2791
- return {
2792
- definitions,
2793
- instances,
2794
- loading,
2795
- error,
2796
- stats,
2797
- refetch: fetchData
2798
- };
2799
- }
2800
-
2801
- // src/ui/WorkflowDashboard.tsx
2802
- import { useState as useState2 } from "react";
2803
- import {
2804
- Button,
2805
- ErrorState,
2806
- LoaderBlock,
2807
- StatCard,
2808
- StatCardGroup
2809
- } from "@contractspec/lib.design-system";
2810
- import { jsxDEV } from "react/jsx-dev-runtime";
2811
- "use client";
2812
- var STATUS_COLORS = {
2813
- ACTIVE: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2814
- DRAFT: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400",
2815
- ARCHIVED: "bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400",
2816
- PENDING: "bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",
2817
- IN_PROGRESS: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900/30 dark:text-indigo-400",
2818
- COMPLETED: "bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",
2819
- REJECTED: "bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400",
2820
- CANCELLED: "bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400"
2821
- };
2822
- function WorkflowDashboard() {
2823
- const [activeTab, setActiveTab] = useState2("definitions");
2824
- const { definitions, instances, loading, error, stats, refetch } = useWorkflowList();
2825
- const tabs = [
2826
- { id: "definitions", label: "Definitions", icon: "\uD83D\uDCCB" },
2827
- { id: "instances", label: "Instances", icon: "\uD83D\uDD04" }
2828
- ];
2829
- if (loading) {
2830
- return /* @__PURE__ */ jsxDEV(LoaderBlock, {
2831
- label: "Loading Workflows..."
2832
- }, undefined, false, undefined, this);
2728
+ ],
2729
+ audit: ["workflow.step.added"]
2730
+ },
2731
+ acceptance: {
2732
+ scenarios: [
2733
+ {
2734
+ key: "add-step-happy-path",
2735
+ given: ["Workflow definition exists"],
2736
+ when: ["User adds a step"],
2737
+ then: ["Step is added", "StepAdded event is emitted"]
2738
+ }
2739
+ ],
2740
+ examples: [
2741
+ {
2742
+ key: "add-approval-step",
2743
+ input: {
2744
+ workflowId: "def-123",
2745
+ stepKey: "approve-contract",
2746
+ type: "approval"
2747
+ },
2748
+ output: { id: "step-456", key: "approve-contract" }
2749
+ }
2750
+ ]
2833
2751
  }
2834
- if (error) {
2835
- return /* @__PURE__ */ jsxDEV(ErrorState, {
2836
- title: "Failed to load Workflows",
2837
- description: error.message,
2838
- onRetry: refetch,
2839
- retryLabel: "Retry"
2840
- }, undefined, false, undefined, this);
2752
+ });
2753
+ var PublishWorkflowContract = defineCommand3({
2754
+ meta: {
2755
+ key: "workflow.definition.publish",
2756
+ version: "1.0.0",
2757
+ stability: "stable",
2758
+ owners: [...OWNERS3],
2759
+ tags: ["workflow", "definition", "publish"],
2760
+ description: "Publish a workflow definition to make it available for use.",
2761
+ goal: "Activate workflow for production use.",
2762
+ context: "Workflow designer, deployment."
2763
+ },
2764
+ io: {
2765
+ input: defineSchemaModel9({
2766
+ name: "PublishWorkflowInput",
2767
+ fields: {
2768
+ workflowId: {
2769
+ type: ScalarTypeEnum9.String_unsecure(),
2770
+ isOptional: false
2771
+ }
2772
+ }
2773
+ }),
2774
+ output: WorkflowDefinitionModel
2775
+ },
2776
+ policy: { auth: "user" },
2777
+ sideEffects: {
2778
+ emits: [
2779
+ {
2780
+ key: "workflow.definition.published",
2781
+ version: "1.0.0",
2782
+ when: "Workflow is published",
2783
+ payload: WorkflowDefinitionModel
2784
+ }
2785
+ ],
2786
+ audit: ["workflow.definition.published"]
2787
+ },
2788
+ acceptance: {
2789
+ scenarios: [
2790
+ {
2791
+ key: "publish-workflow-happy-path",
2792
+ given: ["Workflow definition is valid"],
2793
+ when: ["User publishes workflow"],
2794
+ then: ["Workflow becomes active", "WorkflowPublished event is emitted"]
2795
+ }
2796
+ ],
2797
+ examples: [
2798
+ {
2799
+ key: "publish-onboarding",
2800
+ input: { workflowId: "def-123" },
2801
+ output: { id: "def-123", status: "published" }
2802
+ }
2803
+ ]
2841
2804
  }
2842
- return /* @__PURE__ */ jsxDEV("div", {
2843
- className: "space-y-6",
2844
- children: [
2845
- /* @__PURE__ */ jsxDEV("div", {
2846
- className: "flex items-center justify-between",
2847
- children: [
2848
- /* @__PURE__ */ jsxDEV("h2", {
2849
- className: "text-2xl font-bold",
2850
- children: "Workflow System"
2851
- }, undefined, false, undefined, this),
2852
- /* @__PURE__ */ jsxDEV(Button, {
2853
- onClick: () => alert("Create workflow modal"),
2854
- children: [
2855
- /* @__PURE__ */ jsxDEV("span", {
2856
- className: "mr-2",
2857
- children: "+"
2858
- }, undefined, false, undefined, this),
2859
- " New Workflow"
2860
- ]
2861
- }, undefined, true, undefined, this)
2862
- ]
2863
- }, undefined, true, undefined, this),
2864
- /* @__PURE__ */ jsxDEV(StatCardGroup, {
2865
- children: [
2866
- /* @__PURE__ */ jsxDEV(StatCard, {
2867
- label: "Workflows",
2868
- value: stats.totalDefinitions,
2869
- hint: `${stats.activeDefinitions} active`
2870
- }, undefined, false, undefined, this),
2871
- /* @__PURE__ */ jsxDEV(StatCard, {
2872
- label: "Instances",
2873
- value: stats.totalInstances,
2874
- hint: "total runs"
2875
- }, undefined, false, undefined, this),
2876
- /* @__PURE__ */ jsxDEV(StatCard, {
2877
- label: "Pending",
2878
- value: stats.pendingInstances,
2879
- hint: "awaiting action"
2880
- }, undefined, false, undefined, this),
2881
- /* @__PURE__ */ jsxDEV(StatCard, {
2882
- label: "Completed",
2883
- value: stats.completedInstances,
2884
- hint: "finished"
2885
- }, undefined, false, undefined, this)
2886
- ]
2887
- }, undefined, true, undefined, this),
2888
- /* @__PURE__ */ jsxDEV("nav", {
2889
- className: "bg-muted flex gap-1 rounded-lg p-1",
2890
- role: "tablist",
2891
- children: tabs.map((tab) => /* @__PURE__ */ jsxDEV(Button, {
2892
- type: "button",
2893
- role: "tab",
2894
- "aria-selected": activeTab === tab.id,
2895
- onClick: () => setActiveTab(tab.id),
2896
- className: `flex flex-1 items-center justify-center gap-2 rounded-md px-4 py-2 text-sm font-medium transition-colors ${activeTab === tab.id ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"}`,
2897
- children: [
2898
- /* @__PURE__ */ jsxDEV("span", {
2899
- children: tab.icon
2900
- }, undefined, false, undefined, this),
2901
- tab.label
2902
- ]
2903
- }, tab.id, true, undefined, this))
2904
- }, undefined, false, undefined, this),
2905
- /* @__PURE__ */ jsxDEV("div", {
2906
- className: "min-h-[400px]",
2907
- role: "tabpanel",
2908
- children: [
2909
- activeTab === "definitions" && /* @__PURE__ */ jsxDEV("div", {
2910
- className: "border-border rounded-lg border",
2911
- children: /* @__PURE__ */ jsxDEV("table", {
2912
- className: "w-full",
2913
- children: [
2914
- /* @__PURE__ */ jsxDEV("thead", {
2915
- className: "border-border bg-muted/30 border-b",
2916
- children: /* @__PURE__ */ jsxDEV("tr", {
2917
- children: [
2918
- /* @__PURE__ */ jsxDEV("th", {
2919
- className: "px-4 py-3 text-left text-sm font-medium",
2920
- children: "Name"
2921
- }, undefined, false, undefined, this),
2922
- /* @__PURE__ */ jsxDEV("th", {
2923
- className: "px-4 py-3 text-left text-sm font-medium",
2924
- children: "Type"
2925
- }, undefined, false, undefined, this),
2926
- /* @__PURE__ */ jsxDEV("th", {
2927
- className: "px-4 py-3 text-left text-sm font-medium",
2928
- children: "Status"
2929
- }, undefined, false, undefined, this),
2930
- /* @__PURE__ */ jsxDEV("th", {
2931
- className: "px-4 py-3 text-left text-sm font-medium",
2932
- children: "Created"
2933
- }, undefined, false, undefined, this)
2934
- ]
2935
- }, undefined, true, undefined, this)
2936
- }, undefined, false, undefined, this),
2937
- /* @__PURE__ */ jsxDEV("tbody", {
2938
- className: "divide-border divide-y",
2939
- children: [
2940
- definitions.map((def) => /* @__PURE__ */ jsxDEV("tr", {
2941
- className: "hover:bg-muted/50",
2942
- children: [
2943
- /* @__PURE__ */ jsxDEV("td", {
2944
- className: "px-4 py-3",
2945
- children: [
2946
- /* @__PURE__ */ jsxDEV("div", {
2947
- className: "font-medium",
2948
- children: def.name
2949
- }, undefined, false, undefined, this),
2950
- /* @__PURE__ */ jsxDEV("div", {
2951
- className: "text-muted-foreground text-sm",
2952
- children: def.description
2953
- }, undefined, false, undefined, this)
2954
- ]
2955
- }, undefined, true, undefined, this),
2956
- /* @__PURE__ */ jsxDEV("td", {
2957
- className: "px-4 py-3 font-mono text-sm",
2958
- children: def.type
2959
- }, undefined, false, undefined, this),
2960
- /* @__PURE__ */ jsxDEV("td", {
2961
- className: "px-4 py-3",
2962
- children: /* @__PURE__ */ jsxDEV("span", {
2963
- className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[def.status] ?? ""}`,
2964
- children: def.status
2965
- }, undefined, false, undefined, this)
2966
- }, undefined, false, undefined, this),
2967
- /* @__PURE__ */ jsxDEV("td", {
2968
- className: "text-muted-foreground px-4 py-3 text-sm",
2969
- children: def.createdAt.toLocaleDateString()
2970
- }, undefined, false, undefined, this)
2971
- ]
2972
- }, def.id, true, undefined, this)),
2973
- definitions.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
2974
- children: /* @__PURE__ */ jsxDEV("td", {
2975
- colSpan: 4,
2976
- className: "text-muted-foreground px-4 py-8 text-center",
2977
- children: "No workflow definitions found"
2978
- }, undefined, false, undefined, this)
2979
- }, undefined, false, undefined, this)
2980
- ]
2981
- }, undefined, true, undefined, this)
2982
- ]
2983
- }, undefined, true, undefined, this)
2984
- }, undefined, false, undefined, this),
2985
- activeTab === "instances" && /* @__PURE__ */ jsxDEV("div", {
2986
- className: "border-border rounded-lg border",
2987
- children: /* @__PURE__ */ jsxDEV("table", {
2988
- className: "w-full",
2989
- children: [
2990
- /* @__PURE__ */ jsxDEV("thead", {
2991
- className: "border-border bg-muted/30 border-b",
2992
- children: /* @__PURE__ */ jsxDEV("tr", {
2993
- children: [
2994
- /* @__PURE__ */ jsxDEV("th", {
2995
- className: "px-4 py-3 text-left text-sm font-medium",
2996
- children: "Instance ID"
2997
- }, undefined, false, undefined, this),
2998
- /* @__PURE__ */ jsxDEV("th", {
2999
- className: "px-4 py-3 text-left text-sm font-medium",
3000
- children: "Status"
3001
- }, undefined, false, undefined, this),
3002
- /* @__PURE__ */ jsxDEV("th", {
3003
- className: "px-4 py-3 text-left text-sm font-medium",
3004
- children: "Requested By"
3005
- }, undefined, false, undefined, this),
3006
- /* @__PURE__ */ jsxDEV("th", {
3007
- className: "px-4 py-3 text-left text-sm font-medium",
3008
- children: "Started"
3009
- }, undefined, false, undefined, this)
3010
- ]
3011
- }, undefined, true, undefined, this)
3012
- }, undefined, false, undefined, this),
3013
- /* @__PURE__ */ jsxDEV("tbody", {
3014
- className: "divide-border divide-y",
3015
- children: [
3016
- instances.map((inst) => /* @__PURE__ */ jsxDEV("tr", {
3017
- className: "hover:bg-muted/50",
3018
- children: [
3019
- /* @__PURE__ */ jsxDEV("td", {
3020
- className: "px-4 py-3 font-mono text-sm",
3021
- children: inst.id
3022
- }, undefined, false, undefined, this),
3023
- /* @__PURE__ */ jsxDEV("td", {
3024
- className: "px-4 py-3",
3025
- children: /* @__PURE__ */ jsxDEV("span", {
3026
- className: `inline-flex rounded-full px-2 py-0.5 text-xs font-medium ${STATUS_COLORS[inst.status] ?? ""}`,
3027
- children: inst.status
3028
- }, undefined, false, undefined, this)
3029
- }, undefined, false, undefined, this),
3030
- /* @__PURE__ */ jsxDEV("td", {
3031
- className: "px-4 py-3 text-sm",
3032
- children: inst.requestedBy
3033
- }, undefined, false, undefined, this),
3034
- /* @__PURE__ */ jsxDEV("td", {
3035
- className: "text-muted-foreground px-4 py-3 text-sm",
3036
- children: inst.startedAt.toLocaleDateString()
3037
- }, undefined, false, undefined, this)
3038
- ]
3039
- }, inst.id, true, undefined, this)),
3040
- instances.length === 0 && /* @__PURE__ */ jsxDEV("tr", {
3041
- children: /* @__PURE__ */ jsxDEV("td", {
3042
- colSpan: 4,
3043
- className: "text-muted-foreground px-4 py-8 text-center",
3044
- children: "No workflow instances found"
3045
- }, undefined, false, undefined, this)
3046
- }, undefined, false, undefined, this)
3047
- ]
3048
- }, undefined, true, undefined, this)
3049
- ]
3050
- }, undefined, true, undefined, this)
3051
- }, undefined, false, undefined, this)
3052
- ]
3053
- }, undefined, true, undefined, this)
2805
+ });
2806
+ var ListWorkflowsContract = defineQuery3({
2807
+ meta: {
2808
+ key: "workflow.definition.list",
2809
+ version: "1.0.0",
2810
+ stability: "stable",
2811
+ owners: [...OWNERS3],
2812
+ tags: ["workflow", "definition", "list"],
2813
+ description: "List workflow definitions with filtering.",
2814
+ goal: "Browse and search available workflows.",
2815
+ context: "Workflow list, search."
2816
+ },
2817
+ io: {
2818
+ input: defineSchemaModel9({
2819
+ name: "ListWorkflowsInput",
2820
+ fields: {
2821
+ status: { type: WorkflowStatusEnum, isOptional: true },
2822
+ search: { type: ScalarTypeEnum9.String_unsecure(), isOptional: true },
2823
+ limit: {
2824
+ type: ScalarTypeEnum9.Int_unsecure(),
2825
+ isOptional: true,
2826
+ defaultValue: 20
2827
+ },
2828
+ offset: {
2829
+ type: ScalarTypeEnum9.Int_unsecure(),
2830
+ isOptional: true,
2831
+ defaultValue: 0
2832
+ }
2833
+ }
2834
+ }),
2835
+ output: defineSchemaModel9({
2836
+ name: "ListWorkflowsOutput",
2837
+ fields: {
2838
+ workflows: {
2839
+ type: WorkflowDefinitionModel,
2840
+ isArray: true,
2841
+ isOptional: false
2842
+ },
2843
+ total: { type: ScalarTypeEnum9.Int_unsecure(), isOptional: false }
2844
+ }
2845
+ })
2846
+ },
2847
+ policy: { auth: "user" },
2848
+ acceptance: {
2849
+ scenarios: [
2850
+ {
2851
+ key: "list-workflows-happy-path",
2852
+ given: ["Workflow definitions exist"],
2853
+ when: ["User lists workflows"],
2854
+ then: ["List of workflows is returned"]
2855
+ }
2856
+ ],
2857
+ examples: [
2858
+ {
2859
+ key: "list-all",
2860
+ input: { limit: 10 },
2861
+ output: { workflows: [], total: 5 }
2862
+ }
3054
2863
  ]
3055
- }, undefined, true, undefined, this);
3056
- }
3057
-
3058
- // src/ui/hooks/index.ts
3059
- "use client";
2864
+ }
2865
+ });
2866
+ var GetWorkflowContract = defineQuery3({
2867
+ meta: {
2868
+ key: "workflow.definition.get",
2869
+ version: "1.0.0",
2870
+ stability: "stable",
2871
+ owners: [...OWNERS3],
2872
+ tags: ["workflow", "definition", "get"],
2873
+ description: "Get a workflow definition with all steps.",
2874
+ goal: "View workflow details.",
2875
+ context: "Workflow designer, detail view."
2876
+ },
2877
+ io: {
2878
+ input: defineSchemaModel9({
2879
+ name: "GetWorkflowInput",
2880
+ fields: {
2881
+ workflowId: {
2882
+ type: ScalarTypeEnum9.String_unsecure(),
2883
+ isOptional: false
2884
+ }
2885
+ }
2886
+ }),
2887
+ output: WorkflowDefinitionModel
2888
+ },
2889
+ policy: { auth: "user" },
2890
+ acceptance: {
2891
+ scenarios: [
2892
+ {
2893
+ key: "get-workflow-happy-path",
2894
+ given: ["Workflow definition exists"],
2895
+ when: ["User requests workflow details"],
2896
+ then: ["Workflow details are returned"]
2897
+ }
2898
+ ],
2899
+ examples: [
2900
+ {
2901
+ key: "get-details",
2902
+ input: { workflowId: "def-123" },
2903
+ output: { id: "def-123", name: "Employee Onboarding" }
2904
+ }
2905
+ ]
2906
+ }
2907
+ });
2908
+ // src/workflow-system.feature.ts
2909
+ import { defineFeature } from "@contractspec/lib.contracts-spec";
2910
+ var WorkflowSystemFeature = defineFeature({
2911
+ meta: {
2912
+ key: "workflow-system",
2913
+ title: "Workflow & Approval System",
2914
+ description: "State machine-based workflow engine with role-based approvals, delegation, and escalation",
2915
+ domain: "workflow",
2916
+ owners: ["@workflow-team"],
2917
+ tags: ["workflow", "approval", "state-machine", "automation"],
2918
+ stability: "experimental",
2919
+ version: "1.0.0"
2920
+ },
2921
+ operations: [
2922
+ { key: "workflow.definition.create", version: "1.0.0" },
2923
+ { key: "workflow.definition.update", version: "1.0.0" },
2924
+ { key: "workflow.step.add", version: "1.0.0" },
2925
+ { key: "workflow.definition.publish", version: "1.0.0" },
2926
+ { key: "workflow.definition.list", version: "1.0.0" },
2927
+ { key: "workflow.definition.get", version: "1.0.0" },
2928
+ { key: "workflow.instance.start", version: "1.0.0" },
2929
+ { key: "workflow.instance.transition", version: "1.0.0" },
2930
+ { key: "workflow.instance.pause", version: "1.0.0" },
2931
+ { key: "workflow.instance.resume", version: "1.0.0" },
2932
+ { key: "workflow.instance.cancel", version: "1.0.0" },
2933
+ { key: "workflow.instance.list", version: "1.0.0" },
2934
+ { key: "workflow.instance.get", version: "1.0.0" },
2935
+ { key: "workflow.approval.decide", version: "1.0.0" },
2936
+ { key: "workflow.approval.delegate", version: "1.0.0" },
2937
+ { key: "workflow.approval.comment.add", version: "1.0.0" },
2938
+ { key: "workflow.approval.list.mine", version: "1.0.0" },
2939
+ { key: "workflow.approval.get", version: "1.0.0" }
2940
+ ],
2941
+ events: [
2942
+ { key: "workflow.definition.created", version: "1.0.0" },
2943
+ { key: "workflow.definition.updated", version: "1.0.0" },
2944
+ { key: "workflow.definition.published", version: "1.0.0" },
2945
+ { key: "workflow.step.added", version: "1.0.0" },
2946
+ { key: "workflow.instance.started", version: "1.0.0" },
2947
+ { key: "workflow.step.entered", version: "1.0.0" },
2948
+ { key: "workflow.step.exited", version: "1.0.0" },
2949
+ { key: "workflow.instance.completed", version: "1.0.0" },
2950
+ { key: "workflow.instance.cancelled", version: "1.0.0" },
2951
+ { key: "workflow.instance.paused", version: "1.0.0" },
2952
+ { key: "workflow.instance.resumed", version: "1.0.0" },
2953
+ { key: "workflow.instance.failed", version: "1.0.0" },
2954
+ { key: "workflow.instance.timedOut", version: "1.0.0" },
2955
+ { key: "workflow.approval.requested", version: "1.0.0" },
2956
+ { key: "workflow.approval.decided", version: "1.0.0" },
2957
+ { key: "workflow.approval.delegated", version: "1.0.0" },
2958
+ { key: "workflow.approval.escalated", version: "1.0.0" }
2959
+ ],
2960
+ presentations: [
2961
+ { key: "workflow.designer", version: "1.0.0" },
2962
+ { key: "workflow.definition.viewList", version: "1.0.0" },
2963
+ { key: "workflow.definition.detail", version: "1.0.0" },
2964
+ { key: "workflow.instance.viewList", version: "1.0.0" },
2965
+ { key: "workflow.instance.detail", version: "1.0.0" },
2966
+ { key: "workflow.instance.progress", version: "1.0.0" },
2967
+ { key: "workflow.approval.inbox", version: "1.0.0" },
2968
+ { key: "workflow.approval.detail", version: "1.0.0" },
2969
+ { key: "workflow.approval.form", version: "1.0.0" },
2970
+ { key: "workflow.approval.badge", version: "1.0.0" },
2971
+ { key: "workflow.metrics", version: "1.0.0" }
2972
+ ],
2973
+ opToPresentation: [
2974
+ {
2975
+ op: { key: "workflow.definition.list", version: "1.0.0" },
2976
+ pres: { key: "workflow.definition.viewList", version: "1.0.0" }
2977
+ },
2978
+ {
2979
+ op: { key: "workflow.instance.list", version: "1.0.0" },
2980
+ pres: { key: "workflow.instance.viewList", version: "1.0.0" }
2981
+ },
2982
+ {
2983
+ op: { key: "workflow.approval.list.mine", version: "1.0.0" },
2984
+ pres: { key: "workflow.approval.inbox", version: "1.0.0" }
2985
+ },
2986
+ {
2987
+ op: { key: "workflow.approval.decide", version: "1.0.0" },
2988
+ pres: { key: "workflow.approval.form", version: "1.0.0" }
2989
+ }
2990
+ ],
2991
+ presentationsTargets: [
2992
+ { key: "workflow.designer", version: "1.0.0", targets: ["react"] },
2993
+ {
2994
+ key: "workflow.definition.viewList",
2995
+ version: "1.0.0",
2996
+ targets: ["react", "markdown"]
2997
+ },
2998
+ {
2999
+ key: "workflow.definition.detail",
3000
+ version: "1.0.0",
3001
+ targets: ["react", "markdown"]
3002
+ },
3003
+ {
3004
+ key: "workflow.instance.viewList",
3005
+ version: "1.0.0",
3006
+ targets: ["react", "markdown"]
3007
+ },
3008
+ {
3009
+ key: "workflow.instance.detail",
3010
+ version: "1.0.0",
3011
+ targets: ["react", "markdown"]
3012
+ },
3013
+ { key: "workflow.instance.progress", version: "1.0.0", targets: ["react"] },
3014
+ {
3015
+ key: "workflow.approval.inbox",
3016
+ version: "1.0.0",
3017
+ targets: ["react", "markdown"]
3018
+ },
3019
+ {
3020
+ key: "workflow.approval.detail",
3021
+ version: "1.0.0",
3022
+ targets: ["react", "markdown"]
3023
+ },
3024
+ {
3025
+ key: "workflow.metrics",
3026
+ version: "1.0.0",
3027
+ targets: ["react", "markdown"]
3028
+ }
3029
+ ],
3030
+ capabilities: {
3031
+ requires: [
3032
+ { key: "identity", version: "1.0.0" },
3033
+ { key: "audit-trail", version: "1.0.0" },
3034
+ { key: "notifications", version: "1.0.0" },
3035
+ { key: "feature-flags", version: "1.0.0" }
3036
+ ],
3037
+ provides: [
3038
+ { key: "workflow", version: "1.0.0" },
3039
+ { key: "approval", version: "1.0.0" },
3040
+ { key: "state-machine", version: "1.0.0" }
3041
+ ]
3042
+ },
3043
+ workflows: [
3044
+ { key: "workflow-system.workflow.approval-chain", version: "1.0.0" }
3045
+ ],
3046
+ telemetry: [{ key: "workflow-system.telemetry", version: "1.0.0" }],
3047
+ jobs: [
3048
+ { key: "workflow-system.job.instance-timeout", version: "1.0.0" },
3049
+ { key: "workflow-system.job.escalation", version: "1.0.0" }
3050
+ ],
3051
+ docs: [
3052
+ "docs.examples.workflow-system",
3053
+ "docs.examples.workflow-system.goal",
3054
+ "docs.examples.workflow-system.usage",
3055
+ "docs.examples.workflow-system.constraints"
3056
+ ]
3057
+ });
3060
3058
  export {
3061
3059
  workflowInstanceDetailMarkdownRenderer,
3062
3060
  workflowDefinitionListMarkdownRenderer,