@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,234 @@
1
+ import { AI_TASKS_LOGXER_RUN_ID_METADATA_KEY, AI_TASKS_RUN_LOG_METADATA_KEY, DEFAULT_MAX_RUN_LOG_DATA_JSON_CHARS, DEFAULT_MAX_RUN_LOG_ENTRIES, } from '../types/runLog.js';
2
+ function safeJsonLen(value) {
3
+ try {
4
+ return JSON.stringify(value).length;
5
+ }
6
+ catch {
7
+ return String(value).length;
8
+ }
9
+ }
10
+ /** Truncate `data` for HTTP/console payloads; returns replacement suitable for `RunLogEntry.data`. */
11
+ export function truncateRunLogData(data, maxJsonChars) {
12
+ if (data === undefined)
13
+ return undefined;
14
+ const len = safeJsonLen(data);
15
+ if (len <= maxJsonChars)
16
+ return data;
17
+ let preview;
18
+ try {
19
+ preview = JSON.stringify(data);
20
+ }
21
+ catch {
22
+ preview = String(data);
23
+ }
24
+ if (preview.length > maxJsonChars) {
25
+ preview = preview.slice(0, maxJsonChars);
26
+ }
27
+ return { _truncated: true, preview };
28
+ }
29
+ function isRunLogLevel(x) {
30
+ return x === 'debug' || x === 'info' || x === 'warn' || x === 'error';
31
+ }
32
+ function isRunLogScope(x) {
33
+ return (x === 'graph' ||
34
+ x === 'node' ||
35
+ x === 'task' ||
36
+ x === 'narrix' ||
37
+ x === 'logxer' ||
38
+ x === 'pipeline');
39
+ }
40
+ /** Normalize @exellix/ai-tasks epoch-ms or ISO `ts` to epoch ms for exellix-graph `RunLogEntry`. */
41
+ export function parseRunLogEntryTs(v) {
42
+ if (typeof v === 'number' && Number.isFinite(v))
43
+ return v;
44
+ if (typeof v === 'string' && v.length > 0) {
45
+ const ms = Date.parse(v);
46
+ if (!Number.isNaN(ms))
47
+ return ms;
48
+ }
49
+ return Date.now();
50
+ }
51
+ /** Normalize entries from ai-tasks metadata (best-effort). */
52
+ export function normalizeExternalRunLogEntries(raw) {
53
+ if (!Array.isArray(raw))
54
+ return [];
55
+ const out = [];
56
+ for (const row of raw) {
57
+ if (row == null || typeof row !== 'object')
58
+ continue;
59
+ const r = row;
60
+ const ts = parseRunLogEntryTs(r.ts);
61
+ const level = isRunLogLevel(r.level) ? r.level : 'info';
62
+ const scope = isRunLogScope(r.scope) ? r.scope : 'task';
63
+ const message = typeof r.message === 'string' ? r.message : String(r.message ?? '');
64
+ const nodeId = r.nodeId != null ? String(r.nodeId) : undefined;
65
+ const skillKey = typeof r.skillKey === 'string' && r.skillKey.length > 0 ? r.skillKey : undefined;
66
+ const taskId = typeof r.taskId === 'string' && r.taskId.length > 0 ? r.taskId : undefined;
67
+ const correlationIds = r.correlationIds != null && typeof r.correlationIds === 'object' && !Array.isArray(r.correlationIds)
68
+ ? r.correlationIds
69
+ : undefined;
70
+ const data = 'data' in r ? r.data : undefined;
71
+ out.push({
72
+ ts,
73
+ level,
74
+ scope,
75
+ ...(nodeId ? { nodeId } : {}),
76
+ ...(skillKey ? { skillKey } : {}),
77
+ ...(taskId ? { taskId } : {}),
78
+ ...(correlationIds ? { correlationIds } : {}),
79
+ message,
80
+ ...(data !== undefined ? { data } : {}),
81
+ });
82
+ }
83
+ return out;
84
+ }
85
+ export function extractTaskRunLogFromMetadata(metadata) {
86
+ if (metadata == null || typeof metadata !== 'object' || Array.isArray(metadata))
87
+ return [];
88
+ const m = metadata;
89
+ return normalizeExternalRunLogEntries(m[AI_TASKS_RUN_LOG_METADATA_KEY]);
90
+ }
91
+ export function extractLogxerCorrelationFromMetadata(metadata) {
92
+ if (metadata == null || typeof metadata !== 'object' || Array.isArray(metadata))
93
+ return undefined;
94
+ const m = metadata;
95
+ const runId = m[AI_TASKS_LOGXER_RUN_ID_METADATA_KEY];
96
+ if (typeof runId === 'string' && runId.length > 0)
97
+ return runId;
98
+ return undefined;
99
+ }
100
+ function traceNodeData(entry, summary) {
101
+ if (summary) {
102
+ const d = {
103
+ skillKey: entry.skillKey,
104
+ durationMs: entry.durationMs,
105
+ ok: entry.ok,
106
+ };
107
+ if (entry.activityId)
108
+ d.activityId = entry.activityId;
109
+ if (entry.error) {
110
+ d.error = {
111
+ message: entry.error.message,
112
+ ...(entry.error.code ? { code: entry.error.code } : {}),
113
+ };
114
+ }
115
+ return d;
116
+ }
117
+ const d = {
118
+ startedAt: entry.startedAt,
119
+ endedAt: entry.endedAt,
120
+ skillKey: entry.skillKey,
121
+ ok: entry.ok,
122
+ durationMs: entry.durationMs,
123
+ };
124
+ if (entry.activityId)
125
+ d.activityId = entry.activityId;
126
+ if (entry.summary)
127
+ d.summary = entry.summary;
128
+ if (entry.error)
129
+ d.error = entry.error;
130
+ return d;
131
+ }
132
+ /**
133
+ * Build merged `runLog` for a completed graph run from execution trace + optional per-task lines.
134
+ */
135
+ export function buildRunLog(opts) {
136
+ const { mode, maxEntries, maxDataJsonChars, jobId, taskId, graphId, graphStatus, graphRunStartedAt, execution, taskAppendedEntries = [], logxerCorrelationId: inputCorrelation, } = opts;
137
+ if (mode === 'off') {
138
+ return {
139
+ ...(inputCorrelation ? { logxerCorrelationId: inputCorrelation } : {}),
140
+ };
141
+ }
142
+ const summary = mode === 'summary';
143
+ const graphEndedAt = Date.now();
144
+ const traceRoot = execution._trace;
145
+ const nodesRaw = traceRoot != null &&
146
+ typeof traceRoot === 'object' &&
147
+ !Array.isArray(traceRoot) &&
148
+ traceRoot.nodes != null &&
149
+ typeof traceRoot.nodes === 'object'
150
+ ? traceRoot.nodes
151
+ : {};
152
+ const startedTimes = [];
153
+ for (const e of Object.values(nodesRaw)) {
154
+ if (e == null || typeof e !== 'object')
155
+ continue;
156
+ const s = e.startedAt;
157
+ if (typeof s === 'number' && Number.isFinite(s))
158
+ startedTimes.push(s);
159
+ }
160
+ const inferredStart = startedTimes.length > 0 ? Math.min(...startedTimes) : graphEndedAt;
161
+ const graphStartedAt = typeof graphRunStartedAt === 'number' && Number.isFinite(graphRunStartedAt)
162
+ ? graphRunStartedAt
163
+ : inferredStart;
164
+ const built = [];
165
+ built.push({
166
+ ts: graphStartedAt,
167
+ level: 'info',
168
+ scope: 'graph',
169
+ message: `Graph run started (${graphId})`,
170
+ data: truncateRunLogData({ jobId, taskId, graphId }, maxDataJsonChars),
171
+ });
172
+ const nodeIds = Object.keys(nodesRaw).sort((a, b) => {
173
+ const ea = nodesRaw[a];
174
+ const eb = nodesRaw[b];
175
+ const sa = ea && typeof ea.startedAt === 'number' ? ea.startedAt : 0;
176
+ const sb = eb && typeof eb.startedAt === 'number' ? eb.startedAt : 0;
177
+ return sa - sb || a.localeCompare(b);
178
+ });
179
+ for (const nodeId of nodeIds) {
180
+ const entry = nodesRaw[nodeId];
181
+ if (!entry || typeof entry !== 'object')
182
+ continue;
183
+ const level = entry.ok ? 'info' : 'error';
184
+ const msg = entry.ok
185
+ ? `Node ${nodeId} completed (${entry.skillKey}, ${entry.durationMs}ms)`
186
+ : `Node ${nodeId} failed (${entry.skillKey})`;
187
+ built.push({
188
+ ts: typeof entry.endedAt === 'number' ? entry.endedAt : graphEndedAt,
189
+ level,
190
+ scope: 'node',
191
+ nodeId,
192
+ message: msg,
193
+ data: truncateRunLogData(traceNodeData(entry, summary), maxDataJsonChars),
194
+ });
195
+ }
196
+ built.push({
197
+ ts: graphEndedAt,
198
+ level: graphStatus === 'failed' ? 'error' : 'info',
199
+ scope: 'graph',
200
+ message: graphStatus === 'failed'
201
+ ? `Graph run finished (${graphId}, failed)`
202
+ : `Graph run finished (${graphId}, completed)`,
203
+ data: truncateRunLogData({ jobId, taskId, graphId, status: graphStatus }, maxDataJsonChars),
204
+ });
205
+ built.push(...taskAppendedEntries);
206
+ built.sort((a, b) => a.ts - b.ts || 0);
207
+ let runLogTruncated = false;
208
+ let runLogOmittedCount = 0;
209
+ let out = built;
210
+ if (built.length > maxEntries) {
211
+ runLogTruncated = true;
212
+ runLogOmittedCount = built.length - maxEntries;
213
+ out = built.slice(0, maxEntries);
214
+ }
215
+ const withTruncatedData = out.map((row) => ({
216
+ ...row,
217
+ data: row.data === undefined
218
+ ? undefined
219
+ : truncateRunLogData(row.data, maxDataJsonChars),
220
+ }));
221
+ return {
222
+ runLog: withTruncatedData,
223
+ ...(runLogTruncated ? { runLogTruncated, runLogOmittedCount } : {}),
224
+ ...(inputCorrelation ? { logxerCorrelationId: inputCorrelation } : {}),
225
+ };
226
+ }
227
+ export function resolveRunLogLimits(input) {
228
+ const mode = input.runLogMode ?? input.defaults?.runLogMode ?? 'summary';
229
+ const maxEntries = Math.max(1, input.maxRunLogEntries ?? input.defaults?.maxRunLogEntries ?? DEFAULT_MAX_RUN_LOG_ENTRIES);
230
+ const maxDataJsonChars = Math.max(64, input.maxRunLogDataJsonChars ??
231
+ input.defaults?.maxRunLogDataJsonChars ??
232
+ DEFAULT_MAX_RUN_LOG_DATA_JSON_CHARS);
233
+ return { mode, maxEntries, maxDataJsonChars };
234
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Builds the `RunTaskRequest.taskConfiguration` blob for `@exellix/ai-tasks` ≥ 7.7 compile-at-invoke.
3
+ * Root-level fields already lifted by graph-engine are omitted; compile-only authoring (e.g.
4
+ * `aiTaskStrategies`, `aiTaskProfile`) remains on the blob.
5
+ */
6
+ /**
7
+ * Subset of node `taskConfiguration` forwarded on `RunTaskRequest.taskConfiguration` for ai-tasks compile.
8
+ */
9
+ export declare function buildRunTaskTaskConfigurationForward(taskConfiguration: Record<string, unknown> | undefined | null): Record<string, unknown> | undefined;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Builds the `RunTaskRequest.taskConfiguration` blob for `@exellix/ai-tasks` ≥ 7.7 compile-at-invoke.
3
+ * Root-level fields already lifted by graph-engine are omitted; compile-only authoring (e.g.
4
+ * `aiTaskStrategies`, `aiTaskProfile`) remains on the blob.
5
+ */
6
+ const RUN_TASK_LIFTED_TASK_CONFIGURATION_KEYS = new Set([
7
+ 'taskTypeId',
8
+ 'executionStrategies',
9
+ 'executionStrategyCatalogItems',
10
+ 'modelConfig',
11
+ 'llmCall',
12
+ 'timeoutMs',
13
+ 'narrix',
14
+ 'narrixMode',
15
+ 'narrixInput',
16
+ 'narrixScope',
17
+ 'inputStrategyKey',
18
+ 'aiTasksOutputValidation',
19
+ 'taskKind',
20
+ 'autoValidateDecisionOutput',
21
+ 'runTaskIdentity',
22
+ 'identity',
23
+ 'aiScoping',
24
+ 'aiScopingOptions',
25
+ 'templateRenderOptions',
26
+ 'smartInputRenderOptions',
27
+ 'templateTokens',
28
+ 'aiEngineId',
29
+ 'sessionId',
30
+ 'agentType',
31
+ 'gatewayDiagnostics',
32
+ 'context',
33
+ 'knowledge',
34
+ ]);
35
+ /** Graph-engine / local-skill keys — not consumed by ai-tasks `runTask` compile. */
36
+ const TASK_CONFIGURATION_GRAPH_ENGINE_ONLY_KEYS = new Set([
37
+ 'stepRetryPolicy',
38
+ 'concurrency',
39
+ 'memoryKey',
40
+ 'rules',
41
+ 'firstMatchWins',
42
+ 'defaultOutput',
43
+ 'sensitivityAnalysis',
44
+ 'scopingMapId',
45
+ 'entityIdPath',
46
+ 'questionId',
47
+ 'pack',
48
+ 'opDb',
49
+ 'entityTypePath',
50
+ 'staticEntityType',
51
+ 'payloadPath',
52
+ 'questionTitle',
53
+ 'phase',
54
+ 'seedThingIdPath',
55
+ 'artifactThingType',
56
+ 'xmemoryNamespace',
57
+ 'mergeInferencePaths',
58
+ 'mergeDecisionPaths',
59
+ ]);
60
+ function isPlainObject(v) {
61
+ return v != null && typeof v === 'object' && !Array.isArray(v);
62
+ }
63
+ /**
64
+ * Subset of node `taskConfiguration` forwarded on `RunTaskRequest.taskConfiguration` for ai-tasks compile.
65
+ */
66
+ export function buildRunTaskTaskConfigurationForward(taskConfiguration) {
67
+ if (!isPlainObject(taskConfiguration))
68
+ return undefined;
69
+ const out = {};
70
+ for (const [key, value] of Object.entries(taskConfiguration)) {
71
+ if (RUN_TASK_LIFTED_TASK_CONFIGURATION_KEYS.has(key))
72
+ continue;
73
+ if (TASK_CONFIGURATION_GRAPH_ENGINE_ONLY_KEYS.has(key))
74
+ continue;
75
+ if (value === undefined)
76
+ continue;
77
+ out[key] = value;
78
+ }
79
+ return Object.keys(out).length > 0 ? out : undefined;
80
+ }
@@ -0,0 +1,11 @@
1
+ import type { TaskNode } from '../types/refs.js';
2
+ /**
3
+ * Builds `RunTaskRequest.jobContext` from `jobContextMapping` and `scope.contextualKnowledge`
4
+ * (same semantics for {@link executeNode} and {@link ExellixGraphRuntime}).
5
+ */
6
+ export declare function buildTaskNodeJobContext(args: {
7
+ node: TaskNode;
8
+ jobMemory: unknown;
9
+ executionMemory: unknown;
10
+ variables: Record<string, unknown>;
11
+ }): Record<string, unknown> | undefined;
@@ -0,0 +1,30 @@
1
+ import { createMappedObject } from './memory.js';
2
+ import { processContextualScope } from './contextualScope.js';
3
+ /**
4
+ * Builds `RunTaskRequest.jobContext` from `jobContextMapping` and `scope.contextualKnowledge`
5
+ * (same semantics for {@link executeNode} and {@link ExellixGraphRuntime}).
6
+ */
7
+ export function buildTaskNodeJobContext(args) {
8
+ const { node, jobMemory, executionMemory, variables } = args;
9
+ let jobContext;
10
+ if (node.jobContextMapping) {
11
+ const { map } = node.jobContextMapping;
12
+ if (map) {
13
+ jobContext = createMappedObject(map, {
14
+ node,
15
+ jobMemory,
16
+ executionMemory,
17
+ variables,
18
+ });
19
+ }
20
+ }
21
+ if (node.scope?.contextualKnowledge) {
22
+ const scopedContext = processContextualScope(node.scope, {
23
+ jobMemory,
24
+ variables,
25
+ node,
26
+ });
27
+ jobContext = { ...(jobContext ?? {}), ...scopedContext };
28
+ }
29
+ return jobContext;
30
+ }
@@ -0,0 +1,6 @@
1
+ import type { RunTaskResponse } from '../types/options.js';
2
+ /**
3
+ * Single authoritative model id after gateway routing (G9). Prefer gateway/metadata fields
4
+ * over authored `modelConfig` on the outbound request.
5
+ */
6
+ export declare function resolveCanonicalModelUsed(response: RunTaskResponse): string | undefined;
@@ -0,0 +1,36 @@
1
+ function isPlainObject(v) {
2
+ return v != null && typeof v === 'object' && !Array.isArray(v);
3
+ }
4
+ /**
5
+ * Single authoritative model id after gateway routing (G9). Prefer gateway/metadata fields
6
+ * over authored `modelConfig` on the outbound request.
7
+ */
8
+ export function resolveCanonicalModelUsed(response) {
9
+ const r = response;
10
+ const meta = (r.metadata ?? r.meta);
11
+ if (meta != null) {
12
+ const direct = meta.modelUsed ?? meta.model;
13
+ if (typeof direct === 'string' && direct.trim() !== '')
14
+ return direct.trim();
15
+ const rawConfig = meta.rawConfig;
16
+ if (isPlainObject(rawConfig)) {
17
+ const fromRaw = rawConfig.modelUsed ?? rawConfig.model ?? rawConfig.skillModel ?? rawConfig.xynthesisModel;
18
+ if (typeof fromRaw === 'string' && fromRaw.trim() !== '')
19
+ return fromRaw.trim();
20
+ }
21
+ const gateway = meta.gateway ?? meta.gatewayDiagnostics;
22
+ if (isPlainObject(gateway)) {
23
+ const fromGw = gateway.modelUsed ?? gateway.model ?? gateway.resolvedModel;
24
+ if (typeof fromGw === 'string' && fromGw.trim() !== '')
25
+ return fromGw.trim();
26
+ }
27
+ }
28
+ const parsed = r.parsed;
29
+ if (isPlainObject(parsed)) {
30
+ const parsedMeta = parsed.meta;
31
+ if (isPlainObject(parsedMeta) && typeof parsedMeta.modelUsed === 'string' && parsedMeta.modelUsed.trim() !== '') {
32
+ return parsedMeta.modelUsed.trim();
33
+ }
34
+ }
35
+ return undefined;
36
+ }
@@ -0,0 +1,7 @@
1
+ import { GraphNode } from '../types/refs.js';
2
+ export interface ScopeProcessingContext {
3
+ jobMemory: any;
4
+ variables: any;
5
+ node: GraphNode;
6
+ }
7
+ export declare function processContextualScope(scope: NonNullable<GraphNode['scope']>, context: ScopeProcessingContext): Record<string, any[]>;
@@ -0,0 +1,121 @@
1
+ import { LogicEngine } from '@x12i/graphenix';
2
+ /**
3
+ * Resolves a placeholder string like "{{asset.zone}}" to a value
4
+ */
5
+ function resolvePlaceholder(value, context) {
6
+ if (typeof value !== 'string')
7
+ return value;
8
+ // Check for {{...}} pattern
9
+ const match = value.match(/^\{\{(.+)\}\}$/);
10
+ if (!match)
11
+ return value;
12
+ const path = match[1].trim(); // e.g., "myRoot.someField"
13
+ // Map "{{root.rest...}}" to Graphenix: if `root` exists on job variables or job memory,
14
+ // resolve under $variables or $memory (no hardcoded domain roots).
15
+ let logicPath;
16
+ const firstDot = path.indexOf('.');
17
+ if (firstDot > 0) {
18
+ const root = path.slice(0, firstDot);
19
+ if (context.variables?.[root])
20
+ logicPath = '$variables.' + path;
21
+ else if (context.jobMemory?.[root])
22
+ logicPath = '$memory.' + path;
23
+ else
24
+ logicPath = '$' + path;
25
+ }
26
+ else {
27
+ logicPath = '$' + path;
28
+ }
29
+ // Create minimal context for LogicEngine
30
+ const execContext = {
31
+ state: {}, // No specific state for this resolution
32
+ variables: context.variables || {},
33
+ memory: context.jobMemory || {},
34
+ history: [],
35
+ outputs: { byKey: {}, byNodeId: {} },
36
+ nodeStatus: {},
37
+ node: context.node
38
+ };
39
+ const resolved = LogicEngine.resolveValue(logicPath, {}, execContext);
40
+ return resolved;
41
+ }
42
+ /**
43
+ * Safely access nested property
44
+ */
45
+ function getNested(obj, path) {
46
+ return path.split('.').reduce((acc, part) => acc && acc[part], obj);
47
+ }
48
+ export function processContextualScope(scope, context) {
49
+ const result = {};
50
+ if (!scope.contextualKnowledge)
51
+ return result;
52
+ for (const item of scope.contextualKnowledge) {
53
+ const listName = item.list;
54
+ const sourceList = context.jobMemory?.[listName] || context.variables?.[listName];
55
+ if (!Array.isArray(sourceList)) {
56
+ result[listName] = [];
57
+ continue;
58
+ }
59
+ let filteredList = [...sourceList];
60
+ // Apply Filter
61
+ if (item.filter?.where) {
62
+ filteredList = filteredList.filter(entry => {
63
+ // All conditions must pass (AND logic)
64
+ return item.filter.where.every((condition) => {
65
+ const entryValue = getNested(entry, condition.path);
66
+ if (condition.eq !== undefined) {
67
+ const targetVal = resolvePlaceholder(condition.eq, context);
68
+ return entryValue === targetVal;
69
+ }
70
+ if (condition.eqAny !== undefined) {
71
+ const targetList = Array.isArray(condition.eqAny)
72
+ ? condition.eqAny.map((v) => resolvePlaceholder(v, context))
73
+ : [resolvePlaceholder(condition.eqAny, context)];
74
+ return targetList.includes(entryValue);
75
+ }
76
+ return false;
77
+ });
78
+ });
79
+ }
80
+ // Apply OrderBy
81
+ if (item.filter?.orderBy) {
82
+ filteredList.sort((a, b) => {
83
+ for (const rule of item.filter.orderBy) {
84
+ const valA = getNested(a, rule.path);
85
+ const valB = getNested(b, rule.path);
86
+ if (valA < valB)
87
+ return rule.direction === 'asc' ? -1 : 1;
88
+ if (valA > valB)
89
+ return rule.direction === 'asc' ? 1 : -1;
90
+ }
91
+ return 0;
92
+ });
93
+ }
94
+ // Apply Limit
95
+ if (item.filter?.limit !== undefined) {
96
+ filteredList = filteredList.slice(0, item.filter.limit);
97
+ }
98
+ // Apply Select
99
+ if (item.select) {
100
+ filteredList = filteredList.map(entry => {
101
+ const newEntry = {};
102
+ for (const field of item.select) {
103
+ const val = getNested(entry, field);
104
+ if (val !== undefined) {
105
+ const parts = field.split('.');
106
+ let current = newEntry;
107
+ for (let i = 0; i < parts.length - 1; i++) {
108
+ if (!current[parts[i]])
109
+ current[parts[i]] = {};
110
+ current = current[parts[i]];
111
+ }
112
+ current[parts[parts.length - 1]] = val;
113
+ }
114
+ }
115
+ return newEntry;
116
+ });
117
+ }
118
+ result[listName] = filteredList;
119
+ }
120
+ return result;
121
+ }
@@ -0,0 +1,60 @@
1
+ import type { GraphPredicate } from '../types/refs.js';
2
+ import { EXELLIX_STRUCTURED_DATA_FILTERS_V1, type StructuredDataFiltersV1 } from '../types/refs.js';
3
+ /**
4
+ * Returns paths that are not valid roots for structured data-filter predicates
5
+ * (`data` or `data.*`). Empty when every leaf path is valid.
6
+ */
7
+ export declare function getStructuredDataFilterPathViolations(predicate: GraphPredicate | undefined): string[];
8
+ /**
9
+ * Evaluate a {@link GraphPredicate} tree where every leaf `path` is rooted at `data` or `data.*`,
10
+ * resolving values from `record` (the object that backs those paths).
11
+ *
12
+ * Semantics match {@link evaluateGraphPredicate} leaf operators (`exists`, `eq`) and boolean
13
+ * combinators (`all`, `any`, `not`), but paths are restricted to the `data` root only.
14
+ */
15
+ export declare function evaluateDataFilterPredicate(predicate: GraphPredicate | undefined, record: Record<string, unknown>): boolean;
16
+ export declare function isStructuredDataFiltersV1(value: unknown): value is StructuredDataFiltersV1;
17
+ export type EvaluateStructuredDataFiltersResult = {
18
+ status: 'no_gate';
19
+ ok: true;
20
+ /** Human-readable: nothing to evaluate */
21
+ message: 'conditions.dataFilters was undefined or omitted';
22
+ } | {
23
+ status: 'legacy_reference_ids';
24
+ ok: true;
25
+ /** Catalog / host-defined ids — not interpreted by graph-engine */
26
+ ids: string[];
27
+ 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.';
28
+ } | {
29
+ status: 'unsupported_shape';
30
+ ok: false;
31
+ message: string;
32
+ } | {
33
+ status: 'evaluated';
34
+ ok: boolean;
35
+ version: typeof EXELLIX_STRUCTURED_DATA_FILTERS_V1;
36
+ /** When present, leaf paths that are not `data` / `data.*` (see `strictPaths`) */
37
+ invalidPaths?: string[];
38
+ predicateRejected?: boolean;
39
+ };
40
+ export type EvaluateStructuredDataFiltersOptions = {
41
+ /**
42
+ * When true (default), any leaf path outside `data` / `data.*` makes the result `ok: false`
43
+ * without evaluating the rest of the predicate. Canonical graph documents are validated the same way.
44
+ */
45
+ strictPaths?: boolean;
46
+ };
47
+ /**
48
+ * Public entry: interpret `conditions.dataFilters` (or the same field on `metadata.graphEntry`)
49
+ * against a plain JSON-serializable **record** object.
50
+ *
51
+ * - **Structured v1** (`{ version: "exellix.dataFilters.v1", when }`): evaluated here; leaf paths
52
+ * must be `data` or `data.*` and read from `record`.
53
+ * - **Legacy `string[]`**: not evaluated; returned as {@link EvaluateStructuredDataFiltersResult} with
54
+ * `status: "legacy_reference_ids"` so callers can apply catalog logic themselves.
55
+ * - **`undefined`**: `status: "no_gate"`, `ok: true`.
56
+ *
57
+ * This function performs **no I/O**. It does **not** evaluate `conditions.narratives` or
58
+ * `conditions.aiFilter` — those remain host / tooling concerns unless documented otherwise.
59
+ */
60
+ export declare function evaluateStructuredDataFilters(dataFilters: string[] | StructuredDataFiltersV1 | undefined, record: Record<string, unknown>, options?: EvaluateStructuredDataFiltersOptions): EvaluateStructuredDataFiltersResult;