@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,156 @@
1
+ /**
2
+ * scoped-answer-writer — local skill.
3
+ *
4
+ * Persists execution-memory payloads into Memorix **entity** collections, one
5
+ * **content type** per write (`inferences`, `decisions`, …) via `writeMemorixRecord`.
6
+ *
7
+ * Node config:
8
+ * entityIdPath — required
9
+ * payloadPath — dot-path to `{ inferences?, decisions? }` or flat decisions map
10
+ * memorixWriteDescriptors — optional map of contentType → Catalox write descriptor id
11
+ * (default: descriptor id equals content type name)
12
+ */
13
+ import { writeMemorixRecord } from '@x12i/memorix-writer';
14
+ import { getMemorixWriterClient } from './memorixRuntime.js';
15
+ import { DEFAULT_SCOPED_CONTENT_TYPES, resolveMemorixWriteDescriptorId, } from './memorixScopedConfig.js';
16
+ import { resolveDotPath } from './utils.js';
17
+ function isPlainObject(v) {
18
+ return v !== null && typeof v === 'object' && !Array.isArray(v);
19
+ }
20
+ function bucketPlainValues(record) {
21
+ const out = {};
22
+ for (const [key, value] of Object.entries(record)) {
23
+ if (value === undefined)
24
+ continue;
25
+ if (isPlainObject(value) && 'value' in value) {
26
+ out[key] = value.value;
27
+ }
28
+ else {
29
+ out[key] = value;
30
+ }
31
+ }
32
+ return out;
33
+ }
34
+ function extractContentTypeBuckets(payload, contentTypes) {
35
+ const buckets = {};
36
+ const writtenKeys = [];
37
+ const hasNamedBuckets = contentTypes.some((ct) => isPlainObject(payload[ct]));
38
+ if (hasNamedBuckets) {
39
+ for (const ct of contentTypes) {
40
+ const raw = payload[ct];
41
+ if (!isPlainObject(raw))
42
+ continue;
43
+ const plain = bucketPlainValues(raw);
44
+ if (Object.keys(plain).length === 0)
45
+ continue;
46
+ buckets[ct] = plain;
47
+ writtenKeys.push(...Object.keys(plain).map((k) => `${ct}.${k}`));
48
+ }
49
+ return { buckets, writtenKeys };
50
+ }
51
+ const plain = bucketPlainValues(payload);
52
+ if (Object.keys(plain).length > 0) {
53
+ buckets.decisions = plain;
54
+ writtenKeys.push(...Object.keys(plain).map((k) => `decisions.${k}`));
55
+ }
56
+ return { buckets, writtenKeys };
57
+ }
58
+ const SKILL = 'scoped-answer-writer';
59
+ export async function runScopedAnswerWriter(cfg, executionMemory, pathOpts) {
60
+ const { entityIdPath } = cfg;
61
+ const payloadPath = cfg.payloadPath;
62
+ const contentTypes = cfg.memorixContentTypes?.length
63
+ ? cfg.memorixContentTypes
64
+ : [...DEFAULT_SCOPED_CONTENT_TYPES];
65
+ if (!entityIdPath || !payloadPath) {
66
+ return {
67
+ write_status: 'error',
68
+ entity_id: '',
69
+ content_types_written: [],
70
+ written_keys: [],
71
+ error: `${SKILL}: taskConfiguration.entityIdPath and payloadPath are required`,
72
+ };
73
+ }
74
+ const entityId = resolveDotPath(executionMemory, entityIdPath, pathOpts);
75
+ if (entityId == null || typeof entityId !== 'string' || entityId === '') {
76
+ return {
77
+ write_status: 'error',
78
+ entity_id: String(entityId ?? ''),
79
+ content_types_written: [],
80
+ written_keys: [],
81
+ error: `${SKILL}: entityIdPath "${entityIdPath}" resolved to empty/non-string value`,
82
+ };
83
+ }
84
+ const rawPayload = resolveDotPath(executionMemory, payloadPath, pathOpts);
85
+ if (rawPayload == null || typeof rawPayload !== 'object' || Array.isArray(rawPayload)) {
86
+ return {
87
+ write_status: 'error',
88
+ entity_id: entityId,
89
+ content_types_written: [],
90
+ written_keys: [],
91
+ error: `${SKILL}: payloadPath "${payloadPath}" did not resolve to a plain object`,
92
+ };
93
+ }
94
+ const { buckets, writtenKeys } = extractContentTypeBuckets(rawPayload, contentTypes);
95
+ if (writtenKeys.length === 0) {
96
+ return {
97
+ write_status: 'error',
98
+ entity_id: entityId,
99
+ content_types_written: [],
100
+ written_keys: [],
101
+ error: `${SKILL}: payload at "${payloadPath}" produced no fields to write`,
102
+ };
103
+ }
104
+ const entityType = (cfg.entityTypePath ? String(resolveDotPath(executionMemory, cfg.entityTypePath, pathOpts) ?? '') : '') ||
105
+ cfg.staticEntityType ||
106
+ undefined;
107
+ const now = new Date().toISOString();
108
+ const contentTypesWritten = [];
109
+ try {
110
+ const client = await getMemorixWriterClient();
111
+ for (const [contentType, bucket] of Object.entries(buckets)) {
112
+ const writeDescriptorId = resolveMemorixWriteDescriptorId(cfg, contentType);
113
+ const result = await writeMemorixRecord(client, {
114
+ writeDescriptorId,
115
+ entityId,
116
+ operation: 'upsert',
117
+ input: {
118
+ ...bucket,
119
+ entityType,
120
+ question: cfg.questionTitle,
121
+ updatedAt: now,
122
+ modifiedAt: now,
123
+ },
124
+ });
125
+ if (!result.ok) {
126
+ const msg = result.issues
127
+ ?.filter((i) => i.severity === 'error')
128
+ .map((i) => i.message)
129
+ .join('; ') || `Memorix write failed for content type "${contentType}"`;
130
+ return {
131
+ write_status: 'error',
132
+ entity_id: entityId,
133
+ content_types_written: contentTypesWritten,
134
+ written_keys: [],
135
+ error: `${SKILL}: ${msg}`,
136
+ };
137
+ }
138
+ contentTypesWritten.push(contentType);
139
+ }
140
+ return {
141
+ write_status: 'ok',
142
+ entity_id: entityId,
143
+ content_types_written: contentTypesWritten,
144
+ written_keys: writtenKeys,
145
+ };
146
+ }
147
+ catch (err) {
148
+ return {
149
+ write_status: 'error',
150
+ entity_id: entityId,
151
+ content_types_written: contentTypesWritten,
152
+ written_keys: [],
153
+ error: `${SKILL}: ${err?.message ?? String(err)}`,
154
+ };
155
+ }
156
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * scoped-data-reader — local deterministic skill.
3
+ *
4
+ * Reads entity state via Memorix `fetchMemorixItem`. Item descriptors define which
5
+ * content types and properties appear in sections; this skill flattens them to `fields.*`.
6
+ *
7
+ * Node config:
8
+ * memorixItemDescriptorId | itemDescriptorId — required
9
+ * entityIdPath — dot-path to resolve Memorix entity id
10
+ * pack — parallel reads: `{ slot, memorixItemDescriptorId, entityIdPath }[]`
11
+ */
12
+ import { type MemorixScopedSkillConfig } from './memorixScopedConfig.js';
13
+ import { type ResolveDotPathOpts } from './utils.js';
14
+ export { scopedAnswerDocToFlatFields } from './scopedAnswerFields.js';
15
+ export type ScopedDataReaderPackSlot = {
16
+ slot: string;
17
+ entityIdPath: string;
18
+ memorixItemDescriptorId?: string;
19
+ itemDescriptorId?: string;
20
+ };
21
+ export type ScopedDataReaderConfig = MemorixScopedSkillConfig & {
22
+ entityIdPath: string;
23
+ pack?: ScopedDataReaderPackSlot[];
24
+ };
25
+ export type ScopedDataReaderOutput = {
26
+ answer_status: 'answered' | 'not_found' | 'empty' | 'error';
27
+ fields: Record<string, {
28
+ value: unknown;
29
+ fieldPath: string;
30
+ description?: string;
31
+ reasoning?: string;
32
+ linked?: boolean;
33
+ }>;
34
+ freshness: {
35
+ scopedAt: string;
36
+ } | null;
37
+ unknowns: string[];
38
+ entity_id: string;
39
+ error?: string;
40
+ };
41
+ export type ScopedDataReaderPackOutput = {
42
+ pack_status: 'ok' | 'error';
43
+ slots: Record<string, ScopedDataReaderOutput>;
44
+ error?: string;
45
+ };
46
+ export declare function runScopedDataReaderPack(pack: ScopedDataReaderPackSlot[], executionMemory: unknown, pathOpts?: ResolveDotPathOpts): Promise<ScopedDataReaderPackOutput>;
47
+ export declare function runScopedDataReader(cfg: ScopedDataReaderConfig, executionMemory: unknown, pathOpts?: ResolveDotPathOpts): Promise<ScopedDataReaderOutput | ScopedDataReaderPackOutput>;
@@ -0,0 +1,89 @@
1
+ /**
2
+ * scoped-data-reader — local deterministic skill.
3
+ *
4
+ * Reads entity state via Memorix `fetchMemorixItem`. Item descriptors define which
5
+ * content types and properties appear in sections; this skill flattens them to `fields.*`.
6
+ *
7
+ * Node config:
8
+ * memorixItemDescriptorId | itemDescriptorId — required
9
+ * entityIdPath — dot-path to resolve Memorix entity id
10
+ * pack — parallel reads: `{ slot, memorixItemDescriptorId, entityIdPath }[]`
11
+ */
12
+ import { fetchMemorixItem } from '@x12i/memorix-retrieval';
13
+ import { memorixItemToScopedOutput } from './memorixItemToScopedOutput.js';
14
+ import { getMemorixRetrievalClient } from './memorixRuntime.js';
15
+ import { resolveMemorixItemDescriptorId } from './memorixScopedConfig.js';
16
+ import { resolveDotPath } from './utils.js';
17
+ export { scopedAnswerDocToFlatFields } from './scopedAnswerFields.js';
18
+ async function runScopedDataReaderCore(cfg, executionMemory, pathOpts) {
19
+ const { entityIdPath } = cfg;
20
+ const itemDescriptorId = resolveMemorixItemDescriptorId(cfg);
21
+ const entityId = resolveDotPath(executionMemory, entityIdPath, pathOpts);
22
+ if (entityId == null || typeof entityId !== 'string' || entityId === '') {
23
+ return {
24
+ answer_status: 'error',
25
+ fields: {},
26
+ freshness: null,
27
+ unknowns: [],
28
+ entity_id: String(entityId ?? ''),
29
+ error: `scoped-data-reader: entityIdPath "${entityIdPath}" resolved to empty/non-string value`,
30
+ };
31
+ }
32
+ if (!itemDescriptorId) {
33
+ return {
34
+ answer_status: 'error',
35
+ fields: {},
36
+ freshness: null,
37
+ unknowns: [],
38
+ entity_id: entityId,
39
+ error: 'scoped-data-reader: memorixItemDescriptorId or itemDescriptorId is required',
40
+ };
41
+ }
42
+ try {
43
+ const client = await getMemorixRetrievalClient();
44
+ const item = await fetchMemorixItem(client, {
45
+ itemDescriptorId,
46
+ entityId,
47
+ });
48
+ return memorixItemToScopedOutput(item, entityId);
49
+ }
50
+ catch (err) {
51
+ return {
52
+ answer_status: 'error',
53
+ fields: {},
54
+ freshness: null,
55
+ unknowns: [],
56
+ entity_id: entityId,
57
+ error: `scoped-data-reader: ${err?.message ?? String(err)}`,
58
+ };
59
+ }
60
+ }
61
+ export async function runScopedDataReaderPack(pack, executionMemory, pathOpts) {
62
+ try {
63
+ const entries = await Promise.all(pack.map(async (p) => {
64
+ const out = await runScopedDataReaderCore({
65
+ entityIdPath: p.entityIdPath,
66
+ memorixItemDescriptorId: p.memorixItemDescriptorId,
67
+ itemDescriptorId: p.itemDescriptorId,
68
+ }, executionMemory, pathOpts);
69
+ return [p.slot, out];
70
+ }));
71
+ return {
72
+ pack_status: 'ok',
73
+ slots: Object.fromEntries(entries),
74
+ };
75
+ }
76
+ catch (err) {
77
+ return {
78
+ pack_status: 'error',
79
+ slots: {},
80
+ error: err?.message ?? String(err),
81
+ };
82
+ }
83
+ }
84
+ export async function runScopedDataReader(cfg, executionMemory, pathOpts) {
85
+ if (Array.isArray(cfg.pack) && cfg.pack.length > 0) {
86
+ return runScopedDataReaderPack(cfg.pack, executionMemory, pathOpts);
87
+ }
88
+ return runScopedDataReaderCore(cfg, executionMemory, pathOpts);
89
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared utilities for local skills — no external dependencies.
3
+ */
4
+ export type ResolveDotPathOpts = {
5
+ /** Resolves `xynthesized.task.*` against `execution.xynthesized.taskByNode[nodeId]`. */
6
+ graphTaskNodeId?: string;
7
+ };
8
+ /**
9
+ * Resolve a dot-path into an object. Returns undefined when any segment is missing.
10
+ * Supports `xynthesized.job.*`, `xynthesized.task.*` (node-scoped), and `xynthesized.execution.*`.
11
+ */
12
+ export declare function resolveDotPath(obj: unknown, path: string, opts?: ResolveDotPathOpts): unknown;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Shared utilities for local skills — no external dependencies.
3
+ */
4
+ /**
5
+ * Resolve a dot-path into an object. Returns undefined when any segment is missing.
6
+ * Supports `xynthesized.job.*`, `xynthesized.task.*` (node-scoped), and `xynthesized.execution.*`.
7
+ */
8
+ export function resolveDotPath(obj, path, opts) {
9
+ const p = typeof path === 'string' ? path.trim() : '';
10
+ if (!p)
11
+ return obj;
12
+ if (p.startsWith('xynthesized.execution.')) {
13
+ const tail = p.slice('xynthesized.execution.'.length);
14
+ const ex = obj;
15
+ const xy = ex?.xynthesized;
16
+ return resolveDotPath(xy?.execution, tail, opts);
17
+ }
18
+ if (p.startsWith('xynthesized.job.')) {
19
+ const tail = p.slice('xynthesized.job.'.length);
20
+ const ex = obj;
21
+ const xy = ex?.xynthesized;
22
+ return resolveDotPath(xy?.job, tail, opts);
23
+ }
24
+ if (opts?.graphTaskNodeId && p.startsWith('xynthesized.task.')) {
25
+ const tail = p.slice('xynthesized.task.'.length);
26
+ const ex = obj;
27
+ const xy = ex?.xynthesized;
28
+ const bucket = xy?.taskByNode?.[opts.graphTaskNodeId];
29
+ return resolveDotPath(bucket, tail, opts);
30
+ }
31
+ const parts = p.split('.');
32
+ let cur = obj;
33
+ for (const seg of parts) {
34
+ if (cur == null || typeof cur !== 'object')
35
+ return undefined;
36
+ cur = cur[seg];
37
+ }
38
+ return cur;
39
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Ensures `executionMemory.input.raw` holds the active MAIN payload for PRE synthesis paths
3
+ * (e.g. `inputsConfig` bindings with `path: "input.raw"`).
4
+ */
5
+ export declare function mirrorRuntimeInputRawOnExecutionMemory(executionMemory: Record<string, unknown>): void;
6
+ /**
7
+ * Mirrors MAIN task input onto `executionMemory.input` for the current graph run.
8
+ */
9
+ export declare function mirrorStructuredInputOntoExecutionMemory(executionMemory: Record<string, unknown>, structuredInput: Record<string, unknown>): void;
@@ -0,0 +1,34 @@
1
+ function isPlainObject(v) {
2
+ return v != null && typeof v === 'object' && !Array.isArray(v);
3
+ }
4
+ /**
5
+ * Ensures `executionMemory.input.raw` holds the active MAIN payload for PRE synthesis paths
6
+ * (e.g. `inputsConfig` bindings with `path: "input.raw"`).
7
+ */
8
+ export function mirrorRuntimeInputRawOnExecutionMemory(executionMemory) {
9
+ const main = executionMemory.input;
10
+ if (main === undefined)
11
+ return;
12
+ const raw = isPlainObject(main)
13
+ ? (() => {
14
+ const copy = { ...main };
15
+ delete copy.raw;
16
+ return copy;
17
+ })()
18
+ : main;
19
+ const prev = isPlainObject(executionMemory.input) ? executionMemory.input : {};
20
+ executionMemory.input = { ...prev, raw };
21
+ }
22
+ /**
23
+ * Mirrors MAIN task input onto `executionMemory.input` for the current graph run.
24
+ */
25
+ export function mirrorStructuredInputOntoExecutionMemory(executionMemory, structuredInput) {
26
+ const prev = structuredInput != null && typeof structuredInput === 'object' && !Array.isArray(structuredInput)
27
+ ? (executionMemory.input != null &&
28
+ typeof executionMemory.input === 'object' &&
29
+ !Array.isArray(executionMemory.input)
30
+ ? executionMemory.input
31
+ : {})
32
+ : {};
33
+ executionMemory.input = { ...prev, ...structuredInput };
34
+ }
@@ -0,0 +1,51 @@
1
+ import { GraphNode } from '../types/refs.js';
2
+ import { NodeExecutionResult } from '../types/results.js';
3
+ /**
4
+ * Creates a mapped object from a map configuration.
5
+ * Uses pathExpr (selectByPath) for paths containing [*], {*}, or starting with executionMemory./jobMemory.;
6
+ * otherwise uses Graphenix resolveMappingPath for node.X, output.X, variables.X.
7
+ */
8
+ export declare function createMappedObject(map: Record<string, string>, context: {
9
+ node?: GraphNode;
10
+ output?: any;
11
+ jobMemory?: any;
12
+ executionMemory?: any;
13
+ variables?: Record<string, any>;
14
+ }): any;
15
+ /**
16
+ * Merges memory from job and node sources.
17
+ */
18
+ export declare function mergeMemory(options: {
19
+ jobMemory?: any;
20
+ taskMemory?: any;
21
+ node?: GraphNode;
22
+ }): {
23
+ jobMemory?: any;
24
+ taskMemory?: any;
25
+ };
26
+ /**
27
+ * Merges output into execution object based on mapping configuration.
28
+ * Uses writeByPath for target path (supports nested paths, creates missing objects).
29
+ * Resolves map sources via selectByPath on { output, node, variables } with fallback to Graphenix.
30
+ */
31
+ export declare function mergeExecutionObject(execution: any, path: string, output: any, mode?: 'replace' | 'append' | 'merge', mappingConfig?: {
32
+ map?: Record<string, string>;
33
+ fields?: string[];
34
+ }, context?: {
35
+ node?: GraphNode;
36
+ variables?: Record<string, any>;
37
+ }): any;
38
+ /**
39
+ * Merges execution object into jobMemory so it appears in workingMemory.
40
+ */
41
+ export declare function mergeExecutionIntoMemory(jobMemory: any, execution: any): any;
42
+ /**
43
+ * Builds a semantic memory key for a node result.
44
+ */
45
+ export declare function buildMemoryKey(node: GraphNode): string;
46
+ /**
47
+ * Accumulates a node execution result into jobMemory.
48
+ */
49
+ export declare function accumulateNodeResult(currentMemory: any, node: GraphNode, result: NodeExecutionResult): any;
50
+ /** Copy selected execution fields when target omits them (e.g. webContext from response.executionMemory). */
51
+ export declare function copyExecutionContextFields(targetExecution: unknown, sourceExecution: unknown, fields: string[]): void;