@memberjunction/task-graph 0.0.0 → 6.1.0-edge.2

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.
Files changed (51) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +167 -27
  3. package/dist/DispatcherConditionEvaluator.d.ts +10 -0
  4. package/dist/DispatcherConditionEvaluator.d.ts.map +1 -0
  5. package/dist/DispatcherConditionEvaluator.js +27 -0
  6. package/dist/DispatcherConditionEvaluator.js.map +1 -0
  7. package/dist/TaskClaimStore.d.ts +125 -0
  8. package/dist/TaskClaimStore.d.ts.map +1 -0
  9. package/dist/TaskClaimStore.js +223 -0
  10. package/dist/TaskClaimStore.js.map +1 -0
  11. package/dist/TaskGraphDispatcher.d.ts +548 -0
  12. package/dist/TaskGraphDispatcher.d.ts.map +1 -0
  13. package/dist/TaskGraphDispatcher.js +2232 -0
  14. package/dist/TaskGraphDispatcher.js.map +1 -0
  15. package/dist/TaskGraphService.d.ts +247 -0
  16. package/dist/TaskGraphService.d.ts.map +1 -0
  17. package/dist/TaskGraphService.js +753 -0
  18. package/dist/TaskGraphService.js.map +1 -0
  19. package/dist/TaskGraphSubmitterImpl.d.ts +7 -0
  20. package/dist/TaskGraphSubmitterImpl.d.ts.map +1 -0
  21. package/dist/TaskGraphSubmitterImpl.js +52 -0
  22. package/dist/TaskGraphSubmitterImpl.js.map +1 -0
  23. package/dist/TaskLoopExecutor.d.ts +62 -0
  24. package/dist/TaskLoopExecutor.d.ts.map +1 -0
  25. package/dist/TaskLoopExecutor.js +248 -0
  26. package/dist/TaskLoopExecutor.js.map +1 -0
  27. package/dist/WorkflowSpecSync.d.ts +197 -0
  28. package/dist/WorkflowSpecSync.d.ts.map +1 -0
  29. package/dist/WorkflowSpecSync.js +474 -0
  30. package/dist/WorkflowSpecSync.js.map +1 -0
  31. package/dist/index.d.ts +19 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +19 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/operations/TaskGraphOperations.d.ts +39 -0
  36. package/dist/operations/TaskGraphOperations.d.ts.map +1 -0
  37. package/dist/operations/TaskGraphOperations.js +168 -0
  38. package/dist/operations/TaskGraphOperations.js.map +1 -0
  39. package/dist/operations/WorkflowDraftOperation.d.ts +37 -0
  40. package/dist/operations/WorkflowDraftOperation.d.ts.map +1 -0
  41. package/dist/operations/WorkflowDraftOperation.js +141 -0
  42. package/dist/operations/WorkflowDraftOperation.js.map +1 -0
  43. package/dist/operations/WorkflowOperations.d.ts +22 -0
  44. package/dist/operations/WorkflowOperations.d.ts.map +1 -0
  45. package/dist/operations/WorkflowOperations.js +99 -0
  46. package/dist/operations/WorkflowOperations.js.map +1 -0
  47. package/dist/types.d.ts +328 -0
  48. package/dist/types.d.ts.map +1 -0
  49. package/dist/types.js +9 -0
  50. package/dist/types.js.map +1 -0
  51. package/package.json +36 -8
@@ -0,0 +1,168 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * @fileoverview Remote Operation implementations for the task-graph control plane.
9
+ *
10
+ * **Why these exist rather than bespoke GraphQL mutations.** Remote Operations are MJ's *typed
11
+ * control plane* — one call site reachable from MCP (external agents), from an Action wrapper
12
+ * (internal agents), and from the UI. Phase 2 originally shipped `SubmitTaskGraph` /
13
+ * `CancelTaskGraph` / `RetryTask` as GraphQL mutations, which fixed the durability problem but left
14
+ * the reachability one exactly where it was: callable from the Explorer client and nothing else.
15
+ *
16
+ * That was inconsistent with the closest analogous substrate — Record Set Processing exposes
17
+ * `Run` / `Pause` / `Resume` / `Cancel` / `Get Run Status` entirely as Remote Operations — and it
18
+ * undercut the program's own goal of letting agents *set up* workflows rather than only navigate to
19
+ * them. These operations replace those mutations.
20
+ *
21
+ * Each row is `GenerationType=Manual`, so CodeGen emits a typed base into `@memberjunction/core-entities`
22
+ * and these subclasses supply the body. All logic stays in `TaskGraphService`; these are thin
23
+ * adapters, and the last registration wins by import order per the ClassFactory contract.
24
+ *
25
+ * @module @memberjunction/task-graph
26
+ */
27
+ import { RegisterClass } from '@memberjunction/global';
28
+ import { BaseRemotableOperation, RunView } from '@memberjunction/core';
29
+ import { TaskGraphSubmitOperation, TaskGraphCancelOperation, TaskGraphRetryTaskOperation, TaskGraphGetStatusOperation, } from '@memberjunction/core-entities';
30
+ import { ComputeParentRollup } from '@memberjunction/ai-core-plus';
31
+ import { TaskGraphService } from '../TaskGraphService.js';
32
+ import { LoadWorkflowDraftOperation } from './WorkflowDraftOperation.js';
33
+ /**
34
+ * Builds the service context from the operation's provider + user.
35
+ *
36
+ * `environmentID` is empty on the cancel/retry paths and that is not a placeholder: the graph
37
+ * already exists, so nothing is created that would need one, and `TaskGraphService` reads the field
38
+ * only while persisting a new graph.
39
+ */
40
+ function submitContext(provider, user, environmentID, conversationDetailID) {
41
+ return {
42
+ EnvironmentID: environmentID,
43
+ ConversationDetailID: conversationDetailID ?? null,
44
+ ContextUser: user,
45
+ Provider: provider,
46
+ };
47
+ }
48
+ /**
49
+ * `TaskGraph.Submit` — validate and durably persist a graph, returning immediately.
50
+ *
51
+ * Returning before execution is the point: the caller is freed the moment the work is safe, and the
52
+ * dispatcher owns it from there. That is what lets an agent submit a graph over MCP without holding
53
+ * anything open.
54
+ */
55
+ let TaskGraphSubmitServerOperation = class TaskGraphSubmitServerOperation extends TaskGraphSubmitOperation {
56
+ async InternalExecute(input, provider, user) {
57
+ if (!input?.spec)
58
+ throw new Error('spec is required');
59
+ if (!input?.environmentID)
60
+ throw new Error('environmentID is required');
61
+ const spec = input.spec;
62
+ const result = await new TaskGraphService().Submit(spec, submitContext(provider, user, input.environmentID, input.conversationDetailID));
63
+ return {
64
+ success: result.Success,
65
+ parentTaskID: result.ParentTaskID,
66
+ errorMessage: result.ErrorMessage,
67
+ };
68
+ }
69
+ };
70
+ TaskGraphSubmitServerOperation = __decorate([
71
+ RegisterClass(BaseRemotableOperation, 'TaskGraph.Submit')
72
+ ], TaskGraphSubmitServerOperation);
73
+ export { TaskGraphSubmitServerOperation };
74
+ /** `TaskGraph.Cancel` — cancel a graph and every task in it that has not already settled. */
75
+ let TaskGraphCancelServerOperation = class TaskGraphCancelServerOperation extends TaskGraphCancelOperation {
76
+ async InternalExecute(input, provider, user) {
77
+ if (!input?.parentTaskID)
78
+ throw new Error('parentTaskID is required');
79
+ // EnvironmentID is unused on the cancel path — the graph already exists, so nothing new is
80
+ // created that would need one.
81
+ const ok = await new TaskGraphService().Cancel(input.parentTaskID, submitContext(provider, user, ''));
82
+ if (!ok)
83
+ return { success: false, errorMessage: 'Cancel failed; see the server log for detail.' };
84
+ const parent = await provider.GetEntityObject('MJ: Tasks', user);
85
+ const loaded = await parent.Load(input.parentTaskID);
86
+ return { success: true, status: loaded ? parent.Status : undefined };
87
+ }
88
+ };
89
+ TaskGraphCancelServerOperation = __decorate([
90
+ RegisterClass(BaseRemotableOperation, 'TaskGraph.Cancel')
91
+ ], TaskGraphCancelServerOperation);
92
+ export { TaskGraphCancelServerOperation };
93
+ /**
94
+ * `TaskGraph.RetryTask` — return a failed task to `Pending` and unblock its dependents.
95
+ *
96
+ * Unblocking is not optional: retrying a task while its dependents remain `Blocked` leaves the graph
97
+ * exactly as stuck as before, because nothing downstream ever becomes eligible again.
98
+ */
99
+ let TaskGraphRetryTaskServerOperation = class TaskGraphRetryTaskServerOperation extends TaskGraphRetryTaskOperation {
100
+ async InternalExecute(input, provider, user) {
101
+ if (!input?.taskID)
102
+ throw new Error('taskID is required');
103
+ const ok = await new TaskGraphService().Retry(input.taskID, submitContext(provider, user, ''));
104
+ if (!ok)
105
+ return { success: false, errorMessage: 'Retry failed; the task may not be in a Failed state.' };
106
+ const task = await provider.GetEntityObject('MJ: Tasks', user);
107
+ const loaded = await task.Load(input.taskID);
108
+ return { success: true, status: loaded ? task.Status : undefined };
109
+ }
110
+ };
111
+ TaskGraphRetryTaskServerOperation = __decorate([
112
+ RegisterClass(BaseRemotableOperation, 'TaskGraph.RetryTask')
113
+ ], TaskGraphRetryTaskServerOperation);
114
+ export { TaskGraphRetryTaskServerOperation };
115
+ /**
116
+ * `TaskGraph.GetStatus` — snapshot a graph's progress without waiting for anything.
117
+ *
118
+ * This is the observation half of making execution durable. Once nobody holds a request open, a
119
+ * caller — a client re-attaching after reload, an agent checking work it submitted, an external MCP
120
+ * caller — needs a way to ask "where is it?". The rollup uses the same pure algorithm the dispatcher
121
+ * uses, so the reported status cannot disagree with the engine's own view.
122
+ */
123
+ let TaskGraphGetStatusServerOperation = class TaskGraphGetStatusServerOperation extends TaskGraphGetStatusOperation {
124
+ async InternalExecute(input, provider, user) {
125
+ if (!input?.parentTaskID)
126
+ throw new Error('parentTaskID is required');
127
+ // Read-only snapshot, so `simple` + a narrow field list — no reason to pay for entity
128
+ // objects here. Scoped to the operation's own provider rather than the global default.
129
+ const children = await RunView.FromMetadataProvider(provider).RunView({
130
+ EntityName: 'MJ: Tasks',
131
+ ExtraFilter: `ParentID='${input.parentTaskID}'`,
132
+ Fields: ['ID', 'Name', 'Status', 'AgentRunID', 'ErrorMessage'],
133
+ ResultType: 'simple',
134
+ }, user);
135
+ if (!children.Success) {
136
+ return { success: false, errorMessage: children.ErrorMessage ?? 'Could not load the graph.' };
137
+ }
138
+ const rows = children.Results ?? [];
139
+ const rollup = ComputeParentRollup(rows.map((r) => ({ id: r.ID, status: r.Status })));
140
+ return {
141
+ success: true,
142
+ status: rollup.status,
143
+ percentComplete: rollup.percentComplete,
144
+ tasks: rows.map((r) => ({
145
+ taskID: r.ID,
146
+ name: r.Name,
147
+ status: r.Status,
148
+ agentRunID: r.AgentRunID ?? undefined,
149
+ errorMessage: r.ErrorMessage ?? undefined,
150
+ })),
151
+ };
152
+ }
153
+ };
154
+ TaskGraphGetStatusServerOperation = __decorate([
155
+ RegisterClass(BaseRemotableOperation, 'TaskGraph.GetStatus')
156
+ ], TaskGraphGetStatusServerOperation);
157
+ export { TaskGraphGetStatusServerOperation };
158
+ /** Prevents tree-shaking of the registered operation classes. */
159
+ export function LoadTaskGraphOperations() {
160
+ void TaskGraphSubmitServerOperation;
161
+ void TaskGraphCancelServerOperation;
162
+ void TaskGraphRetryTaskServerOperation;
163
+ void TaskGraphGetStatusServerOperation;
164
+ // Workflow authoring rides the same loader: a host that starts the dispatcher but never
165
+ // registered these would accept a draft request and route it to the contract-only base.
166
+ LoadWorkflowDraftOperation();
167
+ }
168
+ //# sourceMappingURL=TaskGraphOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TaskGraphOperations.js","sourceRoot":"","sources":["../../src/operations/TaskGraphOperations.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAqB,OAAO,EAAY,MAAM,sBAAsB,CAAC;AACpG,OAAO,EAEH,wBAAwB,EACxB,wBAAwB,EACxB,2BAA2B,EAC3B,2BAA2B,GAO9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAgD,MAAM,8BAA8B,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAA0B,MAAM,qBAAqB,CAAC;AAC/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAetE;;;;;;GAMG;AACH,SAAS,aAAa,CAClB,QAA2B,EAC3B,IAAc,EACd,aAAqB,EACrB,oBAAoC;IAEpC,OAAO;QACH,aAAa,EAAE,aAAa;QAC5B,oBAAoB,EAAE,oBAAoB,IAAI,IA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IAAI;YACb,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACpB,MAAM,EAAE,CAAC,CAAC,EAAE;gBACZ,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,MAAM,EAAE,CAAC,CAAC,MAAM;gBAChB,UAAU,EAAE,CAAC,CAAC,UAAU,IAAI,SAAS;gBACrC,YAAY,EAAE,CAAC,CAAC,YAAY,IAAI,SAAS;aAC5C,CAAC,CAAC;SACN,CAAC;IACN,CAAC;CACJ,CAAA;AAvCY,iCAAiC;IAD7C,aAAa,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;GAChD,iCAAiC,CAuC7C;;AAED,iEAAiE;AACjE,MAAM,UAAU,uBAAuB;IACnC,KAAK,8BAA8B,CAAC;IACpC,KAAK,8BAA8B,CAAC;IACpC,KAAK,iCAAiC,CAAC;IACvC,KAAK,iCAAiC,CAAC;IACvC,wFAAwF;IACxF,wFAAwF;IACxF,0BAA0B,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { IMetadataProvider, UserInfo } from '@memberjunction/core';
2
+ import { WorkflowDraftOperation, type WorkflowDraftInput, type WorkflowDraftOutput } from '@memberjunction/core-entities';
3
+ import { type TaskGraphSpec } from '@memberjunction/ai-core-plus';
4
+ /** The seeded prompt that does the drafting. */
5
+ export declare const WORKFLOW_DRAFTING_PROMPT = "Workflow Drafting";
6
+ /**
7
+ * How many agent names the prompt is told about.
8
+ *
9
+ * Bounded because the list goes into a prompt: an instance with hundreds of agents would spend most
10
+ * of its context enumerating them, and a model choosing between 300 names chooses worse than one
11
+ * choosing between 40. Top-level agents come first — those are the ones a workflow step can actually
12
+ * be assigned to.
13
+ */
14
+ export declare const MAX_AGENTS_OFFERED = 40;
15
+ /** `Workflow.Draft` — draft a workflow's steps from a description. Persists nothing. */
16
+ export declare class WorkflowDraftServerOperation extends WorkflowDraftOperation {
17
+ protected InternalExecute(input: WorkflowDraftInput, provider: IMetadataProvider, user: UserInfo): Promise<WorkflowDraftOutput>;
18
+ /**
19
+ * Checks the model's output against the SAME validator the canvas and `Workflow.Save` run.
20
+ *
21
+ * A draft that comes back must be savable. Returning something that only fails later — on the
22
+ * canvas, or worse at save time — would put the author in the position of debugging a graph they
23
+ * did not write, which is precisely the work this operation was meant to save them.
24
+ */
25
+ protected acceptDraft(draft: TaskGraphSpec, workflowName: string): WorkflowDraftOutput;
26
+ /**
27
+ * Agent names a step may be assigned to.
28
+ *
29
+ * Top-level agents only. A sub-agent exists to be called by its parent, so offering one as a
30
+ * workflow step would produce a draft that looks fine and assigns work to something that was
31
+ * never meant to be entered directly.
32
+ */
33
+ protected resolveAssignableAgents(provider: IMetadataProvider, user: UserInfo): Promise<string[]>;
34
+ }
35
+ /** Keeps the registration from being tree-shaken out of a bundled host. */
36
+ export declare function LoadWorkflowDraftOperation(): void;
37
+ //# sourceMappingURL=WorkflowDraftOperation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowDraftOperation.d.ts","sourceRoot":"","sources":["../../src/operations/WorkflowDraftOperation.ts"],"names":[],"mappings":"AAoBA,OAAO,EAA0B,iBAAiB,EAAqB,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EACH,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EAC3B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAIH,KAAK,aAAa,EACrB,MAAM,8BAA8B,CAAC;AAItC,gDAAgD;AAChD,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAErC,wFAAwF;AACxF,qBACa,4BAA6B,SAAQ,sBAAsB;cACpD,eAAe,CAC3B,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,QAAQ,GACf,OAAO,CAAC,mBAAmB,CAAC;IAgD/B;;;;;;OAMG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,GAAG,mBAAmB;IAetF;;;;;;OAMG;cACa,uBAAuB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAiB1G;AAED,2EAA2E;AAC3E,wBAAgB,0BAA0B,IAAI,IAAI,CAGjD"}
@@ -0,0 +1,141 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * @fileoverview `Workflow.Draft` — turn a description into a workflow's steps.
9
+ *
10
+ * **Why this exists.** The Create Workflow front door offers three doors, and the middle one says
11
+ * *"Say what you want done. We draft the steps; you refine them on the canvas."* Without this
12
+ * operation that sentence is a promise the product does not keep — the author types a brief and
13
+ * lands on an empty canvas, which is worse than not offering the door at all.
14
+ *
15
+ * **It persists nothing.** The draft goes back to the caller and onto the canvas; `Workflow.Save` is
16
+ * what commits. That split is what makes the tile's other promise — *"Nothing is saved until you
17
+ * approve it"* — true rather than merely stated, and it is the same draft-then-confirm shape dry-run
18
+ * and Plan Mode already established.
19
+ *
20
+ * **A Remote Operation, per the program's standing rule**, so drafting is reachable from MCP, an
21
+ * Action wrapper and the editor by the same typed call — not a mutation only the Explorer client can
22
+ * make.
23
+ *
24
+ * @module @memberjunction/task-graph
25
+ */
26
+ import { RegisterClass } from '@memberjunction/global';
27
+ import { BaseRemotableOperation, LogError, RunView } from '@memberjunction/core';
28
+ import { WorkflowDraftOperation, } from '@memberjunction/core-entities';
29
+ import { AIPromptParams, FormatValidationErrors, ValidateTaskGraphSpec, } from '@memberjunction/ai-core-plus';
30
+ import { AIEngine } from '@memberjunction/aiengine';
31
+ import { AIPromptRunner } from '@memberjunction/ai-prompts';
32
+ /** The seeded prompt that does the drafting. */
33
+ export const WORKFLOW_DRAFTING_PROMPT = 'Workflow Drafting';
34
+ /**
35
+ * How many agent names the prompt is told about.
36
+ *
37
+ * Bounded because the list goes into a prompt: an instance with hundreds of agents would spend most
38
+ * of its context enumerating them, and a model choosing between 300 names chooses worse than one
39
+ * choosing between 40. Top-level agents come first — those are the ones a workflow step can actually
40
+ * be assigned to.
41
+ */
42
+ export const MAX_AGENTS_OFFERED = 40;
43
+ /** `Workflow.Draft` — draft a workflow's steps from a description. Persists nothing. */
44
+ let WorkflowDraftServerOperation = class WorkflowDraftServerOperation extends WorkflowDraftOperation {
45
+ async InternalExecute(input, provider, user) {
46
+ const description = input?.description?.trim();
47
+ const workflowName = input?.workflowName?.trim();
48
+ if (!description)
49
+ return { success: false, errorMessage: 'A description is required to draft a workflow.' };
50
+ if (!workflowName)
51
+ return { success: false, errorMessage: 'A workflow name is required.' };
52
+ try {
53
+ await AIEngine.Instance.Config(false, user, provider);
54
+ const prompt = AIEngine.Instance.Prompts.find((p) => p.Name === WORKFLOW_DRAFTING_PROMPT);
55
+ if (!prompt) {
56
+ return {
57
+ success: false,
58
+ errorMessage: `The '${WORKFLOW_DRAFTING_PROMPT}' prompt is not present — has the metadata seed been pushed?`,
59
+ };
60
+ }
61
+ const agentNames = await this.resolveAssignableAgents(provider, user);
62
+ if (agentNames.length === 0) {
63
+ // Stated rather than drafted around: every step needs an assignment, so a draft
64
+ // produced with no agents to assign would be invalid the moment it was validated.
65
+ return {
66
+ success: false,
67
+ errorMessage: 'No agents are available to run workflow steps on this instance, so there is nothing to draft with.',
68
+ };
69
+ }
70
+ const params = new AIPromptParams();
71
+ params.prompt = prompt;
72
+ params.contextUser = user;
73
+ params.data = {
74
+ description,
75
+ workflowName,
76
+ availableAgents: agentNames.join('\n'),
77
+ };
78
+ const result = await new AIPromptRunner().ExecutePrompt(params);
79
+ if (!result.success || !result.result) {
80
+ return { success: false, errorMessage: result.errorMessage ?? 'The workflow could not be drafted.' };
81
+ }
82
+ return this.acceptDraft(result.result, workflowName);
83
+ }
84
+ catch (e) {
85
+ const message = e instanceof Error ? e.message : String(e);
86
+ LogError(`[Workflow.Draft] Drafting failed for "${workflowName}": ${message}`);
87
+ return { success: false, errorMessage: message };
88
+ }
89
+ }
90
+ /**
91
+ * Checks the model's output against the SAME validator the canvas and `Workflow.Save` run.
92
+ *
93
+ * A draft that comes back must be savable. Returning something that only fails later — on the
94
+ * canvas, or worse at save time — would put the author in the position of debugging a graph they
95
+ * did not write, which is precisely the work this operation was meant to save them.
96
+ */
97
+ acceptDraft(draft, workflowName) {
98
+ // The name is the author's, not the model's: they typed it on the front door, and a model
99
+ // quietly renaming their workflow is a small betrayal of a field they filled in themselves.
100
+ const graph = { ...draft, workflowName };
101
+ const validation = ValidateTaskGraphSpec(graph);
102
+ if (!validation.Valid) {
103
+ return {
104
+ success: false,
105
+ errorMessage: `The drafted workflow was not usable:\n${FormatValidationErrors(validation.Errors)}`,
106
+ };
107
+ }
108
+ return { success: true, graph };
109
+ }
110
+ /**
111
+ * Agent names a step may be assigned to.
112
+ *
113
+ * Top-level agents only. A sub-agent exists to be called by its parent, so offering one as a
114
+ * workflow step would produce a draft that looks fine and assigns work to something that was
115
+ * never meant to be entered directly.
116
+ */
117
+ async resolveAssignableAgents(provider, user) {
118
+ const result = await RunView.FromMetadataProvider(provider).RunView({
119
+ EntityName: 'MJ: AI Agents',
120
+ ExtraFilter: `Status='Active' AND ParentID IS NULL`,
121
+ Fields: ['Name'],
122
+ OrderBy: 'Name ASC',
123
+ MaxRows: MAX_AGENTS_OFFERED,
124
+ ResultType: 'simple',
125
+ }, user);
126
+ if (!result.Success) {
127
+ throw new Error(result.ErrorMessage ?? 'The list of available agents could not be read.');
128
+ }
129
+ return (result.Results ?? []).map((a) => a.Name).filter((n) => !!n);
130
+ }
131
+ };
132
+ WorkflowDraftServerOperation = __decorate([
133
+ RegisterClass(BaseRemotableOperation, 'Workflow.Draft')
134
+ ], WorkflowDraftServerOperation);
135
+ export { WorkflowDraftServerOperation };
136
+ /** Keeps the registration from being tree-shaken out of a bundled host. */
137
+ export function LoadWorkflowDraftOperation() {
138
+ // Referencing the class is what the bundler needs.
139
+ void WorkflowDraftServerOperation;
140
+ }
141
+ //# sourceMappingURL=WorkflowDraftOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowDraftOperation.js","sourceRoot":"","sources":["../../src/operations/WorkflowDraftOperation.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAqB,QAAQ,EAAE,OAAO,EAAY,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EACH,sBAAsB,GAGzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,cAAc,EACd,sBAAsB,EACtB,qBAAqB,GAExB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,gDAAgD;AAChD,MAAM,CAAC,MAAM,wBAAwB,GAAG,mBAAmB,CAAC;AAE5D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC,wFAAwF;AAEjF,IAAM,4BAA4B,GAAlC,MAAM,4BAA6B,SAAQ,sBAAsB;IAC1D,KAAK,CAAC,eAAe,CAC3B,KAAyB,EACzB,QAA2B,EAC3B,IAAc;QAE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AM,MAAM,GAAG,MAAM,OAAO,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,OAAO,CAC/D;YACI,UAAU,EAAE,eAAe;YAC3B,WAAW,EAAE,sCAAsC;YACnD,MAAM,EAAE,CAAC,MAAM,CAAC;YAChB,OAAO,EAAE,UAAU;YACnB,OAAO,EAAE,kBAAkB;YAC3B,UAAU,EAAE,QAAQ;SACvB,EACD,IAAI,CACP,CAAC;QACF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,YAAY,IAAI,iDAAiD,CAAC,CAAC;QAC9F,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;CACJ,CAAA;AAnGY,4BAA4B;IADxC,aAAa,CAAC,sBAAsB,EAAE,gBAAgB,CAAC;GAC3C,4BAA4B,CAmGxC;;AAED,2EAA2E;AAC3E,MAAM,UAAU,0BAA0B;IACtC,mDAAmD;IACnD,KAAK,4BAA4B,CAAC;AACtC,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { IMetadataProvider, UserInfo } from '@memberjunction/core';
2
+ import { WorkflowSaveOperation, WorkflowValidateOperation, type WorkflowSaveInput, type WorkflowSaveOutput, type WorkflowValidateOutput } from '@memberjunction/core-entities';
3
+ import { ValidateWorkflowSpec } from '@memberjunction/ai-core-plus';
4
+ /** `Workflow.Save` — validate a workflow and reconcile every substrate it owns. */
5
+ export declare class WorkflowSaveServerOperation extends WorkflowSaveOperation {
6
+ protected InternalExecute(input: WorkflowSaveInput, provider: IMetadataProvider, user: UserInfo): Promise<WorkflowSaveOutput>;
7
+ }
8
+ /**
9
+ * `Workflow.Validate` — check a workflow without saving it.
10
+ *
11
+ * Writes nothing, which is the point: an agent drafting a workflow can iterate until it is right
12
+ * before anything reaches the scheduler. Reports every failure at once rather than the first, so a
13
+ * fix takes one round-trip rather than several.
14
+ */
15
+ export declare class WorkflowValidateServerOperation extends WorkflowValidateOperation {
16
+ protected InternalExecute(input: WorkflowSaveInput, _provider: IMetadataProvider, _user: UserInfo): Promise<WorkflowValidateOutput>;
17
+ }
18
+ /** Renders validation failures for a caller that wants one string. */
19
+ export declare function FormatWorkflowErrors(errors: ReturnType<typeof ValidateWorkflowSpec>['Errors']): string;
20
+ /** Prevents tree-shaking of the registered operation classes. */
21
+ export declare function LoadWorkflowOperations(): void;
22
+ //# sourceMappingURL=WorkflowOperations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowOperations.d.ts","sourceRoot":"","sources":["../../src/operations/WorkflowOperations.ts"],"names":[],"mappings":"AAiBA,OAAO,EAA0B,iBAAiB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EACH,qBAAqB,EACrB,yBAAyB,EACzB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEH,oBAAoB,EAEvB,MAAM,8BAA8B,CAAC;AAmBtC,mFAAmF;AACnF,qBACa,2BAA4B,SAAQ,qBAAqB;cAClD,eAAe,CAC3B,KAAK,EAAE,iBAAiB,EACxB,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,QAAQ,GACf,OAAO,CAAC,kBAAkB,CAAC;CAmBjC;AAED;;;;;;GAMG;AACH,qBACa,+BAAgC,SAAQ,yBAAyB;cAC1D,eAAe,CAC3B,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,iBAAiB,EAC5B,KAAK,EAAE,QAAQ,GAChB,OAAO,CAAC,sBAAsB,CAAC;CAWrC;AAED,sEAAsE;AACtE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,CAEtG;AAED,iEAAiE;AACjE,wBAAgB,sBAAsB,IAAI,IAAI,CAG7C"}
@@ -0,0 +1,99 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ /**
8
+ * @fileoverview Remote Operations for authoring workflows.
9
+ *
10
+ * **This is the hole the program set out to close.** Agents could already *navigate* to a workflow;
11
+ * they could not *set one up*. Today `Create Scheduled Job` cannot even set `Configuration`, so an
12
+ * agent asked to "run this every Monday" had nothing to call. These two operations make authoring a
13
+ * workflow — steps and triggers together — a single typed call reachable from MCP (external agents),
14
+ * an Action wrapper (internal agents), and the editor.
15
+ *
16
+ * **Two operations, not one, because drafting and committing are different acts.** `Validate` lets an
17
+ * agent iterate on a draft without writing anything — the draft-then-confirm shape dry-run and Plan
18
+ * Mode already established. `Save` commits. Both run the identical validator, so a workflow that
19
+ * validates cannot then be rejected on save for a different reason.
20
+ *
21
+ * @module @memberjunction/task-graph
22
+ */
23
+ import { RegisterClass, MJGlobal } from '@memberjunction/global';
24
+ import { BaseRemotableOperation } from '@memberjunction/core';
25
+ import { WorkflowSaveOperation, WorkflowValidateOperation, } from '@memberjunction/core-entities';
26
+ import { FormatWorkflowValidationErrors, ValidateWorkflowSpec, } from '@memberjunction/ai-core-plus';
27
+ import { WorkflowSpecSync } from '../WorkflowSpecSync.js';
28
+ /**
29
+ * Resolves the host's agent writer, or null.
30
+ *
31
+ * Looked up through the ClassFactory rather than imported so this package does not depend on the
32
+ * agent-manager. Null is a legitimate configuration (a worker, a test) and produces an honest
33
+ * failure rather than a half-saved workflow.
34
+ */
35
+ function resolveAgentWriter() {
36
+ return MJGlobal.Instance.ClassFactory.CreateInstance(
37
+ // The base class is declared in the agent-manager; resolving by key alone keeps this package
38
+ // free of that import while still finding whatever the host registered.
39
+ Object, 'WorkflowAgentWriter');
40
+ }
41
+ /** `Workflow.Save` — validate a workflow and reconcile every substrate it owns. */
42
+ let WorkflowSaveServerOperation = class WorkflowSaveServerOperation extends WorkflowSaveOperation {
43
+ async InternalExecute(input, provider, user) {
44
+ if (!input?.spec)
45
+ throw new Error('spec is required');
46
+ const spec = input.spec;
47
+ const result = await new WorkflowSpecSync(resolveAgentWriter()).Persist(spec, {
48
+ ContextUser: user,
49
+ Provider: provider,
50
+ });
51
+ return {
52
+ success: result.Success,
53
+ agentID: result.AgentID,
54
+ scheduledJobIDs: result.ScheduledJobIDs,
55
+ // Surfaced, not swallowed: a user who asked for "run this when an invoice changes" and
56
+ // got a workflow that never fires has no way to discover why from the UI alone.
57
+ unreconciled: result.Unreconciled.length ? result.Unreconciled : undefined,
58
+ errorMessage: result.ErrorMessage,
59
+ };
60
+ }
61
+ };
62
+ WorkflowSaveServerOperation = __decorate([
63
+ RegisterClass(BaseRemotableOperation, 'Workflow.Save')
64
+ ], WorkflowSaveServerOperation);
65
+ export { WorkflowSaveServerOperation };
66
+ /**
67
+ * `Workflow.Validate` — check a workflow without saving it.
68
+ *
69
+ * Writes nothing, which is the point: an agent drafting a workflow can iterate until it is right
70
+ * before anything reaches the scheduler. Reports every failure at once rather than the first, so a
71
+ * fix takes one round-trip rather than several.
72
+ */
73
+ let WorkflowValidateServerOperation = class WorkflowValidateServerOperation extends WorkflowValidateOperation {
74
+ async InternalExecute(input, _provider, _user) {
75
+ if (!input?.spec)
76
+ throw new Error('spec is required');
77
+ const validation = ValidateWorkflowSpec(input.spec);
78
+ return {
79
+ valid: validation.Valid,
80
+ errors: validation.Errors.length
81
+ ? validation.Errors.map((e) => ({ code: e.Code, message: e.Message, triggerIndex: e.TriggerIndex }))
82
+ : undefined,
83
+ };
84
+ }
85
+ };
86
+ WorkflowValidateServerOperation = __decorate([
87
+ RegisterClass(BaseRemotableOperation, 'Workflow.Validate')
88
+ ], WorkflowValidateServerOperation);
89
+ export { WorkflowValidateServerOperation };
90
+ /** Renders validation failures for a caller that wants one string. */
91
+ export function FormatWorkflowErrors(errors) {
92
+ return FormatWorkflowValidationErrors(errors);
93
+ }
94
+ /** Prevents tree-shaking of the registered operation classes. */
95
+ export function LoadWorkflowOperations() {
96
+ void WorkflowSaveServerOperation;
97
+ void WorkflowValidateServerOperation;
98
+ }
99
+ //# sourceMappingURL=WorkflowOperations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WorkflowOperations.js","sourceRoot":"","sources":["../../src/operations/WorkflowOperations.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAA+B,MAAM,sBAAsB,CAAC;AAC3F,OAAO,EACH,qBAAqB,EACrB,yBAAyB,GAI5B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,8BAA8B,EAC9B,oBAAoB,GAEvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAA4B,MAAM,qBAAqB,CAAC;AAEjF;;;;;;GAMG;AACH,SAAS,kBAAkB;IACvB,OAAO,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,cAAc;IAChD,6FAA6F;IAC7F,wEAAwE;IACxE,MAAkD,EAClD,qBAAqB,CACxB,CAAC;AACN,CAAC;AAED,mFAAmF;AAE5E,IAAM,2BAA2B,GAAjC,MAAM,2BAA4B,SAAQ,qBAAqB;IACxD,KAAK,CAAC,eAAe,CAC3B,KAAwB,EACxB,QAA2B,EAC3B,IAAc;QAEd,IAAI,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