@sanity/workflow-engine 0.10.0 → 0.11.0
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/_chunks-cjs/schema.cjs +41 -5
- package/dist/_chunks-cjs/schema.cjs.map +1 -1
- package/dist/_chunks-es/schema.js +41 -5
- package/dist/_chunks-es/schema.js.map +1 -1
- package/dist/define.cjs +53 -2
- package/dist/define.cjs.map +1 -1
- package/dist/define.d.cts +380 -2
- package/dist/define.d.ts +380 -2
- package/dist/define.js +53 -2
- package/dist/define.js.map +1 -1
- package/dist/index.cjs +61 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +718 -2
- package/dist/index.d.ts +718 -2
- package/dist/index.js +62 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parse, evaluate } from "groq-js";
|
|
2
2
|
import { actorFulfillsRole, isTerminalTaskStatus, WORKFLOW_DEFINITION_TYPE, andConditions, DOCUMENT_VALUE_PERMISSIONS } from "./_chunks-es/schema.js";
|
|
3
|
-
import { isStartableDefinition } from "./_chunks-es/schema.js";
|
|
3
|
+
import { DRIVER_KINDS, TASK_KINDS, isStartableDefinition } from "./_chunks-es/schema.js";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
function findOpenStageEntry(host) {
|
|
6
6
|
return host.stages.find((s) => s.name === host.currentStage && s.exitedAt === void 0);
|
|
@@ -1651,12 +1651,16 @@ function buildInstanceBase(args) {
|
|
|
1651
1651
|
lastChangedAt: now
|
|
1652
1652
|
};
|
|
1653
1653
|
}
|
|
1654
|
-
const
|
|
1654
|
+
const ENGINE_ACTOR_ID_PREFIX = "engine.";
|
|
1655
|
+
function engineSystemActor(name) {
|
|
1656
|
+
return { kind: "system", id: `${ENGINE_ACTOR_ID_PREFIX}${name}` };
|
|
1657
|
+
}
|
|
1658
|
+
function isEngineActor(actor) {
|
|
1659
|
+
return actor.kind === "system" && actor.id.startsWith(ENGINE_ACTOR_ID_PREFIX);
|
|
1660
|
+
}
|
|
1661
|
+
const MAX_SPAWN_DEPTH = 6, SUBWORKFLOWS_ALL_DONE = "count($subworkflows[status != 'done']) == 0";
|
|
1655
1662
|
function gateActor(outcome) {
|
|
1656
|
-
return
|
|
1657
|
-
kind: "system",
|
|
1658
|
-
id: outcome === "failed" ? FAIL_WHEN_SYSTEM_ID : COMPLETE_WHEN_SYSTEM_ID
|
|
1659
|
-
};
|
|
1663
|
+
return engineSystemActor(outcome === "failed" ? "failWhen" : "completeWhen");
|
|
1660
1664
|
}
|
|
1661
1665
|
function effectiveCompleteWhen(task) {
|
|
1662
1666
|
return task.completeWhen ?? (task.subworkflows !== void 0 ? SUBWORKFLOWS_ALL_DONE : void 0);
|
|
@@ -2295,7 +2299,7 @@ function resolveMachineStep(mutation, task, entry, now) {
|
|
|
2295
2299
|
stage: mutation.currentStage,
|
|
2296
2300
|
to: "done",
|
|
2297
2301
|
at: now,
|
|
2298
|
-
actor:
|
|
2302
|
+
actor: engineSystemActor("machineStep")
|
|
2299
2303
|
});
|
|
2300
2304
|
}
|
|
2301
2305
|
async function buildStageTasks(ctx, stage) {
|
|
@@ -2783,6 +2787,18 @@ function editDisabledReason(args) {
|
|
|
2783
2787
|
if (!predicateSatisfied)
|
|
2784
2788
|
return { kind: "editor-not-permitted", predicate: effective === !0 ? "true" : effective };
|
|
2785
2789
|
}
|
|
2790
|
+
function hasItems(arr) {
|
|
2791
|
+
return arr !== void 0 && arr.length > 0;
|
|
2792
|
+
}
|
|
2793
|
+
function deriveTaskKind(task) {
|
|
2794
|
+
return hasItems(task.actions) ? "user" : hasItems(task.effects) ? "service" : task.completeWhen !== void 0 || task.subworkflows !== void 0 ? "receive" : "script";
|
|
2795
|
+
}
|
|
2796
|
+
function taskKind(task) {
|
|
2797
|
+
return task.kind ?? deriveTaskKind(task);
|
|
2798
|
+
}
|
|
2799
|
+
function driverKind(actor) {
|
|
2800
|
+
return actor.kind === "user" ? "person" : actor.kind === "ai" ? "agent" : isEngineActor(actor) ? "engine" : "service";
|
|
2801
|
+
}
|
|
2786
2802
|
async function evaluateInstance(args) {
|
|
2787
2803
|
const { client, tag, instanceId, resourceClients } = args, now = (args.clock ?? wallClock)();
|
|
2788
2804
|
validateTag(tag);
|
|
@@ -2972,6 +2988,7 @@ async function evaluateTask(args) {
|
|
|
2972
2988
|
return {
|
|
2973
2989
|
task,
|
|
2974
2990
|
status,
|
|
2991
|
+
kind: taskKind(task),
|
|
2975
2992
|
// "pending on actor" treats both `pending` and `active` as waiting on
|
|
2976
2993
|
// the assignee — pending tasks just haven't been activated yet, but
|
|
2977
2994
|
// they're still inbox items. The inbox reads the assignees-kind field
|
|
@@ -3226,7 +3243,7 @@ async function commitAction(ctx, taskName, actionName, callerParams, options) {
|
|
|
3226
3243
|
stage: stage.name,
|
|
3227
3244
|
task: taskName,
|
|
3228
3245
|
action: actionName,
|
|
3229
|
-
...actor !== void 0 ? { actor } : {}
|
|
3246
|
+
...actor !== void 0 ? { actor, driverKind: driverKind(actor) } : {}
|
|
3230
3247
|
});
|
|
3231
3248
|
const statusBefore = mutEntry.status, ranOps = await runOps({
|
|
3232
3249
|
ops: action.ops,
|
|
@@ -4054,7 +4071,7 @@ async function drainEffectsInternal(args) {
|
|
|
4054
4071
|
effectHandlers,
|
|
4055
4072
|
missingHandler,
|
|
4056
4073
|
logger
|
|
4057
|
-
} = args, drainerActor = args.access?.actor ??
|
|
4074
|
+
} = args, drainerActor = args.access?.actor ?? engineSystemActor("drainEffects"), completionAccess = {
|
|
4058
4075
|
actor: drainerActor,
|
|
4059
4076
|
...args.access?.grants !== void 0 ? { grants: args.access.grants } : {}
|
|
4060
4077
|
};
|
|
@@ -4571,6 +4588,35 @@ const HISTORY_DISPLAY = {
|
|
|
4571
4588
|
title: "Workflow instance",
|
|
4572
4589
|
description: "A running (or finished) workflow against its declared fields."
|
|
4573
4590
|
}
|
|
4591
|
+
}, TASK_KIND_DISPLAY = {
|
|
4592
|
+
user: {
|
|
4593
|
+
title: "User task",
|
|
4594
|
+
description: "A person acts via the app \u2014 renders action buttons ranked by outcome."
|
|
4595
|
+
},
|
|
4596
|
+
service: {
|
|
4597
|
+
title: "Service task",
|
|
4598
|
+
description: "An automated system or effect does the work \u2014 renders effect drain status."
|
|
4599
|
+
},
|
|
4600
|
+
script: {
|
|
4601
|
+
title: "Script task",
|
|
4602
|
+
description: "The engine runs a step inline and resolves on activation \u2014 an audit row."
|
|
4603
|
+
},
|
|
4604
|
+
manual: {
|
|
4605
|
+
title: "Manual task",
|
|
4606
|
+
description: "Work done off-system, acknowledged by a person or verified by a predicate \u2014 renders an instruction card with a deep-link."
|
|
4607
|
+
},
|
|
4608
|
+
receive: {
|
|
4609
|
+
title: "Receive task",
|
|
4610
|
+
description: 'No actor; the engine waits on a condition \u2014 renders "waiting until \u2026", no buttons.'
|
|
4611
|
+
}
|
|
4612
|
+
}, DRIVER_KIND_DISPLAY = {
|
|
4613
|
+
person: { title: "Person", description: "A human fired this action." },
|
|
4614
|
+
agent: { title: "Agent", description: "An AI agent fired this action." },
|
|
4615
|
+
service: { title: "Service", description: "An external system or Function fired this action." },
|
|
4616
|
+
engine: {
|
|
4617
|
+
title: "Engine",
|
|
4618
|
+
description: "The workflow engine itself drove this \u2014 a gate, machine step, or housekeeping."
|
|
4619
|
+
}
|
|
4574
4620
|
}, DISPLAY = {
|
|
4575
4621
|
...HISTORY_DISPLAY,
|
|
4576
4622
|
...FIELD_SLOT_DISPLAY,
|
|
@@ -4594,6 +4640,8 @@ export {
|
|
|
4594
4640
|
ConcurrentFireActionError,
|
|
4595
4641
|
DEFAULT_CONTENT_PERSPECTIVE,
|
|
4596
4642
|
DISPLAY,
|
|
4643
|
+
DRIVER_KINDS,
|
|
4644
|
+
DRIVER_KIND_DISPLAY,
|
|
4597
4645
|
EFFECTS_CONTEXT_DISPLAY,
|
|
4598
4646
|
EditFieldDeniedError,
|
|
4599
4647
|
FIELD_SLOT_DISPLAY,
|
|
@@ -4605,6 +4653,8 @@ export {
|
|
|
4605
4653
|
OP_DISPLAY,
|
|
4606
4654
|
PartialGuardDeployError,
|
|
4607
4655
|
RequiredFieldNotProvidedError,
|
|
4656
|
+
TASK_KINDS,
|
|
4657
|
+
TASK_KIND_DISPLAY,
|
|
4608
4658
|
WORKFLOW_DEFINITION_TYPE,
|
|
4609
4659
|
WORKFLOW_INSTANCE_TYPE,
|
|
4610
4660
|
WorkflowStateDivergedError,
|
|
@@ -4620,11 +4670,13 @@ export {
|
|
|
4620
4670
|
defaultLoggerFactory,
|
|
4621
4671
|
denyingGuards,
|
|
4622
4672
|
deployStageGuards,
|
|
4673
|
+
deriveTaskKind,
|
|
4623
4674
|
diagnoseInputFromEvaluation,
|
|
4624
4675
|
diagnoseInstance,
|
|
4625
4676
|
diffEntry,
|
|
4626
4677
|
displayDescription,
|
|
4627
4678
|
displayTitle,
|
|
4679
|
+
driverKind,
|
|
4628
4680
|
effectsContextMap,
|
|
4629
4681
|
evaluateFromSnapshot,
|
|
4630
4682
|
evaluateMutationGuard,
|
|
@@ -4657,6 +4709,7 @@ export {
|
|
|
4657
4709
|
subscriptionDocument,
|
|
4658
4710
|
subscriptionDocumentsForInstance,
|
|
4659
4711
|
tagScopeFilter,
|
|
4712
|
+
taskKind,
|
|
4660
4713
|
validateDefinition,
|
|
4661
4714
|
validateTag,
|
|
4662
4715
|
verdictGuardsForInstance,
|