@exellix/graph-engine 6.0.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.
Files changed (202) hide show
  1. package/.env.example +3 -0
  2. package/CHANGELOG.md +208 -0
  3. package/README.md +827 -0
  4. package/dist/src/errors/ExellixGraphError.d.ts +38 -0
  5. package/dist/src/errors/ExellixGraphError.js +21 -0
  6. package/dist/src/errors/exellixGraphErrorCodes.d.ts +31 -0
  7. package/dist/src/errors/exellixGraphErrorCodes.js +32 -0
  8. package/dist/src/index.d.ts +100 -0
  9. package/dist/src/index.js +75 -0
  10. package/dist/src/inspection/contractInspection.d.ts +21 -0
  11. package/dist/src/inspection/contractInspection.js +526 -0
  12. package/dist/src/inspection/contractTypes.d.ts +137 -0
  13. package/dist/src/inspection/contractTypes.js +1 -0
  14. package/dist/src/inspection/controlInspection.d.ts +22 -0
  15. package/dist/src/inspection/controlInspection.js +130 -0
  16. package/dist/src/inspection/graphInspection.d.ts +51 -0
  17. package/dist/src/inspection/graphInspection.js +467 -0
  18. package/dist/src/inspection/index.d.ts +21 -0
  19. package/dist/src/inspection/index.js +17 -0
  20. package/dist/src/inspection/nodeInspection.d.ts +42 -0
  21. package/dist/src/inspection/nodeInspection.js +474 -0
  22. package/dist/src/inspection/types.d.ts +321 -0
  23. package/dist/src/inspection/types.js +14 -0
  24. package/dist/src/inspection/validateAiTasksNodeExtensions.d.ts +12 -0
  25. package/dist/src/inspection/validateAiTasksNodeExtensions.js +119 -0
  26. package/dist/src/inspection/validateCatalogPlanning.d.ts +21 -0
  27. package/dist/src/inspection/validateCatalogPlanning.js +187 -0
  28. package/dist/src/integrations/ActivityTrackerIntegration.d.ts +86 -0
  29. package/dist/src/integrations/ActivityTrackerIntegration.js +134 -0
  30. package/dist/src/integrations/ActivixGraphRunIntegration.d.ts +34 -0
  31. package/dist/src/integrations/ActivixGraphRunIntegration.js +338 -0
  32. package/dist/src/integrations/ActivixNodeActivityIntegration.d.ts +33 -0
  33. package/dist/src/integrations/ActivixNodeActivityIntegration.js +220 -0
  34. package/dist/src/integrations/cataloxGraphCatalog.d.ts +21 -0
  35. package/dist/src/integrations/cataloxGraphCatalog.js +30 -0
  36. package/dist/src/integrations/createActivixExellixIntegration.d.ts +14 -0
  37. package/dist/src/integrations/createActivixExellixIntegration.js +16 -0
  38. package/dist/src/integrations/createActivixFromEnv.d.ts +31 -0
  39. package/dist/src/integrations/createActivixFromEnv.js +53 -0
  40. package/dist/src/loaders/FileGraphLoader.d.ts +23 -0
  41. package/dist/src/loaders/FileGraphLoader.js +31 -0
  42. package/dist/src/playground/PlaygroundReporter.d.ts +40 -0
  43. package/dist/src/playground/PlaygroundReporter.js +480 -0
  44. package/dist/src/playground/index.d.ts +1 -0
  45. package/dist/src/playground/index.js +1 -0
  46. package/dist/src/runtime/ExellixGraphRuntime.d.ts +263 -0
  47. package/dist/src/runtime/ExellixGraphRuntime.js +1716 -0
  48. package/dist/src/runtime/GraphEngine.d.ts +33 -0
  49. package/dist/src/runtime/GraphEngine.js +4 -0
  50. package/dist/src/runtime/aiTasksObservability.d.ts +6 -0
  51. package/dist/src/runtime/aiTasksObservability.js +37 -0
  52. package/dist/src/runtime/aiTasksStrategyPhases.d.ts +46 -0
  53. package/dist/src/runtime/aiTasksStrategyPhases.js +93 -0
  54. package/dist/src/runtime/applyAiTaskProfileWebScopingToNarrix.d.ts +17 -0
  55. package/dist/src/runtime/applyAiTaskProfileWebScopingToNarrix.js +46 -0
  56. package/dist/src/runtime/buildAiTasksRunTaskRequest.d.ts +67 -0
  57. package/dist/src/runtime/buildAiTasksRunTaskRequest.js +164 -0
  58. package/dist/src/runtime/buildRunLog.d.ts +27 -0
  59. package/dist/src/runtime/buildRunLog.js +234 -0
  60. package/dist/src/runtime/buildRunTaskTaskConfigurationForward.d.ts +9 -0
  61. package/dist/src/runtime/buildRunTaskTaskConfigurationForward.js +80 -0
  62. package/dist/src/runtime/buildTaskNodeJobContext.d.ts +11 -0
  63. package/dist/src/runtime/buildTaskNodeJobContext.js +30 -0
  64. package/dist/src/runtime/canonicalModelUsed.d.ts +6 -0
  65. package/dist/src/runtime/canonicalModelUsed.js +36 -0
  66. package/dist/src/runtime/contextualScope.d.ts +7 -0
  67. package/dist/src/runtime/contextualScope.js +121 -0
  68. package/dist/src/runtime/dataFiltersEvaluation.d.ts +60 -0
  69. package/dist/src/runtime/dataFiltersEvaluation.js +169 -0
  70. package/dist/src/runtime/deepMerge.d.ts +5 -0
  71. package/dist/src/runtime/deepMerge.js +22 -0
  72. package/dist/src/runtime/events.d.ts +92 -0
  73. package/dist/src/runtime/events.js +122 -0
  74. package/dist/src/runtime/executionMatrixHost.d.ts +98 -0
  75. package/dist/src/runtime/executionMatrixHost.js +134 -0
  76. package/dist/src/runtime/executionVariableBuckets.d.ts +67 -0
  77. package/dist/src/runtime/executionVariableBuckets.js +96 -0
  78. package/dist/src/runtime/finalizers/errors.d.ts +9 -0
  79. package/dist/src/runtime/finalizers/errors.js +10 -0
  80. package/dist/src/runtime/finalizers/executeFinalizer.d.ts +40 -0
  81. package/dist/src/runtime/finalizers/executeFinalizer.js +471 -0
  82. package/dist/src/runtime/finalizers/schema.d.ts +18 -0
  83. package/dist/src/runtime/finalizers/schema.js +63 -0
  84. package/dist/src/runtime/finalizers/validateFinalizer.d.ts +16 -0
  85. package/dist/src/runtime/finalizers/validateFinalizer.js +534 -0
  86. package/dist/src/runtime/graphDocumentFingerprint.d.ts +8 -0
  87. package/dist/src/runtime/graphDocumentFingerprint.js +21 -0
  88. package/dist/src/runtime/graphEngineMemoryPaths.d.ts +12 -0
  89. package/dist/src/runtime/graphEngineMemoryPaths.js +55 -0
  90. package/dist/src/runtime/graphResponseMapping.d.ts +23 -0
  91. package/dist/src/runtime/graphResponseMapping.js +156 -0
  92. package/dist/src/runtime/graphResponseMigration.d.ts +7 -0
  93. package/dist/src/runtime/graphResponseMigration.js +44 -0
  94. package/dist/src/runtime/graphRunExecutionSeed.d.ts +29 -0
  95. package/dist/src/runtime/graphRunExecutionSeed.js +61 -0
  96. package/dist/src/runtime/graphRunIdentity.d.ts +7 -0
  97. package/dist/src/runtime/graphRunIdentity.js +18 -0
  98. package/dist/src/runtime/localSkills/deterministicRule.d.ts +137 -0
  99. package/dist/src/runtime/localSkills/deterministicRule.js +196 -0
  100. package/dist/src/runtime/localSkills/index.d.ts +12 -0
  101. package/dist/src/runtime/localSkills/index.js +14 -0
  102. package/dist/src/runtime/localSkills/memorixItemToScopedOutput.d.ts +7 -0
  103. package/dist/src/runtime/localSkills/memorixItemToScopedOutput.js +104 -0
  104. package/dist/src/runtime/localSkills/memorixRuntime.d.ts +9 -0
  105. package/dist/src/runtime/localSkills/memorixRuntime.js +70 -0
  106. package/dist/src/runtime/localSkills/memorixScopedConfig.d.ts +16 -0
  107. package/dist/src/runtime/localSkills/memorixScopedConfig.js +18 -0
  108. package/dist/src/runtime/localSkills/scopedAnswerAssembler.d.ts +23 -0
  109. package/dist/src/runtime/localSkills/scopedAnswerAssembler.js +35 -0
  110. package/dist/src/runtime/localSkills/scopedAnswerFields.d.ts +12 -0
  111. package/dist/src/runtime/localSkills/scopedAnswerFields.js +66 -0
  112. package/dist/src/runtime/localSkills/scopedAnswerWriter.d.ts +32 -0
  113. package/dist/src/runtime/localSkills/scopedAnswerWriter.js +156 -0
  114. package/dist/src/runtime/localSkills/scopedDataReader.d.ts +47 -0
  115. package/dist/src/runtime/localSkills/scopedDataReader.js +89 -0
  116. package/dist/src/runtime/localSkills/utils.d.ts +12 -0
  117. package/dist/src/runtime/localSkills/utils.js +39 -0
  118. package/dist/src/runtime/materializeStructuredRunTaskInput.d.ts +9 -0
  119. package/dist/src/runtime/materializeStructuredRunTaskInput.js +34 -0
  120. package/dist/src/runtime/memory.d.ts +51 -0
  121. package/dist/src/runtime/memory.js +250 -0
  122. package/dist/src/runtime/mergeExellixGraphRuntimeInvocation.d.ts +18 -0
  123. package/dist/src/runtime/mergeExellixGraphRuntimeInvocation.js +32 -0
  124. package/dist/src/runtime/modelConfigSelection.d.ts +7 -0
  125. package/dist/src/runtime/modelConfigSelection.js +37 -0
  126. package/dist/src/runtime/narrixIngestEnv.d.ts +9 -0
  127. package/dist/src/runtime/narrixIngestEnv.js +18 -0
  128. package/dist/src/runtime/pathExpr.d.ts +36 -0
  129. package/dist/src/runtime/pathExpr.js +131 -0
  130. package/dist/src/runtime/predicates.d.ts +14 -0
  131. package/dist/src/runtime/predicates.js +86 -0
  132. package/dist/src/runtime/readTaskNodeInputsConfig.d.ts +23 -0
  133. package/dist/src/runtime/readTaskNodeInputsConfig.js +27 -0
  134. package/dist/src/runtime/resolveExecutionPipelineForTaskNode.d.ts +11 -0
  135. package/dist/src/runtime/resolveExecutionPipelineForTaskNode.js +93 -0
  136. package/dist/src/runtime/resolveGraphEngineMemoryPaths.d.ts +63 -0
  137. package/dist/src/runtime/resolveGraphEngineMemoryPaths.js +213 -0
  138. package/dist/src/runtime/resolveModelConfigForNode.d.ts +20 -0
  139. package/dist/src/runtime/resolveModelConfigForNode.js +69 -0
  140. package/dist/src/runtime/resolveNarrixForTaskNode.d.ts +14 -0
  141. package/dist/src/runtime/resolveNarrixForTaskNode.js +19 -0
  142. package/dist/src/runtime/resolveTaskKey.d.ts +11 -0
  143. package/dist/src/runtime/resolveTaskKey.js +28 -0
  144. package/dist/src/runtime/resolveTaskNodeInputs.d.ts +25 -0
  145. package/dist/src/runtime/resolveTaskNodeInputs.js +140 -0
  146. package/dist/src/runtime/runTaskAugments.d.ts +17 -0
  147. package/dist/src/runtime/runTaskAugments.js +37 -0
  148. package/dist/src/runtime/runTaskResponse.d.ts +4 -0
  149. package/dist/src/runtime/runTaskResponse.js +13 -0
  150. package/dist/src/runtime/runtimeObjects.d.ts +85 -0
  151. package/dist/src/runtime/runtimeObjects.js +50 -0
  152. package/dist/src/runtime/smartInputPaths.d.ts +13 -0
  153. package/dist/src/runtime/smartInputPaths.js +38 -0
  154. package/dist/src/runtime/stepRetry.d.ts +21 -0
  155. package/dist/src/runtime/stepRetry.js +238 -0
  156. package/dist/src/runtime/synthesizedContextPipeline.d.ts +12 -0
  157. package/dist/src/runtime/synthesizedContextPipeline.js +28 -0
  158. package/dist/src/runtime/taskNodeConditionsEvaluation.d.ts +27 -0
  159. package/dist/src/runtime/taskNodeConditionsEvaluation.js +140 -0
  160. package/dist/src/runtime/taskNodeMainReadiness.d.ts +45 -0
  161. package/dist/src/runtime/taskNodeMainReadiness.js +164 -0
  162. package/dist/src/runtime/taskNodeRunTaskPreflight.d.ts +89 -0
  163. package/dist/src/runtime/taskNodeRunTaskPreflight.js +204 -0
  164. package/dist/src/runtime/validateCanonicalGraphDocument.d.ts +25 -0
  165. package/dist/src/runtime/validateCanonicalGraphDocument.js +567 -0
  166. package/dist/src/runtime/variables.d.ts +2 -0
  167. package/dist/src/runtime/variables.js +1 -0
  168. package/dist/src/runtime/withTimeout.d.ts +5 -0
  169. package/dist/src/runtime/withTimeout.js +20 -0
  170. package/dist/src/types/aiTaskProfile.d.ts +41 -0
  171. package/dist/src/types/aiTaskProfile.js +6 -0
  172. package/dist/src/types/aiTasksDerivedTypes.d.ts +5 -0
  173. package/dist/src/types/aiTasksDerivedTypes.js +1 -0
  174. package/dist/src/types/events.d.ts +23 -0
  175. package/dist/src/types/events.js +1 -0
  176. package/dist/src/types/job.d.ts +9 -0
  177. package/dist/src/types/job.js +1 -0
  178. package/dist/src/types/narrix.d.ts +60 -0
  179. package/dist/src/types/narrix.js +1 -0
  180. package/dist/src/types/options.d.ts +122 -0
  181. package/dist/src/types/options.js +1 -0
  182. package/dist/src/types/refs.d.ts +747 -0
  183. package/dist/src/types/refs.js +12 -0
  184. package/dist/src/types/results.d.ts +103 -0
  185. package/dist/src/types/results.js +1 -0
  186. package/dist/src/types/runLog.d.ts +72 -0
  187. package/dist/src/types/runLog.js +18 -0
  188. package/dist/src/types/taskNodeConfiguration.d.ts +95 -0
  189. package/dist/src/types/taskNodeConfiguration.js +3 -0
  190. package/dist/src/util/packageVersion.d.ts +2 -0
  191. package/dist/src/util/packageVersion.js +12 -0
  192. package/dist/testkit/RealTasksClient.d.ts +16 -0
  193. package/dist/testkit/RealTasksClient.js +143 -0
  194. package/dist/testkit/depGraphEngineFactory.d.ts +6 -0
  195. package/dist/testkit/depGraphEngineFactory.js +54 -0
  196. package/dist/testkit/exellixRuntimeObjects.d.ts +7 -0
  197. package/dist/testkit/exellixRuntimeObjects.js +25 -0
  198. package/dist/testkit/inMemoryGraphLoader.d.ts +6 -0
  199. package/dist/testkit/inMemoryGraphLoader.js +12 -0
  200. package/dist/testkit/index.d.ts +4 -0
  201. package/dist/testkit/index.js +4 -0
  202. package/package.json +70 -0
@@ -0,0 +1,169 @@
1
+ import { EXELLIX_STRUCTURED_DATA_FILTERS_V1, } from '../types/refs.js';
2
+ function getByDotPath(root, path) {
3
+ if (!path)
4
+ return undefined;
5
+ const parts = path.split('.').filter(Boolean);
6
+ let cur = root;
7
+ for (const p of parts) {
8
+ if (cur == null || typeof cur !== 'object' || Array.isArray(cur))
9
+ return undefined;
10
+ cur = cur[p];
11
+ }
12
+ return cur;
13
+ }
14
+ function collectLeafPaths(predicate) {
15
+ if (predicate == null)
16
+ return [];
17
+ if (typeof predicate !== 'object')
18
+ return [];
19
+ if ('path' in predicate && typeof predicate.path === 'string') {
20
+ return [predicate.path];
21
+ }
22
+ if ('all' in predicate) {
23
+ const items = predicate.all;
24
+ if (!Array.isArray(items))
25
+ return [];
26
+ return items.flatMap((p) => collectLeafPaths(p));
27
+ }
28
+ if ('any' in predicate) {
29
+ const items = predicate.any;
30
+ if (!Array.isArray(items))
31
+ return [];
32
+ return items.flatMap((p) => collectLeafPaths(p));
33
+ }
34
+ if ('not' in predicate) {
35
+ return collectLeafPaths(predicate.not);
36
+ }
37
+ return [];
38
+ }
39
+ /**
40
+ * Returns paths that are not valid roots for structured data-filter predicates
41
+ * (`data` or `data.*`). Empty when every leaf path is valid.
42
+ */
43
+ export function getStructuredDataFilterPathViolations(predicate) {
44
+ const paths = collectLeafPaths(predicate);
45
+ const bad = [];
46
+ for (const p of paths) {
47
+ if (p === 'data' || p.startsWith('data.'))
48
+ continue;
49
+ bad.push(p);
50
+ }
51
+ return bad;
52
+ }
53
+ function resolveDataPath(record, fullPath) {
54
+ if (!fullPath)
55
+ return undefined;
56
+ const [rootKey, ...rest] = fullPath.split('.');
57
+ const tail = rest.join('.');
58
+ if (rootKey !== 'data')
59
+ return undefined;
60
+ return tail ? getByDotPath(record, tail) : record;
61
+ }
62
+ /**
63
+ * Evaluate a {@link GraphPredicate} tree where every leaf `path` is rooted at `data` or `data.*`,
64
+ * resolving values from `record` (the object that backs those paths).
65
+ *
66
+ * Semantics match {@link evaluateGraphPredicate} leaf operators (`exists`, `eq`) and boolean
67
+ * combinators (`all`, `any`, `not`), but paths are restricted to the `data` root only.
68
+ */
69
+ export function evaluateDataFilterPredicate(predicate, record) {
70
+ if (predicate == null)
71
+ return true;
72
+ if (typeof predicate !== 'object')
73
+ return false;
74
+ if ('all' in predicate) {
75
+ const items = predicate.all;
76
+ if (!Array.isArray(items))
77
+ return false;
78
+ return items.every((p) => evaluateDataFilterPredicate(p, record));
79
+ }
80
+ if ('any' in predicate) {
81
+ const items = predicate.any;
82
+ if (!Array.isArray(items))
83
+ return false;
84
+ return items.some((p) => evaluateDataFilterPredicate(p, record));
85
+ }
86
+ if ('not' in predicate) {
87
+ return !evaluateDataFilterPredicate(predicate.not, record);
88
+ }
89
+ if ('path' in predicate && typeof predicate.path === 'string') {
90
+ const path = predicate.path;
91
+ const v = resolveDataPath(record, path);
92
+ if (predicate.exists !== undefined) {
93
+ if (typeof predicate.exists !== 'boolean')
94
+ return false;
95
+ const exists = v !== undefined && v !== null;
96
+ return predicate.exists ? exists : !exists;
97
+ }
98
+ if (predicate.eq !== undefined) {
99
+ return v === predicate.eq;
100
+ }
101
+ return false;
102
+ }
103
+ return false;
104
+ }
105
+ export function isStructuredDataFiltersV1(value) {
106
+ return (value != null &&
107
+ typeof value === 'object' &&
108
+ !Array.isArray(value) &&
109
+ value.version === EXELLIX_STRUCTURED_DATA_FILTERS_V1 &&
110
+ typeof value.when === 'object' &&
111
+ value.when != null &&
112
+ !Array.isArray(value.when));
113
+ }
114
+ /**
115
+ * Public entry: interpret `conditions.dataFilters` (or the same field on `metadata.graphEntry`)
116
+ * against a plain JSON-serializable **record** object.
117
+ *
118
+ * - **Structured v1** (`{ version: "exellix.dataFilters.v1", when }`): evaluated here; leaf paths
119
+ * must be `data` or `data.*` and read from `record`.
120
+ * - **Legacy `string[]`**: not evaluated; returned as {@link EvaluateStructuredDataFiltersResult} with
121
+ * `status: "legacy_reference_ids"` so callers can apply catalog logic themselves.
122
+ * - **`undefined`**: `status: "no_gate"`, `ok: true`.
123
+ *
124
+ * This function performs **no I/O**. It does **not** evaluate `conditions.narratives` or
125
+ * `conditions.aiFilter` — those remain host / tooling concerns unless documented otherwise.
126
+ */
127
+ export function evaluateStructuredDataFilters(dataFilters, record, options) {
128
+ const strictPaths = options?.strictPaths !== false;
129
+ if (dataFilters === undefined) {
130
+ return {
131
+ status: 'no_gate',
132
+ ok: true,
133
+ message: 'conditions.dataFilters was undefined or omitted',
134
+ };
135
+ }
136
+ if (Array.isArray(dataFilters)) {
137
+ return {
138
+ status: 'legacy_reference_ids',
139
+ ok: true,
140
+ ids: dataFilters,
141
+ message: 'conditions.dataFilters is a string[] of reference ids; graph-engine does not resolve ids. Evaluate in your host or pass a structured `{ version, when }` gate.',
142
+ };
143
+ }
144
+ if (!isStructuredDataFiltersV1(dataFilters)) {
145
+ return {
146
+ status: 'unsupported_shape',
147
+ ok: false,
148
+ message: 'conditions.dataFilters must be string[] (legacy ids), undefined, or { version: "exellix.dataFilters.v1", when: GraphPredicate }.',
149
+ };
150
+ }
151
+ const invalidPaths = getStructuredDataFilterPathViolations(dataFilters.when);
152
+ if (invalidPaths.length > 0 && strictPaths) {
153
+ return {
154
+ status: 'evaluated',
155
+ ok: false,
156
+ version: EXELLIX_STRUCTURED_DATA_FILTERS_V1,
157
+ invalidPaths,
158
+ predicateRejected: false,
159
+ };
160
+ }
161
+ const pass = evaluateDataFilterPredicate(dataFilters.when, record);
162
+ return {
163
+ status: 'evaluated',
164
+ ok: pass,
165
+ version: EXELLIX_STRUCTURED_DATA_FILTERS_V1,
166
+ ...(invalidPaths.length ? { invalidPaths } : {}),
167
+ predicateRejected: !pass && invalidPaths.length === 0,
168
+ };
169
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Deep-merge plain objects for graph-run memory (xynthesized patches).
3
+ * Arrays and non-plain objects are replaced by the patch value.
4
+ */
5
+ export declare function deepMerge<T extends Record<string, unknown>>(target: T, patch: Record<string, unknown>): T;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Deep-merge plain objects for graph-run memory (xynthesized patches).
3
+ * Arrays and non-plain objects are replaced by the patch value.
4
+ */
5
+ export function deepMerge(target, patch) {
6
+ const out = { ...target };
7
+ for (const [k, pv] of Object.entries(patch)) {
8
+ if (pv === undefined)
9
+ continue;
10
+ const tv = out[k];
11
+ if (isPlainObject(tv) && isPlainObject(pv)) {
12
+ out[k] = deepMerge(tv, pv);
13
+ }
14
+ else {
15
+ out[k] = pv;
16
+ }
17
+ }
18
+ return out;
19
+ }
20
+ function isPlainObject(v) {
21
+ return v != null && typeof v === 'object' && !Array.isArray(v);
22
+ }
@@ -0,0 +1,92 @@
1
+ import { GraphExecutionEvent, NodeExecutionEvent } from '../types/events.js';
2
+ import { GraphNode } from '../types/refs.js';
3
+ /**
4
+ * Event emitter interface for graph execution
5
+ */
6
+ export interface EventEmitter {
7
+ emit(event: GraphExecutionEvent | NodeExecutionEvent): void;
8
+ on?(eventType: string, handler: (event: GraphExecutionEvent | NodeExecutionEvent) => void): void;
9
+ }
10
+ /**
11
+ * Forward each emitted event to every emitter in order. Undefined entries are skipped.
12
+ */
13
+ export declare function composeEventEmitters(...emitters: Array<EventEmitter | undefined>): EventEmitter | undefined;
14
+ /**
15
+ * Creates a graph start event
16
+ */
17
+ export declare function createGraphStartEvent(jobId: string, graphId: string, taskId: string, data?: {
18
+ agentId?: string;
19
+ graphDefinition?: any;
20
+ input?: {
21
+ variables?: Record<string, any>;
22
+ jobMemory?: any;
23
+ taskMemory?: any;
24
+ [key: string]: any;
25
+ };
26
+ [key: string]: any;
27
+ }): GraphExecutionEvent;
28
+ /**
29
+ * Creates a graph complete event
30
+ */
31
+ export declare function createGraphCompleteEvent(jobId: string, graphId: string, taskId: string, data?: {
32
+ output?: any;
33
+ nodesExecuted?: number;
34
+ finalMemory?: {
35
+ jobMemory?: any;
36
+ taskMemory?: any;
37
+ [key: string]: any;
38
+ };
39
+ nodeResults?: any[];
40
+ [key: string]: any;
41
+ }): GraphExecutionEvent;
42
+ /**
43
+ * Creates a graph fail event
44
+ */
45
+ export declare function createGraphFailEvent(jobId: string, graphId: string, taskId: string, error: any, data?: {
46
+ finalMemory?: {
47
+ jobMemory?: any;
48
+ taskMemory?: any;
49
+ [key: string]: any;
50
+ };
51
+ [key: string]: any;
52
+ }): GraphExecutionEvent;
53
+ /**
54
+ * Creates a node start event
55
+ */
56
+ export declare function createNodeStartEvent(jobId: string, graphId: string, taskId: string, node: GraphNode, skillKey: string, input?: {
57
+ variables?: Record<string, any>;
58
+ jobMemory?: any;
59
+ taskMemory?: any;
60
+ [key: string]: any;
61
+ }, correlation?: {
62
+ jobType?: string;
63
+ }): NodeExecutionEvent;
64
+ /**
65
+ * Creates a node complete event
66
+ */
67
+ export declare function createNodeCompleteEvent(jobId: string, graphId: string, taskId: string, node: GraphNode, skillKey: string, result: {
68
+ output?: any;
69
+ memoryAfter?: {
70
+ jobMemory?: any;
71
+ taskMemory?: any;
72
+ [key: string]: any;
73
+ };
74
+ [key: string]: any;
75
+ }, correlation?: {
76
+ jobType?: string;
77
+ }): NodeExecutionEvent;
78
+ /**
79
+ * Creates a node fail event
80
+ */
81
+ export declare function createNodeFailEvent(jobId: string, graphId: string, taskId: string, node: GraphNode, skillKey: string, data: {
82
+ error: any;
83
+ memoryAfter?: {
84
+ jobMemory?: any;
85
+ taskMemory?: any;
86
+ execution?: any;
87
+ [key: string]: any;
88
+ };
89
+ response?: any;
90
+ }, correlation?: {
91
+ jobType?: string;
92
+ }): NodeExecutionEvent;
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Forward each emitted event to every emitter in order. Undefined entries are skipped.
3
+ */
4
+ export function composeEventEmitters(...emitters) {
5
+ const valid = emitters.filter((e) => e != null);
6
+ if (valid.length === 0)
7
+ return undefined;
8
+ if (valid.length === 1)
9
+ return valid[0];
10
+ return {
11
+ emit(event) {
12
+ for (const em of valid) {
13
+ em.emit(event);
14
+ }
15
+ },
16
+ };
17
+ }
18
+ /**
19
+ * Creates a graph start event
20
+ */
21
+ export function createGraphStartEvent(jobId, graphId, taskId, data) {
22
+ return {
23
+ type: 'graph:start',
24
+ timestamp: Date.now(),
25
+ jobId,
26
+ taskId,
27
+ graphId,
28
+ data,
29
+ };
30
+ }
31
+ /**
32
+ * Creates a graph complete event
33
+ */
34
+ export function createGraphCompleteEvent(jobId, graphId, taskId, data) {
35
+ return {
36
+ type: 'graph:complete',
37
+ timestamp: Date.now(),
38
+ jobId,
39
+ taskId,
40
+ graphId,
41
+ data,
42
+ };
43
+ }
44
+ /**
45
+ * Creates a graph fail event
46
+ */
47
+ export function createGraphFailEvent(jobId, graphId, taskId, error, data) {
48
+ return {
49
+ type: 'graph:fail',
50
+ timestamp: Date.now(),
51
+ jobId,
52
+ taskId,
53
+ graphId,
54
+ data: {
55
+ error,
56
+ ...data,
57
+ },
58
+ };
59
+ }
60
+ /**
61
+ * Creates a node start event
62
+ */
63
+ export function createNodeStartEvent(jobId, graphId, taskId, node, skillKey, input, correlation) {
64
+ return {
65
+ type: 'node:start',
66
+ timestamp: Date.now(),
67
+ jobId,
68
+ taskId,
69
+ graphId,
70
+ nodeId: node.id,
71
+ node,
72
+ skillKey,
73
+ data: {
74
+ input,
75
+ nodeDefinition: node,
76
+ ...(correlation?.jobType != null ? { jobType: correlation.jobType } : {}),
77
+ },
78
+ };
79
+ }
80
+ /**
81
+ * Creates a node complete event
82
+ */
83
+ export function createNodeCompleteEvent(jobId, graphId, taskId, node, skillKey, result, correlation) {
84
+ return {
85
+ type: 'node:complete',
86
+ timestamp: Date.now(),
87
+ jobId,
88
+ taskId,
89
+ graphId,
90
+ nodeId: node.id,
91
+ node,
92
+ skillKey,
93
+ result: result.output,
94
+ data: {
95
+ output: result.output,
96
+ memoryAfter: result.memoryAfter,
97
+ ...(correlation?.jobType != null ? { jobType: correlation.jobType } : {}),
98
+ },
99
+ };
100
+ }
101
+ /**
102
+ * Creates a node fail event
103
+ */
104
+ export function createNodeFailEvent(jobId, graphId, taskId, node, skillKey, data, correlation) {
105
+ return {
106
+ type: 'node:fail',
107
+ timestamp: Date.now(),
108
+ jobId,
109
+ taskId,
110
+ graphId,
111
+ nodeId: node.id,
112
+ node,
113
+ skillKey,
114
+ error: data.error,
115
+ data: {
116
+ error: data.error,
117
+ memoryAfter: data.memoryAfter,
118
+ ...(data.response !== undefined ? { response: data.response } : {}),
119
+ ...(correlation?.jobType != null ? { jobType: correlation.jobType } : {}),
120
+ },
121
+ };
122
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Host helpers for execution-matrix style orchestrators (e.g. `@exellix/exellix-runtime`).
3
+ *
4
+ * Graph-engine does not call matrix claim APIs; the host injects `executeGraph` and supplies
5
+ * a `{ model, runtime }` request with per-graph `GraphEntryContract` + seeded
6
+ * `runtime.executionMemory` objects built here.
7
+ */
8
+ import type { Graph, GraphEntryContract, GraphEntryExecutionInputSpec, Job } from '../types/refs.js';
9
+ import type { ExellixGraphRuntimeOptions, ExecuteGraphInput, ExecuteGraphResult, GraphRuntimeObject } from './ExellixGraphRuntime.js';
10
+ import type { GraphLoader } from './ExellixGraphRuntime.js';
11
+ /**
12
+ * Reads Layer 01 contract from the canonical graph document (`metadata.graphEntry`).
13
+ * Does not fetch Catalox or bundle stores — those are host concerns before load.
14
+ */
15
+ export declare function resolveGraphEntryFromGraph(graph: Graph): GraphEntryContract | undefined;
16
+ /**
17
+ * Returns an async resolver suitable for `graphId -> GraphEntryContract` when graphs
18
+ * are loaded through the same `GraphLoader` used for execution.
19
+ */
20
+ export declare function createResolveGraphEntryFromLoader(loader: GraphLoader): (graphId: string) => Promise<GraphEntryContract | undefined>;
21
+ export type BuildExecutionSeedSources = {
22
+ /**
23
+ * Highest precedence: explicit dot-path → value (paths match `GraphEntryValueInputSpec.path`).
24
+ */
25
+ valuesByPath?: Record<string, unknown>;
26
+ /**
27
+ * Lower precedence: plain objects (matrix defaults, row payload, per-graph map).
28
+ * For each spec path, `selectByPath(layer, path)` is evaluated; later layers override earlier ones.
29
+ */
30
+ layers?: unknown[];
31
+ };
32
+ export type BuildExecutionSeedResult = {
33
+ /** Shallow clone base + writes; safe to pass as `GraphRuntimeObject.executionMemory`. */
34
+ executionMemory: Record<string, unknown>;
35
+ /** Backwards-readable alias for callers still naming the seed object `execution`. */
36
+ execution: Record<string, unknown>;
37
+ /** Paths written for value-kind specs. */
38
+ appliedPaths: string[];
39
+ /** `kind: "execution"` specs are never auto-filled — host must materialize prior runs. */
40
+ skippedExecutionSpecs: GraphEntryExecutionInputSpec[];
41
+ };
42
+ /**
43
+ * Builds an initial `execution` object from `metadata.graphEntry.inputs` for **value** kinds only.
44
+ * `kind: "execution"` entries are skipped (see return value); the host must merge source executions
45
+ * using `graphId` / `metadataFilter` before calling `executeGraph`.
46
+ */
47
+ export declare function buildExecutionSeedFromGraphEntry(graphEntry: GraphEntryContract | undefined, sources?: BuildExecutionSeedSources): BuildExecutionSeedResult;
48
+ /** Builds the canonical graph-engine execution request for matrix-style hosts. */
49
+ export declare function buildGraphExecutionRequest(input: {
50
+ model: Graph;
51
+ runtime: GraphRuntimeObject;
52
+ }): ExecuteGraphInput;
53
+ /**
54
+ * Validates that dot-paths declared in `requiredExecutionPaths` are present on `execution`
55
+ * (after seeding). Graph-engine does not enforce `graphEntry` at runtime; hosts may call this before execute.
56
+ */
57
+ export declare function validateExecutionSeedPaths(execution: Record<string, unknown>, graphEntry: GraphEntryContract | undefined): {
58
+ ok: boolean;
59
+ missingPaths: string[];
60
+ };
61
+ /**
62
+ * Deterministic job id for matrix rows so retries can reuse the same id for idempotent downstream dedupe.
63
+ * Use the same `attempt` for automatic retries of the same logical run; bump `attempt` only when
64
+ * intentionally starting a new run (new side effects).
65
+ */
66
+ export declare function buildStableMatrixJobId(input: {
67
+ matrixId: string;
68
+ rowId: string;
69
+ graphId: string;
70
+ /** Default 0 — keep constant for same-run retries. */
71
+ attempt?: number;
72
+ }): string;
73
+ /**
74
+ * Builds a `Job` compatible with both classic `executeGraph` (`job.id`) and
75
+ * `createExellixGraphRuntime().executeGraph` (`job.jobId` is also set).
76
+ */
77
+ export declare function buildMatrixJobForGraphRun(input: {
78
+ matrixId: string;
79
+ rowId: string;
80
+ graphId: string;
81
+ attempt?: number;
82
+ agentId?: string;
83
+ jobType?: string;
84
+ jobVariables?: Record<string, unknown>;
85
+ /** Forwarded as `job.input` for runTask `jobInput` merge in injected runtime. */
86
+ jobInput?: unknown;
87
+ }): Job & {
88
+ jobId: string;
89
+ };
90
+ /** True when injected-runtime result is terminal failure (host decides retry / reset). */
91
+ export declare function isExecuteGraphResultFailed(result: ExecuteGraphResult): boolean;
92
+ /**
93
+ * Creates a long-lived graph runtime and exposes `executeGraph` for injection into matrix claim
94
+ * processors (`ProcessMatrixClaimDeps.executeGraph` in `@exellix/exellix-runtime`, etc.).
95
+ */
96
+ export declare function createMatrixHostGraphExecutor(options: ExellixGraphRuntimeOptions): {
97
+ executeGraph: (input: ExecuteGraphInput) => Promise<ExecuteGraphResult>;
98
+ };
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Host helpers for execution-matrix style orchestrators (e.g. `@exellix/exellix-runtime`).
3
+ *
4
+ * Graph-engine does not call matrix claim APIs; the host injects `executeGraph` and supplies
5
+ * a `{ model, runtime }` request with per-graph `GraphEntryContract` + seeded
6
+ * `runtime.executionMemory` objects built here.
7
+ */
8
+ import { mergeGraphDocumentModel } from '../types/refs.js';
9
+ import { createExellixGraphRuntime } from './ExellixGraphRuntime.js';
10
+ import { selectByPath, writeByPath } from './pathExpr.js';
11
+ function isExecutionInputSpec(spec) {
12
+ return spec.kind === 'execution';
13
+ }
14
+ function isValueInputSpec(spec) {
15
+ return spec.kind !== 'execution' && typeof spec.path === 'string';
16
+ }
17
+ /**
18
+ * Reads Layer 01 contract from the canonical graph document (`metadata.graphEntry`).
19
+ * Does not fetch Catalox or bundle stores — those are host concerns before load.
20
+ */
21
+ export function resolveGraphEntryFromGraph(graph) {
22
+ const meta = mergeGraphDocumentModel(graph);
23
+ return meta.graphEntry;
24
+ }
25
+ /**
26
+ * Returns an async resolver suitable for `graphId -> GraphEntryContract` when graphs
27
+ * are loaded through the same `GraphLoader` used for execution.
28
+ */
29
+ export function createResolveGraphEntryFromLoader(loader) {
30
+ return async function resolveGraphEntry(graphId) {
31
+ const graph = await loader.loadGraph(graphId);
32
+ return resolveGraphEntryFromGraph(graph);
33
+ };
34
+ }
35
+ /**
36
+ * Builds an initial `execution` object from `metadata.graphEntry.inputs` for **value** kinds only.
37
+ * `kind: "execution"` entries are skipped (see return value); the host must merge source executions
38
+ * using `graphId` / `metadataFilter` before calling `executeGraph`.
39
+ */
40
+ export function buildExecutionSeedFromGraphEntry(graphEntry, sources = {}) {
41
+ const execution = {};
42
+ const appliedPaths = [];
43
+ const skippedExecutionSpecs = [];
44
+ const valuesByPath = sources.valuesByPath ?? {};
45
+ const layers = sources.layers ?? [];
46
+ for (const spec of graphEntry?.inputs ?? []) {
47
+ if (isExecutionInputSpec(spec)) {
48
+ skippedExecutionSpecs.push(spec);
49
+ continue;
50
+ }
51
+ if (!isValueInputSpec(spec))
52
+ continue;
53
+ const path = spec.path.trim();
54
+ if (!path)
55
+ continue;
56
+ let value = undefined;
57
+ if (Object.prototype.hasOwnProperty.call(valuesByPath, path)) {
58
+ value = valuesByPath[path];
59
+ }
60
+ else {
61
+ for (const layer of layers) {
62
+ if (layer == null || typeof layer !== 'object' || Array.isArray(layer))
63
+ continue;
64
+ const picked = selectByPath(layer, path);
65
+ if (picked !== undefined)
66
+ value = picked;
67
+ }
68
+ }
69
+ if (value !== undefined) {
70
+ writeByPath(execution, path, value, 'replace');
71
+ appliedPaths.push(path);
72
+ }
73
+ }
74
+ return { executionMemory: execution, execution, appliedPaths, skippedExecutionSpecs };
75
+ }
76
+ /** Builds the canonical graph-engine execution request for matrix-style hosts. */
77
+ export function buildGraphExecutionRequest(input) {
78
+ return {
79
+ model: input.model,
80
+ runtime: input.runtime,
81
+ };
82
+ }
83
+ /**
84
+ * Validates that dot-paths declared in `requiredExecutionPaths` are present on `execution`
85
+ * (after seeding). Graph-engine does not enforce `graphEntry` at runtime; hosts may call this before execute.
86
+ */
87
+ export function validateExecutionSeedPaths(execution, graphEntry) {
88
+ const missingPaths = [];
89
+ for (const p of graphEntry?.requiredExecutionPaths ?? []) {
90
+ if (typeof p !== 'string' || !p.trim())
91
+ continue;
92
+ const v = selectByPath(execution, p.trim());
93
+ if (v === undefined)
94
+ missingPaths.push(p.trim());
95
+ }
96
+ return { ok: missingPaths.length === 0, missingPaths };
97
+ }
98
+ /**
99
+ * Deterministic job id for matrix rows so retries can reuse the same id for idempotent downstream dedupe.
100
+ * Use the same `attempt` for automatic retries of the same logical run; bump `attempt` only when
101
+ * intentionally starting a new run (new side effects).
102
+ */
103
+ export function buildStableMatrixJobId(input) {
104
+ const attempt = input.attempt ?? 0;
105
+ return `matrix:${input.matrixId}:row:${input.rowId}:graph:${input.graphId}:attempt:${attempt}`;
106
+ }
107
+ /**
108
+ * Builds a `Job` compatible with both classic `executeGraph` (`job.id`) and
109
+ * `createExellixGraphRuntime().executeGraph` (`job.jobId` is also set).
110
+ */
111
+ export function buildMatrixJobForGraphRun(input) {
112
+ const jobId = buildStableMatrixJobId(input);
113
+ const job = {
114
+ id: jobId,
115
+ jobId,
116
+ ...(input.agentId != null ? { agentId: input.agentId } : {}),
117
+ ...(input.jobType != null ? { jobType: input.jobType } : {}),
118
+ ...(input.jobVariables != null ? { jobVariables: input.jobVariables } : {}),
119
+ ...(input.jobInput !== undefined ? { input: input.jobInput } : {}),
120
+ };
121
+ return job;
122
+ }
123
+ /** True when injected-runtime result is terminal failure (host decides retry / reset). */
124
+ export function isExecuteGraphResultFailed(result) {
125
+ return result.status === 'failed';
126
+ }
127
+ /**
128
+ * Creates a long-lived graph runtime and exposes `executeGraph` for injection into matrix claim
129
+ * processors (`ProcessMatrixClaimDeps.executeGraph` in `@exellix/exellix-runtime`, etc.).
130
+ */
131
+ export function createMatrixHostGraphExecutor(options) {
132
+ const { executeGraph } = createExellixGraphRuntime(options);
133
+ return { executeGraph };
134
+ }